comparison lisp/replace.el @ 58973:7fed010105d9

(perform-replace): Add isearch-case-fold-search. Use delimited-flag for isearch-regexp. Reset isearch-lazy-highlight-last-string to force lazy highlighting when called from isearch mode. (query-replace-highlight): Revert defcustom type to boolean. (query-replace-lazy-highlight): New defcustom. (query-replace): New face. (perform-replace, replace-highlight, replace-dehighlight): Test query-replace-lazy-highlight instead of special value `isearch' of query-replace-highlight. (replace-dehighlight): Don't call isearch-dehighlight. (replace-highlight): Don't call isearch-highlight. Use face `query-replace' unconditionally.
author Juri Linkov <juri@jurta.org>
date Wed, 15 Dec 2004 10:10:54 +0000
parents f55019d052ed
children b24e485e88f7
comparison
equal deleted inserted replaced
58972:71d0bc7835fb 58973:7fed010105d9
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) 1284 (isearch-string isearch-string)
1285 (isearch-regexp isearch-regexp) 1285 (isearch-regexp isearch-regexp)
1286 (isearch-case-fold-search isearch-case-fold-search)
1286 (message 1287 (message
1287 (if query-flag 1288 (if query-flag
1288 (substitute-command-keys 1289 (substitute-command-keys
1289 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) ")))) 1290 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) "))))
1290 1291
1313 (setq search-function 're-search-forward 1314 (setq search-function 're-search-forward
1314 search-string (concat "\\b" 1315 search-string (concat "\\b"
1315 (if regexp-flag from-string 1316 (if regexp-flag from-string
1316 (regexp-quote from-string)) 1317 (regexp-quote from-string))
1317 "\\b"))) 1318 "\\b")))
1318 (if (eq query-replace-highlight 'isearch) 1319 (when query-replace-lazy-highlight
1319 (setq isearch-string search-string 1320 (setq isearch-string search-string
1320 isearch-regexp regexp-flag)) 1321 isearch-regexp (or delimited-flag regexp-flag)
1322 isearch-case-fold-search case-fold-search
1323 isearch-lazy-highlight-last-string nil))
1321 1324
1322 (push-mark) 1325 (push-mark)
1323 (undo-boundary) 1326 (undo-boundary)
1324 (unwind-protect 1327 (unwind-protect
1325 ;; Loop finding occurrences that perhaps should be replaced. 1328 ;; Loop finding occurrences that perhaps should be replaced.
1533 (setq keep-going nil) 1536 (setq keep-going nil)
1534 (setq unread-command-events 1537 (setq unread-command-events
1535 (append (listify-key-sequence key) 1538 (append (listify-key-sequence key)
1536 unread-command-events)) 1539 unread-command-events))
1537 (setq done t))) 1540 (setq done t)))
1538 (when (eq query-replace-highlight 'isearch) 1541 (when query-replace-lazy-highlight
1539 ;; Force isearch rehighlighting 1542 ;; Restore isearch data for lazy highlighting
1543 ;; in case of isearching during recursive edit
1544 (setq isearch-string search-string
1545 isearch-regexp (or delimited-flag regexp-flag)
1546 isearch-case-fold-search case-fold-search)
1547 ;; Force lazy rehighlighting only after replacements
1540 (if (not (memq def '(skip backup))) 1548 (if (not (memq def '(skip backup)))
1541 (setq isearch-lazy-highlight-last-string nil)) 1549 (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)))
1545 ;; Record previous position for ^ when we move on. 1550 ;; Record previous position for ^ when we move on.
1546 ;; Change markers to numbers in the match data 1551 ;; Change markers to numbers in the match data
1547 ;; since lots of markers slow down editing. 1552 ;; since lots of markers slow down editing.
1548 (push (list (point) replaced 1553 (push (list (point) replaced
1549 ;;; If the replacement has already happened, all we need is the 1554 ;;; If the replacement has already happened, all we need is the
1574 (message "Replaced %d occurrence%s" 1579 (message "Replaced %d occurrence%s"
1575 replace-count 1580 replace-count
1576 (if (= replace-count 1) "" "s"))) 1581 (if (= replace-count 1) "" "s")))
1577 (and keep-going stack))) 1582 (and keep-going stack)))
1578 1583
1579 (defcustom query-replace-highlight 1584 (defcustom query-replace-highlight t
1580 (if (and search-highlight isearch-lazy-highlight) 'isearch t) 1585 "*Non-nil means to highlight matches during query replacement."
1581 "*Non-nil means to highlight words during query replacement. 1586 :type 'boolean
1582 If `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))
1586 :group 'matching) 1587 :group 'matching)
1587 1588
1589 (defcustom query-replace-lazy-highlight t
1590 "*Controls the lazy-highlighting during query replacements.
1591 When non-nil, all text in the buffer matching the current match
1592 is highlighted lazily using isearch lazy highlighting (see
1593 `isearch-lazy-highlight-initial-delay' and
1594 `isearch-lazy-highlight-interval')."
1595 :type 'boolean
1596 :group 'matching
1597 :version "21.4")
1598
1599 (defface query-replace
1600 '((t (:inherit isearch)))
1601 "Face for highlighting query replacement matches."
1602 :group 'matching
1603 :version "21.4")
1604
1588 (defvar replace-overlay nil) 1605 (defvar replace-overlay nil)
1589 1606
1607 (defun replace-highlight (beg end)
1608 (if query-replace-highlight
1609 (if replace-overlay
1610 (move-overlay replace-overlay beg end (current-buffer))
1611 (setq replace-overlay (make-overlay beg end))
1612 (overlay-put replace-overlay 'priority 1) ;higher than lazy overlays
1613 (overlay-put replace-overlay 'face 'query-replace)))
1614 (if query-replace-lazy-highlight
1615 (isearch-lazy-highlight-new-loop)))
1616
1590 (defun replace-dehighlight () 1617 (defun replace-dehighlight ()
1591 (cond ((eq query-replace-highlight 'isearch) 1618 (when replace-overlay
1592 (isearch-dehighlight t) 1619 (delete-overlay replace-overlay))
1593 (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup) 1620 (when query-replace-lazy-highlight
1594 (setq isearch-lazy-highlight-last-string nil)) 1621 (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup)
1595 (query-replace-highlight 1622 (setq isearch-lazy-highlight-last-string nil)))
1596 (when replace-overlay
1597 (delete-overlay replace-overlay)
1598 (setq replace-overlay nil)))))
1599
1600 (defun replace-highlight (start end)
1601 (cond ((eq query-replace-highlight 'isearch)
1602 (isearch-highlight start end)
1603 (isearch-lazy-highlight-new-loop))
1604 (query-replace-highlight
1605 (if replace-overlay
1606 (move-overlay replace-overlay start end (current-buffer))
1607 (setq replace-overlay (make-overlay start end))
1608 (overlay-put replace-overlay 'face
1609 (if (facep 'query-replace)
1610 'query-replace 'region))))))
1611 1623
1612 ;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4 1624 ;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4
1613 ;;; replace.el ends here 1625 ;;; replace.el ends here