Mercurial > emacs
comparison lisp/replace.el @ 56350:cae4ae1c68a9
(query-replace-interactive, query-replace-read-args):
Remove the `initial' special value.
(query-replace-regexp-eval, map-query-replace-regexp): Simplify.
(occur-engine): Remove unused var `matchend'.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 05 Jul 2004 22:50:46 +0000 |
parents | cc1deb864ed6 |
children | d073da76f0a5 |
comparison
equal
deleted
inserted
replaced
56349:8d4253b23d7b | 56350:cae4ae1c68a9 |
---|---|
34 :type 'boolean | 34 :type 'boolean |
35 :group 'matching) | 35 :group 'matching) |
36 | 36 |
37 (defvar query-replace-history nil) | 37 (defvar query-replace-history nil) |
38 | 38 |
39 (defcustom query-replace-interactive nil | 39 (defvar query-replace-interactive nil |
40 "Non-nil means `query-replace' uses the last search string. | 40 "Non-nil means `query-replace' uses the last search string. |
41 That becomes the \"string to replace\". | 41 That becomes the \"string to replace\".") |
42 If value is `initial', the last search string is inserted into | |
43 the minibuffer as an initial value for \"string to replace\"." | |
44 :type '(choice (const :tag "Off" nil) | |
45 (const :tag "Initial content" initial) | |
46 (other :tag "Use default value" t)) | |
47 :group 'matching) | |
48 | 42 |
49 (defcustom query-replace-from-history-variable 'query-replace-history | 43 (defcustom query-replace-from-history-variable 'query-replace-history |
50 "History list to use for the FROM argument of `query-replace' commands. | 44 "History list to use for the FROM argument of `query-replace' commands. |
51 The value of this variable should be a symbol; that symbol | 45 The value of this variable should be a symbol; that symbol |
52 is used as a variable to hold a history list for the strings | 46 is used as a variable to hold a history list for the strings |
72 | 66 |
73 (defun query-replace-read-args (string regexp-flag &optional noerror) | 67 (defun query-replace-read-args (string regexp-flag &optional noerror) |
74 (unless noerror | 68 (unless noerror |
75 (barf-if-buffer-read-only)) | 69 (barf-if-buffer-read-only)) |
76 (let (from to) | 70 (let (from to) |
77 (if (and query-replace-interactive | 71 (if query-replace-interactive |
78 (not (eq query-replace-interactive 'initial))) | |
79 (setq from (car (if regexp-flag regexp-search-ring search-ring))) | 72 (setq from (car (if regexp-flag regexp-search-ring search-ring))) |
80 ;; The save-excursion here is in case the user marks and copies | 73 ;; The save-excursion here is in case the user marks and copies |
81 ;; a region in order to specify the minibuffer input. | 74 ;; a region in order to specify the minibuffer input. |
82 ;; That should not clobber the region for the query-replace itself. | 75 ;; That should not clobber the region for the query-replace itself. |
83 (save-excursion | 76 (save-excursion |
84 (setq from (read-from-minibuffer | 77 (setq from (read-from-minibuffer |
85 (format "%s: " string) | 78 (format "%s: " string) |
86 (if (eq query-replace-interactive 'initial) | 79 nil nil nil |
87 (car (if regexp-flag regexp-search-ring search-ring))) | |
88 nil nil | |
89 query-replace-from-history-variable | 80 query-replace-from-history-variable |
90 nil t))) | 81 nil t))) |
91 ;; Warn if user types \n or \t, but don't reject the input. | 82 ;; Warn if user types \n or \t, but don't reject the input. |
92 (and regexp-flag | 83 (and regexp-flag |
93 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) | 84 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) |
267 | 258 |
268 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 259 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
269 only matches that are surrounded by word boundaries. | 260 only matches that are surrounded by word boundaries. |
270 Fourth and fifth arg START and END specify the region to operate on." | 261 Fourth and fifth arg START and END specify the region to operate on." |
271 (interactive | 262 (interactive |
272 (let (from to) | 263 (let* ((from (if query-replace-interactive |
273 (if query-replace-interactive | 264 (car regexp-search-ring) |
274 (setq from (car regexp-search-ring)) | 265 (read-from-minibuffer "Query replace regexp: " |
275 (setq from (read-from-minibuffer "Query replace regexp: " | 266 nil nil nil |
276 nil nil nil | 267 query-replace-from-history-variable |
277 query-replace-from-history-variable | 268 nil t))) |
278 nil t))) | 269 (to (list (read-from-minibuffer |
279 (setq to (list (read-from-minibuffer | 270 (format "Query replace regexp %s with eval: " from) |
280 (format "Query replace regexp %s with eval: " from) | 271 nil nil t query-replace-to-history-variable from t)))) |
281 nil nil t query-replace-to-history-variable from t))) | |
282 ;; We make TO a list because replace-match-string-symbols requires one, | 272 ;; We make TO a list because replace-match-string-symbols requires one, |
283 ;; and the user might enter a single token. | 273 ;; and the user might enter a single token. |
284 (replace-match-string-symbols to) | 274 (replace-match-string-symbols to) |
285 (list from (car to) current-prefix-arg | 275 (list from (car to) current-prefix-arg |
286 (if (and transient-mark-mode mark-active) | 276 (if (and transient-mark-mode mark-active) |
309 | 299 |
310 A prefix argument N says to use each replacement string N times | 300 A prefix argument N says to use each replacement string N times |
311 before rotating to the next. | 301 before rotating to the next. |
312 Fourth and fifth arg START and END specify the region to operate on." | 302 Fourth and fifth arg START and END specify the region to operate on." |
313 (interactive | 303 (interactive |
314 (let (from to) | 304 (let* ((from (if query-replace-interactive |
315 (setq from (if query-replace-interactive | |
316 (car regexp-search-ring) | 305 (car regexp-search-ring) |
317 (read-from-minibuffer "Map query replace (regexp): " | 306 (read-from-minibuffer "Map query replace (regexp): " |
318 nil nil nil | 307 nil nil nil |
319 'query-replace-history nil t))) | 308 'query-replace-history nil t))) |
320 (setq to (read-from-minibuffer | 309 (to (read-from-minibuffer |
321 (format "Query replace %s with (space-separated strings): " | 310 (format "Query replace %s with (space-separated strings): " |
322 from) | 311 from) |
323 nil nil nil | 312 nil nil nil |
324 'query-replace-history from t)) | 313 'query-replace-history from t))) |
325 (list from to | 314 (list from to |
326 (and current-prefix-arg | 315 (and current-prefix-arg |
327 (prefix-numeric-value current-prefix-arg)) | 316 (prefix-numeric-value current-prefix-arg)) |
328 (if (and transient-mark-mode mark-active) | 317 (if (and transient-mark-mode mark-active) |
329 (region-beginning)) | 318 (region-beginning)) |
923 (dolist (buf buffers) | 912 (dolist (buf buffers) |
924 (when (buffer-live-p buf) | 913 (when (buffer-live-p buf) |
925 (let ((matches 0) ;; count of matched lines | 914 (let ((matches 0) ;; count of matched lines |
926 (lines 1) ;; line count | 915 (lines 1) ;; line count |
927 (matchbeg 0) | 916 (matchbeg 0) |
928 (matchend 0) | |
929 (origpt nil) | 917 (origpt nil) |
930 (begpt nil) | 918 (begpt nil) |
931 (endpt nil) | 919 (endpt nil) |
932 (marker nil) | 920 (marker nil) |
933 (curstring "") | 921 (curstring "") |
943 (goto-char (point-min)) ;; begin searching in the buffer | 931 (goto-char (point-min)) ;; begin searching in the buffer |
944 (while (not (eobp)) | 932 (while (not (eobp)) |
945 (setq origpt (point)) | 933 (setq origpt (point)) |
946 (when (setq endpt (re-search-forward regexp nil t)) | 934 (when (setq endpt (re-search-forward regexp nil t)) |
947 (setq matches (1+ matches)) ;; increment match count | 935 (setq matches (1+ matches)) ;; increment match count |
948 (setq matchbeg (match-beginning 0) | 936 (setq matchbeg (match-beginning 0)) |
949 matchend (match-end 0)) | |
950 (setq begpt (save-excursion | 937 (setq begpt (save-excursion |
951 (goto-char matchbeg) | 938 (goto-char matchbeg) |
952 (line-beginning-position))) | 939 (line-beginning-position))) |
953 (setq lines (+ lines (1- (count-lines origpt endpt)))) | 940 (setq lines (+ lines (1- (count-lines origpt endpt)))) |
954 (setq marker (make-marker)) | 941 (setq marker (make-marker)) |