]> git.lizzy.rs Git - micro.git/commitdiff
Improve comments
authorZachary Yedidia <zyedidia@gmail.com>
Sat, 21 Aug 2021 21:58:30 +0000 (17:58 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Sat, 21 Aug 2021 21:58:30 +0000 (17:58 -0400)
internal/action/bufpane.go
internal/action/globals.go
internal/buffer/search.go
internal/util/util.go

index 4ecf25335ad2d446789147b77e7e5f7a5b4289c8..6f5b2c7fb37ad444e4af859826de7de85c06e9a8 100644 (file)
@@ -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 {
index e20f61edfcadfa48e4a449cb34da5f1108fc3f18..c4869c11662d3a9d6faa9c5ba48033284dd9dd5c 100644 (file)
@@ -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
index 5be3128bc3111f4894fb4b74bb0a145dc7a0fb89..0ab6d0c8fde49aca3b6bbbf0f13f6b0715352075 100644 (file)
@@ -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
index f312ef56e91c7bfa4eb76ea60ddb89da5c846ce7..6580145ce4320129e1b56af989050630ae884015 100644 (file)
@@ -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")
 }