emacs-devel
[Top][All Lists]
Advanced

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

Re: wdired.el 1.7 --- Rename files editing their names in dired buffers


From: Juan Leon Lahoz Garcia
Subject: Re: wdired.el 1.7 --- Rename files editing their names in dired buffers
Date: Wed, 07 Nov 2001 11:40:45 -0500

>>>>> "rms" == Richard Stallman <address@hidden> writes:

    rms> For query-replace and such, we could make perform-replace
    rms> understand read-only text regions and skip them. That may be
    rms> useful in general. Please try editing perform-replace in this
    rms> way.

OK, here it goes a patch to replace.el. I've modified replace.el in
Emacs 21.1. This patch makes `perform-replace' (used by
`query-replace' `query-replace-regexp' `replace-string', etc) to
ignore matches that contains read-only properties or are in a read-only
buffer. Without this patch, replace commands fails when they try to
replace a match, even if there are remaining writable matches.

The performance of `perform-replace' decreases with this patch applied.

Please, take a look at this patch. It would need further testing,
specially in complex replacements operations. Style and performance of
it could be improved, I suppose.

I would like to know if you think that `perform-replace' should be
aware about read-only text to skip them (another solution for it,
maybe more efficient, would be modify built-in search commands to be
"customizables" about requisites of the text searched).

I'm sorry and I apologize for this, but I don't know what is the diff
output I need to send (diff options and order of the files passed to
diff), so I post the patch in "manual-style":

1-Add this function to replace.el:

(defun replace-match-non-writable-p()
  "Check that the chars of the last match do not have read-only properties."
  (or buffer-read-only
      (let ((pos-beg (- (match-beginning 0) 1))
            (pos-end (- (match-end 0) 1)))
        (setq pos-beg (max pos-beg 1))
        (while (and (< pos-beg pos-end)
                    (not (get-text-property pos-beg 'read-only)))
          (setq pos-beg (1+ pos-beg)))
        (get-text-property pos-beg 'read-only))))


2-Replace these lines:

                                 (funcall search-function search-string limit t)
                                 ;; For speed, use only integers and
                                 ;; reuse the list used last time.
                                 (match-data t real-match-data)))))

by these:

                                 (let ((match-found
                                        (funcall search-function search-string 
limit t)))
                                   (while
                                       (and match-found
                                            (replace-match-non-writable-p))
                                     (setq match-found
                                           (funcall search-function 
search-string limit t)))
                                   ;; For speed, use only integers and
                                   ;; reuse the list used last time.
                                   (and match-found
                                        (match-data t real-match-data)))))))
 

--
Leon




reply via email to

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