#!/bin/sh
########################################################################
# BooNE utility to configure xemacs to use AFS package repository
#
# Chris Green <greenc@fnal.gov>
# UCR / BooNE
# 2002/05/22
#
########################################################################
date="2002/06/13"
if [ -n "$1" -a "$1" = "-f" ]; then
  force=1
fi

# Set a comprehensive value for EMACSPACKAGEPATH
EMACSPACKAGEPATH="~/.xemacs/xemacs-packages/:/afs/fnal.gov/files/code/e898/code/6/xemacs-packages/::/usr/lib/xemacs/mule-packages/:/usr/lib/xemacs/xemacs-packages/"

if [ -z "$force" -a -f "/etc/profile.d/xemacs.sh" ]; then
  echo "/etc/profile.d/xemacs.sh already exists: use -f to override" 1>&2
  exit 1
fi

# Write the .csh and .sh files into /etc/profile.d
for i in "sh" "csh"; do
  file="/etc/profile.d/xemacs.$i"
cat > $file <<EOF
########################################################################
# xemacs.$i
#
# To be placed in /etc/profile.d for sourcing upon login.
#
# Set EMACSPACKAGEPATH to pick up the latest XEmacs packages
#
# Chris Green <greenc@fnal.gov>
# UCR / BooNE
# $date
#
########################################################################

# Set EMACSPACKAGEPATH environment variable
EOF
case "$i" in
    "sh")
	echo "eval EMACSPACKAGEPATH=\"$EMACSPACKAGEPATH\"; export EMACSPACKAGEPATH" \
>> $file
	;;
    "csh")
	echo "eval setenv EMACSPACKAGEPATH \"$EMACSPACKAGEPATH\"" >> $file
	;;
esac
local="Local"
cat >> $file <<EOF

# Tell [X]Emacs that we want to be in sh-mode[$i] even though we don't
# have an interpreter line.
#
# Upon loading the file, [X]Emacs will ask for permission to evaluate 
# the form below. Satisfy yourself of the safety of this form 
# (eg C-h f sh-set-shell) before confirming execution.
### $local Variables:
### mode: sh
### eval: (sh-set-shell "$i" t nil)
### End:
EOF
  chmod +x $file
done

# Now write the site-start.el file

site_start="/usr/lib/xemacs/xemacs-packages/lisp/site-start.d"

if [ ! -d "$site_start" ]; then
  echo "Unable to find xemacs site-start directory $site_start" 1>&2
  exit 1
fi

if [  -z "$force" -a -f "$site_start/boone.el" ]; then
  echo "$site_start/boone.el already exists: use -f to override" 1>&2
  exit 1
fi

cat > $site_start/boone.el <<EOF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BooNE site-start goodies
;;
;; Chris Green <greenc@fnal.gov>
;; UCR / BooNE
;; $date
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; If we have access to the mwheel functionality, start it.
(if (fboundp 'mwheel-install)
    (mwheel-install))

;; Deactivate initial message in scratch buffer
(setq initial-scratch-message nil)

;; Load the AUC-TeX package
(require 'tex-site)

;; Activate the RefTeX package
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)

;; Set some custom variables
(custom-set-variables
 '(lpr-command "flpr")
 '(ps-lpr-command "flpr")
 '(delete-key-deletes-forward t)
 '(lpr-printer-switch "-q")
 '(ps-printer-name-option "-q")
 '(ps-printer-name nil)
 '(display-warning-suppressed-classes (quote (warning)))
 '(ps-print-color-p nil)
 '(printer-name "WH10W_HP5SI_DUPLEX")
 '(font-lock-mode t nil (font-lock))
)
(custom-set-faces)
EOF
