From 014c41843fa326d7f8163ceca4fa7b99c4d3dd91 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 17 Feb 2010 15:32:53 +0100 Subject: commands: added an eval function + documentation --- ranger/commands.py | 31 +++++++++++++++++++++++++++++++ ranger/help/console.py | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/ranger/commands.py b/ranger/commands.py index a6fc77fb..b3625037 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -315,6 +315,37 @@ class edit(Command): return self._tab_directory_content() +class eval_(Command): + """ + :eval + + Evaluates the python code. + `fm' is a reference to the FM instance. + To display text, use the function `p'. + + Examples: + :eval fm + :eval len(fm.env.directories) + :eval p("Hello World!") + """ + name = 'eval' + + def execute(self): + code = parse(self.line).rest(1) + fm = self.fm + p = fm.notify + try: + try: + result = eval(code) + except SyntaxError: + exec(code) + else: + if result: + p(result) + except Exception as err: + p(err) + + class rename(Command): """ :rename diff --git a/ranger/help/console.py b/ranger/help/console.py index 1ea06f90..cd382d2e 100644 --- a/ranger/help/console.py +++ b/ranger/help/console.py @@ -77,6 +77,10 @@ it conflicts with ":cd". :edit Opens the specified file in the text editor. +:eval + Evaluates the given code inside ranger. `fm' is a reference to + the filemanager instance, `p' is a function to print text. + :filter Displays only files which contain in their basename. -- cgit 1.4.1-2-gfad0