unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Overriding some face attributes without changing the default(s) one(s)
@ 2014-06-06 11:32 Alexandre LAURENT
  2014-06-07  6:55 ` Alex Kost
  2014-06-07 18:52 ` Michael Heerdegen
  0 siblings, 2 replies; 8+ messages in thread
From: Alexandre LAURENT @ 2014-06-06 11:32 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I am trying to customize the whitespace-mode face for "long" lines.
By default, a specific face is defined for long lines but it is kind
of ugly in my case.
I would actually like these lines to look the same color as usual with
weight = bold, i.e. keeping the syntax highlighting (keywords,
strings, function names, etc.), but overriding weight or underline
attributes.

From http://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html,
it seems that setting some attributes to undefined "tells Emacs to
refer to a parent face", but not sure what the parent is in this case
anyway.

Moreover, if I don't set foreground / background at all, these are
just resets to the default face (I suppose).

Since there are multiple different faces for syntax highlighting, and
only one for long lines, I'm not sure that this is even possible. But
if it is, any ideas?

Thanks,

-- 
Alexandre LAURENT



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

* Re: Overriding some face attributes without changing the default(s) one(s)
  2014-06-06 11:32 Overriding some face attributes without changing the default(s) one(s) Alexandre LAURENT
@ 2014-06-07  6:55 ` Alex Kost
  2014-06-07 18:52 ` Michael Heerdegen
  1 sibling, 0 replies; 8+ messages in thread
From: Alex Kost @ 2014-06-07  6:55 UTC (permalink / raw)
  To: Alexandre LAURENT; +Cc: help-gnu-emacs

Alexandre LAURENT (2014-06-06 15:32 +0400) wrote:

> Hi,
>
> I am trying to customize the whitespace-mode face for "long" lines.
> By default, a specific face is defined for long lines but it is kind
> of ugly in my case.
> I would actually like these lines to look the same color as usual with
> weight = bold, i.e. keeping the syntax highlighting (keywords,
> strings, function names, etc.), but overriding weight or underline
> attributes.
>
> From http://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html,
> it seems that setting some attributes to undefined "tells Emacs to
> refer to a parent face", but not sure what the parent is in this case
> anyway.
>
> Moreover, if I don't set foreground / background at all, these are
> just resets to the default face (I suppose).
>
> Since there are multiple different faces for syntax highlighting, and
> only one for long lines, I'm not sure that this is even possible. But
> if it is, any ideas?
>
> Thanks,

I'm not sure I understand the question, but you can customize any face
like this:

  M-x customize-face whitespace-line

or a whole group:

  M-x customize-group whitespace

