spacemacs icon indicating copy to clipboard operation
spacemacs copied to clipboard

Glitches with pdf-tools

Open DrWaleedAYousef opened this issue 2 years ago • 25 comments

Description :octocat:

  1. pdf-tools mode does not start when opening a pdf, unles there is this line in .spacemacs:
(add-hook 'pdf-view-mode-hook 'pdf-tools-enable-minor-modes)

I traced the problem, it only happend when the org layer is loaded.

  1. When scrolling a pdf file, the following buffer always appears (also, attached as an image for clarity)
These default coding systems were tried to encode text
in the buffer ‘ *temp file*’:
  (utf-8 (11 . 4194274) (12 . 4194275) (13 . 4194255) (14 . 4194259) (468 .
  4194204) (469 . 4194285) (471 . 4194267) (473 . 4194267) (477 . 4194295) (480
  . 4194280) (481 . 4194199))
However, each of them encountered characters it couldn’t encode:
  utf-8 cannot encode these: � � � � � � � � � � ...

Click on a character (or switch to this window by ‘M-m w w’
and select the characters by RET) to jump to the place it appears,
where ‘M-m u C-x =’ will give information about it.

Select one of the safe coding systems listed below,
or cancel the writing with C-g and edit the buffer
   to remove or modify the problematic characters,
or specify any other coding system (and risk losing
   the problematic characters).

  raw-text no-conversion

Reproduction guide :beetle:

  • Start Emacs
  • open any PDF.

Observed behaviour: :eyes: :broken_heart: explained upfront

Expected behaviour: :heart: :smile: <<DESCRIPTION OF THE EXPECTED BEHAVIOUR>>

System Info :computer:

  • OS: gnu/linux
  • Emacs: 27.2
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. 63056ecb5)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: emacs
  • Completion: helm
  • Layers:
