GNU bug report logs - #32543
26.1; list-matching-lines-jump-to-current breaks revert-buffer in occur-mode

Previous Next

Package: emacs;

Reported by: Andrey Kolomoets <andreyk.mad <at> gmail.com>

Date: Mon, 27 Aug 2018 14:52:03 UTC

Severity: normal

Found in version 26.1

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32543 in the body.
You can then email your comments to 32543 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#32543; Package emacs. (Mon, 27 Aug 2018 14:52:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Andrey Kolomoets <andreyk.mad <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 27 Aug 2018 14:52:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andrey Kolomoets <andreyk.mad <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; list-matching-lines-jump-to-current breaks revert-buffer in
 occur-mode
Date: Mon, 27 Aug 2018 14:49:41 +0300
0. emacs -Q
1. M-: (setq list-matching-lines-jump-to-current-line t) <RET>
2. M-s o text <RET>
3. C-x o
4. g

(wrong-type-argument number-or-marker-p nil)
  occur-engine("text" (#<buffer *scratch*>) #<buffer *Occur*> 0 t underline shadow match t)
  occur-1("text" nil (#<buffer *scratch*>) "*Occur*")
  apply(occur-1 ("text" nil (#<buffer *scratch*>) "*Occur*"))
  occur-revert-function(t nil)
  revert-buffer(t)
  funcall-interactively(revert-buffer t)
  call-interactively(revert-buffer nil nil)
  command-execute(revert-buffer)

I think it's because occur--orig-line not initialized in occur-revert-function and it fails on

(when (and list-matching-lines-jump-to-current-line
 (null orig-line-shown-p)
 (> curr-line orig-line))


In GNU Emacs 26.1 and still in 27.0.50




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32543; Package emacs. (Sat, 01 Sep 2018 22:51:02 GMT) Full text and rfc822 format available.

Message #8 received at 32543 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Andrey Kolomoets <andreyk.mad <at> gmail.com>
Cc: 32543 <at> debbugs.gnu.org, tino.calancha <at> gmail.com
Subject: Re: bug#32543: 26.1;
 list-matching-lines-jump-to-current breaks revert-buffer in occur-mode
Date: Sun, 02 Sep 2018 01:49:08 +0300
> 0. emacs -Q
> 1. M-: (setq list-matching-lines-jump-to-current-line t) <RET>
> 2. M-s o text <RET>
> 3. C-x o
> 4. g
>
> (wrong-type-argument number-or-marker-p nil)
>   occur-engine("text" (#<buffer *scratch*>) #<buffer *Occur*> 0 t underline shadow match t)
>   occur-1("text" nil (#<buffer *scratch*>) "*Occur*")
>   apply(occur-1 ("text" nil (#<buffer *scratch*>) "*Occur*"))
>   occur-revert-function(t nil)
>   revert-buffer(t)
>   funcall-interactively(revert-buffer t)
>   call-interactively(revert-buffer nil nil)
>   command-execute(revert-buffer)
>
> I think it's because occur--orig-line not initialized in occur-revert-function and it fails on
>
> (when (and list-matching-lines-jump-to-current-line
>  (null orig-line-shown-p)
>  (> curr-line orig-line))

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).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32543; Package emacs. (Mon, 03 Sep 2018 12:35:02 GMT) Full text and rfc822 format available.

Message #11 received at 32543 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 32543 <at> debbugs.gnu.org, Andrey Kolomoets <andreyk.mad <at> gmail.com>
Subject: Re: 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
Juri Linkov <juri <at> 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 <at> 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)))))))
 
 
+(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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32543; Package emacs. (Mon, 03 Sep 2018 22:46:03 GMT) Full text and rfc822 format available.

Message #14 received at 32543 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 32543 <at> debbugs.gnu.org, Andrey Kolomoets <andreyk.mad <at> gmail.com>
Subject: Re: bug#32543: 26.1;
 list-matching-lines-jump-to-current breaks revert-buffer in occur-mode
Date: Tue, 04 Sep 2018 01:41:29 +0300
> How about we store such info in the *Occur* header line as text
> properties?
> Then we don't need to modify `occur-revert-arguments'.

I agree it's one of legitimate places to store information about the buffer.

> +    (let* ((region (occur--parse-occur-buffer))
> +           (region-start (car region))
> +           (region-end (cadr region))
> +           (orig-line (caddr region))
> +           (buffer (cadddr region))

Better to use (nth 1), (nth 2), (nth 3), ...




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32543; Package emacs. (Thu, 06 Sep 2018 10:56:02 GMT) Full text and rfc822 format available.

Message #17 received at 32543 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 32543 <at> debbugs.gnu.org, Andrey Kolomoets <andreyk.mad <at> gmail.com>
Subject: Re: bug#32543: 26.1;
 list-matching-lines-jump-to-current breaks revert-buffer in occur-mode
Date: Thu, 06 Sep 2018 19:55:41 +0900
Juri Linkov <juri <at> linkov.net> writes:

>> +    (let* ((region (occur--parse-occur-buffer))
>> +           (region-start (car region))
>> +           (region-end (cadr region))
>> +           (orig-line (caddr region))
>> +           (buffer (cadddr region))
>
> Better to use (nth 1), (nth 2), (nth 3), ...
Yeah, it reads better.
Here is the updated patch:
--8<-----------------------------cut here---------------start------------->8---
commit 88588f772a82397e8c60e0e066507b3d67b72848
Author: Tino Calancha <tino.calancha <at> gmail.com>
Date:   Thu Sep 6 19:48:18 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..093993a3b6 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1206,9 +1206,38 @@ occur-after-change-function
 	    (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 @@ 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-06
Repository revision: bca35315e16cb53415649e5c0ac2ec0cc1368679




Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Tue, 18 Sep 2018 12:35:02 GMT) Full text and rfc822 format available.

Notification sent to Andrey Kolomoets <andreyk.mad <at> gmail.com>:
bug acknowledged by developer. (Tue, 18 Sep 2018 12:35:02 GMT) Full text and rfc822 format available.

Message #22 received at 32543-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 32543-done <at> debbugs.gnu.org
Subject: Re: bug#32543: 26.1;
 list-matching-lines-jump-to-current breaks revert-buffer in occur-mode
Date: Tue, 18 Sep 2018 21:33:47 +0900
Tino Calancha <tino.calancha <at> gmail.com> writes:

> Juri Linkov <juri <at> linkov.net> writes:
>
>>> +    (let* ((region (occur--parse-occur-buffer))
>>> +           (region-start (car region))
>>> +           (region-end (cadr region))
>>> +           (orig-line (caddr region))
>>> +           (buffer (cadddr region))
>>
>> Better to use (nth 1), (nth 2), (nth 3), ...
> Yeah, it reads better.
> Here is the updated patch:
Fixed in master branch as commit 'Fix bug 32543'
(75d9a55fae1c484aa6d213064931bfe3b65cf5dd)




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 17 Oct 2018 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 329 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.