diff options
| author | Stefan Monnier | 2018-10-09 11:57:22 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2018-10-09 11:57:22 -0400 |
| commit | bd013a448b152a84cff9b18292d8272faf265447 (patch) | |
| tree | eb3917b1b93b20522cff3b251b73231af6629084 /lisp/replace.el | |
| parent | 262f5c809913a232a931131d040964cbdf4ac6f9 (diff) | |
| download | emacs-bd013a448b152a84cff9b18292d8272faf265447.tar.gz emacs-bd013a448b152a84cff9b18292d8272faf265447.zip | |
* lisp/replace.el (occur--garbage-collect-revert-args): New function
(occur-mode, occur-1): Use it.
(occur--region-start, occur--region-end, occur--region-start-line)
(occur--orig-line): Remove vars.
(occur-engine): Fix left over use of occur--region-start-line.
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index a134e4e3e58..ecb47936e7b 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -1121,6 +1121,11 @@ for this is to reveal context in an outline-mode when the occurrence is hidden." | |||
| 1121 | :type 'hook | 1121 | :type 'hook |
| 1122 | :group 'matching) | 1122 | :group 'matching) |
| 1123 | 1123 | ||
| 1124 | (defun occur--garbage-collect-revert-args () | ||
| 1125 | (dolist (boo (nth 2 occur-revert-arguments)) | ||
| 1126 | (when (overlayp boo) (delete-overlay boo))) | ||
| 1127 | (kill-local-variable 'occur-revert-arguments)) | ||
| 1128 | |||
| 1124 | (put 'occur-mode 'mode-class 'special) | 1129 | (put 'occur-mode 'mode-class 'special) |
| 1125 | (define-derived-mode occur-mode special-mode "Occur" | 1130 | (define-derived-mode occur-mode special-mode "Occur" |
| 1126 | "Major mode for output from \\[occur]. | 1131 | "Major mode for output from \\[occur]. |
| @@ -1130,6 +1135,7 @@ Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it. | |||
| 1130 | 1135 | ||
| 1131 | \\{occur-mode-map}" | 1136 | \\{occur-mode-map}" |
| 1132 | (setq-local revert-buffer-function #'occur-revert-function) | 1137 | (setq-local revert-buffer-function #'occur-revert-function) |
| 1138 | (add-hook 'kill-buffer-hook #'occur--garbage-collect-revert-args nil t) | ||
| 1133 | (setq next-error-function #'occur-next-error)) | 1139 | (setq next-error-function #'occur-next-error)) |
| 1134 | 1140 | ||
| 1135 | 1141 | ||
| @@ -1411,10 +1417,6 @@ invoke `occur'." | |||
| 1411 | (or unique-p (not interactive-p))))) | 1417 | (or unique-p (not interactive-p))))) |
| 1412 | 1418 | ||
| 1413 | ;; Region limits when `occur' applies on a region. | 1419 | ;; Region limits when `occur' applies on a region. |
| 1414 | (defvar occur--region-start nil) | ||
| 1415 | (defvar occur--region-end nil) | ||
| 1416 | (defvar occur--region-start-line nil) | ||
| 1417 | (defvar occur--orig-line nil) | ||
| 1418 | (defvar occur--final-pos nil) | 1420 | (defvar occur--final-pos nil) |
| 1419 | 1421 | ||
| 1420 | (defun occur (regexp &optional nlines region) | 1422 | (defun occur (regexp &optional nlines region) |
| @@ -1624,6 +1626,7 @@ See also `multi-occur'." | |||
| 1624 | 42) | 1626 | 42) |
| 1625 | (window-width)) | 1627 | (window-width)) |
| 1626 | "" (occur-regexp-descr regexp)))) | 1628 | "" (occur-regexp-descr regexp)))) |
| 1629 | (occur--garbage-collect-revert-args) | ||
| 1627 | (setq occur-revert-arguments (list regexp nlines bufs)) | 1630 | (setq occur-revert-arguments (list regexp nlines bufs)) |
| 1628 | (if (= count 0) | 1631 | (if (= count 0) |
| 1629 | (kill-buffer occur-buf) | 1632 | (kill-buffer occur-buf) |
| @@ -1659,26 +1662,27 @@ See also `multi-occur'." | |||
| 1659 | ;; begin searching in the buffer | 1662 | ;; begin searching in the buffer |
| 1660 | (goto-char (if (overlayp boo) (overlay-start boo) (point-min))) | 1663 | (goto-char (if (overlayp boo) (overlay-start boo) (point-min))) |
| 1661 | (forward-line 0) | 1664 | (forward-line 0) |
| 1662 | (let ((limit (if (overlayp boo) (overlay-end boo) (point-max))) | 1665 | (let* ((limit (if (overlayp boo) (overlay-end boo) (point-max))) |
| 1663 | (curr-line (line-number-at-pos)) ; line count | 1666 | (start-line (line-number-at-pos)) |
| 1664 | (orig-line (if (not (overlayp boo)) 1 | 1667 | (curr-line start-line) ; line count |
| 1665 | (line-number-at-pos | 1668 | (orig-line (if (not (overlayp boo)) 1 |
| 1666 | (overlay-get boo 'occur--orig-point)))) | 1669 | (line-number-at-pos |
| 1667 | (orig-line-shown-p) | 1670 | (overlay-get boo 'occur--orig-point)))) |
| 1668 | (prev-line nil) ; line number of prev match endpt | 1671 | (orig-line-shown-p) |
| 1669 | (prev-after-lines nil) ; context lines of prev match | 1672 | (prev-line nil) ; line number of prev match endpt |
| 1670 | (matchbeg 0) | 1673 | (prev-after-lines nil) ; context lines of prev match |
| 1671 | (origpt nil) | 1674 | (matchbeg 0) |
| 1672 | (begpt nil) | 1675 | (origpt nil) |
| 1673 | (endpt nil) | 1676 | (begpt nil) |
| 1674 | (marker nil) | 1677 | (endpt nil) |
| 1675 | (curstring "") | 1678 | (marker nil) |
| 1676 | (ret nil) | 1679 | (curstring "") |
| 1677 | ;; The following binding is for when case-fold-search | 1680 | (ret nil) |
| 1678 | ;; has a local binding in the original buffer, in which | 1681 | ;; The following binding is for when case-fold-search |
| 1679 | ;; case we cannot bind it globally and let that have | 1682 | ;; has a local binding in the original buffer, in which |
| 1680 | ;; effect in every buffer we search. | 1683 | ;; case we cannot bind it globally and let that have |
| 1681 | (case-fold-search case-fold)) | 1684 | ;; effect in every buffer we search. |
| 1685 | (case-fold-search case-fold)) | ||
| 1682 | (or coding | 1686 | (or coding |
| 1683 | ;; Set CODING only if the current buffer locally | 1687 | ;; Set CODING only if the current buffer locally |
| 1684 | ;; binds buffer-file-coding-system. | 1688 | ;; binds buffer-file-coding-system. |
| @@ -1792,7 +1796,7 @@ See also `multi-occur'." | |||
| 1792 | (setq orig-line-shown-p t) | 1796 | (setq orig-line-shown-p t) |
| 1793 | (save-excursion | 1797 | (save-excursion |
| 1794 | (goto-char (point-min)) | 1798 | (goto-char (point-min)) |
| 1795 | (forward-line (- orig-line (or occur--region-start-line 1))) | 1799 | (forward-line (- orig-line start-line 1)) |
| 1796 | (occur-engine-line (line-beginning-position) | 1800 | (occur-engine-line (line-beginning-position) |
| 1797 | (line-end-position) keep-props))))) | 1801 | (line-end-position) keep-props))))) |
| 1798 | ;; Actually insert the match display data | 1802 | ;; Actually insert the match display data |
| @@ -1830,7 +1834,7 @@ See also `multi-occur'." | |||
| 1830 | (let ((orig-line-str | 1834 | (let ((orig-line-str |
| 1831 | (save-excursion | 1835 | (save-excursion |
| 1832 | (goto-char (point-min)) | 1836 | (goto-char (point-min)) |
| 1833 | (forward-line (- orig-line (or occur--region-start-line 1))) | 1837 | (forward-line (- orig-line start-line 1)) |
| 1834 | (occur-engine-line (line-beginning-position) | 1838 | (occur-engine-line (line-beginning-position) |
| 1835 | (line-end-position) keep-props)))) | 1839 | (line-end-position) keep-props)))) |
| 1836 | (add-face-text-property | 1840 | (add-face-text-property |