unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: 32543@debbugs.gnu.org, Andrey Kolomoets <andreyk.mad@gmail.com>
Subject: bug#32543: 26.1; list-matching-lines-jump-to-current breaks revert-buffer in occur-mode
Date: Mon, 03 Sep 2018 21:34:15 +0900	[thread overview]
Message-ID: <87o9deahfc.fsf@calancha-pc.dy.bbexcite.jp> (raw)
In-Reply-To: <87d0tw96l7.fsf@mail.linkov.net> (Juri Linkov's message of "Sun,  02 Sep 2018 01:49:08 +0300")

Juri Linkov <juri@linkov.net> writes:

> We have two solutions here: on reverting reset the current line number to
> the default numeric value of occur--orig-line (e.g. 0), or better to
> remember occur--orig-line in occur-revert-arguments.  Maybe Tino has
> better ideas (Cc'ed).
How about we store such info in the *Occur* header line as text
properties?
Then we don't need to modify `occur-revert-arguments'.
Following patch implement this way:
--8<-----------------------------cut here---------------start------------->8---
commit 8fbe516c404a8993c1fc22cdf75e4c553ec1f1a8
Author: Tino Calancha <tino.calancha@gmail.com>
Date:   Mon Sep 3 21:24:38 2018 +0900

    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.

diff --git a/lisp/replace.el b/lisp/replace.el
index 20b868a765..638ad3b368 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1206,9 +1206,38 @@ occur-after-change-function
 	    (move-to-column col)))))))
 
 \f
+(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 (car region))
+           (region-end (cadr region))
+           (orig-line (caddr region))
+           (buffer (cadddr 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 @@ occur-engine
 		(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 @@ occur-engine
 			  (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 @@ occur-engine
 				       ""))
 			     '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

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2018-09-03
Repository revision: db2fed3bdfb351c3283e481829ce687931d27a3d





  reply	other threads:[~2018-09-03 12:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-27 11:49 bug#32543: 26.1; list-matching-lines-jump-to-current breaks revert-buffer in occur-mode Andrey Kolomoets
2018-09-01 22:49 ` Juri Linkov
2018-09-03 12:34   ` Tino Calancha [this message]
2018-09-03 22:41     ` Juri Linkov
2018-09-06 10:55       ` Tino Calancha
2018-09-18 12:33         ` Tino Calancha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o9deahfc.fsf@calancha-pc.dy.bbexcite.jp \
    --to=tino.calancha@gmail.com \
    --cc=32543@debbugs.gnu.org \
    --cc=andreyk.mad@gmail.com \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).