Copy full path to file in Copy-Paste-Clipboard

I am looking for a way to save the current full name of the file I am working in to my copy-paste buffer so that I can switch to another program and paste, for example .. 'C: \ some \ path \ file.txt'

I tried the following method, but actually does nothing:

(defun clip-file () "Put the current file name on the clipboard" (interactive) (let ((filename (if (equal major-mode 'dired-mode) (file-name-directory default-directory) (buffer-file-name)))) (when filename (x-select-text filename)))) 

The x-select-text interprogram-cut-function comes from the interprogram-cut-function , which is mentioned in the Copy-shortcut Mw help file as a variable containing a function that is called to save the kill-ring for external programs, so the text can be copied from Emacs to, for example , Firefox.

I use Emacs on my Windows PC, and therefore not sure if x-select-text will work, since AFAIK has something to do with X-Server from Linux?

+6
source share
3 answers

The code mentioned in my question works, this is a problem with my .emacs file configuration, because I did not restart Emacs correctly.

Therefore use:

 (defun clip-file () "Put the current file name on the clipboard" (interactive) (let ((filename (if (equal major-mode 'dired-mode) (file-name-directory default-directory) (buffer-file-name)))) (when filename (x-select-text filename)))) 
+3
source
 (defun copy-buffer-file-name-as-kill (choice) "Copy the buffer-file-name to the kill-ring" (interactive "cCopy Buffer Name (F) Full, (D) Directory, (N) Name") (let ((new-kill-string) (name (if (eq major-mode 'dired-mode) (dired-get-filename) (or (buffer-file-name) "")))) (cond ((eq choice ?f) (setq new-kill-string name)) ((eq choice ?d) (setq new-kill-string (file-name-directory name))) ((eq choice ?n) (setq new-kill-string (file-name-nondirectory name))) (t (message "Quit"))) (when new-kill-string (message "%s copied" new-kill-string) (kill-new new-kill-string)))) 
+4
source

I came across this question when I was looking for how to copy file path to clipboard using Spacemacs. Therefore, for completeness and assistance to other people who may also find this question in their searches, please note that Spacemacs has this functionality already tied to:

SPC fy

0
source

Source: https://habr.com/ru/post/953861/


All Articles