mirror of
https://github.com/inkarkat/vim-ingo-library.git
synced 2026-05-29 11:18:51 +02:00
ENH: Add ingo#cmdargs#file#FilterFileOptions() variant of ingo#cmdargs#file#FilterFileOptionsAndCommands()
This commit is contained in:
@@ -39,10 +39,36 @@ function! ingo#cmdargs#file#FilterEscapedFileOptionsAndCommands( arguments )
|
||||
\)[1:2]
|
||||
endfunction
|
||||
|
||||
function! ingo#cmdargs#file#FilterFileOptions( fileglobs )
|
||||
"*******************************************************************************
|
||||
"* PURPOSE:
|
||||
" Strip off the optional ++opt file options that can be given to :write and
|
||||
" :saveas.
|
||||
"
|
||||
"* ASSUMPTIONS / PRECONDITIONS:
|
||||
" None.
|
||||
"* EFFECTS / POSTCONDITIONS:
|
||||
" (Potentially) removes options from a:fileglobs.
|
||||
"* INPUTS:
|
||||
" a:fileglobs Raw list of file patterns. To get this from a <q-args> string,
|
||||
" use ingo#cmdargs#file#SplitAndUnescape().
|
||||
"* RETURN VALUES:
|
||||
" [a:fileglobs, fileOptions] First element is the passed list, with any file
|
||||
" options removed. Second element is a List containing all removed file
|
||||
" options.
|
||||
" Note: If the file arguments were obtained through
|
||||
" ingo#cmdargs#file#SplitAndUnescape(), these must be re-escaped for use
|
||||
" in another Ex command:
|
||||
" join(map(l:fileOptionsAndCommands, "escape(v:val, '\\ ')"))
|
||||
"*******************************************************************************
|
||||
return [a:fileglobs, ingo#list#split#RemoveFromStartWhilePredicate(a:fileglobs, 'v:val =~# ' . string('^' . s:fileOptionsExpr . '$'))]
|
||||
endfunction
|
||||
|
||||
function! ingo#cmdargs#file#FilterFileOptionsAndCommands( fileglobs )
|
||||
"*******************************************************************************
|
||||
"* PURPOSE:
|
||||
" Strip off the optional ++opt +cmd file options and command.
|
||||
" Strip off the optional ++opt +cmd file options and command that can be given
|
||||
" to :edit, :split, etc.
|
||||
"
|
||||
" (In Vim 7.2,) options and commands can only appear at the beginning of the
|
||||
" file list; there can be multiple options, followed by only one command. They
|
||||
@@ -51,7 +77,7 @@ function! ingo#cmdargs#file#FilterFileOptionsAndCommands( fileglobs )
|
||||
"* ASSUMPTIONS / PRECONDITIONS:
|
||||
" None.
|
||||
"* EFFECTS / POSTCONDITIONS:
|
||||
" None.
|
||||
" (Potentially) removes options and commands from a:fileglobs.
|
||||
"* INPUTS:
|
||||
" a:fileglobs Raw list of file patterns. To get this from a <q-args> string,
|
||||
" use ingo#cmdargs#file#SplitAndUnescape(). Or alternatively
|
||||
@@ -65,13 +91,13 @@ function! ingo#cmdargs#file#FilterFileOptionsAndCommands( fileglobs )
|
||||
" in another Ex command:
|
||||
" join(map(l:fileOptionsAndCommands, "escape(v:val, '\\ ')"))
|
||||
"*******************************************************************************
|
||||
let l:fileOptionsAndCommands = ingo#list#split#RemoveFromStartWhilePredicate(a:fileglobs, 'v:val =~# ' . string('^' . s:fileOptionsExpr . '$'))
|
||||
let [l:fileglobs, l:fileOptionsAndCommands] = ingo#cmdargs#file#FilterFileOptions(a:fileglobs)
|
||||
|
||||
if get(a:fileglobs, 0, '') =~# '^++\@!'
|
||||
call add(l:fileOptionsAndCommands, remove(a:fileglobs, 0))
|
||||
if get(l:fileglobs, 0, '') =~# '^++\@!'
|
||||
call add(l:fileOptionsAndCommands, remove(l:fileglobs, 0))
|
||||
endif
|
||||
|
||||
return [a:fileglobs, l:fileOptionsAndCommands]
|
||||
return [l:fileglobs, l:fileOptionsAndCommands]
|
||||
endfunction
|
||||
|
||||
function! ingo#cmdargs#file#Unescape( fileArgument )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
" Test modification of the passed-in fileglobs List.
|
||||
" Test modification of the passed-in fileglobs List when stripping options and commands.
|
||||
|
||||
call vimtest#StartTap()
|
||||
call vimtap#Plan(2)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
" Test stripping file options.
|
||||
|
||||
call vimtest#StartTap()
|
||||
call vimtap#Plan(8)
|
||||
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions([]), [[], []], 'empty fileglobs')
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(['/tmp/foo']), [['/tmp/foo'], []], 'just a file')
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(['foo*', 'bar']), [['foo*', 'bar'], []], 'just two files')
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(['+setl et', 'foo*', 'bar']), [['+setl et', 'foo*', 'bar'], []], 'command is treated as file')
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(['foo*', '++ff=unix']), [['foo*', '++ff=unix'], []], 'option after fileglob is treated as fileglob')
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(['++ff=unix', 'foo*', 'bar']), [['foo*', 'bar'], ['++ff=unix']], 'option and two files')
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(['++ff=unix', '++enc=utf-8', 'foo*', 'bar']), [['foo*', 'bar'], ['++ff=unix', '++enc=utf-8']], 'two options and two files')
|
||||
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(['++whatis=that', 'foo*', 'bar']), [['++whatis=that', 'foo*', 'bar'], []], 'invalid option is treated as fileglob')
|
||||
|
||||
call vimtest#Quit()
|
||||
@@ -0,0 +1,10 @@
|
||||
" Test modification of the passed-in fileglobs List when stripping options.
|
||||
|
||||
call vimtest#StartTap()
|
||||
call vimtap#Plan(2)
|
||||
|
||||
let g:fileglobs = ['++ff=unix', '++enc=utf-8', 'foo*', 'bar']
|
||||
call vimtap#Is(ingo#cmdargs#file#FilterFileOptions(g:fileglobs), [['foo*', 'bar'], ['++ff=unix', '++enc=utf-8']], 'two options and two files')
|
||||
call vimtap#Is(g:fileglobs, ['foo*', 'bar'], 'original argument list has been reduced')
|
||||
|
||||
call vimtest#Quit()
|
||||
Reference in New Issue
Block a user