Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 1.17 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! /bin/sh
  2.  
  3. . /etc/rc.conf
  4. . /etc/rc.d/functions
  5.  
  6. #change this. too bad emacs daemon can't really work in mutli-user mode. for now.
  7. USERNAME=volh
  8. DESC="Run the emacs daemon."
  9. NAME=emacs
  10. #change this
  11. DAEMON=/usr/bin/$NAME
  12. DAEMON_ARGS="--daemon"
  13. PIDFILE=/var/run/$NAME.pid
  14. SCRIPTNAME=/etc/rc.d/$NAME
  15. #change this
  16. EMACSCLIENT=/usr/bin/emacsclient
  17.  
  18. #EVALEXIT="(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
  19.  
  20. # This one will save buffers in any case, without prompt(as save-buffers-kill-emacs will unconditionally do).
  21. EVALEXIT="(progn (save-some-buffers t t)(kill-emacs))"
  22.  
  23. # This will save the desktop, but not the buffers themselves
  24. #EVALEXIT="(progn (desktop-save-in-desktop-dir)(kill-emacs))"
  25.  
  26. case "$1" in
  27.   start)
  28.         stat_busy "Starting Emacs"
  29.         su $USERNAME -c "$DAEMON $DAEMON_ARGS" > /dev/null && (add_daemon emacs; stat_done) || stat_fail
  30.   ;;
  31.   stop)
  32.         stat_busy "Stopping Emacs"
  33.         su $USERNAME -c "$EMACSCLIENT --eval \"$EVALEXIT\""  && ( rm_daemon emacs; stat_done ) || stat_fail
  34.   ;;
  35.   restart|force-reload)
  36.         $0 stop
  37.         sleep 1
  38.         $0 start
  39.   ;;
  40.   *)
  41.         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  42.         exit 3
  43.   ;;
  44. esac