GNU bug report logs - #65632
30.0.50; Proposal to improve `faces--attribute-at-point'.

Previous Next

Package: emacs;

Reported by: David Ponce <da_vid <at> orange.fr>

Date: Wed, 30 Aug 2023 18:06:02 UTC

Severity: wishlist

Tags: moreinfo, patch

Found in version 30.0.50

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: David Ponce <da_vid <at> orange.fr>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 65632 <at> debbugs.gnu.org
Subject: bug#65632: 30.0.50; Proposal to improve `faces--attribute-at-point'.
Date: Thu, 31 Aug 2023 10:18:43 +0200
[Message part 1 (text/plain, inline)]
On 31/08/2023 00:30, David Ponce wrote:
> On 30/08/2023 21:22, Eli Zaretskii wrote:
>>> Cc: 65632 <at> debbugs.gnu.org
>>> Date: Wed, 30 Aug 2023 21:35:11 +0300
>>> From: Eli Zaretskii <eliz <at> gnu.org>
>>>
>>>> ;; Display "TEST" in red, bold, italic on yellow background.
>>>> (insert
>>>>    (propertize
>>>>     "TEST" 'font-lock-face
>>>>     '(bold ((:background "yellow") "italic"
>>>>             ((foreground-color . "red") underline)))))
>>>
>>> This is not a valid face, AFAIU.  That it works is sheer luck (because
>>> Emacs is very lenient with this stuff).  The correct face definition
>>> for what you want is this (see 'set-face-attribute's doc string):
>>>
>>>    (insert
>>>      (propertize
>>>       "TEST" 'font-lock-face
>>>       '(:weight bold :background "yellow" :slant italic
>>>          :foreground "red" :underline t)))
>>>
>>> If you use the above, foreground-color-at-point etc. will work as
>>> expected.
>>>
>>> I'm not sure we want to go out of our way to support the kind of face
>>> specifications that you used.
>>
>> However, if we do want that, we already have the technology:
>>
>>    (face-attributes-as-vector (get-char-property (point) 'font-lock-face))
>>
>> This will return a vector of face attribute values, where you can find
>> the value of any attribute you like.  For example, to get the
>> foreground color, evaluate:
>>
>>    (aref 9
>>      (face-attributes-as-vector (get-char-property (point) 'font-lock-face)))
> 
> Hi Eli,
> 
> Thank you very much for letting me know about `face-attributes-as-vector'
> (maybe its doc string could be improved?).  It is exactly the function I need :-)
> 
> In case you are interested, I attached an updated patch to faces.el that use
> this function to lookup face attribute, which improves and simplify  the
> functions `faces--attribute-at-point', `foreground-color-at-point' and
> `background-color-at-point'.
> 
> Regards

Please find attached a revised patch.  I used the name
`faces-attribute' instead of `face-attribute-lookup' for consistency
with `faces--attribute-at-point'.  I simplified this new function
because `face-attributes-as-vector' always returns the symbol
`unspecified' when an attribute is not specified (according to what I
understand of the implementation in xfaces.c).  I also improved the
doc string to include a link to the Elisp manual regarding the meaning
of face specification.

Here is an updated changelog:

	* faces.el: Improve attribute lookup of face at point.
	(face--attribute-index): New constant.
	(faces-attribute): New function.
	(faces--attribute-at-point): Use it.  Remove unused argument.
	(foreground-color-at-point)
	(background-color-at-point): Call accordingly.



Regards
[faces-attribute-lookup-V2.patch (text/x-patch, attachment)]

This bug report was last modified 114 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.