def run(self, edit, line_range=None, name='', plusplus_args='', forced=False): target_line = self.view.line(self.view.sel()[0].begin()) if line_range['text_range']: range = max( ex_range.calculate_range(self.view, line_range=line_range)[0]) target_line = self.view.line(self.view.text_point(range, 0)) target_point = min(target_line.b + 1, self.view.size()) # cheat a little bit to get the parsing right: # - forced == True means we need to execute a command if forced: if sublime.platform() == 'linux': for s in self.view.sel(): # TODO: make shell command configurable. the_shell = self.view.settings().get('linux_shell') the_shell = the_shell or os.path.expandvars("$SHELL") if not the_shell: sublime.status_message( "VintageEx: No shell name found.") return try: p = subprocess.Popen([the_shell, '-c', name], stdout=subprocess.PIPE) except Exception as e: print e sublime.status_message( "VintageEx: Error while executing command through shell." ) return self.view.insert(edit, s.begin(), p.communicate()[0][:-1]) elif sublime.platform() == 'windows': for s in self.view.sel(): p = subprocess.Popen(['cmd.exe', '/C', name], stdout=subprocess.PIPE, startupinfo=get_startup_info()) cp = 'cp' + get_oem_cp() rv = p.communicate()[0].decode(cp)[:-2].strip() self.view.insert(edit, s.begin(), rv) else: ex_error.handle_not_implemented() # Read a file into the current view. else: # Read the current buffer's contents and insert below current line. if not name: new_contents = self.view.substr( sublime.Region(0, self.view.size())) if self.view.substr(target_line.b) != '\n': new_contents = '\n' + new_contents self.view.insert(edit, target_point, new_contents) return # XXX read file "name" # we need proper filesystem autocompletion here else: ex_error.handle_not_implemented() return
def run(self, edit, line_range=None, name='', plusplus_args='', forced=False): target_line = self.view.line(self.view.sel()[0].begin()) if line_range['text_range']: range = max( ex_range.calculate_range(self.view, line_range=line_range)[0]) target_line = self.view.line(self.view.text_point(range, 0)) target_point = min(target_line.b + 1, self.view.size()) # cheat a little bit to get the parsing right: # - forced == True means we need to execute a command if forced: if sublime.platform() == 'linux': for s in self.view.sel(): # TODO: make shell command configurable. the_shell = self.view.settings().get('linux_shell') the_shell = the_shell or os.path.expandvars("$SHELL") if not the_shell: sublime.status_message( "VintageEx: No shell name found.") return try: p = subprocess.Popen([the_shell, '-c', name], stdout=subprocess.PIPE) except Exception as e: print(e) sublime.status_message( "VintageEx: Error while executing command through shell." ) return self.view.insert(edit, s.begin(), p.communicate()[0][:-1]) elif sublime.platform() == 'windows': for s in self.view.sel(): p = subprocess.Popen(['cmd.exe', '/C', name], stdout=subprocess.PIPE, startupinfo=get_startup_info()) cp = 'cp' + get_oem_cp() rv = p.communicate()[0].decode(cp)[:-2].strip() self.view.insert(edit, s.begin(), rv) else: ex_error.handle_not_implemented() # Read a file into the current view. else: # According to Vim's help, :r should read the current file's content # if no file name is given, but Vim doesn't do that. # TODO: implement reading a file into the buffer. ex_error.handle_not_implemented() return
def run(self, edit, line_range=None, name='', plusplus_args='', forced=False): target_line = self.view.line(self.view.sel()[0].begin()) if line_range['text_range']: range = max(ex_range.calculate_range(self.view, line_range=line_range)[0]) target_line = self.view.line(self.view.text_point(range, 0)) target_point = min(target_line.b + 1, self.view.size()) # cheat a little bit to get the parsing right: # - forced == True means we need to execute a command if forced: if sublime.platform() == 'linux': for s in self.view.sel(): # TODO: make shell command configurable. the_shell = self.view.settings().get('linux_shell') the_shell = the_shell or os.path.expandvars("$SHELL") if not the_shell: sublime.status_message("VintageEx: No shell name found.") return try: p = subprocess.Popen([the_shell, '-c', name], stdout=subprocess.PIPE) except Exception as e: print e sublime.status_message("VintageEx: Error while executing command through shell.") return self.view.insert(edit, s.begin(), p.communicate()[0][:-1]) elif sublime.platform() == 'windows': for s in self.view.sel(): p = subprocess.Popen(['cmd.exe', '/C', name], stdout=subprocess.PIPE, startupinfo=get_startup_info() ) cp = 'cp' + get_oem_cp() rv = p.communicate()[0].decode(cp)[:-2].strip() self.view.insert(edit, s.begin(), rv) else: ex_error.handle_not_implemented() # Read a file into the current view. else: # Read the current buffer's contents and insert below current line. if not name: new_contents = self.view.substr( sublime.Region(0, self.view.size())) if self.view.substr(target_line.b) != '\n': new_contents = '\n' + new_contents self.view.insert(edit, target_point, new_contents) return # XXX read file "name" # we need proper filesystem autocompletion here else: ex_error.handle_not_implemented() return
def run(self, edit, line_range=None, name='', plusplus_args='', forced=False): target_line = self.view.line(self.view.sel()[0].begin()) if line_range['text_range']: range = max(ex_range.calculate_range(self.view, line_range=line_range)[0]) target_line = self.view.line(self.view.text_point(range, 0)) target_point = min(target_line.b + 1, self.view.size()) # cheat a little bit to get the parsing right: # - forced == True means we need to execute a command if forced: if sublime.platform() == 'linux': for s in self.view.sel(): # TODO: make shell command configurable. the_shell = self.view.settings().get('linux_shell') the_shell = the_shell or os.path.expandvars("$SHELL") if not the_shell: sublime.status_message("VintageEx: No shell name found.") return try: p = subprocess.Popen([the_shell, '-c', name], stdout=subprocess.PIPE) except Exception as e: print e sublime.status_message("VintageEx: Error while executing command through shell.") return self.view.insert(edit, s.begin(), p.communicate()[0][:-1]) elif sublime.platform() == 'windows': for s in self.view.sel(): p = subprocess.Popen(['cmd.exe', '/C', name], stdout=subprocess.PIPE, startupinfo=get_startup_info() ) cp = 'cp' + get_oem_cp() rv = p.communicate()[0].decode(cp)[:-2].strip() self.view.insert(edit, s.begin(), rv) else: ex_error.handle_not_implemented() # Read a file into the current view. else: # According to Vim's help, :r should read the current file's content # if no file name is given, but Vim doesn't do that. # TODO: implement reading a file into the buffer. ex_error.handle_not_implemented() return
def run(self, edit, range='', name='', plusplus_args='', forced=False): target_line = self.view.line(self.view.sel()[0].begin()) if range: range = max(ex_range.calculate_range(self.view, range)[0]) target_line = self.view.line(self.view.text_point(range, 0)) target_point = min(target_line.b + 1, self.view.size()) # cheat a little bit to get the parsing right: # - forced == True means we need to execute a command if forced: if sublime.platform() == 'linux': for s in self.view.sel(): the_shell = os.path.expandvars("$SHELL") p = subprocess.Popen([the_shell, '-c', name], stdout=subprocess.PIPE) self.view.insert(edit, s.begin(), p.communicate()[0][:-1]) elif sublime.platform() == 'windows': for s in self.view.sel(): p = subprocess.Popen(['cmd.exe', '/C', name], stdout=subprocess.PIPE, startupinfo=get_startup_info() ) cp = 'cp' + get_oem_cp() rv = p.communicate()[0].decode(cp)[:-2].strip() self.view.insert(edit, s.begin(), rv) else: ex_error.handle_not_implemented() # Read a file into the current view. else: # Read the current buffer's contents and insert below current line. if not name: new_contents = self.view.substr( sublime.Region(0, self.view.size())) if self.view.substr(target_line.b) != '\n': new_contents = '\n' + new_contents self.view.insert(edit, target_point, new_contents) return # XXX read file "name" # we need proper filesystem autocompletion here else: ex_error.handle_not_implemented() return