mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 22:57:15 +09:00
Compare commits
141 Commits
v1.2.0
...
better-lua
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0c0747a09 | ||
|
|
64d574c35c | ||
|
|
4e531c2d1e | ||
|
|
ee8fa60bc5 | ||
|
|
e40ff56e07 | ||
|
|
0c1db1e813 | ||
|
|
a9b14d4c1b | ||
|
|
69f77ee2f1 | ||
|
|
3b5b9bbb21 | ||
|
|
65b5d6c5a9 | ||
|
|
1a575bc9ae | ||
|
|
ab242c5b17 | ||
|
|
90977fb4e1 | ||
|
|
404e5d206d | ||
|
|
d41a255361 | ||
|
|
efff850e54 | ||
|
|
4fcdde4149 | ||
|
|
c4d8b9e7fb | ||
|
|
68526dc119 | ||
|
|
4f2fc096e5 | ||
|
|
0f62ef687c | ||
|
|
32eb1135ed | ||
|
|
f88b4a6d57 | ||
|
|
9628b73525 | ||
|
|
d70a48bd13 | ||
|
|
660f1e181a | ||
|
|
773284369b | ||
|
|
f199c15269 | ||
|
|
47e612afef | ||
|
|
921f88b95d | ||
|
|
7fe8d73473 | ||
|
|
fcb09556b1 | ||
|
|
69c6d8a099 | ||
|
|
dd5afc0560 | ||
|
|
471486b531 | ||
|
|
202cfb574c | ||
|
|
ebb0976866 | ||
|
|
5c785ab1ac | ||
|
|
2024b8b2c2 | ||
|
|
86c695ca52 | ||
|
|
9dd1df36d5 | ||
|
|
27f99b6309 | ||
|
|
ed9bc66060 | ||
|
|
d1598bb754 | ||
|
|
cc5855d07b | ||
|
|
487b36f48f | ||
|
|
c0b00c9a4c | ||
|
|
86c2ac95bb | ||
|
|
edb79f2972 | ||
|
|
305cefe461 | ||
|
|
315391b0aa | ||
|
|
fd45acc910 | ||
|
|
a574ae6b6a | ||
|
|
fa56a477c2 | ||
|
|
0db4556efb | ||
|
|
fad95c028a | ||
|
|
5c462f5600 | ||
|
|
5dcc486214 | ||
|
|
9d2915c328 | ||
|
|
4f8f6f1ca3 | ||
|
|
fbf58486fb | ||
|
|
97aae225da | ||
|
|
1ca2debd7c | ||
|
|
c1584dd72f | ||
|
|
2bbd29998e | ||
|
|
3b2d7abe3d | ||
|
|
994d1acbfc | ||
|
|
1f4ae1e2d5 | ||
|
|
18ad74a982 | ||
|
|
4cad06c7b3 | ||
|
|
ec77dccb1d | ||
|
|
63b4848bb0 | ||
|
|
e27802c41e | ||
|
|
75329830f9 | ||
|
|
030a05c103 | ||
|
|
e4751fd84c | ||
|
|
252def5b95 | ||
|
|
42f2af7956 | ||
|
|
91fb8225d1 | ||
|
|
bee60023ae | ||
|
|
0ffae1896b | ||
|
|
8f4820ba28 | ||
|
|
3a02ad8664 | ||
|
|
244e0ded60 | ||
|
|
19926d95fe | ||
|
|
f27ee60149 | ||
|
|
3908813afe | ||
|
|
e6f24b0924 | ||
|
|
b2c1c8f8db | ||
|
|
5a2f9a374b | ||
|
|
59ab5107bf | ||
|
|
06c65d8404 | ||
|
|
d38055f825 | ||
|
|
4aeb4c78ac | ||
|
|
3741a71cc5 | ||
|
|
fc9ddaf941 | ||
|
|
1f6a9cfa46 | ||
|
|
1a18fad1a4 | ||
|
|
39b5c4746e | ||
|
|
5ec08d0a29 | ||
|
|
7ec222895c | ||
|
|
da1ec3132f | ||
|
|
167f1e5770 | ||
|
|
8719b9d75c | ||
|
|
af1f161b06 | ||
|
|
7e4ff05c57 | ||
|
|
f1ecd37578 | ||
|
|
7ccec0e3f7 | ||
|
|
397361f23d | ||
|
|
681da2e90c | ||
|
|
118e6b1804 | ||
|
|
f933b90c66 | ||
|
|
21840d3ffe | ||
|
|
5e80ab9362 | ||
|
|
43eb238b08 | ||
|
|
00718f99cf | ||
|
|
c3a73d63b8 | ||
|
|
bc3c8eaf74 | ||
|
|
8d268ef021 | ||
|
|
c45ff4dd4f | ||
|
|
37ad137012 | ||
|
|
0165c4a40a | ||
|
|
3270acdd00 | ||
|
|
ee84296dfe | ||
|
|
42849e7104 | ||
|
|
a1f6dd6f4f | ||
|
|
47cdfb3de0 | ||
|
|
ac362bf1db | ||
|
|
462f73f695 | ||
|
|
cf92f91e1e | ||
|
|
52d6ac6cda | ||
|
|
eeb2aaf9ae | ||
|
|
f84c9f3b5d | ||
|
|
be56918174 | ||
|
|
08daaf95e4 | ||
|
|
51d73c6618 | ||
|
|
4644a2b5cc | ||
|
|
89863660ba | ||
|
|
641d188997 | ||
|
|
226932e631 | ||
|
|
480a220fda |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.DS_Store
|
||||
|
||||
micro
|
||||
!cmd/micro
|
||||
binaries/
|
||||
|
||||
57
.gitmodules
vendored
Normal file
57
.gitmodules
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
[submodule "cmd/micro/vendor/github.com/blang/semver"]
|
||||
path = cmd/micro/vendor/github.com/blang/semver
|
||||
url = https://github.com/blang/semver
|
||||
[submodule "cmd/micro/vendor/github.com/dustin/go-humanize"]
|
||||
path = cmd/micro/vendor/github.com/dustin/go-humanize
|
||||
url = https://github.com/dustin/go-humanize
|
||||
[submodule "cmd/micro/vendor/github.com/go-errors/errors"]
|
||||
path = cmd/micro/vendor/github.com/go-errors/errors
|
||||
url = https://github.com/go-errors/errors
|
||||
[submodule "cmd/micro/vendor/github.com/mattn/go-isatty"]
|
||||
path = cmd/micro/vendor/github.com/mattn/go-isatty
|
||||
url = https://github.com/mattn/go-isatty
|
||||
[submodule "cmd/micro/vendor/github.com/mattn/go-runewidth"]
|
||||
path = cmd/micro/vendor/github.com/mattn/go-runewidth
|
||||
url = https://github.com/mattn/go-runewidth
|
||||
[submodule "cmd/micro/vendor/github.com/mitchellh/go-homedir"]
|
||||
path = cmd/micro/vendor/github.com/mitchellh/go-homedir
|
||||
url = https://github.com/mitchellh/go-homedir
|
||||
[submodule "cmd/micro/vendor/github.com/sergi/go-diff"]
|
||||
path = cmd/micro/vendor/github.com/sergi/go-diff
|
||||
url = https://github.com/sergi/go-diff
|
||||
[submodule "cmd/micro/vendor/github.com/yuin/gopher-lua"]
|
||||
path = cmd/micro/vendor/github.com/yuin/gopher-lua
|
||||
url = https://github.com/yuin/gopher-lua
|
||||
[submodule "cmd/micro/vendor/golang.org/x/net"]
|
||||
path = cmd/micro/vendor/golang.org/x/net
|
||||
url = https://go.googlesource.com/net
|
||||
[submodule "cmd/micro/vendor/github.com/zyedidia/clipboard"]
|
||||
path = cmd/micro/vendor/github.com/zyedidia/clipboard
|
||||
url = https://github.com/zyedidia/clipboard
|
||||
[submodule "cmd/micro/vendor/github.com/zyedidia/glob"]
|
||||
path = cmd/micro/vendor/github.com/zyedidia/glob
|
||||
url = https://github.com/zyedidia/glob
|
||||
[submodule "cmd/micro/vendor/github.com/zyedidia/tcell"]
|
||||
path = cmd/micro/vendor/github.com/zyedidia/tcell
|
||||
url = https://github.com/zyedidia/tcell
|
||||
[submodule "cmd/micro/vendor/github.com/gdamore/encoding"]
|
||||
path = cmd/micro/vendor/github.com/gdamore/encoding
|
||||
url = https://github.com/gdamore/encoding
|
||||
[submodule "cmd/micro/vendor/golang.org/x/text"]
|
||||
path = cmd/micro/vendor/golang.org/x/text
|
||||
url = https://go.googlesource.com/text
|
||||
[submodule "cmd/micro/vendor/github.com/lucasb-eyer/go-colorful"]
|
||||
path = cmd/micro/vendor/github.com/lucasb-eyer/go-colorful
|
||||
url = https://github.com/lucasb-eyer/go-colorful
|
||||
[submodule "cmd/micro/vendor/layeh.com/gopher-luar"]
|
||||
path = cmd/micro/vendor/layeh.com/gopher-luar
|
||||
url = https://github.com/layeh/gopher-luar
|
||||
[submodule "cmd/micro/vendor/gopkg.in/yaml.v2"]
|
||||
path = cmd/micro/vendor/gopkg.in/yaml.v2
|
||||
url = https://gopkg.in/yaml.v2
|
||||
[submodule "cmd/micro/vendor/github.com/zyedidia/poller"]
|
||||
path = cmd/micro/vendor/github.com/zyedidia/poller
|
||||
url = https://github.com/zyedidia/poller
|
||||
[submodule "cmd/micro/vendor/github.com/flynn/json5"]
|
||||
path = cmd/micro/vendor/github.com/flynn/json5
|
||||
url = https://github.com/flynn/json5
|
||||
4
LICENSE
4
LICENSE
@@ -1,6 +1,6 @@
|
||||
Micro is licensed under the MIT "Expat" License:
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016: Zachary Yedidia, et al.
|
||||
Copyright (c) 2016-2017: Zachary Yedidia, et al.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1106,3 +1106,61 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
||||
|
||||
github.com/flynn/json5/LICENSE
|
||||
================
|
||||
|
||||
Decoder code based on package encoding/json from the Go language.
|
||||
|
||||
Copyright (c) 2012 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
|
||||
Test data based on the parse cases from https://github.com/json5/json5
|
||||
|
||||
Copyright (c) 2012-2016 Aseem Kishore, and others.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
11
Makefile
11
Makefile
@@ -11,7 +11,7 @@ ADDITIONAL_GO_LINKER_FLAGS := $(shell GOOS=$(shell go env GOHOSTOS) \
|
||||
GOBIN ?= $(shell go env GOPATH)/bin
|
||||
|
||||
# Builds micro after checking dependencies but without updating the runtime
|
||||
build: deps
|
||||
build: update
|
||||
go build -ldflags "-s -w -X main.Version=$(VERSION) -X main.CommitHash=$(HASH) -X 'main.CompileDate=$(DATE)' $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
|
||||
# Builds micro after building the runtime and checking dependencies
|
||||
@@ -22,7 +22,7 @@ build-quick:
|
||||
go build -ldflags "-s -w -X main.Version=$(VERSION) -X main.CommitHash=$(HASH) -X 'main.CompileDate=$(DATE)' $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
|
||||
# Same as 'build' but installs to $GOBIN afterward
|
||||
install: deps
|
||||
install: update
|
||||
go install -ldflags "-s -w -X main.Version=$(VERSION) -X main.CommitHash=$(HASH) -X 'main.CompileDate=$(DATE)' $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
|
||||
# Same as 'build-all' but installs to $GOBIN afterward
|
||||
@@ -32,13 +32,9 @@ install-all: runtime install
|
||||
install-quick:
|
||||
go install -ldflags "-s -w -X main.Version=$(VERSION) -X main.CommitHash=$(HASH) -X 'main.CompileDate=$(DATE)' $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
|
||||
# Checks for dependencies
|
||||
deps:
|
||||
go get -d ./cmd/micro
|
||||
|
||||
update:
|
||||
git pull
|
||||
go get -u -d ./cmd/micro
|
||||
git submodule update --init
|
||||
|
||||
# Builds the runtime
|
||||
runtime:
|
||||
@@ -47,7 +43,6 @@ runtime:
|
||||
mv runtime.go cmd/micro
|
||||
|
||||
test:
|
||||
go get -d ./cmd/micro
|
||||
go test ./cmd/micro
|
||||
|
||||
clean:
|
||||
|
||||
20
README.md
20
README.md
@@ -4,6 +4,7 @@
|
||||
[](https://goreportcard.com/report/github.com/zyedidia/micro)
|
||||
[](https://gitter.im/zyedidia/micro?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://github.com/zyedidia/micro/blob/master/LICENSE)
|
||||
[](https://build.snapcraft.io/user/zyedidia/micro)
|
||||
|
||||
Micro is a terminal-based text editor that aims to be easy to use and intuitive, while also taking advantage of the full capabilities
|
||||
of modern terminals. It comes as one single, batteries-included, static binary with no dependencies, and you can download and use it right now.
|
||||
@@ -23,6 +24,7 @@ You can also check out the website for Micro at https://micro-editor.github.io.
|
||||
|
||||
* Easy to use and to install
|
||||
* No dependencies or external files are needed -- just the binary you can download further down the page
|
||||
* Multiple cursors
|
||||
* Common keybindings (ctrl-s, ctrl-c, ctrl-v, ctrl-z...)
|
||||
* Keybindings can be rebound to your liking
|
||||
* Sane defaults
|
||||
@@ -75,16 +77,22 @@ You can install micro using Homebrew on Mac:
|
||||
brew install micro
|
||||
```
|
||||
|
||||
On Windows, you can install micro through Chocolatey:
|
||||
On Windows, you can install micro through [Chocolatey](https://chocolatey.org/) or [Scoop](https://github.com/lukesampson/scoop):
|
||||
|
||||
```
|
||||
choco install micro
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
scoop install micro
|
||||
```
|
||||
|
||||
On Linux, you can install micro through [snap](https://snapcraft.io/docs/core/install)
|
||||
|
||||
```
|
||||
snap install micro --beta
|
||||
snap install micro --edge --classic
|
||||
```
|
||||
|
||||
### Building from source
|
||||
@@ -94,13 +102,15 @@ If your operating system does not have a binary release, but does run Go, you ca
|
||||
Make sure that you have Go version 1.5 or greater (Go 1.4 will work if your version supports CGO) and that your `GOPATH` env variable is set (I recommand setting it to `~/go` if you don't have one).
|
||||
|
||||
```
|
||||
go get -d github.com/zyedidia/micro/...
|
||||
go get -d github.com/zyedidia/micro/cmd/micro
|
||||
cd $GOPATH/src/github.com/zyedidia/micro
|
||||
make install
|
||||
```
|
||||
|
||||
The binary will then be installed to `$GOPATH/bin` (or your `$GOBIN`).
|
||||
|
||||
Please make sure that when you are working with micro's code, you are working on your `GOPATH`.
|
||||
|
||||
You can install directly with `go get` (`go get -u github.com/zyedidia/micro/cmd/micro`) but this isn't recommended because it doesn't build micro with version information which is useful for the plugin manager.
|
||||
|
||||
### MacOS terminal
|
||||
@@ -133,11 +143,11 @@ that micro's default colorscheme won't look very good. You can either set
|
||||
the colorscheme to `simple`, or download a better terminal emulator, like
|
||||
mintty.
|
||||
|
||||
### Plan9, NaCl, Cygwin
|
||||
### Plan9, Cygwin
|
||||
|
||||
Please note that micro uses the amazing [tcell library](https://github.com/gdamore/tcell), but this
|
||||
means that micro is restricted to the platforms tcell supports. As a result, micro does not support
|
||||
Plan9, NaCl, and Cygwin (although this may change in the future).
|
||||
Plan9, and Cygwin (although this may change in the future). Micro also doesn't support NaCl (but NaCl is deprecated anyways).
|
||||
|
||||
# Usage
|
||||
|
||||
|
||||
1067
cmd/micro/actions.go
1067
cmd/micro/actions.go
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
// +build !linux
|
||||
// +build android plan9 nacl windows
|
||||
|
||||
package main
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build linux darwin dragonfly solaris openbsd netbsd freebsd
|
||||
|
||||
package main
|
||||
|
||||
import "syscall"
|
||||
@@ -19,8 +21,7 @@ func (v *View) Suspend(usePlugin bool) bool {
|
||||
|
||||
// suspend the process
|
||||
pid := syscall.Getpid()
|
||||
tid := syscall.Gettid()
|
||||
err := syscall.Tgkill(pid, tid, syscall.SIGSTOP)
|
||||
err := syscall.Kill(pid, syscall.SIGSTOP)
|
||||
if err != nil {
|
||||
TermMessage(err)
|
||||
}
|
||||
@@ -5,97 +5,119 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/zyedidia/json5/encoding/json5"
|
||||
"github.com/flynn/json5"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
var bindings map[Key][]func(*View, bool) bool
|
||||
var mouseBindings map[Key][]func(*View, bool, *tcell.EventMouse) bool
|
||||
var helpBinding string
|
||||
|
||||
var mouseBindingActions = map[string]func(*View, bool, *tcell.EventMouse) bool{
|
||||
"MousePress": (*View).MousePress,
|
||||
"MouseMultiCursor": (*View).MouseMultiCursor,
|
||||
}
|
||||
|
||||
var bindingActions = map[string]func(*View, bool) bool{
|
||||
"CursorUp": (*View).CursorUp,
|
||||
"CursorDown": (*View).CursorDown,
|
||||
"CursorPageUp": (*View).CursorPageUp,
|
||||
"CursorPageDown": (*View).CursorPageDown,
|
||||
"CursorLeft": (*View).CursorLeft,
|
||||
"CursorRight": (*View).CursorRight,
|
||||
"CursorStart": (*View).CursorStart,
|
||||
"CursorEnd": (*View).CursorEnd,
|
||||
"SelectToStart": (*View).SelectToStart,
|
||||
"SelectToEnd": (*View).SelectToEnd,
|
||||
"SelectUp": (*View).SelectUp,
|
||||
"SelectDown": (*View).SelectDown,
|
||||
"SelectLeft": (*View).SelectLeft,
|
||||
"SelectRight": (*View).SelectRight,
|
||||
"WordRight": (*View).WordRight,
|
||||
"WordLeft": (*View).WordLeft,
|
||||
"SelectWordRight": (*View).SelectWordRight,
|
||||
"SelectWordLeft": (*View).SelectWordLeft,
|
||||
"DeleteWordRight": (*View).DeleteWordRight,
|
||||
"DeleteWordLeft": (*View).DeleteWordLeft,
|
||||
"SelectToStartOfLine": (*View).SelectToStartOfLine,
|
||||
"SelectToEndOfLine": (*View).SelectToEndOfLine,
|
||||
"InsertNewline": (*View).InsertNewline,
|
||||
"InsertSpace": (*View).InsertSpace,
|
||||
"Backspace": (*View).Backspace,
|
||||
"Delete": (*View).Delete,
|
||||
"InsertTab": (*View).InsertTab,
|
||||
"Save": (*View).Save,
|
||||
"SaveAll": (*View).SaveAll,
|
||||
"SaveAs": (*View).SaveAs,
|
||||
"Find": (*View).Find,
|
||||
"FindNext": (*View).FindNext,
|
||||
"FindPrevious": (*View).FindPrevious,
|
||||
"Center": (*View).Center,
|
||||
"Undo": (*View).Undo,
|
||||
"Redo": (*View).Redo,
|
||||
"Copy": (*View).Copy,
|
||||
"Cut": (*View).Cut,
|
||||
"CutLine": (*View).CutLine,
|
||||
"DuplicateLine": (*View).DuplicateLine,
|
||||
"DeleteLine": (*View).DeleteLine,
|
||||
"MoveLinesUp": (*View).MoveLinesUp,
|
||||
"MoveLinesDown": (*View).MoveLinesDown,
|
||||
"IndentSelection": (*View).IndentSelection,
|
||||
"OutdentSelection": (*View).OutdentSelection,
|
||||
"OutdentLine": (*View).OutdentLine,
|
||||
"Paste": (*View).Paste,
|
||||
"PastePrimary": (*View).PastePrimary,
|
||||
"SelectAll": (*View).SelectAll,
|
||||
"OpenFile": (*View).OpenFile,
|
||||
"Start": (*View).Start,
|
||||
"End": (*View).End,
|
||||
"PageUp": (*View).PageUp,
|
||||
"PageDown": (*View).PageDown,
|
||||
"HalfPageUp": (*View).HalfPageUp,
|
||||
"HalfPageDown": (*View).HalfPageDown,
|
||||
"StartOfLine": (*View).StartOfLine,
|
||||
"EndOfLine": (*View).EndOfLine,
|
||||
"ToggleHelp": (*View).ToggleHelp,
|
||||
"ToggleRuler": (*View).ToggleRuler,
|
||||
"JumpLine": (*View).JumpLine,
|
||||
"ClearStatus": (*View).ClearStatus,
|
||||
"ShellMode": (*View).ShellMode,
|
||||
"CommandMode": (*View).CommandMode,
|
||||
"Escape": (*View).Escape,
|
||||
"Quit": (*View).Quit,
|
||||
"QuitAll": (*View).QuitAll,
|
||||
"AddTab": (*View).AddTab,
|
||||
"PreviousTab": (*View).PreviousTab,
|
||||
"NextTab": (*View).NextTab,
|
||||
"NextSplit": (*View).NextSplit,
|
||||
"PreviousSplit": (*View).PreviousSplit,
|
||||
"Unsplit": (*View).Unsplit,
|
||||
"VSplit": (*View).VSplitBinding,
|
||||
"HSplit": (*View).HSplitBinding,
|
||||
"ToggleMacro": (*View).ToggleMacro,
|
||||
"PlayMacro": (*View).PlayMacro,
|
||||
"Suspend": (*View).Suspend,
|
||||
"CursorUp": (*View).CursorUp,
|
||||
"CursorDown": (*View).CursorDown,
|
||||
"CursorPageUp": (*View).CursorPageUp,
|
||||
"CursorPageDown": (*View).CursorPageDown,
|
||||
"CursorLeft": (*View).CursorLeft,
|
||||
"CursorRight": (*View).CursorRight,
|
||||
"CursorStart": (*View).CursorStart,
|
||||
"CursorEnd": (*View).CursorEnd,
|
||||
"SelectToStart": (*View).SelectToStart,
|
||||
"SelectToEnd": (*View).SelectToEnd,
|
||||
"SelectUp": (*View).SelectUp,
|
||||
"SelectDown": (*View).SelectDown,
|
||||
"SelectLeft": (*View).SelectLeft,
|
||||
"SelectRight": (*View).SelectRight,
|
||||
"WordRight": (*View).WordRight,
|
||||
"WordLeft": (*View).WordLeft,
|
||||
"SelectWordRight": (*View).SelectWordRight,
|
||||
"SelectWordLeft": (*View).SelectWordLeft,
|
||||
"DeleteWordRight": (*View).DeleteWordRight,
|
||||
"DeleteWordLeft": (*View).DeleteWordLeft,
|
||||
"SelectToStartOfLine": (*View).SelectToStartOfLine,
|
||||
"SelectToEndOfLine": (*View).SelectToEndOfLine,
|
||||
"InsertNewline": (*View).InsertNewline,
|
||||
"InsertSpace": (*View).InsertSpace,
|
||||
"Backspace": (*View).Backspace,
|
||||
"Delete": (*View).Delete,
|
||||
"InsertTab": (*View).InsertTab,
|
||||
"Save": (*View).Save,
|
||||
"SaveAll": (*View).SaveAll,
|
||||
"SaveAs": (*View).SaveAs,
|
||||
"Find": (*View).Find,
|
||||
"FindNext": (*View).FindNext,
|
||||
"FindPrevious": (*View).FindPrevious,
|
||||
"Center": (*View).Center,
|
||||
"Undo": (*View).Undo,
|
||||
"Redo": (*View).Redo,
|
||||
"Copy": (*View).Copy,
|
||||
"Cut": (*View).Cut,
|
||||
"CutLine": (*View).CutLine,
|
||||
"DuplicateLine": (*View).DuplicateLine,
|
||||
"DeleteLine": (*View).DeleteLine,
|
||||
"MoveLinesUp": (*View).MoveLinesUp,
|
||||
"MoveLinesDown": (*View).MoveLinesDown,
|
||||
"IndentSelection": (*View).IndentSelection,
|
||||
"OutdentSelection": (*View).OutdentSelection,
|
||||
"OutdentLine": (*View).OutdentLine,
|
||||
"Paste": (*View).Paste,
|
||||
"PastePrimary": (*View).PastePrimary,
|
||||
"SelectAll": (*View).SelectAll,
|
||||
"OpenFile": (*View).OpenFile,
|
||||
"Start": (*View).Start,
|
||||
"End": (*View).End,
|
||||
"PageUp": (*View).PageUp,
|
||||
"PageDown": (*View).PageDown,
|
||||
"HalfPageUp": (*View).HalfPageUp,
|
||||
"HalfPageDown": (*View).HalfPageDown,
|
||||
"StartOfLine": (*View).StartOfLine,
|
||||
"EndOfLine": (*View).EndOfLine,
|
||||
"ToggleHelp": (*View).ToggleHelp,
|
||||
"ToggleRuler": (*View).ToggleRuler,
|
||||
"JumpLine": (*View).JumpLine,
|
||||
"ClearStatus": (*View).ClearStatus,
|
||||
"ShellMode": (*View).ShellMode,
|
||||
"CommandMode": (*View).CommandMode,
|
||||
"Escape": (*View).Escape,
|
||||
"Quit": (*View).Quit,
|
||||
"QuitAll": (*View).QuitAll,
|
||||
"AddTab": (*View).AddTab,
|
||||
"PreviousTab": (*View).PreviousTab,
|
||||
"NextTab": (*View).NextTab,
|
||||
"NextSplit": (*View).NextSplit,
|
||||
"PreviousSplit": (*View).PreviousSplit,
|
||||
"Unsplit": (*View).Unsplit,
|
||||
"VSplit": (*View).VSplitBinding,
|
||||
"HSplit": (*View).HSplitBinding,
|
||||
"ToggleMacro": (*View).ToggleMacro,
|
||||
"PlayMacro": (*View).PlayMacro,
|
||||
"Suspend": (*View).Suspend,
|
||||
"ScrollUp": (*View).ScrollUpAction,
|
||||
"ScrollDown": (*View).ScrollDownAction,
|
||||
"SpawnMultiCursor": (*View).SpawnMultiCursor,
|
||||
"RemoveMultiCursor": (*View).RemoveMultiCursor,
|
||||
"RemoveAllMultiCursors": (*View).RemoveAllMultiCursors,
|
||||
"SkipMultiCursor": (*View).SkipMultiCursor,
|
||||
|
||||
// This was changed to InsertNewline but I don't want to break backwards compatibility
|
||||
"InsertEnter": (*View).InsertNewline,
|
||||
}
|
||||
|
||||
var bindingMouse = map[string]tcell.ButtonMask{
|
||||
"MouseLeft": tcell.Button1,
|
||||
"MouseMiddle": tcell.Button2,
|
||||
"MouseRight": tcell.Button3,
|
||||
"MouseWheelUp": tcell.WheelUp,
|
||||
"MouseWheelDown": tcell.WheelDown,
|
||||
"MouseWheelLeft": tcell.WheelLeft,
|
||||
"MouseWheelRight": tcell.WheelRight,
|
||||
}
|
||||
|
||||
var bindingKeys = map[string]tcell.Key{
|
||||
"Up": tcell.KeyUp,
|
||||
"Down": tcell.KeyDown,
|
||||
@@ -215,6 +237,8 @@ var bindingKeys = map[string]tcell.Key{
|
||||
"CtrlRightSq": tcell.KeyCtrlRightSq,
|
||||
"CtrlCarat": tcell.KeyCtrlCarat,
|
||||
"CtrlUnderscore": tcell.KeyCtrlUnderscore,
|
||||
"CtrlPageUp": tcell.KeyCtrlPgUp,
|
||||
"CtrlPageDown": tcell.KeyCtrlPgDn,
|
||||
"Tab": tcell.KeyTab,
|
||||
"Esc": tcell.KeyEsc,
|
||||
"Escape": tcell.KeyEscape,
|
||||
@@ -230,12 +254,14 @@ var bindingKeys = map[string]tcell.Key{
|
||||
type Key struct {
|
||||
keyCode tcell.Key
|
||||
modifiers tcell.ModMask
|
||||
buttons tcell.ButtonMask
|
||||
r rune
|
||||
}
|
||||
|
||||
// InitBindings initializes the keybindings for micro
|
||||
func InitBindings() {
|
||||
bindings = make(map[Key][]func(*View, bool) bool)
|
||||
mouseBindings = make(map[Key][]func(*View, bool, *tcell.EventMouse) bool)
|
||||
|
||||
var parsed map[string]string
|
||||
defaults := DefaultBindings()
|
||||
@@ -301,6 +327,7 @@ modSearch:
|
||||
return Key{
|
||||
keyCode: code,
|
||||
modifiers: modifiers,
|
||||
buttons: -1,
|
||||
r: 0,
|
||||
}, true
|
||||
}
|
||||
@@ -311,6 +338,16 @@ modSearch:
|
||||
return Key{
|
||||
keyCode: code,
|
||||
modifiers: modifiers,
|
||||
buttons: -1,
|
||||
r: 0,
|
||||
}, true
|
||||
}
|
||||
|
||||
// See if we can find the key in bindingMouse
|
||||
if code, ok := bindingMouse[k]; ok {
|
||||
return Key{
|
||||
modifiers: modifiers,
|
||||
buttons: code,
|
||||
r: 0,
|
||||
}, true
|
||||
}
|
||||
@@ -320,12 +357,13 @@ modSearch:
|
||||
return Key{
|
||||
keyCode: tcell.KeyRune,
|
||||
modifiers: modifiers,
|
||||
buttons: -1,
|
||||
r: rune(k[0]),
|
||||
}, true
|
||||
}
|
||||
|
||||
// We don't know what happened.
|
||||
return Key{}, false
|
||||
return Key{buttons: -1}, false
|
||||
}
|
||||
|
||||
// findAction will find 'action' using string 'v'
|
||||
@@ -339,6 +377,16 @@ func findAction(v string) (action func(*View, bool) bool) {
|
||||
return action
|
||||
}
|
||||
|
||||
func findMouseAction(v string) func(*View, bool, *tcell.EventMouse) bool {
|
||||
action, ok := mouseBindingActions[v]
|
||||
if !ok {
|
||||
// If the user seems to be binding a function that doesn't exist
|
||||
// We hope that it's a lua function that exists and bind it to that
|
||||
action = LuaFunctionMouseBinding(v)
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
// BindKey takes a key and an action and binds the two together
|
||||
func BindKey(k, v string) {
|
||||
key, ok := findKey(k)
|
||||
@@ -356,18 +404,31 @@ func BindKey(k, v string) {
|
||||
actionNames := strings.Split(v, ",")
|
||||
if actionNames[0] == "UnbindKey" {
|
||||
delete(bindings, key)
|
||||
delete(mouseBindings, key)
|
||||
if len(actionNames) == 1 {
|
||||
actionNames = make([]string, 0, 0)
|
||||
} else {
|
||||
actionNames = append(actionNames[:0], actionNames[1:]...)
|
||||
return
|
||||
}
|
||||
actionNames = append(actionNames[:0], actionNames[1:]...)
|
||||
}
|
||||
actions := make([]func(*View, bool) bool, 0, len(actionNames))
|
||||
mouseActions := make([]func(*View, bool, *tcell.EventMouse) bool, 0, len(actionNames))
|
||||
for _, actionName := range actionNames {
|
||||
actions = append(actions, findAction(actionName))
|
||||
if strings.HasPrefix(actionName, "Mouse") {
|
||||
mouseActions = append(mouseActions, findMouseAction(actionName))
|
||||
} else {
|
||||
actions = append(actions, findAction(actionName))
|
||||
}
|
||||
}
|
||||
|
||||
bindings[key] = actions
|
||||
if len(actions) > 0 {
|
||||
// Can't have a binding be both mouse and normal
|
||||
delete(mouseBindings, key)
|
||||
bindings[key] = actions
|
||||
} else if len(mouseActions) > 0 {
|
||||
// Can't have a binding be both mouse and normal
|
||||
delete(bindings, key)
|
||||
mouseBindings[key] = mouseActions
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultBindings returns a map containing micro's default keybindings
|
||||
@@ -426,6 +487,8 @@ func DefaultBindings() map[string]string {
|
||||
"CtrlEnd": "CursorEnd",
|
||||
"PageUp": "CursorPageUp",
|
||||
"PageDown": "CursorPageDown",
|
||||
"CtrlPageUp": "PreviousTab",
|
||||
"CtrlPageDown": "NextTab",
|
||||
"CtrlG": "ToggleHelp",
|
||||
"CtrlR": "ToggleRuler",
|
||||
"CtrlL": "JumpLine",
|
||||
@@ -442,8 +505,8 @@ func DefaultBindings() map[string]string {
|
||||
"Alt-b": "WordLeft",
|
||||
"Alt-a": "StartOfLine",
|
||||
"Alt-e": "EndOfLine",
|
||||
"Alt-p": "CursorUp",
|
||||
"Alt-n": "CursorDown",
|
||||
// "Alt-p": "CursorUp",
|
||||
// "Alt-n": "CursorDown",
|
||||
|
||||
// Integration with file managers
|
||||
"F1": "ToggleHelp",
|
||||
@@ -453,5 +516,17 @@ func DefaultBindings() map[string]string {
|
||||
"F7": "Find",
|
||||
"F10": "Quit",
|
||||
"Esc": "Escape",
|
||||
|
||||
// Mouse bindings
|
||||
"MouseWheelUp": "ScrollUp",
|
||||
"MouseWheelDown": "ScrollDown",
|
||||
"MouseLeft": "MousePress",
|
||||
"MouseMiddle": "PastePrimary",
|
||||
"Ctrl-MouseLeft": "MouseMultiCursor",
|
||||
|
||||
"Alt-n": "SpawnMultiCursor",
|
||||
"Alt-p": "RemoveMultiCursor",
|
||||
"Alt-c": "RemoveAllMultiCursors",
|
||||
"Alt-x": "SkipMultiCursor",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,13 @@ import (
|
||||
"github.com/zyedidia/micro/cmd/micro/highlight"
|
||||
)
|
||||
|
||||
var (
|
||||
// 0 - no line type detected
|
||||
// 1 - lf detected
|
||||
// 2 - crlf detected
|
||||
fileformat = 0
|
||||
)
|
||||
|
||||
// Buffer stores the text for files that are loaded into the text editor
|
||||
// It uses a rope to efficiently store the string and contains some
|
||||
// simple functions for saving and wrapper functions for modifying the rope
|
||||
@@ -28,7 +35,9 @@ type Buffer struct {
|
||||
// This stores all the text in the buffer as an array of lines
|
||||
*LineArray
|
||||
|
||||
Cursor Cursor
|
||||
Cursor Cursor
|
||||
cursors []*Cursor // for multiple cursors
|
||||
curCursor int // the current cursor
|
||||
|
||||
// Path to the file on disk
|
||||
Path string
|
||||
@@ -86,6 +95,12 @@ func NewBuffer(reader io.Reader, size int64, path string) *Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
if fileformat == 1 {
|
||||
b.Settings["fileformat"] = "unix"
|
||||
} else if fileformat == 2 {
|
||||
b.Settings["fileformat"] = "dos"
|
||||
}
|
||||
|
||||
absPath, _ := filepath.Abs(path)
|
||||
|
||||
b.Path = path
|
||||
@@ -169,6 +184,12 @@ func NewBuffer(reader io.Reader, size int64, path string) *Buffer {
|
||||
file.Close()
|
||||
}
|
||||
|
||||
if b.Settings["mouse"].(bool) {
|
||||
screen.EnableMouse()
|
||||
}
|
||||
|
||||
b.cursors = []*Cursor{&b.Cursor}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -204,7 +225,7 @@ func (b *Buffer) UpdateRules() {
|
||||
}
|
||||
|
||||
ft := b.Settings["filetype"].(string)
|
||||
if ft == "Unknown" || ft == "" {
|
||||
if (ft == "Unknown" || ft == "") && !rehighlight {
|
||||
if highlight.MatchFiletype(ftdetect, b.Path, b.lines[0].data) {
|
||||
header := new(highlight.Header)
|
||||
header.FileType = file.FileType
|
||||
@@ -217,7 +238,7 @@ func (b *Buffer) UpdateRules() {
|
||||
rehighlight = true
|
||||
}
|
||||
} else {
|
||||
if file.FileType == ft {
|
||||
if file.FileType == ft && !rehighlight {
|
||||
header := new(highlight.Header)
|
||||
header.FileType = file.FileType
|
||||
header.FtDetect = ftdetect
|
||||
@@ -236,7 +257,6 @@ func (b *Buffer) UpdateRules() {
|
||||
if b.syntaxDef != nil {
|
||||
highlight.ResolveIncludes(b.syntaxDef, files)
|
||||
}
|
||||
files = nil
|
||||
|
||||
if b.highlighter == nil || rehighlight {
|
||||
if b.syntaxDef != nil {
|
||||
@@ -305,6 +325,30 @@ func (b *Buffer) Update() {
|
||||
b.NumLines = len(b.lines)
|
||||
}
|
||||
|
||||
func (b *Buffer) MergeCursors() {
|
||||
var cursors []*Cursor
|
||||
for i := 0; i < len(b.cursors); i++ {
|
||||
c1 := b.cursors[i]
|
||||
if c1 != nil {
|
||||
for j := 0; j < len(b.cursors); j++ {
|
||||
c2 := b.cursors[j]
|
||||
if c2 != nil && i != j && c1.Loc == c2.Loc {
|
||||
b.cursors[j] = nil
|
||||
}
|
||||
}
|
||||
cursors = append(cursors, c1)
|
||||
}
|
||||
}
|
||||
|
||||
b.cursors = cursors
|
||||
}
|
||||
|
||||
func (b *Buffer) UpdateCursors() {
|
||||
for i, c := range b.cursors {
|
||||
c.Num = i
|
||||
}
|
||||
}
|
||||
|
||||
// Save saves the buffer to its default path
|
||||
func (b *Buffer) Save() error {
|
||||
return b.SaveAs(b.Path)
|
||||
@@ -328,7 +372,7 @@ func (b *Buffer) Serialize() error {
|
||||
b.ModTime,
|
||||
})
|
||||
}
|
||||
file.Close()
|
||||
err = file.Close()
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -356,7 +400,7 @@ func (b *Buffer) SaveAs(filename string) error {
|
||||
b.Insert(end, "\n")
|
||||
}
|
||||
}
|
||||
str := b.String()
|
||||
str := b.SaveString(b.Settings["fileformat"] == "dos")
|
||||
data := []byte(str)
|
||||
err := ioutil.WriteFile(filename, data, 0644)
|
||||
if err == nil {
|
||||
@@ -375,21 +419,13 @@ func (b *Buffer) SaveAsWithSudo(filename string) error {
|
||||
b.UpdateRules()
|
||||
b.Path = filename
|
||||
|
||||
// The user may have already used sudo in which case we won't need the password
|
||||
// It's a bit nicer for them if they don't have to enter the password every time
|
||||
_, err := RunShellCommand("sudo -v")
|
||||
needPassword := err != nil
|
||||
|
||||
// If we need the password, we have to close the screen and ask using the shell
|
||||
if needPassword {
|
||||
// Shut down the screen because we're going to interact directly with the shell
|
||||
screen.Fini()
|
||||
screen = nil
|
||||
}
|
||||
// Shut down the screen because we're going to interact directly with the shell
|
||||
screen.Fini()
|
||||
screen = nil
|
||||
|
||||
// Set up everything for the command
|
||||
cmd := exec.Command("sudo", "tee", filename)
|
||||
cmd.Stdin = bytes.NewBufferString(b.String())
|
||||
cmd.Stdin = bytes.NewBufferString(b.SaveString(b.Settings["fileformat"] == "dos"))
|
||||
|
||||
// This is a trap for Ctrl-C so that it doesn't kill micro
|
||||
// Instead we trap Ctrl-C to kill the program we're running
|
||||
@@ -403,13 +439,10 @@ func (b *Buffer) SaveAsWithSudo(filename string) error {
|
||||
|
||||
// Start the command
|
||||
cmd.Start()
|
||||
err = cmd.Wait()
|
||||
err := cmd.Wait()
|
||||
|
||||
// If we needed the password, we closed the screen, so we have to initialize it again
|
||||
if needPassword {
|
||||
// Start the screen back up
|
||||
InitScreen()
|
||||
}
|
||||
// Start the screen back up
|
||||
InitScreen()
|
||||
if err == nil {
|
||||
b.IsModified = false
|
||||
b.ModTime, _ = GetModTime(filename)
|
||||
@@ -533,3 +566,12 @@ func (b *Buffer) ClearMatches() {
|
||||
b.SetState(i, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Buffer) clearCursors() {
|
||||
for i := 1; i < len(b.cursors); i++ {
|
||||
b.cursors[i] = nil
|
||||
}
|
||||
b.cursors = b.cursors[:1]
|
||||
b.UpdateCursors()
|
||||
b.Cursor.ResetSelection()
|
||||
}
|
||||
|
||||
@@ -35,27 +35,28 @@ var commandActions map[string]func([]string)
|
||||
|
||||
func init() {
|
||||
commandActions = map[string]func([]string){
|
||||
"Set": Set,
|
||||
"SetLocal": SetLocal,
|
||||
"Show": Show,
|
||||
"Run": Run,
|
||||
"Bind": Bind,
|
||||
"Quit": Quit,
|
||||
"Save": Save,
|
||||
"Replace": Replace,
|
||||
"VSplit": VSplit,
|
||||
"HSplit": HSplit,
|
||||
"Tab": NewTab,
|
||||
"Help": Help,
|
||||
"Eval": Eval,
|
||||
"ToggleLog": ToggleLog,
|
||||
"Plugin": PluginCmd,
|
||||
"Reload": Reload,
|
||||
"Cd": Cd,
|
||||
"Pwd": Pwd,
|
||||
"Open": Open,
|
||||
"TabSwitch": TabSwitch,
|
||||
"MemUsage": MemUsage,
|
||||
"Set": Set,
|
||||
"SetLocal": SetLocal,
|
||||
"Show": Show,
|
||||
"Run": Run,
|
||||
"Bind": Bind,
|
||||
"Quit": Quit,
|
||||
"Save": Save,
|
||||
"Replace": Replace,
|
||||
"ReplaceAll": ReplaceAll,
|
||||
"VSplit": VSplit,
|
||||
"HSplit": HSplit,
|
||||
"Tab": NewTab,
|
||||
"Help": Help,
|
||||
"Eval": Eval,
|
||||
"ToggleLog": ToggleLog,
|
||||
"Plugin": PluginCmd,
|
||||
"Reload": Reload,
|
||||
"Cd": Cd,
|
||||
"Pwd": Pwd,
|
||||
"Open": Open,
|
||||
"TabSwitch": TabSwitch,
|
||||
"MemUsage": MemUsage,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,27 +90,28 @@ func MakeCommand(name, function string, completions ...Completion) {
|
||||
// DefaultCommands returns a map containing micro's default commands
|
||||
func DefaultCommands() map[string]StrCommand {
|
||||
return map[string]StrCommand{
|
||||
"set": {"Set", []Completion{OptionCompletion, NoCompletion}},
|
||||
"setlocal": {"SetLocal", []Completion{OptionCompletion, NoCompletion}},
|
||||
"show": {"Show", []Completion{OptionCompletion, NoCompletion}},
|
||||
"bind": {"Bind", []Completion{NoCompletion}},
|
||||
"run": {"Run", []Completion{NoCompletion}},
|
||||
"quit": {"Quit", []Completion{NoCompletion}},
|
||||
"save": {"Save", []Completion{NoCompletion}},
|
||||
"replace": {"Replace", []Completion{NoCompletion}},
|
||||
"vsplit": {"VSplit", []Completion{FileCompletion, NoCompletion}},
|
||||
"hsplit": {"HSplit", []Completion{FileCompletion, NoCompletion}},
|
||||
"tab": {"Tab", []Completion{FileCompletion, NoCompletion}},
|
||||
"help": {"Help", []Completion{HelpCompletion, NoCompletion}},
|
||||
"eval": {"Eval", []Completion{NoCompletion}},
|
||||
"log": {"ToggleLog", []Completion{NoCompletion}},
|
||||
"plugin": {"Plugin", []Completion{PluginCmdCompletion, PluginNameCompletion}},
|
||||
"reload": {"Reload", []Completion{NoCompletion}},
|
||||
"cd": {"Cd", []Completion{FileCompletion}},
|
||||
"pwd": {"Pwd", []Completion{NoCompletion}},
|
||||
"open": {"Open", []Completion{FileCompletion}},
|
||||
"tabswitch": {"TabSwitch", []Completion{NoCompletion}},
|
||||
"memusage": {"MemUsage", []Completion{NoCompletion}},
|
||||
"set": {"Set", []Completion{OptionCompletion, NoCompletion}},
|
||||
"setlocal": {"SetLocal", []Completion{OptionCompletion, NoCompletion}},
|
||||
"show": {"Show", []Completion{OptionCompletion, NoCompletion}},
|
||||
"bind": {"Bind", []Completion{NoCompletion}},
|
||||
"run": {"Run", []Completion{NoCompletion}},
|
||||
"quit": {"Quit", []Completion{NoCompletion}},
|
||||
"save": {"Save", []Completion{NoCompletion}},
|
||||
"replace": {"Replace", []Completion{NoCompletion}},
|
||||
"replaceall": {"ReplaceAll", []Completion{NoCompletion}},
|
||||
"vsplit": {"VSplit", []Completion{FileCompletion, NoCompletion}},
|
||||
"hsplit": {"HSplit", []Completion{FileCompletion, NoCompletion}},
|
||||
"tab": {"Tab", []Completion{FileCompletion, NoCompletion}},
|
||||
"help": {"Help", []Completion{HelpCompletion, NoCompletion}},
|
||||
"eval": {"Eval", []Completion{NoCompletion}},
|
||||
"log": {"ToggleLog", []Completion{NoCompletion}},
|
||||
"plugin": {"Plugin", []Completion{PluginCmdCompletion, PluginNameCompletion}},
|
||||
"reload": {"Reload", []Completion{NoCompletion}},
|
||||
"cd": {"Cd", []Completion{FileCompletion}},
|
||||
"pwd": {"Pwd", []Completion{NoCompletion}},
|
||||
"open": {"Open", []Completion{FileCompletion}},
|
||||
"tabswitch": {"TabSwitch", []Completion{NoCompletion}},
|
||||
"memusage": {"MemUsage", []Completion{NoCompletion}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,16 +508,21 @@ func Save(args []string) {
|
||||
|
||||
// Replace runs search and replace
|
||||
func Replace(args []string) {
|
||||
if len(args) < 2 {
|
||||
if len(args) < 2 || len(args) > 3 {
|
||||
// We need to find both a search and replace expression
|
||||
messenger.Error("Invalid replace statement: " + strings.Join(args, " "))
|
||||
return
|
||||
}
|
||||
|
||||
var flags string
|
||||
allAtOnce := false
|
||||
if len(args) == 3 {
|
||||
// The user included some flags
|
||||
flags = args[2]
|
||||
// user added -a flag
|
||||
if args[2] == "-a" {
|
||||
allAtOnce = true
|
||||
} else {
|
||||
messenger.Error("Invalid replace flag: " + args[2])
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
search := string(args[0])
|
||||
@@ -531,7 +538,32 @@ func Replace(args []string) {
|
||||
view := CurView()
|
||||
|
||||
found := 0
|
||||
if strings.Contains(flags, "c") {
|
||||
replaceAll := func() {
|
||||
var deltas []Delta
|
||||
deltaXOffset := Count(replace) - Count(search)
|
||||
for i := 0; i < view.Buf.LinesNum(); i++ {
|
||||
matches := regex.FindAllIndex(view.Buf.lines[i].data, -1)
|
||||
str := string(view.Buf.lines[i].data)
|
||||
|
||||
if matches != nil {
|
||||
xOffset := 0
|
||||
for _, m := range matches {
|
||||
from := Loc{runePos(m[0], str) + xOffset, i}
|
||||
to := Loc{runePos(m[1], str) + xOffset, i}
|
||||
|
||||
xOffset += deltaXOffset
|
||||
|
||||
deltas = append(deltas, Delta{replace, from, to})
|
||||
found++
|
||||
}
|
||||
}
|
||||
}
|
||||
view.Buf.MultipleReplace(deltas)
|
||||
}
|
||||
|
||||
if allAtOnce {
|
||||
replaceAll()
|
||||
} else {
|
||||
for {
|
||||
// The 'check' flag was used
|
||||
Search(search, view, true)
|
||||
@@ -540,7 +572,7 @@ func Replace(args []string) {
|
||||
}
|
||||
view.Relocate()
|
||||
RedrawAll()
|
||||
choice, canceled := messenger.YesNoPrompt("Perform replacement? (y,n)")
|
||||
choice, canceled := messenger.LetterPrompt("Perform replacement? (y,n,a)", 'y', 'n', 'a')
|
||||
if canceled {
|
||||
if view.Cursor.HasSelection() {
|
||||
view.Cursor.Loc = view.Cursor.CurSelection[0]
|
||||
@@ -548,42 +580,27 @@ func Replace(args []string) {
|
||||
}
|
||||
messenger.Reset()
|
||||
break
|
||||
}
|
||||
if choice {
|
||||
} else if choice == 'a' {
|
||||
if view.Cursor.HasSelection() {
|
||||
view.Cursor.Loc = view.Cursor.CurSelection[0]
|
||||
view.Cursor.ResetSelection()
|
||||
}
|
||||
messenger.Reset()
|
||||
replaceAll()
|
||||
break
|
||||
} else if choice == 'y' {
|
||||
view.Cursor.DeleteSelection()
|
||||
view.Buf.Insert(view.Cursor.Loc, replace)
|
||||
view.Cursor.ResetSelection()
|
||||
messenger.Reset()
|
||||
found++
|
||||
}
|
||||
if view.Cursor.HasSelection() {
|
||||
searchStart = view.Cursor.CurSelection[1]
|
||||
} else {
|
||||
if view.Cursor.HasSelection() {
|
||||
searchStart = ToCharPos(view.Cursor.CurSelection[1], view.Buf)
|
||||
} else {
|
||||
searchStart = ToCharPos(view.Cursor.Loc, view.Buf)
|
||||
}
|
||||
continue
|
||||
searchStart = view.Cursor.Loc
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// var deltas []Delta
|
||||
for i := 0; i < view.Buf.LinesNum(); i++ {
|
||||
// view.Buf.lines[i].data = regex.ReplaceAll(view.Buf.lines[i].data, []byte(replace))
|
||||
for {
|
||||
m := regex.FindIndex(view.Buf.lines[i].data)
|
||||
|
||||
if m != nil {
|
||||
from := Loc{m[0], i}
|
||||
to := Loc{m[1], i}
|
||||
|
||||
// deltas = append(deltas, Delta{replace, from, to})
|
||||
view.Buf.Replace(from, to, replace)
|
||||
found++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// view.Buf.MultipleReplace(deltas)
|
||||
}
|
||||
view.Cursor.Relocate()
|
||||
|
||||
@@ -596,6 +613,12 @@ func Replace(args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// ReplaceAll replaces search term all at once
|
||||
func ReplaceAll(args []string) {
|
||||
// aliased to Replace command
|
||||
Replace(append(args, "-a"))
|
||||
}
|
||||
|
||||
// RunShellCommand executes a shell command and returns the output/error
|
||||
func RunShellCommand(input string) (string, error) {
|
||||
inputCmd := SplitCommandArgs(input)[0]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import "github.com/zyedidia/clipboard"
|
||||
import (
|
||||
"github.com/zyedidia/clipboard"
|
||||
)
|
||||
|
||||
// The Cursor struct stores the location of the cursor in the view
|
||||
// The complicated part about the cursor is storing its location.
|
||||
@@ -21,6 +23,9 @@ type Cursor struct {
|
||||
// This is used for line and word selection where it is necessary
|
||||
// to know what the original selection was
|
||||
OrigSelection [2]Loc
|
||||
|
||||
// Which cursor index is this (for multiple cursors)
|
||||
Num int
|
||||
}
|
||||
|
||||
// Goto puts the cursor at the given cursor's location and gives the current cursor its selection too
|
||||
@@ -245,19 +250,19 @@ func (c *Cursor) UpN(amount int) {
|
||||
proposedY := c.Y - amount
|
||||
if proposedY < 0 {
|
||||
proposedY = 0
|
||||
c.LastVisualX = 0
|
||||
} else if proposedY >= c.buf.NumLines {
|
||||
proposedY = c.buf.NumLines - 1
|
||||
}
|
||||
if proposedY == c.Y {
|
||||
return
|
||||
}
|
||||
|
||||
c.Y = proposedY
|
||||
runes := []rune(c.buf.Line(c.Y))
|
||||
c.X = c.GetCharPosInLine(c.Y, c.LastVisualX)
|
||||
c.X = c.GetCharPosInLine(proposedY, c.LastVisualX)
|
||||
|
||||
if c.X > len(runes) {
|
||||
c.X = len(runes)
|
||||
}
|
||||
|
||||
c.Y = proposedY
|
||||
}
|
||||
|
||||
// DownN moves the cursor down N lines (if possible)
|
||||
@@ -334,9 +339,22 @@ func (c *Cursor) GetCharPosInLine(lineNum, visualPos int) int {
|
||||
func (c *Cursor) GetVisualX() int {
|
||||
runes := []rune(c.buf.Line(c.Y))
|
||||
tabSize := int(c.buf.Settings["tabsize"].(float64))
|
||||
if c.X > len(runes) {
|
||||
c.X = len(runes) - 1
|
||||
}
|
||||
|
||||
if c.X < 0 {
|
||||
c.X = 0
|
||||
}
|
||||
|
||||
return StringWidth(string(runes[:c.X]), tabSize)
|
||||
}
|
||||
|
||||
// StoreVisualX stores the current visual x value in the cursor
|
||||
func (c *Cursor) StoreVisualX() {
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
}
|
||||
|
||||
// Relocate makes sure that the cursor is inside the bounds of the buffer
|
||||
// If it isn't, it moves it to be within the buffer's lines
|
||||
func (c *Cursor) Relocate() {
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
const (
|
||||
// Opposite and undoing events must have opposite values
|
||||
|
||||
// TextEventInsert repreasents an insertion event
|
||||
// TextEventInsert represents an insertion event
|
||||
TextEventInsert = 1
|
||||
// TextEventRemove represents a deletion event
|
||||
TextEventRemove = -1
|
||||
|
||||
// TextEventReplace represents a replace event
|
||||
TextEventReplace = 0
|
||||
)
|
||||
|
||||
@@ -48,6 +48,11 @@ func ExecuteTextEvent(t *TextEvent, buf *Buffer) {
|
||||
for i, d := range t.Deltas {
|
||||
t.Deltas[i].Text = buf.remove(d.Start, d.End)
|
||||
buf.insert(d.Start, []byte(d.Text))
|
||||
t.Deltas[i].Start = d.Start
|
||||
t.Deltas[i].End = Loc{d.Start.X + Count(d.Text), d.Start.Y}
|
||||
}
|
||||
for i, j := 0, len(t.Deltas)-1; i < j; i, j = i+1, j-1 {
|
||||
t.Deltas[i], t.Deltas[j] = t.Deltas[j], t.Deltas[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,30 +102,65 @@ func (eh *EventHandler) ApplyDiff(new string) {
|
||||
// Insert creates an insert text event and executes it
|
||||
func (eh *EventHandler) Insert(start Loc, text string) {
|
||||
e := &TextEvent{
|
||||
C: eh.buf.Cursor,
|
||||
C: *eh.buf.cursors[eh.buf.curCursor],
|
||||
EventType: TextEventInsert,
|
||||
Deltas: []Delta{Delta{text, start, Loc{0, 0}}},
|
||||
Deltas: []Delta{{text, start, Loc{0, 0}}},
|
||||
Time: time.Now(),
|
||||
}
|
||||
eh.Execute(e)
|
||||
e.Deltas[0].End = start.Move(Count(text), eh.buf)
|
||||
end := e.Deltas[0].End
|
||||
|
||||
for _, c := range eh.buf.cursors {
|
||||
move := func(loc Loc) Loc {
|
||||
if start.Y != end.Y && loc.GreaterThan(start) {
|
||||
loc.Y += end.Y - start.Y
|
||||
} else if loc.Y == start.Y && loc.GreaterEqual(start) {
|
||||
loc = loc.Move(Count(text), eh.buf)
|
||||
}
|
||||
return loc
|
||||
}
|
||||
c.Loc = move(c.Loc)
|
||||
c.CurSelection[0] = move(c.CurSelection[0])
|
||||
c.CurSelection[1] = move(c.CurSelection[1])
|
||||
c.OrigSelection[0] = move(c.OrigSelection[0])
|
||||
c.OrigSelection[1] = move(c.OrigSelection[1])
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
}
|
||||
}
|
||||
|
||||
// Remove creates a remove text event and executes it
|
||||
func (eh *EventHandler) Remove(start, end Loc) {
|
||||
e := &TextEvent{
|
||||
C: eh.buf.Cursor,
|
||||
C: *eh.buf.cursors[eh.buf.curCursor],
|
||||
EventType: TextEventRemove,
|
||||
Deltas: []Delta{Delta{"", start, end}},
|
||||
Deltas: []Delta{{"", start, end}},
|
||||
Time: time.Now(),
|
||||
}
|
||||
eh.Execute(e)
|
||||
|
||||
for _, c := range eh.buf.cursors {
|
||||
move := func(loc Loc) Loc {
|
||||
if start.Y != end.Y && loc.GreaterThan(end) {
|
||||
loc.Y -= end.Y - start.Y
|
||||
} else if loc.Y == end.Y && loc.GreaterEqual(end) {
|
||||
loc = loc.Move(-Diff(start, end, eh.buf), eh.buf)
|
||||
}
|
||||
return loc
|
||||
}
|
||||
c.Loc = move(c.Loc)
|
||||
c.CurSelection[0] = move(c.CurSelection[0])
|
||||
c.CurSelection[1] = move(c.CurSelection[1])
|
||||
c.OrigSelection[0] = move(c.OrigSelection[0])
|
||||
c.OrigSelection[1] = move(c.OrigSelection[1])
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
}
|
||||
}
|
||||
|
||||
// Multiple creates an multiple insertions executes them
|
||||
// MultipleReplace creates an multiple insertions executes them
|
||||
func (eh *EventHandler) MultipleReplace(deltas []Delta) {
|
||||
e := &TextEvent{
|
||||
C: eh.buf.Cursor,
|
||||
C: *eh.buf.cursors[eh.buf.curCursor],
|
||||
EventType: TextEventReplace,
|
||||
Deltas: deltas,
|
||||
Time: time.Now(),
|
||||
@@ -195,8 +235,12 @@ func (eh *EventHandler) UndoOneEvent() {
|
||||
|
||||
// Set the cursor in the right place
|
||||
teCursor := t.C
|
||||
t.C = eh.buf.Cursor
|
||||
eh.buf.Cursor.Goto(teCursor)
|
||||
if teCursor.Num >= 0 && teCursor.Num < len(eh.buf.cursors) {
|
||||
t.C = *eh.buf.cursors[teCursor.Num]
|
||||
eh.buf.cursors[teCursor.Num].Goto(teCursor)
|
||||
} else {
|
||||
teCursor.Num = -1
|
||||
}
|
||||
|
||||
// Push it to the redo stack
|
||||
eh.RedoStack.Push(t)
|
||||
@@ -238,8 +282,12 @@ func (eh *EventHandler) RedoOneEvent() {
|
||||
UndoTextEvent(t, eh.buf)
|
||||
|
||||
teCursor := t.C
|
||||
t.C = eh.buf.Cursor
|
||||
eh.buf.Cursor.Goto(teCursor)
|
||||
if teCursor.Num >= 0 && teCursor.Num < len(eh.buf.cursors) {
|
||||
t.C = *eh.buf.cursors[teCursor.Num]
|
||||
eh.buf.cursors[teCursor.Num].Goto(teCursor)
|
||||
} else {
|
||||
teCursor.Num = -1
|
||||
}
|
||||
|
||||
eh.UndoStack.Push(t)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package highlight
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
@@ -82,6 +83,16 @@ func init() {
|
||||
}
|
||||
|
||||
func ParseFtDetect(file *File) (r [2]*regexp.Regexp, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
var ok bool
|
||||
err, ok = r.(error)
|
||||
if !ok {
|
||||
err = fmt.Errorf("pkg: %v", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
rules := file.yamlSrc
|
||||
|
||||
loaded := 0
|
||||
@@ -112,14 +123,22 @@ func ParseFtDetect(file *File) (r [2]*regexp.Regexp, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if loaded == 0 {
|
||||
return r, errors.New("No detect regexes found")
|
||||
}
|
||||
|
||||
return r, err
|
||||
}
|
||||
|
||||
func ParseFile(input []byte) (f *File, err error) {
|
||||
// This is just so if we have an error, we can exit cleanly and return the parse error to the user
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
err = e.(error)
|
||||
if r := recover(); r != nil {
|
||||
var ok bool
|
||||
err, ok = r.(error)
|
||||
if !ok {
|
||||
err = fmt.Errorf("pkg: %v", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -147,8 +166,12 @@ func ParseFile(input []byte) (f *File, err error) {
|
||||
func ParseDef(f *File, header *Header) (s *Def, err error) {
|
||||
// This is just so if we have an error, we can exit cleanly and return the parse error to the user
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
err = e.(error)
|
||||
if r := recover(); r != nil {
|
||||
var ok bool
|
||||
err, ok = r.(error)
|
||||
if !ok {
|
||||
err = fmt.Errorf("pkg: %v", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -211,8 +234,17 @@ func resolveIncludesInRegion(files []*File, region *region) {
|
||||
}
|
||||
}
|
||||
|
||||
func parseRules(input []interface{}, curRegion *region) (*rules, error) {
|
||||
rules := new(rules)
|
||||
func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
var ok bool
|
||||
err, ok = r.(error)
|
||||
if !ok {
|
||||
err = fmt.Errorf("pkg: %v", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
ru = new(rules)
|
||||
|
||||
for _, v := range input {
|
||||
rule := v.(map[interface{}]interface{})
|
||||
@@ -222,7 +254,7 @@ func parseRules(input []interface{}, curRegion *region) (*rules, error) {
|
||||
switch object := val.(type) {
|
||||
case string:
|
||||
if k == "include" {
|
||||
rules.includes = append(rules.includes, object)
|
||||
ru.includes = append(ru.includes, object)
|
||||
} else {
|
||||
// Pattern
|
||||
r, err := regexp.Compile(object)
|
||||
@@ -236,7 +268,7 @@ func parseRules(input []interface{}, curRegion *region) (*rules, error) {
|
||||
Groups[groupStr] = numGroups
|
||||
}
|
||||
groupNum := Groups[groupStr]
|
||||
rules.patterns = append(rules.patterns, &pattern{groupNum, r})
|
||||
ru.patterns = append(ru.patterns, &pattern{groupNum, r})
|
||||
}
|
||||
case map[interface{}]interface{}:
|
||||
// region
|
||||
@@ -244,35 +276,43 @@ func parseRules(input []interface{}, curRegion *region) (*rules, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rules.regions = append(rules.regions, region)
|
||||
ru.regions = append(ru.regions, region)
|
||||
default:
|
||||
return nil, fmt.Errorf("Bad type %T", object)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rules, nil
|
||||
return ru, nil
|
||||
}
|
||||
|
||||
func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegion *region) (*region, error) {
|
||||
var err error
|
||||
func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegion *region) (r *region, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
var ok bool
|
||||
err, ok = r.(error)
|
||||
if !ok {
|
||||
err = fmt.Errorf("pkg: %v", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
region := new(region)
|
||||
r = new(region)
|
||||
if _, ok := Groups[group]; !ok {
|
||||
numGroups++
|
||||
Groups[group] = numGroups
|
||||
}
|
||||
groupNum := Groups[group]
|
||||
region.group = groupNum
|
||||
region.parent = prevRegion
|
||||
r.group = groupNum
|
||||
r.parent = prevRegion
|
||||
|
||||
region.start, err = regexp.Compile(regionInfo["start"].(string))
|
||||
r.start, err = regexp.Compile(regionInfo["start"].(string))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
region.end, err = regexp.Compile(regionInfo["end"].(string))
|
||||
r.end, err = regexp.Compile(regionInfo["end"].(string))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -280,7 +320,7 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
|
||||
|
||||
// skip is optional
|
||||
if _, ok := regionInfo["skip"]; ok {
|
||||
region.skip, err = regexp.Compile(regionInfo["skip"].(string))
|
||||
r.skip, err = regexp.Compile(regionInfo["skip"].(string))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -295,20 +335,20 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
|
||||
Groups[groupStr] = numGroups
|
||||
}
|
||||
groupNum := Groups[groupStr]
|
||||
region.limitGroup = groupNum
|
||||
r.limitGroup = groupNum
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
region.limitGroup = region.group
|
||||
r.limitGroup = r.group
|
||||
}
|
||||
|
||||
region.rules, err = parseRules(regionInfo["rules"].([]interface{}), region)
|
||||
r.rules, err = parseRules(regionInfo["rules"].([]interface{}), r)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return region, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -71,6 +71,16 @@ func NewLineArray(size int64, reader io.Reader) *LineArray {
|
||||
n := 0
|
||||
for {
|
||||
data, err := br.ReadBytes('\n')
|
||||
if len(data) > 1 && data[len(data)-2] == '\r' {
|
||||
data = append(data[:len(data)-2], '\n')
|
||||
if fileformat == 0 {
|
||||
fileformat = 2
|
||||
}
|
||||
} else if len(data) > 0 {
|
||||
if fileformat == 0 {
|
||||
fileformat = 1
|
||||
}
|
||||
}
|
||||
|
||||
if n >= 1000 && loaded >= 0 {
|
||||
totalLinesNum := int(float64(size) * (float64(n) / float64(loaded)))
|
||||
@@ -87,7 +97,7 @@ func NewLineArray(size int64, reader io.Reader) *LineArray {
|
||||
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
la.lines = Append(la.lines, Line{data[:len(data)], nil, nil, false})
|
||||
la.lines = Append(la.lines, Line{data[:], nil, nil, false})
|
||||
// la.lines = Append(la.lines, Line{data[:len(data)]})
|
||||
}
|
||||
// Last line was read
|
||||
@@ -114,6 +124,23 @@ func (la *LineArray) String() string {
|
||||
return str
|
||||
}
|
||||
|
||||
// SaveString returns the string that should be written to disk when
|
||||
// the line array is saved
|
||||
// It is the same as string but uses crlf or lf line endings depending
|
||||
func (la *LineArray) SaveString(useCrlf bool) string {
|
||||
str := ""
|
||||
for i, l := range la.lines {
|
||||
str += string(l.data)
|
||||
if i != len(la.lines)-1 {
|
||||
if useCrlf {
|
||||
str += "\r"
|
||||
}
|
||||
str += "\n"
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
// NewlineBelow adds a newline below the given line number
|
||||
func (la *LineArray) NewlineBelow(y int) {
|
||||
la.lines = append(la.lines, Line{[]byte(" "), nil, nil, false})
|
||||
|
||||
@@ -54,6 +54,28 @@ type Loc struct {
|
||||
X, Y int
|
||||
}
|
||||
|
||||
func Diff(a, b Loc, buf *Buffer) int {
|
||||
if a.Y == b.Y {
|
||||
if a.X > b.X {
|
||||
return a.X - b.X
|
||||
}
|
||||
return b.X - a.X
|
||||
}
|
||||
|
||||
// Make sure a is guaranteed to be less than b
|
||||
if b.LessThan(a) {
|
||||
a, b = b, a
|
||||
}
|
||||
|
||||
loc := 0
|
||||
for i := a.Y + 1; i < b.Y; i++ {
|
||||
// + 1 for the newline
|
||||
loc += Count(buf.Line(i)) + 1
|
||||
}
|
||||
loc += Count(buf.Line(a.Y)) - a.X + b.X + 1
|
||||
return loc
|
||||
}
|
||||
|
||||
// LessThan returns true if b is smaller
|
||||
func (l Loc) LessThan(b Loc) bool {
|
||||
if l.Y < b.Y {
|
||||
|
||||
536
cmd/micro/lua.go
Normal file
536
cmd/micro/lua.go
Normal file
@@ -0,0 +1,536 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
luar "layeh.com/gopher-luar"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
var L *lua.LState
|
||||
|
||||
func init() {
|
||||
L = lua.NewState()
|
||||
L.SetGlobal("import", luar.New(L, Import))
|
||||
}
|
||||
|
||||
func LoadFile(module string, file string, data string) error {
|
||||
pluginDef := "local P = {};" + module + " = P;setmetatable(" + module + ", {__index = _G});setfenv(1, P);"
|
||||
|
||||
if fn, err := L.Load(strings.NewReader(pluginDef+data), file); err != nil {
|
||||
return err
|
||||
} else {
|
||||
L.Push(fn)
|
||||
return L.PCall(0, lua.MultRet, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func Import(pkg string) *lua.LTable {
|
||||
switch pkg {
|
||||
case "fmt":
|
||||
return ImportFmt()
|
||||
case "io":
|
||||
return ImportIo()
|
||||
case "ioutil":
|
||||
return ImportIoUtil()
|
||||
case "net":
|
||||
return ImportNet()
|
||||
case "math":
|
||||
return ImportMath()
|
||||
case "os":
|
||||
return ImportOs()
|
||||
case "runtime":
|
||||
return ImportRuntime()
|
||||
case "path":
|
||||
return ImportPath()
|
||||
case "filepath":
|
||||
return ImportFilePath()
|
||||
case "strings":
|
||||
return ImportStrings()
|
||||
case "regexp":
|
||||
return ImportRegexp()
|
||||
case "errors":
|
||||
return ImportErrors()
|
||||
case "time":
|
||||
return ImportTime()
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func ImportFmt() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "tErrorf", luar.New(L, fmt.Errorf))
|
||||
L.SetField(pkg, "Fprint", luar.New(L, fmt.Fprint))
|
||||
L.SetField(pkg, "Fprintf", luar.New(L, fmt.Fprintf))
|
||||
L.SetField(pkg, "Fprintln", luar.New(L, fmt.Fprintln))
|
||||
L.SetField(pkg, "Fscan", luar.New(L, fmt.Fscan))
|
||||
L.SetField(pkg, "Fscanf", luar.New(L, fmt.Fscanf))
|
||||
L.SetField(pkg, "Fscanln", luar.New(L, fmt.Fscanln))
|
||||
L.SetField(pkg, "Print", luar.New(L, fmt.Print))
|
||||
L.SetField(pkg, "Printf", luar.New(L, fmt.Printf))
|
||||
L.SetField(pkg, "Println", luar.New(L, fmt.Println))
|
||||
L.SetField(pkg, "Scan", luar.New(L, fmt.Scan))
|
||||
L.SetField(pkg, "Scanf", luar.New(L, fmt.Scanf))
|
||||
L.SetField(pkg, "Scanln", luar.New(L, fmt.Scanln))
|
||||
L.SetField(pkg, "Sprint", luar.New(L, fmt.Sprint))
|
||||
L.SetField(pkg, "Sprintf", luar.New(L, fmt.Sprintf))
|
||||
L.SetField(pkg, "Sprintln", luar.New(L, fmt.Sprintln))
|
||||
L.SetField(pkg, "Sscan", luar.New(L, fmt.Sscan))
|
||||
L.SetField(pkg, "Sscanf", luar.New(L, fmt.Sscanf))
|
||||
L.SetField(pkg, "Sscanln", luar.New(L, fmt.Sscanln))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportIo() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Copy", luar.New(L, io.Copy))
|
||||
L.SetField(pkg, "CopyN", luar.New(L, io.CopyN))
|
||||
L.SetField(pkg, "EOF", luar.New(L, io.EOF))
|
||||
L.SetField(pkg, "ErrClosedPipe", luar.New(L, io.ErrClosedPipe))
|
||||
L.SetField(pkg, "ErrNoProgress", luar.New(L, io.ErrNoProgress))
|
||||
L.SetField(pkg, "ErrShortBuffer", luar.New(L, io.ErrShortBuffer))
|
||||
L.SetField(pkg, "ErrShortWrite", luar.New(L, io.ErrShortWrite))
|
||||
L.SetField(pkg, "ErrUnexpectedEOF", luar.New(L, io.ErrUnexpectedEOF))
|
||||
L.SetField(pkg, "LimitReader", luar.New(L, io.LimitReader))
|
||||
L.SetField(pkg, "MultiReader", luar.New(L, io.MultiReader))
|
||||
L.SetField(pkg, "MultiWriter", luar.New(L, io.MultiWriter))
|
||||
L.SetField(pkg, "NewSectionReader", luar.New(L, io.NewSectionReader))
|
||||
L.SetField(pkg, "Pipe", luar.New(L, io.Pipe))
|
||||
L.SetField(pkg, "ReadAtLeast", luar.New(L, io.ReadAtLeast))
|
||||
L.SetField(pkg, "ReadFull", luar.New(L, io.ReadFull))
|
||||
L.SetField(pkg, "TeeReader", luar.New(L, io.TeeReader))
|
||||
L.SetField(pkg, "WriteString", luar.New(L, io.WriteString))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportIoUtil() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "ReadAll", luar.New(L, ioutil.ReadAll))
|
||||
L.SetField(pkg, "ReadDir", luar.New(L, ioutil.ReadDir))
|
||||
L.SetField(pkg, "ReadFile", luar.New(L, ioutil.ReadFile))
|
||||
L.SetField(pkg, "WriteFile", luar.New(L, ioutil.WriteFile))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportNet() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "CIDRMask", luar.New(L, net.CIDRMask))
|
||||
L.SetField(pkg, "Dial", luar.New(L, net.Dial))
|
||||
L.SetField(pkg, "DialIP", luar.New(L, net.DialIP))
|
||||
L.SetField(pkg, "DialTCP", luar.New(L, net.DialTCP))
|
||||
L.SetField(pkg, "DialTimeout", luar.New(L, net.DialTimeout))
|
||||
L.SetField(pkg, "DialUDP", luar.New(L, net.DialUDP))
|
||||
L.SetField(pkg, "DialUnix", luar.New(L, net.DialUnix))
|
||||
L.SetField(pkg, "ErrWriteToConnected", luar.New(L, net.ErrWriteToConnected))
|
||||
L.SetField(pkg, "FileConn", luar.New(L, net.FileConn))
|
||||
L.SetField(pkg, "FileListener", luar.New(L, net.FileListener))
|
||||
L.SetField(pkg, "FilePacketConn", luar.New(L, net.FilePacketConn))
|
||||
L.SetField(pkg, "FlagBroadcast", luar.New(L, net.FlagBroadcast))
|
||||
L.SetField(pkg, "FlagLoopback", luar.New(L, net.FlagLoopback))
|
||||
L.SetField(pkg, "FlagMulticast", luar.New(L, net.FlagMulticast))
|
||||
L.SetField(pkg, "FlagPointToPoint", luar.New(L, net.FlagPointToPoint))
|
||||
L.SetField(pkg, "FlagUp", luar.New(L, net.FlagUp))
|
||||
L.SetField(pkg, "IPv4", luar.New(L, net.IPv4))
|
||||
L.SetField(pkg, "IPv4Mask", luar.New(L, net.IPv4Mask))
|
||||
L.SetField(pkg, "IPv4allrouter", luar.New(L, net.IPv4allrouter))
|
||||
L.SetField(pkg, "IPv4allsys", luar.New(L, net.IPv4allsys))
|
||||
L.SetField(pkg, "IPv4bcast", luar.New(L, net.IPv4bcast))
|
||||
L.SetField(pkg, "IPv4len", luar.New(L, net.IPv4len))
|
||||
L.SetField(pkg, "IPv4zero", luar.New(L, net.IPv4zero))
|
||||
L.SetField(pkg, "IPv6interfacelocalallnodes", luar.New(L, net.IPv6interfacelocalallnodes))
|
||||
L.SetField(pkg, "IPv6len", luar.New(L, net.IPv6len))
|
||||
L.SetField(pkg, "IPv6linklocalallnodes", luar.New(L, net.IPv6linklocalallnodes))
|
||||
L.SetField(pkg, "IPv6linklocalallrouters", luar.New(L, net.IPv6linklocalallrouters))
|
||||
L.SetField(pkg, "IPv6loopback", luar.New(L, net.IPv6loopback))
|
||||
L.SetField(pkg, "IPv6unspecified", luar.New(L, net.IPv6unspecified))
|
||||
L.SetField(pkg, "IPv6zero", luar.New(L, net.IPv6zero))
|
||||
L.SetField(pkg, "InterfaceAddrs", luar.New(L, net.InterfaceAddrs))
|
||||
L.SetField(pkg, "InterfaceByIndex", luar.New(L, net.InterfaceByIndex))
|
||||
L.SetField(pkg, "InterfaceByName", luar.New(L, net.InterfaceByName))
|
||||
L.SetField(pkg, "Interfaces", luar.New(L, net.Interfaces))
|
||||
L.SetField(pkg, "JoinHostPort", luar.New(L, net.JoinHostPort))
|
||||
L.SetField(pkg, "Listen", luar.New(L, net.Listen))
|
||||
L.SetField(pkg, "ListenIP", luar.New(L, net.ListenIP))
|
||||
L.SetField(pkg, "ListenMulticastUDP", luar.New(L, net.ListenMulticastUDP))
|
||||
L.SetField(pkg, "ListenPacket", luar.New(L, net.ListenPacket))
|
||||
L.SetField(pkg, "ListenTCP", luar.New(L, net.ListenTCP))
|
||||
L.SetField(pkg, "ListenUDP", luar.New(L, net.ListenUDP))
|
||||
L.SetField(pkg, "ListenUnix", luar.New(L, net.ListenUnix))
|
||||
L.SetField(pkg, "ListenUnixgram", luar.New(L, net.ListenUnixgram))
|
||||
L.SetField(pkg, "LookupAddr", luar.New(L, net.LookupAddr))
|
||||
L.SetField(pkg, "LookupCNAME", luar.New(L, net.LookupCNAME))
|
||||
L.SetField(pkg, "LookupHost", luar.New(L, net.LookupHost))
|
||||
L.SetField(pkg, "LookupIP", luar.New(L, net.LookupIP))
|
||||
L.SetField(pkg, "LookupMX", luar.New(L, net.LookupMX))
|
||||
L.SetField(pkg, "LookupNS", luar.New(L, net.LookupNS))
|
||||
L.SetField(pkg, "LookupPort", luar.New(L, net.LookupPort))
|
||||
L.SetField(pkg, "LookupSRV", luar.New(L, net.LookupSRV))
|
||||
L.SetField(pkg, "LookupTXT", luar.New(L, net.LookupTXT))
|
||||
L.SetField(pkg, "ParseCIDR", luar.New(L, net.ParseCIDR))
|
||||
L.SetField(pkg, "ParseIP", luar.New(L, net.ParseIP))
|
||||
L.SetField(pkg, "ParseMAC", luar.New(L, net.ParseMAC))
|
||||
L.SetField(pkg, "Pipe", luar.New(L, net.Pipe))
|
||||
L.SetField(pkg, "ResolveIPAddr", luar.New(L, net.ResolveIPAddr))
|
||||
L.SetField(pkg, "ResolveTCPAddr", luar.New(L, net.ResolveTCPAddr))
|
||||
L.SetField(pkg, "ResolveUDPAddr", luar.New(L, net.ResolveUDPAddr))
|
||||
L.SetField(pkg, "ResolveUnixAddr", luar.New(L, net.ResolveUnixAddr))
|
||||
L.SetField(pkg, "SplitHostPort", luar.New(L, net.SplitHostPort))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportMath() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Abs", luar.New(L, math.Abs))
|
||||
L.SetField(pkg, "Acos", luar.New(L, math.Acos))
|
||||
L.SetField(pkg, "Acosh", luar.New(L, math.Acosh))
|
||||
L.SetField(pkg, "Asin", luar.New(L, math.Asin))
|
||||
L.SetField(pkg, "Asinh", luar.New(L, math.Asinh))
|
||||
L.SetField(pkg, "Atan", luar.New(L, math.Atan))
|
||||
L.SetField(pkg, "Atan2", luar.New(L, math.Atan2))
|
||||
L.SetField(pkg, "Atanh", luar.New(L, math.Atanh))
|
||||
L.SetField(pkg, "Cbrt", luar.New(L, math.Cbrt))
|
||||
L.SetField(pkg, "Ceil", luar.New(L, math.Ceil))
|
||||
L.SetField(pkg, "Copysign", luar.New(L, math.Copysign))
|
||||
L.SetField(pkg, "Cos", luar.New(L, math.Cos))
|
||||
L.SetField(pkg, "Cosh", luar.New(L, math.Cosh))
|
||||
L.SetField(pkg, "Dim", luar.New(L, math.Dim))
|
||||
L.SetField(pkg, "Erf", luar.New(L, math.Erf))
|
||||
L.SetField(pkg, "Erfc", luar.New(L, math.Erfc))
|
||||
L.SetField(pkg, "Exp", luar.New(L, math.Exp))
|
||||
L.SetField(pkg, "Exp2", luar.New(L, math.Exp2))
|
||||
L.SetField(pkg, "Expm1", luar.New(L, math.Expm1))
|
||||
L.SetField(pkg, "Float32bits", luar.New(L, math.Float32bits))
|
||||
L.SetField(pkg, "Float32frombits", luar.New(L, math.Float32frombits))
|
||||
L.SetField(pkg, "Float64bits", luar.New(L, math.Float64bits))
|
||||
L.SetField(pkg, "Float64frombits", luar.New(L, math.Float64frombits))
|
||||
L.SetField(pkg, "Floor", luar.New(L, math.Floor))
|
||||
L.SetField(pkg, "Frexp", luar.New(L, math.Frexp))
|
||||
L.SetField(pkg, "Gamma", luar.New(L, math.Gamma))
|
||||
L.SetField(pkg, "Hypot", luar.New(L, math.Hypot))
|
||||
L.SetField(pkg, "Ilogb", luar.New(L, math.Ilogb))
|
||||
L.SetField(pkg, "Inf", luar.New(L, math.Inf))
|
||||
L.SetField(pkg, "IsInf", luar.New(L, math.IsInf))
|
||||
L.SetField(pkg, "IsNaN", luar.New(L, math.IsNaN))
|
||||
L.SetField(pkg, "J0", luar.New(L, math.J0))
|
||||
L.SetField(pkg, "J1", luar.New(L, math.J1))
|
||||
L.SetField(pkg, "Jn", luar.New(L, math.Jn))
|
||||
L.SetField(pkg, "Ldexp", luar.New(L, math.Ldexp))
|
||||
L.SetField(pkg, "Lgamma", luar.New(L, math.Lgamma))
|
||||
L.SetField(pkg, "Log", luar.New(L, math.Log))
|
||||
L.SetField(pkg, "Log10", luar.New(L, math.Log10))
|
||||
L.SetField(pkg, "Log1p", luar.New(L, math.Log1p))
|
||||
L.SetField(pkg, "Log2", luar.New(L, math.Log2))
|
||||
L.SetField(pkg, "Logb", luar.New(L, math.Logb))
|
||||
L.SetField(pkg, "Max", luar.New(L, math.Max))
|
||||
L.SetField(pkg, "Min", luar.New(L, math.Min))
|
||||
L.SetField(pkg, "Mod", luar.New(L, math.Mod))
|
||||
L.SetField(pkg, "Modf", luar.New(L, math.Modf))
|
||||
L.SetField(pkg, "NaN", luar.New(L, math.NaN))
|
||||
L.SetField(pkg, "Nextafter", luar.New(L, math.Nextafter))
|
||||
L.SetField(pkg, "Pow", luar.New(L, math.Pow))
|
||||
L.SetField(pkg, "Pow10", luar.New(L, math.Pow10))
|
||||
L.SetField(pkg, "Remainder", luar.New(L, math.Remainder))
|
||||
L.SetField(pkg, "Signbit", luar.New(L, math.Signbit))
|
||||
L.SetField(pkg, "Sin", luar.New(L, math.Sin))
|
||||
L.SetField(pkg, "Sincos", luar.New(L, math.Sincos))
|
||||
L.SetField(pkg, "Sinh", luar.New(L, math.Sinh))
|
||||
L.SetField(pkg, "Sqrt", luar.New(L, math.Sqrt))
|
||||
L.SetField(pkg, "Tan", luar.New(L, math.Tan))
|
||||
L.SetField(pkg, "Tanh", luar.New(L, math.Tanh))
|
||||
L.SetField(pkg, "Trunc", luar.New(L, math.Trunc))
|
||||
L.SetField(pkg, "Y0", luar.New(L, math.Y0))
|
||||
L.SetField(pkg, "Y1", luar.New(L, math.Y1))
|
||||
L.SetField(pkg, "Yn", luar.New(L, math.Yn))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportMathRand() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "ExpFloat64", luar.New(L, rand.ExpFloat64))
|
||||
L.SetField(pkg, "Float32", luar.New(L, rand.Float32))
|
||||
L.SetField(pkg, "Float64", luar.New(L, rand.Float64))
|
||||
L.SetField(pkg, "Int", luar.New(L, rand.Int))
|
||||
L.SetField(pkg, "Int31", luar.New(L, rand.Int31))
|
||||
L.SetField(pkg, "Int31n", luar.New(L, rand.Int31n))
|
||||
L.SetField(pkg, "Int63", luar.New(L, rand.Int63))
|
||||
L.SetField(pkg, "Int63n", luar.New(L, rand.Int63n))
|
||||
L.SetField(pkg, "Intn", luar.New(L, rand.Intn))
|
||||
L.SetField(pkg, "NormFloat64", luar.New(L, rand.NormFloat64))
|
||||
L.SetField(pkg, "Perm", luar.New(L, rand.Perm))
|
||||
L.SetField(pkg, "Seed", luar.New(L, rand.Seed))
|
||||
L.SetField(pkg, "Uint32", luar.New(L, rand.Uint32))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportOs() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Args", luar.New(L, os.Args))
|
||||
L.SetField(pkg, "Chdir", luar.New(L, os.Chdir))
|
||||
L.SetField(pkg, "Chmod", luar.New(L, os.Chmod))
|
||||
L.SetField(pkg, "Chown", luar.New(L, os.Chown))
|
||||
L.SetField(pkg, "Chtimes", luar.New(L, os.Chtimes))
|
||||
L.SetField(pkg, "Clearenv", luar.New(L, os.Clearenv))
|
||||
L.SetField(pkg, "Create", luar.New(L, os.Create))
|
||||
L.SetField(pkg, "DevNull", luar.New(L, os.DevNull))
|
||||
L.SetField(pkg, "Environ", luar.New(L, os.Environ))
|
||||
L.SetField(pkg, "ErrExist", luar.New(L, os.ErrExist))
|
||||
L.SetField(pkg, "ErrInvalid", luar.New(L, os.ErrInvalid))
|
||||
L.SetField(pkg, "ErrNotExist", luar.New(L, os.ErrNotExist))
|
||||
L.SetField(pkg, "ErrPermission", luar.New(L, os.ErrPermission))
|
||||
L.SetField(pkg, "Exit", luar.New(L, os.Exit))
|
||||
L.SetField(pkg, "Expand", luar.New(L, os.Expand))
|
||||
L.SetField(pkg, "ExpandEnv", luar.New(L, os.ExpandEnv))
|
||||
L.SetField(pkg, "FindProcess", luar.New(L, os.FindProcess))
|
||||
L.SetField(pkg, "Getegid", luar.New(L, os.Getegid))
|
||||
L.SetField(pkg, "Getenv", luar.New(L, os.Getenv))
|
||||
L.SetField(pkg, "Geteuid", luar.New(L, os.Geteuid))
|
||||
L.SetField(pkg, "Getgid", luar.New(L, os.Getgid))
|
||||
L.SetField(pkg, "Getgroups", luar.New(L, os.Getgroups))
|
||||
L.SetField(pkg, "Getpagesize", luar.New(L, os.Getpagesize))
|
||||
L.SetField(pkg, "Getpid", luar.New(L, os.Getpid))
|
||||
L.SetField(pkg, "Getuid", luar.New(L, os.Getuid))
|
||||
L.SetField(pkg, "Getwd", luar.New(L, os.Getwd))
|
||||
L.SetField(pkg, "Hostname", luar.New(L, os.Hostname))
|
||||
L.SetField(pkg, "Interrupt", luar.New(L, os.Interrupt))
|
||||
L.SetField(pkg, "IsExist", luar.New(L, os.IsExist))
|
||||
L.SetField(pkg, "IsNotExist", luar.New(L, os.IsNotExist))
|
||||
L.SetField(pkg, "IsPathSeparator", luar.New(L, os.IsPathSeparator))
|
||||
L.SetField(pkg, "IsPermission", luar.New(L, os.IsPermission))
|
||||
L.SetField(pkg, "Kill", luar.New(L, os.Kill))
|
||||
L.SetField(pkg, "Lchown", luar.New(L, os.Lchown))
|
||||
L.SetField(pkg, "Link", luar.New(L, os.Link))
|
||||
L.SetField(pkg, "Lstat", luar.New(L, os.Lstat))
|
||||
L.SetField(pkg, "Mkdir", luar.New(L, os.Mkdir))
|
||||
L.SetField(pkg, "MkdirAll", luar.New(L, os.MkdirAll))
|
||||
L.SetField(pkg, "ModeAppend", luar.New(L, os.ModeAppend))
|
||||
L.SetField(pkg, "ModeCharDevice", luar.New(L, os.ModeCharDevice))
|
||||
L.SetField(pkg, "ModeDevice", luar.New(L, os.ModeDevice))
|
||||
L.SetField(pkg, "ModeDir", luar.New(L, os.ModeDir))
|
||||
L.SetField(pkg, "ModeExclusive", luar.New(L, os.ModeExclusive))
|
||||
L.SetField(pkg, "ModeNamedPipe", luar.New(L, os.ModeNamedPipe))
|
||||
L.SetField(pkg, "ModePerm", luar.New(L, os.ModePerm))
|
||||
L.SetField(pkg, "ModeSetgid", luar.New(L, os.ModeSetgid))
|
||||
L.SetField(pkg, "ModeSetuid", luar.New(L, os.ModeSetuid))
|
||||
L.SetField(pkg, "ModeSocket", luar.New(L, os.ModeSocket))
|
||||
L.SetField(pkg, "ModeSticky", luar.New(L, os.ModeSticky))
|
||||
L.SetField(pkg, "ModeSymlink", luar.New(L, os.ModeSymlink))
|
||||
L.SetField(pkg, "ModeTemporary", luar.New(L, os.ModeTemporary))
|
||||
L.SetField(pkg, "ModeType", luar.New(L, os.ModeType))
|
||||
L.SetField(pkg, "NewFile", luar.New(L, os.NewFile))
|
||||
L.SetField(pkg, "NewSyscallError", luar.New(L, os.NewSyscallError))
|
||||
L.SetField(pkg, "O_APPEND", luar.New(L, os.O_APPEND))
|
||||
L.SetField(pkg, "O_CREATE", luar.New(L, os.O_CREATE))
|
||||
L.SetField(pkg, "O_EXCL", luar.New(L, os.O_EXCL))
|
||||
L.SetField(pkg, "O_RDONLY", luar.New(L, os.O_RDONLY))
|
||||
L.SetField(pkg, "O_RDWR", luar.New(L, os.O_RDWR))
|
||||
L.SetField(pkg, "O_SYNC", luar.New(L, os.O_SYNC))
|
||||
L.SetField(pkg, "O_TRUNC", luar.New(L, os.O_TRUNC))
|
||||
L.SetField(pkg, "O_WRONLY", luar.New(L, os.O_WRONLY))
|
||||
L.SetField(pkg, "Open", luar.New(L, os.Open))
|
||||
L.SetField(pkg, "OpenFile", luar.New(L, os.OpenFile))
|
||||
L.SetField(pkg, "PathListSeparator", luar.New(L, os.PathListSeparator))
|
||||
L.SetField(pkg, "PathSeparator", luar.New(L, os.PathSeparator))
|
||||
L.SetField(pkg, "Pipe", luar.New(L, os.Pipe))
|
||||
L.SetField(pkg, "Readlink", luar.New(L, os.Readlink))
|
||||
L.SetField(pkg, "Remove", luar.New(L, os.Remove))
|
||||
L.SetField(pkg, "RemoveAll", luar.New(L, os.RemoveAll))
|
||||
L.SetField(pkg, "Rename", luar.New(L, os.Rename))
|
||||
L.SetField(pkg, "SEEK_CUR", luar.New(L, os.SEEK_CUR))
|
||||
L.SetField(pkg, "SEEK_END", luar.New(L, os.SEEK_END))
|
||||
L.SetField(pkg, "SEEK_SET", luar.New(L, os.SEEK_SET))
|
||||
L.SetField(pkg, "SameFile", luar.New(L, os.SameFile))
|
||||
L.SetField(pkg, "Setenv", luar.New(L, os.Setenv))
|
||||
L.SetField(pkg, "StartProcess", luar.New(L, os.StartProcess))
|
||||
L.SetField(pkg, "Stat", luar.New(L, os.Stat))
|
||||
L.SetField(pkg, "Stderr", luar.New(L, os.Stderr))
|
||||
L.SetField(pkg, "Stdin", luar.New(L, os.Stdin))
|
||||
L.SetField(pkg, "Stdout", luar.New(L, os.Stdout))
|
||||
L.SetField(pkg, "Symlink", luar.New(L, os.Symlink))
|
||||
L.SetField(pkg, "TempDir", luar.New(L, os.TempDir))
|
||||
L.SetField(pkg, "Truncate", luar.New(L, os.Truncate))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportRuntime() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "GC", luar.New(L, runtime.GC))
|
||||
L.SetField(pkg, "GOARCH", luar.New(L, runtime.GOARCH))
|
||||
L.SetField(pkg, "GOMAXPROCS", luar.New(L, runtime.GOMAXPROCS))
|
||||
L.SetField(pkg, "GOOS", luar.New(L, runtime.GOOS))
|
||||
L.SetField(pkg, "GOROOT", luar.New(L, runtime.GOROOT))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportPath() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Base", luar.New(L, path.Base))
|
||||
L.SetField(pkg, "Clean", luar.New(L, path.Clean))
|
||||
L.SetField(pkg, "Dir", luar.New(L, path.Dir))
|
||||
L.SetField(pkg, "ErrBadPattern", luar.New(L, path.ErrBadPattern))
|
||||
L.SetField(pkg, "Ext", luar.New(L, path.Ext))
|
||||
L.SetField(pkg, "IsAbs", luar.New(L, path.IsAbs))
|
||||
L.SetField(pkg, "Join", luar.New(L, path.Join))
|
||||
L.SetField(pkg, "Match", luar.New(L, path.Match))
|
||||
L.SetField(pkg, "Split", luar.New(L, path.Split))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportFilePath() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Join", luar.New(L, filepath.Join))
|
||||
L.SetField(pkg, "Clean", luar.New(L, filepath.Join))
|
||||
L.SetField(pkg, "Abs", luar.New(L, filepath.Abs))
|
||||
L.SetField(pkg, "Base", luar.New(L, filepath.Base))
|
||||
L.SetField(pkg, "Clean", luar.New(L, filepath.Clean))
|
||||
L.SetField(pkg, "Dir", luar.New(L, filepath.Dir))
|
||||
L.SetField(pkg, "EvalSymlinks", luar.New(L, filepath.EvalSymlinks))
|
||||
L.SetField(pkg, "Ext", luar.New(L, filepath.Ext))
|
||||
L.SetField(pkg, "FromSlash", luar.New(L, filepath.FromSlash))
|
||||
L.SetField(pkg, "Glob", luar.New(L, filepath.Glob))
|
||||
L.SetField(pkg, "HasPrefix", luar.New(L, filepath.HasPrefix))
|
||||
L.SetField(pkg, "IsAbs", luar.New(L, filepath.IsAbs))
|
||||
L.SetField(pkg, "Join", luar.New(L, filepath.Join))
|
||||
L.SetField(pkg, "Match", luar.New(L, filepath.Match))
|
||||
L.SetField(pkg, "Rel", luar.New(L, filepath.Rel))
|
||||
L.SetField(pkg, "Split", luar.New(L, filepath.Split))
|
||||
L.SetField(pkg, "SplitList", luar.New(L, filepath.SplitList))
|
||||
L.SetField(pkg, "ToSlash", luar.New(L, filepath.ToSlash))
|
||||
L.SetField(pkg, "VolumeName", luar.New(L, filepath.VolumeName))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportStrings() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Contains", luar.New(L, strings.Contains))
|
||||
L.SetField(pkg, "ContainsAny", luar.New(L, strings.ContainsAny))
|
||||
L.SetField(pkg, "ContainsRune", luar.New(L, strings.ContainsRune))
|
||||
L.SetField(pkg, "Count", luar.New(L, strings.Count))
|
||||
L.SetField(pkg, "EqualFold", luar.New(L, strings.EqualFold))
|
||||
L.SetField(pkg, "Fields", luar.New(L, strings.Fields))
|
||||
L.SetField(pkg, "FieldsFunc", luar.New(L, strings.FieldsFunc))
|
||||
L.SetField(pkg, "HasPrefix", luar.New(L, strings.HasPrefix))
|
||||
L.SetField(pkg, "HasSuffix", luar.New(L, strings.HasSuffix))
|
||||
L.SetField(pkg, "Index", luar.New(L, strings.Index))
|
||||
L.SetField(pkg, "IndexAny", luar.New(L, strings.IndexAny))
|
||||
L.SetField(pkg, "IndexByte", luar.New(L, strings.IndexByte))
|
||||
L.SetField(pkg, "IndexFunc", luar.New(L, strings.IndexFunc))
|
||||
L.SetField(pkg, "IndexRune", luar.New(L, strings.IndexRune))
|
||||
L.SetField(pkg, "Join", luar.New(L, strings.Join))
|
||||
L.SetField(pkg, "LastIndex", luar.New(L, strings.LastIndex))
|
||||
L.SetField(pkg, "LastIndexAny", luar.New(L, strings.LastIndexAny))
|
||||
L.SetField(pkg, "LastIndexFunc", luar.New(L, strings.LastIndexFunc))
|
||||
L.SetField(pkg, "Map", luar.New(L, strings.Map))
|
||||
L.SetField(pkg, "NewReader", luar.New(L, strings.NewReader))
|
||||
L.SetField(pkg, "NewReplacer", luar.New(L, strings.NewReplacer))
|
||||
L.SetField(pkg, "Repeat", luar.New(L, strings.Repeat))
|
||||
L.SetField(pkg, "Replace", luar.New(L, strings.Replace))
|
||||
L.SetField(pkg, "Split", luar.New(L, strings.Split))
|
||||
L.SetField(pkg, "SplitAfter", luar.New(L, strings.SplitAfter))
|
||||
L.SetField(pkg, "SplitAfterN", luar.New(L, strings.SplitAfterN))
|
||||
L.SetField(pkg, "SplitN", luar.New(L, strings.SplitN))
|
||||
L.SetField(pkg, "Title", luar.New(L, strings.Title))
|
||||
L.SetField(pkg, "ToLower", luar.New(L, strings.ToLower))
|
||||
L.SetField(pkg, "ToLowerSpecial", luar.New(L, strings.ToLowerSpecial))
|
||||
L.SetField(pkg, "ToTitle", luar.New(L, strings.ToTitle))
|
||||
L.SetField(pkg, "ToTitleSpecial", luar.New(L, strings.ToTitleSpecial))
|
||||
L.SetField(pkg, "ToUpper", luar.New(L, strings.ToUpper))
|
||||
L.SetField(pkg, "ToUpperSpecial", luar.New(L, strings.ToUpperSpecial))
|
||||
L.SetField(pkg, "Trim", luar.New(L, strings.Trim))
|
||||
L.SetField(pkg, "TrimFunc", luar.New(L, strings.TrimFunc))
|
||||
L.SetField(pkg, "TrimLeft", luar.New(L, strings.TrimLeft))
|
||||
L.SetField(pkg, "TrimLeftFunc", luar.New(L, strings.TrimLeftFunc))
|
||||
L.SetField(pkg, "TrimPrefix", luar.New(L, strings.TrimPrefix))
|
||||
L.SetField(pkg, "TrimRight", luar.New(L, strings.TrimRight))
|
||||
L.SetField(pkg, "TrimRightFunc", luar.New(L, strings.TrimRightFunc))
|
||||
L.SetField(pkg, "TrimSpace", luar.New(L, strings.TrimSpace))
|
||||
L.SetField(pkg, "TrimSuffix", luar.New(L, strings.TrimSuffix))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportRegexp() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Match", luar.New(L, regexp.Match))
|
||||
L.SetField(pkg, "MatchReader", luar.New(L, regexp.MatchReader))
|
||||
L.SetField(pkg, "MatchString", luar.New(L, regexp.MatchString))
|
||||
L.SetField(pkg, "QuoteMeta", luar.New(L, regexp.QuoteMeta))
|
||||
L.SetField(pkg, "Compile", luar.New(L, regexp.Compile))
|
||||
L.SetField(pkg, "CompilePOSIX", luar.New(L, regexp.CompilePOSIX))
|
||||
L.SetField(pkg, "MustCompile", luar.New(L, regexp.MustCompile))
|
||||
L.SetField(pkg, "MustCompilePOSIX", luar.New(L, regexp.MustCompilePOSIX))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportErrors() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "New", luar.New(L, errors.New))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ImportTime() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "After", luar.New(L, time.After))
|
||||
L.SetField(pkg, "Sleep", luar.New(L, time.Sleep))
|
||||
L.SetField(pkg, "Tick", luar.New(L, time.Tick))
|
||||
L.SetField(pkg, "Since", luar.New(L, time.Since))
|
||||
L.SetField(pkg, "FixedZone", luar.New(L, time.FixedZone))
|
||||
L.SetField(pkg, "LoadLocation", luar.New(L, time.LoadLocation))
|
||||
L.SetField(pkg, "NewTicker", luar.New(L, time.NewTicker))
|
||||
L.SetField(pkg, "Date", luar.New(L, time.Date))
|
||||
L.SetField(pkg, "Now", luar.New(L, time.Now))
|
||||
L.SetField(pkg, "Parse", luar.New(L, time.Parse))
|
||||
L.SetField(pkg, "ParseDuration", luar.New(L, time.ParseDuration))
|
||||
L.SetField(pkg, "ParseInLocation", luar.New(L, time.ParseInLocation))
|
||||
L.SetField(pkg, "Unix", luar.New(L, time.Unix))
|
||||
L.SetField(pkg, "AfterFunc", luar.New(L, time.AfterFunc))
|
||||
L.SetField(pkg, "NewTimer", luar.New(L, time.NewTimer))
|
||||
L.SetField(pkg, "Nanosecond", luar.New(L, time.Nanosecond))
|
||||
L.SetField(pkg, "Microsecond", luar.New(L, time.Microsecond))
|
||||
L.SetField(pkg, "Millisecond", luar.New(L, time.Millisecond))
|
||||
L.SetField(pkg, "Second", luar.New(L, time.Second))
|
||||
L.SetField(pkg, "Minute", luar.New(L, time.Minute))
|
||||
L.SetField(pkg, "Hour", luar.New(L, time.Hour))
|
||||
|
||||
return pkg
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/mattn/go-runewidth"
|
||||
"github.com/zyedidia/clipboard"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
@@ -69,9 +70,11 @@ type Messenger struct {
|
||||
gutterMessage bool
|
||||
}
|
||||
|
||||
func (m *Messenger) AddLog(msg string) {
|
||||
// AddLog sends a message to the log view
|
||||
func (m *Messenger) AddLog(msg ...interface{}) {
|
||||
logMessage := fmt.Sprint(msg...)
|
||||
buffer := m.getBuffer()
|
||||
buffer.insert(buffer.End(), []byte(msg+"\n"))
|
||||
buffer.insert(buffer.End(), []byte(logMessage+"\n"))
|
||||
buffer.Cursor.Loc = buffer.End()
|
||||
buffer.Cursor.Relocate()
|
||||
}
|
||||
@@ -463,8 +466,10 @@ func (m *Messenger) Display() {
|
||||
if m.hasMessage {
|
||||
if m.hasPrompt || globalSettings["infobar"].(bool) {
|
||||
runes := []rune(m.message + m.response)
|
||||
posx := 0
|
||||
for x := 0; x < len(runes); x++ {
|
||||
screen.SetContent(x, h-1, runes[x], nil, m.style)
|
||||
screen.SetContent(posx, h-1, runes[x], nil, m.style)
|
||||
posx += runewidth.RuneWidth(runes[x])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
synLinesUp = 75 // How many lines up to look to do syntax highlighting
|
||||
synLinesDown = 75 // How many lines down to look to do syntax highlighting
|
||||
doubleClickThreshold = 400 // How many milliseconds to wait before a second click is not a double click
|
||||
undoThreshold = 500 // If two events are less than n milliseconds apart, undo both of them
|
||||
autosaveTime = 8 // Number of seconds to wait before autosaving
|
||||
@@ -50,10 +48,6 @@ var (
|
||||
CommitHash = "Unknown"
|
||||
CompileDate = "Unknown"
|
||||
|
||||
// L is the lua state
|
||||
// This is the VM that runs the plugins
|
||||
L *lua.LState
|
||||
|
||||
// The list of views
|
||||
tabs []*Tab
|
||||
// This is the currently open tab
|
||||
@@ -183,6 +177,10 @@ func InitScreen() {
|
||||
screen, err = tcell.NewScreen()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
if err == tcell.ErrTermNotFound {
|
||||
fmt.Println("Micro does not recognize your terminal:", oldTerm)
|
||||
fmt.Println("Please go to https://github.com/zyedidia/mkinfo to read about how to fix this problem (it should be easy to fix).")
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
if err = screen.Init(); err != nil {
|
||||
@@ -196,7 +194,6 @@ func InitScreen() {
|
||||
}
|
||||
|
||||
screen.SetStyle(defStyle)
|
||||
screen.EnableMouse()
|
||||
}
|
||||
|
||||
// RedrawAll redraws everything -- all the views and the messenger
|
||||
@@ -248,6 +245,7 @@ func main() {
|
||||
flag.Usage = func() {
|
||||
fmt.Println("Usage: micro [OPTIONS] [FILE]...")
|
||||
fmt.Print("Micro's options can be set via command line arguments for quick adjustments. For real configuration, please use the bindings.json file (see 'help options').\n\n")
|
||||
flag.CommandLine.SetOutput(os.Stdout)
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
@@ -360,6 +358,7 @@ func main() {
|
||||
L.SetGlobal("Loc", luar.New(L, func(x, y int) Loc {
|
||||
return Loc{x, y}
|
||||
}))
|
||||
L.SetGlobal("WorkingDirectory", luar.New(L, os.Getwd))
|
||||
L.SetGlobal("JoinPaths", luar.New(L, filepath.Join))
|
||||
L.SetGlobal("DirectoryName", luar.New(L, filepath.Dir))
|
||||
L.SetGlobal("configDir", luar.New(L, configDir))
|
||||
@@ -380,6 +379,9 @@ func main() {
|
||||
L.SetGlobal("AddRuntimeFilesFromDirectory", luar.New(L, PluginAddRuntimeFilesFromDirectory))
|
||||
L.SetGlobal("AddRuntimeFileFromMemory", luar.New(L, PluginAddRuntimeFileFromMemory))
|
||||
|
||||
// Access to Go stdlib
|
||||
L.SetGlobal("import", luar.New(L, Import))
|
||||
|
||||
jobs = make(chan JobFunction, 100)
|
||||
events = make(chan tcell.Event, 100)
|
||||
autosave = make(chan bool)
|
||||
@@ -403,7 +405,9 @@ func main() {
|
||||
// Here is the event loop which runs in a separate thread
|
||||
go func() {
|
||||
for {
|
||||
events <- screen.PollEvent()
|
||||
if screen != nil {
|
||||
events <- screen.PollEvent()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/yuin/gopher-lua"
|
||||
"github.com/zyedidia/tcell"
|
||||
"layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
@@ -60,6 +61,16 @@ func LuaFunctionBinding(function string) func(*View, bool) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func LuaFunctionMouseBinding(function string) func(*View, bool, *tcell.EventMouse) bool {
|
||||
return func(v *View, _ bool, e *tcell.EventMouse) bool {
|
||||
_, err := Call(function, e)
|
||||
if err != nil {
|
||||
TermMessage(err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func unpack(old []string) []interface{} {
|
||||
new := make([]interface{}, len(old))
|
||||
for i, v := range old {
|
||||
@@ -119,11 +130,9 @@ func luaPluginName(name string) string {
|
||||
|
||||
// LoadPlugins loads the pre-installed plugins and the plugins located in ~/.config/micro/plugins
|
||||
func LoadPlugins() {
|
||||
|
||||
loadedPlugins = make(map[string]string)
|
||||
|
||||
for _, plugin := range ListRuntimeFiles(RTPlugin) {
|
||||
|
||||
pluginName := plugin.Name()
|
||||
if _, ok := loadedPlugins[pluginName]; ok {
|
||||
continue
|
||||
@@ -136,9 +145,8 @@ func LoadPlugins() {
|
||||
}
|
||||
|
||||
pluginLuaName := luaPluginName(pluginName)
|
||||
pluginDef := "\nlocal P = {}\n" + pluginLuaName + " = P\nsetmetatable(" + pluginLuaName + ", {__index = _G})\nsetfenv(1, P)\n"
|
||||
|
||||
if err := L.DoString(pluginDef + string(data)); err != nil {
|
||||
if err := LoadFile(pluginName, pluginName, string(data)); err != nil {
|
||||
TermMessage(err)
|
||||
continue
|
||||
}
|
||||
@@ -148,9 +156,8 @@ func LoadPlugins() {
|
||||
}
|
||||
|
||||
if _, err := os.Stat(configDir + "/init.lua"); err == nil {
|
||||
pluginDef := "\nlocal P = {}\n" + "init" + " = P\nsetmetatable(" + "init" + ", {__index = _G})\nsetfenv(1, P)\n"
|
||||
data, _ := ioutil.ReadFile(configDir + "/init.lua")
|
||||
if err := L.DoString(pluginDef + string(data)); err != nil {
|
||||
if err := LoadFile("init", configDir+"init.lua", string(data)); err != nil {
|
||||
TermMessage(err)
|
||||
}
|
||||
loadedPlugins["init"] = "init"
|
||||
|
||||
@@ -8,14 +8,15 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/flynn/json5"
|
||||
"github.com/yuin/gopher-lua"
|
||||
"github.com/zyedidia/json5/encoding/json5"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -434,6 +435,12 @@ func (pv *PluginVersion) DownloadAndInstall() error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
basepath := path.Dir(targetName)
|
||||
|
||||
if err := os.MkdirAll(basepath, dirPerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
content, err := f.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/blang/semver"
|
||||
"testing"
|
||||
|
||||
"github.com/zyedidia/json5/encoding/json5"
|
||||
"github.com/blang/semver"
|
||||
|
||||
"github.com/flynn/json5"
|
||||
)
|
||||
|
||||
func TestDependencyResolving(t *testing.T) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
@@ -11,7 +12,7 @@ var (
|
||||
lastSearch string
|
||||
|
||||
// Where should we start the search down from (or up from)
|
||||
searchStart int
|
||||
searchStart Loc
|
||||
|
||||
// Is there currently a search in progress
|
||||
searching bool
|
||||
@@ -43,7 +44,7 @@ func EndSearch() {
|
||||
}
|
||||
}
|
||||
|
||||
// exit the search mode, reset active search phrase, and clear status bar
|
||||
// ExitSearch exits the search mode, reset active search phrase, and clear status bar
|
||||
func ExitSearch(v *View) {
|
||||
lastSearch = ""
|
||||
searching = false
|
||||
@@ -91,6 +92,66 @@ func HandleSearchEvent(event tcell.Event, v *View) {
|
||||
return
|
||||
}
|
||||
|
||||
func searchDown(r *regexp.Regexp, v *View, start, end Loc) bool {
|
||||
for i := start.Y; i <= end.Y; i++ {
|
||||
var l []byte
|
||||
var charPos int
|
||||
if i == start.Y {
|
||||
runes := []rune(string(v.Buf.lines[i].data))
|
||||
l = []byte(string(runes[start.X:]))
|
||||
charPos = start.X
|
||||
|
||||
if strings.Contains(r.String(), "^") && start.X != 0 {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
l = v.Buf.lines[i].data
|
||||
}
|
||||
|
||||
match := r.FindIndex(l)
|
||||
|
||||
if match != nil {
|
||||
v.Cursor.SetSelectionStart(Loc{charPos + runePos(match[0], string(l)), i})
|
||||
v.Cursor.SetSelectionEnd(Loc{charPos + runePos(match[1], string(l)), i})
|
||||
v.Cursor.OrigSelection[0] = v.Cursor.CurSelection[0]
|
||||
v.Cursor.OrigSelection[1] = v.Cursor.CurSelection[1]
|
||||
v.Cursor.Loc = v.Cursor.CurSelection[1]
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func searchUp(r *regexp.Regexp, v *View, start, end Loc) bool {
|
||||
for i := start.Y; i >= end.Y; i-- {
|
||||
var l []byte
|
||||
if i == start.Y {
|
||||
runes := []rune(string(v.Buf.lines[i].data))
|
||||
l = []byte(string(runes[:start.X]))
|
||||
|
||||
if strings.Contains(r.String(), "$") && start.X != Count(string(l)) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
l = v.Buf.lines[i].data
|
||||
}
|
||||
|
||||
match := r.FindIndex(l)
|
||||
|
||||
if match != nil {
|
||||
v.Cursor.SetSelectionStart(Loc{runePos(match[0], string(l)), i})
|
||||
v.Cursor.SetSelectionEnd(Loc{runePos(match[1], string(l)), i})
|
||||
v.Cursor.OrigSelection[0] = v.Cursor.CurSelection[0]
|
||||
v.Cursor.OrigSelection[1] = v.Cursor.CurSelection[1]
|
||||
v.Cursor.Loc = v.Cursor.CurSelection[1]
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Search searches in the view for the given regex. The down bool
|
||||
// specifies whether it should search down from the searchStart position
|
||||
// or up from there
|
||||
@@ -98,15 +159,6 @@ func Search(searchStr string, v *View, down bool) {
|
||||
if searchStr == "" {
|
||||
return
|
||||
}
|
||||
var str string
|
||||
var charPos int
|
||||
text := v.Buf.String()
|
||||
if down {
|
||||
str = string([]rune(text)[searchStart:])
|
||||
charPos = searchStart
|
||||
} else {
|
||||
str = string([]rune(text)[:searchStart])
|
||||
}
|
||||
r, err := regexp.Compile(searchStr)
|
||||
if v.Buf.Settings["ignorecase"].(bool) {
|
||||
r, err = regexp.Compile("(?i)" + searchStr)
|
||||
@@ -114,37 +166,22 @@ func Search(searchStr string, v *View, down bool) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
matches := r.FindAllStringIndex(str, -1)
|
||||
var match []int
|
||||
if matches == nil {
|
||||
// Search the entire buffer now
|
||||
matches = r.FindAllStringIndex(text, -1)
|
||||
charPos = 0
|
||||
if matches == nil {
|
||||
v.Cursor.ResetSelection()
|
||||
return
|
||||
}
|
||||
|
||||
if !down {
|
||||
match = matches[len(matches)-1]
|
||||
} else {
|
||||
match = matches[0]
|
||||
var found bool
|
||||
if down {
|
||||
found = searchDown(r, v, searchStart, v.Buf.End())
|
||||
if !found {
|
||||
found = searchDown(r, v, v.Buf.Start(), searchStart)
|
||||
}
|
||||
str = text
|
||||
}
|
||||
|
||||
if !down {
|
||||
match = matches[len(matches)-1]
|
||||
} else {
|
||||
match = matches[0]
|
||||
found = searchUp(r, v, searchStart, v.Buf.Start())
|
||||
if !found {
|
||||
found = searchUp(r, v, v.Buf.End(), searchStart)
|
||||
}
|
||||
}
|
||||
|
||||
if match[0] == match[1] {
|
||||
return
|
||||
if found {
|
||||
lastSearch = searchStr
|
||||
} else {
|
||||
v.Cursor.ResetSelection()
|
||||
}
|
||||
|
||||
v.Cursor.SetSelectionStart(FromCharPos(charPos+runePos(match[0], str), v.Buf))
|
||||
v.Cursor.SetSelectionEnd(FromCharPos(charPos+runePos(match[1], str), v.Buf))
|
||||
v.Cursor.Loc = v.Cursor.CurSelection[1]
|
||||
lastSearch = searchStr
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -8,8 +9,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/flynn/json5"
|
||||
"github.com/zyedidia/glob"
|
||||
"github.com/zyedidia/json5/encoding/json5"
|
||||
)
|
||||
|
||||
type optionValidator func(string, interface{}) error
|
||||
@@ -17,6 +18,8 @@ type optionValidator func(string, interface{}) error
|
||||
// The options that the user can set
|
||||
var globalSettings map[string]interface{}
|
||||
|
||||
var invalidSettings bool
|
||||
|
||||
// Options with validators
|
||||
var optionValidators = map[string]optionValidator{
|
||||
"tabsize": validatePositiveValue,
|
||||
@@ -24,10 +27,12 @@ var optionValidators = map[string]optionValidator{
|
||||
"scrollspeed": validateNonNegativeValue,
|
||||
"colorscheme": validateColorscheme,
|
||||
"colorcolumn": validateNonNegativeValue,
|
||||
"fileformat": validateLineEnding,
|
||||
}
|
||||
|
||||
// InitGlobalSettings initializes the options map and sets all options to their default values
|
||||
func InitGlobalSettings() {
|
||||
invalidSettings = false
|
||||
defaults := DefaultGlobalSettings()
|
||||
var parsed map[string]interface{}
|
||||
|
||||
@@ -38,12 +43,14 @@ func InitGlobalSettings() {
|
||||
if !strings.HasPrefix(string(input), "null") {
|
||||
if err != nil {
|
||||
TermMessage("Error reading settings.json file: " + err.Error())
|
||||
invalidSettings = true
|
||||
return
|
||||
}
|
||||
|
||||
err = json5.Unmarshal(input, &parsed)
|
||||
if err != nil {
|
||||
TermMessage("Error reading settings.json:", err.Error())
|
||||
invalidSettings = true
|
||||
}
|
||||
} else {
|
||||
writeSettings = true
|
||||
@@ -71,6 +78,7 @@ func InitGlobalSettings() {
|
||||
// InitLocalSettings scans the json in settings.json and sets the options locally based
|
||||
// on whether the buffer matches the glob
|
||||
func InitLocalSettings(buf *Buffer) {
|
||||
invalidSettings = false
|
||||
var parsed map[string]interface{}
|
||||
|
||||
filename := configDir + "/settings.json"
|
||||
@@ -78,12 +86,14 @@ func InitLocalSettings(buf *Buffer) {
|
||||
input, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
TermMessage("Error reading settings.json file: " + err.Error())
|
||||
invalidSettings = true
|
||||
return
|
||||
}
|
||||
|
||||
err = json5.Unmarshal(input, &parsed)
|
||||
if err != nil {
|
||||
TermMessage("Error reading settings.json:", err.Error())
|
||||
invalidSettings = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +116,11 @@ func InitLocalSettings(buf *Buffer) {
|
||||
|
||||
// WriteSettings writes the settings to the specified filename as JSON
|
||||
func WriteSettings(filename string) error {
|
||||
if invalidSettings {
|
||||
// Do not write the settings if there was an error when reading them
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
if _, e := os.Stat(configDir); e == nil {
|
||||
parsed := make(map[string]interface{})
|
||||
@@ -124,6 +139,7 @@ func WriteSettings(filename string) error {
|
||||
err = json5.Unmarshal(input, &parsed)
|
||||
if err != nil {
|
||||
TermMessage("Error reading settings.json:", err.Error())
|
||||
invalidSettings = true
|
||||
}
|
||||
|
||||
for k, v := range parsed {
|
||||
@@ -136,7 +152,7 @@ func WriteSettings(filename string) error {
|
||||
}
|
||||
}
|
||||
|
||||
txt, _ := json5.MarshalIndent(parsed, "", " ")
|
||||
txt, _ := json.MarshalIndent(parsed, "", " ")
|
||||
err = ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
}
|
||||
return err
|
||||
@@ -205,6 +221,8 @@ func DefaultGlobalSettings() map[string]interface{} {
|
||||
},
|
||||
"pluginrepos": []string{},
|
||||
"useprimary": true,
|
||||
"fileformat": "unix",
|
||||
"mouse": true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +254,8 @@ func DefaultLocalSettings() map[string]interface{} {
|
||||
"tabsize": float64(4),
|
||||
"tabstospaces": false,
|
||||
"useprimary": true,
|
||||
"fileformat": "unix",
|
||||
"mouse": true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,6 +370,10 @@ func SetLocalOption(option, value string, view *View) error {
|
||||
buf.UpdateRules()
|
||||
}
|
||||
|
||||
if option == "fileformat" {
|
||||
buf.IsModified = true
|
||||
}
|
||||
|
||||
if option == "syntax" {
|
||||
if !nativeValue.(bool) {
|
||||
buf.ClearMatches()
|
||||
@@ -358,6 +382,14 @@ func SetLocalOption(option, value string, view *View) error {
|
||||
}
|
||||
}
|
||||
|
||||
if option == "mouse" {
|
||||
if !nativeValue.(bool) {
|
||||
screen.DisableMouse()
|
||||
} else {
|
||||
screen.EnableMouse()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -430,3 +462,17 @@ func validateColorscheme(option string, value interface{}) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateLineEnding(option string, value interface{}) error {
|
||||
endingType, ok := value.(string)
|
||||
|
||||
if !ok {
|
||||
return errors.New("Expected string type for file format")
|
||||
}
|
||||
|
||||
if endingType != "unix" && endingType != "dos" {
|
||||
return errors.New("File format must be either 'unix' or 'dos'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ func (sline *Statusline) Display() {
|
||||
// Add the filetype
|
||||
file += " " + sline.view.Buf.FileType()
|
||||
|
||||
file += " " + sline.view.Buf.Settings["fileformat"].(string)
|
||||
|
||||
rightText := ""
|
||||
if len(helpBinding) > 0 {
|
||||
rightText = helpBinding + " for help "
|
||||
|
||||
@@ -36,11 +36,7 @@ func NumOccurrences(s string, c byte) int {
|
||||
|
||||
// Spaces returns a string with n spaces
|
||||
func Spaces(n int) string {
|
||||
var str string
|
||||
for i := 0; i < n; i++ {
|
||||
str += " "
|
||||
}
|
||||
return str
|
||||
return strings.Repeat(" ", n)
|
||||
}
|
||||
|
||||
// Min takes the min of two ints
|
||||
@@ -267,11 +263,16 @@ func Abs(n int) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// FuncName returns the name of a given function object
|
||||
// FuncName returns the full name of a given function object
|
||||
func FuncName(i interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
||||
}
|
||||
|
||||
// ShortFuncName returns the name only of a given function object
|
||||
func ShortFuncName(i interface{}) string {
|
||||
return strings.TrimPrefix(runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name(), "main.(*View).")
|
||||
}
|
||||
|
||||
// SplitCommandArgs separates multiple command arguments which may be quoted.
|
||||
// The returned slice contains at least one string
|
||||
func SplitCommandArgs(input string) []string {
|
||||
|
||||
1
cmd/micro/vendor/github.com/blang/semver
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/blang/semver
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/blang/semver added at 4a1e882c79
1
cmd/micro/vendor/github.com/dustin/go-humanize
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/dustin/go-humanize
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/dustin/go-humanize added at 259d2a102b
1
cmd/micro/vendor/github.com/flynn/json5
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/flynn/json5
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/flynn/json5 added at 7620272ed6
1
cmd/micro/vendor/github.com/gdamore/encoding
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/gdamore/encoding
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/gdamore/encoding added at b23993cbb6
1
cmd/micro/vendor/github.com/go-errors/errors
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/go-errors/errors
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/go-errors/errors added at 8fa88b06e5
1
cmd/micro/vendor/github.com/lucasb-eyer/go-colorful
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/lucasb-eyer/go-colorful
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/lucasb-eyer/go-colorful added at c900de9dbb
1
cmd/micro/vendor/github.com/mattn/go-isatty
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/mattn/go-isatty
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/mattn/go-isatty added at fc9e8d8ef4
1
cmd/micro/vendor/github.com/mattn/go-runewidth
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/mattn/go-runewidth
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/mattn/go-runewidth added at 97311d9f77
1
cmd/micro/vendor/github.com/mitchellh/go-homedir
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/mitchellh/go-homedir
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/mitchellh/go-homedir added at b8bc1bf767
1
cmd/micro/vendor/github.com/sergi/go-diff
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/sergi/go-diff
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/sergi/go-diff added at feef008d51
1
cmd/micro/vendor/github.com/yuin/gopher-lua
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/yuin/gopher-lua
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/yuin/gopher-lua added at b402f3114e
1
cmd/micro/vendor/github.com/zyedidia/clipboard
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/zyedidia/clipboard
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/zyedidia/clipboard added at adacf416ce
1
cmd/micro/vendor/github.com/zyedidia/glob
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/zyedidia/glob
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/zyedidia/glob added at dd4023a66d
1
cmd/micro/vendor/github.com/zyedidia/poller
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/zyedidia/poller
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/zyedidia/poller added at ab09682913
1
cmd/micro/vendor/github.com/zyedidia/tcell
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/zyedidia/tcell
generated
vendored
Submodule
Submodule cmd/micro/vendor/github.com/zyedidia/tcell added at 898883d175
1
cmd/micro/vendor/golang.org/x/net
generated
vendored
Submodule
1
cmd/micro/vendor/golang.org/x/net
generated
vendored
Submodule
Submodule cmd/micro/vendor/golang.org/x/net added at 1a68b1313c
1
cmd/micro/vendor/golang.org/x/text
generated
vendored
Submodule
1
cmd/micro/vendor/golang.org/x/text
generated
vendored
Submodule
Submodule cmd/micro/vendor/golang.org/x/text added at 210eee5cf7
1
cmd/micro/vendor/gopkg.in/yaml.v2
generated
vendored
Submodule
1
cmd/micro/vendor/gopkg.in/yaml.v2
generated
vendored
Submodule
Submodule cmd/micro/vendor/gopkg.in/yaml.v2 added at cd8b52f826
1
cmd/micro/vendor/layeh.com/gopher-luar
generated
vendored
Submodule
1
cmd/micro/vendor/layeh.com/gopher-luar
generated
vendored
Submodule
Submodule cmd/micro/vendor/layeh.com/gopher-luar added at 16281577df
@@ -169,7 +169,7 @@ func (v *View) paste(clip string) {
|
||||
}
|
||||
clip = strings.Replace(clip, "\n", "\n"+leadingWS, -1)
|
||||
v.Buf.Insert(v.Cursor.Loc, clip)
|
||||
v.Cursor.Loc = v.Cursor.Loc.Move(Count(clip), v.Buf)
|
||||
// v.Cursor.Loc = v.Cursor.Loc.Move(Count(clip), v.Buf)
|
||||
v.freshClip = false
|
||||
messenger.Message("Pasted clipboard")
|
||||
}
|
||||
@@ -450,6 +450,45 @@ func (v *View) MoveToMouseClick(x, y int) {
|
||||
v.Cursor.LastVisualX = v.Cursor.GetVisualX()
|
||||
}
|
||||
|
||||
func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool {
|
||||
relocate := false
|
||||
readonlyBindingsList := []string{"Delete", "Insert", "Backspace", "Cut", "Play", "Paste", "Move", "Add", "DuplicateLine", "Macro"}
|
||||
for _, action := range actions {
|
||||
readonlyBindingsResult := false
|
||||
funcName := ShortFuncName(action)
|
||||
if v.Type.readonly == true {
|
||||
// check for readonly and if true only let key bindings get called if they do not change the contents.
|
||||
for _, readonlyBindings := range readonlyBindingsList {
|
||||
if strings.Contains(funcName, readonlyBindings) {
|
||||
readonlyBindingsResult = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !readonlyBindingsResult {
|
||||
// call the key binding
|
||||
relocate = action(v, true) || relocate
|
||||
// Macro
|
||||
if funcName != "ToggleMacro" && funcName != "PlayMacro" {
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, action)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return relocate
|
||||
}
|
||||
|
||||
func (v *View) SetCursor(c *Cursor) bool {
|
||||
if c == nil {
|
||||
return false
|
||||
}
|
||||
v.Cursor = c
|
||||
v.Buf.curCursor = c.Num
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// HandleEvent handles an event passed by the main loop
|
||||
func (v *View) HandleEvent(event tcell.Event) {
|
||||
// This bool determines whether the view is relocated at the end of the function
|
||||
@@ -462,123 +501,109 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
case *tcell.EventKey:
|
||||
// Check first if input is a key binding, if it is we 'eat' the input and don't insert a rune
|
||||
isBinding := false
|
||||
if e.Key() != tcell.KeyRune || e.Modifiers() != 0 {
|
||||
for key, actions := range bindings {
|
||||
if e.Key() == key.keyCode {
|
||||
if e.Key() == tcell.KeyRune {
|
||||
if e.Rune() != key.r {
|
||||
continue
|
||||
}
|
||||
for key, actions := range bindings {
|
||||
if e.Key() == key.keyCode {
|
||||
if e.Key() == tcell.KeyRune {
|
||||
if e.Rune() != key.r {
|
||||
continue
|
||||
}
|
||||
if e.Modifiers() == key.modifiers {
|
||||
}
|
||||
if e.Modifiers() == key.modifiers {
|
||||
for _, c := range v.Buf.cursors {
|
||||
ok := v.SetCursor(c)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
relocate = false
|
||||
isBinding = true
|
||||
for _, action := range actions {
|
||||
relocate = action(v, true) || relocate
|
||||
funcName := FuncName(action)
|
||||
if funcName != "main.(*View).ToggleMacro" && funcName != "main.(*View).PlayMacro" {
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, action)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
relocate = v.ExecuteActions(actions) || relocate
|
||||
}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
v.Buf.MergeCursors()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !isBinding && e.Key() == tcell.KeyRune {
|
||||
// Insert a character
|
||||
if v.Cursor.HasSelection() {
|
||||
v.Cursor.DeleteSelection()
|
||||
v.Cursor.ResetSelection()
|
||||
}
|
||||
v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
|
||||
v.Cursor.Right()
|
||||
// Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
|
||||
if v.Type.readonly == false {
|
||||
for _, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
|
||||
for pl := range loadedPlugins {
|
||||
_, err := Call(pl+".onRune", string(e.Rune()), v)
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
|
||||
TermMessage(err)
|
||||
// Insert a character
|
||||
if v.Cursor.HasSelection() {
|
||||
v.Cursor.DeleteSelection()
|
||||
v.Cursor.ResetSelection()
|
||||
}
|
||||
v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
|
||||
|
||||
for pl := range loadedPlugins {
|
||||
_, err := Call(pl+".onRune", string(e.Rune()), v)
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
|
||||
TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, e.Rune())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, e.Rune())
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
}
|
||||
}
|
||||
case *tcell.EventPaste:
|
||||
if !PreActionCall("Paste", v) {
|
||||
break
|
||||
// Check viewtype if readonly don't paste (readonly help and log view etc.)
|
||||
if v.Type.readonly == false {
|
||||
if !PreActionCall("Paste", v) {
|
||||
break
|
||||
}
|
||||
|
||||
for _, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
v.paste(e.Text())
|
||||
}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
|
||||
PostActionCall("Paste", v)
|
||||
}
|
||||
|
||||
v.paste(e.Text())
|
||||
|
||||
PostActionCall("Paste", v)
|
||||
case *tcell.EventMouse:
|
||||
x, y := e.Position()
|
||||
x -= v.lineNumOffset - v.leftCol + v.x
|
||||
y += v.Topline - v.y
|
||||
// Don't relocate for mouse events
|
||||
relocate = false
|
||||
|
||||
button := e.Buttons()
|
||||
|
||||
switch button {
|
||||
case tcell.Button1:
|
||||
// Left click
|
||||
if v.mouseReleased {
|
||||
v.MoveToMouseClick(x, y)
|
||||
if time.Since(v.lastClickTime)/time.Millisecond < doubleClickThreshold {
|
||||
if v.doubleClick {
|
||||
// Triple click
|
||||
v.lastClickTime = time.Now()
|
||||
|
||||
v.tripleClick = true
|
||||
v.doubleClick = false
|
||||
|
||||
v.Cursor.SelectLine()
|
||||
v.Cursor.CopySelection("primary")
|
||||
} else {
|
||||
// Double click
|
||||
v.lastClickTime = time.Now()
|
||||
|
||||
v.doubleClick = true
|
||||
v.tripleClick = false
|
||||
|
||||
v.Cursor.SelectWord()
|
||||
v.Cursor.CopySelection("primary")
|
||||
for key, actions := range bindings {
|
||||
if button == key.buttons && e.Modifiers() == key.modifiers {
|
||||
for _, c := range v.Buf.cursors {
|
||||
ok := v.SetCursor(c)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
v.doubleClick = false
|
||||
v.tripleClick = false
|
||||
v.lastClickTime = time.Now()
|
||||
|
||||
v.Cursor.OrigSelection[0] = v.Cursor.Loc
|
||||
v.Cursor.CurSelection[0] = v.Cursor.Loc
|
||||
v.Cursor.CurSelection[1] = v.Cursor.Loc
|
||||
relocate = v.ExecuteActions(actions) || relocate
|
||||
}
|
||||
v.mouseReleased = false
|
||||
} else if !v.mouseReleased {
|
||||
v.MoveToMouseClick(x, y)
|
||||
if v.tripleClick {
|
||||
v.Cursor.AddLineToSelection()
|
||||
} else if v.doubleClick {
|
||||
v.Cursor.AddWordToSelection()
|
||||
} else {
|
||||
v.Cursor.SetSelectionEnd(v.Cursor.Loc)
|
||||
v.Cursor.CopySelection("primary")
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
v.Buf.MergeCursors()
|
||||
}
|
||||
}
|
||||
|
||||
for key, actions := range mouseBindings {
|
||||
if button == key.buttons && e.Modifiers() == key.modifiers {
|
||||
for _, action := range actions {
|
||||
action(v, true, e)
|
||||
}
|
||||
}
|
||||
case tcell.Button2:
|
||||
// Middle mouse button was clicked,
|
||||
// We should paste primary
|
||||
v.PastePrimary(true)
|
||||
}
|
||||
|
||||
switch button {
|
||||
case tcell.ButtonNone:
|
||||
// Mouse event with no click
|
||||
if !v.mouseReleased {
|
||||
// Mouse was just released
|
||||
|
||||
x, y := e.Position()
|
||||
x -= v.lineNumOffset - v.leftCol + v.x
|
||||
y += v.Topline - v.y
|
||||
|
||||
// Relocating here isn't really necessary because the cursor will
|
||||
// be in the right place from the last mouse event
|
||||
// However, if we are running in a terminal that doesn't support mouse motion
|
||||
@@ -592,14 +617,6 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
}
|
||||
v.mouseReleased = true
|
||||
}
|
||||
case tcell.WheelUp:
|
||||
// Scroll up
|
||||
scrollspeed := int(v.Buf.Settings["scrollspeed"].(float64))
|
||||
v.ScrollUp(scrollspeed)
|
||||
case tcell.WheelDown:
|
||||
// Scroll down
|
||||
scrollspeed := int(v.Buf.Settings["scrollspeed"].(float64))
|
||||
v.ScrollDown(scrollspeed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,6 +631,10 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (v *View) mainCursor() bool {
|
||||
return v.Buf.curCursor == len(v.Buf.cursors)-1
|
||||
}
|
||||
|
||||
// GutterMessage creates a message in this view's gutter
|
||||
func (v *View) GutterMessage(section string, lineN int, msg string, kind int) {
|
||||
lineN--
|
||||
@@ -840,22 +861,20 @@ func (v *View) DisplayView() {
|
||||
}
|
||||
|
||||
charLoc := char.realLoc
|
||||
if v.Cursor.HasSelection() &&
|
||||
(charLoc.GreaterEqual(v.Cursor.CurSelection[0]) && charLoc.LessThan(v.Cursor.CurSelection[1]) ||
|
||||
charLoc.LessThan(v.Cursor.CurSelection[0]) && charLoc.GreaterEqual(v.Cursor.CurSelection[1])) {
|
||||
// The current character is selected
|
||||
lineStyle = defStyle.Reverse(true)
|
||||
for _, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
if v.Cursor.HasSelection() &&
|
||||
(charLoc.GreaterEqual(v.Cursor.CurSelection[0]) && charLoc.LessThan(v.Cursor.CurSelection[1]) ||
|
||||
charLoc.LessThan(v.Cursor.CurSelection[0]) && charLoc.GreaterEqual(v.Cursor.CurSelection[1])) {
|
||||
// The current character is selected
|
||||
lineStyle = defStyle.Reverse(true)
|
||||
|
||||
if style, ok := colorscheme["selection"]; ok {
|
||||
lineStyle = style
|
||||
if style, ok := colorscheme["selection"]; ok {
|
||||
lineStyle = style
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
|
||||
v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X && !cursorSet {
|
||||
screen.ShowCursor(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y)
|
||||
cursorSet = true
|
||||
}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
|
||||
if v.Buf.Settings["cursorline"].(bool) && tabs[curTab].CurView == v.Num &&
|
||||
!v.Cursor.HasSelection() && v.Cursor.Y == realLineN {
|
||||
@@ -866,6 +885,16 @@ func (v *View) DisplayView() {
|
||||
|
||||
screen.SetContent(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y, char.drawChar, nil, lineStyle)
|
||||
|
||||
for i, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
|
||||
v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X && (!cursorSet || i != 0) {
|
||||
ShowMultiCursor(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y, i)
|
||||
cursorSet = true
|
||||
}
|
||||
}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
|
||||
lastChar = char
|
||||
}
|
||||
}
|
||||
@@ -876,19 +905,27 @@ func (v *View) DisplayView() {
|
||||
var cx, cy int
|
||||
if lastChar != nil {
|
||||
lastX = xOffset + lastChar.visualLoc.X + lastChar.width
|
||||
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
|
||||
v.Cursor.Y == lastChar.realLoc.Y && v.Cursor.X == lastChar.realLoc.X+1 {
|
||||
screen.ShowCursor(lastX, yOffset+lastChar.visualLoc.Y)
|
||||
cx, cy = lastX, yOffset+lastChar.visualLoc.Y
|
||||
for i, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
|
||||
v.Cursor.Y == lastChar.realLoc.Y && v.Cursor.X == lastChar.realLoc.X+1 {
|
||||
ShowMultiCursor(lastX, yOffset+lastChar.visualLoc.Y, i)
|
||||
cx, cy = lastX, yOffset+lastChar.visualLoc.Y
|
||||
}
|
||||
}
|
||||
realLoc = Loc{lastChar.realLoc.X, realLineN}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
realLoc = Loc{lastChar.realLoc.X + 1, realLineN}
|
||||
visualLoc = Loc{lastX - xOffset, lastChar.visualLoc.Y}
|
||||
} else if len(line) == 0 {
|
||||
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
|
||||
v.Cursor.Y == realLineN {
|
||||
screen.ShowCursor(xOffset, yOffset+visualLineN)
|
||||
cx, cy = xOffset, yOffset+visualLineN
|
||||
for i, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
|
||||
v.Cursor.Y == realLineN {
|
||||
ShowMultiCursor(xOffset, yOffset+visualLineN, i)
|
||||
cx, cy = xOffset, yOffset+visualLineN
|
||||
}
|
||||
}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
lastX = xOffset
|
||||
realLoc = Loc{0, realLineN}
|
||||
visualLoc = Loc{0, visualLineN}
|
||||
@@ -908,7 +945,7 @@ func (v *View) DisplayView() {
|
||||
|
||||
if v.Buf.Settings["cursorline"].(bool) && tabs[curTab].CurView == v.Num &&
|
||||
!v.Cursor.HasSelection() && v.Cursor.Y == realLineN {
|
||||
for i := lastX; i < xOffset+v.Width; i++ {
|
||||
for i := lastX; i < xOffset+v.Width-v.lineNumOffset; i++ {
|
||||
style := GetColor("cursor-line")
|
||||
fg, _, _ := style.Decompose()
|
||||
style = style.Background(fg)
|
||||
@@ -930,6 +967,18 @@ func (v *View) DisplayView() {
|
||||
}
|
||||
}
|
||||
|
||||
// ShowMultiCursor will display a cursor at a location
|
||||
// If i == 0 then the terminal cursor will be used
|
||||
// Otherwise a fake cursor will be drawn at the position
|
||||
func ShowMultiCursor(x, y, i int) {
|
||||
if i == 0 {
|
||||
screen.ShowCursor(x, y)
|
||||
} else {
|
||||
r, _, _, _ := screen.GetContent(x, y)
|
||||
screen.SetContent(x, y, r, nil, defStyle.Reverse(true))
|
||||
}
|
||||
}
|
||||
|
||||
// Display renders the view, the cursor, and statusline
|
||||
func (v *View) Display() {
|
||||
if globalSettings["termtitle"].(bool) {
|
||||
@@ -937,7 +986,7 @@ func (v *View) Display() {
|
||||
}
|
||||
v.DisplayView()
|
||||
// Don't draw the cursor if it is out of the viewport or if it has a selection
|
||||
if (v.Cursor.Y-v.Topline < 0 || v.Cursor.Y-v.Topline > v.Height-1) || (v.Cursor.HasSelection() && v.Num == tabs[curTab].CurView) {
|
||||
if v.Num == tabs[curTab].CurView && (v.Cursor.Y-v.Topline < 0 || v.Cursor.Y-v.Topline > v.Height-1 || v.Cursor.HasSelection()) {
|
||||
screen.HideCursor()
|
||||
}
|
||||
_, screenH := screen.Size()
|
||||
|
||||
27
data/com.github.zyedidia.micro.metainfo.xml
Normal file
27
data/com.github.zyedidia.micro.metainfo.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component>
|
||||
<id>com.github.zyedidia.micro</id>
|
||||
<name>Micro Text Editor</name>
|
||||
<summary>A modern and intuitive terminal-based text editor</summary>
|
||||
<url type="homepage">https://micro-editor.github.io</url>
|
||||
<url type="bugtracker">https://github.com/zyedidia/micro</url>
|
||||
<metadata_license>MIT</metadata_license>
|
||||
<categories>
|
||||
<category>Development</category>
|
||||
<category>TextEditor</category>
|
||||
</categories>
|
||||
|
||||
<provides>
|
||||
<binary>micro</binary>
|
||||
</provides>
|
||||
<releases>
|
||||
<release version="1.2.0" date="2017-05-28" />
|
||||
</releases>
|
||||
<developer_name>Zachary Yedidia</developer_name>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<caption>Micro Text Editor editing its source code.</caption>
|
||||
<image type="source">https://raw.githubusercontent.com/zyedidia/micro/master/assets/micro-solarized.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
</component>
|
||||
27
runtime/colorschemes/darcula.micro
Normal file
27
runtime/colorschemes/darcula.micro
Normal file
@@ -0,0 +1,27 @@
|
||||
color-link default "#CCCCCC,#242424"
|
||||
color-link comment "#707070,#242424"
|
||||
color-link identifier "#FFC66D,#242424"
|
||||
color-link constant "#7A9EC2,#242424"
|
||||
color-link constant.string "#6A8759,#242424"
|
||||
color-link constant.string.char "#6A8759,#242424"
|
||||
color-link statement "#CC8242,#242424"
|
||||
color-link symbol "#CCCCCC,#242424"
|
||||
color-link preproc "#CC8242,#242424"
|
||||
color-link type "#CC8242,#242424"
|
||||
color-link special "#CC8242,#242424"
|
||||
color-link underlined "#D33682,#242424"
|
||||
color-link error "bold #CB4B16,#242424"
|
||||
color-link todo "bold #D33682,#242424"
|
||||
color-link statusline "#242424,#CCCCCC"
|
||||
color-link tabbar "#242424,#CCCCCC"
|
||||
color-link indent-char "#4F4F4F,#242424"
|
||||
color-link line-number "#666666,#242424"
|
||||
color-link current-line-number "#666666,#242424"
|
||||
color-link gutter-error "#CB4B16,#242424"
|
||||
color-link gutter-warning "#E6DB74,#242424"
|
||||
color-link cursor-line "#2C2C2C"
|
||||
color-link color-column "#2C2C2C"
|
||||
#No extended types; Plain brackets.
|
||||
color-link type.extended "default"
|
||||
#color-link symbol.brackets "default"
|
||||
color-link symbol.tag "#AE81FF,#242424"
|
||||
@@ -1,4 +1,3 @@
|
||||
# This is the monokai colorscheme
|
||||
color-link default "#F8F8F2,#282828"
|
||||
color-link comment "#75715E,#282828"
|
||||
color-link identifier "#66D9EF,#282828"
|
||||
@@ -14,7 +13,7 @@ color-link underlined "#D33682,#282828"
|
||||
color-link error "bold #CB4B16,#282828"
|
||||
color-link todo "bold #D33682,#282828"
|
||||
color-link statusline "#282828,#F8F8F2"
|
||||
color-link tabbar "#282828,#f8f8f2"
|
||||
color-link tabbar "#282828,#F8F8F2"
|
||||
color-link indent-char "#505050,#282828"
|
||||
color-link line-number "#AAAAAA,#323232"
|
||||
color-link current-line-number "#AAAAAA,#282828"
|
||||
@@ -22,6 +21,7 @@ color-link gutter-error "#CB4B16,#282828"
|
||||
color-link gutter-warning "#E6DB74,#282828"
|
||||
color-link cursor-line "#323232"
|
||||
color-link color-column "#323232"
|
||||
#No extended types; plain brackets
|
||||
#No extended types; Plain brackets.
|
||||
color-link type.extended "default"
|
||||
color-link symbol.brackets "default"
|
||||
#color-link symbol.brackets "default"
|
||||
color-link symbol.tag "#AE81FF,#282828"
|
||||
|
||||
@@ -2,22 +2,23 @@ color-link default "#839496,#002833"
|
||||
color-link comment "#586E75,#002833"
|
||||
color-link identifier "#268BD2,#002833"
|
||||
color-link constant "#2AA198,#002833"
|
||||
color-link constant.specialChar "#DC322F,#002833"
|
||||
color-link statement "#859900,#002833"
|
||||
color-link symbol "#859900,#002833"
|
||||
color-link preproc "#CB4B16,#002833"
|
||||
color-link type "#B58900,#002833"
|
||||
color-link special "#DC322F,#002833"
|
||||
color-link special "#268BD2,#002833"
|
||||
color-link underlined "#D33682,#002833"
|
||||
color-link error "bold #CB4B16,#002833"
|
||||
color-link todo "bold #D33682,#002833"
|
||||
color-link statusline "#003541,#839496"
|
||||
color-link tabbar "#003541,#839496"
|
||||
color-link indent-char "#586E75,#002833"
|
||||
color-link indent-char "#003541,#002833"
|
||||
color-link line-number "#586E75,#003541"
|
||||
color-link current-line-number "#586E75,#002833"
|
||||
color-link gutter-error "#003541,#CB4B16"
|
||||
color-link gutter-warning "#CB4B16,#002833"
|
||||
color-link cursor-line "#003541"
|
||||
color-link color-column "#003541"
|
||||
color-link type.extended "default"
|
||||
color-link symbol.brackets "default"
|
||||
color-link type.extended "#839496,#002833"
|
||||
color-link symbol.brackets "#839496,#002833"
|
||||
|
||||
@@ -10,12 +10,17 @@ Here are the possible commands that you can use.
|
||||
|
||||
* `replace "search" "value" flags`: This will replace `search` with `value`.
|
||||
The `flags` are optional.
|
||||
At this point, there is only one flag: `c`, which enables `check` mode
|
||||
which asks if you'd like to perform the replacement each time.
|
||||
At this point, there is only one flag: `-a`, which replaces all occurrences
|
||||
at once.
|
||||
|
||||
Note that `search` must be a valid regex. If one of the arguments
|
||||
does not have any spaces in it, you may omit the quotes.
|
||||
|
||||
* `replaceall "search" "value"`: This will replace `search` with `value` without
|
||||
user confirmation.
|
||||
|
||||
See `replace` command for more information.
|
||||
|
||||
* `set option value`: sets the option to value. See the `options` help topic
|
||||
for a list of options you can set.
|
||||
|
||||
|
||||
@@ -1,141 +1,126 @@
|
||||
#Default Keys
|
||||
# Default Keys
|
||||
|
||||
Below are simple charts of the default hotkeys and their functions.
|
||||
For more information about binding custom hotkeys or changing
|
||||
default bindings, please run `>help keybindings`
|
||||
default bindings, please run `> help keybindings`
|
||||
|
||||
Please remember that *all* keys here are rebindable!
|
||||
If you don't like it, you can change it!
|
||||
|
||||
(We are not responsible for you forgetting what you bind keys to.
|
||||
Do not open an issue because you forgot your keybindings.)
|
||||
# Power user
|
||||
|
||||
#Power user
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+E | Switch to the micro command prompt to run a command. |
|
||||
| | (See `>help commands` for a list of commands. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+B | Run shell commands in micro's current working directory.|
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
|-------- |-------------------------------------------------------------------------------------------------- |
|
||||
| Ctrl+E | Open a command prompt for running commands (see `> help commands` for a list of valid commands). |
|
||||
| Tab | In command prompt, it will autocomplete if possible. |
|
||||
| Ctrl+B | Run a shell command (this will close micro while your command executes). |
|
||||
|
||||
#Navigation
|
||||
# Navigation
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
|--------+---------------------------------------------------------+
|
||||
| Arrows | Move the cursor around your current document. |
|
||||
| | (Yes this is rebindable to the vim keys if you want.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Shift+ | Move and select text. |
|
||||
| Arrows | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Home | Move to the beginning of the current line. (Naturally.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| End | Move to the end of the current line. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| PageUp | Move cursor up lines quickly. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| PageDn | Move cursor down lines quickly. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+L | Jump to line in current file. ( Prompts for line # ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+W | Move between splits open in current tab. |
|
||||
| | (See vsplit and hsplit in `>help commands`) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+T | Open a new tab. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+, | Move to the previous tab in the tablist. |
|
||||
| | (This works like moving between file buffers in nano) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+. | Move to the next tab in the tablist. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
|-------------------------- |------------------------------------------------------------------------------------------ |
|
||||
| Arrows | Move the cursor around |
|
||||
| Shift+arrows | Move and select text |
|
||||
| Home or CtrlLeftArrow | Move to the beginning of the current line |
|
||||
| End or CtrlRightArrow | Move to the end of the current line |
|
||||
| AltLeftArrow | Move cursor one word left |
|
||||
| AltRightArrow | Move cursor one word right |
|
||||
| PageUp | Move cursor up one page |
|
||||
| PageDown | Move cursor down one page |
|
||||
| CtrlHome or CtrlUpArrow | Move cursor to start of document |
|
||||
| CtrlEnd or CtrlDownArrow | Move cursor to end of document |
|
||||
| Ctrl+L | Jump to a line in the file (prompts with #) |
|
||||
| Ctrl+W | Cycle between splits in the current tab (use `> vsplit` or `> hsplit` to create a split) |
|
||||
|
||||
#Find Operations
|
||||
# Tabs
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+F | Find text in current file. ( Prompts for text to find.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+N | Find next instance of current search in current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+P | Find prev instance of current search in current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
|-------- |------------------------- |
|
||||
| Ctrl+T | Open a new tab |
|
||||
| Alt+, | Previous tab |
|
||||
| Alt+. | Next tab |
|
||||
|
||||
#File Operations
|
||||
# Find Operations
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+Q | Close current file. ( Quits micro if last file open. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+O | Open a file. ( Prompts you to input filename. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+S | Save current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
|-------- |------------------------------------------ |
|
||||
| Ctrl+F | Find (opens prompt) |
|
||||
| Ctrl+N | Find next instance of current search |
|
||||
| Ctrl+P | Find previous instance of current search |
|
||||
|
||||
#Text operations
|
||||
# File Operations
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+A | Select all text in current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+X | Cut selected text. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+C | Copy selected text. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+V | Paste selected text. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+K | Cut current line. ( Can then be pasted with Ctrl+V) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+D | Duplicate current line. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+Z | Undo actions. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+Y | Redo actions. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
|-------- |---------------------------------------------------------------- |
|
||||
| Ctrl+Q | Close current file (quits micro if this is the last file open) |
|
||||
| Ctrl+O | Open a file (prompts for filename) |
|
||||
| Ctrl+S | Save current file |
|
||||
|
||||
#Other
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+G | Open the help file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+H | Alternate backspace. |
|
||||
| | (Some old terminals don't support the Backspace key .) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+R | Toggle the line number ruler. ( On the lefthand side.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
# Text operations
|
||||
|
||||
#Emacs style actions
|
||||
| Key | Description of function |
|
||||
|--------------------------------- |------------------------------------------ |
|
||||
| AltShiftRightArrow | Select word right |
|
||||
| AltShiftLeftArrow | Select word left |
|
||||
| ShiftHome or CtrlShiftLeftArrow | Select to start of current line |
|
||||
| ShiftEnd or CtrlShiftRightArrow | Select to end of current line |
|
||||
| CtrlShiftUpArrow | Select to start of file |
|
||||
| CtrlShiftDownArrow | Select to end of file |
|
||||
| Ctrl+X | Cut selected text |
|
||||
| Ctrl+C | Copy selected text |
|
||||
| Ctrl+V | Paste |
|
||||
| Ctrl+K | Cut current line |
|
||||
| Ctrl+D | Duplicate current line |
|
||||
| Ctrl+Z | Undo |
|
||||
| Ctrl+Y | Redo |
|
||||
| AltUpArrow | Move current line or selected lines up |
|
||||
| AltDownArrow | Move current line of selected lines down |
|
||||
| AltBackspace or AltCtrl+H | Delete word left |
|
||||
| Ctrl+A | Select all |
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+F | Move to the end of the next word. (To the next space.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+B | Move to the beginning of the previous word. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+A | Alternate Home key. ( Move to beginning of line. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+E | Alternate End key. ( Move to the end of line.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+P | Move cursor up. ( Same as up key. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+N | Move cursor down. ( Same as down key. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
# Macros
|
||||
|
||||
#Function keys.
|
||||
| Key | Description of function |
|
||||
|-------- |---------------------------------------------------------------------------------- |
|
||||
| Ctrl+U | Toggle macro recording (press Ctrl+U to start recording and press again to stop) |
|
||||
| Ctrl+J | Run latest recorded macro |
|
||||
|
||||
# Multiple cursors
|
||||
|
||||
| Key | Description of function |
|
||||
|---------------- |---------------------------------------------------------------------------------------------- |
|
||||
| Alt+N | Create new multiple cursor from selection (will select current word if no current selection) |
|
||||
| Alt+P | Remove latest multiple cursor |
|
||||
| Alt+C | Remove all multiple cursors (cancel) |
|
||||
| Alt+X | Skip multiple cursor selection |
|
||||
| Ctrl-MouseLeft | Place a multiple cursor at any location |
|
||||
|
||||
# Other
|
||||
|
||||
| Key | Description of function |
|
||||
|-------- |----------------------------------------------------------------------------------- |
|
||||
| Ctrl+G | Open help file |
|
||||
| Ctrl+H | Backspace (old terminals do not support the backspace key and use Ctrl+H instead) |
|
||||
| Ctrl+R | Toggle the line number ruler |
|
||||
|
||||
# Emacs style actions
|
||||
|
||||
| Key | Description of function |
|
||||
|------- |------------------------- |
|
||||
| Alt+F | Next word |
|
||||
| Alt+B | Previous word |
|
||||
| Alt+A | Move to start of line |
|
||||
| Alt+E | Move to end of line |
|
||||
|
||||
# Function keys.
|
||||
|
||||
Warning! The function keys may not work in all terminals!
|
||||
+--------+---------------------------------------------------------+
|
||||
| F1 | Open help. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| F2 | Save current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| F3 | Find in current file. ( Same as Ctrl+F ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| F4 | Close current file. (Quit if only file.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| F7 | Find in current file. (Same as Ctrl+F) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| F10 | Close current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Macros
|
||||
|
||||
Micro supports the use of keyboard macros. Simply press Ctrl+U to
|
||||
begin recording a macro and press Ctrl+U to stop recording.
|
||||
|
||||
Press Ctrl+J to run your recorded macro.
|
||||
| Key | Description of function |
|
||||
|----- |------------------------- |
|
||||
| F1 | Open help |
|
||||
| F2 | Save |
|
||||
| F3 | Find |
|
||||
| F4 | Quit |
|
||||
| F7 | Find |
|
||||
| F10 | Quit |
|
||||
|
||||
@@ -15,9 +15,9 @@ and you can see which commands are available by pressing tab, or by
|
||||
viewing the help topic `> help commands`. When I write `> ...` I mean press
|
||||
CtrlE and then type whatever is there.
|
||||
|
||||
Move the cursor around with the mouse or the arrow keys. Type `>help defaultkeys` to
|
||||
Move the cursor around with the mouse or the arrow keys. Type `> help defaultkeys` to
|
||||
get a quick, easy overview of the default hotkeys and what they do. For more info
|
||||
on rebinding keys, see type `>help keybindings`
|
||||
on rebinding keys, see type `> help keybindings`
|
||||
|
||||
If the colorscheme doesn't look good, you can change it with `> set colorscheme ...`.
|
||||
You can press tab to see the available colorschemes, or see more information with
|
||||
|
||||
@@ -131,9 +131,22 @@ HSplit
|
||||
PreviousSplit
|
||||
ToggleMacro
|
||||
PlayMacro
|
||||
Suspend (Linux only)
|
||||
ScrollUp
|
||||
ScrollDown
|
||||
SpawnMultiCursor
|
||||
RemoveMultiCursor
|
||||
RemoveAllMultiCursors
|
||||
SkipMultiCursor
|
||||
UnbindKey
|
||||
```
|
||||
|
||||
You can also bind some mouse actions (these must be bound to mouse buttons)
|
||||
```
|
||||
MousePress
|
||||
MouseMultiCursor
|
||||
```
|
||||
|
||||
Here is the list of all possible keys you can bind:
|
||||
|
||||
```
|
||||
@@ -262,6 +275,18 @@ Escape
|
||||
Enter
|
||||
```
|
||||
|
||||
You can also bind some mouse buttons (they may be bound to normal actions or mouse actions)
|
||||
|
||||
```
|
||||
MouseLeft
|
||||
MouseMiddle
|
||||
MouseRight
|
||||
MouseWheelUp
|
||||
MouseWheelDown
|
||||
MouseWheelLeft
|
||||
MouseWheelRight
|
||||
```
|
||||
|
||||
# Default keybinding configuration.
|
||||
|
||||
```json
|
||||
@@ -276,10 +301,10 @@ Enter
|
||||
"ShiftRight": "SelectRight",
|
||||
"AltLeft": "WordLeft",
|
||||
"AltRight": "WordRight",
|
||||
"AltShiftRight": "SelectWordRight",
|
||||
"AltShiftLeft": "SelectWordLeft",
|
||||
"AltUp": "MoveLinesUp",
|
||||
"AltDown": "MoveLinesDown",
|
||||
"AltShiftRight": "SelectWordRight",
|
||||
"AltShiftLeft": "SelectWordLeft",
|
||||
"CtrlLeft": "StartOfLine",
|
||||
"CtrlRight": "EndOfLine",
|
||||
"CtrlShiftLeft": "SelectToStartOfLine",
|
||||
@@ -291,13 +316,12 @@ Enter
|
||||
"CtrlShiftUp": "SelectToStart",
|
||||
"CtrlShiftDown": "SelectToEnd",
|
||||
"Enter": "InsertNewline",
|
||||
"Space": "InsertSpace",
|
||||
"CtrlH": "Backspace",
|
||||
"Backspace": "Backspace",
|
||||
"Alt-CtrlH": "DeleteWordLeft",
|
||||
"Alt-Backspace": "DeleteWordLeft",
|
||||
"Tab": "IndentSelection,InsertTab",
|
||||
"Backtab": "OutdentSelection",
|
||||
"Backtab": "OutdentSelection,OutdentLine",
|
||||
"CtrlO": "OpenFile",
|
||||
"CtrlS": "Save",
|
||||
"CtrlF": "Find",
|
||||
@@ -336,8 +360,6 @@ Enter
|
||||
"Alt-b": "WordLeft",
|
||||
"Alt-a": "StartOfLine",
|
||||
"Alt-e": "EndOfLine",
|
||||
"Alt-p": "CursorUp",
|
||||
"Alt-n": "CursorDown",
|
||||
|
||||
// Integration with file managers
|
||||
"F1": "ToggleHelp",
|
||||
@@ -347,10 +369,23 @@ Enter
|
||||
"F7": "Find",
|
||||
"F10": "Quit",
|
||||
"Esc": "Escape",
|
||||
|
||||
// Mouse bindings
|
||||
"MouseWheelUp": "ScrollUp",
|
||||
"MouseWheelDown": "ScrollDown",
|
||||
"MouseLeft": "MousePress",
|
||||
"MouseMiddle": "PastePrimary",
|
||||
"Ctrl-MouseLeft": "MouseMultiCursor",
|
||||
|
||||
// Multiple cursors bindings
|
||||
"Alt-n": "SpawnMultiCursor",
|
||||
"Alt-p": "RemoveMultiCursor",
|
||||
"Alt-c": "RemoveAllMultiCursors",
|
||||
"Alt-x": "SkipMultiCursor",
|
||||
}
|
||||
```
|
||||
|
||||
#Final notes
|
||||
# Final notes
|
||||
Note: On some old terminal emulators and on Windows machines, `CtrlH` should be used
|
||||
for backspace.
|
||||
|
||||
|
||||
@@ -155,6 +155,12 @@ Here are the options that you can set:
|
||||
|
||||
default value: `off`
|
||||
|
||||
* `mouse`: whether to enable mouse support. When mouse support is disabled, usually the terminal will be able
|
||||
to access mouse events which can be useful if you want to copy from the terminal instead of from micro (if
|
||||
over ssh for example, because the terminal has access to the local clipboard and micro does not).
|
||||
|
||||
default value: `on`
|
||||
|
||||
---
|
||||
|
||||
Default plugin options:
|
||||
@@ -173,6 +179,13 @@ Default plugin options:
|
||||
|
||||
default value: `on`
|
||||
|
||||
* `fileformat`: this determines what kind of line endings micro will use for the file. Unix line endings
|
||||
are just `\n` (lf) whereas dos line endings are `\r\n` (crlf). The two possible values for this option
|
||||
are `unix` and `dos`. The fileformat will be automatically detected and displayed on the statusline but
|
||||
this option is useful if you would like to change the line endings or if you are starting a new file.
|
||||
|
||||
default value: `unix`
|
||||
|
||||
Any option you set in the editor will be saved to the file
|
||||
~/.config/micro/settings.json so, in effect, your configuration file will be
|
||||
created for you. If you'd like to take your configuration with you to another
|
||||
|
||||
@@ -21,6 +21,16 @@ This is almost always the current view, which you can get with `CurView()` as we
|
||||
|
||||
All available actions are listed in the keybindings section of the help.
|
||||
|
||||
For callbacks to mouse actions, you are also given the event info:
|
||||
|
||||
```lua
|
||||
function onMousePress(view, event)
|
||||
local x, y = event:Position()
|
||||
|
||||
return false
|
||||
end
|
||||
```
|
||||
|
||||
These functions should also return a boolean specifying whether the view
|
||||
should be relocated to the cursor or not after the action is complete.
|
||||
|
||||
@@ -61,9 +71,11 @@ as Go's GOOS variable, so `darwin`, `windows`, `linux`, `freebsd`...)
|
||||
|
||||
* `Loc(x, y int) Loc`: returns a new `Loc` struct
|
||||
|
||||
* `JoinPaths(dir... string) string` combines multiple directories to a full path
|
||||
* `WorkingDirectory() string`: returns a rooted path name to the current working directory
|
||||
|
||||
* `DirectoryName(path string)` returns all but the last element of path ,typically the path's directory
|
||||
* `JoinPaths(dir... string) string`: combines multiple directories to a full path
|
||||
|
||||
* `DirectoryName(path string)`: returns all but the last element of path ,typically the path's directory
|
||||
|
||||
* `GetOption(name string)`: returns the value of the requested option
|
||||
|
||||
@@ -130,10 +142,31 @@ The possible methods which you can call using the `messenger` variable are:
|
||||
|
||||
* `messenger.Message(msg ...interface{})`
|
||||
* `messenger.Error(msg ...interface{})`
|
||||
* `messenger.YesNoPrompt(prompt string) (bool, bool)`
|
||||
* `messenger.YesNoPrompt(prompt string) (bool,bool)`
|
||||
* `messenger.Prompt(prompt, historyType string, completionType Completion) (string, bool)`
|
||||
* `messenger.AddLog(msg ...interface{})`
|
||||
|
||||
If you want a standard prompt, just use `messenger.Prompt(prompt, "", 0)`
|
||||
## Note
|
||||
`golang` function signatures use `.` and lua uses `:` so
|
||||
```go
|
||||
messenger.Message()
|
||||
```
|
||||
turns to
|
||||
```lua
|
||||
messenger:Message()
|
||||
```
|
||||
|
||||
If you want a standard prompt, just use
|
||||
```lua
|
||||
messenger:Prompt(prompt, "", 0)
|
||||
```
|
||||
|
||||
Debug or logging your plugin can be done with below lua example code.
|
||||
```lua
|
||||
messenger:AddLog("Message goes here ",pluginVariableToPrintHere)
|
||||
```
|
||||
In Micro Editor to see your plugin logging output press `ctrl E` then type `log`
|
||||
A logging window will open and any logging sent from your plugin will be displayed here.
|
||||
|
||||
# Adding help files, syntax files, or colorschemes in your plugin
|
||||
|
||||
@@ -156,25 +189,25 @@ See this example to learn how to use `MakeCompletion` and `MakeCommand`
|
||||
|
||||
```lua
|
||||
local function StartsWith(String,Start)
|
||||
String = String:upper()
|
||||
Start = Start:upper()
|
||||
return string.sub(String,1,string.len(Start))==Start
|
||||
String = String:upper()
|
||||
Start = Start:upper()
|
||||
return string.sub(String,1,string.len(Start))==Start
|
||||
end
|
||||
|
||||
function complete(input)
|
||||
local allCompletions = {"Hello", "World", "Foo", "Bar"}
|
||||
local result = {}
|
||||
|
||||
for i,v in pairs(allCompletions) do
|
||||
if StartsWith(v, input) then
|
||||
table.insert(result, v)
|
||||
end
|
||||
end
|
||||
return result
|
||||
local allCompletions = {"Hello", "World", "Foo", "Bar"}
|
||||
local result = {}
|
||||
|
||||
for i,v in pairs(allCompletions) do
|
||||
if StartsWith(v, input) then
|
||||
table.insert(result, v)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function foo(arg)
|
||||
messenger:Message(arg)
|
||||
messenger:Message(arg)
|
||||
end
|
||||
|
||||
MakeCommand("foo", "example.foo", MakeCompletion("example.complete"))
|
||||
|
||||
@@ -1085,6 +1085,7 @@ function onRune(r, v)
|
||||
-- when converting go structs to lua
|
||||
-- It needs to be dereferenced because the function expects a non pointer struct
|
||||
v.Buf:Insert(-v.Cursor.Loc, charAt(autoclosePairs[i], 2))
|
||||
v:CursorLeft(false)
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -1107,6 +1108,8 @@ function preInsertNewline(v)
|
||||
v:InsertNewline(false)
|
||||
v:InsertTab(false)
|
||||
v.Buf:Insert(-v.Cursor.Loc, "\n" .. ws)
|
||||
v:StartOfLine(false)
|
||||
v:CursorLeft(false)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -92,6 +92,10 @@ function split(str, sep)
|
||||
end
|
||||
|
||||
function basename(file)
|
||||
local name = string.gsub(file, "(.*/)(.*)", "%2")
|
||||
local sep = "/"
|
||||
if OS == "windows" then
|
||||
sep = "\\"
|
||||
end
|
||||
local name = string.gsub(file, "(.*" .. sep .. ")(.*)", "%2")
|
||||
return name
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ rules:
|
||||
- type.extended: "\\b(bool)\\b"
|
||||
- statement: "\\b(typename|mutable|volatile|register|explicit)\\b"
|
||||
- statement: "\\b(for|if|while|do|else|case|default|switch)\\b"
|
||||
- statement: "\\b(try|throw|catch|operator|new|delete)\\b"
|
||||
- statement: "\\b(try|throw|catch|operator|delete)\\b"
|
||||
- statement: "\\b(goto|continue|break|return)\\b"
|
||||
- preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)"
|
||||
- constant: "'([^'\\\\]|(\\\\[\"'abfnrtv\\\\]))'"
|
||||
|
||||
36
runtime/syntax/crontab.yaml
Normal file
36
runtime/syntax/crontab.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
filetype: crontab
|
||||
|
||||
detect:
|
||||
filename: "crontab$"
|
||||
header: "^#.*?/etc/crontab"
|
||||
|
||||
rules:
|
||||
# The time and date fields are:
|
||||
# field allowed values
|
||||
# ----- --------------
|
||||
# minute 0-59
|
||||
# hour 0-23
|
||||
# day of month 0-31
|
||||
# month 0-12 (or names, see below)
|
||||
# day of week 0-7 (0 or 7 is Sun, or use names)
|
||||
|
||||
- statement: "^([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)\\s+(.*)$\\n?"
|
||||
- constant: "^([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)\\s+([\\*0-9,\\-\\/]+)"
|
||||
|
||||
# Shell Values
|
||||
- type: "^[A-Z]+\\="
|
||||
|
||||
# Months and weekday keywords
|
||||
- type: "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec"
|
||||
- constant: "sun|mon|tue|wed|thu|fri|sat"
|
||||
- type: "\\@(reboot|yearly|annually|monthly|weekly|daily|midnight|hourly)"
|
||||
|
||||
# Conditionals
|
||||
- special: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|^|!|=|&|\\|)"
|
||||
|
||||
- comment:
|
||||
start: "#"
|
||||
end: "$"
|
||||
rules:
|
||||
- todo: "(TODO|XXX|FIXME):?"
|
||||
|
||||
41
runtime/syntax/julia.yaml
Normal file
41
runtime/syntax/julia.yaml
Normal file
@@ -0,0 +1,41 @@
|
||||
filetype: julia
|
||||
|
||||
detect:
|
||||
filename: "\\.jl$"
|
||||
header: "^#!.*/(env +)?julia( |$)"
|
||||
|
||||
rules:
|
||||
|
||||
# built-in objects
|
||||
- constant.bool: "\\b(true|false)\\b"
|
||||
# built-in attributes
|
||||
- constant: "__[A-Za-z0-9_]+__"
|
||||
# definitions
|
||||
- identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[(]"
|
||||
# keywords
|
||||
- statement: "\\b(begin|break|catch|continue|function|elseif|else|end|finally|for|global|local|if|include|using|require|macro|println|return|try|type|while|module)\\b"
|
||||
# decorators
|
||||
- identifier.macro: "@[A-Za-z0-9_]+"
|
||||
# operators
|
||||
- symbol.operator: "[-+*/|=%<>&~^]|\\b(and|not|or|is|in)\\b"
|
||||
# parentheses
|
||||
- symbol.brackets: "([(){}]|\\[|\\])"
|
||||
# numbers
|
||||
- constant.number: "\\b[0-9]+\\b"
|
||||
|
||||
- constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'"
|
||||
|
||||
- constant.string:
|
||||
start: "\"\"\""
|
||||
end: "\"\"\""
|
||||
rules: []
|
||||
|
||||
- constant.string:
|
||||
start: "'''"
|
||||
end: "'''"
|
||||
rules: []
|
||||
|
||||
- comment:
|
||||
start: "#"
|
||||
end: "$"
|
||||
rules: []
|
||||
@@ -1,7 +1,7 @@
|
||||
filetype: ledger
|
||||
|
||||
detect:
|
||||
filename: "(^|\\.|/)ledger|ldgr|beancount|bnct$"
|
||||
filename: "(^|\\.|/)(ledger|ldgr|beancount|bnct)$"
|
||||
|
||||
rules:
|
||||
- special: "^([0-9]{4}(/|-)[0-9]{2}(/|-)[0-9]{2}|[=~]) .*"
|
||||
|
||||
@@ -15,16 +15,24 @@ func main() {
|
||||
for _, f := range files {
|
||||
if strings.HasSuffix(f.Name(), ".yaml") {
|
||||
input, _ := ioutil.ReadFile(f.Name())
|
||||
_, err := highlight.ParseDef(input)
|
||||
//fmt.Println("Checking file -> ", f.Name())
|
||||
file, err := highlight.ParseFile(input)
|
||||
if err != nil {
|
||||
hadErr = true
|
||||
fmt.Printf("%s:\n", f.Name())
|
||||
fmt.Printf("Could not parse file -> %s:\n", f.Name())
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
_, err1 := highlight.ParseDef(file, nil)
|
||||
if err1 != nil {
|
||||
hadErr = true
|
||||
fmt.Printf("Could not parse input file using highlight.ParseDef(%s):\n", f.Name())
|
||||
fmt.Println(err1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hadErr {
|
||||
fmt.Println("No issues!")
|
||||
fmt.Println("No issues found!")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,11 +105,9 @@ func parseFile(text, filename string) (filetype, syntax, header string, rules []
|
||||
var start string
|
||||
var end string
|
||||
// Use m and s flags by default
|
||||
flags := "ms"
|
||||
if len(submatch) == 5 {
|
||||
// If len is 5 the user provided some additional flags
|
||||
color = string(submatch[1])
|
||||
flags += string(submatch[2])
|
||||
start = string(submatch[3])
|
||||
end = string(submatch[4])
|
||||
} else if len(submatch) == 4 {
|
||||
|
||||
55
runtime/syntax/twig.yaml
Normal file
55
runtime/syntax/twig.yaml
Normal file
@@ -0,0 +1,55 @@
|
||||
filetype: twig
|
||||
|
||||
detect:
|
||||
filename: "\\.twig$"
|
||||
|
||||
rules:
|
||||
- include: "html"
|
||||
- symbol.tag:
|
||||
start: "\\{\\{[[:space:]]"
|
||||
end: "[[:space:]]\\}\\}"
|
||||
rules:
|
||||
- identifier: "\\b(abs|batch|capitalize|convert|encoding|date(_modify)?|default|escape|first|format|join|json_encode|keys|last|length|lower|merge|nl2br|number_format|raw|replace|reverse|round|slice|sort|split|striptags|title|trim|upper|url_encode)\\b"
|
||||
- identifier.class: "\\b(attribute|block|constant|cycle|date|dump|include|max|min|parent|random|range|source|template_from_string)\\b"
|
||||
- type.keyword: "\\b(and|as|constant|defined|divisibleby|empty|even|false|in|is|iterable|not|null|odd|or|same(as)?|true|with)\\b"
|
||||
- symbol.operator: "[.:;,+*?|=!\\%]|<|>|/|-|&"
|
||||
- symbol.brackets: "[(){}]|\\[|\\]"
|
||||
- constant.number: "\\b[0-9]+\\b|\\b0x[0-9A-Fa-f]+\\b"
|
||||
- constant.string:
|
||||
start: "\""
|
||||
end: "\""
|
||||
skip: "\\\\"
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
- constant.string:
|
||||
start: "'"
|
||||
end: "'"
|
||||
skip: "\\\\"
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
- symbol.tag:
|
||||
start: "\\{%[[:space:]]"
|
||||
end: "[[:space:]]%\\}"
|
||||
rules:
|
||||
- identifier: "\\b(abs|batch|capitalize|convert|encoding|date(_modify)?|default|escape|first|format|join|json_encode|keys|last|length|lower|merge|nl2br|number_format|raw|replace|reverse|round|slice|sort|split|striptags|title|trim|upper|url_encode)\\b"
|
||||
- identifier.class: "\\b(attribute|block|constant|cycle|date|dump|include|max|min|parent|random|range|source|template_from_string)\\b"
|
||||
- type.keyword: "\\b(and|as|constant|defined|divisibleby|empty|even|false|in|is|iterable|not|null|odd|or|same(as)?|true|with)\\b"
|
||||
- symbol.operator: "[.:;,+*?|=!\\%]|<|>|/|-|&"
|
||||
- symbol.brackets: "[(){}]|\\[|\\]"
|
||||
- constant.number: "\\b[0-9]+\\b|\\b0x[0-9A-Fa-f]+\\b"
|
||||
- constant.string:
|
||||
start: "\""
|
||||
end: "\""
|
||||
skip: "\\\\"
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
- constant.string:
|
||||
start: "'"
|
||||
end: "'"
|
||||
skip: "\\\\"
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
- comment:
|
||||
start: "\\{#"
|
||||
end: "#\\}"
|
||||
rules: []
|
||||
@@ -4,7 +4,7 @@ detect:
|
||||
filename: "\\.vala$"
|
||||
|
||||
rules:
|
||||
- type: "\\b(float|double|bool|char|int|uint|short|long|void|(un)?signed)\\b"
|
||||
- type: "\\b(float|double|bool|u?char|u?int(8|16|32|64)?|u?short|u?long|void|s?size_t|unichar)\\b"
|
||||
- identifier.class: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[()]"
|
||||
- statement: "\\b(for|if|while|do|else|case|default|switch|try|throw|catch)\\b"
|
||||
- statement: "\\b(inline|typedef|struct|enum|union|extern|static|const)\\b"
|
||||
|
||||
@@ -9,6 +9,6 @@ rules:
|
||||
- constant.number: "\\b[0-9]+\\b"
|
||||
- symbol.operator: "[*:=]"
|
||||
- constant.bool: "\\b(true|false)\\b"
|
||||
- comment: "(^|[[:space:]])#([^{].*)?$"
|
||||
- comment: "(^|[[:space:]])!([^{].*)?$"
|
||||
- indent-char.whitespace: "[[:space:]]+$"
|
||||
- indent-char: " + +| + +"
|
||||
|
||||
@@ -15,16 +15,16 @@ rules:
|
||||
- special: "(^---|^\\.\\.\\.|^%YAML|^%TAG)"
|
||||
|
||||
- constant.string:
|
||||
start: "\""
|
||||
start: "(^| )\""
|
||||
end: "\""
|
||||
skip: "\\\\."
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
|
||||
- constant.string:
|
||||
start: "'"
|
||||
start: "(^| )'"
|
||||
end: "'"
|
||||
skip: "\\\\."
|
||||
skip: "(\\\\.)|('')"
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
|
||||
|
||||
@@ -14,5 +14,17 @@ apps:
|
||||
parts:
|
||||
micro:
|
||||
source: .
|
||||
plugin: go
|
||||
go-importpath: github.com/zyedidia/micro/cmd/micro
|
||||
source-type: git
|
||||
plugin: nil
|
||||
build-packages: [golang-go, make]
|
||||
prepare: |
|
||||
mkdir -p ../go/src/github.com/zyedidia/micro
|
||||
cp -R . ../go/src/github.com/zyedidia/micro
|
||||
build: |
|
||||
export GOPATH=$(pwd)/../go
|
||||
export GOBIN=$(pwd)/../go/bin
|
||||
cd ../go/src/github.com/zyedidia/micro
|
||||
make install
|
||||
install: |
|
||||
mkdir $SNAPCRAFT_PART_INSTALL/bin
|
||||
mv ../go/bin/micro $SNAPCRAFT_PART_INSTALL/bin/
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/zyedidia/micro/tools/semver"
|
||||
)
|
||||
|
||||
func getTag(match ...string) (string, *semver.PRVersion) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# This script creates the nightly release on Github for micro
|
||||
# It assumes that the binaries are in the current directory
|
||||
# You must have the correct Github access token to run this script
|
||||
|
||||
echo "Deleting old release"
|
||||
@@ -23,6 +22,10 @@ github-release release \
|
||||
--description "Autogenerated nightly build of micro" \
|
||||
--pre-release
|
||||
|
||||
echo "Cross compiling binaries"
|
||||
./cross-compile.sh $1
|
||||
mv ../binaries .
|
||||
|
||||
echo "Uploading OSX binary"
|
||||
github-release upload \
|
||||
--user zyedidia \
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# This script creates releases on Github for micro
|
||||
# It assumes that the binaries are in the current directory
|
||||
# You must have the correct Github access token to run this script
|
||||
|
||||
# $1 is the title, $2 is the description
|
||||
@@ -20,6 +19,10 @@ github-release release \
|
||||
--description "$2" \
|
||||
--pre-release
|
||||
|
||||
echo "Cross compiling binaries"
|
||||
./cross-compile.sh $1
|
||||
mv ../binaries .
|
||||
|
||||
echo "Uploading OSX binary"
|
||||
github-release upload \
|
||||
--user zyedidia \
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# This script creates releases on Github for micro
|
||||
# It assumes that the binaries are in the current directory
|
||||
# You must have the correct Github access token to run this script
|
||||
|
||||
# $1 is the title, $2 is the description
|
||||
@@ -19,6 +18,10 @@ github-release release \
|
||||
--name "$1" \
|
||||
--description "$2" \
|
||||
|
||||
echo "Cross compiling binaries"
|
||||
./cross-compile.sh $1
|
||||
mv ../binaries .
|
||||
|
||||
echo "Uploading OSX binary"
|
||||
github-release upload \
|
||||
--user zyedidia \
|
||||
|
||||
23
tools/semver/json.go
Normal file
23
tools/semver/json.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package semver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// MarshalJSON implements the encoding/json.Marshaler interface.
|
||||
func (v Version) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(v.String())
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the encoding/json.Unmarshaler interface.
|
||||
func (v *Version) UnmarshalJSON(data []byte) (err error) {
|
||||
var versionString string
|
||||
|
||||
if err = json.Unmarshal(data, &versionString); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
*v, err = Parse(versionString)
|
||||
|
||||
return
|
||||
}
|
||||
416
tools/semver/range.go
Normal file
416
tools/semver/range.go
Normal file
@@ -0,0 +1,416 @@
|
||||
package semver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type wildcardType int
|
||||
|
||||
const (
|
||||
noneWildcard wildcardType = iota
|
||||
majorWildcard wildcardType = 1
|
||||
minorWildcard wildcardType = 2
|
||||
patchWildcard wildcardType = 3
|
||||
)
|
||||
|
||||
func wildcardTypefromInt(i int) wildcardType {
|
||||
switch i {
|
||||
case 1:
|
||||
return majorWildcard
|
||||
case 2:
|
||||
return minorWildcard
|
||||
case 3:
|
||||
return patchWildcard
|
||||
default:
|
||||
return noneWildcard
|
||||
}
|
||||
}
|
||||
|
||||
type comparator func(Version, Version) bool
|
||||
|
||||
var (
|
||||
compEQ comparator = func(v1 Version, v2 Version) bool {
|
||||
return v1.Compare(v2) == 0
|
||||
}
|
||||
compNE = func(v1 Version, v2 Version) bool {
|
||||
return v1.Compare(v2) != 0
|
||||
}
|
||||
compGT = func(v1 Version, v2 Version) bool {
|
||||
return v1.Compare(v2) == 1
|
||||
}
|
||||
compGE = func(v1 Version, v2 Version) bool {
|
||||
return v1.Compare(v2) >= 0
|
||||
}
|
||||
compLT = func(v1 Version, v2 Version) bool {
|
||||
return v1.Compare(v2) == -1
|
||||
}
|
||||
compLE = func(v1 Version, v2 Version) bool {
|
||||
return v1.Compare(v2) <= 0
|
||||
}
|
||||
)
|
||||
|
||||
type versionRange struct {
|
||||
v Version
|
||||
c comparator
|
||||
}
|
||||
|
||||
// rangeFunc creates a Range from the given versionRange.
|
||||
func (vr *versionRange) rangeFunc() Range {
|
||||
return Range(func(v Version) bool {
|
||||
return vr.c(v, vr.v)
|
||||
})
|
||||
}
|
||||
|
||||
// Range represents a range of versions.
|
||||
// A Range can be used to check if a Version satisfies it:
|
||||
//
|
||||
// range, err := semver.ParseRange(">1.0.0 <2.0.0")
|
||||
// range(semver.MustParse("1.1.1") // returns true
|
||||
type Range func(Version) bool
|
||||
|
||||
// OR combines the existing Range with another Range using logical OR.
|
||||
func (rf Range) OR(f Range) Range {
|
||||
return Range(func(v Version) bool {
|
||||
return rf(v) || f(v)
|
||||
})
|
||||
}
|
||||
|
||||
// AND combines the existing Range with another Range using logical AND.
|
||||
func (rf Range) AND(f Range) Range {
|
||||
return Range(func(v Version) bool {
|
||||
return rf(v) && f(v)
|
||||
})
|
||||
}
|
||||
|
||||
// ParseRange parses a range and returns a Range.
|
||||
// If the range could not be parsed an error is returned.
|
||||
//
|
||||
// Valid ranges are:
|
||||
// - "<1.0.0"
|
||||
// - "<=1.0.0"
|
||||
// - ">1.0.0"
|
||||
// - ">=1.0.0"
|
||||
// - "1.0.0", "=1.0.0", "==1.0.0"
|
||||
// - "!1.0.0", "!=1.0.0"
|
||||
//
|
||||
// A Range can consist of multiple ranges separated by space:
|
||||
// Ranges can be linked by logical AND:
|
||||
// - ">1.0.0 <2.0.0" would match between both ranges, so "1.1.1" and "1.8.7" but not "1.0.0" or "2.0.0"
|
||||
// - ">1.0.0 <3.0.0 !2.0.3-beta.2" would match every version between 1.0.0 and 3.0.0 except 2.0.3-beta.2
|
||||
//
|
||||
// Ranges can also be linked by logical OR:
|
||||
// - "<2.0.0 || >=3.0.0" would match "1.x.x" and "3.x.x" but not "2.x.x"
|
||||
//
|
||||
// AND has a higher precedence than OR. It's not possible to use brackets.
|
||||
//
|
||||
// Ranges can be combined by both AND and OR
|
||||
//
|
||||
// - `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1`
|
||||
func ParseRange(s string) (Range, error) {
|
||||
parts := splitAndTrim(s)
|
||||
orParts, err := splitORParts(parts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expandedParts, err := expandWildcardVersion(orParts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var orFn Range
|
||||
for _, p := range expandedParts {
|
||||
var andFn Range
|
||||
for _, ap := range p {
|
||||
opStr, vStr, err := splitComparatorVersion(ap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vr, err := buildVersionRange(opStr, vStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not parse Range %q: %s", ap, err)
|
||||
}
|
||||
rf := vr.rangeFunc()
|
||||
|
||||
// Set function
|
||||
if andFn == nil {
|
||||
andFn = rf
|
||||
} else { // Combine with existing function
|
||||
andFn = andFn.AND(rf)
|
||||
}
|
||||
}
|
||||
if orFn == nil {
|
||||
orFn = andFn
|
||||
} else {
|
||||
orFn = orFn.OR(andFn)
|
||||
}
|
||||
|
||||
}
|
||||
return orFn, nil
|
||||
}
|
||||
|
||||
// splitORParts splits the already cleaned parts by '||'.
|
||||
// Checks for invalid positions of the operator and returns an
|
||||
// error if found.
|
||||
func splitORParts(parts []string) ([][]string, error) {
|
||||
var ORparts [][]string
|
||||
last := 0
|
||||
for i, p := range parts {
|
||||
if p == "||" {
|
||||
if i == 0 {
|
||||
return nil, fmt.Errorf("First element in range is '||'")
|
||||
}
|
||||
ORparts = append(ORparts, parts[last:i])
|
||||
last = i + 1
|
||||
}
|
||||
}
|
||||
if last == len(parts) {
|
||||
return nil, fmt.Errorf("Last element in range is '||'")
|
||||
}
|
||||
ORparts = append(ORparts, parts[last:])
|
||||
return ORparts, nil
|
||||
}
|
||||
|
||||
// buildVersionRange takes a slice of 2: operator and version
|
||||
// and builds a versionRange, otherwise an error.
|
||||
func buildVersionRange(opStr, vStr string) (*versionRange, error) {
|
||||
c := parseComparator(opStr)
|
||||
if c == nil {
|
||||
return nil, fmt.Errorf("Could not parse comparator %q in %q", opStr, strings.Join([]string{opStr, vStr}, ""))
|
||||
}
|
||||
v, err := Parse(vStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not parse version %q in %q: %s", vStr, strings.Join([]string{opStr, vStr}, ""), err)
|
||||
}
|
||||
|
||||
return &versionRange{
|
||||
v: v,
|
||||
c: c,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
// inArray checks if a byte is contained in an array of bytes
|
||||
func inArray(s byte, list []byte) bool {
|
||||
for _, el := range list {
|
||||
if el == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// splitAndTrim splits a range string by spaces and cleans whitespaces
|
||||
func splitAndTrim(s string) (result []string) {
|
||||
last := 0
|
||||
var lastChar byte
|
||||
excludeFromSplit := []byte{'>', '<', '='}
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] == ' ' && !inArray(lastChar, excludeFromSplit) {
|
||||
if last < i-1 {
|
||||
result = append(result, s[last:i])
|
||||
}
|
||||
last = i + 1
|
||||
} else if s[i] != ' ' {
|
||||
lastChar = s[i]
|
||||
}
|
||||
}
|
||||
if last < len(s)-1 {
|
||||
result = append(result, s[last:])
|
||||
}
|
||||
|
||||
for i, v := range result {
|
||||
result[i] = strings.Replace(v, " ", "", -1)
|
||||
}
|
||||
|
||||
// parts := strings.Split(s, " ")
|
||||
// for _, x := range parts {
|
||||
// if s := strings.TrimSpace(x); len(s) != 0 {
|
||||
// result = append(result, s)
|
||||
// }
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
// splitComparatorVersion splits the comparator from the version.
|
||||
// Input must be free of leading or trailing spaces.
|
||||
func splitComparatorVersion(s string) (string, string, error) {
|
||||
i := strings.IndexFunc(s, unicode.IsDigit)
|
||||
if i == -1 {
|
||||
return "", "", fmt.Errorf("Could not get version from string: %q", s)
|
||||
}
|
||||
return strings.TrimSpace(s[0:i]), s[i:], nil
|
||||
}
|
||||
|
||||
// getWildcardType will return the type of wildcard that the
|
||||
// passed version contains
|
||||
func getWildcardType(vStr string) wildcardType {
|
||||
parts := strings.Split(vStr, ".")
|
||||
nparts := len(parts)
|
||||
wildcard := parts[nparts-1]
|
||||
|
||||
possibleWildcardType := wildcardTypefromInt(nparts)
|
||||
if wildcard == "x" {
|
||||
return possibleWildcardType
|
||||
}
|
||||
|
||||
return noneWildcard
|
||||
}
|
||||
|
||||
// createVersionFromWildcard will convert a wildcard version
|
||||
// into a regular version, replacing 'x's with '0's, handling
|
||||
// special cases like '1.x.x' and '1.x'
|
||||
func createVersionFromWildcard(vStr string) string {
|
||||
// handle 1.x.x
|
||||
vStr2 := strings.Replace(vStr, ".x.x", ".x", 1)
|
||||
vStr2 = strings.Replace(vStr2, ".x", ".0", 1)
|
||||
parts := strings.Split(vStr2, ".")
|
||||
|
||||
// handle 1.x
|
||||
if len(parts) == 2 {
|
||||
return vStr2 + ".0"
|
||||
}
|
||||
|
||||
return vStr2
|
||||
}
|
||||
|
||||
// incrementMajorVersion will increment the major version
|
||||
// of the passed version
|
||||
func incrementMajorVersion(vStr string) (string, error) {
|
||||
parts := strings.Split(vStr, ".")
|
||||
i, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
parts[0] = strconv.Itoa(i + 1)
|
||||
|
||||
return strings.Join(parts, "."), nil
|
||||
}
|
||||
|
||||
// incrementMajorVersion will increment the minor version
|
||||
// of the passed version
|
||||
func incrementMinorVersion(vStr string) (string, error) {
|
||||
parts := strings.Split(vStr, ".")
|
||||
i, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
parts[1] = strconv.Itoa(i + 1)
|
||||
|
||||
return strings.Join(parts, "."), nil
|
||||
}
|
||||
|
||||
// expandWildcardVersion will expand wildcards inside versions
|
||||
// following these rules:
|
||||
//
|
||||
// * when dealing with patch wildcards:
|
||||
// >= 1.2.x will become >= 1.2.0
|
||||
// <= 1.2.x will become < 1.3.0
|
||||
// > 1.2.x will become >= 1.3.0
|
||||
// < 1.2.x will become < 1.2.0
|
||||
// != 1.2.x will become < 1.2.0 >= 1.3.0
|
||||
//
|
||||
// * when dealing with minor wildcards:
|
||||
// >= 1.x will become >= 1.0.0
|
||||
// <= 1.x will become < 2.0.0
|
||||
// > 1.x will become >= 2.0.0
|
||||
// < 1.0 will become < 1.0.0
|
||||
// != 1.x will become < 1.0.0 >= 2.0.0
|
||||
//
|
||||
// * when dealing with wildcards without
|
||||
// version operator:
|
||||
// 1.2.x will become >= 1.2.0 < 1.3.0
|
||||
// 1.x will become >= 1.0.0 < 2.0.0
|
||||
func expandWildcardVersion(parts [][]string) ([][]string, error) {
|
||||
var expandedParts [][]string
|
||||
for _, p := range parts {
|
||||
var newParts []string
|
||||
for _, ap := range p {
|
||||
if strings.Index(ap, "x") != -1 {
|
||||
opStr, vStr, err := splitComparatorVersion(ap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
versionWildcardType := getWildcardType(vStr)
|
||||
flatVersion := createVersionFromWildcard(vStr)
|
||||
|
||||
var resultOperator string
|
||||
var shouldIncrementVersion bool
|
||||
switch opStr {
|
||||
case ">":
|
||||
resultOperator = ">="
|
||||
shouldIncrementVersion = true
|
||||
case ">=":
|
||||
resultOperator = ">="
|
||||
case "<":
|
||||
resultOperator = "<"
|
||||
case "<=":
|
||||
resultOperator = "<"
|
||||
shouldIncrementVersion = true
|
||||
case "", "=", "==":
|
||||
newParts = append(newParts, ">="+flatVersion)
|
||||
resultOperator = "<"
|
||||
shouldIncrementVersion = true
|
||||
case "!=", "!":
|
||||
newParts = append(newParts, "<"+flatVersion)
|
||||
resultOperator = ">="
|
||||
shouldIncrementVersion = true
|
||||
}
|
||||
|
||||
var resultVersion string
|
||||
if shouldIncrementVersion {
|
||||
switch versionWildcardType {
|
||||
case patchWildcard:
|
||||
resultVersion, _ = incrementMinorVersion(flatVersion)
|
||||
case minorWildcard:
|
||||
resultVersion, _ = incrementMajorVersion(flatVersion)
|
||||
}
|
||||
} else {
|
||||
resultVersion = flatVersion
|
||||
}
|
||||
|
||||
ap = resultOperator + resultVersion
|
||||
}
|
||||
newParts = append(newParts, ap)
|
||||
}
|
||||
expandedParts = append(expandedParts, newParts)
|
||||
}
|
||||
|
||||
return expandedParts, nil
|
||||
}
|
||||
|
||||
func parseComparator(s string) comparator {
|
||||
switch s {
|
||||
case "==":
|
||||
fallthrough
|
||||
case "":
|
||||
fallthrough
|
||||
case "=":
|
||||
return compEQ
|
||||
case ">":
|
||||
return compGT
|
||||
case ">=":
|
||||
return compGE
|
||||
case "<":
|
||||
return compLT
|
||||
case "<=":
|
||||
return compLE
|
||||
case "!":
|
||||
fallthrough
|
||||
case "!=":
|
||||
return compNE
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MustParseRange is like ParseRange but panics if the range cannot be parsed.
|
||||
func MustParseRange(s string) Range {
|
||||
r, err := ParseRange(s)
|
||||
if err != nil {
|
||||
panic(`semver: ParseRange(` + s + `): ` + err.Error())
|
||||
}
|
||||
return r
|
||||
}
|
||||
418
tools/semver/semver.go
Normal file
418
tools/semver/semver.go
Normal file
@@ -0,0 +1,418 @@
|
||||
package semver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
numbers string = "0123456789"
|
||||
alphas = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-"
|
||||
alphanum = alphas + numbers
|
||||
)
|
||||
|
||||
// SpecVersion is the latest fully supported spec version of semver
|
||||
var SpecVersion = Version{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
Patch: 0,
|
||||
}
|
||||
|
||||
// Version represents a semver compatible version
|
||||
type Version struct {
|
||||
Major uint64
|
||||
Minor uint64
|
||||
Patch uint64
|
||||
Pre []PRVersion
|
||||
Build []string //No Precedence
|
||||
}
|
||||
|
||||
// Version to string
|
||||
func (v Version) String() string {
|
||||
b := make([]byte, 0, 5)
|
||||
b = strconv.AppendUint(b, v.Major, 10)
|
||||
b = append(b, '.')
|
||||
b = strconv.AppendUint(b, v.Minor, 10)
|
||||
b = append(b, '.')
|
||||
b = strconv.AppendUint(b, v.Patch, 10)
|
||||
|
||||
if len(v.Pre) > 0 {
|
||||
b = append(b, '-')
|
||||
b = append(b, v.Pre[0].String()...)
|
||||
|
||||
for _, pre := range v.Pre[1:] {
|
||||
b = append(b, '.')
|
||||
b = append(b, pre.String()...)
|
||||
}
|
||||
}
|
||||
|
||||
if len(v.Build) > 0 {
|
||||
b = append(b, '+')
|
||||
b = append(b, v.Build[0]...)
|
||||
|
||||
for _, build := range v.Build[1:] {
|
||||
b = append(b, '.')
|
||||
b = append(b, build...)
|
||||
}
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Equals checks if v is equal to o.
|
||||
func (v Version) Equals(o Version) bool {
|
||||
return (v.Compare(o) == 0)
|
||||
}
|
||||
|
||||
// EQ checks if v is equal to o.
|
||||
func (v Version) EQ(o Version) bool {
|
||||
return (v.Compare(o) == 0)
|
||||
}
|
||||
|
||||
// NE checks if v is not equal to o.
|
||||
func (v Version) NE(o Version) bool {
|
||||
return (v.Compare(o) != 0)
|
||||
}
|
||||
|
||||
// GT checks if v is greater than o.
|
||||
func (v Version) GT(o Version) bool {
|
||||
return (v.Compare(o) == 1)
|
||||
}
|
||||
|
||||
// GTE checks if v is greater than or equal to o.
|
||||
func (v Version) GTE(o Version) bool {
|
||||
return (v.Compare(o) >= 0)
|
||||
}
|
||||
|
||||
// GE checks if v is greater than or equal to o.
|
||||
func (v Version) GE(o Version) bool {
|
||||
return (v.Compare(o) >= 0)
|
||||
}
|
||||
|
||||
// LT checks if v is less than o.
|
||||
func (v Version) LT(o Version) bool {
|
||||
return (v.Compare(o) == -1)
|
||||
}
|
||||
|
||||
// LTE checks if v is less than or equal to o.
|
||||
func (v Version) LTE(o Version) bool {
|
||||
return (v.Compare(o) <= 0)
|
||||
}
|
||||
|
||||
// LE checks if v is less than or equal to o.
|
||||
func (v Version) LE(o Version) bool {
|
||||
return (v.Compare(o) <= 0)
|
||||
}
|
||||
|
||||
// Compare compares Versions v to o:
|
||||
// -1 == v is less than o
|
||||
// 0 == v is equal to o
|
||||
// 1 == v is greater than o
|
||||
func (v Version) Compare(o Version) int {
|
||||
if v.Major != o.Major {
|
||||
if v.Major > o.Major {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
if v.Minor != o.Minor {
|
||||
if v.Minor > o.Minor {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
if v.Patch != o.Patch {
|
||||
if v.Patch > o.Patch {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// Quick comparison if a version has no prerelease versions
|
||||
if len(v.Pre) == 0 && len(o.Pre) == 0 {
|
||||
return 0
|
||||
} else if len(v.Pre) == 0 && len(o.Pre) > 0 {
|
||||
return 1
|
||||
} else if len(v.Pre) > 0 && len(o.Pre) == 0 {
|
||||
return -1
|
||||
}
|
||||
|
||||
i := 0
|
||||
for ; i < len(v.Pre) && i < len(o.Pre); i++ {
|
||||
if comp := v.Pre[i].Compare(o.Pre[i]); comp == 0 {
|
||||
continue
|
||||
} else if comp == 1 {
|
||||
return 1
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
// If all pr versions are the equal but one has further prversion, this one greater
|
||||
if i == len(v.Pre) && i == len(o.Pre) {
|
||||
return 0
|
||||
} else if i == len(v.Pre) && i < len(o.Pre) {
|
||||
return -1
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Validate validates v and returns error in case
|
||||
func (v Version) Validate() error {
|
||||
// Major, Minor, Patch already validated using uint64
|
||||
|
||||
for _, pre := range v.Pre {
|
||||
if !pre.IsNum { //Numeric prerelease versions already uint64
|
||||
if len(pre.VersionStr) == 0 {
|
||||
return fmt.Errorf("Prerelease can not be empty %q", pre.VersionStr)
|
||||
}
|
||||
if !containsOnly(pre.VersionStr, alphanum) {
|
||||
return fmt.Errorf("Invalid character(s) found in prerelease %q", pre.VersionStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, build := range v.Build {
|
||||
if len(build) == 0 {
|
||||
return fmt.Errorf("Build meta data can not be empty %q", build)
|
||||
}
|
||||
if !containsOnly(build, alphanum) {
|
||||
return fmt.Errorf("Invalid character(s) found in build meta data %q", build)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// New is an alias for Parse and returns a pointer, parses version string and returns a validated Version or error
|
||||
func New(s string) (vp *Version, err error) {
|
||||
v, err := Parse(s)
|
||||
vp = &v
|
||||
return
|
||||
}
|
||||
|
||||
// Make is an alias for Parse, parses version string and returns a validated Version or error
|
||||
func Make(s string) (Version, error) {
|
||||
return Parse(s)
|
||||
}
|
||||
|
||||
// ParseTolerant allows for certain version specifications that do not strictly adhere to semver
|
||||
// specs to be parsed by this library. It does so by normalizing versions before passing them to
|
||||
// Parse(). It currently trims spaces, removes a "v" prefix, and adds a 0 patch number to versions
|
||||
// with only major and minor components specified
|
||||
func ParseTolerant(s string) (Version, error) {
|
||||
s = strings.TrimSpace(s)
|
||||
s = strings.TrimPrefix(s, "v")
|
||||
|
||||
// Split into major.minor.(patch+pr+meta)
|
||||
parts := strings.SplitN(s, ".", 3)
|
||||
if len(parts) < 3 {
|
||||
if strings.ContainsAny(parts[len(parts)-1], "+-") {
|
||||
return Version{}, errors.New("Short version cannot contain PreRelease/Build meta data")
|
||||
}
|
||||
for len(parts) < 3 {
|
||||
parts = append(parts, "0")
|
||||
}
|
||||
s = strings.Join(parts, ".")
|
||||
}
|
||||
|
||||
return Parse(s)
|
||||
}
|
||||
|
||||
// Parse parses version string and returns a validated Version or error
|
||||
func Parse(s string) (Version, error) {
|
||||
if len(s) == 0 {
|
||||
return Version{}, errors.New("Version string empty")
|
||||
}
|
||||
|
||||
// Split into major.minor.(patch+pr+meta)
|
||||
parts := strings.SplitN(s, ".", 3)
|
||||
if len(parts) != 3 {
|
||||
return Version{}, errors.New("No Major.Minor.Patch elements found")
|
||||
}
|
||||
|
||||
// Major
|
||||
if !containsOnly(parts[0], numbers) {
|
||||
return Version{}, fmt.Errorf("Invalid character(s) found in major number %q", parts[0])
|
||||
}
|
||||
if hasLeadingZeroes(parts[0]) {
|
||||
return Version{}, fmt.Errorf("Major number must not contain leading zeroes %q", parts[0])
|
||||
}
|
||||
major, err := strconv.ParseUint(parts[0], 10, 64)
|
||||
if err != nil {
|
||||
return Version{}, err
|
||||
}
|
||||
|
||||
// Minor
|
||||
if !containsOnly(parts[1], numbers) {
|
||||
return Version{}, fmt.Errorf("Invalid character(s) found in minor number %q", parts[1])
|
||||
}
|
||||
if hasLeadingZeroes(parts[1]) {
|
||||
return Version{}, fmt.Errorf("Minor number must not contain leading zeroes %q", parts[1])
|
||||
}
|
||||
minor, err := strconv.ParseUint(parts[1], 10, 64)
|
||||
if err != nil {
|
||||
return Version{}, err
|
||||
}
|
||||
|
||||
v := Version{}
|
||||
v.Major = major
|
||||
v.Minor = minor
|
||||
|
||||
var build, prerelease []string
|
||||
patchStr := parts[2]
|
||||
|
||||
if buildIndex := strings.IndexRune(patchStr, '+'); buildIndex != -1 {
|
||||
build = strings.Split(patchStr[buildIndex+1:], ".")
|
||||
patchStr = patchStr[:buildIndex]
|
||||
}
|
||||
|
||||
if preIndex := strings.IndexRune(patchStr, '-'); preIndex != -1 {
|
||||
prerelease = strings.Split(patchStr[preIndex+1:], ".")
|
||||
patchStr = patchStr[:preIndex]
|
||||
}
|
||||
|
||||
if !containsOnly(patchStr, numbers) {
|
||||
return Version{}, fmt.Errorf("Invalid character(s) found in patch number %q", patchStr)
|
||||
}
|
||||
if hasLeadingZeroes(patchStr) {
|
||||
return Version{}, fmt.Errorf("Patch number must not contain leading zeroes %q", patchStr)
|
||||
}
|
||||
patch, err := strconv.ParseUint(patchStr, 10, 64)
|
||||
if err != nil {
|
||||
return Version{}, err
|
||||
}
|
||||
|
||||
v.Patch = patch
|
||||
|
||||
// Prerelease
|
||||
for _, prstr := range prerelease {
|
||||
parsedPR, err := NewPRVersion(prstr)
|
||||
if err != nil {
|
||||
return Version{}, err
|
||||
}
|
||||
v.Pre = append(v.Pre, parsedPR)
|
||||
}
|
||||
|
||||
// Build meta data
|
||||
for _, str := range build {
|
||||
if len(str) == 0 {
|
||||
return Version{}, errors.New("Build meta data is empty")
|
||||
}
|
||||
if !containsOnly(str, alphanum) {
|
||||
return Version{}, fmt.Errorf("Invalid character(s) found in build meta data %q", str)
|
||||
}
|
||||
v.Build = append(v.Build, str)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// MustParse is like Parse but panics if the version cannot be parsed.
|
||||
func MustParse(s string) Version {
|
||||
v, err := Parse(s)
|
||||
if err != nil {
|
||||
panic(`semver: Parse(` + s + `): ` + err.Error())
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// PRVersion represents a PreRelease Version
|
||||
type PRVersion struct {
|
||||
VersionStr string
|
||||
VersionNum uint64
|
||||
IsNum bool
|
||||
}
|
||||
|
||||
// NewPRVersion creates a new valid prerelease version
|
||||
func NewPRVersion(s string) (PRVersion, error) {
|
||||
if len(s) == 0 {
|
||||
return PRVersion{}, errors.New("Prerelease is empty")
|
||||
}
|
||||
v := PRVersion{}
|
||||
if containsOnly(s, numbers) {
|
||||
if hasLeadingZeroes(s) {
|
||||
return PRVersion{}, fmt.Errorf("Numeric PreRelease version must not contain leading zeroes %q", s)
|
||||
}
|
||||
num, err := strconv.ParseUint(s, 10, 64)
|
||||
|
||||
// Might never be hit, but just in case
|
||||
if err != nil {
|
||||
return PRVersion{}, err
|
||||
}
|
||||
v.VersionNum = num
|
||||
v.IsNum = true
|
||||
} else if containsOnly(s, alphanum) {
|
||||
v.VersionStr = s
|
||||
v.IsNum = false
|
||||
} else {
|
||||
return PRVersion{}, fmt.Errorf("Invalid character(s) found in prerelease %q", s)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IsNumeric checks if prerelease-version is numeric
|
||||
func (v PRVersion) IsNumeric() bool {
|
||||
return v.IsNum
|
||||
}
|
||||
|
||||
// Compare compares two PreRelease Versions v and o:
|
||||
// -1 == v is less than o
|
||||
// 0 == v is equal to o
|
||||
// 1 == v is greater than o
|
||||
func (v PRVersion) Compare(o PRVersion) int {
|
||||
if v.IsNum && !o.IsNum {
|
||||
return -1
|
||||
} else if !v.IsNum && o.IsNum {
|
||||
return 1
|
||||
} else if v.IsNum && o.IsNum {
|
||||
if v.VersionNum == o.VersionNum {
|
||||
return 0
|
||||
} else if v.VersionNum > o.VersionNum {
|
||||
return 1
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
} else { // both are Alphas
|
||||
if v.VersionStr == o.VersionStr {
|
||||
return 0
|
||||
} else if v.VersionStr > o.VersionStr {
|
||||
return 1
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PreRelease version to string
|
||||
func (v PRVersion) String() string {
|
||||
if v.IsNum {
|
||||
return strconv.FormatUint(v.VersionNum, 10)
|
||||
}
|
||||
return v.VersionStr
|
||||
}
|
||||
|
||||
func containsOnly(s string, set string) bool {
|
||||
return strings.IndexFunc(s, func(r rune) bool {
|
||||
return !strings.ContainsRune(set, r)
|
||||
}) == -1
|
||||
}
|
||||
|
||||
func hasLeadingZeroes(s string) bool {
|
||||
return len(s) > 1 && s[0] == '0'
|
||||
}
|
||||
|
||||
// NewBuildVersion creates a new valid build version
|
||||
func NewBuildVersion(s string) (string, error) {
|
||||
if len(s) == 0 {
|
||||
return "", errors.New("Buildversion is empty")
|
||||
}
|
||||
if !containsOnly(s, alphanum) {
|
||||
return "", fmt.Errorf("Invalid character(s) found in build meta data %q", s)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
28
tools/semver/sort.go
Normal file
28
tools/semver/sort.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package semver
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// Versions represents multiple versions.
|
||||
type Versions []Version
|
||||
|
||||
// Len returns length of version collection
|
||||
func (s Versions) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Swap swaps two versions inside the collection by its indices
|
||||
func (s Versions) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
// Less checks if version at index i is less than version at index j
|
||||
func (s Versions) Less(i, j int) bool {
|
||||
return s[i].LT(s[j])
|
||||
}
|
||||
|
||||
// Sort sorts a slice of versions
|
||||
func Sort(versions []Version) {
|
||||
sort.Sort(Versions(versions))
|
||||
}
|
||||
30
tools/semver/sql.go
Normal file
30
tools/semver/sql.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package semver
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Scan implements the database/sql.Scanner interface.
|
||||
func (v *Version) Scan(src interface{}) (err error) {
|
||||
var str string
|
||||
switch src := src.(type) {
|
||||
case string:
|
||||
str = src
|
||||
case []byte:
|
||||
str = string(src)
|
||||
default:
|
||||
return fmt.Errorf("Version.Scan: cannot convert %T to string.", src)
|
||||
}
|
||||
|
||||
if t, err := Parse(str); err == nil {
|
||||
*v = t
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the database/sql/driver.Valuer interface.
|
||||
func (v Version) Value() (driver.Value, error) {
|
||||
return v.String(), nil
|
||||
}
|
||||
@@ -1,14 +1,6 @@
|
||||
cd ../cmd/micro
|
||||
|
||||
govendor init
|
||||
govendor add +e
|
||||
|
||||
cd ../../..
|
||||
cd ../..
|
||||
|
||||
tar czf "$1".tar.gz micro
|
||||
zip -rq "$1".zip micro
|
||||
mv "$1".tar.gz micro
|
||||
mv "$1".zip micro
|
||||
|
||||
cd micro/cmd/micro
|
||||
rm -rf vendor
|
||||
|
||||
Reference in New Issue
Block a user