In my config file, how do I set the frame title so that it shows:

  1. The buffer name
  2. If a file buffer, show the path to the file without the filename

So something like this:

.emacs.el -- D:\Dropbox\dotfiles


Does something like this give the name you want:

(set-frame-name (format "%s%s" (buffer-name)
            (if-let (fn (buffer-file-name))
                (format " -- %s" (file-name-directory fn))

If you use an older emacs (less than v25) try:

(set-frame-name (format "%s%s"
            (let ((bfn (buffer-file-name)))
              (if bfn
                  (format " -- %s" (file-name-directory bfn))

If it does maybe you can add it to a hook function to run it, e.g. when you open a file or something.

  • That gives me an error: Symbol's function definition is void: if-let – Simon May 6 '17 at 23:00
  • I guess you use an older emacs? I added another version for an older one. – John Kitchin May 7 '17 at 12:23

This is what I do in my init

(setq-default frame-title-format
          '(("" invocation-name "@" system-name "\t")
            (buffer-file-name "%f" "%b")))

Basically it handles a buffer for a file or a special buffer. As for the format of the file path, you could play around with buffer-file-name.

  • The part that I'm having trouble with is getting the path without the filename, and only including -- if a its a file buffer. So I need to find a way to remove the filename from %f, and only show -- if %f exists – Simon May 5 '17 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.