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

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

Re: Special hilighting for comments


From: Jean Louis
Subject: Re: Special hilighting for comments
Date: Sat, 10 Dec 2022 22:44:33 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Heime <heimeborgia@protonmail.com> [2022-12-10 20:12]:

;; [Highlighted line]

> > 
> > This works well:
> > 
> > (highlight-regexp "^;; \\[.*$")
> 
> Would it be possible to change only the foreground to some specified
> colour? 

Always use {C-h f FUNCTION-NAME} to find description of the function.

{C-h f highlight-regexp RET} tells you:

(highlight-regexp REGEXP &optional FACE SUBEXP LIGHTER)

Set face of each match of REGEXP to FACE.
Interactively, prompt for REGEXP using ‘read-regexp’, then FACE.
Use the global history list for FACE.  Limit face setting to the
corresponding SUBEXP (interactively, the prefix argument) of REGEXP.
If SUBEXP is omitted or nil, the entire REGEXP is highlighted.

That means you can use FACE for which you may define foreground and
background.

To find some interesting face I did following:

{M-x list-faces-display RET}

then I found one like 'custom-invalid and did following:

(highlight-regexp "^;; \\[.*$" 'custom-invalid)

So that one 

;; [Highlights this line]

To define your special face:

(info "(elisp) Defining Faces")

Use the function `defface'. Here is example from Emacs library:

(defface ansi-color-black
  '((t :foreground "black" :background "black"))
  "Face used to render black color code."
  :group 'ansi-colors
  :version "28.1")

Now that means it should not be hard to replicate it and create your
own face with foreground and background and then to use the function
`highlight-regexp' as above shown or as:

(highlight-regexp "^;; \\[.*$" 'my-face)

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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