想用 pdf-tools 做主力 pdf 阅读器,但是……

超级快,我做了双缓冲设计,触摸板滑动时特别顺滑

2 个赞

[quote=“manateelazycat, post:62, topic:5242, full:true”] 级快,我做了双缓冲设计,触摸板滑动时特别顺滑 [/quote 这个插件可以和 latex很好的工作在一起吗?经常使用 emacs 来写 latex文档,不知道这个pdf阅读器怎么样?

1 个赞

这个阅读器和LaTeX工作得很好

@et2010 我发现了两个workaround:

第一个的要求是你的电脑性能不差:提高pdf-tools对mouse event识别的resolution即可

(defun pdf-view-mouse-set-region (event &optional allow-extend-p
                                          rectangle-p)
    "Select a region of text using the mouse with mouse event EVENT.

Allow for stacking of regions, if ALLOW-EXTEND-P is non-nil.

Create a rectangular region, if RECTANGLE-P is non-nil.

Stores the region in `pdf-view-active-region'."
    (interactive "@e")
    (setq pdf-view--have-rectangle-region rectangle-p)
    (unless (and (eventp event)
                 (mouse-event-p event))
      (signal 'wrong-type-argument (list 'mouse-event-p event)))
    (unless (and allow-extend-p
                 (or (null (get this-command 'pdf-view-region-window))
                     (equal (get this-command 'pdf-view-region-window)
                            (selected-window))))
      (pdf-view-deactivate-region))
    (put this-command 'pdf-view-region-window
         (selected-window))
    (let* ((window (selected-window))
           (pos (event-start event))
           (begin-inside-image-p t)
           (begin (if (posn-image pos)
                      (posn-object-x-y pos)
                    (setq begin-inside-image-p nil)
                    (posn-x-y pos)))
           (abs-begin (posn-x-y pos))
           pdf-view-continuous
           region)
      (when (pdf-util-track-mouse-dragging (event 0.005)
                                           (let* ((pos (event-start event))
                                                  (end (posn-object-x-y pos))
                                                  (end-inside-image-p
                                                   (and (eq window (posn-window pos))
                                                        (posn-image pos))))
                                             (when (or end-inside-image-p
                                                       begin-inside-image-p)
                                               (cond
                                                ((and end-inside-image-p
                                                      (not begin-inside-image-p))
                                                 ;; Started selection ouside the image, setup begin.
                                                 (let* ((xy (posn-x-y pos))
                                                        (dxy (cons (- (car xy) (car begin))
                                                                   (- (cdr xy) (cdr begin))))
                                                        (size (pdf-view-image-size t)))
                                                   (setq begin (cons (max 0 (min (car size)
                                                                                 (- (car end) (car dxy))))
                                                                     (max 0 (min (cdr size)
                                                                                 (- (cdr end) (cdr dxy)))))
                                                         ;; Store absolute position for later.
                                                         abs-begin (cons (- (car xy)
                                                                            (- (car end)
                                                                               (car begin)))
                                                                         (- (cdr xy)
                                                                            (- (cdr end)
                                                                               (cdr begin))))
                                                         begin-inside-image-p t)))
                                                ((and begin-inside-image-p
                                                      (not end-inside-image-p))
                                                 ;; Moved outside the image, setup end.
                                                 (let* ((xy (posn-x-y pos))
                                                        (dxy (cons (- (car xy) (car abs-begin))
                                                                   (- (cdr xy) (cdr abs-begin))))
                                                        (size (pdf-view-image-size t)))
                                                   (setq end (cons (max 0 (min (car size)
                                                                               (+ (car begin) (car dxy))))
                                                                   (max 0 (min (cdr size)
                                                                               (+ (cdr begin) (cdr dxy)))))))))
                                               (let ((iregion (if rectangle-p
                                                                  (list (min (car begin) (car end))
                                                                        (min (cdr begin) (cdr end))
                                                                        (max (car begin) (car end))
                                                                        (max (cdr begin) (cdr end)))
                                                                (list (car begin) (cdr begin)
                                                                      (car end) (cdr end)))))
                                                 (setq region
                                                       (pdf-util-scale-pixel-to-relative iregion))
(pdf-view-display-region
 (cons region pdf-view-active-region)
 rectangle-p)
                                                 (pdf-util-scroll-to-edges iregion)))))

        (setq pdf-view-active-region
              (append pdf-view-active-region
                      (list region)))
        (pdf-view--push-mark))))

关键(唯一的改动)是when pdf-util-track-mouse-dragging (event 0.005)

第二种方法(可以和第一种结合着用) 是放弃即时反馈,仅在松开鼠标时最后显示选中的区域,很简单,把

(pdf-view-display-region
 (cons region pdf-view-active-region)
 rectangle-p)

(pdf-util-track-mouse-dragging)这个macro里移出来就行了

(defun pdf-view-mouse-set-region (event &optional allow-extend-p
                                          rectangle-p)
    "Select a region of text using the mouse with mouse event EVENT.

Allow for stacking of regions, if ALLOW-EXTEND-P is non-nil.

Create a rectangular region, if RECTANGLE-P is non-nil.

Stores the region in `pdf-view-active-region'."
    (interactive "@e")
    (setq pdf-view--have-rectangle-region rectangle-p)
    (unless (and (eventp event)
                 (mouse-event-p event))
      (signal 'wrong-type-argument (list 'mouse-event-p event)))
    (unless (and allow-extend-p
                 (or (null (get this-command 'pdf-view-region-window))
                     (equal (get this-command 'pdf-view-region-window)
                            (selected-window))))
      (pdf-view-deactivate-region))
    (put this-command 'pdf-view-region-window
         (selected-window))
    (let* ((window (selected-window))
           (pos (event-start event))
           (begin-inside-image-p t)
           (begin (if (posn-image pos)
                      (posn-object-x-y pos)
                    (setq begin-inside-image-p nil)
                    (posn-x-y pos)))
           (abs-begin (posn-x-y pos))
           pdf-view-continuous
           region)
      (when (pdf-util-track-mouse-dragging (event 0.005)
              (let* ((pos (event-start event))
                     (end (posn-object-x-y pos))
                     (end-inside-image-p
                      (and (eq window (posn-window pos))
                           (posn-image pos))))
                (when (or end-inside-image-p
                          begin-inside-image-p)
                  (cond
                   ((and end-inside-image-p
                         (not begin-inside-image-p))
                    ;; Started selection ouside the image, setup begin.
                    (let* ((xy (posn-x-y pos))
                           (dxy (cons (- (car xy) (car begin))
                                      (- (cdr xy) (cdr begin))))
                           (size (pdf-view-image-size t)))
                      (setq begin (cons (max 0 (min (car size)
                                                    (- (car end) (car dxy))))
                                        (max 0 (min (cdr size)
                                                    (- (cdr end) (cdr dxy)))))
                            ;; Store absolute position for later.
                            abs-begin (cons (- (car xy)
                                               (- (car end)
                                                  (car begin)))
                                            (- (cdr xy)
                                               (- (cdr end)
                                                  (cdr begin))))
                            begin-inside-image-p t)))
                   ((and begin-inside-image-p
                         (not end-inside-image-p))
                    ;; Moved outside the image, setup end.
                    (let* ((xy (posn-x-y pos))
                           (dxy (cons (- (car xy) (car abs-begin))
                                      (- (cdr xy) (cdr abs-begin))))
                           (size (pdf-view-image-size t)))
                      (setq end (cons (max 0 (min (car size)
                                                  (+ (car begin) (car dxy))))
                                      (max 0 (min (cdr size)
                                                  (+ (cdr begin) (cdr dxy)))))))))
                  (let ((iregion (if rectangle-p
                                     (list (min (car begin) (car end))
                                           (min (cdr begin) (cdr end))
                                           (max (car begin) (car end))
                                           (max (cdr begin) (cdr end)))
                                   (list (car begin) (cdr begin)
                                         (car end) (cdr end)))))
                    (setq region
                          (pdf-util-scale-pixel-to-relative iregion))

                    (pdf-util-scroll-to-edges iregion)))))
        (pdf-view-display-region
         (cons region pdf-view-active-region)
         rectangle-p)
        (setq pdf-view-active-region
              (append pdf-view-active-region
                      (list region)))
        (pdf-view--push-mark))))

另外pdf-tools里最好要么禁用evil,要么关闭evil-visual的鼠标选取功能

PS其实这个function可以改改 直接加上highlight的功能,这样就能一键highlight了,爽歪歪

3 个赞

这个牛逼!谢谢!

你使用 pdf-tools 的几率大吗?我现在几乎每天要阅读大量的pdf软件,使用这个插件的频率很高。感觉这个使用体验并不很好,主要还是一个性能的问题,速度偏慢,evince比它体验太好了。主要是pdf-tools很好的和Emacs结合起来,到现在还没有放弃使用这个插件。几次都想放弃这个插件了。无奈,最后还是拿回来使用了。

想问一下大佬,eaf异常退出该怎么查找问题呢? EAF process starting… Opening /mnt/doc/pdf/Effective_Java/Effective_Java.pdf with eaf.pdfviewer eaf exited abnormally with code 1

操作系统;ubuntu 18.04 桌面;gnome emacs版本:25 python版本:3.7

有一个buffer显示的错误信息

EAF不支持Wayland构建的Gnome

fvwm或icewm支持吗?

支持kde,gnome2或者其他以x11技术为基础的桌面环境

很多窗口管理器的icccm协议实现不完整,没法跑eaf

pdf-tool add markup annotation 区域上移有遇到过么?

image

这个问题我也常遇到.

对同一个 pdf 文件,在商业软件上 mark 的效果好很多.

个人觉得, 稍微一点儿的偏差, 对自己学习来讲倒是不是很重要了.

pdf-tool 要改进得花大功夫.

(but, I think it’s too much pain for too little gain)

刚又试了一些pdf, 有些pdf又是没有问题的,迷惑行为

那是pdf文件本身的问题。

pdf-tools有没有设置dark theme的方法? 白底黑字太亮了,有点瞎眼

pdf-view-midnight-minor-mode

1 个赞

妙啊(补四个字符)

你还可以把midnight-mode的前景和背景色换成和你的主题一样:

(let ((params (frame-parameters)))
  (setq pdf-view-midnight-colors
        (cons (alist-get 'foreground-color params)
              (alist-get 'background-color params))))
2 个赞