summaryrefslogtreecommitdiff
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2018-09-18 21:29:59 +0900
committerTino Calancha <tino.calancha@gmail.com>2018-09-18 21:29:59 +0900
commit75d9a55fae1c484aa6d213064931bfe3b65cf5dd (patch)
tree897dc16b3a037d58185ccee6f18b87a16d9bb8d7 /lisp/replace.el
parent458948189e56a110739ff9002236d269b8382293 (diff)
downloademacs-75d9a55fae1c484aa6d213064931bfe3b65cf5dd.tar.gz
Fix bug 32543
Store the region and orig line into the *Occur* header line. Retrieve this information in `occur-revert-function'. * lisp/replace.el (occur--parse-occur-buffer): New defun. (occur-revert-function): Use it. (occur-engine): Store region and original position as text properties into the *Occur* header line. * lisp/replace.el (occur-engine): Add sensible default values for (occur--orig-line and nlines.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el39
1 files changed, 36 insertions, 3 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 20b868a765c..eb65c7a82d4 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1206,9 +1206,38 @@ To return to ordinary Occur mode, use \\[occur-cease-edit]."
(move-to-column col)))))))
+(defun occur--parse-occur-buffer()
+ "Retrieve a list of the form (BEG END ORIG-LINE BUFFER).
+BEG and END define the region.
+ORIG-LINE and BUFFER are the line and the buffer from which
+the user called `occur'."
+ (save-excursion
+ (goto-char (point-min))
+ (let ((buffer (get-text-property (point-at-bol) 'occur-title))
+ (beg-pos (get-text-property (point-at-bol) 'region-start))
+ (end-pos (get-text-property (point-at-bol) 'region-end))
+ (orig-line (get-text-property (point-at-bol) 'current-line))
+ beg-line end-line)
+ (list beg-pos end-pos orig-line buffer))))
+
(defun occur-revert-function (_ignore1 _ignore2)
"Handle `revert-buffer' for Occur mode buffers."
- (apply 'occur-1 (append occur-revert-arguments (list (buffer-name)))))
+ (if (cdr (nth 2 occur-revert-arguments)) ; multi-occur
+ (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))
+ (let* ((region (occur--parse-occur-buffer))
+ (region-start (nth 0 region))
+ (region-end (nth 1 region))
+ (orig-line (nth 2 region))
+ (buffer (nth 3 region))
+ (regexp (car occur-revert-arguments)))
+ (with-current-buffer buffer
+ (when (wholenump orig-line)
+ (goto-char 1)
+ (forward-line (1- orig-line)))
+ (save-excursion
+ (if region
+ (occur regexp nil (list (cons region-start region-end)))
+ (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))))))))
(defun occur-mode-find-occurrence ()
(let ((pos (get-text-property (point) 'occur-target)))
@@ -1651,7 +1680,7 @@ See also `multi-occur'."
(matches 0) ;; count of matches
(curr-line ;; line count
(or occur--region-start-line 1))
- (orig-line occur--orig-line)
+ (orig-line (or occur--orig-line 1))
(orig-line-shown-p)
(prev-line nil) ;; line number of prev match endpt
(prev-after-lines nil) ;; context lines of prev match
@@ -1701,6 +1730,8 @@ See also `multi-occur'."
(setq matches (1+ matches)))
(when (and list-matching-lines-jump-to-current-line
(not multi-occur-p))
+ (or orig-line (setq orig-line 1))
+ (or nlines (setq nlines (line-number-at-pos (point-max))))
(when (= curr-line orig-line)
(add-face-text-property
0 len list-matching-lines-current-line-face nil curstring)
@@ -1859,7 +1890,9 @@ See also `multi-occur'."
""))
'read-only t))
(setq end (point))
- (add-text-properties beg end `(occur-title ,buf))
+ (add-text-properties beg end `(occur-title ,buf current-line ,orig-line
+ region-start ,occur--region-start
+ region-end ,occur--region-end))
(when title-face
(add-face-text-property beg end title-face))
(goto-char (if (and list-matching-lines-jump-to-current-line