unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Davin Pearson <davin.pearson@gmail.com>
To: Anders Lindgren <andlind@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re:
Date: Sun, 2 Jan 2022 14:15:58 +1300	[thread overview]
Message-ID: <CAG9ihEvSeQgOJkZXmGg60bOGgjDr2jH+MQZ6pi44g0U9vG3PQg@mail.gmail.com> (raw)
In-Reply-To: <CABr8ebaWvqqnG8s7RzvsJ75=hHfX=y2q0H=OipPxfAjXgWk9Sg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 6505 bytes --]

I have factored out enough code to make debugging
my code easier for yous.  Note that the 'append
and the 'prepend options do not appear to work.

The only code which shows some sense of elegance
is the t option which fontifies ghi but instead of showing
just one layer of fontification shows the string ghi in
the bold face (i.e. overwriting the font-lock-string-face).

(remove-hook 'font-lock-mode-hook 'dmp-my-fonts)
(add-hook 'font-lock-mode-hook 'dmp-my-fonts)

(defun dmp-my-fonts ()
  (font-lock-add-keywords
   'emacs-lisp-mode
   `(
     ("abc" 0 'bold 'append)
     ("def" 0 'bold 'prepend)
     ("ghi" 0 'bold t)
     ("jkl" 0 'bold 't)
     )
   'end))

(progn
  (setq abc 123)
  (setq def 123)
  (setq ghi 123)
  (setq jkl 123)
  )

 "abc" abc
 "def" def
 "ghi" ghi
 "jkl" jkl

(buffer-substring (point) (+ (point) 1)) evalled
on the above returns

#("e" 0 1 (fontified t face font-lock-string-face))

when evalled on the strings

and this on the symbols

#("e" 0 1 (fontified t))

except for ghi which returns

#("h" 0 1 (fontified t face bold))

See the attached file for a pictorial version of my code and what it does.

On Sat, 1 Jan 2022 at 04:23, Anders Lindgren <andlind@gmail.com> wrote:

> Hi!
>
> I just noticed that all your font-lock rules have specified "t" as the
> OVERRIDE flag. This has the effect that the face in the rule replaces the
> existing face. Instead, if you use 'prepend' or 'append' it will place both
> faces on the text. With 'append' the new face will come before the old
> face. (If the two faces both define a face property, the first face in the
> list takes precedence.)
>
> You can check the result for yourself. If you eval '(buffer-substring
> (point) (+ (point) 1))' where you want both faces to be applied, the value
> of the 'face' property should be a list of faces.
>
>     -- Anders
>
> On Wed, Dec 29, 2021 at 12:43 AM Davin Pearson <davin.pearson@gmail.com>
> wrote:
>
>> Could you please run my code on your machine to verify that it works on
>> your machine but not mine.
>>
>> On Wed, 29 Dec 2021 at 06:51, Eli Zaretskii <eliz@gnu.org> wrote:
>>
>>> [Please keep the list address on the CC.]
>>>
>>> > From: Davin Pearson <davin.pearson@gmail.com>
>>> > Date: Tue, 28 Dec 2021 16:58:50 +1300
>>> >
>>> > In your email to me you said that one of the foreground colours
>>> > will "win" and the other will be ignored.  What I want is the
>>> > same thing for the background colour.  As far as I understand the
>>> > winning foreground colour will be the one that is added last in
>>> > the fontification spec, and with the symbol 'end added to
>>> > font-lock-add-keywords.
>>> >
>>> > Here is my font-lock-string-face
>>> >
>>> > "assdsdasd"
>>> >
>>> > Here is the text dmp-asdssd coloured in my choice of colours: red
>>> > and green:
>>> >
>>> > "dmp-asdssd" (*)
>>> >
>>> > Here is the code that fontifies the above code.
>>> >
>>> > (make-face 'dmp-face--line0--col1-red)
>>> > (set-face-foreground 'dmp-face--line0--col1-red "#ff0000")
>>> > (set-face-background 'dmp-face--line0--col1-red nil)
>>> > (make-face-bold 'dmp-face--line0--col1-red)
>>> >
>>> > (make-face 'dmp-face--line0--col2-green)
>>> > (set-face-foreground 'dmp-face--line0--col2-green "#00ff00")
>>> > (set-face-background 'dmp-face--line0--col2-green nil)
>>> > (make-face-bold 'dmp-face--line0--col2-green)
>>> >
>>> > (make-face 'dmp-face--line0--col3-blue)
>>> > (set-face-foreground 'dmp-face--line0--col3-blue "#0000ff")
>>> > (set-face-background 'dmp-face--line0--col3-blue nil)
>>> > (make-face-bold 'dmp-face--line0--col3-blue)
>>> >
>>> > Here are some useful constant strings:
>>> >
>>> > (defvar dmp-defun-inner-regexp-less-dash+star
>>> "a-zA-Z0-9_.!@$%^&=<>/|+:;?~")
>>> > (defvar dmp-defun-inner-regexp-less-dash      (concat ""
>>> dmp-defun-inner-regexp-less-dash+star))
>>> > (defvar dmp-defun-inner-regexp-less-star      (concat "-"
>>> dmp-defun-inner-regexp-less-dash+star))
>>> > (defvar dmp-defun-inner-regexp                (concat "-,"
>>> dmp-defun-inner-regexp-less-dash+star))
>>> > (defvar dmp-defun-outer-regexp                (concat "["
>>> dmp-defun-inner-regexp            "]+"))
>>> > (defvar dmp-bra                               "\\(^\\|[][
>>> \t\r\n()'\",.:=]\\)")
>>> > (defvar dmp-ket                               "\\($\\|[][
>>> \t\r\n()\",.:=]\\)")
>>> >
>>> > Here is the actual font lock code:
>>> >
>>> > (defun dmp-getting--syntax-highlighting--online ()
>>> >   (font-lock-add-keywords
>>> >    'emacs-lisp-mode
>>> >    '(
>>> >      (, (format "\\(dmp[0-9]\\)\\(\\(-[%s]+\\)+\\)%s"
>>> >                 dmp-defun-inner-regexp-less-dash
>>> >                 dmp-ket)
>>> >         (1 'dmp-face--line0--col1-red t)
>>> >         (2 'dmp-face--line0--col2-green t)
>>> >         )
>>> >      (, (format
>>> "\\(dmp[0-9]\\(-[%s]+\\)\\)\\(\\([-_][-_]\\|:\\)[%s]+\\)%s"
>>> >                 dmp-defun-inner-regexp-less-dash
>>> >                 dmp-defun-inner-regexp
>>> >                 dmp-ket)
>>> >         (1 'dmp-face--line0--col1-red t)
>>> >         (3 'dmp-face--line0--col2-green t))
>>> >      (, (format
>>> "\\(dmp[0-9]*\\(-[%s]+\\)*\\)\\([_-][_-][%s]+\\)\\([_-][_-][%s]+\\)%s"
>>> >                 *dmp-defun-inner-regexp-less-dash*
>>> >                 *dmp-defun-inner-regexp*
>>> >                 *dmp-defun-inner-regexp*
>>> >                 *dmp-ket*)
>>> >         (1 'dmp-face--line0--col1-red t)
>>> >         (3 'dmp-face--line0--col2-green t)
>>> >         (4 'dmp-face--line0--col3-blue t))
>>> >      )
>>> >    'end)
>>> >   )
>>> > (add-hook 'font-lock-mode-hook
>>> 'dmp-getting--syntax-highlighting--online 'APPEND)
>>> >
>>> > Notice that in the text marked with a (*) the background colour
>>> > of the above text is the same as the background colour of the
>>> > screen.
>>> >
>>> > When dmp-face--line0--col1-red, dmp-face--line0--col2-green and
>>> > dmp-face--line0--col3-blue 's set-face-foreground set to nil, as it
>>> > is above, I want the for the string face's background colour to
>>> > show through as light blue in the fontification of dmp-asdssd.
>>>
>>> I think this is something that your code does.  If I just merge two
>>> faces, one with a background color, the other with a foreground color,
>>> the result of the merge has the background of the first faces and the
>>> foreground of the second.
>>>
>>> So I conclude that something goes wrong in your
>>> dmp-getting--syntax-highlighting--on-line function, or in how it
>>> interacts with font-lock.
>>>
>>

[-- Attachment #1.2: Type: text/html, Size: 8861 bytes --]

[-- Attachment #2: to-gnu.emacs.star-20220102-140746.png --]
[-- Type: image/png, Size: 370527 bytes --]

  reply	other threads:[~2022-01-02  1:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20  2:29 (unknown) Davin Pearson
2021-12-20 14:13 ` none Stefan Monnier
2021-12-21 14:29 ` Eli Zaretskii
     [not found]   ` <CAG9ihEvK5VVgP9O+TXYSz+BQF1=YzMgzGBbc5s-fewwT34yytA@mail.gmail.com>
     [not found]     ` <CAG9ihEsdD2Dd=paZatMfnD3HJxKsUM=3etTz7c-tDcs-H80PoA@mail.gmail.com>
     [not found]       ` <CAG9ihEsQFkx+uE+pZ7R42GXUFR_C2PSzVK8M5AQuHdtOsND0cg@mail.gmail.com>
     [not found]         ` <CAG9ihEv_OPaYhTgfh2WnfckC5r21U5Hv0qW7Msnwz4Bbvz6ccg@mail.gmail.com>
2021-12-28 17:51           ` Re: Eli Zaretskii
2021-12-28 23:41             ` Re: Davin Pearson
2021-12-31 15:23               ` Re: Anders Lindgren
2022-01-02  1:15                 ` Davin Pearson [this message]
2022-01-02  5:19                   ` Re: Stefan Monnier
2022-01-03  0:53                     ` Re: Davin Pearson
  -- strict thread matches above, loose matches on Subject: below --
2023-02-15 17:57 Make all tree-sitter modes optional Alan Mackenzie
2023-02-15 18:33 ` Eli Zaretskii
2023-02-17 13:30   ` Alan Mackenzie
2023-02-17 13:37     ` Po Lu
2023-02-17 13:46       ` Stefan Monnier
2023-02-17 14:16         ` Po Lu
2023-02-17 14:40           ` Eli Zaretskii
2023-02-17 14:56             ` Dmitry Gutov
2023-02-17 15:04               ` Eli Zaretskii
     [not found]                 ` <8735741fic.fsf@dick>
2023-02-17 15:41                   ` Alan Mackenzie
2021-12-02 14:09 Re: Angelo Graziosi
2021-11-04  6:36 Re: Pedro Andres Aranda Gutierrez
2017-10-24 18:52 wait_reading_process_ouput hangs in certain cases (w/ patches) Matthias Dahl
2017-11-14 16:03 ` Eli Zaretskii
2017-11-14 16:23   ` Eli Zaretskii
2017-11-14 21:54     ` Paul Eggert
2017-11-15 14:03       ` Matthias Dahl
2017-11-16 16:46         ` Paul Eggert
2017-11-18 14:24           ` Matthias Dahl
2017-11-19  7:07             ` Paul Eggert
2017-11-20 15:29               ` Matthias Dahl
2017-11-21 14:44                 ` Matthias Dahl
2017-11-22  8:55                   ` Paul Eggert
2017-12-04  9:40                     ` Matthias Dahl
2018-02-13 14:25                       ` Matthias Dahl
2018-02-16 16:01                         ` Eli Zaretskii
2018-02-16 16:09                           ` Lars Ingebrigtsen
2018-02-22 11:45                             ` andres.ramirez
2018-02-26 14:39                               ` Matthias Dahl
2018-02-26 15:11                                 ` andrés ramírez
2018-02-26 15:17                                   ` Lars Ingebrigtsen
2018-02-26 15:29                                     ` andrés ramírez
2018-02-26 16:52                                       ` Daniel Colascione
2018-02-26 17:19                                         ` andrés ramírez
2018-02-26 17:24                                           ` Daniel Colascione
2018-02-27  1:53                                             ` Re: andrés ramírez
2016-02-08  7:54 (unknown) steve
2016-02-08 12:56 ` Artur Malabarba
2016-02-08 19:05   ` Re: Steve Purcell
2016-02-08 20:16     ` Re: Artur Malabarba
     [not found] <CAFkz2yroLhknptDnWyC9B1fbZKEwTCV-T0VttHQiwZoaAW-j6A@mail.gmail.com>
2012-12-20  8:36 ` Re: Константин Куликов
2005-09-10 14:39 Re: Abdulaim
2005-07-06 17:37 Re: Ishok
2005-03-20  5:29 Re: info
2005-01-06 12:16 Re: Документ
2004-11-26 21:10 Re: Robbie Womack
2004-10-10 18:45 Re: John Gard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAG9ihEvSeQgOJkZXmGg60bOGgjDr2jH+MQZ6pi44g0U9vG3PQg@mail.gmail.com \
    --to=davin.pearson@gmail.com \
    --cc=andlind@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).