dalanicolai / pdf-continuous-scroll-mode.el

A pdf-tools extension that provides continuous scrolling functionality
GNU General Public License v3.0
144 stars 10 forks source link

[BUG] Does not handle some epdfinfo failure #10

Closed NightMachinery closed 3 years ago

NightMachinery commented 4 years ago

My epdfinfo was broken (happens on macOS):

❯ epdfinfo
dyld: Library not loaded: /usr/local/opt/poppler/lib/libpoppler.102.dylib
  Referenced from: /usr/local/bin/epdfinfo
  Reason: image not found
[1]    32911 abort      epdfinfo

And this in turn broke pdf-continuous-scroll-mode.el with some rather unhelpful messages. Here is a stacktrace:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p "Abort trap: 6")
  =(0 "Abort trap: 6")
  (if (= 0 (apply #'call-process executable cmdfile (current-buffer) nil (if pdf-info-epdfinfo-error-filename (progn (list pdf-info-epdfinfo-error-filename))))) nil (error "Error running `%s': %s" pdf-info-epdfinfo-program (buffer-string)))
  (progn (let ((temp-file pdffile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (set-buffer-multibyte nil) (insert pdf-info-empty-page-data)) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (let ((temp-file cmdfile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (insert (format "renderpage:%s:1:100\nquit\n" (pdf-info-query--escape pdffile)))) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (if (= 0 (apply #'call-process executable cmdfile (current-buffer) nil (if pdf-info-epdfinfo-error-filename (progn (list pdf-info-epdfinfo-error-filename))))) nil (error "Error running `%s': %s" pdf-info-epdfinfo-program (buffer-string))))
  (unwind-protect (progn (let ((temp-file pdffile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (set-buffer-multibyte nil) (insert pdf-info-empty-page-data)) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (let ((temp-file cmdfile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (insert (format "renderpage:%s:1:100\nquit\n" ...))) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (if (= 0 (apply #'call-process executable cmdfile (current-buffer) nil (if pdf-info-epdfinfo-error-filename (progn (list pdf-info-epdfinfo-error-filename))))) nil (error "Error running `%s': %s" pdf-info-epdfinfo-program (buffer-string)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let ((temp-file pdffile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (set-buffer-multibyte nil) (insert pdf-info-empty-page-data)) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (let ((temp-file cmdfile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (insert ...)) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (if (= 0 (apply #'call-process executable cmdfile (current-buffer) nil (if pdf-info-epdfinfo-error-filename (progn ...)))) nil (error "Error running `%s': %s" pdf-info-epdfinfo-program (buffer-string)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let ((temp-file pdffile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer ... ... ...) (save-current-buffer ... ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (let ((temp-file cmdfile) (temp-buffer (generate-new-buffer " *temp file*"))) (unwind-protect (prog1 (save-current-buffer ... ...) (save-current-buffer ... ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (if (= 0 (apply #'call-process executable cmdfile (current-buffer) nil (if pdf-info-epdfinfo-error-filename ...))) nil (error "Error running `%s': %s" pdf-info-epdfinfo-program (buffer-string)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
  (unwind-protect (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let ((temp-file pdffile) (temp-buffer ...)) (unwind-protect (prog1 ... ...) (and ... ...))) (let ((temp-file cmdfile) (temp-buffer ...)) (unwind-protect (prog1 ... ...) (and ... ...))) (if (= 0 (apply ... executable cmdfile ... nil ...)) nil (error "Error running `%s': %s" pdf-info-epdfinfo-program (buffer-string)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))) (if (file-exists-p cmdfile) (progn (delete-file cmdfile))) (if (file-exists-p pdffile) (progn (delete-file pdffile))) (if (file-exists-p tempdir) (progn (delete-directory tempdir t))))
  (let* ((default-directory (expand-file-name "~/")) (cmdfile (make-temp-file "commands")) (pdffile (make-temp-file "empty.pdf")) (tempdir (make-temp-file "tmpdir" t)) (process-environment (cons (concat "TMPDIR=" tempdir) process-environment))) (unwind-protect (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let (... ...) (unwind-protect ... ...)) (let (... ...) (unwind-protect ... ...)) (if (= 0 ...) nil (error "Error running `%s': %s" pdf-info-epdfinfo-program ...))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))) (if (file-exists-p cmdfile) (progn (delete-file cmdfile))) (if (file-exists-p pdffile) (progn (delete-file pdffile))) (if (file-exists-p tempdir) (progn (delete-directory tempdir t)))))
  (let ((executable pdf-info-epdfinfo-program)) (if (stringp executable) nil (error "pdf-info-epdfinfo-program is unset or not a string")) (if (file-executable-p executable) nil (error "pdf-info-epdfinfo-program is not executable")) (if pdf-info-epdfinfo-error-filename (progn (if (and (stringp pdf-info-epdfinfo-error-filename) (file-writable-p pdf-info-epdfinfo-error-filename)) nil (error "pdf-info-epdfinfo-error-filename should contain wr...")))) (let* ((default-directory (expand-file-name "~/")) (cmdfile (make-temp-file "commands")) (pdffile (make-temp-file "empty.pdf")) (tempdir (make-temp-file "tmpdir" t)) (process-environment (cons (concat "TMPDIR=" tempdir) process-environment))) (unwind-protect (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let ... ...) (let ... ...) (if ... nil ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))) (if (file-exists-p cmdfile) (progn (delete-file cmdfile))) (if (file-exists-p pdffile) (progn (delete-file pdffile))) (if (file-exists-p tempdir) (progn (delete-directory tempdir t))))))
  pdf-info-check-epdfinfo()
  (if (and (processp (pdf-info-process)) (eq (process-status (pdf-info-process)) 'run)) nil (if (pdf-info-process) (progn (tq-close pdf-info--queue) (setq pdf-info--queue nil))) (if (or force (eq pdf-info--queue t) (and (eq pdf-info-restart-process-p 'ask) (not noninteractive) (y-or-n-p "The epdfinfo server quit, restart it ? ")) (and pdf-info-restart-process-p (not (eq pdf-info-restart-process-p 'ask)))) nil (if (eq pdf-info-restart-process-p 'ask) (progn (setq pdf-info-restart-process-p nil))) (error "The epdfinfo server quit")) (pdf-info-check-epdfinfo) (let* ((process-connection-type) (default-directory "~") (proc (apply #'start-process "epdfinfo" " *epdfinfo*" pdf-info-epdfinfo-program (if pdf-info-epdfinfo-error-filename (progn (list pdf-info-epdfinfo-error-filename)))))) (save-current-buffer (set-buffer " *epdfinfo*") (erase-buffer)) (set-process-query-on-exit-flag proc nil) (set-process-coding-system proc 'utf-8-unix 'utf-8-unix) (setq pdf-info--queue (tq-create proc))))
  pdf-info-process-assert-running()
  pdf-info-query(features)
  (let (pdf-info-asynchronous) (pdf-info-query 'features))
  (setq pdf-info-features (let (pdf-info-asynchronous) (pdf-info-query 'features)))
  (or pdf-info-features (setq pdf-info-features (let (pdf-info-asynchronous) (pdf-info-query 'features))))
  pdf-info-features()
  (memq 'markup-annotations (pdf-info-features))
  (null (memq 'markup-annotations (pdf-info-features)))
  (not (null (memq 'markup-annotations (pdf-info-features))))
  pdf-info-markup-annotations-p()
  (if (pdf-info-markup-annotations-p) (list 'text 'file 'squiggly 'highlight 'underline 'strike-out) (list 'text 'file))
  (closure (t) nil (if (pdf-info-markup-annotations-p) (list 'text 'file 'squiggly 'highlight 'underline 'strike-out) (list 'text 'file)))()
  funcall((closure (t) nil (if (pdf-info-markup-annotations-p) (list 'text 'file 'squiggly 'highlight 'underline 'strike-out) (list 'text 'file))))
  eval((funcall #'(closure (t) nil (if (pdf-info-markup-annotations-p) (list 'text 'file 'squiggly 'highlight 'underline 'strike-out) (list 'text 'file)))))
  custom-initialize-reset(pdf-annot-list-listed-types (funcall #'(closure (t) nil (if (pdf-info-markup-annotations-p) (list 'text 'file 'squiggly 'highlight 'underline 'strike-out) (list 'text 'file)))))
  custom-declare-variable(pdf-annot-list-listed-types (funcall #'(closure (t) nil (if (pdf-info-markup-annotations-p) (list 'text 'file 'squiggly 'highlight 'underline 'strike-out) (list 'text 'file)))) "A list of annotation types displayed in the list b..." :group pdf-annot :type (set (const 3d) (const caret) (const circle) (const file) (const free-text) (const highlight) (const ink) (const line) (const link) (const movie) (const poly-line) (const polygon) (const popup) (const printer-mark) (const screen) (const sound) (const square) (const squiggly) (const stamp) (const strike-out) (const text) (const trap-net) (const underline) (const unknown) (const watermark) (const widget)))
  #<subr eval-buffer>(#<buffer  *load*> nil "/Users/evar/.emacs.d.doom/.local/straight/build/pd..." nil t)
  apply(#<subr eval-buffer> (#<buffer  *load*> nil "/Users/evar/.emacs.d.doom/.local/straight/build/pd..." nil t))
  eval-buffer(#<buffer  *load*> nil "/Users/evar/.emacs.d.doom/.local/straight/build/pd..." nil t)  ; Reading at buffer position 7827
  load-with-code-conversion("/Users/evar/.emacs.d.doom/.local/straight/build/pd..." "/Users/evar/.emacs.d.doom/.local/straight/build/pd..." nil t)
  require(pdf-annot)
  #<subr eval-buffer>()
  apply(#<subr eval-buffer> nil)
  eval-buffer()  ; Reading at buffer position 1107
  funcall-interactively(eval-buffer)
  call-interactively(eval-buffer nil nil)
  command-execute(eval-buffer)
dalanicolai commented 4 years ago

Thanks, for reporting and including the stacktrace. pdf-continuous-scroll-mode works only for pdf-tools, and pdf-tools requires a working epdfinfo server. Also, I am on GNU/linux, so unfortunately I can not support macOS specific issues (also I am not a real developer anyway). On the other hand the scrolling functions of doc-view-mode work very similar (it appears that pdf-tools just copied them more or less), so that pdf-continuous-scroll-mode can easily get ported to doc-view-mode (which I did already, however I continued hacking to make them sync with djvu.el buffers, so that they now do not work with pdf-documents anymore. But for if you are interested, I will upload the code to my elisp experiments repository. But you would have to remove the djvu-specific functions to make it work with pdf documents again. Unfortunately this has no priority for me).

NightMachinery commented 4 years ago

@dalanicolai This is not a big issue, actually. I simply wanted to tell you that this is a possible output of epdfinfo (currently it causes an unhandled exception.). Just reinstalling epdfinfo solves this. I hoped you could add a proper error message for this "Abort trap: 6" output, that's all.

dalanicolai commented 4 years ago

Ah I see. Very good that you take time to report the issues, but to me in this case this looks more related to epdfinfo which is part of pdf-tools. Or do you think it is a bug of the pdf-continuous-scroll-mode package? In that case could you explain a little more specifically? Otherwise, I think we can close this issue?