[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Feature request/RFC: proper highlighting of code embedded in comment
Re: Feature request/RFC: proper highlighting of code embedded in comments
Mon, 17 Oct 2016 10:25:51 -0400
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0
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 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)))
;; 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.
Description: OpenPGP digital signature