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

Mads Kiilerich mads at kiilerich.com
Sun Apr 4 17:07:05 CDT 2010


Itamar Ravid wrote, On 04/04/2010 01:07 PM:
> edit() {
>     case "${EDITOR}" in
>         "")
>             EDITOR="vi"
>             ;;
>         emacs)
>             EDITOR="$EDITOR -nw"
>             ;;
>         gvim|vim)
>             # Note special case when opening two files below
>             EDITOR="$EDITOR"

why?

>             ;;
>     esac
>
>     if [ -z "$2" ]; then
>         "$EDITOR" "$1"

AFAICS you haven't tested this (and the following) with "emacs -nw"? 
Here we want $EDITOR to expand to a command with some arguments, so it 
shouldn't be quoted.

>     else
>         if [ $EDITOR = "vim" -o $EDITOR = "gvim" ]; then
>             # Handle irregular arg-ordering when calling g/vim
>             "$EDITOR" "+e $2" "+set buftype=help" "+split $1"
>         else
>             "$EDITOR" "$1" "$2"
>         fi
>     fi
> }
> This, I believe, handles the problems discussed while still containing 
> the edit logic within the function. What do you think?

I think that this is a nice-to-have, but also that it complicates the 
code and makes it harder for the next guy to customize the code to fit 
his need. The more I look at the code the more I think the cost in 
increased complexity is too high.

Anyway, why not do something like this:

--- a/hgeditor
+++ b/hgeditor
@@ -12,11 +12,15 @@
      emacs)
          EDITOR="$EDITOR -nw"
          ;;
-    gvim|vim)
-        EDITOR="$EDITOR -f -o"
-        ;;
  esac

+vim() {
+    if [ "$2" ]; then
+        "$(which vim)" "+e $2" "+set buftype=help" "+split $1"
+    else
+        "$(which vim)" -f -o "$1"
+    fi
+}

  HGTMP=""
  cleanup_exit() {


/Mads


More information about the Mercurial mailing list