def insert_timestamp(cls, active=True): u""" Insert a timestamp at the cursor position. TODO: show fancy calendar to pick the date from. TODO: add all modifier of orgmode. """ today = date.today() msg = u''.join([u'Inserting ', unicode(today.strftime(u'%Y-%m-%d %a'), u'utf-8'), u' | Modify date']) modifier = get_user_input(msg) # abort if the user canceled the input promt if modifier is None: return newdate = cls._modify_time(today, modifier) # format if isinstance(newdate, datetime): newdate = newdate.strftime( u'%Y-%m-%d %a %H:%M'.encode(u'utf-8')).decode(u'utf-8') else: newdate = newdate.strftime( u'%Y-%m-%d %a'.encode(u'utf-8')).decode(u'utf-8') timestamp = u'<%s>' % newdate if active else u'[%s]' % newdate insert_at_cursor(timestamp)
def insert_timestamp(cls, active=True): u""" Insert a timestamp at the cursor position. TODO: show fancy calendar to pick the date from. TODO: add all modifier of orgmode. """ today = date.today() msg = u''.join([ u'Inserting ', unicode(today.strftime(u'%Y-%m-%d %a'), u'utf-8'), u' | Modify date' ]) modifier = get_user_input(msg) # abort if the user canceled the input promt if modifier is None: return newdate = cls._modify_time(today, modifier) # format if isinstance(newdate, datetime): newdate = newdate.strftime( u'%Y-%m-%d %a %H:%M'.encode(u'utf-8')).decode(u'utf-8') else: newdate = newdate.strftime( u'%Y-%m-%d %a'.encode(u'utf-8')).decode(u'utf-8') timestamp = u'<%s>' % newdate if active else u'[%s]' % newdate insert_at_cursor(timestamp)
def new_checkbox(cls, below=None): 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() # default checkbox level level = h.level # if no checkbox is found, insert at current line with indent level=1 if c is None: start = h.start if h.checkboxes: level = h.first_checkbox.level else: level = c.level if below: start = c.end_of_last_child else: start = c.start vim.current.window.cursor = (start + 1, 0) if below: vim.command("normal o") else: vim.command("normal O") new_checkbox = Checkbox(level=level) insert_at_cursor(str(new_checkbox)) vim.command("call feedkeys('a')")
def new_checkbox(cls, below=None): 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 start = vim.current.window.cursor[0] - 1 # if no checkbox is found, insert at current line with indent level=1 if c is None: if h.checkboxes: level = h.first_checkbox.level 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) t = '%d%s' % (num, t[-1]) except ValueError: try: char = ord(t[:-1]) + (1 if below else -1) t = '%s%s' % (chr(char), t[-1]) except ValueError: pass nc.type = t if not c.status: nc.status = None level = c.level if below: start = c.end_of_last_child else: start = c.start nc.level = level vim.current.window.cursor = (start + 1, 0) if below: vim.command("normal o") else: vim.command("normal O") insert_at_cursor(str(nc)) vim.command("call feedkeys('a')")