[code] [textadept] Menu modification delay 2

From: Gabriel Dubatti <gdubatti.att.gmail.com>
Date: Thu, 10 Nov 2016 19:21:21 -0300

Hi Mitchell,

Splitting the code in this way:

   local m1=_L['_File']
   local m2=_L['_New']

....

   local m15=_L['Quickly Open _Current Directory']
   local m16=_L['Quickly Open Current _Project']

-------

   local menu= textadept.menu.menubar[m1]
   menu[m2][2]= nf
   menu[m3][2]= of
   menu[m4][2]= orf
   menu[m5][2]= cb
   menu[m6][2]= cab
....

I can confirm that all the delay is in menu[] modification.

I hope that helps.

Best wishes,

Gabriel

----------------------
Hi Mitchell,

     I noticed that my TA startup slows down after every call to reset().
     I managed to track the issue to the menu modification code in my
init.lua using a simple log:

   log_event("change file menu")

   local menu= textadept.menu.menubar[_L['_File']]
   menu[_L['_New']][2]= Proj.new_file
   menu[_L['_Open']][2]= Proj.open_file
   menu[_L['Open _Recent...']][2]= Proj.open_recent_file
   menu[_L['_Close']][2]= Proj.close_buffer
   menu[_L['Close All']][2]= Proj.close_all_buffers

   log_event("change tab context menu")

   menu= textadept.menu.tab_context_menu
   insert_menu(menu,2,{'Close Others', Proj.close_others})
   insert_menu(menu,3,{"Mark as don't close", Proj.keep_thisbuffer})
   insert_menu(menu,4,{_L['Close All'], Proj.onlykeep_projopen})

   log_event("change buffer menu")

   menu= textadept.menu.menubar[_L['_Buffer']]
   menu[_L['_Next Buffer']][2]= Proj.next_buffer
   menu[_L['_Previous Buffer']][2]= Proj.prev_buffer
   menu[_L['_Switch to Buffer...']][2]= Proj.switch_buffer

   log_event("change quick open menu")

   menu= textadept.menu.menubar[_L['_Tools']][_L['Quick _Open']]
   menu[_L['Quickly Open _User Home']][2]= Proj.qopen_user
   menu[_L['Quickly Open _Textadept Home']][2]= Proj.qopen_home
   menu[_L['Quickly Open _Current Directory']][2]= Proj.qopen_curdir
   menu[_L['Quickly Open Current _Project']][2]= Proj.snapopen

   log_event("change menu end")

---------------log code-----
local log_ev={}
function log_event(event)
   local line= os.date('%c')..": "..event.."\n"
   log_ev[#log_ev+1]= line
end
keys.cf5 = function()
   Proj.go_file(nil) --new file
   log_event("DUMP\n")
   for i=1,#log_ev do
     buffer:append_text(log_ev[i])
   end
end
log_event("START")
events.connect(events.RESET_BEFORE, log_event("RESET_BEFORE"))
events.connect(events.RESET_AFTER, log_event("RESET_AFTER"))
-----------------

I got a 1 second delay after the first reset:
10/11/2016 12:50:41: START
10/11/2016 12:50:41: RESET_BEFORE
10/11/2016 12:50:41: RESET_AFTER
10/11/2016 12:50:42: INITIALIZED
10/11/2016 12:50:42: change file menu
10/11/2016 12:50:42: change tab context menu
10/11/2016 12:50:42: change buffer menu
10/11/2016 12:50:42: change quick open menu
10/11/2016 12:50:42: change menu end

and 4 seconds after several calls to reset():
10/11/2016 12:49:27: START
10/11/2016 12:49:27: RESET_BEFORE
10/11/2016 12:49:27: RESET_AFTER
10/11/2016 12:49:28: INITIALIZED
10/11/2016 12:49:28: change file menu
10/11/2016 12:49:29: change tab context menu
10/11/2016 12:49:29: change buffer menu
10/11/2016 12:49:30: change quick open menu
10/11/2016 12:49:31: change menu end

As you can see, there is an extra 3 seconds delay.
I also tried using local variables to see if the problem was in the Proj
object:

log_event("change file menu 1")
   local nf=Proj.new_file
   local of=Proj.open_file
   local orf=Proj.open_recent_file
   local cb=Proj.close_buffer
   local cab=Proj.close_all_buffers
   local co=Proj.close_others
   local kt=Proj.keep_thisbuffer
   local kop=Proj.onlykeep_projopen
   local nb=Proj.next_buffer
   local pb=Proj.prev_buffer
   local sb=Proj.switch_buffer
   local qou=Proj.qopen_user
   local qoh=Proj.qopen_home
   local qoc=Proj.qopen_curdir
   local sno=Proj.snapopen
log_event then log_event("change file menu 2")

and got:
10/11/2016 13:26:10: change file menu 1
10/11/2016 13:26:10: change file menu 2
10/11/2016 13:26:11: change tab context menu
10/11/2016 13:26:11: change buffer menu
10/11/2016 13:26:12: change quick open menu
10/11/2016 13:26:13: change menu end

Seems like something in menu[] or L[] keeps growing with each reset...

Not a big deal but I thought it might be interesting to you.

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 Thu 10 Nov 2016 - 17:21:21 EST

This archive was generated by hypermail 2.2.0 : Fri 11 Nov 2016 - 06:44:57 EST