diff options
| author | Juri Linkov | 2013-12-19 02:29:41 +0200 |
|---|---|---|
| committer | Juri Linkov | 2013-12-19 02:29:41 +0200 |
| commit | 3ee4cd6482abbabb06630a6c725277d42061eee7 (patch) | |
| tree | 37de7f94d5bf0f7b7cab7335c814ae5f50f0d2ac /lisp/replace.el | |
| parent | 0cda6b7b136178f42510c9e4ededcbaa38c4cc19 (diff) | |
| download | emacs-3ee4cd6482abbabb06630a6c725277d42061eee7.tar.gz emacs-3ee4cd6482abbabb06630a6c725277d42061eee7.zip | |
query-replace backward
* lisp/replace.el (query-replace-read-args): Split a non-negative arg
and a negative arg into separate elements.
(query-replace, query-replace-regexp, replace-string)
(replace-regexp): Add arg `backward'. Doc fix.
(replace-match-maybe-edit): When new arg `backward' is non-nil,
move point to the beginning of the match.
(replace-search, replace-highlight): Use new arg `backward'
to set the value of `isearch-forward'.
(perform-replace): Add arg `backward' and use it to perform
replacement backward.
* lisp/isearch.el (isearch-query-replace): Use a negative prefix arg
to call `perform-replace' with a non-nil arg `backward'.
Fixes: debbugs:14979
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 134 |
1 files changed, 87 insertions, 47 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 2c6b02364b2..fea8941363d 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -226,9 +226,11 @@ the original string if not." | |||
| 226 | (let* ((from (query-replace-read-from prompt regexp-flag)) | 226 | (let* ((from (query-replace-read-from prompt regexp-flag)) |
| 227 | (to (if (consp from) (prog1 (cdr from) (setq from (car from))) | 227 | (to (if (consp from) (prog1 (cdr from) (setq from (car from))) |
| 228 | (query-replace-read-to from prompt regexp-flag)))) | 228 | (query-replace-read-to from prompt regexp-flag)))) |
| 229 | (list from to current-prefix-arg))) | 229 | (list from to |
| 230 | (and current-prefix-arg (not (eq current-prefix-arg '-))) | ||
| 231 | (and current-prefix-arg (eq current-prefix-arg '-))))) | ||
| 230 | 232 | ||
| 231 | (defun query-replace (from-string to-string &optional delimited start end) | 233 | (defun query-replace (from-string to-string &optional delimited start end backward) |
| 232 | "Replace some occurrences of FROM-STRING with TO-STRING. | 234 | "Replace some occurrences of FROM-STRING with TO-STRING. |
| 233 | As each match is found, the user must type a character saying | 235 | As each match is found, the user must type a character saying |
| 234 | what to do with it. For directions, type \\[help-command] at that time. | 236 | what to do with it. For directions, type \\[help-command] at that time. |
| @@ -259,7 +261,9 @@ to be replaced will match a sequence of whitespace chars defined by the | |||
| 259 | regexp in `search-whitespace-regexp'. | 261 | regexp in `search-whitespace-regexp'. |
| 260 | 262 | ||
| 261 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 263 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 262 | only matches surrounded by word boundaries. | 264 | only matches surrounded by word boundaries. A negative prefix arg means |
| 265 | replace backward. | ||
| 266 | |||
| 263 | Fourth and fifth arg START and END specify the region to operate on. | 267 | Fourth and fifth arg START and END specify the region to operate on. |
| 264 | 268 | ||
| 265 | To customize possible responses, change the \"bindings\" in `query-replace-map'." | 269 | To customize possible responses, change the \"bindings\" in `query-replace-map'." |
| @@ -267,7 +271,9 @@ To customize possible responses, change the \"bindings\" in `query-replace-map'. | |||
| 267 | (let ((common | 271 | (let ((common |
| 268 | (query-replace-read-args | 272 | (query-replace-read-args |
| 269 | (concat "Query replace" | 273 | (concat "Query replace" |
| 270 | (if current-prefix-arg " word" "") | 274 | (if current-prefix-arg |
| 275 | (if (eq current-prefix-arg '-) " backward" " word") | ||
| 276 | "") | ||
| 271 | (if (and transient-mark-mode mark-active) " in region" "")) | 277 | (if (and transient-mark-mode mark-active) " in region" "")) |
| 272 | nil))) | 278 | nil))) |
| 273 | (list (nth 0 common) (nth 1 common) (nth 2 common) | 279 | (list (nth 0 common) (nth 1 common) (nth 2 common) |
| @@ -277,12 +283,13 @@ To customize possible responses, change the \"bindings\" in `query-replace-map'. | |||
| 277 | (if (and transient-mark-mode mark-active) | 283 | (if (and transient-mark-mode mark-active) |
| 278 | (region-beginning)) | 284 | (region-beginning)) |
| 279 | (if (and transient-mark-mode mark-active) | 285 | (if (and transient-mark-mode mark-active) |
| 280 | (region-end))))) | 286 | (region-end)) |
| 281 | (perform-replace from-string to-string t nil delimited nil nil start end)) | 287 | (nth 3 common)))) |
| 288 | (perform-replace from-string to-string t nil delimited nil nil start end backward)) | ||
| 282 | 289 | ||
| 283 | (define-key esc-map "%" 'query-replace) | 290 | (define-key esc-map "%" 'query-replace) |
| 284 | 291 | ||
| 285 | (defun query-replace-regexp (regexp to-string &optional delimited start end) | 292 | (defun query-replace-regexp (regexp to-string &optional delimited start end backward) |
| 286 | "Replace some things after point matching REGEXP with TO-STRING. | 293 | "Replace some things after point matching REGEXP with TO-STRING. |
| 287 | As each match is found, the user must type a character saying | 294 | As each match is found, the user must type a character saying |
| 288 | what to do with it. For directions, type \\[help-command] at that time. | 295 | what to do with it. For directions, type \\[help-command] at that time. |
| @@ -313,7 +320,9 @@ to be replaced will match a sequence of whitespace chars defined by the | |||
| 313 | regexp in `search-whitespace-regexp'. | 320 | regexp in `search-whitespace-regexp'. |
| 314 | 321 | ||
| 315 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 322 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 316 | only matches surrounded by word boundaries. | 323 | only matches surrounded by word boundaries. A negative prefix arg means |
| 324 | replace backward. | ||
| 325 | |||
| 317 | Fourth and fifth arg START and END specify the region to operate on. | 326 | Fourth and fifth arg START and END specify the region to operate on. |
| 318 | 327 | ||
| 319 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, | 328 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, |
| @@ -341,7 +350,9 @@ Use \\[repeat-complex-command] after this command for details." | |||
| 341 | (let ((common | 350 | (let ((common |
| 342 | (query-replace-read-args | 351 | (query-replace-read-args |
| 343 | (concat "Query replace" | 352 | (concat "Query replace" |
| 344 | (if current-prefix-arg " word" "") | 353 | (if current-prefix-arg |
| 354 | (if (eq current-prefix-arg '-) " backward" " word") | ||
| 355 | "") | ||
| 345 | " regexp" | 356 | " regexp" |
| 346 | (if (and transient-mark-mode mark-active) " in region" "")) | 357 | (if (and transient-mark-mode mark-active) " in region" "")) |
| 347 | t))) | 358 | t))) |
| @@ -352,8 +363,9 @@ Use \\[repeat-complex-command] after this command for details." | |||
| 352 | (if (and transient-mark-mode mark-active) | 363 | (if (and transient-mark-mode mark-active) |
| 353 | (region-beginning)) | 364 | (region-beginning)) |
| 354 | (if (and transient-mark-mode mark-active) | 365 | (if (and transient-mark-mode mark-active) |
| 355 | (region-end))))) | 366 | (region-end)) |
| 356 | (perform-replace regexp to-string t t delimited nil nil start end)) | 367 | (nth 3 common)))) |
| 368 | (perform-replace regexp to-string t t delimited nil nil start end backward)) | ||
| 357 | 369 | ||
| 358 | (define-key esc-map [?\C-%] 'query-replace-regexp) | 370 | (define-key esc-map [?\C-%] 'query-replace-regexp) |
| 359 | 371 | ||
| @@ -475,7 +487,7 @@ Fourth and fifth arg START and END specify the region to operate on." | |||
| 475 | to-strings "")))) | 487 | to-strings "")))) |
| 476 | (perform-replace regexp replacements t t nil n nil start end))) | 488 | (perform-replace regexp replacements t t nil n nil start end))) |
| 477 | 489 | ||
| 478 | (defun replace-string (from-string to-string &optional delimited start end) | 490 | (defun replace-string (from-string to-string &optional delimited start end backward) |
| 479 | "Replace occurrences of FROM-STRING with TO-STRING. | 491 | "Replace occurrences of FROM-STRING with TO-STRING. |
| 480 | Preserve case in each match if `case-replace' and `case-fold-search' | 492 | Preserve case in each match if `case-replace' and `case-fold-search' |
| 481 | are non-nil and FROM-STRING has no uppercase letters. | 493 | are non-nil and FROM-STRING has no uppercase letters. |
| @@ -491,7 +503,8 @@ to be replaced will match a sequence of whitespace chars defined by the | |||
| 491 | regexp in `search-whitespace-regexp'. | 503 | regexp in `search-whitespace-regexp'. |
| 492 | 504 | ||
| 493 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 505 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 494 | only matches surrounded by word boundaries. | 506 | only matches surrounded by word boundaries. A negative prefix arg means |
| 507 | replace backward. | ||
| 495 | 508 | ||
| 496 | Operates on the region between START and END (if both are nil, from point | 509 | Operates on the region between START and END (if both are nil, from point |
| 497 | to the end of the buffer). Interactively, if Transient Mark mode is | 510 | to the end of the buffer). Interactively, if Transient Mark mode is |
| @@ -513,7 +526,9 @@ and TO-STRING is also null.)" | |||
| 513 | (let ((common | 526 | (let ((common |
| 514 | (query-replace-read-args | 527 | (query-replace-read-args |
| 515 | (concat "Replace" | 528 | (concat "Replace" |
| 516 | (if current-prefix-arg " word" "") | 529 | (if current-prefix-arg |
| 530 | (if (eq current-prefix-arg '-) " backward" " word") | ||
| 531 | "") | ||
| 517 | " string" | 532 | " string" |
| 518 | (if (and transient-mark-mode mark-active) " in region" "")) | 533 | (if (and transient-mark-mode mark-active) " in region" "")) |
| 519 | nil))) | 534 | nil))) |
| @@ -521,12 +536,13 @@ and TO-STRING is also null.)" | |||
| 521 | (if (and transient-mark-mode mark-active) | 536 | (if (and transient-mark-mode mark-active) |
| 522 | (region-beginning)) | 537 | (region-beginning)) |
| 523 | (if (and transient-mark-mode mark-active) | 538 | (if (and transient-mark-mode mark-active) |
| 524 | (region-end))))) | 539 | (region-end)) |
| 525 | (perform-replace from-string to-string nil nil delimited nil nil start end)) | 540 | (nth 3 common)))) |
| 541 | (perform-replace from-string to-string nil nil delimited nil nil start end backward)) | ||
| 526 | (put 'replace-string 'interactive-only | 542 | (put 'replace-string 'interactive-only |
| 527 | "use `search-forward' and `replace-match' instead.") | 543 | "use `search-forward' and `replace-match' instead.") |
| 528 | 544 | ||
| 529 | (defun replace-regexp (regexp to-string &optional delimited start end) | 545 | (defun replace-regexp (regexp to-string &optional delimited start end backward) |
| 530 | "Replace things after point matching REGEXP with TO-STRING. | 546 | "Replace things after point matching REGEXP with TO-STRING. |
| 531 | Preserve case in each match if `case-replace' and `case-fold-search' | 547 | Preserve case in each match if `case-replace' and `case-fold-search' |
| 532 | are non-nil and REGEXP has no uppercase letters. | 548 | are non-nil and REGEXP has no uppercase letters. |
| @@ -543,7 +559,9 @@ In Transient Mark mode, if the mark is active, operate on the contents | |||
| 543 | of the region. Otherwise, operate from point to the end of the buffer. | 559 | of the region. Otherwise, operate from point to the end of the buffer. |
| 544 | 560 | ||
| 545 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 561 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 546 | only matches surrounded by word boundaries. | 562 | only matches surrounded by word boundaries. A negative prefix arg means |
| 563 | replace backward. | ||
| 564 | |||
| 547 | Fourth and fifth arg START and END specify the region to operate on. | 565 | Fourth and fifth arg START and END specify the region to operate on. |
| 548 | 566 | ||
| 549 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, | 567 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, |
| @@ -582,7 +600,9 @@ which will run faster and will not set the mark or print anything." | |||
| 582 | (let ((common | 600 | (let ((common |
| 583 | (query-replace-read-args | 601 | (query-replace-read-args |
| 584 | (concat "Replace" | 602 | (concat "Replace" |
| 585 | (if current-prefix-arg " word" "") | 603 | (if current-prefix-arg |
| 604 | (if (eq current-prefix-arg '-) " backward" " word") | ||
| 605 | "") | ||
| 586 | " regexp" | 606 | " regexp" |
| 587 | (if (and transient-mark-mode mark-active) " in region" "")) | 607 | (if (and transient-mark-mode mark-active) " in region" "")) |
| 588 | t))) | 608 | t))) |
| @@ -590,8 +610,9 @@ which will run faster and will not set the mark or print anything." | |||
| 590 | (if (and transient-mark-mode mark-active) | 610 | (if (and transient-mark-mode mark-active) |
| 591 | (region-beginning)) | 611 | (region-beginning)) |
| 592 | (if (and transient-mark-mode mark-active) | 612 | (if (and transient-mark-mode mark-active) |
| 593 | (region-end))))) | 613 | (region-end)) |
| 594 | (perform-replace regexp to-string nil t delimited nil nil start end)) | 614 | (nth 3 common)))) |
| 615 | (perform-replace regexp to-string nil t delimited nil nil start end backward)) | ||
| 595 | (put 'replace-regexp 'interactive-only | 616 | (put 'replace-regexp 'interactive-only |
| 596 | "use `re-search-forward' and `replace-match' instead.") | 617 | "use `re-search-forward' and `replace-match' instead.") |
| 597 | 618 | ||
| @@ -1849,7 +1870,7 @@ but coerced to the correct value of INTEGERS." | |||
| 1849 | new))) | 1870 | new))) |
| 1850 | (match-data integers reuse t))) | 1871 | (match-data integers reuse t))) |
| 1851 | 1872 | ||
| 1852 | (defun replace-match-maybe-edit (newtext fixedcase literal noedit match-data) | 1873 | (defun replace-match-maybe-edit (newtext fixedcase literal noedit match-data backward) |
| 1853 | "Make a replacement with `replace-match', editing `\\?'. | 1874 | "Make a replacement with `replace-match', editing `\\?'. |
| 1854 | NEWTEXT, FIXEDCASE, LITERAL are just passed on. If NOEDIT is true, no | 1875 | NEWTEXT, FIXEDCASE, LITERAL are just passed on. If NOEDIT is true, no |
| 1855 | check for `\\?' is made to save time. MATCH-DATA is used for the | 1876 | check for `\\?' is made to save time. MATCH-DATA is used for the |
| @@ -1873,6 +1894,9 @@ passed in. If LITERAL is set, no checking is done, anyway." | |||
| 1873 | noedit nil))) | 1894 | noedit nil))) |
| 1874 | (set-match-data match-data) | 1895 | (set-match-data match-data) |
| 1875 | (replace-match newtext fixedcase literal) | 1896 | (replace-match newtext fixedcase literal) |
| 1897 | ;; `replace-match' leaves point at the end of the replacement text, | ||
| 1898 | ;; so move point to the beginning when replacing backward. | ||
| 1899 | (when backward (goto-char (nth 0 match-data))) | ||
| 1876 | noedit) | 1900 | noedit) |
| 1877 | 1901 | ||
| 1878 | (defvar replace-search-function nil | 1902 | (defvar replace-search-function nil |
| @@ -1888,7 +1912,7 @@ It is called with three arguments, as if it were | |||
| 1888 | `re-search-forward'.") | 1912 | `re-search-forward'.") |
| 1889 | 1913 | ||
| 1890 | (defun replace-search (search-string limit regexp-flag delimited-flag | 1914 | (defun replace-search (search-string limit regexp-flag delimited-flag |
| 1891 | case-fold-search) | 1915 | case-fold-search backward) |
| 1892 | "Search for the next occurrence of SEARCH-STRING to replace." | 1916 | "Search for the next occurrence of SEARCH-STRING to replace." |
| 1893 | ;; Let-bind global isearch-* variables to values used | 1917 | ;; Let-bind global isearch-* variables to values used |
| 1894 | ;; to search the next replacement. These let-bindings | 1918 | ;; to search the next replacement. These let-bindings |
| @@ -1907,7 +1931,7 @@ It is called with three arguments, as if it were | |||
| 1907 | (isearch-case-fold-search case-fold-search) | 1931 | (isearch-case-fold-search case-fold-search) |
| 1908 | (isearch-adjusted nil) | 1932 | (isearch-adjusted nil) |
| 1909 | (isearch-nonincremental t) ; don't use lax word mode | 1933 | (isearch-nonincremental t) ; don't use lax word mode |
| 1910 | (isearch-forward t) | 1934 | (isearch-forward (not backward)) |
| 1911 | (search-function | 1935 | (search-function |
| 1912 | (or (if regexp-flag | 1936 | (or (if regexp-flag |
| 1913 | replace-re-search-function | 1937 | replace-re-search-function |
| @@ -1919,7 +1943,7 @@ It is called with three arguments, as if it were | |||
| 1919 | 1943 | ||
| 1920 | (defun replace-highlight (match-beg match-end range-beg range-end | 1944 | (defun replace-highlight (match-beg match-end range-beg range-end |
| 1921 | search-string regexp-flag delimited-flag | 1945 | search-string regexp-flag delimited-flag |
| 1922 | case-fold-search) | 1946 | case-fold-search backward) |
| 1923 | (if query-replace-highlight | 1947 | (if query-replace-highlight |
| 1924 | (if replace-overlay | 1948 | (if replace-overlay |
| 1925 | (move-overlay replace-overlay match-beg match-end (current-buffer)) | 1949 | (move-overlay replace-overlay match-beg match-end (current-buffer)) |
| @@ -1935,7 +1959,7 @@ It is called with three arguments, as if it were | |||
| 1935 | (isearch-regexp-lax-whitespace | 1959 | (isearch-regexp-lax-whitespace |
| 1936 | replace-regexp-lax-whitespace) | 1960 | replace-regexp-lax-whitespace) |
| 1937 | (isearch-case-fold-search case-fold-search) | 1961 | (isearch-case-fold-search case-fold-search) |
| 1938 | (isearch-forward t) | 1962 | (isearch-forward (not backward)) |
| 1939 | (isearch-other-end match-beg) | 1963 | (isearch-other-end match-beg) |
| 1940 | (isearch-error nil)) | 1964 | (isearch-error nil)) |
| 1941 | (isearch-lazy-highlight-new-loop range-beg range-end)))) | 1965 | (isearch-lazy-highlight-new-loop range-beg range-end)))) |
| @@ -1951,7 +1975,7 @@ It is called with three arguments, as if it were | |||
| 1951 | 1975 | ||
| 1952 | (defun perform-replace (from-string replacements | 1976 | (defun perform-replace (from-string replacements |
| 1953 | query-flag regexp-flag delimited-flag | 1977 | query-flag regexp-flag delimited-flag |
| 1954 | &optional repeat-count map start end) | 1978 | &optional repeat-count map start end backward) |
| 1955 | "Subroutine of `query-replace'. Its complexity handles interactive queries. | 1979 | "Subroutine of `query-replace'. Its complexity handles interactive queries. |
| 1956 | Don't use this in your own program unless you want to query and set the mark | 1980 | Don't use this in your own program unless you want to query and set the mark |
| 1957 | just as `query-replace' does. Instead, write a simple loop like this: | 1981 | just as `query-replace' does. Instead, write a simple loop like this: |
| @@ -2005,10 +2029,15 @@ make, or the user didn't cancel the call." | |||
| 2005 | minibuffer-prompt-properties)))) | 2029 | minibuffer-prompt-properties)))) |
| 2006 | 2030 | ||
| 2007 | ;; If region is active, in Transient Mark mode, operate on region. | 2031 | ;; If region is active, in Transient Mark mode, operate on region. |
| 2008 | (when start | 2032 | (if backward |
| 2009 | (setq limit (copy-marker (max start end))) | 2033 | (when end |
| 2010 | (goto-char (min start end)) | 2034 | (setq limit (copy-marker (min start end))) |
| 2011 | (deactivate-mark)) | 2035 | (goto-char (max start end)) |
| 2036 | (deactivate-mark)) | ||
| 2037 | (when start | ||
| 2038 | (setq limit (copy-marker (max start end))) | ||
| 2039 | (goto-char (min start end)) | ||
| 2040 | (deactivate-mark))) | ||
| 2012 | 2041 | ||
| 2013 | ;; If last typed key in previous call of multi-buffer perform-replace | 2042 | ;; If last typed key in previous call of multi-buffer perform-replace |
| 2014 | ;; was `automatic-all', don't ask more questions in next files | 2043 | ;; was `automatic-all', don't ask more questions in next files |
| @@ -2038,13 +2067,17 @@ make, or the user didn't cancel the call." | |||
| 2038 | (unwind-protect | 2067 | (unwind-protect |
| 2039 | ;; Loop finding occurrences that perhaps should be replaced. | 2068 | ;; Loop finding occurrences that perhaps should be replaced. |
| 2040 | (while (and keep-going | 2069 | (while (and keep-going |
| 2041 | (not (or (eobp) (and limit (>= (point) limit)))) | 2070 | (if backward |
| 2071 | (not (or (bobp) (and limit (<= (point) limit)))) | ||
| 2072 | (not (or (eobp) (and limit (>= (point) limit))))) | ||
| 2042 | ;; Use the next match if it is already known; | 2073 | ;; Use the next match if it is already known; |
| 2043 | ;; otherwise, search for a match after moving forward | 2074 | ;; otherwise, search for a match after moving forward |
| 2044 | ;; one char if progress is required. | 2075 | ;; one char if progress is required. |
| 2045 | (setq real-match-data | 2076 | (setq real-match-data |
| 2046 | (cond ((consp match-again) | 2077 | (cond ((consp match-again) |
| 2047 | (goto-char (nth 1 match-again)) | 2078 | (goto-char (if backward |
| 2079 | (nth 0 match-again) | ||
| 2080 | (nth 1 match-again))) | ||
| 2048 | (replace-match-data | 2081 | (replace-match-data |
| 2049 | t real-match-data match-again)) | 2082 | t real-match-data match-again)) |
| 2050 | ;; MATCH-AGAIN non-nil means accept an | 2083 | ;; MATCH-AGAIN non-nil means accept an |
| @@ -2053,22 +2086,26 @@ make, or the user didn't cancel the call." | |||
| 2053 | (and | 2086 | (and |
| 2054 | (replace-search search-string limit | 2087 | (replace-search search-string limit |
| 2055 | regexp-flag delimited-flag | 2088 | regexp-flag delimited-flag |
| 2056 | case-fold-search) | 2089 | case-fold-search backward) |
| 2057 | ;; For speed, use only integers and | 2090 | ;; For speed, use only integers and |
| 2058 | ;; reuse the list used last time. | 2091 | ;; reuse the list used last time. |
| 2059 | (replace-match-data t real-match-data))) | 2092 | (replace-match-data t real-match-data))) |
| 2060 | ((and (< (1+ (point)) (point-max)) | 2093 | ((and (if backward |
| 2094 | (> (1- (point)) (point-min)) | ||
| 2095 | (< (1+ (point)) (point-max))) | ||
| 2061 | (or (null limit) | 2096 | (or (null limit) |
| 2062 | (< (1+ (point)) limit))) | 2097 | (if backward |
| 2098 | (> (1- (point)) limit) | ||
| 2099 | (< (1+ (point)) limit)))) | ||
| 2063 | ;; If not accepting adjacent matches, | 2100 | ;; If not accepting adjacent matches, |
| 2064 | ;; move one char to the right before | 2101 | ;; move one char to the right before |
| 2065 | ;; searching again. Undo the motion | 2102 | ;; searching again. Undo the motion |
| 2066 | ;; if the search fails. | 2103 | ;; if the search fails. |
| 2067 | (let ((opoint (point))) | 2104 | (let ((opoint (point))) |
| 2068 | (forward-char 1) | 2105 | (forward-char (if backward -1 1)) |
| 2069 | (if (replace-search search-string limit | 2106 | (if (replace-search search-string limit |
| 2070 | regexp-flag delimited-flag | 2107 | regexp-flag delimited-flag |
| 2071 | case-fold-search) | 2108 | case-fold-search backward) |
| 2072 | (replace-match-data | 2109 | (replace-match-data |
| 2073 | t real-match-data) | 2110 | t real-match-data) |
| 2074 | (goto-char opoint) | 2111 | (goto-char opoint) |
| @@ -2089,7 +2126,9 @@ make, or the user didn't cancel the call." | |||
| 2089 | (setq match-again | 2126 | (setq match-again |
| 2090 | (and nonempty-match | 2127 | (and nonempty-match |
| 2091 | (or (not regexp-flag) | 2128 | (or (not regexp-flag) |
| 2092 | (and (looking-at search-string) | 2129 | (and (if backward |
| 2130 | (looking-back search-string) | ||
| 2131 | (looking-at search-string)) | ||
| 2093 | (let ((match (match-data))) | 2132 | (let ((match (match-data))) |
| 2094 | (and (/= (nth 0 match) (nth 1 match)) | 2133 | (and (/= (nth 0 match) (nth 1 match)) |
| 2095 | match)))))) | 2134 | match)))))) |
| @@ -2126,11 +2165,11 @@ make, or the user didn't cancel the call." | |||
| 2126 | (replace-highlight | 2165 | (replace-highlight |
| 2127 | (nth 0 real-match-data) (nth 1 real-match-data) | 2166 | (nth 0 real-match-data) (nth 1 real-match-data) |
| 2128 | start end search-string | 2167 | start end search-string |
| 2129 | regexp-flag delimited-flag case-fold-search)) | 2168 | regexp-flag delimited-flag case-fold-search backward)) |
| 2130 | (setq noedit | 2169 | (setq noedit |
| 2131 | (replace-match-maybe-edit | 2170 | (replace-match-maybe-edit |
| 2132 | next-replacement nocasify literal | 2171 | next-replacement nocasify literal |
| 2133 | noedit real-match-data) | 2172 | noedit real-match-data backward) |
| 2134 | replace-count (1+ replace-count))) | 2173 | replace-count (1+ replace-count))) |
| 2135 | (undo-boundary) | 2174 | (undo-boundary) |
| 2136 | (let (done replaced key def) | 2175 | (let (done replaced key def) |
| @@ -2145,7 +2184,7 @@ make, or the user didn't cancel the call." | |||
| 2145 | (replace-highlight | 2184 | (replace-highlight |
| 2146 | (match-beginning 0) (match-end 0) | 2185 | (match-beginning 0) (match-end 0) |
| 2147 | start end search-string | 2186 | start end search-string |
| 2148 | regexp-flag delimited-flag case-fold-search) | 2187 | regexp-flag delimited-flag case-fold-search backward) |
| 2149 | ;; Bind message-log-max so we don't fill up the message log | 2188 | ;; Bind message-log-max so we don't fill up the message log |
| 2150 | ;; with a bunch of identical messages. | 2189 | ;; with a bunch of identical messages. |
| 2151 | (let ((message-log-max nil) | 2190 | (let ((message-log-max nil) |
| @@ -2175,6 +2214,7 @@ make, or the user didn't cancel the call." | |||
| 2175 | (get delimited-flag 'isearch-message-prefix)) | 2214 | (get delimited-flag 'isearch-message-prefix)) |
| 2176 | "word ") "") | 2215 | "word ") "") |
| 2177 | (if regexp-flag "regexp " "") | 2216 | (if regexp-flag "regexp " "") |
| 2217 | (if backward "backward " "") | ||
| 2178 | from-string " with " | 2218 | from-string " with " |
| 2179 | next-replacement ".\n\n" | 2219 | next-replacement ".\n\n" |
| 2180 | (substitute-command-keys | 2220 | (substitute-command-keys |
| @@ -2203,7 +2243,7 @@ make, or the user didn't cancel the call." | |||
| 2203 | (setq noedit | 2243 | (setq noedit |
| 2204 | (replace-match-maybe-edit | 2244 | (replace-match-maybe-edit |
| 2205 | next-replacement nocasify literal | 2245 | next-replacement nocasify literal |
| 2206 | noedit real-match-data) | 2246 | noedit real-match-data backward) |
| 2207 | replace-count (1+ replace-count))) | 2247 | replace-count (1+ replace-count))) |
| 2208 | (setq done t replaced t)) | 2248 | (setq done t replaced t)) |
| 2209 | ((eq def 'act-and-exit) | 2249 | ((eq def 'act-and-exit) |
| @@ -2211,7 +2251,7 @@ make, or the user didn't cancel the call." | |||
| 2211 | (setq noedit | 2251 | (setq noedit |
| 2212 | (replace-match-maybe-edit | 2252 | (replace-match-maybe-edit |
| 2213 | next-replacement nocasify literal | 2253 | next-replacement nocasify literal |
| 2214 | noedit real-match-data) | 2254 | noedit real-match-data backward) |
| 2215 | replace-count (1+ replace-count))) | 2255 | replace-count (1+ replace-count))) |
| 2216 | (setq keep-going nil) | 2256 | (setq keep-going nil) |
| 2217 | (setq done t replaced t)) | 2257 | (setq done t replaced t)) |
| @@ -2220,7 +2260,7 @@ make, or the user didn't cancel the call." | |||
| 2220 | (setq noedit | 2260 | (setq noedit |
| 2221 | (replace-match-maybe-edit | 2261 | (replace-match-maybe-edit |
| 2222 | next-replacement nocasify literal | 2262 | next-replacement nocasify literal |
| 2223 | noedit real-match-data) | 2263 | noedit real-match-data backward) |
| 2224 | replace-count (1+ replace-count) | 2264 | replace-count (1+ replace-count) |
| 2225 | real-match-data (replace-match-data | 2265 | real-match-data (replace-match-data |
| 2226 | t real-match-data) | 2266 | t real-match-data) |
| @@ -2230,7 +2270,7 @@ make, or the user didn't cancel the call." | |||
| 2230 | (setq noedit | 2270 | (setq noedit |
| 2231 | (replace-match-maybe-edit | 2271 | (replace-match-maybe-edit |
| 2232 | next-replacement nocasify literal | 2272 | next-replacement nocasify literal |
| 2233 | noedit real-match-data) | 2273 | noedit real-match-data backward) |
| 2234 | replace-count (1+ replace-count))) | 2274 | replace-count (1+ replace-count))) |
| 2235 | (setq done t query-flag nil replaced t) | 2275 | (setq done t query-flag nil replaced t) |
| 2236 | (if (eq def 'automatic-all) (setq multi-buffer t))) | 2276 | (if (eq def 'automatic-all) (setq multi-buffer t))) |
| @@ -2274,7 +2314,7 @@ make, or the user didn't cancel the call." | |||
| 2274 | (setq noedit | 2314 | (setq noedit |
| 2275 | (replace-match-maybe-edit | 2315 | (replace-match-maybe-edit |
| 2276 | next-replacement nocasify literal noedit | 2316 | next-replacement nocasify literal noedit |
| 2277 | real-match-data) | 2317 | real-match-data backward) |
| 2278 | replaced t)) | 2318 | replaced t)) |
| 2279 | (setq done t)) | 2319 | (setq done t)) |
| 2280 | 2320 | ||