【问题】在不使用EAF的情况下,怎样加速Emacs阅读pdf的速度

docview 慢是因为默认用的 pdf->img 的转换程序慢,换成 mupdf 的就会快许多。

Linux 平台下可以使用 eaf-pdf-viewer

macOS 下 eaf 支持不佳,可以转而使用 pdf-tools

pdf-tools 遇大文件会发生卡顿

此时有三种选择:

  1. 换更强劲的 cpu,让天下没有能让 pdf-tools 卡顿的 PDF 文件
  2. 在虚拟机上安装 Linux 使用 eaf,但这要克服一下键位冲突问题
  3. 使用外部 pdf,放弃在 Emacs 中阅读 pdf 的想法

上述 3 的参考链接:

http://xahlee.info/emacs/emacs/emacs_dired_open_file_in_ext_apps.html

整合一下:

(defun xah-open-in-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.

URL `http://xahlee.info/emacs/emacs/emacs_dired_open_file_in_ext_apps.html'
Version: 2019-11-04 2023-04-05 2023-06-26"
  (interactive)
  (let (xfileList xdoIt)
    (setq xfileList
          (if Fname
              (list Fname)
            (if (string-equal major-mode "dired-mode")
                (dired-get-marked-files)
              (list buffer-file-name))))
    (setq xdoIt (if (<= (length xfileList) 10) t (y-or-n-p "Open more than 10 files? ")))
    (when xdoIt
      (cond
       ((string-equal system-type "windows-nt")
        (let ((xoutBuf (get-buffer-create "*xah open in external app*"))
              (xcmdlist (list "PowerShell" "-Command" "Invoke-Item" "-LiteralPath")))
          (mapc
           (lambda (x)
             (message "%s" x)
             (apply 'start-process (append (list "xah open in external app" xoutBuf) xcmdlist (list (format "'%s'" (if (string-match "'" x) (replace-match "`'" t t x) x))) nil)))
           xfileList)
          ;; (switch-to-buffer-other-window xoutBuf)
          )
        ;; old code. calling shell. also have a bug if filename contain apostrophe
        ;; (mapc (lambda (xfpath) (shell-command (concat "PowerShell -Command \"Invoke-Item -LiteralPath\" " "'" (shell-quote-argument (expand-file-name xfpath)) "'"))) xfileList)
        )
       ((string-equal system-type "darwin")
        (mapc (lambda (xfpath) (shell-command (concat "open " (shell-quote-argument xfpath)))) xfileList))
       ((string-equal system-type "gnu/linux")
        (mapc (lambda (xfpath)
                (call-process shell-file-name nil 0 nil
                              shell-command-switch
                              (format "%s %s"
                                      "xdg-open"
                                      (shell-quote-argument xfpath))))
              xfileList))
       ((string-equal system-type "berkeley-unix")
        (mapc (lambda (xfpath) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" xfpath))) xfileList))))))

(defun find-file-auto (orig-fun &rest args)
  (let ((filename (car args)))
    (if (cl-find-if
         (lambda (regexp) (string-match regexp filename))
         '("\\.pdf\\'" "\\.docx?\\'"))
        (xah-open-in-external-app filename)
      (apply orig-fun args))))

(advice-add 'find-file :around 'find-file-auto)

这将实现 Emacs 默认使用外部 pdf viewer 打开 pdf 文件的功能

================================================

当然,仍然期待 EAF 对 macOS 的支持。至少 pdf-viewer 是翘首以盼的。

1 个赞

其实 All in Emacs 是为了可以简便地适应和设置快捷键。不过,这在很多时候得不偿失。

3 个赞