如何在 Emacs dired 模式下从外部打开文件?

发布于 2024-11-26 11:54:20 字数 63 浏览 2 评论 0原文

我想用 evince 而不是 DocView 模式打开 pdf。是否可以使用“evince”等特定命令打开文件?

I want to open a pdf with evince instead of DocView mode. Is there a possibility to open a file with a specific command like 'evince'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

诠释孤独 2024-12-03 11:54:20

是的。在 dired 中使用 ! 对文件运行 shell 命令。

不过,就 <​​code>evince 而言,使用 & 更为明智,因为它会异步运行该命令,因此当您打开 PDF 时,emacs 仍然可用。

Yes. Use ! while in dired to run a shell command on a file.

In the case of evince, it's smarter to use &, though, which will run the command asynchronously, so emacs will still be usable while you have the PDF open.

忆梦 2024-12-03 11:54:20

有不止一种方法可以做到这一点。我建议 OpenWith 库。您的情况的设置可能如下所示:

(add-to-list 'load-path "/path/to/downloaded/openwith.el")
(require 'openwith)
(setq openwith-associations '(("\\.pdf\\'" "evince" (file))))
(openwith-mode t)

它设置可在 diredfind-file 中工作的文件处理程序。

There is more then one way to do that. I suggest OpenWith library. Setup for your case may look like that:

(add-to-list 'load-path "/path/to/downloaded/openwith.el")
(require 'openwith)
(setq openwith-associations '(("\\.pdf\\'" "evince" (file))))
(openwith-mode t)

It sets file handler that will work from both dired and find-file.

明媚殇 2024-12-03 11:54:20

试试这个。

(defun dired-open-file ()
  "In dired, open the file named on this line."
  (interactive)
  (let* ((file (dired-get-filename nil t)))
    (message "Opening %s..." file)
    (call-process "gnome-open" nil 0 nil file)
    (message "Opening %s done" file)))

Try this.

(defun dired-open-file ()
  "In dired, open the file named on this line."
  (interactive)
  (let* ((file (dired-get-filename nil t)))
    (message "Opening %s..." file)
    (call-process "gnome-open" nil 0 nil file)
    (message "Opening %s done" file)))
っ〆星空下的拥抱 2024-12-03 11:54:20

您可以使用 ! 打开文件,然后指定命令。

You can use ! to open the file and then specify a command.

绻影浮沉 2024-12-03 11:54:20

请注意,退出 Emacs 后,您可以使用 nohup 使进程保持活动状态[维基百科],因此将点放在 dired 中的单个文件上:

C-u ! nohup evince ? &

这会创建一个 执着的进程 [EmacsWiki]。

Note that you can keep the process alive after exiting Emacs by using nohup [Wikipedia], so put the point on a single file in dired:

C-u ! nohup evince ? &

which creates a Persistent Processes [EmacsWiki].

烟酒忠诚 2024-12-03 11:54:20

在Windows中,我经常使用!并命令“资源管理器”打开 PDF/Word/Excel...

In Windows, I offen use ! and command "explorer" to open PDF/Word/Excel...

淡淡绿茶香 2024-12-03 11:54:20

另一个 Windows 操作系统解决方案使用 explorer.exe 打开单个/多个文件。要打开多个文件,请在 dired 中使用 m 标记文件,然后按 o 打开多个文件。要仅在点下打开单个文件,请点击 o。我已经在 Windows 上本机运行的 Emacs 28.2 GUI 中对其进行了测试(无 WSL/Cygwin/Linux-on-Windows)。

  (use-package dired
      :bind (:map dired-mode-map
          ("o" . jr/dired-open))
      :config
      (defun jr/dired-open ()
      (interactive)
      (if-let ((marks (dired-get-marked-files)))
        (dolist (file marks)
          (shell-command (format "explorer.exe %s" (file-name-nondirectory file))))
      (user-error "No marked files; aborting"))))

Another windows OS solution using explorer.exe to open single/multiple files. To open multiple files, mark the file using m in dired and then hit o to open multiple files. To just open a single file under point hit o. I have tested it in Emacs 28.2 GUI running natively on windows (no WSL/Cygwin/Linux-on-Windows).

  (use-package dired
      :bind (:map dired-mode-map
          ("o" . jr/dired-open))
      :config
      (defun jr/dired-open ()
      (interactive)
      (if-let ((marks (dired-get-marked-files)))
        (dolist (file marks)
          (shell-command (format "explorer.exe %s" (file-name-nondirectory file))))
      (user-error "No marked files; aborting"))))
面如桃花 2024-12-03 11:54:20
(defun dired-open()
  (interactive)
  (setq file (dired-get-file-for-visit))
  (setq ext (file-name-extension file))
  (cond ((string= ext "pdf")
         ;; shell-quote-argument escapes white spaces on the file name
         (async-shell-command (concat "zathura " (shell-quote-argument file))))
        ((string= ext "epub")
         (async-shell-command (concat "zathura " (shell-quote-argument file))))
        ((string= ext "rar")
         (async-shell-command (concat "file-roller " (shell-quote-argument file))))
        ((string= ext "zip")
         (async-shell-command (concat "file-roller " (shell-quote-argument file))))
        (t (dired-find-file))))
(defun dired-open()
  (interactive)
  (setq file (dired-get-file-for-visit))
  (setq ext (file-name-extension file))
  (cond ((string= ext "pdf")
         ;; shell-quote-argument escapes white spaces on the file name
         (async-shell-command (concat "zathura " (shell-quote-argument file))))
        ((string= ext "epub")
         (async-shell-command (concat "zathura " (shell-quote-argument file))))
        ((string= ext "rar")
         (async-shell-command (concat "file-roller " (shell-quote-argument file))))
        ((string= ext "zip")
         (async-shell-command (concat "file-roller " (shell-quote-argument file))))
        (t (dired-find-file))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文