Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

format padding and text properties

5 views
Skip to first unread message

Eric Abrahamsen

unread,
Jun 22, 2016, 1:38:44 AM6/22/16
to help-gn...@gnu.org
I'm trying to pad out a string that has had a face applied to it, and
it's not quite going as I'd hoped. In a nutshell:

(setq ss "bubba")
(put-text-property 0 (length ss) 'face 'my-face ss)
(format "%10s" ss)

--> #(" bubba" 0 5 (face my-face))

I'd like the face to stay with the actual string, not the spaces! Does
text property stickiness have anything to do with this? Does anyone have
any clever tips?

Using Emacs git...

Thanks!
Eric


to...@tuxteam.de

unread,
Jun 22, 2016, 2:08:54 AM6/22/16
to help-gn...@gnu.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This is remarkable. I didn't even know that text properties made it
through format (admittedly in a strange way).

Learnt something new today :-)

regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAldqK10ACgkQBcgs9XrR2kaLlgCeKWgaxjgec2jD4zRnKIowTtV9
vl4An2hzEejXYD356p5U4CXAqWsP5BWg
=y28V
-----END PGP SIGNATURE-----

Eric Abrahamsen

unread,
Jun 22, 2016, 4:06:39 AM6/22/16
to help-gn...@gnu.org
<to...@tuxteam.de> writes:

> On Wed, Jun 22, 2016 at 01:38:16PM +0800, Eric Abrahamsen wrote:
>> I'm trying to pad out a string that has had a face applied to it, and
>> it's not quite going as I'd hoped. In a nutshell:
>>
>> (setq ss "bubba")
>> (put-text-property 0 (length ss) 'face 'my-face ss)
>> (format "%10s" ss)
>>
>> --> #(" bubba" 0 5 (face my-face))
>>
>> I'd like the face to stay with the actual string, not the spaces! Does
>> text property stickiness have anything to do with this? Does anyone have
>> any clever tips?
>
> This is remarkable. I didn't even know that text properties made it
> through format (admittedly in a strange way).
>
> Learnt something new today :-)

So you're saying I shouldn't expect this to Just Work? :)


Lars Magne Ingebrigtsen

unread,
Jun 22, 2016, 4:20:57 AM6/22/16
to Eric Abrahamsen, help-gn...@gnu.org
Eric Abrahamsen <er...@ericabrahamsen.net> writes:

> (setq ss "bubba")
> (put-text-property 0 (length ss) 'face 'my-face ss)
> (format "%10s" ss)
>
> --> #(" bubba" 0 5 (face my-face))

Is this with an up-to-date trunk? This should have been fixed a few
weeks ago:

commit 1c09423880e1c48d6ba02a196430e829d1d87d57
Author: Eli Zaretskii <el...@gnu.org>
Date: Thu Jun 9 16:52:08 2016 +0300

Fix copying text properties by 'format'


--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no

to...@tuxteam.de

unread,
Jun 22, 2016, 4:22:02 AM6/22/16
to help-gn...@gnu.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, Jun 22, 2016 at 04:06:21PM +0800, Eric Abrahamsen wrote:
> <to...@tuxteam.de> writes:

[...]

> > Learnt something new today :-)
>
> So you're saying I shouldn't expect this to Just Work? :)

You're over-estimating my chops, which is flattering :-)

I was just saying that *I* didn't expect that to Just Work. Let's
just wait until someone more knowledgeable chimes in (or until
I get a chance to RTFM: $DAYJOB has me in its claws at the moment)

regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAldqSpsACgkQBcgs9XrR2kb0gQCeLXevRDLDWB4YOSJYeGAgzN2+
drgAnjf4uVS+qkZJaSWrRstM+chwzDae
=uHsi
-----END PGP SIGNATURE-----

Eric Abrahamsen

unread,
Jun 22, 2016, 4:39:10 AM6/22/16
to help-gn...@gnu.org
Lars Magne Ingebrigtsen <l...@gnus.org> writes:

> Eric Abrahamsen <er...@ericabrahamsen.net> writes:
>
>> (setq ss "bubba")
>> (put-text-property 0 (length ss) 'face 'my-face ss)
>> (format "%10s" ss)
>>
>> --> #(" bubba" 0 5 (face my-face))
>
> Is this with an up-to-date trunk? This should have been fixed a few
> weeks ago:
>
> commit 1c09423880e1c48d6ba02a196430e829d1d87d57
> Author: Eli Zaretskii <el...@gnu.org>
> Date: Thu Jun 9 16:52:08 2016 +0300
>
> Fix copying text properties by 'format'

Ah! No wonder the bug seemed to crop up out of nowhere.

The bad news is the problem still seems to be there. I pulled and built
the master branch this morning, and can see Eli's patch in git log.

"GNU Emacs 25.1.50.5 (x86_64-unknown-linux-gnu, GTK+ Version 3.20.6)
of 2016-06-22"

Eric


Eli Zaretskii

unread,
Jun 22, 2016, 11:04:10 AM6/22/16
to help-gn...@gnu.org
> From: Eric Abrahamsen <er...@ericabrahamsen.net>
> Date: Wed, 22 Jun 2016 16:38:40 +0800
>
> > commit 1c09423880e1c48d6ba02a196430e829d1d87d57
> > Author: Eli Zaretskii <el...@gnu.org>
> > Date: Thu Jun 9 16:52:08 2016 +0300
> >
> > Fix copying text properties by 'format'
>
> Ah! No wonder the bug seemed to crop up out of nowhere.
>
> The bad news is the problem still seems to be there.

It's not a problem, it's the intended behavior.

If you want to put the face only on the text, either change the format
to not produce padding, or append the faceless spaces afterwards.

Eli Zaretskii

unread,
Jun 22, 2016, 11:06:42 AM6/22/16
to help-gn...@gnu.org
> Date: Wed, 22 Jun 2016 08:08:29 +0200
> From: <to...@tuxteam.de>
>
> This is remarkable. I didn't even know that text properties made it
> through format (admittedly in a strange way).

It's not strange: the entire text produced from 'format' inherits the
faces both from the string arguments and from the format descriptor.

Eric Abrahamsen

unread,
Jun 22, 2016, 11:11:28 AM6/22/16
to help-gn...@gnu.org
Okay, good to know. I'll adjust my code accordingly.


to...@tuxteam.de

unread,
Jun 23, 2016, 2:31:04 AM6/23/16
to help-gn...@gnu.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

:-)

That's how miracles go: if you totally not expect something, then you
don't look it up in the docs...

Thanks y'all for teaching me something new.

Regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAldrgg8ACgkQBcgs9XrR2kb50gCdEdurTyNa7LksoUEorhsIyROi
yjoAnj1oLjxI8vlKvwvtZmoB+aZAFbRD
=rQF9
-----END PGP SIGNATURE-----

0 new messages