all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Special hilighting for comments
@ 2022-12-10  2:42 Heime
  2022-12-10  6:12 ` Marcin Borkowski
  2022-12-10  8:14 ` Eli Zaretskii
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-12-10  2:42 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


I have seen that emacs-lisp-mode allows the highlighting of some specially formatted comments using strings enclosed by single quotes 'this-thing'.  This can be very useful beyond its intended use (highlighting function and variable names).  

For instance, I can use this to highlight the first comment with a different colour from the rest of the comments. 

But this special highlighting only works for function and variables names without spaces.  

So I cannot do the following to get 'A Remark here' highlighted in a different colour.

;; 'A Remark here'   
;; Some comment here
;; Another comment here
;; You are a hero

Can the use of '' be extended so I can use the highlighting more generally as described.  Or perhaps have an additional highlighting for more general things, separate from function and variable names.





^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10  2:42 Special hilighting for comments Heime
@ 2022-12-10  6:12 ` Marcin Borkowski
  2022-12-10  6:23   ` Heime
  2022-12-10  8:14 ` Eli Zaretskii
  1 sibling, 1 reply; 32+ messages in thread
From: Marcin Borkowski @ 2022-12-10  6:12 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor


On 2022-12-10, at 03:42, Heime <heimeborgia@protonmail.com> wrote:

> I have seen that emacs-lisp-mode allows the highlighting of some specially formatted comments using strings enclosed by single quotes 'this-thing'.  This can be very useful beyond its intended use (highlighting function and variable names).  
>
> For instance, I can use this to highlight the first comment with a different colour from the rest of the comments. 
>
> But this special highlighting only works for function and variables names without spaces.  
>
> So I cannot do the following to get 'A Remark here' highlighted in a different colour.
>
> ;; 'A Remark here'   
> ;; Some comment here
> ;; Another comment here
> ;; You are a hero
>
> Can the use of '' be extended so I can use the highlighting more generally as described.  Or perhaps have an additional highlighting for more general things, separate from function and variable names.

Try M-s h C-h.

Hth,

-- 
Marcin Borkowski
http://mbork.pl



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10  6:12 ` Marcin Borkowski
@ 2022-12-10  6:23   ` Heime
  2022-12-10  8:13     ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-10  6:23 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

------- Original Message -------
On Saturday, December 10th, 2022 at 6:12 AM, Marcin Borkowski <mbork@mbork.pl> wrote:


> On 2022-12-10, at 03:42, Heime heimeborgia@protonmail.com wrote:
> 
> > I have seen that emacs-lisp-mode allows the highlighting of some specially formatted comments using strings enclosed by single quotes 'this-thing'. This can be very useful beyond its intended use (highlighting function and variable names).
> > 
> > For instance, I can use this to highlight the first comment with a different colour from the rest of the comments.
> > 
> > But this special highlighting only works for function and variables names without spaces.
> > 
> > So I cannot do the following to get 'A Remark here' highlighted in a different colour.
> > 
> > ;; 'A Remark here'
> > ;; Some comment here
> > ;; Another comment here
> > ;; You are a hero
> > 
> > Can the use of '' be extended so I can use the highlighting more generally as described. Or perhaps have an additional highlighting for more general things, separate from function and variable names.
> 
> 
> Try M-s h C-h.

M-s does not do anything.




^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10  6:23   ` Heime
@ 2022-12-10  8:13     ` Eli Zaretskii
  0 siblings, 0 replies; 32+ messages in thread
From: Eli Zaretskii @ 2022-12-10  8:13 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 10 Dec 2022 06:23:10 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> > Try M-s h C-h.
> 
> M-s does not do anything.

It does, in Emacs 29 and later.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10  2:42 Special hilighting for comments Heime
  2022-12-10  6:12 ` Marcin Borkowski
@ 2022-12-10  8:14 ` Eli Zaretskii
  2022-12-10  8:30   ` Heime
  1 sibling, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-12-10  8:14 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 10 Dec 2022 02:42:45 +0000
