36 |
|
|
37 |
(defvar query-replace-history nil) |
(defvar query-replace-history nil) |
38 |
|
|
39 |
(defcustom query-replace-interactive nil |
(defvar query-replace-interactive nil |
40 |
"Non-nil means `query-replace' uses the last search string. |
"Non-nil means `query-replace' uses the last search string. |
41 |
That becomes the \"string to replace\". |
That becomes the \"string to replace\".") |
|
If value is `initial', the last search string is inserted into |
|
|
the minibuffer as an initial value for \"string to replace\"." |
|
|
:type '(choice (const :tag "Off" nil) |
|
|
(const :tag "Initial content" initial) |
|
|
(other :tag "Use default value" t)) |
|
|
:group 'matching) |
|
42 |
|
|
43 |
(defcustom query-replace-from-history-variable 'query-replace-history |
(defcustom query-replace-from-history-variable 'query-replace-history |
44 |
"History list to use for the FROM argument of `query-replace' commands. |
"History list to use for the FROM argument of `query-replace' commands. |
68 |
(unless noerror |
(unless noerror |
69 |
(barf-if-buffer-read-only)) |
(barf-if-buffer-read-only)) |
70 |
(let (from to) |
(let (from to) |
71 |
(if (and query-replace-interactive |
(if query-replace-interactive |
|
(not (eq query-replace-interactive 'initial))) |
|
72 |
(setq from (car (if regexp-flag regexp-search-ring search-ring))) |
(setq from (car (if regexp-flag regexp-search-ring search-ring))) |
73 |
;; The save-excursion here is in case the user marks and copies |
;; The save-excursion here is in case the user marks and copies |
74 |
;; a region in order to specify the minibuffer input. |
;; a region in order to specify the minibuffer input. |
76 |
(save-excursion |
(save-excursion |
77 |
(setq from (read-from-minibuffer |
(setq from (read-from-minibuffer |
78 |
(format "%s: " string) |
(format "%s: " string) |
79 |
(if (eq query-replace-interactive 'initial) |
nil nil nil |
|
(car (if regexp-flag regexp-search-ring search-ring))) |
|
|
nil nil |
|
80 |
query-replace-from-history-variable |
query-replace-from-history-variable |
81 |
nil t))) |
nil t))) |
82 |
;; Warn if user types \n or \t, but don't reject the input. |
;; Warn if user types \n or \t, but don't reject the input. |
260 |
only matches that are surrounded by word boundaries. |
only matches that are surrounded by word boundaries. |
261 |
Fourth and fifth arg START and END specify the region to operate on." |
Fourth and fifth arg START and END specify the region to operate on." |
262 |
(interactive |
(interactive |
263 |
(let (from to) |
(let* ((from (if query-replace-interactive |
264 |
(if query-replace-interactive |
(car regexp-search-ring) |
265 |
(setq from (car regexp-search-ring)) |
(read-from-minibuffer "Query replace regexp: " |
266 |
(setq from (read-from-minibuffer "Query replace regexp: " |
nil nil nil |
267 |
nil nil nil |
query-replace-from-history-variable |
268 |
query-replace-from-history-variable |
nil t))) |
269 |
nil t))) |
(to (list (read-from-minibuffer |
270 |
(setq to (list (read-from-minibuffer |
(format "Query replace regexp %s with eval: " from) |
271 |
(format "Query replace regexp %s with eval: " from) |
nil nil t query-replace-to-history-variable from t)))) |
|
nil nil t query-replace-to-history-variable from t))) |
|
272 |
;; We make TO a list because replace-match-string-symbols requires one, |
;; We make TO a list because replace-match-string-symbols requires one, |
273 |
;; and the user might enter a single token. |
;; and the user might enter a single token. |
274 |
(replace-match-string-symbols to) |
(replace-match-string-symbols to) |
301 |
before rotating to the next. |
before rotating to the next. |
302 |
Fourth and fifth arg START and END specify the region to operate on." |
Fourth and fifth arg START and END specify the region to operate on." |
303 |
(interactive |
(interactive |
304 |
(let (from to) |
(let* ((from (if query-replace-interactive |
|
(setq from (if query-replace-interactive |
|
305 |
(car regexp-search-ring) |
(car regexp-search-ring) |
306 |
(read-from-minibuffer "Map query replace (regexp): " |
(read-from-minibuffer "Map query replace (regexp): " |
307 |
nil nil nil |
nil nil nil |
308 |
'query-replace-history nil t))) |
'query-replace-history nil t))) |
309 |
(setq to (read-from-minibuffer |
(to (read-from-minibuffer |
310 |
(format "Query replace %s with (space-separated strings): " |
(format "Query replace %s with (space-separated strings): " |
311 |
from) |
from) |
312 |
nil nil nil |
nil nil nil |
313 |
'query-replace-history from t)) |
'query-replace-history from t))) |
314 |
(list from to |
(list from to |
315 |
(and current-prefix-arg |
(and current-prefix-arg |
316 |
(prefix-numeric-value current-prefix-arg)) |
(prefix-numeric-value current-prefix-arg)) |
914 |
(let ((matches 0) ;; count of matched lines |
(let ((matches 0) ;; count of matched lines |
915 |
(lines 1) ;; line count |
(lines 1) ;; line count |
916 |
(matchbeg 0) |
(matchbeg 0) |
|
(matchend 0) |
|
917 |
(origpt nil) |
(origpt nil) |
918 |
(begpt nil) |
(begpt nil) |
919 |
(endpt nil) |
(endpt nil) |
933 |
(setq origpt (point)) |
(setq origpt (point)) |
934 |
(when (setq endpt (re-search-forward regexp nil t)) |
(when (setq endpt (re-search-forward regexp nil t)) |
935 |
(setq matches (1+ matches)) ;; increment match count |
(setq matches (1+ matches)) ;; increment match count |
936 |
(setq matchbeg (match-beginning 0) |
(setq matchbeg (match-beginning 0)) |
|
matchend (match-end 0)) |
|
937 |
(setq begpt (save-excursion |
(setq begpt (save-excursion |
938 |
(goto-char matchbeg) |
(goto-char matchbeg) |
939 |
(line-beginning-position))) |
(line-beginning-position))) |