help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Code folding in Emacs.


From: tolugboji
Subject: Code folding in Emacs.
Date: Sun, 10 Oct 2021 12:42:43 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Sunday, October 10th, 2021 at 11:54 AM, Hongyi Zhao <hongyi.zhao@gmail.com> 
wrote:

> On Sun, Oct 10, 2021 at 7:37 PM tolugboji tolugboji@protonmail.com wrote:
>
> > Emacs should develop code folding (opening and closing) to also work with 
> > the mouse.
>
> The code snippet I posted above is based on an idea here [1], as shown below:
>
> --------------------------------------------------------------------------------
>
> Outlines and Overviews
>
> SelectiveDisplay – a poor-man’s OutlineMode. It hides lines with more
>
> than the provided number of spaces in front. It can help in getting a
>
> quick overview of files as long as paragraph lines are further
>
> indented than headlines. This is great for viewing man pages: ‘C-u 1
>
> M-x set-selective-display’ to show only headings, `M-x <up> RET’ to
>
> disable it again.
>
> More SelectiveDisplay: ‘set-selective-display’ is `C-x$’ by default.
>
> You can make it a lot friendlier with a wrapper: – DaleWiles
>
> (global-set-key "\C-x$" 'set-selective-display-dlw)
>
> (defun set-selective-display-dlw (&optional level)
>
> "Fold text indented more than the cursor.
>
> If level is set, set the indent level to level.
>
> 0 displays the entire buffer."
>
> (interactive "P")
>
> (set-selective-display (or level (current-column))))
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> It seems the idea was initiated by DaleWiles, but his/her homepage
>
> given on emacswiki [2] is empty.
>
> Another note, though there are already several code-folding relevant
>
> packages available on melpa [3-5]. In my opinion, this concise and
>
> clear code snippet is suitable for any programming language that uses
>
> indented semantic blocks, and it beats all relevant packages found on
>
> melpa.

Because it is such a basic operation many would like to use, emacs should 
provide it
from itself.  Currently outline-minor-mode in too complicated and inconsistent 
to be
used regularly.  Using a long string of *** is difficult to understand, whereas 
a
hierarchy based on numeric values is better.  An additional problem is that 
Headings
Folding and Code Folding are dealt as they are the same.  Very bad idea.


> [1] https://www.emacswiki.org/emacs/EmacsNiftyTricks#h5o-6
>
> [2] https://www.emacswiki.org/emacs/DaleWiles
>
> [3] https://github.com/gregsexton/origami.el
>
> [4] https://github.com/matsievskiysv/vimish-fold
>
> [5] https://github.com/emacsorphanage/yafolding
>
> HZ
>
> > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> >
> > On Sunday, October 10th, 2021 at 8:16 AM, Hongyi Zhao hongyi.zhao@gmail.com 
> > wrote:
> >
> > > I just found the following code snippet from here [1] for code folding in 
> > > Emacs:
> > >
> > > (global-set-key (kbd "<C-f5>") 'set-selective-display-dlw)
> > >
> > > (defun set-selective-display-dlw (&optional level)
> > >
> > > "Fold text indented same of more than the cursor.
> > >
> > > If level is set, set the indent level to LEVEL.
> > >
> > > If 'selective-display' is already set to LEVEL, clicking
> > >
> > > F5 again will unset 'selective-display' by setting it to 0."
> > >
> > > (interactive "P")
> > >
> > > (if (eq selective-display (1+ (current-column)))
> > >
> > > (set-selective-display 0)
> > >
> > > (set-selective-display (or level (1+ (current-column))))))
> > >
> > > The above code trick seems very simple, but it works for many
> > >
> > > languages. So I recommend it here.
> > >
> > > [1] https://discourse.julialang.org/t/code-folding-for-emacs/41421/3
> > >
> > > Regards
> > > -------
> > >
> > > Assoc. Prof. Hongyi Zhao hongyi.zhao@gmail.com
> > >
> > > Theory and Simulation of Materials
> > >
> > > Hebei Vocational University of Technology and Engineering
> > >
> > > No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



reply via email to

[Prev in Thread] Current Thread [Next in Thread]