Skip to content

Commit

Permalink
WIP: feat: BobProject from log entry
Browse files Browse the repository at this point in the history
Allows calling :BobProject without arguments when on a log entry, which
will recreate the project the same way as it was logged.

TODO:

* documenation
* test
  • Loading branch information
ThomasFeher committed May 19, 2024
1 parent 3cee68c commit b23fc69
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions ftdetect/vim-bob.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
au BufRead,BufNewFile .vim-bob_project.log set filetype=vim-bob_project_log.yaml
58 changes: 52 additions & 6 deletions plugin/vim-bob.vim
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,61 @@ function! s:GetStatus(...)
echo l:output
endfunction

function! s:Project(bang, package, ...)
call s:CheckInit()

function! s:Project(bang, ...)
let l:args = {}
if a:0 > 0
" the first option is always the configuration (without the '-c')
let l:args.config = a:1
call s:CheckInit()
let l:package = a:1
if a:0 > 1
let l:args.args = a:000[1:-1]
" the second option is always the configuration (without the '-c')
let l:args.config = a:2
if a:0 > 2
let l:args.args = a:000[2:-1]
endif
endif
else
if &filetype =~? 'vim-bob_project_log'
let l:line_nr = line('.')
let l:line = getline(l:line_nr)
while l:line !~ '^- '
echo l:line_nr . ': ' . l:line
if l:line_nr == 1
throw 'error: could not find a valid log entry'
endif
let l:line_nr = l:line_nr - 1
let l:line = getline(l:line_nr)
endwhile
" now we are at the begin of the entry
" parse prefix
let l:line = getline(l:line_nr + 1)
let l:match = matchlist(l:line, ' prefix: \(.*\)')
if empty(l:match)
throw 'internal error: expected entry `prefix` at line ' . (l:line_nr + 1)
endif
let g:bob_prefix = l:match[1]
" parse directory
let l:line = getline(l:line_nr + 3)
let l:match = matchlist(l:line, ' directory: \(.*\)')
if empty(l:match)
throw 'internal error: expected entry `directory` at line ' . (l:line_nr + 3)
endif
call s:Init(match[1])
" parse configuration
let l:line = getline(l:line_nr + 2)
let l:match = matchlist(l:line, ' configuration: \(.*\)')
if empty(l:match)
throw 'internal error: expected entry `configuration` at line ' . (l:line_nr + 2)
endif
let l:args.config = l:match[1]
" parse arguments
let l:line = getline(l:line_nr + 4)
let l:match = matchlist(l:line, ' arguments: \(.*\)')
if empty(l:match)
throw 'internal error: expected entry `arguments` at line ' . (l:line_nr + 4)
endif
let l:args.args = l:match[1]
else
throw 'error: too few arguments or not a .vim-bob_project.log file'
endif
endif
" build the project
Expand Down

0 comments on commit b23fc69

Please sign in to comment.