Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different highlighting when called from LaTeX-mode-hook #36

Open
mjkramer opened this issue Sep 25, 2018 · 3 comments
Open

Different highlighting when called from LaTeX-mode-hook #36

mjkramer opened this issue Sep 25, 2018 · 3 comments

Comments

@mjkramer
Copy link

mjkramer commented Sep 25, 2018

Edit: Diagnosis isn't quite right; see next comment.

When I include magic-latex-buffer in LaTeX-mode-hook (whether at the end or beginning, doesn't matter), the result is what I expect that MLB works its magic in the right a few places, and the rest of the highlighting is left alone. On the other hand, without MLB in the hook, if I open a file and then activate MLB manually, the highlighting changes drastically (e.g. highlighting all commands indiscriminately, removing the highlighting from command arguments, changing the colors of sections, etc.).

In the screenshot below, the left column shows the "stock" highlighting without MLB. The middle one shows the result when MLB is included in the hook. On the right is the undesirable result I get upon manually activating MLB. (I also get this result if MLB is in the hook and I manually toggle it off and then back on.)

For what it's worth, my LaTeX-mode-hook looks like (spacemacs/load-yasnippet smartparens-mode evil-matchit-mode mjk-latex//LaTeX-mode-hook turn-on-reftex magic-latex-buffer TeX-PDF-mode TeX-source-correlate-mode LaTeX-math-mode TeX-fold-mode latex/auto-fill-mode spacemacs//init-company-LaTeX-mode company-mode). This does not seem to be a Spacemacs-specific issue, but I can try it on a vanilla Emacs.

image

@mjkramer
Copy link
Author

Upon preliminary inspection of magic-latex-buffer.el, it looks like the righthand column shows the intended result. It's supposed to change those faces.

So now the issue is that MLB is not fully re-fontifying the buffer when activated in LaTeX-mode-hook. Will investigate further.

@mjkramer
Copy link
Author

The problem seems to be that find-file-hook is calling TeX-update-style after MLB has initialized, and TeX-update-style clears font-lock-keywords (by setting font-lock-set-defaults to nil before calling (font-lock-set-defaults). So the effect of MLB's

(font-lock-add-keywords nil ml/keywords 'set)

is being cancelled out. Manually enabling magic-latex-buffer works, because at that point find-file-hook has already been run.

I will try to think of a non-hacky way to fix this.

@mjkramer
Copy link
Author

I can confirm that the problem goes away when I put latex-magic-buffer in TeX-update-style-hook instead of LaTeX-mode-hook. Should this be documented in the README? Anyway I'll go ahead and submit a PR to Spacemacs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant