* How to add syntax highlighting inside comments for an existing major mode
@ 2007-10-11 9:24 Julien Barnier
2007-10-11 10:16 ` Michaël Cadilhac
0 siblings, 1 reply; 4+ messages in thread
From: Julien Barnier @ 2007-10-11 9:24 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
I am trying to customize some syntax highlighting for an existing
major mode. What I would like to do is to display different type of
comments with different faces.
In this mode, comments are lines that begins with one or several
«#». What I would like to display differently those which begin with
«#####» than those which begin with «####», etc.
I tried the 'font-lock-add-keywords' way, but it doesn't seem to work
inside comments, with something like that :
(font-lock-add-keywords 'ess-mode
'(("^##### .*$" . my-beautiful-face)))
Do you have any idea for a proper way to do such a thing ?
Thanks in advance for any help.
--
Julien
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to add syntax highlighting inside comments for an existing major mode
2007-10-11 9:24 How to add syntax highlighting inside comments for an existing major mode Julien Barnier
@ 2007-10-11 10:16 ` Michaël Cadilhac
0 siblings, 0 replies; 4+ messages in thread
From: Michaël Cadilhac @ 2007-10-11 10:16 UTC (permalink / raw)
To: Julien Barnier; +Cc: help-gnu-emacs
[-- Attachment #1.1: Type: text/plain, Size: 780 bytes --]
Julien Barnier <jbarnier@ens-lsh.fr> writes:
> In this mode, comments are lines that begins with one or several
> «#». What I would like to display differently those which begin with
> «#####» than those which begin with «####», etc.
The simplest way to achieve that is the following, IMO :
(add-hook 'your-mode-hook
(lambda ()
(highlight-regexp "^# .*" 'hi-blue)
(highlight-regexp "^## .*" 'hi-red-b)))
--
| Michaël `Micha' Cadilhac | In a World without Walls and Fences, |
| http://michael.cadilhac.name | who needs Windows and Gates? |
| JID/MSN: | -- Dino Esposito |
`---- michael.cadilhac@gmail.com | - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to add syntax highlighting inside comments for an existing major mode
[not found] <mailman.1943.1192095336.18990.help-gnu-emacs@gnu.org>
@ 2007-10-11 11:49 ` Johan Bockgård
0 siblings, 0 replies; 4+ messages in thread
From: Johan Bockgård @ 2007-10-11 11:49 UTC (permalink / raw)
To: help-gnu-emacs
Julien Barnier <jbarnier@ens-lsh.fr> writes:
> In this mode, comments are lines that begins with one or several
> «#». What I would like to display differently those which begin with
> «#####» than those which begin with «####», etc.
>
> I tried the 'font-lock-add-keywords' way, but it doesn't seem to work
> inside comments, with something like that :
>
> (font-lock-add-keywords 'ess-mode
> '(("^##### .*$" . my-beautiful-face)))
>
(info "(elisp)Search-based Fontification")
`(MATCHER . SUBEXP-HIGHLIGHTER)'
In this kind of element, SUBEXP-HIGHLIGHTER is a list which
specifies how to highlight matches found by MATCHER. It has the
form:
(SUBEXP FACESPEC [[OVERRIDE [LAXMATCH]])
The CAR, SUBEXP, is an integer specifying which subexpression of
the match to fontify (0 means the entire matching text). The
second subelement, FACESPEC, is an expression whose value
specifies the face, as described above.
The last two values in SUBEXP-HIGHLIGHTER, OVERRIDE and LAXMATCH,
are optional flags. If OVERRIDE is `t', this element can override
existing fontification made by previous elements of
`font-lock-keywords'. If it is `keep', then each character is
fontified if it has not been fontified already by some other
element. If it is `prepend', the face specified by FACESPEC is
added to the beginning of the `font-lock-face' property. If it is
`append', the face is added to the end of the `font-lock-face'
property.
[...]
Here are some examples of elements of this kind, and what they do:
;; Highlight occurrences of either `foo' or `bar', using
;; `foo-bar-face', even if they have already been highlighted.
;; `foo-bar-face' should be a variable whose value is a face.
("foo\\|bar" 0 foo-bar-face t)
--
Johan Bockgård
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to add syntax highlighting inside comments for an existing major mode
@ 2007-10-11 12:06 martin rudalics
0 siblings, 0 replies; 4+ messages in thread
From: martin rudalics @ 2007-10-11 12:06 UTC (permalink / raw)
To: jbarnier; +Cc: help-gnu-emacs
> I am trying to customize some syntax highlighting for an existing
> major mode. What I would like to do is to display different type of
> comments with different faces.
>
> In this mode, comments are lines that begins with one or several
> «#». What I would like to display differently those which begin with
> «#####» than those which begin with «####», etc.
>
> I tried the 'font-lock-add-keywords' way, but it doesn't seem to work
> inside comments, with something like that :
>
> (font-lock-add-keywords 'ess-mode
> '(("^##### .*$" . my-beautiful-face)))
>
> Do you have any idea for a proper way to do such a thing ?
Write your own `font-lock-syntactic-face-function' and do
(setq font-lock-defaults
'(...
(font-lock-syntactic-face-function
. my-font-lock-syntactic-face-function))))
(defun my-font-lock-syntactic-face-function (state)
(if (nth 3 state)
(...)
;; Here investigate STATE and decide which face to use.
))
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-10-11 12:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-11 9:24 How to add syntax highlighting inside comments for an existing major mode Julien Barnier
2007-10-11 10:16 ` Michaël Cadilhac
[not found] <mailman.1943.1192095336.18990.help-gnu-emacs@gnu.org>
2007-10-11 11:49 ` Johan Bockgård
-- strict thread matches above, loose matches on Subject: below --
2007-10-11 12:06 martin rudalics
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).