def prepare_payload(self, ns): fname = "{}.clj".format(ns_to_path(ns)) base = 'test' if ns.endswith('-test') else 'src' open_with = self.nvim.vars.get('acid_open_new_file_with', 'edit') path = os.path.join(current_path(self.nvim), base, fname) directory = os.path.dirname(path) if not os.path.exists(directory): os.makedirs(directory) with open(path, 'w') as fpath: fpath.write('(ns {})'.format(ns)) self.nvim.command('silent {} {}'.format(open_with, path)) # Does not interact with nrepl return None
def prepare_payload(self, ns): files = list(list_clj_files(self.nvim)) path = '{}.clj'.format(ns_to_path(ns)) log.log_debug('Found all this clojure files: {}', files) log.log_debug('Attempting to match against {}', path) match = list(filter(lambda k: k.endswith(path), files)) if any(match): fpath, *_ = match fpath = os.path.relpath(fpath, start=current_path(self.nvim)) with open(fpath, 'r') as source: data = '\n'.join(source.readlines()) return { 'file': data, 'file-path': fpath, 'file-name': os.path.basename(fpath) } else: log.warning(self.nvim, 'no file found!')
def new_file(self, args): ns = args[0] has_path = len(args) > 1 if not has_path: fname = "{}.clj".format(ns_to_path(ns)) base = 'test' if ns.endswith('-test') else 'src' path = os.path.join(current_path(self.nvim), base, fname) else: path = args[1] if os.path.exists(path): log_debug("File already exists. Aborting.") return path directory = os.path.dirname(path) if not os.path.exists(directory): os.makedirs(directory) with open(path, 'w') as fpath: fpath.write('(ns {})'.format(ns)) return path