#!/usr/local/bin/wish8.5 -f
#
# async editor frontend for exmh
# Arg1: invoking interpreter's name (from [winfo name .])
# Arg2-end: editor command, including pathname
# LastArg: pathname of draft message
#

package require Tk
wm withdraw .

# simple argv cracking
set exmh [lindex $argv 0]
set editorCmd [lrange $argv 1 end]
set draftpath [lindex $argv [expr {[llength $argv] - 1}]]
set draftm [file tail $draftpath]

send $exmh [list Edit_Ident [winfo name .]]

# Used to do a split/join on $editorCmd to allow quoted -geom arguments.
# But that totally screws some arguments, like
# exmh-async gvim -c {cal SetSyn("mail")}
# other interesting cases are
# exmh-async xterm -geom +0+0 -e vi {+/^[-]*$}

if [catch {eval exec $editorCmd} err] {
    send $exmh [list Exmh_Status "exmh-async: editor failed: $err" purple]
}
send $exmh EditDialog $draftm

exit 0
