all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Trying to define face dynamically
@ 2019-10-17 18:54 Óscar Fuentes
  2019-10-17 19:30 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Óscar Fuentes @ 2019-10-17 18:54 UTC (permalink / raw)
  To: help-gnu-emacs

(Apologies if this message arrives duplicated. Seems that gmane is
eatin/delaying messages again)

On this mode, which uses Emacs 27 specific features:

https://raw.githubusercontent.com/dcolascione/emacs-window-highlight/master/window-highlight.el

I stumbled on

(mapcar (lambda (face)
           (face-remap-add-relative
              face '(:filtered (:window has-keyboard-focus t)
                       window-highlight-focused-window)))
    '(default fringe))

This remaps faces "default" and "fringe" to the face
window-highlight-focused-window (defined elsewhere by the user).

I'm trying to get rid of the hard-coded window-highlight-focused-window
face, take the current face and calculate the new attributes on the fly,
so when the theme changes everything is automatically adapted.

Teorically this would darken the background of the windows that have no
keyboard focus by 10%:

(mapcar (lambda (face)
           (face-remap-add-relative
              face `(:filtered (:window has-keyboard-focus nil)
                     :background ,(color-darken-name
                                   (face-attribute face :background)
				   10.0))))
    '(default fringe))

But this has not the desired effect: faces remain the same and every now
and then Emacs throws an error "wrong-type-argument stringp nil" from
functions such as font-info.

What I'm doing wrong?



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

* Re: Trying to define face dynamically
  2019-10-17 18:54 Trying to define face dynamically Óscar Fuentes
@ 2019-10-17 19:30 ` Eli Zaretskii
  2019-10-17 19:54   ` Óscar Fuentes
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2019-10-17 19:30 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Óscar Fuentes <ofv@wanadoo.es>
> Date: Thu, 17 Oct 2019 20:54:34 +0200
> 
> (mapcar (lambda (face)
>            (face-remap-add-relative
>               face `(:filtered (:window has-keyboard-focus nil)
>                      :background ,(color-darken-name
>                                    (face-attribute face :background)
> 				   10.0))))
>     '(default fringe))
> 
> But this has not the desired effect: faces remain the same and every now
> and then Emacs throws an error "wrong-type-argument stringp nil" from
> functions such as font-info.
> 
> What I'm doing wrong?

You didn't say what color-darken-name does, but I think the problem is
that ':background "foo"' is not a face spec.  Did you try something
like '(background-color . ,(color-darken-name ...))' or maybe
'(:background ,(color-darken-name ...))' instead?



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

* Re: Trying to define face dynamically
  2019-10-17 19:30 ` Eli Zaretskii
@ 2019-10-17 19:54   ` Óscar Fuentes
  2019-10-18  0:15     ` Óscar Fuentes
  0 siblings, 1 reply; 4+ messages in thread
From: Óscar Fuentes @ 2019-10-17 19:54 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> (mapcar (lambda (face)
>>            (face-remap-add-relative
>>               face `(:filtered (:window has-keyboard-focus nil)
>>                      :background ,(color-darken-name
>>                                    (face-attribute face :background)
>> 				   10.0))))
>>     '(default fringe))
>> 
>> But this has not the desired effect: faces remain the same and every now
>> and then Emacs throws an error "wrong-type-argument stringp nil" from
>> functions such as font-info.
>> 
>> What I'm doing wrong?
>
> You didn't say what color-darken-name does, but I think the problem is
> that ':background "foo"' is not a face spec.  Did you try something
> like '(background-color . ,(color-darken-name ...))' or maybe
> '(:background ,(color-darken-name ...))' instead?

Thanks. Changing to either of your suggestions eliminates the error, but
the face is not altered.

My try was based on the example on the Info node of Face Remapping, that
shows this example:

          (face-remap-add-relative 'default :height 1.5)

which is itself confusing as the docstring says

"... SPECS, should form either a list of face names, or a property list
     of attribute/value pairs."

color-darken-name is a function defined in lisp/color.el.




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

* Re: Trying to define face dynamically
  2019-10-17 19:54   ` Óscar Fuentes
@ 2019-10-18  0:15     ` Óscar Fuentes
  0 siblings, 0 replies; 4+ messages in thread
From: Óscar Fuentes @ 2019-10-18  0:15 UTC (permalink / raw)
  To: help-gnu-emacs

Óscar Fuentes <ofv@wanadoo.es> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> (mapcar (lambda (face)
>>>            (face-remap-add-relative
>>>               face `(:filtered (:window has-keyboard-focus nil)
>>>                      :background ,(color-darken-name
>>>                                    (face-attribute face :background)
>>> 				   10.0))))
>>>     '(default fringe))
>>> 
>>> But this has not the desired effect: faces remain the same and every now
>>> and then Emacs throws an error "wrong-type-argument stringp nil" from
>>> functions such as font-info.
>>> 
>>> What I'm doing wrong?
>>
>> You didn't say what color-darken-name does, but I think the problem is
>> that ':background "foo"' is not a face spec.  Did you try something
>> like '(background-color . ,(color-darken-name ...))' or maybe
>> '(:background ,(color-darken-name ...))' instead?
>
> Thanks. Changing to either of your suggestions eliminates the error, but
> the face is not altered.

Eli's suggestion was right. The face change didn't apply because
specific actions are required by the minor mode to be effective.

For the record, this is the complete call:

(mapcar (lambda (face)
	  (face-remap-add-relative
	   face
	   `(:filtered
	     (:window has-keyboard-focus nil)
	     (:background
	      ,(color-darken-name
		(face-attribute 'default :background)
		3.0)))))
	'(default fringe))

This darkens the "default" and "fringe" background colors by 3% when the
window has no keyboard focus. Neat. Now, if we only had a hook for
detecting enabling/disabling of themes for invocating the code above
automatically...

I'll submit a bug report about that.




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

end of thread, other threads:[~2019-10-18  0:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-17 18:54 Trying to define face dynamically Óscar Fuentes
2019-10-17 19:30 ` Eli Zaretskii
2019-10-17 19:54   ` Óscar Fuentes
2019-10-18  0:15     ` Óscar Fuentes

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.