Пример #1
0
    def init_org_todo(cls):
        u""" Initialize org todo selection window.
		"""
        bufnr = int(re.findall('\d+$', vim.current.buffer.name)[0])
        all_states = ORGTODOSTATES.get(bufnr, None)

        vim_commands = [
            u'let g:org_sav_timeoutlen=&timeoutlen',
            u'au orgmode BufEnter <buffer> :if ! exists("g:org_sav_timeoutlen")|let g:org_sav_timeoutlen=&timeoutlen|set timeoutlen=1|endif',
            u'au orgmode BufLeave <buffer> :if exists("g:org_sav_timeoutlen")|let &timeoutlen=g:org_sav_timeoutlen|unlet g:org_sav_timeoutlen|endif',
            u'setlocal nolist tabstop=16 buftype=nofile timeout timeoutlen=1 winfixheight',
            u'setlocal statusline=Org\\ todo\\ (%s)' % vim.eval(
                u_encode(
                    u'fnameescape(fnamemodify(bufname(%d), ":t"))' % bufnr)),
            u'nnoremap <silent> <buffer> <Esc> :%sbw<CR>' %
            vim.eval(u_encode(u'bufnr("%")')),
            u'nnoremap <silent> <buffer> <CR> :let g:org_state = fnameescape(expand("<cword>"))<Bar>bw<Bar>exec "%s ORGMODE.plugins[u\'Todo\'].set_todo_state(\'".g:org_state."\')"<Bar>unlet! g:org_state<CR>'
            % VIM_PY_CALL,
        ]
        # because timeoutlen can only be set globally it needs to be stored and
        # restored later
        # make window a scratch window and set the statusline differently
        for cmd in vim_commands:
            vim.command(u_encode(cmd))

        if all_states is None:
            vim.command(u_encode(u'bw'))
            echom(u'No todo states avaiable for buffer %s' %
                  vim.current.buffer.name)

        for idx, state in enumerate(all_states):
            pairs = [split_access_key(x, sub=u' ') for x in it.chain(*state)]
            line = u'\t'.join(u''.join((u'[%s] ' % x[1], x[0])) for x in pairs)
            vim.current.buffer.append(u_encode(line))
            for todo, key in pairs:
                # FIXME if double key is used for access modified this doesn't work
                vim.command(
                    u_encode(
                        u'nnoremap <silent> <buffer> %s :bw<CR><c-w><c-p>%s ORGMODE.plugins[u"Todo"].set_todo_state("%s")<CR>'
                        % (key, VIM_PY_CALL, u_decode(todo))))

        # position the cursor of the current todo item
        vim.command(u_encode(u'normal! G'))
        current_state = settings.unset(u'org_current_state_%d' % bufnr)
        if current_state is not None and current_state != '':
            for i, buf in enumerate(vim.current.buffer):
                idx = buf.find(current_state)
                if idx != -1:
                    vim.current.window.cursor = (i + 1, idx)
                    break
            else:
                vim.current.window.cursor = (2, 4)

        # finally make buffer non modifiable
        vim.command(u_encode(u'setfiletype orgtodo'))
        vim.command(u_encode(u'setlocal nomodifiable'))

        # remove temporary todo states for the current buffer
        del ORGTODOSTATES[bufnr]
