Mercurial > emacs
comparison lisp/replace.el @ 96908:531d21ce5cca
(multi-query-replace-map): New variable.
(perform-replace): Add processing of new multi-buffer keys bound
to `automatic-all' and `exit-current'. Set `query-flag' to nil
if last input char was `automatic-all'. Set new local variable
`multi-buffer' to t when one of new two keys were typed. Return
non-nil value of `multi-buffer' that tells to calling functions
to continue replacement on the next file.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Wed, 23 Jul 2008 01:18:39 +0000 |
parents | b5e89d359b84 |
children | 922b39c63813 |
comparison
equal
deleted
inserted
replaced
96907:c80b0289ddf5 | 96908:531d21ce5cca |
---|---|
1370 The \"bindings\" in this map are not commands; they are answers. | 1370 The \"bindings\" in this map are not commands; they are answers. |
1371 The valid answers include `act', `skip', `act-and-show', | 1371 The valid answers include `act', `skip', `act-and-show', |
1372 `exit', `act-and-exit', `edit', `delete-and-edit', `recenter', | 1372 `exit', `act-and-exit', `edit', `delete-and-edit', `recenter', |
1373 `automatic', `backup', `exit-prefix', and `help'.") | 1373 `automatic', `backup', `exit-prefix', and `help'.") |
1374 | 1374 |
1375 (defvar multi-query-replace-map | |
1376 (let ((map (make-sparse-keymap))) | |
1377 (set-keymap-parent map query-replace-map) | |
1378 (define-key map "Y" 'automatic-all) | |
1379 (define-key map "N" 'exit-current) | |
1380 map) | |
1381 "Keymap that defines additional bindings for multi-buffer replacements. | |
1382 It extends its parent map `query-replace-map' with new bindings to | |
1383 operate on a set of buffers/files. The difference with its parent map | |
1384 is the additional answers `automatic-all' to replace all remaining | |
1385 matches in all remaining buffers with no more questions, and | |
1386 `exit-current' to skip remaining matches in the current buffer | |
1387 and to continue with the next buffer in the sequence.") | |
1388 | |
1375 (defun replace-match-string-symbols (n) | 1389 (defun replace-match-string-symbols (n) |
1376 "Process a list (and any sub-lists), expanding certain symbols. | 1390 "Process a list (and any sub-lists), expanding certain symbols. |
1377 Symbol Expands To | 1391 Symbol Expands To |
1378 N (match-string N) (where N is a string of digits) | 1392 N (match-string N) (where N is a string of digits) |
1379 #N (string-to-number (match-string N)) | 1393 #N (string-to-number (match-string N)) |
1525 (noedit nil) | 1539 (noedit nil) |
1526 (keep-going t) | 1540 (keep-going t) |
1527 (stack nil) | 1541 (stack nil) |
1528 (replace-count 0) | 1542 (replace-count 0) |
1529 (nonempty-match nil) | 1543 (nonempty-match nil) |
1544 (multi-buffer nil) | |
1530 | 1545 |
1531 ;; If non-nil, it is marker saying where in the buffer to stop. | 1546 ;; If non-nil, it is marker saying where in the buffer to stop. |
1532 (limit nil) | 1547 (limit nil) |
1533 | 1548 |
1534 ;; Data for the next match. If a cons, it has the same format as | 1549 ;; Data for the next match. If a cons, it has the same format as |
1545 ;; If region is active, in Transient Mark mode, operate on region. | 1560 ;; If region is active, in Transient Mark mode, operate on region. |
1546 (when start | 1561 (when start |
1547 (setq limit (copy-marker (max start end))) | 1562 (setq limit (copy-marker (max start end))) |
1548 (goto-char (min start end)) | 1563 (goto-char (min start end)) |
1549 (deactivate-mark)) | 1564 (deactivate-mark)) |
1565 | |
1566 ;; If last typed key in previous call of multi-buffer perform-replace | |
1567 ;; was `automatic-all', don't ask more questions in next files | |
1568 (when (eq (lookup-key map (vector last-input-char)) 'automatic-all) | |
1569 (setq query-flag nil multi-buffer t)) | |
1550 | 1570 |
1551 ;; REPLACEMENTS is either a string, a list of strings, or a cons cell | 1571 ;; REPLACEMENTS is either a string, a list of strings, or a cons cell |
1552 ;; containing a function and its first argument. The function is | 1572 ;; containing a function and its first argument. The function is |
1553 ;; called to generate each replacement like this: | 1573 ;; called to generate each replacement like this: |
1554 ;; (funcall (car replacements) (cdr replacements) replace-count) | 1574 ;; (funcall (car replacements) (cdr replacements) replace-count) |
1703 (with-current-buffer standard-output | 1723 (with-current-buffer standard-output |
1704 (help-mode)))) | 1724 (help-mode)))) |
1705 ((eq def 'exit) | 1725 ((eq def 'exit) |
1706 (setq keep-going nil) | 1726 (setq keep-going nil) |
1707 (setq done t)) | 1727 (setq done t)) |
1728 ((eq def 'exit-current) | |
1729 (setq multi-buffer t keep-going nil done t)) | |
1708 ((eq def 'backup) | 1730 ((eq def 'backup) |
1709 (if stack | 1731 (if stack |
1710 (let ((elt (pop stack))) | 1732 (let ((elt (pop stack))) |
1711 (goto-char (nth 0 elt)) | 1733 (goto-char (nth 0 elt)) |
1712 (setq replaced (nth 1 elt) | 1734 (setq replaced (nth 1 elt) |
1742 noedit real-match-data) | 1764 noedit real-match-data) |
1743 replace-count (1+ replace-count) | 1765 replace-count (1+ replace-count) |
1744 real-match-data (replace-match-data | 1766 real-match-data (replace-match-data |
1745 t real-match-data) | 1767 t real-match-data) |
1746 replaced t))) | 1768 replaced t))) |
1747 ((eq def 'automatic) | 1769 ((or (eq def 'automatic) (eq def 'automatic-all)) |
1748 (or replaced | 1770 (or replaced |
1749 (setq noedit | 1771 (setq noedit |
1750 (replace-match-maybe-edit | 1772 (replace-match-maybe-edit |
1751 next-replacement nocasify literal | 1773 next-replacement nocasify literal |
1752 noedit real-match-data) | 1774 noedit real-match-data) |
1753 replace-count (1+ replace-count))) | 1775 replace-count (1+ replace-count))) |
1754 (setq done t query-flag nil replaced t)) | 1776 (setq done t query-flag nil replaced t) |
1777 (if (eq def 'automatic-all) (setq multi-buffer t))) | |
1755 ((eq def 'skip) | 1778 ((eq def 'skip) |
1756 (setq done t)) | 1779 (setq done t)) |
1757 ((eq def 'recenter) | 1780 ((eq def 'recenter) |
1758 (recenter nil)) | 1781 (recenter nil)) |
1759 ((eq def 'edit) | 1782 ((eq def 'edit) |
1836 (replace-dehighlight)) | 1859 (replace-dehighlight)) |
1837 (or unread-command-events | 1860 (or unread-command-events |
1838 (message "Replaced %d occurrence%s" | 1861 (message "Replaced %d occurrence%s" |
1839 replace-count | 1862 replace-count |
1840 (if (= replace-count 1) "" "s"))) | 1863 (if (= replace-count 1) "" "s"))) |
1841 (and keep-going stack))) | 1864 (or (and keep-going stack) multi-buffer))) |
1842 | 1865 |
1843 (defvar replace-overlay nil) | 1866 (defvar replace-overlay nil) |
1844 | 1867 |
1845 (defun replace-highlight (match-beg match-end range-beg range-end | 1868 (defun replace-highlight (match-beg match-end range-beg range-end |
1846 string regexp case-fold) | 1869 string regexp case-fold) |