0

Say I'm in the middle of switch-to-buffer (using vertico.el btw), I couldn't find the buffer/file I need. I want to use a key binding to call helm-recentf or helm-locate etc, how should I go about doing that? tried

(use-package vertico
  :bind (:map vertico-map
              ("M-t" . (lambda()(interactive)(vertico-exit)(helm-recentf)))))

but that doesn't work, the code after (vertico-exit) doesn't get called. If I remove (vertico-exit), vertico will hang around. what's the correct way to do this?

Drew
  • 75,699
  • 9
  • 109
  • 225
SparedWhisle
  • 569
  • 3
  • 13
  • A [recursive edit](https://www.gnu.org/software/emacs/manual/html_node/emacs/Recursive-Edit.html) perhaps? – NickD Jul 14 '22 at 16:37

1 Answers1

0
  1. emacs -Q
  2. When in *scratch* buffer, copy the below snippet
(custom-set-variables
 '(enable-recursive-minibuffers t)
 '(minibuffer-depth-indicate-mode t))

(package-initialize)

(vertico-mode 1)
(require 'helm)

(defvar-local my-vertico-command nil)

(advice-add 'vertico--exhibit
            :after
            (defun vertico--setup:after ()
              (when (and
                     ;; The command is `switch-to-buffer'
                     (eq my-vertico-command 'switch-to-buffer)
                     ;; There are no matching candidates
                     (null vertico--candidates))
                ;; Put current minibuffer contents in kill ring.
                ;; It can be yanked if needed as a pattern for
                ;; `helm-recentf'.
                (kill-new (minibuffer-contents))
                ;; Launch `helm-recentf' on exit
                (run-with-timer nil nil 'helm-recentf)
                ;; Exit the current command which `switch-to-buffer'.
                (call-interactively 'exit-minibuffer))))

(add-hook 'minibuffer-setup-hook
          (defun my-minibuffer-with-setup-hook ()
            ;; Note down the command which is reading from minibuffer
            ;; in `my-vertico-command'.
            (setq my-vertico-command this-command)))

  1. M-x eval-buffer RET
  2. C-x b, start typing some gibberish. You will start with vertico, but will end up with helm.