From: scs@iti.org (Steve Simmons)
Subject: X-based/elm-based mail browser using tk
Organization: Industrial Technology Institute
Date: Sat, 12 Dec 1992 04:55:37 GMT


I've been following tk/tcl for some time, but just recently sat down to
actually *do* something with it.  The tk/tcl kit includes a simple file
browser, and as a learning exercise I hacked it up to become a mailbox
browser.  It brings up a list of your mail folders, you click on the
name, and it fires up an instance of elm on the indicated folder.

What, you're not an elm fan?  This should be useful for *any* mail
reading program.  Simple change the 'elm' command to the mailer of your
choice.

In the elm windows use your standard elm commands.  In the browse
windows do double-click to select a mailbox; do ^Q or ^C to exit the
browse windows.  You may want to set the "dirswitch" and "dir"
variables to match your personal usage.

Lest anyone jump up and down about given features: this was so
startlingly simple and functional that I and others am already using
it.  There's an hour of work tops in the thing, most of that reading
the manual page.  Probably 80% of the code is ripped off directly from
the tk sample file browser.

For those reading this in comp.mail.elm, tk/tcl is an X windows toolkit
and command processing language.  You can download the code from
sprite.berkeley.edu; the language is discussed in comp.lang.tcl, to
which this article is crossposted.

Enjoy.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  tkelm
# Wrapped by scs@hela.iti.org on Fri Dec 11 23:54:20 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'tkelm' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tkelm'\"
else
echo shar: Extracting \"'tkelm'\" \(1752 characters\)
sed "s/^X//" >'tkelm' <<'END_OF_FILE'
X#!/usr/local/bin/wish -f
X#
X# This script generates a directory browser, which lists the working
X# directory and allows you to open files or subdirectories by
X# double-clicking.
X
X# Create a scrollbar on the right side of the main window and a listbox
X# on the left side.
X
X# These are the switches needed to generate a ls listing that prints
X# all files except . and .., and appends a "/" to directory names.  Your
X# mileage may vary.
X
Xset dirswitch "-AF"
X
X# The default location of your mail folder.  Elm's default is "Mail",
X# but many folks override this.
X
Xset dir ".mailbox"
X
Xscrollbar .scroll -command ".list yview"
Xlistbox .list -borderwidth 2 -yscroll ".scroll set" -relief raised -geometry 20x20
Xpack append . .scroll {right filly} .list {left expand fill}
X
X# The procedure below is invoked to open a browser on a given file;  if the
X# file is a directory then another instance of this program is invoked; if
X# the file is a regular file then the Mx editor is invoked to display
X# the file.
X
Xproc mailbrowse {dir file} {
X    if {[string compare $dir "."] != 0} {set file $dir/$file}
X    if [file isdirectory $file] {
X	exec mailbrowse $file &
X    } else {
X	if [file isfile $file] {
X	    exec /usr/bin/X11/xterm -T $file -n $file -e elm -f $file &
X	} else {
X	    puts stdout "\"$file\" isn't a directory or regular file"
X	}
X    }
X}
X
X# Fill the listbox with a list of all the files in the directory (run
X# the "ls" command to get that information).
X
Xif $argc>0 {set dir [lindex $argv 0]}
Xforeach i [exec ls $dirswitch $dir] {
X    .list insert end $i
X}
X
X# Set up bindings for the browser.
X
Xbind .list <Control-q> {destroy .}
Xbind .list <Control-c> {destroy .}
Xfocus .list
Xbind .list <Double-Button-1> {foreach i [selection get] {mailbrowse $dir $i}}
END_OF_FILE
if test 1752 -ne `wc -c <'tkelm'`; then
    echo shar: \"'tkelm'\" unpacked with wrong size!
fi
chmod +x 'tkelm'
# end of 'tkelm'
fi
echo shar: End of shell archive.
exit 0
-- 
	"You can't get here from here."