Filters

Here you can discuss about your favorite plug-in.
pepak
Posts: 504
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 12 times
Been thanked: 41 times

Filters

Post by pepak »

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.
pepak
Posts: 504
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 12 times
Been thanked: 41 times

Filters

Post by pepak »

Version 0.06
  • Added a support for unconfigured filters. This solves a common situation where the plugin had already been configured with some filters and then a new version with additional filters is introduced: In prior versions, the new filters would not become available until the user configured them. Now these filters are added automatically to the list of available filters. They should still be configured to allow their automatic execution through the "Autoselect" filter, but they will work manually without any configuration.
  • Updated the plugin to a newer version of Dialog API. Among other things, this allows the plugin to properly react to resizing of the FAR's window.
  • Minor fixes for compatibility with Delphi 10.1 and newer.
  • BASE64 decoded was only available in debug builds (copy&paste error).
  • Added a condition that the plugin is available to the Autoselect macro.
User avatar
HaRT
Moderator
Posts: 9561
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 111 times
Been thanked: 232 times

Filters

Post by HaRT »

citRiks wrote: Wed 14 Oct, 2020 11:17 applying on editor selection is not working with any "external filter"
Works for me, at least with the sort command.
Фар есть инструмент, а не нянька. © 2009 DrKnS
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

pepak wrote: Wed 14 Oct, 2020 18:27 Seems to work fine for me as well. Note though that Filters is only applicable to regular blocks, not vertical blocks.
Yes, it is a trivial part, and it's Ok to me.
pepak wrote: Wed 14 Oct, 2020 18:27 Could you maybe be a bit more specific. I actually think that I designed the plugin precisely with the idea of supporting blocks.
Great, so i go to TPlugin.ReplaceSelectedContent (am i on the right way to see the implementation?)
image.png
from there i understand that the Content cimes from TPlugin.GetEditorInfo(EditorID: TIntPtr; out EditorInfo: TEditorInfo; out FileName, Content: string)
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
pepak
Posts: 504
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 12 times
Been thanked: 41 times

Filters

Post by pepak »

The "TopLine" variable here deals with the positioning of the cursor, not with the actual replacement. The replacement was already been done in TFarEditor.DeleteSelection and TFarEditor.InsertText.
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

.. shortly, this part makes problems in certain circumstances
The circumstances are, any empty line in selection, see my note in comments

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;
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

pepak, i am sorry i left you in the middle without notice,
because i wanted to proof it in the detailed way possible,
so i wrote the proof in Lua-code, which is one-to-one translation from your Pascal code
The problem with empty lines in selection reproduced here the same exact way:

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





--]]
You may try it with all kind of selections,
with empty lines or without, and see the results immediatly.
I tested it making selections at the block comment in the bottom of the Lua- code
Last edited by citRiks on Mon 19 Oct, 2020 14:38, edited 4 times in total.
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

also, this line DelphiFar.pas:3689 of TFarEditor.GetSelection(..) function also does not looks justified:
while Row < Info.TotalLines do begin
why "TotalLines"? arent we want selection lines only?
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

HaRT, just try your sort operstion with empty lines on the top of selection, you will see :)
also, i may reporduce the sort, and the problem this way:

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 ]                                                                  ║
 ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
It reminded me, using this UTF8+byte order mask will insert to editor those "BOMs",
in the middle of text, which is of course is not that should be there
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
User avatar
HaRT
Moderator
Posts: 9561
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 111 times
Been thanked: 232 times

Filters

Post by HaRT »

citRiks wrote: Wed 14 Oct, 2020 21:24 try your sort operstion with empty lines on the top of selection, you will see
Right, I'm getting an instead of filters list.

@pepak If there are empty lines inside selection, I get various text corruption or lost lines. This is data loss that makes using filters (both built-in and external) simply dangerous.
Фар есть инструмент, а не нянька. © 2009 DrKnS
pepak
Posts: 504
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 12 times
Been thanked: 41 times

Filters

Post by pepak »

Noted. Will check it out for myself and if I can confirm the error, fix it.
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

pepak wrote: Thu 15 Oct, 2020 05:28 Noted. Will check it out for myself and if I can confirm the error, fix it.
Yeah, please check it out. The plugin is useful, worth to be fixed.
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

pepak wrote: Wed 14 Oct, 2020 18:31 Anyway, I just made a quick test with Delphi 10.4 compile and the plugin compiles without any issues and whatever I tried to do with it, it worked fine. Including the "external filter on a selection".
So, u found no bugs with applying on editor's selection?
From your point of view, no fix required, either .. ?

i am sorry, i just have not recognised the right timing of the answers.
My partial excuse comes from splitting the topic into the two (abt Delphi and abt the plugin).
Thanks to HaRT for pointing that out.
Last edited by citRiks on Mon 19 Oct, 2020 01:40, edited 1 time in total.
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
User avatar
HaRT
Moderator
Posts: 9561
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 111 times
Been thanked: 232 times

Filters

Post by HaRT »

citRiks wrote: Sun 18 Oct, 2020 16:42 So, u found no bugs with applying on editor's selection?
From your point of view, no fix required, either .. ?
The has been given already; nagging is unlikely to speed things up. Please be polite and positive.
Фар есть инструмент, а не нянька. © 2009 DrKnS
pepak
Posts: 504
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 12 times
Been thanked: 41 times

Filters

Post by pepak »

I am not yet ready to release a new version, but you may want to give this preliminary one a try: The selection problem (empty lines break the selection) is fixed. I didn't encounter any unexpected behavior with the UTF8 handling - I am, of course, not removing BOMs from the middle of the text because that's the responsibility of the producer, not my plugin; I have no way of knowing whether that byte sequence is a BOM or an actual binary data that needs to be returned.

Please check this version out and if it works for you, let me know. If you know of any other errors, please let me know as well, so that I can make a version with all known errors fixed. If I don't get any new bug reports, I expect to create version 0.07 next weekend.
Attachments
filters-0.06-fix1.7z
(547.61 KiB) Downloaded 6 times
citRiks
Posts: 895
Joined: Fri 25 Oct, 2019 18:18
Has thanked: 269 times
Been thanked: 46 times

Filters

Post by citRiks »

pepak wrote: Sun 25 Oct, 2020 11:36 have no way of knowing whether that byte sequence is a BOM or an actual binary data that needs to be returned.
To may way of thinking,
if we work on editor selection, it can be only text data, or supposed to be text data, not binary.
I would say what those first two bytes of text have very easy detectable signature.
It is always first two bytes, and always only very certain bytes.
Detecting of UTF8 strings is necessary for any text handling nowadays.
Here is the Lua-code for it, can be easily translated to Pascal.
it is simple and bug-free (er.. well, should be),
handling any kind of unicode (not only UTF8):

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
Last edited by citRiks on Sun 25 Oct, 2020 20:59, edited 2 times in total.
А кто не поверит в наше миролюбие, / Тот кровью умоется. / И будет такая борьба за мир, / Что камня на камне не останется.
Post Reply

Return to “General Plug-In Discussions”