def open_file(self, root): '''Open the the file in vim using c.openWith.''' trace = False and not g.unitTesting c = self.c # Common arguments. if trace: g.trace(self.entire_file, root.h) cursor_arg = self.get_cursor_arg() tab_arg = "-tab" if self.uses_tab else "" remote_arg = "--remote" + tab_arg + "-silent" if self.entire_file: # vim-open-file. assert root.isAnyAtFileNode(), root args = [self.vim_exe, "--servername", "LEO", remote_arg] # No cursor arg. dir_ = g.setDefaultDirectory(c, root) fn = c.os_path_finalize_join(dir_, root.anyAtFileNodeName()) c_arg = '%s %s' % (' '.join(args), fn) command = 'subprocess.Popen(%s,shell=True)' % c_arg if trace: g.trace(command) try: subprocess.Popen(c_arg, shell=True) except OSError: g.es_print(command) g.es_exception() else: # vim-open-node root.v._vim_old_body = root.v.b # Not used in existing code, but it may be used elsewhere. args = [self.vim_exe, "--servername", "LEO", remote_arg, cursor_arg] if trace: g.trace('c.openWith(%s)' % args) d = {'args': args, 'ext': None, 'kind': 'subprocess.Popen', 'p': root.copy(), } c.openWith(d=d)
def open_file(self, root): '''Open the the file in vim using c.openWith.''' trace = (False or self.trace) and not g.unitTesting c = self.c efc = g.app.externalFilesController # Common arguments. if trace: g.trace(self.entire_file, root.h) # cursor_arg = self.get_cursor_arg() tab_arg = "-tab" if self.uses_tab else "" remote_arg = "--remote" + tab_arg + "-silent" args = [self.vim_exe, "--servername", "LEO", remote_arg] # No cursor arg. if self.entire_file: # vim-open-file assert root.isAnyAtFileNode(), root dir_ = g.setDefaultDirectory(c, root) fn = c.os_path_finalize_join(dir_, root.anyAtFileNodeName()) else: # vim-open-node ext = 'txt' fn = efc.create_temp_file(c, ext, c.p) c_arg = '%s %s' % (' '.join(args), fn) command = 'subprocess.Popen(%s,shell=True)' % c_arg if trace: g.trace(command) try: subprocess.Popen(c_arg, shell=True) except OSError: g.es_print(command) g.es_exception()
def open_with(self, c, d): ''' Called by c.openWith to handle items in the Open With... menu. 'd' a dict created from an @openwith settings node with these keys: 'args': the command-line arguments to be used to open the file. 'ext': the file extension. 'kind': the method used to open the file, such as subprocess.Popen. 'name': menu label (used only by the menu code). 'p': the nearest @<file> node, or None. 'shortcut': menu shortcut (used only by the menu code). ''' try: ext = d.get('ext') if not g.doHook('openwith1', c=c, p=c.p, v=c.p.v, d=d): root = d.get('p') if root: # Open the external file itself. directory = g.setDefaultDirectory(c, root) path = c.os_path_finalize_join(directory, root.anyAtFileNodeName()) self.open_file_in_external_editor(c, d, path) else: # Open a temp file containing just the node. p = c.p ext = self.compute_ext(c, p, ext) path = self.compute_temp_file_path(c, p, ext) if path: self.remove_temp_file(p, path) self.create_temp_file(c, ext, p) self.open_file_in_external_editor(c, d, path) g.doHook('openwith2', c=c, p=c.p, v=c.p.v, d=d) except Exception: g.es('unexpected exception in c.openWith') g.es_exception()
def open_file(self, root): '''Open the the file in vim using c.openWith.''' c = self.c efc = g.app.externalFilesController # Common arguments. tab_arg = "-tab" if self.uses_tab else "" remote_arg = "--remote" + tab_arg + "-silent" args = [self.vim_exe, "--servername", "LEO", remote_arg] # No cursor arg. if self.entire_file: # vim-open-file args.append( '+0') # Go to first line of the file. This is an Ex command. assert root.isAnyAtFileNode(), root dir_ = g.setDefaultDirectory(c, root) fn = c.expand_path_expression(root.anyAtFileNodeName()) # #1341. fn = c.os_path_finalize_join(dir_, fn) else: # vim-open-node args.append(self.get_cursor_arg()) # Set the cursor position to the current line in the node. ext = 'txt' fn = efc.create_temp_file(c, ext, c.p) c_arg = '%s %s' % (' '.join(args), fn) command = 'subprocess.Popen(%s,shell=True)' % c_arg try: subprocess.Popen(c_arg, shell=True) except OSError: g.es_print(command) g.es_exception()
def open_file(self, root): '''Open the the file in vim using c.openWith.''' c = self.c efc = g.app.externalFilesController # Common arguments. tab_arg = "-tab" if self.uses_tab else "" remote_arg = "--remote" + tab_arg + "-silent" args = [self.vim_exe, "--servername", "LEO", remote_arg] # No cursor arg. if self.entire_file: # vim-open-file args.append('+0') # Go to first line of the file. This is an Ex command. assert root.isAnyAtFileNode(), root dir_ = g.setDefaultDirectory(c, root) fn = c.os_path_finalize_join(dir_, root.anyAtFileNodeName()) else: # vim-open-node args.append(self.get_cursor_arg()) # Set the cursor position to the current line in the node. ext = 'txt' fn = efc.create_temp_file(c, ext, c.p) c_arg = '%s %s' % (' '.join(args), fn) command = 'subprocess.Popen(%s,shell=True)' % c_arg try: subprocess.Popen(c_arg, shell=True) except OSError: g.es_print(command) g.es_exception()
def open_file(self, root): '''Open the the file in vim using c.openWith.''' trace = False and not g.unitTesting c = self.c # Common arguments. if trace: g.trace(self.entire_file, root.h) cursor_arg = self.get_cursor_arg() tab_arg = "-tab" if self.uses_tab else "" remote_arg = "--remote" + tab_arg + "-silent" if self.entire_file: # vim-open-file. assert root.isAnyAtFileNode(), root args = [self.vim_exe, "--servername", "LEO", remote_arg] # No cursor arg. dir_ = g.setDefaultDirectory(c, root) fn = c.os_path_finalize_join(dir_, root.anyAtFileNodeName()) c_arg = '%s %s' % (' '.join(args), fn) command = 'subprocess.Popen(%s,shell=True)' % c_arg if trace: g.trace(command) try: subprocess.Popen(c_arg, shell=True) except OSError: g.es_print(command) g.es_exception() else: # vim-open-node root.v._vim_old_body = root.v.b # Not used in existing code, but it may be used elsewhere. args = [ self.vim_exe, "--servername", "LEO", remote_arg, cursor_arg ] if trace: g.trace('c.openWith(%s)' % args) d = { 'args': args, 'ext': None, 'kind': 'subprocess.Popen', 'p': root.copy(), } c.openWith(d=d)
def open_with(self, c, d): ''' Called by c.openWith to handle items in the Open With... menu. d is a dictionary created from an @openwith settings node. 'args': the command-line arguments to be used to open the file. 'ext': the file extension. 'kind': the method used to open the file, such as subprocess.Popen. 'name': menu label (used only by the menu code). 'shortcut': menu shortcut (used only by the menu code). d may also have the following entry, created by c.openWith: 'p': the nearest @<file> node. ''' trace = False and not g.unitTesting if trace: self.dump_d(d, 'open_with') try: ext = d.get('ext') if not g.doHook('openwith1', c=c, p=c.p, v=c.p.v, d=d): root = d.get('p') if root: # Called from open-with menu. dir_ = g.setDefaultDirectory(c, root) fn = c.os_path_finalize_join(dir_, root.anyAtFileNodeName()) self.open_temp_file(c, d, fn) else: p = c.p d['ext'] = self.get_ext(c, p, ext) fn = self.open_with_helper(c, d, p) if fn: self.open_temp_file(c, d, fn) g.doHook('openwith2', c=c, p=c.p, v=c.p.v, d=d) except Exception: g.es('unexpected exception in c.openWith') g.es_exception()
def set_expected_imported_headlines(self, root): '''Set v._imported_headline for every vnode.''' trace = False and not g.unitTesting cc = self c = cc.c ic = cc.c.importCommands language = g.scanForAtLanguage(c, root) ext = '.' + g.app.language_extension_dict.get(language) aClass = ic.classDispatchDict.get(ext) scanner = aClass(importCommands=ic, atAuto=True) # Duplicate the fn logic from ic.createOutline. theDir = g.setDefaultDirectory(c, root, importing=True) fn = c.os_path_finalize_join(theDir, root.h) fn = root.h.replace('\\', '/') junk, fn = g.os_path_split(fn) fn, junk = g.os_path_splitext(fn) if aClass and hasattr(scanner, 'headlineForNode'): for p in root.subtree(): if not hasattr(p.v, '_imported_headline'): h = scanner.headlineForNode(fn, p) setattr(p.v, '_imported_headline', h) if trace and h != p.h: g.trace('==>', h) # p.h,'==>',h
def set_expected_imported_headlines(self,root): '''Set v._imported_headline for every vnode.''' trace = False and not g.unitTesting cc = self c = cc.c ic = cc.c.importCommands language = g.scanForAtLanguage(c,root) ext = '.'+g.app.language_extension_dict.get(language) aClass = ic.classDispatchDict.get(ext) scanner = aClass(importCommands=ic,atAuto=True) # Duplicate the fn logic from ic.createOutline. theDir = g.setDefaultDirectory(c,root,importing=True) fn = c.os_path_finalize_join(theDir,root.h) fn = root.h.replace('\\','/') junk,fn = g.os_path_split(fn) fn,junk = g.os_path_splitext(fn) if aClass and hasattr(scanner,'headlineForNode'): for p in root.subtree(): if not hasattr(p.v,'_imported_headline'): h = scanner.headlineForNode(fn,p) setattr(p.v,'_imported_headline',h) if trace and h != p.h: g.trace('==>',h) # p.h,'==>',h
def open_with(self, c, d): ''' Called by c.openWith to handle items in the Open With... menu. d is a dictionary created from an @openwith settings node. 'args': the command-line arguments to be used to open the file. 'ext': the file extension. 'kind': the method used to open the file, such as subprocess.Popen. 'name': menu label (used only by the menu code). 'shortcut': menu shortcut (used only by the menu code). d may also have the following entry, created by c.openWith: 'p': the nearest @<file> node. ''' trace = False and not g.unitTesting if trace: self.dump_d(d, 'open_with') try: ext = d.get('ext') if not g.doHook('openwith1', c=c, p=c.p, v=c.p.v, d=d): root = d.get('p') if root: # Called from open-with menu. dir_ = g.setDefaultDirectory(c, root) fn = c.os_path_finalize_join(dir_, root.anyAtFileNodeName()) self.open_temp_file(c, d, fn) else: p = c.p ext = self.get_ext(c, p, ext) fn = self.open_with_helper(c, ext, p) if fn: self.open_temp_file(c, d, fn) g.doHook('openwith2', c=c, p=c.p, v=c.p.v, d=d) except Exception: g.es('unexpected exception in c.openWith') g.es_exception()