From: Andy Wokula Date: Fri, 15 Dec 2017 18:22:52 +0000 (+0100) Subject: v0.9 X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/8b7939ff867684ca9e31f1f0022fb91bbbdf152d?ds=sidebyside;hp=--cc v0.9 --- 8b7939ff867684ca9e31f1f0022fb91bbbdf152d diff --git a/autoload/explainpat.vim b/autoload/explainpat.vim index 5662732..0fded10 100644 --- a/autoload/explainpat.vim +++ b/autoload/explainpat.vim @@ -1,7 +1,7 @@ " File: explainpat.vim " Created: 2011 Nov 02 -" Last Change: 2017 Oct 20 -" Version: 0.7 +" Last Change: 2017 Dec 15 +" Version: 0.9 " Author: Andy Wokula " License: Vim License, see :h license @@ -66,7 +66,7 @@ func! explainpat#ExplainPattern(cmd_arg, ...) "{{{ " >=1 at pos 0 or after '\|', '\&', '\(', '\%(' or '\n'; else 0 or less: let s:at_begin_of_pat = 1 - let hulit = a:0>=1 && type(a:1)==s:DICT ? a:1 : s:NewHelpPrinter() + let hulit = a:0>=1 && type(a:1)==s:DICT ? a:1 : explainpat#NewHelpPrinter() call hulit.AddIndent(' ') let bull = s:NewTokenBiter(magicpat) while !bull.AtEnd() @@ -99,7 +99,7 @@ let s:FUNCREF = type(function("tr")) let s:LIST = type([]) " }}} -let s:magic_item_pattern = '\C^\%(\\\%(@<\|%#=\|%[dxouU[(^$V#<>]\=\|z[1-9se(]\|@[>=!]\|_[[^$.]\=\|.\)\|.\)' +let s:magic_item_pattern = '\C^\%(\\\%(%#=\|%[dxouU[(^$V#<>]\=\|z[1-9se(]\|@[>=!]\=\|_[[^$.]\=\|.\)\|.\)' let s:doc = {} " {{{ " this is all the help data ... @@ -187,17 +187,21 @@ let s:doc['\@='] = "(assertion) require match for preceding atom" let s:doc['\@!'] = "(assertion) forbid match for preceding atom" func! s:DocBefore(bull, hulit, item) "{{{ - let rest = a:bull.Bite('^[=!]') - if rest == "=" + let rest = a:bull.Bite('^\d*\%[<[=!]]') + if rest == "<=" call a:hulit.Print(a:item.rest, "(assertion) require match for preceding atom to the left") - elseif rest == "!" + elseif rest == "= 1 @@ -482,7 +486,13 @@ let s:doc['\%U'] = function("s:DocBspercHexEight") " 1234abcd " \V "}}} -func! s:NewHelpPrinter() "{{{ +" {{{ +func! s:SillyCheck(digits) "{{{ + return strlen(a:digits) < 10 ? a:digits : '{silly large number}' +endfunc "}}} +" }}} + +func! explainpat#NewHelpPrinter() "{{{ let obj = {} let obj.literals = '' let obj.indents = [] diff --git a/doc/explainpat.txt b/doc/explainpat.txt index afe0fc9..0268c69 100644 --- a/doc/explainpat.txt +++ b/doc/explainpat.txt @@ -1,6 +1,6 @@ *explainpat.txt* Give detailed help on a regexp pattern. - For Vim version 7.0. Last change: 2017 Oct 20 + For Vim version 7.0. Last change: 2017 Dec 15 By Andy Wokula *explainpat* *explainpat.vim* @@ -25,6 +25,9 @@ URL http://vim.sourceforge.net/scripts/script.php?script_id=4364 a explain pattern from register a etc. +> + :ExplainPattern \C^\%(\\\%(@<\|%#=\|%[dxouU[(^$V#<>]\=\|z[1-9se(]\|@[>=!]\|_[[^$.]\=\|.\)\|.\) + Notes: The pattern is first converted into a purely |magic| pattern using |nwo#magic#MakeMagic()|. This means that embedded |/\V| |/\M| |/\m| |/\v| @@ -37,6 +40,7 @@ specifiers are effectively removed from the explanation. ============================================================================== TODO: +? `\%[...]` can be nested? But documentation |/\%[]| says no. Ideas: - If the user already knows regular expressions but of a different kind, @@ -53,6 +57,12 @@ Ideas: ============================================================================== History: +v0.9 ++ BF accept `\@123<=` and `\@123 explainpat#NewHelpPrinter() + v0.7 + BF `\{3,4\}` not accepted, only `\{3,4}`