mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 23:05:40 -04:00
Add support for syntax headers and update tcell
This commit is contained in:
parent
c2e7fd34a7
commit
8663014bbe
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ tools/build-version
|
|||||||
tools/build-date
|
tools/build-date
|
||||||
tools/info-plist
|
tools/info-plist
|
||||||
tools/bindata
|
tools/bindata
|
||||||
|
*.hdr
|
||||||
|
5
Makefile
5
Makefile
@ -18,6 +18,9 @@ build:
|
|||||||
build-dbg:
|
build-dbg:
|
||||||
go build -mod=readonly -ldflags "-s -w $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
go build -mod=readonly -ldflags "-s -w $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||||
|
|
||||||
|
build-mod:
|
||||||
|
go build -ldflags "-s -w $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||||
|
|
||||||
# Builds micro after building the runtime and checking dependencies
|
# Builds micro after building the runtime and checking dependencies
|
||||||
build-all: runtime build
|
build-all: runtime build
|
||||||
|
|
||||||
@ -39,6 +42,7 @@ install-quick:
|
|||||||
# Builds the runtime
|
# Builds the runtime
|
||||||
runtime:
|
runtime:
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
|
go run runtime/syntax/make_headers.go runtime/syntax
|
||||||
go build -o tools/bindata ./tools/go-bindata
|
go build -o tools/bindata ./tools/go-bindata
|
||||||
tools/bindata -pkg config -nomemcopy -nometadata -o runtime.go runtime/...
|
tools/bindata -pkg config -nomemcopy -nometadata -o runtime.go runtime/...
|
||||||
mv runtime.go internal/config
|
mv runtime.go internal/config
|
||||||
@ -49,3 +53,4 @@ test:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f micro
|
rm -f micro
|
||||||
|
rm -f runtime/syntax/*.hdr
|
||||||
|
2
go.mod
2
go.mod
@ -16,7 +16,7 @@ require (
|
|||||||
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
|
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
|
||||||
github.com/zyedidia/poller v0.0.0-20170616160828-ab09682913b7 // indirect
|
github.com/zyedidia/poller v0.0.0-20170616160828-ab09682913b7 // indirect
|
||||||
github.com/zyedidia/pty v2.0.0+incompatible // indirect
|
github.com/zyedidia/pty v2.0.0+incompatible // indirect
|
||||||
github.com/zyedidia/tcell v0.0.0-20191227234059-2c574ec1b972
|
github.com/zyedidia/tcell v0.0.0-20191228235154-5b9bbc0d56c7
|
||||||
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415
|
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415
|
||||||
golang.org/x/text v0.3.2
|
golang.org/x/text v0.3.2
|
||||||
gopkg.in/yaml.v2 v2.2.7
|
gopkg.in/yaml.v2 v2.2.7
|
||||||
|
2
go.sum
2
go.sum
@ -48,6 +48,8 @@ github.com/zyedidia/tcell v0.0.0-20191219170756-59b50b23fa9b h1:cryFENlMxJJrkimV
|
|||||||
github.com/zyedidia/tcell v0.0.0-20191219170756-59b50b23fa9b/go.mod h1:yXgdp23+aW8OMENYVBvpKoeiBtjaVWJ9HhpPDu6LBfM=
|
github.com/zyedidia/tcell v0.0.0-20191219170756-59b50b23fa9b/go.mod h1:yXgdp23+aW8OMENYVBvpKoeiBtjaVWJ9HhpPDu6LBfM=
|
||||||
github.com/zyedidia/tcell v0.0.0-20191227234059-2c574ec1b972 h1:tqsPH3tvIF9LQMWQODln09mJEV1ZlwC1qc5dTplj+eI=
|
github.com/zyedidia/tcell v0.0.0-20191227234059-2c574ec1b972 h1:tqsPH3tvIF9LQMWQODln09mJEV1ZlwC1qc5dTplj+eI=
|
||||||
github.com/zyedidia/tcell v0.0.0-20191227234059-2c574ec1b972/go.mod h1:yXgdp23+aW8OMENYVBvpKoeiBtjaVWJ9HhpPDu6LBfM=
|
github.com/zyedidia/tcell v0.0.0-20191227234059-2c574ec1b972/go.mod h1:yXgdp23+aW8OMENYVBvpKoeiBtjaVWJ9HhpPDu6LBfM=
|
||||||
|
github.com/zyedidia/tcell v0.0.0-20191228235154-5b9bbc0d56c7 h1:Qw5255OIirY741L/Kt5KLitfzfhpk29x+A193zByTS0=
|
||||||
|
github.com/zyedidia/tcell v0.0.0-20191228235154-5b9bbc0d56c7/go.mod h1:yXgdp23+aW8OMENYVBvpKoeiBtjaVWJ9HhpPDu6LBfM=
|
||||||
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 h1:752dTQ5OatJ9M5ULK2+9lor+nzyZz+LYDo3WGngg3Rc=
|
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 h1:752dTQ5OatJ9M5ULK2+9lor+nzyZz+LYDo3WGngg3Rc=
|
||||||
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415/go.mod h1:8leT8G0Cm8NoJHdrrKHyR9MirWoF4YW7pZh06B6H+1E=
|
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415/go.mod h1:8leT8G0Cm8NoJHdrrKHyR9MirWoF4YW7pZh06B6H+1E=
|
||||||
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
@ -12,11 +12,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RTColorscheme = 0
|
RTColorscheme = 0
|
||||||
RTSyntax = 1
|
RTSyntax = 1
|
||||||
RTHelp = 2
|
RTHelp = 2
|
||||||
RTPlugin = 3
|
RTPlugin = 3
|
||||||
NumTypes = 4 // How many filetypes are there
|
RTSyntaxHeader = 4
|
||||||
|
NumTypes = 5 // How many filetypes are there
|
||||||
)
|
)
|
||||||
|
|
||||||
type RTFiletype byte
|
type RTFiletype byte
|
||||||
@ -135,6 +136,7 @@ func InitRuntimeFiles() {
|
|||||||
|
|
||||||
add(RTColorscheme, "colorschemes", "*.micro")
|
add(RTColorscheme, "colorschemes", "*.micro")
|
||||||
add(RTSyntax, "syntax", "*.yaml")
|
add(RTSyntax, "syntax", "*.yaml")
|
||||||
|
add(RTSyntaxHeader, "header", "*.hdr")
|
||||||
add(RTHelp, "help", "*.md")
|
add(RTHelp, "help", "*.md")
|
||||||
|
|
||||||
initlua := filepath.Join(ConfigDir, "init.lua")
|
initlua := filepath.Join(ConfigDir, "init.lua")
|
||||||
|
74
runtime/syntax/make_headers.go
Normal file
74
runtime/syntax/make_headers.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HeaderYaml struct {
|
||||||
|
FileType string `yaml:"filetype"`
|
||||||
|
Detect struct {
|
||||||
|
FNameRgx string `yaml:"filename"`
|
||||||
|
HeaderRgx string `yaml:"header"`
|
||||||
|
} `yaml:"detect"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Header struct {
|
||||||
|
FileType string
|
||||||
|
FNameRgx string
|
||||||
|
HeaderRgx string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
os.Chdir(os.Args[1])
|
||||||
|
}
|
||||||
|
files, _ := ioutil.ReadDir(".")
|
||||||
|
for _, f := range files {
|
||||||
|
fname := f.Name()
|
||||||
|
if strings.HasSuffix(fname, ".yaml") {
|
||||||
|
convert(fname[:len(fname)-5])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func convert(name string) {
|
||||||
|
filename := name + ".yaml"
|
||||||
|
var hdr HeaderYaml
|
||||||
|
source, err := ioutil.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
err = yaml.Unmarshal(source, &hdr)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
encode(name, hdr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(name string, c HeaderYaml) {
|
||||||
|
f, _ := os.Create(name + ".hdr")
|
||||||
|
f.WriteString(c.FileType + "\n")
|
||||||
|
f.WriteString(c.Detect.FNameRgx + "\n")
|
||||||
|
f.WriteString(c.Detect.HeaderRgx + "\n")
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func decode(name string) Header {
|
||||||
|
start := time.Now()
|
||||||
|
data, _ := ioutil.ReadFile(name + ".hdr")
|
||||||
|
strs := bytes.Split(data, []byte{'\n'})
|
||||||
|
var hdr Header
|
||||||
|
hdr.FileType = string(strs[0])
|
||||||
|
hdr.FNameRgx = string(strs[1])
|
||||||
|
hdr.HeaderRgx = string(strs[2])
|
||||||
|
fmt.Printf("took %v\n", time.Since(start))
|
||||||
|
|
||||||
|
return hdr
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user