Пример #2
0
	def init_org_todo(cls):
		u""" Initialize org todo selection window.
		"""
		bufnr = int(vim.current.buffer.name.split('/')[-1])
		all_states = ORGTODOSTATES.get(bufnr, None)

		vim_commands = [
			u'let g:org_sav_timeoutlen=&timeoutlen',
			u'au orgmode BufEnter <buffer> :if ! exists("g:org_sav_timeoutlen")|let g:org_sav_timeoutlen=&timeoutlen|set timeoutlen=1|endif',
			u'au orgmode BufLeave <buffer> :if exists("g:org_sav_timeoutlen")|let &timeoutlen=g:org_sav_timeoutlen|unlet g:org_sav_timeoutlen|endif',
			u'setlocal nolist tabstop=16 buftype=nofile timeout timeoutlen=1 winfixheight',
			u'setlocal statusline=Org\\ todo\\ (%s)' % vim.eval(u_encode(u'fnameescape(fnamemodify(bufname(%d), ":t"))' % bufnr)),
			u'nnoremap <silent> <buffer> <Esc> :%sbw<CR>' % vim.eval(u_encode(u'bufnr("%")')),
			u'nnoremap <silent> <buffer> <CR> :let g:org_state = fnameescape(expand("<cword>"))<Bar>bw<Bar>exec "%s ORGMODE.plugins[u\'Todo\'].set_todo_state(\'".g:org_state."\')"<Bar>unlet! g:org_state<CR>' % VIM_PY_CALL,
			]
		# because timeoutlen can only be set globally it needs to be stored and
		# restored later
		# make window a scratch window and set the statusline differently
		for cmd in vim_commands:
			vim.command(u_encode(cmd))

		if all_states is None:
			vim.command(u_encode(u'bw'))
			echom(u'No todo states avaiable for buffer %s' % vim.current.buffer.name)

		for idx, state in enumerate(all_states):
			pairs = [split_access_key(x, sub=u' ') for x in it.chain(*state)]
			line = u'\t'.join(u''.join((u'[%s] ' % x[1], x[0])) for x in pairs)
			vim.current.buffer.append(u_encode(line))
			for todo, key in pairs:
				# FIXME if double key is used for access modified this doesn't work
				vim.command(u_encode(u'nnoremap <silent> <buffer> %s :bw<CR><c-w><c-p>%s ORGMODE.plugins[u"Todo"].set_todo_state("%s")<CR>' % (key, VIM_PY_CALL, u_decode(todo))))

		# position the cursor of the current todo item
		vim.command(u_encode(u'normal! G'))
		current_state = settings.unset(u'org_current_state_%d' % bufnr)
		if current_state is not None and current_state != '':
			for i, buf in enumerate(vim.current.buffer):
				idx = buf.find(current_state)
				if idx != -1:
					vim.current.window.cursor = (i + 1, idx)
					break
			else:
				vim.current.window.cursor = (2, 4)

		# finally make buffer non modifiable
		vim.command(u_encode(u'setfiletype orgtodo'))
		vim.command(u_encode(u'setlocal nomodifiable'))

		# remove temporary todo states for the current buffer
		del ORGTODOSTATES[bufnr]
Пример #3
0
    def init_org_todo(cls):
        u""" Initialize org todo selection window.
		"""
        bufnr = int(vim.current.buffer.name.split('/')[-1])
        all_states = ORGTODOSTATES.get(bufnr, None)

        # because timeoutlen can only be set globally it needs to be stored and restored later
        vim.command(u_encode(u'let g:org_sav_timeoutlen=&timeoutlen'))
        vim.command(
            u_encode(
                u'au orgmode BufEnter <buffer> :if ! exists("g:org_sav_timeoutlen")|let g:org_sav_timeoutlen=&timeoutlen|set timeoutlen=1|endif'
            ))
        vim.command(
            u_encode(
                u'au orgmode BufLeave <buffer> :if exists("g:org_sav_timeoutlen")|let &timeoutlen=g:org_sav_timeoutlen|unlet g:org_sav_timeoutlen|endif'
            ))
        # make window a scratch window and set the statusline differently
        vim.command(
            u_encode(
                u'setlocal nolist tabstop=16 buftype=nofile timeout timeoutlen=1 winfixheight'
            ))
        vim.command(
            u_encode((u'setlocal statusline=Org\\ todo\\ (%s)' % vim.eval(
                u_encode((u'fnameescape(fnamemodify(bufname(%d), ":t"))' %
                          bufnr))))))
        vim.command(
            u_encode((u'nnoremap <silent> <buffer> <Esc> :%sbw<CR>' %
                      (vim.eval(u_encode(u'bufnr("%")')), ))))
        vim.command(
            u_encode(
                u'nnoremap <silent> <buffer> <CR> :let g:org_state = fnameescape(expand("<cword>"))<Bar>bw<Bar>exec "%s ORGMODE.plugins[u\'Todo\'].set_todo_state(\'".g:org_state."\')"<Bar>unlet! g:org_state<CR>'
                % VIM_PY_CALL))

        if all_states is None:
            vim.command(u_encode(u'bw'))
            echom(u'No todo states avaiable for buffer %s' %
                  vim.current.buffer.name)

        for l in range(0, len(all_states)):
            res = u''
            for j in range(0, 2):
                if j < len(all_states[l]):
                    for i in all_states[l][j]:
                        if type(i) != unicode:
                            continue
                        v, k = split_access_key(i)
                        if k:
                            res += (u'\t'
                                    if res else u'') + u'[%s] %s' % (k, v)
                            # map access keys to callback that updates current heading
                            # map selection keys
                            vim.command(
                                u_encode((
                                    u'nnoremap <silent> <buffer> %s :bw<CR><c-w><c-p>%s ORGMODE.plugins[u"Todo"].set_todo_state(u_decode("%s")))<CR>'
                                    % (k, VIM_PY_CALL, v))))
                        elif v:
                            res += (u'\t' if res else u'') + v
            if res:
                if l == 0:
                    # WORKAROUND: the cursor can not be positioned properly on
                    # the first line. Another line is just inserted and it
                    # works great
                    vim.current.buffer[0] = u_encode(u'')
                vim.current.buffer.append(u_encode(res))

        # position the cursor of the current todo item
        vim.command(u_encode(u'normal! G'))
        current_state = settings.unset(u'org_current_state_%d' % bufnr)
        found = False
        if current_state is not None and current_state != '':
            for i in range(0, len(vim.current.buffer)):
                idx = vim.current.buffer[i].find(current_state)
                if idx != -1:
                    vim.current.window.cursor = (i + 1, idx)
                    found = True
                    break
        if not found:
            vim.current.window.cursor = (2, 4)

        # finally make buffer non modifiable
        vim.command(u_encode(u'setfiletype orgtodo'))
        vim.command(u_encode(u'setlocal nomodifiable'))

        # remove temporary todo states for the current buffer
        del ORGTODOSTATES[bufnr]
