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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
#!/bin/sh
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"
mkdir -p binaries
mkdir -p micro-$VERSION
cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-PARTY mic... | If security is the concern, don't we want sha256 or something? | #!/bin/sh
set -e
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"
mkdir -p binaries
mkdir -p micro-$VERSION
cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-P... | @@ -1,120 +1,107 @@
-cd ..
-
-mkdir -p binaries
-mkdir -p micro-$1
-
-cp LICENSE micro-$1
-cp README.md micro-$1
-cp LICENSE-THIRD-PARTY micro-$1
-cp assets/packaging/micro.1 micro-$1
-cp assets/packaging/micro.desktop micro-$1
-cp assets/micro-logo-mark.svg micro-$1/micro.svg
+#!/bin/sh
HASH="$(git rev-parse --shor... | tools/cross-compile.sh | 22 | Shell | 0.357 | security | 62 | 47 | 47 | false | nightly: Use GitHub Actions for scheduled builds | 3,334 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
#!/bin/sh
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"
mkdir -p binaries
mkdir -p micro-$VERSION
cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-PARTY mic... | nit: Just wondering, maybe it's better to use `.sha256` extension, to make it clear which sum it is?
What is the convention for sha256 sum file extension (if there is any)? | #!/bin/sh
set -e
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"
mkdir -p binaries
mkdir -p micro-$VERSION
cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-P... | @@ -1,120 +1,107 @@
-cd ..
-
-mkdir -p binaries
-mkdir -p micro-$1
-
-cp LICENSE micro-$1
-cp README.md micro-$1
-cp LICENSE-THIRD-PARTY micro-$1
-cp assets/packaging/micro.1 micro-$1
-cp assets/packaging/micro.desktop micro-$1
-cp assets/micro-logo-mark.svg micro-$1/micro.svg
+#!/bin/sh
HASH="$(git rev-parse --shor... | tools/cross-compile.sh | 24 | Shell | 0.571 | question | 173 | 49 | 49 | false | nightly: Use GitHub Actions for scheduled builds | 3,334 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
command -v fpm > /dev/null
RESULT=$?
if [ $RESULT -eq 0 ]; then
fpm -s dir -t deb -p micro-$1-amd64.deb --name micro --license mit --version $1 --deb-recommends xclip --description "A modern and intuitive terminal-based text editor" --after-install ./assets/packaging/deb/micro.postinst --before-remove ./assets/packagi... | All this could be just `command -v fpm > /dev/null && fpm -s dir ...`? | command -v fpm > /dev/null && fpm -s dir -t deb -p micro-$1-amd64.deb --name micro --license mit --version $1 --deb-recommends xclip --description "A modern and intuitive terminal-based text editor" --after-install ./assets/packaging/deb/micro.postinst --before-remove ./assets/packaging/deb/micro.prerm ./micro=/usr/bin... | @@ -1 +1,9 @@
-fpm -s dir -t deb -p micro-$1-amd64.deb --name micro --license mit --version $1 --deb-recommends xclip --description "A modern and intuitive terminal-based text editor" --after-install ./assets/packaging/deb/micro.postinst --before-remove ./assets/packaging/deb/micro.prerm ./micro=/usr/bin/micro ./assets... | tools/package-deb.sh | 9 | Shell | 0.571 | question | 70 | 10 | 2 | false | nightly: Use GitHub Actions for scheduled builds | 3,334 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
#!/bin/sh
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"
mkdir -p binaries
mkdir -p micro-$VERSION
cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-PARTY mic... | Maybe it's a good idea to use `#!/bin/sh -e`? Any of the commands in this script may potentially fails, so we'd better not ignore such failures silently?
What do these github actions do if the command (`cross-compile.sh` in this case) exits with a non-zero status? I hope they abort the action and log the stderr outp... | #!/bin/sh
set -e
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"
mkdir -p binaries
mkdir -p micro-$VERSION
cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-P... | @@ -1,120 +1,107 @@
-cd ..
-
-mkdir -p binaries
-mkdir -p micro-$1
-
-cp LICENSE micro-$1
-cp README.md micro-$1
-cp LICENSE-THIRD-PARTY micro-$1
-cp assets/packaging/micro.1 micro-$1
-cp assets/packaging/micro.desktop micro-$1
-cp assets/micro-logo-mark.svg micro-$1/micro.svg
+#!/bin/sh | tools/cross-compile.sh | 1 | Shell | 0.643 | bug | 323 | 26 | 26 | false | nightly: Use GitHub Actions for scheduled builds | 3,334 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
cd ..
mkdir -p binaries
mkdir -p micro-$1
cp LICENSE micro-$1
cp README.md micro-$1
cp LICENSE-THIRD-PARTY micro-$1
cp assets/packaging/micro.1 micro-$1
cp assets/packaging/micro.desktop micro-$1
cp assets/micro-logo-mark.svg micro-$1/micro.svg
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-versi... | I realized using `$VERSION` within the archive resp. asset name is counterproductive when used for the `nightly` upload, because the `softprops/action-gh-release` will only delete and update assets with the same name present.
Having an updated from e.g. `2.0.14-dev.243` -> `2.0.14-dev.244` -> `2.0.14-dev.245` fills th... | #!/bin/sh
set -e
HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"
mkdir -p binaries
mkdir -p micro-$VERSION
cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-P... | @@ -1,120 +1,109 @@
-cd ..
+#!/bin/sh
-mkdir -p binaries
-mkdir -p micro-$1
-
-cp LICENSE micro-$1
-cp README.md micro-$1
-cp LICENSE-THIRD-PARTY micro-$1
-cp assets/packaging/micro.1 micro-$1
-cp assets/packaging/micro.desktop micro-$1
-cp assets/micro-logo-mark.svg micro-$1/micro.svg
+set -e
HASH="$(git rev-pars... | tools/cross-compile.sh | 25 | Shell | 0.786 | suggestion | 999 | 50 | 50 | false | nightly: Use GitHub Actions for scheduled builds | 3,334 | zyedidia/micro | 13,805 | Go | JoeKar | JoeKar |
}
// Cut the selection to the system clipboard
func (h *BufPane) Cut() bool {
if !h.Cursor.HasSelection() {
return false
}
h.Cursor.CopySelection(clipboard.ClipboardReg)
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
h.freshClip = false
InfoBar.Message("Cut selection")
h.Relocate()
return true
}
// ... | 1. Minor thing,
```suggestion
if h.freshClip && time.Since(h.lastCutTime) < 10 * time.Second {
```
2. I know this is a behavior from before but I never knew it was there. I think we should either (or both)
a. Mention this somewhere in the documentation
b. Maybe have an option to toggle this on or off? | }
// Cut the selection to the system clipboard
func (h *BufPane) Cut() bool {
if !h.Cursor.HasSelection() {
return false
}
h.Cursor.CopySelection(clipboard.ClipboardReg)
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
h.freshClip = false
InfoBar.Message("Cut selection")
h.Relocate()
return true
}
// ... | @@ -1162,101 +1162,180 @@ func (h *BufPane) Redo() bool {
return true
}
+func (h *BufPane) selectLines() int {
+ if h.Cursor.HasSelection() {
+ start := h.Cursor.CurSelection[0]
+ end := h.Cursor.CurSelection[1]
+ if start.GreaterThan(end) {
+ start, end = end, start
+ }
+ if end.X == 0 {
+ end = end.Move... | internal/action/actions.go | 26 | Go | 0.857 | question | 319 | 51 | 51 | false | Improve and unify `CopyLine`, `CutLine`, `DeleteLine`, `DuplicateLine` actions | 3,335 | zyedidia/micro | 13,805 | Go | Neko-Box-Coder | dmaluka |
if h.Cursor.HasSelection() {
origLoc := h.Cursor.Loc
origLastVisualX := h.Cursor.LastVisualX
origSelection := h.Cursor.CurSelection
start := h.Cursor.CurSelection[0]
end := h.Cursor.CurSelection[1]
if start.GreaterThan(end) {
start, end = end, start
}
if end.X == 0 {
end = end.Move(-1, h.Buf)
... | Minor thing
```suggestion
InfoBar.Message(fmt.Sprintf("Duplicated %d lines", end.Y - start.Y + 1))
``` | origLoc := h.Cursor.Loc
origLastVisualX := h.Cursor.LastVisualX
origSelection := h.Cursor.CurSelection
start := h.Cursor.CurSelection[0]
end := h.Cursor.CurSelection[1]
if start.GreaterThan(end) {
start, end = end, start
}
if end.X == 0 {
end = end.Move(-1, h.Buf)
}
h.Cursor.Deselect(true)
... | @@ -1162,101 +1162,180 @@ func (h *BufPane) Redo() bool {
return true
}
+func (h *BufPane) selectLines() int {
+ if h.Cursor.HasSelection() {
+ start := h.Cursor.CurSelection[0]
+ end := h.Cursor.CurSelection[1]
+ if start.GreaterThan(end) {
+ start, end = end, start
+ }
+ if end.X == 0 {
+ end = end.Move... | internal/action/actions.go | 26 | Go | 0.714 | refactor | 108 | 51 | 51 | false | Improve and unify `CopyLine`, `CutLine`, `DeleteLine`, `DuplicateLine` actions | 3,335 | zyedidia/micro | 13,805 | Go | Neko-Box-Coder | dmaluka |
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
if !b.Modified() {
e := calcHash(b, &b.origHash)
if e == ErrFileTooLarge {
b.Settings["fastdirty"] = false
}
}
}
} else if option == "statusline" {
screen.Redraw()
} else if option == "filetype" {
co... | Shouldn't we remove `config.InitRuntimeFiles()` and `config.ReadSettings()` as well? | )
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need to update filetype before updating other settings based on it
b.Settings["filetype"] = "unknown"
if v, ok := settings["filetype"]; ok {
b.Set... | @@ -25,10 +25,6 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
if err != nil {
screen.TermMessage(err)
}
- err = config.InitGlobalSettings() | internal/buffer/settings.go | 26 | Go | 0.429 | question | 84 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
if reloadPlugins {
config.InitPlugins()
}
oldParsedSettings := config.ParsedSettings()
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
parsedSettings := config.ParsedSettings()
defaultGlobals := config.DefaultGlobalSettings()
for k := range defaultGlobals {
if _, ok := parsedSet... | 1. We should do this for local settings as well.
2. We should do this for local settings not just in `reload` but also in `set filetype`.
For example, with this in `settings.json`:
```
"ft:c": {
"ruler": false
},
```
open `foo.go`, run `set filetype c` -> the ruler disappears (as expected)... |
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
if _, ok := config.VolatileSettings[k]; ok {
// reload... | @@ -354,13 +354,23 @@ func reloadRuntime(reloadPlugins bool) {
config.InitPlugins()
}
+ oldParsedSettings := config.ParsedSettings()
+
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
- err = config.InitGlobalSettings()
- if err != nil {
- screen.TermMessage(err)
+
+ parsedSetting... | internal/action/command.go | 26 | Go | 1 | suggestion | 389 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
)
var Autosave chan bool
var autotime int
// lock for autosave
var autolock sync.Mutex
func init() {
Autosave = make(chan bool)
}
func SetAutoTime(a int) {
autolock.Lock()
autotime = a
autolock.Unlock()
}
func StartAutoSave() {
go func() {
autolock.Lock()
a := autotime
autolock.Unlock()
if a < 1 {
... | Hmm, am I reading the code (not just your code) correctly: if `autosave` is already set to a positive value and we change it to another positive value, we spawn a new goroutine without stopping the old one? So both goroutines are now running? So autosave is actually done twice more often than it should? (And if we repe... |
var Autosave chan bool
var autotime chan float64
func init() {
Autosave = make(chan bool)
autotime = make(chan float64)
}
func SetAutoTime(a float64) {
autotime <- a
}
func StartAutoSave() {
go func() {
var a float64
var t *time.Timer
var elapsed <-chan time.Time
for {
select {
case a = <-autotime... | @@ -23,14 +23,20 @@ func SetAutoTime(a int) {
func StartAutoSave() {
go func() {
+ autolock.Lock()
+ a := autotime
+ autolock.Unlock()
+ if a < 1 {
+ return
+ } | internal/config/autosave.go | 26 | Go | 0.643 | bug | 786 | 39 | 45 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
if !b.Modified() {
... | Why so tricky? The option will be set in `b.Settings` by `b.SetOptionNative()` anyway, so why not just:
```
for k := range config.DefaultCommonSettings() {
...
}
```
Also it would be nice to do this in a separate commit: one commit to remove the undesired stuff for globals and unneeded parsing, and another c... | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -20,16 +20,17 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
} else if option == "statusline" {
screen.Redraw()
} else if option == "filetype" {
- config.InitRuntimeFiles(true)
- err := config.ReadSettings()
- if err != nil {
- screen.TermMessage(err)
- }
- err = co... | internal/buffer/settings.go | 24 | Go | 0.857 | question | 362 | 49 | 49 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
)
var Autosave chan bool
var autotime chan float64
// lock for autosave
var autolock sync.Mutex
func init() {
Autosave = make(chan bool)
autotime = make(chan float64)
}
func SetAutoTime(a float64) {
autotime <- a
}
func StartAutoSave() {
go func() {
var a float64
var elapsed <-chan time.Time
for {
sel... | This seems to work correctly from the autosave perspective, however it seems a bit unclean: it doesn't stop the previous `elapsed` timer, so it will still fire after some time. Although it won't cause an unwanted autosave (thanks to the fact that the `elapsed` variable is now assigned to a different channel, so we will... |
var Autosave chan bool
var autotime chan float64
func init() {
Autosave = make(chan bool)
autotime = make(chan float64)
}
func SetAutoTime(a float64) {
autotime <- a
}
func StartAutoSave() {
go func() {
var a float64
var t *time.Timer
var elapsed <-chan time.Time
for {
select {
case a = <-autotime... | @@ -6,32 +6,36 @@ import (
)
var Autosave chan bool
-var autotime float64
+var autotime chan float64
// lock for autosave
var autolock sync.Mutex
func init() {
Autosave = make(chan bool)
+ autotime = make(chan float64)
}
func SetAutoTime(a float64) {
- autolock.Lock()
- autotime = a
- autolock.Unlock()... | internal/config/autosave.go | 26 | Go | 0.643 | suggestion | 603 | 37 | 45 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
oldParsedSettings := config.ParsedSettings()
err := config.ReadSettings()
if err != n... | It seems in this simple case `else if` would be slightly more readable than `continue`. |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
par... | @@ -354,13 +354,23 @@ func reloadRuntime(reloadPlugins bool) {
config.InitPlugins()
}
+ oldParsedSettings := config.ParsedSettings()
+
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
- err = config.InitGlobalSettings()
- if err != nil {
- screen.TermMessage(err)
+
+ parsedSetting... | internal/action/command.go | 26 | Go | 0.357 | suggestion | 87 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
oldParsedSettings := config.ParsedSettings()
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
parsedSettings := config.ParsedSettings()
defaultSettings := c... | Do we need `oldParsedSettings`? If the setting is not present in the new parsed settings, we should set it to the default in any case?
If it is to avoid unneeded setting it to the default if it's already default, then it looks inconsistent with the above case when it is present in `parsedSettings`: in that case we d... | err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
parsedSettings := config.ParsedSettings()
defaultSettings := co... | @@ -354,13 +354,23 @@ func reloadRuntime(reloadPlugins bool) {
config.InitPlugins()
}
+ oldParsedSettings := config.ParsedSettings()
+
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
- err = config.InitGlobalSettings()
- if err != nil {
- screen.TermMessage(err)
+
+ parsedSetting... | internal/action/command.go | 26 | Go | 0.643 | question | 394 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
if !b.Modified() {
... | This seems unneeded: we already ensure skipping `filetype` below? | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -20,7 +20,19 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
} else if option == "statusline" {
screen.Redraw()
} else if option == "filetype" {
- config.InitLocalSettings(b.Settings, b.Path)
+ parsedSettings := config.ParsedSettings()
+ parsedSettings[option] = nativeVa... | internal/buffer/settings.go | 23 | Go | 0.5 | question | 65 | 48 | 48 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
oldParsedSettings := config.ParsedSettings()
err := config.ReadSettings()
if err != n... | Still buggy: some options are normally overridden per buffer in `NewBuffer()`, so they should be overridden after `reload` as well. Those are at least: `fileformat`, `fastdirty` if the file is large, `encoding` if the specified encoding is invalid.
In other words, if the user runs `reload` but hasn't changed anythin... |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
par... | @@ -354,13 +354,23 @@ func reloadRuntime(reloadPlugins bool) {
config.InitPlugins()
}
+ oldParsedSettings := config.ParsedSettings()
+
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
- err = config.InitGlobalSettings()
- if err != nil {
- screen.TermMessage(err)
+
+ parsedSetting... | internal/action/command.go | 26 | Go | 0.786 | bug | 394 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
b.Endings = FFDos
}
b.isModified = true
} else if option == "syntax" {
if !nativeValue.(bool) {
b.ClearMatches()
} else {
b.UpdateRules()
}
} else if option == "encoding" {
_, err := htmlindex.Get(b.Settings["encoding"].(string))
if err != nil {
b.Settings["encoding"] = "utf-8"
}
b.isMod... | I believe we should just return error in this case, not override previously set (valid) encoding. | b.DoSetOptionNative(k, v)
}
}
}
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
if reflect.DeepEqual(b.Settings[option], nativeValue) {
return
}
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
if b.Size() > LargeFileThreshold {
b.... | @@ -49,6 +50,10 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
b.UpdateRules()
}
} else if option == "encoding" {
+ _, err := htmlindex.Get(b.Settings["encoding"].(string))
+ if err != nil {
+ b.Settings["encoding"] = "utf-8" | internal/buffer/settings.go | 26 | Go | 0.429 | suggestion | 97 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
if option == pl.Name {
if nativeValue.(bool) && !pl.Loaded {
pl.Load()
_, err := pl.Call("init")
if err != nil && err != config.ErrNoSuchFunction {
screen.TermMessage(err)
}
} else if !nativeValue.(bool) && pl.Loaded {
_, err := pl.Call("deinit")
if err != nil && err != co... | Maybe useful, but still not fully preventing unneeded rewriting of `settings.json`: we still rewrite it (even multiple times) when `SetGlobalOptionNative()` is called from `reloadRuntime()`, i.e. when the setting has changed, yet we don't need to write it, since this new setting is already in `settings.json`, by defini... | } else if !nativeValue.(bool) && pl.Loaded {
_, err := pl.Call("deinit")
if err != nil && err != config.ErrNoSuchFunction {
screen.TermMessage(err)
}
}
}
}
}
return nil
}
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
if err := config.OptionIsValid(opti... | @@ -535,8 +536,10 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
}
// ...if it's not local continue with the globals
- config.GlobalSettings[option] = nativeValue
- config.ModifiedSettings[option] = true
+ if !reflect.DeepEqual(config.GlobalSettings[option], nativeValue) { | internal/action/command.go | 26 | Go | 0.643 | question | 375 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
}
// add any options to parsedSettings that have since been marked as non-default
for k, v := range GlobalSettings {
if def, ok := defaults[k]; !ok || !reflect.DeepEqual(v, def) {
if _, wr := ModifiedSettings[k]; wr {
parsedSettings[k] = v
}
}
}
// check for changes and prevent unnecessar... | Instead of all this we can just use a local boolean variable which we set to true if we modify or delete anything in `parsedSettings` in this function?
...But I actually have doubts whether it's a good idea to prevent unnecessary writes so generically. Think of such a scenario, for example:
1. The user starts mic... | if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
if strings.HasPrefix(k, "ft:") {
if settings["filetype"].(string) == k[3:] {
for k1, v1 := range v.(map[string]interface{}) {
settings[k1] = v1
}
}
} else {
g, _ := glob.Compile(k)
if g.MatchString(path) {
for k1, v1 ... | @@ -298,6 +299,22 @@ func WriteSettings(filename string) error {
}
}
+ // check for changes and prevent unnecessary writes
+ if len(parsedSettings) == len(oldParsedSettings) {
+ equal := true
+ for k, _ := range parsedSettings {
+ vNew, okNew := parsedSettings[k]
+ vOld, okOld := oldParsedSettings[... | internal/config/settings.go | 26 | Go | 0.643 | question | 993 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
case "dos":
b.Endings = FFDos
}
b.isModified = true
} else if option == "syntax" {
if !nativeValue.(bool) {
b.ClearMatches()
} else {
b.UpdateRules()
}
} else if option == "encoding" {
_, err := htmlindex.Get(b.Settings["encoding"].(string))
if err != nil {
return err
}
b.isModified = ... | We don't really check this return value (thus don't report the error to the user) in `reload`... | } else {
b.DoSetOptionNative(k, v)
}
}
}
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
if reflect.DeepEqual(b.Settings[option], nativeValue) {
return
}
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
if b.Size() > LargeFileThresho... | @@ -49,6 +50,10 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
b.UpdateRules()
}
} else if option == "encoding" {
+ _, err := htmlindex.Get(b.Settings["encoding"].(string))
+ if err != nil {
+ return err | internal/buffer/settings.go | 26 | Go | 0.571 | suggestion | 96 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
parsedSett... | Belated suggestion: since it is not exactly obvious what is this for, add a short comment like "reload should not override auto-detected file format"? | }
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
p... | @@ -362,6 +362,9 @@ func reloadRuntime(reloadPlugins bool) {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
+ if k == "fileformat" { | internal/action/command.go | 26 | Go | 0.429 | question | 150 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
if k == "fileformat" {
continue
... | Maybe we shouldn't just interrupt reloading settings, bindings, colorscheme etc on the halfway because of this error, but just report it via `screen.TermMessage` and continue, like we do in other error cases in this function? (`screen.TermMessage`, unlike `InfoBar.Error`, will not overwrite previous error messages.)
... | }
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
if _, ok := config.Vola... | @@ -366,9 +366,13 @@ func reloadRuntime(reloadPlugins bool) {
continue
}
if _, ok := parsedSettings[k]; ok {
- SetGlobalOptionNative(k, parsedSettings[k])
+ err = SetGlobalOptionNative(k, parsedSettings[k])
} else {
- SetGlobalOptionNative(k, defaultSettings[k])
+ err = SetGlobalOptionNative(k, def... | internal/action/command.go | 26 | Go | 0.786 | bug | 1,104 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
}
// NewTabCmd opens the given file in a new tab
func (h *BufPane) NewTabCmd(args []string) {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
if len(args) > 0 {
for _, a := range args {
b, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
... | Looks quite ugly to me. It would be much more natural to add a boolean param to `SetGlobalOptionNative()` to tell it whether to write or not.
Yeah, I know `SetGlobalOptionNative()` is exposed to plugins... So, since `reloadRuntime()` is in the same package, how about a private `setGlobalOptionNative()` function, wit... | iOffset := config.GetInfoBarOffset()
if len(args) > 0 {
for _, a := range args {
b, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
return
}
tp := NewTabFromBuffer(0, 0, width, height-1-iOffset, b)
Tabs.AddTab(tp)
Tabs.SetActive(len(Tabs.List) - 1)
... | @@ -532,7 +532,7 @@ func (h *BufPane) NewTabCmd(args []string) {
}
}
-func SetGlobalOptionNative(option string, nativeValue interface{}) error {
+func SetGlobalOptionNativeNoWrite(option string, nativeValue interface{}) error { | internal/action/command.go | 26 | Go | 0.571 | question | 440 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
func (h *BufPane) ReloadCmd(args []string) {
reloadRuntime(true)
}
// ReloadConfig reloads only the configuration
func ReloadConfig() {
reloadRuntime(false)
}
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
conf... | Just noticed that if we failed to read settings, we probably don't need to do the below steps with settings? (I hope `ReadSettings()` -> `json5.Unmarshal()` will not modify `parsedSettings` in this case?) | // ReloadCmd reloads all files (syntax files, colorschemes, plugins...)
func (h *BufPane) ReloadCmd(args []string) {
reloadRuntime(true)
}
// ReloadConfig reloads only the configuration
func ReloadConfig() {
reloadRuntime(false)
}
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPlugi... | @@ -358,9 +358,15 @@ func reloadRuntime(reloadPlugins bool) {
if err != nil { | internal/action/command.go | 26 | Go | 0.571 | bug | 204 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
reloadRuntime(false)
}
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMess... | Might be better to move this comment under the `if`? | func ReloadConfig() {
reloadRuntime(false)
}
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != n... | @@ -362,6 +362,10 @@ func reloadRuntime(reloadPlugins bool) {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
+ // reload should not override auto-detected file format | internal/action/command.go | 26 | Go | 0.429 | refactor | 52 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
}
}
} else if option == "statusline" {
screen.Redraw()
} else if option == "filetype" {
settings := config.ParsedSettings()
settings["filetype"] = nativeValue
config.InitLocalSettings(settings, b.Path)
for k, v := range config.DefaultCommonSettings() {
if k == "filetype" {
continue
}
if _,... | Hmm... this brings back the original issue reported in #3342: setting `filetype` overrides volatile settings (even though for the current buffer only)? | b.Settings["filetype"] = v
}
}
// update syntax rules, which will also update filetype if needed
b.UpdateRules()
settings["filetype"] = b.Settings["filetype"]
config.InitLocalSettings(settings, b.Path)
for k, v := range config.DefaultCommonSettings() {
if k == "filetype" {
// prevent recursion
cont... | @@ -20,7 +20,19 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
} else if option == "statusline" {
screen.Redraw()
} else if option == "filetype" {
- config.InitLocalSettings(b.Settings, b.Path)
+ settings := config.ParsedSettings()
+ settings["filetype"] = nativeValue
+ c... | internal/buffer/settings.go | 26 | Go | 0.643 | question | 151 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
screen.TermMessage(err)
}
}
}
}
}
for _, b := range buffer.OpenBuffers {
if err := b.SetOptionNative(option, nativeValue); err != nil {
return err
}
}
return config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
}
func SetGlobalOption(option, value string) error {
if ... | Hmm... this unexpectedly overrides local per-buffer settings that were changed at runtime by the user via `setlocal` or by a plugin? | return nil
}
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
if err := config.OptionIsValid(option, nativeValue); err != nil {
return err
}
// check for local option first...
for _, s := range config.LocalSettings {
if s == option {
return MainTab().CurPane().Buf.SetOptionNative... | @@ -589,7 +591,9 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
}
for _, b := range buffer.OpenBuffers {
- b.SetOptionNative(option, nativeValue)
+ if err := b.SetOptionNative(option, nativeValue); err != nil {
+ return err
+ } | internal/action/command.go | 26 | Go | 0.571 | question | 132 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
err = config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
}
return err
}
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
return setGlobalOptionNative(option, nativeValue, true)
}
func SetGlobalOption(option, value string) error {
if _, ok := config.GlobalSettings[o... | How about:
```
if write {
return config.WriteSettings(...)
}
return nil
``` | // ...if it's not local continue with the globals...
if err := doSetGlobalOptionNative(option, nativeValue); err != nil {
return err
}
// ...at last check the buffer locals
for _, b := range buffer.OpenBuffers {
b.DoSetOptionNative(option, nativeValue)
delete(b.LocalSettings, option)
}
return config.Writ... | @@ -596,7 +596,16 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
}
}
- return config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
+ var err error
+ if write {
+ err = config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
+ } | internal/action/command.go | 26 | Go | 0.571 | suggestion | 82 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
for _, pl := range config.Plugins {
if option == pl.Name {
if nativeValue.(bool) && !pl.Loaded {
pl.Load()
_, err := pl.Call("init")
if err != nil && err != config.ErrNoSuchFunction {
screen.TermMessage(err)
}
} else if !nativeValue.(bool) && pl.Loaded {
_, err := p... | How about:
```
if reflect.DeepEqual(config.GlobalSettings[option], nativeValue) {
if write {
// Although the setting in micro hasn't changed, the setting on the disk
// may have changed. Make sure to update it.
return config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
}
return nil
... | } else if !nativeValue.(bool) && pl.Loaded {
_, err := pl.Call("deinit")
if err != nil && err != config.ErrNoSuchFunction {
screen.TermMessage(err)
}
}
}
}
}
return nil
}
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
if err := config.OptionIsValid(opti... | @@ -538,60 +539,62 @@ func setGlobalOptionNative(option string, nativeValue interface{}, write bool) e
}
// ...if it's not local continue with the globals
- config.GlobalSettings[option] = nativeValue
- config.ModifiedSettings[option] = true
- delete(config.VolatileSettings, option)
-
- if option == "colorscheme"... | internal/action/command.go | 26 | Go | 0.857 | question | 392 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
"golang.org/x/text/encoding/htmlindex"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
if !reflect.DeepEqual(b.Settings[option], nativeValue) {
b.S... | And here we have even less reason to not return immediately if they are equal?
i.e. we shouldn't call `b.OptionCallback` if they are equal? | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -1,82 +1,86 @@
package buffer
import (
+ "reflect"
+
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
"golang.org/x/text/encoding/htmlindex"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
- b.Settings[option] = nativeValue... | internal/buffer/settings.go | 12 | Go | 0.571 | question | 140 | 37 | 37 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
return
}
h.HSplitBuf(buf)
}
// EvalCmd evaluates a lua expression
func (h *BufPane) EvalCmd(args []string) {
InfoBar.Error("Eval unsupported")
}
// NewTabCmd opens the given file in a new tab
func (h *BufPane) NewTabCmd(args []string) {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset(... | This is after we are done with locals, so it should be after the below comment `// ...if it's not local continue with the globals`? |
// NewTabCmd opens the given file in a new tab
func (h *BufPane) NewTabCmd(args []string) {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
if len(args) > 0 {
for _, a := range args {
b, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
... | @@ -544,6 +545,15 @@ func setGlobalOptionNative(option string, nativeValue interface{}, write bool) e
}
}
+ if reflect.DeepEqual(config.GlobalSettings[option], nativeValue) { | internal/action/command.go | 26 | Go | 0.571 | question | 131 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
screen.TermMessage(err)
}
}
}
}
}
return nil
}
func processGlobalOptionNative(option string, nativeValue interface{}, overwriteLocals bool, write bool) error {
// check for local option first...
for _, s := range config.LocalSettings {
if s == option {
if overwriteLocals {
return Main... | I'm struggling, if this really is a good location to clean up single entries in the `LocalSettings` map. | }
return nil
}
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
if err := config.OptionIsValid(option, nativeValue); err != nil {
return err
}
// check for local option first...
for _, s := range config.LocalSettings {
if s == option {
return MainTab().CurPane().Buf.SetOptionNa... | @@ -574,11 +588,48 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
}
}
+ return nil
+}
+
+func processGlobalOptionNative(option string, nativeValue interface{}, overwriteLocals bool, write bool) error {
+ // check for local option first...
+ for _, s := range config.LocalSettings {
... | internal/action/command.go | 26 | Go | 0.5 | refactor | 104 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | JoeKar | JoeKar |
package buffer
import (
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}, storeLocal bool) error {
if reflect.DeepEqual(b.Settings[option], nativeValue) {
return nil
}
b.Settings[... | Breaks compatibility with plugins, right? | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -7,13 +7,17 @@ import (
"github.com/zyedidia/micro/v2/internal/screen"
)
-func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
+func (b *Buffer) SetOptionNative(option string, nativeValue interface{}, storeLocal bool) error { | internal/buffer/settings.go | 10 | Go | 0.071 | question | 41 | 35 | 35 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
log.Fatal("error starting CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
InitLog()
err = config.InitConfigDir(*flagConfigDir)
if err != nil {
screen.TermMessage(err)
}
config.InitRuntimeFiles(true)
config.InitPlugins()
err = config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}... | Looks ugly. Can't we just validate options directly in `config.ReadSettings()`? Especially since it looks like we are already partially doing it there (in `verifySetting()`). | }
defer pprof.StopCPUProfile()
}
InitLog()
err = config.InitConfigDir(*flagConfigDir)
if err != nil {
screen.TermMessage(err)
}
config.InitRuntimeFiles(true)
config.InitPlugins()
err = config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
err = config.InitGlobalSettings()
if err != nil... | @@ -261,6 +261,14 @@ func main() {
if err != nil {
screen.TermMessage(err)
}
+
+ settings := config.ParsedSettings()
+ for k, v := range settings {
+ if err = config.OptionIsValid(k, v); err != nil {
+ screen.TermMessage(err)
+ }
+ } | cmd/micro/micro.go | 26 | Go | 0.5 | suggestion | 174 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
outerLoop:
for k := range defaultSettings {
if k == "filefo... | So... in an attempt to fix bugs, we are adding more special cases in more places, making the code more complicated and messy (as if it wasn't messy already), and undoubtedly adding more hidden bugs to be found in the future. Why, instead, not stop and think, and analyze existing cases, and try to simplify and clean up ... | config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
if _, ok := config.Volatile... | @@ -374,6 +374,10 @@ func reloadRuntime(reloadPlugins bool) {
}
}
if _, ok := parsedSettings[k]; ok {
+ if err = config.OptionIsValid(k, parsedSettings[k]); err != nil { | internal/action/command.go | 26 | Go | 0.786 | bug | 1,724 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
nativeValue, err := config.GetNativeValue(option, config.GlobalSettings[option], value)
if err != nil {
return err
}
return SetGlobalOptionNative(option, nativeValue)
}
// ResetCmd resets a setting to its default value
func (h *BufPane) ResetCmd(args []string) {
if len(args) < 1 {
InfoBar.Error("Not enough ... | It seems this entire `if _, ok := defaultLocals[option]` is superfluous (since `defaultGlobals` includes default locals as well, and `SetGlobalOptionNative()` above sets those default locals per buffer as well)? | }
return SetGlobalOptionNative(option, nativeValue)
}
// ResetCmd resets a setting to its default value
func (h *BufPane) ResetCmd(args []string) {
if len(args) < 1 {
InfoBar.Error("Not enough arguments")
return
}
option := args[0]
defaults := config.DefaultAllSettings()
if _, ok := defaults[option]; ok ... | @@ -646,6 +647,7 @@ func (h *BufPane) ResetCmd(args []string) {
}
if _, ok := defaultLocals[option]; ok { | internal/action/command.go | 26 | Go | 0.571 | question | 211 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
par... | Doesn't work for me: `reload` still overrides the auto-detected format.
Looks like the reason is, again, that setting `filetype` (by `DoSetOptionNative()` below) triggers setting other options, including `fileformat`.
Actually now it seems to me that this hardcoded skipping of `fileformat` here is not quite corre... | }
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
p... | @@ -361,6 +361,10 @@ func reloadRuntime(reloadPlugins bool) {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
+ if k == "fileformat" {
+ // reload should not override auto-detected file format
+ continue | internal/action/command.go | 26 | Go | 0.714 | question | 738 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
// because they have been modified by the user in this session
ModifiedSettings map[string]bool
// VolatileSettings is a map of settings which should not be written to disk
// because they have been temporarily set for this session only
VolatileSettings map[string]bool
)
func init() {
ModifiedSettings = make(ma... | Maybe do this inside `verifySetting()`? That would slim `validateParsedSettings()` down quite a bit. | // ModifiedSettings is a map of settings which should be written to disk
// because they have been modified by the user in this session
ModifiedSettings map[string]bool
// VolatileSettings is a map of settings which should not be written to disk
// because they have been temporarily set for this session only
Vol... | @@ -155,6 +155,68 @@ func init() {
VolatileSettings = make(map[string]bool)
}
+func validateParsedSettings() error {
+ var err error
+ defaults := DefaultAllSettings()
+ for k, v := range parsedSettings {
+ if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
+ if strings.HasPrefix(k, "ft:") {
+ for k1,... | internal/config/settings.go | 26 | Go | 0.5 | suggestion | 100 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
e := calcHash(b, &b.or... | Ehh... this causes a regression: modify the buffer (without saving it) and run `reload` -> statusbar now shows that the buffer is not modified (while it is) and Ctrl-Q closes the buffer without asking to save changes.
That's because we update `b.origHash` here, so `b.Modified()` now returns true. So now we know what... | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -10,11 +10,9 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
if option == "fastdirty" {
if !nativeValue.(bool) {
- if !b.Modified() {
- e := calcHash(b, &b.origHash)
- if e == ErrFileTooLarge {
- b.Settings["fastdirty"] = false
- }
+ e := calcHash(b, &b.ori... | internal/buffer/settings.go | 13 | Go | 0.643 | suggestion | 460 | 38 | 38 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
pars... | nit: Empty line after this line? |
func reloadRuntime(reloadPlugins bool) {
if reloadPlugins {
err := config.RunPluginFn("deinit")
if err != nil {
screen.TermMessage(err)
}
}
config.InitRuntimeFiles(true)
if reloadPlugins {
config.InitPlugins()
}
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
} else {
par... | @@ -361,6 +361,10 @@ func reloadRuntime(reloadPlugins bool) {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
+ if _, ok := config.VolatileSettings[k]; ok {
+ // reload should not override volatile settings
+ continue
+ } | internal/action/command.go | 26 | Go | 0.071 | question | 32 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
var has... | So we calculate the hash while we don't need to calculate it at all (we don't use the calculated `hash` value at all), we just need to find out the file size?
Actually it looks like we do need to calculate `b.origHash` here (but only if `!b.Modified()`), since if `fastdirty` was previously enabled, `b.origHash` was ... | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -10,11 +12,10 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
if option == "fastdirty" {
if !nativeValue.(bool) {
- if !b.Modified() {
- e := calcHash(b, &b.origHash)
- if e == ErrFileTooLarge {
- b.Settings["fastdirty"] = false
- }
+ var hash [md5.Size]byt... | internal/buffer/settings.go | 16 | Go | 0.786 | bug | 765 | 41 | 41 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
}
}
return err
}
func ReadSettings() error {
parsedSettings = make(map[string]interface{})
filename := filepath.Join(ConfigDir, "settings.json")
if _, e := os.Stat(filename); e == nil {
input, err := ioutil.ReadFile(filename)
if err != nil {
settingsParseError = true
return errors.New("Error reading s... | We leave `parsedSettings` in an invalid state? So `ParsedSettings()` will return invalid settings (while we were assuming it should always return valid settings, so that we don't need to repeatedly validate settings in lots of places)? | continue
}
}
}
return err
}
func ReadSettings() error {
parsedSettings = make(map[string]interface{})
filename := filepath.Join(ConfigDir, "settings.json")
if _, e := os.Stat(filename); e == nil {
input, err := ioutil.ReadFile(filename)
if err != nil {
settingsParseError = true
return errors.Ne... | @@ -171,17 +227,9 @@ func ReadSettings() error {
settingsParseError = true
return errors.New("Error reading settings.json: " + err.Error())
}
-
- // check if autosave is a boolean and convert it to float if so
- if v, ok := parsedSettings["autosave"]; ok {
- s, ok := v.(bool)
- if ok {
- if ... | internal/config/settings.go | 26 | Go | 0.643 | question | 235 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
// for empty files, use the fileformat setting instead of
// autodetection
switch settings["fileformat"] {
case "unix":
ff = FFUnix
case "dos":
ff = FFDos
}
}
b.LineArray = NewLineArray(uint64(size), ff, reader)
}
b.EventHandler = NewEventHandler(b.SharedBuffer, b.cursors)
... | It gets added to `LocalSettings` even if it is set to default, not autodetected (i.e. if the file is empty). | ff = FFUnix
case "dos":
ff = FFDos
}
} 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 w... | @@ -388,8 +388,10 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
switch b.Endings {
case FFUnix:
b.Settings["fileformat"] = "unix"
+ b.LocalSettings["fileformat"] = true | internal/buffer/buffer.go | 26 | Go | 0.5 | suggestion | 108 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(filetype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; ok || filetype {
settings["filetype"] =... | Maybe
```
if _, ok := b.LocalSettings["filetype"]; ok || filetype {
settings["filetype"] = b.Settings["filetype"]
} else {
b.Settings["filetype"] = "unknown"
if v, ok := settings["filetype"]; ok {
b.Settings["filetype"] = v
}
}
```
? | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -8,6 +8,43 @@ import (
"github.com/zyedidia/micro/v2/internal/screen"
)
+func (b *Buffer) ReloadSettings(filetype bool) {
+ settings := config.ParsedSettings()
+
+ if _, ok := b.LocalSettings["filetype"]; ok || filetype {
+ settings["filetype"] = b.Settings["filetype"]
+ } else if _, ok := settings["filetype"]... | internal/buffer/settings.go | 20 | Go | 0.929 | question | 262 | 45 | 45 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(filetype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; ok || filetype {
settings["filetype"] =... | `UpdateRules()` still supports `ft == ""` (equivalent to `ft == "unknown"`, undocumented). I'm not sure it makes sense to keep supporting it, but if we do, we should consistently handle it here as well? | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -8,6 +8,43 @@ import (
"github.com/zyedidia/micro/v2/internal/screen"
)
+func (b *Buffer) ReloadSettings(filetype bool) {
+ settings := config.ParsedSettings()
+
+ if _, ok := b.LocalSettings["filetype"]; ok || filetype {
+ settings["filetype"] = b.Settings["filetype"]
+ } else if _, ok := settings["filetype"]... | internal/buffer/settings.go | 21 | Go | 0.786 | question | 202 | 46 | 46 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(filetype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; ok || filetype {
settings["filetype"] =... | We also update rules (unconditionally) in `DoSetOptionNative("filetype")` and in `reload` (and we indeed should do that, especially in `reload`, since it may reload syntax files). So we unnecessarily update them twice?
So maybe we should instead update rules just here, in `ReloadSettings()`, unconditionally, but bef... | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -8,6 +8,43 @@ import (
"github.com/zyedidia/micro/v2/internal/screen"
)
+func (b *Buffer) ReloadSettings(filetype bool) {
+ settings := config.ParsedSettings()
+
+ if _, ok := b.LocalSettings["filetype"]; ok || filetype {
+ settings["filetype"] = b.Settings["filetype"]
+ } else if _, ok := settings["filetype"]... | internal/buffer/settings.go | 22 | Go | 1 | suggestion | 783 | 47 | 47 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
)
func init() {
ModifiedSettings = make(map[string]bool)
VolatileSettings = make(map[string]bool)
}
func validateParsedSettings() error {
var err error
defaults := DefaultAllSettings()
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
if strings.HasPrefix(k, "ft:")... | In this case, unlike in other cases, we leave the invalid glob in place, whereas later in `InitLocalSettings()` we assume that the glob is valid and don't check `glob.Compile()` for errors? | VolatileSettings map[string]bool
)
func init() {
ModifiedSettings = make(map[string]bool)
VolatileSettings = make(map[string]bool)
}
func validateParsedSettings() error {
var err error
defaults := DefaultAllSettings()
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {... | @@ -155,6 +155,62 @@ func init() {
VolatileSettings = make(map[string]bool)
}
+func validateParsedSettings() error {
+ var err error
+ defaults := DefaultAllSettings()
+ for k, v := range parsedSettings {
+ if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
+ if strings.HasPrefix(k, "ft:") {
+ for k1,... | internal/config/settings.go | 26 | Go | 0.643 | question | 189 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | 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
}
// 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
// Must be called ... | I was actually thinking that we might remove the invalid entry from the `parsedSettings` in `validateParsedSettings()`, in line with how we handle other error cases, i.e. ensure that in the end `parsedSettings` is fully valid, instead of leaving this a special case that we need to remember about. | var err error
GlobalSettings = DefaultAllSettings()
for k, v := range parsedSettings {
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
GlobalSettings[k] = v
}
}
return err
}
// InitLocalSettings scans the json in settings.json and sets the options locally based
// on whether the filetype or pat... | @@ -228,40 +284,30 @@ func InitGlobalSettings() error {
// 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
// Must be called after ReadSettings
-func InitLocalSettings(settings map[string]interface{}, path strin... | internal/config/settings.go | 26 | Go | 0.786 | suggestion | 297 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package buffer
import (
"crypto/md5"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
if !b.M... | Just FYI this made me reveal a bunch of other small issues around `calcHash()`: #3430
...And just now I've also realized that this checking of file size inside `calcHash()` itself doesn't seem to make much sense, actually. It doesn't really optimize anything, since just calculating the file size (i.e. adding up line... | package buffer
import (
"crypto/md5"
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
settings := config.ParsedSettings()
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
// need t... | @@ -13,7 +15,12 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
if !b.Modified() {
e := calcHash(b, &b.origHash)
if e == ErrFileTooLarge {
- b.Settings["fastdirty"] = false
+ b.Settings["fastdirty"] = true
+ }
+ } else {
+ b.origHash = [md5.Size]byte{}
+... | internal/buffer/settings.go | 22 | Go | 0.571 | performance | 719 | 47 | 47 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
}
func SetGlobalOption(option, value string) error {
if _, ok := config.GlobalSettings[option]; !ok {
return config.ErrInvalidOption
}
nativeValue, err := config.GetNativeValue(option, config.GlobalSettings[option], value)
if err != nil {
return err
}
return SetGlobalOptionNative(option, nativeValue)
}
//... | Still not checked for errors.
`reset ruler aaa` -> silently does nothing. |
func SetGlobalOption(option, value string) error {
if _, ok := config.GlobalSettings[option]; !ok {
return config.ErrInvalidOption
}
nativeValue, err := config.GetNativeValue(option, config.GlobalSettings[option], value)
if err != nil {
return err
}
return SetGlobalOptionNative(option, nativeValue)
}
// R... | @@ -634,16 +634,10 @@ func (h *BufPane) ResetCmd(args []string) {
}
option := args[0]
+ defaults := config.DefaultAllSettings()
- defaultGlobals := config.DefaultGlobalSettings()
- defaultLocals := config.DefaultCommonSettings()
-
- if _, ok := defaultGlobals[option]; ok {
- SetGlobalOptionNative(option, defau... | internal/action/command.go | 26 | Go | 0.5 | suggestion | 74 | 51 | 51 | false | Rework `filetype` change, `reload` command and `autosave` | 3,343 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
h.Relocate()
return true
}
// SelectToEndOfLine selects to the end of the current line
func (h *BufPane) SelectToEndOfLine() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.Cursor.End()
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
}
func (h *BufPane) paragraphPr... | `line != h.Cursor.Y` seems not needed anymore? | h.Relocate()
return true
}
// SelectToEndOfLine selects to the end of the current line
func (h *BufPane) SelectToEndOfLine() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.Cursor.End()
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
}
func (h *BufPane) paragraphPr... | @@ -490,38 +490,84 @@ func (h *BufPane) SelectToEndOfLine() bool {
return true
}
-// ParagraphPrevious moves the cursor to the previous empty line, or beginning of the buffer if there's none
-func (h *BufPane) ParagraphPrevious() bool {
+func (h *BufPane) paragraphPrevious() {
var line int
+ // Skip to the first... | internal/action/actions.go | 26 | Go | 0.214 | question | 46 | 51 | 51 | false | Adding selection for ParagraphPrevious and ParagraphNext. | 3,353 | zyedidia/micro | 13,805 | Go | dmaluka | hchac |
}
}
func (h *BufPane) paragraphNext() {
var line int
// Skip to the first non-empty line
for line = h.Cursor.Y; line < h.Buf.LinesNum(); line++ {
if len(h.Buf.LineBytes(line)) != 0 {
break
}
}
// Find the first empty line
for ; line < h.Buf.LinesNum(); line++ {
if len(h.Buf.LineBytes(line)) == 0 && lin... | Just noticed: these comment lines are way too long, could you split them?
Besides that, the PR looks good to me. | }
}
func (h *BufPane) paragraphNext() {
var line int
// Skip to the first non-empty line
for line = h.Cursor.Y; line < h.Buf.LinesNum(); line++ {
if len(h.Buf.LineBytes(line)) != 0 {
break
}
}
// Find the first empty line
for ; line < h.Buf.LinesNum(); line++ {
if len(h.Buf.LineBytes(line)) == 0 {
h... | @@ -490,38 +490,84 @@ func (h *BufPane) SelectToEndOfLine() bool {
return true
}
-// ParagraphPrevious moves the cursor to the previous empty line, or beginning of the buffer if there's none
-func (h *BufPane) ParagraphPrevious() bool {
+func (h *BufPane) paragraphPrevious() {
var line int
+ // Skip to the first... | internal/action/actions.go | 26 | Go | 0.429 | refactor | 113 | 51 | 51 | false | Adding selection for ParagraphPrevious and ParagraphNext. | 3,353 | zyedidia/micro | 13,805 | Go | dmaluka | hchac |
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
if ahead, err := semver.NewPRVersion(tagParts[1]); err == nil {
return tagParts[0], &ahead
}
} else if len(tagParts) == 4 {
if ahead, err := semver.NewPRVersion(tagParts[2]); err == nil {
return tagParts[0] + "-" + tagParts[1], &... | Print the error if it failed?
Hmm... errors are not printed in the rest of this code either... | } else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Printf("semver.NewPRVersion(%s): %v", tagParts[1], err)
} else if len(tagParts) == 4 {
ahead, err := semver.NewPRVersion(... | @@ -42,6 +42,10 @@ func main() {
version, err := semver.ParseTolerant(versionStr)
if err != nil {
// no version tag found so just return what ever we can find.
+ if hash, err := exec.Command("git", "rev-parse", "--short", "HEAD").Output(); err == nil { | tools/build-version.go | 26 | Go | 0.357 | bug | 95 | 51 | 51 | false | workflows: General improvements | 3,354 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
if ahead, err := semver.NewPRVersion(tagParts[1]); err == nil {
return tagParts[0], &ahead
}
log.Println("semver.NewPRVersion:", err)
} el... | Do you have an example this log output? I guess this output doesn't include the actual output (stderr) of the `git fetch --tags` command? | if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Printf("semver.NewPRVersion(%s): %v", tag... | @@ -36,15 +36,11 @@ func getTag(match ...string) (string, *semver.PRVersion) {
}
func main() {
- tags, err := exec.Command("git", "tag").Output()
- if err != nil {
- log.Println("git tag:", err)
- }
- if len(tags) == 0 {
- // no tags found -- fetch them
- err = exec.Command("git", "fetch", "--tags").Run()
- if ... | tools/build-version.go | 26 | Go | 0.5 | question | 137 | 51 | 51 | false | workflows: General improvements | 3,354 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
//+build ignore
package main
import (
"fmt"
"log"
"os/exec"
"strings"
"github.com/blang/semver"
)
func getTag(match ...string) (string, *semver.PRVersion) {
args := append([]string{
"describe", "--tags",
}, match...)
if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} el... | These don't look very useful as is. Are you gonna remove them, or improve them? | //+build ignore
package main
import (
"fmt"
"log"
"os/exec"
"strings"
"github.com/blang/semver"
)
func getTag(match ...string) (string, *semver.PRVersion) {
args := append([]string{
"describe", "--tags",
}, match...)
if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} el... | @@ -22,26 +23,37 @@ func getTag(match ...string) (string, *semver.PRVersion) {
if ahead, err := semver.NewPRVersion(tagParts[1]); err == nil {
return tagParts[0], &ahead
}
+ log.Println("semver.NewPRVersion:", err) | tools/build-version.go | 26 | Go | 0.286 | question | 79 | 51 | 51 | false | workflows: General improvements | 3,354 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
}, match...)
if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Printf("semver.NewPRVersion... | Hmm, this is what I'm getting now:
```
$ go run tools/build-version.go
2024/06/20 19:15:04 git fetch --tags exit status 1
2024/06/20 19:15:04
2.0.14-dev.213
```
Consequently, when I'm just building micro, I'm getting:
```
$ make
GOOS=linux GOARCH=amd64 go generate ./runtime
2024/06/20 19:16:58 git fetch ... | }, match...)
if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Printf("semver.NewPRVersion... | @@ -38,20 +38,13 @@ func getTag(match ...string) (string, *semver.PRVersion) {
}
func main() {
- tags, err := exec.Command("git", "tag").Output()
- if err != nil {
- log.Println("git tag:", err)
+ // Fetch the latest tags
+ if err := exec.Command("git", "fetch", "--tags").Run(); err != nil { | tools/build-version.go | 26 | Go | 0.857 | question | 954 | 51 | 51 | false | workflows: General improvements | 3,354 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Printf("semver.NewPRVersion(%s): %v", tagParts[1], err)
} else if len(tagParts) == 4 {
ahead, err := sem... | ...Per the above comment: so for some reason it is printing an empty string for me, instead of the stderr output. I've no idea why. | return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Printf("semver.NewPRVersion(%s): %v", tagParts[1], err)
} else if len(tagParts) == 4 {
ahead, err := sem... | @@ -38,20 +38,13 @@ func getTag(match ...string) (string, *semver.PRVersion) {
}
func main() {
- tags, err := exec.Command("git", "tag").Output()
- if err != nil {
- log.Println("git tag:", err)
+ // Fetch the latest tags
+ if err := exec.Command("git", "fetch", "--tags").Run(); err != nil {
+ log.Println("git fe... | tools/build-version.go | 26 | Go | 0.429 | suggestion | 131 | 51 | 51 | false | workflows: General improvements | 3,354 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
"describe", "--tags",
}, match...)
if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Pri... | Do we still need to run `git tag`? IIUC it was just to check if we need to fetch or not? | "describe", "--tags",
}, match...)
if tag, err := exec.Command("git", args...).Output(); err != nil {
return "", nil
} else {
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
ahead, err := semver.NewPRVersion(tagParts[1])
if err == nil {
return tagParts[0], &ahead
}
log.Pri... | @@ -38,23 +38,12 @@ func getTag(match ...string) (string, *semver.PRVersion) {
}
func main() {
- tags, err := exec.Command("git", "tag").Output()
- if err != nil {
+ if err := exec.Command("git", "tag").Run(); err != nil { | tools/build-version.go | 26 | Go | 0.357 | question | 88 | 51 | 51 | false | workflows: General improvements | 3,354 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
inputCmd := args[0]
// Shut down the screen because we're going to interact directly with the shell
screenb := screen.TempFini()
args = args[1:]
// Set up everything for the command
outputBytes := &bytes.Buffer{}
cmd := exec.Command(inputCmd, args...)
cmd.Stdin = os.Stdin
if getOutput {
cmd.Stdout = io.Mu... | Print error if it failed?
I've just tried this, seems to work ok (e.g. when trying to run `RunInteractiveShell()` with a non-existing command):
```
--- a/internal/shell/shell.go
+++ b/internal/shell/shell.go
@@ -104,6 +104,8 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error
e... | inputCmd := args[0]
// Shut down the screen because we're going to interact directly with the shell
screenb := screen.TempFini()
args = args[1:]
// Set up everything for the command
outputBytes := &bytes.Buffer{}
cmd := exec.Command(inputCmd, args...)
cmd.Stdin = os.Stdin
if getOutput {
cmd.Stdout = io.Mu... | @@ -101,8 +101,10 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error
c := make(chan os.Signal, 1)
signal.Reset(os.Interrupt)
signal.Notify(c, os.Interrupt)
- cmd.Start()
- err = cmd.Wait()
+ err = cmd.Start()
+ if err == nil { | internal/shell/shell.go | 26 | Go | 0.929 | bug | 463 | 51 | 51 | false | Receive SIGINT only in RunInteractiveShell | 3,357 | zyedidia/micro | 13,805 | Go | dmaluka | niten94 |
}
// AddTab adds a new tab with an empty buffer
func (h *BufPane) AddTab() bool {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
b := buffer.NewBufferFromString("", "", buffer.BTDefault)
tp := NewTabFromBuffer(0, 0, width, height-iOffset, b)
Tabs.AddTab(tp)
Tabs.SetActive(len(Tabs.Lis... | This calculation is not needed anymore, right? It is just `Tabs.SetActive(Tabs.Active() - 1)`. | quit()
}
return true
}
// AddTab adds a new tab with an empty buffer
func (h *BufPane) AddTab() bool {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
b := buffer.NewBufferFromString("", "", buffer.BTDefault)
tp := NewTabFromBuffer(0, 0, width, height-iOffset, b)
Tabs.AddTab(tp)
T... | @@ -1793,6 +1793,9 @@ func (h *BufPane) PreviousTab() bool {
if tabsLen == 1 {
return false
}
+ if Tabs.Active() == 0 {
+ return false
+ }
a := Tabs.Active() + tabsLen
Tabs.SetActive((a - 1) % tabsLen) | internal/action/actions.go | 26 | Go | 0.357 | suggestion | 94 | 51 | 51 | false | Implemented new actions `FirstTab`, `LastTab`, `FirstSplit` and `LastSplit` | 3,403 | zyedidia/micro | 13,805 | Go | dmaluka | masmu |
h.HSplitBuf(buffer.NewBufferFromString("", "", buffer.BTDefault))
return true
}
// Unsplit closes all splits in the current tab except the active one
func (h *BufPane) Unsplit() bool {
tab := h.tab
n := tab.GetNode(h.splitID)
ok := n.Unsplit()
if ok {
tab.RemovePane(tab.GetPane(h.splitID))
tab.Resize()
ta... | `lastSplitIndex`? `lastPaneIdx`?
...And actually I don't find this variable (here and in other functions) very useful. `if h.tab.active == len(h.tab.Panes)-1` would be fine. But that's a nit. | }
// NextSplit changes the view to the next split
func (h *BufPane) NextSplit() bool {
if h.tab.active == len(h.tab.Panes)-1 {
return false
}
h.tab.SetActive(h.tab.active + 1)
return true
}
// PreviousSplit changes the view to the previous split
func (h *BufPane) PreviousSplit() bool {
if h.tab.active == 0 {
... | @@ -1847,6 +1880,10 @@ func (h *BufPane) NextSplit() bool {
if len(h.tab.Panes) == 1 {
return false
}
+ lastTabIndex := len(h.tab.Panes) - 1 | internal/action/actions.go | 26 | Go | 0.571 | suggestion | 194 | 51 | 51 | false | Implemented new actions `FirstTab`, `LastTab`, `FirstSplit` and `LastSplit` | 3,403 | zyedidia/micro | 13,805 | Go | dmaluka | masmu |
func (h *BufPane) Unsplit() bool {
tab := h.tab
n := tab.GetNode(h.splitID)
ok := n.Unsplit()
if ok {
tab.RemovePane(tab.GetPane(h.splitID))
tab.Resize()
tab.SetActive(len(tab.Panes) - 1)
return true
}
return false
}
// NextSplit changes the view to the next split
func (h *BufPane) NextSplit() bool {
i... | Again, this check is not needed anymore, as we already do exactly the same check above. | }
h.tab.SetActive(h.tab.active + 1)
return true
}
// PreviousSplit changes the view to the previous split
func (h *BufPane) PreviousSplit() bool {
if h.tab.active == 0 {
return false
}
h.tab.SetActive(h.tab.active - 1)
return true
}
// FirstSplit changes the view to the first split
func (h *BufPane) FirstSpl... | @@ -1847,6 +1880,10 @@ func (h *BufPane) NextSplit() bool {
if len(h.tab.Panes) == 1 {
return false
}
+ lastTabIndex := len(h.tab.Panes) - 1
+ if h.tab.active == lastTabIndex {
+ return false
+ }
a := h.tab.active
if a < len(h.tab.Panes)-1 { | internal/action/actions.go | 26 | Go | 0.214 | suggestion | 87 | 51 | 51 | false | Implemented new actions `FirstTab`, `LastTab`, `FirstSplit` and `LastSplit` | 3,403 | zyedidia/micro | 13,805 | Go | dmaluka | masmu |
quit()
}
})
} else {
quit()
}
return true
}
// AddTab adds a new tab with an empty buffer
func (h *BufPane) AddTab() bool {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
b := buffer.NewBufferFromString("", "", buffer.BTDefault)
tp := NewTabFromBuffer(0, 0, width, height-... | Hmm, this check is actually not needed anymore either? if `tabsLen` is 1, `Tabs.Active()` can be only zero.
And actually in `NextTab()` similarly.
And in most (all?) other functions too? | quit()
}
})
} else {
quit()
}
return true
}
// AddTab adds a new tab with an empty buffer
func (h *BufPane) AddTab() bool {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
b := buffer.NewBufferFromString("", "", buffer.BTDefault)
tp := NewTabFromBuffer(0, 0, width, height-... | @@ -1797,10 +1797,10 @@ func (h *BufPane) PreviousTab() bool {
if tabsLen == 1 { | internal/action/actions.go | 26 | Go | 0.5 | question | 192 | 51 | 51 | false | Implemented new actions `FirstTab`, `LastTab`, `FirstSplit` and `LastSplit` | 3,403 | zyedidia/micro | 13,805 | Go | dmaluka | masmu |
lastC.SetSelectionStart(match[0])
lastC.SetSelectionEnd(match[1])
lastC.OrigSelection[0] = lastC.CurSelection[0]
lastC.OrigSelection[1] = lastC.CurSelection[1]
lastC.Loc = lastC.CurSelection[1]
h.Buf.MergeCursors()
h.Buf.SetCurCursor(h.Buf.NumCursors() - 1)
} else {
InfoBar.Message("No matches found")... | It's almost exactly the same code as in `SkipMultiCursor()`, right? So it should be easy to move this code to a common helper function? | }
if found {
lastC.SetSelectionStart(match[0])
lastC.SetSelectionEnd(match[1])
lastC.OrigSelection[0] = lastC.CurSelection[0]
lastC.OrigSelection[1] = lastC.CurSelection[1]
lastC.Loc = lastC.CurSelection[1]
h.Buf.MergeCursors()
h.Buf.SetCurCursor(h.Buf.NumCursors() - 1)
} else {
InfoBar.Message("No ... | @@ -2099,6 +2099,41 @@ func (h *BufPane) SkipMultiCursor() bool {
return true
}
+// SkipMultiCursorBack moves the current multiple cursor to the previously available position
+func (h *BufPane) SkipMultiCursorBack() bool {
+ lastC := h.Buf.GetCursor(h.Buf.NumCursors() - 1)
+ if !lastC.HasSelection() {
+ return fa... | internal/action/actions.go | 26 | Go | 0.571 | refactor | 135 | 51 | 51 | false | Implemented `SkipMultiCursorBack` as a counterpart to `SkipMultiCursor` | 3,404 | zyedidia/micro | 13,805 | Go | dmaluka | masmu |
mx, my := e.Position()
// ignore click on the status line
if my >= h.BufView().Y+h.BufView().Height {
return false
}
mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my})
if h.Buf.NumCursors() > 1 {
cursors := h.Buf.GetCursors()
for _, c := range cursors {
if c.Loc == mouseLoc {
h.Buf.RemoveCursor(c... | Erg, this looks ugly. I didn't meant this helper function not to be a method of `BufPane`.
The most obvious way is to name it `skipMultiCursor()` i.e. non-capitalized, i.e. private (it doesn't need to be public, right?). I.e.:
```
func (h *BufPane) skipMultiCursor(forward bool) bool
``` | mx, my := e.Position()
// ignore click on the status line
if my >= h.BufView().Y+h.BufView().Height {
return false
}
mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my})
if h.Buf.NumCursors() > 1 {
cursors := h.Buf.GetCursors()
for _, c := range cursors {
if c.Loc == mouseLoc {
h.Buf.RemoveCursor(c... | @@ -2064,22 +2064,25 @@ func (h *BufPane) MouseMultiCursor(e *tcell.EventMouse) bool {
return true
}
-// SkipMultiCursor moves the current multiple cursor to the next available position
-func (h *BufPane) SkipMultiCursor() bool {
+// SkipMultiCursor moves the current multiple cursor to the next or previous availab... | internal/action/actions.go | 26 | Go | 0.786 | refactor | 295 | 51 | 51 | false | Implemented `SkipMultiCursorBack` as a counterpart to `SkipMultiCursor` | 3,404 | zyedidia/micro | 13,805 | Go | dmaluka | masmu |
b := h.Buf
mx, my := e.Position()
// ignore click on the status line
if my >= h.BufView().Y+h.BufView().Height {
return false
}
mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my})
if h.Buf.NumCursors() > 1 {
cursors := h.Buf.GetCursors()
for _, c := range cursors {
if c.Loc == mouseLoc {
h.Buf.Re... | `SkipMultiCursor` still capitalized in this comment.
I think we don't need a comment here. It's an internal function, and from its usage below it is obvious what it does. | b := h.Buf
mx, my := e.Position()
// ignore click on the status line
if my >= h.BufView().Y+h.BufView().Height {
return false
}
mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my})
if h.Buf.NumCursors() > 1 {
cursors := h.Buf.GetCursors()
for _, c := range cursors {
if c.Loc == mouseLoc {
h.Buf.Re... | @@ -2064,22 +2064,25 @@ func (h *BufPane) MouseMultiCursor(e *tcell.EventMouse) bool {
return true
}
-// SkipMultiCursor moves the current multiple cursor to the next available position
-func (h *BufPane) SkipMultiCursor() bool {
+// SkipMultiCursor moves the current multiple cursor to the next or previous availab... | internal/action/actions.go | 26 | Go | 0.5 | suggestion | 173 | 51 | 51 | false | Implemented `SkipMultiCursorBack` as a counterpart to `SkipMultiCursor` | 3,404 | zyedidia/micro | 13,805 | Go | dmaluka | masmu |
ft["php"] = "// %s"
ft["pony"] = "// %s"
ft["powershell"] = "# %s"
ft["proto"] = "// %s"
ft["python"] = "# %s"
ft["python3"] = "# %s"
ft["ruby"] = "# %s"
ft["rust"] = "// %s"
ft["scala"] = "// %s"
ft["shell"] = "# %s"
ft["sql"] = "-- %s"
ft["swift"] = "// %s"
ft["tex"] = "% %s"
ft["toml"] = "# %s"
ft["twig"] = "{# %s #... | I think this wording is harder to misinterpret:
```suggestion
micro.InfoBar():Error("\"commenttype\" option has been renamed to \"comment.type\"",
", please update your configuration")
```
| ft["php"] = "// %s"
ft["pony"] = "// %s"
ft["powershell"] = "# %s"
ft["proto"] = "// %s"
ft["python"] = "# %s"
ft["python3"] = "# %s"
ft["ruby"] = "# %s"
ft["rust"] = "// %s"
ft["scala"] = "// %s"
ft["shell"] = "# %s"
ft["sql"] = "-- %s"
ft["swift"] = "// %s"
ft["tex"] = "% %s"
ft["toml"] = "# %s"
ft["twig"] = "{# %s #... | @@ -61,17 +62,20 @@ ft["zig"] = "// %s"
ft["zscript"] = "// %s"
ft["zsh"] = "# %s"
-local last_ft
-
function updateCommentType(buf)
- if buf.Settings["commenttype"] == nil or (last_ft ~= buf.Settings["filetype"] and last_ft ~= nil) then
+ if buf.Settings["commenttype"] ~= nil then
+ micro.InfoBar():Er... | runtime/plugins/comment/comment.lua | 26 | Lua | 1 | suggestion | 234 | 51 | 51 | false | Fixing comment plugin not using user settings when overriding default setting | 3,424 | zyedidia/micro | 13,805 | Go | Andriamanitra | Neko-Box-Coder |
ft["perl"] = "# %s"
ft["php"] = "// %s"
ft["pony"] = "// %s"
ft["powershell"] = "# %s"
ft["proto"] = "// %s"
ft["python"] = "# %s"
ft["python3"] = "# %s"
ft["ruby"] = "# %s"
ft["rust"] = "// %s"
ft["scala"] = "// %s"
ft["shell"] = "# %s"
ft["sql"] = "-- %s"
ft["swift"] = "// %s"
ft["tex"] = "% %s"
ft["toml"] = "# %s"
f... | It is not nearly obvious *why* can't it be reset by a "filetype" change if we use `SetOptionNative()` (it took me some time to figure it out, for instance). We should explain it better, e.g. "Don't use SetOptionNative() to set "comment.type", otherwise "comment.type" will be marked as locally overridden and will not be... | ft["pascal"] = "{ %s }"
ft["perl"] = "# %s"
ft["php"] = "// %s"
ft["pony"] = "// %s"
ft["powershell"] = "# %s"
ft["proto"] = "// %s"
ft["python"] = "# %s"
ft["python3"] = "# %s"
ft["ruby"] = "# %s"
ft["rust"] = "// %s"
ft["scala"] = "// %s"
ft["shell"] = "# %s"
ft["sql"] = "-- %s"
ft["swift"] = "// %s"
ft["tex"] = "% %... | @@ -61,17 +61,15 @@ ft["zig"] = "// %s"
ft["zscript"] = "// %s"
ft["zsh"] = "# %s"
-local last_ft
-
function updateCommentType(buf)
- if buf.Settings["commenttype"] == nil or (last_ft ~= buf.Settings["filetype"] and last_ft ~= nil) then
+ -- NOTE: Don't use SetOptionNative() to set "comment.type",
+ -- ot... | runtime/plugins/comment/comment.lua | 26 | Lua | 0.786 | suggestion | 911 | 51 | 51 | false | Fixing comment plugin not using user settings when overriding default setting | 3,424 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
ft["php"] = "// %s"
ft["pony"] = "// %s"
ft["powershell"] = "# %s"
ft["proto"] = "// %s"
ft["python"] = "# %s"
ft["python3"] = "# %s"
ft["ruby"] = "# %s"
ft["rust"] = "// %s"
ft["scala"] = "// %s"
ft["shell"] = "# %s"
ft["sql"] = "-- %s"
ft["swift"] = "// %s"
ft["tex"] = "% %s"
ft["toml"] = "# %s"
ft["twig"] = "{# %s #... | After changing `commenttype` to `comment.type` in `settings.json` and running the `reload` command, micro still stubbornly shows this error. | ft["php"] = "// %s"
ft["pony"] = "// %s"
ft["powershell"] = "# %s"
ft["proto"] = "// %s"
ft["python"] = "# %s"
ft["python3"] = "# %s"
ft["ruby"] = "# %s"
ft["rust"] = "// %s"
ft["scala"] = "// %s"
ft["shell"] = "# %s"
ft["sql"] = "-- %s"
ft["swift"] = "// %s"
ft["tex"] = "% %s"
ft["toml"] = "# %s"
ft["twig"] = "{# %s #... | @@ -64,8 +64,8 @@ ft["zsh"] = "# %s"
function updateCommentType(buf)
if buf.Settings["commenttype"] ~= nil then
- micro.InfoBar():Error("\"commenttype\" option has been updated to \"comment.type\"",
- "instead, please update accordingly")
+ micro.InfoBar():Error("\"com... | runtime/plugins/comment/comment.lua | 26 | Lua | 0.643 | suggestion | 140 | 51 | 51 | false | Fixing comment plugin not using user settings when overriding default setting | 3,424 | zyedidia/micro | 13,805 | Go | dmaluka | Neko-Box-Coder |
if _, ok := Groups[groupStr]; !ok {
numGroups++
Groups[groupStr] = numGroups
}
groupNum := Groups[groupStr]
r.limitGroup = groupNum
if err != nil {
return nil, err
}
} else {
r.limitGroup = r.group
}
// rules are optional
if rules, ok := regionInfo["rules"]; ok {
r.rules, err = parseRule... | nit: It seems a bit more idiomatic to use `&rules{}` instead of `new(rules)` in such cases. (Yeah it was me who first used `new(rules)` in #3213. We can change it to `&rules{}` there as well.) |
if _, ok := Groups[groupStr]; !ok {
numGroups++
Groups[groupStr] = numGroups
}
groupNum := Groups[groupStr]
r.limitGroup = groupNum
if err != nil {
return nil, err
}
} else {
r.limitGroup = r.group
}
// rules are optional
if rules, ok := regionInfo["rules"]; ok {
r.rules, err = parseRule... | @@ -476,10 +476,17 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
r.limitGroup = r.group
}
- r.rules, err = parseRules(regionInfo["rules"].([]interface{}), r)
+ // rules are optional
+ if rules, ok := regionInfo["rules"]; ok {
+ r.rules, err = parseRules(rules.([]interface{}... | pkg/highlight/parser.go | 26 | Go | 0.571 | suggestion | 192 | 31 | 31 | false | Remove empty rules in regions | 3,458 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
sha256sum micro-$VERSION-$1.zip > micro-$VERSION-$1.zip.sha
mv micro-$VERSION-$1.* binaries
rm micro-$VERSION/micro.exe
}
# Mac
echo "OSX 64"
GOOS=darwin GOARCH=amd64 make build
create_artefact_generic "osx"
# Mac ARM64
echo "MacOS ARM64"
GOOS=darwin GOARCH=arm64 make build
create_artefact_generic "macos-arm64"
#... | Shouldn't we rather ask @benweissmann to update the script? | sha256sum micro-$VERSION-$1.zip > micro-$VERSION-$1.zip.sha
mv micro-$VERSION-$1.* binaries
rm micro-$VERSION/micro.exe
}
# Mac
echo "OSX 64"
GOOS=darwin GOARCH=amd64 make build
create_artefact_generic "osx"
# Mac ARM64
echo "MacOS ARM64"
GOOS=darwin GOARCH=arm64 make build
create_artefact_generic "macos-arm64"
#... | @@ -54,8 +54,9 @@ if ./tools/package-deb.sh $VERSION; then
fi
create_artefact_generic "linux64"
-echo "Linux 64 fully static"
-CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make build
+echo "Linux 64 fully static (deprecated)"
+# Only kept for https://github.com/benweissmann/getmic.ro/blob/f90870e948afab8be9ec40884050044b5... | tools/cross-compile.sh | 26 | Shell | 0.286 | question | 59 | 51 | 51 | false | Makefile: Make all builds explicitly fully static (disable CGO) | 3,466 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
package util
import (
"fmt"
"runtime"
humanize "github.com/dustin/go-humanize"
)
// GetMemStats returns a string describing the memory usage and gc time used so far
func GetMemStats() string {
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
return fmt.Sprintf("Alloc: %s, Sys: %s, GC: %d, PauseTot... | These may be actually occasionally useful for profiling?
BTW I didn't even know about the existence of this `internal/util/profile.go` until now (and I find it rather nice). (And BTW also I didn't know about the existence of the `memusage` command.) |
import (
"fmt"
"log"
"runtime"
"time"
humanize "github.com/dustin/go-humanize"
)
// GetMemStats returns a string describing the memory usage and gc time used so far
func GetMemStats() string {
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
return fmt.Sprintf("Alloc: %s, Sys: %s, GC: %d, PauseT... | @@ -15,13 +13,3 @@ func GetMemStats() string {
runtime.ReadMemStats(&memstats)
return fmt.Sprintf("Alloc: %s, Sys: %s, GC: %d, PauseTotalNs: %dns", humanize.Bytes(memstats.Alloc), humanize.Bytes(memstats.Sys), memstats.NumGC, memstats.PauseTotalNs)
}
-
-func Tic(s string) time.Time {
- log.Println("START:", s)
- r... | internal/util/profile.go | 16 | Go | 0.643 | suggestion | 252 | 16 | 27 | false | Remove unused internal or unexported functions | 3,481 | zyedidia/micro | 13,805 | Go | dmaluka | alexandear |
func (mf memoryFile) Name() string {
return mf.name
}
func (mf memoryFile) Data() ([]byte, error) {
return mf.data, nil
}
func (rf realFile) Name() string {
fn := filepath.Base(string(rf))
return fn[:len(fn)-len(filepath.Ext(fn))]
}
func (rf realFile) Data() ([]byte, error) {
return ioutil.ReadFile(string(rf))
}... | The `namedFile` type itself is not used either, so it should be also removed? |
func (rf realFile) Name() string {
fn := filepath.Base(string(rf))
return fn[:len(fn)-len(filepath.Ext(fn))]
}
func (rf realFile) Data() ([]byte, error) {
return ioutil.ReadFile(string(rf))
}
func (af assetFile) Name() string {
fn := path.Base(string(af))
return fn[:len(fn)-len(path.Ext(fn))]
}
func (af assetF... | @@ -99,10 +99,6 @@ func (af assetFile) Data() ([]byte, error) {
return rt.Asset(string(af))
}
-func (nf namedFile) Name() string { | internal/config/rtfiles.go | 26 | Go | 0.571 | question | 77 | 51 | 51 | false | Remove unused internal or unexported functions | 3,481 | zyedidia/micro | 13,805 | Go | dmaluka | alexandear |
return errors.New(fmt.Sprintf("Unable to load help text for %s: %v", page, err))
} else {
helpBuffer := buffer.NewBufferFromString(string(data), page+".md", buffer.BTHelp)
helpBuffer.SetName("Help " + page)
helpBuffer.SetOptionNative("hltaberrors", false)
helpBuffer.SetOptionNative("hltrailingws", false)
... | It might be better to add a flag e.g. `-v` (meaning vsplit) that can be anywhere in the command, not necessarily the 1st argument, similarly to the `replace` command.
...Or maybe we shouldn't overthink this and should simply add an option, e.g. `helpsplit`. | return errors.New(fmt.Sprintf("Unable to load help text for %s: %v", page, err))
} else {
helpBuffer := buffer.NewBufferFromString(string(data), page+".md", buffer.BTHelp)
helpBuffer.SetName("Help " + page)
helpBuffer.SetOptionNative("hltaberrors", false)
helpBuffer.SetOptionNative("hltrailingws", false)
... | @@ -439,21 +439,35 @@ func (h *BufPane) openHelp(page string) error {
if h.Buf.Type == buffer.BTHelp {
h.OpenBuffer(helpBuffer)
- } else {
+ } else if hsplit {
h.HSplitBuf(helpBuffer)
+ } else {
+ h.VSplitBuf(helpBuffer)
}
}
return nil
}
// HelpCmd tries to open the given help page in a hor... | internal/action/command.go | 26 | Go | 0.643 | suggestion | 260 | 51 | 51 | false | action/command: Allow `-vsplit` & `-hsplit` as optional argument for `help` | 3,502 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
func (h *BufPane) ReopenCmd(args []string) {
if h.Buf.Modified() {
InfoBar.YNPrompt("Save file before reopen?", func(yes, canceled bool) {
if !canceled && yes {
h.Save()
h.ReOpen()
} else if !canceled {
h.ReOpen()
}
})
} else {
h.ReOpen()
}
}
func (h *BufPane) openHelp(page string, hsplit... | Is it a good idea to just remove this unconditionally? Shouldn't we add e.g. another flag for that (e.g. `-n` meaning "new pane"), or e.g. another option? | func (h *BufPane) ReopenCmd(args []string) {
if h.Buf.Modified() {
InfoBar.YNPrompt("Save file before reopen?", func(yes, canceled bool) {
if !canceled && yes {
h.Save()
h.ReOpen()
} else if !canceled {
h.ReOpen()
}
})
} else {
h.ReOpen()
}
}
func (h *BufPane) openHelp(page string, hsplit... | @@ -437,9 +437,7 @@ func (h *BufPane) openHelp(page string, hsplit bool) error {
helpBuffer.SetOptionNative("hltaberrors", false)
helpBuffer.SetOptionNative("hltrailingws", false)
- if h.Buf.Type == buffer.BTHelp {
- h.OpenBuffer(helpBuffer) | internal/action/command.go | 26 | Go | 0.571 | refactor | 154 | 51 | 51 | false | action/command: Allow `-vsplit` & `-hsplit` as optional argument for `help` | 3,502 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
if forceSplit {
InfoBar.Error(errSplit)
return
}
hsplit = true
forceSplit = true
default:
topics = append(topics, arg)
}
}
if len(topics) < 1 {
// Do the same as without arg
h.openHelp("help", hsplit, forceSplit)
return
}
for _, topic := range topics {
if config... | If current pane is a help pane and `forceSplit` is false, this opens just the last topic (in this current pane).
Something like this?
```
if len(topics) > 1 {
forceSplit = true
}
``` | hsplit = false
forceSplit = true
case "-hsplit":
if forceSplit {
InfoBar.Error(errSplit)
return
}
hsplit = true
forceSplit = true
default:
topics = append(topics, arg)
}
}
if len(topics) < 1 {
// Do the same as without arg
h.openHelp("help", hsplit, forceSplit)
... | @@ -485,13 +485,15 @@ func (h *BufPane) HelpCmd(args []string) {
return
}
- if config.FindRuntimeFile(config.RTHelp, topics[0]) != nil {
- err := h.openHelp(topics[0], hsplit, forceSplit)
- if err != nil {
- InfoBar.Error(err)
+ for _, topic := range topics {
+ if config.FindRuntimeFile(config.RTHel... | internal/action/command.go | 26 | Go | 0.714 | suggestion | 193 | 51 | 51 | false | action/command: Allow `-vsplit` & `-hsplit` as optional argument for `help` | 3,502 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
}
}
if len(topics) < 1 {
// Do the same as without arg
h.openHelp("help", hsplit, forceSplit)
return
}
if len(topics) > 1 {
forceSplit = true
}
for _, topic := range topics {
if config.FindRuntimeFile(config.RTHelp, topic) != nil {
err := h.openHelp(topic, hsplit, forceSplit)
if ... | nit: "opens one or more vertical splits"?
Same for `HSplitCmd()` and `NewTabCmd()`. | forceSplit = true
default:
topics = append(topics, arg)
}
}
if len(topics) < 1 {
// Do the same as without arg
h.openHelp("help", hsplit, forceSplit)
return
}
if len(topics) > 1 {
forceSplit = true
}
for _, topic := range topics {
if config.FindRuntimeFile(config.RTHelp, topic... | @@ -501,7 +501,7 @@ func (h *BufPane) HelpCmd(args []string) {
}
}
-// VSplitCmd opens a vertical split with file given in the first argument
+// VSplitCmd opens vertical splits with the files given as arguments | internal/action/command.go | 26 | Go | 0.357 | nitpick | 84 | 51 | 51 | false | action/command: Allow `-vsplit` & `-hsplit` as optional argument for `help` | 3,502 | zyedidia/micro | 13,805 | Go | dmaluka | JoeKar |
// ScrollUpAction scrolls the view up
func (h *BufPane) ScrollUpAction() bool {
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center... | 1. This moves the cursor even if the cursor is already in the current view. If that is the intended behavior, then it should be named not `MoveCursorToView` but rather something like `MoveCursorToViewTop`?
2. This doesn't take `scrollmargin` into account. Whereas `h.Relocate()` below does take it into account, and mov... |
// ScrollUpAction scrolls the view up
func (h *BufPane) ScrollUpAction() bool {
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center... | @@ -160,6 +160,16 @@ func (h *BufPane) Center() bool {
return true
}
+// MoveCursorToView moves the cursor to the current view
+func (h *BufPane) MoveCursorToView() bool {
+ v := h.GetView()
+ h.Cursor.GotoLoc(buffer.Loc{0, v.StartLine.Line}) | internal/action/actions.go | 26 | Go | 0.643 | question | 569 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
if h.Cursor.HasSelection() {
h.Cursor.Loc = h.Cursor.CurSelection[1]
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
}
h.MoveCursorDown(h.BufView().Height)
h.Relocate()
return true
}
// HalfPageUp scrolls the view up half a page
func (h *BufPane) HalfPageUp() bool {
h.ScrollUp(h.BufView().Height / 2)
r... | While `MoveCursorToView` looks quite generic and useful, these 2 actions `PageUpAndMoveCursor` and `PageDownAndMoveCursor` don't look nice. It should be possible to use chained actions `PageUp,MoveCursorToView` and `PageDown,MoveCursorToView` instead, that's what chained actions are for. | h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorUp(h.BufView().Height)
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
}
// SelectPageDown selects down one page
func (h *BufPane) SelectPageDown() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorDow... | @@ -1688,6 +1698,29 @@ func (h *BufPane) HalfPageDown() bool {
return true
}
+// PageUpAndMoveCursor scrolls the view up a page and moves the cursor to keep it in view
+func (h *BufPane) PageUpAndMoveCursor() bool { | internal/action/actions.go | 26 | Go | 0.643 | suggestion | 288 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
h.Cursor.StoreVisualX()
}
h.MoveCursorDown(h.BufView().Height)
h.Relocate()
return true
}
// HalfPageUp scrolls the view up half a page
func (h *BufPane) HalfPageUp() bool {
h.ScrollUp(h.BufView().Height / 2)
return true
}
// HalfPageDown scrolls the view down half a page
func (h *BufPane) HalfPageDown() bool... | This doesn't take soft-wrapped lines into account. The correct way is:
```
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
SLoc: h.Scroll(v.StartLine, scrollmargin),
VisualX: 0,
}))
``` | h.Relocate()
return true
}
// SelectPageDown selects down one page
func (h *BufPane) SelectPageDown() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorDown(h.BufView().Height)
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
}
// CursorPageUp places the cur... | @@ -1688,6 +1698,29 @@ func (h *BufPane) HalfPageDown() bool {
return true
}
+// PageUpAndMoveCursor scrolls the view up a page and moves the cursor to keep it in view
+func (h *BufPane) PageUpAndMoveCursor() bool {
+ h.ScrollUp(h.BufView().Height)
+ v := h.GetView()
+ scrollmargin := int(h.Buf.Settings["scrollmar... | internal/action/actions.go | 26 | Go | 0.714 | suggestion | 199 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
func (h *BufPane) ScrollUpAction() bool {
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h... | This is, again, not the right way to check if the cursor is within the view. For the same reason: the cursor may be in the first line in the view, yet outside the view, since this line may be wrapped, so only a part of this line may be visible. That's why `v.StartLine` is a `SLoc` structure, with 2 fields: `Line` which... | func (h *BufPane) ScrollUpAction() bool {
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h... | @@ -160,13 +160,19 @@ func (h *BufPane) Center() bool {
return true
}
-// MoveCursorToView moves the cursor to the current view
-func (h *BufPane) MoveCursorToView() bool {
+// CursorToView moves the cursor to the current view
+func (h *BufPane) CursorToView() bool {
v := h.GetView()
- h.Cursor.GotoLoc(buffer.Lo... | internal/action/actions.go | 26 | Go | 0.786 | suggestion | 612 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufView().Height/2)
h.SetView(v)
h.ScrollAdjust()
... | So this new `CursorToView` action means "move cursor to the current view" without defining where exactly will it move the cursor in the current view. And I'm not sure if the top of the view (plus scrollmargin) is the best "default" location.
In other cases when we move cursor to a location which is far from its curr... | func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufView().Height/2)
h.SetView(v)
h.ScrollAdjust()
... | @@ -160,13 +160,19 @@ func (h *BufPane) Center() bool {
return true
}
-// MoveCursorToView moves the cursor to the current view
-func (h *BufPane) MoveCursorToView() bool {
+// CursorToView moves the cursor to the current view
+func (h *BufPane) CursorToView() bool {
v := h.GetView()
- h.Cursor.GotoLoc(buffer.Lo... | internal/action/actions.go | 26 | Go | 0.643 | question | 600 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
// ScrollUpAction scrolls the view up
func (h *BufPane) ScrollUpAction() bool {
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center ... | Don't deselect if the cursor is already in the current view? | // ScrollUpAction scrolls the view up
func (h *BufPane) ScrollUpAction() bool {
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center ... | @@ -160,13 +160,19 @@ func (h *BufPane) Center() bool {
return true
}
-// MoveCursorToView moves the cursor to the current view
-func (h *BufPane) MoveCursorToView() bool {
+// CursorToView moves the cursor to the current view
+func (h *BufPane) CursorToView() bool {
v := h.GetView()
- h.Cursor.GotoLoc(buffer.Lo... | internal/action/actions.go | 26 | Go | 0.214 | question | 60 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
if !h.Buf.Settings["softwrap"].(bool) {
h.Cursor.UpN(n)
} else {
vloc := h.VLocFromLoc(h.Cursor.Loc)
sloc := h.Scroll(vloc.SLoc, -n)
if sloc == vloc.SLoc {
// we are at the beginning of buffer
h.Cursor.Loc = h.Buf.Start()
h.Cursor.LastVisualX = 0
} else {
vloc.SLoc = sloc
vloc.VisualX = h.Cur... | It would be useful to return false if the cursor is already in the current view, i.e. if `CursorToView` does nothing. We do that in various other cases when the action did nothing because there was nothing to do, e.g. `Deselect` returns false if there is no selection, `NextTab` returns false if there is no next tab etc... | func (h *BufPane) CursorToViewCenter() bool {
v := h.GetView()
h.Buf.ClearCursors()
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
SLoc: h.Scroll(v.StartLine, h.BufView().Height/2),
VisualX: 0,
}))
return true
}
// CursorToViewBottom moves the cursor to the bottom of the view,
// offset by scrollmargin unles... | @@ -160,13 +160,19 @@ func (h *BufPane) Center() bool {
return true
}
-// MoveCursorToView moves the cursor to the current view
-func (h *BufPane) MoveCursorToView() bool {
+// CursorToView moves the cursor to the current view
+func (h *BufPane) CursorToView() bool {
v := h.GetView()
- h.Cursor.GotoLoc(buffer.Lo... | internal/action/actions.go | 26 | Go | 0.643 | style | 381 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
none = false
break
}
}
if none && InfoBar.HasGutter {
InfoBar.ClearGutter()
}
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, h))
if err != nil {
screen.TermMessage(err)
}
}
}
// BufKeyActions contains the list of all possible key actions the bufhandler could execute
var BufKey... | It should be also mentioned in `runtime/help/keybindings.md`. | none = false
break
}
}
if none && InfoBar.HasGutter {
InfoBar.ClearGutter()
}
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, h))
if err != nil {
screen.TermMessage(err)
}
}
}
// BufKeyActions contains the list of all possible key actions the bufhandler could execute
var BufKey... | @@ -738,6 +738,7 @@ var BufKeyActions = map[string]BufKeyAction{
"CursorRight": (*BufPane).CursorRight,
"CursorStart": (*BufPane).CursorStart,
"CursorEnd": (*BufPane).CursorEnd,
+ "CursorToView": (*BufPane).CursorToView, | internal/action/bufpane.go | 26 | Go | 0.429 | suggestion | 61 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView... | nit: What about a more concise variable name, e.g. `csloc`? (Among other things, to make this code line slightly shorter and thus more vsplit-friendly.) | h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView... | @@ -160,6 +160,24 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToView moves the cursor within the view if it's currently out of view.
+// The cursor is moved to an offset of 25% from the top of the view.
+func (h *BufPane) CursorToView() bool {
+ v := h.GetView()
+ height := h.BufView().Height
+ cu... | internal/action/actions.go | 26 | Go | 0.5 | nitpick | 152 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufView().Height/2)
h.SetView(v)
h.ScrollAdjust()
return true
}
// CursorToView moves the cur... | It probably makes more sense to remove multicursors before moving the cursor, not after it, since we want to move just one cursor? (Although the end result is probably the same.)
Probably even before deselect. See e.g. `GotoCmd()` and `JumpCmd()` in `internal/action/command.go`. | h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufView().Height/2)
h.SetView(v)
h.ScrollAdjust()
return true
}
// CursorToViewTop moves the ... | @@ -160,6 +160,24 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToView moves the cursor within the view if it's currently out of view.
+// The cursor is moved to an offset of 25% from the top of the view.
+func (h *BufPane) CursorToView() bool {
+ v := h.GetView()
+ height := h.BufView().Height
+ cu... | internal/action/actions.go | 26 | Go | 0.643 | suggestion | 282 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufView().Height/2)
h.SetView(v)
h.ScrollAdjust()
... | Overall LGTM, but I still find it rather non-intuitive that we add scrollmargin even if the view is at the beginning of the file. Especially in the case when the cursor itself is at the beginning of the file, i.e. if the cursor already at the very top of the view. In this case `CursorToViewTop` unexpectedly moves the c... | func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufView().Height/2)
h.SetView(v)
h.ScrollAdjust()
... | @@ -160,6 +160,41 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToViewTop moves the cursor to the top of the view, offset by scrollmargin
+func (h *BufPane) CursorToViewTop() bool {
+ v := h.GetView()
+ h.Buf.ClearCursors()
+ scrollmargin := int(h.Buf.Settings["scrollmargin"].(float64))
+ h.Cursor.G... | internal/action/actions.go | 26 | Go | 0.643 | style | 635 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView... | Again, this doesn't take softwrap into account. A line may be so long that it doesn't fit in the entire view, so the cursor may be in the very first line of the file, yet still not at the top of the file.
See `Relocate()` in `internal/display/bufwindow.go` for an example of how to do such checks correctly. | h.ScrollUp(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView... | @@ -160,6 +160,50 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToViewTop moves the cursor to the top of the view,
+// offset by scrollmargin unless at the beginning or end of the file
+func (h *BufPane) CursorToViewTop() bool {
+ v := h.GetView()
+ h.Buf.ClearCursors()
+ scrollmargin := int(h.Buf.S... | internal/action/actions.go | 26 | Go | 0.571 | suggestion | 310 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
VisualX: 0,
}))
return true
}
// CursorToViewCenter moves the cursor to the center of the view
func (h *BufPane) CursorToViewCenter() bool {
v := h.GetView()
h.Buf.ClearCursors()
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
SLoc: h.Scroll(v.StartLine, h.BufView().Height/2),
VisualX: 0,
}))
return true
... | And same problem here...
Once again, `bEnd.Line-lastLine.Line` may be less than `scrollmargin` yet span 10000 visual lines. | SLoc: h.Scroll(v.StartLine, scrollmargin),
VisualX: 0,
}))
return true
}
// CursorToViewCenter moves the cursor to the center of the view
func (h *BufPane) CursorToViewCenter() bool {
v := h.GetView()
h.Buf.ClearCursors()
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
SLoc: h.Scroll(v.StartLine, h.BufVi... | @@ -160,6 +160,52 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToViewTop moves the cursor to the top of the view,
+// offset by scrollmargin unless at the beginning or end of the file
+func (h *BufPane) CursorToViewTop() bool {
+ v := h.GetView()
+ h.Buf.ClearCursors()
+ scrollmargin := int(h.Buf.S... | internal/action/actions.go | 26 | Go | 0.5 | suggestion | 126 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), ... | It is the same condition as `v.StartLine == bStart` (the distance between two different visual lines cannot possibly be non-zero), so using `Diff()` is an overkill in this case. | return true
}
// ScrollDownAction scrolls the view up
func (h *BufPane) ScrollDownAction() bool {
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
return true
}
// Center centers the view on the cursor
func (h *BufPane) Center() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), ... | @@ -160,6 +160,53 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToViewTop moves the cursor to the top of the view,
+// offset by scrollmargin unless at the beginning or end of the file
+func (h *BufPane) CursorToViewTop() bool {
+ v := h.GetView()
+ h.Buf.ClearCursors()
+ scrollmargin := int(h.Buf.S... | internal/action/actions.go | 26 | Go | 0.5 | suggestion | 177 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
SLoc: h.Scroll(v.StartLine, scrollmargin),
VisualX: 0,
}))
return true
}
// CursorToViewCenter moves the cursor to the center of the view
func (h *BufPane) CursorToViewCenter() bool {
v := h.GetView()
h.Buf.ClearCursors()
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
SLoc: h.Scroll(v.StartLine, h.BufVi... | mega-nit: `height` is used just once in this function, so you could use `h.BufView().Height` directly instead. | SLoc: h.Scroll(v.StartLine, scrollmargin),
VisualX: 0,
}))
return true
}
// CursorToViewCenter moves the cursor to the center of the view
func (h *BufPane) CursorToViewCenter() bool {
v := h.GetView()
h.Buf.ClearCursors()
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
SLoc: h.Scroll(v.StartLine, h.BufVi... | @@ -160,6 +160,53 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToViewTop moves the cursor to the top of the view,
+// offset by scrollmargin unless at the beginning or end of the file
+func (h *BufPane) CursorToViewTop() bool {
+ v := h.GetView()
+ h.Buf.ClearCursors()
+ scrollmargin := int(h.Buf.S... | internal/action/actions.go | 26 | Go | 0.571 | suggestion | 110 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
func (h *BufPane) MoveCursorUp(n int) {
if !h.Buf.Settings["softwrap"].(bool) {
h.Cursor.UpN(n)
} else {
vloc := h.VLocFromLoc(h.Cursor.Loc)
sloc := h.Scroll(vloc.SLoc, -n)
if sloc == vloc.SLoc {
// we are at the beginning of buffer
h.Cursor.Loc = h.Buf.Start()
h.Cursor.StoreVisualX()
} else {
v... | Shouldn't we move here from the middle of the screen/view to the first line in the moment we're already at 50% of the first page and move one page up again....vice versa for the move to the bottom?
Just to be consistent with CursorToView{Top|Bottom}? | // offset by scrollmargin unless at the beginning or end of the file
func (h *BufPane) CursorToViewTop() bool {
v := h.GetView()
h.Buf.ClearCursors()
scrollmargin := int(h.Buf.Settings["scrollmargin"].(float64))
bStart := display.SLoc{0, 0}
if v.StartLine == bStart {
scrollmargin = 0
}
h.Cursor.GotoLoc(h.LocFr... | @@ -160,6 +160,52 @@ func (h *BufPane) Center() bool {
return true
}
+// CursorToViewTop moves the cursor to the top of the view,
+// offset by scrollmargin unless at the beginning or end of the file
+func (h *BufPane) CursorToViewTop() bool {
+ v := h.GetView()
+ h.Buf.ClearCursors()
+ scrollmargin := int(h.Buf.S... | internal/action/actions.go | 26 | Go | 0.5 | question | 251 | 51 | 51 | false | add actions CursorToViewTop, CursorToViewCenter, CursorToViewBottom | 3,506 | zyedidia/micro | 13,805 | Go | JoeKar | nimishjha |
log.Printf("semver.NewPRVersion(%s): %v", tagParts[1], err)
} else if len(tagParts) == 4 {
ahead, err := semver.NewPRVersion(tagParts[2])
if err == nil {
return tagParts[0] + "-" + tagParts[1], &ahead
}
log.Printf("semver.NewPRVersion(%s): %v", tagParts[2], err)
}
return string(tag), nil
}
}
... | ~~But doesn't that mean we've no `versionStr` right now?~~
I know we're coming from #3514 resp. https://github.com/termux/termux-packages/issues/21286.
Edit:
Got it...it hits when a release will be tagged later as `nightly` and this tag is checked out instead of e.g. `v2.0.14`.
Edit2:
Should work. I tried it w... | log.Printf("semver.NewPRVersion(%s): %v", tagParts[1], err)
} else if len(tagParts) == 4 {
ahead, err := semver.NewPRVersion(tagParts[2])
if err == nil {
return tagParts[0] + "-" + tagParts[1], &ahead
}
log.Printf("semver.NewPRVersion(%s): %v", tagParts[2], err)
}
return string(tag), nil
}
}
... | @@ -49,7 +49,7 @@ func main() {
}
// Get the tag of the current revision.
tag, _ := getTag("--exact-match")
- if tag == versionStr {
+ if tag == versionStr || ahead == nil { | tools/build-version.go | 26 | Go | 0.643 | suggestion | 372 | 51 | 51 | false | Set version as release when there are no commits ahead | 3,515 | zyedidia/micro | 13,805 | Go | JoeKar | niten94 |
h.MoveCursorUp(h.BufView().Height)
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
}
// SelectPageDown selects down one page
func (h *BufPane) SelectPageDown() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorDown(h.BufView().Height)
h.Cursor.SelectTo(h.Cur... | Why remove deselect? Try selecting text and pressing PageUp or PageDown and see what happens.
(The below `if h.Cursor.HasSelection()` block, on the other hand, indeed looks pointless, so it might be good to clean it away, in a separate change.) | return true
}
// SelectPageUp selects up one page
func (h *BufPane) SelectPageUp() bool {
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
scrollAmount := h.BufView().Height - pageOverlap
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorUp(scrollAmount)
h.Cursor.... | @@ -1696,31 +1696,26 @@ func (h *BufPane) SelectPageDown() bool {
return true
}
-// CursorPageUp places the cursor a page up
+// CursorPageUp scrolls the view up a page,
+// keeping the cursor at the same relative position in the view
func (h *BufPane) CursorPageUp() bool {
- h.Cursor.Deselect(true) | internal/action/actions.go | 26 | Go | 0.643 | question | 247 | 51 | 51 | false | implement nano-like page up/page down functionality | 3,518 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorUp(h.BufView().Height)
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
}
// SelectPageDown selects down one page
func (h *BufPane) SelectPageDown() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h... | I don't think we should remove multicursors. `CursorPageUp` and `CursorPageDown` are still some of the most basic cursor movement actions, so they should work with multiple cursors, like other cursor movement actions.
Moreover, try adding a multicursor and pressing PageUp or PageDown and see what happens.
I suppo... | pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
h.ScrollDown(h.BufView().Height - pageOverlap)
h.ScrollAdjust()
return true
}
// SelectPageUp selects up one page
func (h *BufPane) SelectPageUp() bool {
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
scrollAmount := h.BufView().Height - pa... | @@ -1696,31 +1696,26 @@ func (h *BufPane) SelectPageDown() bool {
return true
}
-// CursorPageUp places the cursor a page up
+// CursorPageUp scrolls the view up a page,
+// keeping the cursor at the same relative position in the view
func (h *BufPane) CursorPageUp() bool {
- h.Cursor.Deselect(true)
-
- if h.Curs... | internal/action/actions.go | 26 | Go | 0.857 | bug | 1,922 | 51 | 51 | false | implement nano-like page up/page down functionality | 3,518 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
return true
}
// SelectPageUp selects up one page
func (h *BufPane) SelectPageUp() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorUp(h.BufView().Height)
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
}
// SelectPageDown selects down one page
func (h *Buf... | This description emphasizes the "view" aspect so much that it forgets that first of all it is the cursor that moves (that is what these action do: they move the cursor a page up or down, right?), and the view moves as a result of that, not the other way around. | return true
}
// PageDown scrolls the view down a page
func (h *BufPane) PageDown() bool {
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
h.ScrollDown(h.BufView().Height - pageOverlap)
h.ScrollAdjust()
return true
}
// SelectPageUp selects up one page
func (h *BufPane) SelectPageUp() bool {
pageOve... | @@ -1696,31 +1696,26 @@ func (h *BufPane) SelectPageDown() bool {
return true
}
-// CursorPageUp places the cursor a page up
+// CursorPageUp scrolls the view up a page, | internal/action/actions.go | 26 | Go | 0.5 | suggestion | 261 | 51 | 51 | false | implement nano-like page up/page down functionality | 3,518 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
// SelectPageDown selects down one page
func (h *BufPane) SelectPageDown() bool {
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
scrollAmount := h.BufView().Height - pageOverlap
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorDown(scrollAmount)
h.Cursor.SelectT... | Just for for the sake of comprehensibility move this `h.MoveCursorUp(scrollAmount)` between `scrollAmount ` and `if h.Cursor.Num == 0 {`, since we move the cursor first and the view afterwards. | h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorUp(scrollAmount)
h.Cursor.SelectTo(h.Cursor.Loc)
if h.Cursor.Num == 0 {
h.ScrollUp(scrollAmount)
}
h.Relocate()
return true
}
// SelectPageDown selects down one page
func (h *BufPane) SelectPageDown() bool {
pageOverlap := int(h.Buf.Settings["pageoverl... | @@ -1676,50 +1676,58 @@ func (h *BufPane) PageDown() bool {
// SelectPageUp selects up one page
func (h *BufPane) SelectPageUp() bool {
+ pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
+ scrollAmount := h.BufView().Height - pageOverlap
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cu... | internal/action/actions.go | 26 | Go | 0.571 | refactor | 193 | 51 | 51 | false | implement nano-like page up/page down functionality | 3,518 | zyedidia/micro | 13,805 | Go | JoeKar | nimishjha |
// CursorPageUp places the cursor a page up,
// moving the view to keep cursor at the same relative position in the view
func (h *BufPane) CursorPageUp() bool {
h.Cursor.Deselect(true)
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
scrollAmount := h.BufView().Height - pageOverlap
if h.Cursor.Num == 0 ... | Like in `CursorPageUp()` between `scrollAmount` and `if h.Cursor.Num == 0 {`. | if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.MoveCursorDown(scrollAmount)
h.Cursor.SelectTo(h.Cursor.Loc)
if h.Cursor.Num == 0 {
h.ScrollDown(scrollAmount)
h.ScrollAdjust()
}
h.Relocate()
return true
}
// CursorPageUp places the cursor a page up,
// moving the view to keep c... | @@ -1676,50 +1676,58 @@ func (h *BufPane) PageDown() bool {
// SelectPageUp selects up one page
func (h *BufPane) SelectPageUp() bool {
+ pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
+ scrollAmount := h.BufView().Height - pageOverlap
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cu... | internal/action/actions.go | 26 | Go | 0.357 | suggestion | 77 | 51 | 51 | false | implement nano-like page up/page down functionality | 3,518 | zyedidia/micro | 13,805 | Go | JoeKar | nimishjha |
// PageUp scrolls the view up a page
func (h *BufPane) PageUp() bool {
h.ScrollUp(h.BufView().Height)
return true
}
// PageDown scrolls the view down a page
func (h *BufPane) PageDown() bool {
h.ScrollDown(h.BufView().Height)
h.ScrollAdjust()
return true
}
// SelectPageUp selects up one page
func (h *BufPane) S... | Just like in `CursorPageUp/Down`, it should be done for the first cursor only, right? Otherwise `SelectPageUp/Down` selects multiple pages instead of one. | func (h *BufPane) End() bool {
v := h.GetView()
v.StartLine = h.Scroll(h.SLocFromLoc(h.Buf.End()), -h.BufView().Height+1)
h.SetView(v)
return true
}
// PageUp scrolls the view up a page
func (h *BufPane) PageUp() bool {
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
h.ScrollUp(h.BufView().Height - p... | @@ -1676,50 +1676,58 @@ func (h *BufPane) PageDown() bool {
// SelectPageUp selects up one page
func (h *BufPane) SelectPageUp() bool {
+ pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
+ scrollAmount := h.BufView().Height - pageOverlap
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cu... | internal/action/actions.go | 26 | Go | 0.571 | suggestion | 154 | 51 | 51 | false | implement nano-like page up/page down functionality | 3,518 | zyedidia/micro | 13,805 | Go | dmaluka | nimishjha |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.