Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

Ido Bury Buffer

A lesson for the less-informed: while using ido to switch buffers, you can kill buffers with C-k.

For some reason, though, you can't bury them. C-b seems like an obvious choice, but find your personal preference.

(add-hook
 'ido-setup-hook
 (defun endless/define-ido-bury-key ()
   (define-key ido-completion-map
     (kbd "C-b") 'endless/ido-bury-buffer-at-head)))

(defun endless/ido-bury-buffer-at-head ()
  "Bury the buffer at the head of `ido-matches'."
  (interactive)
  (let ((enable-recursive-minibuffers t)
        (buf (ido-name (car ido-matches)))
        (nextbuf (cadr ido-matches)))
    (when (get-buffer buf)
      ;; If next match names a buffer use the buffer object;
      ;; buffer name may be changed by packages such as
      ;; uniquify.
      (when (and nextbuf (get-buffer nextbuf))
        (setq nextbuf (get-buffer nextbuf)))
      (bury-buffer buf)
      (if (bufferp nextbuf)
          (setq nextbuf (buffer-name nextbuf)))
      (setq ido-default-item nextbuf
            ido-text-init ido-text
            ido-exit 'refresh)
      (exit-minibuffer))))

Don't be overly impressed by the apparent robustness of the code, it's merely an adaptation of ido-kill-buffer-at-head.

Tags: lisp, init.el, emacs,

comments powered by Disqus