Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing arguments. Example: ci2na works and c2ina works as well #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions autoload/targets.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ set cpo&vim
let s:lastRawTarget = targets#target#withError('initial')
let s:lastTrigger = " "

" a:count is unused here, but added for consistency with targets#x
function! targets#o(trigger, typed, count)
call s:init()
let context = targets#context#new('o', a:trigger, 1, {})

" reset last raw target to not avoid it in #o when it was set from #x
let s:lastRawTarget = targets#target#withError('#o')

let [target, rawTarget] = s:findTarget(context, v:count1)
let [target, rawTarget] = s:findTarget(context, a:count)
if target.state().isInvalid()
call s:abortMatch(context, '#o: ' . target.error)
return s:cleanUp()
Expand All @@ -39,26 +38,53 @@ function! targets#e(mapmode, modifier, original)
return a:original
endif

let char1 = nr2char(getchar())
let [trigger, which, chars] = [char1, 'c', char1]
let s:char1 = nr2char(getchar())

" Check if user inputs count
let s:parsedCount = 0
while s:char1 =~# '^\d\+$'
let s:parsedCount *= 10
let s:parsedCount += s:char1
let s:char1 = nr2char(getchar())
endwhile


let [trigger, which, chars] = [s:char1, 'c', s:char1]
for i in range(2)
if g:targets_nl[i] ==# trigger
" trigger was which, get another char for trigger
let char2 = nr2char(getchar())
let [trigger, which, chars] = [char2, 'nl'[i], chars . char2]
let s:char2 = nr2char(getchar())

" Check if user inputs count
if s:char2 =~# '^\d\+$'
let s:parsedCount = 0
while s:char2 =~# '^\d\+$'
let s:parsedCount *= 10
let s:parsedCount += s:char2
let s:char2 = nr2char(getchar())
endwhile
endif

let [trigger, which, chars] = [s:char2, 'nl'[i], chars . s:char2]
break
endif
endfor

if s:parsedCount == 0
let s:parsedCount = v:count1
endif

echo "parsed count: " . s:parsedCount

let typed = a:original . chars
if empty(s:getFactories(trigger))
return typed
endif

let trigger = substitute(trigger, "'", "''", "g")
let typed = substitute(typed, "'", "''", "g")

let s:call = "call targets#" . a:mapmode . "('" . trigger . which . a:modifier . "', '" . typed . "', " . v:count1 . ")"
echo "call targets#" . a:mapmode . "('" . trigger . which . a:modifier . "', '" . typed . "', " . s:parsedCount . ")"
let s:call = "call targets#" . a:mapmode . "('" . trigger . which . a:modifier . "', '" . typed . "', " . s:parsedCount . ")"
" indirectly (but silently) call targets#do below
return "@(targets)"
endfunction
Expand Down