spacemacs在finder打开文件的那个插件是什么

那是后安装的还是系统自带的, 子龙在视频里是 spc b f 就在 finder 显示了.

reveal-in-osx-finder.el 要查看是哪个包,先在 which-key 查看 function 的名字,再C-h f搜索 function 的定义,找到在哪个 package。


顺带这应该是osxlayer里的。 SPC h SPC查看插件被哪个layer使用。

1 个赞

不是 Emacs 自带的,不清楚什么插件提供这个功能,之前我也要类似的需求:

(defun chunyang-mac-Finder-reveal (file)
  "Reveal (select/highlight) FILE in Finder."
  (interactive (list (or (buffer-file-name) ".")))
  (do-applescript
   (format (concat
            "tell application \"Finder\"\n"
            "	activate\n"
            "	reveal POSIX file \"%s\"\n"
            "end tell")
           (expand-file-name file))))

open -R /path/to/file 也可以。

1 个赞

这个在linux里也可以吗?

哦,之前不知道。你提的这个方法更方便/简单。

GNU/Linux 上没有和 open(1) 或 AppleScript 类似的东西,所以你只能指望你所用的文件管理器能支持这个功能了(比如提供一个命令行选项:$ some-file-manager --reveal file

有那个插件就不需要在命令行使用open了~

spc h spc 显示有这个包, 是 osx layer 里的, 但是为啥 C-h f 搜不到这个函数呢

子龙说只在mac有效, 因为是用finder打开, 但是linux应该也有类似的吧

我从spacemacs中抄来的

(defun maple/open-in-external-app ()
  "Open current file in external application."
  (interactive)
  (let ((file-path (if (eq major-mode 'dired-mode)
                       (dired-get-file-for-visit)
                     (buffer-file-name))))
    (if file-path
        (cond
         ((maple/system-is-mswindows) (w32-shell-execute "open" (replace-regexp-in-string "/" "\\\\" file-path)))
         ((maple/system-is-mac) (shell-command (format "open \"%s\"" file-path)))
         ((maple/system-is-linux) (let ((process-connection-type nil))
                                    (start-process "" nil "xdg-open" file-path))))
      (message "No file associated to this buffer."))))

这个也挺好的, 自己去实现, 但是 spacemacs 自带的那个无效, 不知道怎么回事, 在 OSX layer 里面, keybindings.el 里面明明定义好了快捷键了, 但是 which key 根本不提示有那个快捷键, 硬按就是 undefined

命令中不显示这个命令.

Unless the system type is macOS, the package will not be loaded. And if the package is not loaded, you cannot find the definition of the functions.

我从stackexchange抄来的打开当前目录的方法(无视操作系统区别):

  (defun browse-file-directory ()
    "Open the current file's directory however the OS would."
    (interactive)
    (if default-directory
        (browse-url-of-file (expand-file-name default-directory))
      (error "No `default-directory' to open")))

windows下亲测把default-directory换成buffer-file-name就能打开当前文件了。

1 个赞

我的配置,在dired 下面用C-c C-o 可以打开任何文件或者目录,文件会自动调用系统默认程序打开,支持linux,mac,windows,甚至可以用m键mark多个文件然后打开

     (defun open-in-external-app ()
      "Open the current file or dired marked files in external app."
      (interactive)
      (let ( doIt
             (myFileList
              (cond
               ((string-equal major-mode "dired-mode") (dired-get-marked-files))
               (t (list (buffer-file-name))) ) ) )

        (setq doIt (if (<= (length myFileList) 5)
                       t
                     (y-or-n-p "Open more than 5 files?") ) )

        (when doIt
          (cond
           ((string-equal system-type "windows-nt")
            (mapc (lambda (fPath) (w32-shell-execute "open" (replace-regexp-in-string "/" "\\" fPath t t)) ) myFileList))
           ((string-equal system-type "darwin")
            (mapc (lambda (fPath) (shell-command (format "open \"%s\"" fPath)) )  myFileList) )
           ((string-equal system-type "gnu/linux")
            (mapc (lambda (fPath) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" fPath)) ) myFileList) ) ) )
        (local-set-key (kbd "C-c C-o") 'open-in-external-app)) )

可以在 spacemacs 直接使用 shell 用 open . 命令来打开, 其实就跟在终端打开一样, 只是不如 spacemacs 的快捷键那么方便了. 还得 SPC ! 然后输入命令. 好处是省下了个插件.