Fork me on GitHub

Is there a way to quickly fold all top-level definitions like this: got it: zm and zr

parrot 4
Daniel Hines12:04:29

I've been missing this a ton! The best answer I found on so far was, "you don't need it"... :thinking_face:


OK, I'll tag on to that: anybody know a way to increase or decrease the fold level? I'm in a JS file that just defines a class, and zm closes the class entirely. I'd like to decrease the foldlevel by one such that the class is open but its methods are closed. In vim, zr and zm decrement and increment the foldlevel, and zR and zM have the same behavior as zr and zm in Spacemacs.


have you tried different folding method? say origami?


There is also hs-mode C-c @


@ag I haven't ever tried origami, although I'm aware of its existence? Do you recommend it?


it works better with some langs, I think there was an issue in spacemacs repo where someone proposed more "intelligent" way - ability to define modes handled by origami or evil


I've tried setting dotspacemacs-folding-method to 'origami but I think something didn't work right for me in sass files, I can't recall what was wrong with it. Maybe I'll give another try

đź‘Ť 4

@vijaykiran - What is this C-c @ voodoo? "hideshow" mode, huh? Interesting. Looks like I can get C-c @ C-l to do what I want, if I'm on a line that's inside the class but outside any method. I will keep that in mind, thanks!


@jeff.terrell also sometimes you can get more productive if you move away from collapse/expand workflow to "narrow/widen".


there's also edit-indirect package that lets you edit regions in an indirect buffer (similar to org-babel source blocks with C-c ').


that thing is also cool to edit things like docstrings and comments. In the project I'm currently working we try to add very informative docstrings, with examples and shit. And I sometimes edit them using that package in markdown or org mode.


I've been narrowing in my org file sometimes, and I like it. I have a harder time imagining how that wouldn't get in my way with source code, but maybe I'll have to try it out and see how it goes.


Interesting, about edit-indirect. I'll add that to my list of things to look into, thanks!


yeah, edit-indirect is interesting because when you narrow say on a defn, you can always go back to the main file and check things outside of the scope of than defn. But in that window you can be laser-focused just on that fn


here's how you can set it up:

(use-package edit-indirect
    (defun ag/edit-indirect-guess-mode (parent-buffer beg end)
      (let ((major (with-current-buffer parent-buffer major-mode)))
        (cond ((eq major 'clojurescript-mode) (org-mode))
              (t (funcall major)))))
    (setq edit-indirect-guess-mode-function 'ag/edit-indirect-guess-mode))
throw :ensure t key in there and you can play with it without even restarting Emacs. See in this example, edit-indirect for cljs files will open indirect buffer in org-mode


I don't understand why this is necessary yet, but I've made a note of it, and I'm hoping to look into edit-indirect more today. Thanks for sharing!


why what's necessary?


Setting the edit-indirect-guess-mode-function variable.


if you don't it will open indirect buffer in fundamental mode (If I remember it right)

đź‘Ť 4

I tried this from a source block in an org file (also TIL about , '—thanks for that incidental tip!). It opened in the same mode as the parent buffer—org-mode. When I changed the mode of the indirect buffer with SPC SPC emacs-lisp-mode, that changed the parent buffer too. Do you typically have different modes for parent vs. indirect buffers?


Also, as I'm thinking about it, I definitely buy the idea that narrowing will help one focus. But why not just narrow in the same buffer, instead of opening up an indirect buffer and narrowing there? I guess, if you can have different modes in each buffer, that seems like a good use case. But I'm struggling to come up with others. What do you think?


you can narrow in the same buffer, that's not a problem I do that a lot. but. When you're workflow is: - I wanna do edits in this particular function, but I also need to peak into things outside of it


then narrowing into an indirect buffer is nice


another use case, that I actually use very often: - I want to edit this docstring, but it's more convenient for me to do this in org-mode I can of course open scratch buffer, change the mode and then copy and paste it into the main file, but indirect buffer is faster


Gotcha. Thanks for explaining; those use cases make sense. đź‘Ť


ya, indirect buffers are a killing feature of Emacs. In general every other editor/IDE tries to bind things on a file. You have a file and associated environment where your changes are reflected in that file (when you save). Emacs keeps things detached from your filesystem and that's mindblowingly awesome.


Editing two different functions of the same file and treating them like they live in completely different files is something than no other editor does