> From: Heime <heimeborgia@protonmail.com>
> 
> I have seen that emacs-lisp-mode allows the highlighting of some specially formatted comments using strings enclosed by single quotes 'this-thing'.  This can be very useful beyond its intended use (highlighting function and variable names).  
> 
> For instance, I can use this to highlight the first comment with a different colour from the rest of the comments. 
> 
> But this special highlighting only works for function and variables names without spaces.  
> 
> So I cannot do the following to get 'A Remark here' highlighted in a different colour.
> 
> ;; 'A Remark here'   
> ;; Some comment here
> ;; Another comment here
> ;; You are a hero
> 
> Can the use of '' be extended so I can use the highlighting more generally as described.  Or perhaps have an additional highlighting for more general things, separate from function and variable names.

You can extend it if you want, but we won't, because that was
specifically intended to highlight symbols, not arbitrary text.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10  8:14 ` Eli Zaretskii
@ 2022-12-10  8:30   ` Heime
  2022-12-10  8:49     ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-10  8:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs






Sent with Proton Mail secure email.

------- Original Message -------
On Saturday, December 10th, 2022 at 8:14 AM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Sat, 10 Dec 2022 02:42:45 +0000
> > From: Heime heimeborgia@protonmail.com
> > 
> > I have seen that emacs-lisp-mode allows the highlighting of some specially formatted comments using strings enclosed by single quotes 'this-thing'. This can be very useful beyond its intended use (highlighting function and variable names).
> > 
> > For instance, I can use this to highlight the first comment with a different colour from the rest of the comments.
> > 
> > But this special highlighting only works for function and variables names without spaces.
> > 
> > So I cannot do the following to get 'A Remark here' highlighted in a different colour.
> > 
> > ;; 'A Remark here'
> > ;; Some comment here
> > ;; Another comment here
> > ;; You are a hero
> > 
> > Can the use of '' be extended so I can use the highlighting more generally as described. Or perhaps have an additional highlighting for more general things, separate from function and variable names.
> 
> 
> You can extend it if you want, but we won't, because that was
> specifically intended to highlight symbols, not arbitrary text.

Emacs is missing out on a beneficial capability beyond just highlight symbols in other programming language modes.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10  8:30   ` Heime
@ 2022-12-10  8:49     ` Eli Zaretskii
  2022-12-10 10:53       ` Heime
  0 siblings, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-12-10  8:49 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 10 Dec 2022 08:30:01 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> Emacs is missing out on a beneficial capability beyond just highlight symbols in other programming language modes.

I don't think that's true: have you tried using the capabilities in
hi-lock.el, as I suggested up-thread?  That package can let you
highlight anything.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10  8:49     ` Eli Zaretskii
@ 2022-12-10 10:53       ` Heime
  2022-12-10 11:15         ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-10 10:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

------- Original Message -------
On Saturday, December 10th, 2022 at 8:49 AM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Sat, 10 Dec 2022 08:30:01 +0000
> > From: Heime heimeborgia@protonmail.com
> > Cc: help-gnu-emacs@gnu.org
> > 
> > Emacs is missing out on a beneficial capability beyond just highlight symbols in other programming language modes.
> 
> 
> I don't think that's true: have you tried using the capabilities in
> hi-lock.el, as I suggested up-thread? That package can let you
> highlight anything.

What do I need to do?



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 10:53       ` Heime
@ 2022-12-10 11:15         ` Eli Zaretskii
  2022-12-10 11:26           ` Heime
  0 siblings, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-12-10 11:15 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 10 Dec 2022 10:53:42 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> > > Emacs is missing out on a beneficial capability beyond just highlight symbols in other programming language modes.
> > 
> > 
> > I don't think that's true: have you tried using the capabilities in
> > hi-lock.el, as I suggested up-thread? That package can let you
> > highlight anything.
> 
> What do I need to do? 

Type "M-s h l" (or "M-x highlight-lines-matching-regexp RET").



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 11:15         ` Eli Zaretskii
@ 2022-12-10 11:26           ` Heime
  2022-12-10 14:21             ` Eli Zaretskii
  2022-12-10 15:52             ` Jean Louis
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-12-10 11:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