If you need to do it with elisp, try the following:

  (set-face-attribute 'whitespace-line nil :background 'unspecified :weight 'bold)



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

* Re: Overriding some face attributes without changing the default(s) one(s)
  2014-06-06 11:32 Overriding some face attributes without changing the default(s) one(s) Alexandre LAURENT
  2014-06-07  6:55 ` Alex Kost
@ 2014-06-07 18:52 ` Michael Heerdegen
  2014-06-07 23:09   ` Alexandre LAURENT
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2014-06-07 18:52 UTC (permalink / raw)
  To: help-gnu-emacs

Alexandre LAURENT <shaoner@gmail.com> writes:

> Hi,
>
> I am trying to customize the whitespace-mode face for "long" lines.
> By default, a specific face is defined for long lines but it is kind
> of ugly in my case.
> I would actually like these lines to look the same color as usual with
> weight = bold, i.e. keeping the syntax highlighting (keywords,
> strings, function names, etc.), but overriding weight or underline
> attributes.

Just configure the face to use the bold attribute, and leave all other
attributes emtpy.

> From
> http://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html,
> it seems that setting some attributes to undefined "tells Emacs to
> refer to a parent face", but not sure what the parent is in this case
> anyway.

This refers to inheritance, which is not directly related to what you
want.

> Since there are multiple different faces for syntax highlighting, and
> only one for long lines, I'm not sure that this is even possible. But
> if it is, any ideas?

What you want works well for me without doing anything special.  The
`whitespace-line' face is "merged" with the normal font locking, and I
see the colors from syntax highlighting, but in bold for long lines.

I'm not completely sure if that works in older Emacs version.
Anyway, just try it!

Michael.




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

* Re: Overriding some face attributes without changing the default(s) one(s)
  2014-06-07 18:52 ` Michael Heerdegen
@ 2014-06-07 23:09   ` Alexandre LAURENT
  2014-06-08  6:02     ` Alex Kost
  0 siblings, 1 reply; 8+ messages in thread
From: Alexandre LAURENT @ 2014-06-07 23:09 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

On Sat, Jun 7, 2014 at 8:52 PM, Michael Heerdegen
<michael_heerdegen@web.de> wrote:
> Just configure the face to use the bold attribute, and leave all other
> attributes emtpy.
>
Well, weird because that's exactly what I did but maybe not the right way.
In my case, I configure this face in a theme like this:

(custom-theme-set-faces
 'monokai-nox
;; ...
'(whitespace-line ((t (:weight bold))))
;; ...
)
If I open a C file, for each long line, the whole line still uses the
default whitespace-line face + bold (which prevents the syntax
highlighting)

> What you want works well for me without doing anything special.  The
> `whitespace-line' face is "merged" with the normal font locking, and I
> see the colors from syntax highlighting, but in bold for long lines.
>
Good to know, I'm going to test with an empty emacs config + the
configuration of the whitespace-line face.

> I'm not completely sure if that works in older Emacs version.
I'm using emacs 24.3.1 so this should work I suppose.

Thanks,

-- 
Alexandre LAURENT



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

* Re: Overriding some face attributes without changing the default(s) one(s)
  2014-06-07 23:09   ` Alexandre LAURENT
@ 2014-06-08  6:02     ` Alex Kost
  2014-06-08 20:23       ` Alexandre LAURENT
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Kost @ 2014-06-08  6:02 UTC (permalink / raw)
  To: Alexandre LAURENT; +Cc: Michael Heerdegen, help-gnu-emacs

Alexandre LAURENT (2014-06-08 03:09 +0400) wrote:

> On Sat, Jun 7, 2014 at 8:52 PM, Michael Heerdegen
> <michael_heerdegen@web.de> wrote:
>> Just configure the face to use the bold attribute, and leave all other
>> attributes emtpy.
>>
> Well, weird because that's exactly what I did but maybe not the right way.
> In my case, I configure this face in a theme like this:
>
> (custom-theme-set-faces
>  'monokai-nox
> ;; ...
> '(whitespace-line ((t (:weight bold))))
> ;; ...
> )
> If I open a C file, for each long line, the whole line still uses the
> default whitespace-line face + bold (which prevents the syntax
> highlighting)
>
>> What you want works well for me without doing anything special.  The
>> `whitespace-line' face is "merged" with the normal font locking, and I
>> see the colors from syntax highlighting, but in bold for long lines.
>>
> Good to know, I'm going to test with an empty emacs config + the
> configuration of the whitespace-line face.
>
>> I'm not completely sure if that works in older Emacs version.
> I'm using emacs 24.3.1 so this should work I suppose.

The problem is that in emacs 24.3.1 default face specifications are
merged with the face specifications defined by a theme, so what you see
is a "bold" defined by your theme and the bits from a default spec.  In
emacs 24.4 (and in the current trunk) your theme would work as expected:
if a face is themed, then the default spec is ignored completely.

If you want to make emacs 24.3.1 display only themed faces, you have to
override all the bits of the default spec in your theme (which sounds
horrible IMO), so for example the following should "free" your
background:

(custom-theme-set-faces
 'monokai-nox
;; ...
'(whitespace-line ((t (:background unspecified :weight bold))))
;; ...
)

If you are interested, I wrote something about that here:
<https://github.com/alezost/alect-themes/#emacs-2431-and-earlier>

Also there were some related bugs, for example:
<http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16658>

I hope it was helpful.

--
Alex Kost



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

* Re: Overriding some face attributes without changing the default(s) one(s)
  2014-06-08  6:02     ` Alex Kost
@ 2014-06-08 20:23       ` Alexandre LAURENT
  2014-06-09  6:26         ` Alex Kost
  0 siblings, 1 reply; 8+ messages in thread
From: Alexandre LAURENT @ 2014-06-08 20:23 UTC (permalink / raw)
  To: Alex Kost; +Cc: Michael Heerdegen, help-gnu-emacs

On Sun, Jun 8, 2014 at 8:02 AM, Alex Kost <alezost@gmail.com> wrote:
>
> The problem is that in emacs 24.3.1 default face specifications are
> merged with the face specifications defined by a theme, so what you see
> is a "bold" defined by your theme and the bits from a default spec.  In
> emacs 24.4 (and in the current trunk) your theme would work as expected:
> if a face is themed, then the default spec is ignored completely.
>
> If you want to make emacs 24.3.1 display only themed faces, you have to
> override all the bits of the default spec in your theme (which sounds
> horrible IMO), so for example the following should "free" your
Yes it is horrible, I wanted to avoid that.
> background:
>
> (custom-theme-set-faces
>  'monokai-nox
> ;; ...
> '(whitespace-line ((t (:background unspecified :weight bold))))
Actually, setting the foreground to unspecified does not work either.
I'm pretty sure it takes the "default" face and this face only, which
is different from the multiple faces applied when opening a source
file (no matter what that source file is).
I also define this default face in both my themes.
> ;; ...
> )
>
> If you are interested, I wrote something about that here:
> <https://github.com/alezost/alect-themes/#emacs-2431-and-earlier>
>
> Also there were some related bugs, for example:
> <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16658>
>
> I hope it was helpful.
Yes it is!

Since I definitely need emacs24.4 for some other features/fix (ex: the
rectangular region to be visually highlighted), I'll just wait for the
package to be available on my distro.

Thank you.

-- 
Alexandre LAURENT



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

* Re: Overriding some face attributes without changing the default(s) one(s)
  2014-06-08 20:23       ` Alexandre LAURENT
@ 2014-06-09  6:26         ` Alex Kost
  2014-06-09 18:10           ` Alexandre LAURENT
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Kost @ 2014-06-09  6:26 UTC (permalink / raw)
  To: Alexandre LAURENT; +Cc: help-gnu-emacs

Alexandre LAURENT (2014-06-09 00:23 +0400) wrote:

> On Sun, Jun 8, 2014 at 8:02 AM, Alex Kost <alezost@gmail.com> wrote:
>>
>> The problem is that in emacs 24.3.1 default face specifications are
>> merged with the face specifications defined by a theme, so what you see
>> is a "bold" defined by your theme and the bits from a default spec.  In
>> emacs 24.4 (and in the current trunk) your theme would work as expected:
>> if a face is themed, then the default spec is ignored completely.
>>
>> If you want to make emacs 24.3.1 display only themed faces, you have to
>> override all the bits of the default spec in your theme (which sounds
>> horrible IMO), so for example the following should "free" your
> Yes it is horrible, I wanted to avoid that.
>> background:
>>
>> (custom-theme-set-faces
>>  'monokai-nox
>> ;; ...
>> '(whitespace-line ((t (:background unspecified :weight bold))))
> Actually, setting the foreground to unspecified does not work either.
> I'm pretty sure it takes the "default" face and this face only, which
> is different from the multiple faces applied when opening a source
> file (no matter what that source file is).
> I also define this default face in both my themes.

Oh, now I understand what you want.  Actually here you faced with
another problem: when you enable whitespace-mode in emacs 24.3.1,
"whitespace-line" becomes the only active face in a long line, and in
emacs 24.4 it is added to the faces in that line.

So let's say, you have the following long line in a buffer with
"emacs-lisp-mode" (and "whitespace-mode" is enabled):

(defun some-function (arg1 arg2 &rest args) "A very useful function." (interactive) (message "Hello"))

If you move your cursor to the "defun" word and press "C-4 C-x =", in
the bottom of the "*Help*" buffer you will see:

There are text properties here:
  face                 whitespace-line
  fontified            t

I.e. only "whitespace-line" face is active and you can't see
"font-lock-keyword-face" (used for highlighting "defun") no matter how
you customized "whitespace-line".

As for emacs 24.4, you will see:

There are text properties here:
  face                 (whitespace-line font-lock-keyword-face)
  fontified            t

In this case if some bits of face spec are unspecified in
"whitespace-line" face, the ones from "font-lock-keyword-face" are used.

So that is not the same problem we were discussing before, but it is
also fixed in emacs 24.4.

>> ;; ...
>> )
>>
>> If you are interested, I wrote something about that here:
>> <https://github.com/alezost/alect-themes/#emacs-2431-and-earlier>
>>
>> Also there were some related bugs, for example:
>> <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16658>
>>
>> I hope it was helpful.
> Yes it is!
>
> Since I definitely need emacs24.4 for some other features/fix (ex: the
> rectangular region to be visually highlighted), I'll just wait for the
> package to be available on my distro.
>
> Thank you.




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

* Re: Overriding some face attributes without changing the default(s) one(s)
  2014-06-09  6:26         ` Alex Kost
@ 2014-06-09 18:10           ` Alexandre LAURENT
  0 siblings, 0 replies; 8+ messages in thread
From: Alexandre LAURENT @ 2014-06-09 18:10 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-gnu-emacs

On Mon, Jun 9, 2014 at 8:26 AM, Alex Kost <alezost@gmail.com> wrote:
> Oh, now I understand what you want.  Actually here you faced with
> another problem: when you enable whitespace-mode in emacs 24.3.1,
> "whitespace-line" becomes the only active face in a long line, and in
> emacs 24.4 it is added to the faces in that line.
>
> So let's say, you have the following long line in a buffer with
> "emacs-lisp-mode" (and "whitespace-mode" is enabled):
>
> (defun some-function (arg1 arg2 &rest args) "A very useful function." (interactive) (message "Hello"))
>
> If you move your cursor to the "defun" word and press "C-4 C-x =", in
> the bottom of the "*Help*" buffer you will see:
>
> There are text properties here:
>   face                 whitespace-line
>   fontified            t
>
> I.e. only "whitespace-line" face is active and you can't see
> "font-lock-keyword-face" (used for highlighting "defun") no matter how
> you customized "whitespace-line".
>
> As for emacs 24.4, you will see:
>
> There are text properties here:
>   face                 (whitespace-line font-lock-keyword-face)
>   fontified            t
>
> In this case if some bits of face spec are unspecified in
> "whitespace-line" face, the ones from "font-lock-keyword-face" are used.
>
> So that is not the same problem we were discussing before, but it is
> also fixed in emacs 24.4.
Ok, I thought both issues were somehow related.
The thing is, I was not sure how to highlight these long lines anyway,
but I just cannot have a single face to handle this.

I sometimes have to read code from people who don't care about these
kind of rules (yes, they could even develop their project in a single
line (I suppose that they don't plan to read their own code)), so ~70%
of the file loses the syntax highlighting in this case.
For now, I'll just remove "lines" from "whitespace-style" and define
something like this:
(add-hook 'prog-mode-hook
 (lambda ()
(font-lock-add-keywords
nil
'(("^[^\n]\\{80\\}\\(.*\\)$"
;;...
)))))
It should be enough, and I can catch and highlight the end of the line only.

Anyway, thanks it is clear now and I didn't know about "C-4 C-x =".

-- 
Alexandre LAURENT



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

end of thread, other threads:[~2014-06-09 18:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-06 11:32 Overriding some face attributes without changing the default(s) one(s) Alexandre LAURENT
2014-06-07  6:55 ` Alex Kost
2014-06-07 18:52 ` Michael Heerdegen
2014-06-07 23:09   ` Alexandre LAURENT
2014-06-08  6:02     ` Alex Kost
2014-06-08 20:23       ` Alexandre LAURENT
2014-06-09  6:26         ` Alex Kost
2014-06-09 18:10           ` Alexandre LAURENT

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