1

I have a header-line that displays currently opened file name on top of the buffer window. I can't find a way to copy the text/file name from that header-line if emacs runs under X/gui (selecting with a mouse and coping it works fine under terminal). Does anyone have any suggestions? (Perhaps there is a way to trigger an event by clicking on header-line so that could store file name so I could paste it into the terminal via mouse click as I usually do in -nw?)

enter image description here

TerryTsao
  • 1,176
  • 4
  • 18
pawciobiel
  • 13
  • 4
  • It may also be possible to define a key for mouse-3 press on [header-line mouse-3] event https://emacs.stackexchange.com/questions/47211/local-map-in-header-line – pawciobiel Jul 07 '22 at 21:38
  • https://emacs.stackexchange.com/tags/elisp/info – Drew Jul 11 '22 at 14:24

1 Answers1

1

To get this

Filename in header-line

and this

Clicking on header-line copies it to kill-ring

do this


(add-hook
 'find-file-hook
 (defun my-find-file-hook ()
   (add-to-list
    'header-line-format
    '(:eval
      (let ((text (buffer-file-name)))
        (when text
          (buttonize
           text
           (lambda (text)
             (message "Copied `%s' to kill ring" text)
             (kill-new text))
           text
           "Click me, to copy me")))))))