------- Original Message -------
On Saturday, December 10th, 2022 at 11:15 AM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Sat, 10 Dec 2022 10:53:42 +0000
> > From: Heime heimeborgia@protonmail.com
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > > Emacs is missing out on a beneficial capability beyond just highlight symbols in other programming language modes.
> > > 
> > > I don't think that's true: have you tried using the capabilities in
> > > hi-lock.el, as I suggested up-thread? That package can let you
> > > highlight anything.
> > 
> > What do I need to do?
> 
> 
> Type "M-s h l" (or "M-x highlight-lines-matching-regexp RET").

How can I do it with elisp code.  Highlighting lines starting with
";; [".

Thus in elisp-mode, how to achieve the following

;; [Highlighted line]
;; Some comment 
;; Other comment

Have started with the following, whilst you suggest "highlight-lines-matching-regexp".

(defun hl-regexp ()
  (interactive)
  (highlight-regexp ";; [.*" some-face))

(defun hl-elisp ()
  (add-to-list 'auto-mode-alist '("\\.el\\'" . hi-lock-mode))
  (add-hook 'hi-lock-mode-hook 'hlregexp))







^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 11:26           ` Heime
@ 2022-12-10 14:21             ` Eli Zaretskii
  2022-12-10 14:28               ` Heime
  2022-12-10 15:52             ` Jean Louis
  1 sibling, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-12-10 14:21 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 10 Dec 2022 11:26:58 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> > Type "M-s h l" (or "M-x highlight-lines-matching-regexp RET").
> 
> How can I do it with elisp code.  Highlighting lines starting with
> ";; [".
> 
> Thus in elisp-mode, how to achieve the following
> 
> ;; [Highlighted line]
> ;; Some comment 
> ;; Other comment
> 
> Have started with the following, whilst you suggest "highlight-lines-matching-regexp".

I suggested a user command.  If you want to do it from Lisp, use the
command as a function, or use lower-level functions if that suits your
needs better.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 14:21             ` Eli Zaretskii
@ 2022-12-10 14:28               ` Heime
  0 siblings, 0 replies; 32+ messages in thread
From: Heime @ 2022-12-10 14:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

------- Original Message -------
On Saturday, December 10th, 2022 at 2:21 PM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Sat, 10 Dec 2022 11:26:58 +0000
> > From: Heime heimeborgia@protonmail.com
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > Type "M-s h l" (or "M-x highlight-lines-matching-regexp RET").
> > 
> > How can I do it with elisp code. Highlighting lines starting with
> > ";; [".
> > 
> > Thus in elisp-mode, how to achieve the following
> > 
> > ;; [Highlighted line]
> > ;; Some comment
> > ;; Other comment
> > 
> > Have started with the following, whilst you suggest "highlight-lines-matching-regexp".
> 
> 
> I suggested a user command. If you want to do it from Lisp, use the
> command as a function, or use lower-level functions if that suits your
> needs better.

Yes, I want to do it from lisp.




^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 11:26           ` Heime
  2022-12-10 14:21             ` Eli Zaretskii
@ 2022-12-10 15:52             ` Jean Louis
  2022-12-10 17:11               ` Heime
  1 sibling, 1 reply; 32+ messages in thread
From: Jean Louis @ 2022-12-10 15:52 UTC (permalink / raw)
  To: Heime; +Cc: Eli Zaretskii, help-gnu-emacs

* Heime <heimeborgia@protonmail.com> [2022-12-10 14:28]:
> > Type "M-s h l" (or "M-x highlight-lines-matching-regexp RET").
> 
> How can I do it with elisp code.  Highlighting lines starting with
> ";; [".
> 
> Thus in elisp-mode, how to achieve the following

;; [Highlighted line]

This works well:

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

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 15:52             ` Jean Louis
@ 2022-12-10 17:11               ` Heime
  2022-12-10 17:16                 ` Eli Zaretskii
  2022-12-10 19:44                 ` Jean Louis
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-12-10 17:11 UTC (permalink / raw)
  To: Jean Louis; +Cc: Eli Zaretskii, help-gnu-emacs

