Compare commits

...

7 Commits

Author SHA1 Message Date
Neko Box Coder
b43854c633
Merge 5dc41ce756 into 1539da7fdc 2024-09-16 23:11:23 +03:00
Oleksandr Redko
1539da7fdc
test: simplify cmd/micro tests (#3470) 2024-09-16 19:33:59 +02:00
Oleksandr Redko
a3211dce57
Build: set 1.17 as minimum supported Go version (#3461) 2024-09-16 19:21:43 +02:00
Neko Box Coder
5dc41ce756
Fixing old comment option error message being spammed 2024-08-24 18:10:13 +01:00
Neko Box Coder
7134d3f272
Rewording error message for old comment option 2024-08-22 21:46:42 +01:00
Neko Box Coder
b4920fb645
Added error message when using old comment option 2024-08-22 20:31:08 +01:00
Neko Box Coder
d40a952392
Updating comment plugin option and fixing comment option reset bug
Updating comment plugin option to be comment.type
Fixing unwanted comment option reset when switching buffers
2024-08-22 20:24:53 +01:00
8 changed files with 65 additions and 74 deletions

View File

@ -7,7 +7,7 @@ jobs:
nightly:
strategy:
matrix:
go-version: [1.19.x]
go-version: [1.23.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:

View File

@ -8,7 +8,7 @@ jobs:
release:
strategy:
matrix:
go-version: [1.19.x]
go-version: [1.23.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:

View File

@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.19.x]
go-version: [1.17.x, 1.23.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:

View File

@ -162,7 +162,7 @@ Without these tools installed, micro will use an internal clipboard for copy and
If your operating system does not have a binary release, but does run Go, you can build from source.
Make sure that you have Go version 1.16 or greater and Go modules are enabled.
Make sure that you have Go version 1.17 or greater and Go modules are enabled.
```
git clone https://github.com/zyedidia/micro

View File

@ -2,7 +2,6 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"testing"
@ -26,7 +25,7 @@ func init() {
func startup(args []string) (tcell.SimulationScreen, error) {
var err error
tempDir, err = ioutil.TempDir("", "micro_test")
tempDir, err = os.MkdirTemp("", "micro_test")
if err != nil {
return nil, err
}
@ -164,20 +163,22 @@ func findBuffer(file string) *buffer.Buffer {
return buf
}
func createTestFile(name string, content string) (string, error) {
testf, err := ioutil.TempFile("", name)
func createTestFile(t *testing.T, content string) string {
f, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
return "", err
t.Fatal(err)
}
defer func() {
if err := f.Close(); err != nil {
t.Fatal(err)
}
}()
if _, err := f.WriteString(content); err != nil {
t.Fatal(err)
}
if _, err := testf.Write([]byte(content)); err != nil {
return "", err
}
if err := testf.Close(); err != nil {
return "", err
}
return testf.Name(), nil
return f.Name()
}
func TestMain(m *testing.M) {
@ -194,18 +195,12 @@ func TestMain(m *testing.M) {
}
func TestSimpleEdit(t *testing.T) {
file, err := createTestFile("micro_simple_edit_test", "base content")
if err != nil {
t.Error(err)
return
}
defer os.Remove(file)
file := createTestFile(t, "base content")
openFile(file)
if findBuffer(file) == nil {
t.Errorf("Could not find buffer %s", file)
return
t.Fatalf("Could not find buffer %s", file)
}
injectKey(tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone)
@ -223,28 +218,21 @@ func TestSimpleEdit(t *testing.T) {
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
assert.Equal(t, "firstfoobar\nbase content\n", string(data))
}
func TestMouse(t *testing.T) {
file, err := createTestFile("micro_mouse_test", "base content")
if err != nil {
t.Error(err)
return
}
defer os.Remove(file)
file := createTestFile(t, "base content")
openFile(file)
if findBuffer(file) == nil {
t.Errorf("Could not find buffer %s", file)
return
t.Fatalf("Could not find buffer %s", file)
}
// buffer:
@ -275,10 +263,9 @@ func TestMouse(t *testing.T) {
// base content
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
assert.Equal(t, "firstline\nsecondline\nbase content\n", string(data))
@ -301,18 +288,12 @@ Ernleȝe test_string æðelen
`
func TestSearchAndReplace(t *testing.T) {
file, err := createTestFile("micro_search_replace_test", srTestStart)
if err != nil {
t.Error(err)
return
}
defer os.Remove(file)
file := createTestFile(t, srTestStart)
openFile(file)
if findBuffer(file) == nil {
t.Errorf("Could not find buffer %s", file)
return
t.Fatalf("Could not find buffer %s", file)
}
injectKey(tcell.KeyCtrlE, rune(tcell.KeyCtrlE), tcell.ModCtrl)
@ -321,10 +302,9 @@ func TestSearchAndReplace(t *testing.T) {
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
assert.Equal(t, srTest2, string(data))
@ -337,10 +317,9 @@ func TestSearchAndReplace(t *testing.T) {
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
data, err = ioutil.ReadFile(file)
data, err = os.ReadFile(file)
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
assert.Equal(t, srTest3, string(data))

16
go.mod
View File

@ -14,17 +14,29 @@ require (
github.com/zyedidia/clipper v0.1.1
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d
github.com/zyedidia/tcell/v2 v2.0.10 // indirect
github.com/zyedidia/tcell/v2 v2.0.10
github.com/zyedidia/terminal v0.0.0-20230315200948-4b3bcf6dddef
golang.org/x/text v0.3.8
gopkg.in/yaml.v2 v2.2.8
layeh.com/gopher-luar v1.0.7
)
require (
github.com/creack/pty v1.1.18 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
github.com/xo/terminfo v0.0.0-20200218205459-454e5b68f9e8 // indirect
github.com/zyedidia/poller v1.0.1 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
)
replace github.com/kballard/go-shellquote => github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655
replace github.com/mattn/go-runewidth => github.com/zyedidia/go-runewidth v0.0.12
replace layeh.com/gopher-luar => github.com/layeh/gopher-luar v1.0.7
go 1.16
go 1.17

8
go.sum
View File

@ -54,14 +54,6 @@ github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d h1:zmDMkh22zXOB7gz8
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d/go.mod h1:NDJSTTYWivnza6zkRapeX2/LwhKPEMQ7bJxqgDVT78I=
github.com/zyedidia/poller v1.0.1 h1:Tt9S3AxAjXwWGNiC2TUdRJkQDZSzCBNVQ4xXiQ7440s=
github.com/zyedidia/poller v1.0.1/go.mod h1:vZXJOHGDcuK08GXhF6IAY0ZFd2WcgOR5DOTp84Uk5eE=
github.com/zyedidia/tcell/v2 v2.0.9 h1:FxXRkE62N0GPHES7EMLtp2rteYqC9r1kVid8vJN1kOE=
github.com/zyedidia/tcell/v2 v2.0.9/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
github.com/zyedidia/tcell/v2 v2.0.10-0.20221007181625-f562052bccb8 h1:53ULv4mmLyQDnqbjVxanckP57WSreWHwTmlLJrJEutY=
github.com/zyedidia/tcell/v2 v2.0.10-0.20221007181625-f562052bccb8/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
github.com/zyedidia/tcell/v2 v2.0.10-0.20230320201625-54f6acdada4a h1:W4TWa++Wk6uRGxZoxr2nPX1TpIEl+Wxv0mTtocG4TYc=
github.com/zyedidia/tcell/v2 v2.0.10-0.20230320201625-54f6acdada4a/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
github.com/zyedidia/tcell/v2 v2.0.10-0.20230831153116-061c5b2c7260 h1:SCAmAacT5BxZsmOFdFy5zwwi6nj1MjA60gydjKdTgXo=
github.com/zyedidia/tcell/v2 v2.0.10-0.20230831153116-061c5b2c7260/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
github.com/zyedidia/tcell/v2 v2.0.10 h1:6fbbYAx/DYc9A//4jU1OeBrxtc9qJxYCZXCtGQbtTWU=
github.com/zyedidia/tcell/v2 v2.0.10/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
github.com/zyedidia/terminal v0.0.0-20230315200948-4b3bcf6dddef h1:LeB4Qs0Tss4r/Qh8pfsTTqagDYHysfKJLYzAH3MVfu0=

View File

@ -3,6 +3,7 @@ VERSION = "1.0.0"
local util = import("micro/util")
local config = import("micro/config")
local buffer = import("micro/buffer")
local micro = import("micro")
local ft = {}
@ -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 ft[buf.Settings["filetype"]] ~= nil then
buf:SetOptionNative("commenttype", ft[buf.Settings["filetype"]])
else
buf:SetOptionNative("commenttype", "# %s")
-- NOTE: Don't use SetOptionNative() to set "comment.type",
-- otherwise "comment.type" can't be reset by a "filetype" change.
if buf.Settings["comment.type"] == "" then
if buf.Settings["commenttype"] ~= nil then
micro.InfoBar():Error("\"commenttype\" option has been renamed to \"comment.type\"",
", please update your configuration")
end
last_ft = buf.Settings["filetype"]
if ft[buf.Settings["filetype"]] ~= nil then
buf.Settings["comment.type"] = ft[buf.Settings["filetype"]]
else
buf.Settings["comment.type"] = "# %s"
end
end
end
@ -88,7 +92,7 @@ function commentLine(bp, lineN, indentLen)
updateCommentType(bp.Buf)
local line = bp.Buf:Line(lineN)
local commentType = bp.Buf.Settings["commenttype"]
local commentType = bp.Buf.Settings["comment.type"]
local sel = -bp.Cursor.CurSelection
local curpos = -bp.Cursor.Loc
local index = string.find(commentType, "%%s") - 1
@ -114,7 +118,7 @@ function uncommentLine(bp, lineN, commentRegex)
updateCommentType(bp.Buf)
local line = bp.Buf:Line(lineN)
local commentType = bp.Buf.Settings["commenttype"]
local commentType = bp.Buf.Settings["comment.type"]
local sel = -bp.Cursor.CurSelection
local curpos = -bp.Cursor.Loc
local index = string.find(commentType, "%%s") - 1
@ -178,7 +182,7 @@ end
function comment(bp, args)
updateCommentType(bp.Buf)
local commentType = bp.Buf.Settings["commenttype"]
local commentType = bp.Buf.Settings["comment.type"]
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)")
if bp.Cursor:HasSelection() then
@ -204,6 +208,10 @@ function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
function preinit()
config.RegisterCommonOption("comment", "type", "")
end
function init()
config.MakeCommand("comment", comment, config.NoComplete)
config.TryBindKey("Alt-/", "lua:comment.comment", false)