3

I have Emacs display the full path of the file in my window title:

(setq-default frame-title-format '("%f [%m] - Emacs"))

And in my mode-line:

(setq-default mode-line-buffer-identification
              (list 'buffer-file-name
                    (propertized-buffer-identification "%12f")
                    (propertized-buffer-identification "%12b")))

But I would prefer it to not show my actual user name, how can I get this abbreviate standard unix path?

Drew
  • 75,699
  • 9
  • 109
  • 225
yPhil
  • 963
  • 5
  • 22

1 Answers1

5

Use function abbreviate-file-name. C-h f tells us:

abbreviate-file-name is a compiled Lisp function in files.el.

(abbreviate-file-name FILENAME)

Return a version of FILENAME shortened using directory-abbrev-alist.

This also substitutes ~ for the user's home directory (unless the home directory is a root directory) and removes automounter prefixes (see the variable automount-dir-prefix).

When this function is first called, it caches the user's home directory as a regexp in abbreviated-home-dir, and reuses it afterwards (so long as the home directory does not change; if you want to permanently change your home directory after having started Emacs, set abbreviated-home-dir to nil so it will be recalculated).

If you want to use that in frame-title-format and mode-line-format, try this:

(setq-default frame-title-format
              '((:eval (list (abbreviate-file-name
                               (expand-file-name buffer-file-name))
                             " [%m] - Emacs"))))

(setq-default mode-line-buffer-identification
              '((:eval (list (abbreviate-file-name
                               (expand-file-name buffer-file-name))))))
Drew
  • 75,699
  • 9
  • 109
  • 225
  • Ah, but it won't work either in the frame title or in the mode-line... But it actually answers the question, so I'll upvote, and maybe re-phrase the title? – yPhil Feb 25 '21 at 12:33
  • Updated. I didn't notice that you were actually asking two things. – Drew Feb 25 '21 at 17:10
  • You lose the "properties" (colors, but more seriously mouse interactions) but 1-I have a feeling we'll get there soon and 2-it *does* answer the question ; thanks! – yPhil Feb 25 '21 at 21:40