Re: [code] [textadept] Tab click event

From: Gabriel Dubatti <gdubatti.att.gmail.com>
Date: Sat, 23 Jul 2016 23:58:48 -0300

El 23/07/16 a las 22:57, Mitchell escribió:
> Hi Gabriel,
>
> On Sat, 23 Jul 2016, Gabriel Dubatti wrote:
>
>> Hi Mitchell,
>>
>> I just wondered if you can add a "tab_clicked" event that allows
>> us, if
>> we want, to change the view 'before' the buffer is changed.
>> I find this more natural (more IDE like) than the actual behavior,
>> specially when split views show search results or compiler output.
>
> Do you mean in an event handler, call `ui.goto_view(...)` such that
> subsequent `events.BUFFER_BEFORE_SWITCH` and `events.BUFFER_AFTER_SWITCH`
> apply to the buffer in the view just switched to?

Yes. I use the tab click event to change the view (if needed) before the
buffer switching occurs.
For example, if the tab corresponding to a project file is clicked, the
project view is enforced.
This prevents that the project file is displayed in the wrong view
(which breaks the "IDE panels" effect).
The same holds for the search results view and for regular files (that
must not be shown in project or in the search views).

Here is my event code:

events.connect(events.TAB_CLICKED, function(ntab)

   --tab clicked (0...) check if a view change is needed
   if #_VIEWS > 1 then
     if _BUFFERS[ntab]._project_select ~= nil then
       --project buffer: force project view
       local projv= Proj.prefview[Proj.PRJV_PROJECT] --preferred view
for the project
       my_goto_view(projv)

     elseif _BUFFERS[ntab]._type == Proj.PRJT_SEARCH then
       --project search results
       if Proj.search_vn ~= nil then
         my_goto_view(Proj.search_vn)
       end

     else
       --regular file: check we are not in project/search results view
       Proj.goto_filesview() --change to files view if needed
     end
   end
end)

>> [snip]
>>
>> I add this line by hand every time I update textadept and compiled
>> it in
>> Ubuntu without any problem (couldn't compile it in Windows yet).
>> It would be great if you can add this to version 9 (hope is not to
> late).
>
> There is no rush. Textadept 9 is not due for another few months :)
>
> Cheers,
> Mitchell

Great!
BTW I'm using this code in my init.lua to be version 8 and 9 compatible:

TA_MAYOR_VER= tonumber(_RELEASE:match('^Textadept (.+)%..+$'))

function my_goto_view(view)
   if TA_MAYOR_VER < 9 then
     ui.goto_view(view)
   else
     ui.goto_view(_VIEWS[view])
   end
end

Best wishes,
Gabriel

-- 
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 Sat 23 Jul 2016 - 22:58:48 EDT

This archive was generated by hypermail 2.2.0 : Sun 24 Jul 2016 - 06:42:54 EDT