all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* multi-line highlighting
@ 2021-02-28 10:01 Colin Baxter
  2021-02-28 10:13 ` Colin Baxter
  2021-02-28 16:00 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Colin Baxter @ 2021-02-28 10:01 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I have in an org-mode file a need to color the face of the string
between 'Alpha:' and a period. To achieve this I have

#+begin_src elisp
(add-hook 'org-mode-hook (lambda ()
   (font-lock-add-keywords nil
     '(("\\(Alpha:\\)\\([^\n\r\t]+\\)\\(.\\)"
      (1 font-lock-builtin-face) ;; Face for 'Alpha:'.
      (2 font-lock-doc-face) ;; Subsequent face)))))
#+end_src

This works well. 'Alpha:' is in font-lock-builtin-face and the rest of
the line until the period is in font-lock-doc-face. Occasionally,
unfortunately, the line runs over to a "new line" - and of course the
face locking 2 is lost on the new line.

How can I maintain the font locking 2 for two or maybe three lines? I
have tried inserting a '\n' in the regexp and a

#+begin_src elisp
eval: (set (make-local-variable 'font-lock-multiline) t)
#+end_src

as a local variable, but to no avail. I have searched online, but all
the examples I've found are based on adding keywords, which is not what
I want. I'm probably overlooking something simple.

I would be grateful for pointers as to where to look.

Best wishes,

Colin Baxter.




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

* Re: multi-line highlighting
  2021-02-28 10:01 multi-line highlighting Colin Baxter
@ 2021-02-28 10:13 ` Colin Baxter
  2021-02-28 12:34   ` Colin Baxter
  2021-02-28 16:00 ` Stefan Monnier
  1 sibling, 1 reply; 5+ messages in thread
From: Colin Baxter @ 2021-02-28 10:13 UTC (permalink / raw)
  To: help-gnu-emacs

Typo! Should be

#+begin_src elisp
(add-hook 'org-mode-hook (lambda ()
   (font-lock-add-keywords nil
     '(("\\(Alpha:\\)\\([^\n\r\t]+\\)\\(.\\)"
      (1 font-lock-builtin-face) ;; Face for 'Alpha:'
      (2 font-lock-doc-face) ;; Subsequent face
      )))))
#+end_src

Bets wishes,






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

* Re: multi-line highlighting
  2021-02-28 10:13 ` Colin Baxter
@ 2021-02-28 12:34   ` Colin Baxter
  0 siblings, 0 replies; 5+ messages in thread
From: Colin Baxter @ 2021-02-28 12:34 UTC (permalink / raw)
  To: help-gnu-emacs

Solution is easier than I thought. This works.

#+begin_src elisp
(add-hook 'org-mode-hook (lambda ()
   (font-lock-add-keywords nil
     '( ("<alpha>\\|</alpha>" . font-lock-warning-face)
      ("<alpha>\\([^<]+?\\)</alpha>" . (1 font-lock-constant-face))
))))
#+end_src

and then put

eval: (set (make-local-variable 'font-lock-multiline) t)

as a local variable.

Sorry for answering my own question!

Best wishes,




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

* Re: multi-line highlighting
  2021-02-28 10:01 multi-line highlighting Colin Baxter
  2021-02-28 10:13 ` Colin Baxter
@ 2021-02-28 16:00 ` Stefan Monnier
  2021-02-28 17:57   ` Colin Baxter
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2021-02-28 16:00 UTC (permalink / raw)
  To: help-gnu-emacs

> I have in an org-mode file a need to color the face of the string
> between 'Alpha:' and a period. To achieve this I have
>
> #+begin_src elisp
> (add-hook 'org-mode-hook (lambda ()
>    (font-lock-add-keywords nil
>      '(("\\(Alpha:\\)\\([^\n\r\t]+\\)\\(.\\)"
                                         ^^^
This is not the regexp for a "period".

Also this regexp will clearly not match multiple lines since you
explicitly exclude \n from the matched chars.

> as a local variable, but to no avail. I have searched online, but all
> the examples I've found are based on adding keywords, which is not what
> I want. I'm probably overlooking something simple.

Have you looked at the ELisp reference manual that comes with your Emacs?
It has a section called "Font Lock Multiline".


        Stefan




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

* Re: multi-line highlighting
  2021-02-28 16:00 ` Stefan Monnier
@ 2021-02-28 17:57   ` Colin Baxter
  0 siblings, 0 replies; 5+ messages in thread
From: Colin Baxter @ 2021-02-28 17:57 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca> writes:

    >> I have in an org-mode file a need to color the face of the string
    >> between 'Alpha:' and a period. To achieve this I have
    >> 
    >> #+begin_src elisp (add-hook 'org-mode-hook (lambda ()
    >> (font-lock-add-keywords nil
    >> '(("\\(Alpha:\\)\\([^\n\r\t]+\\)\\(.\\)"
    >                                          ^^^ This is not the
    > regexp for a "period".

Yes, I discovered that fact.

I now have what I want working with this:

#+begin_src elisp
(add-hook 'org-mode-hook (lambda ()
   (font-lock-add-keywords nil
               '(("Alpha:\\|." . font-lock-warning-face)
                 ("Alpha:\\([^<]+?\\)." . (1 font-lock-constant-face))
                 ("Beta:\\|." . font-lock-doc-face)
                 ("Beta:\\([^<]+?\\)." .  (1 font-lock-comment-face))))))
#+end_src

My end marker is the FULLWIDTH FULL STOP character. It may not be the
most rigorous solution but it works.

    > Have you looked at the ELisp reference manual that comes with your
    > Emacs?  It has a section called "Font Lock Multiline".

Yes, I did.

Thanks.

Best wishes



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

end of thread, other threads:[~2021-02-28 17:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-28 10:01 multi-line highlighting Colin Baxter
2021-02-28 10:13 ` Colin Baxter
2021-02-28 12:34   ` Colin Baxter
2021-02-28 16:00 ` Stefan Monnier
2021-02-28 17:57   ` Colin Baxter

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.