From: Stephen Eglen <S.J.Eglen@damtp.cam.ac.uk>
To: bug-gnu-emacs@gnu.org
Cc: Stephen Eglen <S.J.Eglen@damtp.cam.ac.uk>
Subject: Font lock problem when changing major mode
Date: Thu, 21 Jun 2007 20:00:56 +0100 [thread overview]
Message-ID: <t5xps3p16af.fsf@notch.damtp.cam.ac.uk> (raw)
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''
reply other threads:[~2007-06-21 19:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=t5xps3p16af.fsf@notch.damtp.cam.ac.uk \
--to=s.j.eglen@damtp.cam.ac.uk \
--cc=bug-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).