From: Zachary Yedidia Date: Sat, 21 Aug 2021 21:58:30 +0000 (-0400) Subject: Improve comments X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=0914f158c2f57ee47e2a9fdf2994b9a015cd300e;p=micro.git Improve comments --- diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 4ecf2533..6f5b2c7f 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -16,17 +16,23 @@ import ( "github.com/zyedidia/tcell/v2" ) +// BufKeyAction represents an action bound to a key. type BufKeyAction func(*BufPane) bool + +// BufMouseAction is an action that must be bound to a mouse event. type BufMouseAction func(*BufPane, *tcell.EventMouse) bool +// BufBindings stores the bindings for the buffer pane type. var BufBindings *KeyTree +// BufKeyActionGeneral makes a general pane action from a BufKeyAction. func BufKeyActionGeneral(a BufKeyAction) PaneKeyAction { return func(p Pane) bool { return a(p.(*BufPane)) } } +// BufMouseActionGeneral makes a general pane mouse action from a BufKeyAction. func BufMouseActionGeneral(a BufMouseAction) PaneMouseAction { return func(p Pane, me *tcell.EventMouse) bool { return a(p.(*BufPane), me) @@ -37,6 +43,7 @@ func init() { BufBindings = NewKeyTree() } +// LuaAction makes a BufKeyAction from a lua function. func LuaAction(fn string) func(*BufPane) bool { luaFn := strings.Split(fn, ".") if len(luaFn) <= 1 { @@ -233,6 +240,7 @@ type BufPane struct { searchOrig buffer.Loc } +// NewBufPane creates a new buffer pane with the given window. func NewBufPane(buf *buffer.Buffer, win display.BWindow, tab *Tab) *BufPane { h := new(BufPane) h.Buf = buf @@ -247,15 +255,19 @@ func NewBufPane(buf *buffer.Buffer, win display.BWindow, tab *Tab) *BufPane { return h } +// NewBufPaneFromBuf constructs a new pane from the given buffer and automatically +// creates a buf window. func NewBufPaneFromBuf(buf *buffer.Buffer, tab *Tab) *BufPane { w := display.NewBufWindow(0, 0, 0, 0, buf) return NewBufPane(buf, w, tab) } +// SetTab sets this pane's tab. func (h *BufPane) SetTab(t *Tab) { h.tab = t } +// Tab returns this pane's tab. func (h *BufPane) Tab() *Tab { return h.tab } @@ -266,9 +278,8 @@ func (h *BufPane) ResizePane(size int) { h.tab.Resize() } -// PluginCB calls all plugin callbacks with a certain name and -// displays an error if there is one and returns the aggregrate -// boolean response +// PluginCB calls all plugin callbacks with a certain name and displays an +// error if there is one and returns the aggregrate boolean response func (h *BufPane) PluginCB(cb string) bool { b, err := config.RunPluginFnBool(cb, luar.New(ulua.L, h)) if err != nil { @@ -277,8 +288,7 @@ func (h *BufPane) PluginCB(cb string) bool { return b } -// PluginCBRune is the same as PluginCB but also passes a rune to -// the plugins +// PluginCBRune is the same as PluginCB but also passes a rune to the plugins func (h *BufPane) PluginCBRune(cb string, r rune) bool { b, err := config.RunPluginFnBool(cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r))) if err != nil { @@ -287,6 +297,7 @@ func (h *BufPane) PluginCBRune(cb string, r rune) bool { return b } +// OpenBuffer opens the given buffer in this pane. func (h *BufPane) OpenBuffer(b *buffer.Buffer) { h.Buf.Close() h.Buf = b @@ -294,23 +305,26 @@ func (h *BufPane) OpenBuffer(b *buffer.Buffer) { h.Cursor = b.GetActiveCursor() h.Resize(h.GetView().Width, h.GetView().Height) h.Relocate() - // Set mouseReleased to true because we assume the mouse is not being pressed when - // the editor is opened + // Set mouseReleased to true because we assume the mouse is not being + // pressed when the editor is opened h.mouseReleased = true - // Set isOverwriteMode to false, because we assume we are in the default mode when editor - // is opened + // Set isOverwriteMode to false, because we assume we are in the default + // mode when editor is opened h.isOverwriteMode = false h.lastClickTime = time.Time{} } +// ID returns this pane's split id. func (h *BufPane) ID() uint64 { return h.splitID } +// SetID sets the split ID of this pane. func (h *BufPane) SetID(i uint64) { h.splitID = i } +// Name returns the BufPane's name. func (h *BufPane) Name() string { n := h.Buf.GetName() if h.Buf.Modified() { @@ -421,6 +435,7 @@ func (h *BufPane) HandleEvent(event tcell.Event) { } } +// Bindings returns the current bindings tree for this buffer. func (h *BufPane) Bindings() *KeyTree { if h.bindings != nil { return h.bindings @@ -535,6 +550,7 @@ func (h *BufPane) DoRuneInsert(r rune) { } } +// VSplitIndex opens the given buffer in a vertical split on the given side. func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane { e := NewBufPaneFromBuf(buf, h.tab) e.splitID = MainTab().GetNode(h.splitID).VSplit(right) @@ -543,6 +559,8 @@ func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane { MainTab().SetActive(len(MainTab().Panes) - 1) return e } + +// HSplitIndex opens the given buffer in a horizontal split on the given side. func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane { e := NewBufPaneFromBuf(buf, h.tab) e.splitID = MainTab().GetNode(h.splitID).HSplit(bottom) @@ -552,16 +570,22 @@ func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane { return e } +// VSplitBuf opens the given buffer in a new vertical split. func (h *BufPane) VSplitBuf(buf *buffer.Buffer) *BufPane { return h.VSplitIndex(buf, h.Buf.Settings["splitright"].(bool)) } + +// HSplitBuf opens the given buffer in a new horizontal split. func (h *BufPane) HSplitBuf(buf *buffer.Buffer) *BufPane { return h.HSplitIndex(buf, h.Buf.Settings["splitbottom"].(bool)) } + +// Close this pane. func (h *BufPane) Close() { h.Buf.Close() } +// SetActive marks this pane as active. func (h *BufPane) SetActive(b bool) { h.BWindow.SetActive(b) if b { diff --git a/internal/action/globals.go b/internal/action/globals.go index e20f61ed..c4869c11 100644 --- a/internal/action/globals.go +++ b/internal/action/globals.go @@ -2,7 +2,10 @@ package action import "github.com/zyedidia/micro/v2/internal/buffer" +// InfoBar is the global info bar. var InfoBar *InfoPane + +// LogBufPane is a global log buffer. var LogBufPane *BufPane // InitGlobals initializes the log buffer and the info bar diff --git a/internal/buffer/search.go b/internal/buffer/search.go index 5be3128b..0ab6d0c8 100644 --- a/internal/buffer/search.go +++ b/internal/buffer/search.go @@ -91,10 +91,10 @@ func (b *Buffer) findUp(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) { l = util.SliceStart(l, end.X) } - all_matches := r.FindAllIndex(l, -1) + allMatches := r.FindAllIndex(l, -1) - if all_matches != nil { - match := all_matches[len(all_matches)-1] + if allMatches != nil { + match := allMatches[len(allMatches)-1] start := Loc{charpos + util.RunePos(l, match[0]), i} end := Loc{charpos + util.RunePos(l, match[1]), i} return [2]Loc{start, end}, true diff --git a/internal/util/util.go b/internal/util/util.go index f312ef56..6580145c 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -25,7 +25,7 @@ var ( // Version is the version number or commit hash Version = "0.0.0-unknown" - // Semantic version + // SemVersion is the Semantic version SemVersion semver.Version // CommitHash is the commit this version was built on CommitHash = "Unknown" @@ -421,14 +421,17 @@ func Clamp(val, min, max int) int { return val } +// IsNonAlphaNumeric returns if the rune is not a number of letter or underscore. func IsNonAlphaNumeric(c rune) bool { return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '_' } +// IsAutocomplete returns whether a character should begin an autocompletion. func IsAutocomplete(c rune) bool { return c == '.' || !IsNonAlphaNumeric(c) } +// ParseSpecial replaces escaped ts with '\t'. func ParseSpecial(s string) string { return strings.ReplaceAll(s, "\\t", "\t") }