aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorJuri Linkov2012-09-06 11:33:17 +0300
committerJuri Linkov2012-09-06 11:33:17 +0300
commit1ec5e41d0ec506abe02ac223596430f98cb3b951 (patch)
tree3bc25b459a178a41c949aa6f6b1b39a2220cbcf9 /lisp/replace.el
parenta864ef14570715dc3233fbbf2e9da7aa8f29729e (diff)
downloademacs-1ec5e41d0ec506abe02ac223596430f98cb3b951.tar.gz
emacs-1ec5e41d0ec506abe02ac223596430f98cb3b951.zip
Use `isearch-search-fun' in `perform-replace' (bug#10885, bug#10887).
* lisp/replace.el (replace-search-function) (replace-re-search-function): Set default values to nil. (perform-replace): Let-bind isearch-related variables based on replace-related values, call `isearch-search-fun' and let-bind the result to `search-function'. Remove code that sets `search-function' and `search-string' separately for `delimited-flag'. (replace-highlight): Add new argument `delimited-flag' and rename other arguments to the names used in `perform-replace'. Let-bind `isearch-word' to the argument `delimited-flag'.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el43
1 files changed, 18 insertions, 25 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 3373ee8e512..f9f97dfe485 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1717,12 +1717,12 @@ passed in. If LITERAL is set, no checking is done, anyway."
1717 (replace-match newtext fixedcase literal) 1717 (replace-match newtext fixedcase literal)
1718 noedit) 1718 noedit)
1719 1719
1720(defvar replace-search-function 'search-forward 1720(defvar replace-search-function nil
1721 "Function to use when searching for strings to replace. 1721 "Function to use when searching for strings to replace.
1722It is used by `query-replace' and `replace-string', and is called 1722It is used by `query-replace' and `replace-string', and is called
1723with three arguments, as if it were `search-forward'.") 1723with three arguments, as if it were `search-forward'.")
1724 1724
1725(defvar replace-re-search-function 're-search-forward 1725(defvar replace-re-search-function nil
1726 "Function to use when searching for regexps to replace. 1726 "Function to use when searching for regexps to replace.
1727It is used by `query-replace-regexp', `replace-regexp', 1727It is used by `query-replace-regexp', `replace-regexp',
1728`query-replace-regexp-eval', and `map-query-replace-regexp'. 1728`query-replace-regexp-eval', and `map-query-replace-regexp'.
@@ -1755,9 +1755,14 @@ make, or the user didn't cancel the call."
1755 (nocasify (not (and case-replace case-fold-search))) 1755 (nocasify (not (and case-replace case-fold-search)))
1756 (literal (or (not regexp-flag) (eq regexp-flag 'literal))) 1756 (literal (or (not regexp-flag) (eq regexp-flag 'literal)))
1757 (search-function 1757 (search-function
1758 (if regexp-flag 1758 (or (if regexp-flag
1759 replace-re-search-function 1759 replace-re-search-function
1760 replace-search-function)) 1760 replace-search-function)
1761 (let ((isearch-regexp regexp-flag)
1762 (isearch-word delimited-flag)
1763 (isearch-case-fold-search case-fold-search)
1764 (isearch-forward t))
1765 (isearch-search-fun))))
1761 (search-string from-string) 1766 (search-string from-string)
1762 (real-match-data nil) ; The match data for the current match. 1767 (real-match-data nil) ; The match data for the current match.
1763 (next-replacement nil) 1768 (next-replacement nil)
@@ -1811,12 +1816,6 @@ make, or the user didn't cancel the call."
1811 (vector repeat-count repeat-count 1816 (vector repeat-count repeat-count
1812 replacements replacements))))) 1817 replacements replacements)))))
1813 1818
1814 (if delimited-flag
1815 (setq search-function 're-search-forward
1816 search-string (concat "\\b"
1817 (if regexp-flag from-string
1818 (regexp-quote from-string))
1819 "\\b")))
1820 (when query-replace-lazy-highlight 1819 (when query-replace-lazy-highlight
1821 (setq isearch-lazy-highlight-last-string nil)) 1820 (setq isearch-lazy-highlight-last-string nil))
1822 1821
@@ -1898,7 +1897,7 @@ make, or the user didn't cancel the call."
1898 (replace-highlight 1897 (replace-highlight
1899 (nth 0 real-match-data) (nth 1 real-match-data) 1898 (nth 0 real-match-data) (nth 1 real-match-data)
1900 start end search-string 1899 start end search-string
1901 (or delimited-flag regexp-flag) case-fold-search)) 1900 regexp-flag delimited-flag case-fold-search))
1902 (setq noedit 1901 (setq noedit
1903 (replace-match-maybe-edit 1902 (replace-match-maybe-edit
1904 next-replacement nocasify literal 1903 next-replacement nocasify literal
@@ -1917,7 +1916,7 @@ make, or the user didn't cancel the call."
1917 (replace-highlight 1916 (replace-highlight
1918 (match-beginning 0) (match-end 0) 1917 (match-beginning 0) (match-end 0)
1919 start end search-string 1918 start end search-string
1920 (or delimited-flag regexp-flag) case-fold-search) 1919 regexp-flag delimited-flag case-fold-search)
1921 ;; Bind message-log-max so we don't fill up the message log 1920 ;; Bind message-log-max so we don't fill up the message log
1922 ;; with a bunch of identical messages. 1921 ;; with a bunch of identical messages.
1923 (let ((message-log-max nil) 1922 (let ((message-log-max nil)
@@ -2099,15 +2098,11 @@ make, or the user didn't cancel the call."
2099 (if (= replace-count 1) "" "s"))) 2098 (if (= replace-count 1) "" "s")))
2100 (or (and keep-going stack) multi-buffer))) 2099 (or (and keep-going stack) multi-buffer)))
2101 2100
2102(defvar isearch-error)
2103(defvar isearch-forward)
2104(defvar isearch-case-fold-search)
2105(defvar isearch-string)
2106
2107(defvar replace-overlay nil) 2101(defvar replace-overlay nil)
2108 2102
2109(defun replace-highlight (match-beg match-end range-beg range-end 2103(defun replace-highlight (match-beg match-end range-beg range-end
2110 string regexp case-fold) 2104 search-string regexp-flag delimited-flag
2105 case-fold-search)
2111 (if query-replace-highlight 2106 (if query-replace-highlight
2112 (if replace-overlay 2107 (if replace-overlay
2113 (move-overlay replace-overlay match-beg match-end (current-buffer)) 2108 (move-overlay replace-overlay match-beg match-end (current-buffer))
@@ -2115,13 +2110,11 @@ make, or the user didn't cancel the call."
2115 (overlay-put replace-overlay 'priority 1001) ;higher than lazy overlays 2110 (overlay-put replace-overlay 'priority 1001) ;higher than lazy overlays
2116 (overlay-put replace-overlay 'face 'query-replace))) 2111 (overlay-put replace-overlay 'face 'query-replace)))
2117 (if query-replace-lazy-highlight 2112 (if query-replace-lazy-highlight
2118 (let ((isearch-string string) 2113 (let ((isearch-string search-string)
2119 (isearch-regexp regexp) 2114 (isearch-regexp regexp-flag)
2120 ;; Set isearch-word to nil because word-replace is regexp-based, 2115 (isearch-word delimited-flag)
2121 ;; so `isearch-search-fun' should not use `word-search-forward'.
2122 (isearch-word nil)
2123 (search-whitespace-regexp nil) 2116 (search-whitespace-regexp nil)
2124 (isearch-case-fold-search case-fold) 2117 (isearch-case-fold-search case-fold-search)
2125 (isearch-forward t) 2118 (isearch-forward t)
2126 (isearch-error nil)) 2119 (isearch-error nil))
2127 (isearch-lazy-highlight-new-loop range-beg range-end)))) 2120 (isearch-lazy-highlight-new-loop range-beg range-end))))