[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Status of font-lock-fontify-region and ways to fontify a string
From: |
Clément Pit--Claudel |
Subject: |
Status of font-lock-fontify-region and ways to fontify a string |
Date: |
Wed, 6 Jan 2016 17:54:20 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 |
Hi all,
Emacs 25 complains when I use font-lock-fontify-buffer, suggesting I replace it
by font-lock-flush or font-lock-ensure. I've been running into problems with
both of these (I don't have good repros yet, but I've had cases where even
calling both in succession didn't result in the buffer being fontified).
This causes me to wonder: what is the recommended way to fontify a string
according to a given mode? font-lock-fontify region was not marked
interactive-only; is it still a good idea to call it from lisp code?
Alternatively, is the following snippet expected to always returned a fontified
string?
(with-temp-buffer
(my-fancy-mode)
(insert some-text)
(font-lock-ensure)
(buffer-string))
Similarly, since this is a common operation in the mode that I'm currently
working on, does font-lock provide a way to fontify a string as if it was the
only text in the current buffer? At the moment I use
(with-temp-buffer
(erase-buffer)
(fundamental-mode)
(when ref-buffer
(cl-loop for var in '(font-lock-keywords
font-lock-keywords-only
font-lock-keywords-case-fold-search
font-lock-extra-managed-props
font-lock-mode
font-lock-set-defaults
font-lock-syntax-table
font-lock-syntactic-face-function)
do (set (make-local-variable var)
(buffer-local-value var ref-buffer))))
(setq-local font-lock-support-mode nil)
(setq-local font-lock-fontified nil)
(insert str)
(let ((font-lock-major-mode major-mode))
(font-lock-fontify-region (point-min) (point-max)))
(buffer-string))
which seems very brittle.
Thanks,
Clément.
signature.asc
Description: OpenPGP digital signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Status of font-lock-fontify-region and ways to fontify a string,
Clément Pit--Claudel <=