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?
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.
You can if you shell out to something like xclip (Linux), pbcopy (Mac), putclip (Cygwin).
I personally use wrapper scripts
c
andp
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: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.C-x C-d
, also callable viaM-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.copy-buffer-file-name-as-kill
from [0] does exactly what you need I think. It also has the option to copy just directory name, or just file name.[0] http://www.emacswiki.org/emacs/download/buffer-extension.el
The direct implementation of what you want is:
That said, I find it incredibly useful to be able to get the full path of what is in the minibuffer, and this is what I use:
And then if I want it in the clipboard, I just kill the line (C-a C-k). But we could easily copy the truename to the clipboard in the above command, just change the last line to be:
The new part is the call to
'kill-new
which puts the string in the kill ring.C-x C-b
shows a list of buffers and the file path for each buffer where applicable.