aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorTino Calancha2018-09-18 21:29:59 +0900
committerTino Calancha2018-09-18 21:29:59 +0900
commit75d9a55fae1c484aa6d213064931bfe3b65cf5dd (patch)
tree897dc16b3a037d58185ccee6f18b87a16d9bb8d7 /lisp/replace.el
parent458948189e56a110739ff9002236d269b8382293 (diff)
downloademacs-75d9a55fae1c484aa6d213064931bfe3b65cf5dd.tar.gz
emacs-75d9a55fae1c484aa6d213064931bfe3b65cf5dd.zip
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]."
1206 (move-to-column col))))))) 1206 (move-to-column col)))))))
1207 1207
1208 1208
1209(defun occur--parse-occur-buffer()
1210 "Retrieve a list of the form (BEG END ORIG-LINE BUFFER).
1211BEG and END define the region.
1212ORIG-LINE and BUFFER are the line and the buffer from which
1213the user called `occur'."
1214 (save-excursion
1215 (goto-char (point-min))
1216 (let ((buffer (get-text-property (point-at-bol) 'occur-title))
1217 (beg-pos (get-text-property (point-at-bol) 'region-start))
1218 (end-pos (get-text-property (point-at-bol) 'region-end))
1219 (orig-line (get-text-property (point-at-bol) 'current-line))
1220 beg-line end-line)
1221 (list beg-pos end-pos orig-line buffer))))
1222
1209(defun occur-revert-function (_ignore1 _ignore2) 1223(defun occur-revert-function (_ignore1 _ignore2)
1210 "Handle `revert-buffer' for Occur mode buffers." 1224 "Handle `revert-buffer' for Occur mode buffers."
1211 (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))) 1225 (if (cdr (nth 2 occur-revert-arguments)) ; multi-occur
1226 (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))
1227 (let* ((region (occur--parse-occur-buffer))
1228 (region-start (nth 0 region))
1229 (region-end (nth 1 region))
1230 (orig-line (nth 2 region))
1231 (buffer (nth 3 region))
1232 (regexp (car occur-revert-arguments)))
1233 (with-current-buffer buffer
1234 (when (wholenump orig-line)
1235 (goto-char 1)
1236 (forward-line (1- orig-line)))
1237 (save-excursion
1238 (if region
1239 (occur regexp nil (list (cons region-start region-end)))
1240 (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))))))))
1212 1241
1213(defun occur-mode-find-occurrence () 1242(defun occur-mode-find-occurrence ()
1214 (let ((pos (get-text-property (point) 'occur-target))) 1243 (let ((pos (get-text-property (point) 'occur-target)))
@@ -1651,7 +1680,7 @@ See also `multi-occur'."
1651 (matches 0) ;; count of matches 1680 (matches 0) ;; count of matches
1652 (curr-line ;; line count 1681 (curr-line ;; line count
1653 (or occur--region-start-line 1)) 1682 (or occur--region-start-line 1))
1654 (orig-line occur--orig-line) 1683 (orig-line (or occur--orig-line 1))
1655 (orig-line-shown-p) 1684 (orig-line-shown-p)
1656 (prev-line nil) ;; line number of prev match endpt 1685 (prev-line nil) ;; line number of prev match endpt
1657 (prev-after-lines nil) ;; context lines of prev match 1686 (prev-after-lines nil) ;; context lines of prev match
@@ -1701,6 +1730,8 @@ See also `multi-occur'."
1701 (setq matches (1+ matches))) 1730 (setq matches (1+ matches)))
1702 (when (and list-matching-lines-jump-to-current-line 1731 (when (and list-matching-lines-jump-to-current-line
1703 (not multi-occur-p)) 1732 (not multi-occur-p))
1733 (or orig-line (setq orig-line 1))
1734 (or nlines (setq nlines (line-number-at-pos (point-max))))
1704 (when (= curr-line orig-line) 1735 (when (= curr-line orig-line)
1705 (add-face-text-property 1736 (add-face-text-property
1706 0 len list-matching-lines-current-line-face nil curstring) 1737 0 len list-matching-lines-current-line-face nil curstring)
@@ -1859,7 +1890,9 @@ See also `multi-occur'."
1859 "")) 1890 ""))
1860 'read-only t)) 1891 'read-only t))
1861 (setq end (point)) 1892 (setq end (point))
1862 (add-text-properties beg end `(occur-title ,buf)) 1893 (add-text-properties beg end `(occur-title ,buf current-line ,orig-line
1894 region-start ,occur--region-start
1895 region-end ,occur--region-end))
1863 (when title-face 1896 (when title-face
1864 (add-face-text-property beg end title-face)) 1897 (add-face-text-property beg end title-face))
1865 (goto-char (if (and list-matching-lines-jump-to-current-line 1898 (goto-char (if (and list-matching-lines-jump-to-current-line