help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add syntax-highlighting to a Help buffer?


From: Emanuel Berg
Subject: Re: How to add syntax-highlighting to a Help buffer?
Date: Sat, 04 Jul 2015 17:09:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> help-mode doesn't use font-lock. It directly attaches
> face text properties to the buffer text.
> If font-lock-mode fontifies such a buffer (it
> doesn't as long as font-lock-keywords is nil even
> when it is active), all face text properties get
> ignored by the display engine.

Yes, however that doesn't mean we can't use it the
same way we are used to. See the below solution.

One question is, why doesn't help-mode do this the
customary way?

> Note that there is a font-lock-face text property
> existing as well.

Yes - see line 17 in the source below, in the original
file. It is set to nil.

Here is is a dump that shows this works:

    http://user.it.uu.se/~embe8573/dumps/color-help.png

Here is the source that does it:

    http://user.it.uu.se/~embe8573/conf/emacs-init/help-font-lock.el

Here is the source that does it, only yanked:

(defvar help-font-lock-keywords
  '(
    ("interactive"  . 'font-lock-regexp-grouping-backslash)
    ("autoloaded"   .  font-lock-function-name-face)
    ("compiled"     .  font-lock-doc-face)
    ("Lisp"         .  font-lock-variable-name-face)
    ("function"     .  font-lock-builtin-face)
))

(defun help-custom-font-lock ()
  (interactive)
  (let ((font-lock-unfontify-region-function
         (lambda (start end)
           (remove-text-properties (point-min) (point-max)
                                   '(font-lock-face nil)))))
    (font-lock-unfontify-buffer)
    (set (make-local-variable 'font-lock-defaults)
         '(help-font-lock-keywords t))
    (font-lock-fontify-buffer)))

(add-hook 'help-mode-hook 'help-custom-font-lock)

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

[Prev in Thread] Current Thread [Next in Thread]