Subject: bug#28998: 27.0.50; Man--sections is in reverse order

From: "Basil L. Contovounesios" <[email-masked]>
Date: Tue, 07 Nov 2017 15:07:09 +0000

>From 6bc6f316f4bd3dc80b96d2d894bce66487cb9127 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Wed, 25 Oct 2017 16:57:43 +0100
Subject: [PATCH 1/2] Keep Man sections in natural order (bug#28998)

* lisp/man.el (Man-build-section-alist): Reverse sections.
---
 lisp/man.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/man.el b/lisp/man.el
index 7a892c6e88..f7b1609c92 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -1522,7 +1522,8 @@ Man-build-section-alist
       (let ((section (match-string 1)))
         (unless (member section Man--sections)
           (push section Man--sections)))
-      (forward-line 1))))
+      (forward-line 1)))
+  (setq Man--sections (nreverse Man--sections)))
 
 (defsubst Man-build-references-alist ()
   "Build the list of references (in the SEE ALSO section)."
-- 
2.14.2

>From f96f95b830825681fb618f1727fcc3e0f488102f Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Tue, 7 Nov 2017 14:51:37 +0000
Subject: [PATCH 2/2] Rename Man-build-section-alist (bug#28998)

The defsubst Man-build-section-alist builds and returns a list of
strings, so rename it to Man-build-section-list and make it a defun.

* lisp/man.el (Man-build-section-alist): Do it and reduce syntax.
(Man-goto-page):
* lisp/woman.el (woman-find-file): Use it.
---
 lisp/man.el   | 10 +++++-----
 lisp/woman.el |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/man.el b/lisp/man.el
index f7b1609c92..798e78bbe7 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -1513,16 +1513,16 @@ Man-mode
   (set (make-local-variable 'bookmark-make-record-function)
        'Man-bookmark-make-record))
 
-(defsubst Man-build-section-alist ()
+(defun Man-build-section-list ()
   "Build the list of manpage sections."
-  (setq Man--sections nil)
+  (setq Man--sections ())
   (goto-char (point-min))
   (let ((case-fold-search nil))
-    (while (re-search-forward Man-heading-regexp (point-max) t)
+    (while (re-search-forward Man-heading-regexp nil t)
       (let ((section (match-string 1)))
         (unless (member section Man--sections)
           (push section Man--sections)))
-      (forward-line 1)))
+      (forward-line)))
   (setq Man--sections (nreverse Man--sections)))
 
 (defsubst Man-build-references-alist ()
@@ -1803,7 +1803,7 @@ Man-goto-page
       (widen)
       (goto-char page-start)
       (narrow-to-region page-start page-end)
-      (Man-build-section-alist)
+      (Man-build-section-list)
       (Man-build-references-alist)
       (goto-char (point-min)))))
 
diff --git a/lisp/woman.el b/lisp/woman.el
index 111086e362..1edf6e34c3 100644
--- a/lisp/woman.el
+++ b/lisp/woman.el
@@ -1619,7 +1619,7 @@ woman-find-file
 	      (setq woman-buffer-alist
 		    (cons (cons file-name bufname) woman-buffer-alist)
 		    woman-buffer-number 0)))))
-  (Man-build-section-alist)
+  (Man-build-section-list)
   (Man-build-references-alist)
   (goto-char (point-min)))
 
-- 
2.14.2

Noam Postavsky <[email-masked]> writes:

>> -(defsubst Man-build-section-alist ()
>> +(defsubst Man-build-section-list ()
>
> Perhaps we should switch to defun while we're at it?
>
>> -  (let ((case-fold-search nil))
>> +  (let (case-fold-search)
>
> Personally, I like the more explicit version here.

I attach slightly reworded patches updated with your two
suggestions.

Thanks,

-- 
Basil