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: Heime
Subject: Re: Special hilighting for comments
Date: Sun, 11 Dec 2022 02:37:38 +0000

------- Original Message -------
On Sunday, December 11th, 2022 at 2:10 AM, Heime <heimeborgia@protonmail.com> 
wrote:


> ------- Original Message -------
> On Saturday, December 10th, 2022 at 7:44 PM, Jean Louis bugs@gnu.support 
> wrote:
> 
> 
> 
> > * 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
> 
> 
> Made my own face with your help.

Would you know the problem with the following regexp

"^;; \\[.+\\].*$"

It fails to match

;; [something] other things







reply via email to

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