def opendoc(cls, split=False, switch=False): u""" If you are in the agenda view jump to the document the item in the current line belongs to. cls.line2doc is used for that. :split: if True, open the document in a new split window. :switch: if True, switch to another window and open the the document there. """ row, _ = vim.current.window.cursor try: bufname, bufnr, destrow = cls.line2doc[row] except: return # reload source file if it is not loaded if get_bufname(bufnr) is None: vim.command((u'badd %s' % bufname).encode(u'utf-8')) bufnr = get_bufnumber(bufname) tmp = cls.line2doc[row] cls.line2doc[bufnr] = tmp # delete old endry del cls.line2doc[row] if split: vim.command((u"sbuffer %s" % bufnr).encode(u'utf-8')) elif switch: vim.command(u"wincmd w".encode(u'utf-8')) vim.command((u"buffer %d" % bufnr).encode(u'utf-8')) else: vim.command((u"buffer %s" % bufnr).encode(u'utf-8')) vim.command((u"normal! %dgg <CR>" % (destrow + 1)).encode(u'utf-8'))
def list_next_week(cls): agenda_documents = cls._get_agendadocuments() if not agenda_documents: return raw_agenda = ORGMODE.agenda_manager.get_next_week_and_active_todo( agenda_documents) # create buffer at bottom cmd = [u'setlocal filetype=orgagenda', ] cls._switch_to(u'AGENDA', cmd) # line2doc is a dic with the mapping: # line in agenda buffer --> source document # It's easy to jump to the right document this way cls.line2doc = {} # format text for agenda last_date = raw_agenda[0].active_date final_agenda = [u'Week Agenda:', unicode(last_date)] for i, h in enumerate(raw_agenda): # insert date information for every new date (not datetime) if unicode(h.active_date)[1:11] != unicode(last_date)[1:11]: today = date.today() # insert additional "TODAY" string if h.active_date.year == today.year and \ h.active_date.month == today.month and \ h.active_date.day == today.day: section = unicode(h.active_date) + u" TODAY" today_row = len(final_agenda) + 1 else: section = unicode(h.active_date) final_agenda.append(section) # update last_date last_date = h.active_date bufname = os.path.basename(vim.buffers[h.document.bufnr-1].name) bufname = bufname[:-4] if bufname.endswith(u'.org') else bufname formated = u" %(bufname)s (%(bufnr)d) %(todo)s %(title)s" % { 'bufname': bufname, 'bufnr': h.document.bufnr, 'todo': h.todo, 'title': h.title } final_agenda.append(formated) cls.line2doc[len(final_agenda)] = (get_bufname(h.document.bufnr), h.document.bufnr, h.start) # show agenda vim.current.buffer[:] = [ i.encode(u'utf-8') for i in final_agenda ] vim.command(u'setlocal nomodifiable conceallevel=2 concealcursor=nc'.encode(u'utf-8')) # try to jump to the positon of today try: vim.command((u'normal! %sgg<CR>' % today_row).encode(u'utf-8')) except: pass
def list_timeline(cls): """ List a timeline of the current buffer to get an overview of the current file. """ raw_agenda = ORGMODE.agenda_manager.get_timestamped_items( [ORGMODE.get_document()]) # create buffer at bottom cmd = [u'setlocal filetype=orgagenda'] cls._switch_to(u'AGENDA', cmd) cls.line2doc = {} # format text of agenda final_agenda = [] for i, h in enumerate(raw_agenda): tmp = u"%s %s" % (h.todo, h.title) final_agenda.append(tmp) cls.line2doc[len(final_agenda)] = (get_bufname(h.document.bufnr), h.document.bufnr, h.start) # show agenda vim.current.buffer[:] = [ i.encode(u'utf-8') for i in final_agenda ] vim.command(u'setlocal nomodifiable conceallevel=2 concealcursor=nc'.encode(u'utf-8'))
def list_all_todos(cls): u""" List all todos in all agenda files in one buffer. """ agenda_documents = cls._get_agendadocuments() if not agenda_documents: return raw_agenda = ORGMODE.agenda_manager.get_todo(agenda_documents) cls.line2doc = {} # create buffer at bottom cmd = [u'setlocal filetype=orgagenda'] cls._switch_to(u'AGENDA', cmd) # format text of agenda final_agenda = [] for i, h in enumerate(raw_agenda): tmp = u"%s %s" % (h.todo, h.title) final_agenda.append(tmp) cls.line2doc[len(final_agenda)] = (get_bufname(h.document.bufnr), h.document.bufnr, h.start) # show agenda vim.current.buffer[:] = [ i.encode(u'utf-8') for i in final_agenda ] vim.command(u'setlocal nomodifiable conceallevel=2 concealcursor=nc'.encode(u'utf-8'))