De-hardcode room priv bindings, take first
authorMyhailo Danylenko <isbear@ukrpost.net>
Thu, 16 Jul 2009 14:56:26 +0300
changeset 73 b3ebfb8eb798
parent 72 d049c92d0809
child 74 9d1d5939ac9f
De-hardcode room priv bindings, take first
CMakeLists.txt
examples/room_priv.lua
--- a/CMakeLists.txt	Thu May 21 00:13:26 2009 +0300
+++ b/CMakeLists.txt	Thu Jul 16 14:56:26 2009 +0300
@@ -44,7 +44,7 @@
 set(CPACK_SOURCE_GENERATOR TBZ2)
 set(CPACK_GENERATOR DEB)
 # FIXME: Detect architecture. How? Though, it anyway produces nonconformant deb names...
-set(CPACK_SYSTEM_NAME i386)
+#set(CPACK_SYSTEM_NAME i386)
 # XXX: Set package name directly to get rid of -Sources?
 set(CPACK_SOURCE_IGNORE_FILES "/\\\\..*;\\\\.swp;~$;/build/;\\\\.tar\\\\.;\\\\.deb;\\\\.so")
 include(CPack)
--- a/examples/room_priv.lua	Thu May 21 00:13:26 2009 +0300
+++ b/examples/room_priv.lua	Thu Jul 16 14:56:26 2009 +0300
@@ -1,6 +1,7 @@
 
 -- ROOM NICK COMPLETION
 
+-- global
 room_cid = main.command ( 'priv',
 	function ( args )
 		main.run ( 'room privmsg ' .. args )
@@ -8,9 +9,10 @@
 
 commands_help['priv'] = "nick message\n\nSends private message to room participant. Nick completion available! ;)"
 
-registered_nicks = {}
+local registered_nicks = {}
 
-function register_nicks ()
+-- global, used in binding
+function room_priv_register_nicks ()
 	for k, nick in pairs ( registered_nicks ) do
 		main.del_completion ( room_cid, nick )
 	end
@@ -29,15 +31,21 @@
 	end
 end
 
-room_priv_pgup_action = main.binding ( '338' )
-room_priv_pgdn_action = main.binding ( '339' )
-main.binding ( '338', ('lua main.run ( %q ); register_nicks ()'):format ( room_priv_pgup_action ) )
-main.binding ( '339', ('lua main.run ( %q ); register_nicks ()'):format ( room_priv_pgdn_action ) )
+-- XXX
+local room_priv_pattern = "roster%s+(up|down)"
+local room_priv_restore = {}
+for key, binding in pairs ( main.binding () ) do
+	if binding:match ( room_priv_pattern ) then
+		room_priv_restore[key] = binding
+		main.binding ( key, ('lua main.run ( %q ); room_priv_register_nicks ()'):format ( binding )
+	end
+end
 
 hooks_d['hook-quit'].room_priv =
 	function ( args )
-		main.binding ( '338', room_priv_pgup_action )
-		main.binding ( '339', room_priv_pgdn_action )
+		for key, binding in pairs ( room_priv_restore ) do
+			main.binding ( key, binding )
+		end
 	end
 
 -- vim: se ts=4: --