#!/bin/sh
# Register/unregister thailatex
# Written by Theppitak Karoonboonyanan <thep@linux.thai.net>
# License: GPL

prefix=@prefix@

EMACSLISPDIR=@emacsdir@/site-lisp

do_install()
{
  echo "Regenerating TeX ls-R ..."
  @TEXHASH@

  # add Emacs macro for activating Thai LaTeX filter
  echo "Installing emacs macro ..."
  if test -f $EMACSLISPDIR/site-start.el; then
    sed -i -e '/thai-latex-setup/d' $EMACSLISPDIR/site-start.el
  fi
  if test -f $EMACSLISPDIR/thai-latex-setup.el; then
    echo '(load-library "thai-latex-setup")' >> $EMACSLISPDIR/site-start.el
  fi
}

do_uninstall()
{
  echo "Regenerating TeX ls-R ..."
  @TEXHASH@

  # remove Emacs macro for activating Thai LaTeX filter
  echo "Uninstalling emacs macro ..."
  if test -f $EMACSLISPDIR/site-start.el; then
    sed -i -e '/thai-latex-setup/d' $EMACSLISPDIR/site-start.el
  fi
}

# Main script

if test -f $EMACSLISPDIR/thai-latex-setup.el; then
  echo "ThaiLaTeX macro exists, so we will enable it."
  do_install
else
  echo "ThaLaTeX macro no longer exists, so we will disable it."
  do_uninstall
fi

