emacs

Showing the current directory in Emacs’ mode line

Today I got tired of always looking up, where all these little files named “_show.rhtml”, “_list.rhtml” and their ilk are living, and patched the emacs mode line to include the last element of the current buffer’s directory. http://www.emacswiki.org/cgi-bin/wiki/ModeLineDirtrack describes something very similar, but it repeats the whole mode line definition of mode-line-format, which might break with the next version of Emacs. It’s much cleaner to add to a variable that is used in the mode line:

(setq-default mode-line-buffer-identification
              (cons
               '(:eval (replace-regexp-in-string "^.*/\\(.*\\)/" "\\1/" default-directory))
               mode-line-buffer-identification))

5 Comments

  1. My combined solution to keep propertization and restrict directory name to file buffers:

    (defun find-file-mode-line ()
    (setq mode-line-buffer-identification
    ‘(:eval (propertized-buffer-identification
    (concat (replace-regexp-in-string “^.*/\\(.*\\)/” “\\1/” default-directory) “%12b”)))))
    (add-hook ‘find-file-hook ‘find-file-mode-line)

  2. In the mean time I found an even better solution using the uniquify library.

    (require 'uniquify)
     
    (setq uniquify-buffer-name-style 'reverse)
    (setq uniquify-separator "|")
    (setq uniquify-after-kill-buffer-p t)
    (setq uniquify-ignore-buffers-re "^*")
  3. Thanks for your ‘uniquify’ suggestion. This is the best improvement since I learned about ido-mode.

Leave a Reply

Your email address will not be published. Required fields are marked *