Use variable in setcustom

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Use variable in setcustom

Ergus
Hi I want to have a simple colour palette that must be compatible with
tui and gui.

The problem is that the color names are not the same so for example the
brightblack are not available in gui only in tui.

To work around this I made:

```
(defconst my/colors '((black . "#000000")
                      (red . "#cd0000")
                       ...
                       (brightcyan . "#00ffff")
                      (brightwhite . "#ffffff"))
   "List of colors.")
```

And then I assign the colors with something like:

```
(set-face-foreground 'font-lock-preprocessor-face (cdr (assq 'magenta
my/colors)))
```

But if I try to use a better method for my colors as Stefan suggested:

(custom-set-face ...)

It doesn't work. Do we have some method to define colours or paletes?

So that I could use a similar approach like?

```
(set-face-foreground 'font-lock-preprocessor-face "mycolor")
```

Thanks in advance,
Ergus

Reply | Threaded
Open this post in threaded view
|

Re: Use variable in setcustom

Eli Zaretskii
> Date: Sun, 10 Nov 2019 03:30:36 +0100
> From: Ergus <[hidden email]>
>
> Do we have some method to define colours or paletes?
>
> So that I could use a similar approach like?
>
> ```
> (set-face-foreground 'font-lock-preprocessor-face "mycolor")
> ```

Color names are passed to the underlying GUI system, so you cannot
easily invent your own.

Reply | Threaded
Open this post in threaded view
|

Re: Use variable in setcustom

Yuri Khan-2
In reply to this post by Ergus
On Sun, 10 Nov 2019 at 09:31, Ergus <[hidden email]> wrote:
>
> Hi I want to have a simple colour palette that must be compatible with
> tui and gui.

The practical solution to that is to use a (stack of) terminal
emulator(s) that supports 24-bit colors.

> The problem is that the color names are not the same so for example the
> brightblack are not available in gui only in tui.
>
> To work around this I made:
>
> ```
> (defconst my/colors '((black . "#000000")
>                       (red . "#cd0000")
>                        ...
>                        (brightcyan . "#00ffff")
>                       (brightwhite . "#ffffff"))
>    "List of colors.")
> ```
>
> And then I assign the colors with something like:
>
> ```
> (set-face-foreground 'font-lock-preprocessor-face (cdr (assq 'magenta
> my/colors)))
> ```
>
> But if I try to use a better method for my colors as Stefan suggested:
>
> (custom-set-face ...)
>
> It doesn't work. Do we have some method to define colours or paletes?

Custom themes. Which are arbitrary Elisp code and can thus define and
use variables:

    (defconst yk-scarletred "#ef2929")

    (custom-theme-set-faces 'yk-dark-theme
      …
      `(yk-incorrect
        ((((type graphic)) . (:underline (:color ,yk-scarletred :style wave)))
         (((min-colors 16777216)) . (:foreground ,yk-scarletred :underline t))))
      `(trailing-whitespace ((default . (:inherit yk-incorrect))))
      …)

    (provide-theme 'yk-dark-theme)

You can use anti-quoted variables or expressions with custom-set-face,
too (I just think themes are cleaner):

    (custom-set-faces
     `(font-lock-preprocessor-face
       ((default :foreground ,(cdr (assq 'magenta my/colors))))))

Reply | Threaded
Open this post in threaded view
|

[OFFTOPIC] Re: Use variable in setcustom

VanL
Yuri Khan <[hidden email]> writes:

> On Sun, 10 Nov 2019 at 09:31, Ergus <[hidden email]> wrote:
>>
>> Hi I want to have a simple colour palette that must be compatible with
>> tui and gui.
>
> The practical solution to that is to use a (stack of) terminal
> emulator(s) that supports 24-bit colors.
>
>> The problem is that the color names are not the same so for example the
>> brightblack are not available in gui only in tui.
>>

I don't know if this is possible.  Can a monochrome theme
work on gui/tui and be included in the standard source
distribution?  To my eyes the color choices in the default
options feel uncomfortable.  What I've learned to do is to
say change blue1 to blue3, for example.  Which is doable in
gui.

--
© 2019 VanL
gpg using EEF2 37E9 3840 0D5D 9183  251E 9830 384E 9683 B835
          'If the bug bites,don't fight it.' - Nancy S. Steinhardt