before_code stringlengths 14 465k | reviewer_comment stringlengths 16 64.5k | after_code stringlengths 9 467k | diff_context stringlengths 0 97k | file_path stringlengths 5 226 | comment_line int32 0 26 | language stringclasses 37
values | quality_score float32 0.07 1 | comment_type stringclasses 9
values | comment_length int32 16 64.5k | before_lines int32 1 17.2k | after_lines int32 1 12.1k | is_negative bool 2
classes | pr_title stringlengths 1 308 | pr_number int32 1 299k | repo_name stringclasses 533
values | repo_stars int64 321 419k | repo_language stringclasses 27
values | reviewer_username stringlengths 0 39 | author_username stringlengths 2 39 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
if sloc == vloc.SLoc {
// we are at the end of buffer
h.Cursor.Loc = h.Buf.End()
h.Cursor.StoreVisualX()
} else {
vloc.SLoc = sloc
vloc.VisualX = h.Cursor.LastWrappedVisualX
h.Cursor.Loc = h.LocFromVLoc(vloc)
}
}
}
// CursorUp moves the cursor up
func (h *BufPane) CursorUp() bool {
h.Cursor.D... | This looks completely wrong. Try selecting any number of lines other than 2 and pressing Down and see what happens.
How about something straightforward like:
```go
--- a/internal/action/actions.go
+++ b/internal/action/actions.go
@@ -254,8 +254,12 @@ func (h *BufPane) CursorUp() bool {
// CursorDown moves t... | if sloc == vloc.SLoc {
// we are at the end of buffer
h.Cursor.Loc = h.Buf.End()
h.Cursor.StoreVisualX()
} else {
vloc.SLoc = sloc
vloc.VisualX = h.Cursor.LastWrappedVisualX
h.Cursor.Loc = h.LocFromVLoc(vloc)
}
}
}
// CursorUp moves the cursor up
func (h *BufPane) CursorUp() bool {
h.Cursor.D... | @@ -254,8 +254,16 @@ func (h *BufPane) CursorUp() bool {
// CursorDown moves the cursor down
func (h *BufPane) CursorDown() bool {
- h.Cursor.Deselect(false)
- h.MoveCursorDown(1)
+ downN := 1
+ if h.Cursor.HasSelection() {
+ if h.Cursor.CurSelection[1].X == 0 {
+ h.Cursor.Deselect(true) | internal/action/actions.go | 26 | Go | 0.857 | bug | 604 | 51 | 51 | false | actions: Perform `Cursor(Page)Down` with selection like GUI editors do | 3,540 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
h.Cursor.Deselect(true)
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
scrollAmount := h.BufView().Height - pageOverlap
h.MoveCursorUp(scrollAmount)
if h.Cursor.Num == 0 {
h.ScrollUp(scrollAmount)
}
h.Relocate()
return true
}
// CursorPageDown places the cursor a page down,
// moving the view to... | And when it comes to `CursorPageDown`, I'm not sure this is useful. For example: put a cursor somewhere close to the end of buffer (just a few lines above the end), select some lines and then press PageDown -> the cursor is unexpectedly placed not at the last line but at the line before it. | h.Cursor.Deselect(true)
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
scrollAmount := h.BufView().Height - pageOverlap
h.MoveCursorUp(scrollAmount)
if h.Cursor.Num == 0 {
h.ScrollUp(scrollAmount)
}
h.Relocate()
return true
}
// CursorPageDown places the cursor a page down,
// moving the view to... | @@ -1746,6 +1747,7 @@ func (h *BufPane) CursorPageDown() bool {
}
if selectionEndNewline {
h.Cursor.Start()
+ h.MoveCursorUp(1) | internal/action/actions.go | 26 | Go | 0.643 | suggestion | 291 | 51 | 51 | false | actions: Perform `Cursor(Page)Down` with selection like GUI editors do | 3,540 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
return l.GreaterEqual(start) && l.LessEqual(end)
}
prevMatchEnd := buffer.Loc{-1, -1}
var doReplacement func()
doReplacement = func() {
locs, found, err := h.Buf.FindNext(search, start, end, searchLoc, true, true)
if err != nil {
InfoBar.Error(err)
return
}
if !found || !inRange(locs[0])... | Why not do this just immediately after we found and replaced an empty match, rather than postpone it to the next iteration? i.e.
```go
--- a/internal/action/command.go
+++ b/internal/action/command.go
@@ -993,6 +993,14 @@ func (h *BufPane) ReplaceCmd(args []string) {
if end.Y == locs[1].Y {
end = e... | return l.GreaterEqual(start) && l.LessEqual(end)
}
lastMatchEnd := buffer.Loc{-1, -1}
var doReplacement func()
doReplacement = func() {
locs, found, err := h.Buf.FindNext(search, start, end, searchLoc, true, true)
if err != nil {
InfoBar.Error(err)
return
}
if !found || !inRange(locs[0])... | @@ -977,6 +979,17 @@ func (h *BufPane) ReplaceCmd(args []string) {
return
}
+ if prevMatchEnd == locs[1] {
+ // skip empty match right after previous match
+ if searchLoc == end {
+ searchLoc = start
+ } else {
+ searchLoc = searchLoc.Move(1, h.Buf)
+ } | internal/action/command.go | 26 | Go | 0.857 | question | 650 | 51 | 51 | false | avoid infinite loop in `replace` when empty string matches | 3,566 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
nreplaced, _ = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex)
} else {
inRange := func(l buffer.Loc) bool {
return l.GreaterEqual(start) && l.LessEqual(end)
}
prevMatchEnd := buffer.Loc{-1, -1}
var doReplacement func()
doReplacement = func() {
locs, found, err := h.Buf.FindNext(search, sta... | It's better to squash this fix into the first commit. | nreplaced, _ = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex)
} else {
inRange := func(l buffer.Loc) bool {
return l.GreaterEqual(start) && l.LessEqual(end)
}
lastMatchEnd := buffer.Loc{-1, -1}
var doReplacement func()
doReplacement = func() {
locs, found, err := h.Buf.FindNext(search, sta... | @@ -983,6 +983,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
// skip empty match right after previous match
if searchLoc == end {
searchLoc = start
+ prevMatchEnd = buffer.Loc{-1, -1} | internal/action/command.go | 26 | Go | 0.286 | suggestion | 53 | 51 | 51 | false | avoid infinite loop in `replace` when empty string matches | 3,566 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
if h.Buf.LastSearch != "" {
h.Buf.LastSearch = ""
return true
}
return false
}
// FindNext searches forwards for the last used search term
func (h *BufPane) FindNext() bool {
if h.Buf.LastSearch == "" {
return false
}
// If the cursor is at the start of a selection and we search we want
// to search from ... | A comment like "skip empty match right after previous match" from #3566 would be also helpful here. | }
return false
}
// FindNext searches forwards for the last used search term
func (h *BufPane) FindNext() bool {
if h.Buf.LastSearch == "" {
return false
}
// If the cursor is at the start of a selection and we search we want
// to search from the end of the selection in the case that
// the selection is a se... | @@ -1213,11 +1216,22 @@ func (h *BufPane) FindNext() bool {
InfoBar.Error(err)
}
if found {
+ if h.Buf.LastMatch[1] == match[0] && match[0] == match[1] { | internal/action/actions.go | 26 | Go | 0.214 | suggestion | 99 | 51 | 51 | false | make `FindNext` and `FindPrevious` work with empty matches | 3,572 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
}
return false
}
// FindNext searches forwards for the last used search term
func (h *BufPane) FindNext() bool {
if h.Buf.LastSearch == "" {
return false
}
// If the cursor is at the start of a selection and we search we want
// to search from the end of the selection in the case that
// the selection is a se... | We should also initialize `LastMatch` with this value when creating the buffer? |
// FindNext searches forwards for the last used search term
func (h *BufPane) FindNext() bool {
if h.Buf.LastSearch == "" {
return false
}
// If the cursor is at the start of a selection and we search we want
// to search from the end of the selection in the case that
// the selection is a search result in whic... | @@ -1213,11 +1216,22 @@ func (h *BufPane) FindNext() bool {
InfoBar.Error(err)
}
if found {
+ if h.Buf.LastMatch[1] == match[0] && match[0] == match[1] {
+ h.Cursor.ResetSelection()
+ h.Buf.LastMatch = [2]buffer.Loc{buffer.Loc{-1, -1}, buffer.Loc{-1, -1}} | internal/action/actions.go | 26 | Go | 0.429 | question | 79 | 51 | 51 | false | make `FindNext` and `FindPrevious` work with empty matches | 3,572 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
package buffer
import (
"regexp"
"github.com/zyedidia/micro/v2/internal/util"
)
func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
rPadStart := regexp.MustCompile(".(?:"+r.String()+")")
rPadEnd := regexp.MustCompile("(?:"+r.String()+").")
rPadBoth := regexp.MustC... | From the code it isn't obvious at all what are these multiple alternative regexps even needed for. I believe we should add a comment explaining it. | package buffer
import (
"regexp"
"unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
// We want "^" and "$" to match only the beginning/end of a line, not the
// beginning/end of the search region if it is in the middle of a line.
// In that case we use padded regexps to require a rune before or after
/... | @@ -6,6 +6,40 @@ import (
"github.com/zyedidia/micro/v2/internal/util"
)
+func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) { | internal/buffer/search.go | 9 | Go | 0.429 | suggestion | 147 | 34 | 34 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
package buffer
import (
"regexp"
"github.com/zyedidia/micro/v2/internal/util"
)
func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
rPadStart := regexp.MustCompile(".(?:"+r.String()+")")
rPadEnd := regexp.MustCompile("(?:"+r.String()+").")
rPadBoth := regexp.MustC... | Is this `(?:)` group useful here? It seems (correct me if I'm wrong) that as long as the `r` regex is valid (and we know it is valid), just appending/prepending `"."` to it is guaranteed to produce the regex we want. | package buffer
import (
"regexp"
"unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
// We want "^" and "$" to match only the beginning/end of a line, not the
// beginning/end of the search region if it is in the middle of a line.
// In that case we use padded regexps to require a rune before or after
/... | @@ -6,6 +6,40 @@ import (
"github.com/zyedidia/micro/v2/internal/util"
)
+func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
+ rPadStart := regexp.MustCompile(".(?:"+r.String()+")") | internal/buffer/search.go | 20 | Go | 0.643 | bug | 216 | 45 | 45 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
package buffer
import (
"regexp"
"github.com/zyedidia/micro/v2/internal/util"
)
func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
rPadStart := regexp.MustCompile(".(?:"+r.String()+")")
rPadEnd := regexp.MustCompile("(?:"+r.String()+").")
rPadBoth := regexp.MustC... | The idiomatic way to define such C-enum-style numeric constants is:
```
const (
rPadNone = iota
rPadStart
rPadEnd
rPadBoth
)
``` | package buffer
import (
"regexp"
"unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
// We want "^" and "$" to match only the beginning/end of a line, not the
// beginning/end of the search region if it is in the middle of a line.
// In that case we use padded regexps to require a rune before or after
/... | @@ -6,6 +6,40 @@ import (
"github.com/zyedidia/micro/v2/internal/util"
)
+func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
+ rPadStart := regexp.MustCompile(".(?:"+r.String()+")")
+ rPadEnd := regexp.MustCompile("(?:"+r.String()+").")
+ rPadBoth := regexp.MustComp... | internal/buffer/search.go | 19 | Go | 0.714 | style | 140 | 44 | 44 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
rPadStart := regexp.MustCompile(".(?:"+r.String()+")")
rPadEnd := regexp.MustCompile("(?:"+r.String()+").")
rPadBoth := regexp.MustCompile(".(?:"+r.String()+").")
return r, rPadStart, rPadEnd, rPadBoth
}
func findLi... | gofmt wants it to be `start.X - 1` (with spaces). |
// We want "^" and "$" to match only the beginning/end of a line, not the
// beginning/end of the search region if it is in the middle of a line.
// In that case we use padded regexps to require a rune before or after
// the match. (This also affects other empty-string patters like "\\b".)
// The following two flags i... | @@ -6,6 +6,40 @@ import (
"github.com/zyedidia/micro/v2/internal/util"
)
+func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
+ rPadStart := regexp.MustCompile(".(?:"+r.String()+")")
+ rPadEnd := regexp.MustCompile("(?:"+r.String()+").")
+ rPadBoth := regexp.MustComp... | internal/buffer/search.go | 26 | Go | 0.214 | suggestion | 49 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
charpos = start.X-1
l = util.SliceEnd(l, charpos)
ri += 1 // rPadNone -> rPadStart, rPadEnd -> rPadBoth
}
}
return l, charpos, rPadded[ri]
}
func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
if start.Y > b.LinesNum(... | I guess `padRegexp()` could just return the array of 4 regexps so we could just use it, and naturally index with the numeric constants `rPadNone`, `rPadStart`, `rPadEnd`, `rPadBoth` (defined with `iota` as I suggested above) instead of a separate variable for each.
And then, it also seems cleaner to let `findLinePar... | if i == start.Y {
nchars := util.CharacterCount(l)
start.X = util.Clamp(start.X, 0, nchars)
if start.X > 0 {
charpos = start.X - 1
l = util.SliceEnd(l, charpos)
padMode |= padStart
}
}
if padMode == padStart {
r = regexp.MustCompile(".(?:" + r.String() + ")")
} else if padMode == padEnd {
r = ... | @@ -21,33 +55,23 @@ func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
start, end = end, start
}
- for i := start.Y; i <= end.Y; i++ {
- l := b.LineBytes(i)
- charpos := 0
+ rPadNone, rPadStart, rPadEnd, rPadBoth := padRegexp(r)
+ rPadded := [4]*regexp.Regexp{rPadNone, rPadStart, rPad... | internal/buffer/search.go | 26 | Go | 0.643 | suggestion | 526 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
package buffer
import (
"regexp"
"github.com/zyedidia/micro/v2/internal/util"
)
const (
rPadNone = iota
rPadStart
rPadEnd
rPadBoth
)
func padRegexp(r *regexp.Regexp) [4]*regexp.Regexp { // r is used when searching an entire line
rPaddedStart := regexp.MustCompile(".(?:"+r.String()+")") // used whe... | I didn't mean that we should explain when is each of these regexes used (that is rather clear from the code). I meant that we should explain _why_ are we even doing all this. It is not obvious that we are doing all this just to avoid false matches for `^`, `$`, `\b` etc.
Basically you already explained that in the P... | package buffer
import (
"regexp"
"unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
// We want "^" and "$" to match only the beginning/end of a line, not the
// beginning/end of the search region if it is in the middle of a line.
// In that case we use padded regexps to require a rune before or after
/... | @@ -6,38 +6,45 @@ import (
"github.com/zyedidia/micro/v2/internal/util"
)
-func padRegexp(r *regexp.Regexp) (*regexp.Regexp, *regexp.Regexp, *regexp.Regexp, *regexp.Regexp) {
- rPadStart := regexp.MustCompile(".(?:"+r.String()+")")
- rPadEnd := regexp.MustCompile("(?:"+r.String()+").")
- rPadBoth := regexp.MustCom... | internal/buffer/search.go | 16 | Go | 0.643 | suggestion | 656 | 41 | 41 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
if start.Y > b.LinesNum()-1 {
start.X = lastcn - 1
}
if end.Y > b.LinesNum()-1 {
end.X = lastcn
}
start.Y = util.Clamp(start.Y, 0, b.LinesNum()-1)
end.Y = util.Clamp(end.... | gofmt doesn't want spaces here (not that I like it)... | r = regexp.MustCompile("(?:" + r.String() + ").")
} else if padMode == padStart|padEnd {
r = regexp.MustCompile(".(?:" + r.String() + ").")
}
return l, charpos, padMode, r
}
func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1)... | @@ -65,17 +63,17 @@ func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
rPadded := padRegexp(r)
for i := start.Y; i <= end.Y; i++ {
- l, charpos, ri := findLineParams(b, start, end, i)
+ l, charpos, padMode := findLineParams(b, start, end, i)
- match := rPadded[ri].FindIndex(l)
+ ma... | internal/buffer/search.go | 26 | Go | 0.214 | suggestion | 54 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
return l, charpos, padMode
}
func (b *Buffer) findNext(r *regexp.Regexp, start, end Loc, down bool) ([2]Loc, bool) {
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
if start.Y > b.LinesNum()-1 {
start.X = lastcn - 1
}
if end.Y > b.LinesNum()-1 {
end.X = lastcn
}
start.Y = util.Clamp(start.Y, 0... | Argh, this looks ugly... I missed the fact that the direction of the loop also differs, so deduplication is not quite as trivial as I thought.
I'd suggest to drop this for now, leaving this refactoring effort to another PR (if at all). | r = regexp.MustCompile(".(?:" + r.String() + ").")
}
return l, charpos, padMode, r
}
func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
if start.Y > b.LinesNum()-1 {
start.X = lastcn - 1
}
if end.Y > b.LinesNum()-1 {
en... | @@ -67,50 +67,27 @@ func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
rPadded := padRegexp(r)
- for i := start.Y; i <= end.Y; i++ {
- l, charpos, padMode := findLineParams(b, start, end, i)
-
- match := rPadded[padMode].FindIndex(l)
-
- if match != nil {
- start := Loc{charpos + ut... | internal/buffer/search.go | 26 | Go | 0.5 | refactor | 238 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
if !found {
l, found = b.findUp(r, end, start)
}
}
return l, found, nil
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
// and returns the number of replacements made and the number of characters
// added or removed on the last line of the range
func (b *Buffer) Replace... | Still, what is the advantage of using `findAll()` to remember all matches in some temporary storage to handle them afterwards, instead of just using `findDown()` and handling each match right away? | return l, found, nil
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
// and returns the number of replacements made and the number of characters
// added or removed on the last line of the range
func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []byte... | @@ -194,64 +194,50 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b
charsEnd := util.CharacterCount(b.LineBytes(end.Y))
found := 0
+ var charCount int
var deltas []Delta
- // This replacement function works in general, but it creates a separate
- // modification for each mat... | internal/buffer/search.go | 26 | Go | 0.714 | question | 197 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
} else {
l, found = b.findUp(r, from, start)
if !found {
l, found = b.findUp(r, end, start)
}
}
return l, found, nil
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
// and returns the number of replacements made and the number of characters
// added or removed on the... | Can't we just do this `findDown()` based logic (instead of the old `search.ReplaceAllFunc()` based logic) for all lines, not just for the first and last line?
And considering my other comment, I imagine we don't even need to deal with individual lines here, we can simply call `findDown()` in a loop for the entire ra... | }
}
return l, found, nil
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
// and returns the number of replacements made and the number of characters
// added or removed on the last line of the range
func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace... | @@ -165,53 +185,59 @@ func (b *Buffer) FindNext(s string, start, end, from Loc, down bool, useRegex bo
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
-// and returns the number of replacements made and the number of runes
+// and returns the number of replacements made and t... | internal/buffer/search.go | 26 | Go | 0.643 | suggestion | 377 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
} else {
l, found = b.findUp(r, from, start)
if !found {
l, found = b.findUp(r, end, start)
}
}
return l, found, nil
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
// and returns the number of replacements made and the number of characters
// added or removed on the... | Seems easy to optimize a bit?
```go
--- a/internal/buffer/search.go
+++ b/internal/buffer/search.go
@@ -200,7 +200,7 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b
for i := start.Y; i <= end.Y; i++ {
l := b.LineBytes(i)
charCount = util.CharacterCount(l)
- if i ==... | }
}
return l, found, nil
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
// and returns the number of replacements made and the number of characters
// added or removed on the last line of the range
func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace... | @@ -165,53 +185,59 @@ func (b *Buffer) FindNext(s string, start, end, from Loc, down bool, useRegex bo
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
-// and returns the number of replacements made and the number of runes
+// and returns the number of replacements made and t... | internal/buffer/search.go | 26 | Go | 0.857 | performance | 618 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
if captureGroups {
newText = search.ReplaceAll(b.Substr(match[0], match[1]), replace)
} else {
newText = replace
}
deltas = append(deltas, Delta{newText, match[0], match[1]})
}
} else {
newLine := search.ReplaceAllFunc(l, func(in []byte) []byte {
found++
var result []byte
i... | I don't quite get this. `charEnd` is the number of characters in the last line (before replacement), and `charCount` is the number of characters in the line at the last iteration of the loop (again, before replacement), i.e. the same thing, so this return value will be always 0? (Except the case when there were no iter... | package buffer
import (
"regexp"
"unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
// We want "^" and "$" to match only the beginning/end of a line, not the
// beginning/end of the search region if it is in the middle of a line.
// In that case we use padded regexps to require a rune before or after
/... | @@ -165,53 +185,59 @@ func (b *Buffer) FindNext(s string, start, end, from Loc, down bool, useRegex bo
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
-// and returns the number of replacements made and the number of runes
+// and returns the number of replacements made and t... | internal/buffer/search.go | 26 | Go | 0.643 | suggestion | 596 | 28 | 239 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
if captureGroups {
newText = search.ReplaceAll(b.Substr(match[0], match[1]), replace)
} else {
newText = replace
}
deltas = append(deltas, Delta{newText, match[0], match[1]})
}
} else {
newLine := search.ReplaceAllFunc(l, func(in []byte) []byte {
found++
var result []byte
i... | As I already noted, if the loop was never executed (so nothing was replaced), we should return 0, but here we return non-zero?
Also please squash such bugfixes into previous commits. The commit history in a PR should be like "fix issue A, fix issue B", not like "fix issue A, fix issue B, introduce issue C, fix issue... | package buffer
import (
"regexp"
"unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
// We want "^" and "$" to match only the beginning/end of a line, not the
// beginning/end of the search region if it is in the middle of a line.
// In that case we use padded regexps to require a rune before or after
/... | @@ -239,5 +238,6 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b
b.MultipleReplace(deltas)
- return found, charCount - charsEnd
+ deltaX := util.CharacterCount(b.LineBytes(end.Y)) - charCount | internal/buffer/search.go | 26 | Go | 0.643 | bug | 324 | 29 | 239 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
}
if end.Y > b.LinesNum()-1 {
end.X = lastcn
}
start.Y = util.Clamp(start.Y, 0, b.LinesNum()-1)
end.Y = util.Clamp(end.Y, 0, b.LinesNum()-1)
if start.GreaterThan(end) {
start, end = end, start
}
rPadded := padRegexp(r)
for i := start.Y; i <= end.Y; i++ {
l, charpos, padMode := findLineParams(b, start,... | nit: It seems it would be a bit more readable if we rearrange the lines: the two `if`s together and then `start := ` and `end := ` together. | start.X = lastcn - 1
}
if end.Y > b.LinesNum()-1 {
end.X = lastcn
}
start.Y = util.Clamp(start.Y, 0, b.LinesNum()-1)
end.Y = util.Clamp(end.Y, 0, b.LinesNum()-1)
if start.GreaterThan(end) {
start, end = end, start
}
for i := start.Y; i <= end.Y; i++ {
l, charpos, padMode, rPadded := findLineParams(b, ... | @@ -21,32 +66,23 @@ func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
start, end = end, start
}
- for i := start.Y; i <= end.Y; i++ {
- l := b.LineBytes(i)
- charpos := 0
+ rPadded := padRegexp(r)
- if i == start.Y && start.Y == end.Y {
- nchars := util.CharacterCount(l)
- sta... | internal/buffer/search.go | 26 | Go | 0.5 | nitpick | 140 | 51 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
package buffer
import (
"regexp"
"github.com/zyedidia/micro/v2/internal/util"
)
func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
if start.Y > b.LinesNum()-1 {
start.X = lastcn - 1
}
if end.Y > b.LinesNum()-1 {
end.X = ... | I've noticed that because of this `ReplaceAll()` usage, matching `\b` still doesn't work fully correctly:
1. `replace \\b aaa` (interactive replace) -> finds matches but doesn't replace them (IOW correctly finds the next beginning or end of a word, but doesn't insert `aaa` here).
2. `replace \\b aaa -a` with select... | start, end = end, start
}
charsEnd := util.CharacterCount(b.LineBytes(end.Y))
found := 0
var deltas []Delta
for i := start.Y; i <= end.Y; i++ {
l := b.LineBytes(i)
charCount := util.CharacterCount(l)
if (i == start.Y && start.X > 0) || (i == end.Y && end.X < charCount) {
// This replacement code works... | @@ -146,53 +181,58 @@ func (b *Buffer) FindNext(s string, start, end, from Loc, down bool, useRegex bo
}
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
-// and returns the number of replacements made and the number of runes
+// and returns the number of replacements made and t... | internal/buffer/search.go | 26 | Go | 0.857 | bug | 1,262 | 199 | 51 | false | match beginning and end of line correctly | 3,575 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
return true
}
// IsWhitespace returns true if the given rune is a space, tab, or newline
func IsWhitespace(c rune) bool {
return unicode.IsSpace(c)
}
// IsBytesWhitespace returns true if the given bytes are all whitespace
func IsBytesWhitespace(b []byte) bool {
for _, c := range b {
if !IsWhitespace(rune(c)) {
... | Maybe `'\'`? Comments are not code, we don't need to quote `\` in comments. | return true
}
// IsWhitespace returns true if the given rune is a space, tab, or newline
func IsWhitespace(c rune) bool {
return unicode.IsSpace(c)
}
// IsBytesWhitespace returns true if the given bytes are all whitespace
func IsBytesWhitespace(b []byte) bool {
for _, c := range b {
if !IsWhitespace(rune(c)) {
... | @@ -320,6 +320,25 @@ func RunePos(b []byte, i int) int {
return CharacterCount(b[:i])
}
+// IndexAnyUnquoted returns the first position is s of a character from chars.
+// Escaped (with '\\') and quoted (with single or double quotes) characters | internal/util/util.go | 26 | Go | 0.357 | suggestion | 75 | 51 | 51 | false | ignore quoted characters when splitting keybindings into actions | 3,612 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
func IsWhitespace(c rune) bool {
return unicode.IsSpace(c)
}
// IsBytesWhitespace returns true if the given bytes are all whitespace
func IsBytesWhitespace(b []byte) bool {
for _, c := range b {
if !IsWhitespace(rune(c)) {
return false
}
}
return true
}
// RunePos returns the rune index of a given byte ind... | This iterates over raw bytes, not Unicode runes. Although the end result is probably gonna be correct (as long as `chars` includes ASCII characters only) thanks to the fact that UTF-8 is backward compatible with ASCII, it's cleaner to iterate over runes:
```
for _, c := range s {
```
(See e.g. `util.IsSpaces()`... | func IsWhitespace(c rune) bool {
return unicode.IsSpace(c)
}
// IsBytesWhitespace returns true if the given bytes are all whitespace
func IsBytesWhitespace(b []byte) bool {
for _, c := range b {
if !IsWhitespace(rune(c)) {
return false
}
}
return true
}
// RunePos returns the rune index of a given byte ind... | @@ -320,6 +320,25 @@ func RunePos(b []byte, i int) int {
return CharacterCount(b[:i])
}
+// IndexAnyUnquoted returns the first position is s of a character from chars.
+// Escaped (with '\\') and quoted (with single or double quotes) characters
+// are ignored. Returns -1 if not successful
+func IndexAnyUnquoted(s... | internal/util/util.go | 26 | Go | 0.786 | suggestion | 359 | 51 | 51 | false | ignore quoted characters when splitting keybindings into actions | 3,612 | zyedidia/micro | 13,805 | Go | dmaluka | matthias314 |
txt, _ := json.MarshalIndent(parsedSettings, "", " ")
txt = append(txt, '\n')
err = writeFile(filename, txt)
}
return err
}
// RegisterCommonOptionPlug creates a new option (called pl.name). This is meant to be called by plugins to add options.
func RegisterCommonOptionPlug(pl string, name string, defaultv... | `RegisterGlobalOption()` takes native value, whose type is not necessarily a string, right? |
txt, _ := json.MarshalIndent(parsedSettings, "", " ")
txt = append(txt, '\n')
err = writeFile(filename, txt)
}
return err
}
// RegisterCommonOptionPlug creates a new option (called pl.name). This is meant to be called by plugins to add options.
func RegisterCommonOptionPlug(pl string, name string, defaultv... | @@ -408,6 +409,16 @@ func RegisterGlobalOptionPlug(pl string, name string, defaultvalue any) error {
return RegisterGlobalOption(pl+"."+name, defaultvalue)
}
+// **Deprecated**
+func SetGlobalOptionNativePlug(option string, nativeValue interface{}) error {
+ return RegisterGlobalOption(option, nativeValue)
+}
+
+/... | internal/config/settings.go | 26 | Go | 0.5 | question | 91 | 51 | 51 | false | Removing the ability for plugins to modify settings.json and bindings.json. Adding an option to reject plugins to bind keys. | 3,618 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
func eventsEqual(e1 Event, e2 Event) bool {
seq1, ok1 := e1.(KeySequenceEvent)
seq2, ok2 := e2.(KeySequenceEvent)
if ok1 && ok2 {
if len(seq1.keys) != len(seq2.keys) {
return false
}
for i := 0; i < len(seq1.keys); i++ {
if seq1.keys[i] != seq2.keys[i] {
return false
}
}
return true
}
retu... | How about actually _registering_ the keybinding (as I suggested in https://github.com/zyedidia/micro/pull/3385#issuecomment-2229772786)? |
func eventsEqual(e1 Event, e2 Event) bool {
seq1, ok1 := e1.(KeySequenceEvent)
seq2, ok2 := e2.(KeySequenceEvent)
if ok1 && ok2 {
if len(seq1.keys) != len(seq2.keys) {
return false
}
for i := 0; i < len(seq1.keys); i++ {
if seq1.keys[i] != seq2.keys[i] {
return false
}
}
return true
}
retu... | @@ -261,9 +261,23 @@ func eventsEqual(e1 Event, e2 Event) bool {
return e1 == e2
}
+// RegisterKeybindingPlug registers a default keybinding for the plugin without writing to bindings.json.
+// This operation can be rejected by lockbindings to prevent unexpected actions by the user.
+func RegisterKeybindingPlug(k,... | internal/action/bindings.go | 26 | Go | 0.357 | question | 136 | 51 | 51 | false | Removing the ability for plugins to modify settings.json and bindings.json. Adding an option to reject plugins to bind keys. | 3,618 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
}
}
return event, nil
}
func eventsEqual(e1 Event, e2 Event) bool {
seq1, ok1 := e1.(KeySequenceEvent)
seq2, ok2 := e2.(KeySequenceEvent)
if ok1 && ok2 {
if len(seq1.keys) != len(seq2.keys) {
return false
}
for i := 0; i < len(seq1.keys); i++ {
if seq1.keys[i] != seq2.keys[i] {
return false
... | What kind of "unexpected actions"?
AFAICS, `lockbindings` is completely pointless now, what it prevents is not overwriting `bindings.json` (that is already prevented anyway) but doing anything at all? | }
}
return event, nil
}
func eventsEqual(e1 Event, e2 Event) bool {
seq1, ok1 := e1.(KeySequenceEvent)
seq2, ok2 := e2.(KeySequenceEvent)
if ok1 && ok2 {
if len(seq1.keys) != len(seq2.keys) {
return false
}
for i := 0; i < len(seq1.keys); i++ {
if seq1.keys[i] != seq2.keys[i] {
return false
... | @@ -261,9 +261,23 @@ func eventsEqual(e1 Event, e2 Event) bool {
return e1 == e2
}
+// RegisterKeybindingPlug registers a default keybinding for the plugin without writing to bindings.json.
+// This operation can be rejected by lockbindings to prevent unexpected actions by the user. | internal/action/bindings.go | 26 | Go | 0.571 | question | 203 | 51 | 51 | false | Removing the ability for plugins to modify settings.json and bindings.json. Adding an option to reject plugins to bind keys. | 3,618 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
return nil, errors.New(k + " is not a bindable event")
}
}
return event, nil
}
func eventsEqual(e1 Event, e2 Event) bool {
seq1, ok1 := e1.(KeySequenceEvent)
seq2, ok2 := e2.(KeySequenceEvent)
if ok1 && ok2 {
if len(seq1.keys) != len(seq2.keys) {
return false
}
for i := 0; i < len(seq1.keys); i++ {... | // TryBindKeyPlug tries to bind **a** key for the plugin without writing to bindings.json.
derived from
// TryBindKey tries to bind a key by writing to config.ConfigDir/bindings.json | return nil, errors.New(k + " is not a bindable event")
}
}
return event, nil
}
func eventsEqual(e1 Event, e2 Event) bool {
seq1, ok1 := e1.(KeySequenceEvent)
seq2, ok2 := e2.(KeySequenceEvent)
if ok1 && ok2 {
if len(seq1.keys) != len(seq2.keys) {
return false
}
for i := 0; i < len(seq1.keys); i++ {... | @@ -261,9 +261,14 @@ func eventsEqual(e1 Event, e2 Event) bool {
return e1 == e2
}
+// TryBindKeyPlug tries to bind key for the plugin without writing to bindings.json. | internal/action/bindings.go | 26 | Go | 0.357 | suggestion | 184 | 51 | 51 | false | Removing the ability for plugins to modify settings.json and bindings.json. Adding an option to reject plugins to bind keys. | 3,618 | zyedidia/micro | 13,805 | Go | JoeKar | Neko-Box-Coder |
type StatusLine struct {
Info map[string]func(*buffer.Buffer) string
win *BufWindow
}
var statusInfo = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": f... | Maybe `overwritemode` is more precise, as suggested in the linked feature request. | type StatusLine struct {
Info map[string]func(*buffer.Buffer) string
win *BufWindow
}
var statusInfo = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": f... | @@ -47,6 +47,12 @@ var statusInfo = map[string]func(*buffer.Buffer) string{
}
return ""
},
+ "overwrite": func(b *buffer.Buffer) string { | internal/display/statusline.go | 26 | Go | 0.357 | suggestion | 82 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | JoeKar | JoeKar |
return b
}
// 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(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
if err != nil {
screen.TermMessage(err)
}
return b
}
func (h *... | What about other cursors?
I've tried using overwrite mode with multicursors with your PR. It doesn't work very well. | return b
}
// 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(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
if err != nil {
screen.TermMessage(err)
}
return b
}
func (h *... | @@ -353,14 +351,13 @@ func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
h.Buf = b
h.BWindow.SetBuffer(b)
h.Cursor = b.GetActiveCursor()
+ // Set the cursors IsOverwriteMode by default to false on open
+ h.Cursor.IsOverwriteMode = false | internal/action/bufpane.go | 26 | Go | 0.357 | question | 117 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
win *BufWindow
}
var statusInfo = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor... | "Delete" is not exactly what the overwrite mode is about. It is about overwrite aka replace, right?
I'm not sure which string should we display here.
I'm also wondering: can we be space-saving here and display a string _only_ when in overwrite mode (similarly to `$(modified)`)? Then maybe we could even add `$(ove... |
win *BufWindow
}
var statusInfo = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor... | @@ -47,6 +47,12 @@ var statusInfo = map[string]func(*buffer.Buffer) string{
}
return ""
},
+ "overwrite": func(b *buffer.Buffer) string {
+ if b.GetActiveCursor().IsOverwriteMode {
+ return "del" | internal/display/statusline.go | 26 | Go | 0.643 | question | 472 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
fini int32
cursors []*Cursor
curCursor int
StartCursor Loc
// OptionCallback is called after a buffer option value is changed.
// The display module registers its OptionCallback to ensure the buffer window
// is properly updated when needed. This is a workaround for the fact that
// the buffer mod... | Why not `IsOverwriteMode`? Or, even better, just `OverwriteMode`? | fini int32
cursors []*Cursor
curCursor int
StartCursor Loc
// OptionCallback is called after a buffer option value is changed.
// The display module registers its OptionCallback to ensure the buffer window
// is properly updated when needed. This is a workaround for the fact that
// the buffer mod... | @@ -209,6 +209,9 @@ type Buffer struct {
LastSearchRegex bool
// HighlightSearch enables highlighting all instances of the last successful search
HighlightSearch bool
+
+ // Keep track of cursor overwrite/replace
+ OverwriteModeActive bool | internal/buffer/buffer.go | 26 | Go | 0.429 | question | 65 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
if err != nil {
screen.TermMessage(err)
}
return b
}
// 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(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
if err != nil {
scr... | The comment tells *exactly* what is entirely obvious without the comment, and nothing more. (The original comment for `isOverwriteMode` at least told something more; although not exactly a revelation either.) | if err != nil {
screen.TermMessage(err)
}
return b
}
// 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(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
if err != nil {
scr... | @@ -351,16 +349,15 @@ func (h *BufPane) resetMouse() {
func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
h.Buf.Close()
h.Buf = b
+ // Set the OverwriteModeActive by default to false on open | internal/action/bufpane.go | 26 | Go | 0.571 | suggestion | 208 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
fini int32
cursors []*Cursor
curCursor int
StartCursor Loc
// OptionCallback is called after a buffer option value is changed.
// The display module registers its OptionCallback to ensure the buffer window
// is properly updated when needed. This is a workaround for the fact that
// the buffer mo... | 1. cursor?
2. overwrite and replace is the same thing?
The original comment was IMO more useful. |
fini int32
cursors []*Cursor
curCursor int
StartCursor Loc
// OptionCallback is called after a buffer option value is changed.
// The display module registers its OptionCallback to ensure the buffer window
// is properly updated when needed. This is a workaround for the fact that
// the buffer mo... | @@ -209,6 +209,9 @@ type Buffer struct {
LastSearchRegex bool
// HighlightSearch enables highlighting all instances of the last successful search
HighlightSearch bool
+
+ // Keep track of cursor overwrite/replace | internal/buffer/buffer.go | 26 | Go | 0.429 | suggestion | 100 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
win *BufWindow
}
var statusInfo = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor... | Looks cute, but is there a chance anyone will guess what it means?
Also, add a space after it, similarly to `$(modified)` (and for the same reason)? |
win *BufWindow
}
var statusInfo = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor... | @@ -47,6 +47,12 @@ var statusInfo = map[string]func(*buffer.Buffer) string{
}
return ""
},
+ "overwrite": func(b *buffer.Buffer) string {
+ if b.OverwriteModeActive {
+ return "[>]" | internal/display/statusline.go | 26 | Go | 0.5 | question | 151 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
screen.TermMessage(err)
}
return b
}
// 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(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
if err != nil {
screen.TermMessage(e... | BTW this assignment itself is not too useful either, since it is initialized to false by default anyway. | screen.TermMessage(err)
}
return b
}
// 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(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
if err != nil {
screen.TermMessage(e... | @@ -351,16 +349,15 @@ func (h *BufPane) resetMouse() {
func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
h.Buf.Close()
h.Buf = b
+ // Set the OverwriteModeActive by default to false on open
+ h.Buf.OverwriteModeActive = false | internal/action/bufpane.go | 26 | Go | 0.429 | suggestion | 104 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
fini int32
cursors []*Cursor
curCursor int
StartCursor Loc
// OptionCallback is called after a buffer option value is changed.
// The display module registers its OptionCallback to ensure the buffer window
// is properly updated when needed. This is a workaround for the fact that
// the buffer mod... | `an` is used instead of `a` before a word than begins with a vowel... And regardless, this sentence sounds unclear and weird, don't you find? I suppose a lot of people would have a hard time trying to understand this comment, before finally realizing "ah, that's simply what the Insert key does".
If you're so keen to... | fini int32
cursors []*Cursor
curCursor int
StartCursor Loc
// OptionCallback is called after a buffer option value is changed.
// The display module registers its OptionCallback to ensure the buffer window
// is properly updated when needed. This is a workaround for the fact that
// the buffer mod... | @@ -209,6 +209,10 @@ type Buffer struct {
LastSearchRegex bool
// HighlightSearch enables highlighting all instances of the last successful search
HighlightSearch bool
+
+ // OverwriteMode is used to identify if a inserted character shall replace
+ // the following character. | internal/buffer/buffer.go | 26 | Go | 0.643 | suggestion | 634 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
"hltrailingws": false,
"incsearch": true,
"ignorecase": true,
"indentchar": " ",
"keepautoindent": false,
"matchbrace": true,
"matchbraceleft": true,
"matchbracestyle": "underline",
"mkparents": false,
"pageoverlap": float64(2),
"permbackup": false,
"readonly": ... | This introduces ` | ` even when `[overwrite]` is not displayed.
Why not put `$(overwrite)` right after `$(modified)`? Especially since `[ro]` and `[overwrite]` are now mutually exclusive, so it seems a good idea to put them at the same place. | "hltrailingws": false,
"incsearch": true,
"ignorecase": true,
"indentchar": " ",
"keepautoindent": false,
"matchbrace": true,
"matchbraceleft": true,
"matchbracestyle": "underline",
"mkparents": false,
"pageoverlap": float64(2),
"permbackup": false,
"readonly": ... | @@ -93,7 +93,7 @@ var defaultCommonSettings = map[string]interface{}{
"softwrap": false,
"splitbottom": true,
"splitright": true,
- "statusformatl": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
+ "statusformatl": "$(filena... | internal/config/settings.go | 26 | Go | 0.571 | suggestion | 246 | 51 | 51 | false | statusline: Provide `overwrite` mode indicator | 3,620 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | The callback seems to be called when the value is the same.
This pull request might be merged, but I will test later if there's no other bugs with the callback here. | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | @@ -13,12 +13,19 @@ import (
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
- if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
+ _, local := b.LocalSettings["filetype"]
+ _, volatile := config.VolatileSettings["filetype"]
+ if reloadFiletype && !local && ... | internal/buffer/settings.go | 26 | Go | 0.5 | bug | 166 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | niten94 | JoeKar |
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
config.InitLocalSettin... | I don't know much about the code handling configuration so I might be thinking something wrong.
`config.InitLocalSettings` is not called when `filetype` changes here. It is called when `filetype` changes after `b.UpdateRules()`, so removing the if statement and moving `oldValue` to the beginning of `ReloadSettings` ... | "crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
config.UpdatePathGlobL... | @@ -12,20 +12,33 @@ import (
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
+ config.InitLocalSettings(settings, b.Path)
- if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
+ _, local := b.LocalSettings["filetype"]
+ _, volatile := config.VolatileSetting... | internal/buffer/settings.go | 26 | Go | 0.786 | bug | 344 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | niten94 | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | This causes micro crashing if there is a `ft:` setting in settings.json. | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | @@ -12,27 +12,29 @@ import (
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
+ oldValue := b.Settings["filetype"]
_, local := b.LocalSettings["filetype"]
_, volatile := config.VolatileSettings["filetype"]
if reloadFiletype && !local && !volatile {
// need to up... | internal/buffer/settings.go | 21 | Go | 0.429 | bug | 72 | 46 | 46 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | Is this line a leftover you forgot to remove? AFAICS it is buggy in several ways, and furthermore completely unneeded, since https://github.com/zyedidia/micro/pull/3662/commits/b40854a860e6abae69dc64e9eb61f4e59b7ed6c6? (Which btw means that https://github.com/zyedidia/micro/pull/3662/commits/b40854a860e6abae69dc64e9eb6... | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | @@ -18,6 +18,8 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
if reloadFiletype && !local && !volatile {
// need to update filetype before updating other settings based on it
b.Settings["filetype"] = "unknown"
+ settings["filetype"] = "unknown" | internal/buffer/settings.go | 21 | Go | 0.786 | bug | 547 | 46 | 46 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
oldFileType := b.Settings["filetype"]
_, local := b.LocalSettings["filetype"]
_, volatile := config.VolatileSettings["filetype"]
if reloadFiletype && !local && !volatile {
// need to updat... | I'd also add an empty line after this line. | luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
config.UpdatePathGlobLocals(settings, b.AbsPath)
oldFiletype := b.Settings["filetype"].(string)
_, local := b.LocalSettings["filetype"]
_, volatile := config.VolatileSettings["filetype"]
i... | @@ -27,9 +28,14 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
// update syntax rules, which will also update filetype if needed
b.UpdateRules()
- settings["filetype"] = b.Settings["filetype"]
+ curFileType := b.Settings["filetype"]
+ if oldFileType != curFileType {
+ b.doCallbacks("filetype", oldFi... | internal/buffer/settings.go | 26 | Go | 0.071 | suggestion | 43 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must be called after ReadSettings
func InitGlobalSettings() error {
var err error
GlobalSettings = DefaultAllSettings()
for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
... | This could be just `if filetype, ok := settings["filetype"]; ok && filetype.(string) == k[3:] {` ?
And about the commit message: as always, it would be good if it described not just _what_ the commit does but _why_ does it do what it does (i.e. in this case, _why_ does `InitLocalSettings()` need to check for presenc... | // InitGlobalSettings initializes the options map and sets all options to their default values
// Must be called after ReadSettings
func InitGlobalSettings() error {
var err error
GlobalSettings = DefaultAllSettings()
for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
... | @@ -295,7 +295,11 @@ func InitLocalSettings(settings map[string]interface{}, path string) {
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
if strings.HasPrefix(k, "ft:") {
- if settings["filetype"].(string) == k[3:] {
+ filetype, ok := settings["filetype"]
+ ... | internal/config/settings.go | 26 | Go | 0.786 | suggestion | 458 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | BTW this duplicated calling of `InitLocalSettings()` looks ugly and confusing. I think we should at least add a comment explaining why it is here. But it seems cleaner to split `InitLocalSettings()` into 2 separate functions instead: for handling `ft:` settings and for handling glob settings? | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | @@ -18,6 +18,8 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
if reloadFiletype && !local && !volatile {
// need to update filetype before updating other settings based on it
b.Settings["filetype"] = "unknown"
+ settings["filetype"] = "unknown"
+ config.InitLocalSettings(settings, b.Path) | internal/buffer/settings.go | 22 | Go | 0.643 | refactor | 293 | 47 | 47 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
return nil
}
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must be called after ReadSettings
func InitGlobalSettings() error {
var err error
GlobalSettings = DefaultAllSettings()
for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).Strin... | We don't need to add this check anymore?
(In other words, the commit message is not just not very helpful (as it doesn't explain in what cases `settings["filetype"]` may be unset) but also misleading, as there are no such cases anymore?) |
return nil
}
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must be called after ReadSettings
func InitGlobalSettings() error {
var err error
GlobalSettings = DefaultAllSettings()
for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).Strin... | @@ -295,7 +295,7 @@ func InitLocalSettings(settings map[string]interface{}, path string) {
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
if strings.HasPrefix(k, "ft:") {
- if settings["filetype"].(string) == k[3:] {
+ if filetype, ok := settings["filetype"];... | internal/config/settings.go | 26 | Go | 0.714 | suggestion | 240 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
if err := OptionIsValid(option, value); err != nil {
return err
}
return nil
}
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must be called after ReadSettings
func InitGlobalSettings() error {
var err error
GlobalSettings = DefaultAllSettings()
for k, v :=... | Subjective nit: maybe `UpdatePathGlobLocals()` and `UpdateFileTypeLocals()`? In line with `UpdateRules()`, etc. |
if err := OptionIsValid(option, value); err != nil {
return err
}
return nil
}
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must be called after ReadSettings
func InitGlobalSettings() error {
var err error
GlobalSettings = DefaultAllSettings()
for k, v :=... | @@ -288,24 +288,31 @@ func InitGlobalSettings() error {
return err
}
-// InitLocalSettings scans the json in settings.json and sets the options locally based
-// on whether the filetype or path matches ft or glob local settings
+// ApplyPathGlobLocals scans the already parsed settings and sets the options locally
... | internal/config/settings.go | 26 | Go | 0.643 | nitpick | 111 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType)
}
if err := OptionIsValid(option, value); err != nil {
return err
}
return nil
}
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must... | "based on whether the path matches a glob"? | return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType)
}
if err := OptionIsValid(option, value); err != nil {
return err
}
return nil
}
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must... | @@ -288,24 +288,31 @@ func InitGlobalSettings() error {
return err
}
-// InitLocalSettings scans the json in settings.json and sets the options locally based
-// on whether the filetype or path matches ft or glob local settings
+// ApplyPathGlobLocals scans the already parsed settings and sets the options locally
... | internal/config/settings.go | 26 | Go | 0.071 | question | 43 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
} else {
// in case of autodetection treat as locally set
b.LocalSettings["fileformat"] = true
}
b.LineArray = NewLineArray(uint64(size), ff, reader)
}
b.EventHandler = NewEventHandler(b.SharedBuffer, b.cursors)
// The last time this file was modified
b.UpdateModTime()
}
if b.Settings["rea... | Let's make it clear (not force the reader to guess what does "potential" mean here, etc): "...so update per-filetype settings"? | }
if b.Settings["readonly"].(bool) && b.Type == BTDefault {
b.Type.Readonly = true
}
switch b.Endings {
case FFUnix:
b.Settings["fileformat"] = "unix"
case FFDos:
b.Settings["fileformat"] = "dos"
}
b.UpdateRules()
// we know the filetype now, so update per-filetype settings
config.UpdateFileTypeLocal... | @@ -397,8 +397,8 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
}
b.UpdateRules()
- // init local settings again now that we know the filetype
- config.InitLocalSettings(b.Settings, b.Path)
+ // we know the filetype now, so apply potential locals | internal/buffer/buffer.go | 26 | Go | 0.5 | question | 127 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | Shouldn't we do this even if `reloadFiletype` is false?
We need glob matching for any settings, for just `filetype`, right? | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | @@ -18,6 +18,7 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
if reloadFiletype && !local && !volatile {
// need to update filetype before updating other settings based on it
b.Settings["filetype"] = "unknown"
+ config.ApplyPathGlobLocals(settings, b.Path) | internal/buffer/settings.go | 21 | Go | 0.714 | question | 126 | 46 | 46 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | `oldFiletype`? In line with `reloadFiletype`, etc.
(Yeah, it was me who suggested `oldFileType`, sorry.) | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | @@ -12,6 +12,7 @@ import (
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
+ oldFileType := b.Settings["filetype"] | internal/buffer/settings.go | 15 | Go | 0.643 | suggestion | 105 | 40 | 40 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
hasBackup := false
if !found {
b.SharedBuffer = new(SharedBuffer)
b.Type = btype
b.AbsPath = absPath
b.Path = path
// this is a little messy since we need to know some settings to read
// the file properly, but some settings depend on the filetype, which
// we don't know until reading the file. We fi... | This only updates `settings`. `b.Settings` are never updated (except 3 of them below).
This is a regression: glob locals don't work anymore (I assume you didn't test it?), they only work after a `reload`. |
hasBackup := false
if !found {
b.SharedBuffer = new(SharedBuffer)
b.Type = btype
b.AbsPath = absPath
b.Path = path
b.Settings = config.DefaultCommonSettings()
b.LocalSettings = make(map[string]bool)
for k, v := range config.GlobalSettings {
if _, ok := config.DefaultGlobalOnlySettings[k]; !ok {
... | @@ -341,7 +341,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
b.Settings[k] = v
}
}
- config.InitLocalSettings(settings, absPath)
+ config.ApplyPathGlobLocals(settings, absPath) | internal/buffer/buffer.go | 26 | Go | 0.571 | suggestion | 205 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
oldFileType := b.Settings["filetype"]
_, local := b.LocalSettings["filetype"]
_, volatile := config.VolatileSettings["filetype"]
if reloadFiletype && !local && !volatile {
// need to update filetype before updating oth... | Maybe it's cleaner to just pass the filetype to `ApplyFileTypeLocals()` as an argument... | )
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
config.UpdatePathGlobLocals(settings, b.AbsPath)
oldFiletype := b.Settings["filetype"].(string)
_, local := b.LocalSettings["filetype"]
_, volatile := config.VolatileSettings["filetype"]
if reloadFiletype && !local && ... | @@ -26,9 +27,15 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
// update syntax rules, which will also update filetype if needed
b.UpdateRules()
- settings["filetype"] = b.Settings["filetype"]
+ curFileType := b.Settings["filetype"]
+ if oldFileType != curFileType {
+ b.doCallbacks("filetype", oldFi... | internal/buffer/settings.go | 26 | Go | 0.5 | suggestion | 89 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
// ApplyPathGlobLocals scans the already parsed settings and sets the options locally
// based on the path which matches the glob
// Must be called after ReadSettings
func ApplyPathGlobLocals(settings map[string]interface{}, path string) {
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).St... | While we're at it, we may address such case:
```
"ft:go" {
"filetype": "c"
}
```
to prevent it from causing unpredictable results? |
// UpdatePathGlobLocals scans the already parsed settings and sets the options locally
// based on whether the path matches a glob
// Must be called after ReadSettings
func UpdatePathGlobLocals(settings map[string]interface{}, path string) {
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).... | @@ -288,24 +288,31 @@ func InitGlobalSettings() error {
return err
}
-// InitLocalSettings scans the json in settings.json and sets the options locally based
-// on whether the filetype or path matches ft or glob local settings
+// ApplyPathGlobLocals scans the already parsed settings and sets the options locally
... | internal/config/settings.go | 26 | Go | 0.857 | question | 140 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
GlobalSettings[k] = v
}
}
return err
}
// UpdatePathGlobLocals scans the already parsed settings and sets the options locally
// based on whether the path matches a glob
// Must be called after ReadSettings
func Upd... | Again, "based on whether the filetype matches to "ft:""? | for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
GlobalSettings[k] = v
}
}
return err
}
// UpdatePathGlobLocals scans the already parsed settings and sets the options locally
// based on whether the path matches a glob
// Must be called after ReadSettings
func Upd... | @@ -288,24 +288,31 @@ func InitGlobalSettings() error {
return err
}
-// InitLocalSettings scans the json in settings.json and sets the options locally based
-// on whether the filetype or path matches ft or glob local settings
+// UpdatePathGlobLocals scans the already parsed settings and sets the options locally... | internal/config/settings.go | 26 | Go | 0.357 | question | 56 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
_, local := b.LocalSe... | Technically this is a regression (although fixed by https://github.com/zyedidia/micro/pull/3662/commits/e16c8de0b2364ac9d0a6d95c1a4b9a7e9105e059 afterwards): glob settings no longer updated on reload.
I.e. if we don't want any single commit to introduce regressions (to keep it bisection-friendly etc), we should call... | "crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
config.UpdatePathGlobL... | @@ -25,9 +25,8 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
// update syntax rules, which will also update filetype if needed
b.UpdateRules()
- settings["filetype"] = b.Settings["filetype"]
- config.InitLocalSettings(settings, b.Path)
+ config.UpdateFileTypeLocals(settings, b.Settings["filetype"].(... | internal/buffer/settings.go | 26 | Go | 0.786 | suggestion | 1,327 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
oldFiletype := b.Settings["filetyp... | nit: I'd move it below:
```go
diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go
index afb6ae72..37465a92 100644
--- a/internal/buffer/settings.go
+++ b/internal/buffer/settings.go
@@ -11,10 +11,11 @@ import (
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
- oldFiletype := ... | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings(... | @@ -11,6 +11,7 @@ import (
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
+ oldFiletype := b.Settings["filetype"] | internal/buffer/settings.go | 14 | Go | 1 | nitpick | 787 | 39 | 39 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
oldFiletype := b.Settings["filetype"]
settings := config.ParsedSettings()
config.UpdatePathGlobLocals(settings, b.AbsPath)
_, local := b.LocalSettings["filetype"]
_, volatile := config.VolatileSettings["filetype"]
if reloadFiletype && !local && !volatile ... | We could also set `curFiletype` and `oldFiletype` to`b.Settings["filetype"].(string)` instead of type-asserting it here. | )
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
config.UpdatePathGlobLocals(settings, b.AbsPath)
oldFiletype := b.Settings["filetype"].(string)
_, local := b.LocalSettings["filetype"]
_, volatile := config.VolatileSettings["filetype"]
if reloadFiletype && !local && ... | @@ -27,7 +28,13 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
// update syntax rules, which will also update filetype if needed
b.UpdateRules()
- config.UpdateFileTypeLocals(settings, b.Settings["filetype"].(string))
+ curFiletype := b.Settings["filetype"]
+ if oldFiletype != curFiletype {
+ b.doCall... | internal/buffer/settings.go | 26 | Go | 0.714 | suggestion | 120 | 51 | 51 | false | buffer: Fix `ReloadSettings(true)` for volatile `filetype` | 3,662 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
VERSION = "1.1.0"
local micro = import("micro")
local buffer = import("micro/buffer")
local config = import("micro/config")
local shell = import("micro/shell")
local filepath = import("filepath")
local humanize = import("humanize")
local strings = import("strings")
function init()
micro.SetStatusInfoFn("status.br... | The version of builtin plugins does not seem to be updated and there is only a fix done in this pull request, so I don't know if this would be fine. I'll revert this sometime around this week. | VERSION = "1.0.0"
local micro = import("micro")
local buffer = import("micro/buffer")
local config = import("micro/config")
local shell = import("micro/shell")
local filepath = import("filepath")
local humanize = import("humanize")
local strings = import("strings")
function init()
micro.SetStatusInfoFn("status.br... | @@ -1,9 +1,12 @@
-VERSION = "1.0.0"
+VERSION = "1.1.0" | runtime/plugins/status/status.lua | 1 | Lua | 0.357 | suggestion | 192 | 26 | 26 | false | `status.lua`: Display commit and branch of repository where file is located | 3,673 | zyedidia/micro | 13,805 | Go | niten94 | niten94 |
// else accordingly
func (n *Node) Unsplit() bool {
if !n.IsLeaf() || n.parent == nil {
return false
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
if n.parent.Kind == STVert {
n.parent.unsplit(ind, true)
} else {
n.parent.unsplit(ind, false)
}
if n.parent.IsLeaf()... | nit: Maybe clarify a bit better what this actually means, e.g. "Simplify removes unnecessary intermediate parents that have just one child"?
(Since just from looking at the code it is not immediately obvious that the check `len(n.children) != 1` is crucial.) | // Unsplit deletes this split and resizes everything
// else accordingly
func (n *Node) Unsplit() bool {
if !n.IsLeaf() || n.parent == nil {
return false
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
n.parent.unsplit(ind)
if n.parent.IsLeaf() {
return n.parent.Unsplit(... | @@ -479,9 +479,32 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.simplify()
return true
}
+// Simplify removes unnecessary chained parents | internal/views/splits.go | 26 | Go | 0.643 | refactor | 261 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if n.parent.Kind == STVert {
n.parent.unsplit(ind, true)
} else {
n.parent.unsplit(ind, false)
}
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
n.parent.simplify()
return true
}
// Simplify removes unnecessary chained parents
func (n *Node) simplify() {
if n.parent == nil || len(n.children) != 1 {
... | nit: Are these 2 temporary variable necessary? | }
n.parent.unsplit(ind)
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
n.parent.flatten()
return true
}
// flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
... | @@ -479,9 +479,32 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.simplify()
return true
}
+// Simplify removes unnecessary chained parents
+func (n *Node) simplify() {
+ if n.parent == nil || len(n.children) != 1 {
+ return
+ }
+
+ ind := 0
+ for i, c := ... | internal/views/splits.go | 26 | Go | 0.071 | question | 46 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
// Unsplit deletes this split and resizes everything
// else accordingly
func (n *Node) Unsplit() bool {
if !n.IsLeaf() || n.parent == nil {
return false
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
n.parent.unsplit(ind)
if n.parent.IsLeaf() {
return n.parent.Unsplit... | This fixes a regression in https://github.com/zyedidia/micro/pull/3708/commits/ec4ca05aa21ecc2badc3dc83afa6a792781c5cd1 so this commit should be squashed into https://github.com/zyedidia/micro/pull/3708/commits/ec4ca05aa21ecc2badc3dc83afa6a792781c5cd1 ?
Also just a question: could you describe an example test when t... |
// Unsplit deletes this split and resizes everything
// else accordingly
func (n *Node) Unsplit() bool {
if !n.IsLeaf() || n.parent == nil {
return false
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
n.parent.unsplit(ind)
if n.parent.IsLeaf() {
return n.parent.Unsplit... | @@ -483,6 +483,7 @@ func (n *Node) Unsplit() bool {
// Simplify removes unnecessary chained parents
func (n *Node) simplify() {
if n.parent == nil || len(n.children) != 1 {
+ n.markResize() | internal/views/splits.go | 26 | Go | 0.643 | bug | 540 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
}
n.parent.simplify()
return true
}
// simplify removes unnecessary intermediate parents that have only one child
func (n *Node) simplify() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
n.parent.children[ind] = ... | nit: "the child node"? (just to be clear that this is not about the `n` node) | }
// flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
// Replace cur... | @@ -479,9 +479,35 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.simplify()
return true
}
+// simplify removes unnecessary intermediate parents that have only one child
+func (n *Node) simplify() {
+ if n.parent == nil || len(n.children) != 1 {
+ return
+... | internal/views/splits.go | 26 | Go | 0.357 | nitpick | 77 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if c.id == n.id {
ind = i
}
}
if len(n.children) == 1 {
// Replace current node with child node to remove chained parent
n.parent.children[ind] = n.children[0]
n.parent.children[ind].parent = n.parent
if n.children[0].IsLeaf() {
n.parent.children[ind].Kind = n.Kind
} else {
// Flatten the chil... | if `ind == origsize-1`, the second slice has length 0, so `copy` is a no-op, so we can omit this if? |
// Replace current node with its child node to remove chained parent
successor := n.children[0]
n.parent.children[ind] = successor
successor.parent = n.parent
// Maintain the tree in a consistent state: any child node's kind (horiz vs vert)
// should be the opposite of its parent's kind.
if successor.IsLeaf() ... | @@ -479,9 +479,58 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 0.5 | question | 100 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if len(n.children) == 1 {
// Replace current node with child node to remove chained parent
n.parent.children[ind] = n.children[0]
n.parent.children[ind].parent = n.parent
if n.children[0].IsLeaf() {
n.parent.children[ind].Kind = n.Kind
} else {
// Flatten the child node that replaced the current node
... | nit: maybe use `copy` instead (although it makes no functional difference), just to keep the same "style" as above?
And then in combination with my above 2 suggestions, we can beautify the code as follows:
```go
--- a/internal/views/splits.go
+++ b/internal/views/splits.go
@@ -513,12 +513,12 @@ func (n *Node) ... | successor.parent = n.parent
// Maintain the tree in a consistent state: any child node's kind (horiz vs vert)
// should be the opposite of its parent's kind.
if successor.IsLeaf() {
successor.Kind = n.Kind
} else {
// If the successor node has children, that means it is a chained parent as well.
// Therefor... | @@ -479,9 +479,58 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 0.857 | suggestion | 971 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if n.children[0].IsLeaf() {
n.parent.children[ind].Kind = n.Kind
} else {
// Flatten the child node that replaced the current node
n.parent.children[ind].flatten()
}
} else if !n.IsLeaf() && n.Kind == n.parent.Kind {
// If we have the same kind as the parent (cuased by previous flattening),
// repla... | Maybe add ", so the children may have new siblings"? | successor.Kind = n.Kind
} else {
// If the successor node has children, that means it is a chained parent as well.
// Therefore it can be replaced by its own children.
origsize := len(n.parent.children)
// Let's say we have 5 children and want to replace [2] with its children [a] [b] [c]
// [0] [1] [2] [3... | @@ -479,9 +479,58 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 0.214 | question | 52 | 50 | 46 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
}
}
if len(n.children) == 1 {
// Replace current node with its child node to remove chained parent
n.parent.children[ind] = n.children[0]
n.parent.children[ind].parent = n.parent
if n.children[0].IsLeaf() {
n.parent.children[ind].Kind = n.Kind
} else {
// Flatten the child node that replaced the cu... | `n.children`, not `n.parent.children`.
I've observed at least 2 problems because of this:
1. Open a vsplit, then a hsplit in the right split, then a vsplit in the right bottom split, then close the right top split (so that only vertical splits remain), then open another vsplit -> proportional resize isn't really wo... | successor := n.children[0]
n.parent.children[ind] = successor
successor.parent = n.parent
// Maintain the tree in a consistent state: any child node's kind (horiz vs vert)
// should be the opposite of its parent's kind.
if successor.IsLeaf() {
successor.Kind = n.Kind
} else {
// If the successor node has ch... | @@ -479,9 +479,59 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 1 | bug | 1,957 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
// Replace current node with its child node to remove chained parent
n.parent.children[ind] = n.children[0]
n.parent.children[ind].parent = n.parent
if n.children[0].IsLeaf() {
n.parent.children[ind].Kind = n.Kind
} else {
// Flatten the child node that replaced the current node
n.parent.children[ind... | I've realized it probably doesn't make sense to call `markSizes()` after return from the recursive call at line 509? Even if it doesn't cause problems, it seems it just needlessly updates the same parent that has just been updated inside the recursive call?
So, maybe for code clarity:
```
diff --git a/internal/vie... | // Maintain the tree in a consistent state: any child node's kind (horiz vs vert)
// should be the opposite of its parent's kind.
if successor.IsLeaf() {
successor.Kind = n.Kind
} else {
// If the successor node has children, that means it is a chained parent as well.
// Therefore it can be replaced by its ow... | @@ -479,9 +479,59 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 1 | bug | 1,363 | 51 | 49 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
n.parent.flatten()
return true
}
// flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
... | `!successor.IsLeaf()` here is redundant?
And actually `successor.Kind == n.parent.Kind` seems redundant too, it should always be true, unless we have a bug? | // flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
// Replace curren... | @@ -479,9 +479,56 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 0.714 | bug | 159 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
}
// flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
// Replace cur... | If we remove `successor.Kind == n.parent.Kind` above as redundant, we can update this comment like: "If the successor node has its own children, it means it is a redundant chained parent too, so replace it with its children."? | func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
ind = i
}
}
// Replace current node with its child node to remove chained parent
successor := n.children[0]
n.parent.children[ind] = successor
successor.p... | @@ -479,9 +479,56 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 0.643 | question | 226 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
successor := n.parent.children[ind]
successor.parent = n.parent
if successor.IsLeaf() {
successor.Kind = n.Kind
} else if !successor.IsLeaf() && successor.Kind == n.parent.Kind {
// If we have the same kind as the parent (caused by removing chained parent),
// replace successor node with its children.
orig... | s/might have been updated/has been updated/
s/may have new siblings/have new siblings/
? | // should be the opposite of its parent's kind.
if successor.IsLeaf() {
successor.Kind = n.Kind
} else {
// If the successor node has children, that means it is a chained parent as well.
// Therefore it can be replaced by its own children.
origsize := len(n.parent.children)
// Let's say we have 5 children... | @@ -479,9 +479,56 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 0.214 | question | 92 | 50 | 48 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
n.parent.flatten()
return true
}
// flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for... | Maybe add a comment above this line: "Make sure the tree remains in a consistent state: any child node's kind (horizontal vs vertical) is the opposite of its parent's kind"?
Also why not rearrange the lines like this:
```go
--- a/internal/views/splits.go
+++ b/internal/views/splits.go
@@ -495,10 +495,12 @@ func ... | n.parent.flatten()
return true
}
// flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
return
}
ind := 0
for i, c := range n.parent.children {
if c.id == n.id {
... | @@ -479,9 +479,56 @@ func (n *Node) Unsplit() bool {
if n.parent.IsLeaf() {
return n.parent.Unsplit()
}
+
+ n.parent.flatten()
return true
}
+// flattens the tree by removing unnecessary intermediate parents that have only one child
+// and handles the side effect of it
+func (n *Node) flatten() {
+ if n.pa... | internal/views/splits.go | 26 | Go | 0.857 | suggestion | 873 | 51 | 51 | false | Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit | 3,708 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
InfoBar.Message("")
return true
}
// ForceQuit closes the current tab or view even if there are unsaved changes
// (no prompt)
func (h *BufPane) ForceQuit() bool {
h.Buf.Close()
if len(MainTab().Panes) > 1 {
h.Unsplit()
} else if len(Tabs.List) > 1 {
Tabs.RemoveTab(h.splitID)
} else {
screen.Screen.Fini()
... | Or just `if h.Buf.Modified() && !h.Buf.Shared()` like in other functions? | InfoBar.Message("")
return true
}
// ForceQuit closes the current tab or view even if there are unsaved changes
// (no prompt)
func (h *BufPane) ForceQuit() bool {
h.Buf.Close()
if len(MainTab().Panes) > 1 {
h.Unsplit()
} else if len(Tabs.List) > 1 {
Tabs.RemoveTab(h.splitID)
} else {
screen.Screen.Fini()
... | @@ -1910,11 +1910,9 @@ func (h *BufPane) ForceQuit() bool {
// Quit this will close the current tab or view that is open
func (h *BufPane) Quit() bool {
if h.Buf.Modified() {
- for _, b := range buffer.OpenBuffers {
- if b != h.Buf && b.SharedBuffer == h.Buf.SharedBuffer {
- h.ForceQuit()
- return true
- ... | internal/action/actions.go | 26 | Go | 0.357 | question | 73 | 51 | 51 | false | Skip save on `open` or `term` command if buffer is shared | 3,719 | zyedidia/micro | 13,805 | Go | dmaluka | niten94 |
return true
}
// ClearInfo clears the infobar
func (h *BufPane) ClearInfo() bool {
if InfoBar.Msg == "" {
return false
}
InfoBar.Message("")
return true
}
// ForceQuit closes the current tab or view even if there are unsaved changes
// (no prompt)
func (h *BufPane) ForceQuit() bool {
h.Buf.Close()
if len(Mai... | > This slightly changes the open and term command to be similar with the
Quit action, where the buffer or pane is replaced after the prompts are
completed if "n" wasn't pressed after the 1st prompt.
This sounds like there is some functional change, not just code refactoring, but AFAICS there is no functional chang... | return true
}
// ClearInfo clears the infobar
func (h *BufPane) ClearInfo() bool {
if InfoBar.Msg == "" {
return false
}
InfoBar.Message("")
return true
}
// ForceQuit closes the current tab or view even if there are unsaved changes
// (no prompt)
func (h *BufPane) ForceQuit() bool {
h.Buf.Close()
if len(Mai... | @@ -1907,6 +1907,18 @@ func (h *BufPane) ForceQuit() bool {
return true | internal/action/actions.go | 26 | Go | 0.5 | refactor | 341 | 51 | 51 | false | Skip save on `open` or `term` command if buffer is shared | 3,719 | zyedidia/micro | 13,805 | Go | dmaluka | niten94 |
// OpenCmd opens a new buffer with a given filename
func (h *BufPane) OpenCmd(args []string) {
if len(args) > 0 {
filename := args[0]
// the filename might or might not be quoted, so unquote first then join the strings.
args, err := shellquote.Split(filename)
if err != nil {
InfoBar.Error("Error parsing ar... | Passing action="Save" will cause executing `onSave` callback?
Reminds me of https://github.com/zyedidia/micro/pull/3689#discussion_r1990022986
At the moment I'm inclined to think it's ok. |
// OpenCmd opens a new buffer with a given filename
func (h *BufPane) OpenCmd(args []string) {
if len(args) > 0 {
filename := args[0]
// the filename might or might not be quoted, so unquote first then join the strings.
args, err := shellquote.Split(filename)
if err != nil {
InfoBar.Error("Error parsing ar... | @@ -309,14 +309,7 @@ func (h *BufPane) OpenCmd(args []string) {
h.OpenBuffer(b)
}
if h.Buf.Modified() && !h.Buf.Shared() {
- InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
- if !canceled && !yes {
- open()
- } else if !canceled && yes {... | internal/action/command.go | 26 | Go | 0.571 | suggestion | 193 | 51 | 51 | false | Skip save on `open` or `term` command if buffer is shared | 3,719 | zyedidia/micro | 13,805 | Go | dmaluka | niten94 |
}
// TermCmd opens a terminal in the current view
func (h *BufPane) TermCmd(args []string) {
if !TermEmuSupported {
InfoBar.Error("Terminal emulator not supported on this system")
return
}
if len(args) == 0 {
sh := os.Getenv("SHELL")
if sh == "" {
InfoBar.Error("Shell environment not found")
return
... | What about `else`?
It's a regression (try it). | }
// TermCmd opens a terminal in the current view
func (h *BufPane) TermCmd(args []string) {
if !TermEmuSupported {
InfoBar.Error("Terminal emulator not supported on this system")
return
}
if len(args) == 0 {
sh := os.Getenv("SHELL")
if sh == "" {
InfoBar.Error("Shell environment not found")
return
... | @@ -1077,52 +1109,17 @@ func (h *BufPane) TermCmd(args []string) {
args = []string{sh}
}
- term := func(i int, newtab bool) {
- t := new(shell.Terminal)
- err := t.Start(args, false, true, nil, nil)
- if err != nil {
- InfoBar.Error(err)
- return
- }
-
- id := h.ID()
- if newtab {
- h.AddTab()
- i ... | internal/action/command.go | 26 | Go | 0.214 | question | 47 | 51 | 51 | false | command: Fix crash caused by `TermCmd()` | 3,738 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
continue
}
}
}
}
continue
}
if k == "autosave" {
// if autosave is a boolean convert it to float
s, ok := v.(bool)
if ok {
if s {
parsedSettings["autosave"] = 8.0
} else {
parsedSettings["autosave"] = 0.0
}
}
continue
}
if k == "indentchar" {
... | > I am happy to revert the prompt message of telling user `indentchar` is deprecated, if people/maintainer finds it controversial.
Definitely!
You already added the mechanism to convert it, which is fine. We can add a deprecation note here.
Most probably we should only overwrite `indenttabchar` in case it doesn't ... | }
}
}
}
continue
}
if k == "autosave" {
// if autosave is a boolean convert it to float
s, ok := v.(bool)
if ok {
if s {
parsedSettings["autosave"] = 8.0
} else {
parsedSettings["autosave"] = 0.0
}
}
continue
}
if _, ok := defaults[k]; ok {
if e := ... | @@ -210,6 +212,13 @@ func validateParsedSettings() error {
}
continue
}
+
+ if k == "indentchar" {
+ // migrate to "indenttabchar" from "indentchar"
+ parsedSettings["indenttabchar"] = v
+ err = errors.New("indentchar has been deprecated, use indenttabchar instead")
+ } | internal/config/settings.go | 26 | Go | 0.786 | suggestion | 450 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | JoeKar | Neko-Box-Coder |
if err := OptionIsValid(option, value); err != nil {
return err
}
return nil
}
// InitGlobalSettings initializes the options map and sets all options to their default values
// Must be called after ReadSettings
func InitGlobalSettings() error {
var err error
GlobalSettings = DefaultAllSettings()
for k, v := ... | Do we really need to check this here once again?
We've validated and maybe extended the settings (even the maps) in `validateParsedSettings()` already. | for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
GlobalSettings[k] = v
}
}
return err
}
// UpdatePathGlobLocals scans the already parsed settings and sets the options locally
// based on whether the path matches a glob
// Must be called after ReadSettings
func Upd... | @@ -295,6 +310,7 @@ func InitGlobalSettings() error {
// based on whether the path matches a glob
// Must be called after ReadSettings
func UpdatePathGlobLocals(settings map[string]interface{}, path string) {
+ checkDeprecatedSettings(settings) | internal/config/settings.go | 26 | Go | 0.5 | question | 152 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | JoeKar | Neko-Box-Coder |
tabsize := util.IntOpt(b.Settings["tabsize"])
colorcolumn := util.IntOpt(b.Settings["colorcolumn"])
// this represents the current draw position
// within the current window
vloc := buffer.Loc{X: 0, Y: 0}
if softwrap {
// the start line may be partially out of the current window
vloc.Y = -w.StartLine.Row
}
... | The `charsentries` variable is unnecessary, we can directly use `strings.Split()` here. From Go spec (https://go.dev/ref/spec#For_range): "The range expression `x` is evaluated before beginning the loop". | tabsize := util.IntOpt(b.Settings["tabsize"])
colorcolumn := util.IntOpt(b.Settings["colorcolumn"])
// this represents the current draw position
// within the current window
vloc := buffer.Loc{X: 0, Y: 0}
if softwrap {
// the start line may be partially out of the current window
vloc.Y = -w.StartLine.Row
}
... | @@ -450,6 +451,32 @@ func (w *BufWindow) displayBuffer() {
cursors := b.GetCursors()
curStyle := config.DefStyle
+
+ // Parse showchars which is in the format of option1=val1,option2=val2,...
+ spacechars := " "
+ tabchars := b.Settings["indentchar"].(string)
+ indentspacechars := " "
+ indenttabchars := b.Settin... | internal/display/bufwindow.go | 26 | Go | 0.643 | suggestion | 204 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
vloc := buffer.Loc{X: 0, Y: 0}
if softwrap {
// the start line may be partially out of the current window
vloc.Y = -w.StartLine.Row
}
// this represents the current draw position in the buffer (char positions)
bloc := buffer.Loc{X: -1, Y: w.StartLine.Line}
cursors := b.GetCursors()
curStyle := config.DefS... | What if the value itself contains `=`?
...How about:
```go
split := strings.SplitN(entry, "=", 2)
if len(split) < 2 {
continue
}
key, val := split[0], split[1]
``` | vloc := buffer.Loc{X: 0, Y: 0}
if softwrap {
// the start line may be partially out of the current window
vloc.Y = -w.StartLine.Row
}
// this represents the current draw position in the buffer (char positions)
bloc := buffer.Loc{X: -1, Y: w.StartLine.Line}
cursors := b.GetCursors()
curStyle := config.DefS... | @@ -450,6 +451,32 @@ func (w *BufWindow) displayBuffer() {
cursors := b.GetCursors()
curStyle := config.DefStyle
+
+ // Parse showchars which is in the format of option1=val1,option2=val2,...
+ spacechars := " "
+ tabchars := b.Settings["indentchar"].(string)
+ indentspacechars := " "
+ indenttabchars := b.Settin... | internal/display/bufwindow.go | 26 | Go | 0.714 | question | 184 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
}
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(uti... | I think it's better to move `isplaceholder` and `showoffset` somewhere close to the end of the list of arguments (close to other "less important", more "corner-case" arguments `highlight` and `showcursor`).
At least `combc` should be kept after `r` (since `r` and `combc` together represent a displayed visible chara... | if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(util.GetL... | @@ -494,7 +521,7 @@ func (w *BufWindow) displayBuffer() {
}
bloc.X = bslice
- draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
+ draw := func(r rune, showoffset int, combc []rune, isplaceholder bool, style tcell.Style, highlight bool, showcursor bool) { | internal/display/bufwindow.go | 26 | Go | 0.643 | suggestion | 861 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
w.drawGutter(&vloc, &bloc)
}
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bl... | You just remove setting `dontOverrideBackground`? This setting is here for a reason.
Why do we need to move `hltaberrors` and `hltrailingws` handling out of `draw()`? What I was suggesting was just to move overriding the displayed rune (and the style, but only in the case when we override the rune) out of `draw()`. ... | w.drawGutter(&vloc, &bloc)
}
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bl... | @@ -511,37 +606,6 @@ func (w *BufWindow) displayBuffer() {
// over cursor-line and color-column
dontOverrideBackground := origBg != defBg
- if b.Settings["hltaberrors"].(bool) {
- if s, ok := config.Colorscheme["tab-error"]; ok {
- isTab := (r == '\t') || (r == ' ' && !showcursor)
- i... | internal/display/bufwindow.go | 26 | Go | 0.786 | suggestion | 667 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
}
}
}
}
return returnrune, style, bgoverridable
}
draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool, bgoverridable bool) {
if nColsBeforeStart <= 0 && vloc.Y >= 0 {
if highlight {
if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
style... | So, if we have this new `bgoverridable` anyway, what's the point of keeping `dontOverrideBackground`? We can just modify `bgoverridable` itself? | preservebg = true
}
}
}
}
return drawrune, style, preservebg
}
draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool, preservebg bool) {
defer func() {
if nColsBeforeStart <= 0 {
vloc.X++
}
nColsBeforeStart--
}()
if nColsBefore... | @@ -510,36 +624,8 @@ func (w *BufWindow) displayBuffer() {
// syntax or hlsearch highlighting with non-default background takes precedence
// over cursor-line and color-column
dontOverrideBackground := origBg != defBg
-
- if b.Settings["hltaberrors"].(bool) {
- if s, ok := config.Colorscheme[... | internal/display/bufwindow.go | 26 | Go | 0.5 | question | 144 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(util.GetLeadingWhitespace(bline))
trailingwsStart := blineLen - util.CharacterCount(util.GetTraili... | `matchbracestyle` used to be handled after all other options, now it is handled before all other options. Are we sure it will not cause regressions? (At first glance it looks like there are no problems with that, but who knows.) | if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(util.GetLeadingWhitespace(bline))
trailingwsStart := blineLen - util.CharacterCount(util.GetTraili... | @@ -494,133 +519,170 @@ func (w *BufWindow) displayBuffer() {
}
bloc.X = bslice
- draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
- if nColsBeforeStart <= 0 && vloc.Y >= 0 {
- if highlight {
- if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
- style =... | internal/display/bufwindow.go | 26 | Go | 0.786 | style | 228 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if b.Settings["hltrailingws"].(bool) {
if s, ok := config.Colorscheme["trailingws"]; ok {
if bloc.X >= trailingwsStart && bloc.X < blineLen {
hl := true
for _, c := range cursors {
if c.NewTrailingWsY == bloc.Y {
hl = false
break
}
}
if hl {
fg, ... | Don't you think you are doing way too many different (and not exactly related) changes in the same commit? Any chances you can split them into separate commits, for easier review (not just by me)? | }
if b.Settings["hltrailingws"].(bool) {
if s, ok := config.Colorscheme["trailingws"]; ok {
if bloc.X >= trailingwsStart && bloc.X < blineLen {
hl := true
for _, c := range cursors {
if c.NewTrailingWsY == bloc.Y {
hl = false
break
}
}
if hl {
... | @@ -494,133 +519,170 @@ func (w *BufWindow) displayBuffer() {
}
bloc.X = bslice
- draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
- if nColsBeforeStart <= 0 && vloc.Y >= 0 {
- if highlight {
- if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
- style =... | internal/display/bufwindow.go | 26 | Go | 0.429 | question | 196 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
for _, mb := range matchingBraces {
if mb.X == bloc.X && mb.Y == bloc.Y {
if b.Settings["matchbracestyle"].(string) == "highlight" {
if s, ok := config.Colorscheme["match-brace"]; ok {
return r, s, bgoverridable
} else {
return r, style.Reverse(true), bgoverridable
}
} e... | Instead of having this `else` branch which duplicates the outer `else` branch below, we can just add `indenttabchars != ""` to the outer `if` condition?
Ditto for `spacechars` below. | for _, mb := range matchingBraces {
if mb.X == bloc.X && mb.Y == bloc.Y {
if b.Settings["matchbracestyle"].(string) == "highlight" {
if s, ok := config.Colorscheme["match-brace"]; ok {
return r, s, false
} else {
return r, style.Reverse(true), false
}
} else {
retu... | @@ -514,28 +539,45 @@ func (w *BufWindow) displayBuffer() {
}
}
- if r != '\t' && r != ' '{
+ if r != '\t' && r != ' ' {
return r, style, bgoverridable
}
- var returnrune rune
- if r == '\t' {
- indentrunes := []rune(b.Settings["indentchar"].(string))
- // if empty indentchar setting... | internal/display/bufwindow.go | 26 | Go | 0.571 | refactor | 185 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
return r, style.Reverse(true), bgoverridable
}
} else {
return r, style.Underline(true), bgoverridable
}
}
}
if r != '\t' && r != ' ' {
return r, style, bgoverridable
}
var indentrunes []rune
switch r {
case '\t':
if bloc.X < leadingwsEnd {
if indenttabc... | Simply checking `bloc.X%tabsize == 0` is buggy, since `bloc.X` is not necessarily the _visual_ position of the character in the line (since there may be tab characters in the line before this space character). Try it: put some space characters after some tab characters (before the first visible character in a line) -> ... | return r, style.Reverse(true), false
}
} else {
return r, style.Underline(true), false
}
}
}
if r != '\t' && r != ' ' {
return r, style, false
}
var indentrunes []rune
switch r {
case '\t':
if bloc.X < leadingwsEnd && indenttabchars != "" {
indentrunes =... | @@ -514,28 +539,45 @@ func (w *BufWindow) displayBuffer() {
}
}
- if r != '\t' && r != ' '{
+ if r != '\t' && r != ' ' {
return r, style, bgoverridable
}
- var returnrune rune
- if r == '\t' {
- indentrunes := []rune(b.Settings["indentchar"].(string))
- // if empty indentchar setting... | internal/display/bufwindow.go | 26 | Go | 0.786 | bug | 417 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
var indentrunes []rune
switch r {
case '\t':
if bloc.X < leadingwsEnd {
if indenttabchars != "" {
indentrunes = []rune(indenttabchars)
} else {
indentrunes = []rune(tabchars)
}
} else {
indentrunes = []rune(tabchars)
}
case ' ':
if bloc.X%tabsize == 0 && bloc... | nit: maybe `drawrune` instead (in line with the name used by the callers, and because the meaning of this variable is precisely: the rune to be drawn)? |
var indentrunes []rune
switch r {
case '\t':
if bloc.X < leadingwsEnd && indenttabchars != "" {
indentrunes = []rune(indenttabchars)
} else {
indentrunes = []rune(tabchars)
}
case ' ':
if linex%tabsize == 0 && bloc.X < leadingwsEnd && indentspacechars != "" {
indentrunes = []... | @@ -514,28 +539,45 @@ func (w *BufWindow) displayBuffer() {
}
}
- if r != '\t' && r != ' '{
+ if r != '\t' && r != ' ' {
return r, style, bgoverridable
}
- var returnrune rune
- if r == '\t' {
- indentrunes := []rune(b.Settings["indentchar"].(string))
- // if empty indentchar setting... | internal/display/bufwindow.go | 26 | Go | 0.571 | question | 151 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(util.Get... | nit: `bgoverridable` remains true in almost all cases, except `hltaberrors` and `hltrailingws`. So maybe move its declaration closer to the point where is becomes useful, i.e. before the `hltaberrors` checks, and in all the earlier `return` statements just use `true`? | case "itab":
indenttabchars = val
}
}
for ; vloc.Y < w.bufHeight; vloc.Y++ {
vloc.X = 0
currentLine := false
for _, c := range cursors {
if !c.HasSelection() && bloc.Y == c.Y && w.active {
currentLine = true
break
}
}
s := lineNumStyle
if currentLine {
s = curNumStyle
}
if ... | @@ -494,7 +494,87 @@ func (w *BufWindow) displayBuffer() {
}
bloc.X = bslice
- draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
+ getRuneStyle := func(r rune, style tcell.Style, isplaceholder bool) (rune, tcell.Style, bool) {
+ bgoverridable := true | internal/display/bufwindow.go | 26 | Go | 0.786 | question | 268 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
fg, _, _ := s.Decompose()
style = style.Background(fg)
bgoverridable = false
}
}
}
}
return returnrune, style, bgoverridable
}
draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool, bgoverridable bool) {
if nColsBeforeStart <= 0 && vloc.... | nit: maybe move this comment inside the `if` (since it relates specifically to the `origBg == defBg` check)? | // use space if no showchars or after we showed showchars
drawrune = ' '
}
if s, ok := config.Colorscheme["indent-char"]; ok {
fg, _, _ := s.Decompose()
style = style.Foreground(fg)
}
preservebg := false
if b.Settings["hltaberrors"].(bool) && bloc.X < leadingwsEnd {
if s, ok := conf... | @@ -509,37 +589,8 @@ func (w *BufWindow) displayBuffer() {
// syntax or hlsearch highlighting with non-default background takes precedence
// over cursor-line and color-column | internal/display/bufwindow.go | 26 | Go | 0.571 | refactor | 108 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
// returns the rune to be drawn, style of it and if the bg should be preserved
getRuneStyle := func(r rune, style tcell.Style, isplaceholder bool) (rune, tcell.Style, bool) {
if nColsBeforeStart > 0 || vloc.Y < 0 || isplaceholder {
return r, style, false
}
for _, mb := range matchingBraces {
if mb... | What's the point of this comment? | }
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(uti... | @@ -494,28 +494,28 @@ func (w *BufWindow) displayBuffer() {
}
bloc.X = bslice
+ // returns the rune to be drawn, style of it and if the bg should be preserved | internal/display/bufwindow.go | 26 | Go | 0.071 | question | 33 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if s, ok := config.Colorscheme["selection"]; ok {
style = s
}
}
if b.Settings["cursorline"].(bool) && w.active && !preservebg &&
!c.HasSelection() && c.Y == bloc.Y {
if s, ok := config.Colorscheme["cursor-line"]; ok {
fg, _, _ := s.Decompose()
style = style.Backg... | Also just realized: this can be even simpler:
```go
// syntax or hlsearch highlighting with non-default background takes precedence
// over cursor-line and color-column
if !preservebg && origBg != defBg {
preservebg = true
}
``` | defer func() {
if nColsBeforeStart <= 0 {
vloc.X++
}
nColsBeforeStart--
}()
if nColsBeforeStart > 0 || vloc.Y < 0 {
return
}
if highlight {
if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
style = config.DefStyle.Reverse(true)
if s, ok := config.Colorscheme["hlse... | @@ -597,10 +598,10 @@ func (w *BufWindow) displayBuffer() {
_, origBg, _ := style.Decompose()
_, defBg, _ := config.DefStyle.Decompose()
- // syntax or hlsearch highlighting with non-default background takes precedence
- // over cursor-line and color-column
- if bgoverridable {
- bgoverridable ... | internal/display/bufwindow.go | 26 | Go | 0.786 | suggestion | 238 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(util.Get... | Any reason why you renamed `showoffset` to `drawoffset`?
Neither name seems quite intuitive to me, but at least `showoffset` somehow relates to `showchars` (and `showchars` is the only reason for the existence of this argument, right?). |
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes(bloc.Y)
blineLen := util.CharacterCount(bline)
leadingwsEnd := len(util.Get... | @@ -495,7 +520,7 @@ func (w *BufWindow) displayBuffer() {
bloc.X = bslice
// returns the rune to be drawn, style of it and if the bg should be preserved
- getRuneStyle := func(r rune, style tcell.Style, isplaceholder bool) (rune, tcell.Style, bool) {
+ getRuneStyle := func(r rune, style tcell.Style, drawoffse... | internal/display/bufwindow.go | 26 | Go | 0.643 | suggestion | 237 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if startStyle != nil {
curStyle = *startStyle
}
bloc.X = bslice
// returns the rune to be drawn, style of it and if the bg should be preserved
getRuneStyle := func(r rune, style tcell.Style, isplaceholder bool) (rune, tcell.Style, bool) {
if nColsBeforeStart > 0 || vloc.Y < 0 || isplaceholder {
ret... | You don't need to fix the white space issue in https://github.com/zyedidia/micro/pull/3760/commits/814322a7c0ea3fe80111f9d66b86030d402f3ed9#diff-57bc6641ff1bc2d9b749d3994e6f7dac19ca5642e9ab90fe18663e95d8bc4dd1R542 when you don't add it here. :wink: | }
if vloc.Y >= 0 {
if w.hasMessage {
w.drawGutter(&vloc, &bloc)
}
if b.Settings["diffgutter"].(bool) {
w.drawDiffGutter(s, false, &vloc, &bloc)
}
if b.Settings["ruler"].(bool) {
w.drawLineNum(s, false, &vloc, &bloc)
}
} else {
vloc.X = w.gutterOffset
}
bline := b.LineBytes... | @@ -494,7 +494,88 @@ func (w *BufWindow) displayBuffer() {
}
bloc.X = bslice
- draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
+ // returns the rune to be drawn, style of it and if the bg should be preserved
+ getRuneStyle := func(r rune, style tcell.Style, isplacehol... | internal/display/bufwindow.go | 26 | Go | 0.429 | suggestion | 249 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | JoeKar | Neko-Box-Coder |
}
}
}
if r != '\t' && r != ' '{
return r, style, false
}
var drawrune rune
if r == '\t' {
indentrunes := []rune(b.Settings["indentchar"].(string))
// if empty indentchar settings, use space
if len(indentrunes) == 0 {
indentrunes = []rune{' '}
}
drawrune = indentru... | Do I oversee something here or are both blocks equal except the check for `&& r != ' '`, which is always true.
In the removed block we had no duplication. | leadingwsEnd := len(util.GetLeadingWhitespace(bline))
trailingwsStart := blineLen - util.CharacterCount(util.GetTrailingWhitespace(bline))
line, nColsBeforeStart, bslice, startStyle := w.getStartInfo(w.StartCol, bloc.Y)
if startStyle != nil {
curStyle = *startStyle
}
bloc.X = bslice
// returns the ru... | @@ -494,7 +494,88 @@ func (w *BufWindow) displayBuffer() {
}
bloc.X = bslice
- draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
+ // returns the rune to be drawn, style of it and if the bg should be preserved
+ getRuneStyle := func(r rune, style tcell.Style, isplacehol... | internal/display/bufwindow.go | 26 | Go | 0.571 | suggestion | 155 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | JoeKar | Neko-Box-Coder |
if s, ok := config.Colorscheme["selection"]; ok {
style = s
}
}
if b.Settings["cursorline"].(bool) && w.active && !preservebg &&
!c.HasSelection() && c.Y == bloc.Y {
if s, ok := config.Colorscheme["cursor-line"]; ok {
fg, _, _ := s.Decompose()
style = sty... | Isn't `preservebg` already `true`?
It shouldn't be introduced that way even it is fixed in the next commit. | }
}
}
}
return drawrune, style, preservebg
}
draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool, preservebg bool) {
defer func() {
if nColsBeforeStart <= 0 {
vloc.X++
}
nColsBeforeStart--
}()
if nColsBeforeStart > 0 || vloc.Y < 0 {... | @@ -509,37 +590,8 @@ func (w *BufWindow) displayBuffer() {
// syntax or hlsearch highlighting with non-default background takes precedence
// over cursor-line and color-column
- dontOverrideBackground := origBg != defBg
-
- if b.Settings["hltaberrors"].(bool) {
- if s, ok := config.Colorschem... | internal/display/bufwindow.go | 26 | Go | 0.571 | question | 108 | 51 | 51 | false | Adding indenttabchar, indentspacechar and spacechar options | 3,760 | zyedidia/micro | 13,805 | Go | JoeKar | Neko-Box-Coder |
s[k] = v
}
return s
}
func verifySetting(option string, value interface{}, def interface{}) error {
var interfaceArr []interface{}
valType := reflect.TypeOf(value)
defType := reflect.TypeOf(def)
assignable := false
switch option {
case "pluginrepos", "pluginchannels":
assignable = valType.AssignableTo(ref... | Maybe move it into the switch above, where we already check for other options? | s[k] = v
}
return s
}
func verifySetting(option string, value interface{}, def interface{}) error {
var interfaceArr []interface{}
valType := reflect.TypeOf(value)
defType := reflect.TypeOf(def)
assignable := false
switch option {
case "pluginrepos", "pluginchannels":
assignable = valType.AssignableTo(ref... | @@ -270,6 +270,12 @@ func verifySetting(option string, value interface{}, def interface{}) error {
return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType)
}
+ if option == "colorscheme" {
+ // Plugins are not initialized yet, so do not not ve... | internal/config/settings.go | 26 | Go | 0.286 | question | 78 | 51 | 51 | false | Fix non-working colorscheme plugins | 3,761 | zyedidia/micro | 13,805 | Go | JoeKar | dmaluka |
func ParsedSettings() map[string]interface{} {
s := make(map[string]interface{})
for k, v := range parsedSettings {
s[k] = v
}
return s
}
func verifySetting(option string, value interface{}, def interface{}) error {
var interfaceArr []interface{}
valType := reflect.TypeOf(value)
defType := reflect.TypeOf(def)... | > not not
Double negation? I missed that the first time I read it. | func ParsedSettings() map[string]interface{} {
s := make(map[string]interface{})
for k, v := range parsedSettings {
s[k] = v
}
return s
}
func verifySetting(option string, value interface{}, def interface{}) error {
var interfaceArr []interface{}
valType := reflect.TypeOf(value)
defType := reflect.TypeOf(def)... | @@ -270,6 +270,12 @@ func verifySetting(option string, value interface{}, def interface{}) error {
return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType)
}
+ if option == "colorscheme" {
+ // Plugins are not initialized yet, so do not not ve... | internal/config/settings.go | 26 | Go | 0.214 | suggestion | 69 | 51 | 51 | false | Fix non-working colorscheme plugins | 3,761 | zyedidia/micro | 13,805 | Go | JoeKar | dmaluka |
case FFDos:
b.Settings["fileformat"] = "dos"
}
b.UpdateRules()
// we know the filetype now, so update per-filetype settings
config.UpdateFileTypeLocals(b.Settings, b.Settings["filetype"].(string))
if _, err := os.Stat(filepath.Join(config.ConfigDir, "buffers")); errors.Is(err, fs.ErrNotExist) {
os.Mkdir(fil... | Looks like `None` and `StartCursorSearchText` are doing the same thing, so why need both?
So instead of this `CommandOrder` field we can just have a boolean field e.g. `SearchAfterStart`? | var ff FileFormat = FFAuto
if size == 0 {
// for empty files, use the fileformat setting instead of
// autodetection
switch b.Settings["fileformat"] {
case "unix":
ff = FFUnix
case "dos":
ff = FFDos
}
} else {
// in case of autodetection treat as locally set
b.LocalSe... | @@ -409,6 +430,29 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
b.AddCursor(NewCursor(b, b.StartCursor))
b.GetActiveCursor().Relocate()
+ switch bcommand.CommandOrder {
+ case None, StartCursorSearchText: | internal/buffer/buffer.go | 26 | Go | 0.571 | question | 190 | 51 | 51 | false | micro: Handle +/text search text from args | 3,767 | zyedidia/micro | 13,805 | Go | dmaluka | luca020400 |
switch b.Endings {
case FFUnix:
b.Settings["fileformat"] = "unix"
case FFDos:
b.Settings["fileformat"] = "dos"
}
b.UpdateRules()
// we know the filetype now, so update per-filetype settings
config.UpdateFileTypeLocals(b.Settings, b.Settings["filetype"].(string))
if _, err := os.Stat(filepath.Join(config.C... | I'm afraid we need to update `OrigSelection` as well. Try using Shift+Right or Shift+Down after opening a file with `+/TEXT`. | if !hasBackup {
reader := bufio.NewReader(transform.NewReader(r, b.encoding.NewDecoder()))
var ff FileFormat = FFAuto
if size == 0 {
// for empty files, use the fileformat setting instead of
// autodetection
switch b.Settings["fileformat"] {
case "unix":
ff = FFUnix
case "dos":
... | @@ -409,6 +430,29 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
b.AddCursor(NewCursor(b, b.StartCursor))
b.GetActiveCursor().Relocate()
+ switch bcommand.CommandOrder {
+ case None, StartCursorSearchText:
+ // We can just search from current cursor and move it accordingly
+ ... | internal/buffer/buffer.go | 26 | Go | 0.5 | suggestion | 125 | 51 | 51 | false | micro: Handle +/text search text from args | 3,767 | zyedidia/micro | 13,805 | Go | dmaluka | luca020400 |
// 2. If there is no input file and the input is not a terminal, that means
// something is being piped in and the stdin should be opened in an
// empty buffer
// 3. If there is no input file and the input is a terminal, an empty buffer
// should be opened
var filename string
var input []byte
var err error
... | `[ -~]` is to match printable ascii characters, I guess? What about non-ascii Unicode characters? |
// 1. If it is given a files in flag.Args(), it should open those
// 2. If there is no input file and the input is not a terminal, that means
// something is being piped in and the stdin should be opened in an
// empty buffer
// 3. If there is no input file and the input is a terminal, an empty buffer
// shoul... | @@ -165,39 +167,70 @@ func LoadInput(args []string) []*buffer.Buffer {
}
files := make([]string, 0, len(args))
+
flagStartPos := buffer.Loc{-1, -1}
- flagr := regexp.MustCompile(`^\+(\d+)(?::(\d+))?$`)
- for _, a := range args {
- match := flagr.FindStringSubmatch(a)
- if len(match) == 3 && match[2] != "" {
-... | cmd/micro/micro.go | 26 | Go | 0.357 | question | 97 | 51 | 51 | false | micro: Handle +/text search text from args | 3,767 | zyedidia/micro | 13,805 | Go | dmaluka | luca020400 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.