all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: Status of font-lock-fontify-region and ways to fontify a string
Date: Wed, 6 Jan 2016 17:54:20 -0500	[thread overview]
Message-ID: <568D9B1C.2040200@gmail.com> (raw)

[-- 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 --]

                 reply	other threads:[~2016-01-06 22:54 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=568D9B1C.2040200@gmail.com \
    --to=clement.pit@gmail.com \
    --cc=emacs-devel@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.