all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working
@ 2022-01-03 16:48 Stefan Kangas
  2022-01-03 18:40 ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2022-01-03 16:48 UTC (permalink / raw)
  To: 52980

On current master:

 0. emacs -Q lisp/help.el
        ;; Any file where the header would normally be elided
 1. M-x elide-head RET
 2. M-x revert-buffer RET
 3. M-: elide-head-overlay RET  => nil
        ;; Note that the overlay is still in the buffer though.
 4. M-x elide-head RET
        ;; A second overlay is added.
 5. M-x elide-head-show RET

Now I see no license, as only the second overlay is removed.

Note that the above sequence of commands should be equivalent to what
happens when you revert the buffer if you have added `elide-head' to a
major mode hook, as in:

  (add-hook 'prog-mode-hook 'elide-head)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working
  2022-01-03 16:48 bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working Stefan Kangas
@ 2022-01-03 18:40 ` Stefan Kangas
  2022-01-04  8:15   ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2022-01-03 18:40 UTC (permalink / raw)
  To: 52980

Stefan Kangas <stefan@marxist.se> writes:

>  0. emacs -Q lisp/help.el
>         ;; Any file where the header would normally be elided
>  1. M-x elide-head RET
>  2. M-x revert-buffer RET
>  3. M-: elide-head-overlay RET  => nil
>         ;; Note that the overlay is still in the buffer though.
>  4. M-x elide-head RET
>         ;; A second overlay is added.
>  5. M-x elide-head-show RET
>
> Now I see no license, as only the second overlay is removed.

I started looking into a solution with {before,after}-revert-hook, but
that just seems duplicate what we would get from just using a minor
mode.  So I'm starting to think that `elide-head' and `elide-head-show'
should be obsoleted in favor of a new local minor mode
`elide-head-mode'.

That would also save me from having to add a third command
`elide-head-toggle' to toggle the hiding on or off.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working
  2022-01-03 18:40 ` Stefan Kangas
@ 2022-01-04  8:15   ` Stefan Kangas
  2022-01-04 17:08     ` jakanakaevangeli
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2022-01-04  8:15 UTC (permalink / raw)
  To: 52980

