The function to show current file's full path in mini buffer

前端 未结 12 487
醉梦人生
醉梦人生 2020-12-12 11:58

I need to get the full path of the file that I\'m editing with emacs.

  • Is there a function for that?
  • If not, what would be the elisp function for getti
12条回答
  •  旧巷少年郎
    2020-12-12 12:36

    I have the following code already in use for a long time. It copies the full file path to the kill ring when I press the middle mouse button on the buffer name in the mode-line. It copies just the buffer name to the kill-ring when I press shift-mouse-2 on the buffer-name in the mode-line.

    (defun copy-buffer-file-name (event &optional bufName)
      "Copy buffer file name to kill ring.
    If no file is associated with buffer just get buffer name.
    "
      (interactive "eP")
      (save-selected-window
        (message "bufName: %S" bufName)
        (select-window (posn-window (event-start event)))
        (let ((name (or (unless bufName (buffer-file-name)) (buffer-name))))
          (message "Saved file name \"%s\" in killring." name)
          (kill-new name)
          name)))
    
    (define-key mode-line-buffer-identification-keymap [mode-line mouse-2] 'copy-buffer-file-name)
    (define-key mode-line-buffer-identification-keymap [mode-line S-mouse-2] '(lambda (e) (interactive "e") (copy-buffer-file-name e 't)))
    

提交回复
热议问题