[ create a new paste ] login | about

Link: http://codepad.org/bYP3Gpt8    [ raw code | fork ]

Python, pasted on Dec 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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, "-")


Create a new paste based on this one


Comments: