Fix some golint warnings

This commit is contained in:
Zachary Yedidia 2017-10-01 12:42:23 -04:00
parent 28acfc6d3f
commit 46ced988eb
6 changed files with 42 additions and 36 deletions

View file

@ -15,7 +15,7 @@ type Colorscheme map[string]tcell.Style
// The current colorscheme // The current colorscheme
var colorscheme Colorscheme var colorscheme Colorscheme
// This takes in a syntax group and returns the colorscheme's style for that group // GetColor takes in a syntax group and returns the colorscheme's style for that group
func GetColor(color string) tcell.Style { func GetColor(color string) tcell.Style {
st := defStyle st := defStyle
if color == "" { if color == "" {

View file

@ -2,7 +2,7 @@ package highlight
import "regexp" import "regexp"
// DetectFiletype will use the list of syntax definitions provided and the filename and first line of the file // MatchFiletype will use the list of syntax definitions provided and the filename and first line of the file
// to determine the filetype of the file // to determine the filetype of the file
// It will return the corresponding syntax definition for the filetype // It will return the corresponding syntax definition for the filetype
func MatchFiletype(ftdetect [2]*regexp.Regexp, filename string, firstLine []byte) bool { func MatchFiletype(ftdetect [2]*regexp.Regexp, filename string, firstLine []byte) bool {

View file

@ -54,6 +54,7 @@ type Loc struct {
X, Y int X, Y int
} }
// Diff returns the distance between two locations
func Diff(a, b Loc, buf *Buffer) int { func Diff(a, b Loc, buf *Buffer) int {
if a.Y == b.Y { if a.Y == b.Y {
if a.X > b.X { if a.X > b.X {

View file

@ -28,6 +28,7 @@ func init() {
L.SetGlobal("import", luar.New(L, Import)) L.SetGlobal("import", luar.New(L, Import))
} }
// LoadFile loads a lua file
func LoadFile(module string, file string, data string) error { func LoadFile(module string, file string, data string) error {
pluginDef := "local P = {};" + module + " = P;setmetatable(" + module + ", {__index = _G});setfenv(1, P);" pluginDef := "local P = {};" + module + " = P;setmetatable(" + module + ", {__index = _G});setfenv(1, P);"
@ -39,40 +40,43 @@ func LoadFile(module string, file string, data string) error {
} }
} }
// Import allows a lua plugin to import a package
func Import(pkg string) *lua.LTable { func Import(pkg string) *lua.LTable {
switch pkg { switch pkg {
case "fmt": case "fmt":
return ImportFmt() return importFmt()
case "io": case "io":
return ImportIo() return importIo()
case "ioutil": case "io/ioutil":
return ImportIoUtil() return importIoUtil()
case "net": case "net":
return ImportNet() return importNet()
case "math": case "math":
return ImportMath() return importMath()
case "math/rand":
return importMathRand()
case "os": case "os":
return ImportOs() return importOs()
case "runtime": case "runtime":
return ImportRuntime() return importRuntime()
case "path": case "path":
return ImportPath() return importPath()
case "filepath": case "filepath":
return ImportFilePath() return importFilePath()
case "strings": case "strings":
return ImportStrings() return importStrings()
case "regexp": case "regexp":
return ImportRegexp() return importRegexp()
case "errors": case "errors":
return ImportErrors() return importErrors()
case "time": case "time":
return ImportTime() return importTime()
default: default:
return nil return nil
} }
} }
func ImportFmt() *lua.LTable { func importFmt() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "tErrorf", luar.New(L, fmt.Errorf)) L.SetField(pkg, "tErrorf", luar.New(L, fmt.Errorf))
@ -98,7 +102,7 @@ func ImportFmt() *lua.LTable {
return pkg return pkg
} }
func ImportIo() *lua.LTable { func importIo() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "Copy", luar.New(L, io.Copy)) L.SetField(pkg, "Copy", luar.New(L, io.Copy))
@ -122,7 +126,7 @@ func ImportIo() *lua.LTable {
return pkg return pkg
} }
func ImportIoUtil() *lua.LTable { func importIoUtil() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "ReadAll", luar.New(L, ioutil.ReadAll)) L.SetField(pkg, "ReadAll", luar.New(L, ioutil.ReadAll))
@ -133,7 +137,7 @@ func ImportIoUtil() *lua.LTable {
return pkg return pkg
} }
func ImportNet() *lua.LTable { func importNet() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "CIDRMask", luar.New(L, net.CIDRMask)) L.SetField(pkg, "CIDRMask", luar.New(L, net.CIDRMask))
@ -201,7 +205,7 @@ func ImportNet() *lua.LTable {
return pkg return pkg
} }
func ImportMath() *lua.LTable { func importMath() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "Abs", luar.New(L, math.Abs)) L.SetField(pkg, "Abs", luar.New(L, math.Abs))
@ -269,7 +273,7 @@ func ImportMath() *lua.LTable {
return pkg return pkg
} }
func ImportMathRand() *lua.LTable { func importMathRand() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "ExpFloat64", luar.New(L, rand.ExpFloat64)) L.SetField(pkg, "ExpFloat64", luar.New(L, rand.ExpFloat64))
@ -289,7 +293,7 @@ func ImportMathRand() *lua.LTable {
return pkg return pkg
} }
func ImportOs() *lua.LTable { func importOs() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "Args", luar.New(L, os.Args)) L.SetField(pkg, "Args", luar.New(L, os.Args))
@ -380,7 +384,7 @@ func ImportOs() *lua.LTable {
return pkg return pkg
} }
func ImportRuntime() *lua.LTable { func importRuntime() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "GC", luar.New(L, runtime.GC)) L.SetField(pkg, "GC", luar.New(L, runtime.GC))
@ -392,7 +396,7 @@ func ImportRuntime() *lua.LTable {
return pkg return pkg
} }
func ImportPath() *lua.LTable { func importPath() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "Base", luar.New(L, path.Base)) L.SetField(pkg, "Base", luar.New(L, path.Base))
@ -408,7 +412,7 @@ func ImportPath() *lua.LTable {
return pkg return pkg
} }
func ImportFilePath() *lua.LTable { func importFilePath() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "Join", luar.New(L, filepath.Join)) L.SetField(pkg, "Join", luar.New(L, filepath.Join))
@ -434,7 +438,7 @@ func ImportFilePath() *lua.LTable {
return pkg return pkg
} }
func ImportStrings() *lua.LTable { func importStrings() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "Contains", luar.New(L, strings.Contains)) L.SetField(pkg, "Contains", luar.New(L, strings.Contains))
@ -484,7 +488,7 @@ func ImportStrings() *lua.LTable {
return pkg return pkg
} }
func ImportRegexp() *lua.LTable { func importRegexp() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "Match", luar.New(L, regexp.Match)) L.SetField(pkg, "Match", luar.New(L, regexp.Match))
@ -499,7 +503,7 @@ func ImportRegexp() *lua.LTable {
return pkg return pkg
} }
func ImportErrors() *lua.LTable { func importErrors() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "New", luar.New(L, errors.New)) L.SetField(pkg, "New", luar.New(L, errors.New))
@ -507,7 +511,7 @@ func ImportErrors() *lua.LTable {
return pkg return pkg
} }
func ImportTime() *lua.LTable { func importTime() *lua.LTable {
pkg := L.NewTable() pkg := L.NewTable()
L.SetField(pkg, "After", luar.New(L, time.After)) L.SetField(pkg, "After", luar.New(L, time.After))

View file

@ -56,6 +56,7 @@ func Max(a, b int) int {
return b return b
} }
// FSize gets the size of a file
func FSize(f *os.File) int64 { func FSize(f *os.File) int64 {
fi, _ := f.Stat() fi, _ := f.Stat()
// get the size // get the size
@ -246,6 +247,7 @@ func lcs(a, b string) string {
return lcs return lcs
} }
// CommonSubstring gets a common substring among the inputs
func CommonSubstring(arr ...string) string { func CommonSubstring(arr ...string) string {
commonStr := arr[0] commonStr := arr[0]

View file

@ -9,6 +9,7 @@ import (
"github.com/zyedidia/tcell" "github.com/zyedidia/tcell"
) )
// The ViewType defines what kind of view this is
type ViewType struct { type ViewType struct {
kind int kind int
readonly bool // The file cannot be edited readonly bool // The file cannot be edited
@ -210,15 +211,10 @@ func (v *View) CanClose() bool {
//if char == 'y' { //if char == 'y' {
if choice { if choice {
v.Save(true) v.Save(true)
return true
} else {
return true
} }
} }
} else {
return true
} }
return false return true
} }
// OpenBuffer opens a new buffer in this view. // OpenBuffer opens a new buffer in this view.
@ -449,6 +445,7 @@ func (v *View) MoveToMouseClick(x, y int) {
v.Cursor.LastVisualX = v.Cursor.GetVisualX() v.Cursor.LastVisualX = v.Cursor.GetVisualX()
} }
// Execute actions executes the supplied actions
func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool { func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool {
relocate := false relocate := false
readonlyBindingsList := []string{"Delete", "Insert", "Backspace", "Cut", "Play", "Paste", "Move", "Add", "DuplicateLine", "Macro"} readonlyBindingsList := []string{"Delete", "Insert", "Backspace", "Cut", "Play", "Paste", "Move", "Add", "DuplicateLine", "Macro"}
@ -478,6 +475,7 @@ func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool {
return relocate return relocate
} }
// SetCursor sets the view's and buffer's cursor
func (v *View) SetCursor(c *Cursor) bool { func (v *View) SetCursor(c *Cursor) bool {
if c == nil { if c == nil {
return false return false
@ -682,6 +680,7 @@ func (v *View) openHelp(helpPage string) {
} }
} }
// DisplayView draws the view to the screen
func (v *View) DisplayView() { func (v *View) DisplayView() {
if v.Buf.Settings["softwrap"].(bool) && v.leftCol != 0 { if v.Buf.Settings["softwrap"].(bool) && v.leftCol != 0 {
v.leftCol = 0 v.leftCol = 0