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

前端 未结 12 454
醉梦人生
醉梦人生 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)))
    
    0 讨论(0)
  • 2020-12-12 12:36

    C-x C-d, also callable via M-x list-directory, will show you the directory for your current file, and you only need to hit the "Enter" key to clear the minibuffer. Additional details are available here.

    0 讨论(0)
  • 2020-12-12 12:38

    C-x C-b shows a list of buffers and the file path for each buffer where applicable.

    0 讨论(0)
  • 2020-12-12 12:39

    No need for extra function, just

    M-! pwd
    
    0 讨论(0)
  • 2020-12-12 12:43

    C-u C-x C-b lists buffers currently visiting files.

    0 讨论(0)
  • 2020-12-12 12:43

    Can I copy the path name to System(OS)'s clipboard, not the kill ring so that I can use the info with the other apps?

    You can if you shell out to something like xclip (Linux), pbcopy (Mac), putclip (Cygwin).

    I personally use wrapper scripts c and p for copy and paste respectively, the first reading from standard input, the latter writing to standard output. That way, this works on all my development platforms:

    (shell-command (format "echo '%s' | c" buffer-file-name))
    

    I find this more reliable and configurable than using the Emacs clipboard support. For example, my c command copies the input to all 3 clipboards on Linux (primary, secondary, clipboard), so I can paste with either Ctrl-V or middle click.

    0 讨论(0)
提交回复
热议问题