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'))
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_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, current_buffer=False): u""" List all todos in: current_buffer = False all agenda files current_buffer = True current org_file in one buffer. """ if current_buffer: agenda_documents = vim.current.buffer.name loaded_agendafiles = cls._load_agendafiles([agenda_documents]) else: loaded_agendafiles = cls._get_agendadocuments() if not loaded_agendafiles: return raw_agenda = ORGMODE.agenda_manager.get_todo(loaded_agendafiles) 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'))
def list_all_todos(cls, current_buffer=False): u""" List all todos in one buffer. Args: current_buffer (bool): False: all agenda files True: current org_file """ if current_buffer: agenda_documents = vim.current.buffer.name loaded_agendafiles = cls._load_agendafiles([agenda_documents]) else: loaded_agendafiles = cls._get_agendadocuments() if not loaded_agendafiles: return raw_agenda = ORGMODE.agenda_manager.get_todo(loaded_agendafiles) 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[:] = [u_encode(i) for i in final_agenda] vim.command( u_encode( u'setlocal nomodifiable conceallevel=2 concealcursor=nc'))
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].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_next_week_for(cls, agenda_documents): raw_agenda = ORGMODE.agenda_manager.get_next_week_and_active_todo( agenda_documents) # if raw_agenda is empty, return directly if not raw_agenda: vim.command('echom "All caught-up. No agenda or active todo next week."') return # 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].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_next_week_for(cls, agenda_documents): raw_agenda = ORGMODE.agenda_manager.get_next_week_and_active_todo( agenda_documents) # if raw_agenda is empty, return directly if not raw_agenda: vim.command( 'echom "All caught-up. No agenda or active todo next week."') return # 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 raw_agenda = sorted(raw_agenda, key=lambda x: x.active_date.strftime('%s')) final_agenda, last_date = [u'Week Agenda:'], '' for i, h in enumerate(raw_agenda): # insert date information for every new date (not datetime) section = h.active_date.strftime('<%F %a>') if section != last_date: today = date.today() # insert additional "TODAY" string today_flag = '' if h.active_date.year == today.year and \ h.active_date.month == today.month and \ h.active_date.day == today.day: today_flag = u" TODAY" today_row = len(final_agenda) + 1 final_agenda.append(section + today_flag) # update last_date last_date = section bufname = os.path.basename(vim.buffers[h.document.bufnr].name) bufname = bufname[:-4] if bufname.endswith(u'.org') else bufname tstamp = h.active_date.strftime('%H:%M') if tstamp == '00:00': tstamp = '-----' formated = u"%(todo)+8s %(bufname)-10s %(tstamp)s %(title)s" % { 'bufname': bufname, 'todo': h.todo, 'title': h.title, 'tstamp': tstamp } final_agenda.append(formated) cls.line2doc[len(final_agenda)] = (get_bufname(h.document.bufnr), h.document.bufnr, h.start) # show agenda vim.current.buffer[:] = [u_encode(i) for i in final_agenda] vim.command( u_encode( u'setlocal nomodifiable conceallevel=2 concealcursor=nc')) # try to jump to the positon of today try: vim.command(u_encode(u'normal! %sgg<CR>' % today_row)) except: pass
def list_next_week_for(cls, agenda_documents): raw_agenda = ORGMODE.agenda_manager.get_next_week_or_active_todo( agenda_documents) # if raw_agenda is empty, return directly if not raw_agenda: vim.command('echom "All caught-up. No agenda or active todo next week."') return # create buffer at bottom cmd = [u'setlocal filetype=orgagenda', ] cls._switch_to(u'AGENDA_WEEK', 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 = {} # Create the ongoing todo section raw_agenda_todo = sorted([h for h in raw_agenda if h.active_date == None]) final_agenda_todo = [] for i, h in enumerate(raw_agenda_todo): tmp = u"%s %s" % (h.todo, h.title) final_agenda_todo.append(tmp) cls.line2doc[len(final_agenda_todo)] = (get_bufname(h.document.bufnr), h.document.bufnr, h.start) if len(final_agenda_todo) > 0: final_agenda_todo.append('') # Create the weekly section raw_agenda_weekly = sorted([h for h in raw_agenda if h.active_date != None]) if len(raw_agenda_weekly) > 0: last_date = raw_agenda_weekly[0].active_date else: last_date = '' final_agenda_weekly = [u'Week Agenda:', unicode(last_date)] for i, h in enumerate(raw_agenda_weekly): # 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_weekly) + 1 else: section = unicode(h.active_date) final_agenda_weekly.append(section) # update last_date last_date = h.active_date bufname = os.path.basename(vim.buffers[h.document.bufnr].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_weekly.append(formated) cls.line2doc[len(final_agenda_todo)+len(final_agenda_weekly)] = (get_bufname(h.document.bufnr), h.document.bufnr, h.start) # show agenda final_agenda = final_agenda_todo + final_agenda_weekly vim.current.buffer[:] = [u_encode(i) for i in final_agenda] vim.command(u_encode(u'setlocal nomodifiable conceallevel=2 concealcursor=nc')) # try to jump to the positon of today try: vim.command(u_encode(u'normal! %sgg<CR>' % today_row)) except: pass