views:

353

answers:

3

I am doing small modification to SLIME, so that I can get all currently loaded symbols from Lisp, analyze them and make font-lock fontify them.

I managed to do all these steps, but I have a small problem - when keyword list changes in font-lock the buffer is not updated unless you restart the major lisp-mode. I don't want to restart lisp-mode every time I update keywords, because I have several hooks on lisp-mode that I want to run only when I load the file for the first time.

Is there an other way to update font-lock so it reads all then new keywords and fontifies the buffer accordingly? Switching off font-lock and using font-lock-fontify-buffer does not do the trick.

UPD: Added bounty - the question is still up. I need a way to reload font-lock keyword without reloading major mode.

+1  A: 

Triggering the major-mode is not what makes font-lock do its thing. I am not intimately familiar with the internals of SLIME or lisp-mode, but just setting the variable should make it work. Toggling font-lock-mode will make font-lock start refontifying with the new keywords in mind, as should font-lock-fontify-buffer.

I hack on cperl-mode, mostly, and it is a simple matter of cperl-init-faces (which sets the internal font-lock variables) and a restart of font-lock. lisp-mode should not be much different, except for not needing a call to cperl-init-faces ;)

Edit: some experimentation with lisp-interaction-mode reveals that even restarting font-lock-mode is not strictly necessary. Just changing font-lock-keywords is enough, as long as you re-trigger fontification somehow. (Editing text, font-lock-fontify-buffer, etc.)

jrockway
That's very strange. What do you use to modify keywords? I use "font-lock-add-keywords".
freiksenet
Font-lock restart does not also help for python mode for example. Maybe it is my version of Emacs? What version do you have? I have GNU Emacs 23.1.50.1 on x86-64 Ubuntu.
freiksenet
+1  A: 

You could temporarily clear the mode hook variable and restart it:

(defun my-restart-lisp-mode ()
  (interactive)
  (let ((lisp-mode-hook nil))
    (normal-mode)))
scottfrazer
Cool, I'll try this.I wonder why it does not work like jrockway described by default :)
freiksenet
Okay, this is better, but this disables all hooks, including slime hook for example, which is not good :( I really wonder if it is possible to do it without restarting the mode.
freiksenet
+2  A: 

Ok, how about this instead:

(defun my-font-lock-restart ()
  (interactive)
  (setq font-lock-mode-major-mode nil)
  (font-lock-fontify-buffer))
scottfrazer
Awesome, this seems to work!
freiksenet