# HG changeset patch # User Osku Salerma # Date 2007-12-05 11:40:01 # Node ID 3c80ecdc1bcd0fd06b254b097ca11fee4d0b201c # Parent 3da652f2039cb8a00c1331b73b5af864f344b35f Use VISUAL in addition to EDITOR when choosing the editor to use. diff --git a/hgmerge b/hgmerge --- a/hgmerge +++ b/hgmerge @@ -17,8 +17,12 @@ LOCAL="$1" 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 @@ if [ -n "$DISPLAY" ]; then 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 @@ if [ -n "$DIFF" -a -n "$PATCH" ]; then 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 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -430,8 +430,8 @@ def commit(ui, repo, *pats, **opts): 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 @@ 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 = ui.geteditor() cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0]) if not cmdpath: if editor == 'vi': diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -43,8 +43,7 @@ HG:: '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 @@ LOGNAME:: 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 diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -440,9 +440,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 = self.geteditor() util.system("%s \"%s\"" % (editor, name), environ={'HGUSER': user}, @@ -464,3 +462,11 @@ class ui(object): 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")) +