To set up FontLockMode for BufferMenu, use this bit of Emacs lisp.

    (setq buffer-menu-buffer-font-lock-keywords
      '(("^....[*]Man .*Man.*"   . font-lock-variable-name-face) ;Man page
        (".*Dired.*"             . font-lock-comment-face)       ; Dired
        ("^....[*]shell.*"       . font-lock-preprocessor-face)  ; shell buff
        (".*[*]scratch[*].*"     . font-lock-function-name-face) ; scratch buffer
        ("^....[*].*"            . font-lock-string-face)        ; "*" named buffers
        ("^..[*].*"              . font-lock-constant-face)      ; Modified
        ("^.[%].*"               . font-lock-keyword-face)))     ; Read only

    (defun buffer-menu-custom-font-lock  ()
      (let ((font-lock-unfontify-region-function
             (lambda (start end)
               (remove-text-properties start end '(font-lock-face nil)))))
        (font-lock-unfontify-buffer)
        (set (make-local-variable 'font-lock-defaults)
             '(buffer-menu-buffer-font-lock-keywords t))
        (font-lock-fontify-buffer)))

    (add-hook 'buffer-menu-mode-hook 'buffer-menu-custom-font-lock)

Here is a graphic screen shot showing how the highlighting looks in Buffer menu.

[[image:BufferMenuHighlightingScreenshot0.png]]


As of Emacs version 24.3, this appears to not work anymore. -- MDL


If you use ElectricBufferList, then simply use this instead for the last line:

    (add-hook 'electric-buffer-menu-mode-hook 'buffer-menu-custom-font-lock)

See also: BufferMenuPlus, which provides similar highlighting, and more. You can customize the faces used without affecting the font-lock faces.

----
CategoryBufferSwitching
CategoryFaces
