The function to show current file's full path

2019-01-29 20:46发布

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 getting that?
  • How can I copy the result (path name) to a clipboard so that I can reuse it?

I'm using Mac OS X and Aqumacs.

(setq filepath (get-fullpath-current-file)) ???
(copy-to-clipboard 'filepath) ???

ADDED

(defun show-file-name ()
  "Show the full path file name in the minibuffer."
  (interactive)
  (message (buffer-file-name))
  (kill-new (file-truename buffer-file-name))
)
(global-set-key "\C-cz" 'show-file-name)

Combining the two answers that I got, I could get what I want. Thanks for the answers. And some more questions.

  • What's for (file-truename)?
  • 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?

12条回答
你好瞎i
2楼-- · 2019-01-29 21:05

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

查看更多
姐就是有狂的资本
3楼-- · 2019-01-29 21:07

It's the built-in function buffer-file-name that gives you the full path of your file.

The best thing to do is to have your emacs window to always show your system-name and the full path of the buffer you're currently editing :

(setq frame-title-format
      (list (format "%s %%S: %%j " (system-name))
        '(buffer-file-name "%f" (dired-directory dired-directory "%b"))))

You can also do something like this :

(defun show-file-name ()
  "Show the full path file name in the minibuffer."
  (interactive)
  (message (buffer-file-name)))

(global-set-key [C-f1] 'show-file-name) ; Or any other key you want
查看更多
We Are One
4楼-- · 2019-01-29 21:08

To borrow from Jérôme Radix's answer, if you just want to quickly see the file path of the current buffer, you can do M-: buffer-file-name.

查看更多
来,给爷笑一个
5楼-- · 2019-01-29 21:09

The simplest way and would be

(buffer-name)<(C-x)(C-e)> for the file name to appear in the echo area

(buffer-name)<(C-u)(C-x)(C-e)> would print the location <here>

Borrowing from Trey Jackson I came up with this:

(defun buffer-kill-path ()
  "copy buffer's full path to kill ring"
  (interactive)
  (kill-new (buffer-file-name)))

You can find more information on site

查看更多
趁早两清
6楼-- · 2019-01-29 21:13

No need for extra function, just

M-! pwd
查看更多
小情绪 Triste *
7楼-- · 2019-01-29 21:20

My trick is to do a C-x C-f like to open a file, it wil prefill the minibuff with the current file path, C-g to quit. Faster than M-: buffer-file-name but far far uglier than any other methods.

查看更多
登录 后发表回答