【发布时间】:2013-12-11 04:11:10
【问题描述】:
在 Mac OSX 上的 Emacs 中,是否有在 Finder 中显示当前文件的功能?
【问题讨论】:
在 Mac OSX 上的 Emacs 中,是否有在 Finder 中显示当前文件的功能?
【问题讨论】:
有点晚了,但我只是基于此创建了一个脚本。当从 dired 缓冲区调用时,它会打开文件夹。
https://github.com/kaz-yos/reveal-in-osx-finder(新链接)
编辑 2014-02-06 现在可以在 MELPA 上使用:M-x list-packages 应该在其他包中列出reveal-in-finder。
请看这里使用。 https://github.com/kaz-yos/reveal-in-osx-finder
编辑 2014-04-08 我稍微更新了脚本(如下)。这在 dired 缓冲区中应该会有所帮助。
(0.3.0 中的新功能)如果在 dired 缓冲区中调用 M-x reveal-in-finder,它将在 OS X Finder 中打开当前文件夹。如果可用,它还将突出显示该文件。
编辑 2015-08-03 该包已重命名为reveal-in-osx-finder.el,以避免与其他类型的“查找器”混淆。
【讨论】:
finder 没有限定。 finder.el 是一个标准的 Emacs 库,它的命令、函数和变量使用名称 finder 来表示与“MAC OS X Finder”完全不同的东西。请考虑使用名称和名称组件,例如 macosx-finder 或 osx-finder,而不仅仅是 finder。
解决方案 #1::下面的第二个解决方案是最初的解决方案,但我现在使用的方法略有不同,它也可以最大化 Finder 窗口。因此,这是替代解决方案(适用于目录和文件):
(defun dired-open-in-finder ()
"This function contemplates that we are in columns view in Finder (Command+3),
rather than list view (Command+2)."
(interactive)
(let ((path (dired-get-file-for-visit))
(display-pixel-height (number-to-string (display-pixel-height)))
(display-pixel-width (number-to-string (display-pixel-width))))
(when path
(let* ((maximize
(concat
"tell application \"Finder\" to set the bounds of the front Finder window to "
"{0, 0, " display-pixel-width ", " display-pixel-height "}\n"))
(script
(concat
"tell application \"Finder\"\n"
" set frontmost to true\n"
" make new Finder window to (POSIX file \"" path "\")\n"
maximize
"end tell\n")))
(start-process "finder" nil "osascript" "-e" script)))))
解决方案 #2:我不记得我从哪里得到的 - 如果有人知道,请告诉我,我会向作者发布引用 - 谢谢。
(defun open-finder ()
(interactive)
(let ((path (or (buffer-file-name) (dired-file-name-at-point)))
dir file)
(when path
(setq dir (file-name-directory path))
(setq file (file-name-nondirectory path)))
(open-finder-1 dir file)))
(defun open-finder-1 (dir file)
(let ((script
(if file
(concat
"tell application \"Finder\"\n"
" set frontmost to true\n"
" make new Finder window to (POSIX file \"" (expand-file-name dir) "\")\n"
" select file \"" file "\"\n"
"end tell\n")
(concat
"tell application \"Finder\"\n"
" set frontmost to true\n"
" make new Finder window to {path to desktop folder}\n"
"end tell\n"))))
(start-process "osascript-getinfo" nil "osascript" "-e" script)))
【讨论】:
tell application "Finder" to reveal path:to:some:filestackoverflow.com/questions/11222501/…
这是一个老问题,但让我添加一个解决方案。到目前为止,我对此感到满意。
(defun open-current-file-in-finder ()
(interactive)
(shell-command "open -R ."))
【讨论】:
这不是 Emacs 函数,因此可能不是您想要的,但如果您使用 Cocoa 构建的 Emacs (apple-appkit),最简单的解决方案是 ⌘-click 或 ⌃-click 中的文件名菜单栏,然后单击封闭文件夹,该文件夹将在 Finder 中打开。
【讨论】:
改进 diadochos 的回答。 这是针对 OSX 系统的。它可以轻松更改为任何基于 unix 或 gnu 的操作系统。
这实际上是打开父目录(不是包含文件的目录)
(defun open-current-file-in-finder ()
(interactive)
(shell-command "open -R ."))
这就是我要找的。打开包含文件的目录。
(defun open-current-file-directory ()
(interactive)
(shell-command "open ."))
(defun show-in-finder ()
(interactive)
(shell-command (concat "open -R " buffer-file-name)))
在 Emacs 25.1.1 中测试
【讨论】:
在 dired 模式下,输入 '!' 而不是 'e' 或 'f' 以在 emacs 缓冲区中打开文件然后“打开-R”。将打开一个指向您的文件的新 Finder 窗口。
【讨论】:
您也可以只输入以下内容。
M-:
open .
当您在当前缓冲区中打开文件时。
好处是你不需要记住函数的名称,甚至不需要记住它的一部分来获得自动完成。
【讨论】:
! open . 不是M-: open .
最简单的方法是在您的组织文档中写一个file://... 链接,例如
file://Users/my_username/Backups/
现在,将光标移动到该链接中的任意位置并运行 M-x org-open-at-point(为简单起见,我将其绑定到我的 org-mode-map 中的 s-.)
您也可以按C-c C-l 编辑链接并为其赋予可读的标题。
【讨论】: