Function to display the current full file path in the mini-buffer

I need to get the full path to the file that I am editing with emacs.

  • Is there a function for this?
  • If not, what would the elisp function be to get this?
  • How to copy the result (path) to the clipboard so that I can reuse it?

I use 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)

By combining the two answers that I received, I could get what I want. Thanks for answers. And a few more questions.

  • What for (file-truename)?
  • Can I copy the path name to the System (OS) clipboard and not to the kill ring so that I can use the information with other applications?
+76
clipboard emacs elisp aquamacs
Sep 08 '10 at 15:49
source share
11 answers

This is the built-in buffer-file-name function, which gives you the full path to your file.

It’s best to have your emacs window always display your system name and the full path to the buffer you are 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 
+74
Sep 08 '10 at 16:04
source share

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

+48
Jul 02 '13 at 0:14
source share

My trick is to make Cx Cf to open the file, it will launch a mini-tube with the current file path, Cg , to exit. Faster than M-: buffer-file-name , but much more ugly than any other methods.

+29
Oct 24 '13 at 8:22
source share

Direct implementation of what you want:

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

However, I find it incredibly useful to be able to get the full path to what is in the minibuffer, and this is what I use:

 (define-key minibuffer-local-completion-map "\Cr" 'resolve-sym-link) (defun resolve-sym-link () "Try to resolve symbolic links into true paths." (interactive) (beginning-of-line) (let* ((file (buffer-substring (point) (save-excursion (end-of-line) (point)))) (file-dir (file-name-directory file)) (file-true-dir (file-truename file-dir)) (file-name (file-name-nondirectory file))) (delete-region (point) (save-excursion (end-of-line) (point))) (insert (concat file-true-dir file-name)))) 

And if I want it on the clipboard, I just kill the string ( Ca Ck ). But we could easily copy the name truename to the clipboard in the above command, just change the last line:

 (insert (kill-new (concat file-true-dir file-name))))) 

The new part is a call to 'kill-new , which places the string in the kill ring.

+14
Sep 08 '10 at 15:59
source share

I have the following code that has been used for a long time. It copies the full path to the kill ring when I click the middle mouse button on the buffer name in the mode line. It only copies the buffer name in 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))) 
+3
Oct 29 '14 at 12:09 on
source share

No need for extra features, just

 M-! pwd 
+2
Jan 21 '17 at 2:23 on
source share

Can I copy the path name to the System (OS) clipboard and not to the kill ring so that I can use the information with other applications?

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

I personally use the shell scripts c and p to copy and paste, respectively, the first reading from standard input, the last is written to standard output. Thus, this works on all my development platforms:

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

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

+1
Nov 07 '13 at 11:50
source share

Cx Cb shows a list of buffers and a file path for each buffer, where applicable.

+1
Feb 10 '16 at 22:31
source share

Cx Cd , also called via the Mx list-directory , will show you the directory for your current file, and you only need to press the Enter key to clear the minibuffer. Further details are available here .

+1
Dec 19 '16 at 19:03
source share

The easiest way will be

 (buffer-name)<(Cx)(Ce)> for the file name to appear in the echo area (buffer-name)<(Cu)(Cx)(Ce)> would print the location <here> 

Borrowing from Trey Jackson I came up with this:

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

Additional information can be found on the website.

0
Feb 08 '15 at 18:06
source share

copy-buffer-file-name-as-kill from [0] does exactly what you need, I think. It also has the ability to copy only the directory name or just the file name.

[0] http://www.emacswiki.org/emacs/download/buffer-extension.el

0
Aug 20 '15 at 10:50
source share



All Articles