Skip to content

Conversation

@juergenhoetzel
Copy link
Contributor

Fixes a mismatch of the completion START position in the Emacs buffer and the candidatates that didn't include the expected module-prefix.

Fixes #455

@juergenhoetzel
Copy link
Contributor Author

@bbatsov You contributed the original code: Could you take a look?

@juergenhoetzel juergenhoetzel force-pushed the capf-module-completion branch 2 times, most recently from e99219b to b684685 Compare January 23, 2025 20:47
src/top/utop.el Outdated
(push argument utop-completion)
(throw 'done t))))))
(when-let* ((pos (string-match "[^.]*$" prefix))
((string-prefix-p (substring prefix pos) argument)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like much pushing conditional checks without bindings to when-let, as this makes a bit harder to understand what the code does.

src/top/utop.el Outdated
(throw 'done t))))))
(when-let* ((pos (string-match "[^.]*$" prefix))
((string-prefix-p (substring prefix pos) argument)))
(push (concat (substring prefix 0 pos) argument) utop-completion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a binding for (substring prefix 0 pos) will make this bit of code slightly easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your helpful suggestions. I amended the commit.

Fixes a mismatch of the completion START position in the Emacs buffer
and the candidatates that didn't include the expected module-prefix.

Fixes ocaml-community#455
@juergenhoetzel juergenhoetzel force-pushed the capf-module-completion branch from b684685 to 1b0d11a Compare April 3, 2025 20:05
@juergenhoetzel juergenhoetzel requested a review from bbatsov April 3, 2025 20:06
Copy link
Contributor

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed change seems solid to me!

@Octachron
Copy link
Member

The code looks correct from afar (I am unfortunately less familiar with emacs than with the compiler), however I am not been able to reproduce the bug report yet. @juergenhoetzel , do you have a full reproduction case that I could follow to check the bug and the fix in order to move forward with this PR?

@juergenhoetzel
Copy link
Contributor Author

The code looks correct from afar (I am unfortunately less familiar with emacs than with the compiler), however I am not been able to reproduce the bug report yet. @juergenhoetzel , do you have a full reproduction case that I could follow to check the bug and the fix in order to move forward with this PR?

Of course:

  1. Start utop: M-x utop
  2. Enter prefix Filename.co and press tab

Result: No completions

Using this PR, this will result in Filename.concat

@Octachron Octachron merged commit 5da1bb6 into ocaml-community:master Jul 22, 2025
4 of 5 checks passed
@Octachron
Copy link
Member

I finally found the time to test the fix, sorry for the wait ! I have merged the PR and it should be part of the upcomong 2.16.0 release this week.

Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Completion broken when running utop from emacs

3 participants