Mercurial > emacs
comparison lisp/replace.el @ 60713:77391bae98f1
(perform-replace): Remove bindings of global
variables isearch-string, isearch-regexp, isearch-case-fold-search.
Add three new arguments to `replace-highlight'.
(replace-highlight): Add arguments string, regexp, case-fold.
Let-bind isearch-string, isearch-regexp, isearch-case-fold-search
to allow isearch-lazy-highlight-new-loop to use these values
to set corresponding isearch-lazy-highlight-... internal
variables whose values lazy highlighting will use regardless of
changes to global variables isearch-string, isearch-regexp,
isearch-case-fold-search during lazy highlighting loop.
(replace-dehighlight): Rename `isearch-lazy-highlight-cleanup'
to `lazy-highlight-cleanup'.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Fri, 18 Mar 2005 09:59:45 +0000 |
parents | 4d79094ee455 |
children | 94214f10d9c4 30ad2795fdab |
comparison
equal
deleted
inserted
replaced
60712:d37e83a20683 | 60713:77391bae98f1 |
---|---|
1342 | 1342 |
1343 ;; Data for the next match. If a cons, it has the same format as | 1343 ;; Data for the next match. If a cons, it has the same format as |
1344 ;; (match-data); otherwise it is t if a match is possible at point. | 1344 ;; (match-data); otherwise it is t if a match is possible at point. |
1345 (match-again t) | 1345 (match-again t) |
1346 | 1346 |
1347 (isearch-string isearch-string) | |
1348 (isearch-regexp isearch-regexp) | |
1349 (isearch-case-fold-search isearch-case-fold-search) | |
1350 (message | 1347 (message |
1351 (if query-flag | 1348 (if query-flag |
1352 (substitute-command-keys | 1349 (substitute-command-keys |
1353 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) ")))) | 1350 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) ")))) |
1354 | 1351 |
1378 search-string (concat "\\b" | 1375 search-string (concat "\\b" |
1379 (if regexp-flag from-string | 1376 (if regexp-flag from-string |
1380 (regexp-quote from-string)) | 1377 (regexp-quote from-string)) |
1381 "\\b"))) | 1378 "\\b"))) |
1382 (when query-replace-lazy-highlight | 1379 (when query-replace-lazy-highlight |
1383 (setq isearch-string search-string | 1380 (setq isearch-lazy-highlight-last-string nil)) |
1384 isearch-regexp (or delimited-flag regexp-flag) | |
1385 isearch-case-fold-search case-fold-search | |
1386 isearch-lazy-highlight-last-string nil)) | |
1387 | 1381 |
1388 (push-mark) | 1382 (push-mark) |
1389 (undo-boundary) | 1383 (undo-boundary) |
1390 (unwind-protect | 1384 (unwind-protect |
1391 ;; Loop finding occurrences that perhaps should be replaced. | 1385 ;; Loop finding occurrences that perhaps should be replaced. |
1451 noedit nil)) | 1445 noedit nil)) |
1452 (if (not query-flag) | 1446 (if (not query-flag) |
1453 (let ((inhibit-read-only | 1447 (let ((inhibit-read-only |
1454 query-replace-skip-read-only)) | 1448 query-replace-skip-read-only)) |
1455 (unless (or literal noedit) | 1449 (unless (or literal noedit) |
1456 (replace-highlight (nth 0 real-match-data) | 1450 (replace-highlight |
1457 (nth 1 real-match-data) | 1451 (nth 0 real-match-data) (nth 1 real-match-data) |
1458 start end)) | 1452 start end search-string |
1453 (or delimited-flag regexp-flag) case-fold-search)) | |
1459 (setq noedit | 1454 (setq noedit |
1460 (replace-match-maybe-edit | 1455 (replace-match-maybe-edit |
1461 next-replacement nocasify literal | 1456 next-replacement nocasify literal |
1462 noedit real-match-data) | 1457 noedit real-match-data) |
1463 replace-count (1+ replace-count))) | 1458 replace-count (1+ replace-count))) |
1469 ;; leave behind proper match data for the stack. | 1464 ;; leave behind proper match data for the stack. |
1470 ;; Commands not setting `done' need to adjust | 1465 ;; Commands not setting `done' need to adjust |
1471 ;; `real-match-data'. | 1466 ;; `real-match-data'. |
1472 (while (not done) | 1467 (while (not done) |
1473 (set-match-data real-match-data) | 1468 (set-match-data real-match-data) |
1474 (replace-highlight (match-beginning 0) (match-end 0) | 1469 (replace-highlight |
1475 start end) | 1470 (match-beginning 0) (match-end 0) |
1471 start end search-string | |
1472 (or delimited-flag regexp-flag) case-fold-search) | |
1476 ;; Bind message-log-max so we don't fill up the message log | 1473 ;; Bind message-log-max so we don't fill up the message log |
1477 ;; with a bunch of identical messages. | 1474 ;; with a bunch of identical messages. |
1478 (let ((message-log-max nil)) | 1475 (let ((message-log-max nil)) |
1479 (message message | 1476 (message message |
1480 (query-replace-descr from-string) | 1477 (query-replace-descr from-string) |
1602 (setq unread-command-events | 1599 (setq unread-command-events |
1603 (append (listify-key-sequence key) | 1600 (append (listify-key-sequence key) |
1604 unread-command-events)) | 1601 unread-command-events)) |
1605 (setq done t))) | 1602 (setq done t))) |
1606 (when query-replace-lazy-highlight | 1603 (when query-replace-lazy-highlight |
1607 ;; Restore isearch data for lazy highlighting | |
1608 ;; in case of isearching during recursive edit | |
1609 (setq isearch-string search-string | |
1610 isearch-regexp (or delimited-flag regexp-flag) | |
1611 isearch-case-fold-search case-fold-search) | |
1612 ;; Force lazy rehighlighting only after replacements | 1604 ;; Force lazy rehighlighting only after replacements |
1613 (if (not (memq def '(skip backup))) | 1605 (if (not (memq def '(skip backup))) |
1614 (setq isearch-lazy-highlight-last-string nil)))) | 1606 (setq isearch-lazy-highlight-last-string nil)))) |
1615 ;; Record previous position for ^ when we move on. | 1607 ;; Record previous position for ^ when we move on. |
1616 ;; Change markers to numbers in the match data | 1608 ;; Change markers to numbers in the match data |
1646 (if (= replace-count 1) "" "s"))) | 1638 (if (= replace-count 1) "" "s"))) |
1647 (and keep-going stack))) | 1639 (and keep-going stack))) |
1648 | 1640 |
1649 (defvar replace-overlay nil) | 1641 (defvar replace-overlay nil) |
1650 | 1642 |
1651 (defun replace-highlight (match-beg match-end range-beg range-end) | 1643 (defun replace-highlight (match-beg match-end range-beg range-end |
1644 string regexp case-fold) | |
1652 (if query-replace-highlight | 1645 (if query-replace-highlight |
1653 (if replace-overlay | 1646 (if replace-overlay |
1654 (move-overlay replace-overlay match-beg match-end (current-buffer)) | 1647 (move-overlay replace-overlay match-beg match-end (current-buffer)) |
1655 (setq replace-overlay (make-overlay match-beg match-end)) | 1648 (setq replace-overlay (make-overlay match-beg match-end)) |
1656 (overlay-put replace-overlay 'priority 1) ;higher than lazy overlays | 1649 (overlay-put replace-overlay 'priority 1) ;higher than lazy overlays |
1657 (overlay-put replace-overlay 'face 'query-replace))) | 1650 (overlay-put replace-overlay 'face 'query-replace))) |
1658 (when query-replace-lazy-highlight | 1651 (if query-replace-lazy-highlight |
1659 (isearch-lazy-highlight-new-loop range-beg range-end))) | 1652 (let ((isearch-string string) |
1653 (isearch-regexp regexp) | |
1654 (isearch-case-fold-search case-fold)) | |
1655 (isearch-lazy-highlight-new-loop range-beg range-end)))) | |
1660 | 1656 |
1661 (defun replace-dehighlight () | 1657 (defun replace-dehighlight () |
1662 (when replace-overlay | 1658 (when replace-overlay |
1663 (delete-overlay replace-overlay)) | 1659 (delete-overlay replace-overlay)) |
1664 (when query-replace-lazy-highlight | 1660 (when query-replace-lazy-highlight |
1665 (isearch-lazy-highlight-cleanup lazy-highlight-cleanup) | 1661 (lazy-highlight-cleanup lazy-highlight-cleanup) |
1666 (setq isearch-lazy-highlight-last-string nil))) | 1662 (setq isearch-lazy-highlight-last-string nil))) |
1667 | 1663 |
1668 ;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4 | 1664 ;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4 |
1669 ;;; replace.el ends here | 1665 ;;; replace.el ends here |