Victor_VG
Tracker Mod | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору ------------------------------------------------------------------------------- -- Удаление конечных пробелов и табов и конечных пустых строк. © SimSU ------------------------------------------------------------------------------- -- Требуется модуль - %FARPROFILE%\Macros\modules\SimSU\Utils.lua 20130101 ------------------------------------------------------------------------------- -- Умеет: -- удалять пробелы из окончаний строк -- удалять все пустые строки -- работать только в выделенном -- удалять пустые строки из конца файла ---- Насктройка local EndLn=true -- Установить "Пустые строки из конца файла" по умолчанию. ---- Macro { area="Editor"; key="AltDel"; description="Удаление конечных пробелов и табов и конечных пустых строк. © SimSU"; action = function() local U=require("SimSU.Utils") -- Требуется модуль - %FARPROFILE%\Macros\modules\SimSU\Utils.lua. local RorE= win.GetEnv("farlang")=="Russian" local Items={} Items[1]= RorE and "\2 Пробелы из окончаний строк\n" or "\2 Blanks from terminations of lines\n" Items[2]= RorE and "Все пустые строки\n" or "All empty lines\n" Items[3]= RorE and "Только в выделенном\n" or "Only in selected\n" Items[3]= Object.Selected and ("\2 "..Items[3]) or Items[3] Items[4]="\1\n" Items[5]= RorE and "Пустые строки из конца файла" or "Empty lines from file end" Items[5]= EndLn and ("\2 "..Items[5]) or Items[5] Items=Menu.Show(table.concat(Items),RorE and "Удаление пустот © SimSU\nInsert - пометить нужные действия" or "Removal of emptiness © SimSU\nInsert - mark necessary actions",0x8+0x10,2) if Items~=0 then local space=Items:find("1",1,true) local allln=Items:find("2",1,true) local insel=Items:find("3",1,true) local endln=Items:find("5",1,true) local i,count = 0,0 if insel then i=Editor.Sel(0,0) count=Editor.Sel(0,2)-i if Editor.Sel(0,3)>1 then count=count+1 end if count==0 then i=Editor.Pos(0,1) count=1 end else count=Editor.Lines i=1 end Editor.Undo(0) local E=U.GetEditState() -- Запомним состояние редактора. if space or allln then for j=1,count do local str=Editor.GetStr(i) local trm=mf.trim(str,2) -- Фаровский trim в 5 раз быстрее всего, чего я смог добиться от lua, так как это частный специализированный случай. if allln and trm=="" then Editor.DelLine(i) if i<E.Cur.Y then E.Cur.Y=E.Cur.Y-1 end if i<E.Sel.Beg.Y then E.Sel.Beg.Y=E.Sel.Beg.Y-1 end if i<E.Sel.End.Y then E.Sel.End.Y=E.Sel.End.Y-1 end i=i-1 elseif space and str~=trm then Editor.SetStr(trm,i) end i=i+1 end end if endln then if mf.trim(Editor.GetStr(Editor.Lines))=="" then while mf.trim(Editor.GetStr(Editor.Lines-1))=="" do if Editor.Pos(0,1)==Editor.Lines then Editor.Pos(1,1,Editor.Lines-1) end -- А то Editor.DelLine вешает LuaMacro и вместе с ним FAR, если курсор оказывается за концом файла. Editor.DelLine(Editor.Lines-1) end end end U.SetEditState(E)-- Восстановим состояние редактора. Editor.Undo(1) end end; } |