Showing the current directory in Emacs’ mode line
May 23, 2008 – 3:28 pmToday 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))
4 Responses to “Showing the current directory in Emacs’ mode line”
But I am using vim. Please provide this patch for vim.
By ccm on May 29, 2008
You can always use viper-mode.
By admin on May 29, 2008
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)
By maf on Dec 24, 2008
In the mean time I found an even better solution using the uniquify library.
By admin on Mar 24, 2009