Filters
Posted: Wed 25 Dec, 2019 07:45
Latest post of the previous page:
It's not in my code. I suppose I could modify it anyway, but I have no idea how difficult it would be.Latest post of the previous page:
It's not in my code. I suppose I could modify it anyway, but I have no idea how difficult it would be.Yes, it is a trivial part, and it's Ok to me.
Great, so i go to
TPlugin.ReplaceSelectedContent
(am i on the right way to see the implementation?)
from there i understand that the Content
cimes from TPlugin.GetEditorInfo(EditorID: TIntPtr; out EditorInfo: TEditorInfo; out FileName, Content: string)
Code: Select all
class function TFarEditor.GetSelection(EditorID: TIntPtr; out Str: string; out SelectionType: TIntPtr): boolean;
var
Info: TEditorInfo;
Row: TIntPtr;
Line, EOL: string;
SelStart, SelLength: TIntPtr;
EOLInSelection: boolean;
begin
Result := False;
if not GetInfo(EditorID, Info) then
Exit;
if Info.BlockType = BTYPE_NONE then
Exit;
Str := '';
SelectionType := Info.BlockType;
Row := Info.BlockStartLine;
while Row < Info.TotalLines do begin
if not GetString(EditorID, Row, Line, EOL, SelStart, SelLength, EOLInSelection) then
Break;
// this gives false break, when the line is in slection, but with zero length,
// so, the selection length also becomes zero-size,
// and it does not goes further, as it should:
if SelStart <= 0 then
Break;
if SelLength <= 0 then
Break;
Line := Copy(Line, SelStart, SelLength);
if EOLInSelection or (Info.BlockType = BTYPE_COLUMN) then
Str := Str + Line + EOL
else
Str := Str + Line;
Result := True;
Inc(Row);
end;
end;
Code: Select all
Macro { description = "WRONG SELECTION HANDLING CODE EXAMPLE",
area = "Editor"; key = "AltS";
priority = 100; sortpriority = 100;
action = function()
-- ###
local edinf = editor.GetInfo()
local edstr = editor.GetString (edinf.EditorID, edinf.BlockStartLine)
local edpos = editor.SetPosition (edinf.EditorID, edinf.BlockStartLine, edstr.SelStart - 1)
local edsel = editor.GetSelection (edinf.EditorID)
local sz_sel_txt = ""
local ii_row = edinf.BlockStartLine
while ii_row < edinf.TotalLines
do
local ii_str = editor.GetString(edinf.EditorID, ii_r)
if ii_str.SelStart == -1
then ii_str.SelStart = 0
ii_str.SelLength= 0
ii_str.has_EOL = false
else if ii_str.SelEnd == -1
then ii_str.SelLength= string.len(ii_str.StringText)
ii_str.has_EOL = true
else ii_str.SelLength= ii_str.SelEnd - ii_str.SelStart
ii_str.has_EOL = false
end
end
if ii_str.SelStart <= 0 then break end
if ii_str.SelLength <= 0 then break end
sz_sel_txt = sz_sel_txt..string.sub(ii_str.StringText, ii_str.SelStart, ii_str.SelLength)..(ii_str.has_EOL and "\n" or "")
ii_row = ii_row + 1
end
far.Show(sz_sel_txt)
-- @@@
end;
}
--[[
111111111111111
dddddddd
3333333333
aaaaaaaa
fdffffffffff
324333333333333333333
--]]
TFarEditor.GetSelection(..)
function also does not looks justified: while Row < Info.TotalLines do begin
Code: Select all
╔═════════════════════════════════════════════════════════════════ External Filter ══════════════════════════════════════════════════════════════════╗
║ Description: ║
║ Sort ↓║
║ File mask: (use comma as a separator) ║
║ * ↓║
║ [ ] Edit before use ║
║ Command template ║
║ sort %i ↓║
║ ║
║ Pass input as: Temp file ↓ (use %i in the te ║
║ Input encoding: UTF8 ↓ [x] Byte Order Mark ║
║ Get output from: STDOUT ↓ ║
║ Output encoding: UTF8 ↓ ║
║ ║
║ { OK } [ Cancel ] ║
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
Right, I'm getting an instead of filters list.
So, u found no bugs with applying on editor's selection?
To may way of thinking,
Code: Select all
local fnc_det_bom_str = function(str_head)
local boms = {
{name = "ASCI", code = ""},
{name = "32LE", code = '\255\254\0\0'}, -- utf32le
{name = "32BE", code = '\0\0\254\255'}, -- utf32be
{name = "16LE", code = '\255\254'}, -- utf16le
{name = "16BE", code = '\254\255'}, -- utf16be
{name = "UTF8", code = '\239\187\191'} -- utf8
}
local str_bom
local res = 1
for ii = #boms, 3, -1
do str_bom = string.sub(str_head, 1, #(boms[ii].code))
if str_bom == boms[ii].code
then if ii == 4 and str_bom == boms[2].code then ii = 2 end
res = ii
break
end
end
return boms[res].name, boms[res].code
end
local fnc_read_header_text = function(file_name)
local fp = io.open(filename)
if not fp then return end
local s = fp:read(512)
fp:close()
return s:gsub("%s+", " "):match("[%w_].*")
end
local fnc_det_bom_file = function(file_name)
local str_head, bom_name, bom_code
local fHnd = io.open(file_name, "rb")
if fHnd
then str_head = fHnd:read(4) or ''
fHnd:close()
bom_name, bom_code = Xer0X.fnc_det_bom_str(str_head)
end
return bom_name, bom_code
end