Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code folding #453

Open
v217 opened this issue Nov 1, 2015 · 26 comments
Open

code folding #453

v217 opened this issue Nov 1, 2015 · 26 comments

Comments

@v217
Copy link

v217 commented Nov 1, 2015

Arbitrary text folding like in vim zf.

@Delapouite Delapouite mentioned this issue Jan 20, 2017
8 tasks
@lenormf
Copy link
Contributor

lenormf commented May 16, 2017

Has the integration of soft wrapping made things easier, to support folding?

@net
Copy link
Contributor

net commented Sep 18, 2017

Code folding would be very useful.

@lenormf
Copy link
Contributor

lenormf commented Sep 19, 2017

My question still stands.

@mawww
Copy link
Owner

mawww commented Sep 19, 2017

Could be easier yeah, the main problem with folding is similar to what we have with wrapping: we dont know how things are outside of the displayed window, so any movement primitive that would rely on how lines are displayed (necessary with folding if we dont want to open folds everytime the cursor moves on top of them) will behave strangely for non displayed selections.

In general, it seems tricky to have folding and multiple selections work together. Also, I have been trying to move away from display dependent movements, to make interactive use and script use of the editing language as close as possible.

@Iiridayn
Copy link

Iiridayn commented Feb 5, 2018

I personally don't use code folding, though I've sincerely tried it (a team member loves it). I feel it makes it too easy to hide code smells which should be cleaned up anyway. Ie - file/method/if-then-else/loop body too long? Split it out (into a file or another method/function - especially long loop bodies). Interdependent code sections too far apart? Move them closer. Even so, I've found decent movement commands (usually *) work pretty well for single file navigation in vim w/o folds for even the worst files I've seen.

So, while I can see why folding would be difficult to do well, I don't mind the lack.

@jeanm
Copy link

jeanm commented Feb 23, 2018

I also don't use code folding, although I know plenty of people who do. However, one good reason I see for supporting folding in general it is that it would enable the development of plugins similar to VimOutliner and org-mode. KakOutliner would rock.

@laelath
Copy link
Contributor

laelath commented Aug 19, 2018

One way you could get around the problem of inconsistent behavior between interactive and script use could be to automatically expand a fold if a selection enters it.

@andreyorst
Copy link
Contributor

Why can't folded code be edited with multiple cursors in the same way how code is being edited off screen? When I edit 800 LOC file with 200+ carets I don't see whole file, but only part of it. I (and Kakoune) just know where text will be replaced, no need to show it on screen.

@mawww
Copy link
Owner

mawww commented Oct 17, 2018

@andreyorst The expected difficulty was that it was not clear what say j in normal mode would do on undisplayed text that could be potentially folded.

I believe this difficulty has been solved by deciding that:

  • normal mode keys should never take display information into account (with the exception of mouse clicks, which are fundamentally visual)
  • Any highligthing that hides buffer text should disable itself when the hidden text is partially selected (i.e. neither fully selected, nor not selected at all).

With that said, I believe we can implement folding by extending the replace-ranges highlighter, currently it assumes (but does not enforce IIRC) that we replace a range with text the same length, we need to extend it so that it can replace arbitrary text, and then its just a matter having an external script setting a range-specs option to <range to fold>|<text to display>.

@andreyorst
Copy link
Contributor

It would be super cool if subset of Emacs Org-mode could be implemented with folding, and #2536 feature

@andreyorst
Copy link
Contributor

Also, I would like to use folding in tagbar.kak to fold sections, in case user don't wan't to see Macros section for example. But I suppose it would be difficult, since after re-displaying the buffer, content' of *tagbar* is being fully replaced by new content, and folds will be opened up after that. This also could be the case when :format command is used on the file, I suppose that it should format folded text but don't open folds.

@aidam38
Copy link

aidam38 commented Mar 4, 2019

What is the timeline on this? When will we roughly have folding? It is the last thing that is keeping me from making Kakoune my 'life-time' editor, it is really crucial for LaTeX.

@andreyorst
Copy link
Contributor

