1

I want to set the frame title as follows:

  • When the current buffer is visiting a file, show the full path name and the Emacs version.
  • When the current buffer has no file, then show the buffer name and the Emacs version.

In my init.el, I put

(setq-default frame-title-format
  (concat (if (buffer-file-name) "%f" "%b") " - " (substring (emacs-version) 0 15)))

But here is the result:screenshot with the title containing a file name without the full path

Why doesn't my code print the file name with the full path?

3

Because you're setting frame-title-format to "%b - GNU Emacs 26.1 ".

You can try the following instead

(setq frame-title-format
      `((buffer-file-name "%f" "%b")
        ,(format " - GNU Emacs %s" emacs-version)))

The following does the same but it probably does some unneeded work (that is, computing the version string) repeatedly

(setq frame-title-format
      (list '(buffer-file-name "%f" "%b")
            '(:eval (format " - GNU Emacs %s" emacs-version))))
  • It's work. Nice. But what is different between (format " - GNU Emacs %s" emacs-version)) and '(:eval (format " - GNU Emacs %s" emacs-version)) ? – a_subscriber Nov 15 '18 at 14:22
  • FYI, OP: @rpluim answered the question in your comment. – Drew Nov 15 '18 at 14:35
  • @xuchunyang I'd forgotten about the (symbol then else) form for mode-line-format, nice one. – rpluim Nov 15 '18 at 15:31
  • 2
    @Alexei The value of (format " - GNU Emacs %s" emacs-version) is a constant and is known when Emacs starts. If you use '(:eval (format ...)), Emacs will compute it whenever the frame title needs to be updated, which is unnecessary. – xuchunyang Nov 15 '18 at 17:26
1

Emacs is evaluating your expression at the time when you setq frame-title-format, whereas you want it to be evaluated dynamically. Try wrapping your code in :eval as explained at Mode-Line-Data

  • I need when create/open buffer to evaluate on fly is this is a buffer with or not file. Is it possible? – a_subscriber Nov 15 '18 at 13:37

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.