about summary refs log tree commit diff stats
path: root/doc/examples/plugin_hello_world.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-03-09 18:48:02 +0100
committerhut <hut@lavabit.com>2013-03-09 18:48:02 +0100
commitd2c7d024290ee95afa418975c728ad64172dcfec (patch)
treeeea0659eab7bb0c7b9cc2026468c840d7f22a5c9 /doc/examples/plugin_hello_world.py
parent62af277734f05f27f20467393c9d997012ddd2b4 (diff)
downloadranger-d2c7d024290ee95afa418975c728ad64172dcfec.tar.gz
move examples to doc/examples
Diffstat (limited to 'doc/examples/plugin_hello_world.py')
-rw-r--r--doc/examples/plugin_hello_world.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/doc/examples/plugin_hello_world.py b/doc/examples/plugin_hello_world.py
new file mode 100644
index 00000000..a803e21b
--- /dev/null
+++ b/doc/examples/plugin_hello_world.py
@@ -0,0 +1,23 @@
+# Compatible with ranger 1.6.*
+#
+# This is a sample plugin that displays "Hello World" in ranger's console after
+# it started.
+
+# We are going to extend the hook "ranger.api.hook_ready", so first we need
+# to import ranger.api:
+import ranger.api
+
+# Save the previously existing hook, because maybe another module already
+# extended that hook and we don't want to lose it:
+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 safe.
+    return old_hook_ready(fm)
+
+# Finally, "monkey patch" the existing hook_ready function with our replacement:
+ranger.api.hook_ready = hook_ready