Skip to content

Commit 80747b2

Browse files
committed
Test1
1 parent ad11247 commit 80747b2

4 files changed

Lines changed: 709 additions & 0 deletions

File tree

BlockComment.fmlua

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
;;
2+
;; Закомментировать или раскомментировать выделенный блок
3+
;; (c) Max Rusov
4+
;;
5+
6+
macro Descr="Comment/uncomment selected block" Area="Editor" Keys="Ctrl-:Release"
7+
{{
8+
#include_macro_once "CommentFunc"
9+
_G.ToggleComment(nil, _G.FindComment( Editor.FileName ) )
10+
}}
11+
12+
13+
macro Descr="Uncomment selected block" Area="Editor" Keys="CtrlShift-:Release"
14+
{{
15+
#include_macro_once "CommentFunc"
16+
local Comment1 = _G.FindComment( Editor.FileName )
17+
if type(Comment1) == "string" then
18+
_G.UnCommentLineBlock(nil, Comment1 )
19+
end
20+
}}
21+
22+
23+
macro Descr="Comment/uncomment selected block (alternative)" Area="Editor" Keys="Ctrl-:Hold"
24+
{{
25+
#include_macro_once "CommentFunc"
26+
local Comment1, Comment2 = _G.FindComment( Editor.FileName )
27+
if Comment2 then
28+
_G.ToggleComment(Id, Comment2 )
29+
else
30+
mf.beep()
31+
end
32+
}}
33+
34+
35+
//-----------------------------------------------------------------------------
36+
// Глобальные функции
37+
38+
macro Name="CommentFunc"
39+
{{
40+
local Settings = {
41+
{"pas,pp,dpr", "//", {"(*", "*)"} },
42+
{"lua,fmlua", "--", {"--[[", "--]]"} },
43+
{"bat", "rem " },
44+
{"htm,html,xml", {"<!--", "-->"} }
45+
}
46+
47+
48+
function _G.FindComment(AName)
49+
local vExt = mf.fsplit(AName, 8):sub(2):lower()
50+
for i, vRow in ipairs(Settings) do
51+
for iExt in vRow[1]:gmatch("[^%s,]+") do
52+
if iExt == vExt then
53+
return vRow[2], vRow[3]
54+
end
55+
end
56+
end
57+
return "//", {"/*", "*/"}
58+
end
59+
60+
-- function _G.FindComment(AName)
61+
-- local vExt = mf.fsplit(AName, 8):sub(2)
62+
-- local vReg = regex.new("^(.*,)*\\s*"..vExt.."\\s*(,.*)*$")
63+
-- for i = 1, table.maxn(Settings) do
64+
-- local vRow = Settings[i]
65+
-- if vReg:find(vRow[1]) then
66+
-- return vRow[2], vRow[3]
67+
-- end
68+
-- end
69+
-- return "//", {"/*", "*/"}
70+
-- end
71+
72+
73+
function CorrectBlockWidth(ADelta)
74+
local vInfo = editor.GetSelection(Id)
75+
editor.Select(Id, vInfo.BlockType, vInfo.StartLine, vInfo.StartPos,
76+
vInfo.EndPos - vInfo.StartPos + ADelta,
77+
vInfo.EndLine - vInfo.StartLine + 1)
78+
end
79+
80+
------------------------------------------------------------------------------
81+
82+
function _G.CommentLineBlock(Id, AComment)
83+
local vInfo = editor.GetSelection(Id)
84+
if not vInfo then return end
85+
editor.UndoRedo(Id, "EUR_BEGIN")
86+
for i = vInfo.StartLine, vInfo.EndLine do
87+
local vRow = editor.GetString(Id, i)
88+
local vStr = vRow.StringText
89+
vStr = vStr:sub(0, vRow.SelStart) .. AComment .. vStr:sub(vRow.SelStart+1)
90+
editor.SetString(Id, i, vStr, vRow.StringEOL)
91+
end
92+
editor.UndoRedo(Id, "EUR_END")
93+
end
94+
95+
function _G.UnCommentLineBlock(Id, AComment)
96+
local vLen = AComment:len()
97+
local vInfo = editor.GetSelection(Id)
98+
if not vInfo then return end
99+
editor.UndoRedo(Id, "EUR_BEGIN")
100+
for i = vInfo.StartLine, vInfo.EndLine do
101+
local vRow = editor.GetString(Id, i)
102+
local vStr = vRow.StringText
103+
local vPos = vRow.SelStart
104+
if vStr:sub(vPos+1, vPos+vLen) == AComment then
105+
vStr = vStr:sub(0, vPos) .. vStr:sub(vPos+1+vLen)
106+
editor.SetString(Id, i, vStr, vRow.StringEOL)
107+
end
108+
end
109+
editor.UndoRedo(Id, "EUR_END")
110+
end
111+
112+
function _G.IsBlockLineComment(Id, AComment)
113+
local vLen = AComment:len()
114+
local vInfo = editor.GetSelection(Id)
115+
if not vInfo then return false end
116+
for i = vInfo.StartLine, vInfo.EndLine do
117+
local vRow = editor.GetString(Id, i)
118+
local vStr = vRow.StringText
119+
local vPos = vRow.SelStart
120+
if vStr:sub(vPos+1, vPos+vLen) ~= AComment then
121+
return false
122+
end
123+
end
124+
return true
125+
end
126+
127+
function _G.ToggleCommentLineBlock(Id, AComment)
128+
if not _G.IsBlockLineComment(Id, AComment) then
129+
_G.CommentLineBlock(Id, AComment)
130+
else
131+
_G.UnCommentLineBlock(Id, AComment)
132+
end
133+
end
134+
135+
------------------------------------------------------------------------------
136+
137+
function _G.CommentStreamBlock(Id, AComment)
138+
local vRow, vStr, vCol, vCor
139+
local vInfo = editor.GetSelection(Id)
140+
if not vInfo then return end
141+
editor.UndoRedo(Id, "EUR_BEGIN")
142+
143+
vRow = editor.GetString(Id, vInfo.EndLine)
144+
vStr = vRow.StringText
145+
vCor = vRow.SelEnd >= 0
146+
vCol = vRow.SelEnd >= 0 and vRow.SelEnd or vRow.StringLength
147+
vStr = vStr:sub(0, vCol) .. AComment[2] .. vStr:sub(vCol+1)
148+
editor.SetString(Id, vInfo.EndLine, vStr, vRow.StringEOL)
149+
150+
vRow = editor.GetString(Id, vInfo.StartLine)
151+
vStr = vRow.StringText
152+
vStr = vStr:sub(0, vRow.SelStart) .. AComment[1] .. vStr:sub(vRow.SelStart+1)
153+
editor.SetString(Id, vInfo.StartLine, vStr, vRow.StringEOL)
154+
155+
editor.UndoRedo(Id, "EUR_END")
156+
157+
if vCor then
158+
CorrectBlockWidth( AComment[2]:len() + (vInfo.StartLine == vInfo.EndLine and AComment[1]:len() or 0) )
159+
end
160+
end
161+
162+
163+
function _G.UnCommentStreamBlock(Id, AComment)
164+
local vRow, vStr, vCol, vCor
165+
local vInfo = editor.GetSelection(Id)
166+
if not vInfo then return end
167+
168+
editor.UndoRedo(Id, "EUR_BEGIN")
169+
170+
vRow = editor.GetString(Id, vInfo.EndLine)
171+
vCor = vRow.SelEnd >= 0
172+
vCol = vRow.SelEnd >= 0 and vRow.SelEnd or vRow.StringLength
173+
vStr = vRow.StringText
174+
vStr = vStr:sub(0, vCol - AComment[2]:len()) .. vStr:sub(vCol + 1)
175+
editor.SetString(Id, vInfo.EndLine, vStr, vRow.StringEOL)
176+
177+
vRow = editor.GetString(Id, vInfo.StartLine)
178+
vStr = vRow.StringText
179+
vStr = vStr:sub(0, vRow.SelStart) .. vStr:sub(vRow.SelStart + AComment[1]:len() + 1)
180+
editor.SetString(Id, vInfo.StartLine, vStr, vRow.StringEOL)
181+
182+
editor.UndoRedo(Id, "EUR_END")
183+
184+
if vCor then
185+
CorrectBlockWidth( -( AComment[2]:len() + (vInfo.StartLine == vInfo.EndLine and AComment[1]:len() or 0) ) )
186+
end
187+
188+
return true
189+
end
190+
191+
192+
function _G.IsBlockStreamComment(Id, AComment)
193+
local vInfo = editor.GetSelection(Id)
194+
if not vInfo then return false end
195+
196+
local vRow1 = editor.GetString(Id, vInfo.StartLine)
197+
local vRow2 = editor.GetString(Id, vInfo.EndLine)
198+
199+
if (vRow1.StringText:sub(vRow1.SelStart + 1, vRow1.SelStart + AComment[1]:len()) ~= AComment[1]) or
200+
(vRow2.StringText:sub(vRow2.SelEnd - AComment[2]:len() + 1, vRow2.SelEnd) ~= AComment[2]) then
201+
return false
202+
end
203+
204+
return true
205+
end
206+
207+
208+
function _G.ToggleCommentStreamBlock(Id, AComment)
209+
if not _G.IsBlockStreamComment(Id, AComment) then
210+
_G.CommentStreamBlock(Id, AComment)
211+
else
212+
_G.UnCommentStreamBlock(Id, AComment)
213+
end
214+
end
215+
216+
217+
function _G.ToggleComment(Id, AComment)
218+
if type(AComment) == "string" then
219+
_G.ToggleCommentLineBlock(Id, AComment)
220+
else
221+
_G.ToggleCommentStreamBlock(Id, AComment)
222+
end
223+
end
224+
225+
}}

ChangeCodepage.fmlua

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
;;
2+
;; Смена кодировки редактора путем перезагрузки файла.
3+
;; Позволяет переключаться между однобайтовыми и многобайтовыми кодировками
4+
;; (c) Max Rusov
5+
;;
6+
7+
macro
8+
Descr="Editor: Change Favorite Code Page"
9+
Key="ShiftF8"
10+
Area="Editor"
11+
{{
12+
if band(Editor.State, 0x800) ~= 0 then
13+
msgbox("Change Code Page", "Not supported in modal editor", 0x1);
14+
exit()
15+
end
16+
17+
Str = "&ANSI | 1251\n";
18+
Str = Str .. "&OEM | 866\n";
19+
Str = Str .. "UTF-&8 | 65001\n";
20+
Str = Str .. "&Unicode | 1200\n";
21+
--Прочие любимые кодировки
22+
23+
24+
-- Попробуем узнать текущую кодировку
25+
Keys("ShiftF2")
26+
Res = mf.trim(Dlg.GetValue(6,0));
27+
Keys("Esc")
28+
29+
Code = mf.substr(Res, 0, mf.index(Res, " ") - 1);
30+
31+
Pos = mf.index(Str, Code.."\n");
32+
if Pos >= 0 then
33+
Init = mf.substr(Str, 0, Pos + mf.len(Code));
34+
Pos = mf.rindex(Init, "\n");
35+
if Pos >= 0 then
36+
Init = mf.substr(Init, Pos + 1);
37+
end
38+
Init = mf.replace(Init, "&", "");
39+
-- MsgBox("", %Init);
40+
end
41+
42+
43+
Res = Menu.Show(Str, "Code Pages", 0x10, Init);
44+
if Res == "" then
45+
exit()
46+
end
47+
48+
Code = mf.trim(mf.substr(Res, mf.index(Res, "|") + 1))
49+
50+
if band(Editor.State, 0x8) ~= 0 then
51+
Res = msgbox("Change Code Page", "File has been modified. Save?", bor(0x1, 0x50000))
52+
if (Res ~= 1) and (Res ~= 2) then
53+
exit()
54+
end
55+
if Res==1 then
56+
Keys("F2")
57+
end
58+
end
59+
60+
FileName = Editor.FileName;
61+
62+
Keys("ShiftF4")
63+
print( FileName );
64+
Keys("Tab")
65+
Keys("CtrlDown")
66+
Menu.Select(Code, 1);
67+
Keys("Enter")
68+
69+
Keys("Enter")
70+
Keys("e") --Reload
71+
}}
72+
73+
74+
macro
75+
Descr="Editor: Change All Code Page"
76+
Key="AltShiftF8"
77+
Area="Editor"
78+
{{
79+
Keys("ShiftF8")
80+
}}
81+

0 commit comments

Comments
 (0)