[-- Attachment #1: Type: text/plain, Size: 499 bytes --]

tags 52980 + patch
thanks

Stefan Kangas <stefan@marxist.se> writes:

> I started looking into a solution with {before,after}-revert-hook, but
> that just seems duplicate what we would get from just using a minor
> mode.  So I'm starting to think that `elide-head' and `elide-head-show'
> should be obsoleted in favor of a new local minor mode
> `elide-head-mode'.
>
> That would also save me from having to add a third command
> `elide-head-toggle' to toggle the hiding on or off.

Here's a patch.

[-- Attachment #2: 0001-New-minor-mode-elide-head-mode.patch --]
[-- Type: text/x-diff, Size: 10833 bytes --]

From f03eddf4beb079f25ed70405c994b3a2a1e11be9 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Tue, 4 Jan 2022 08:21:45 +0100
Subject: [PATCH] New minor mode elide-head-mode

* lisp/elide-head.el (elide-head-mode): New minor mode.
(elide-head--delete-overlay, elide-head--show)
(elide-head--hide): New functions factored out from ...
(elide-head, elide-head-show): ... here.  Make obsolete in favor
of elide-head-mode.
(elide-head-headers-to-hide): Doc fix.

* test/lisp/elide-head-tests.el (ert-x): Require.
(elide-head-tests-elide-head-mode)
(elide-head-tests-elide-head-mode/enable-disable)
(elide-head-tests-elide-head-mode/revert): New tests.
(elide-head--add-test): Update test to use elide-head-mode.
(elide-head-tests-elide-head)
(elide-head-tests-elide-head-with-prefix-arg)
(elide-head-tests-show): Make obsolete.
---
 etc/NEWS                      |   7 +++
 lisp/elide-head.el            | 111 ++++++++++++++++++++++------------
 test/lisp/elide-head-tests.el |  72 +++++++++++++++++-----
 3 files changed, 139 insertions(+), 51 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 9c892b285d..4b38902370 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -781,6 +781,13 @@ the Netscape web browser was released in February, 2008.
 This support has been obsolete since Emacs 25.1.  The final version of
 the Galeon web browser was released in September, 2008.
 
+** Miscellaneous
+
+---
+*** New minor mode 'elide-head-mode'.
+Enabling this minor mode toggles hiding header material.  The commands
+'elide-head' and 'elide-head-show' are now obsolete.
+
 \f
 * New Modes and Packages in Emacs 29.1
 
diff --git a/lisp/elide-head.el b/lisp/elide-head.el
index dab51cabc4..a3610f7657 100644
--- a/lisp/elide-head.el
+++ b/lisp/elide-head.el
@@ -26,12 +26,12 @@
 ;; notices) in file headers to avoid clutter when you know what it
 ;; says.
 ;;
-;; `elide-head-headers-to-hide' controls what is elided by the command
-;; `elide-head'.  A buffer-local invisible overlay manages the
-;; elision.
+;; `elide-head-headers-to-hide' controls what is elided by the minor
+;; mode `elide-head-mode'.  A buffer-local invisible overlay manages
+;; the elision.
 
-;; You might add `elide-head' to appropriate major mode hooks or to
-;; `find-file-hook'.  Please do not do this in site init files.  If
+;; You might add `elide-head-mode' to appropriate major mode hooks or
+;; to `find-file-hook'.  Please do not do this in site init files.  If
 ;; you do, information may be hidden from users who don't know it
 ;; already.
 
@@ -73,13 +73,76 @@ elide-head-headers-to-hide
 The cars of elements of the list are searched for in order.  Text is
 elided with an invisible overlay from the end of the line where the
 first match is found to the end of the match for the corresponding
-cdr."
+cdr.
+
+This affects `elide-head-mode'."
   :type '(alist :key-type  (regexp :tag "Start regexp")
                 :value-type (regexp :tag "End regexp"))
   :version "29.1")
 
 (defvar-local elide-head-overlay nil)
 
