Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Emacs 将完整文件路径复制到复制粘贴剪贴板_Emacs_Clipboard - Fatal编程技术网

Emacs 将完整文件路径复制到复制粘贴剪贴板

Emacs 将完整文件路径复制到复制粘贴剪贴板,emacs,clipboard,Emacs,Clipboard,我正在寻找一种方法,将我正在处理的文件的当前完整文件名保存到我的复制粘贴缓冲区中,以便能够切换到另一个程序并粘贴,例如“C:\some\path\file.txt” 我尝试过以下方法,但实际上几乎没有效果: (defun clip-file () "Put the current file name on the clipboard" (interactive) (let ((filename (if (equal major-mode 'dired-mode)

我正在寻找一种方法,将我正在处理的文件的当前完整文件名保存到我的复制粘贴缓冲区中,以便能够切换到另一个程序并粘贴,例如“C:\some\path\file.txt”

我尝试过以下方法,但实际上几乎没有效果:

(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))))
函数x-select-text源自程序间剪切函数,该函数在复制快捷方式M-w的帮助文件中作为包含函数的变量提到,该函数被调用以保存外部程序的终止环,因此可以将文本从Emacs复制粘贴到例如Firefox


我在Windows PC上使用Emacs,因此不确定x-select-text是否有效,因为它可能与Linux上的x-Server有关?

我问题中提到的代码有效,这是我配置.Emacs文件的问题,因为我没有正确重新启动Emacs

(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))))
因此,请使用:

(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))))

在搜索如何使用SpaceMac将文件路径复制到剪贴板时,我偶然发现了这个问题。因此,为了完整性和帮助其他可能在搜索中发现此问题的人,请注意SpaceMac的此功能已绑定到:


SPC f y

我觉得你的代码很好。x-*仍然用于非x窗口内容。有时,他们会创建一个更通用的函数名,而不使用x-,从而清理问题。但在这种情况下,x-select-text就是其中之一,但它显然不适合我。它适合你吗?是的,它似乎适合我,任何Emacs版本20-24。例如,如果我在Emacs中使用它,然后在其他一些Windows应用程序中使用C-v。但是默认目录应该被扩展,使用扩展文件名默认目录,或者更好的方法是使用文件名目录默认目录,或者如果您不想要最终的/,则使用目录文件名目录默认目录。例如,如果不展开dir,可以得到~/foobar/。如果已经处于dired模式,则不需要它。w将复制文件名,c-u w将复制相对文件名,c-u 0 w将复制绝对文件名。好的,它现在可以工作了:my.emacs文件有问题这很好,但是,按照请求者的要求,将结果放入kill环而不是OS剪贴板。我尝试用x-select-text替换kill new,但在Aquaemacs GNU Emacs 23.4.1中不起作用。它与开发人员构建的Emacs Trunk build一样完美-在OSX Snow Leopard 10.6.8上使用ns-我可以将结果粘贴到任何应用程序中,如另一个文本编辑器等作品很棒!但我想知道是否有一种方法可以将它复制到emacs缓冲区中?它似乎被添加到我的操作系统的剪贴板,但没有添加到emacs剪贴板。通常,当我复制某些内容时,我可以将其粘贴到emacs缓冲区中。