summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-02-18 22:41:15 +0100
committerhut <hut@lavabit.com>2010-03-09 14:40:23 +0100
commitee4687c32e105a69d49c023e8f3a695b4b407ce2 (patch)
tree0b9cc7a28abd4244454be26d0678c3b739cb3d5c /ranger
parent6ae8cb053b78effdeda1d9ba5966086e02befc9a (diff)
downloadranger-ee4687c32e105a69d49c023e8f3a695b4b407ce2.tar.gz
keyparser: renamed KeyMap.add to KeyMap.map
Diffstat (limited to 'ranger')
-rw-r--r--ranger/api/keys.py28
-rw-r--r--ranger/container/keymap.py4
-rw-r--r--ranger/defaults/keys.py44
-rw-r--r--ranger/gui/ui.py10
4 files changed, 29 insertions, 57 deletions
diff --git a/ranger/api/keys.py b/ranger/api/keys.py
index a08c57b3..86911569 100644
--- a/ranger/api/keys.py
+++ b/ranger/api/keys.py
@@ -23,34 +23,6 @@ from ranger.gui.widgets import console_mode as cmode
 from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
 from ranger.container.keymap import KeyMap, Direction
 
-def make_abbreviations(command_list):
-	def bind(*args, **keywords):
-		if keywords:
-			command_list.show(*args, **keywords)
-		else:
-			lastarg = args[-1]
-			if hasattr(lastarg, '__call__'):
-				# do the binding
-				command_list.bind(lastarg, *args[:-1])
-			else:
-				# act as a decorator. eg:
-				#    @bind('a')
-				#    def do_stuff(arg):
-				#       arg.fm.ui.do_stuff()
-				#
-				# is equivalent to:
-				#    bind('a', lambda arg: arg.fm.ui.do_stuff())
-				return lambda fnc: command_list.bind(fnc, *args)
-
-	def show(*args, **keywords):
-		command_list.show(*args, **keywords)
-
-	def alias(*args):
-		command_list.alias(*args)
-
-	return bind, alias
-
-
 class Wrapper(object):
 	def __init__(self, firstattr):
 		self.__firstattr__ = firstattr
diff --git a/ranger/container/keymap.py b/ranger/container/keymap.py
index abc73d4d..dae8955a 100644
--- a/ranger/container/keymap.py
+++ b/ranger/container/keymap.py
@@ -75,7 +75,7 @@ class CommandArgs(object):
 
 class KeyMap(Tree):
 	"""Contains a tree with all the keybindings"""
-	def add(self, *args, **keywords):
+	def map(self, *args, **keywords):
 		if keywords:
 			return self.add_binding(*args, **keywords)
 		firstarg = args[-1]
@@ -84,7 +84,7 @@ class KeyMap(Tree):
 			return self.add_binding(*args[:-1], **keywords)
 		def decorator_function(func):
 			keywords = {FUNC:func}
-			self.add(*args, **keywords)
+			self.map(*args, **keywords)
 			return func
 		return decorator_function
 
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index e6d2b0cc..aaa332b9 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -336,7 +336,7 @@ def _basic_movement(command_list):
 
 def get_directions():
 	k = KeyMap()
-	map = k.add
+	map = k.map
 
 	map('<down>', dir=Direction(down=1))
 	map('<up>', dir=Direction(down=-1))
@@ -355,37 +355,37 @@ def move(arg):
 def get_ui_keys():
 	k = KeyMap()
 	k.merge(system_keys())
-	map = k.add
+	map = k.map
 
-	map('<dir>', func=move)
-	map('<C-c>', 'Q', func=fm.exit())
+	map('<dir>', move)
+	map('<C-c>', 'Q', fm.exit())
 
 	# --------------------------------------------------------- history
-	map('H', func=fm.history_go(-1))
-	map('L', func=fm.history_go(1))
+	map('H', fm.history_go(-1))
+	map('L', fm.history_go(1))
 
 	# ----------------------------------------------- tagging / marking
-	map('t', func=fm.tag_toggle())
-	map('T', func=fm.tag_remove())
+	map('t', fm.tag_toggle())
+	map('T', fm.tag_remove())
 
-	map(' ', func=fm.mark(toggle=True))
-	map('v', func=fm.mark(all=True, toggle=True))
-	map('V', func=fm.mark(all=True, val=False))
+	map(' ', fm.mark(toggle=True))
+	map('v', fm.mark(all=True, toggle=True))
+	map('V', fm.mark(all=True, val=False))
 
 	# ------------------------------------------ file system operations
-	map('yy', func=fm.copy())
-	map('dd', func=fm.cut())
-	map('pp', func=fm.paste())
-	map('po', func=fm.paste(overwrite=True))
-	map('pl', func=fm.paste_symlink())
-	map('p', hint='press //p// once again to confirm pasting' \
-			', func=or //l// to create symlinks')
+	map('yy', fm.copy())
+	map('dd', fm.cut())
+	map('pp', fm.paste())
+	map('po', fm.paste(overwrite=True))
+	map('pl', fm.paste_symlink())
+	map('p<psv>', fm.notify('press //p// once again to confirm pasting' \
+			', or //l// to create symlinks'))
 
 	# ---------------------------------------------------- run programs
-	map('s', func=fm.execute_command(os.environ['SHELL']))
-	map('E', func=fm.edit_file())
-	map('term', func=fm.execute_command('x-terminal-emulator', flags='d'))
-	map('du', func=fm.execute_command('du --max-depth=1 -h | less'))
+	map('s', fm.execute_command(os.environ['SHELL']))
+	map('E', fm.edit_file())
+	map('term', fm.execute_command('x-terminal-emulator', flags='d'))
+	map('du', fm.execute_command('du --max-depth=1 -h | less'))
 
 	return k
 
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 79552bf2..eb7c26fa 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -134,13 +134,12 @@ class UI(DisplayableContainer):
 			return
 
 		kbuf = self.env.keybuffer
+		cmd = kbuf.command
 
-		if kbuf.done:
-			cmd = kbuf.command
-		elif kbuf.failure:
+		if kbuf.failure:
 			kbuf.clear()
 			return
-		else:
+		elif not cmd:
 			return
 
 		self.env.cmd = cmd
@@ -153,7 +152,8 @@ class UI(DisplayableContainer):
 				cmd.function(CommandArgs.from_widget(self))
 			except Exception as error:
 				self.fm.notify(error)
-			kbuf.clear()
+			if kbuf.done:
+				kbuf.clear()
 
 	def get_next_key(self):
 		"""Waits for key input and returns the pressed key"""