Subject: 27.1; lisp-outline-level returns imprecise level number

From: Howard Melman <[email-masked]>
Date: Tue, 2 Mar 2021 11:35:01 -0500

lisp-outline-level returns a functional but incorrect level
number.  Comments beginning with ";;; " should be at level 1
but it returns 5 because they match ";;; [^ \t\n]" and the
current code just returns that length.

The following version returns the right level following the
convention that ;;; are top level comments and each lower
level adds a ;.  As in the existing code, lines that match
an autoload tag or begin with ( return level 1000.

This fix would be helpful for code that wants to deal with
headings by level number generically (e.g., display the top
3 heading levels).  Other modes like outline, org, texinfo,
and html-mode return a level rooted at 1.  Programming modes
are more mixed, but this seems like an easy improvement for
lisp modes.

    (defun lisp-outline-level ()
      "Lisp mode `outline-level' function."
      ;; expects outline-regexp is ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|("
      ;; and point is at the beginning of a matching line
      (let ((len (- (match-end 0) (match-beginning 0))))
        (cond ((looking-at "(\\|;;;###autoload")
               1000)
              ((looking-at ";;\\(;+\\) ")
               (- (match-end 1) (match-beginning 1)))
              ;; above should match everything but just in case
              (t
               len))))

In GNU Emacs 27.1 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95))
of 2020-08-12 built on builder10-14.porkrind.org
Windowing system distributor 'Apple', version 10.3.1894
System Description:  Mac OS X 10.15.7

Configured using:
'configure --with-ns '--enable-locallisppath=/Library/Application
Support/Emacs/${version}/site-lisp:/Library/Application
Support/Emacs/site-lisp' --with-modules'

-- 

Howard