unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Passing values through a variable
@ 2021-02-14  1:46 michael-franzese
  2021-02-14  3:39 ` michael-franzese
  0 siblings, 1 reply; 11+ messages in thread
From: michael-franzese @ 2021-02-14  1:46 UTC (permalink / raw)
  To: Help Gnu Emacs

I want to change the expression (1 'texcmd-colour) so that
the value 1 can be set through a variable (e.g. stdhl).

Can I just do

(defvar-local stdhl 1
  "Uses standard highlighting for keywords when set to 1.
When stdhl is 0, the leading backslash is also highlighted.")

(defconst tex-keywords
  `(
    ;; Greek.  Use (0 'texcmd-colour) to highlight the leading "\".
    (,(rx "\\" word-start (group (or "alpha" "beta" "chi" "delta"
          "Delta" "epsilon" "varepsilon" "eta" "gamma" "Gamma" "iota"
          "kappa" "lambda" "Lambda" "mu" "nu" "omega" "Omega" "phi"
          "varphi" "Phi" "pi" "varpi" "Pi" "psi" "Psi" "rho" "varrho"
          "sigma" "varsigma" "Sigma" "tau" "theta" "vartheta" "Theta"
          "upsilon" "Upsilon" "xi" "Xi" "zeta")) word-end)
     (stdhl 'texcmd-colour))

(font-lock-add-keywords nil comseq-crucible t)


Below is the original code

(defconst tex-keywords
  `(
    ;; Greek.  Use (0 'colour-tex-cruc) to highlight the leading "\".
    (,(rx "\\" word-start (group (or "alpha" "beta" "chi" "delta"
          "Delta" "epsilon" "varepsilon" "eta" "gamma" "Gamma" "iota"
          "kappa" "lambda" "Lambda" "mu" "nu" "omega" "Omega" "phi"
          "varphi" "Phi" "pi" "varpi" "Pi" "psi" "Psi" "rho" "varrho"
          "sigma" "varsigma" "Sigma" "tau" "theta" "vartheta" "Theta"
          "upsilon" "Upsilon" "xi" "Xi" "zeta")) word-end)
     (1 'texcmd-colour))

(font-lock-add-keywords nil tex-keywords t)



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

* Re: Passing values through a variable
  2021-02-14  1:46 Passing values through a variable michael-franzese
@ 2021-02-14  3:39 ` michael-franzese
  2021-02-14  3:56   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 11+ messages in thread
From: michael-franzese @ 2021-02-14  3:39 UTC (permalink / raw)
  To: michael-franzese; +Cc: Help Gnu Emacs

Does anybody know how to use "font-lock-add-keywords" to
highlight keywords?  Have tried as follows.

(defface texcmd-colour
  '( (default :inherit bold)
     ( ((class color) (min-colors 88) (background light))
       :foreground "#FF0000" )
     ( ((class color) (min-colors 88) (background dark))
       :foreground "#FF0000" )
     (t :inherit font-lock-builtin-face) )
  "Typeface for sutting colour to tex commands.")

(defvar-local stdhl 1
  "Uses standard highlighting for keywords when set to 1.
When stdhl is 0, the leading backslash is also highlighted.")

(defconst comseq-list
  `(
    ;; Greek.
    (,(rx "\\" word-start (group (or "alpha" "beta" "chi" "delta"
          "Delta" "epsilon" "varepsilon" "eta" "gamma" "Gamma" "iota"
          "kappa" "lambda" "Lambda" "mu" "nu" "omega" "Omega" "phi"
          "varphi" "Phi" "pi" "varpi" "Pi" "psi" "Psi" "rho" "varrho"
          "sigma" "varsigma" "Sigma" "tau" "theta" "vartheta" "Theta"
          "upsilon" "Upsilon" "xi" "Xi" "zeta")) word-end)
     (stdhl 'colour-texcmd))
"Fontification for letters and symbols.")

(font-lock-add-keywords nil comseq-list t)


> Sent: Sunday, February 14, 2021 at 1:46 PM
> From: michael-franzese@gmx.com
> To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Passing values through a variable
>
> I want to change the expression (1 'texcmd-colour) so that
> the value 1 can be set through a variable (e.g. stdhl).
>
> Can I just do
>
> (defvar-local stdhl 1
>   "Uses standard highlighting for keywords when set to 1.
> When stdhl is 0, the leading backslash is also highlighted.")
>
> (defconst tex-keywords
>   `(
>     ;; Greek.  Use (0 'texcmd-colour) to highlight the leading "\".
>     (,(rx "\\" word-start (group (or "alpha" "beta" "chi" "delta"
>           "Delta" "epsilon" "varepsilon" "eta" "gamma" "Gamma" "iota"
>           "kappa" "lambda" "Lambda" "mu" "nu" "omega" "Omega" "phi"
>           "varphi" "Phi" "pi" "varpi" "Pi" "psi" "Psi" "rho" "varrho"
>           "sigma" "varsigma" "Sigma" "tau" "theta" "vartheta" "Theta"
>           "upsilon" "Upsilon" "xi" "Xi" "zeta")) word-end)
>      (stdhl 'texcmd-colour))
>
> (font-lock-add-keywords nil comseq-crucible t)
>
>
> Below is the original code
>
> (defconst tex-keywords
>   `(
>     ;; Greek.  Use (0 'colour-tex-cruc) to highlight the leading "\".
>     (,(rx "\\" word-start (group (or "alpha" "beta" "chi" "delta"
>           "Delta" "epsilon" "varepsilon" "eta" "gamma" "Gamma" "iota"
>           "kappa" "lambda" "Lambda" "mu" "nu" "omega" "Omega" "phi"
>           "varphi" "Phi" "pi" "varpi" "Pi" "psi" "Psi" "rho" "varrho"
>           "sigma" "varsigma" "Sigma" "tau" "theta" "vartheta" "Theta"
>           "upsilon" "Upsilon" "xi" "Xi" "zeta")) word-end)
>      (1 'texcmd-colour))
>
> (font-lock-add-keywords nil tex-keywords t)
>
>



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

* Re: Passing values through a variable
  2021-02-14  3:39 ` michael-franzese
@ 2021-02-14  3:56   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-14  4:14     ` michael-franzese
  0 siblings, 1 reply; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-14  3:56 UTC (permalink / raw)
  To: help-gnu-emacs

michael-franzese wrote:

> Does anybody know how to use "font-lock-add-keywords" to
> highlight keywords?

Oh, no, not again :)

But wait... if it happens again and again, _I_ don't have to
do it again!

"if anything can start anew, then everything must continue"

So yes, here is an example:

Note: The keywords don't have to be expressions BTW. They can
be single words. Then, instead of the index (1 in the example)
just add a dot, i.e. (word . face)

\alpha^{high}
\beta_{low}

(progn
  (font-lock-add-keywords
   'emacs-lisp-mode
   '(
     ("\\^{\\([[:alnum:]]*\\)}" 1 font-lock-builtin-face)
     ("_{\\([[:alnum:]]*\\)}"   1 font-lock-function-name-face)
     )
   t)
  (text-mode)
  (emacs-lisp-mode) )
;;                   ^ eval

You can see the result in this screenshot:

  https://dataswamp.org/~incal/figures/emacs/high-low.png

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: Passing values through a variable
  2021-02-14  3:56   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-14  4:14     ` michael-franzese
  2021-02-14  4:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 11+ messages in thread
From: michael-franzese @ 2021-02-14  4:14 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs

You have used

("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face)

How can I pass the "1" using a variable, rather than hardwiring it?


> Sent: Sunday, February 14, 2021 at 3:56 PM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Passing values through a variable
>
> michael-franzese wrote:
>
> > Does anybody know how to use "font-lock-add-keywords" to
> > highlight keywords?
>
> Oh, no, not again :)
>
> But wait... if it happens again and again, _I_ don't have to
> do it again!
>
> "if anything can start anew, then everything must continue"
>
> So yes, here is an example:
>
> Note: The keywords don't have to be expressions BTW. They can
> be single words. Then, instead of the index (1 in the example)
> just add a dot, i.e. (word . face)
>
> \alpha^{high}
> \beta_{low}
>
> (progn
>   (font-lock-add-keywords
>    'emacs-lisp-mode
>    '(
>      ("\\^{\\([[:alnum:]]*\\)}" 1 font-lock-builtin-face)
>      ("_{\\([[:alnum:]]*\\)}"   1 font-lock-function-name-face)
>      )
>    t)
>   (text-mode)
>   (emacs-lisp-mode) )
> ;;                   ^ eval
>
> You can see the result in this screenshot:
>
>   https://dataswamp.org/~incal/figures/emacs/high-low.png
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



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

* Re: Passing values through a variable
  2021-02-14  4:14     ` michael-franzese
@ 2021-02-14  4:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-14 17:18         ` michael-franzese
  2021-02-14 17:40         ` michael-franzese
  0 siblings, 2 replies; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-14  4:32 UTC (permalink / raw)
  To: help-gnu-emacs

michael-franzese wrote:

> You have used
>
> ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face)
>
> How can I pass the "1" using a variable, rather than
> hardwiring it?

That's not how it works. Figure it out... or see
the docstring.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: Passing values through a variable
  2021-02-14  4:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-14 17:18         ` michael-franzese
  2021-02-14 17:52           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-14 17:40         ` michael-franzese
  1 sibling, 1 reply; 11+ messages in thread
From: michael-franzese @ 2021-02-14 17:18 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs


> Sent: Sunday, February 14, 2021 at 4:32 PM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Passing values through a variable
>
> michael-franzese wrote:
>
> > You have used
> >
> > ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face)
> >
> > How can I pass the "1" using a variable, rather than
> > hardwiring it?
>
> That's not how it works. Figure it out... or see
> the docstring.

What should I look for?

> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



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

* Re: Passing values through a variable
  2021-02-14  4:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-14 17:18         ` michael-franzese
@ 2021-02-14 17:40         ` michael-franzese
  2021-02-14 17:52           ` michael-franzese
  1 sibling, 1 reply; 11+ messages in thread
From: michael-franzese @ 2021-02-14 17:40 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs

I would like to set up my own foreground and background colour
for the keywords.

> Sent: Sunday, February 14, 2021 at 4:32 PM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Passing values through a variable
>
> michael-franzese wrote:
>
> > You have used
> >
> > ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face)
> >
> > How can I pass the "1" using a variable, rather than
> > hardwiring it?
>
> That's not how it works. Figure it out... or see
> the docstring.
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



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

* Re: Passing values through a variable
  2021-02-14 17:40         ` michael-franzese
@ 2021-02-14 17:52           ` michael-franzese
  2021-02-14 18:02             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 11+ messages in thread
From: michael-franzese @ 2021-02-14 17:52 UTC (permalink / raw)
  To: michael-franzese; +Cc: help-gnu-emacs, moasenwood

Have looked into the use of "how"  in
  (defun font-lock-add-keywords (mode keywords &optional how)

But have not got far in my understanding.

> Sent: Monday, February 15, 2021 at 5:40 AM
> From: michael-franzese@gmx.com
> To: moasenwood@zoho.eu
> Cc: help-gnu-emacs@gnu.org
> Subject: Re: Passing values through a variable
>
> I would like to set up my own foreground and background colour
> for the keywords.
>
> > Sent: Sunday, February 14, 2021 at 4:32 PM
> > From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> > To: help-gnu-emacs@gnu.org
> > Subject: Re: Passing values through a variable
> >
> > michael-franzese wrote:
> >
> > > You have used
> > >
> > > ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face)
> > >
> > > How can I pass the "1" using a variable, rather than
> > > hardwiring it?
> >
> > That's not how it works. Figure it out... or see
> > the docstring.
> >
> > --
> > underground experts united
> > http://user.it.uu.se/~embe8573
> > https://dataswamp.org/~incal
> >
> >
> >
>
>



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

* Re: Passing values through a variable
  2021-02-14 17:18         ` michael-franzese
@ 2021-02-14 17:52           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-14 18:08             ` michael-franzese
  0 siblings, 1 reply; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-14 17:52 UTC (permalink / raw)
  To: help-gnu-emacs

michael-franzese wrote:

>>> You have used
>>>
>>> ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face)
>>>
>>> How can I pass the "1" using a variable, rather than
>>> hardwiring it?
>>
>> That's not how it works. Figure it out... or see
>> the docstring.
>
> What should I look for?

1 is the index of the subexpression that should be affected,
see this screenshot. So you search for the whole expression,
but colorize only the subexpression pointed to by the index.

See how the code corresponds to the first two lines?

   https://dataswamp.org/~incal/figures/emacs/high-low.png

If you don't have any subexpression, just a single expression
that might be as plain as a word, you don't need an index,
instead use (word . face) - I think I mentioned
this...? Nevermind.

Anyway here is an example of that:

  https://dataswamp.org/~incal/figures/emacs/dressed-up-as-themselves.png

Look at the code and think. What does the file name refer to?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: Passing values through a variable
  2021-02-14 17:52           ` michael-franzese
@ 2021-02-14 18:02             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-14 18:02 UTC (permalink / raw)
  To: help-gnu-emacs

michael-franzese wrote:

> Have looked into the use of "how"  in
>   (defun font-lock-add-keywords (mode keywords &optional how)
>
> But have not got far in my understanding.

:)

I replied to this exact question recently!

Grep the backlog!

I'm gonna stop answering question if it goes on like this.
Everybody: "Oh, no champ, don't say that, stay!"
Manny: Well, OK, if you say...

The Sweet Science of Emacs Problem Solving:

1. think

2. read the docstring

3. "try, try again"

New NGE movie coming really soon now!
3.0+1.0 Thrice Upon a Time, "[o]riginally expected for release in 2015"
https://en.wikipedia.org/wiki/Neon_Genesis_Evangelion
https://en.wikipedia.org/wiki/Evangelion:_3.0%2B1.0_Thrice_Upon_a_Time

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: Passing values through a variable
  2021-02-14 17:52           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-14 18:08             ` michael-franzese
  0 siblings, 0 replies; 11+ messages in thread
From: michael-franzese @ 2021-02-14 18:08 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs




The oricinal code used either a "0" or a "1".  With "0", the leading
"\" is highlighted; whereas with "1", the leading "\" is not highlighted.

  (defconst comseq-list
  `(
    (,(rx "\\" word-start (group (or "alpha" "beta" "chi" "delta")) word-end)
     (1 'colour-texcmd-crucible))

> Sent: Monday, February 15, 2021 at 5:52 AM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Passing values through a variable
>
> michael-franzese wrote:
>
> >>> You have used
> >>>
> >>> ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face)
> >>>
> >>> How can I pass the "1" using a variable, rather than
> >>> hardwiring it?
> >>
> >> That's not how it works. Figure it out... or see
> >> the docstring.
> >
> > What should I look for?
>
> 1 is the index of the subexpression that should be affected,
> see this screenshot. So you search for the whole expression,
> but colorize only the subexpression pointed to by the index.
>
> See how the code corresponds to the first two lines?
>
>    https://dataswamp.org/~incal/figures/emacs/high-low.png
>
> If you don't have any subexpression, just a single expression
> that might be as plain as a word, you don't need an index,
> instead use (word . face) - I think I mentioned
> this...? Nevermind.
>
> Anyway here is an example of that:
>
>   https://dataswamp.org/~incal/figures/emacs/dressed-up-as-themselves.png
>
> Look at the code and think. What does the file name refer to?
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



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

end of thread, other threads:[~2021-02-14 18:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-14  1:46 Passing values through a variable michael-franzese
2021-02-14  3:39 ` michael-franzese
2021-02-14  3:56   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-14  4:14     ` michael-franzese
2021-02-14  4:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-14 17:18         ` michael-franzese
2021-02-14 17:52           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-14 18:08             ` michael-franzese
2021-02-14 17:40         ` michael-franzese
2021-02-14 17:52           ` michael-franzese
2021-02-14 18:02             ` Emanuel Berg via Users list for the GNU Emacs text editor

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