unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* New function: rcd-highlight-list
@ 2021-05-18 17:08 Jean Louis
  2021-05-18 17:27 ` tomas
  0 siblings, 1 reply; 10+ messages in thread
From: Jean Louis @ 2021-05-18 17:08 UTC (permalink / raw)
  To: Help GNU Emacs


(defun rcd-highlight-list (list)
  "Uses LIST to highlight strings in buffer."
  (hi-lock-mode)
  (let* ((list (delete "" list))
	(highlights hi-lock-face-defaults))
    (while list
      (highlight-regexp (pop list) (pop highlights)))))

Just feed to this function a list of strings to highlight:

(rcd-highlight-list '("just" "to" "function" "list" "strings" "highlight"))

or use some highlighted tags in every text mode:

(rcd-highlight-list '("TODO" "DONE" "DELEGATED"))

or add it to some mode:

(add-hook 'mail-mode-hook
          (lambda ()
            (rcd-highlight-list '("TODO" "DONE" "DELEGATED" "To:" "Subject:"))))




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

* Re: New function: rcd-highlight-list
  2021-05-18 17:08 New function: rcd-highlight-list Jean Louis
@ 2021-05-18 17:27 ` tomas
  2021-05-18 17:43   ` Jean Louis
  0 siblings, 1 reply; 10+ messages in thread
From: tomas @ 2021-05-18 17:27 UTC (permalink / raw)
  To: help-gnu-emacs

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

On Tue, May 18, 2021 at 08:08:29PM +0300, Jean Louis wrote:
> 
> (defun rcd-highlight-list (list)
>   "Uses LIST to highlight strings in buffer."
>   (hi-lock-mode)
>   (let* ((list (delete "" list))
> 	(highlights hi-lock-face-defaults))
>     (while list
>       (highlight-regexp (pop list) (pop highlights)))))
> 
> Just feed to this function a list of strings to highlight:

What happens if one of the strings is ".*"?

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: New function: rcd-highlight-list
  2021-05-18 17:27 ` tomas
@ 2021-05-18 17:43   ` Jean Louis
  2021-05-18 18:47     ` tomas
  0 siblings, 1 reply; 10+ messages in thread
From: Jean Louis @ 2021-05-18 17:43 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

* tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-18 20:28]:
> On Tue, May 18, 2021 at 08:08:29PM +0300, Jean Louis wrote:
> > 
> > (defun rcd-highlight-list (list)
> >   "Uses LIST to highlight strings in buffer."
> >   (hi-lock-mode)
> >   (let* ((list (delete "" list))
> > 	(highlights hi-lock-face-defaults))
> >     (while list
> >       (highlight-regexp (pop list) (pop highlights)))))
> > 
> > Just feed to this function a list of strings to highlight:
> 
> What happens if one of the strings is ".*"?

Yes, it is not for all circumstances. It will also not support too
many keywords as it uses hi-lock-face-defaults list

-- 
Jean

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

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




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

* Re: New function: rcd-highlight-list
  2021-05-18 17:43   ` Jean Louis
@ 2021-05-18 18:47     ` tomas
  2021-05-18 20:13       ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-05-18 20:14       ` Jean Louis
  0 siblings, 2 replies; 10+ messages in thread
From: tomas @ 2021-05-18 18:47 UTC (permalink / raw)
  To: help-gnu-emacs

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

On Tue, May 18, 2021 at 08:43:21PM +0300, Jean Louis wrote:
> * tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-18 20:28]:
> > On Tue, May 18, 2021 at 08:08:29PM +0300, Jean Louis wrote:
> > > 
> > > (defun rcd-highlight-list (list)
> > >   "Uses LIST to highlight strings in buffer."
> > >   (hi-lock-mode)
> > >   (let* ((list (delete "" list))
> > > 	(highlights hi-lock-face-defaults))
> > >     (while list
> > >       (highlight-regexp (pop list) (pop highlights)))))
> > > 
> > > Just feed to this function a list of strings to highlight:
> > 
> > What happens if one of the strings is ".*"?
> 
> Yes, it is not for all circumstances. It will also not support too
> many keywords as it uses hi-lock-face-defaults list

Perhaps the function `regexp-quote' is built for you :)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: New function: rcd-highlight-list
  2021-05-18 18:47     ` tomas
@ 2021-05-18 20:13       ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-05-19  7:52         ` tomas
  2021-05-18 20:14       ` Jean Louis
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-05-18 20:13 UTC (permalink / raw)
  To: help-gnu-emacs

tomas@tuxteam.de [2021-05-18 20:47:48] wrote:
> On Tue, May 18, 2021 at 08:43:21PM +0300, Jean Louis wrote:
>> * tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-18 20:28]:
>> > On Tue, May 18, 2021 at 08:08:29PM +0300, Jean Louis wrote:
>> > > 
>> > > (defun rcd-highlight-list (list)
>> > >   "Uses LIST to highlight strings in buffer."
>> > >   (hi-lock-mode)
>> > >   (let* ((list (delete "" list))
>> > > 	(highlights hi-lock-face-defaults))
>> > >     (while list
>> > >       (highlight-regexp (pop list) (pop highlights)))))
>> > > 
>> > > Just feed to this function a list of strings to highlight:
>> > 
>> > What happens if one of the strings is ".*"?
>> 
>> Yes, it is not for all circumstances. It will also not support too
>> many keywords as it uses hi-lock-face-defaults list
>
> Perhaps the function `regexp-quote' is built for you :)

I think you mistyped `regexp-opt`.


        Stefan




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

* Re: New function: rcd-highlight-list
  2021-05-18 18:47     ` tomas
  2021-05-18 20:13       ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-05-18 20:14       ` Jean Louis
  1 sibling, 0 replies; 10+ messages in thread
From: Jean Louis @ 2021-05-18 20:14 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

* tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-18 22:06]:
> > Yes, it is not for all circumstances. It will also not support too
> > many keywords as it uses hi-lock-face-defaults list
> 
> Perhaps the function `regexp-quote' is built for you :)

Good to know how to avoid ".*" regexp problems.

(defun rcd-highlight-list (list)
  "Uses LIST to highlight strings in buffer."
  (hi-lock-mode)
  (let* ((list (delete "" list))
	(highlights hi-lock-face-defaults))
    (while list
      (highlight-regexp (regexp-quote (pop list)) (pop highlights)))))

(rcd-highlight-list '("regexp-quote" ".*")) ⇒ it works well!


-- 
Jean

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

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




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

* Re: New function: rcd-highlight-list
  2021-05-18 20:13       ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-05-19  7:52         ` tomas
  2021-05-19 10:15           ` Yuri Khan
  2021-05-19 10:27           ` Jean Louis
  0 siblings, 2 replies; 10+ messages in thread
From: tomas @ 2021-05-19  7:52 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

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

On Tue, May 18, 2021 at 04:13:56PM -0400, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
> tomas@tuxteam.de [2021-05-18 20:47:48] wrote:
> > On Tue, May 18, 2021 at 08:43:21PM +0300, Jean Louis wrote:
> >> * tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-18 20:28]:
> >> > On Tue, May 18, 2021 at 08:08:29PM +0300, Jean Louis wrote:
> >> > > 
> >> > > (defun rcd-highlight-list (list)
> >> > >   "Uses LIST to highlight strings in buffer."
> >> > >   (hi-lock-mode)
> >> > >   (let* ((list (delete "" list))
> >> > > 	(highlights hi-lock-face-defaults))
> >> > >     (while list
> >> > >       (highlight-regexp (pop list) (pop highlights)))))
> >> > > 
> >> > > Just feed to this function a list of strings to highlight:
> >> > 
> >> > What happens if one of the strings is ".*"?
> >> 
> >> Yes, it is not for all circumstances. It will also not support too
> >> many keywords as it uses hi-lock-face-defaults list
> >
> > Perhaps the function `regexp-quote' is built for you :)
> 
> I think you mistyped `regexp-opt`.

Always taking things to the next level.

But yes, you're right: the whole while loop above would collapse
in a puff of pink smoke or something ;-)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: New function: rcd-highlight-list
  2021-05-19  7:52         ` tomas
@ 2021-05-19 10:15           ` Yuri Khan
  2021-05-19 10:31             ` tomas
  2021-05-19 10:27           ` Jean Louis
  1 sibling, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2021-05-19 10:15 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs, Stefan Monnier

On Wed, 19 May 2021 at 14:53, <tomas@tuxteam.de> wrote:

> > >> > >     (while list
> > >> > >       (highlight-regexp (pop list) (pop highlights)))))

> > > Perhaps the function `regexp-quote' is built for you :)
> >
> > I think you mistyped `regexp-opt`.
>
> Always taking things to the next level.
>
> But yes, you're right: the whole while loop above would collapse
> in a puff of pink smoke or something ;-)

Not exactly: the while loop above generates puffs of pink, yellow,
green, blue, and black smoke, so you’d lose functionality if you
collapsed it to a single (highlight-regexp (regexp-opt …) …).



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

* Re: New function: rcd-highlight-list
  2021-05-19  7:52         ` tomas
  2021-05-19 10:15           ` Yuri Khan
@ 2021-05-19 10:27           ` Jean Louis
  1 sibling, 0 replies; 10+ messages in thread
From: Jean Louis @ 2021-05-19 10:27 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs, Stefan Monnier

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

* tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-19 10:54]:
> Always taking things to the next level.
> 
> But yes, you're right: the whole while loop above would collapse
> in a puff of pink smoke or something ;-)

(rcd-highlight-list '("But" "yes," "you're" "right:" "the" "whole" "while" "loop" "above" "would" "collapse" "in" "a" "puff" "of" "pink" "smoke" "or" "something" ";-)" "Jean" "Take" "action" "in" "Free" "Software" "Foundation" "campaigns"))

Picture tells that it keeps highlighting more or less yellow.

-- 
Jean

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

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/


[-- Attachment #2: 2021-05-19-13:26:06.png --]
[-- Type: image/png, Size: 136635 bytes --]

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

* Re: New function: rcd-highlight-list
  2021-05-19 10:15           ` Yuri Khan
@ 2021-05-19 10:31             ` tomas
  0 siblings, 0 replies; 10+ messages in thread
From: tomas @ 2021-05-19 10:31 UTC (permalink / raw)
  To: Yuri Khan; +Cc: help-gnu-emacs, Stefan Monnier

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

On Wed, May 19, 2021 at 05:15:26PM +0700, Yuri Khan wrote:

[...]

> Not exactly: the while loop above generates puffs of pink, yellow,
> green [...]

Oh, yes. I missed the colours, somehow :)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

end of thread, other threads:[~2021-05-19 10:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-18 17:08 New function: rcd-highlight-list Jean Louis
2021-05-18 17:27 ` tomas
2021-05-18 17:43   ` Jean Louis
2021-05-18 18:47     ` tomas
2021-05-18 20:13       ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-19  7:52         ` tomas
2021-05-19 10:15           ` Yuri Khan
2021-05-19 10:31             ` tomas
2021-05-19 10:27           ` Jean Louis
2021-05-18 20:14       ` Jean Louis

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