I am looking for a method to save the current full filename of the file I'm working on into my copy-paste buffer to be able to switch to another program and paste e.g. 'C:\some\path\file.txt'.
I have tried the following method but it actually does pretty much 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 function x-select-text
originates from interprogram-cut-function
, which is mentioned in the help file of the Copy-shortcut M-w
as a variable containing a function, that is called to save the kill-ring for external programs, so the text may be copy-pasted from Emacs to e.g. Firefox.
I'm using Emacs on my Windows-PC and am therefore not sure, if x-select-text
would work, since AFAIK it has something to do with the X-Server from Linux?
The code mentioned in my question works, it was a problem with my configuration of .emacs-file, because I didn't restart Emacs properly.
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))))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments