al-geiser.el 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;; al-geiser.el --- Additional functionality for geiser
  2. ;; Copyright © 2014–2018 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. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'geiser-mode)
  17. (defun al/geiser-repl ()
  18. "Return the current Geiser REPL."
  19. (or (geiser-repl--repl/impl 'guile)
  20. (error "Geiser REPL not found")))
  21. (defun al/geiser-eval (str &optional repl)
  22. "Evaluate STR with guile expression using Geiser REPL.
  23. If REPL is nil, use the current Geiser REPL.
  24. Return a list of strings with result values of evaluation."
  25. (with-current-buffer (or repl (al/geiser-repl))
  26. (let ((res (geiser-eval--send/wait `(:eval (:scm ,str)))))
  27. (if (geiser-eval--retort-error res)
  28. (error "Error in evaluating guile expression: %s"
  29. (geiser-eval--retort-output res))
  30. (cdr (assq 'result res))))))
  31. ;;;###autoload
  32. (defun al/geiser-add-to-load-path (directory)
  33. "Add DIRECTORY to the Guile REPL load paths."
  34. (interactive "DDirectory to add: ")
  35. (al/geiser-eval
  36. (concat "(set! %load-path "
  37. "(cons \"" directory "\" %load-path))"))
  38. (al/geiser-eval
  39. (concat "(set! %load-compiled-path "
  40. "(cons \"" directory "\" %load-compiled-path))")))
  41. ;;;###autoload
  42. (defun al/geiser-eval-dwim (arg)
  43. "Eval (with geiser) last sexp or region if it is active.
  44. ARG is passed to `geiser-eval-last-sexp'."
  45. (interactive "P")
  46. (if (use-region-p)
  47. (geiser-eval-region (region-beginning) (region-end))
  48. (geiser-eval-last-sexp arg)))
  49. ;;;###autoload
  50. (defun al/geiser-repl-enter-dwim ()
  51. "Send input or goto the error at point.
  52. Substitution for `geiser-repl--maybe-send'."
  53. (interactive)
  54. (cond ((< (point) (geiser-repl--last-prompt-start))
  55. (if (geiser-repl--is-input)
  56. (geiser-repl--grab-input)
  57. (ignore-errors (compile-goto-error))))
  58. (t
  59. (geiser-repl--send-input))))
  60. ;;;###autoload
  61. (defun al/geiser-repl-kill-whole-line (arg)
  62. "Similar to `kill-whole-line', but respect geiser repl prompt."
  63. (interactive "p")
  64. (kill-region (comint-line-beginning-position)
  65. (progn (forward-line arg) (point))))
  66. ;;;###autoload
  67. (defun al/geiser-doc-doc-symbol-at-point ()
  68. "Open documentation for symbol at point.
  69. This function refers to `geiser-doc-symbol-at-point' as
  70. `geiser-doc-edit-symbol-at-point' refers to
  71. `geiser-edit-symbol-at-point'."
  72. (interactive)
  73. (let* ((impl (geiser-doc--implementation))
  74. (module (geiser-doc--module)))
  75. (unless (and impl module)
  76. (error "I don't know what module this buffer refers to."))
  77. (with--geiser-implementation impl
  78. (geiser-doc-symbol-at-point))))
  79. (defun al/geiser-repl-buffer-name (impl)
  80. "Return buffer name of Geiser REPL for IMPL."
  81. (format "*%s*" (geiser-repl--repl-name impl)))
  82. ;;; Connecting to pre-defined sockets
  83. (defvar al/geiser-sockets nil
  84. "List of Guile's socket files used by `al/geiser-socket-connect'.")
  85. ;;;###autoload
  86. (defun al/geiser-socket-connect (socket)
  87. "Connect Geiser to Guile's SOCKET file.
  88. Interactively, prompt for SOCKET using completions from
  89. `al/geiser-sockets'."
  90. (interactive
  91. (list (expand-file-name
  92. (completing-read "Socket: " al/geiser-sockets))))
  93. (geiser-connect-local 'guile socket))
  94. (provide 'al-geiser)
  95. ;;; al-geiser.el ends here