all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to use display text property with after-string?
@ 2016-10-21  6:15 Marcin Borkowski
  2016-10-21  6:59 ` Joost Kremers
  2016-10-21  7:35 ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Marcin Borkowski @ 2016-10-21  6:15 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hi all,

I want to set the "display" text property so that some text is displayed
after the buffer part I'm setting the property to.  However, I can't do
it.  Consider an Elisp buffer with these contents:

--8<---------------cut here---------------start------------->8---
;; this is a comment

(put-text-property 14 21 'display '(after-string " which is cool!"))
--8<---------------cut here---------------end--------------->8---

After C-x C-e with point at the end, I see this:

--8<---------------cut here---------------start------------->8---
;; this is a comment

(put-text-property 14 21 'display '(after-string " which is cool!"))
--8<---------------cut here---------------end--------------->8---

but I expected this:

--8<---------------cut here---------------start------------->8---
;; this is a commentcomment

(put-text-property 14 21 'display '(after-string " which is cool!"))
--8<---------------cut here---------------end--------------->8---

What am I doing wrong?

TIA,

-- 
Marcin Borkowski



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

* Re: How to use display text property with after-string?
  2016-10-21  6:15 How to use display text property with after-string? Marcin Borkowski
@ 2016-10-21  6:59 ` Joost Kremers
  2016-10-21  7:35 ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Joost Kremers @ 2016-10-21  6:59 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list