+(defun elide-head--delete-overlay ()
+  "Delete the overlay in `elide-head-overlay'."
+  (when (overlayp elide-head-overlay)
+    (delete-overlay elide-head-overlay)))
+
+(defun elide-head--hide ()
+  "Hide elided (hidden) headers."
+  (save-excursion
+    (save-restriction
+      (let ((rest elide-head-headers-to-hide)
+            beg end)
+        (widen)
+        (goto-char (point-min))
+        (while rest
+          (save-excursion
+            (when (re-search-forward (caar rest) nil t)
+              (setq beg (point))
+              (when (re-search-forward (cdar rest) nil t)
+                (setq end (point-marker)
+                      rest nil))))
+          (if rest (setq rest (cdr rest))))
+        (if (not (and beg end))
+            (if (called-interactively-p 'interactive)
+                (message "No header found"))
+          (goto-char beg)
+          (end-of-line)
+          (if (overlayp elide-head-overlay)
+              (move-overlay elide-head-overlay (point-marker) end)
+            (setq elide-head-overlay (make-overlay (point-marker) end)))
+          (overlay-put elide-head-overlay 'invisible t)
+          (overlay-put elide-head-overlay 'evaporate t)
+          (overlay-put elide-head-overlay 'after-string "..."))))))
+
+(defun elide-head--show ()
+  "Show elided (hidden) headers."
+  (if (and (overlayp elide-head-overlay)
+           (overlay-buffer elide-head-overlay))
+      (elide-head--delete-overlay)
+    (if (called-interactively-p 'interactive)
+        (message "No header hidden"))))
+
+;;;###autoload
+(define-minor-mode elide-head-mode
+  "Toggle eliding (hiding) header material in the current buffer.
+
+When Elide Header mode is enabled, headers are hidden according
+to `elide-head-headers-to-hide'.
+
+This is suitable as an entry on `find-file-hook' or appropriate
+mode hooks."
+  :group 'elide-head
+  (if elide-head-mode
+      (progn
+        (elide-head--hide)
+        (add-hook 'before-revert-hook 'elide-head--delete-overlay nil 'local))
+    (elide-head--show)
+    (remove-hook 'before-revert-hook 'elide-head--delete-overlay 'local)))
+
+\f
+;;; Obsolete
+
 ;;;###autoload
 (defun elide-head (&optional arg)
   "Hide header material in buffer according to `elide-head-headers-to-hide'.
@@ -88,43 +151,17 @@ elide-head
 an elided material again.
 
 This is suitable as an entry on `find-file-hook' or appropriate mode hooks."
+  (declare (obsolete elide-head-mode "29.1"))
   (interactive "P")
   (if arg
-      (elide-head-show)
-    (save-excursion
-      (save-restriction
-	(let ((rest elide-head-headers-to-hide)
-	      beg end)
-	  (widen)
-	  (goto-char (point-min))
-	  (while rest
-	    (save-excursion
-	      (when (re-search-forward (caar rest) nil t)
-		(setq beg (point))
-		(when (re-search-forward (cdar rest) nil t)
-		  (setq end (point-marker)
-			rest nil))))
-	    (if rest (setq rest (cdr rest))))
-	  (if (not (and beg end))
-	      (if (called-interactively-p 'interactive)
-		  (message "No header found"))
-	    (goto-char beg)
-	    (end-of-line)
-	    (if (overlayp elide-head-overlay)
-		(move-overlay elide-head-overlay (point-marker) end)
-	      (setq elide-head-overlay (make-overlay (point-marker) end)))
-	    (overlay-put elide-head-overlay 'invisible t)
-	    (overlay-put elide-head-overlay 'evaporate t)
-	    (overlay-put elide-head-overlay 'after-string "...")))))))
+      (elide-head--show)
+    (elide-head--hide)))
 
 (defun elide-head-show ()
   "Show a header in the current buffer elided by \\[elide-head]."
+  (declare (obsolete elide-head-mode "29.1"))
   (interactive)
-  (if (and (overlayp elide-head-overlay)
-	   (overlay-buffer elide-head-overlay))
-      (delete-overlay elide-head-overlay)
-    (if (called-interactively-p 'interactive)
-	(message "No header hidden"))))
+  (elide-head--show))
 
 (provide 'elide-head)
 
diff --git a/test/lisp/elide-head-tests.el b/test/lisp/elide-head-tests.el
index 804617f48f..5ed2c0b934 100644
--- a/test/lisp/elide-head-tests.el
+++ b/test/lisp/elide-head-tests.el
@@ -28,41 +28,51 @@
 
 (require 'elide-head)
 (require 'ert)
+(require 'ert-x)
 
-(ert-deftest elide-head-tests-elide-head ()
+(ert-deftest elide-head-tests-elide-head-mode ()
   (let ((elide-head-headers-to-hide '(("START" . "END"))))
     (with-temp-buffer
       (insert "foo\nSTART\nHIDDEN\nEND\nbar")
-      (elide-head)
+      (elide-head-mode 1)
       (let ((o (car (overlays-at 14))))
         (should (= (overlay-start o) 10))
         (should (= (overlay-end o) 21))
         (should (overlay-get o 'invisible))
         (should (overlay-get o 'evaporate))))))
 
-(ert-deftest elide-head-tests-elide-head-with-prefix-arg ()
+(ert-deftest elide-head-tests-elide-head-mode/enable-disable ()
   (let ((elide-head-headers-to-hide '(("START" . "END"))))
     (with-temp-buffer
       (insert "foo\nSTART\nHIDDEN\nEND\nbar")
-      (elide-head)
+      (elide-head-mode 1)
       (should (overlays-at 14))
-      (elide-head t)
+      (elide-head-mode -1)
       (should-not (overlays-at 14)))))
 
-(ert-deftest elide-head-tests-show ()
-  (let ((elide-head-headers-to-hide '(("START" . "END"))))
-    (with-temp-buffer
-      (insert "foo\nSTART\nHIDDEN\nEND\nbar")
-      (elide-head)
-      (should (overlays-at 14))
-      (elide-head-show)
-      (should-not (overlays-at 14)))))
+(ert-deftest elide-head-tests-elide-head-mode/revert ()
+  (ert-with-temp-file fil
+    (with-temp-file fil
+      (insert "foo\nSTART\nHIDDEN\nEND\nbar"))
+    (let ((elide-head-headers-to-hide '(("START" . "END")))
+          (buf (find-file-noselect fil)))
+      (save-excursion
+        (unwind-protect
+            (progn
+              (set-buffer buf)
+              (elide-head-mode 1)
+              (should (= 1 (length (overlays-in (point-min) (point-max)))))
+              (revert-buffer nil t)
+              (elide-head-mode 1)
+              (should (= 1 (length (overlays-in (point-min) (point-max))))))
+          (when buf (kill-buffer buf)))))))
+
 
 (defmacro elide-head--add-test (name text search-str)
   `(ert-deftest ,(intern (format "elide-head--test-headers-to-hide/%s" name)) ()
      (with-temp-buffer
        (insert ,text)
-       (elide-head)
+       (elide-head-mode 1)
        (goto-char (point-min))
        (re-search-forward ,search-str)
        (let ((o (car (overlays-at (match-beginning 0)))))
@@ -163,5 +173,39 @@ elide-head--add-test
         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 " "This program is distributed in the hope that")
 
+\f
+;;; Obsolete
+
+(with-suppressed-warnings ((obsolete elide-head)
+                           (obsolete elide-head-show))
+  (ert-deftest elide-head-tests-elide-head ()
+    (let ((elide-head-headers-to-hide '(("START" . "END"))))
+      (with-temp-buffer
+        (insert "foo\nSTART\nHIDDEN\nEND\nbar")
+        (elide-head)
+        (let ((o (car (overlays-at 14))))
+          (should (= (overlay-start o) 10))
+          (should (= (overlay-end o) 21))
+          (should (overlay-get o 'invisible))
+          (should (overlay-get o 'evaporate))))))
+
+  (ert-deftest elide-head-tests-elide-head-with-prefix-arg ()
+    (let ((elide-head-headers-to-hide '(("START" . "END"))))
+      (with-temp-buffer
+        (insert "foo\nSTART\nHIDDEN\nEND\nbar")
+        (elide-head)
+        (should (overlays-at 14))
+        (elide-head t)
+        (should-not (overlays-at 14)))))
+
+  (ert-deftest elide-head-tests-show ()
+    (let ((elide-head-headers-to-hide '(("START" . "END"))))
+      (with-temp-buffer
+        (insert "foo\nSTART\nHIDDEN\nEND\nbar")
+        (elide-head)
+        (should (overlays-at 14))
+        (elide-head-show)
+        (should-not (overlays-at 14))))))
+
 (provide 'elide-head-tests)
 ;;; elide-head-tests.el ends here
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working
  2022-01-04  8:15   ` Stefan Kangas
@ 2022-01-04 17:08     ` jakanakaevangeli
  2022-01-05  9:30       ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: jakanakaevangeli @ 2022-01-04 17:08 UTC (permalink / raw)
  To: Stefan Kangas, 52980

Just one minor suggestion from me:

Stefan Kangas <stefan@marxist.se> writes:

> tags 52980 + patch
> thanks
>
> Stefan Kangas <stefan@marxist.se> writes:
>
>> I started looking into a solution with {before,after}-revert-hook, but
>> that just seems duplicate what we would get from just using a minor
>> mode.  So I'm starting to think that `elide-head' and `elide-head-show'
>> should be obsoleted in favor of a new local minor mode
>> `elide-head-mode'.
>>
>> That would also save me from having to add a third command
>> `elide-head-toggle' to toggle the hiding on or off.
>
> Here's a patch.
> [...]
> 
> +;;;###autoload
> +(define-minor-mode elide-head-mode
> +  "Toggle eliding (hiding) header material in the current buffer.
> +
> +When Elide Header mode is enabled, headers are hidden according
> +to `elide-head-headers-to-hide'.
> +
> +This is suitable as an entry on `find-file-hook' or appropriate
> +mode hooks."
> +  :group 'elide-head
> +  (if elide-head-mode
> +      (progn
> +        (elide-head--hide)
> +        (add-hook 'before-revert-hook 'elide-head--delete-overlay nil 'local))
> +    (elide-head--show)
> +    (remove-hook 'before-revert-hook 'elide-head--delete-overlay 'local)))

Perhaps change-major-mode-hook would be more appropriate as suggested by
"(elisp) Creating Buffer-Local". That would make the minor mode clean up
its overlay if the user executes M-x normal-mode in addition to M-x
revert-buffer.

> [...]

Best regards.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working
  2022-01-04 17:08     ` jakanakaevangeli
@ 2022-01-05  9:30       ` Stefan Kangas
  2022-01-09 10:13         ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2022-01-05  9:30 UTC (permalink / raw)
  To: jakanakaevangeli, 52980

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

<jakanakaevangeli@chiru.no> writes:

>> +  (if elide-head-mode
>> +      (progn
>> +        (elide-head--hide)
>> +        (add-hook 'before-revert-hook 'elide-head--delete-overlay nil 'local))
>> +    (elide-head--show)
>> +    (remove-hook 'before-revert-hook 'elide-head--delete-overlay 'local)))
>
> Perhaps change-major-mode-hook would be more appropriate as suggested by
> "(elisp) Creating Buffer-Local". That would make the minor mode clean up
> its overlay if the user executes M-x normal-mode in addition to M-x
> revert-buffer.

I think you're right, thanks!  Updated patch attached.

[-- Attachment #2: 0001-New-minor-mode-elide-head-mode.patch --]
[-- Type: text/x-diff, Size: 11552 bytes --]

From d8a2146340594746d52c66fcc472a5dc8e28443a Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Tue, 4 Jan 2022 08:21:45 +0100
Subject: [PATCH] New minor mode elide-head-mode

* lisp/elide-head.el (elide-head-mode): New minor mode.  (Bug#52980)
(elide-head--delete-overlay, elide-head--show)
(elide-head--hide): New functions factored out from ...
(elide-head, elide-head-show): ... here.  Make obsolete in favor
of elide-head-mode.
(elide-head-headers-to-hide): Doc fix.

* test/lisp/elide-head-tests.el (ert-x): Require.
(elide-head-tests-elide-head-mode)
(elide-head-tests-elide-head-mode/enable-disable)
(elide-head-tests-elide-head-mode/normal-mode)
(elide-head-tests-elide-head-mode/revert-buffer): New tests.
(elide-head--add-test): Update test to use elide-head-mode.
(elide-head-tests-elide-head)
(elide-head-tests-elide-head-with-prefix-arg)
(elide-head-tests-show): Make obsolete.
---
 etc/NEWS                      |   7 +++
 lisp/elide-head.el            | 111 ++++++++++++++++++++++------------
 test/lisp/elide-head-tests.el |  88 ++++++++++++++++++++++-----
 3 files changed, 155 insertions(+), 51 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 9c892b285d..4b38902370 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -781,6 +781,13 @@ the Netscape web browser was released in February, 2008.
 This support has been obsolete since Emacs 25.1.  The final version of
 the Galeon web browser was released in September, 2008.
 
+** Miscellaneous
+
+---
+*** New minor mode 'elide-head-mode'.
+Enabling this minor mode toggles hiding header material.  The commands
+'elide-head' and 'elide-head-show' are now obsolete.
+
 \f
 * New Modes and Packages in Emacs 29.1
 
diff --git a/lisp/elide-head.el b/lisp/elide-head.el
index dab51cabc4..837dca1afe 100644
--- a/lisp/elide-head.el
+++ b/lisp/elide-head.el
@@ -26,12 +26,12 @@
 ;; notices) in file headers to avoid clutter when you know what it
 ;; says.
 ;;
-;; `elide-head-headers-to-hide' controls what is elided by the command
-;; `elide-head'.  A buffer-local invisible overlay manages the
-;; elision.
+;; `elide-head-headers-to-hide' controls what is elided by the minor
+;; mode `elide-head-mode'.  A buffer-local invisible overlay manages
+;; the elision.
 
-;; You might add `elide-head' to appropriate major mode hooks or to
-;; `find-file-hook'.  Please do not do this in site init files.  If
+;; You might add `elide-head-mode' to appropriate major mode hooks or
+;; to `find-file-hook'.  Please do not do this in site init files.  If
 ;; you do, information may be hidden from users who don't know it
 ;; already.
 
@@ -73,13 +73,76 @@ elide-head-headers-to-hide
 The cars of elements of the list are searched for in order.  Text is
 elided with an invisible overlay from the end of the line where the
 first match is found to the end of the match for the corresponding
-cdr."
+cdr.
+
+This affects `elide-head-mode'."
   :type '(alist :key-type  (regexp :tag "Start regexp")
                 :value-type (regexp :tag "End regexp"))
   :version "29.1")
 
 (defvar-local elide-head-overlay nil)
 
+(defun elide-head--delete-overlay ()
+  "Delete the overlay in `elide-head-overlay'."
+  (when (overlayp elide-head-overlay)
+    (delete-overlay elide-head-overlay)))
+
+(defun elide-head--hide ()
+  "Hide elided (hidden) headers."
+  (save-excursion
+    (save-restriction
+      (let ((rest elide-head-headers-to-hide)
+            beg end)
+        (widen)
+        (goto-char (point-min))
+        (while rest
+          (save-excursion
+            (when (re-search-forward (caar rest) nil t)
+              (setq beg (point))
+              (when (re-search-forward (cdar rest) nil t)
+                (setq end (point-marker)
+                      rest nil))))
+          (if rest (setq rest (cdr rest))))
+        (if (not (and beg end))
+            (if (called-interactively-p 'interactive)
+                (message "No header found"))
+          (goto-char beg)
+          (end-of-line)
+          (if (overlayp elide-head-overlay)
+              (move-overlay elide-head-overlay (point-marker) end)
+            (setq elide-head-overlay (make-overlay (point-marker) end)))
+          (overlay-put elide-head-overlay 'invisible t)
+          (overlay-put elide-head-overlay 'evaporate t)
+          (overlay-put elide-head-overlay 'after-string "..."))))))
+
+(defun elide-head--show ()
+  "Show elided (hidden) headers."
+  (if (and (overlayp elide-head-overlay)
+           (overlay-buffer elide-head-overlay))
+      (elide-head--delete-overlay)
+    (if (called-interactively-p 'interactive)
+        (message "No header hidden"))))
+
+;;;###autoload
+(define-minor-mode elide-head-mode
+  "Toggle eliding (hiding) header material in the current buffer.
+
+When Elide Header mode is enabled, headers are hidden according
+to `elide-head-headers-to-hide'.
+
+This is suitable as an entry on `find-file-hook' or appropriate
+mode hooks."
+  :group 'elide-head
+  (if elide-head-mode
+      (progn
+        (elide-head--hide)
+        (add-hook 'change-major-mode-hook 'elide-head--delete-overlay nil 'local))
+    (elide-head--show)
+    (remove-hook 'change-major-mode-hook 'elide-head--delete-overlay 'local)))
+
+\f
+;;; Obsolete
+
 ;;;###autoload
 (defun elide-head (&optional arg)
   "Hide header material in buffer according to `elide-head-headers-to-hide'.
@@ -88,43 +151,17 @@ elide-head
 an elided material again.
 
 This is suitable as an entry on `find-file-hook' or appropriate mode hooks."
+  (declare (obsolete elide-head-mode "29.1"))
   (interactive "P")
   (if arg
-      (elide-head-show)
-    (save-excursion
-      (save-restriction
-	(let ((rest elide-head-headers-to-hide)
-	      beg end)
-	  (widen)
-	  (goto-char (point-min))
-	  (while rest
-	    (save-excursion
-	      (when (re-search-forward (caar rest) nil t)
-		(setq beg (point))
-		(when (re-search-forward (cdar rest) nil t)
-		  (setq end (point-marker)
-			rest nil))))
-	    (if rest (setq rest (cdr rest))))
-	  (if (not (and beg end))
-	      (if (called-interactively-p 'interactive)
-		  (message "No header found"))
-	    (goto-char beg)
-	    (end-of-line)
-	    (if (overlayp elide-head-overlay)
-		(move-overlay elide-head-overlay (point-marker) end)
-	      (setq elide-head-overlay (make-overlay (point-marker) end)))
-	    (overlay-put elide-head-overlay 'invisible t)
-	    (overlay-put elide-head-overlay 'evaporate t)
-	    (overlay-put elide-head-overlay 'after-string "...")))))))
+      (elide-head--show)
+    (elide-head--hide)))
 
 (defun elide-head-show ()
   "Show a header in the current buffer elided by \\[elide-head]."
+  (declare (obsolete elide-head-mode "29.1"))
   (interactive)
-  (if (and (overlayp elide-head-overlay)
-	   (overlay-buffer elide-head-overlay))
-      (delete-overlay elide-head-overlay)
-    (if (called-interactively-p 'interactive)
-	(message "No header hidden"))))
+  (elide-head--show))
 
 (provide 'elide-head)
 
diff --git a/test/lisp/elide-head-tests.el b/test/lisp/elide-head-tests.el
index 804617f48f..6f351170f1 100644
--- a/test/lisp/elide-head-tests.el
+++ b/test/lisp/elide-head-tests.el
@@ -28,41 +28,67 @@
 
 (require 'elide-head)
 (require 'ert)
+(require 'ert-x)
 
-(ert-deftest elide-head-tests-elide-head ()
+(ert-deftest elide-head-tests-elide-head-mode ()
   (let ((elide-head-headers-to-hide '(("START" . "END"))))
     (with-temp-buffer
       (insert "foo\nSTART\nHIDDEN\nEND\nbar")
-      (elide-head)
+      (elide-head-mode 1)
       (let ((o (car (overlays-at 14))))
         (should (= (overlay-start o) 10))
         (should (= (overlay-end o) 21))
         (should (overlay-get o 'invisible))
         (should (overlay-get o 'evaporate))))))
 
-(ert-deftest elide-head-tests-elide-head-with-prefix-arg ()
+(ert-deftest elide-head-tests-elide-head-mode/enable-disable ()
   (let ((elide-head-headers-to-hide '(("START" . "END"))))
     (with-temp-buffer
       (insert "foo\nSTART\nHIDDEN\nEND\nbar")
-      (elide-head)
+      (elide-head-mode 1)
       (should (overlays-at 14))
-      (elide-head t)
+      (elide-head-mode -1)
       (should-not (overlays-at 14)))))
 
-(ert-deftest elide-head-tests-show ()
-  (let ((elide-head-headers-to-hide '(("START" . "END"))))
-    (with-temp-buffer
-      (insert "foo\nSTART\nHIDDEN\nEND\nbar")
-      (elide-head)
-      (should (overlays-at 14))
-      (elide-head-show)
-      (should-not (overlays-at 14)))))
+(ert-deftest elide-head-tests-elide-head-mode/normal-mode ()
+  (ert-with-temp-file fil
+    (with-temp-file fil
+      (insert "foo\nSTART\nHIDDEN\nEND\nbar"))
+    (let ((elide-head-headers-to-hide '(("START" . "END")))
+          (buf (find-file-noselect fil)))
+      (save-excursion
+        (unwind-protect
+            (progn
+              (set-buffer buf)
+              (elide-head-mode 1)
+              (should (= 1 (length (overlays-in (point-min) (point-max)))))
+              (normal-mode)
+              (should (= 0 (length (overlays-in (point-min) (point-max))))))
+          (when buf (kill-buffer buf)))))))
+
+(ert-deftest elide-head-tests-elide-head-mode/revert-buffer ()
+  (ert-with-temp-file fil
+    (with-temp-file fil
+      (insert "foo\nSTART\nHIDDEN\nEND\nbar"))
+    (let ((elide-head-headers-to-hide '(("START" . "END")))
+          (buf (find-file-noselect fil)))
+      (save-excursion
+        (unwind-protect
+            (progn
+              (set-buffer buf)
+              (elide-head-mode 1)
+              (should (= 1 (length (overlays-in (point-min) (point-max)))))
+              (revert-buffer nil t)
+              (elide-head-mode 1)
+              (should (= 1 (length (overlays-in (point-min) (point-max))))))
+          (when buf (kill-buffer buf)))))))
+
 
 (defmacro elide-head--add-test (name text search-str)
   `(ert-deftest ,(intern (format "elide-head--test-headers-to-hide/%s" name)) ()
      (with-temp-buffer
        (insert ,text)
-       (elide-head)
+       (elide-head-mode 1)
        (goto-char (point-min))
        (re-search-forward ,search-str)
        (let ((o (car (overlays-at (match-beginning 0)))))
@@ -163,5 +189,39 @@ elide-head--add-test
         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 " "This program is distributed in the hope that")
 
+\f
+;;; Obsolete
+
+(with-suppressed-warnings ((obsolete elide-head)
+                           (obsolete elide-head-show))
+  (ert-deftest elide-head-tests-elide-head ()
+    (let ((elide-head-headers-to-hide '(("START" . "END"))))
+      (with-temp-buffer
+        (insert "foo\nSTART\nHIDDEN\nEND\nbar")
+        (elide-head)
+        (let ((o (car (overlays-at 14))))
+          (should (= (overlay-start o) 10))
+          (should (= (overlay-end o) 21))
+          (should (overlay-get o 'invisible))
+          (should (overlay-get o 'evaporate))))))
+
+  (ert-deftest elide-head-tests-elide-head-with-prefix-arg ()
+    (let ((elide-head-headers-to-hide '(("START" . "END"))))
+      (with-temp-buffer
+        (insert "foo\nSTART\nHIDDEN\nEND\nbar")
+        (elide-head)
+        (should (overlays-at 14))
+        (elide-head t)
+        (should-not (overlays-at 14)))))
+
+  (ert-deftest elide-head-tests-show ()
+    (let ((elide-head-headers-to-hide '(("START" . "END"))))
+      (with-temp-buffer
+        (insert "foo\nSTART\nHIDDEN\nEND\nbar")
+        (elide-head)
+        (should (overlays-at 14))
+        (elide-head-show)
+        (should-not (overlays-at 14))))))
+
 (provide 'elide-head-tests)
 ;;; elide-head-tests.el ends here
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working
  2022-01-05  9:30       ` Stefan Kangas
@ 2022-01-09 10:13         ` Stefan Kangas
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Kangas @ 2022-01-09 10:13 UTC (permalink / raw)
  To: jakanakaevangeli; +Cc: 52980

close 52980 29.1
thanks

No further comments within 4 days; pushed to master as commit
262a7c9ea0.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-09 10:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-03 16:48 bug#52980: elide-head and revert-buffer interaction stops elide-head-show from working Stefan Kangas
2022-01-03 18:40 ` Stefan Kangas
2022-01-04  8:15   ` Stefan Kangas
2022-01-04 17:08     ` jakanakaevangeli
2022-01-05  9:30       ` Stefan Kangas
2022-01-09 10:13         ` Stefan Kangas

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.