diff options
| author | Juri Linkov | 2018-02-06 23:20:10 +0200 |
|---|---|---|
| committer | Juri Linkov | 2018-02-06 23:20:10 +0200 |
| commit | 31350817ae6eda2e071dbc28f1f1edc50e5f3b0c (patch) | |
| tree | 60bc5152558543048b7dc6446ca27a13b7091926 | |
| parent | 5c414441ed73f1a302a2953dc493e83b98589262 (diff) | |
| download | emacs-31350817ae6eda2e071dbc28f1f1edc50e5f3b0c.tar.gz emacs-31350817ae6eda2e071dbc28f1f1edc50e5f3b0c.zip | |
Support occur command operating on the region from Isearch.
* lisp/isearch.el (isearch-occur): Use region-bounds as region arg of occur.
(isearch-query-replace): Use use-region-p.
* lisp/replace.el (occur--region-start-line): Rename from
occur--matches-threshold.
(occur): Use complete lines when region is active for line-oriented occur.
(occur-engine): Count lines either from occur--region-start-line or 1.
| -rw-r--r-- | lisp/isearch.el | 9 | ||||
| -rw-r--r-- | lisp/replace.el | 14 |
2 files changed, 13 insertions, 10 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el index 9297c0f95ba..729f629423c 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -1853,11 +1853,11 @@ replacements from Isearch is `M-s w ... M-%'." | |||
| 1853 | (concat "Query replace" | 1853 | (concat "Query replace" |
| 1854 | (isearch--describe-regexp-mode (or delimited isearch-regexp-function) t) | 1854 | (isearch--describe-regexp-mode (or delimited isearch-regexp-function) t) |
| 1855 | (if backward " backward" "") | 1855 | (if backward " backward" "") |
| 1856 | (if (and transient-mark-mode mark-active) " in region" "")) | 1856 | (if (use-region-p) " in region" "")) |
| 1857 | isearch-regexp) | 1857 | isearch-regexp) |
| 1858 | t isearch-regexp (or delimited isearch-regexp-function) nil nil | 1858 | t isearch-regexp (or delimited isearch-regexp-function) nil nil |
| 1859 | (if (and transient-mark-mode mark-active) (region-beginning)) | 1859 | (if (use-region-p) (region-beginning)) |
| 1860 | (if (and transient-mark-mode mark-active) (region-end)) | 1860 | (if (use-region-p) (region-end)) |
| 1861 | backward)) | 1861 | backward)) |
| 1862 | (and isearch-recursive-edit (exit-recursive-edit))) | 1862 | (and isearch-recursive-edit (exit-recursive-edit))) |
| 1863 | 1863 | ||
| @@ -1920,7 +1920,8 @@ characters in that string." | |||
| 1920 | 'isearch-regexp-function-descr | 1920 | 'isearch-regexp-function-descr |
| 1921 | (isearch--describe-regexp-mode isearch-regexp-function)) | 1921 | (isearch--describe-regexp-mode isearch-regexp-function)) |
| 1922 | regexp) | 1922 | regexp) |
| 1923 | nlines))) | 1923 | nlines |
| 1924 | (if (use-region-p) (region-bounds))))) | ||
| 1924 | 1925 | ||
| 1925 | (declare-function hi-lock-read-face-name "hi-lock" ()) | 1926 | (declare-function hi-lock-read-face-name "hi-lock" ()) |
| 1926 | 1927 | ||
diff --git a/lisp/replace.el b/lisp/replace.el index 0efd0820966..c6892328d71 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -1387,7 +1387,7 @@ invoke `occur'." | |||
| 1387 | ;; Region limits when `occur' applies on a region. | 1387 | ;; Region limits when `occur' applies on a region. |
| 1388 | (defvar occur--region-start nil) | 1388 | (defvar occur--region-start nil) |
| 1389 | (defvar occur--region-end nil) | 1389 | (defvar occur--region-end nil) |
| 1390 | (defvar occur--matches-threshold nil) | 1390 | (defvar occur--region-start-line nil) |
| 1391 | (defvar occur--orig-line nil) | 1391 | (defvar occur--orig-line nil) |
| 1392 | (defvar occur--final-pos nil) | 1392 | (defvar occur--final-pos nil) |
| 1393 | 1393 | ||
| @@ -1441,13 +1441,15 @@ is not modified." | |||
| 1441 | (or end (setq end (point-max)))) | 1441 | (or end (setq end (point-max)))) |
| 1442 | (let ((occur--region-start start) | 1442 | (let ((occur--region-start start) |
| 1443 | (occur--region-end end) | 1443 | (occur--region-end end) |
| 1444 | (occur--matches-threshold | 1444 | (occur--region-start-line |
| 1445 | (and in-region-p | 1445 | (and in-region-p |
| 1446 | (line-number-at-pos (min start end)))) | 1446 | (line-number-at-pos (min start end)))) |
| 1447 | (occur--orig-line | 1447 | (occur--orig-line |
| 1448 | (line-number-at-pos (point)))) | 1448 | (line-number-at-pos (point)))) |
| 1449 | (save-excursion ; If no matches `occur-1' doesn't restore the point. | 1449 | (save-excursion ; If no matches `occur-1' doesn't restore the point. |
| 1450 | (and in-region-p (narrow-to-region start end)) | 1450 | (and in-region-p (narrow-to-region |
| 1451 | (save-excursion (goto-char start) (line-beginning-position)) | ||
| 1452 | (save-excursion (goto-char end) (line-end-position)))) | ||
| 1451 | (occur-1 regexp nlines (list (current-buffer))) | 1453 | (occur-1 regexp nlines (list (current-buffer))) |
| 1452 | (and in-region-p (widen)))))) | 1454 | (and in-region-p (widen)))))) |
| 1453 | 1455 | ||
| @@ -1621,7 +1623,7 @@ See also `multi-occur'." | |||
| 1621 | (let ((lines 0) ;; count of matching lines | 1623 | (let ((lines 0) ;; count of matching lines |
| 1622 | (matches 0) ;; count of matches | 1624 | (matches 0) ;; count of matches |
| 1623 | (curr-line ;; line count | 1625 | (curr-line ;; line count |
| 1624 | (or occur--matches-threshold 1)) | 1626 | (or occur--region-start-line 1)) |
| 1625 | (orig-line occur--orig-line) | 1627 | (orig-line occur--orig-line) |
| 1626 | (orig-line-shown-p) | 1628 | (orig-line-shown-p) |
| 1627 | (prev-line nil) ;; line number of prev match endpt | 1629 | (prev-line nil) ;; line number of prev match endpt |
| @@ -1754,7 +1756,7 @@ See also `multi-occur'." | |||
| 1754 | (setq orig-line-shown-p t) | 1756 | (setq orig-line-shown-p t) |
| 1755 | (save-excursion | 1757 | (save-excursion |
| 1756 | (goto-char (point-min)) | 1758 | (goto-char (point-min)) |
| 1757 | (forward-line (1- orig-line)) | 1759 | (forward-line (- orig-line (or occur--region-start-line 1))) |
| 1758 | (occur-engine-line (line-beginning-position) | 1760 | (occur-engine-line (line-beginning-position) |
| 1759 | (line-end-position) keep-props))))) | 1761 | (line-end-position) keep-props))))) |
| 1760 | ;; Actually insert the match display data | 1762 | ;; Actually insert the match display data |
| @@ -1792,7 +1794,7 @@ See also `multi-occur'." | |||
| 1792 | (let ((orig-line-str | 1794 | (let ((orig-line-str |
| 1793 | (save-excursion | 1795 | (save-excursion |
| 1794 | (goto-char (point-min)) | 1796 | (goto-char (point-min)) |
| 1795 | (forward-line (1- orig-line)) | 1797 | (forward-line (- orig-line (or occur--region-start-line 1))) |
| 1796 | (occur-engine-line (line-beginning-position) | 1798 | (occur-engine-line (line-beginning-position) |
| 1797 | (line-end-position) keep-props)))) | 1799 | (line-end-position) keep-props)))) |
| 1798 | (add-face-text-property | 1800 | (add-face-text-property |