codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
import sublime, sublimeplugin, re class MagicHyphenCommand(sublimeplugin.TextCommand): def run(self, view, args): hyphen = args[0] for region in view.sel(): if region.empty(): pos = region.a y, x = view.rowcol(pos) if x == 0: view.insert(pos, hyphen) else: char = view.substr(pos - 1) if re.search("\w", char) == None: view.insert(pos, hyphen) else: if hyphen == "-": view.insert(pos, "_") else: view.insert(pos, "-")
Private
[
?
]
Run code
Submit