Пример #4
0
	def init_org_todo(cls):
		u""" Initialize org todo selection window.
		"""
		bufnr = int(vim.current.buffer.name.split('/')[-1])
		all_states = ORGTODOSTATES.get(bufnr, None)

		# because timeoutlen can only be set globally it needs to be stored and restored later
		vim.command(u'let g:org_sav_timeoutlen=&timeoutlen'.encode(u'utf-8'))
		vim.command(u'au orgmode BufEnter <buffer> :if ! exists("g:org_sav_timeoutlen")|let g:org_sav_timeoutlen=&timeoutlen|set timeoutlen=1|endif'.encode(u'utf-8'))
		vim.command(u'au orgmode BufLeave <buffer> :if exists("g:org_sav_timeoutlen")|let &timeoutlen=g:org_sav_timeoutlen|unlet g:org_sav_timeoutlen|endif'.encode(u'utf-8'))
		# make window a scratch window and set the statusline differently
		vim.command(u'setlocal tabstop=16 buftype=nofile timeout timeoutlen=1 winfixheight'.encode(u'utf-8'))
		vim.command((u'setlocal statusline=Org\\ todo\\ (%s)' % vim.eval((u'fnameescape(fnamemodify(bufname(%d), ":t"))' % bufnr).encode(u'utf-8'))).encode(u'utf-8'))
		vim.command((u'nnoremap <silent> <buffer> <Esc> :%sbw<CR>' % (vim.eval(u'bufnr("%")'.encode(u'utf-8')), )).encode(u'utf-8'))
		vim.command(u'nnoremap <silent> <buffer> <CR> :let g:org_state = fnameescape(expand("<cword>"))<Bar>bw<Bar>exec "py ORGMODE.plugins[u\'Todo\'].set_todo_state(\'".g:org_state."\')"<Bar>unlet! g:org_state<CR>'.encode(u'utf-8'))

		if all_states is None:
			vim.command(u'bw'.encode(u'utf-8'))
			echom(u'No todo states avaiable for buffer %s' % vim.current.buffer.name)

		for l in xrange(0, len(all_states)):
			res = u''
			did_done = False
			for j in xrange(0, 2):
				if j < len(all_states[l]):
					for i in all_states[l][j]:
						if type(i) != unicode:
							continue
						v, k = split_access_key(i)
						if k:
							res += (u'\t' if res else u'') + u'[%s] %s' % (k, v)
							# map access keys to callback that updates current heading
							# map selection keys
							vim.command((u'nnoremap <silent> <buffer> %s :bw<Bar>py ORGMODE.plugins[u"Todo"].set_todo_state("%s".decode(u"utf-8"))<CR>' % (k, v)).encode(u'utf-8') )
						elif v:
							res += (u'\t' if res else u'') + v
			if res:
				if l == 0:
					# WORKAROUND: the cursor can not be positioned properly on
					# the first line. Another line is just inserted and it
					# works great
					vim.current.buffer[0] = u''.encode(u'utf-8')
				vim.current.buffer.append(res.encode(u'utf-8'))

		# position the cursor of the current todo item
		vim.command(u'normal G'.encode(u'utf-8'))
		current_state = settings.unset(u'org_current_state_%d' % bufnr)
		found = False
		if current_state is not None and current_state != '':
			for i in xrange(0, len(vim.current.buffer)):
				idx = vim.current.buffer[i].find(current_state)
				if idx != -1:
					vim.current.window.cursor = (i + 1, idx)
					found = True
					break
		if not found:
			vim.current.window.cursor = (2, 4)

		# finally make buffer non modifiable
		vim.command(u'setfiletype orgtodo'.encode(u'utf-8'))
		vim.command(u'setlocal nomodifiable'.encode(u'utf-8'))

		# remove temporary todo states for the current buffer
		del ORGTODOSTATES[bufnr]