syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.68k stars 4.89k forks source link

Glitches with pdf-tools #15106

Closed DrWaleedAYousef closed 11 months ago

DrWaleedAYousef commented 2 years ago

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.

  2. 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:

Observed behaviour: :eyes: :broken_heart: explained upfront

Expected behaviour: :heart: :smile: <>

System Info :computer:

Backtrace :paw_prints:

<<BACKTRACE IF RELEVANT>>

image

barryridge commented 2 years ago

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.

smile13241324 commented 2 years ago

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

dalanicolai commented 2 years ago

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.

smile13241324 commented 2 years ago

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.
dalanicolai commented 2 years ago

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).

DrWaleedAYousef commented 2 years ago

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

dalanicolai commented 2 years ago

@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.

DrWaleedAYousef commented 2 years ago

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.

dalanicolai commented 2 years ago

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!

DrWaleedAYousef commented 2 years ago

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 commented 2 years ago

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?
lebensterben commented 2 years ago

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

DrWaleedAYousef commented 2 years ago

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 commented 2 years ago

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

dalanicolai commented 2 years ago

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.

lebensterben commented 2 years ago

well just use diff-hl then.

dalanicolai commented 2 years ago

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

dalanicolai commented 2 years ago

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).

DrWaleedAYousef commented 2 years ago

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.

lebensterben commented 2 years ago

except launching the pdf-tools mods

what do you mean by mods?

DrWaleedAYousef commented 2 years ago

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.

manuelbb-upb commented 2 years ago

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.

lebensterben commented 2 years ago

@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)?

DrWaleedAYousef commented 2 years ago

@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!

manuelbb-upb commented 2 years ago

@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.

github-actions[bot] commented 1 year ago

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!