diff options
| author | Juri Linkov | 2013-02-02 01:38:41 +0200 |
|---|---|---|
| committer | Juri Linkov | 2013-02-02 01:38:41 +0200 |
| commit | dc2bc29527d65f54704570c991e023cbb0723544 (patch) | |
| tree | 2096e5aab561b99ed282243946041ba2fa9d9174 /lisp/replace.el | |
| parent | f864e0ea838f8f5e1a27b2ac612d0072c1606507 (diff) | |
| download | emacs-dc2bc29527d65f54704570c991e023cbb0723544.tar.gz emacs-dc2bc29527d65f54704570c991e023cbb0723544.zip | |
* lisp/replace.el (perform-replace): Move let-bindings of isearch-*
variables deeper to the loop that searches for the next match.
Add bindings for `isearch-nonincremental' and `isearch-adjusted'.
Use `isearch-search-fun-default' instead of `isearch-search-fun'.
* lisp/isearch.el (isearch-search-fun-default): Check for null
first element of isearch-cmds as a precaution when it's used
with inactive isearch.
Fixes: debbugs:13579
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 102 |
1 files changed, 56 insertions, 46 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index fb251821445..7757426cf95 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -1819,19 +1819,6 @@ make, or the user didn't cancel the call." | |||
| 1819 | case-fold-search)) | 1819 | case-fold-search)) |
| 1820 | (nocasify (not (and case-replace case-fold-search))) | 1820 | (nocasify (not (and case-replace case-fold-search))) |
| 1821 | (literal (or (not regexp-flag) (eq regexp-flag 'literal))) | 1821 | (literal (or (not regexp-flag) (eq regexp-flag 'literal))) |
| 1822 | (search-function | ||
| 1823 | (or (if regexp-flag | ||
| 1824 | replace-re-search-function | ||
| 1825 | replace-search-function) | ||
| 1826 | (let ((isearch-regexp regexp-flag) | ||
| 1827 | (isearch-word delimited-flag) | ||
| 1828 | (isearch-lax-whitespace | ||
| 1829 | replace-lax-whitespace) | ||
| 1830 | (isearch-regexp-lax-whitespace | ||
| 1831 | replace-regexp-lax-whitespace) | ||
| 1832 | (isearch-case-fold-search case-fold-search) | ||
| 1833 | (isearch-forward t)) | ||
| 1834 | (isearch-search-fun)))) | ||
| 1835 | (search-string from-string) | 1822 | (search-string from-string) |
| 1836 | (real-match-data nil) ; The match data for the current match. | 1823 | (real-match-data nil) ; The match data for the current match. |
| 1837 | (next-replacement nil) | 1824 | (next-replacement nil) |
| @@ -1894,39 +1881,62 @@ make, or the user didn't cancel the call." | |||
| 1894 | ;; Loop finding occurrences that perhaps should be replaced. | 1881 | ;; Loop finding occurrences that perhaps should be replaced. |
| 1895 | (while (and keep-going | 1882 | (while (and keep-going |
| 1896 | (not (or (eobp) (and limit (>= (point) limit)))) | 1883 | (not (or (eobp) (and limit (>= (point) limit)))) |
| 1897 | ;; Use the next match if it is already known; | 1884 | ;; Let-bind global isearch-* variables to values used |
| 1898 | ;; otherwise, search for a match after moving forward | 1885 | ;; to search the next replacement. These let-bindings |
| 1899 | ;; one char if progress is required. | 1886 | ;; should be effective both at the time of calling |
| 1900 | (setq real-match-data | 1887 | ;; `isearch-search-fun-default' and also at the |
| 1901 | (cond ((consp match-again) | 1888 | ;; time of funcalling `search-function'. |
| 1902 | (goto-char (nth 1 match-again)) | 1889 | ;; These isearch-* bindings can't be placed higher |
| 1903 | (replace-match-data | 1890 | ;; outside of this loop because then another I-search |
| 1904 | t real-match-data match-again)) | 1891 | ;; used after `recursive-edit' might override them. |
| 1905 | ;; MATCH-AGAIN non-nil means accept an | 1892 | (let* ((isearch-regexp regexp-flag) |
| 1906 | ;; adjacent match. | 1893 | (isearch-word delimited-flag) |
| 1907 | (match-again | 1894 | (isearch-lax-whitespace |
| 1908 | (and | 1895 | replace-lax-whitespace) |
| 1909 | (funcall search-function search-string | 1896 | (isearch-regexp-lax-whitespace |
| 1910 | limit t) | 1897 | replace-regexp-lax-whitespace) |
| 1911 | ;; For speed, use only integers and | 1898 | (isearch-case-fold-search case-fold-search) |
| 1912 | ;; reuse the list used last time. | 1899 | (isearch-adjusted nil) |
| 1913 | (replace-match-data t real-match-data))) | 1900 | (isearch-nonincremental t) ; don't use lax word mode |
| 1914 | ((and (< (1+ (point)) (point-max)) | 1901 | (isearch-forward t) |
| 1915 | (or (null limit) | 1902 | (search-function |
| 1916 | (< (1+ (point)) limit))) | 1903 | (or (if regexp-flag |
| 1917 | ;; If not accepting adjacent matches, | 1904 | replace-re-search-function |
| 1918 | ;; move one char to the right before | 1905 | replace-search-function) |
| 1919 | ;; searching again. Undo the motion | 1906 | (isearch-search-fun-default)))) |
| 1920 | ;; if the search fails. | 1907 | ;; Use the next match if it is already known; |
| 1921 | (let ((opoint (point))) | 1908 | ;; otherwise, search for a match after moving forward |
| 1922 | (forward-char 1) | 1909 | ;; one char if progress is required. |
| 1923 | (if (funcall | 1910 | (setq real-match-data |
| 1924 | search-function search-string | 1911 | (cond ((consp match-again) |
| 1925 | limit t) | 1912 | (goto-char (nth 1 match-again)) |
| 1926 | (replace-match-data | 1913 | (replace-match-data |
| 1927 | t real-match-data) | 1914 | t real-match-data match-again)) |
| 1928 | (goto-char opoint) | 1915 | ;; MATCH-AGAIN non-nil means accept an |
| 1929 | nil)))))) | 1916 | ;; adjacent match. |
| 1917 | (match-again | ||
| 1918 | (and | ||
| 1919 | (funcall search-function search-string | ||
| 1920 | limit t) | ||
| 1921 | ;; For speed, use only integers and | ||
| 1922 | ;; reuse the list used last time. | ||
| 1923 | (replace-match-data t real-match-data))) | ||
| 1924 | ((and (< (1+ (point)) (point-max)) | ||
| 1925 | (or (null limit) | ||
| 1926 | (< (1+ (point)) limit))) | ||
| 1927 | ;; If not accepting adjacent matches, | ||
| 1928 | ;; move one char to the right before | ||
| 1929 | ;; searching again. Undo the motion | ||
| 1930 | ;; if the search fails. | ||
| 1931 | (let ((opoint (point))) | ||
| 1932 | (forward-char 1) | ||
| 1933 | (if (funcall | ||
| 1934 | search-function search-string | ||
| 1935 | limit t) | ||
| 1936 | (replace-match-data | ||
| 1937 | t real-match-data) | ||
| 1938 | (goto-char opoint) | ||
| 1939 | nil))))))) | ||
| 1930 | 1940 | ||
| 1931 | ;; Record whether the match is nonempty, to avoid an infinite loop | 1941 | ;; Record whether the match is nonempty, to avoid an infinite loop |
| 1932 | ;; repeatedly matching the same empty string. | 1942 | ;; repeatedly matching the same empty string. |