* 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 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 ` 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
* 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
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
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.