簡體   English   中英

帶有蜻蜓的模態命令

[英]Modal commands with Dragonfly

我正在使用vim一樣,是模態的。 我希望能夠使用命令啟用和禁用語法。

例如,如果我說link ,我有一個操作在屏幕上顯示帶有 2 個字母標簽的可能鏈接列表,因此我希望語法啟用僅接受 2 個字母單詞的模式。 特別是在說link之后,我不希望語法接受任何正常的命令,就像另一個link一樣。

這可能嗎?

啊哈! 我剛剛在別人的語法中發現了這個:

class PythonEnabler(CompoundRule):
    spec = "Enable Python"                  # Spoken command to enable the Python grammar.

    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        pythonBootstrap.disable()
        pythonGrammar.enable()
        print "Python grammar enabled"

class PythonDisabler(CompoundRule):
    spec = "switch language"                  # spoken command to disable the Python grammar.

    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        pythonGrammar.disable()
        pythonBootstrap.enable()
        print "Python grammar disabled"

pythonBootstrap = Grammar("python bootstrap")                
pythonBootstrap.add_rule(PythonEnabler())
pythonBootstrap.load()

pythonGrammar = Grammar("python grammar")
pythonGrammar.add_rule(PythonTestRule())
pythonGrammar.add_rule(PythonCommentsSyntax())
pythonGrammar.add_rule(PythonControlStructures())
pythonGrammar.add_rule(PythonDisabler())

所以基本上,你可以簡單地使用some_grammar.disable()some_grammar.enable

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM