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

2

9

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)?

Dorene answered 23/4, 2015 at 7:17 Comment(1)
Here's the actual answer to the question asked: emacs.stackexchange.com/a/63584/36074Franck
B
11

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
Bonnes answered 23/4, 2015 at 11:0 Comment(3)
I would also recommend enabling uniquify, which updates the buffer name in sane ways when you're visiting multiple files with the same name.Finding
Is there a function I can use to show it in the mini buffer?Sybilsybila
@PeterPrevos: M-: buffer-file-name RETBonnes
R
1

What I do is to create a bind to show the file name in the minibuffer

(global-set-key (kbd "C-c C-f C-n") (lambda () (interactive) (message (buffer-file-name))))

Maybe there is already a feature for that that I don't know

Reichard answered 14/3, 2023 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.