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

Invalid function: book image positions #15

Closed workcomplete closed 2 years ago

workcomplete commented 2 years ago

Hey recently updated to the new single buffer pdf-continuous-scroll-mode.el and was working well yesterday. Unfortunately today I can open pdfs but cannot scroll or move pages using any of the relevant commands. Mini buffer is complaining:

image-set-window-vscroll: Invalid function: book-image-positions image-mode-reapply-winprops: Invalid function: book-image-positions image-mode-window-get: Wrong type argument: listp

Config:

(use-package! pdf-continuous-scroll-mode) (map! :map pdf-view-mode-map ""#'pdf-continuous-scroll-forward) (map! :map pdf-view-mode-map ""#'pdf-continuous-scroll-backward) (setq book-page-vertical-margin 0) (setq pdf-view-image-relief 1) (setq pdf-continuous-suppress-introduction 1)

dalanicolai commented 2 years ago

I don't know why it reports that this is an invalid function, because it is defined in the file. Maybe, you have some compiled (pdf-continuous-scroll-mode.elc) file that somehow breaks things.

Although I am not sure if it will be of any help, it might be handy to upload a backtrace here. You can usually obtain it by doing M-x toggle-debug-on-error before triggering the error.

If you are unable to find the cause, then you could use the 2-buffer version, by loading the file from here

workcomplete commented 2 years ago

I ran doom build yesterday and the original issue seems to have resolved.

However I have noticed two other issues (let me know if I should start a new issue)

The first is similar to #16 , where every time I call org-noter-insert-precise-note (which moves focus to an ivy complete buffer), the pdf goes blank rather than going to the first page.

The second problem is that while I am dragging the cursor to select/higlight text in a pdf, the page appears to drag and zoom/grow with the cursor.

dalanicolai commented 2 years ago

Thanks for reporting this. Unfortunately I do not fully understand the Emacs/image-mode's its (re)display mechanism. Both issues you reported in your last comment (pdf goes blank, and, grows while dragging) I have encountered also when testing the package in vanilla Emacs. A problem is that I am a Spacemacs user, where the second issue does not occur, and the first issue only occurs sporadically (and also here I do not yet understand why/how it works exactly), but generally the package works fine in Spacemacs.

The pdf-tools (re)display mechanism is quite involved and largely undocumented, therefore it takes a lot of time to find out how it works (and how to fix it). I hope some more knowledgeable users will try to use it and help fix these bugs.

I am slowly trying to find out how these things work in detail, but, as my available time is limited, I am not sure how long (weeks, months) it will take before I find it.

I guess, when you are using org-noter, it is probably wise not to use this package (unfortunately).

Also, there are more things that need to get fixed, like history-mode, isearch and probably other functionalities.

averter commented 2 years ago

I've also recently updated to the latest version and am experiencing the same issue. I am running GNU Emacs 27.2. By trial and error I found that the error message is triggered by (setq book-page-vertical-margin 0). I might revert back to the two buffers solution since the current version seems to be under heavy development. In any case I intend to make a donation to this project and look forward to see it merged with pdf-tools. Thanks.

averter commented 2 years ago

FYI, toggle-debug-on-error reveals

  book-image-positions()
  image-mode-reapply-winprops()
  redisplay_internal\ \(C\ function\)()
  redisplay()

Despite my limited elisp skills I notice that book-image-positions is set as a macro and not a function. Could this be the source of the problem? The relevant portion of code in pdf-continuous-scroll-mode.el is

(defun image-mode-reapply-winprops ()
  ;; When set-window-buffer, set hscroll and vscroll to what they were
  ;; last time the image was displayed in this window.
  (when (listp image-mode-winprops-alist)
    ;; Beware: this call to image-mode-winprops can't be optimized away,
    ;; because it not only gets the winprops data but sets it up if needed
    ;; (e.g. it's used by doc-view to display the image in a new window).
    (let* ((winprops (image-mode-winprops nil t))
           (hscroll (image-mode-window-get 'hscroll winprops))
           (vscroll (round (* (image-mode-window-get 'relative-vscroll winprops)
                              (car (last (book-image-positions)))))))
      (when (image-get-display-property) ;Only do it if we display an image!
          (if hscroll (set-window-hscroll (selected-window) hscroll))
          (if vscroll (set-window-vscroll (selected-window) vscroll t))))))

;; (defmacro book-current-page (&optional win)
;;   `(image-mode-window-get 'page ,win))
(defmacro book-overlays (&optional window) `(image-mode-window-get 'overlays ,window))
(defmacro book-image-sizes (&optional window) `(image-mode-window-get 'image-sizes ,window))
(defmacro book-image-positions (&optional window) `(image-mode-window-get 'image-positions ,window))
dalanicolai commented 2 years ago

Thanks, for this 'update'. I think it is wise indeed to go back to the two-buffer solution, as it costs too much time (which I don't have, unfortunately) to 'finish/fix' the feature. About it being related to the implementation as macro, I am quite sure it is. There must be a file that uses the macro, that gets compiled before the macro is loaded. However, I am not maintaining this package (and will not sort it out). A better, but still very incomplete, version can be found in the continuous-scroll-version-3 branch of my pdf-tools fork. But also for that version I am short on resources for finishing it....