------- Original Message -------
On Saturday, December 10th, 2022 at 3:52 PM, Jean Louis <bugs@gnu.support> wrote:


> * Heime heimeborgia@protonmail.com [2022-12-10 14:28]:
> 
> > > Type "M-s h l" (or "M-x highlight-lines-matching-regexp RET").
> > 
> > How can I do it with elisp code. Highlighting lines starting with
> > ";; [".
> > 
> > Thus in elisp-mode, how to achieve the following
> 
> 
> ;; [Highlighted line]
> 
> This works well:
> 
> (highlight-regexp "^;; \\[.*$")

Would it be possible to change only the foreground to some specified colour? 
 




^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 17:11               ` Heime
@ 2022-12-10 17:16                 ` Eli Zaretskii
  2022-12-10 17:39                   ` Heime
  2022-12-10 19:44                 ` Jean Louis
  1 sibling, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-12-10 17:16 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 10 Dec 2022 17:11:38 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, help-gnu-emacs@gnu.org
> 
> > This works well:
> > 
> > (highlight-regexp "^;; \\[.*$")
> 
> Would it be possible to change only the foreground to some specified colour? 

Do you ever consult the built-in documentation before you ask
questions here?  Because the answer to that is right at your
fingertips: just type

  M-x customize-group RET hi-lock RET

and look there for relevant customizable settings (faces, in this
case).



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 17:16                 ` Eli Zaretskii
@ 2022-12-10 17:39                   ` Heime
  2022-12-10 17:57                     ` Thibaut Verron
  2022-12-10 18:32                     ` Eli Zaretskii
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-12-10 17:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

------- Original Message -------
On Saturday, December 10th, 2022 at 5:16 PM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Sat, 10 Dec 2022 17:11:38 +0000
> > From: Heime heimeborgia@protonmail.com
> > Cc: Eli Zaretskii eliz@gnu.org, help-gnu-emacs@gnu.org
> > 
> > > This works well:
> > > 
> > > (highlight-regexp "^;; \\[.*$")
> > 
> > Would it be possible to change only the foreground to some specified colour?
> 
> 
> Do you ever consult the built-in documentation before you ask
> questions here? Because the answer to that is right at your
> fingertips: just type
> 
> M-x customize-group RET hi-lock RET
> 
> and look there for relevant customizable settings (faces, in this
> case).

I have not worked much with faces.  There is the tutorial but it is too basic for things I want to do.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 17:39                   ` Heime
@ 2022-12-10 17:57                     ` Thibaut Verron
  2022-12-10 18:32                     ` Eli Zaretskii
  1 sibling, 0 replies; 32+ messages in thread
From: Thibaut Verron @ 2022-12-10 17:57 UTC (permalink / raw)
  To: Heime; +Cc: Eli Zaretskii, help-gnu-emacs

Le sam. 10 déc. 2022 à 18:40, Heime <heimeborgia@protonmail.com> a écrit :

> ------- Original Message -------
> On Saturday, December 10th, 2022 at 5:16 PM, Eli Zaretskii <eliz@gnu.org>
> wrote:
>
>
> > > Date: Sat, 10 Dec 2022 17:11:38 +0000
> > > From: Heime heimeborgia@protonmail.com
> > > Cc: Eli Zaretskii eliz@gnu.org, help-gnu-emacs@gnu.org
> > >
> > > > This works well:
> > > >
> > > > (highlight-regexp "^;; \\[.*$")
> > >
> > > Would it be possible to change only the foreground to some specified
> colour?
> >
> >
> > Do you ever consult the built-in documentation before you ask
> > questions here? Because the answer to that is right at your
> > fingertips: just type
> >
> > M-x customize-group RET hi-lock RET
> >
> > and look there for relevant customizable settings (faces, in this
> > case).
>
> I have not worked much with faces.  There is the tutorial but it is too
> basic for things I want to do.
>

If you mean the elisp tutorial
https://www.gnu.org/software/emacs/manual/html_node/eintr/ , you might be
the first person ever to use "basic" to refer to it.

Anyway, a tutorial can introduce you to a language, but you can't expect it
to cover everything, that's what the reference documentation is for.

Faces: https://www.gnu.org/software/emacs/manual/html_node/emacs/Faces.html


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 17:39                   ` Heime
  2022-12-10 17:57                     ` Thibaut Verron
@ 2022-12-10 18:32                     ` Eli Zaretskii
  2022-12-12  0:59                       ` Heime
  1 sibling, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-12-10 18:32 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 10 Dec 2022 17:39:34 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> > > Would it be possible to change only the foreground to some specified colour?
> > Do you ever consult the built-in documentation before you ask
> > questions here? Because the answer to that is right at your
> > fingertips: just type
> > 
> > M-x customize-group RET hi-lock RET
> > 
> > and look there for relevant customizable settings (faces, in this
> > case).
> 
> I have not worked much with faces.  There is the tutorial but it is too basic for things I want to do.

The above will present an easy-to use UI for customizing the face's
colors.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 17:11               ` Heime
  2022-12-10 17:16                 ` Eli Zaretskii
@ 2022-12-10 19:44                 ` Jean Louis
  2022-12-11  2:10                   ` Heime
  1 sibling, 1 reply; 32+ messages in thread
From: Jean Louis @ 2022-12-10 19:44 UTC (permalink / raw)
  To: Heime; +Cc: help-gnu-emacs

* 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/



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 19:44                 ` Jean Louis
@ 2022-12-11  2:10                   ` Heime
  2022-12-11  2:37                     ` Heime
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-11  2:10 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs


