bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problems with query-replace, replace-string


From: Chris
Subject: problems with query-replace, replace-string
Date: 21 Dec 2001 04:05:02 -0800

In article <200111142226.fAEMQjv01611@oswald.oakland.redhat.com>,
Spencer Thiel (sthiel@redhat.com) wrote

   > This sometimes replaced "Software Manager</h2>" with "Update
   > Assistanth2>", and "Software Manager</a>" with "Update
   > Assistanta>" clipping the </. It seems that the replacement
   > is happening to characters that aren't included inside the
   > search string.

I have seen the problem myself several times, and now believe I know
its cause:

In Emacs 21.1, replace.el has this:

        ((eq def 'act)
         (or replaced
          (progn
            (replace-match next-replacement nocasify literal)
            (setq replace-count (1+ replace-count))))

If the buffer is not modified before the 'query-replace' is run, then
the 'replace-match' call will be the first function call to modify the
buffer. When a buffer is first modified, emacs checks to see whether
if has been changed on disk. If the buffer is an ange-ftp buffer, then
this check is done by 'ange-ftp-file-modtime', which sends a 'mdtm'
command to the ftp process and uses 'string-match' to check the
returned date/time. That 'string-match' trashes the results of the
search that 'perform-replace' in replace.el has already done, so the
replace replaces the wrong substring of the buffer.

My fix to the problem is to replace this line of ange-ftp.el (it's
line 3445, in function 'ange-ftp-file-modtime'):
       (when (string-match "^213 [0-9]\\{14\\}$" line)
with this:
       (when (string-equal "213 " (substring line 0 4))

Perhaps it's not ideal - it's certainly not such a strict test of the
returned line, but it works for me. I guess I would rather somehow
call 'save_search_regs()' before and 'restore_match_data()' after the
string-match call in ange-ftp, but I don't know whether those 2
functions are available from Emacs Lisp.

I hope this is helpful. I'm pretty pleased with myself, anyway. :o)

If anything is unclear, or I can help further please don't hesitate to
email me  (but please note I really only have 2 'o's in my surname).

Chris.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]