#!/bin/sh
#|-*- mode:lisp -*-|#
#|Launch emacs
exec ros -m roswell -N roswell -- $0 "$@"
|#

(progn
  (roswell:include "util"))

(defpackage :ros.script.emacs.3672012160
  (:use :cl))
(in-package :ros.script.emacs.3672012160)

(defvar *verbose-p* nil)

(defmacro mute-error-if-not-verbose (&body body)
  "Execute the body, catches (and hide) any error if *verbose-p* is nil."
  `(handler-case
       ,@body
     (error (condition)
       (if *verbose-p*
           (error condition)
           (values nil condition)))))

(defun main (&rest argv)
  (let ((path (merge-pathnames "helper.el" (roswell:opt "homedir")))
        (*verbose-p* (or (roswell:verbose)
                         (roswell:opt "emacs.verbose"))))
    (unless (probe-file path)
      (roswell:roswell '("install" "slime") :interactive nil))
    (mute-error-if-not-verbose
     (roswell:exec
      `("emacs" "-l" ,(namestring path) "--eval"
                ,(format nil
                         #-win32
                         "(setq inferior-lisp-program \"ros -Q ~:[~;~:*-L ~A ~]run\")"
                         #+win32
                         "\"(setq inferior-lisp-program \\\"ros -Q ~:[~;~:*-L ~A ~]run\\\")\""
                         (roswell:opt "*lisp"))
                ,@argv)))))
;;; vim: set ft=lisp lisp:
