al-slime.el 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; al-slime.el --- Additional functionality for slime
  2. ;; Copyright © 2013-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 'slime)
  15. ;;;###autoload
  16. (defun al/slime-eval-dwim ()
  17. "Eval (with slime) last sexp or region if it is active."
  18. (interactive)
  19. (if (use-region-p)
  20. (slime-eval-region (region-beginning) (region-end))
  21. (slime-eval-last-expression)))
  22. (defvar slime-repl-input-start-mark)
  23. ;;;###autoload
  24. (defun al/slime-repl-kill-whole-line (arg)
  25. "Similar to `kill-whole-line', respecting slime-repl prompt."
  26. (interactive "p")
  27. (let ((prompt-pos (marker-position slime-repl-input-start-mark)))
  28. (if (< (point) prompt-pos)
  29. (kill-whole-line arg)
  30. (kill-region prompt-pos
  31. (progn (forward-line arg) (point))))))
  32. ;;;###autoload
  33. (defun al/slime-stumpwm-connect (&optional display)
  34. "Connect to a swank server running by StumpWM on DISPLAY.
  35. If DISPLAY is nil, use the current DISPLAY environment variable.
  36. With prefix, prompt for DISPLAY.
  37. The port of the running swank server is defined by adding DISPLAY
  38. number to `slime-port'. See
  39. <https://github.com/alezost/stumpwm-config/blob/master/init.lisp>."
  40. (interactive
  41. (list (when current-prefix-arg
  42. (read-string "Display: " (getenv "DISPLAY")))))
  43. (let* ((display (or display (getenv "DISPLAY")))
  44. (display-num (if (string-match (rx ":" (group (+ digit)))
  45. display)
  46. (string-to-number (match-string 1 display))
  47. 0)))
  48. (slime-connect slime-lisp-host (+ slime-port display-num))))
  49. (provide 'al-slime)
  50. ;;; al-slime.el ends here