在Emacs中,如何在Finder中显示当前文件?

问题描述 投票:5回答:8

在Mac OSX上的Emacs中,是否有一个功能可以在Finder中显示当前文件?

emacs org-mode
8个回答
7
投票

有点晚了,但我刚刚创建了一个基于此的脚本。从dired缓冲区调用时,它会打开该文件夹。

https://github.com/kaz-yos/reveal-in-osx-finder(新链接)

编辑2014-02-06现在可用于MELPA:M-x列表包应列出其他包中的揭示查找器。

看这里使用。 https://github.com/kaz-yos/reveal-in-osx-finder

编辑2014-04-08我稍微更新了脚本(下面)。这在dired缓冲区中应该是有用的。

(在0.3.0中为NEW)如果在直接缓冲区中调用M-x显示查找器,它将在OS X Finder中打开当前文件夹。它还将在可用时突出显示该文件。

编辑2015-08-03该软件包被重命名为reveal-in-osx-finder.el,以避免与其他类型的“finder”混淆。


4
投票

解决方案#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)))

3
投票

这不是一个Emacs函数,所以也许不是你所追求的,但如果你使用的是Cocoa构建的Emacs(apple-appkit),最简单的解决方案是在菜单栏中点击或^单击文件名,然后单击封闭文件夹,然后在Finder中打开。


2
投票

这是一个老问题,但让我添加一个解决方案。到目前为止,我对此很满意。

(defun open-current-file-in-finder ()
  (interactive)
  (shell-command "open -R ."))

0
投票

改善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中测试过


0
投票

在直接模式下,输入'!'而不是'e'或'f'来打开emacs缓冲区中的文件然后“打开-R”。将打开一个指向您的文件的新Finder窗口。


0
投票

您也可以输入以下内容。

M-:
open .

当您在当前缓冲区中打开文件时。

好处是你不需要记住函数的名称,甚至不需要记住它的一部分才能获得自动完成功能。


0
投票

最简单的方法是在组织文档中编写file://...链接,例如

file://Users/my_username/Backups/

现在,将光标移动到该链接中的任何位置并运行M-x org-open-at-point(为了简单起见,我将其绑定到我的org-mode-map中的s-.


你也可以按C-c C-l编辑链接并给它一个人类可读的标题。

© www.soinside.com 2019 - 2024. All rights reserved.