unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20872: 24.5; add-face-text-property doesn't work for :height
@ 2015-06-22 11:02 Oleh Krehel
  2015-06-22 15:10 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Oleh Krehel @ 2015-06-22 11:02 UTC (permalink / raw)
  To: 20872


Here's a code that works for setting a string foreground:

    (defface test-face
      '((t (:height 1.2 :foreground "green")))
      "doc.")
    (setq asdf (propertize "asdf" 'face 'test-face))
    (add-face-text-property 0 (length asdf) '(:foreground "red") nil asdf)

`asdf' will still have the height 1.2 through `test-face' while gaining
a red foreground, instead of green.

But this doesn't work:

    (add-face-text-property 0 (length asdf) '(:height 1.0) nil asdf)

While the text properties will change, when inserting `asdf' into a
`fundamental-mode' buffer, it will still have the height 1.2. How can I
set the height to 1.0, while preserving the face?

The actual use case is to offer propertized strings a choices in the
minibuffer. In that case, I want to keep all face properties, except the
height. Since extra height messes up the trimming of strings to
`window-width'.





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

* bug#20872: 24.5; add-face-text-property doesn't work for :height
  2015-06-22 11:02 bug#20872: 24.5; add-face-text-property doesn't work for :height Oleh Krehel
@ 2015-06-22 15:10 ` Eli Zaretskii
  2015-06-22 15:31 ` Wolfgang Jenkner
  2015-06-22 16:06 ` Stefan Monnier
  2 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2015-06-22 15:10 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: 20872

> From: Oleh Krehel <ohwoeowho@gmail.com>
> Date: Mon, 22 Jun 2015 13:02:45 +0200
> 
>     (defface test-face
>       '((t (:height 1.2 :foreground "green")))
>       "doc.")
>     (setq asdf (propertize "asdf" 'face 'test-face))
>     (add-face-text-property 0 (length asdf) '(:foreground "red") nil asdf)
> 
> `asdf' will still have the height 1.2 through `test-face' while gaining
> a red foreground, instead of green.
> 
> But this doesn't work:
> 
>     (add-face-text-property 0 (length asdf) '(:height 1.0) nil asdf)
> 
> While the text properties will change, when inserting `asdf' into a
> `fundamental-mode' buffer, it will still have the height 1.2. How can I
> set the height to 1.0, while preserving the face?

Untested: copy the face using copy-face, then change ':height'
attribute of the copied face using set-face-attribute, and finally
apply the modified face to the string.





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

* bug#20872: 24.5; add-face-text-property doesn't work for :height
  2015-06-22 15:31 ` Wolfgang Jenkner
@ 2015-06-22 15:30   ` Oleh Krehel
  0 siblings, 0 replies; 7+ messages in thread
From: Oleh Krehel @ 2015-06-22 15:30 UTC (permalink / raw)
  To: Wolfgang Jenkner; +Cc: 20872

Wolfgang Jenkner <wjenkner@inode.at> writes:

> A float as value of the :height attribute works as a scaling factor, see
> `set-face-attribute'.  So, IIUC, the following would work
>
> (add-face-text-property 0 (length asdf) `(:height ,(/ 1 1.2)) nil asdf)

Genius! This actually works. Thanks a lot.





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

* bug#20872: 24.5; add-face-text-property doesn't work for :height
  2015-06-22 11:02 bug#20872: 24.5; add-face-text-property doesn't work for :height Oleh Krehel
  2015-06-22 15:10 ` Eli Zaretskii
@ 2015-06-22 15:31 ` Wolfgang Jenkner
  2015-06-22 15:30   ` Oleh Krehel
  2015-06-22 16:06 ` Stefan Monnier
  2 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Jenkner @ 2015-06-22 15:31 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: 20872

On Mon, Jun 22 2015, Oleh Krehel wrote:

> But this doesn't work:
>
>     (add-face-text-property 0 (length asdf) '(:height 1.0) nil asdf)
>
> While the text properties will change, when inserting `asdf' into a
> `fundamental-mode' buffer, it will still have the height 1.2. How can I
> set the height to 1.0, while preserving the face?

A float as value of the :height attribute works as a scaling factor, see
`set-face-attribute'.  So, IIUC, the following would work

(add-face-text-property 0 (length asdf) `(:height ,(/ 1 1.2)) nil asdf)







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

* bug#20872: 24.5; add-face-text-property doesn't work for :height
  2015-06-22 11:02 bug#20872: 24.5; add-face-text-property doesn't work for :height Oleh Krehel
  2015-06-22 15:10 ` Eli Zaretskii
  2015-06-22 15:31 ` Wolfgang Jenkner
@ 2015-06-22 16:06 ` Stefan Monnier
  2015-06-23  9:20   ` Oleh Krehel
  2 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2015-06-22 16:06 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: 20872

>     (add-face-text-property 0 (length asdf) '(:height 1.0) nil asdf)

":height 1.0" means "multiply the height by 1", i.e. it's a no-op.

> minibuffer. In that case, I want to keep all face properties, except the
> height. Since extra height messes up the trimming of strings to
> `window-width'.

You can try to set :height to the *integer* pixel height of the
minibuffer lines.


        Stefan





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

* bug#20872: 24.5; add-face-text-property doesn't work for :height
  2015-06-22 16:06 ` Stefan Monnier
@ 2015-06-23  9:20   ` Oleh Krehel
  2015-06-23 13:38     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Oleh Krehel @ 2015-06-23  9:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 20872

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>     (add-face-text-property 0 (length asdf) '(:height 1.0) nil asdf)
>
> ":height 1.0" means "multiply the height by 1", i.e. it's a no-op.
>
>> minibuffer. In that case, I want to keep all face properties, except the
>> height. Since extra height messes up the trimming of strings to
>> `window-width'.
>
> You can try to set :height to the *integer* pixel height of the
> minibuffer lines.

Thanks, that's even better. Should I use this:

(add-face-text-property
 0 (length asdf)
 `(:height ,(face-attribute 'default :height)) nil asdf)






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

* bug#20872: 24.5; add-face-text-property doesn't work for :height
  2015-06-23  9:20   ` Oleh Krehel
@ 2015-06-23 13:38     ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2015-06-23 13:38 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: 20872

> Thanks, that's even better. Should I use this:

> (add-face-text-property
>  0 (length asdf)
>  `(:height ,(face-attribute 'default :height)) nil asdf)

Looks OK,


        Stefan





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

end of thread, other threads:[~2015-06-23 13:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-22 11:02 bug#20872: 24.5; add-face-text-property doesn't work for :height Oleh Krehel
2015-06-22 15:10 ` Eli Zaretskii
2015-06-22 15:31 ` Wolfgang Jenkner
2015-06-22 15:30   ` Oleh Krehel
2015-06-22 16:06 ` Stefan Monnier
2015-06-23  9:20   ` Oleh Krehel
2015-06-23 13:38     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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