I am developing an Emacs package that applies when Emacs is used as a server. It should set the frame title when activated, and also when receiving certain commands from Emacsclient.
The package adds the current project name and the buffer file name to the frame title. The problem is that using set-frame-parameter
does not allow the frame title to vary with the current buffer name. So I decided to try setting frame-title-format
instead, but then the title is not updated before a new frame is opened, or I change to another buffer in the current frame. For example:
(defvar my-project-name "project A")
(defun my-set-title ()
(let ((name
(if buffer-file-name
(buffer-file-name)
(buffer-name))))
(concat my-project-name " : " name)))
(setq frame-title-format '(:eval (my-set-title)))
Now, in order to update the frame title to reflect a new project name, I used:
(setq my-project-name "project B")
(set-frame-parameter nil 'title "dummy")
(set-frame-parameter nil 'title nil)
The reason for first setting the title to a dummy value and then resetting it to nil
is to also update the title for the current buffer in the current frame immediately. But I could not find this trick in the documentation, so is this going to work in general?