I want to set the title of emacs to be the mode-line when ever it changes.
As pointed to by the answer below,
(setq frame-title-format mode-line-format) solved things elegantly.
Original question bits:
I can set the emacs title via:
(set-frame-parameter nil 'title (concat "*GNU EMACS* " (format-mode-line mode-line-format)))
For this, I would like to hook into the mode-line. But does it have a hook? How could I find out if it has a change-hook?
At present, I use a timer that updates it every 5 seconds, but this is not so elegant.
;-- Timer to update title of emacs during a pomodoro. (defun my/pomodoro-start-title-update-timer () (interactive) (setq pomodoro-title-update-timer (run-at-time (current-time) 5 'my/set-title-to-mode-line))) ;-- I don't use the below, but useful: (defun my/kill-pomodoro-timer () (interactive) (cancel-timer pomodoro-title-update-timer ) ) (defun my/set-title-to-mode-line () "Sets the title of the emacs window to the mode line. Used by pomodoro timer." (interactive) (set-frame-parameter nil 'title (concat "*GNU EMACS* " (format-mode-line mode-line-format))) ) ;-- Start the timer. TODO: change this to be a hook for when the mode-line changes. (my/pomodoro-start-title-update-timer)
I have tried adding a hook to
post-command-hook like so:
(add-hook 'post-command-hook (lambda () 'my/set-title-to-mode-line ))
But this only updates the the title if I change between buffers. The ticking of the pomodoro [Pomodoro~22:56] -> [Pomodoro~22:55] etc.. doesn't actually trigger this hook. So I can use the above for general purpose, and a timer for when pomodoro is active at present.