all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#9871: `query-replace' and friends break text properties
@ 2011-10-25 22:20 Štěpán Němec
  2019-08-19  0:03 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Štěpán Němec @ 2011-10-25 22:20 UTC (permalink / raw)
  To: 9871

emacs -Q
(put-text-property (point-min) (point) 'oh-no! t)
M-<
M-% buffer RET fluffer RET y

Whoops, the property's gone in the replaced text.

The replacement commands should honour text properties just as
`self-insert-command' does.

-- 
Štěpán





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

* bug#9871: `query-replace' and friends break text properties
  2011-10-25 22:20 bug#9871: `query-replace' and friends break text properties Štěpán Němec
@ 2019-08-19  0:03 ` Lars Ingebrigtsen
  2019-08-19  0:57   ` Drew Adams
  2019-08-19  8:43   ` Štěpán Němec
  0 siblings, 2 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2019-08-19  0:03 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: 9871

Štěpán Němec <stepnem@gmail.com> writes:

> emacs -Q
> (put-text-property (point-min) (point) 'oh-no! t)
> M-<
> M-% buffer RET fluffer RET y
>
> Whoops, the property's gone in the replaced text.
>
> The replacement commands should honour text properties just as
> `self-insert-command' does.

I guess the question becomes -- what text properties should be in the
result?

If you have

(with-temp-buffer
  (insert (propertize "hel" 'face 'bold))
  (insert (propertize "lo" 'face 'underline))
  (goto-char (point-min))
  (replace-regexp "ell" "yes, well")
  (buffer-string))

should "yes, well" be in bold or underline?  Or a mix?  I don't really
think there's any solution here that will satisfy anybody.

But I guess it would make some sense to view this as "delete the text,
and then pretend we're inserting text as if by `self-insert-command'",
which would make the new text bold here.

I don't know...  all solutions here seem kinda ad hoc, so perhaps the
current behaviour is the least surprising.  Any opinions?

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





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

* bug#9871: `query-replace' and friends break text properties
  2019-08-19  0:03 ` Lars Ingebrigtsen
@ 2019-08-19  0:57   ` Drew Adams
  2019-08-19  8:43   ` Štěpán Němec
  1 sibling, 0 replies; 5+ messages in thread
From: Drew Adams @ 2019-08-19  0:57 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Štěpán Němec; +Cc: 9871

> I guess the question becomes -- what text properties should be in the
> result?
> 
> If you have
> 
> (with-temp-buffer
>   (insert (propertize "hel" 'face 'bold))
>   (insert (propertize "lo" 'face 'underline))
>   (goto-char (point-min))
>   (replace-regexp "ell" "yes, well")
>   (buffer-string))
> 
> should "yes, well" be in bold or underline?  Or a mix?  I don't really
> think there's any solution here that will satisfy anybody.
> 
> But I guess it would make some sense to view this as "delete the text,
> and then pretend we're inserting text as if by `self-insert-command'",
> which would make the new text bold here.
> 
> I don't know...  all solutions here seem kinda ad hoc, so perhaps the
> current behaviour is the least surprising.  Any opinions?

I take a slightly different position from both
of you, I guess.

I'd say that the replacement text should replace
the text to replace as if `delete-selection-mode'
were turned on and you (1) selected the text to
replace and then ` yanked the replacement text
from the kill ring to replace it.  The text props
are copied to the kill-ring as part of the text.
And yanking the text gives you copies that also
have those text properties.  Why shouldn't the
same behavior be available for query-replace?

If a user specifies replacement text that has
text properties then it should be used as is:
its properties should remain when it takes the
place of text in the buffer.

E.g. Copy some buffer text that has properties
into the kill ring. Then use `M-%' and yank that
copied, propertized text as the replacement text.
The places where it now appears as replacement
should all have the same text properties.  But
they don't seem to.





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

* bug#9871: `query-replace' and friends break text properties
  2019-08-19  0:03 ` Lars Ingebrigtsen
  2019-08-19  0:57   ` Drew Adams
@ 2019-08-19  8:43   ` Štěpán Němec
  2019-08-19 20:37     ` Lars Ingebrigtsen
  1 sibling, 1 reply; 5+ messages in thread
From: Štěpán Němec @ 2019-08-19  8:43 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 9871

On Sun, 18 Aug 2019 17:03:28 -0700
Lars Ingebrigtsen wrote:

> I guess the question becomes -- what text properties should be in the
> result?
>
> If you have
>
> (with-temp-buffer
>   (insert (propertize "hel" 'face 'bold))
>   (insert (propertize "lo" 'face 'underline))
>   (goto-char (point-min))
>   (replace-regexp "ell" "yes, well")
>   (buffer-string))
>
> should "yes, well" be in bold or underline?  Or a mix?  I don't really
> think there's any solution here that will satisfy anybody.
                                                    ^^^^^^^
I assume you meant "everybody".

> But I guess it would make some sense to view this as "delete the text,
> and then pretend we're inserting text as if by `self-insert-command'",
> which would make the new text bold here.

Yes it would. I also think that the straightforward case where all the
text has the same value for a property will be much more frequent than
your contrived example (note my property wasn't even visible at all; in
case of font-locking for example I'd expect the result to get
refontified as usual anyway).

> I don't know...  all solutions here seem kinda ad hoc, so perhaps the
> current behaviour is the least surprising.  Any opinions?

I definitely don't consider it the least surprising, but I guess you're
rather asking for the opinion of other people.

On Sun, 18 Aug 2019 17:57:18 -0700 (PDT)
Drew Adams wrote:

[...]

> If a user specifies replacement text that has
> text properties then it should be used as is:
> its properties should remain when it takes the
> place of text in the buffer.

[...]

Sure. For the yanking (i.e., interactive) case there's also
`yank-handled-properties' and `yank-excluded-properties'.

-- 
Štěpán





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

* bug#9871: `query-replace' and friends break text properties
  2019-08-19  8:43   ` Štěpán Němec
@ 2019-08-19 20:37     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2019-08-19 20:37 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: 9871

Štěpán Němec <stepnem@gmail.com> writes:

> Yes it would. I also think that the straightforward case where all the
> text has the same value for a property will be much more frequent than
> your contrived example (note my property wasn't even visible at all; in
> case of font-locking for example I'd expect the result to get
> refontified as usual anyway).

I just used a face because that's visible; the same applies to any text
property.

Thinking about it a bit more, I don't really feel that
delete-then-insert semantics will be very nice as a feature, either.

(with-temp-buffer
  (insert (propertize "hello" 'face 'bold))
  (goto-char (point-min))
  (replace-regexp "hello" "hey")
  (buffer-string))

If you replace a phrase that has one face with a different phrase, if
text properties are preserved, surely you'd expect that "hey" to also be
bold.  But it won't be, since the "hello" was deleted first and then
"hey" was inserted.

So I don't really think there's any way to DWIM here that is "what I
mean", and if you want to copy over text properties in one form of
another, you have to write some code to express what you want to have
happen.

So I'm closing this bug report.

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





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

end of thread, other threads:[~2019-08-19 20:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-25 22:20 bug#9871: `query-replace' and friends break text properties Štěpán Němec
2019-08-19  0:03 ` Lars Ingebrigtsen
2019-08-19  0:57   ` Drew Adams
2019-08-19  8:43   ` Štěpán Němec
2019-08-19 20:37     ` Lars Ingebrigtsen

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.