------- 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.




^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  2:10                   ` Heime
@ 2022-12-11  2:37                     ` Heime
  2022-12-11  4:23                       ` Jean Louis
  2022-12-11  6:54                       ` tomas
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-12-11  2:37 UTC (permalink / raw)
  To: Heime; +Cc: Jean Louis, help-gnu-emacs

------- 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







^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  2:37                     ` Heime
@ 2022-12-11  4:23                       ` Jean Louis
  2022-12-11  5:06                         ` Heime
  2022-12-11  6:54                       ` tomas
  1 sibling, 1 reply; 32+ messages in thread
From: Jean Louis @ 2022-12-11  4:23 UTC (permalink / raw)
  To: Heime; +Cc: help-gnu-emacs

* Heime <heimeborgia@protonmail.com> [2022-12-11 05:38]:
> Would you know the problem with the following regexp

;; [something] other things

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

The above works well.

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  4:23                       ` Jean Louis
@ 2022-12-11  5:06                         ` Heime
  2022-12-11  9:06                           ` Jean Louis
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-11  5:06 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

------- Original Message -------
On Sunday, December 11th, 2022 at 4:23 AM, Jean Louis <bugs@gnu.support> wrote:


> * Heime heimeborgia@protonmail.com [2022-12-11 05:38]:
> 
> > Would you know the problem with the following regexp
> 
> 
> ;; [something] other things
> 
> (highlight-regexp "^;; \\[.*$")
> 
> The above works well. --> Jean

I would like to use a sub-expresion to highlight "[something]" only




^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  2:37                     ` Heime
  2022-12-11  4:23                       ` Jean Louis
@ 2022-12-11  6:54                       ` tomas
  2022-12-11  6:59                         ` Heime
  1 sibling, 1 reply; 32+ messages in thread
From: tomas @ 2022-12-11  6:54 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 312 bytes --]

On Sun, Dec 11, 2022 at 02:37:38AM +0000, Heime wrote:


> Would you know the problem with the following regexp
> 
> "^;; \\[.+\\].*$"
> 
> It fails to match
> 
> ;; [something] other things

Worksforme. At least if the first semicolon is actually at the
start of a line, that is.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  6:54                       ` tomas
@ 2022-12-11  6:59                         ` Heime
  2022-12-11  7:24                           ` tomas
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-11  6:59 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs


------- Original Message -------
On Sunday, December 11th, 2022 at 6:54 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:


> On Sun, Dec 11, 2022 at 02:37:38AM +0000, Heime wrote:
> 
> > Would you know the problem with the following regexp
> > 
> > "^;; \\[.+\\].*$"
> > 
> > It fails to match
> > 
> > ;; [something] other things
> 
> 
> Worksforme. At least if the first semicolon is actually at the
> start of a line, that is.
> 
> Cheers
> --
> t

