[PATCH] Support VISUAL environment variable

Osku Salerma osku at iki.fi
Tue Dec 4 06:32:55 CST 2007


I didn't like it much when Mercurial fired up vi to write my commit
message in, ignoring my VISUAL=emacs unlike pretty much every other unix
program out there. The patch below fixes that, and in addition moves the
editor-finding code to a single place so it's no longer duplicated.

I guess technically it's a layering violation for util to be calling
functions in ui objects, so if you really want to avoid that the function
could be moved to ui.

I also didn't update any of the documentation talking about EDITOR, since
it's scattered all over the place, and the whole point of the patch is
that things will "just work" for more people without them having to read
the documentation or change their settings.


# HG changeset patch
# User Osku Salerma <osku at iki.fi>
# Date 1196770366 -32400
# Node ID 0c553122888cc1d01869d17db44908889d647b26
# Parent  feac5b0bf9bad2c125ebd5f3e133bcd46ecb8c7c
Add util.geteditor and have it look for VISUAL in addition to EDITOR.

diff -r feac5b0bf9ba -r 0c553122888c mercurial/commands.py
--- a/mercurial/commands.py	Wed Nov 28 13:58:31 2007 -0800
+++ b/mercurial/commands.py	Tue Dec 04 21:12:46 2007 +0900
@@ -941,9 +941,7 @@ def debuginstall(ui):

      # editor
      ui.status(_("Checking commit editor...\n"))
-    editor = (os.environ.get("HGEDITOR") or
-              ui.config("ui", "editor") or
-              os.environ.get("EDITOR", "vi"))
+    editor = util.geteditor(ui)
      cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
      if not cmdpath:
          if editor == 'vi':
diff -r feac5b0bf9ba -r 0c553122888c mercurial/ui.py
--- a/mercurial/ui.py	Wed Nov 28 13:58:31 2007 -0800
+++ b/mercurial/ui.py	Tue Dec 04 21:12:46 2007 +0900
@@ -435,9 +435,7 @@ class ui(object):
              f.write(text)
              f.close()

-            editor = (os.environ.get("HGEDITOR") or
-                    self.config("ui", "editor") or
-                    os.environ.get("EDITOR", "vi"))
+            editor = util.geteditor(self)

              util.system("%s \"%s\"" % (editor, name),
                          environ={'HGUSER': user},
diff -r feac5b0bf9ba -r 0c553122888c mercurial/util.py
--- a/mercurial/util.py	Wed Nov 28 13:58:31 2007 -0800
+++ b/mercurial/util.py	Tue Dec 04 21:12:46 2007 +0900
@@ -550,6 +550,13 @@ def _matcher(canonroot, cwd, names, inc,
          match = lambda fn: incmatch(fn) and not excmatch(fn) and patmatch(fn)

      return (roots, match, (inc or exc or anypats) and True)
+
+def geteditor(ui):
+    '''return editor to use'''
+    return (os.environ.get("HGEDITOR") or
+            ui.config("ui", "editor") or
+            os.environ.get("EDITOR") or
+            os.environ.get("VISUAL", "vi"))

  _hgexecutable = None



--
Osku Salerma


More information about the Mercurial-devel mailing list