From a17508d5c1492af1579ae561a840cdd859946ddc Mon Sep 17 00:00:00 2001 From: toonn Date: Wed, 31 Jan 2018 11:22:45 +0100 Subject: Make new `rifle` behavior backwards compatible. There's 4 possible situation: 1. `VISUAL` set, `EDITOR` set 2. `VISUAL` set, `EDITOR` not set 3. `VISUAL` not set, `EDITOR` set 4. `VISUAL` not set, `EDITOR` not set All but _No.2_ are already properly handled. Behavior can differ depending on whether you have an old or a new `rifle.conf` in cases _No.1_ (if the variables differ the new approach prefers `VISUAL` instead of `EDITOR`) and _No.2_ (new approach will use `VISUAL` whereas the old approach would've fallen back to _vim_). _No.3_ is likely the most common case and works almost identically with either approach. _No.4_ still falls back to _vim_ as before. Fix #1048 --- ranger/ext/rifle.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index 36f3243e..84b8f375 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -343,10 +343,15 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes else: if 'PAGER' not in os.environ: os.environ['PAGER'] = DEFAULT_PAGER - if 'VISUAL' not in os.environ and 'EDITOR' not in os.environ: - os.environ['VISUAL'] = DEFAULT_EDITOR - # necessary for compatibility with old rifle.conf - os.environ['EDITOR'] = DEFAULT_EDITOR + if 'VISUAL' not in os.environ: + if 'EDITOR' not in os.environ: + os.environ['VISUAL'] = DEFAULT_EDITOR + # necessary for compatibility with old rifle.conf + os.environ['EDITOR'] = DEFAULT_EDITOR + else: + if 'EDITOR' not in os.environ: + # similar to new behavior for old rifle.conf + os.environ['EDITOR'] = os.environ['VISUAL'] command = self.hook_command_postprocessing(command) self.hook_before_executing(command, self._mimetype, self._app_flags) try: -- cgit 1.4.1-2-gfad0