Fork me on GitHub
#spacemacs
<
2018-04-17
>
troglotit09:04:11

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:

jeff.terrell12:04:46

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.

ag17:04:13

have you tried different folding method? say origami?

vijaykiran18:04:39

There is also hs-mode C-c @

jeff.terrell19:04:34

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

ag20:04:38

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

ag20:04:58

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
jeff.terrell20:04:27

@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!

ag22:04:13

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

ag22:04:51

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

ag22:04:38

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.

jeff.terrell22:04:02

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.

jeff.terrell22:04:18

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

ag22:04:47

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

ag22:04:47

here's how you can set it up:

(use-package edit-indirect
    :config
    (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

jeff.terrell17:04:13

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!

ag19:04:38

why what's necessary?

jeff.terrell19:04:59

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

ag02:04:45

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

đź‘Ť 4
jeff.terrell13:04:18

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?

jeff.terrell14:04:27

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?

ag17:04:19

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

ag17:04:43

then narrowing into an indirect buffer is nice

ag17:04:54

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

jeff.terrell18:04:04

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

ag18:04:32

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.

ag18:04:40

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