* Font lock problem when changing major mode
@ 2007-06-21 19:00 Stephen Eglen
0 siblings, 0 replies; only message in thread
From: Stephen Eglen @ 2007-06-21 19:00 UTC (permalink / raw)
To: bug-gnu-emacs; +Cc: Stephen Eglen
I've found a minor problem with font locking, when handling changes in
major mode. I have a major mode, defined roughly below. It is based
on comint-mode similar to comments in comint.el (around line 3500):
(defun inferior-ess-mode ()
(comint-mode)
(setq major-mode 'inferior-ess-mode)
;; ...
(setq font-lock-defaults
'(inferior-ess-font-lock-keywords nil nil ((?' . "."))))
)
Importantly, the 2nd element of font-lock-defaults is set to nil, as I
want font-lock-keywords-only to be nil. However,
font-lock-keywords-only is set to 't during comint-mode, due to this
code near the end of comint-mode:
(setq font-lock-defaults '(nil t))
(add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
Even though font-lock-defontify is called in a buffer changing from
comint-mode to inferior-ess-mode, font-lock-set-defaults will not
update any font-lock local variables because the buffer-local flag
font-lock-set-defaults has been set.
The following addition (marked SJE) to font-lock-defontify solves my
immediate problem:
(defun font-lock-defontify ()
"Clear out all `font-lock-face' properties in current buffer.
A major mode that uses `font-lock-face' properties might want to put
this function onto `change-major-mode-hook'."
(let ((modp (buffer-modified-p))
(inhibit-read-only t))
(save-restriction
(widen)
(remove-list-of-text-properties (point-min) (point-max)
'(font-lock-face)))
;; SJE: next two lines new.
(kill-local-variable font-lock-set-defaults)
(kill-local-variable font-lock-keywords-only)
(restore-buffer-modified-p modp)))
However, this is not a complete solution (e.g. it doesn't handle
resetting font-lock-keywords-case-fold-search). Just removing the
local var font-lock-set-defaults doesn't work because the function
font-lock-set-defaults changes font-lock-keywords-only (and
-case-fold-search) iff it is non-nil:
(when (nth 1 defaults)
(set (make-local-variable 'font-lock-keywords-only) t))
If these tests are changed to something like:
(when (> (length defaults) 1)
(set (make-local-variable 'font-lock-keywords-only)
(nth 1 defaults)))
then we only need to kill the local var font-lock-set-defaults
in font-lock-defontify.
Finally, since font-lock-defaults is now buffer local in Emacs 22, is
it worth removing redundant calls to make it buffer-local?
$ grep -r "make-local-variable 'font-lock-defaults" * | wc -l
reveals 80 files in lisp/. Should those redundant calls be removed?
Rather than send a patch, I thought I'd check first this kind of
change is appropriate. If it sounds okay, I can send a patch, or
update CVS directly.
Stephen
In GNU Emacs 22.1.1 (i386-apple-darwin8.9.1, Carbon Version 1.6.0)
of 2007-06-07 on cpc6-cmbg2-0-0-cust449.cmbg.cable.ntl.com
Windowing system distributor `Apple Inc.', version 10.4.9
configured using `configure '--enable-carbon-app''
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-06-21 19:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-21 19:00 Font lock problem when changing major mode Stephen Eglen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).