all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Custom colour for a custom command
@ 2015-09-30 17:49 Sharon Kimble
  2015-10-02  0:00 ` Emanuel Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Sharon Kimble @ 2015-09-30 17:49 UTC (permalink / raw)
  To: help-emacs

[-- Attachment #1: Type: text/plain, Size: 476 bytes --]

I have a latex command called "\myparencite{foo}" which has the same
colour as the surrounding text. How can I have a colour of :foreground
"green" :background "black" for it in my theme please? This theme is
"darkest-midnight", my own theme unpublished anywhere. Or should it be
instituted in my "init.org" setup please?

Thanks
Sharon.
-- 
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.0, fluxbox 1.3.7, emacs 24.5.50.3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

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

* Re: Custom colour for a custom command
  2015-09-30 17:49 Custom colour for a custom command Sharon Kimble
@ 2015-10-02  0:00 ` Emanuel Berg
  2015-10-02 19:13   ` Sharon Kimble
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2015-10-02  0:00 UTC (permalink / raw)
  To: help-gnu-emacs

Sharon Kimble <boudiccas@skimble.plus.com> writes:

> I have a latex command called "\myparencite{foo}"
> which has the same colour as the surrounding text.

(font-lock-add-keywords 'latex-mode
 '(("\\(myparencite\\){\\(.*\\)}" (1 font-lock-constant-face)
                                  (2 font-lock-doc-face) )))

Note: If you open a file.tex, you might end up in
TeX-mode or some other mode to do (La)TeX. So, first
see if it works (after evaluation) with

    M-x latex-mode RET

then, if your mode isn't that, make the substitution
in the code.

> How can I have a colour of :foreground "green"
> :background "black" for it in my theme please?

As you see in the code, use the font-lock-*
faces instead. I'm sure one of yours is green, so
use that.

One way of finding out which one is green is putting
point at a char that has a green face and then invoke
this:

(defun what-face (pos)
  (interactive "d")
  (let((face (or (get-char-property pos 'face)
                 (get-char-property pos 'read-cf-name) )))
    (message " Face: %s" (or face "(no face!)")) ))

Source: http://user.it.uu.se/~embe8573/conf/emacs-init/faces.el

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: Custom colour for a custom command
  2015-10-02  0:00 ` Emanuel Berg
@ 2015-10-02 19:13   ` Sharon Kimble
  2015-10-03  0:47     ` Emanuel Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Sharon Kimble @ 2015-10-02 19:13 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2192 bytes --]

Emanuel Berg <embe8573@student.uu.se> writes:

> Sharon Kimble <boudiccas@skimble.plus.com> writes:
>
>> I have a latex command called "\myparencite{foo}"
>> which has the same colour as the surrounding text.
>
> (font-lock-add-keywords 'latex-mode
>  '(("\\(myparencite\\){\\(.*\\)}" (1 font-lock-constant-face)
>                                   (2 font-lock-doc-face) )))

This is working well, except in this situation -

--8<---------------cut here---------------start------------->8---
 \myparencite{1767}[18] and N-methyl-serotonin \parencite{ }[19]. 
--8<---------------cut here---------------end--------------->8---

where the green colouration continues after \myparencite into the
following text, and even colouring the \parencite which has not yet been
worked on.

These two lines are from my theme, if its relevant, -

--8<---------------cut here---------------start------------->8---
 '(font-lock-constant-face ((t (:foreground "#A6E22E"))))
 '(font-lock-doc-face ((t (:foreground "#EEDC82"))))
--8<---------------cut here---------------end--------------->8---

But it is usable so thanks very much. 

Thanks
Sharon.

