al-server.el 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;;; al-server.el --- Code for working with Emacs server
  2. ;; Copyright © 2014-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'server)
  15. (defvar al/server-running? nil
  16. "The state of the current server.
  17. This variable is set by `al/server-start'.")
  18. ;;;###autoload
  19. (defun al/server-start (&optional leave-dead inhibit-prompt)
  20. "Same as `server-start' but also set `al/server-running?'."
  21. (interactive "P")
  22. (server-start leave-dead inhibit-prompt)
  23. (setq al/server-running? (not leave-dead)))
  24. ;;;###autoload
  25. (defun al/server-stop ()
  26. "Stop the current server."
  27. (interactive)
  28. (al/server-start t))
  29. (defun al/server-named-start (&rest names)
  30. "Start server using the first `server-name' from NAMES.
  31. If there is such server running, try the second name and so on.
  32. If servers with all NAMES are running, do not start the server."
  33. (let ((name (car names))
  34. (rest (cdr names)))
  35. (if (null name)
  36. (setq server-name "server-unused")
  37. (setq server-name name)
  38. (if (server-running-p)
  39. (apply #'al/server-named-start rest)
  40. (al/server-start)))))
  41. (provide 'al-server)
  42. ;;; al-server.el ends here