Skip to content

Commit 5d44f2e

Browse files
committed
Add command to reformat the current file
To format the current file via [yapf](https://github.com/google/yapf) use the keyboard shortcut `^` + `⇧` + `H`.
1 parent a74e54f commit 5d44f2e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Commands/Reformat Document.tmCommand

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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>beforeRunningCommand</key>
6+
<string>nop</string>
7+
<key>command</key>
8+
<string>#!/bin/bash
9+
10+
. "$TM_SUPPORT_PATH/lib/bash_init.sh"
11+
12+
yapf_output=`"${TM_YAPF:-yapf}" --style="${TM_YAPF_STYLE:-pep8}" &lt; /dev/stdin`
13+
exit_status=$?
14+
15+
if [ $exit_status -eq 0 ]; then
16+
exit_show_tool_tip "File is already formatted"
17+
elif [ $exit_status -eq 2 ]; then
18+
echo "$yapf_output"
19+
else
20+
exit_show_tool_tip
21+
fi
22+
</string>
23+
<key>input</key>
24+
<string>selection</string>
25+
<key>inputFormat</key>
26+
<string>text</string>
27+
<key>keyEquivalent</key>
28+
<string>^H</string>
29+
<key>name</key>
30+
<string>Reformat Document</string>
31+
<key>outputCaret</key>
32+
<string>interpolateByChar</string>
33+
<key>outputFormat</key>
34+
<string>text</string>
35+
<key>outputLocation</key>
36+
<string>replaceInput</string>
37+
<key>requiredCommands</key>
38+
<array>
39+
<dict>
40+
<key>command</key>
41+
<string>yapf</string>
42+
<key>locations</key>
43+
<array>
44+
<string>/usr/local/bin/yapf</string>
45+
</array>
46+
</dict>
47+
</array>
48+
<key>scope</key>
49+
<string>source.python</string>
50+
<key>uuid</key>
51+
<string>CA6F6269-AD9D-46DB-A9A1-7A9987C4E6EA</string>
52+
<key>version</key>
53+
<integer>2</integer>
54+
</dict>
55+
</plist>

info.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<string>504278F6-89F4-11D9-9326-000D93B6E43C</string>
3333
<string>09E7930D-E706-4C90-B37E-5B95E1D97949</string>
3434
<string>44C9C59C-89F9-11D9-9326-000D93B6E43C</string>
35+
<string>CA6F6269-AD9D-46DB-A9A1-7A9987C4E6EA</string>
3536
<string>95FFEECE-73E4-4B33-9CAE-1641C62FFBC0</string>
3637
<string>------------------------------------</string>
3738
<string>095E8342-FAED-4B95-A229-E245B0B601A7</string>

0 commit comments

Comments
 (0)