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?
3 Answers
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
-
11
-
4
-
-
@yPhil
(custom-set-variables '(setq-default frame-title-format '("%f [%m]")))
? Commented Jan 7, 2021 at 14:08 -
%m
is now deprecated in favor of the variablemode-name
. See %-Constructs in the Mode Line Commented Feb 21, 2023 at 15:35
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]")))))
Additionally you can also indicate if there any unsaved changes using the below code (as mentioned here):
(setq frame-title-format
'((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))
(:eval (if (buffer-modified-p)
" •"))
" Emacs")
)
Note that this doesn't work for Spacemacs. Below is the config for spacemacs which you need to add in dotspacemacs/init
(as mentioned here)
Spacemacs documentation: https://develop.spacemacs.org/doc/DOCUMENTATION.html#title
dotspacemacs-frame-title-format "%b - Spacemacs"
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".