comparison lisp/replace.el @ 56304:31b76ccf08bf

(query-replace-interactive): Change type from boolean to choice. Add value `initial'. (query-replace-read-args): Handle value `initial' of query-replace-interactive.
author Juri Linkov <juri@jurta.org>
date Thu, 01 Jul 2004 09:58:44 +0000
parents 610a9a9c39d0
children 06c785c5e655
comparison
equal deleted inserted replaced
56303:d86ec00a8470 56304:31b76ccf08bf
36 36
37 (defvar query-replace-history nil) 37 (defvar query-replace-history nil)
38 38
39 (defcustom query-replace-interactive nil 39 (defcustom 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 :type 'boolean 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))
43 :group 'matching) 47 :group 'matching)
44 48
45 (defcustom query-replace-from-history-variable 'query-replace-history 49 (defcustom query-replace-from-history-variable 'query-replace-history
46 "History list to use for the FROM argument of `query-replace' commands. 50 "History list to use for the FROM argument of `query-replace' commands.
47 The value of this variable should be a symbol; that symbol 51 The value of this variable should be a symbol; that symbol
68 72
69 (defun query-replace-read-args (string regexp-flag &optional noerror) 73 (defun query-replace-read-args (string regexp-flag &optional noerror)
70 (unless noerror 74 (unless noerror
71 (barf-if-buffer-read-only)) 75 (barf-if-buffer-read-only))
72 (let (from to) 76 (let (from to)
73 (if query-replace-interactive 77 (if (and query-replace-interactive
74 (setq from (car (if regexp-flag regexp-search-ring search-ring))) 78 (not (eq query-replace-interactive 'initial)))
79 (setq from (car (if regexp-flag regexp-search-ring search-ring)))
75 ;; The save-excursion here is in case the user marks and copies 80 ;; The save-excursion here is in case the user marks and copies
76 ;; a region in order to specify the minibuffer input. 81 ;; a region in order to specify the minibuffer input.
77 ;; That should not clobber the region for the query-replace itself. 82 ;; That should not clobber the region for the query-replace itself.
78 (save-excursion 83 (save-excursion
79 (setq from (read-from-minibuffer (format "%s: " string) 84 (setq from (read-from-minibuffer
80 nil nil nil 85 (format "%s: " string)
81 query-replace-from-history-variable 86 (if (eq query-replace-interactive 'initial)
82 nil t))) 87 (car (if regexp-flag regexp-search-ring search-ring)))
88 nil nil
89 query-replace-from-history-variable
90 nil t)))
83 ;; Warn if user types \n or \t, but don't reject the input. 91 ;; Warn if user types \n or \t, but don't reject the input.
84 (and regexp-flag 92 (and regexp-flag
85 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) 93 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
86 (let ((match (match-string 3 from))) 94 (let ((match (match-string 3 from)))
87 (cond 95 (cond
90 ((string= match "\\t") 98 ((string= match "\\t")
91 (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB"))) 99 (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB")))
92 (sit-for 2)))) 100 (sit-for 2))))
93 101
94 (save-excursion 102 (save-excursion
95 (setq to (read-from-minibuffer (format "%s %s with: " string from) 103 (setq to (read-from-minibuffer
96 nil nil nil 104 (format "%s %s with: " string from)
97 query-replace-to-history-variable from t))) 105 nil nil nil
106 query-replace-to-history-variable from t)))
98 (when (and regexp-flag 107 (when (and regexp-flag
99 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)) 108 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))
100 (let (pos list char) 109 (let (pos list char)
101 (while 110 (while
102 (progn 111 (progn