Yes it works.  I am trying to use subexp in highlight-regexp.
To match "^;; \\[.+\\].*$" but highlight only the "\\[.+\\]" part.





^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  6:59                         ` Heime
@ 2022-12-11  7:24                           ` tomas
  2022-12-11  7:33                             ` Heime
  0 siblings, 1 reply; 32+ messages in thread
From: tomas @ 2022-12-11  7:24 UTC (permalink / raw)
  To: Heime; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 867 bytes --]

On Sun, Dec 11, 2022 at 06:59:32AM +0000, Heime wrote:
> 
> ------- Original Message -------
> On Sunday, December 11th, 2022 at 6:54 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:
> 
> 
> > On Sun, Dec 11, 2022 at 02:37:38AM +0000, Heime wrote:
> > 
> > > Would you know the problem with the following regexp
> > > 
> > > "^;; \\[.+\\].*$"
> > > 
> > > It fails to match
> > > 
> > > ;; [something] other things
> > 
> > 
> > Worksforme. At least if the first semicolon is actually at the
> > start of a line, that is.
> > 
> > Cheers
> > --
> > t
> 
> Yes it works.  I am trying to use subexp in highlight-regexp.
> To match "^;; \\[.+\\].*$" but highlight only the "\\[.+\\]" part.

Aha. Read again the documentation string of `hightlight-regexp'.
Is there any part in there you don't understand? What about
SUBEXP?

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  7:24                           ` tomas
@ 2022-12-11  7:33                             ` Heime
  2022-12-11  7:47                               ` tomas
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-11  7:33 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs


------- Original Message -------
On Sunday, December 11th, 2022 at 7:24 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:


> On Sun, Dec 11, 2022 at 06:59:32AM +0000, Heime wrote:
> 
> > ------- Original Message -------
> > On Sunday, December 11th, 2022 at 6:54 AM, tomas@tuxteam.de tomas@tuxteam.de wrote:
> > 
> > > On Sun, Dec 11, 2022 at 02:37:38AM +0000, Heime wrote:
> > > 
> > > > Would you know the problem with the following regexp
> > > > 
> > > > "^;; \\[.+\\].*$"
> > > > 
> > > > It fails to match
> > > > 
> > > > ;; [something] other things
> > > 
> > > Worksforme. At least if the first semicolon is actually at the
> > > start of a line, that is.
> > > 
> > > Cheers
> > > --
> > > t
> > 
> > Yes it works. I am trying to use subexp in highlight-regexp.
> > To match "^;; \\[.+\\].*$" but highlight only the "\\[.+\\]" part.
> 
> 
> Aha. Read again the documentation string of `hightlight-regexp'.
> Is there any part in there you don't understand? What about
> SUBEXP?

