emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:


From: Davin Pearson
Subject: Re:
Date: Sun, 2 Jan 2022 14:15:58 +1300

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: to-gnu.emacs.star-20220102-140746.png
Description: PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]