Skip to content

Commit

Permalink
fix broken commenting when the Go package is disabled
Browse files Browse the repository at this point in the history
close #797
  • Loading branch information
DisposaBoy committed Dec 8, 2017
1 parent 1fd23d5 commit 749ac22
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 14 deletions.
39 changes: 39 additions & 0 deletions Comments.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>source.go</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string>// </string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_START_2</string>
<key>value</key>
<string>/*</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_END_2</string>
<key>value</key>
<string>*/</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_DISABLE_INDENT_2</string>
<key>value</key>
<string>yes</string>
</dict>
</array>
</dict>
</dict>
</plist>
54 changes: 54 additions & 0 deletions Indentation Rules.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Indentation Rules</string>
<key>scope</key>
<string>source.go</string>
<key>settings</key>
<dict>
<key>decreaseIndentPattern</key>
<string><![CDATA[(?x)
^ # start of line
(.*\*/)? # skip comments if present
( # three possibilities
\s* \} # whitespace and a closing curly brace
( # capture:
[^}{"']* \{ # anything other than curly braces or quotes, then open curly
)? # (optional)
[;\s]*? # any whitespace or semicolons
|
(?:\s* (case|default).*:) # case statements pop back one indent
|
(?: \) (?<! \( ) ) # closing braces not preceded by opening braces
)
(//.*|/\*.*\*/\s*)? # skip any comments (optional)
$ # end of line
]]></string>
<key>increaseIndentPattern</key>
<string>(?x)
^
(?: .* \*/ )? # skip any comments
(?:
(.* \{ [^}"'\n]*) # lines containing an open curly but no quotes or close curly
| # OR
(?:\s* (case|default).*:) # case statements
| # OR
(.* \( [^)"'\n]*) # lines containing an open brace but no quotes or close brace
)
(//.*|/\*.*\*/\s*)? # skip any comments (optional)
$
</string>
<!--
<key>indentNextLinePattern</key>
<string>(?x)^
(?! .* [;:{}] # do not indent when line ends with ;, :, {, or }
\s* (//|/[*] .* [*]/ \s* $) # …account for potential trailing comment
)
</string>
-->
<key>unIndentedLinePattern</key>
<string>^\s*((/\*|\*/|//|import\b.*|package\b.*).*)?$</string>
</dict>
</dict>
</plist>
49 changes: 35 additions & 14 deletions something_borrowed/Go/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,47 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
)

type dlFile struct {
name string
url string
dirs []string
}

func main() {
urls := map[string]string{
"Comments.tmPreferences": "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Comments.tmPreferences",
"Indentation Rules.tmPreferences": "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Indentation%20Rules.tmPreferences",
"Go.sublime-syntax": "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Go.sublime-syntax",
urls := []dlFile{
{
name: "Comments.tmPreferences",
url: "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Comments.tmPreferences",
dirs: []string{"../..", "."},
},
{
name: "Indentation Rules.tmPreferences",
url: "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Indentation%20Rules.tmPreferences",
dirs: []string{"../..", "."},
},
{
name: "Go.sublime-syntax",
url: "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Go.sublime-syntax",
dirs: []string{"."},
},
}
for name, url := range urls {
dl(name, url)
for _, f := range urls {
dl(f)
}

cmd := exec.Command("git", "status", ".")
cmd := exec.Command("git", "status", "--short")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}

func dl(name, url string) {
fmt.Printf("Sync %s: ", name)
func dl(f dlFile) {
fmt.Printf("Sync %s: ", f.name)

resp, err := http.Get(url)
resp, err := http.Get(f.url)
if err != nil {
fmt.Println(err)
return
Expand All @@ -45,10 +64,12 @@ func dl(name, url string) {
return
}

ioutil.WriteFile(name, content, 0644)
if err != nil {
fmt.Println(err)
return
for _, dir := range f.dirs {
ioutil.WriteFile(filepath.Join(dir, f.name), content, 0644)
if err != nil {
fmt.Println(err)
return
}
}

fmt.Println("ok")
Expand Down

0 comments on commit 749ac22

Please sign in to comment.