summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-09-29 00:05:06 +0200
committerhut <hut@lavabit.com>2011-09-29 00:14:35 +0200
commitaffbad6ce1e2c8783b0002b617fe0a229546a069 (patch)
tree38bb46d7b90a04cdc81891bdfd8d51730727c1f1
parentbdc872b0178be74059f49d8878b5c05f2d7ed8ce (diff)
downloadranger-affbad6ce1e2c8783b0002b617fe0a229546a069.tar.gz
core.main: added --list-unused-keys option
-rw-r--r--doc/ranger.17
-rw-r--r--doc/ranger.pod6
-rw-r--r--ranger/container/keymap.py4
-rw-r--r--ranger/core/helper.py2
-rw-r--r--ranger/core/main.py14
5 files changed, 30 insertions, 3 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 897a2969..2192047c 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -124,7 +124,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RANGER 1"
-.TH RANGER 1 "ranger-1.4.3" "09/28/2011" "ranger manual"
+.TH RANGER 1 "ranger-1.4.3" "09/29/2011" "ranger manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -174,6 +174,11 @@ write the last visited directory into \fItargetfile\fR.
 Create copies of the default configuration files in your local configuration
 directory.  Existing ones will not be overwritten.  Possible values: \fIall\fR,
 \&\fIapps\fR, \fIcommands\fR, \fIkeys\fR, \fIoptions\fR, \fIscope\fR.
+.IP "\fB\-\-list\-unused\-keys\fR" 14
+.IX Item "--list-unused-keys"
+List common keys which are not bound to any action in the \*(L"browser\*(R" context.
+This list is not complete, you can bind any key that is supported by curses:
+use the key code returned by \f(CW\*(C`getch()\*(C'\fR.
 .IP "\fB\-\-fail\-unless\-c\fRd" 14
 .IX Item "--fail-unless-cd"
 Return the exit code 1 if ranger is used to run a file instead of used for file
diff --git a/doc/ranger.pod b/doc/ranger.pod
index e5cd8987..be1d14fd 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -65,6 +65,12 @@ Create copies of the default configuration files in your local configuration
 directory.  Existing ones will not be overwritten.  Possible values: I<all>,
 I<apps>, I<commands>, I<keys>, I<options>, I<scope>.
 
+=item B<--list-unused-keys>
+
+List common keys which are not bound to any action in the "browser" context.
+This list is not complete, you can bind any key that is supported by curses:
+use the key code returned by C<getch()>.
+
 =item B<--fail-unless-c>d
 
 Return the exit code 1 if ranger is used to run a file instead of used for file
diff --git a/ranger/container/keymap.py b/ranger/container/keymap.py
index d52a5215..8739d22a 100644
--- a/ranger/container/keymap.py
+++ b/ranger/container/keymap.py
@@ -95,9 +95,9 @@ class KeyMapWithDirections(KeyMap):
 		self.directions = KeyMap()
 
 	def merge(self, other):
-		assert hasattr(other, 'directions'), 'Merging with wrong type?'
 		Tree.merge(self, other)
-		Tree.merge(self.directions, other.directions)
+		if hasattr(other, 'directions'):
+			Tree.merge(self.directions, other.directions)
 
 	def dir(self, *args, **keywords):
 		if ALIASARG in keywords:
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index d1ef3ed0..910c0241 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -73,6 +73,8 @@ def parse_arguments():
 	parser.add_option('--choosedir', type='string', metavar='TARGET',
 			help="Makes ranger act like a directory chooser. When ranger quits"
 			", it will write the name of the last visited directory to TARGET")
+	parser.add_option('--list-unused-keys', action='store_true',
+			help="List common keys which are not bound to any action.")
 
 	options, positional = parser.parse_args()
 	arg = OpenStruct(options.__dict__, targets=positional)
diff --git a/ranger/core/main.py b/ranger/core/main.py
index e6392387..5a7b32af 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -77,6 +77,20 @@ def main():
 		fm.tabs = dict((n+1, os.path.abspath(path)) for n, path \
 				in enumerate(targets[:9]))
 		load_settings(fm, arg.clean)
+
+		if arg.list_unused_keys:
+			from ranger.ext.keybinding_parser import special_keys
+			tree = EnvironmentAware.env.keymanager.get_context('browser')
+			tree.merge(tree.directions)
+			reversed_special_keys = dict((v,k) for k,v in special_keys.items())
+			for key in sorted(special_keys.values()):
+				if key not in tree._tree:
+					print("<%s>" % reversed_special_keys[key])
+			for key in range(33, 128):
+				if key not in tree._tree:
+					print(chr(key))
+			return 1 if arg.fail_unless_cd else 0
+
 		if fm.env.username == 'root':
 			fm.settings.preview_files = False
 			fm.settings.use_preview_script = False