reddit / emacs
Actionable, code folding in emacs fringe?
rufusthedogwoof · 2022-04-06 01:31
Hi,
I read quite a bit more than I write and would enjoy a feature with the ergonomics such as the following:
[https://emacs.stackexchange.com/questions/112/actionable-code-folding-in-emacs-fringe](https://emacs.stackexchange.com/questions/112/actionable-code-folding-in-emacs-fringe)
Has anything changed with "click-able folds" since the above question 7 years ago?
Just curious how folks solve this, or if I'm out of the ordinary for missing this functionality.
(P.S. I'm on doom emacs and was thinking about attempting to bind mouse clicks to hideshow/vimish-fold for different languages but I guessed with my elisp skills it would get unwieldy fast...)
Any tips appreciated, thanks in advance.
ManWhoTwistsAndTurns · 2022-04-06 01:41
I tried making a modifier key + mouse button keymap to toggle folds, and rarely use it, but maybe you'll get some play with it
(global-set-key (kbd "s-<mouse-1>") 'evil-toggle-fold)
Substitute 'evil-toggle-fold with whatever function you need. "s-" in the kbd s-exp stands for super, so you might want to make that C (for control) or m (for alt/meta).
I agree that clicking on an icon in the fringe/gutter, like in Sublime Text is easier and more pleasing. Even better would be a hover-preview in addition.
rufusthedogwoof · 2022-04-06 03:54
Thanks for that, i think i tried that a few years ago and remembered being annoyed i had to have the point in the exact right spot.
At the moment i'm going to bind some folding and sexp movement to the tool-bar so maybe I can just get acclimated to a new (read-only) code-base with a mouse. My fingers get tired.
andreyorst · 2022-04-06 07:04
I've searched this topic about a year ago and it seems that `hideshowvis` was still the only option back then. Never touched it since, as I'm not really using folding, just was curious, because one of my colleagues wanted to switch to Emacs, but they wanted code folding buttons like in their IDE.
One problem is that there's no dedicated place for these buttons to go, e.g. there's no guarantee that some other package will not draw something in the fringe in the same cell as the button. Something like CIDER can draw top-level evaluation markers on the fringe, right where such folding button would be. Of course it's often configurable, but conflicts still may occur. Especially if someone uses a git-gutter style package, that displays its status in the fringe.
hkjels · 2022-04-06 07:15
Have you tried replacing the arrows or widening the fringe?
rufusthedogwoof · 2022-04-06 16:06
Hmmm good to know thanks. I’m nearly full time in cider.
I’m dabbling with some of the lsp features in treemacs… it seems to let me study a codebase with a mouse when I’m in “read-only/study” mode.
Any keybindings I absolutely need I have either shoved into a tool-bar icon or have bound to my left hand… I’m a right handed mouse user.
It’s not bad but maybe could be better. Maybe I don’t need clickable folds….
Thanks again emacs friend.
rufusthedogwoof · 2022-04-06 16:08
I did a while back… maybe I’ll try this again. Thanks.
rufusthedogwoof · 2022-04-06 16:09
I did a while back… maybe I’ll try this again. Thanks.
andreyorst · 2022-04-06 16:53
well, as others pointed out you can use hideshow's `S-<mouse-2>` to get clickable folding.
crawsphi · 2022-04-06 17:00
They may not fit all your needs, but just in case you're not aware: check out narrowing (for example `C-x n d` - `narrow-to-defun`) and `selective-display`. They are built in and allow you to quickly hide various portions of the buffer.
hmelman · 2022-04-07 00:10
I use outline-minor-mode in text and code buffers. New with Emacs 28 are org-like bindings for cycling. So S-TAB cycles the whole buffer through hidden/headers/all and I think TAB on the heading show/hides the tree below it. Much easier than remembering the bindings of all the original outline-minor-mode commands and IMHO easier than mousing to the fringe.
xenodium · 2022-04-08 08:31
Seen [https://github.com/billsacks/yafolding](https://github.com/billsacks/yafolding) ?
rufusthedogwoof · 2022-04-08 13:25
Thank you I’ll give that one a try as well.
samrjack · 2022-12-15 21:03
If you're still looking for some folding indicators, the [ts-fold](https://github.com/emacs-tree-sitter/ts-fold#%EF%B8%8F-indicators-mode) package has some nice ones. The only catch is that it uses tree-sitter which isn't helpful if your desired lang isn't supported.
rufusthedogwoof · 2022-12-16 16:48
thanks for that, i'll try it out, i desperately need org-mode folding however, doesn't look like that is [supported](https://github.com/emacs-tree-sitter/ts-fold#-supported-languages) at the moment.