From 33aeef8e9fe3891723a2d2fe450859c46cb572ab Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 22 Feb 2013 03:09:08 +0100 Subject: examples/plugin_chmod_keybindings.py: fixed crash --- examples/plugin_chmod_keybindings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/plugin_chmod_keybindings.py b/examples/plugin_chmod_keybindings.py index 9c9a0982..f26cb3e3 100644 --- a/examples/plugin_chmod_keybindings.py +++ b/examples/plugin_chmod_keybindings.py @@ -10,7 +10,7 @@ def hook_init(fm): # Generate key bindings for the chmod command command = "map {0}{1}{2} shell -d chmod {1}{0}{2} %s" - for mode in list('ugoa') + '': + for mode in list('ugoa') + ['']: for perm in "rwxXst": fm.execute_console(command.format('-', mode, perm)) fm.execute_console(command.format('+', mode, perm)) -- cgit 1.4.1-2-gfad0 From 58247b857f861c057158ec3ecab89f3dffcfe290 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 22 Feb 2013 03:17:46 +0100 Subject: core.main: added RANGER_LOAD_DEFAULT_RC environment variable this fixes the problem that examples/plugin_skip_default_rc doesn't work, because plugins are loaded after the rc.conf. --- doc/ranger.1 | 5 +++++ doc/ranger.pod | 6 ++++++ examples/plugin_skip_default_rc.py | 9 --------- ranger/config/rc.conf | 4 ++-- ranger/core/main.py | 5 +---- 5 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 examples/plugin_skip_default_rc.py (limited to 'examples') diff --git a/doc/ranger.1 b/doc/ranger.1 index 64199243..e18ec5d0 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -1028,6 +1028,11 @@ These environment variables have an effect on ranger: ranger sets this environment variable to \*(L"1\*(R" or increments it if it already exists. External programs can determine whether they were spawned from ranger by checking for this variable. +.IP "\s-1RANGER_LOAD_DEFAULT_RC\s0" 8 +.IX Item "RANGER_LOAD_DEFAULT_RC" +If this variable is set to \s-1FALSE\s0, ranger will not load the default rc.conf. +This can save time if you copied the whole rc.conf to ~/.config/ranger/ and +don't need the default one at all. .IP "\s-1EDITOR\s0" 8 .IX Item "EDITOR" Defines the editor to be used for the \*(L"E\*(R" key. Defaults to \*(L"nano\*(R". diff --git a/doc/ranger.pod b/doc/ranger.pod index 86b7df25..748e48b3 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -1105,6 +1105,12 @@ ranger sets this environment variable to "1" or increments it if it already exists. External programs can determine whether they were spawned from ranger by checking for this variable. +=item RANGER_LOAD_DEFAULT_RC + +If this variable is set to FALSE, ranger will not load the default rc.conf. +This can save time if you copied the whole rc.conf to ~/.config/ranger/ and +don't need the default one at all. + =item EDITOR Defines the editor to be used for the "E" key. Defaults to "nano". diff --git a/examples/plugin_skip_default_rc.py b/examples/plugin_skip_default_rc.py deleted file mode 100644 index 6a657a99..00000000 --- a/examples/plugin_skip_default_rc.py +++ /dev/null @@ -1,9 +0,0 @@ -# This plugin inhibits the loading of the default rc.conf. This serves to -# speed up starting time by avoiding to load rc.conf twice if you have a full -# copy of it in ~/.config/ranger. -# -# Don't use this if you have a supplementary rc.conf or no rc.conf at all, or -# you will end up without key bindings and options. - -import ranger.core.main -ranger.core.main.load_default_config = False diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index f5effe2d..bfb2d457 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -3,8 +3,8 @@ # To change them, it is recommended to create the file # ~/.config/ranger/rc.conf and add your custom commands there. # -# If you copy this whole file there, you may want to install the plugin -# "plugins/plugin_skip_default_rc.py" to avoid loading the rc.conf twice. +# If you copy this whole file there, you may want to set the environment +# variable RANGER_LOAD_DEFAULT_RC to FALSE to avoid loading it twice. # # The purpose of this file is mainly to define keybindings and settings. # For running more complex python code, please create a plugin in "plugins/" or diff --git a/ranger/core/main.py b/ranger/core/main.py index fbdb3bcd..dc35b47e 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -8,8 +8,6 @@ The main function responsible to initialize the FM object and stuff. import os.path import sys -load_default_config = True - def main(): """initialize objects and run the filemanager""" import locale @@ -234,7 +232,6 @@ def parse_arguments(): def load_settings(fm, clean): - global load_default_config from ranger.core.actions import Actions import ranger.core.shared import ranger.api.commands @@ -264,7 +261,7 @@ def load_settings(fm, clean): custom_conf = fm.confpath('rc.conf') default_conf = fm.relpath('config', 'rc.conf') - if load_default_config: + if os.environ.get('RANGER_LOAD_DEFAULT_RC', 0) != 'FALSE': fm.source(default_conf) if os.access(custom_conf, os.R_OK): fm.source(custom_conf) -- cgit 1.4.1-2-gfad0 From d894fd02f52c569cfcf73917a006d68513af56ff Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 22 Feb 2013 03:27:58 +0100 Subject: use 4-space-indents in files that had 2-space-indents --- examples/plugin_hello_world.py | 10 +++++----- ranger/ext/cached_function.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'examples') diff --git a/examples/plugin_hello_world.py b/examples/plugin_hello_world.py index 187f428e..e43eb61d 100644 --- a/examples/plugin_hello_world.py +++ b/examples/plugin_hello_world.py @@ -11,11 +11,11 @@ old_hook_ready = ranger.api.hook_ready # Create a replacement for the hook that... def hook_ready(fm): - # ...does the desired action... - fm.notify("Hello World") - # ...and calls the saved hook. If you don't care about the return value, simply - # return the return value of the previous hook to be on the safe side. - return old_hook_ready(fm) + # ...does the desired action... + fm.notify("Hello World") + # ...and calls the saved hook. If you don't care about the return value, + # simply return the return value of the previous hook to be safe. + return old_hook_ready(fm) # Finally, "monkey patch" the existing hook_ready function with our replacement: ranger.api.hook_ready = hook_ready diff --git a/ranger/ext/cached_function.py b/ranger/ext/cached_function.py index bbd6d2d4..daee6397 100644 --- a/ranger/ext/cached_function.py +++ b/ranger/ext/cached_function.py @@ -2,14 +2,14 @@ # This software is distributed under the terms of the GNU GPL version 3. def cached_function(fnc): - cache = {} - def inner_cached_function(*args): - try: - return cache[args] - except: - value = fnc(*args) - cache[args] = value - return value - inner_cached_function._cache = cache - return inner_cached_function + cache = {} + def inner_cached_function(*args): + try: + return cache[args] + except: + value = fnc(*args) + cache[args] = value + return value + inner_cached_function._cache = cache + return inner_cached_function -- cgit 1.4.1-2-gfad0