28

I am using Emacs 24.5.1 on OpenSUSE Tumbleweed, with Gnome 3.16, and the title of the GTK window with Emacs in it is always emacs@hostname. How can I change it to the name of the current file I'm editing?

4
  • Why do you need this? I'm curious for your use case. The file name is already shown in the mode line, isn't it? Sep 22, 2015 at 21:25
  • Gnome in Overview mode has the window title in big text below the window thumbnail, the one in the mode line is too small to see.
    – Sean
    Sep 23, 2015 at 13:32
  • 1
    Just a side remark: If you have several frames open - for example if you open a file in another frame with C-x 5 f - then each frame will show the buffer name as title. It's only when you have just a single frame that you see "emacs@hostname".
    – pst
    Aug 24, 2020 at 10:55
  • @Dieter.Wilhelm The title bar can show the buffer name and mode of the minibuffer, which the mode line doesn't display. Jan 30, 2021 at 11:50

2 Answers 2

38

The file name as frame name

    (setq-default frame-title-format '("%f"))

The file name and the major mode as frame name (my conf)

    (setq-default frame-title-format '("%f [" mode-name "]"))

See

5
  • 11
    Use %b to get the filename without the path
    – Adversus
    Jun 12, 2017 at 7:24
  • 4
    '%b' is also better for unsaved buffers, like "scratch"
    – teroi
    May 16, 2018 at 8:29
  • Does somebody know how to set it in custom-set-variables?
    – yPhil
    Jan 6, 2021 at 22:50
  • @yPhil (custom-set-variables '(setq-default frame-title-format '("%f [%m]"))) ?
    – djangoliv
    Jan 7, 2021 at 14:08
  • %m is now deprecated in favor of the variable mode-name. See %-Constructs in the Mode Line Feb 21, 2023 at 15:35
9

Make emacs' window title show path of the current file:

(setq-default frame-title-format
              '(:eval
                (format "%s@%s: %s %s"
                        (or (file-remote-p default-directory 'user)
                            user-real-login-name)
                        (or (file-remote-p default-directory 'host)
                            system-name)
                        (buffer-name)
                        (cond
                         (buffer-file-truename
                          (concat "(" buffer-file-truename ")"))
                         (dired-directory
                          (concat "{" dired-directory "}"))
                         (t
                          "[no file]")))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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