" ingo/regexp/magic.vim: Functions around handling magicness in regular expressions. " " DEPENDENCIES: " - ingo/collections.vim autoload script for ingo#regexp#magic#Normalize() " - ingo/collections/fromsplit.vim autoload script " - ingo/regexp/collection.vim autoload script " " Copyright: (C) 2011-2017 Ingo Karkat " The VIM LICENSE applies to this script; see ':help copyright'. " " Maintainer: Ingo Karkat " " REVISION DATE REMARKS " 1.029.004 24-Jan-2017 Test failure in " PatternsOnText/t7580-SubstituteMultiple-magic.vim " alerted me to the fact that \V[1] needs to be " escaped as \[1]. Also process the collections " through new " ingo#regexp#magic#ConvertMagicnessOfCollection(). " 1.029.003 23-Jan-2017 BUG: ingo#regexp#magic#Normalize() also " processes the contents of collections [...]; " especially the escaping of "]" wreaks havoc on " the pattern. Rename s:ConvertMagicness() into " ingo#regexp#magic#ConvertMagicnessOfElement() " and introduce intermediate " s:ConvertMagicnessOfFragment() that first " separates collections from other elements and " only invokes the former on those other elements. " 1.009.002 14-Jun-2013 Minor: Make substitute() robust against " 'ignorecase'. " 1.006.001 24-May-2013 file creation from ingosearch.vim. let s:save_cpo = &cpo set cpo&vim function! ingo#regexp#magic#GetNormalizeMagicnessAtom( pattern ) "****************************************************************************** "* PURPOSE: " Return normalizing \m (or \M) if a:pattern contains atom(s) that change the " default magicness. This makes it possible to append another pattern without " having a:pattern affect it. " "* ASSUMPTIONS / PRECONDITIONS: " None. "* EFFECTS / POSTCONDITIONS: " None. "* INPUTS: " a:pattern Regular expression to observe. "* RETURN VALUES: " Normalizing atom or empty string. "****************************************************************************** let l:normalizingAtom = (&magic ? 'm' : 'M') let l:magicChangeAtoms = substitute('vmMV', '\C'.l:normalizingAtom, '', '') return (a:pattern =~# '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@