1

I've been recently experimenting with having the tooltips for the buffer on the mode line show the full file path via:

;; try switching buffer name tooltip in the mode line to actually be the full buffer name
(setq-default mode-line-buffer-identification
              (list (propertize
                     "%12b"
                     'face 'mode-line-buffer-id
                     'help-echo
                     '(format "%s\nmouse-1: Previous buffer\nmouse-3: Next buffer" (buffer-name))
                     'mouse-face 'mode-line-highlight
                     'local-map mode-line-buffer-identification-keymap)))

That works as expected for a single window or the windows are horizontally split:

enter image description here

But when the frame is split vertically it reverts back to the default behavior and the hint just says "buffer name"

c

Does anyone know what's going on and how to get the behavior I want?

4
  • What Emacs version? Do you see the same thing with emacs -Q (no init file)? With Emacs 19.1 I see only Buffer name in all cases.
    – Drew
    Commented Feb 5 at 23:16
  • This is emacs 29.1
    – benleis
    Commented Feb 5 at 23:36
  • That's a good point I am using the doom mode line as well (but not the rest of doom emacs). With vanilla config it works more normally. I'll go turn off the doom mode line and see what happens. Update: yes its related to doom mode line
    – benleis
    Commented Feb 5 at 23:40
  • Scratch that - on further testing with vanilla config - the tooltips are always showing the buffer name for the selected buffer ie they both are the same. So not the "buffer name" issue that I saw originally but still not the behavior I want
    – benleis
    Commented Feb 6 at 0:10

1 Answer 1

1

the tooltips are always showing the buffer name for the selected buffer

Indeed -- after all, you're just calling (buffer-name).

I think you're after something like this?

(defun my-buffer-identification-at-mouse-position ()
  "The buffer file name at `mouse-pixel-position'."
  (or (cl-destructuring-bind (frame x . y)
          (mouse-pixel-position)
        (let ((win (window-at-x-y x y frame)))
          (when (and win (window-live-p win))
            (with-selected-window win
              (or (buffer-file-name)
                  dired-directory
                  (buffer-name))))))
      "<unknown>"))

(setq-default mode-line-buffer-identification
              (list (propertize
                     "%12b"
                     'face 'mode-line-buffer-id
                     'help-echo
                     '(format "%s\nmouse-1: Previous buffer\nmouse-3: Next buffer"
                              (my-buffer-identification-at-mouse-position))
                     'mouse-face 'mode-line-highlight
                     'local-map mode-line-buffer-identification-keymap)))

N.b. The dired-directory value doesn't help immediately, as dired is one of the numerous things which sets its own mode-line-buffer-identification, but you could override that if you wanted to.

1
  • I'll give that a try - I came up with a simpler solution that also works. Rather than trying to do something dynamic I started allocating individual mode lines per buffer and assigning a static tool tip with the filename to them. Since I mostly want to do this in ediff mode - that's workable
    – benleis
    Commented Feb 6 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.