Right.  Have done 

  (highlight-regexp "^;; \\[.+\\].*$" 'elf-face "\\[.+\\]")

which does not get the highlighting.

And the following, also did nothing

  (highlight-regexp "^;; \\[.+\\].*$" 'elf-face "^;; \\[.+\\].*$")

 






^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  7:33                             ` Heime
@ 2022-12-11  7:47                               ` tomas
  2022-12-11  7:52                                 ` Heime
  0 siblings, 1 reply; 32+ messages in thread
From: tomas @ 2022-12-11  7:47 UTC (permalink / raw)
  To: Heime; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2045 bytes --]

On Sun, Dec 11, 2022 at 07:33:19AM +0000, Heime wrote:
> 
> ------- Original Message -------
> On Sunday, December 11th, 2022 at 7:24 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:
> 
> 
> > On Sun, Dec 11, 2022 at 06:59:32AM +0000, Heime wrote:
> > 
> > > ------- Original Message -------
> > > On Sunday, December 11th, 2022 at 6:54 AM, tomas@tuxteam.de tomas@tuxteam.de wrote:
> > > 
> > > > On Sun, Dec 11, 2022 at 02:37:38AM +0000, Heime wrote:
> > > > 
> > > > > Would you know the problem with the following regexp
> > > > > 
> > > > > "^;; \\[.+\\].*$"
> > > > > 
> > > > > It fails to match
> > > > > 
> > > > > ;; [something] other things
> > > > 
> > > > Worksforme. At least if the first semicolon is actually at the
> > > > start of a line, that is.
> > > > 
> > > > Cheers
> > > > --
> > > > t
> > > 
> > > Yes it works. I am trying to use subexp in highlight-regexp.
> > > To match "^;; \\[.+\\].*$" but highlight only the "\\[.+\\]" part.
> > 
> > 
> > Aha. Read again the documentation string of `hightlight-regexp'.
> > Is there any part in there you don't understand? What about
> > SUBEXP?
> 
> Right.  Have done 
> 
>   (highlight-regexp "^;; \\[.+\\].*$" 'elf-face "\\[.+\\]")
> 
> which does not get the highlighting.

[...]

Ah. There's your misunderstanding. Read the section about
"grouping constructs" in regular expressions. The short
version is that this argument SUBGROUP refers to the count
number of that subexpression, starting with 1.

So you need to group the part you are interested in in
your regexp (the subexpression) with \(...\) (don't forget
the extra backslash for the string syntax) like so:

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

Now this is the first subgroup in your regexp (actually, the
only one). You refer to it with 1. This might work

   (highlight-regexp "^;; \\(\\[.+\\]\\).*$" 'elf-face 1)

Now read the section on "\( ... \)" in the chapter "Backslash
constructs in Regular Expressions". The others are useful,
too :)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  7:47                               ` tomas
@ 2022-12-11  7:52                                 ` Heime
  2022-12-11  8:55                                   ` tomas
  0 siblings, 1 reply; 32+ messages in thread
From: Heime @ 2022-12-11  7:52 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

------- Original Message -------
On Sunday, December 11th, 2022 at 7:47 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:


> On Sun, Dec 11, 2022 at 07:33:19AM +0000, Heime wrote:
> 
> > ------- Original Message -------
> > On Sunday, December 11th, 2022 at 7:24 AM, tomas@tuxteam.de tomas@tuxteam.de wrote:
> > 
> > > On Sun, Dec 11, 2022 at 06:59:32AM +0000, Heime wrote:
> > > 
> > > > ------- Original Message -------
> > > > On Sunday, December 11th, 2022 at 6:54 AM, tomas@tuxteam.de tomas@tuxteam.de wrote:
> > > > 
> > > > > On Sun, Dec 11, 2022 at 02:37:38AM +0000, Heime wrote:
> > > > > 
> > > > > > Would you know the problem with the following regexp
> > > > > > 
> > > > > > "^;; \\[.+\\].*$"
> > > > > > 
> > > > > > It fails to match
> > > > > > 
> > > > > > ;; [something] other things
> > > > > 
> > > > > Worksforme. At least if the first semicolon is actually at the
> > > > > start of a line, that is.
> > > > > 
> > > > > Cheers
> > > > > --
> > > > > t
> > > > 
> > > > Yes it works. I am trying to use subexp in highlight-regexp.
> > > > To match "^;; \\[.+\\].*$" but highlight only the "\\[.+\\]" part.
> > > 
> > > Aha. Read again the documentation string of `hightlight-regexp'.
> > > Is there any part in there you don't understand? What about
> > > SUBEXP?
> > 
> > Right. Have done
> > 
> > (highlight-regexp "^;; \\[.+\\].*$" 'elf-face "\\[.+\\]")
> > 
> > which does not get the highlighting.
> 
> 
> [...]
> 
> Ah. There's your misunderstanding. Read the section about
> "grouping constructs" in regular expressions. The short
> version is that this argument SUBGROUP refers to the count
> number of that subexpression, starting with 1.
> 
> So you need to group the part you are interested in in
> your regexp (the subexpression) with \(...\) (don't forget
> the extra backslash for the string syntax) like so:
> 
> "^;; \\(\\[.+\\]\\).$"
> 
> Now this is the first subgroup in your regexp (actually, the
> only one). You refer to it with 1. This might work
> 
> (highlight-regexp "^;; \\(\\[.+\\]\\).$" 'elf-face 1)
> 
> Now read the section on "\( ... \)" in the chapter "Backslash
> constructs in Regular Expressions". The others are useful,
> too :)

Success.  Thank you so very much.  I now understand how it works.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  7:52                                 ` Heime
@ 2022-12-11  8:55                                   ` tomas
  0 siblings, 0 replies; 32+ messages in thread
From: tomas @ 2022-12-11  8:55 UTC (permalink / raw)
  To: Heime; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 172 bytes --]

On Sun, Dec 11, 2022 at 07:52:53AM +0000, Heime wrote:

[...]

> Success.  Thank you so very much.  I now understand how it works.

Glad it helped

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-11  5:06                         ` Heime
@ 2022-12-11  9:06                           ` Jean Louis
  0 siblings, 0 replies; 32+ messages in thread
From: Jean Louis @ 2022-12-11  9:06 UTC (permalink / raw)
  To: Heime; +Cc: help-gnu-emacs

* Heime <heimeborgia@protonmail.com> [2022-12-11 08:06]:

;; [something] other things

(highlight-regexp (rx line-start ";; " "[" (one-or-more not-newline) "]"))

or you want only "something" to be highlighted?

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: Special hilighting for comments
  2022-12-10 18:32                     ` Eli Zaretskii
@ 2022-12-12  0:59                       ` Heime
  0 siblings, 0 replies; 32+ messages in thread
From: Heime @ 2022-12-12  0:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

------- Original Message -------
On Saturday, December 10th, 2022 at 6:32 PM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Sat, 10 Dec 2022 17:39:34 +0000
> > From: Heime heimeborgia@protonmail.com
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > > Would it be possible to change only the foreground to some specified colour?
> > > > Do you ever consult the built-in documentation before you ask
> > > > questions here? Because the answer to that is right at your
> > > > fingertips: just type
> > > 
> > > M-x customize-group RET hi-lock RET
> > > 
> > > and look there for relevant customizable settings (faces, in this
> > > case).
> > 
> > I have not worked much with faces. There is the tutorial but it is too basic for things I want to do.
> 
> 
> The above will present an easy-to use UI for customizing the face's
> colors.

There is "font-lock-add-keywords" and the variable "font-lock-keywords".  Prepending in the OVERRIDE field, a new face will be seen on top of the normal comment face.

How does the "font-lock-add-keywords" compare to "hi-lock" ?





^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2022-12-12  0:59 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-10  2:42 Special hilighting for comments Heime
2022-12-10  6:12 ` Marcin Borkowski
2022-12-10  6:23   ` Heime
2022-12-10  8:13     ` Eli Zaretskii
2022-12-10  8:14 ` Eli Zaretskii
2022-12-10  8:30   ` Heime
2022-12-10  8:49     ` Eli Zaretskii
2022-12-10 10:53       ` Heime
2022-12-10 11:15         ` Eli Zaretskii
2022-12-10 11:26           ` Heime
2022-12-10 14:21             ` Eli Zaretskii
2022-12-10 14:28               ` Heime
2022-12-10 15:52             ` Jean Louis
2022-12-10 17:11               ` Heime
2022-12-10 17:16                 ` Eli Zaretskii
2022-12-10 17:39                   ` Heime
2022-12-10 17:57                     ` Thibaut Verron
2022-12-10 18:32                     ` Eli Zaretskii
2022-12-12  0:59                       ` Heime
2022-12-10 19:44                 ` Jean Louis
2022-12-11  2:10                   ` Heime
2022-12-11  2:37                     ` Heime
2022-12-11  4:23                       ` Jean Louis
2022-12-11  5:06                         ` Heime
2022-12-11  9:06                           ` Jean Louis
2022-12-11  6:54                       ` tomas
2022-12-11  6:59                         ` Heime
2022-12-11  7:24                           ` tomas
2022-12-11  7:33                             ` Heime
2022-12-11  7:47                               ` tomas
2022-12-11  7:52                                 ` Heime
2022-12-11  8:55                                   ` tomas

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.