有没有办法在sublimetext中设置折叠符号只读?

时间:2017-01-04 09:56:47

标签: sublimetext3 sublime-text-plugin

如果我删除sublimetext中的折叠符号,整个折叠文字会被删除吗? 我希望折叠符号在您删除它之前展开(就像在vim中一样)。 enter image description here

2 个答案:

答案 0 :(得分:3)

如果我理解你想要这种行为,那么如果你在折叠后面并按退格键,它会自动展开。这很容易存档(在版本3125+中),您只需要添加上下文和命令。

通过工具>>创建插件开发者>>新插件...... ,粘贴并保存:

import sublime
import sublime_plugin


class UnfoldBeforeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        for sel in view.sel():
            # fold the position before the selection
            view.unfold(sublime.Region(sel.b - 1))


class IsBehindFoldContext(sublime_plugin.EventListener):
    def on_query_context(self, view, key, operator, operand, match_all):
        if key != "is_behind_fold":
            return

        quantor = all if match_all else any

        result = quantor(
            view.is_folded(sel) and view.is_folded(sublime.Region(sel.b - 1))
            for sel in view.sel()
        )

        if operator == sublime.OP_EQUAL:
            result = result == operand
        elif operator == sublime.OP_NOT_EQUAL:
            result = result != operand
        else:
            raise Exception("Operator type not supported")

        return result

将此添加到您的keymap:

{
    "keys": ["backspace"],
    "command": "unfold_before",
    "context":
    [
        { "key": "selection_empty" },
        { "key": "is_behind_fold", "operator": "equal", "operand": true }
    ]
}

现在你应该没事。

答案 1 :(得分:1)

只需打开折叠,任何自定义折叠都将消失。对于自定义折叠,我的意思是使用CTRL + SHIFT + ]插入折叠。