Skip to content

Commit

Permalink
Merge branch 'release/v1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Jul 15, 2016
2 parents 0b98a17 + f69f534 commit cc9412b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
6 changes: 4 additions & 2 deletions 1c-query.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
<dict>
<key>name</key>
<string>comment.line.double-slash.sdbl</string>
<key>match</key>
<string>(//.*)</string>
<key>begin</key>
<string>//</string>
<key>end</key>
<string>$</string>
</dict>
<dict>
<key>name</key>
Expand Down
12 changes: 8 additions & 4 deletions 1c.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,10 @@
<dict>
<key>name</key>
<string>comment.line.double-slash.bsl</string>
<key>match</key>
<string>(^\s*//.*$)</string>
<key>begin</key>
<string>^\s*//</string>
<key>end</key>
<string>$</string>
</dict>
<dict>
<key>name</key>
Expand All @@ -519,8 +521,10 @@
<dict>
<key>name</key>
<string>comment.line.double-slash.bsl</string>
<key>match</key>
<string>(//.*$)</string>
<key>begin</key>
<string>//</string>
<key>end</key>
<string>$</string>
</dict>
<dict>
<key>name</key>
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.5.0

* Добавлена возможность автоматически разворачивать конструкции вида `++`/`+=` и подобных по нажатию на `Tab`

## 1.4.12

* В варианты запуска скриптов oscript добавлен режим `-check`
Expand Down
20 changes: 20 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,25 @@
"operand": false
}
]
},
{
"keys": [
"tab"
],
"command": "expand_abbreviation",
"context":
[
{
"key": "selection_empty",
"operator": "equal",
"operand": true,
"match_all": false
},
{
"key": "selector",
"operator": "equal",
"operand": "source.bsl"
}
]
}
]
49 changes: 49 additions & 0 deletions expand_abbreviation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sublime
import sublime_plugin
import re


class ExpandAbbreviationCommand(sublime_plugin.TextCommand):

def run(self, edit):
view = sublime.active_window().active_view()
r = self.view.sel()[0]
empty_region = r.empty()
line = view.substr(sublime.Region(r.b, r.b - 2))
if empty_region and (line == "++" or
line == "--" or
line == "+=" or
line == "-=" or
line == "*=" or
line == "/=" or
line == "%="):
begin_line = self.view.full_line(r).a
region_text = sublime.Region(begin_line, self.view.sel()[0].b - 2)
prec_text = view.substr(region_text)
if re.search(r'([\w]+\s?)$', prec_text):
word = re.search(r'([\w]+\s?)$', prec_text).group(1)
postfix = ""
if line == "++":
postfix = " + 1;"
elif line == "--":
postfix = " - 1;"
elif line == "+=":
postfix = " + "
elif line == "-=":
postfix = " - "
elif line == "*=":
postfix = " * "
elif line == "/=":
postfix = " / "
elif line == "%=":
postfix = " % "
snippet = word + " = " + word + postfix
begin_word = self.view.sel()[0].b - len(word) - 2
region = sublime.Region(begin_word, self.view.sel()[0].b)
self.view.replace(edit, region, snippet)
return
elif not empty_region:
self.view.run_command('indent')
return

self.view.insert(edit, self.view.sel()[0].b, '\t')

0 comments on commit cc9412b

Please sign in to comment.