" ingo/smartcase.vim: Functions for SmartCase searches. " " DEPENDENCIES: " " Copyright: (C) 2014-2020 Ingo Karkat " The VIM LICENSE applies to this script; see ':help copyright'. " " Maintainer: Ingo Karkat let s:save_cpo = &cpo set cpo&vim let s:singleSmartCaseAssertion = '\%(\A\&\k\)\=' let s:singleSmartCasePattern = printf('\V\C\^\\c\\(%s\(\zs\.\*\ze\)\\|\1%s\\)\$', escape(s:singleSmartCaseAssertion, '\') , escape(s:singleSmartCaseAssertion, '\')) function! ingo#smartcase#IsSmartCasePattern( pattern ) return (a:pattern =~# '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@ 2 ? a:atom : '\A\=') endfunction function! ingo#smartcase#FromPattern( pattern, ... ) let l:pattern = a:pattern let l:additionalEscapeCharacters = (a:0 ? a:1 : '') " Make all non-alphabetic delimiter characters and whitespace optional. " Keep any regexp atoms, like \<, \%# (the 3+ character ones must be " explicitly matched). " As backslashes are escaped, they must be handled separately. Same for any " escaped substitution separator. let l:pattern = substitute(l:pattern, '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@(]\|%[<>]\?''\|@\%(=\|!\|<=\|\)\|_[\[$^.]\|{[-[:digit:],]*}' . \ '\)', \ '\=s:Escape(submatch(0))', 'g' \) " Allow delimiters between CamelCase fragments to catch all variants. let l:pattern = substitute(l:pattern, '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@