* bug#8174: 24.0.50; `replace-match' doesn't work right with propertized text
@ 2011-03-04 22:16 Drew Adams
2011-03-04 22:42 ` Drew Adams
2011-03-05 4:18 ` Stefan Monnier
0 siblings, 2 replies; 5+ messages in thread
From: Drew Adams @ 2011-03-04 22:16 UTC (permalink / raw)
To: 8174
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'
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#8174: 24.0.50; `replace-match' doesn't work right with propertized text
2011-03-04 22:16 bug#8174: 24.0.50; `replace-match' doesn't work right with propertized text Drew Adams
@ 2011-03-04 22:42 ` Drew Adams
2011-03-05 0:01 ` Drew Adams
2011-03-05 4:18 ` Stefan Monnier
1 sibling, 1 reply; 5+ messages in thread
From: Drew Adams @ 2011-03-04 22:42 UTC (permalink / raw)
To: 8174
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#8174: 24.0.50; `replace-match' doesn't work right with propertized text
2011-03-04 22:16 bug#8174: 24.0.50; `replace-match' doesn't work right with propertized text Drew Adams
2011-03-04 22:42 ` Drew Adams
@ 2011-03-05 4:18 ` Stefan Monnier
2011-03-05 5:05 ` Drew Adams
1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2011-03-05 4:18 UTC (permalink / raw)
To: Drew Adams; +Cc: 8174
> (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
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#8174: 24.0.50; `replace-match' doesn't work right with propertized text
2011-03-05 4:18 ` Stefan Monnier
@ 2011-03-05 5:05 ` Drew Adams
0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2011-03-05 5:05 UTC (permalink / raw)
To: 'Stefan Monnier'; +Cc: 8174
> > (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'.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-03-05 5:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-04 22:16 bug#8174: 24.0.50; `replace-match' doesn't work right with propertized text Drew Adams
2011-03-04 22:42 ` Drew Adams
2011-03-05 0:01 ` Drew Adams
2011-03-05 4:18 ` Stefan Monnier
2011-03-05 5:05 ` Drew Adams
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).