Skip to content

Instantly share code, notes, and snippets.

@nriley
Created August 22, 2015 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nriley/541200857d9e7eac7f73 to your computer and use it in GitHub Desktop.
Save nriley/541200857d9e7eac7f73 to your computer and use it in GitHub Desktop.
better buffer switching - a bit like electric-buffer-list, but with fit-to-buffer and window management that makes more sense to me
(global-set-key (kbd "C-x C-b")
(lambda ()
(interactive)
(let ((buffer-list-window (list-buffers)))
(fit-window-to-buffer buffer-list-window)
(select-window buffer-list-window)
(setq tabulated-list-sort-key '("File"))
(tabulated-list-init-header)
; don't try to preserve selection, because...
(tabulated-list-print nil)
; ...we're about to place the point at the beginning of
; the line for the selected buffer
(if (search-forward "\n." nil t)
(forward-char -1))
(hl-line-mode t))))
(defun Buffer-menu-quit-and-select ()
(interactive)
(Buffer-menu-execute)
(let ((selected-buffer (Buffer-menu-buffer t)))
(quit-window)
(switch-to-buffer selected-buffer)))
(define-key Buffer-menu-mode-map "\C-m" 'Buffer-menu-quit-and-select)
(define-key Buffer-menu-mode-map "j" 'next-line)
(define-key Buffer-menu-mode-map "k" 'previous-line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment