Skip to content

Commit

Permalink
Special case :AD to replace buffer with template
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Jul 5, 2015
1 parent 172b6b0 commit 78a27aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions autoload/projectionist.vim
Expand Up @@ -546,11 +546,13 @@ endfunction
" Section: :A

function! s:jumpopt(file) abort
let pattern = '[:+@#]\d\+$\|[+@#].*$'
let pattern = '!$\|[:+@#]\d\+$\|[+@#].*$'
let file = substitute(a:file, pattern, '', '')
let jump = matchstr(a:file, pattern)
if jump =~# '^[:+@#]\d\+$'
return [file, '+'.jump[1:-1].' ']
elseif jump ==# '!'
return [file, '+AD ']
elseif !empty(jump)
return [file, '+A'.escape(jump, ' ').' ']
else
Expand All @@ -567,6 +569,9 @@ function! s:edit_command(cmd, count, ...) abort
if empty(open[0])
return 'echoerr "Invalid count"'
endif
elseif a:cmd =~# 'read'
call projectionist#apply_template()
return ''
else
let alternates = projectionist#query_file('alternate')
let warning = get(filter(copy(alternates), 'v:val =~# "replace %.*}"'), 0, '')
Expand Down Expand Up @@ -659,7 +664,6 @@ function! projectionist#apply_template() abort
endif
%delete_
call setline(1, split(template, "\n"))
setlocal nomodified
doautocmd BufReadPost
endif
return ''
Expand Down
5 changes: 4 additions & 1 deletion doc/projectionist.txt
Expand Up @@ -141,7 +141,10 @@ are available.
:AT [file] Like :A, but open in a tab.

*projectionist-:AD*
:AD [file] Like :A, but |:read| the file into the current buffer.
:AD Replace the contents of the buffer with the new file
template.

:AD {file} Like :A, but |:read| the file into the current buffer.

*projectionist-:Cd*
:Cd |:cd| to the innermost root.
Expand Down
1 change: 1 addition & 0 deletions plugin/projectionist.vim
Expand Up @@ -95,5 +95,6 @@ augroup projectionist
autocmd BufNewFile *
\ if !empty(get(b:, 'projectionist')) |
\ call projectionist#apply_template() |
\ setlocal nomodified
\ endif
augroup END

0 comments on commit 78a27aa

Please sign in to comment.