Use VISUAL in addition to EDITOR when choosing the editor to use.
--- a/hgmerge Tue Dec 18 14:01:42 2007 -0600
+++ b/hgmerge Wed Dec 05 20:40:01 2007 +0900
@@ -17,8 +17,12 @@
BASE="$2"
OTHER="$3"
-if [ -z "$EDITOR" ]; then
- EDITOR="vi"
+if [ -n "$VISUAL" ]; then
+ EDIT_PROG="$VISUAL"
+elif [ -n "$EDITOR" ]; then
+ EDIT_PROG="$EDITOR"
+else
+ EDIT_PROG="vi"
fi
# find decent versions of our utilities, insisting on the GNU versions where we
@@ -165,16 +169,16 @@
fi
fi
-# Attempt to do a merge with $EDITOR
+# Attempt to do a merge with $EDIT_PROG
if [ -n "$MERGE" -o -n "$DIFF3" ]; then
echo "conflicts detected in $LOCAL"
cp "$BACKUP" "$CHGTEST"
- case "$EDITOR" in
+ case "$EDIT_PROG" in
"emacs")
- $EDITOR "$LOCAL" --eval '(condition-case nil (smerge-mode 1) (error nil))' || failure
+ $EDIT_PROG "$LOCAL" --eval '(condition-case nil (smerge-mode 1) (error nil))' || failure
;;
*)
- $EDITOR "$LOCAL" || failure
+ $EDIT_PROG "$LOCAL" || failure
;;
esac
# Some editors do not return meaningful error codes
@@ -195,7 +199,7 @@
success
else
# If rejects are empty after using the editor, merge was ok
- $EDITOR "$LOCAL" "$LOCAL.rej" || failure
+ $EDIT_PROG "$LOCAL" "$LOCAL.rej" || failure
$TEST -s "$LOCAL.rej" || success
fi
failure
--- a/mercurial/commands.py Tue Dec 18 14:01:42 2007 -0600
+++ b/mercurial/commands.py Wed Dec 05 20:40:01 2007 +0900
@@ -430,8 +430,8 @@
If a list of files is omitted, all changes reported by "hg status"
will be committed.
- If no commit message is specified, the editor configured in your hgrc
- or in the EDITOR environment variable is started to enter a message.
+ If no commit message is specified, the configured editor is started to
+ enter a message.
"""
def commitfunc(ui, repo, files, message, match, opts):
return repo.commit(files, message, opts['user'], opts['date'], match,
@@ -748,9 +748,7 @@
# editor
ui.status(_("Checking commit editor...\n"))
- editor = (os.environ.get("HGEDITOR") or
- ui.config("ui", "editor") or
- os.environ.get("EDITOR", "vi"))
+ editor = ui.geteditor()
cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
if not cmdpath:
if editor == 'vi':
--- a/mercurial/help.py Tue Dec 18 14:01:42 2007 -0600
+++ b/mercurial/help.py Wed Dec 05 20:40:01 2007 +0900
@@ -43,8 +43,7 @@
'hg' (with com/exe/bat/cmd extension on Windows) is searched.
HGEDITOR::
- This is the name of the editor to use when committing. Defaults to the
- value of EDITOR.
+ This is the name of the editor to use when committing. See EDITOR.
(deprecated, use .hgrc)
@@ -94,9 +93,16 @@
If neither HGUSER nor EMAIL is set, LOGNAME will be used (with
'@hostname' appended) as the author value for a commit.
+VISUAL::
+ This is the name of the editor to use when committing. See EDITOR.
+
EDITOR::
- This is the name of the editor used in the hgmerge script. It will be
- used for commit messages if HGEDITOR isn't set. Defaults to 'vi'.
+ Sometimes Mercurial needs to open a text file in an editor for a user
+ to modify, for example when writing commit messages or when using the
+ hgmerge script. The editor it uses is determined by looking at the
+ environment variables HGEDITOR, VISUAL and EDITOR, in that order. The
+ first non-empty one is chosen. If all of them are empty, the editor
+ defaults to 'vi'.
PYTHONPATH::
This is used by Python to find imported modules and may need to be set
--- a/mercurial/ui.py Tue Dec 18 14:01:42 2007 -0600
+++ b/mercurial/ui.py Wed Dec 05 20:40:01 2007 +0900
@@ -440,9 +440,7 @@
f.write(text)
f.close()
- editor = (os.environ.get("HGEDITOR") or
- self.config("ui", "editor") or
- os.environ.get("EDITOR", "vi"))
+ editor = self.geteditor()
util.system("%s \"%s\"" % (editor, name),
environ={'HGUSER': user},
@@ -464,3 +462,11 @@
if self.traceback:
traceback.print_exc()
return self.traceback
+
+ def geteditor(self):
+ '''return editor to use'''
+ return (os.environ.get("HGEDITOR") or
+ self.config("ui", "editor") or
+ os.environ.get("VISUAL") or
+ os.environ.get("EDITOR", "vi"))
+