diff options
| author | K. Handa | 2016-01-03 17:53:43 +0900 |
|---|---|---|
| committer | K. Handa | 2016-01-03 17:53:43 +0900 |
| commit | fb6d826c69939c2d016c1b824d4e9bcb53d9e643 (patch) | |
| tree | b9ce862d6cbe25e740203421984df21e4cbadbf4 /lisp/replace.el | |
| parent | 536f48e9a2251b9e654ea974bd90ff2f40218753 (diff) | |
| parent | 91917dd58ec5278e555b9c693a830749083e8f89 (diff) | |
| download | emacs-fb6d826c69939c2d016c1b824d4e9bcb53d9e643.tar.gz emacs-fb6d826c69939c2d016c1b824d4e9bcb53d9e643.zip | |
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index b6802aeaf57..d48f4f3fdf9 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -34,9 +34,11 @@ | |||
| 34 | :group 'matching) | 34 | :group 'matching) |
| 35 | 35 | ||
| 36 | (defcustom replace-character-fold nil | 36 | (defcustom replace-character-fold nil |
| 37 | "Non-nil means `query-replace' should do character folding in matches. | 37 | "Non-nil means replacement commands should do character folding in matches. |
| 38 | This means, for instance, that \\=' will match a large variety of | 38 | This means, for instance, that \\=' will match a large variety of |
| 39 | unicode quotes." | 39 | unicode quotes. |
| 40 | This variable affects `query-replace' and `replace-string', but not | ||
| 41 | `replace-regexp'." | ||
| 40 | :type 'boolean | 42 | :type 'boolean |
| 41 | :group 'matching | 43 | :group 'matching |
| 42 | :version "25.1") | 44 | :version "25.1") |
| @@ -111,7 +113,8 @@ strings or patterns." | |||
| 111 | :version "22.1") | 113 | :version "22.1") |
| 112 | 114 | ||
| 113 | (defcustom query-replace-show-replacement t | 115 | (defcustom query-replace-show-replacement t |
| 114 | "Non-nil means to show what actual replacement text will be." | 116 | "Non-nil means show substituted replacement text in the minibuffer. |
| 117 | This variable affects only `query-replace-regexp'." | ||
| 115 | :type 'boolean | 118 | :type 'boolean |
| 116 | :group 'matching | 119 | :group 'matching |
| 117 | :version "23.1") | 120 | :version "23.1") |
| @@ -314,6 +317,10 @@ If `replace-lax-whitespace' is non-nil, a space or spaces in the string | |||
| 314 | to be replaced will match a sequence of whitespace chars defined by the | 317 | to be replaced will match a sequence of whitespace chars defined by the |
| 315 | regexp in `search-whitespace-regexp'. | 318 | regexp in `search-whitespace-regexp'. |
| 316 | 319 | ||
| 320 | If `replace-character-fold' is non-nil, matching uses character folding, | ||
| 321 | i.e. it ignores diacritics and other differences between equivalent | ||
| 322 | character strings. | ||
| 323 | |||
| 317 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 324 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 318 | only matches surrounded by word boundaries. A negative prefix arg means | 325 | only matches surrounded by word boundaries. A negative prefix arg means |
| 319 | replace backward. | 326 | replace backward. |
| @@ -372,6 +379,8 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp | |||
| 372 | to be replaced will match a sequence of whitespace chars defined by the | 379 | to be replaced will match a sequence of whitespace chars defined by the |
| 373 | regexp in `search-whitespace-regexp'. | 380 | regexp in `search-whitespace-regexp'. |
| 374 | 381 | ||
| 382 | This function is not affected by `replace-character-fold'. | ||
| 383 | |||
| 375 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 384 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 376 | only matches surrounded by word boundaries. A negative prefix arg means | 385 | only matches surrounded by word boundaries. A negative prefix arg means |
| 377 | replace backward. | 386 | replace backward. |
| @@ -460,6 +469,8 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp | |||
| 460 | to be replaced will match a sequence of whitespace chars defined by the | 469 | to be replaced will match a sequence of whitespace chars defined by the |
| 461 | regexp in `search-whitespace-regexp'. | 470 | regexp in `search-whitespace-regexp'. |
| 462 | 471 | ||
| 472 | This function is not affected by `replace-character-fold'. | ||
| 473 | |||
| 463 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 474 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 464 | only matches that are surrounded by word boundaries. | 475 | only matches that are surrounded by word boundaries. |
| 465 | Fourth and fifth arg START and END specify the region to operate on." | 476 | Fourth and fifth arg START and END specify the region to operate on." |
| @@ -551,6 +562,10 @@ If `replace-lax-whitespace' is non-nil, a space or spaces in the string | |||
| 551 | to be replaced will match a sequence of whitespace chars defined by the | 562 | to be replaced will match a sequence of whitespace chars defined by the |
| 552 | regexp in `search-whitespace-regexp'. | 563 | regexp in `search-whitespace-regexp'. |
| 553 | 564 | ||
| 565 | If `replace-character-fold' is non-nil, matching uses character folding, | ||
| 566 | i.e. it ignores diacritics and other differences between equivalent | ||
| 567 | character strings. | ||
| 568 | |||
| 554 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 569 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 555 | only matches surrounded by word boundaries. A negative prefix arg means | 570 | only matches surrounded by word boundaries. A negative prefix arg means |
| 556 | replace backward. | 571 | replace backward. |
| @@ -602,6 +617,8 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp | |||
| 602 | to be replaced will match a sequence of whitespace chars defined by the | 617 | to be replaced will match a sequence of whitespace chars defined by the |
| 603 | regexp in `search-whitespace-regexp'. | 618 | regexp in `search-whitespace-regexp'. |
| 604 | 619 | ||
| 620 | This function is not affected by `replace-character-fold' | ||
| 621 | |||
| 605 | In Transient Mark mode, if the mark is active, operate on the contents | 622 | In Transient Mark mode, if the mark is active, operate on the contents |
| 606 | of the region. Otherwise, operate from point to the end of the buffer. | 623 | of the region. Otherwise, operate from point to the end of the buffer. |
| 607 | 624 | ||
| @@ -1416,6 +1433,17 @@ See also `multi-occur'." | |||
| 1416 | buf)) | 1433 | buf)) |
| 1417 | (buffer-list)))))) | 1434 | (buffer-list)))))) |
| 1418 | 1435 | ||
| 1436 | (defun occur-regexp-descr (regexp) | ||
| 1437 | (format " for %s\"%s\"" | ||
| 1438 | (or (get-text-property 0 'isearch-regexp-function-descr regexp) | ||
| 1439 | "") | ||
| 1440 | (if (get-text-property 0 'isearch-string regexp) | ||
| 1441 | (propertize | ||
| 1442 | (query-replace-descr | ||
| 1443 | (get-text-property 0 'isearch-string regexp)) | ||
| 1444 | 'help-echo regexp) | ||
| 1445 | (query-replace-descr regexp)))) | ||
| 1446 | |||
| 1419 | (defun occur-1 (regexp nlines bufs &optional buf-name) | 1447 | (defun occur-1 (regexp nlines bufs &optional buf-name) |
| 1420 | (unless (and regexp (not (equal regexp ""))) | 1448 | (unless (and regexp (not (equal regexp ""))) |
| 1421 | (error "Occur doesn't work with the empty regexp")) | 1449 | (error "Occur doesn't work with the empty regexp")) |
| @@ -1484,9 +1512,11 @@ See also `multi-occur'." | |||
| 1484 | (if (= count 1) "" "es") | 1512 | (if (= count 1) "" "es") |
| 1485 | ;; Don't display regexp if with remaining text | 1513 | ;; Don't display regexp if with remaining text |
| 1486 | ;; it is longer than window-width. | 1514 | ;; it is longer than window-width. |
| 1487 | (if (> (+ (length regexp) 42) (window-width)) | 1515 | (if (> (+ (length (or (get-text-property 0 'isearch-string regexp) |
| 1488 | "" (format-message | 1516 | regexp)) |
| 1489 | " for `%s'" (query-replace-descr regexp))))) | 1517 | 42) |
| 1518 | (window-width)) | ||
| 1519 | "" (occur-regexp-descr regexp)))) | ||
| 1490 | (setq occur-revert-arguments (list regexp nlines bufs)) | 1520 | (setq occur-revert-arguments (list regexp nlines bufs)) |
| 1491 | (if (= count 0) | 1521 | (if (= count 0) |
| 1492 | (kill-buffer occur-buf) | 1522 | (kill-buffer occur-buf) |
| @@ -1547,6 +1577,9 @@ See also `multi-occur'." | |||
| 1547 | ;; Highlight the matches | 1577 | ;; Highlight the matches |
| 1548 | (let ((len (length curstring)) | 1578 | (let ((len (length curstring)) |
| 1549 | (start 0)) | 1579 | (start 0)) |
| 1580 | ;; Count empty lines that don't use next loop (Bug#22062). | ||
| 1581 | (when (zerop len) | ||
| 1582 | (setq matches (1+ matches))) | ||
| 1550 | (while (and (< start len) | 1583 | (while (and (< start len) |
| 1551 | (string-match regexp curstring start)) | 1584 | (string-match regexp curstring start)) |
| 1552 | (setq matches (1+ matches)) | 1585 | (setq matches (1+ matches)) |
| @@ -1647,8 +1680,7 @@ See also `multi-occur'." | |||
| 1647 | lines (if (= lines 1) "" "s"))) | 1680 | lines (if (= lines 1) "" "s"))) |
| 1648 | ;; Don't display regexp for multi-buffer. | 1681 | ;; Don't display regexp for multi-buffer. |
| 1649 | (if (> (length buffers) 1) | 1682 | (if (> (length buffers) 1) |
| 1650 | "" (format " for \"%s\"" | 1683 | "" (occur-regexp-descr regexp)) |
| 1651 | (query-replace-descr regexp))) | ||
| 1652 | (buffer-name buf)) | 1684 | (buffer-name buf)) |
| 1653 | 'read-only t)) | 1685 | 'read-only t)) |
| 1654 | (setq end (point)) | 1686 | (setq end (point)) |
| @@ -1661,14 +1693,14 @@ See also `multi-occur'." | |||
| 1661 | (goto-char (point-min)) | 1693 | (goto-char (point-min)) |
| 1662 | (let ((beg (point)) | 1694 | (let ((beg (point)) |
| 1663 | end) | 1695 | end) |
| 1664 | (insert (format "%d match%s%s total for \"%s\":\n" | 1696 | (insert (format "%d match%s%s total%s:\n" |
| 1665 | global-matches (if (= global-matches 1) "" "es") | 1697 | global-matches (if (= global-matches 1) "" "es") |
| 1666 | ;; Don't display the same number of lines | 1698 | ;; Don't display the same number of lines |
| 1667 | ;; and matches in case of 1 match per line. | 1699 | ;; and matches in case of 1 match per line. |
| 1668 | (if (= global-lines global-matches) | 1700 | (if (= global-lines global-matches) |
| 1669 | "" (format " in %d line%s" | 1701 | "" (format " in %d line%s" |
| 1670 | global-lines (if (= global-lines 1) "" "s"))) | 1702 | global-lines (if (= global-lines 1) "" "s"))) |
| 1671 | (query-replace-descr regexp))) | 1703 | (occur-regexp-descr regexp))) |
| 1672 | (setq end (point)) | 1704 | (setq end (point)) |
| 1673 | (when title-face | 1705 | (when title-face |
| 1674 | (add-face-text-property beg end title-face))) | 1706 | (add-face-text-property beg end title-face))) |
| @@ -1979,6 +2011,9 @@ passed in. If LITERAL is set, no checking is done, anyway." | |||
| 1979 | (when backward (goto-char (nth 0 match-data))) | 2011 | (when backward (goto-char (nth 0 match-data))) |
| 1980 | noedit) | 2012 | noedit) |
| 1981 | 2013 | ||
| 2014 | (defvar replace-update-post-hook nil | ||
| 2015 | "Function(s) to call after query-replace has found a match in the buffer.") | ||
| 2016 | |||
| 1982 | (defvar replace-search-function nil | 2017 | (defvar replace-search-function nil |
| 1983 | "Function to use when searching for strings to replace. | 2018 | "Function to use when searching for strings to replace. |
| 1984 | It is used by `query-replace' and `replace-string', and is called | 2019 | It is used by `query-replace' and `replace-string', and is called |
| @@ -2232,7 +2267,7 @@ It must return a string." | |||
| 2232 | (and nonempty-match | 2267 | (and nonempty-match |
| 2233 | (or (not regexp-flag) | 2268 | (or (not regexp-flag) |
| 2234 | (and (if backward | 2269 | (and (if backward |
| 2235 | (looking-back search-string) | 2270 | (looking-back search-string nil) |
| 2236 | (looking-at search-string)) | 2271 | (looking-at search-string)) |
| 2237 | (let ((match (match-data))) | 2272 | (let ((match (match-data))) |
| 2238 | (and (/= (nth 0 match) (nth 1 match)) | 2273 | (and (/= (nth 0 match) (nth 1 match)) |
| @@ -2286,7 +2321,8 @@ It must return a string." | |||
| 2286 | ;; `real-match-data'. | 2321 | ;; `real-match-data'. |
| 2287 | (while (not done) | 2322 | (while (not done) |
| 2288 | (set-match-data real-match-data) | 2323 | (set-match-data real-match-data) |
| 2289 | (replace-highlight | 2324 | (run-hooks 'replace-update-post-hook) ; Before `replace-highlight'. |
| 2325 | (replace-highlight | ||
| 2290 | (match-beginning 0) (match-end 0) | 2326 | (match-beginning 0) (match-end 0) |
| 2291 | start end search-string | 2327 | start end search-string |
| 2292 | regexp-flag delimited-flag case-fold-search backward) | 2328 | regexp-flag delimited-flag case-fold-search backward) |