python3: Use global variables for py/pyfile so they are accessible from within pyton too

This commit is contained in:
Tomas Babej 2016-12-16 04:13:41 +01:00
parent 8f4a87e16e
commit be0cfed86c
3 changed files with 38 additions and 38 deletions

View file

@ -6,11 +6,11 @@ endif
" Check presence of the python support
if has("python")
let s:py='py '
let s:pyfile='pyfile '
let g:taskwiki_py='py '
let g:taskwiki_pyfile='pyfile '
elseif has("python3")
let s:py='py3 '
let s:pyfile='py3file '
let g:taskwiki_py='py3 '
let g:taskwiki_pyfile='py3file '
else
echoerr "Taskwiki requires Vim compiled with the Python support."
finish
@ -26,11 +26,11 @@ let s:plugin_path = escape(expand('<sfile>:p:h:h'), '\')
" Run the measure parts first, if desired
if exists("g:taskwiki_measure_coverage")
execute s:pyfile . s:plugin_path . '/taskwiki/coverage.py'"
execute g:taskwiki_pyfile . s:plugin_path . '/taskwiki/coverage.py'"
endif
" Execute the main body of taskwiki source
execute s:pyfile . s:plugin_path . '/taskwiki/main.py'
execute g:taskwiki_pyfile . s:plugin_path . '/taskwiki/main.py'
augroup taskwiki
autocmd!
@ -42,54 +42,54 @@ augroup taskwiki
execute "autocmd BufWinEnter *.".expand('%:e')." silent! loadview"
execute "autocmd BufWinEnter *.".expand('%:e')." silent! doautocmd SessionLoadPost *.".expand('%:e')
endif
execute "autocmd BufEnter *.".expand('%:e')." :" . s:py . "cache.reset()"
execute "autocmd BufEnter *.".expand('%:e')." :" . g:taskwiki_py . "cache.reset()"
augroup END
" Global update commands
execute "command! -nargs=* TaskWikiBufferSave :" . s:py . "WholeBuffer.update_to_tw()"
execute "command! -nargs=* TaskWikiBufferLoad :" . s:py . "WholeBuffer.update_from_tw()"
execute "command! -nargs=* TaskWikiBufferSave :" . g:taskwiki_py . "WholeBuffer.update_to_tw()"
execute "command! -nargs=* TaskWikiBufferLoad :" . g:taskwiki_py . "WholeBuffer.update_from_tw()"
" Split reports commands
execute "command! -nargs=* TaskWikiProjects :" . s:py . "SplitProjects(<q-args>).execute()"
execute "command! -nargs=* TaskWikiProjectsSummary :" . s:py . "SplitSummary(<q-args>).execute()"
execute "command! -nargs=* TaskWikiBurndownDaily :" . s:py . "SplitBurndownDaily(<q-args>).execute()"
execute "command! -nargs=* TaskWikiBurndownMonthly :" . s:py . "SplitBurndownMonthly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiBurndownWeekly :" . s:py . "SplitBurndownWeekly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiCalendar :" . s:py . "SplitCalendar(<q-args>).execute()"
execute "command! -nargs=* TaskWikiGhistoryAnnual :" . s:py . "SplitGhistoryAnnual(<q-args>).execute()"
execute "command! -nargs=* TaskWikiGhistoryMonthly :" . s:py . "SplitGhistoryMonthly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiHistoryAnnual :" . s:py . "SplitHistoryAnnual(<q-args>).execute()"
execute "command! -nargs=* TaskWikiHistoryMonthly :" . s:py . "SplitHistoryMonthly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiStats :" . s:py . "SplitStats(<q-args>).execute()"
execute "command! -nargs=* TaskWikiTags :" . s:py . "SplitTags(<q-args>).execute()"
execute "command! -nargs=* TaskWikiProjects :" . g:taskwiki_py . "SplitProjects(<q-args>).execute()"
execute "command! -nargs=* TaskWikiProjectsSummary :" . g:taskwiki_py . "SplitSummary(<q-args>).execute()"
execute "command! -nargs=* TaskWikiBurndownDaily :" . g:taskwiki_py . "SplitBurndownDaily(<q-args>).execute()"
execute "command! -nargs=* TaskWikiBurndownMonthly :" . g:taskwiki_py . "SplitBurndownMonthly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiBurndownWeekly :" . g:taskwiki_py . "SplitBurndownWeekly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiCalendar :" . g:taskwiki_py . "SplitCalendar(<q-args>).execute()"
execute "command! -nargs=* TaskWikiGhistoryAnnual :" . g:taskwiki_py . "SplitGhistoryAnnual(<q-args>).execute()"
execute "command! -nargs=* TaskWikiGhistoryMonthly :" . g:taskwiki_py . "SplitGhistoryMonthly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiHistoryAnnual :" . g:taskwiki_py . "SplitHistoryAnnual(<q-args>).execute()"
execute "command! -nargs=* TaskWikiHistoryMonthly :" . g:taskwiki_py . "SplitHistoryMonthly(<q-args>).execute()"
execute "command! -nargs=* TaskWikiStats :" . g:taskwiki_py . "SplitStats(<q-args>).execute()"
execute "command! -nargs=* TaskWikiTags :" . g:taskwiki_py . "SplitTags(<q-args>).execute()"
" Commands that operate on tasks in the buffer
execute "command! -range TaskWikiInfo :<line1>,<line2>" . s:py . "SelectedTasks().info()"
execute "command! -range TaskWikiEdit :<line1>,<line2>" . s:py . "SelectedTasks().edit()"
execute "command! -range TaskWikiLink :<line1>,<line2>" . s:py . "SelectedTasks().link()"
execute "command! -range TaskWikiGrid :<line1>,<line2>" . s:py . "SelectedTasks().grid()"
execute "command! -range TaskWikiDelete :<line1>,<line2>" . s:py . "SelectedTasks().delete()"
execute "command! -range TaskWikiStart :<line1>,<line2>" . s:py . "SelectedTasks().start()"
execute "command! -range TaskWikiStop :<line1>,<line2>" . s:py . "SelectedTasks().stop()"
execute "command! -range TaskWikiDone :<line1>,<line2>" . s:py . "SelectedTasks().done()"
execute "command! -range TaskWikiInfo :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().info()"
execute "command! -range TaskWikiEdit :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().edit()"
execute "command! -range TaskWikiLink :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().link()"
execute "command! -range TaskWikiGrid :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().grid()"
execute "command! -range TaskWikiDelete :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().delete()"
execute "command! -range TaskWikiStart :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().start()"
execute "command! -range TaskWikiStop :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().stop()"
execute "command! -range TaskWikiDone :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().done()"
execute "command! -range -nargs=* TaskWikiSort :<line1>,<line2>" . s:py . "SelectedTasks().sort(<q-args>)"
execute "command! -range -nargs=* TaskWikiMod :<line1>,<line2>" . s:py . "SelectedTasks().modify(<q-args>)"
execute "command! -range -nargs=* TaskWikiAnnotate :<line1>,<line2>" . s:py . "SelectedTasks().annotate(<q-args>)"
execute "command! -range -nargs=* TaskWikiSort :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().sort(<q-args>)"
execute "command! -range -nargs=* TaskWikiMod :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().modify(<q-args>)"
execute "command! -range -nargs=* TaskWikiAnnotate :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().annotate(<q-args>)"
" Interactive commands
execute "command! -range TaskWikiChooseProject :<line1>,<line2>" . s:py . "ChooseSplitProjects('global').execute()"
execute "command! -range TaskWikiChooseTag :<line1>,<line2>" . s:py . "ChooseSplitTags('global').execute()"
execute "command! -range TaskWikiChooseProject :<line1>,<line2>" . g:taskwiki_py . "ChooseSplitProjects('global').execute()"
execute "command! -range TaskWikiChooseTag :<line1>,<line2>" . g:taskwiki_py . "ChooseSplitTags('global').execute()"
" Meta commands
execute "command! TaskWikiInspect :" . s:py . "Meta().inspect_viewport()"
execute "command! TaskWikiInspect :" . g:taskwiki_py . "Meta().inspect_viewport()"
" Disable <CR> as VimwikiFollowLink
if !hasmapto('<Plug>VimwikiFollowLink')
nmap <Plug>NoVimwikiFollowLink <Plug>VimwikiFollowLink
endif
execute "nmap <silent><buffer> <CR> :" . s:py . "Mappings.task_info_or_vimwiki_follow_link()<CR>"
execute "nmap <silent><buffer> <CR> :" . g:taskwiki_py . "Mappings.task_info_or_vimwiki_follow_link()<CR>"
" Leader-related mappings. Mostly <Leader>t + <first letter of the action>
nmap <silent><buffer> <Leader>ta :TaskWikiAnnotate<CR>

View file

@ -392,7 +392,7 @@ class CallbackSplitMixin(object):
# Remap <CR> to calling the callback and wiping the buffer
vim.command(
"nnoremap <silent> <buffer> <enter> :"
+ vim.vars['s:py'].decode() +
+ vim.vars['taskwiki_py'].decode() +
"callback = pickle.loads("
"vim.current.buffer.vars['taskwiki_callback']); "
"callback.callback(); "

View file

@ -294,7 +294,7 @@ def show_in_split(lines, size=None, position="belowright", vertical=False,
# Remove cursorline in original window if it was this split which set it
if cursorline_activated_in_window is not None:
vim.command("au BufLeave,BufDelete,BufWipeout <buffer> "
+ vim.vars['s:py'].decode() +
+ vim.vars['taskwiki_py'].decode() +
" vim.windows[{0}].options['cursorline']=False"
.format(cursorline_activated_in_window))