unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Status of font-lock-fontify-region and ways to fontify a string
@ 2016-01-06 22:54 Clément Pit--Claudel
  0 siblings, 0 replies; only message in thread
From: Clément Pit--Claudel @ 2016-01-06 22:54 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 1853 bytes --]

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.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-01-06 22:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-06 22:54 Status of font-lock-fontify-region and ways to fontify a string Clément Pit--Claudel

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).