2008-08-22 bs-show

Yeah yeah, more .emacs goodness! Well. Simple stuff, right? So here’s the thing: In the old days, I [SwitchingBuffers switched buffers] using [ListBuffers buffer-list] which is bound to C-x C-b. It does the job. Then I learnt about [BufferMenu buffer-menu] and bound it to C-x C-b. Time passes. People talk about [IbufferMode ibuffer]. But it’s too damn complicated. I realized that [BufferSelection bs-show] is good enough for me.

It lists the buffer the way I want them, and it allows me to quickly cycle through the sets I’m interested in, and it’s easy to define new sets. Use ’c’ to cycle through the sets.

;;; bs instead of buffer-menu
(global-set-key (kbd "C-x C-b") 'bs-show)

(setq bs-configurations
      '(("all" nil nil nil nil nil)
        ("files" nil nil nil bs-visits-non-file bs-sort-buffer-interns-are-last)
        ("dired" nil nil nil
         (lambda (buf)
           (with-current-buffer buf
             (not (eq major-mode 'dired-mode)))) nil)
        ("rcirc" nil nil nil
         (lambda (buf)
           (with-current-buffer buf
             (not (eq major-mode 'rcirc-mode))))
	 rcirc-sort-buffers)))

(defun rcirc-sort-name (buf)
  "Return server process and buffer name as a string."
  (when (boundp 'rcirc-server-buffer)
    (with-current-buffer buf
      (downcase (concat (if rcirc-server-buffer
			    (buffer-name rcirc-server-buffer)
			  " ")
			" "
			(or rcirc-target ""))))))

(defun rcirc-sort-buffers (a b)
  "Sort buffers A and B using `rcirc-sort-name'."
  (string< (rcirc-sort-name a)
	   (rcirc-sort-name b)))

Notice how the rcirc entry uses a separate sorting routine, and how the sorting routing uses a “SERVER TARGET” to sort buffers. Thus, all targets on a particular server are grouped together. Also note the use of boundp to check whether the rcirc variables exist. If rcirc isn’t loaded, we must avoid “Symbol’s value as variable is void” errors.

rcirc

I don’t remember any longer why I used the negative test for the major-mode in bs-configurations. If you try to use the positive tests it just doesn’t work. I just tried it. I’m too lazy to investigate. If you figure it out, let me know.

​#Emacs