Beispiel #1
0
// Will load view settings respect to current syntax
// e.g if current syntax is Python settings order will be:
// Packages/Python/Python.sublime-settings
// Packages/Python/Python (Windows).sublime-settings
// Packages/User/Python.sublime-settings
// <Buffer Specific Settings>
func (v *View) loadSettings() {
	syntax := v.Settings().Get("syntax", "").(string)

	if syntax == "" {
		v.Settings().SetParent(v.window)
		return
	}

	defSettings, usrSettings, platSettings := &HasSettings{}, &HasSettings{}, &HasSettings{}

	defSettings.Settings().SetParent(v.window)
	platSettings.Settings().SetParent(defSettings)
	usrSettings.Settings().SetParent(platSettings)
	v.Settings().SetParent(usrSettings)

	ed := GetEditor()
	if r, err := rubex.Compile(`([A-Za-z]+?)\.(?:[^.]+)$`); err != nil {
		log.Error(err)
		return
	} else if s := r.FindStringSubmatch(syntax); s != nil {
		p := path.Join(LIME_PACKAGES_PATH, s[1], s[1]+".sublime-settings")
		ed.load(packages.NewPacket(p, defSettings.Settings()))

		p = path.Join(LIME_PACKAGES_PATH, s[1], s[1]+" ("+ed.Plat()+").sublime-settings")
		ed.load(packages.NewPacket(p, platSettings.Settings()))

		p = path.Join(LIME_USER_PACKAGES_PATH, s[1]+".sublime-settings")
		ed.load(packages.NewPacket(p, usrSettings.Settings()))
	}
}
Beispiel #2
0
func (p *plugin) loadKeyBindings() {
	ed := backend.GetEditor()
	tmp := ed.KeyBindings().Parent()

	ed.KeyBindings().SetParent(p)
	p.KeyBindings().Parent().KeyBindings().SetParent(tmp)

	pt := path.Join(p.Name(), "Default.sublime-keymap")
	p.load(packages.NewPacket(pt, p.KeyBindings().Parent().KeyBindings()))

	pt = path.Join(p.Name(), "Default ("+ed.Plat()+").sublime-keymap")
	p.load(packages.NewPacket(pt, p.KeyBindings()))
}
Beispiel #3
0
func (e *Editor) loadSettings() {
	e.platformSettings.Settings().SetParent(e.defaultSettings)
	e.Settings().SetParent(e.platformSettings)

	p := path.Join(LIME_DEFAULTS_PATH, "Preferences.sublime-settings")
	defPckt := packages.NewPacket(p, e.defaultSettings.Settings())
	e.load(defPckt)

	p = path.Join(LIME_DEFAULTS_PATH, "Preferences ("+e.Plat()+").sublime-settings")
	platPckt := packages.NewPacket(p, e.platformSettings.Settings())
	e.load(platPckt)

	p = path.Join(LIME_USER_PACKAGES_PATH, "Preferences.sublime-settings")
	usrPckt := packages.NewPacket(p, e.Settings())
	e.load(usrPckt)
}
Beispiel #4
0
func (p *plugin) loadSettings() {
	ed := backend.GetEditor()
	tmp := ed.Settings().Parent()

	ed.Settings().SetParent(p)
	p.Settings().Parent().Settings().Parent().Settings().SetParent(tmp)

	pt := path.Join(p.Name(), "Preferences.sublime-settings")
	p.load(packages.NewPacket(pt, p.Settings().Parent().Settings().Parent().Settings()))

	pt = path.Join(p.Name(), "Preferences ("+ed.Plat()+").sublime-settings")
	p.load(packages.NewPacket(pt, p.Settings().Parent().Settings()))

	pt = path.Join(backend.LIME_USER_PACKAGES_PATH, "Preferences.sublime-settings")
	p.load(packages.NewPacket(pt, p.Settings()))
}
Beispiel #5
0
func TestWatchingSettings(t *testing.T) {
	// TODO: This won't pass until the settings hierarchy is set up properly.
	return

	var path string = "testdata/Default.sublime-settings"

	editor := GetEditor()
	editor.loadSetting(packages.NewPacket(path, editor.Settings()))

	buf, err := ioutil.ReadFile(path)
	if err != nil {
		t.Fatal("Error in reading the default settings")
	}

	data := []byte("{\n\t\"tab_size\": 8\n}")
	err = ioutil.WriteFile(path, data, 0644)
	if err != nil {
		t.Fatal("Error in writing to setting")
	}

	time.Sleep(time.Millisecond * 10)

	if tab_size := editor.Settings().Get("tab_size").(float64); tab_size != 8 {
		t.Errorf("Expected tab_size equal to 8, but got %v", tab_size)
	}

	err = ioutil.WriteFile(path, buf, 0644)
	if err != nil {
		t.Fatal("Error in writing the default back to setting")
	}
}
Beispiel #6
0
func (e *Editor) loadSettings() {
	defSettings, platSettings := &HasSettings{}, &HasSettings{}
	platSettings.Settings().SetParent(defSettings)
	ed.Settings().SetParent(platSettings)

	p := path.Join(LIME_DEFAULTS_PATH, "Preferences.sublime-settings")
	defPckt := packages.NewPacket(p, defSettings.Settings())
	e.loadSetting(defPckt)

	p = path.Join(LIME_DEFAULTS_PATH, "Preferences ("+e.plat()+").sublime-settings")
	platPckt := packages.NewPacket(p, platSettings.Settings())
	e.loadSetting(platPckt)

	p = path.Join(LIME_USER_PACKETS_PATH, "Preferences.sublime-settings")
	userPckt := packages.NewPacket(p, e.Settings())
	e.loadSetting(userPckt)
}
Beispiel #7
0
func TestLoadKeyBinding(t *testing.T) {
	editor := GetEditor()
	editor.loadKeyBinding(packages.NewPacket("testdata/Default.sublime-keymap", new(keys.KeyBindings)))

	kb := editor.keyBindings.Filter(keys.KeyPress{Key: 'i'})
	if kb.Len() == 69 {
		t.Errorf("Expected editor to have key %d bound, but it didn't", 69)
	}
}
Beispiel #8
0
func TestLoadKeyBinding(t *testing.T) {
	editor := GetEditor()
	pkg := packages.NewPacket("testdata/Default.sublime-keymap", editor.KeyBindings())
	editor.load(pkg)

	kb := editor.KeyBindings().Filter(keys.KeyPress{Key: 'i'})
	if expectedLen := 3; kb.Len() != expectedLen {
		t.Errorf("Expected to have %d keys in the filter, but it had %d", expectedLen, kb.Len())
	}
}
Beispiel #9
0
func (e *Editor) loadKeyBindings() {
	e.KeyBindings().SetParent(e.userBindings)
	e.userBindings.KeyBindings().SetParent(e.platformBindings)
	e.platformBindings.KeyBindings().SetParent(e.defaultBindings)

	p := path.Join(LIME_DEFAULTS_PATH, "Default.sublime-keymap")
	defPckt := packages.NewPacket(p, e.defaultBindings.KeyBindings())
	e.load(defPckt)

	p = path.Join(LIME_DEFAULTS_PATH, "Default ("+e.Plat()+").sublime-keymap")
	platPckt := packages.NewPacket(p, e.platformBindings.KeyBindings())
	e.load(platPckt)

	p = path.Join(LIME_USER_PACKAGES_PATH, "Default.sublime-keymap")
	usrPckt := packages.NewPacket(p, e.userBindings.KeyBindings())
	e.load(usrPckt)

	p = path.Join(LIME_USER_PACKAGES_PATH, "Default ("+e.Plat()+").sublime-keymap")
	usrPlatPckt := packages.NewPacket(p, e.KeyBindings())
	e.load(usrPlatPckt)
}
Beispiel #10
0
func TestLoadSetting(t *testing.T) {
	editor := GetEditor()
	editor.load(packages.NewPacket("testdata/Default.sublime-settings", editor.Settings()))

	if editor.Settings().Has("tab_size") != true {
		t.Error("Expected editor settings to have tab_size, but it didn't")
	}

	tab_size := editor.Settings().Get("tab_size").(float64)
	if tab_size != 4 {
		t.Errorf("Expected tab_size to equal 4, got: %v", tab_size)
	}
}