aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorK. Handa2016-01-03 17:53:43 +0900
committerK. Handa2016-01-03 17:53:43 +0900
commitfb6d826c69939c2d016c1b824d4e9bcb53d9e643 (patch)
treeb9ce862d6cbe25e740203421984df21e4cbadbf4 /lisp/replace.el
parent536f48e9a2251b9e654ea974bd90ff2f40218753 (diff)
parent91917dd58ec5278e555b9c693a830749083e8f89 (diff)
downloademacs-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.el60
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.
38This means, for instance, that \\=' will match a large variety of 38This means, for instance, that \\=' will match a large variety of
39unicode quotes." 39unicode quotes.
40This 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.
117This 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
314to be replaced will match a sequence of whitespace chars defined by the 317to be replaced will match a sequence of whitespace chars defined by the
315regexp in `search-whitespace-regexp'. 318regexp in `search-whitespace-regexp'.
316 319
320If `replace-character-fold' is non-nil, matching uses character folding,
321i.e. it ignores diacritics and other differences between equivalent
322character strings.
323
317Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace 324Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
318only matches surrounded by word boundaries. A negative prefix arg means 325only matches surrounded by word boundaries. A negative prefix arg means
319replace backward. 326replace backward.
@@ -372,6 +379,8 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
372to be replaced will match a sequence of whitespace chars defined by the 379to be replaced will match a sequence of whitespace chars defined by the
373regexp in `search-whitespace-regexp'. 380regexp in `search-whitespace-regexp'.
374 381
382This function is not affected by `replace-character-fold'.
383
375Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace 384Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
376only matches surrounded by word boundaries. A negative prefix arg means 385only matches surrounded by word boundaries. A negative prefix arg means
377replace backward. 386replace backward.
@@ -460,6 +469,8 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
460to be replaced will match a sequence of whitespace chars defined by the 469to be replaced will match a sequence of whitespace chars defined by the
461regexp in `search-whitespace-regexp'. 470regexp in `search-whitespace-regexp'.
462 471
472This function is not affected by `replace-character-fold'.
473
463Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace 474Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
464only matches that are surrounded by word boundaries. 475only matches that are surrounded by word boundaries.
465Fourth and fifth arg START and END specify the region to operate on." 476Fourth 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
551to be replaced will match a sequence of whitespace chars defined by the 562to be replaced will match a sequence of whitespace chars defined by the
552regexp in `search-whitespace-regexp'. 563regexp in `search-whitespace-regexp'.
553 564
565If `replace-character-fold' is non-nil, matching uses character folding,
566i.e. it ignores diacritics and other differences between equivalent
567character strings.
568
554Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace 569Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
555only matches surrounded by word boundaries. A negative prefix arg means 570only matches surrounded by word boundaries. A negative prefix arg means
556replace backward. 571replace backward.
@@ -602,6 +617,8 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
602to be replaced will match a sequence of whitespace chars defined by the 617to be replaced will match a sequence of whitespace chars defined by the
603regexp in `search-whitespace-regexp'. 618regexp in `search-whitespace-regexp'.
604 619
620This function is not affected by `replace-character-fold'
621
605In Transient Mark mode, if the mark is active, operate on the contents 622In Transient Mark mode, if the mark is active, operate on the contents
606of the region. Otherwise, operate from point to the end of the buffer. 623of 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.
1984It is used by `query-replace' and `replace-string', and is called 2019It 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)