2121 'RunCmd' ,
2222)})
2323
24+ client_actions = NS (** {k : k for k in (
25+ 'Activate' ,
26+ 'Restart' ,
27+ 'Shutdown' ,
28+ 'CmdOutput' ,
29+ )})
30+
2431class Config (object ):
2532 def __init__ (self , m ):
2633 self .override_settings = m .get ('OverrideSettings' ) or {}
@@ -48,33 +55,51 @@ def __init__(self, v={}):
4855
4956 self .client_actions = []
5057 for ca in (v .get ('ClientActions' ) or []):
51- if ca .get ('Name' ) == 'output' :
52- self .client_actions .append (CmdOutput (v = ca ))
53- else :
54- self .client_actions .append (ClientAction (v = ca ))
58+ CA = client_action_creators .get (ca .get ('Name' ) or '' ) or ClientAction
59+ self .client_actions .append (CA (v = ca ))
5560
5661 def __repr__ (self ):
5762 return repr (self .__dict__ )
5863
5964class ClientAction (object ):
6065 def __init__ (self , v = {}):
61- self .name = v .get ('Name' ) or ''
62- self .data = v .get ('Data' ) or {}
66+ self .action_name = v .get ('Name' ) or ''
67+ self .action_data = v .get ('Data' ) or {}
6368
6469 def __repr__ (self ):
6570 return repr (vars (self ))
6671
67- class CmdOutput (ClientAction ):
68- def __init__ (self , v = {} ):
72+ class ClientAction_Output (ClientAction ):
73+ def __init__ (self , v ):
6974 super ().__init__ (v = v )
70- self .fd = self .data .get ('Fd' ) or ''
71- self .output = self .data .get ('Output' ) or ''
72- self .close = self .data .get ('Close' ) or False
73- self .fd = self .data .get ('Fd' ) or ''
75+ ad = self .action_data
76+
77+ self .fd = ad .get ('Fd' ) or ''
78+ self .output = ad .get ('Output' ) or ''
79+ self .close = ad .get ('Close' ) or False
80+ self .fd = ad .get ('Fd' ) or ''
7481
7582 def __repr__ (self ):
7683 return repr (vars (self ))
7784
85+ class ClientAction_Activate (ClientAction ):
86+ def __init__ (self , v ):
87+ super ().__init__ (v = v )
88+ ad = self .action_data
89+
90+ self .path = ad .get ('Path' ) or ''
91+ self .name = ad .get ('Name' ) or ''
92+ self .row = ad .get ('Row' ) or 0
93+ self .col = ad .get ('Col' ) or 0
94+
95+ def __repr__ (self ):
96+ return repr (vars (self ))
97+
98+ client_action_creators = {
99+ client_actions .CmdOutput : ClientAction_Output ,
100+ client_actions .Activate : ClientAction_Activate ,
101+ }
102+
78103class Completion (object ):
79104 def __init__ (self , v ):
80105 self .query = v .get ('Query' ) or ''
@@ -198,38 +223,27 @@ def _editor_props(view):
198223 'Settings' : sett ,
199224 }
200225
226+ def view_is_9o (view ):
227+ return view is not None and view .settings ().get ('9o' )
228+
201229def _view_props (view ):
202- view = gs .active_view (view = view )
230+ was_9o = view_is_9o (view )
231+ if was_9o :
232+ view = gs .active_view ()
233+ else :
234+ view = gs .active_view (view = view )
235+
203236 if view is None :
204237 return {}
205238
206239 pos = gs .sel (view ).begin ()
207- row , col = view .rowcol (pos )
208240 scope , lang , fn , props = _view_header (view , pos )
209- wd = gs .basedir_or_cwd (fn )
210-
211- if lang == '9o' :
212- if 'prompt.9o' in scope :
213- r = view .extract_scope (pos )
214- pos -= r .begin ()
215- s = view .substr (r )
216- src = s .lstrip ().lstrip ('#' ).lstrip ()
217- pos -= len (s ) - len (src )
218- src = src .rstrip ()
219- else :
220- pos = 0
221- src = ''
222-
223- wd = view .settings ().get ('9o.wd' ) or wd
224- props ['Path' ] = '_.9o'
225- else :
226- src = _view_src (view , lang )
241+ wd = gs .getwd () or gs .basedir_or_cwd (fn )
242+ src = _view_src (view , lang )
227243
228244 props .update ({
229245 'Wd' : wd ,
230246 'Pos' : pos ,
231- 'Row' : row ,
232- 'Col' : col ,
233247 'Dirty' : view .is_dirty (),
234248 'Src' : src ,
235249 })
@@ -272,7 +286,6 @@ def _view_header(view, pos):
272286 return scope , lang , path , {
273287 'Path' : path ,
274288 'Name' : view_name (view , ext = ext , lang = lang ),
275- 'Ext' : ext ,
276289 'Hash' : _view_hash (view ),
277290 'Lang' : lang ,
278291 'Scope' : scope ,
@@ -296,6 +309,9 @@ def _view_scope_lang(view, pos):
296309 return ('' , '' )
297310
298311 scope = view .scope_name (pos ).strip ().lower ()
312+ if view_is_9o (view ):
313+ return (scope , 'cmd-promp' )
314+
299315 l = _scope_lang_pat .findall (scope )
300316 lang = l [- 1 ] if l else ''
301317 return (scope , lang )
0 commit comments