有什么代码折叠插件推荐吗?

基于缩进就可以,目前自己用的是 yafolding,想知道是否还有更好的选择。

我一直用origami:

自己的配置(其实是抄的):

(add-hook 'prog-mode-hook 'origami-mode)
(with-eval-after-load 'origami
    (define-key origami-mode-map (kbd "C-c f") 'origami-recursively-toggle-node)
    (define-key origami-mode-map (kbd "C-c F") 'origami-toggle-all-nodes))

我现在用 evil 的折叠(其实背后也是 hideshow),不足的地方自己稍微改一改,够应付常见的语言。不仅可以折叠方法,还可以折叠块(ifelse 等等),使用很灵活,效率也没有问题。

最常用的方法是 hs-hide-level,即按当前光标位置的 level 折叠所有相邻的结构。

当我想看整个文件的大纲:

class Foo {
    function bar () {...}
    function quux () {...}
}

当我想总览某个比较复杂的函数实现:

    function bar () {
        if (cond) {...}
        else {...}
    }
3 个赞

我看代码结构都是在配对的() {}之间跳来跳去,用陈斌的evil-matchit,ruby的ifend之间也能跳,刚测了一下python,if没有end也能首尾跳,但是最近有用到coffeescript,没有end,跳不了 :cry: ,下次试试折叠

給language client實現textDocument/foldingRange

https://microsoft.github.io/language-server-protocol/specification

export interface FoldingRange {

	/**
	 * The zero-based line number from where the folded range starts.
	 */
	startLine: number;

	/**
	 * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
	 */
	startCharacter?: number;

	/**
	 * The zero-based line number where the folded range ends.
	 */
	endLine: number;

	/**
	 * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
	 */
	endCharacter?: number;

	/**
	 * Describes the kind of the folding range such as `comment' or 'region'. The kind
	 * is used to categorize folding ranges and used by commands like 'Fold all comments'. See
	 * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
	 */
	kind?: string;
}

yafolding 其实挺不错的, 用 Emacs, 代码缩进什么的, 不管那个 mode, 应该都不是问题吧? 只要缩进正确, yafolding 就正确.

origami怎么折叠C++注释?