From e478969e11c38a8bf1502d534dc1a33e49962022 Mon Sep 17 00:00:00 2001 From: Fredrik Ehnbom Date: Wed, 17 Apr 2013 16:55:01 +0200 Subject: [PATCH] View.ScoreSelector. Export constants to python api. --- backend/sublime/sublime_manual.go | 42 ++++++++++++ backend/sublime/sublime_plugin.py | 7 -- backend/sublime/sublime_test.go | 2 +- backend/sublime/testdata/api.txt | 106 ++++++++++++++++++------------ backend/view.go | 7 ++ 5 files changed, 115 insertions(+), 49 deletions(-) diff --git a/backend/sublime/sublime_manual.go b/backend/sublime/sublime_manual.go index 3e364b41..51ca3233 100644 --- a/backend/sublime/sublime_manual.go +++ b/backend/sublime/sublime_manual.go @@ -5,6 +5,7 @@ import ( "fmt" "lime/3rdparty/libs/gopy/lib" "lime/backend" + "lime/backend/render" "os" "strings" "time" @@ -141,6 +142,42 @@ func init() { {"OnQueryContextGlue", &_onQueryContextGlueClass}, {"ViewEventGlue", &_viewEventGlueClass}, } + type constant struct { + name string + constant int + } + constants := []constant{ + {"OP_EQUAL", int(backend.OpEqual)}, + {"OP_NOT_EQUAL", int(backend.OpNotEqual)}, + {"OP_REGEX_MATCH", int(backend.OpRegexMatch)}, + {"OP_NOT_REGEX_MATCH", int(backend.OpNotRegexMatch)}, + {"OP_REGEX_CONTAINS", int(backend.OpRegexContains)}, + {"OP_NOT_REGEX_CONTAINS", int(backend.OpNotRegexContains)}, + {"INHIBIT_WORD_COMPLETIONS", 0}, + {"INHIBIT_EXPLICIT_COMPLETIONS", 0}, + {"LITERAL", 0}, + {"IGNORECASE", 0}, + {"CLASS_WORD_START", 0}, + {"CLASS_WORD_END", 0}, + {"CLASS_PUNCTUATION_START", 0}, + {"CLASS_PUNCTUATION_END", 0}, + {"CLASS_SUB_WORD_START", 0}, + {"CLASS_SUB_WORD_END", 0}, + {"CLASS_LINE_START", 0}, + {"CLASS_LINE_END", 0}, + {"CLASS_EMPTY_LINE", 0}, + {"DRAW_EMPTY", int(render.DRAW_EMPTY)}, + {"HIDE_ON_MINIMAP", int(render.HIDE_ON_MINIMAP)}, + {"DRAW_EMPTY_AS_OVERWRITE", int(render.DRAW_EMPTY_AS_OVERWRITE)}, + {"DRAW_NO_FILL", int(render.DRAW_NO_FILL)}, + {"DRAW_NO_OUTLINE", int(render.DRAW_NO_OUTLINE)}, + {"DRAW_SOLID_UNDERLINE", int(render.DRAW_SOLID_UNDERLINE)}, + {"DRAW_STIPPLED_UNDERLINE", int(render.DRAW_STIPPLED_UNDERLINE)}, + {"DRAW_SQUIGGLY_UNDERLINE", int(render.DRAW_SQUIGGLY_UNDERLINE)}, + {"PERSISTENT", int(render.PERSISTENT)}, + {"HIDDEN", int(render.HIDDEN)}, + } + for _, cl := range classes { c, err := cl.c.Create() if err != nil { @@ -150,6 +187,11 @@ func init() { panic(err) } } + for _, c := range constants { + if err := m.AddIntConstant(c.name, c.constant); err != nil { + panic(err) + } + } py.AddToPath("../../backend/packages/") py.AddToPath("../../3rdparty/bundles/") py.AddToPath("../../backend/sublime/") diff --git a/backend/sublime/sublime_plugin.py b/backend/sublime/sublime_plugin.py index f90d5a928..c7e4031c 100644 --- a/backend/sublime/sublime_plugin.py +++ b/backend/sublime/sublime_plugin.py @@ -7,13 +7,6 @@ import sys import importlib -sublime.OP_EQUAL = 0 -sublime.OP_NOT_EQUAL = 1 -sublime.OP_REGEX_MATCH = 2 -sublime.OP_NOT_REGEX_MATCH = 3 -sublime.OP_REGEX_CONTAINS = 4 -sublime.OP_NOT_REGEX_CONTAINS = 5 - class Command(object): def is_enabled(self, args=None): return True diff --git a/backend/sublime/sublime_test.go b/backend/sublime/sublime_test.go index 3bccbfe1..547af784 100644 --- a/backend/sublime/sublime_test.go +++ b/backend/sublime/sublime_test.go @@ -91,7 +91,7 @@ func TestSublime(t *testing.T) { t.Error(err) } else { ty := item.Type() - line := fmt.Sprintf("%s%-30s: %s\n", indent, v2, ty) + line := fmt.Sprintf("%s%s\n", indent, v2) buf.WriteString(line) if ty == py.TypeType { f(indent+"\t", item, buf) diff --git a/backend/sublime/testdata/api.txt b/backend/sublime/testdata/api.txt index 79998584..c95bbf61 100644 --- a/backend/sublime/testdata/api.txt +++ b/backend/sublime/testdata/api.txt @@ -1,4 +1,4 @@ -ApplicationCommandGlue : +ApplicationCommandGlue __class__ __delattr__ __dir__ @@ -21,7 +21,23 @@ ApplicationCommandGlue : __sizeof__ __str__ __subclasshook__ -Edit : +CLASS_EMPTY_LINE +CLASS_LINE_END +CLASS_LINE_START +CLASS_PUNCTUATION_END +CLASS_PUNCTUATION_START +CLASS_SUB_WORD_END +CLASS_SUB_WORD_START +CLASS_WORD_END +CLASS_WORD_START +DRAW_EMPTY +DRAW_EMPTY_AS_OVERWRITE +DRAW_NO_FILL +DRAW_NO_OUTLINE +DRAW_SOLID_UNDERLINE +DRAW_SQUIGGLY_UNDERLINE +DRAW_STIPPLED_UNDERLINE +Edit __class__ __delattr__ __dir__ @@ -44,13 +60,19 @@ Edit : __sizeof__ __str__ __subclasshook__ -OP_EQUAL : -OP_NOT_EQUAL : -OP_NOT_REGEX_CONTAINS : -OP_NOT_REGEX_MATCH : -OP_REGEX_CONTAINS : -OP_REGEX_MATCH : -OnQueryContextGlue : +HIDDEN +HIDE_ON_MINIMAP +IGNORECASE +INHIBIT_EXPLICIT_COMPLETIONS +INHIBIT_WORD_COMPLETIONS +LITERAL +OP_EQUAL +OP_NOT_EQUAL +OP_NOT_REGEX_CONTAINS +OP_NOT_REGEX_MATCH +OP_REGEX_CONTAINS +OP_REGEX_MATCH +OnQueryContextGlue __class__ __delattr__ __dir__ @@ -73,7 +95,8 @@ OnQueryContextGlue : __sizeof__ __str__ __subclasshook__ -Region : +PERSISTENT +Region __class__ __delattr__ __dir__ @@ -108,7 +131,7 @@ Region : intersection intersects size -RegionSet : +RegionSet __class__ __delattr__ __dir__ @@ -139,7 +162,7 @@ RegionSet : contains regions substract -Settings : +Settings __class__ __delattr__ __dir__ @@ -169,7 +192,7 @@ Settings : has id set -TextCommandGlue : +TextCommandGlue __class__ __delattr__ __dir__ @@ -192,7 +215,7 @@ TextCommandGlue : __sizeof__ __str__ __subclasshook__ -View : +View __class__ __delattr__ __dir__ @@ -239,6 +262,7 @@ View : rowcol run_command scope_name + score_selector sel set_name set_overwrite_status @@ -251,7 +275,7 @@ View : visible_region window word -ViewEventGlue : +ViewEventGlue __class__ __delattr__ __dir__ @@ -274,7 +298,7 @@ ViewEventGlue : __sizeof__ __str__ __subclasshook__ -Window : +Window __class__ __delattr__ __dir__ @@ -304,7 +328,7 @@ Window : run_command settings views -WindowCommandGlue : +WindowCommandGlue __class__ __delattr__ __dir__ @@ -327,27 +351,27 @@ WindowCommandGlue : __sizeof__ __str__ __subclasshook__ -__doc__ : -__name__ : -__package__ : -active_window : -arch : -console : -error_message : -get_clipboard : -log_commands : -log_input : -message_dialog : -new_window : -ok_cancel_dialog : -packages_path : -platform : -register : -run_command : -set_clipboard : -set_timeout : -settings : -status_message : -test_window : -unregister : -version : +__doc__ +__name__ +__package__ +active_window +arch +console +error_message +get_clipboard +log_commands +log_input +message_dialog +new_window +ok_cancel_dialog +packages_path +platform +register +run_command +set_clipboard +set_timeout +settings +status_message +test_window +unregister +version diff --git a/backend/view.go b/backend/view.go index cd097ea5..1675b5fd 100644 --- a/backend/view.go +++ b/backend/view.go @@ -366,6 +366,13 @@ func (v *View) ScopeName(point int) string { return v.lastScopeName } +func (v *View) ScoreSelector(point int, selector string) int { + if sn := v.ScopeName(point); len(sn) > 0 { + return 1 + strings.Index(sn, selector) + } + return 0 +} + func (v *View) CommandHistory(idx int, modifying_only bool) (name string, args Args, count int) { // TODO: merge history when possible if i := v.undoStack.index(idx, modifying_only); i != -1 {