nex3 / perspective-el

Perspectives for Emacs.
MIT License
880 stars 71 forks source link

Display perspective in frame title #192

Open sellout opened 1 year ago

sellout commented 1 year ago

Since there is one (or merged) active perspective in a frame, displaying it in the title makes more sense than in the mode-line or header. So, suggesting another possible value for persp-show-modestring: 'frame-title.

There’s no global-frame-title to append it to, but searching frame-title-format for "%b" and adding an entry just before it, (like ((:edit (persp-mode-line)) "%b") in the simplest case) might do it.

As an added bonus, when I go to share a window with Google Meet, it can be hard to find the right window to select (they are all just random buffer names), so having the perspective for that frame in the title would be very helpful.

sellout commented 1 year ago

Ah, since it doesn’t propertize text in the title, you probably also want to always treat persp-modestring-short as t if persp-show-modestring is 'frame-title. I use the short form anyway, so I didn’t notice initially.

sellout commented 1 year ago

Ok, my quick experiment is not so successful – it sets the title for all frames to whatever perspective the selected frame is in. But I’m sure there’s a way around that …

cmm commented 11 months ago

FWIW this seems to work for me:

(setq frame-title-format '("%b" (:eval (when-let ((persp (frame-parameter nil 'persp--curr))) (format " [%s]" (persp-name persp))))))

(but of course relying on non-public things is not ideal)

sellout commented 11 months ago

Thanks, @cmm, that looks like it works for me. I extracted it into a function:

(defun persp-frame-title ()
  (when-let ((persp (frame-parameter nil 'persp--curr)))
    (let ((open (nth 0 persp-modestring-dividers))
          (close (nth 1 persp-modestring-dividers)))
      (concat open persp close))))

(setq frame-title-format '((:eval (persp-frame-title)) " %b"))

It matches the existing rendering (e.g., using persp-modestring-dividers), but always treats it as the short modestring, since there’s no propertization in the frame title.

gcv commented 11 months ago

@sellout: Have you tried using (persp-current-name) in place of (frame-parameter nil 'persp--curr)?

I would merge in a PR that added persp-frame-title and included documentation about how to use it.

sellout commented 11 months ago

@sellout: Have you tried using (persp-current-name) in place of (frame-parameter nil 'persp--curr)?

I hadn’t. It looks like

(defun persp-frame-title ()
  (let ((open (nth 0 persp-modestring-dividers))
        (close (nth 1 persp-modestring-dividers)))
    (concat open (persp-current-name) close)))

works just as well.

I would merge in a PR that added persp-frame-title and included documentation about how to use it.

I think for a PR, adding (const :tag "Frame Title" frame-title) to persp-show-modestring would be the way to go. I’m happy to submit one (with @cmm tagged as co-author), unless @cmm would like to submit one themselves.

cmm commented 11 months ago

@sellout happy to have helped (I guess, not really sure?), feel free to go ahead :)