Subject: bug#48724: Code collapsing and outline headings for elisp

From: Christopher Dimech <[email-masked]>
Date: Sun, 30 May 2021 03:38:39 +0200

> Sent: Sunday, May 30, 2021 at 11:55 AM
> From: "Christopher Dimech" <[email-masked]>
> To: "Juri Linkov" <[email-masked]>
> Cc: [email-masked]
> Subject: bug#48724: Code collapsing and outline headings for elisp
>
> > Sent: Sunday, May 30, 2021 at 9:57 AM
> > From: "Juri Linkov" <[email-masked]>
> > To: "Christopher Dimech" <[email-masked]>
> > Cc: [email-masked]
> > Subject: Re: bug#48724: Code collapsing and outline headings for elisp
> >
> > > Currently, outline-minor-mode has the capability to treat "defun" constructs
> > > as heading, allowing one to choose to hide some code from view by collapsing
> > > the region of code.  It would be beneficial for the actual major mode itself
> > > (i.e. emacs-lisp-mode) to handle the code collapsing, leaving the code highlighting
> > > intact.  Code collapsing could also be extended beyond not only collapsing
> > > functions and variables ((defun, defvar), but also to additional constructs that could
> > > be indented (e.g. lists '(...), let, let*, pcase) and other constructs users could
> > > find useful (e.g. if, when, ).
> > >
> > > And for outline-minor-mode, the mode could then be used to further enhance the structuring
> > > of larger chunks of code (e.g. a collection of functions) using outline headings.  Outlining
> > > would then be a separate capability different from code collapsing.
> > 
> > Currently everything is customizable in outline-minor-mode by just
> > two variables: outline-regexp and outline-level.  So when necessary,
> > emacs-lisp-mode could provide an option that will set different values
> > of these variables, one of which could set outline-regexp to a regexp
> > that matches: lists, '(...), let, let*, pcase, if, when, etc…
> 
> The general impression is that outline-minor-mode is a general mode
> for customisable headings that are then handled by the respective
> major mode.
> 
> General settings could be better, because some variables are not customizable.
> 
> Serious problem is that the two important variables: `outline-regexp' and
> `outline-heading-alist' are not customizable by using "M-x customize-group".
> 
> Additionally both of them should be customizable per mode.  Don't you think so?
> 
> There has been a discussion today about outline-minor-mode settings for fortran
> (both fixed and free form).  Have had a go at using "!" and "!!", but "Hide Body"
> did not hide the body.
> 
> There could be some default headings for fortran when outline-minor-mode is enabled.
> One could follow the current setup for emacs-lisp-mode, for fortran.
> 
> !! for heading level 1
> !!! for subheading level 2
> !!!! for subsubheading level 3
> 
> Together with "Hide Body" for lines beginning with "subroutine" and "function".
 
Looking at emacs-lisp again, the levels should be as follows

!!! for heading level 1 (starting as !!! as in emacs-lisp-mode)
!!!! for subheading level 2
!!!!! for subsubheading level 3  etc

I wonder if there exists the capabibily in outline-minor-mode to hide
code structures inside another code structure.

For instance for "do", "if" and "else" statements.

do in1 = 1, nr(1)
  do in2 = 1, nr(1)
    ind = in1 - in2
    if (ind < 0) then
      res(in1, in2) = conjg(fc(abs(ind)+1))
    else
      res(in1, in2) = fc(ind+1)
    endif
  enddo
enddo

hiding would then give the following

do in1 = 1, nr(1)
  do in2 = 1, nr(1)
    ind = in1 - in2
    if (ind < 0) then ...
    else ...
    end if
  end do
end do

do in1 = 1, nr(1)
  do in2 = 1, nr(1) ...
  end do
end do

do in1 = 1, nr(1) ...
end do