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 EGI=editor.GetInfo() local pos,pEnd = EGI.CurPos,s.StringLength+1 local Y1,X1 = EGI.CurLine 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 X1=_G.LFSTag.Rev and e or b 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,X1,Y1,nFound,nReps ]] --<xsl:apply-templates select=""><div><div><div><font><p></p></font></div></div> --<xsl:when test=""><xsl:apply-templates select=""><xsl:sort select="" /> --</xsl:apply-templates></xsl:when></div></xsl:apply-templates> 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,X1,Y1,nFound,nReps = Plugin.SyncCall(LFS_Guid,"code",Code) --ttime = far.FarClock()-ttime if Num==0 and not Rev then Keys("Left") end --far.Message("Num="..tostring(Num).."\nRev="..tostring(Rev).."\nnFound="..tostring(nFound).."\nnReps"..tostring(nReps)) if X1 and Y1 then local EGI=editor.GetInfo() local X2,Y2 = EGI.CurPos,EGI.CurLine local F=far.Flags local SelectData={ BlockType=F.BTYPE_STREAM, BlockStartLine=math.min(Y2,Y1), BlockStartPos=Y1<Y2 and X1 or (Y1==Y2 and math.min(X1,X2) or X2) } if X1==X2 then SelectData.BlockStartPos=SelectData.BlockStartPos+(Y1<Y2 and 1 or -1) end SelectData.BlockHeight=math.max(Y1,Y2)-math.min(Y1,Y2)+1 if Y1<Y2 then SelectData.BlockWidth=X2-X1+1 elseif Y1==Y2 then SelectData.BlockWidth=math.abs(X2-X1)+1 else SelectData.BlockWidth=X1-X2+1 end if X1==X2 then if Y1<Y2 then SelectData.BlockStartPos=SelectData.BlockStartPos-1 else SelectData.BlockStartPos=SelectData.BlockStartPos+1 end end far.Message("Y1="..SelectData.BlockStartLine.."\nX1="..SelectData.BlockStartPos.."\nW="..SelectData.BlockWidth.."\nH="..SelectData.BlockHeight) --editor.Select(nil,F.BTYPE_NONE,-1,-1,0,1) editor.Select(nil,SelectData) --local report="Time: "..ttime.." mcs" --far.Message(report,"Report",nil,"l") end end } |