Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collapse Clojure docstrings in Spacemacs

I am using Spacemacs to write a program in Clojure. I would like to be able to collapse docstrings. I've tried selecting the docstring and pressing z a, however, that ends up collapsing the entire function body.

Specifically, I would like to be able to turn this:

(defn flip-and-vectorize
  "Returns a vector with the arguments flipped so that

   `(flip-and-vectorize 1 2)`

   returns the following vector

   `[2 1]`"
  [a b]
  [b a])

into something akin to this

(defn flip-and-vectorize
  "..."
  [a b]
  [b a])

Edit:

Even being able to collapse arbitrary lines would be acceptable; meaning the collapsed version of the above function could look something like this:

(defn flip-and-vectorize
  ...
  [a b]
  [b a])

This would mean that the collapsing logic would not need to understand what a "docstring" was, but would merely collapse the selected lines.

like image 495
jason Avatar asked Nov 08 '22 21:11

jason


1 Answers

There are two options:

  1. https://github.com/magnars/fold-this.el
  2. https://github.com/mrkkrp/vimish-fold

Both these packages support folding regions. As in, it can fold whatever is selected. The difference is the latter has more features. Especially the ability to remember folds even if you close and re-open a buffer.

To use them, follow the instructions on their github page. But, when it says to run package-install, instead in spacemacs you want to open your .spacemacs with SPC f e d and add the package to your dotspacemacs-additional-packages as such:

dotspacemacs-additional-packages '(fold-this)

Fold-this is more straightforward to setup, because it has less features.

In either case, you'll need to add your own keybindings. Or just select the region to fold, and go SPC SPC fold-this.

If using vimish-fold, you need to select the region to fold, and call SPC SPC vimish-fold to fold, and then you can use C-` thereafter to toggle the fold on and off. Or call SPC SPC vimish-fold-delete to remove the fold.

like image 128
Didier A. Avatar answered Nov 15 '22 07:11

Didier A.