Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » FAR Manager (часть 5)

Модерирует : gyra, Maz

Maz (15-01-2020 17:38): FAR Manager (часть 6)  Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

Alexyz21



Silver Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору

Код:
local SelectFound=true -- Select Found true=yes, false=no
 
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
    --far.Message("b="..b.."\ne="..e)
    _G.LFSTag={}
    if e-b==1
    then
      _G.LFSTag.Rev=true
      _G.LFSTag.Num=1
      _G.LFSTag.Cnt=1
    else
      _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.Cnt=b==pos and 2 or 1
      _G.LFSTag.Tag=_G.LFSTag.Rev and '<'.._G.LFSTag.Txt:sub(3,-1) or _G.LFSTag.Txt
    end
    X1=_G.LFSTag.Rev and e or b
    break
  end
  start=e+1
end
if not _G.LFSTag then return end
 
local Data={
  sSearchPat="(<\\/?(?:\\w+?|xsl:\\w+?-?\\w+?))[ >]|(\\/>)",
  sReplacePat=[=[
    if not _G.LFSTag.Rev and T[2] and T[2]=='/>' and M==_G.LFSTag.Cnt then _G.LFSTag.Num=0
    elseif _G.LFSTag.Rev and T[1] and T[1]:sub(2,2)~='/' and M==_G.LFSTag.Cnt then _G.LFSTag.Num=0
    elseif T[1] and T[1]==_G.LFSTag.Txt then _G.LFSTag.Num=_G.LFSTag.Num+1
    elseif T[1] and (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="" /><br />/>
--</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 SelectFound and Num==0 and 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,SelectData)
      --local report="Time: "..ttime.." mcs"
      --far.Message(report,"Report",nil,"l")
    end
  end
}

Всего записей: 3484 | Зарегистр. 16-06-2007 | Отправлено: 12:30 23-09-2019 | Исправлено: Alexyz21, 14:18 23-09-2019
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » FAR Manager (часть 5)
Maz (15-01-2020 17:38): FAR Manager (часть 6)


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru