Search code examples
emacselisp

how to show path to file in the Emacs mode-line?


In the mode-line appears the name of the buffer I am working with (argf.rb):

enter image description here

For a buffer visiting a file, is it possible to display the absolute file name (i.e., include the path)?


Solution

  • First, what you see is buffer name, not file name. Try to open two files with the same names (in different directories) and see what I mean.

    Second, yes, I am sure it is possible - just customize mode-line-format.

    Third, it might not be such a great idea - the mode line is already quite crowded and the long path will just not fit. I know it sounds great now, but you will hate it the next day.

    Instead, put the path into the title bar:

    (setq frame-title-format
          '(buffer-file-name "%b - %f" ; File buffer
            (dired-directory dired-directory ; Dired buffer
             (revert-buffer-function "%b" ; Buffer Menu
              ("%b - Dir: " default-directory))))) ; Plain buffer