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 + 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 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 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[start:start] = [unicode(nc)] # update checkboxes status cls.update_checkboxes_status() vim.command((u'exe "normal %dgg"|startinsert!' % (start + 1, )).encode(u'utf-8'))
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_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_encode((u'exe "normal %dgg"|startinsert!' % (start + 1, )))) else: vim.command(u_encode((u'exe "normal %dgg$"' % (start + 1, ))))
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')")