Library frame-cmds.el contains two commands for renaming frames:
‘rename-frame’ - Rename a frame named OLD-NAME to NEW-NAME. ALL-NAMED non-‘nil’ means rename all frames named FRAME to NEWNAME.OLD-NAME can be a frame, its name, or ‘nil’. Default is ‘selected-frame’.NEW-NAME is a string or ‘nil’. Default NEW-NAME is current ‘buffer-name’.‘rename-non-minibuffer-frame’ - Unless OLD-NAME names the ‘minibuffer-frame’, use ‘rename-frame’ to rename a frame named OLD-NAME to NEW-NAME. ALL-NAMED non-‘nil’ means rename all frames named FRAME to NEWNAME.OLD-NAME can be a frame, its name, or ‘nil’. Default is ‘selected-frame’.NEW-NAME is a string or ‘nil’. Default NEW-NAME is current ‘buffer-name’.The frame title is changed by changing the value of the variable ‘frame-title-format’. Likewise, the icon title can be changed with ‘icon-title-format’. They recognize the same special characters as variable ‘mode-line-format’:
A string is printed verbatim in the mode line except for %-constructs:
(%-constructs are allowed when the string is the entire mode-line-format
or when it is found in a cons-cell or a list)
%b -- print buffer name. %f -- print visited file name.
%F -- print frame name.
%* -- print %, * or hyphen. %+ -- print *, % or hyphen.
%& is like %*, but ignore read-only-ness.
% means buffer is read-only and * means it is modified.
For a modified read-only buffer, %* gives % and %+ gives *.
%s -- print process status. %l -- print the current line number.
%c -- print the current column number (this makes editing slower).
To make the column number update correctly in all cases,
`column-number-mode' must be non-nil.
%p -- print percent of buffer above top of window, or Top, Bot or All.
%P -- print percent of buffer above bottom of window, perhaps plus Top,
or print Bottom or All.
%m -- print the mode name.
%n -- print Narrow if appropriate.
%z -- print mnemonics of buffer, terminal, and keyboard coding systems.
%Z -- like %z, but including the end-of-line format.
%[ -- print one [ for each recursive editing level. %] similar.
%% -- print %. %- -- print infinitely many dashes.
Decimal digits after the % specify field width to which to pad.Note that most of the following examples use lists but string values are also valid.
(setq frame-title-format '("" "%b @ Emacs " emacs-version))
(setq frame-title-format '("" "[%b] - Emacs " emacs-version))
(setq frame-title-format (list "%b - " (getenv "USERNAME") "@" (getenv "USERDOMAIN"))) ;;list is needed here, could someone explain ?
;; list is needed in the last example to flatten the sub-lists, otherwise a quote is sufficientAnother example to use in an init file, used on e.g. Ubuntu where USERDOMAIN doesn’t exist, and the environment variable HOSTNAME isn’t exported by default (as can be seen by running “export -p” at a login shell), and we want to get the host name by running the POSIX ‘hostname(1)’ command only once, at startup.
(setq my-hostname
(replace-regexp-in-string "\\(^[[:space:]\n]*\\|[[:space:]\n]*$\\)" "" ;; like perl chomp()
(with-output-to-string
(call-process "/bin/hostname" nil standard-output nil))))
(setq my-username (getenv "USERNAME"))
(setq frame-title-format '("%b - " my-username "@" my-hostname))(setq frame-title-format (list "%f - " (getenv "USER") "@" (getenv "HOSTNAME")))
(setq frame-title-format `(,(user-login-name) "@" ,(system-name) " " global-mode-string " %f" ))
And if you’re an ErcChannelTracking fan, take a look at
(setq frame-title-format '("" erc-modified-channels-object "%b @ Emacs " emacs-version))To set both frame and icon title to the same thing, which also tells if you are using GnuEmacs or XEmacs:
(setq frame-title-format
(setq icon-title-format
(format "%%b - %semacs" (if (featurep 'xemacs) "x" ""))))Display date/time if ‘display-time-mode’ is set:
(setq frame-title-format '("" invocation-name "@" system-name " "
global-mode-string " %f" ))
;; See also: `display-time-format' and `mode-line-format'Feel free to add your titles here!
By Kelvin Hu:
Hi guys, I find a almost perfect format, as below:
(setq frame-title-format
'("%S" (buffer-file-name "%f"
(dired-directory dired-directory "%b"))))It is really a good format, I tried it and finally I have a new version as below:
(setq frame-title-format
'(buffer-file-name
"%f"
(dired-directory dired-directory "%b")))or
(setq frame-title-format
'("%f" (dired-directory dired-directory "%b")))but I still do not know how they work (don’t let me google, I have googled a lot), so could any one please explain it? Thanks very much.
See the Elisp manual, here: Frame Titles. It refers you to Mode Line Data for the details. How did I find that in the manual? ‘i’ (‘Info-index’) in a manual is your friend. – DrewAdams
From `mode-line-format`:
The value may be nil, a string, a symbol or a list. ... A list whose car is a string or list is processed by processing each of the list elements recursively, as separate mode line constructs, and concatenating the results. ... A list whose car is a symbol is processed by examining the symbol's value, and, if that value is non-nil, processing the cadr of the list recursively; and if that value is nil, processing the caddr of the list recursively.
targzeta
When running Emacs inside of xterm (e.g. with emacs -nw), it is possible to mostly mimic the behavior of frame/icon titles. To do so, you will need a copy of xterm-title.el, xterm-frobs.el, and the following snippet for your .emacs:
(when (and (not window-system)
(string-match "^xterm" (getenv "TERM")))
(require 'xterm-title)
(xterm-title-mode 1))Then modify the frame/icon frame title variables as you would in a window system.
By avar:
My Emacs insists that I have a “dumb” terminal. Even under xterm. This works for me:
(when (and
(not window-system)
(or
(string= (getenv "TERM") "dumb")
(string-match "^xterm" (getenv "TERM"))))
(require 'xterm-title)
(xterm-title-mode 1))By PaulGoins:
My Emacs (emacs-snapshot on Ubuntu, version 1:20090730-1~intrepid1) says TERM is “dumb” after fully loading, but while loading .emacs it does show the right thing (rxvt-unicode, in my case). “Your mileage may vary”, I suppose.
(Note: xterm-title-mode does not seem to work with urxvt. It does work fine with other xterm-compatibles like gnome-terminal.)
By wisnij:
I wasn’t able to get xterm-title working with my Cygwin xterm for some reason. As a stopgap, using xterm-frobs directly seems to work well enough:
(if (and (not window-system)
(string-match "^xterm" (getenv "TERM")))
(progn
(require 'xterm-frobs)
(defun my-xterm-title-hook ()
(xterm-set-window-title
(concat
(cond (buffer-read-only "% ")
((buffer-modified-p) "* "))
(buffer-name)
" (" invocation-name "@" system-name ")")))
(add-hook 'post-command-hook 'my-xterm-title-hook))
(setq frame-title-format
'(""
(:eval (cond (buffer-read-only "%% ")
((buffer-modified-p) "* ")))
"%b (" invocation-name "@" system-name ")")))By CraigMcDaniel:
As an alternative to using xterm-title.el/xterm-frobs.el, send your own escape codes to the terminal. I’m running iTerm2 so this example sets the window title to the full file name and the tab title to the shorter buffer name:
defun xterm-title-update ()
(interactive)
(send-string-to-terminal (concat "\033]1; " (buffer-name) "\007"))
(if buffer-file-name
(send-string-to-terminal (concat "\033]2; " (buffer-file-name) "\007"))
(send-string-to-terminal (concat "\033]2; " (buffer-name) "\007"))))
(add-hook 'post-command-hook 'xterm-title-update)