aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/menu.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2011-01-21 00:41:36 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2011-01-21 00:41:36 -0500
commit78bcda2db6b0b8669a6fbcf63b1143602f544416 (patch)
treedf837e91e357573ca84be0b20155189252337cec /modules/textadept/menu.lua
parent2247eeb38c71da492cb96711e133b353e7c3129d (diff)
downloadtextadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.tar.gz
textadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.zip
Code cleanup.
Diffstat (limited to 'modules/textadept/menu.lua')
-rw-r--r--modules/textadept/menu.lua52
1 files changed, 25 insertions, 27 deletions
diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua
index e3ef2576..a914cb83 100644
--- a/modules/textadept/menu.lua
+++ b/modules/textadept/menu.lua
@@ -366,32 +366,30 @@ set_menubar(menubar)
set_contextmenu(context_menu)
-- Most of this handling code comes from keys.lua.
-events.connect('menu_clicked',
- function(menu_id)
- local active_table
- if menu_id > 1000 then
- active_table = context_actions[menu_id - 1000]
- else
- active_table = menu_actions[menu_id]
- end
- local f, args
- if active_table and #active_table > 0 then
- local func = active_table[1]
- if type(func) == 'function' then
- f, args = func, { unpack(active_table, 2) }
- elseif type(func) == 'string' then
- local object = active_table[2]
- if object == 'buffer' then
- f, args = buffer[func], { buffer, unpack(active_table, 3) }
- elseif object == 'view' then
- f, args = view[func], { view, unpack(active_table, 3) }
- end
- end
- if f and args then
- local ret, retval = pcall(f, unpack(args))
- if not ret then error(retval) end
- else
- error(L('Unknown command:')..' '..tostring(func))
+events.connect('menu_clicked', function(menu_id)
+ local active_table
+ if menu_id > 1000 then
+ active_table = context_actions[menu_id - 1000]
+ else
+ active_table = menu_actions[menu_id]
+ end
+ local f, args
+ if active_table and #active_table > 0 then
+ local func = active_table[1]
+ if type(func) == 'function' then
+ f, args = func, { unpack(active_table, 2) }
+ elseif type(func) == 'string' then
+ local object = active_table[2]
+ if object == 'buffer' or object == 'view' then
+ local v = _G[object]
+ f, args = v[func], { v, unpack(active_table, 3) }
end
end
- end)
+ if f and args then
+ local ret, retval = pcall(f, unpack(args))
+ if not ret then error(retval) end
+ else
+ error(L('Unknown command:')..' '..tostring(func))
+ end
+ end
+end)