(dap c-c++ php systemd
     (latex :variables latex-build-command "LatexMk" latex-enable-auto-fill t latex-backend 'lsp latex-build-engine 'luatex latex-view-pdf-in-split-window t latex-enable-magic t latex-refresh-preview t latex-enable-folding t)
     (bibtex :variables bibtex-enable-ebib-support t ebib-preload-bib-files
             '("~/MyDocuments/Phd/texmf/bibtex/bib/base/publications.bib" "~/MyDocuments/Phd/texmf/bibtex/bib/base/booksIhave.bib")
             ebib-file-search-dirs
             '("~/MyDocuments/Phd/PDF/")
             ebib-import-directory
             '("~/Downloads/"))
     lua
     (html :variable css-enable-lsp t less-enable-lsp t scss-enable-lsp t html-enable-lsp t web-fmt-tool 'web-beautify html-enable-leex-support t)
     web-beautify prettier gnus auto-completion emacs-lisp git
     (yaml :variables yaml-enable-lsp t)
     (python :variables python-format-on-save t python-formatter 'yapf python-fill-column 99 python-backend 'lsp python-lsp-server 'pyright)
     auto-completion better-defaults emacs-lisp git helm lsp markdown multiple-cursors
     (org :variables org-enable-org-contacts-support t org-contacts-files
          '("~/.emacs.d.loadpath/Contacts-Imported.org")
          org-capture-templates
          '(("c" "Contacts" entry
             (file "~/Contacts-Imported.org")
             "* %(org-contacts-template-name))\n:PROPERTIES:\n:EMAIL: %(org-contacts-template-email)\n:END:")))
     (pdf :variables pdf-view-display-size 'fit-page)
     (shell :variables shell-default-shell 'eshell shell-default-height 30 shell-default-position 'bottom)
     (spell-checking :variables spell-checking-enable-auto-dictionary t)
     syntax-checking version-control treemacs)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY ACL GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP

Backtrace :paw_prints:

<<BACKTRACE IF RELEVANT>>

image

DrWaleedAYousef avatar Oct 18 '21 16:10 DrWaleedAYousef

I'm also experiencing this problem, both on Ubuntu 20.04 using the Snap-installed Emacs 28 native comp. and MacOS Catalina using the Brew-installed Emacs 28 native comp.

Also, the PDF buffer tends to crash Emacs on MacOS when I try to interact with it once it is open, e.g. by attempting to scroll through it with the mouse, but I am unsure as to whether or not this is a separate issue.

barryridge avatar Nov 25 '21 19:11 barryridge

Did run into the same issue this week, I will check this later.

smile13241324 avatar Nov 28 '21 08:11 smile13241324

I never had the problem that pdf-tools did not start, but I have run into the 'can not encode buffer pop-up' problem also. I have posted a solution already here. So, for me the solution is to deactivate git-gutter-mode in the pdf-buffer. I guess we could add a fix by deactivating git-gutter-mode by default in the pdf buffer.

dalanicolai avatar Nov 29 '21 11:11 dalanicolai

Strange, I was not able to get this issue on my linux box. However I have now added some code to not activate git-gutter-mode in pdf-view-mode, can you double check whether this solves the encoding issues?

The auto start issue I cannot reproduce, on my side I am always getting pdf-view-mode activated when I open a PDF file. Can you post the value of pdf-view-mode-hook without your fix? In my case I see the following:

pdf-view-mode-hook is a variable defined in pdf-view.el.

Value
(pdf-view-restore-mode
 pdf-tools-enable-minor-modes)

View as literal Set

Documentation
Hook run after entering PDFView mode.

smile13241324 avatar Nov 29 '21 21:11 smile13241324

I only get this issue with a PDF that I created using the newest version of latex.

Anyway, unfortunately the problem is not yet completely fixed because I now get a message

Error running timer ‘git-gutter:live-update’: (wrong-type-argument arrayp nil)

And here is the backtrace produced by that error:

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  substring(nil 0 1)
  file-truename(nil)
  git-gutter:live-update()
  apply(git-gutter:live-update nil)
  timer-event-handler([t 0 2 0 t git-gutter:live-update nil idle 0])

The error does not show up when I disable global-git-gutter-mode first. (Note, that this error only occurs in this particular PDF created with the newest latex version)

Now the message, although ugly, is not such a big deal, but somehow the global-git-gutter-mode (or the timer) also causes pdf-view-mode to open in emacs-state, which of course is annoying.

So I guess, we should first try to disable that timer (which gets initialized in git-gutter-mode), and then see if that prevents pdf-view-mode to open in emacs-state (for PDFs created with the newest latex).

dalanicolai avatar Nov 30 '21 10:11 dalanicolai

For the mode-activation problem, why it only happens with the org mode enabled

For the encoding problem, it happens with any PDF file, whether created with latex or not

DrWaleedAYousef avatar Nov 30 '21 19:11 DrWaleedAYousef

@DrWaleedAYousef Thanks for the feedback, but could you respond to @smile13241324 his questions. Also, did you try if deactivating git-gutter-mode (manually) solves the 'encoding popup' problem? Otherwise, maybe you could gather more info about it by following the advice in this answer.

Both @smile13241324 and I could not reproduce the problem of the org layer preventing pdf-tools to start, so it is quite difficult to guess (what and) why it happens only with org mode.

dalanicolai avatar Nov 30 '21 20:11 dalanicolai

Thanks @dalanicolai and @smile13241324 . Related to your questions, there are some updates:

  1. The encoding problem is gone by itself! I no longer see the pop-up buffer complaining!!
  2. Regarding, the (add-hook 'pdf-view-mode-hook 'pdf-tools-enable-minor-modes) it seems that this problem is gone by itself as well!! Whether I keep this in the dotfile or not the pdf-tools starts. However, it starts in the emacs state. Even when I press Ctr z, the evilified yellow color of the normal state appears but with no effect on the keybindings (e.g., j and k for navigation).

I hope this helps.

DrWaleedAYousef avatar Dec 01 '21 15:12 DrWaleedAYousef

The issue of pdf-view starting in emacs-state seems to get triggered by the first form, i.e. (pdf-tools-install), in the :config section of pdf/init-pdf-tools, but this happens only when the version control layer is installed.

Additionally, there is the error message from the timer which is started by 'git-gutter-mode' (I guess git-gutter-mode gets disabled 'locally' via a hook, but then the timer already got triggered by the initial activation of git-gutter-mode, I did not check this, it is just a hypothesis). This error is of minor priority, because it seems to do no harm other than triggering the error message. I don't know a straightforward way to deactivate the timer (e.g. via a hook), so I guess this should get fixed in git-gutter-mode itself.

Anyway, there are two reasonable temporary workarounds:

  1. don't use the version control layer (personally, I am only using git layer functionality anyway)
  2. comment out the (pdf-tools-install) form in pdf/init-pdf-tools

@DrWaleedAYousef sounds like you have synced (git pull/reinstalled) Spacemacs, bugs generally don't fix themselves :) Thanks for the feedback of course!

dalanicolai avatar Dec 02 '21 12:12 dalanicolai

I commented out the version-control layer; yet, the pdf starts in emacs-state.

Regarding the self-update, yes I have the following script to update the packages and spacemacs:

emacsclient -e '(kill-emacs)'
emacs --daemon -f configuration-layer/update-packages
emacsclient -e '(kill-emacs)'
cd .emacs.d
git pull --rebase
emacs &

DrWaleedAYousef avatar Dec 08 '21 23:12 DrWaleedAYousef

Now, after weeks of working, I can confirm the following:

  1. The encoding problem no longer exists
  2. The minor mode problem exists inconsistently. Sometimes the emacs state is activated when opening a pdf and sometimes the minor mode is working; very inconsistent. Any advice?

DrWaleedAYousef avatar Jan 07 '22 16:01 DrWaleedAYousef

The inconsistency makes it hard to reproduce. I never reproduced it actually.

lebensterben avatar Jan 07 '22 17:01 lebensterben

The inconsistency makes it hard to reproduce. I never reproduced it actually.

Ok, I will try to keep an eye and debug then report here. Please leave the issue open.

DrWaleedAYousef avatar Jan 08 '22 01:01 DrWaleedAYousef

I know it is too early, because I need to experiment for a relatively long period to confirm my observation, but this is just to keep you in the loop: Since I posted above (so, I am experimenting now for 4 days) I disabled the org layer from the .spacemacs. Everything is working great, with full pdf-view functionality as expected!f

DrWaleedAYousef avatar Jan 12 '22 00:01 DrWaleedAYousef

I have created a fix upstream for pdf-view starting in normal-state. The issue about the coding system message is due to git-gutter-mode getting activated somehow. I am not sure if that should have been fixed, I can not find a commit about it, but on the other hand things seem to work fine here. I will probably create an upstream fix for that also anyway (just I have no time now). I guess you will automatically get notified when I create the upstream fix there also.

Then there is one error left which is Emacs erroring with Error running timer ‘git-gutter:live-update’: (wrong-type-argument arrayp nil) (not reported here). It seems that that error is due to some misconfiguration in Spacemacs.

dalanicolai avatar Apr 20 '22 13:04 dalanicolai

well just use diff-hl then.

lebensterben avatar Apr 20 '22 14:04 lebensterben

Funny that it shows every push --force here...

dalanicolai avatar Apr 21 '22 09:04 dalanicolai

As you find in the links above, both upstream fixes have been merged so that the issues mentioned here should have been solved (and the issue can be closed).

dalanicolai avatar May 03 '22 11:05 dalanicolai

The glitches that I mentioned are solved except launching the pdf-tools modes when opening a pdf. Every once and then it does not open.

On May 3, 2022, at 4:46 AM, Daniel Nicolai @.***> wrote:

 As you find in the links above, both upstream fixes have been merged so that the issues mentioned here should have been solved (and the issue can be closed).

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

DrWaleedAYousef avatar May 03 '22 21:05 DrWaleedAYousef

except launching the pdf-tools mods

what do you mean by mods?

lebensterben avatar May 03 '22 22:05 lebensterben

Sorry: mode

On May 3, 2022, at 3:17 PM, Lucius Hu @.***> wrote:

 except launching the pdf-tools mods

what do you mean by mods?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

DrWaleedAYousef avatar May 03 '22 22:05 DrWaleedAYousef

This is a situation where the minor modes are not set correctly: If the latex layer is setup with latex-view-pdf-in-split-window t and there is no buffer yet that displays the PDF for a tex file, so that SPC m v has to create a new buffer, then some minor modes appear to be missing and the leader key does not work. Everything is fine if the PDF is open in some other buffer. In the first case find-file-noselect creates a new buffer, in the second case some existing buffer is reused, see source.

It is also fixed by (add-hook 'pdf-view-mode-hook 'pdf-tools-enable-minor-modes) in the user-config.

manuelbb-upb avatar Jul 07 '22 11:07 manuelbb-upb

@manuelbb-upb I read the linked upstream issue and it seems to be fixed there. Do you still see the same bug in Spacemacs (after updating pdf-tools)?

lebensterben avatar Jul 13 '22 20:07 lebensterben

@manuelbb-upb I read the linked upstream issue and it seems to be fixed there. Do you still see the same bug in Spacemacs (after updating pdf-tools)?

For me, the only remaining bug is that the pdf-tools-enable-minor-modes sometimes does not launch automatically. It requires calling it, then re-open the pdf!

DrWaleedAYousef avatar Jul 14 '22 08:07 DrWaleedAYousef

@manuelbb-upb I read the linked upstream issue and it seems to be fixed there. Do you still see the same bug in Spacemacs (after updating pdf-tools)?

Yes, the leader key bug in that private layer appears to be fixed now. However, the linking to this issue was rather by accident (as I wrongly thought the bugs to be related). Sorry! I still use the add-hook fix to enable all minor modes otherwise.

manuelbb-upb avatar Jul 14 '22 09:07 manuelbb-upb

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

github-actions[bot] avatar Aug 03 '23 18:08 github-actions[bot]