Skip to content

Commit

Permalink
golint documentation tweaks. No functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
quarnster committed Sep 28, 2015
1 parent 551dc58 commit 06ae817
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
15 changes: 13 additions & 2 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (
)

type (
// Action defines an interface for Apply-ing and Undo-ing
// an action.
Action interface {
Apply()
Undo()
}

// CompositeAction is just a structure containing multiple Action items
CompositeAction struct {
actions []Action
}
Expand All @@ -38,32 +41,35 @@ func (ca CompositeAction) String() string {
return ret
}

// Apply all the sub-actions in order of this CompositeAction
func (ca *CompositeAction) Apply() {
for _, a := range ca.actions {
a.Apply()
}
}

// Undo all the sub-actions in reverse order of this CompositeAction
func (ca *CompositeAction) Undo() {
l := len(ca.actions) - 1
for i := range ca.actions {
ca.actions[l-i].Undo()
}
}

// Adds the action to this CompositeAction, without first
// Add adds the action to this CompositeAction, without first
// executing the action
func (ca *CompositeAction) Add(a Action) {
ca.actions = append(ca.actions, a)
}

// Executes the provided action and then adds
// AddExec executes the provided action and then adds
// the action to this CompositeAction
func (ca *CompositeAction) AddExec(a Action) {
ca.Add(a)
ca.actions[len(ca.actions)-1].Apply()
}

// Len returns the number of sub-actions this CompositeAction object contains
func (ca *CompositeAction) Len() int {
return len(ca.actions)
}
Expand Down Expand Up @@ -95,14 +101,19 @@ func (ea eraseAction) String() string {
return fmt.Sprintf("erase %v", ea.region)
}

// NewEraseAction returns a new action that erases the given region in the given buffer
func NewEraseAction(b Buffer, region Region) Action {
return &eraseAction{insertAction{buffer: b}, region}
}

// NewInsertAction returns a new action that inserts the given string value at
// position point in the Buffer b.
func NewInsertAction(b Buffer, point int, value string) Action {
return &insertAction{b, Clamp(0, b.Size(), point), []rune(value)}
}

// NewReplaceAction returns a new action that replaces the data in the given
// buffers region with the provided value
func NewReplaceAction(b Buffer, region Region, value string) Action {
return &CompositeAction{[]Action{
NewEraseAction(b, region),
Expand Down
24 changes: 12 additions & 12 deletions regionset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type RegionSet struct {
lock sync.Mutex
}

// Adjusts all the regions in the set
// Adjust adjusts all the regions in the set
func (r *RegionSet) Adjust(position, delta int) {
r.lock.Lock()
defer r.lock.Unlock()
Expand Down Expand Up @@ -75,15 +75,15 @@ func (r *RegionSet) flush() {
}
}

// Removes the given region from the set
// Substract (sic #5) removes the given region from the set
func (r *RegionSet) Substract(r2 Region) {
r3 := r.Cut(r2)
r.lock.Lock()
defer r.lock.Unlock()
r.regions = r3.regions
}

// Adds the given region to the set
// Add adds the given region to the set
func (r *RegionSet) Add(r2 Region) {
r.lock.Lock()
defer r.lock.Unlock()
Expand All @@ -98,27 +98,27 @@ func (r *RegionSet) Add(r2 Region) {
r.merge(ref, ov)
}

// Clears the set
// Clear clears the set
func (r *RegionSet) Clear() {
r.lock.Lock()
defer r.lock.Unlock()
r.regions = r.regions[0:0]
r.flush()
}

// Gets the region at index i
// Get returns the region at index i
func (r *RegionSet) Get(i int) Region {
r.lock.Lock()
defer r.lock.Unlock()
return r.regions[i]
}

// Returns the number of regions contained in the set
// Len returns the number of regions contained in the set
func (r *RegionSet) Len() int {
return len(r.regions)
}

// Adds all regions in the array to the set
// AddAll adds all regions in the array to the set, merging any overlapping regions into a single region
func (r *RegionSet) AddAll(rs []Region) {
r.lock.Lock()
defer r.lock.Unlock()
Expand Down Expand Up @@ -146,7 +146,7 @@ func (r *RegionSet) AddAll(rs []Region) {
}
}

// Returns whether the specified region is part of the set
// Contains returns whether the specified region is part of the set or not
func (r *RegionSet) Contains(r2 Region) bool {
r.lock.Lock()
defer r.lock.Unlock()
Expand All @@ -159,7 +159,7 @@ func (r *RegionSet) Contains(r2 Region) bool {
return false
}

// Returns a copy of the regions in the set
// Regions returns a copy of the regions in the set
func (r *RegionSet) Regions() (ret []Region) {
r.lock.Lock()
defer r.lock.Unlock()
Expand All @@ -168,7 +168,7 @@ func (r *RegionSet) Regions() (ret []Region) {
return
}

// Returns whether the set contains at least one
// HasNonEmpty returns whether the set contains at least one
// region that isn't empty.
func (r *RegionSet) HasNonEmpty() bool {
r.lock.Lock()
Expand All @@ -181,7 +181,7 @@ func (r *RegionSet) HasNonEmpty() bool {
return false
}

// Opposite of #HasNonEmpty
// HasEmpty returns the opposite of #HasNonEmpty
func (r *RegionSet) HasEmpty() bool {
r.lock.Lock()
defer r.lock.Unlock()
Expand All @@ -193,7 +193,7 @@ func (r *RegionSet) HasEmpty() bool {
return false
}

// Cuts away the provided region from the set, and returns
// Cut cuts away the provided region from the set, and returns
// the new set
func (r *RegionSet) Cut(r2 Region) (ret RegionSet) {
r.lock.Lock()
Expand Down

0 comments on commit 06ae817

Please sign in to comment.