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

font-lock-activate isue with hooks #9

Closed
Ergus opened this issue Apr 13, 2019 · 8 comments
Closed

font-lock-activate isue with hooks #9

Ergus opened this issue Apr 13, 2019 · 8 comments

Comments

@Ergus
Copy link

Ergus commented Apr 13, 2019

Hi:

I am trying to use this package with the hooks, but it is not working.

After some debugging I just found that the problem is that font-lock-mode is nil in that moment because it is set later; but you can use the global variable global-font-lock-mode. which is already set in that moment:

Something like:

(when (and (or font-lock-mode  global-font-lock-mode)
           (fboundp 'font-lock-refresh-defaults))
      (font-lock-refresh-defaults)))

In cmake-font-lock-activate could fix this issue.

@Lindydancer
Copy link
Owner

Lindydancer commented Apr 15, 2019 via email

@Ergus
Copy link
Author

Ergus commented Apr 15, 2019

Hi:

I had exactly the same set up that is described in the readme, and it didn't work. I don't enable font-lock-mode explicitly in the init file because it is already enabled by default with the global-font-lock-mode. After loading, the global variable font-lock-mode remains nil, but the buffer local one is set to t.

The only config I have tried that works for me is:

(use-package cmake-mode
  :mode ("\\'CMakeLists\\.txt\\'" "\\.cmake\(.in\)?\\'")
  :config
  (add-to-list 'company-backends 'company-cmake))

(use-package cmake-font-lock
  :preface
  (defun my/cmake-font-lock ()
    (cmake-font-lock-setup)
    (when (and (or font-lock-mode  global-font-lock-mode)
           (fboundp 'font-lock-refresh-defaults))
      (font-lock-refresh-defaults)))
  :init
  (add-hook 'cmake-mode-hook #'my/cmake-font-lock t))

@Lindydancer
Copy link
Owner

Lindydancer commented Apr 15, 2019 via email

@Ergus
Copy link
Author

Ergus commented Apr 15, 2019

Hi I double check and your config worked, as well the use-packages one when I tried them alone.

After double checking it seems that the problem is a conflict with the packages: highlight-numbers and highlight-indent-guides.

For some reason when one of them is enabled the cmake-font-lock-mode does not work when enabled as a hook (not your or mine config). Probably it has to do with some global-vs-local variable issue, but I am not a lisp specialist to understand where the conflict is.

So for now I will continue with the workaround that is working for me.

@Ergus Ergus closed this as completed Apr 15, 2019
@Lindydancer
Copy link
Owner

Lindydancer commented Apr 16, 2019 via email

@Ergus
Copy link
Author

Ergus commented Apr 16, 2019

Hi I have been looking the code in highlight-numbers looking for the issue source, but I can't find it. Probably you could give a look too, it is a pretty simple package and 4 eyes are better than two.

@Ergus
Copy link
Author

Ergus commented Jun 4, 2020

Hi:

After some time I am comming back to this and I wrote to Stefan Monnier to guive a look. So far he thinks that cmake-font-lock.el should reallybe part of cmake.el because setting font-lock-defaults directly can only be done reliably by the major-mode function itself rather than from the mode hook.

Could you consider to do that?

@Lindydancer
Copy link
Owner

Lindydancer commented Jun 6, 2020 via email

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

2 participants