2

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?

3

In general way, force-mode-line-update is used for frame title updating.

(setq my-project-name "project B")
(force-mode-line-update)
1

This might not do what you want in all circumstances, but perhaps it will help.

I tell Emacs to rename the frame whenever it gets iconified (or thumbified). I use the frame name - frame parameter name instead of frame parameter title.

I bind keys for iconifying (or thumbifying) frames to commands that rename the frame before iconifying it.

For my purposes, this is enough. For your purposes, it might not be.

Note that if a frame has more than one window, selecting a different window does not automatically change the frame name, with this setup. That's the behavior I prefer.

If/when I do want the frame name to reflect a different window (the one currently selected) then I hit C-z twice to iconify/restore the frame so it gets renamed. You could of course just bind rename-frame to a key or whatever, to do the same thing directly.

The functions (commands) for doing this, and for renaming frames (e.g. rename-frame), are in library frame-cmds.el.

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.