lisp - Sublime Text and Clojure: Don't pair single quotes -


is there way syntax type define keyboard shortcuts, or set keyboard shortcut depend on syntax type (perhaps under "context") setting?

my quoted lists '(1 2 3) entered in this: '(1 2 3)' because sublime applies helpful (but not in case) behavior.

here relevant bit of default (osx).sublime-keymap file

// auto-pair single quotes { "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'$0'"}, "context":     [         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },         { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },         { "key": "preceding_text", "operator": "not_regex_contains", "operand": "['a-za-z0-9_]$", "match_all": true },         { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single", "match_all": true }     ] }, { "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'${0:$selection}'"}, "context":     [         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },         { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }     ] }, { "keys": ["'"], "command": "move", "args": {"by": "characters", "forward": true}, "context":     [         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },         { "key": "following_text", "operator": "regex_contains", "operand": "^'", "match_all": true }     ] }, 

you should able to, though it's kind of pain. first, have disable built in auto pairing (don't worry, when finished, auto pairing else should work). this, set following in user settings.

"auto_match_enabled": false 

then add following settings.

"my_auto_match_enabled": false 

next, need add new set of keybindings. did 1 posted, i'll explain did since may not obvious.

{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'${0:$selection}'"}, "context":     [         { "key": "setting.my_auto_match_enabled", "operator": "equal", "operand": true },         { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },         { "key": "selector", "operator": "not_equal", "operand": "source.clojure", "match_all": true }     ] } 

first, note switched first context key setting.auto_match_enabled setting.my_auto_match_enabled. next, added last context entry limit scope. this, snippet run when not in source.clojure scope. may have modify don't know scope name in clojure is, guessed =). have of single quote entries. now, because disabled built in auto pairing, have readd of entries well. in these entries, again change setting.auto_match_enabled setting.my_auto_match_enabled. after that, should work. note doesn't have my_auto_match_enabled, that's chose. may change see fit.

with being said, didn't test of this, comment if run issues.

explanation:

so might asking yourself, why need disable built in auto matching code? here's answer. if block auto complete in our user settings, using similar scoping rule, still fall default, inserting auto paired quotes regardless of in user folder. might thinking, if modify default settings file. though this, again inserting same context setting, have make sure restore file on subsequent updates. guess in end you. if edit default file, keep in mind if ever need revert, have change file again.

sublime text 3:

in st3, can perform modify "default" file. due change in how packages loaded in st3. rather needing extracted packages folder, plugins run directly .sublime-package files (which renamed zips). in addition, file in packages directory takes precedence on .sublime-package file. so, in st3, create packages/default/default (your os here).sublime-keymap, , add context line. safe subsequent updates updates no longer modify packages directory.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -