def _export(cls, _format): """ Export current file in out format :flavor: pdf or html :returns: return code """ f = _format if _format == 'pdf' else 'html' emacs = os.path.expandvars(os.path.expanduser( \ settings.get(u'org_export_emacs', u'/usr/bin/emacs'))) if os.path.exists(emacs): cmd = [emacs, u'-nw', u'--batch', u'--visit=%s' \ % (vim.eval(u'expand("%:p")'), ), \ u'--funcall=org-export-as-%s' % f] # source init script as well init_script = cls._get_init_script() if init_script: cmd.extend(['--script', init_script]) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, \ stderr=subprocess.PIPE) p.wait() if p.returncode != 0 or settings.get(u'org_export_verbose') == 1: echom('\n'.join(p.communicate())) return p.returncode else: echoe(u'Unable to find emacs binary %s' % emacs)
def _export(cls, format_): """Export current file to format_. :format_: pdf or html :returns: return code """ emacsbin = os.path.expandvars(os.path.expanduser( settings.get(u'org_export_emacs', u'/usr/bin/emacs'))) if not os.path.exists(emacsbin): echoe(u'Unable to find emacs binary %s' % emacsbin) # build the export command cmd = [ emacsbin, u'-nw', u'--batch', u'--visit=%s' % vim.eval(u'expand("%:p")'), u'--funcall=%s' % format_ ] # source init script as well init_script = cls._get_init_script() if init_script: cmd.extend(['--script', init_script]) # export p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() if p.returncode != 0 or settings.get(u'org_export_verbose') == 1: echom('\n'.join(p.communicate())) return p.returncode
def _export(cls, format_): """Export current file to format. Args: format_: pdf or html Returns: return code """ emacsbin = os.path.expandvars( os.path.expanduser( settings.get(u'org_export_emacs', u'/usr/bin/emacs'))) if not os.path.exists(emacsbin): echoe(u'Unable to find emacs binary %s' % emacsbin) # build the export command cmd = [ emacsbin, u'-nw', u'--batch', u'--visit=%s' % vim.eval(u'expand("%:p")'), u'--funcall=%s' % format_ ] # source init script as well init_script = cls._get_init_script() if init_script: cmd.extend(['--script', init_script]) # export p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() if p.returncode != 0 or settings.get(u'org_export_verbose') == 1: echom('\n'.join(p.communicate())) return p.returncode
def register(self): """ Registration of plugin. Key bindings and other initialization should be done. """ settings.set('org_leader', ',') leader = settings.get('org_leader', ',') self.keybindings.append( Keybinding( '%sd' % leader, Plug( 'OrgToggleTodoToggle', ':silent! py ORGMODE.plugins["Todo"].toggle_todo_state()<CR>' ))) self.menu + ActionEntry('&TODO/DONE/-', self.keybindings[-1]) submenu = self.menu + Submenu('Select &keyword') self.keybindings.append( Keybinding( '<S-Right>', Plug( 'OrgToggleTodoForward', ':silent! py ORGMODE.plugins["Todo"].toggle_todo_state()<CR>' ))) submenu + ActionEntry('&Next keyword', self.keybindings[-1]) self.keybindings.append( Keybinding( '<S-Left>', Plug( 'OrgToggleTodoBackward', ':silent! py ORGMODE.plugins["Todo"].toggle_todo_state(False)<CR>' ))) submenu + ActionEntry('&Previous keyword', self.keybindings[-1]) settings.set('org_todo_keywords', ['TODO', '|', 'DONE'])
def register(self): u""" Registration of the plugin. Key bindings and other initialization should be done here. """ settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') self.keybindings.append( Keybinding( u'%ssa' % leader, Plug(u'OrgDateInsertTimestampActive', u':py ORGMODE.plugins[u"Date"].insert_timestamp()<CR>'))) self.menu + ActionEntry(u'Timest&', self.keybindings[-1]) self.keybindings.append( Keybinding( u'%ssi' % leader, Plug( u'OrgDateInsertTimestampInactive', u':py ORGMODE.plugins[u"Date"].insert_timestamp(False)<CR>' ))) self.menu + ActionEntry(u'Timestamp (&inactive)', self.keybindings[-1]) submenu = self.menu + Submenu(u'Change &Date') submenu + ActionEntry(u'Day &Earlier', u'<C-x>', u'<C-x>') submenu + ActionEntry(u'Day &Later', u'<C-a>', u'<C-a>')
def register(self): u""" Registration of plugin. Key bindings and other initialization should be done. """ settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') self.keybindings.append(Keybinding(u'%sd' % leader, Plug( u'OrgTodoToggle', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(interactive=True)<CR>'))) self.menu + ActionEntry(u'&TODO/DONE/-', self.keybindings[-1]) submenu = self.menu + Submenu(u'Select &keyword') self.keybindings.append(Keybinding(u'<S-Right>', Plug( u'OrgTodoForward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state()<CR>'))) submenu + ActionEntry(u'&Next keyword', self.keybindings[-1]) self.keybindings.append(Keybinding(u'<S-Left>', Plug( u'OrgTodoBackward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(direction=False)<CR>'))) submenu + ActionEntry(u'&Previous keyword', self.keybindings[-1]) self.keybindings.append(Keybinding(u'<C-S-Right>', Plug( u'OrgTodoSetForward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(next_set=True)<CR>'))) submenu + ActionEntry(u'Next keyword &set', self.keybindings[-1]) self.keybindings.append(Keybinding(u'<C-S-Left>', Plug( u'OrgTodoSetBackward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(direction=False, next_set=True)<CR>'))) submenu + ActionEntry(u'Previous &keyword set', self.keybindings[-1]) settings.set(u'org_todo_keywords', [u'TODO'.encode(u'utf-8'), u'|'.encode(u'utf-8'), u'DONE'.encode(u'utf-8')])
def _get_agendadocuments(self): u""" Return the org documents of the agenda files; return None if no agenda documents are defined. TODO: maybe turn this into an decorator? """ # load org files of agenda agenda_files = settings.get(u'org_agenda_files', u',') if not agenda_files or agenda_files == ',': echoe((u"No org_agenda_files defined. Use :let " u"g:org_agenda_files=['~/org/index.org'] to add " u"files to the agenda view.")) return # glob for files in agenda_files resolved_files = [] for f in agenda_files: f = glob.glob(os.path.join(os.path.expanduser(os.path.dirname(f)), os.path.basename(f))) resolved_files.extend(f) agenda_files = [os.path.realpath(f) for f in resolved_files] # load the agenda files into buffers for agenda_file in agenda_files: vim.command((u'badd %s' % agenda_file.replace(" ", "\ ")).encode(u'utf-8')) # determine the buffer nr of the agenda files agenda_nums = [get_bufnumber(fn) for fn in agenda_files] # collect all documents of the agenda files and create the agenda return [ORGMODE.get_document(i) for i in agenda_nums if i is not None]
def register(self): u""" Registration of the plugin. Key bindings and other initialization should be done here. """ settings.set(u"org_leader", u",") leader = settings.get(u"org_leader", u",") self.keybindings.append( Keybinding( u"%ssa" % leader, Plug(u"OrgDateInsertTimestampActive", u':py ORGMODE.plugins[u"Date"].insert_timestamp()<CR>'), ) ) self.menu + ActionEntry(u"Timest&", self.keybindings[-1]) self.keybindings.append( Keybinding( u"%ssi" % leader, Plug(u"OrgDateInsertTimestampInactive", u':py ORGMODE.plugins[u"Date"].insert_timestamp(False)<CR>'), ) ) self.menu + ActionEntry(u"Timestamp (&inactive)", self.keybindings[-1]) submenu = self.menu + Submenu(u"Change &Date") submenu + ActionEntry(u"Day &Earlier", u"<C-x>", u"<C-x>") submenu + ActionEntry(u"Day &Later", u"<C-a>", u"<C-a>")
def _get_agendadocuments(self): u""" Return the org documents of the agenda files; return None if no agenda documents are defined. TODO: maybe turn this into an decorator? """ # load org files of agenda agenda_files = settings.get(u'vimwiki_org_agenda_files', u',') if not agenda_files or agenda_files == ',': echoe((u"No org_agenda_files defined. Use :let " u"g:org_agenda_files=['~/org/index.org'] to add " u"files to the agenda view.")) return # glob for files in agenda_files resolved_files = [] for f in agenda_files: f = glob.glob( os.path.join(os.path.expanduser(os.path.dirname(f)), os.path.basename(f))) resolved_files.extend(f) agenda_files = [os.path.realpath(f) for f in resolved_files] # load the agenda files into buffers for agenda_file in agenda_files: vim.command( (u'badd %s' % agenda_file.replace(" ", "\ ")).encode(u'utf-8')) # determine the buffer nr of the agenda files agenda_nums = [get_bufnumber(fn) for fn in agenda_files] # collect all documents of the agenda files and create the agenda return [ORGMODE.get_document(i) for i in agenda_nums if i is not None]
def _get_agendadocuments(self): u""" Return the org documents of the agenda files; return None if no agenda documents are defined. TODO: maybe turn this into an decorator? """ # load org files of agenda agenda_files = settings.get(u'org_agenda_files', u',') if not agenda_files or agenda_files == ',': echoe((u"No org_agenda_files defined. Use :let " u"g:org_agenda_files=['~/org/index.org'] to add " u"files to the agenda view.")) return agenda_files = [os.path.expanduser(f) for f in agenda_files] for agenda_file in agenda_files: vim.command((u'badd %s' % agenda_file).encode(u'utf-8')) # determine the buffer nr of the agenda files agenda_nums = [get_bufnumber(fn) for fn in agenda_files] # collect all documents of the agenda files and create the agenda return [ORGMODE.get_document(i) for i in agenda_nums if i is not None]
def _get_init_script(cls): init_script = settings.get(u'org_export_init_script', u'') if init_script: init_script = os.path.expandvars(os.path.expanduser(init_script)) if os.path.exists(init_script): return init_script else: echoe(u'Unable to find init script %s' % init_script)
def toggle_todo_state( cls, direction=Direction.FORWARD, interactive=False, next_set=False): u""" Toggle state of TODO item :returns: The changed heading """ d = ORGMODE.get_document(allow_dirty=True) # get heading heading = d.find_current_heading() if not heading: vim.eval(u'feedkeys("^", "n")') return todo_states = d.get_todo_states(strip_access_key=False) # get todo states if not todo_states: echom(u'No todo keywords configured.') return current_state = heading.todo # get new state interactively if interactive: # determine position of the interactive prompt prompt_pos = settings.get(u'org_todo_prompt_position', u'botright') if prompt_pos not in [u'botright', u'topleft']: prompt_pos = u'botright' # pass todo states to new window ORGTODOSTATES[d.bufnr] = todo_states settings.set( u'org_current_state_%d' % d.bufnr, current_state if current_state is not None else u'', overwrite=True) todo_buffer_exists = bool(int(vim.eval(u_encode( u'bufexists("org:todo/%d")' % (d.bufnr, ))))) if todo_buffer_exists: # if the buffer already exists, reuse it vim.command(u_encode( u'%s sbuffer org:todo/%d' % (prompt_pos, d.bufnr, ))) else: # create a new window vim.command(u_encode( u'keepalt %s %dsplit org:todo/%d' % (prompt_pos, len(todo_states), d.bufnr))) else: new_state = Todo._get_next_state( current_state, todo_states, direction=direction, next_set=next_set) cls.set_todo_state(new_state) # plug plug = u'OrgTodoForward' if direction == Direction.BACKWARD: plug = u'OrgTodoBackward' return plug
def _get_states(cls): """ Return the next states divided in TODO states and DONE states. """ states = settings.get('org_todo_keywords', []) if not '|' in states: return states[:-1], [states[-1]] else: seperator_pos = states.index('|') return states[0:seperator_pos], states[seperator_pos + 1:]
def _get_states(cls): u""" Return the next states divided in TODO states and DONE states. """ states = settings.get(u'org_todo_keywords', []) if not u'|' in states: return states[:-1], [states[-1]] else: seperator_pos = states.index(u'|') return states[0:seperator_pos], states[seperator_pos + 1:]
def toggle_todo_state(cls, direction=Direction.FORWARD, interactive=False, next_set=False): u""" Toggle state of TODO item :returns: The changed heading """ d = ORGMODE.get_document(allow_dirty=True) # get heading heading = d.find_current_heading() if not heading: vim.eval(u'feedkeys("^", "n")') return todo_states = d.get_todo_states(strip_access_key=False) # get todo states if not todo_states: echom(u'No todo keywords configured.') return current_state = heading.todo # get new state interactively if interactive: # determine position of the interactive prompt prompt_pos = settings.get(u'org_todo_prompt_position', u'botright') if prompt_pos not in [u'botright', u'topleft']: prompt_pos = u'botright' # pass todo states to new window ORGTODOSTATES[d.bufnr] = todo_states settings.set( u'org_current_state_%d' % d.bufnr, current_state if current_state is not None else u'', overwrite=True) todo_buffer_exists = bool(int(vim.eval(( u'bufexists("org:todo/%d")' % (d.bufnr, )).encode(u'utf-8')))) if todo_buffer_exists: # if the buffer already exists, reuse it vim.command(( u'%s sbuffer org:todo/%d' % (prompt_pos, d.bufnr, )).encode(u'utf-8')) else: # create a new window vim.command(( u'keepalt %s %dsplit org:todo/%d' % (prompt_pos, len(todo_states), d.bufnr)).encode(u'utf-8')) else: new_state = Todo._get_next_state( current_state, todo_states, direction=direction, interactive=interactive, next_set=next_set) cls.set_todo_state(new_state) # plug plug = u'OrgTodoForward' if direction == Direction.BACKWARD: plug = u'OrgTodoBackward' return plug
def get_todo_states(self, strip_access_key=True): u""" Returns a list containing a tuple of two lists of allowed todo states split by todo and done states. Multiple todo-done state sequences can be defined. :returns: [([todo states], [done states]), ..] """ states = settings.get(u'org_todo_keywords', []) # TODO this function gets called too many times when change of state of # one todo is triggered, check with: # print(states) # this should be changed by saving todo states into some var and only # if new states are set hook should be called to register them again # into a property # TODO move this to documents.py, it is all tangled up like this, no # structure... if type(states) not in (list, tuple): return [] def parse_states(s, stop=0): res = [] if not s: return res if type(s[0]) in (unicode, str): r = [] for i in s: _i = i if type(_i) == str: _i = u_decode(_i) if type(_i) == unicode and _i: if strip_access_key and u'(' in _i: _i = _i[:_i.index(u'(')] if _i: r.append(_i) else: r.append(_i) if not u'|' in r: if not stop: res.append((r[:-1], [r[-1]])) else: res = (r[:-1], [r[-1]]) else: seperator_pos = r.index(u'|') if not stop: res.append((r[0:seperator_pos], r[seperator_pos + 1:])) else: res = (r[0:seperator_pos], r[seperator_pos + 1:]) elif type(s) in (list, tuple) and not stop: for i in s: r = parse_states(i, stop=1) if r: res.append(r) return res return parse_states(states)
def _get_agendadocuments(self): u""" Return the org documents of the agenda files; return None if no agenda documents are defined. TODO: maybe turn this into an decorator? """ # load org files of agenda agenda_files = settings.get(u'org_agenda_files', u',') if not agenda_files or agenda_files == ',': echoe(u"No org_agenda_files defined. Use :let " u"g:org_agenda_files=['~/org/index.org'] to add " u"files to the agenda view.") return return self._load_agendafiles(agenda_files)
def register(self): u""" Registration of plugin. Key bindings and other initialization should be done. """ # register plug self.keybindings.append(Keybinding(u'<Tab>', Plug(u'OrgToggleFolding', u':py ORGMODE.plugins[u"ShowHide"].toggle_folding()<CR>'))) self.menu + ActionEntry(u'&Cycle Visibility', self.keybindings[-1]) settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') self.keybindings.append(Keybinding(u'%s,' % (leader, ), u':exe ":set fdl=". (&fdl - 1)<CR>', mode=MODE_NORMAL)) self.keybindings.append(Keybinding(u'%s.' % (leader, ), u':exe ":set fdl=". (&fdl + 1)<CR>', mode=MODE_NORMAL)) for i in xrange(0, 10): self.keybindings.append(Keybinding(u'%s%d' % (leader, i), u'zM:set fdl=%d<CR>' % i, mode=MODE_NORMAL))
def _get_agendadocuments(self): u""" Return the org documents of the agenda files; return None if no agenda documents are defined. TODO: maybe turn this into an decorator? """ # load org files of agenda agenda_files = settings.get(u'org_agenda_files', u',') if not agenda_files or agenda_files == ',': echoe(( u"No org_agenda_files defined. Use :let " u"g:org_agenda_files=['~/org/index.org'] to add " u"files to the agenda view.")) return return self._load_agendafiles(agenda_files)
def register(self): """ Registration of plugin. Key bindings and other initialization should be done. """ # an Action menu entry which binds "keybinding" to action ":action" settings.set('org_tags_column', '77') settings.set('org_tags_completion_ignorecase', '0') settings.set('org_leader', ',') leader = settings.get('org_leader', ',') self.keybindings.append( Keybinding( '%st' % leader, Plug('OrgSetTags', ':py ORGMODE.plugins["TagsProperties"].set_tags()<CR>'))) self.menu + ActionEntry('Set &Tags', self.keybindings[-1]) self.commands.append( Command( 'OrgTagsRealign', ":py ORGMODE.plugins['TagsProperties'].realign_all_tags()")) # workaround to align tags when user is leaving insert mode vim.command("""function Org_complete_tags(ArgLead, CmdLine, CursorPos) python << EOF ORGMODE.plugins['TagsProperties'].complete_tags() EOF if exists('b:org_complete_tags') let tmp = b:org_complete_tags unlet b:org_complete_tags return tmp else return [] endif endfunction""") # this is for all org files opened after this file vim.command( "au FileType org :au InsertLeave <buffer> :py ORGMODE.plugins['TagsProperties'].realign_tags()" ) # this is for the current file vim.command( "au InsertLeave <buffer> :py ORGMODE.plugins['TagsProperties'].realign_tags()" )
def complete_tags(cls): u""" build a list of tags and store it in variable b:org_tag_completion """ d = ORGMODE.get_document() heading = d.current_heading() if not heading: return leading_portion = vim.eval(u'a:ArgLead').decode(u'utf-8') cursor = int(vim.eval(u'a:CursorPos')) # extract currently completed tag idx_orig = leading_portion.rfind(u':', 0, cursor) if idx_orig == -1: idx = 0 else: idx = idx_orig current_tag = leading_portion[idx:cursor].lstrip(u':') head = leading_portion[:idx + 1] if idx_orig == -1: head = u'' tail = leading_portion[cursor:] # extract all tags of the current file all_tags = set() for h in d.all_headings(): for t in h.tags: all_tags.add(t) ignorecase = bool( int( settings.get(u'org_tag_completion_ignorecase', int(vim.eval(u'&ignorecase'))))) possible_tags = [] current_tags = heading.tags for t in all_tags: if ignorecase: if t.lower().startswith(current_tag.lower()): possible_tags.append(t) elif t.startswith(current_tag): possible_tags.append(t) vim.command(( u'let b:org_complete_tags = [%s]' % u', '.join([u'"%s%s:%s"' % (head, i, tail) for i in possible_tags])).encode(u'utf-8'))
def get_todo_states(self, strip_access_key=True): u""" Returns a list containing a tuple of two lists of allowed todo states split by todo and done states. Multiple todo-done state sequences can be defined. :returns: [([todo states], [done states]), ..] """ states = settings.get(u'vimwiki_org_todo_keywords', []) if type(states) not in (list, tuple): return [] def parse_states(s, stop=0): res = [] if not s: return res if type(s[0]) in (unicode, str): r = [] for i in s: _i = i if type(_i) == str: _i = _i.decode(u'utf-8') if type(_i) == unicode and _i: if strip_access_key and u'(' in _i: _i = _i[:_i.index(u'(')] if _i: r.append(_i) else: r.append(_i) if not u'|' in r: if not stop: res.append((r[:-1], [r[-1]])) else: res = (r[:-1], [r[-1]]) else: seperator_pos = r.index(u'|') if not stop: res.append((r[0:seperator_pos], r[seperator_pos + 1:])) else: res = (r[0:seperator_pos], r[seperator_pos + 1:]) elif type(s) in (list, tuple) and not stop: for i in s: r = parse_states(i, stop=1) if r: res.append(r) return res return parse_states(states)
def register(self): """ Registration of the plugin. Key bindings and other initialization should be done here. """ settings.set('org_leader', ',') leader = settings.get('org_leader', ',') self.keybindings.append(Keybinding('%stn' % leader, Plug('OrgDateInsertTimestampActive', ':py ORGMODE.plugins["Date"].insert_timestamp()<CR>'))) self.menu + ActionEntry('Timestamp', self.keybindings[-1]) self.keybindings.append(Keybinding('%sti' % leader, Plug('OrgDateInsertTimestampInactive', ':py ORGMODE.plugins["Date"].insert_timestamp(False)<CR>'))) self.menu + ActionEntry('Timestamp (inactive)', self.keybindings[-1])
def complete_tags(cls): u""" build a list of tags and store it in variable b:org_tag_completion """ d = ORGMODE.get_document() heading = d.current_heading() if not heading: return leading_portion = u_decode(vim.eval(u'a:ArgLead')) cursor = int(vim.eval(u'a:CursorPos')) # extract currently completed tag idx_orig = leading_portion.rfind(u':', 0, cursor) if idx_orig == -1: idx = 0 else: idx = idx_orig current_tag = leading_portion[idx: cursor].lstrip(u':') head = leading_portion[:idx + 1] if idx_orig == -1: head = u'' tail = leading_portion[cursor:] # extract all tags of the current file all_tags = set() for h in d.all_headings(): for t in h.tags: all_tags.add(t) ignorecase = bool(int(settings.get(u'org_tag_completion_ignorecase', int(vim.eval(u'&ignorecase'))))) possible_tags = [] # TODO current tags never used... current_tags = heading.tags for t in all_tags: if ignorecase: if t.lower().startswith(current_tag.lower()): possible_tags.append(t) elif t.startswith(current_tag): possible_tags.append(t) vim.command(u_encode(u'let b:org_complete_tags = [%s]' % u', '.join([u'"%s%s:%s"' % (head, i, tail) for i in possible_tags])))
def register(self): u""" Registration and keybindings. """ # leader settings settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') # to PDF self.keybindings.append(Keybinding(u'%sep' % leader, Plug(u'OrgExportToPDF', u':py ORGMODE.plugins[u"Export"].topdf()<CR>'))) self.menu + ActionEntry(u'To PDF (via Emacs)', self.keybindings[-1]) # to HTML self.keybindings.append(Keybinding(u'%seh' % leader, Plug(u'OrgExportToHTML', u':py ORGMODE.plugins[u"Export"].tohtml()<CR>'))) self.menu + ActionEntry(u'To HTML (via Emacs)', self.keybindings[-1])
def complete_tags(cls): """ build a list of tags and store it in variable b:org_tag_completion """ heading = Document.current_heading() if not heading: return leading_portion = vim.eval('a:ArgLead') cursor = int(vim.eval('a:CursorPos')) # extract currently completed tag idx_orig = leading_portion.rfind(':', 0, cursor) if idx_orig == -1: idx = 0 else: idx = idx_orig current_tag = leading_portion[idx: cursor].lstrip(':') head = leading_portion[:idx + 1] if idx_orig == -1: head = '' tail = leading_portion[cursor:] # extract all tags of the current file all_tags = set() for h in Document.headings(): for t in h.tags: all_tags.add(t) ignorecase = bool(int(settings.get('org_tags_completion_ignorecase', '0'))) possible_tags = [] current_tags = heading.tags for t in all_tags: if ignorecase: if t.lower().startswith(current_tag.lower()): possible_tags.append(t) elif t.startswith(current_tag): possible_tags.append(t) vim.command('let b:org_complete_tags = [%s]' % ', '.join(['"%s%s:%s"' % (head, i, tail) for i in possible_tags]))
def register(self): u""" Registration of the plugin. Key bindings and other initialization should be done here. """ settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') self.keybindings.append(Keybinding(u'%ssa' % leader, Plug(u'OrgDateInsertTimestampActive', u':py ORGMODE.plugins[u"Date"].insert_timestamp()<CR>'))) self.menu + ActionEntry(u'Timest&', self.keybindings[-1]) self.keybindings.append(Keybinding(u'%ssi' % leader, Plug(u'OrgDateInsertTimestampInactive', u':py ORGMODE.plugins[u"Date"].insert_timestamp(False)<CR>'))) self.menu + ActionEntry(u'Timestamp (&inactive)', self.keybindings[-1]) submenu = self.menu + Submenu(u'Change &Date') submenu + ActionEntry(u'Day &Earlier', u'<C-x>', u'<C-x>') submenu + ActionEntry(u'Day &Later', u'<C-a>', u'<C-a>')
def register(self): """ Registration of plugin. Key bindings and other initialization should be done. """ settings.set('org_leader', ',') leader = settings.get('org_leader', ',') self.keybindings.append(Keybinding('%sd' % leader, Plug( 'OrgToggleTodoToggle', ':silent! py ORGMODE.plugins["Todo"].toggle_todo_state()<CR>'))) self.menu + ActionEntry('&TODO/DONE/-', self.keybindings[-1]) submenu = self.menu + Submenu('Select &keyword') self.keybindings.append(Keybinding('<S-Right>', Plug( 'OrgToggleTodoForward', ':silent! py ORGMODE.plugins["Todo"].toggle_todo_state()<CR>'))) submenu + ActionEntry('&Next keyword', self.keybindings[-1]) self.keybindings.append(Keybinding('<S-Left>', Plug( 'OrgToggleTodoBackward', ':silent! py ORGMODE.plugins["Todo"].toggle_todo_state(False)<CR>'))) submenu + ActionEntry('&Previous keyword', self.keybindings[-1]) settings.set('org_todo_keywords', ['TODO', '|', 'DONE'])
def register(self): u""" Registration of plugin. Key bindings and other initialization should be done. """ settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') self.keybindings.append(Keybinding(u'%sd' % leader, Plug( u'OrgTodoToggle', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(interactive=True)<CR>'))) self.menu + ActionEntry(u'&TODO/DONE/-', self.keybindings[-1]) submenu = self.menu + Submenu(u'Select &keyword') self.keybindings.append(Keybinding(u'<S-Right>', Plug( u'OrgTodoForward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state()<CR>'))) submenu + ActionEntry(u'&Next keyword', self.keybindings[-1]) self.keybindings.append(Keybinding(u'<S-Left>', Plug( u'OrgTodoBackward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(direction=False)<CR>'))) submenu + ActionEntry(u'&Previous keyword', self.keybindings[-1]) self.keybindings.append(Keybinding(u'<C-S-Right>', Plug( u'OrgTodoSetForward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(next_set=True)<CR>'))) submenu + ActionEntry(u'Next keyword &set', self.keybindings[-1]) self.keybindings.append(Keybinding(u'<C-S-Left>', Plug( u'OrgTodoSetBackward', u':py ORGMODE.plugins[u"Todo"].toggle_todo_state(direction=False, next_set=True)<CR>'))) submenu + ActionEntry(u'Previous &keyword set', self.keybindings[-1]) settings.set(u'org_todo_keywords', [u'TODO'.encode(u'utf-8'), u'|'.encode(u'utf-8'), u'DONE'.encode(u'utf-8')]) vim.command(u'au orgmode BufReadCmd org:todo/* :py ORGMODE.plugins[u"Todo"].init_org_todo()'.encode(u'utf-8'))
def register(self): u""" Registration and keybindings. """ # leader settings settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') # to PDF self.keybindings.append( Keybinding( u'%sep' % leader, Plug(u'OrgExportToPDF', u':py ORGMODE.plugins[u"Export"].topdf()<CR>'))) self.menu + ActionEntry(u'To PDF (via Emacs)', self.keybindings[-1]) # to HTML self.keybindings.append( Keybinding( u'%seh' % leader, Plug(u'OrgExportToHTML', u':py ORGMODE.plugins[u"Export"].tohtml()<CR>'))) self.menu + ActionEntry(u'To HTML (via Emacs)', self.keybindings[-1])
def register(self): u""" Registration of the plugin. Key bindings and other initialization should be done here. """ settings.set(u'org_leader', u',') leader = settings.get(u'org_leader', u',') self.keybindings.append(Keybinding(u'%scat' % leader, Plug(u'OrgAgendaTodo', u':py ORGMODE.plugins[u"Agenda"].list_all_todos()<CR>'))) self.menu + ActionEntry(u'Agenda for all TODOs', self.keybindings[-1]) self.keybindings.append(Keybinding(u'%scaa' % leader, Plug(u'OrgAgendaWeek', u':py ORGMODE.plugins[u"Agenda"].list_next_week()<CR>'))) self.menu + ActionEntry(u'Agenda for the week', self.keybindings[-1]) self.keybindings.append(Keybinding(u'%scaL' % leader, Plug(u'OrgAgendaTimeline', u':py ORGMODE.plugins[u"Agenda"].list_timeline()<CR>'))) self.menu + ActionEntry(u'Timeline for this buffer', self.keybindings[-1])
def register(self): """ Registration of the plugin. Key bindings and other initialization should be done here. """ settings.set('org_leader', ',') leader = settings.get('org_leader', ',') self.keybindings.append( Keybinding( '%stn' % leader, Plug('OrgDateInsertTimestampActive', ':py ORGMODE.plugins["Date"].insert_timestamp()<CR>'))) self.menu + ActionEntry('Timestamp', self.keybindings[-1]) self.keybindings.append( Keybinding( '%sti' % leader, Plug( 'OrgDateInsertTimestampInactive', ':py ORGMODE.plugins["Date"].insert_timestamp(False)<CR>')) ) self.menu + ActionEntry('Timestamp (inactive)', self.keybindings[-1])
def register(self): """ Registration of plugin. Key bindings and other initialization should be done. """ # an Action menu entry which binds "keybinding" to action ":action" settings.set('org_tags_column', '77') settings.set('org_tags_completion_ignorecase', '0') settings.set('org_leader', ',') leader = settings.get('org_leader', ',') self.keybindings.append(Keybinding('%st' % leader, Plug('OrgSetTags', ':py ORGMODE.plugins["TagsProperties"].set_tags()<CR>'))) self.menu + ActionEntry('Set &Tags', self.keybindings[-1]) self.commands.append(Command('OrgTagsRealign', ":py ORGMODE.plugins['TagsProperties'].realign_all_tags()")) # workaround to align tags when user is leaving insert mode vim.command("""function Org_complete_tags(ArgLead, CmdLine, CursorPos) python << EOF ORGMODE.plugins['TagsProperties'].complete_tags() EOF if exists('b:org_complete_tags') let tmp = b:org_complete_tags unlet b:org_complete_tags return tmp else return [] endif endfunction""") # this is for all org files opened after this file vim.command("au FileType org :au InsertLeave <buffer> :py ORGMODE.plugins['TagsProperties'].realign_tags()") # this is for the current file vim.command("au InsertLeave <buffer> :py ORGMODE.plugins['TagsProperties'].realign_tags()")
def new_checkbox(cls, below=None, plain=None): ''' if below is: True -> create new list below current line False/None -> create new list above current line if plain is: True -> create a plainlist item False/None -> create an empty checkbox ''' d = ORGMODE.get_document() h = d.current_heading() if h is None: return # init checkboxes for current heading h.init_checkboxes() c = h.current_checkbox() nc = Checkbox() nc._heading = h # default checkbox level level = h.level + 1 start = vim.current.window.cursor[0] - 1 # if no checkbox is found, insert at current line with indent level=1 if c is None: h.checkboxes.append(nc) else: l = c.get_parent_list() idx = c.get_index_in_parent_list() if l is not None and idx is not None: l.insert(idx + (1 if below else 0), nc) # workaround for broken associations, Issue #165 nc._parent = c.parent if below: if c.next_sibling: c.next_sibling._previous_sibling = nc nc._next_sibling = c.next_sibling c._next_sibling = nc nc._previous_sibling = c else: if c.previous_sibling: c.previous_sibling._next_sibling = nc nc._next_sibling = c nc._previous_sibling = c.previous_sibling c._previous_sibling = nc t = c.type # increase key for ordered lists if t[-1] in OrderListType: try: num = int(t[:-1]) + (1 if below else -1) if num < 0: # don't decrease to numbers below zero echom(u"Can't decrement further than '0'") return t = '%d%s' % (num, t[-1]) except ValueError: try: char = ord(t[:-1]) + (1 if below else -1) if below: if char == 91: # stop incrementing at Z (90) echom(u"Can't increment further than 'Z'") return elif char == 123: # increment from z (122) to A char = 65 else: if char == 96: # stop decrementing at a (97) echom(u"Can't decrement further than 'a'") return elif char == 64: # decrement from A (65) to z char = 122 t = u'%s%s' % (chr(char), t[-1]) except ValueError: pass nc.type = t level = c.level if below: start = c.end_of_last_child else: start = c.start if plain: # only create plainlist item when requested nc.status = None nc.level = level if below: start += 1 # vim's buffer behave just opposite to Python's list when inserting a # new item. The new entry is appended in vim put prepended in Python! vim.current.buffer.append("") # workaround for neovim vim.current.buffer[start:start] = [unicode(nc)] del vim.current.buffer[-1] # restore from workaround for neovim # update checkboxes status cls.update_checkboxes_status() # do not start insert upon adding new checkbox, Issue #211 if int(settings.get(u'org_prefer_insert_mode', u'1')): vim.command((u'exe "normal %dgg"|startinsert!' % (start + 1, )).encode(u'utf-8')) else: vim.command((u'exe "normal %dgg$"' % (start + 1, )).encode(u'utf-8'))
def tag_column(self): return int(settings.get('org_tag_column', '77'))
def new_heading(cls, below=None, insert_mode=False, end_of_last_child=False): u""" :below: True, insert heading below current heading, False, insert heading above current heading, None, special behavior for insert mode, use the current text as heading :insert_mode: True, if action is performed in insert mode :end_of_last_child: True, insert heading at the end of last child, otherwise the newly created heading will "take over" the current heading's children """ d = ORGMODE.get_document() current_heading = d.current_heading() cursor = vim.current.window.cursor[:] if not current_heading: # the user is in meta data region pos = cursor[0] - 1 heading = Heading(title=d.meta_information[pos], body=d.meta_information[pos + 1:]) d.headings.insert(0, heading) del d.meta_information[pos:] d.write() vim.command((u'exe "normal %dgg"|startinsert!' % (heading.start_vim, )).encode(u'utf-8')) return heading heading = Heading(level=current_heading.level) # it's weird but this is the behavior of original orgmode if below is None: below = cursor[1] != 0 or end_of_last_child heading_insert_position = 0 if below: heading_insert_position = 1 if not end_of_last_child: # append heading at the end of current heading but also take # over the children of current heading heading.children = [h.copy() for h in current_heading.children] del current_heading.children # if cursor is currently on a heading, insert parts of it into the # newly created heading if insert_mode and cursor[1] != 0 and cursor[0] == current_heading.start_vim: offset = cursor[1] - current_heading.level - 1 - (len(current_heading.todo) \ + 1 if current_heading.todo else 0) if offset < 0: offset = 0 if int(settings.get(u'org_improve_split_heading', u'1')) and \ offset > 0 and len(current_heading.title) == offset + 1 \ and current_heading.title[offset - 1] not in (u' ', u'\t'): offset += 1 heading.title = current_heading.title[offset:] current_heading.title = current_heading.title[:offset] heading.body = current_heading.body[:] current_heading.body = [] # insert newly created heading l = current_heading.get_parent_list() idx = current_heading.get_index_in_parent_list() if l is not None and idx is not None: l.insert(idx + heading_insert_position, heading) else: raise HeadingDomError(u'Current heading is not properly linked in DOM') d.write() vim.command((u'exe "normal %dgg"|startinsert!' % (heading.start_vim, )).encode(u'utf-8')) # return newly created heading return heading
def new_checkbox(cls, below=None, plain=None): ''' if below is: True -> create new list below current line False/None -> create new list above current line if plain is: True -> create a plainlist item False/None -> create an empty checkbox ''' d = ORGMODE.get_document() h = d.current_heading() if h is None: return # init checkboxes for current heading h.init_checkboxes() c = h.current_checkbox() nc = Checkbox() nc._heading = h # default checkbox level # make it align with the 4-space tabbing level = 4 start = vim.current.window.cursor[0] - 1 # if no checkbox is found, insert at current line with indent level=1 if c is None: h.checkboxes.append(nc) else: l = c.get_parent_list() idx = c.get_index_in_parent_list() if l is not None and idx is not None: l.insert(idx + (1 if below else 0), nc) # workaround for broken associations, Issue #165 nc._parent = c.parent if below: if c.next_sibling: c.next_sibling._previous_sibling = nc nc._next_sibling = c.next_sibling c._next_sibling = nc nc._previous_sibling = c else: if c.previous_sibling: c.previous_sibling._next_sibling = nc nc._next_sibling = c nc._previous_sibling = c.previous_sibling c._previous_sibling = nc t = c.type # increase key for ordered lists if t[-1] in OrderListType: try: num = int(t[:-1]) + (1 if below else -1) if num < 0: # don't decrease to numbers below zero echom(u"Can't decrement further than '0'") return t = '%d%s' % (num, t[-1]) except ValueError: try: char = ord(t[:-1]) + (1 if below else -1) if below: if char == 91: # stop incrementing at Z (90) echom(u"Can't increment further than 'Z'") return elif char == 123: # increment from z (122) to A char = 65 else: if char == 96: # stop decrementing at a (97) echom(u"Can't decrement further than 'a'") return elif char == 64: # decrement from A (65) to z char = 122 t = u'%s%s' % (chr(char), t[-1]) except ValueError: pass nc.type = t level = c.level if below: start = c.end_of_last_child else: start = c.start if plain: # only create plainlist item when requested nc.status = None nc.level = level if below: start += 1 # vim's buffer behave just opposite to Python's list when inserting a # new item. The new entry is appended in vim put prepended in Python! vim.current.buffer.append("") # workaround for neovim vim.current.buffer[start:start] = [unicode(nc)] del vim.current.buffer[-1] # restore from workaround for neovim # update checkboxes status cls.update_checkboxes_status() # do not start insert upon adding new checkbox, Issue #211 if int(settings.get(u'org_prefer_insert_mode', u'1')): vim.command( u_encode(u'exe "normal %dgg"|startinsert!' % (start + 1, ))) else: vim.command(u_encode(u'exe "normal %dgg$"' % (start + 1, )))
def new_heading(cls, below=None, insert_mode=False, end_of_last_child=False): u""" :below: True, insert heading below current heading, False, insert heading above current heading, None, special behavior for insert mode, use the current text as heading :insert_mode: True, if action is performed in insert mode :end_of_last_child: True, insert heading at the end of last child, otherwise the newly created heading will "take over" the current heading's children """ d = ORGMODE.get_document() current_heading = d.current_heading() cursor = vim.current.window.cursor[:] if not current_heading: # the user is in meta data region pos = cursor[0] - 1 heading = Heading(title=d.meta_information[pos], body=d.meta_information[pos + 1:]) d.headings.insert(0, heading) del d.meta_information[pos:] d.write() vim.command( u_encode(u'exe "normal %dgg"|startinsert!' % (heading.start_vim, ))) return heading # check for plain list(checkbox) current_heading.init_checkboxes() c = current_heading.current_checkbox() if c is not None: ORGMODE.plugins[u"EditCheckbox"].new_checkbox(below, not c.status) return heading = Heading(level=current_heading.level) # it's weird but this is the behavior of original orgmode if below is None: below = cursor[1] != 0 or end_of_last_child # insert newly created heading l = current_heading.get_parent_list() idx = current_heading.get_index_in_parent_list() if l is not None and idx is not None: l.insert(idx + (1 if below else 0), heading) else: raise HeadingDomError( u'Current heading is not properly linked in DOM') if below and not end_of_last_child: # append heading at the end of current heading and also take # over the children of current heading for child in current_heading.children: heading.children.append(child, taint=False) current_heading.children.remove_slice( 0, len(current_heading.children), taint=False) # if cursor is currently on a heading, insert parts of it into the # newly created heading if insert_mode and cursor[1] != 0 and cursor[ 0] == current_heading.start_vim: offset = cursor[1] - current_heading.level - 1 - ( len(current_heading.todo) + 1 if current_heading.todo else 0) if offset < 0: offset = 0 if int(settings.get(u'org_improve_split_heading', u'1')) and \ offset > 0 and len(current_heading.title) == offset + 1 \ and current_heading.title[offset - 1] not in (u' ', u'\t'): offset += 1 heading.title = current_heading.title[offset:] current_heading.title = current_heading.title[:offset] heading.body = current_heading.body[:] current_heading.body = [] d.write() # do not start insert upon adding new headings, unless already in insert mode. Issue #211 if int(settings.get(u'org_prefer_insert_mode', u'1')) or insert_mode: vim.command( u_encode(u'exe "normal %dgg"|startinsert!' % (heading.start_vim, ))) else: vim.command(u_encode(u'exe "normal %dgg$"' % (heading.start_vim, ))) # return newly created heading return heading
def new_heading(cls, below=None, insert_mode=False, end_of_last_child=False): u""" :below: True, insert heading below current heading, False, insert heading above current heading, None, special behavior for insert mode, use the current text as heading :insert_mode: True, if action is performed in insert mode :end_of_last_child: True, insert heading at the end of last child, otherwise the newly created heading will "take over" the current heading's children """ d = ORGMODE.get_document() current_heading = d.current_heading() cursor = vim.current.window.cursor[:] if not current_heading: # the user is in meta data region pos = cursor[0] - 1 heading = Heading(title=d.meta_information[pos], body=d.meta_information[pos + 1:]) d.headings.insert(0, heading) del d.meta_information[pos:] d.write() vim.command(u_encode(u'exe "normal %dgg"|startinsert!' % (heading.start_vim, ))) return heading # check for plain list(checkbox) current_heading.init_checkboxes() c = current_heading.current_checkbox() if c is not None: ORGMODE.plugins[u"EditCheckbox"].new_checkbox(below, not c.status) return heading = Heading(level=current_heading.level) # it's weird but this is the behavior of original orgmode if below is None: below = cursor[1] != 0 or end_of_last_child # insert newly created heading l = current_heading.get_parent_list() idx = current_heading.get_index_in_parent_list() if l is not None and idx is not None: l.insert(idx + (1 if below else 0), heading) else: raise HeadingDomError(u'Current heading is not properly linked in DOM') if below and not end_of_last_child: # append heading at the end of current heading and also take # over the children of current heading for child in current_heading.children: heading.children.append(child, taint=False) current_heading.children.remove_slice( 0, len(current_heading.children), taint=False) # if cursor is currently on a heading, insert parts of it into the # newly created heading if insert_mode and cursor[1] != 0 and cursor[0] == current_heading.start_vim: offset = cursor[1] - current_heading.level - 1 - ( len(current_heading.todo) + 1 if current_heading.todo else 0) if offset < 0: offset = 0 if int(settings.get(u'org_improve_split_heading', u'1')) and \ offset > 0 and len(current_heading.title) == offset + 1 \ and current_heading.title[offset - 1] not in (u' ', u'\t'): offset += 1 heading.title = current_heading.title[offset:] current_heading.title = current_heading.title[:offset] heading.body = current_heading.body[:] current_heading.body = [] d.write() # do not start insert upon adding new headings, unless already in insert mode. Issue #211 if int(settings.get(u'org_prefer_insert_mode', u'1')) or insert_mode: vim.command(u_encode(u'exe "normal %dgg"|startinsert!' % (heading.start_vim, ))) else: vim.command(u_encode(u'exe "normal %dgg$"' % (heading.start_vim, ))) # return newly created heading return heading
def tag_column(self): return int(settings.get("org_tag_column", "77"))
def new_heading(cls, below=None, insert_mode=False, end_of_last_child=False): u""" :below: True, insert heading below current heading, False, insert heading above current heading, None, special behavior for insert mode, use the current text as heading :insert_mode: True, if action is performed in insert mode :end_of_last_child: True, insert heading at the end of last child, otherwise the newly created heading will "take over" the current heading's children """ d = ORGMODE.get_document() current_heading = d.current_heading() cursor = vim.current.window.cursor[:] if not current_heading: # the user is in meta data region pos = cursor[0] - 1 heading = Heading(title=d.meta_information[pos], body=d.meta_information[pos + 1:]) d.headings.insert(0, heading) del d.meta_information[pos:] d.write() vim.command((u'exe "normal %dgg"|startinsert!' % (heading.start_vim, )).encode(u'utf-8')) return heading heading = Heading(level=current_heading.level) # it's weird but this is the behavior of original orgmode if below is None: below = cursor[1] != 0 or end_of_last_child heading_insert_position = 0 if below: heading_insert_position = 1 if not end_of_last_child: # append heading at the end of current heading but also take # over the children of current heading heading.children = [h.copy() for h in current_heading.children] del current_heading.children # if cursor is currently on a heading, insert parts of it into the # newly created heading if insert_mode and cursor[1] != 0 and cursor[ 0] == current_heading.start_vim: offset = cursor[1] - current_heading.level - 1 - (len(current_heading.todo) \ + 1 if current_heading.todo else 0) if offset < 0: offset = 0 if int(settings.get(u'org_improve_split_heading', u'1')) and \ offset > 0 and len(current_heading.title) == offset + 1 \ and current_heading.title[offset - 1] not in (u' ', u'\t'): offset += 1 heading.title = current_heading.title[offset:] current_heading.title = current_heading.title[:offset] heading.body = current_heading.body[:] current_heading.body = [] # insert newly created heading l = current_heading.get_parent_list() idx = current_heading.get_index_in_parent_list() if l is not None and idx is not None: l.insert(idx + heading_insert_position, heading) else: raise HeadingDomError( u'Current heading is not properly linked in DOM') d.write() vim.command((u'exe "normal %dgg"|startinsert!' % (heading.start_vim, )).encode(u'utf-8')) # return newly created heading return heading
def tag_column(self): return int(settings.get(u'vimwiki_org_tag_column', u'77'))