[PATCH 1 of 2] Abstract the functionality of calling an editor into the 'edit' function to prevent

Itamar Ravid iravid at iravid.com
Sat Apr 3 10:17:54 CDT 2010


# HG changeset patch
# User Itamar Ravid <iravid at iravid.com>
# Date 1270307531 -10800
# Node ID 2272a05026eb11f2d52067606729df6d86f18627
# Parent  cd0c49bdbfd9edab18c3656d8a8a0bd27a9aa82a
Abstract the functionality of calling an editor into the 'edit' function to prevent
users from having to mess with the code responsible for generating the temporary
commit message and diff files.

diff -r cd0c49bdbfd9 -r 2272a05026eb hgeditor
--- a/hgeditor	Thu Apr 01 17:51:59 2010 -0500
+++ b/hgeditor	Sat Apr 03 18:12:11 2010 +0300
@@ -3,19 +3,22 @@
 # This is an example of using HGEDITOR to create of diff to review the
 # changes while commiting.
 
-# If you want to pass your favourite editor some other parameters
-# only for Mercurial, modify this:
-case "${EDITOR}" in
-    "")
-        EDITOR="vi"
-        ;;
-    emacs)
-        EDITOR="$EDITOR -nw"
-        ;;
-    gvim|vim)
-        EDITOR="$EDITOR -f -o"
-        ;;
-esac
+# Edit a file, optionally opening another one as reference within the editor.
+# If you want to pass your favourite editor some other parameters only for Mercurial, 
+# modify the 'case' statement within this function.
+edit() {
+    case "${EDITOR}" in
+        "")
+            vi "$1" "$2"
+            ;;
+        emacs)
+            emacs -nw "$1" "$2"
+            ;;
+        gvim|vim)
+            $EDITOR -f -o "$1" "$2"
+            ;;
+    esac
+}
 
 
 HGTMP=""
@@ -45,9 +48,9 @@
     MD5=$(which md5 2>/dev/null)
 [ -x "${MD5}" ] && CHECKSUM=`${MD5} "$HGTMP/msg"`
 if [ -s "$HGTMP/diff" ]; then
-    $EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $?
+    edit "$HGTMP/msg" "$HGTMP/diff" || exit $?
 else
-    $EDITOR "$HGTMP/msg" || exit $?
+    edit "$HGTMP/msg" || exit $?
 fi
 [ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13)
 


More information about the Mercurial mailing list