aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorJuri Linkov2004-12-12 22:33:28 +0000
committerJuri Linkov2004-12-12 22:33:28 +0000
commit35d59c0f52a589d33670810449a588ecbfc2c3cf (patch)
treebc1bdfa9cdd5db75e0e223f065140bfbcaa80e92 /lisp/replace.el
parent15fd7d5da5b7001337c87edd795c747e61894a81 (diff)
downloademacs-35d59c0f52a589d33670810449a588ecbfc2c3cf.tar.gz
emacs-35d59c0f52a589d33670810449a588ecbfc2c3cf.zip
* replace.el (query-replace-highlight): Add new value `isearch'
that allows query replacement to use isearch highlighting. Change type from `boolean' to `choice'. Doc fix. (replace-highlight, replace-dehighlight, perform-replace): Use isearch highlighting if query-replace-highlight eq `isearch'.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el54
1 files changed, 39 insertions, 15 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 933a0004ce2..646f693cd7f 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1281,6 +1281,8 @@ make, or the user didn't cancel the call."
1281 ;; (match-data); otherwise it is t if a match is possible at point. 1281 ;; (match-data); otherwise it is t if a match is possible at point.
1282 (match-again t) 1282 (match-again t)
1283 1283
1284 (isearch-string isearch-string)
1285 (isearch-regexp isearch-regexp)
1284 (message 1286 (message
1285 (if query-flag 1287 (if query-flag
1286 (substitute-command-keys 1288 (substitute-command-keys
@@ -1313,6 +1315,10 @@ make, or the user didn't cancel the call."
1313 (if regexp-flag from-string 1315 (if regexp-flag from-string
1314 (regexp-quote from-string)) 1316 (regexp-quote from-string))
1315 "\\b"))) 1317 "\\b")))
1318 (if (eq query-replace-highlight 'isearch)
1319 (setq isearch-string search-string
1320 isearch-regexp regexp-flag))
1321
1316 (push-mark) 1322 (push-mark)
1317 (undo-boundary) 1323 (undo-boundary)
1318 (unwind-protect 1324 (unwind-protect
@@ -1528,7 +1534,14 @@ make, or the user didn't cancel the call."
1528 (setq unread-command-events 1534 (setq unread-command-events
1529 (append (listify-key-sequence key) 1535 (append (listify-key-sequence key)
1530 unread-command-events)) 1536 unread-command-events))
1531 (setq done t)))) 1537 (setq done t)))
1538 (when (eq query-replace-highlight 'isearch)
1539 ;; Force isearch rehighlighting
1540 (if (not (memq def '(skip backup)))
1541 (setq isearch-lazy-highlight-last-string nil))
1542 ;; Restore isearch data in case of isearching during edit
1543 (setq isearch-string search-string
1544 isearch-regexp regexp-flag)))
1532 ;; Record previous position for ^ when we move on. 1545 ;; Record previous position for ^ when we move on.
1533 ;; Change markers to numbers in the match data 1546 ;; Change markers to numbers in the match data
1534 ;; since lots of markers slow down editing. 1547 ;; since lots of markers slow down editing.
@@ -1563,27 +1576,38 @@ make, or the user didn't cancel the call."
1563 (if (= replace-count 1) "" "s"))) 1576 (if (= replace-count 1) "" "s")))
1564 (and keep-going stack))) 1577 (and keep-going stack)))
1565 1578
1566(defcustom query-replace-highlight t 1579(defcustom query-replace-highlight
1567 "*Non-nil means to highlight words during query replacement." 1580 (if (and search-highlight isearch-lazy-highlight) 'isearch t)
1568 :type 'boolean 1581 "*Non-nil means to highlight words during query replacement.
1582If `isearch', use isearch highlighting for query replacement."
1583 :type '(choice (const :tag "Highlight" t)
1584 (const :tag "No highlighting" nil)
1585 (const :tag "Isearch highlighting" 'isearch))
1569 :group 'matching) 1586 :group 'matching)
1570 1587
1571(defvar replace-overlay nil) 1588(defvar replace-overlay nil)
1572 1589
1573(defun replace-dehighlight () 1590(defun replace-dehighlight ()
1574 (and replace-overlay 1591 (cond ((eq query-replace-highlight 'isearch)
1575 (progn 1592 (isearch-dehighlight t)
1576 (delete-overlay replace-overlay) 1593 (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup)
1577 (setq replace-overlay nil)))) 1594 (setq isearch-lazy-highlight-last-string nil))
1595 (query-replace-highlight
1596 (when replace-overlay
1597 (delete-overlay replace-overlay)
1598 (setq replace-overlay nil)))))
1578 1599
1579(defun replace-highlight (start end) 1600(defun replace-highlight (start end)
1580 (and query-replace-highlight 1601 (cond ((eq query-replace-highlight 'isearch)
1581 (if replace-overlay 1602 (isearch-highlight start end)
1582 (move-overlay replace-overlay start end (current-buffer)) 1603 (isearch-lazy-highlight-new-loop))
1583 (setq replace-overlay (make-overlay start end)) 1604 (query-replace-highlight
1584 (overlay-put replace-overlay 'face 1605 (if replace-overlay
1585 (if (facep 'query-replace) 1606 (move-overlay replace-overlay start end (current-buffer))
1586 'query-replace 'region))))) 1607 (setq replace-overlay (make-overlay start end))
1608 (overlay-put replace-overlay 'face
1609 (if (facep 'query-replace)
1610 'query-replace 'region))))))
1587 1611
1588;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4 1612;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4
1589;;; replace.el ends here 1613;;; replace.el ends here