提交 f56dfb7d 编写于 作者: F Fredrik Ehnbom

code cleanup

上级 baa7b171
......@@ -16,3 +16,5 @@ backend/sublime/*.go
*.log.0*
.DS_Store
frontend/termbox/termbox
frontend/html/html
3rdparty/bundles/User
......@@ -232,10 +232,16 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/backend/sublime/region.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/window.go
)
add_custom_target(fix
COMMAND ${GOCMD} run ${CMAKE_SOURCE_DIR}/build/fix.go
DEPENDS ${PEGDEPENDS}
)
add_custom_target(lime
DEPENDS ${CMAKE_SOURCE_DIR}/backend/sublime/region.go
DEPENDS ${GOPATH}/pkg/${GOOS}_${GOARCH}/lime/3rdparty/libs/gopy/lib.a
DEPENDS Oniguruma
DEPENDS fix
)
add_custom_target(termbox ALL
......@@ -262,6 +268,7 @@ foreach(testfile ${TESTS})
endforeach(testfile)
add_custom_target(test
COMMAND ${GOCMD} test -i ${GO_TESTS}
COMMAND ${GOCMD} test -v ${GO_TESTS}
DEPENDS lime
)
Copyright (c) 2013 Fredrik Ehnbom and [contributors](https://github.com/limetext/lime/graphs/contributors)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
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.
......@@ -8,7 +8,11 @@ There was a period of about 6 months after the Sublime Text 2 "stable" version w
As none of the other text editors I've tried come close to the love I had for Sublime Text, I decided I had to create my own.
The frontend(s) are not ready to replace your favourite editor, but the backend itself I believe isn't too far away.
# Status
The [frontend(s)](https://github.com/limetext/lime/issues?direction=desc&labels=frontend) are **not** ready to replace your favourite editor, but the backend itself I believe isn't too far away.
Your help is needed to move the project forward! Claim an [issue](https://github.com/limetext/lime/issues) as your own and submit a pull request!
![Screenshot taken Oct 23 2013](http://i.imgur.com/VIpmjau.png)
......@@ -18,87 +22,13 @@ Because I like the architecture of the extensibilities in the original editor.
# Goals
- ☑ 100% Open source
- ☑ Compatible with Textmate color schemes (which is what ST is using)
- ☑ Compatible with Textmate syntax definitions (which again is what ST is using)
- ☐ Compatible with Textmate snippets
- ☑ Compatible with Sublime Text’s python plugin API. I’ll probably never implement this 100%, only the api bits I need for the plugins I use.
- ☑ Compatible with Sublime Text’s keybindings and settings (think most of it is working)
- ☐ Compatible with Sublime Text snippets
- ☐ Sublime Text’s Goto anything panel
- ☑ Multiple cursors
- ☑ Regression tests (Programming in [Go](http://golang.org) makes it trivial and even fun to write them ;))
- ☐ Support for plugging in a custom parser for more advanced syntax highlighting.
- ☐ Terminal UI (*Maybe* I’ll work on a simple non-terminal UI at some point)
- ☐ Cross platform (It appears to be compiling and running on OSX and Linux last I tried, but needs further validation.)
Please refer to the [Goals](https://github.com/limetext/lime/wiki/Goals) page in the [wiki](https://github.com/limetext/lime/wiki/_pages).
# Build instructions
### Install required components
- [cmake](http://cmake.org/)
- Some form of build system that cmake can create a build system for (ninja, make, visual studio)
- Git
- Mercurial
- Other required components will be downloaded as needed
### Download the needed repositories
mkdir -p code/go/src
cd code/go/src
git clone --recursive https://github.com/limetext/lime.git lime
### Compile lime
mkdir code/go/src/lime/build2
cd code/go/src/lime/build2
cmake .. # or use the cmake gui to create a build system suitable for you
make # presuming you told cmake to generate makefiles
make test # To run all tests
Done!
# To use termbox frontend
cd code/go/src/lime/build2
make termbox # again presuming using a makefile based cmake target
cd ../frontend/termbox
./termbox
Press Ctrl+Q to exit.
# To use qt5 frontend
It's broken, don't.
cd ../frontend/qt5
go run main.go
Please refer to the [Building](https://github.com/limetext/lime/wiki/Building) page in the [wiki](https://github.com/limetext/lime/wiki/_pages).
# License
The license of the project is the 2-clause BSD license:
```
Copyright (c) 2013 Fredrik Ehnbom
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
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.
```
The license of the project is the [2-clause BSD license](https://github.com/limetext/lime/blob/master/LICENSE).
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package backend
type (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package backend
import (
......@@ -148,18 +151,14 @@ func (ch *commandHandler) RunApplicationCommand(name string, args Args) error {
}
func (ch *commandHandler) Unregister(name string) error {
if _, ok := ch.ApplicationCommands[name]; !ok {
if _, ok := ch.TextCommands[name]; !ok {
if _, ok := ch.WindowCommands[name]; !ok {
return fmt.Errorf("%s wasn't a registered command", name)
} else {
ch.WindowCommands[name] = nil
}
} else {
ch.TextCommands[name] = nil
}
} else {
if _, ok := ch.ApplicationCommands[name]; ok {
ch.ApplicationCommands[name] = nil
} else if _, ok := ch.TextCommands[name]; ok {
ch.TextCommands[name] = nil
} else if _, ok := ch.WindowCommands[name]; !ok {
return fmt.Errorf("%s wasn't a registered command", name)
} else {
ch.WindowCommands[name] = nil
}
return nil
}
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
//"github.com/quarnster/util/text"
. "lime/backend"
"strings"
"unicode"
......@@ -33,12 +35,10 @@ func (c *TitleCaseCommand) Run(v *View, e *Edit) error {
for i := 0; i < sel.Len(); i++ {
r := sel.Get(i)
if r.Size() == 0 {
// return error or just ignore?
} else {
//v.Replace(e, r, c.Characters)
t := v.Buffer().Substr(r)
v.Replace(e, r, strings.Title(t))
continue
}
t := v.Buffer().Substr(r)
v.Replace(e, r, strings.Title(t))
}
return nil
}
......@@ -48,20 +48,18 @@ func (c *SwapCaseCommand) Run(v *View, e *Edit) error {
for i := 0; i < sel.Len(); i++ {
r := sel.Get(i)
if r.Size() == 0 {
// return error or just ignore?
} else {
//v.Replace(e, r, c.Characters)
text := v.Buffer().Substr(r)
swapped := make([]rune, 0)
for _, c := range text {
if unicode.IsUpper(c) {
swapped = append(swapped, unicode.ToLower(c))
} else {
swapped = append(swapped, unicode.ToUpper(c))
}
continue
}
text := v.Buffer().Substr(r)
swapped := make([]rune, 0)
for _, c := range text {
if unicode.IsUpper(c) {
swapped = append(swapped, unicode.ToLower(c))
} else {
swapped = append(swapped, unicode.ToUpper(c))
}
v.Replace(e, r, string(swapped))
}
v.Replace(e, r, string(swapped))
}
return nil
}
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......@@ -27,14 +30,11 @@ func TestTitleCase(t *testing.T) {
v.Sel().Add(Region{24, 51})
e = v.BeginEdit()
ed.CommandHandler().RunTextCommand(v, "title_case", nil)
v.EndEdit(e)
result := v.Buffer().Substr(Region{0, v.Buffer().Size()})
if result != expected {
t.Errorf(`TitleCaseCommand Failed.
Expected: %s
Got: %s`, expected, result)
......@@ -49,14 +49,10 @@ func TestTitleCase(t *testing.T) {
v.Sel().Add(Region{0, 17})
v.Sel().Add(Region{52, 71})
e = v.BeginEdit()
ed.CommandHandler().RunTextCommand(v, "title_case", nil)
v.EndEdit(e)
result = v.Buffer().Substr(Region{0, v.Buffer().Size()})
if result != expectedMulti {
t.Errorf(`TitleCaseCommand Failed.
Expected: %s
Got: %s`, expectedMulti, result)
......@@ -69,14 +65,10 @@ func TestTitleCase(t *testing.T) {
v.EndEdit(e)
v.Sel().Clear()
e = v.BeginEdit()
ed.CommandHandler().RunTextCommand(v, "title_case", nil)
v.EndEdit(e)
result = v.Buffer().Substr(Region{0, v.Buffer().Size()})
if result != quote {
t.Errorf(`TitleCaseCommand Failed.
Expected: %s
Got: %s`, quote, result)
......@@ -92,19 +84,14 @@ func TestTitleCase(t *testing.T) {
v.Sel().Clear()
v.Sel().Add(Region{0, v.Buffer().Size()})
e = v.BeginEdit()
ed.CommandHandler().RunTextCommand(v, "title_case", nil)
v.EndEdit(e)
result = v.Buffer().Substr(Region{0, v.Buffer().Size()})
if result != titleRussian {
t.Errorf(`TitleCaseCommand Failed.
Expected: %s
Got: %s`, titleRussian, result)
}
}
func TestSwapCase(t *testing.T) {
......@@ -125,14 +112,10 @@ func TestSwapCase(t *testing.T) {
v.Sel().Clear()
v.Sel().Add(Region{0, v.Buffer().Size()})
e = v.BeginEdit()
ed.CommandHandler().RunTextCommand(v, "swap_case", nil)
v.EndEdit(e)
result := v.Buffer().Substr(Region{0, v.Buffer().Size()})
if result != helloSwapped {
t.Errorf(`TitleCaseCommand Failed.
Expected: %s
Got: -%s-`, helloSwapped, result)
......@@ -146,17 +129,12 @@ func TestSwapCase(t *testing.T) {
v.Sel().Clear()
v.Sel().Add(Region{0, v.Buffer().Size()})
e = v.BeginEdit()
ed.CommandHandler().RunTextCommand(v, "swap_case", nil)
v.EndEdit(e)
result = v.Buffer().Substr(Region{0, v.Buffer().Size()})
if result != privetSwapped {
t.Errorf(`TitleCaseCommand Failed.
Expected: %s
Got: %s`, privetSwapped, result)
}
}
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......@@ -41,32 +44,32 @@ func (c *FindUnderExpandCommand) Run(v *View, e *Edit) error {
}
sel.Clear()
sel.AddAll(rs)
} else {
last := rs[len(rs)-1]
b := v.Buffer()
data := b.SubstrR(last)
next := last
size := last.Size()
next.A += size
next.B += size
buf := b.SubstrR(Region{next.A, next.B})
for next.End() < b.Size() {
buf[size-1] = b.Index(next.B - 1)
found := true
for j, r := range buf {
if r != data[j] {
found = false
break
}
}
if found {
sel.Add(next)
return nil
}
last := rs[len(rs)-1]
b := v.Buffer()
data := b.SubstrR(last)
next := last
size := last.Size()
next.A += size
next.B += size
buf := b.SubstrR(Region{next.A, next.B})
for next.End() < b.Size() {
buf[size-1] = b.Index(next.B - 1)
found := true
for j, r := range buf {
if r != data[j] {
found = false
break
}
copy(buf, buf[1:])
next.A += 1
next.B += 1
}
if found {
sel.Add(next)
break
}
copy(buf, buf[1:])
next.A += 1
next.B += 1
}
return nil
}
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......@@ -49,13 +52,13 @@ func (c *UnmarkUndoGroupsForGluingCommand) Run(v *backend.View, e *backend.Edit)
func (c *GlueMarkedUndoGroupsCommand) Run(v *backend.View, e *backend.Edit) error {
pos := v.UndoStack().Position()
if mark, ok := v.Settings().Get(lime_cmd_mark).(int); ok {
if l, p := pos-mark, mark; p != -1 && (l-p) > 1 {
v.UndoStack().GlueFrom(mark)
}
} else {
mark, ok := v.Settings().Get(lime_cmd_mark).(int)
if !ok {
return fmt.Errorf("No mark in the current view")
}
if l, p := pos-mark, mark; p != -1 && (l-p) > 1 {
v.UndoStack().GlueFrom(mark)
}
return nil
}
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package backend
import (
......@@ -126,18 +129,19 @@ func (e *Editor) Init() {
}
func (e *Editor) loadKeybinding(fn string) {
if d, err := ioutil.ReadFile(fn); err != nil {
d, err := ioutil.ReadFile(fn)
if err != nil {
log4go.Error("Couldn't load file %s: %s", fn, err)
}
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
log4go.Error(err)
} else {
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
log4go.Error(err)
} else {
log4go.Info("Loaded %s", fn)
}
e.keyBindings.merge(&bindings)
log4go.Info("Loaded %s", fn)
}
e.keyBindings.merge(&bindings)
}
func (e *Editor) loadKeybindings() {
// TODO(q): should search for keybindings
e.loadKeybinding("../../backend/packages/Default/Default.sublime-keymap")
......@@ -145,14 +149,14 @@ func (e *Editor) loadKeybindings() {
}
func (e *Editor) loadSetting(fn string) {
if d, err := ioutil.ReadFile(fn); err != nil {
d, err := ioutil.ReadFile(fn)
if err != nil {
log4go.Error("Couldn't load file %s: %s", fn, err)
}
if err := loaders.LoadJSON(d, e.Settings()); err != nil {
log4go.Error(err)
} else {
if err := loaders.LoadJSON(d, e.Settings()); err != nil {
log4go.Error(err)
} else {
log4go.Info("Loaded %s", fn)
}
log4go.Info("Loaded %s", fn)
}
}
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package backend
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package backend
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package backend
import (
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package loaders
import (
......@@ -29,17 +32,16 @@ func LoadJSON(data []byte, intf interface{}) error {
if !p.Parse(str) {
return fmt.Errorf("%s, %s", p.Error(), p.RootNode())
} else {
root := p.RootNode()
for _, child := range root.Children {
switch child.Name {
case "BlockComment", "LineComment", "EndOfFile", "JunkComma":
if child.Range.End() < len(lut) {
set.Add(Region{lut[child.Range.Begin()], lut[child.Range.End()]})
}
default:
return errors.New("Unhandled node: " + child.Name)
}
root := p.RootNode()
for _, child := range root.Children {
switch child.Name {
case "BlockComment", "LineComment", "EndOfFile", "JunkComma":
if child.Range.End() < len(lut) {
set.Add(Region{lut[child.Range.Begin()], lut[child.Range.End()]})
}
default:
return errors.New("Unhandled node: " + child.Name)
}
}
b.AddCallback(func(b Buffer, pos, delta int) {
......
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package loaders
import (
......@@ -60,16 +63,15 @@ func LoadPlist(data []byte, intf interface{}) error {
)
if !p.Parse(strings.Replace(string(data), "\r", "", -1)) {
return p.Error()
} else {