显示当前文件在迷你缓冲区中的完整路径的功能
我需要获取正在使用 emacs 编辑的文件的完整路径。
- 有这样的功能吗?
- 如果没有,那么 elisp 函数可以得到什么?
- 如何将结果(路径名)复制到剪贴板以便我可以重复使用它?
我使用的是 Mac OS X 和 Aqumacs。
(setq filepath (get-fullpath-current-file)) ???
(copy-to-clipboard 'filepath) ???
添加
(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)
结合我得到的两个答案,我可以得到我想要的。感谢您的回答。还有一些问题。
- (文件真实名称)有什么用?
- 我可以将路径名复制到系统(操作系统)的剪贴板,而不是杀环,以便我可以在其他应用程序中使用该信息吗?
I need to get the full path of the file that I'm editing with emacs.
- Is there a function for that?
- If not, what would be the elisp function for getting that?
- How can I copy the result (path name) to a clipboard so that I can reuse it?
I'm using 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)
Combining the two answers that I got, I could get what I want. Thanks for the answers. And some more questions.
- What's for (file-truename)?
- Can I copy the path name to System(OS)'s clipboard, not the kill ring so that I can use the info with the other apps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
如果你使用evil,你可以使用:reg(ister)来显示evil寄存器。 % 将是当前路径,您也可以使用它粘贴到当前缓冲区(或 # 如果您更改了缓冲区)。
If you use evil, you can use :reg(ister) to show the evil registers. % will be the current path, which you can also use to paste into the current buffer (or # in case you changed buffers).
要按照标题所说的那样(显示迷你缓冲区中的当前文件路径),您可以这样做:
要在模式行中永久显示它,您可以使用这个:
或者这个(颜色+缩写):
To do what the title says (show the current file path in the minibuffer) you can do this:
To permanently show it in the mode-line, you can use this:
Or this (color + abbrev) :
我认为来自 [0] 的
copy-buffer-file-name-as-kill
正是您所需要的。它还可以选择仅复制目录名或仅复制文件名。[0] http://www.emacswiki.org/emacs/download/buffer-扩展名.el
copy-buffer-file-name-as-kill
from [0] does exactly what you need I think. It also has the option to copy just directory name, or just file name.[0] http://www.emacswiki.org/emacs/download/buffer-extension.el
如果您使用 xclip (Linux)、pbcopy (Mac)、putclip (Cygwin) 之类的工具,就可以实现。
我个人使用包装脚本
c
和p
分别进行复制和粘贴,首先从标准输入读取,后者写入标准输出。这样,它就适用于我的所有开发平台:我发现这比使用 Emacs 剪贴板支持更可靠且可配置。例如,我的 c 命令将输入复制到 Linux 上的所有 3 个剪贴板(主剪贴板、辅助剪贴板),因此我可以使用 Ctrl-V 或中键单击进行粘贴。
You can if you shell out to something like xclip (Linux), pbcopy (Mac), putclip (Cygwin).
I personally use wrapper scripts
c
andp
for copy and paste respectively, the first reading from standard input, the latter writing to standard output. That way, this works on all my development platforms:I find this more reliable and configurable than using the Emacs clipboard support. For example, my
c
command copies the input to all 3 clipboards on Linux (primary, secondary, clipboard), so I can paste with either Ctrl-V or middle click.最简单的方法是
向特雷·杰克逊借用
我想出了这个:
您可以在网站上找到更多信息
The simplest way and would be
Borrowing from Trey Jackson
I came up with this:
You can find more information on site
我已经使用以下代码很长时间了。
当我在模式行中的缓冲区名称上按鼠标中键时,它会将完整文件路径复制到终止环。当我在模式行中的缓冲区名称上按 Shift-鼠标-2 时,它仅将缓冲区名称复制到终止环。
I have the following code already in use for a long time.
It copies the full file path to the kill ring when I press the middle mouse button on the buffer name in the mode-line. It copies just the buffer name to the kill-ring when I press shift-mouse-2 on the buffer-name in the mode-line.
Cu Cx Cb
列出当前访问文件的缓冲区。C-u C-x C-b
lists buffers currently visiting files.Cx Cd
,也可通过Mx list-directory
调用,将显示当前文件的目录,您只需按“Enter”键即可清除迷你缓冲区。其他详细信息可在此处获取。C-x C-d
, also callable viaM-x list-directory
, will show you the directory for your current file, and you only need to hit the "Enter" key to clear the minibuffer. Additional details are available here.Cx Cb
显示缓冲区列表以及每个缓冲区的文件路径(如果适用)。C-x C-b
shows a list of buffers and the file path for each buffer where applicable.不需要额外的功能,只需
No need for extra function, just
你想要的直接实现是:
也就是说,我发现能够获取迷你缓冲区中内容的完整路径非常有用,这就是我使用的:
然后如果我想要它在剪贴板中,我只需杀死该行(Ca Ck)即可。但是我们可以在上面的命令中轻松地将 truename 复制到剪贴板,只需将最后一行更改为:
新部分是对
'kill-new
的调用,它将字符串放入 Kill 环中。The direct implementation of what you want is:
That said, I find it incredibly useful to be able to get the full path of what is in the minibuffer, and this is what I use:
And then if I want it in the clipboard, I just kill the line (C-a C-k). But we could easily copy the truename to the clipboard in the above command, just change the last line to be:
The new part is the call to
'kill-new
which puts the string in the kill ring.我的技巧是执行
Cx Cf
就像打开一个文件一样,它会用当前文件路径预填充 minibuff,Cg
退出。比 M-: buffer-file-name 更快,但比任何其他方法都丑陋得多。My trick is to do a
C-x C-f
like to open a file, it wil prefill the minibuff with the current file path,C-g
to quit. Faster thanM-: buffer-file-name
but far far uglier than any other methods.借用Jérôme Radix的答案,如果你只是想快速查看当前缓冲区的文件路径,你可以这样做
M-: buffer-file-name
。或者,在缓冲区中的某处输入
(buffer-file-name)
并在右括号上运行Cx Ce
(这适用于任何模式,而不仅仅是 lisp 模式) 。To borrow from Jérôme Radix's answer, if you just want to quickly see the file path of the current buffer, you can do
M-: buffer-file-name
.Alternately, type
(buffer-file-name)
in the buffer somewhere and runC-x C-e
on the closing parenthesis (this will work in any mode, not just lisp-mode).内置函数
buffer-file-name
为您提供文件的完整路径。最好的办法是让你的 emacs 窗口始终显示你的系统名称和你当前正在编辑的缓冲区的完整路径:
你也可以这样做:
It's the built-in function
buffer-file-name
that gives you the full path of your file.The best thing to do is to have your emacs window to always show your system-name and the full path of the buffer you're currently editing :
You can also do something like this :