mirror of
https://github.com/inkarkat/vim-ingo-library.git
synced 2025-12-22 12:13:58 +01:00
ENH: ingo#query#get#[Valid]Char() takes digraphs by default
This can be disabled via a:options.isAllowDigraphs = 0. The query functions for register, mark, substitute confirm, history recall, and confirmed filter disallow that as it's not needed.
This commit is contained in:
@@ -208,6 +208,8 @@ HISTORY
|
||||
a:options.additionalValidExpr
|
||||
- Add ingo/digraph.vim module.
|
||||
- Add ingo#query#get#CharOrDigraph().
|
||||
- ENH: ingo#query#get#[Valid]Char() takes digraphs by default; can be disabled
|
||||
via a:options.isAllowDigraphs = 0.
|
||||
|
||||
##### 1.043 04-Feb-2022
|
||||
- Minor: Actually support no-argument form of
|
||||
|
||||
@@ -315,7 +315,8 @@ function! ingo#plugin#historyrecall#List( what, multiplier, register, ... )
|
||||
\ 'validExpr': "[123456789\<CR>\<Del>\<BS>" .
|
||||
\ (empty(l:validNamesAndRecalls) ? '' : '"' . l:validNamesAndRecalls) .
|
||||
\ l:additionalKeys .
|
||||
\ ']'
|
||||
\ ']',
|
||||
\ 'isAllowDigraphs': 0,
|
||||
\})
|
||||
if empty(l:choice) || l:choice ==# "\<CR>"
|
||||
return 1
|
||||
@@ -337,7 +338,10 @@ function! ingo#plugin#historyrecall#List( what, multiplier, register, ... )
|
||||
return 1
|
||||
elseif l:choice ==# '"'
|
||||
echon l:choice
|
||||
let l:choice = ingo#query#get#ValidChar({'validExpr': "[\<CR>" . l:validNamesAndRecalls . ']'})
|
||||
let l:choice = ingo#query#get#ValidChar({
|
||||
\ 'validExpr': "[\<CR>" . l:validNamesAndRecalls . ']'
|
||||
\ 'isAllowDigraphs': 0,
|
||||
\})
|
||||
if empty(l:choice) || l:choice ==# "\<CR>"
|
||||
return 1
|
||||
elseif l:choice =~# '[1-9]'
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
" ingo/plugin/rendered/Confirmeach.vim: Filter items by confirming each, as with :s///c.
|
||||
"
|
||||
" DEPENDENCIES:
|
||||
" - ingo/query/get.vim autoload script
|
||||
"
|
||||
" Copyright: (C) 2015-2018 Ingo Karkat
|
||||
" Copyright: (C) 2015-2022 Ingo Karkat
|
||||
" The VIM LICENSE applies to this script; see ':help copyright'.
|
||||
"
|
||||
" Maintainer: Ingo Karkat <ingo@karkat.de>
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! ingo#plugin#rendered#Confirmeach#Filter( items )
|
||||
let l:confirmedItems = []
|
||||
@@ -19,7 +20,10 @@ function! ingo#plugin#rendered#Confirmeach#Filter( items )
|
||||
echon ' Use (y/n/a/q/l; <Esc> to abort)?'
|
||||
echohl None
|
||||
|
||||
let l:choice = ingo#query#get#Char({'isBeepOnInvalid': 0, 'validExpr': "[ynl\<Esc>aq]"})
|
||||
let l:choice = ingo#query#get#Char({
|
||||
\ 'isBeepOnInvalid': 0, 'validExpr': "[ynl\<Esc>aq]",
|
||||
\ 'isAllowDigraphs': 0,
|
||||
\})
|
||||
if l:choice ==# "\<Esc>"
|
||||
return a:items
|
||||
elseif l:choice ==# 'q'
|
||||
@@ -40,4 +44,6 @@ function! ingo#plugin#rendered#Confirmeach#Filter( items )
|
||||
return l:confirmedItems
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
|
||||
|
||||
@@ -105,6 +105,8 @@ function! ingo#query#get#Char( ... )
|
||||
" you add \e, it will be returned as ^[.
|
||||
" a:options.invalidExpr Unanchored pattern for invalid characters.
|
||||
" Takes precedence over a:options.validExpr.
|
||||
" a:options.isAllowDigraphs Flag (default true) whether digraphs (CTRL-K +
|
||||
" char1 + char2) can be entered as well.
|
||||
"* RETURN VALUES:
|
||||
" Either the valid character, or an empty string when aborted or invalid
|
||||
" character.
|
||||
@@ -113,8 +115,9 @@ function! ingo#query#get#Char( ... )
|
||||
let l:isBeepOnInvalid = get(l:options, 'isBeepOnInvalid', 1)
|
||||
let l:validExpr = get(l:options, 'validExpr', '')
|
||||
let l:invalidExpr = get(l:options, 'invalidExpr', '')
|
||||
let l:GetChar = (get(l:options, 'isAllowDigraphs', 1) ? function('ingo#query#get#CharOrDigraph') : function('ingo#compat#getcharstr'))
|
||||
|
||||
let l:char = ingo#compat#getcharstr()
|
||||
let l:char = call(l:GetChar, [])
|
||||
if l:char ==# "\<Esc>" && (empty(l:validExpr) || l:char !~ ingo#regexp#Anchored(l:validExpr))
|
||||
return ''
|
||||
elseif (! empty(l:validExpr) && l:char !~ ingo#regexp#Anchored(l:validExpr)) ||
|
||||
@@ -144,6 +147,8 @@ function! ingo#query#get#ValidChar( ... )
|
||||
" you add \e, it will be returned as ^[.
|
||||
" a:options.invalidExpr Unanchored pattern for invalid characters. Takes
|
||||
" precedence over a:options.validExpr.
|
||||
" a:options.isAllowDigraphs Flag (default true) whether digraphs (CTRL-K +
|
||||
" char1 + char2) can be entered as well.
|
||||
"* RETURN VALUES:
|
||||
" Either the valid character, or an empty string when aborted.
|
||||
"******************************************************************************
|
||||
@@ -151,9 +156,10 @@ function! ingo#query#get#ValidChar( ... )
|
||||
let l:isBeepOnInvalid = get(l:options, 'isBeepOnInvalid', 1)
|
||||
let l:validExpr = get(l:options, 'validExpr', '')
|
||||
let l:invalidExpr = get(l:options, 'invalidExpr', '')
|
||||
let l:GetChar = (get(l:options, 'isAllowDigraphs', 1) ? function('ingo#query#get#CharOrDigraph') : function('ingo#compat#getcharstr'))
|
||||
|
||||
while 1
|
||||
let l:char = ingo#compat#getcharstr()
|
||||
let l:char = call(l:GetChar, [])
|
||||
|
||||
if l:char ==# "\<Esc>" && (empty(l:validExpr) || l:char !~ ingo#regexp#Anchored(l:validExpr))
|
||||
return ''
|
||||
@@ -197,7 +203,8 @@ function! ingo#query#get#Register( ... )
|
||||
try
|
||||
let l:register = ingo#query#get#Char({
|
||||
\ 'validExpr': ingo#register#All() . (empty(l:additionalValidExpr) ? '' : '\|' . l:additionalValidExpr),
|
||||
\ 'invalidExpr': get(l:options, 'invalidRegisterExpr', '')
|
||||
\ 'invalidExpr': get(l:options, 'invalidRegisterExpr', ''),
|
||||
\ 'isAllowDigraphs': 0,
|
||||
\})
|
||||
return (empty(l:register) ? l:errorRegister : l:register)
|
||||
catch /^Vim\%((\a\+)\)\=:E523:/ " E523: Not allowed here
|
||||
@@ -231,7 +238,8 @@ function! ingo#query#get#WritableRegister( ... )
|
||||
try
|
||||
let l:register = ingo#query#get#Char({
|
||||
\ 'validExpr': ingo#register#Writable() . (empty(l:additionalValidExpr) ? '' : '\|' . l:additionalValidExpr),
|
||||
\ 'invalidExpr': get(l:options, 'invalidRegisterExpr', '')
|
||||
\ 'invalidExpr': get(l:options, 'invalidRegisterExpr', ''),
|
||||
\ 'isAllowDigraphs': 0,
|
||||
\})
|
||||
return (empty(l:register) ? l:errorRegister : l:register)
|
||||
catch /^Vim\%((\a\+)\)\=:E523:/ " E523: Not allowed here
|
||||
@@ -257,7 +265,8 @@ function! ingo#query#get#Mark( ... )
|
||||
try
|
||||
return ingo#query#get#Char({
|
||||
\ 'validExpr': '[a-zA-Z0-9''`"[\]<>^.(){}]',
|
||||
\ 'invalidExpr': (a:0 ? (a:1 is# 1 ? '[0-9^.(){}]' : a:1) : '')
|
||||
\ 'invalidExpr': (a:0 ? (a:1 is# 1 ? '[0-9^.(){}]' : a:1) : ''),
|
||||
\ 'isAllowDigraphs': 0,
|
||||
\})
|
||||
catch /^Vim\%((\a\+)\)\=:E523:/ " E523: Not allowed here
|
||||
return ''
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
" ingo/query/substitute.vim: Functions for confirming a command like :substitute//c.
|
||||
"
|
||||
" DEPENDENCIES:
|
||||
" - ingo/query.vim autoload script
|
||||
"
|
||||
" Copyright: (C) 2014-2016 Ingo Karkat
|
||||
" Copyright: (C) 2014-2022 Ingo Karkat
|
||||
" The VIM LICENSE applies to this script; see ':help copyright'.
|
||||
"
|
||||
" Maintainer: Ingo Karkat <ingo@karkat.de>
|
||||
"
|
||||
" REVISION DATE REMARKS
|
||||
" 1.025.002 27-Jan-2016 Refactoring: Factor out ingo#query#Question().
|
||||
" 1.017.001 04-Mar-2014 file creation
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! s:Question( msg )
|
||||
call ingo#query#Question(a:msg . ' (y/n/a/q/l/^E/^Y)?')
|
||||
@@ -32,7 +29,11 @@ function! ingo#query#substitute#Get( msg )
|
||||
call s:Question(a:msg)
|
||||
|
||||
while 1
|
||||
let l:choice = ingo#query#get#Char({'isBeepOnInvalid': 0, 'validExpr': "[ynl\<Esc>aq\<C-e>\<C-y>]"})
|
||||
let l:choice = ingo#query#get#Char({
|
||||
\ 'isBeepOnInvalid': 0,
|
||||
\ 'validExpr': "[ynl\<Esc>aq\<C-e>\<C-y>]",
|
||||
\ 'isAllowDigraphs': 0,
|
||||
\})
|
||||
if l:choice ==# "\<C-e>" || l:choice ==# "\<C-y>"
|
||||
execute 'normal!' l:choice
|
||||
redraw
|
||||
@@ -45,4 +46,6 @@ function! ingo#query#substitute#Get( msg )
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
|
||||
|
||||
@@ -223,6 +223,8 @@ HISTORY *ingo-library-history*
|
||||
a:options.additionalValidExpr
|
||||
- Add ingo/digraph.vim module.
|
||||
- Add ingo#query#get#CharOrDigraph().
|
||||
- ENH: ingo#query#get#[Valid]Char() takes digraphs by default; can be disabled
|
||||
via a:options.isAllowDigraphs = 0.
|
||||
|
||||
1.043 04-Feb-2022
|
||||
- Minor: Actually support no-argument form of
|
||||
|
||||
Reference in New Issue
Block a user