local Code=[[ _G.LFSTag=nil local patt=regex.new("<\\/?(?:\\w+?|xsl:\\w+?-?\\w+?)[ >]","ix") local s=editor.GetStringW() if not s then return end local pos,pEnd = editor.GetInfo().CurPos,s.StringLength+1 if pos>pEnd then return elseif pos==pEnd then pos=pos-1 end local text,start = s.StringText.."\0",1 while true do local b,e = patt:findW(text,start) if b==nil or b>pos then break elseif e>=pos then _G.LFSTag={} --_G.LFSTag={Num=win.subW(text,pos,pos)=='\60\0' and 0 or 1} --far.Message("b="..b.."\npos="..pos) _G.LFSTag.Txt=win.Utf16ToUtf8(win.subW(text,b,e-1)) _G.LFSTag.Rev=_G.LFSTag.Txt:sub(2,2)=='/' _G.LFSTag.Num=b==pos and not _G.LFSTag.Rev and 0 or 1 _G.LFSTag.Tag=_G.LFSTag.Rev and '<'.._G.LFSTag.Txt:sub(3,-1) or _G.LFSTag.Txt break end start=e+1 end if not _G.LFSTag then return end --far.Message("Txt=".._G.LFSTag.Txt.."\nTag=".._G.LFSTag.Tag) local Data={ sSearchPat="(</?(?:\\w+?|xsl:\\w+?-?\\w+?))[ >]", sReplacePat="if T[1]==_G.LFSTag.Txt then _G.LFSTag.Num=_G.LFSTag.Num+1 elseif (T[1]:sub(2,2)=='/' and '<'..T[1]:sub(3,-1) or T[1])==_G.LFSTag.Tag then _G.LFSTag.Num=LFSTag.Num-1 end if _G.LFSTag.Num==0 then return true,true end", sRegexLib="oniguruma", --"far" (default), "oniguruma", "pcre" or "pcre2" bRegExpr=true, bSearchBack=_G.LFSTag.Rev, bRepIsFunc=true, bConfirmReplace=true, fUserChoiceFunc=function() return "cancel" end } local nFound,nReps = lfsearch.EditorAction("test:replace",Data) return _G.LFSTag.Num,_G.LFSTag.Rev,nFound,nReps ]] --<div><div><font><p></p></font></div></div> --<xsl:when test=""><xsl:apply-templates select=""><xsl:sort select="" /></xsl:apply-templates></xsl:when> local LFS_Guid="8E11EA75-0303-4374-AC60-D1E38F865449" Macro { description="Goto Begin<=>End of Tags"; area="Editor"; key="AltM"; action=function() --local ttime=far.FarClock() local Num,Rev,nFound,nReps = Plugin.SyncCall(LFS_Guid,"code",Code) --ttime = far.FarClock()-ttime --far.Message("Num="..tostring(Num).."\nRev="..tostring(Rev).."\nnFound="..tostring(nFound).."\nnReps"..tostring(nReps)) if Num==0 and not Rev then Keys("Left") end --local report="Time: "..ttime.." mcs" --far.Message(report,"Report",nil,"l") end } |