Re: [code] Find panel, $ ^ Regexp

From: Gabriel Dubatti <gdubatti.att.gmail.com>
Date: Fri, 16 Dec 2016 12:16:22 -0300

It may be a bit late for your needs, but this is what I use to type at
the beginning and/or end of a range of lines:

-- Alt+9 = MULTILINE TYPER
-- [BEFORE]....[AFTER]
-- [EMPTY]
keys.a9 = function()
   local n1=1
   local n2=buffer.line_count
   if (buffer.selections > 1) or (buffer.selection_n_start[0] ~=
buffer.selection_n_end[0]) then
     --if something is selected use selected line range
     n1=buffer:line_from_position(buffer.selection_n_start[0])+1
     n2=buffer:line_from_position(buffer.selection_n_end[0])+1
   end

   local button, inputs = ui.dialogs.inputbox{
     title = 'Quick-type',
     informative_text = {'Multiline Typer', 'Before begin:', 'After
end:', 'Empty lines:', 'From line:', 'To line:'},
     text = {"","","",n1,n2}
   }
   if button == 1 then
     n1=tonumber(inputs[4])-1
     n2=tonumber(inputs[5])-1
     if n2 >= n1 then
       local totne= 0
       local totem= 0
       buffer:begin_undo_action()
       if n1 < 0 then n1=0 end
       if n2 > buffer.line_count-1 then n2=buffer.line_count-1 end
       for i= n1, n2 do
         buffer:goto_line(i)
         if buffer:get_line(i):match('^[\r\n]*$') then
           buffer.add_text(buffer, inputs[3])
           totem=totem+1
         else
           buffer.add_text(buffer, inputs[1])
           buffer.goto_pos(buffer, buffer.line_end_position[i])
           buffer.add_text(buffer, inputs[2])
           totne=totne+1
         end
       end
       buffer:end_undo_action()
       ui.statusbar_text= "Modified lines: "..totem.." empty,
"..totne.." non empty"
     end
   end
end

Best regards,

Gabriel

El 12/12/2016 a las 05:16, Olivier Guibe escribió:
>
> Dear all
>
> Many thanks for all the answers.
> Such a regexp find/replace is very unusual for me (I was trying
> some Advent code in Python on free time :) ).
>
> Now the situation is clear.
>
> Regards
> O.G.
>
>
> Le Dimanche 11 Décembre 2016 22:51 CET, Mitchell <m.att.foicica.com> a écrit:
>
>> Hi David,
>>
>> On Sun, 11 Dec 2016, David Reimer wrote:
>>
>>> I think there is a solution to Olivier's regex scenario.
>>>
>>> To add characters at the end of a "line" (= paragraph?) in TextAdept 9:
>>>
>>> 1. Make sure "Regex" is checked;
>>> 2. In "Find" put `(.)$`
>>> 3. In "Replace" put `\1newstring`
>>> 4. Click "Replace all".
>>>
>>> Explanation uses Markdown backticks to demarcate raw text.
>>>
>>> In "Find": the `(.)$` finds any character as last character at EOL.
>>> The parentheses save that character for back-reference.
>>>
>>> In "Replace": the `\1` recalls the character saved in parentheses from
>>> the find and incudes it; `newstring` is the text you wish to add at
>>> the EOL.
>>>
>>> Works very nicely! Of course, it does *not* add the `newstring` in
>>> "empty lines/paragraphs". I'm still trying to work out a way to find
>>> and manipulate the `^$` -- if there is a workaround to this "TRE
>>> limitation". (Do I understand its doc rightly, that `REG_NEWLINE` can
>>> be compiled to overcome this?
>>> <http://laurikari.net/tre/documentation/regcomp/> I might be
>>> mistaken.)
>> I just wanted to jump in and say that Textadept compiles all TRE regexes
>> with `REG_NEWLINE`, so nothing more can be done in this regard.
>>
>> Cheers,
>> Mitchell
>> --
>> You are subscribed to code.att.foicica.com.
>> To change subscription settings, send an e-mail to code+help.att.foicica.com.
>> To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
>>
>
>
>
>
>
>

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 16 Dec 2016 - 10:16:22 EST

This archive was generated by hypermail 2.2.0 : Sat 17 Dec 2016 - 06:54:09 EST