elisp 729 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. usage () {
  3. cat <<EOF>&2
  4. Usage: ${0##*/} [OPTIONS] SCRIPT [ARGS...]
  5. Run Emacs Lisp SCRIPT.
  6. Options:
  7. -b: Byte-compile before running.
  8. -c: Remove byte code once finished.
  9. EOF
  10. }
  11. OPT_BYTE=false
  12. OPT_CLEAN=false
  13. while getopts :bc OPT; do
  14. case $OPT in
  15. b)
  16. OPT_BYTE=true ;;
  17. c)
  18. OPT_CLEAN=true ;;
  19. \?)
  20. usage
  21. exit 1 ;;
  22. esac
  23. done
  24. shift $((OPTIND - 1))
  25. if [ $# -eq 0 ]; then
  26. usage
  27. exit 1
  28. fi
  29. if ! command -v emacs >/dev/null 2>&1; then
  30. echo >&2 'emacs not found'
  31. exit 1
  32. fi
  33. script="$1"
  34. if $OPT_BYTE && [ "${0##*.}" = "el" ]; then
  35. script="${1%.*}.elc"
  36. emacs -Q --batch -f batch-byte-compile "$1" 2>/dev/null
  37. fi
  38. shift
  39. emacs -Q --script "$script" "$@" 2>&1
  40. status=$?
  41. $OPT_CLEAN && rm "$script"
  42. exit $status