GNU bug report logs - #8174
24.0.50; `replace-match' doesn't work right with propertized text

Previous Next

Package: emacs;

Reported by: "Drew Adams" <drew.adams <at> oracle.com>

Date: Fri, 4 Mar 2011 22:18:01 UTC

Severity: normal

Found in version 24.0.50

Done: "Drew Adams" <drew.adams <at> oracle.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8174 in the body.
You can then email your comments to 8174 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8174; Package emacs. (Fri, 04 Mar 2011 22:18:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Drew Adams" <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 04 Mar 2011 22:18:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: <bug-gnu-emacs <at> gnu.org>
Subject: 24.0.50; `replace-match' doesn't work right with propertized text
Date: Fri, 4 Mar 2011 14:16:06 -0800
C-x C-f foo.txt
 
Type this text (between the lines) into buffer foo.txt:
 
--------------------------------
toto
titi
tata
tutu
tete
 

(defun foo ()
  (interactive)
  (require 'image-dired)
  (save-excursion
    (goto-char (point-min))
    (re-search-forward "tata")
    (let* ((file  "@@@@@")
    (strg  (apply #'propertize "AAAAAA"
    `(display ,(image-dired-get-thumbnail-image file)
       rear-nonsticky (display)))))
      (replace-match strg))))
--------------------------------
 
Replace `@@@@@' in `foo's definition by a real image-file absolute file
name, and then evaluate the definition.  Then `M-x foo RET'.
 
I would expect the text `tata' to be replaced by the propertized string,
whose text is `AAAAAAA' and whose properties are as indicated.  IOW, I
would expect to see the image displayed in place of `tata'.
 
Instead, the image is displayed at a different location: in place of the
"ursi" in `save-excursion'.
 
If you put the cursor at the beginning of the displayed image (just
after the `c' of `save-excursion') and hit `C-u C-x =', you'll see
something like this in *Help*, with the image appearing after
`character: ' in *Help* (i.e. in place of `A'):
 
        character: A (65, #o101, #x41)
preferred charset: ascii (ASCII (ISO646 IRV))
       code point: 0x41
           syntax: w  which means: word
         category: .:Base, a:ASCII, l:Latin, r:Roman
      buffer code: #x41
        file code: #x41 (encoded by coding system iso-latin-1-dos)
          display: by this font (glyph code)
    uniscribe:-outline-Courier
New-normal-normal-normal-mono-13-*-*-*-c-*-iso8859-1 (#x24)
 
Character code properties: customize what to show
  name: LATIN CAPITAL LETTER A
  general-category: Lu (Letter, Uppercase)
 
There are text properties here:
  display              [Show]
  fontified            t
  rear-nonsticky       (display)
 
[back]
 
If you click the `Show' button for property `display' then you see,
correctly, the image spec for the thumbnail image - e.g.,
(image :type jpeg
:file "c:/.emacs.d/image-dired/abc_33e34a7116fe5da6ff6a9103c8774f02.thumb.jpg")
 
Similarly for each of the `A's that replaced `ursi'.  IOW, each
character `A' of the replacement has the proper `display' property.  But
the the image position is incorrect.  The wrong text seems to have been
replaced by `replace-match'.
 

In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
 of 2011-02-28 on 3249CTO
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.4) --no-opt --cflags
-Ic:/imagesupport/include'
 





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8174; Package emacs. (Fri, 04 Mar 2011 22:44:02 GMT) Full text and rfc822 format available.

Message #8 received at 8174 <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: <8174 <at> debbugs.gnu.org>
Subject: RE: bug#8174: 24.0.50;
	`replace-match' doesn't work right with propertized text
Date: Fri, 4 Mar 2011 14:42:13 -0800
Some additional info:

In Emacs 22.3, the same thing happens.  But in that case, the image is put at
yet a different position.  Instead of replacing the `ursi' in `save-excursion',
it replaces the `to\nt' of `toto\ntiti'.  The displayed result is this:

to|---------------|iti

where |---------------| is location of the displayed image.


Seems like a longstanding bug, but it manifests itself a bit differently now.





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8174; Package emacs. (Sat, 05 Mar 2011 00:03:01 GMT) Full text and rfc822 format available.

Message #11 received at 8174 <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: <8174 <at> debbugs.gnu.org>
Subject: RE: bug#8174: 24.0.50;
	`replace-match' doesn't work right with propertized text
Date: Fri, 4 Mar 2011 16:01:46 -0800
Besides a fix for this bug, I would like to know about any workarounds that
might be usable in releases where the bug is not yet fixed.  Thx.





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8174; Package emacs. (Sat, 05 Mar 2011 04:19:02 GMT) Full text and rfc822 format available.

Message #14 received at 8174 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: "Drew Adams" <drew.adams <at> oracle.com>
Cc: 8174 <at> debbugs.gnu.org
Subject: Re: bug#8174: 24.0.50;
	`replace-match' doesn't work right with propertized text
Date: Fri, 04 Mar 2011 23:18:10 -0500
> (defun foo ()
>   (interactive)
>   (require 'image-dired)
>   (save-excursion
>     (goto-char (point-min))
>     (re-search-forward "tata")
>     (let* ((file  "@@@@@")
>     (strg  (apply #'propertize "AAAAAA"
>     `(display ,(image-dired-get-thumbnail-image file)
>        rear-nonsticky (display)))))
>       (replace-match strg))))
> --------------------------------
 
> Replace `@@@@@' in `foo's definition by a real image-file absolute file
> name, and then evaluate the definition.  Then `M-x foo RET'.
 
> I would expect the text `tata' to be replaced by the propertized string,
> whose text is `AAAAAAA' and whose properties are as indicated.  IOW, I
> would expect to see the image displayed in place of `tata'.

First things first: (ignoring the lack of check that re-search-forward
indeed succeeded) the only things allowed between the string match and
the use of the match-data are a few Emacs primitives known to leave the
match-data untouched.  image-dired-get-thumbnail-image is not one of
those primitives.


        Stefan




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8174; Package emacs. (Sat, 05 Mar 2011 05:06:02 GMT) Full text and rfc822 format available.

Message #17 received at 8174 <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: "'Stefan Monnier'" <monnier <at> iro.umontreal.ca>
Cc: 8174 <at> debbugs.gnu.org
Subject: RE: bug#8174: 24.0.50;
	`replace-match' doesn't work right with propertized text
Date: Fri, 4 Mar 2011 21:05:32 -0800
> >     (re-search-forward "tata")
> >     (let* ((file  "@@@@@")
> >     (strg  (apply #'propertize "AAAAAA"
> >     `(display ,(image-dired-get-thumbnail-image file)
> >        rear-nonsticky (display)))))
> >       (replace-match strg))))
>  
> First things first: (ignoring the lack of check that
> re-search-forward indeed succeeded)

The real code uses (when (re-search-forward... nil t)...).

> the only things allowed between the string match and
> the use of the match-data are a few Emacs primitives known to 
> leave the match-data untouched.  image-dired-get-thumbnail-image
> is not one of those primitives.

Yes, that's the problem here, so no bug.  I was not expecting to need to wrap
the `(apply... )' in `save-match-data'.  Usually I can pretty much tell when the
match data gets modified, but I guess I should have looked closer at
`image-dired-get-thumbnail-image'.





bug closed, send any further explanations to 8174 <at> debbugs.gnu.org and "Drew Adams" <drew.adams <at> oracle.com> Request was from "Drew Adams" <drew.adams <at> oracle.com> to control <at> debbugs.gnu.org. (Sat, 05 Mar 2011 05:08:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 02 Apr 2011 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 14 years and 140 days ago.

Previous Next


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