On Fri, Oct 21 2016, Marcin Borkowski wrote:
> Hi all,
>
> I want to set the "display" text property so that some text is 
> displayed
> after the buffer part I'm setting the property to.  However, I 
> can't do
> it.  Consider an Elisp buffer with these contents:
>
> --8<---------------cut 
> here---------------start------------->8---
> ;; this is a comment
>
> (put-text-property 14 21 'display '(after-string " which is 
> cool!"))
> --8<---------------cut 
> here---------------end--------------->8---
>
> After C-x C-e with point at the end, I see this:
>
> --8<---------------cut 
> here---------------start------------->8---
> ;; this is a comment
>
> (put-text-property 14 21 'display '(after-string " which is 
> cool!"))
> --8<---------------cut 
> here---------------end--------------->8---
>
> but I expected this:
>
> --8<---------------cut 
> here---------------start------------->8---
> ;; this is a commentcomment
>
> (put-text-property 14 21 'display '(after-string " which is 
> cool!"))
> --8<---------------cut 
> here---------------end--------------->8---
>

I'm getting this (Emacs 25.1.2):

,----
| ;; this is a comment
| 
| (put-text-property 14 21 'display '(after-string " which is 
  cool!"))
`----

But looknig through the Elisp manual, it seems that `after-string' 
is an overlay property, not a text property, so what you're after 
probably isn't supposed to work.



-- 
Joost Kremers
Life has its moments



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

* Re: How to use display text property with after-string?
  2016-10-21  6:15 How to use display text property with after-string? Marcin Borkowski
  2016-10-21  6:59 ` Joost Kremers
@ 2016-10-21  7:35 ` Eli Zaretskii
  2016-10-21 19:41   ` Marcin Borkowski
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2016-10-21  7:35 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Marcin Borkowski <mbork@mbork.pl>
> Date: Fri, 21 Oct 2016 08:15:31 +0200
> 
> --8<---------------cut here---------------start------------->8---
> ;; this is a comment
> 
> (put-text-property 14 21 'display '(after-string " which is cool!"))
> --8<---------------cut here---------------end--------------->8---
> 
> After C-x C-e with point at the end, I see this:
> 
> --8<---------------cut here---------------start------------->8---
> ;; this is a comment
> 
> (put-text-property 14 21 'display '(after-string " which is cool!"))
> --8<---------------cut here---------------end--------------->8---
> 
> but I expected this:
> 
> --8<---------------cut here---------------start------------->8---
> ;; this is a commentcomment
> 
> (put-text-property 14 21 'display '(after-string " which is cool!"))
> --8<---------------cut here---------------end--------------->8---
> 
> What am I doing wrong?

The 'display' property doesn't support after-string, only the overlay
properties do.



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

* Re: How to use display text property with after-string?
  2016-10-21  7:35 ` Eli Zaretskii
@ 2016-10-21 19:41   ` Marcin Borkowski
  2016-10-21 20:04     ` Eli Zaretskii
  2016-10-22 19:49     ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Marcin Borkowski @ 2016-10-21 19:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


On 2016-10-21, at 09:35, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Marcin Borkowski <mbork@mbork.pl>
>> Date: Fri, 21 Oct 2016 08:15:31 +0200
>> 
>> --8<---------------cut here---------------start------------->8---
>> ;; this is a comment
>> 
>> (put-text-property 14 21 'display '(after-string " which is cool!"))
>> --8<---------------cut here---------------end--------------->8---
>> 
>> After C-x C-e with point at the end, I see this:
>> 
>> --8<---------------cut here---------------start------------->8---
>> ;; this is a comment
>> 
>> (put-text-property 14 21 'display '(after-string " which is cool!"))
>> --8<---------------cut here---------------end--------------->8---
>> 
>> but I expected this:
>> 
>> --8<---------------cut here---------------start------------->8---
>> ;; this is a commentcomment
>> 
>> (put-text-property 14 21 'display '(after-string " which is cool!"))
>> --8<---------------cut here---------------end--------------->8---
>> 
>> What am I doing wrong?
>
> The 'display' property doesn't support after-string, only the overlay
> properties do.

I see.  I was a bit afraid that is the case.

Is there any other way to put some nonexistent text in the buffer?
Overlays are not very good that, since I hear many overlays in a buffer
may slow things down.  My use case is as follows: I want to write
a function which will find all the dates in the US format (M/D/Y) in the
buffer and put a date in a sane format (maybe together with something
like "3 days ago" or "tomorrow") next to them.  (That would be very
useful for me, since I sometimes get emails from Americans, and dealing
with dates in M/D/Y format is a huge cognitive load for me;-).)

TIA,

-- 
Marcin Borkowski



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

* Re: How to use display text property with after-string?
  2016-10-21 19:41   ` Marcin Borkowski
@ 2016-10-21 20:04     ` Eli Zaretskii
  2016-10-22  3:57       ` Marcin Borkowski
  2016-10-22 19:49     ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2016-10-21 20:04 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Marcin Borkowski <mbork@mbork.pl>
> Cc: help-gnu-emacs@gnu.org
> Date: Fri, 21 Oct 2016 21:41:21 +0200
> 
> > The 'display' property doesn't support after-string, only the overlay
> > properties do.
> 
> I see.  I was a bit afraid that is the case.
> 
> Is there any other way to put some nonexistent text in the buffer?

What's wrong with 'display' text property?  Just make its value be a
string, not '(after-string "something").

> Overlays are not very good that, since I hear many overlays in a buffer
> may slow things down.  My use case is as follows: I want to write
> a function which will find all the dates in the US format (M/D/Y) in the
> buffer and put a date in a sane format (maybe together with something
> like "3 days ago" or "tomorrow") next to them.  (That would be very
> useful for me, since I sometimes get emails from Americans, and dealing
> with dates in M/D/Y format is a huge cognitive load for me;-).)

The 'display' text property whose value is a string causes that string
be displayed _instead_ of the text covered by the text property.
Which sounds exactly what you want.  One caveat: you cannot move
cursor through the display string (the same is true for
after-strings).



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

* Re: How to use display text property with after-string?
  2016-10-21 20:04     ` Eli Zaretskii
@ 2016-10-22  3:57       ` Marcin Borkowski
  0 siblings, 0 replies; 7+ messages in thread
From: Marcin Borkowski @ 2016-10-22  3:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


On 2016-10-21, at 22:04, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Marcin Borkowski <mbork@mbork.pl>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Fri, 21 Oct 2016 21:41:21 +0200
>> 
>> > The 'display' property doesn't support after-string, only the overlay
>> > properties do.
>> 
>> I see.  I was a bit afraid that is the case.
>> 
>> Is there any other way to put some nonexistent text in the buffer?
>
> What's wrong with 'display' text property?  Just make its value be a
> string, not '(after-string "something").

OK.

>> Overlays are not very good that, since I hear many overlays in a buffer
>> may slow things down.  My use case is as follows: I want to write
>> a function which will find all the dates in the US format (M/D/Y) in the
>> buffer and put a date in a sane format (maybe together with something
>> like "3 days ago" or "tomorrow") next to them.  (That would be very
>> useful for me, since I sometimes get emails from Americans, and dealing
>> with dates in M/D/Y format is a huge cognitive load for me;-).)
>
> The 'display' text property whose value is a string causes that string
> be displayed _instead_ of the text covered by the text property.
> Which sounds exactly what you want.  One caveat: you cannot move
> cursor through the display string (the same is true for
> after-strings).

Thanks.  It was not exactly what I wanted: I wanted a fragment of buffer
containing e.g.

10/25/16

to display as

10/25/16 [2016-10-25, 3 days from today]

Of course, I can include the original text in the `display' property,
but as you have pointed out, this is not the same (though I'm not even
shure whether it's not actually _better_).

Thanks a lot,

-- 
Marcin Borkowski



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

* Re: How to use display text property with after-string?
  2016-10-21 19:41   ` Marcin Borkowski
  2016-10-21 20:04     ` Eli Zaretskii
@ 2016-10-22 19:49     ` Stefan Monnier
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2016-10-22 19:49 UTC (permalink / raw)
  To: help-gnu-emacs

> Overlays are not very good that, since I hear many overlays in a buffer
> may slow things down.

They have some performance issues, but it's not so terrible that it
should stop you from using them.


        Stefan




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

end of thread, other threads:[~2016-10-22 19:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-21  6:15 How to use display text property with after-string? Marcin Borkowski
2016-10-21  6:59 ` Joost Kremers
2016-10-21  7:35 ` Eli Zaretskii
2016-10-21 19:41   ` Marcin Borkowski
2016-10-21 20:04     ` Eli Zaretskii
2016-10-22  3:57       ` Marcin Borkowski
2016-10-22 19:49     ` Stefan Monnier

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.