我使用以下代码指示Emacs使用外部应用程序打开PDF文件:
(require 'openwith)
'(openwith-associations (quote (("\\.skim\\'" "open" (file)) ("\\.pdf\\'" "open" (file)))))
(openwith-mode t)当我访问PDF文件时,它成功地在我的外部程序中打开了该文件,但它也给了我错误和回溯:
Debugger entered--Lisp error: (error "Opened Foundation - Isaac Asimov.pdf in external program")
signal(error ("Opened Foundation - Isaac Asimov.pdf in external program"))
error("Opened %s in external program" "Foundation - Isaac Asimov.pdf")
openwith-file-handler(insert-file-contents "/Users/jay/iBooks/Books/Foundation - Isaac Asimov.pdf" t nil nil nil)
insert-file-contents("~/iBooks/Books/Foundation - Isaac Asimov.pdf" t)
byte-code("\302\303 \302\"\210)\302\207" [inhibit-read-only filename t insert-file-contents] 3)
find-file-noselect-1(#<killed buffer> "~/iBooks/Books/Foundation - Isaac Asimov.pdf" nil nil "~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books/Foundation - Isaac Asimov.pdf" (21490564 16777218))
find-file-noselect("/Users/jay/iBooks/Books/Foundation - Isaac Asimov.pdf" nil nil nil)
find-file("/Users/jay/iBooks/Books/Foundation - Isaac Asimov.pdf")
mapc(find-file ("/Users/jay/iBooks/Books/Foundation - Isaac Asimov.pdf"))
helm-find-many-files("/Users/jay/iBooks/Books/Foundation - Isaac Asimov.pdf")
apply(helm-find-many-files "/Users/jay/iBooks/Books/Foundation - Isaac Asimov.pdf")如何在不引发错误的情况下在外部应用程序中打开文件?
发布于 2014-08-05 02:04:05
我的建议是结合使用start-process和dired-mode在外部应用程序中打开文件。
Xah Lee编写了简短而有效的函数来处理在OS上设置的外部默认应用程序中打开文件:http://ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html
(defun xah-open-in-external-app (&optional file)
"Open the current file or dired marked files in external app.
The app is chosen from your OS's preference."
(interactive)
(let ( doIt
(myFileList
(cond
((string-equal major-mode "dired-mode") (dired-get-marked-files))
((not file) (list (buffer-file-name)))
(file (list file)))))
(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) ) ) ) ) )我使用了类似的东西(可以在下面的Github链接中查看),但它不像Xah Lee编写的函数那样简单:https://github.com/lawlist/dired-read-file-name/blob/master/dired-read-file-name.el
发布于 2021-04-21 16:15:28
如果文件的路径在缓冲区中,我用M-w保存它,然后调用shell-command并调用xdg-open C-y。这将拉出先前保存的文件的路径,并使用相关程序打开该文件。xdg-open负责查找正确的程序来打开该文件(screenshots)。
https://stackoverflow.com/questions/25109968
复制相似问题