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

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

Re: Code folding in Emacs.


From: Thibaut Verron
Subject: Re: Code folding in Emacs.
Date: Thu, 14 Oct 2021 10:21:59 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

On 14/10/2021 07:47, David Masterson wrote:
Hongyi Zhao <hongyi.zhao@gmail.com> writes:

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
See Origami.

Which is, sadly, now unmaintained. Most notably, it lacks documentation on how to specify a parser, all one can do is guess based on the existing ones. There are forks attempting to clear those gaps, but afaik it's not there yet -- and they face distribution issues, with package repositories refusing to keep several packages with the same name.

It would be great if Emacs had something like origami built-in, aka a folding framework with a more flexible way to specify folding points than regexps (hideshow) or headers (outline). Essentially something like smie, but for folding: define functions to test if we are at an opener, at a closer, to find the closer for an opener, to find the subnodes if applicable, and let the package merge it all, construct the folding tree and take care of the folding.





reply via email to

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