Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about completion mode #547

Open
rpgoldman opened this issue Nov 20, 2022 · 8 comments
Open

Question about completion mode #547

rpgoldman opened this issue Nov 20, 2022 · 8 comments

Comments

@rpgoldman
Copy link
Contributor

I wonder if you can help me debug a problem I am having. sly completions are not working as expected (I think).

Here's what I do:

  1. M-TAB to request symbol creation
  2. I get a minibuffer (*sly-completions*) with a list of completions and the prompt to use <right> and <left> to navigate completions.
  3. I press <right>
  4. The cursor moves right in the original buffer and the minibuffer manages.

My best guess is that this prompt reflects an expectation that the cursor will be in the *sly-completions* minibuffer, but for me it is, instead, left in the source buffer. Is that correct?

If so, I have no idea what I could be doing to break the cursor placement. But before I go crazy trying to figure this out, I wanted to make sure that I am right in my guess above. Thanks!

@joaotavora
Copy link
Owner

There's osmething odd with that prompt. My prompt doesn't suggest those keys:

image

Can you reproduce this exact situation from Emacs -Q?

@rpgoldman
Copy link
Contributor Author

rpgoldman commented Nov 23, 2022

Sorry to be so long getting to this. I did reproduce this on an un-customized emacs. I still see this:

image

The one confound is that I'm using Aquamacs, and maybe that is interfering. I will check further.

Meanwhile, when you are in this situation, is the cursor in the minibuffer, or does it stay in "thingy.lisp"? It's hard for me to tell from your image, so I am left wondering -- does completion override the bindings for C-n and C-p in "thingy.lisp", or does the cursor get left in the minibuffer so you use C-n and C-p there to navigate and select?

For me, navigating the set of completions works, but annoyingly I have to do C-x b to get to the completion buffer before the keystrokes work (which I often forget to do). It seems like this is just my problem, and given the results on emacs w/o customizations, it is most likely an Aquamacs thing.

P.S. the contents of the *scratch* buffer in my figure should be the only customizations in that emacs session.

@joaotavora
Copy link
Owner

The one confound is that I'm using Aquamacs, and maybe that is interfering. I will check further.

I'm very inclined to believe that. Aquamacs is extremely heavily customized last time I used it. I didn't even know it was still a thing, and am suprised SLY works on it.

@rpgoldman
Copy link
Contributor Author

@joaotavora Sorry to bother you again, but would you just let me know where the cursor is positioned after the completion key for you? Is it in the completion minibuffer (as I suspect), or in the buffer where the completion command was typed?

If it is in the original buffer (not the minibuffer), do C-n and C-p move up and down in the minibuffer or are they interpreted in the source buffer?

@joaotavora
Copy link
Owner

When SLY's built in completion UI kicks in, like in the screenshot above, the active window is the source-editing window (which can be the REPL). Also in this active window, the point (which is the correct term to mean "cursor" in Emacs parlance) is unchanged (i.e. it is where you last left it).

When one presses C-n and C-p the temporary and inactive *sly-completions* window which is showing below the source window is updated to highlight the completion candidate that will be inserted "at point" if you press RET (Enter) or TAB.

@rpgoldman
Copy link
Contributor Author

Thank you, @joaotavora ! I will look and see why that is not happening for me. Seems like you are saying that the C-n and C-p characters are read in the main window, but move the subsidiary window.

That's a very helpful clue and I will try to figure out what is breaking this!

@rpgoldman
Copy link
Contributor Author

I looked further and now I see that the next and previous completion keys seem to work, it's just that for some reason Aquamacs (I think it's Aquamacs!) is rewriting the keystrokes in here:

"Use \\[sly-next-completion] and \\[sly-prev-completion] to navigate completions."
          " \\[sly-choose-completion] or [mouse-1] selects a completion."
          "\n\nAnnotation flags: (b)oundp (f)boundp (g)eneric-function (c)lass (m)acro (s)pecial-operator\n\n"

to be wrong. I wouldn't know how to do this even if I wanted to!

@rpgoldman
Copy link
Contributor Author

For anyone else who encounters this problem, I offer a proposed fix from Win Treese, the Aquamacs maintainer:

  1. Aquamacs redefines C-n and C-p to be aquamacs-next-line and aquamacs-previous-line, respectively. I think this was originally done to make things more intuitive with certain configurations different than default Emacs, but I can’t reconstruct the details at the moment.

  2. In defining the keymap for the Sly completions buffer, Sly remaps certain keys to next/prev. This makes sense, but doesn’t have the desired effect in Aquamacs.

To clean up the bindings and give the right hint about the keys to use, I think you can use the following code after Sly is loaded:

(define-key sly--completion-display-mode-map [right] nil)
(define-key sly--completion-display-mode-map [left] nil)
(define-key sly--completion-display-mode-map [up] nil)
(define-key sly--completion-display-mode-map [down] nil)
(define-key sly--completion-display-mode-map [remap previous-line] nil)
(define-key sly--completion-display-mode-map [remap next-line] nil)
(define-key sly--completion-display-mode-map [backtab] nil)
(define-key sly--completion-display-mode-map [remap aquamacs-next-line] #'sly-next-completion)
(define-key sly--completion-display-mode-map [remap aquamacs-previous-line] #'sly-prev-completion)

I will update this issue after testing and close it if this provides the solution.

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

No branches or pull requests

2 participants