Another good usecase for folding could be hiding all lines that doesn't contain a cursor. So for example you have 40 cursors in whole buffer, but you don't see them all. Instead of jumping between each with ( we could hide all lines that doesn't have a cursor, to see all cursors in one screen.

This could be done without folding if a temporary buffer was opened and lines with cursors vere copied there, and then pasted back when editing finished, but it is less convenient compared to working in single buffer.

@JJK96
Copy link
Contributor

JJK96 commented Nov 15, 2019

I've experimented a bit with the replace_ranges highlighter and have extended it to be able to replace multiple lines.

currently it assumes (but does not enforce IIRC) that we replace a range with text the same length

I have not really solved this problem yet, if you try to replace multiple ranges the content shifts in some way. I think this could be solved with the update_ranges function, but I cannot get it to work.

JJK96@578fdd9

Full branch (highlight)

EDIT: I see that update_ranges only notices changes to the actual buffer, not to the display_buffer.

@cipharius
Copy link
Contributor

cipharius commented May 6, 2020

How about approaching code folds and buffer narrowing in general using concept such as virtual buffers/buffer views?

The proposal is to allow taking live slices of a buffer and join them in a new virtual buffer, which would be a projection of the original buffer. Think multi-selections that we already have, but linked to a new buffer like context. Changes in the virtual buffer affect the source buffer and changes in source buffer affect the virtual buffer.

This would bypass the issue of disconnection between underlying data and the presented view. Such virtual buffers wouldn't need special command handling, since the data visible in such buffer is exactly what it contains, except it is composed from regions of it's source buffer.

I think it is noteworthy to point out that Emacs also has similar concept known as buffer narrowing.

EDIT: After browsing kakoune's code base for a bit, it seems that Window is already such "view on a buffer" concept. Perhaps extending window's capabilities is the way?

@andreyorst
Copy link
Contributor

andreyorst commented May 7, 2020 via email

@Delapouite
Copy link
Contributor

@cipharius You've described a virtual buffer made of slices from an existing buffer which is quite nice. This same concept could also be applied the other way around: build a virtual buffer which is the concatenation of more than one buffers.

Example: if I'm working on a web frontend component, which is made of 3 files foo.js, foo.html and foo.css. But then I found that I made the same typo in each of those files. So what I could do, is to temporarily merge them into a virtual buffer foo, do my typo fix with something like %sbar<ret>cqux<esc> and then save and close this virtual buffer. It means that I have successfully been able to do a "search-replace" in a set of specific files without learning any new Kakoune editing concept except the "virtual buffer" one.

In the end virtual buffers are cool for narrowing and widening.

@danr
Copy link
Contributor

danr commented May 7, 2020

One can get a makeshift virtual buffer for replacing across several files using https://github.com/occivink/kakoune-find . Nevertheless built-in virtual buffers would be really interesting.

@mawww
Copy link
Owner

mawww commented May 10, 2020

954373d Added support for multi-line replace ranges, which should provide a backend for code folding.

As said in the commit message, it likely has rough edges remaining, but those can be fixed as we find them.

@Screwtapello
Copy link
Contributor

Rough edges in the current replace-ranges implementation include #3644 and #3689.

@joemaro
Copy link

joemaro commented Oct 24, 2020

i really am looking forward to be able to do folding in kakoune

@Kabouik
Copy link
Contributor

Kabouik commented Feb 9, 2021

Same here!

@flexagoon
Copy link

Same, I really want folding

@joemaro
Copy link

joemaro commented Jun 26, 2023

Any news or plans on this? Or plugins that make this possible?

@jtrv
Copy link
Contributor

jtrv commented Jul 25, 2023

#453 (comment)

...hiding all lines that doesn't contain a cursor. So for example you have 40 cursors in whole buffer, but you don't see them all. Instead of jumping between each with ( we could hide all lines that doesn't have a cursor, to see all cursors in one screen.

https://github.com/caksoylar/kakoune-focus serves this case just in case anyone comes across this.

still hoping for code-folding 🤞🏽

@nandoflorestan
Copy link

I just wanted to mention, in passing, that in 2024 people still want code folding, including me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests