Permalink
Browse files

messily accept long commands for :r!, like :r! dir /D

  • Loading branch information...
1 parent 164dd0e commit 4a1eabe2cbbcdabda36a28933cd31a976885468b @guillermooo guillermooo committed Sep 26, 2011
Showing with 24 additions and 5 deletions.
  1. +10 −4 ex_command_parser.py
  2. +14 −1 ex_commands.py
View
@@ -7,7 +7,7 @@
# holds info about an ex command
-EX_CMD = namedtuple('ex_command', 'name command forced range args')
+EX_CMD = namedtuple('ex_command', 'name command forced range args args_extra')
EX_RANGE_REGEXP = re.compile(r'^(:?([.$%]|(:?/.*?/|\?.*?\?){1,2}|\d+)([-+]\d+)?)(([,;])(:?([.$]|(:?/.*?/|\?.*?\?){1,2}|\d+)([-+]\d+)?))?')
EX_ONLY_RANGE_REGEXP = re.compile(r'(?:([%$.]|\d+|/.*?(?<!\\)/|\?.*?\?)([-+]\d+)*(?:([,;])([%$.]|\d+|/.*?(?<!\\)/|\?.*?\?)([-+]\d+)*)?)|(^[/?].*$)')
@@ -63,7 +63,8 @@ def parse_command(cmd):
command='ex_goto',
forced=False,
range=cmd_name,
- args=''
+ args='',
+ args_extra=''
)
if cmd_name.startswith('!'):
@@ -73,7 +74,8 @@ def parse_command(cmd):
command=None,
forced=False,
range=None,
- args=args
+ args=args,
+ args_extra=''
)
range = get_cmd_line_range(cmd_name)
@@ -93,12 +95,16 @@ def parse_command(cmd):
cmd_data = EX_COMMANDS[cmd_data]
cmd_args = {}
+ cmd_args_extra = ''
if cmd_data['args'] and args:
cmd_args = dict(zip(cmd_data['args'], args))
+ if len(args) > len(cmd_data['args']):
+ cmd_args['_extra'] = ' '.join(args[len(cmd_data['args']):])
return EX_CMD(name=cmd_name,
command=cmd_data['command'],
forced=bang,
range=range,
- args=cmd_args
+ args=cmd_args,
+ args_extra=cmd_args_extra
)
View
@@ -8,7 +8,7 @@
def gather_buffer_info(v):
- """gathers data to be displayed by :ls/:buffers
+ """gathers data to be displayed by :ls or :buffers
"""
path = v.file_name()
if path:
@@ -63,13 +63,26 @@ def run(self, edit, args='', **kwargs):
class ExReadShellOut(sublime_plugin.TextCommand):
def run(self, edit, shell_cmd='', forced=False, **kwargs):
+ if '_extra' in kwargs:
+ shell_cmd += ' ' + kwargs['_extra']
if os.name == 'posix':
if forced:
shell = os.path.expandvars("$SHELL")
p = subprocess.Popen([shell, '-c', shell_cmd],
stdout=subprocess.PIPE)
self.view.insert(edit, self.view.sel()[0].begin(),
p.communicate()[0])
+ elif os.name == 'nt':
+ if forced:
+ p = subprocess.Popen(['cmd.exe', '/C', shell_cmd],
+ stdout=subprocess.PIPE)
+ # xxx I think only raymond chen can get this line right
+ # xxx :r! dir throws encoding error with utf_8_sig
+ # xxx :r! whoami throws error with utf_16_le
+ # xxx both if /U is passed to cmd.exe.
+ # FIXME get code page dynamically
+ rv = p.communicate()[0].decode('cp850')
+ self.view.insert(edit, self.view.sel()[0].begin(), rv)
else:
sublime.status_message('VintageEx: Not implemented.')

0 comments on commit 4a1eabe

Please sign in to comment.