3 ms·
On a related note: The single thing I absolutely love in Visual Studio is how it handles C#'s #region statements. While they traditionally seem to be used mostl
by btschaegg 9y ago
On a related note: The single thing I absolutely love in Visual Studio is how it handles C#'s #region statements. While they traditionally seem to be used mostly to group class members (which doesn't really benefit the reader much, IMHO), one can use them to hide the fact that C# still has the tendency to be a bit verbous by reducing complicated methods to pseudo code.
I tend to use this pattern quite a lot:
#region Find the first Foo with Bar
var foo =
foos.Where(f => f.Bar)
.Distinct()
.OrderBy(f => f.Baz)
.FirstOrDefault();
#endregion
I still miss a similar feature in Emacs and Vim. There are similar folding markers one could use (say {{{ }}}), but they don't seem to work together with syntax-based folding.
- taeric 9y agoThis would be easy to code up in Emacs. If interested, I'll try and get an implementation out. (Currently on my phone...)
- btschaegg 9y agoIf you know how to do this, I would indeed be interested. I already pondered if it wouldn't be possible to merge multiple "folding strategies" if one would build some kind of interface with which multiple routines could basically communicate folds in a buffer. Say you have one routine scanning the syntax of the according language, one looking for folding markers and one for manual (Vim-style) folds. I guess it technically should be trivial to use all of them provided they are nested and don't intersect in weird ways (the latter could be resolved with some simple priorities).
- taeric 9y agoI wound up not getting the computer out. Looking at it right now to see if it would be as easy as I was thinking. Simply put, knowing how advanced org-mode can get with folds, this is likely trivial to do. (If you haven't played with it, I'd recommend taking a look. I don't have perfect examples, but http://taeric.github.io/DancingLinks.org http://taeric.github.io/DancingLinks.org is an example. Open that in emacs with org-mode and you will see that all of the source blocks can be folded together. For me, the source blocks are correctly colored, as well.) Quickly searching, I found https://www.emacswiki.org/emacs/FoldingMode https://www.emacswiki.org/emacs/FoldingMode, which seems to be a large start to this. There were also some other ideas that seem to get close. The basic idea I had was to just make a few functions that would: - Fold from current location to next #endregion - List all region/endregion's in the current buffer - Fold all region/endregion's in the current buffer The second of those felt trivial, since it is basically M-x occur #region\|#endregion. On top of that, I just need to learn how to actually make overlays and then the rest feels like it would fall into place easily enough. Edit: It occurs to me that I didn't show how to actually hide text, which I think is your question. Fastest way I can see is this (run this in your scratch buffer to see it in action): (let ((o (make-overlay 5 120))) (overlay-put o 'display "---hidden---")) To easily delete this particular overlay, if you make it, use: (let ((o (overlays-at 5))) (mapcar 'delete-overlay o)) So, the basic task that will need to be completed is finding the point position for the start and end of make-overlay.
- BJanecke 9y agoI think that's really cool, although // Find the first foo with bar foos.map(f => f.bar).uniq().orderBy(f => f.baz)[0] does the same basic thing, the ability to collapse and display intent is incredibly rad for lack of a better word