Remove local settings

This commit is contained in:
Zachary Yedidia
2019-08-03 17:12:23 -07:00
parent 763e635fea
commit 9eed8bc247
10 changed files with 33 additions and 77 deletions

View File

@@ -201,12 +201,6 @@ func main() {
action.InitTabs(b)
action.InitGlobals()
for _, s := range config.LocalSettings {
if _, ok := config.GlobalSettings[s]; ok {
delete(config.GlobalSettings, s)
}
}
// Here is the event loop which runs in a separate thread
go func() {
events = make(chan tcell.Event)

View File

@@ -1,7 +1,6 @@
package action
import (
"log"
"strings"
"time"
@@ -296,7 +295,6 @@ func (h *BufPane) DoKeyEvent(e Event) bool {
return false
}
rel := action(h)
log.Println("calling on", estr)
if h.PluginCB("on"+estr) && rel {
h.Relocate()
}

View File

@@ -3,7 +3,6 @@ package action
import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
@@ -271,9 +270,7 @@ func ReloadConfig() {
screen.TermMessage(err)
}
log.Println("RELOAD CONFIG", len(buffer.OpenBuffers))
for _, b := range buffer.OpenBuffers {
log.Println("UPDATE RULES")
b.UpdateRules()
}
}
@@ -450,7 +447,7 @@ func (h *BufPane) ResetCmd(args []string) {
option := args[0]
defaultGlobals := config.DefaultGlobalSettings()
defaultLocals := config.DefaultLocalSettings()
defaultLocals := config.DefaultCommonSettings()
if _, ok := defaultGlobals[option]; ok {
SetGlobalOptionNative(option, defaultGlobals[option])

View File

@@ -92,17 +92,16 @@ func OptionComplete(b *buffer.Buffer) ([]string, []string) {
input, argstart := buffer.GetArg(b)
var suggestions []string
localSettings := config.DefaultLocalSettings()
for option := range config.GlobalSettings {
if strings.HasPrefix(option, input) {
suggestions = append(suggestions, option)
}
}
for option := range localSettings {
if strings.HasPrefix(option, input) && !contains(suggestions, option) {
suggestions = append(suggestions, option)
}
}
// for option := range localSettings {
// if strings.HasPrefix(option, input) && !contains(suggestions, option) {
// suggestions = append(suggestions, option)
// }
// }
sort.Strings(suggestions)
completions := make([]string, len(suggestions))
@@ -122,19 +121,19 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
completeValue := false
args := bytes.Split(l, []byte{' '})
if len(args) >= 2 {
localSettings := config.DefaultLocalSettings()
// localSettings := config.DefaultLocalSettings()
for option := range config.GlobalSettings {
if option == string(args[len(args)-2]) {
completeValue = true
break
}
}
for option := range localSettings {
if option == string(args[len(args)-2]) {
completeValue = true
break
}
}
// for option := range localSettings {
// if option == string(args[len(args)-2]) {
// completeValue = true
// break
// }
// }
}
if !completeValue {
return OptionComplete(b)
@@ -144,18 +143,18 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
inputOpt = strings.TrimSpace(inputOpt)
var suggestions []string
localSettings := config.DefaultLocalSettings()
// localSettings := config.DefaultLocalSettings()
var optionVal interface{}
for k, option := range config.GlobalSettings {
if k == inputOpt {
optionVal = option
}
}
for k, option := range localSettings {
if k == inputOpt {
optionVal = option
}
}
// for k, option := range localSettings {
// if k == inputOpt {
// optionVal = option
// }
// }
switch optionVal.(type) {
case bool:

View File

@@ -6,7 +6,6 @@ import (
"errors"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
@@ -163,7 +162,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
b := new(Buffer)
b.Settings = config.DefaultLocalSettings()
b.Settings = config.DefaultCommonSettings()
for k, v := range config.GlobalSettings {
if _, ok := b.Settings[k]; ok {
b.Settings[k] = v
@@ -294,7 +293,6 @@ func (b *Buffer) SetName(s string) {
func (b *Buffer) Insert(start Loc, text string) {
if !b.Type.Readonly {
log.Println("INSERT", start, text)
b.EventHandler.cursors = b.cursors
b.EventHandler.active = b.curCursor
b.EventHandler.Insert(start, text)

View File

@@ -2,7 +2,6 @@ package config
import (
"errors"
"log"
lua "github.com/yuin/gopher-lua"
ulua "github.com/zyedidia/micro/internal/lua"
@@ -102,7 +101,6 @@ func (p *Plugin) Load() error {
func (p *Plugin) Call(fn string, args ...lua.LValue) (lua.LValue, error) {
plug := ulua.L.GetGlobal(p.Name)
log.Println(p.Name, fn, plug)
luafn := ulua.L.GetField(plug, fn)
if luafn == lua.LNil {
return nil, ErrNoSuchFunction

View File

@@ -2,7 +2,6 @@ package config
import (
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
@@ -138,7 +137,6 @@ func InitRuntimeFiles() {
// Search ConfigDir for plugin-scripts
plugdir := filepath.Join(ConfigDir, "plugins")
files, _ := ioutil.ReadDir(plugdir)
log.Println("reading", plugdir)
for _, d := range files {
if d.IsDir() {
srcs, _ := ioutil.ReadDir(filepath.Join(plugdir, d.Name()))

View File

@@ -129,10 +129,6 @@ func RegisterCommonOption(name string, defaultvalue interface{}) error {
return nil
}
func RegisterLocalOption(name string, defaultvalue interface{}) {
defaultLocalSettings[name] = defaultvalue
}
func RegisterGlobalOption(name string, defaultvalue interface{}) error {
if v, ok := GlobalSettings[name]; !ok {
defaultGlobalSettings[name] = defaultvalue
@@ -162,11 +158,13 @@ var defaultCommonSettings = map[string]interface{}{
"eofnewline": false,
"fastdirty": true,
"fileformat": "unix",
"filetype": "unknown",
"ignorecase": false,
"indentchar": " ",
"keepautoindent": false,
"matchbrace": false,
"matchbraceleft": false,
"readonly": false,
"rmtrailingws": false,
"ruler": true,
"savecursor": false,
@@ -199,6 +197,16 @@ func GetInfoBarOffset() int {
return offset
}
// DefaultCommonSettings returns the default global settings for micro
// Note that colorscheme is a global only option
func DefaultCommonSettings() map[string]interface{} {
commonsettings := make(map[string]interface{})
for k, v := range defaultCommonSettings {
commonsettings[k] = v
}
return commonsettings
}
var defaultGlobalSettings = map[string]interface{}{
"colorscheme": "default",
"infobar": true,
@@ -222,29 +230,8 @@ func DefaultGlobalSettings() map[string]interface{} {
return globalsettings
}
// LocalSettings is a list of the local only settings
var LocalSettings = []string{"filetype", "readonly"}
var defaultLocalSettings = map[string]interface{}{
"filetype": "unknown",
"readonly": false,
}
// DefaultLocalSettings returns the default local settings
// Note that filetype is a local only option
func DefaultLocalSettings() map[string]interface{} {
localsettings := make(map[string]interface{})
for k, v := range defaultCommonSettings {
localsettings[k] = v
}
for k, v := range defaultLocalSettings {
localsettings[k] = v
}
return localsettings
}
// DefaultAllSettings returns a map of all settings and their
// default values (both local and global settings)
// default values (both common and global settings)
func DefaultAllSettings() map[string]interface{} {
allsettings := make(map[string]interface{})
for k, v := range defaultCommonSettings {
@@ -253,9 +240,6 @@ func DefaultAllSettings() map[string]interface{} {
for k, v := range defaultGlobalSettings {
allsettings[k] = v
}
for k, v := range defaultLocalSettings {
allsettings[k] = v
}
return allsettings
}

View File

@@ -1,7 +1,6 @@
package display
import (
"log"
"strconv"
"unicode/utf8"
@@ -150,27 +149,21 @@ func (w *BufWindow) Relocate() bool {
ret := false
activeC := w.Buf.GetActiveCursor()
cy := activeC.Y
log.Println("RELOCATE", w.StartLine, cy, height)
scrollmargin := int(b.Settings["scrollmargin"].(float64))
if cy < w.StartLine+scrollmargin && cy > scrollmargin-1 {
log.Println("a")
w.StartLine = cy - scrollmargin
ret = true
} else if cy < w.StartLine {
log.Println("b")
w.StartLine = cy
ret = true
}
if cy > w.StartLine+height-1-scrollmargin && cy < b.LinesNum()-scrollmargin {
log.Println("c")
w.StartLine = cy - height + 1 + scrollmargin
ret = true
} else if cy >= b.LinesNum()-scrollmargin && cy >= height {
log.Println("d")
w.StartLine = b.LinesNum() - height
ret = true
}
log.Println("RELOCATE DONE", w.StartLine)
// horizontal relocation (scrolling)
if !b.Settings["softwrap"].(bool) {
@@ -363,7 +356,6 @@ func (w *BufWindow) showCursor(x, y int, main bool) {
// displayBuffer draws the buffer being shown in this window on the screen.Screen
func (w *BufWindow) displayBuffer() {
log.Println("STARTLINE", w.StartLine)
b := w.Buf
hasMessage := len(b.Messages) > 0

View File

@@ -3,7 +3,6 @@ package util
import (
"errors"
"fmt"
"log"
"os"
"os/user"
"path/filepath"
@@ -205,7 +204,6 @@ func FSize(f *os.File) int64 {
// IsWordChar returns whether or not the string is a 'word character'
// Word characters are defined as numbers, letters, or '_'
func IsWordChar(r rune) bool {
log.Println("IsWordChar")
return unicode.IsLetter(r) || unicode.IsNumber(r) || r == '_'
}