不能直接打开到源文件/源目录,直接打开会显示乱码。
可以参考这个帖子:
我是安装了 consult
, 有这个命令 consult-file-externally
, 配合 Embark
使用会更加方便。
如果不想安装第三方包的话,可以用这个函数。
(defun open-with-external-app (&optional @fname)
"Open the current file or dired marked files in external app.
When called in Emacs Lisp, if @FNAME is given, open that."
(interactive)
(let* (
($file-list
(if @fname
(progn (list @fname))
(if (string-equal major-mode "dired-mode")
(dired-get-marked-files)
(list (buffer-file-name)))))
($do-it-p (if (<= (length $file-list) 5)
t
(y-or-n-p "Open more than 5 files? "))))
(when $do-it-p
(cond
((string-equal system-type "windows-nt")
(mapc
(lambda ($fpath)
(shell-command
(concat "PowerShell -Command \"Invoke-Item -LiteralPath\" " "'"
(shell-quote-argument (expand-file-name $fpath )) "'")))
$file-list))
((string-equal system-type "darwin")
(mapc
(lambda ($fpath)
(shell-command
(concat "open " (shell-quote-argument $fpath))))
$file-list))
((string-equal system-type "gnu/linux")
(mapc
(lambda ($fpath)
(let ((process-connection-type nil))
(start-process "" nil "xdg-open" $fpath)))
$file-list))))))
1 个赞