1

I want to bind key when in ido-switch-buffer to open ibuffer instead, but I do not understand how to make that with elisp. Here's my config:

(defun my-open-ibuffer ()
  "Open ibuffer from ido-switch-buffer"
  (interactive)
  (minibuffer-keyboard-quit)
  (ibuffer-other-window))

(defun bind-ido-keys ()
  "Keybindings for ido mode."
  (define-key ido-completion-map (kbd "C-H-S-c") 'my-open-ibuffer))

(add-hook 'ido-setup-hook #'bind-ido-keys)

It looks like when I call (minibuffer-keyboard-quit) to close ido-minibuffer function stops evaluating and not running next (ibuffer-other-window) that should open ibuffer. If I comment out (minibuffer-keyboard-quit) it works as supposed - open new ibuffer window with not closed minibuffer. But I want minibuffer to be closed, and config described above only closes minibuffer and not triggering ibuffer opening.

1

Ok looks like I figured it out by myself, and great thanks for this to abo-abo's brilliant post about callback-quit

The trick is in minibuffer-quit-and-run macro described below, if anyone had the same issues with running smth with minibuffer closing:

(defmacro minibuffer-quit-and-run (&rest body)
  "Quit the minibuffer and run BODY afterwards."
  `(progn
     (run-at-time nil nil
                  (lambda ()
                    (put 'quit 'error-message "Quit")
                    ,@body))
     (minibuffer-keyboard-quit)))

(defun my-open-ibuffer ()
  "Open ibuffer from ido-switch-buffer"
  (interactive)
  (minibuffer-quit-and-run (ibuffer-other-window)))



(defun bind-ido-keys ()
  "Keybindings for ido mode."
  (define-key ido-completion-map (kbd "C-H-S-c") 'my-open-ibuffer))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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