0

I'm using Vertico for completion, which uses the command vertico-exit-input to exit, particularly when the input is empty. I would like to trigger this command when I press the left arrow key while point is at the beginning of the minibuffer. So I wrote a function

(defun ahpbwd ()
  "This function quits Vertico if at the beginning of a minibuffer and otherwise behaves like the left arrow key."
  (interactive)
  (cond
   ((derived-mode-p 'minibuffer-mode)
    (if (bobp) (call-interactively 'vertico-exit-input)))
   (t (backward-char))
   ))

However, this doesn't work, even though it works if I replace (bobp) with (eobp) and press left arrow at the end of the minibuffer. Similarly, it also doesn't work if I use

(eq (point) (point-min)

instead of (eobp). I think this is because there is usuall initial text in the minibuffer, like, say, the path of the current file in the file navigation minibuffer, which messes up the positioning. Is there any way I can either account for that text or use a modified minimal position command that does?

2
  • 1
    Is there a function that the vertico library uses to analyze each keyboard stroke, perhaps attached to a pre/post command hook? If so, then you could also check this-command / last-command and/or other checks to examine buffer position ...
    – lawlist
    Commented Dec 31, 2023 at 4:26
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Commented Dec 31, 2023 at 18:54

1 Answer 1

0

I'm not fully satisfied with this solution because it messes up my formatting, but a quick hack I found was

(defun ahpbwd ()
  "This function quits Vertico if at the beginning of a minibuffer and otherwise behaves like the left arrow key."
  (interactive)
  (let ((pos (point))) 
    (backward-char)
    (if (and (derived-mode-p 'minibuffer-mode) (equal (- pos 1) (point)))
        (vertico-exit-input))))

So remembering the position of point, then going backward and if point remains at the same position and the buffer is a minibuffer, quitting Vertico.

2
  • 1
    The doc-string for equal says: "Use = if you want integers and floats to be able to be equal."
    – lawlist
    Commented Dec 31, 2023 at 4:30
  • @lawlist Thanks, I always get these equality predicates mixed up. Commented Dec 31, 2023 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.