def end_of_text(mode): row = None for row in all_text_lines(mode + 's'): pass if row is not None: vim.current.window.cursor = row, 0 vim.command('normal $')
def create_sibling(mode): row, level = topic_line() level, bullet, number, line = split_line(row) row = row_of_created_empty(mode, row) if number is not None: number += 1 build_line(row, level, bullet, number, '') move_cursor(row, level) vim.command('startinsert')
def act_on_region(mode, command, generator): # Execute Vim COMMAND over the region defined by the first and last lines # produced by GENERATOR. start = None for row, level in generator(mode): if start is None: start = row if start is None: no_such_line() else: vim.command('normal %dG%s%dG' % (row, command, start))
def hide_text(mode): row, level = row_and_level() if level is None: vim.command('normal zc') else: try: row = next(all_text_lines(mode + 's')) except StopIteration: pass else: command_at(row, 'normal zc')
def create_supertopic(mode): topic_row, topic_level = topic_line() for row, level in all_preceding_lines(mode, topic_row): if level is not None and level < topic_level: level, bullet, number, line = split_line(row) break else: no_such_line() return row = row_of_created_empty(mode, row) if number is not None: number += 1 build_line(row, level, '.', None, '') move_cursor(row, level) vim.command('startinsert')
def register_local_keys(plugin, triplets): for keys, modes, name in triplets: for mode in modes: python_command = ':python %s.%s(\'%s\')' % (plugin, name, mode) sid_name = '<SID>%s_%s' % (mode, name) plug_name = '<Plug>%s_%s_%s' % (plugin.capitalize(), mode, name) vim.command('%smap <buffer> %s %s' % (mode, keys, plug_name)) vim.command('%snoremap <buffer> <script> %s %s' % (mode, plug_name, sid_name)) if mode == 'i': vim.command('%snoremap <buffer> <silent> %s <C-O>%s<CR>' % (mode, sid_name, python_command)) else: vim.command('%snoremap <buffer> <silent> %s %s<CR>' % (mode, sid_name, python_command))
def error(message): # Reports MESSAGE as a Vim warning. vim.command('echohl WarningMsg | echo "%s" | echohl None' % message.rstrip().replace('"', '\\"'))
def command_at(row, command): # Temporarily move cursor on ROW and execute Vim COMMAND there. cursor = vim.current.window.cursor vim.current.window.cursor = row, 0 vim.command(command) vim.current.window.cursor = cursor
def create_subtopic(mode): row, level = topic_line() row = row_of_created_empty(mode, row) build_line(row, level + 1, '.', None, '') move_cursor(row, level + 1) vim.command('startinsert')
def beginning_of_text(mode): for row in all_text_lines(mode + 's'): vim.current.window.cursor = row, 0 vim.command('normal ^') break
prefix = '*' else: if bullet != '@': if number is not None: bullet = '#' + str(number) elif level == 1 or bullet in '.:,;#': bullet = '.:,;'[(level + delta - 2) % 4] prefix = '.' + ' ' * (level + delta - 2) + bullet if line is None: buffer[row-1] = prefix else: buffer[row-1] = prefix + ' ' + line def is_invisible(row=None): # Tells if the line at ROW is within a currently closed fold. if row is None: row, col = vim.current.window.cursor return int(vim.eval('foldclosed(%d)' % row)) >= 0 def no_such_line(): # Reports "No such line" as a Vim warning. error("No such line.") def error(message): # Reports MESSAGE as a Vim warning. vim.command('echohl WarningMsg | echo "%s" | echohl None' % message.rstrip().replace('"', '\\"')) install_with_vim() vim.command('autocmd FileType allout python allout.install_with_vim()')