Skip to content

Commit 2c19761

Browse files
committed
Merge pull request #200 from zhengbli/issue199
Add "TypeScript Indent" tmPreferences files
2 parents 2f32d32 + f85febd commit 2c19761

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# [PackageDev] target_format: plist, ext: tmPreferences
2+
---
3+
name: TypeScript Indent
4+
uuid: 77966fa8-af34-4f1e-8535-e556d5063853
5+
scope: source.ts
6+
settings:
7+
bracketIndentNextLinePattern:
8+
>
9+
(?x)
10+
^ \s* \b(if|while|else)\b [^;]* $
11+
| ^ \s* \b(for)\b .* $
12+
decreaseIndentPattern: ^(.*\*/)?\s*\}.*$
13+
increaseIndentPattern: ^.*\{[^}"']*$

TypeScript Indent.tmPreferences

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>TypeScript Indent</string>
7+
<key>scope</key>
8+
<string>source.ts</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>bracketIndentNextLinePattern</key>
12+
<string>(?x)
13+
^ \s* \b(if|while|else)\b [^;]* $
14+
| ^ \s* \b(for)\b .* $
15+
</string>
16+
<key>decreaseIndentPattern</key>
17+
<string>^(.*\*/)?\s*\}.*$</string>
18+
<key>increaseIndentPattern</key>
19+
<string>^.*\{[^}"']*$</string>
20+
</dict>
21+
<key>uuid</key>
22+
<string>77966fa8-af34-4f1e-8535-e556d5063853</string>
23+
</dict>
24+
</plist>

typescript/commands/format.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ..libs.view_helpers import *
2+
from ..libs import log
23
from .base_command import TypeScriptBaseTextCommand
34

45

@@ -8,6 +9,8 @@ class TypescriptFormatOnKey(TypeScriptBaseTextCommand):
89
in the case of "\n", this is only called when no completion dialogue is visible
910
"""
1011
def run(self, text, key="", insert_key=True):
12+
log.debug("running TypescriptFormatOnKey")
13+
1114
if 0 == len(key):
1215
return
1316
check_update_view(self.view)
@@ -27,19 +30,22 @@ def run(self, text, key="", insert_key=True):
2730
class TypescriptFormatSelection(TypeScriptBaseTextCommand):
2831
"""Command to format the current selection"""
2932
def run(self, text):
33+
log.debug("running TypescriptFormatSelection")
3034
r = self.view.sel()[0]
3135
format_range(text, self.view, r.begin(), r.end())
3236

3337

3438
class TypescriptFormatDocument(TypeScriptBaseTextCommand):
3539
"""Command to format the entire buffer"""
3640
def run(self, text):
41+
log.debug("running TypescriptFormatDocument")
3742
format_range(text, self.view, 0, self.view.size())
3843

3944

4045
class TypescriptFormatLine(TypeScriptBaseTextCommand):
4146
"""Command to format the current line"""
4247
def run(self, text):
48+
log.debug("running TypescriptFormatLine")
4349
line_region = self.view.line(self.view.sel()[0])
4450
line_text = self.view.substr(line_region)
4551
if NON_BLANK_LINE_PATTERN.search(line_text):
@@ -53,6 +59,7 @@ def run(self, text):
5359

5460
class TypescriptFormatBrackets(TypeScriptBaseTextCommand):
5561
def run(self, text):
62+
log.debug("running TypescriptFormatBrackets")
5663
check_update_view(self.view)
5764
sel = self.view.sel()
5865
if len(sel) == 1:
@@ -70,6 +77,7 @@ def run(self, text):
7077

7178
class TypescriptPasteAndFormat(TypeScriptBaseTextCommand):
7279
def run(self, text):
80+
log.debug("running TypescriptPasteAndFormat")
7381
view = self.view
7482
check_update_view(view)
7583
regions_before_paste = regions_to_static_regions(view.sel())
@@ -93,6 +101,7 @@ class TypescriptAutoIndentOnEnterBetweenCurlyBrackets(TypeScriptBaseTextCommand)
93101
"""
94102

95103
def run(self, text):
104+
log.debug("running TypescriptAutoIndentOnEnterBetweenCurlyBrackets")
96105
view = self.view
97106
view.run_command('typescript_format_on_key', {"key": "\n"})
98107
loc = view.sel()[0].begin()

typescript/listeners/listeners.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def on_modified_with_info(self, view, info):
8484
EventHub.run_listeners("on_modified_with_info", view, info)
8585

8686
def post_on_modified(self, view):
87+
log.debug("post_on_modified")
8788
EventHub.run_listeners("post_on_modified", view)
8889

8990
def on_selection_modified(self, view):

0 commit comments

Comments
 (0)