def _select(self, cmd, choice): if runEmacsCmd("(md-at-start-of-erc-input-line)") == 't': # we're addressing them, include the colon EmacsText("%s: " % choice, lower=False, capitalCheck=False)() else: # we're referring to them, omit the colon EmacsText("%s" % choice, lower=False, capitalCheck=False)()
def _select(self, action, choice): if "go" in action["words"]: Cmd("(md-go-to-next \"%s\")" % choice)() elif "doog" in action["words"]: Cmd("(md-go-to-previous \"%s\")" % choice)() else: EmacsText("%s" % choice, lower=False)()
def _lisp(self, extras={}): command = " ".join(extras[self.verbRule]['words']) spokenKeyword = " ".join(extras[self.kwRule]['words']) writtenKeyword = self.writtenForms[spokenKeyword] if command == "key": EmacsText("%s" % writtenKeyword, lower=False)() elif command == "doog key": return "(md-go-to-previous \"%s\")" % writtenKeyword elif command == "go key": return "(md-go-to-next \"%s\")" % writtenKeyword else: assert False
import mdlog log = mdlog.getLogger(__name__) from Actions import Key from rules.ContextualRule import makeContextualRule from requirements.Emacs import IsEmacs from requirements.ModeRequirement import ModeRequirement from rules.emacs.common import emacsExtras, emacsDefaults from rules.emacs.Cmd import Cmd from rules.emacs.Text import EmacsText from protocol import RuleType IsErcMode = ModeRequirement(modes="erc-mode") _mapping = { "slash join [<text>]": EmacsText("/join #%(text)s"), "slash me [<text>]": EmacsText("/me %(text)s"), } ERCTextRule = makeContextualRule("ERCText", _mapping, emacsExtras, emacsDefaults, ruleType=RuleType.TERMINAL) ERCTextRule.context.addRequirement(IsEmacs) ERCTextRule.context.addRequirement(IsErcMode) _mapping = { "prior": Key("a-p"), "future": Key("a-n"), "smiley wink": EmacsText(";)"),
# text commands "capitalize" : Key("a-c"), "bigger" : Key("a-u"), "smaller" : Key("a-l"), # navigation commands "jump <charrule>" : Key("a-enter") + PressKey(), "jump char <charrule>" : Key("c-u,a-enter") + PressKey(), # save mark, almost never use, need to get used to #"push" : Key("c-space,c-space"), "snap [<i>]" : Key("c-u,c-space:%(i)d"), "big snap [<i>]" : Key("c-t,c-space:%(i)d"), "num <big>" : EmacsText("%(big)d"), "insert character" : Key("c-t,8,enter"), # "complete" : Minibuf("company-complete"), "open this" : Key("c-enter"), "shell command" : Minibuf("etc-shell-command"), "insert path" : InsertString("(buffer-file-name)"), "insert base name" : InsertString("(file-name-base (buffer-file-name))"), "insert buffer name" : InsertString("(buffer-name)"), "insert name without extension" : InsertString("(file-name-sans-extension (buffer-file-name))"), "insert directory" : InsertString("(file-name-directory (buffer-file-name))"), "insert extension" : InsertString("(file-name-extension (buffer-file-name))"), "insert username" : InsertString('(user-login-name)'), "switch previous" : Key("c-t,c-left"), "switch next" : Key("c-t,c-right"),
def emacsTextPrint(self, words): return EmacsText('')._print(words)
class EmacsUnderscore(Underscore): pass EmacsCamel._print = emacsTextPrint EmacsHyphen._print = emacsTextPrint EmacsUnderscore._print = emacsTextPrint _extras = [Dictation("text")] _defaults = {} _mapping = { "type <text>": EmacsText("%(text)s", False), } EmacsTypingRule = makeContextualRule("EmacsTypingRule", _mapping, _extras, _defaults, RuleType.TERMINAL) EmacsTypingRule.context.addRequirement(IsEmacs) _mapping = { "fasten <text>": EmacsText("%(text)s", False, spaceCheck=False), "cap fasten <text>": EmacsText("%(text)s", False, spaceCheck=False, allCaps=True), } EmacsFastenRule = makeContextualRule("EmacsFastenRule", _mapping, _extras, _defaults, RuleType.TERMINAL)
"unsetopt", ["/usr/bin/", "user bin"], "up", "valgrind", "wait", ["wc", "word count"], "which", "while", ["xargs", "X args"], ["zsh", "Z shell"], "crontab", "sleep", "time", [">", "stood out"], ["2>", "stood err"], ["&>", "stood both"], ] ShellKeywordRule = KeywordRule(["shell-mode", "sh-mode"], _keywords) _mapping = { "back [<i>]": Key("b,enter") * Repeat(extra="i"), "forward [<i>]": Key("f,enter") * Repeat(extra="i"), "surface [<i>]": (EmacsText("up") + Key("enter")) * Repeat(extra="i"), } ShellRule = makeContextualRule("Shell", _mapping, emacsExtras, emacsDefaults) ShellRule.context.addRequirement(IsEmacs) ShellRule.context.addRequirement( ModeRequirement(modes=["shell-mode", "sh-mode"]))
class EmacsCamel(Camel): pass class EmacsHyphen(Hyphen): pass class EmacsUnderscore(Underscore): pass EmacsCamel._print = emacsTextPrint EmacsHyphen._print = emacsTextPrint EmacsUnderscore._print = emacsTextPrint _extras = [ Dictation("text") ] _defaults = {} _mapping = { "type <text>" : EmacsText("%(text)s", False), } EmacsTypingRule = makeContextualRule("EmacsTypingRule", _mapping, _extras, _defaults, RuleType.TERMINAL) EmacsTypingRule.context.addRequirement(IsEmacs) _mapping = { "fasten <text>" : EmacsText("%(text)s", False, spaceCheck=False), "sky fasten <text>" : EmacsText("%(text)s", False, spaceCheck=False, allCaps=True), } EmacsFastenRule = makeContextualRule("EmacsFastenRule", _mapping, _extras, _defaults, RuleType.TERMINAL) EmacsFastenRule.context.addRequirement(IsEmacs) _mapping = { "camel <text>" : EmacsCamel("%(text)s"),
Key("a-l"), # navigation commands "jump <charrule>": Key("a-enter") + PressKey(), "jump char <charrule>": Key("c-u,a-enter") + PressKey(), # save mark, almost never use, need to get used to #"push" : Key("c-space,c-space"), "snap [<i>]": Key("c-u,c-space:%(i)d"), "big snap [<i>]": Key("c-t,c-space:%(i)d"), "num <big>": EmacsText("%(big)d"), "insert character": Key("c-t,8,enter"), # "complete" : Minibuf("company-complete"), "open this": Key("c-enter"), "shell command": Minibuf("etc-shell-command"), "insert path": InsertString("(buffer-file-name)"), "insert base name": InsertString("(file-name-base (buffer-file-name))"), "insert buffer name": InsertString("(buffer-name)"), "insert name without extension": InsertString("(file-name-sans-extension (buffer-file-name))"),