emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* how to add font-lock keywords
@ 2011-08-23 17:51 Le Wang
  2011-08-24  1:01 ` John Wiegley
  0 siblings, 1 reply; 7+ messages in thread
From: Le Wang @ 2011-08-23 17:51 UTC (permalink / raw)
  To: Orgmode Mailing List

Hi all,

I wasn't able to google a clear examples of how to do this.  For
example, I'd like to highlight all text between double-quotes.

-- 
Le

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

* Re: how to add font-lock keywords
  2011-08-23 17:51 how " Le Wang
@ 2011-08-24  1:01 ` John Wiegley
  2011-08-24  1:17   ` John Wiegley
  0 siblings, 1 reply; 7+ messages in thread
From: John Wiegley @ 2011-08-24  1:01 UTC (permalink / raw)
  To: emacs-orgmode

>>>>> Le Wang <l26wang@gmail.com> writes:

> I wasn't able to google a clear examples of how to do this.  For example,
> I'd like to highlight all text between double-quotes.

Typically it looks something like this:

  (font-lock-add-keywords org-mode
                          (list (list (concat "\\(\"[^\"]+\"\\)")
                                      1 highlight-face t)))

Where `highlight-face' is the face you'd like to use.  The regexp doesn't
handle cases where \" legitimately occurs in a string, either.  The part
between the \\(\\) is what gets colorized.

John

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

* Re: how to add font-lock keywords
  2011-08-24  1:01 ` John Wiegley
@ 2011-08-24  1:17   ` John Wiegley
  2011-08-24  4:25     ` Le Wang
  0 siblings, 1 reply; 7+ messages in thread
From: John Wiegley @ 2011-08-24  1:17 UTC (permalink / raw)
  To: emacs-orgmode

>>>>> John Wiegley <jwiegley@gmail.com> writes:

>>>>> Le Wang <l26wang@gmail.com> writes:
>> I wasn't able to google a clear examples of how to do this.  For example,
>> I'd like to highlight all text between double-quotes.

> Typically it looks something like this:

>   (font-lock-add-keywords org-mode
[...]

Sorry, that should be 'org-mode, to name the symbol, not attempt to use its
value.

John

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

* Re: how to add font-lock keywords
  2011-08-24  1:17   ` John Wiegley
@ 2011-08-24  4:25     ` Le Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Le Wang @ 2011-08-24  4:25 UTC (permalink / raw)
  To: John Wiegley; +Cc: emacs-orgmode

Thanks for the hint, I tried this, but all my beautiful salad bowl
colours went away.

(font-lock-add-keywords 'org-mode '(("\"\\(\\(?:.\\|\n\\)*?[^\\]\\)\""
0 font-lock-string-face)))

Notice that I made a bad attempt to handle escaped quotation mark in
the string.  Does anyone know a better solution to handle escaped
characters in font-lock?

On Wed, Aug 24, 2011 at 9:17 AM, John Wiegley <jwiegley@gmail.com> wrote:
>>>>>> John Wiegley <jwiegley@gmail.com> writes:
>
>>>>>> Le Wang <l26wang@gmail.com> writes:
>>> I wasn't able to google a clear examples of how to do this.  For example,
>>> I'd like to highlight all text between double-quotes.
>
>> Typically it looks something like this:
>
>>   (font-lock-add-keywords org-mode
> [...]
>
> Sorry, that should be 'org-mode, to name the symbol, not attempt to use its
> value.
>
> John
>
>
>



-- 
Le

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

* How to add font-lock keywords
@ 2021-12-11 11:21 Daniel Fleischer
  2021-12-21 19:35 ` Bruno Barbier
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Fleischer @ 2021-12-11 11:21 UTC (permalink / raw)
  To: emacs-orgmode

Hi, I want to add custom keywords to be highlighted. I used

    (font-lock-add-keywords nil '(("books" . org-level-4)) t)


but nothing happens after I restart orgmode or call 'font-lock-update'.

-- 

Daniel Fleischer


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

* Re: How to add font-lock keywords
  2021-12-11 11:21 How to add font-lock keywords Daniel Fleischer
@ 2021-12-21 19:35 ` Bruno Barbier
  2021-12-23  8:20   ` Daniel Fleischer
  0 siblings, 1 reply; 7+ messages in thread
From: Bruno Barbier @ 2021-12-21 19:35 UTC (permalink / raw)
  To: Daniel Fleischer, emacs-orgmode


Hi,

Daniel Fleischer <danflscr@gmail.com> writes:

> Hi, I want to add custom keywords to be highlighted. I used
>     (font-lock-add-keywords nil '(("books" . org-level-4)) t)
>
> but nothing happens after I restart orgmode or call 'font-lock-update'.

The following works for me, in an org mode buffer:

,----
| (font-lock-add-keywords nil '(("books" . 'org-level-4)) t)
`----

(I added a quote before the face name).

No need to call font-lock-update or restart: any new or modified text
gets the new fontification.

Bruno

> -- 
> Daniel Fleischer


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

* Re: How to add font-lock keywords
  2021-12-21 19:35 ` Bruno Barbier
@ 2021-12-23  8:20   ` Daniel Fleischer
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Fleischer @ 2021-12-23  8:20 UTC (permalink / raw)
  To: Bruno Barbier; +Cc: emacs-orgmode

Bruno Barbier [2021-12-21 Tue 20:35] wrote:

> The following works for me, in an org mode buffer:
>
> ,----
> | (font-lock-add-keywords nil '(("books" . 'org-level-4)) t)
> `----

> No need to call font-lock-update or restart: any new or modified text
> gets the new fontification.

Thanks, it works with the quote.

-- 

Daniel Fleischer


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

end of thread, other threads:[~2021-12-23  8:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-11 11:21 How to add font-lock keywords Daniel Fleischer
2021-12-21 19:35 ` Bruno Barbier
2021-12-23  8:20   ` Daniel Fleischer
  -- strict thread matches above, loose matches on Subject: below --
2011-08-23 17:51 how " Le Wang
2011-08-24  1:01 ` John Wiegley
2011-08-24  1:17   ` John Wiegley
2011-08-24  4:25     ` Le Wang

Code repositories for project(s) associated with this public inbox

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

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