如何在Spacemacs中折叠Clojure文档字符串

jas*_*son 5 clojure code-folding spacemacs

我正在使用Spacemacs在Clojure中编写程序.我希望能够折叠docstrings.我已经尝试选择文档字符串并按下z a,但最终会折叠整个函数体.

具体来说,我希望能够解决这个问题:

(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])
Run Code Online (Sandbox Code Playgroud)

变成类似于此的东西

(defn flip-and-vectorize
  "..."
  [a b]
  [b a])
Run Code Online (Sandbox Code Playgroud)

编辑:

即使能够折叠任意线也是可以接受的; 意味着上面函数的折叠版本看起来像这样:

(defn flip-and-vectorize
  ...
  [a b]
  [b a])
Run Code Online (Sandbox Code Playgroud)

这意味着折叠逻辑不需要理解"文档字符串"是什么,而只是折叠选定的行.

Did*_* A. 1

有两种选择:

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

这两个包都支持折叠区域。例如,它可以折叠任何选择的内容。不同之处在于后者具有更多功能。尤其是即使您关闭并重新打开缓冲区也能记住折叠的能力。

要使用它们,请按照其 github 页面上的说明进行操作。但是,当它说运行 package-install 时,您需要在 spacemacs 中打开.spacemacsSPC f e d添加软件包,dotspacemacs-additional-packages如下所示:

dotspacemacs-additional-packages '(fold-this)
Run Code Online (Sandbox Code Playgroud)

折叠 - 设置起来更简单,因为它的功能较少。

无论哪种情况,您都需要添加自己的键绑定。或者只需选择要折叠的区域,然后转到SPC SPC fold-this

如果使用 vimish-fold,您需要选择要折叠的区域,并调用SPC SPC vimish-fold折叠,然后您可以使用C-`此后打开和关闭折叠。或者打电话SPC SPC vimish-fold-delete取消折叠。