Copy full file path into Copy-Paste-Clipboard

Peter Wildemann

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?

Peter Wildemann

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to copy file path to clipboard?

From Dev

Copy file full path in Xcode

From Dev

Automatically save screenshot and copy file path to clipboard

From Java

Xcode Clipboard: Copy & Paste stuck

From Dev

Copy and Paste from Clipboard to URxvt

From Dev

Java Clipboard for cut/copy/paste

From Dev

Copy from clipboard and paste into a userform

From Dev

How do I copy a file to the clipboard and paste it somewhere else?

From Dev

Copy file to clipboard in Delphi

From Dev

how to copy the current file full name to global clipboard in vim

From Dev

Command-line utility to copy file to clipboard from file path

From Dev

How can I copy the path to the currently opened file in gedit to the clipboard?

From Dev

How to copy and paste a file?

From Dev

How to copy and paste a file?

From Dev

Copy / paste text selections between tmux and the clipboard

From Dev

service to clear clipboard in android to prevent copy paste

From Dev

Copy+Paste DataGridViewSelectedCellCollection to/from Clipboard

From Dev

A command-line clipboard copy and paste utility?

From Dev

JTable copy and paste using Clipboard and AbstractAction

From Dev

Clipboard Copy / Paste on Content script (Chrome Extension)

From Dev

Copy / paste text selections between tmux and the clipboard

From Dev

A command-line clipboard copy and paste utility?

From Dev

Copy+Paste DataGridViewSelectedCellCollection to/from Clipboard

From Dev

Ditto clipboard manager for multiple copy and paste

From Dev

Solve the multiple copy and paste clipboard problem

From Dev

Copy content of HTM file into clipboard

From Dev

Copy image from clipboard to file

From Dev

Vim: copy from file to clipboard

From Dev

Copy content of HTM file into clipboard

Related Related

  1. 1

    How to copy file path to clipboard?

  2. 2

    Copy file full path in Xcode

  3. 3

    Automatically save screenshot and copy file path to clipboard

  4. 4

    Xcode Clipboard: Copy & Paste stuck

  5. 5

    Copy and Paste from Clipboard to URxvt

  6. 6

    Java Clipboard for cut/copy/paste

  7. 7

    Copy from clipboard and paste into a userform

  8. 8

    How do I copy a file to the clipboard and paste it somewhere else?

  9. 9

    Copy file to clipboard in Delphi

  10. 10

    how to copy the current file full name to global clipboard in vim

  11. 11

    Command-line utility to copy file to clipboard from file path

  12. 12

    How can I copy the path to the currently opened file in gedit to the clipboard?

  13. 13

    How to copy and paste a file?

  14. 14

    How to copy and paste a file?

  15. 15

    Copy / paste text selections between tmux and the clipboard

  16. 16

    service to clear clipboard in android to prevent copy paste

  17. 17

    Copy+Paste DataGridViewSelectedCellCollection to/from Clipboard

  18. 18

    A command-line clipboard copy and paste utility?

  19. 19

    JTable copy and paste using Clipboard and AbstractAction

  20. 20

    Clipboard Copy / Paste on Content script (Chrome Extension)

  21. 21

    Copy / paste text selections between tmux and the clipboard

  22. 22

    A command-line clipboard copy and paste utility?

  23. 23

    Copy+Paste DataGridViewSelectedCellCollection to/from Clipboard

  24. 24

    Ditto clipboard manager for multiple copy and paste

  25. 25

    Solve the multiple copy and paste clipboard problem

  26. 26

    Copy content of HTM file into clipboard

  27. 27

    Copy image from clipboard to file

  28. 28

    Vim: copy from file to clipboard

  29. 29

    Copy content of HTM file into clipboard

HotTag

Archive