Skip to content
Browse files

add basic support for registers (:delete)

  • Loading branch information...
1 parent 73b13a5 commit 0ef8058cf7e68d125db5765794a8bdf5608ff4b1 @guillermooo guillermooo committed
Showing with 32 additions and 5 deletions.
  1. +1 −1 ex_command_parser.py
  2. +31 −4 ex_commands.py
View
2 ex_command_parser.py
@@ -133,7 +133,7 @@
('delete', 'd'): ex_cmd_data(
command='ex_delete',
invocations=(
- re.compile(r' *(?P<register>[a-zA-Z0-9]) *(?P<count>\d+)'),
+ re.compile(r' *(?P<register>[a-zA-Z0-9])? *(?P<count>\d+)?'),
),
error_on=(ERR_UNWANTED_BANG,)
),
View
35 ex_commands.py
@@ -1,7 +1,11 @@
import sublime
import sublime_plugin
+import sys
import os
+
+sys.path.append(os.path.join(sublime.packages_path(), 'Vintage'))
+
import re
import subprocess
import tempfile
@@ -13,6 +17,8 @@
import ex_range
+from vintage import g_registers
+
GLOBAL_RANGES = []
@@ -21,6 +27,22 @@ def handle_not_implemented():
sublime.status_message('VintageEx: Not implemented')
+def set_register(text, register):
+ global g_registers
+ if register == '*' or register == '+':
+ sublime.set_clipboard(text)
+ elif register == '%':
+ pass
+ else:
+ reg = register.lower()
+ append = (reg != register)
+
+ if append and reg in g_registers:
+ g_registers[reg] += text
+ else:
+ g_registers[reg] = text
+
+
def filter_region(txt, command):
try:
contents = tempfile.NamedTemporaryFile(suffix='.txt', delete=False)
@@ -465,14 +487,19 @@ def run(self, edit, range='.', pattern=''):
class ExDelete(sublime_plugin.TextCommand):
def run(self, edit, range='.', register='', count=''):
# xxx somewhat different to vim's behavior
- if register.isdigit():
- count = register
- register = ''
-
rs = get_region_by_range(self.view, range)
self.view.sel().clear()
+
+ to_store = []
for r in rs:
self.view.sel().add(r)
+ if register:
+ to_store.append(self.view.substr(r))
+
+ # xxx: pasting from register isn't linewise if a range's specified
+ # xxx: but it works well with visual selections
+ if register:
+ set_register('\n'.join(to_store), register)
self.view.run_command('split_selection_into_lines')
self.view.run_command('run_macro_file',

0 comments on commit 0ef8058

Please sign in to comment.
Something went wrong with that request. Please try again.