Micro: Feature request: Add support for code folding

Created on 11 Apr 2017  路  10Comments  路  Source: zyedidia/micro

The only killer feature available in modern graphical code editors seems to be missing in micro: code folding.
I understand the implementation would be non-trivial but the benefit of having such feature is really high.
Please consider adding it.

enhancement

Most helpful comment

If a generic approach would not be feasible, what about at least folding of indented lines (Python), folding of curly bracket contents (C-like family of languages) and user-hinted folding (like "Marker" at http://learnvimscriptthehardway.stevelosh.com/chapters/48.html - there is a good description of available approaches). Vim's folding could be explored from https://github.com/vim/vim/blob/9d20ce6970158de69202a82529d9e97827a9e71b/src/fold.c#L1120 where syntax parsers can be found at https://github.com/vim/vim/blob/d07969093a9b3051511c478d71c36de6fc33c0d6/runtime/syntax/python.vim

All 10 comments

@sarimak How would that be done though? Not every code file supported by micro delineates code blocks in the same way. It could be a large performance hit to micro in addition to being rather difficult to implement.

I am aware of Scintilla-based editor with code folding - Geany - which uses lexers on top of parsers for finding the folding points. Maybe you could re-use at least the approach, if not the existing code?

See https://github.com/geany/geany/blob/7ae1d031efe8dd1b967c89ee404ab6fb2172ec4c/ctags/parsers/python.c for an example of a parser and https://github.com/geany/geany/blob/master/scintilla/lexers/LexPython.cxx#L715 for an example of a lexer + https://github.com/geany/geany/blob/2a2ae728341d12b7cea29b671beb08e441f62d95/scintilla/lexers/LexBasic.cxx#L101 for generic lexer's code related to folding.

And there is also a support for code folding in Github Atom:
Per-language configuration: https://github.com/atom/language-python/blob/master/settings/language-python.cson
Folding the view: https://github.com/atom/atom/blob/cc6e127ec149221871e4e6025616fa6e8118c138/src/language-mode.coffee#L94
Parser: https://github.com/atom/language-python/tree/master/grammars
Plugin for custom folding: https://github.com/bsegraves/custom-folds
(I don't speak JavaScript => these are at least some starting points)

If a generic approach would not be feasible, what about at least folding of indented lines (Python), folding of curly bracket contents (C-like family of languages) and user-hinted folding (like "Marker" at http://learnvimscriptthehardway.stevelosh.com/chapters/48.html - there is a good description of available approaches). Vim's folding could be explored from https://github.com/vim/vim/blob/9d20ce6970158de69202a82529d9e97827a9e71b/src/fold.c#L1120 where syntax parsers can be found at https://github.com/vim/vim/blob/d07969093a9b3051511c478d71c36de6fc33c0d6/runtime/syntax/python.vim

+1

It could be some keybinds like atom:

https://flight-manual.atom.io/using-atom/sections/folding/

Any update on this? 馃槄

@Penguinlay As far as I know, nobody has started working on this feature yet. Be the change you want to see :slightly_smiling_face:

I code in my own bubble, but FWIW, indentation-based folding would absolutely be sufficient for me.

I am currently swamped but I will give it a shot this weekend. 馃槉

The only terminal editor I know of that supports code folding is Textadept (Scintilla based). See the discussion of the feature here: https://foicica.com/textadept/api.html#lexer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rbagman picture Rbagman  路  4Comments

zanglebert picture zanglebert  路  4Comments

johnmbaughman picture johnmbaughman  路  3Comments

KhodeN picture KhodeN  路  3Comments

xintrea picture xintrea  路  3Comments