From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: Feature request/RFC: proper highlighting of code embedded in comments
Date: Mon, 17 Oct 2016 10:25:51 -0400 [thread overview]
Message-ID: <a454a5bd-19f0-f396-143a-54190d4b7ff3@gmail.com> (raw)
In-Reply-To: <jwvh98bdt50.fsf-monnier+gmane.emacs.devel@gnu.org>
[-- Attachment #1.1: Type: text/plain, Size: 2240 bytes --]
On 2016-10-17 09:12, Stefan Monnier wrote:
>> (font-lock-add-keywords nil '(("^ *>>> \\(.*\\)" (0
>> (indirect-font-lock-highlighter 1 'python-mode)))))
>
> IIUC you additionally want to handle the "... " lines.
Yup; this was just a POC :)
>> Stefan (and emacs-devel!), do you think I should add this to ELPA?
>
> Feel free.
Will do it soon!
>> Are there downsides I should be aware of?
>
> The usual:
> - running the major mode might run "side-effecting code" from the user's
> hook. I consider it a bug in the user's setup, but it does happen.
> - it fails to take into account local modifications of the font-lock rules.
This second point is interesting. I ran into this issue with company-coq. The problem was that entering the coq major mode took a long time (maybe .2 seconds?), so fontifying small things on the fly was slow. I ended up copying font-lock related variables. Something like
(defconst company-coq--font-lock-vars '(font-lock-keywords
font-lock-keywords-only
font-lock-keywords-case-fold-search
font-lock-syntax-table
font-lock-syntactic-face-function)
"Font-lock variables that influence fontification.")
(defun company-coq--fontify-buffer-with (&optional ref-buffer)
"Fontify current buffer according to settings in REF-BUFFER."
(cl-loop for var in company-coq--font-lock-vars
do (set (make-local-variable var)
(buffer-local-value var ref-buffer)))
(ignore-errors
;; Some modes, such as whitespace-mode, rely on buffer-local state to do
;; their fontification. Thus copying only font-lock variables is not
;; enough; one would need to copy these modes private variables as well.
;; See GH-124.
(font-lock-default-fontify-region (point-min) (point-max) nil)))
But this is a bit broken, because fontification rules can run essentially anything. It would be nice to have a feature like "fontify as if this code was at position 0 in this buffer". I don't know whether it would make sense.
Cheers,
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
prev parent reply other threads:[~2016-10-17 14:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-15 15:19 Feature request/RFC: proper highlighting of code embedded in comments Clément Pit--Claudel
2016-10-15 20:22 ` Dmitry Gutov
2016-10-15 21:21 ` Clément Pit--Claudel
2016-10-16 17:42 ` Stefan Monnier
2016-10-16 21:05 ` Clément Pit--Claudel
2016-10-17 13:02 ` Stefan Monnier
2016-10-17 14:19 ` Clément Pit--Claudel
2016-10-16 21:10 ` Clément Pit--Claudel
2016-10-17 13:12 ` Stefan Monnier
2016-10-17 14:25 ` Clément Pit--Claudel [this message]
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=a454a5bd-19f0-f396-143a-54190d4b7ff3@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.