>
> Note: If you open a file.tex, you might end up in
> TeX-mode or some other mode to do (La)TeX. So, first
> see if it works (after evaluation) with
>
>     M-x latex-mode RET
>
> then, if your mode isn't that, make the substitution
> in the code.
>
>> How can I have a colour of :foreground "green"
>> :background "black" for it in my theme please?
>
> As you see in the code, use the font-lock-*
> faces instead. I'm sure one of yours is green, so
> use that.
>
> One way of finding out which one is green is putting
> point at a char that has a green face and then invoke
> this:
>
> (defun what-face (pos)
>   (interactive "d")
>   (let((face (or (get-char-property pos 'face)
>                  (get-char-property pos 'read-cf-name) )))
>     (message " Face: %s" (or face "(no face!)")) ))
>
> Source: http://user.it.uu.se/~embe8573/conf/emacs-init/faces.el

-- 
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.0, fluxbox 1.3.7, emacs 24.5.50.3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

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

* Re: Custom colour for a custom command
  2015-10-02 19:13   ` Sharon Kimble
@ 2015-10-03  0:47     ` Emanuel Berg
  2015-10-03  1:16       ` Emanuel Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2015-10-03  0:47 UTC (permalink / raw)
  To: help-gnu-emacs

Sharon Kimble <boudiccas@skimble.plus.com> writes:

>>> I have a latex command called "\myparencite{foo}"
>>> which has the same colour as the surrounding text.
>> (font-lock-add-keywords 'latex-mode
>> '(("\\(myparencite\\){\\(.*\\)}" (1
>> font-lock-constant-face) (2 font-lock-doc-face) )))
>
> This is working well, except in this situation -
>
>  \myparencite{1767}[18] and N-methyl-serotonin
> \parencite{ }[19].
>
> where the green colouration continues after
> \myparencite into the following text, and even
> colouring the \parencite which has not yet been
> worked on.

Okay, well obviously that shouldn't happen so then
there is a bug in the regexp. Stay tuned...

> These two lines are from my theme, if its relevant
>
>  '(font-lock-constant-face ((t (:foreground
> "#A6E22E")))) '(font-lock-doc-face ((t (:foreground
> "#EEDC82"))))

It is relevant in the sense that there you set those
color constants to the colors you'd like, but that is
the fun and easy part once the regexp matches.

Note that font-lock-constant-face and -doc- ditto are
only placeholders for a color in this case, so instead
of changing those colors (unless for some other reason
of course) in this case you probably have colors that
you like already, so pick the font-lock-constant-*s
that correspond to them you like. Because obviously if
you change the colors in your theme them will change
not only those two new matches (when it works) but all
Emacs which uses those font constants, and that should
be a lot and the more the marrier. Right?

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: Custom colour for a custom command
  2015-10-03  0:47     ` Emanuel Berg
@ 2015-10-03  1:16       ` Emanuel Berg
  2015-10-04  0:22         ` Emanuel Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2015-10-03  1:16 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

>> This is working well, except in this situation -
>>
>> \myparencite{1767}[18] and N-methyl-serotonin
>> \parencite{ }[19].
>>
>> where the green colouration continues after
>> \myparencite into the following text, and even
>> colouring the \parencite which has not yet been
>> worked on.
>
> Okay, well obviously that shouldn't happen so then
> there is a bug in the regexp. Stay tuned...

Try this:

(font-lock-add-keywords 'latex-mode
                        '(("\\(myparencite\\){\\(\\(.\\|\n\\)*?\\)}"
                           (1 font-lock-constant-face)
                           (2 font-lock-doc-face) )))

Here is a dump that shows that it works :P

    http://user.it.uu.se/~embe8573/dumps/faces.png

But seriously, this is a quick fix that is useful to
know and often to use but for more complicated stuff
it will run into to problems - that are patchable (?)
- sooner or later anyway (both the problems and the
patches).

So probably instead I'd be content with just
highlighting the command which will make for
a super-easy regexp and a most-definitely tangible
improvement at low cost.

Otherwise dig deep. Here, I have a piece of code that
hopefully will discourage you from such long-ear
workaholicism - highlighting starts line 246. No, only
those mad, or very enthusiastic, do that sort of
things...

    http://user.it.uu.se/~embe8573/fps/fpscalc.el

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: Custom colour for a custom command
  2015-10-03  1:16       ` Emanuel Berg
@ 2015-10-04  0:22         ` Emanuel Berg
  0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-10-04  0:22 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> So probably instead I'd be content with just
> highlighting the command which will make for
> a super-easy regexp and a most-definitely tangible
> improvement at low cost.

(font-lock-add-keywords 'latex-mode
                        '(("myparencite" . font-lock-constant-face )))

Note the change in notation which comes with this
being only one word with no syntactic somersaults to
it which has to be dealt with by grouping (the
\\( ... \\) in the previous suggestion, groups which
are refered to by the enumeration digits that are also
unnecessary now).

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

end of thread, other threads:[~2015-10-04  0:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-30 17:49 Custom colour for a custom command Sharon Kimble
2015-10-02  0:00 ` Emanuel Berg
2015-10-02 19:13   ` Sharon Kimble
2015-10-03  0:47     ` Emanuel Berg
2015-10-03  1:16       ` Emanuel Berg
2015-10-04  0:22         ` Emanuel Berg

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.