Skip to content
Permalink
Browse files

implement external cmdline + pasting in cmdline

  • Loading branch information
lunixbochs committed Nov 16, 2017
1 parent dd6f29c commit 4c20a772029dae085e466377b32da710ddc4dd87
Showing with 74 additions and 3 deletions.
  1. +13 −2 actual.py
  2. +8 −1 neo.py
  3. +53 −0 view.py
@@ -7,6 +7,7 @@
from .edit import Edit
from . import settings

class ActualSkipCmd(sublime_plugin.TextCommand): pass

class ActualEnable(sublime_plugin.ApplicationCommand):
def is_enabled(self):
@@ -114,10 +115,20 @@ def on_post_save_async(self, view):
# to prevent inconsistent updates
# then force a copy afterwards
def on_text_command(self, view, name, args):
v = ActualVim.get(view, create=False)
v = ActualVim.get(view, exact=False, create=False)
if not v:
return

if name == 'paste' and view.window().active_panel() == 'input' and v.cmd_panel:
tmp = []
for c in sublime.get_clipboard():
if c == '\n':
tmp.append('<cr>')
break
tmp.append(c)
v.press(''.join(tmp))
return ('actual_skip_cmd', {})

if name == 'drag_select':
v.drag_select = args.get('by')

@@ -128,7 +139,7 @@ def on_window_command(self, view, name, args):
self.on_text_command(view, name, args)

def on_post_text_command(self, view, name, args):
v = ActualVim.get(view, create=False)
v = ActualVim.get(view, exact=False, create=False)
if not v:
return

9 neo.py
@@ -147,7 +147,11 @@ def _setup(self):
self._sem.acquire()

# set up UI (before anything else so we can see errors)
options = {'popupmenu_external': True, 'rgb': True}
options = {
'ext_popupmenu': True,
'ext_cmdline': True,
'rgb': True,
}
self.nv.ui_attach(self.width, self.height, options)

# hidden buffers allow us to multiplex them
@@ -197,6 +201,9 @@ def on_notification(method, data):
self.av.on_bell()
elif name in ('popupmenu_show', 'popupmenu_hide', 'popupmenu_select'):
self.av.on_popupmenu(name, args)
elif name in ('cmdline_show', 'cmdline_pos', 'cmdline_special_char', 'cmdline_hide',
'cmdline_block_show', 'cmdline_block_append', 'cmdline_block_hide'):
self.av.on_cmdline(name, args)
vim.screen.redraw(data)
if self.av:
self.av.on_redraw(data, vim.screen)
53 view.py
@@ -44,6 +44,10 @@ def __init__(self, view):
self.keyq = queue.Queue()

self.view = view
self.cmd_panel = None
self.cmd_text = None
self.cmd_lock = threading.Lock()

self.last_sel = None
self.buf = None
self.sub_changes = None
@@ -54,6 +58,7 @@ def __init__(self, view):
self.last_size = None
self.block = False
self.block_hit = False
self.nosync = False

# settings are marked here when applying mode-specific settings, and erased after
self.tmpsettings = []
@@ -337,6 +342,8 @@ def sync_to_vim(self, force=False):

def sync_from_vim(self, edit=None):
if not self.actual: return
if self.nosync:
return

def update(view, edit):
with self.busy:
@@ -595,6 +602,51 @@ def render(update=False):
self.popup['selected'] = args[0][0]
render(update=True)

def on_cmdline(self, cmd, args):
with self.cmd_lock:
window = self.view.window()
if cmd == 'cmdline_show':
content, pos, firstc, prompt, indent, level = args[0]
text = content[0][1]

def on_done(s):
self.nosync = False
with self.update_lock:
self.update_needed += 1
def onready():
sublime.set_timeout(self.update, 0)
_, ready = neo.vim.press('<cr>', onready)
if ready: self.update()

def on_cancel():
if self.cmd_panel:
self.press('<esc>')

text = firstc + text
panel = self.cmd_panel
if panel:
if text != self.cmd_text:
with Edit(panel) as edit:
edit.replace(sublime.Region(0, panel.size()), text)
self.cmd_text = text
else:
panel = window.show_input_panel(prompt, text, on_done, None, on_cancel)
self.nosync = True
s = panel.settings()
s.set('av_input', True)
s.set('actual_mode', True)
_views[panel.id()] = self
self.cmd_panel = panel
elif cmd == 'cmdline_hide':
self.nosync = False
panel = self.cmd_panel
if panel:
self.cmd_panel = None
self.cmd_text = None
_views.pop(panel.id(), None)
if window.active_panel() == 'input':
window.run_command('hide_panel', {'cancel': True})

def on_write(self):
self.view.run_command('save')

@@ -678,6 +730,7 @@ def on_redraw(self, data, screen):
self.screen_changes = screen.changes
hl = screen.highlights()
sublime.set_timeout(lambda: self.highlight(hl), 0)
self.status_from_vim()

def on_appcmd(self, cmd, args): sublime.run_command(cmd, args or {})
def on_wincmd(self, cmd, args): self.view.window().run_command(cmd, args or {})

0 comments on commit 4c20a77

Please sign in to comment.
You can’t perform that action at this time.