Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.4 KiB

  1. ;;; le-scheme.el --- lispy support for Scheme. -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2014-2015 Oleh Krehel
  3. ;; This file is not part of GNU Emacs
  4. ;; This file is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation; either version 3, or (at your option)
  7. ;; any later version.
  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. ;; For a full copy of the GNU General Public License
  13. ;; see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;
  16. ;;; Code:
  17. (eval-and-compile
  18. (require 'geiser-eval nil t))
  19. (require 'lispy-inline)
  20. (defvar geiser-impl--implementation)
  21. (declare-function geiser-repl--connection* "geiser-repl")
  22. (declare-function run-geiser "geiser-repl")
  23. (declare-function geiser-repl--buffer-name "geiser-repl")
  24. (declare-function geiser-eval--send/wait "geiser-eval")
  25. (declare-function geiser-eval--retort-error "geiser-eval")
  26. (declare-function geiser-mode "geiser-mode")
  27. (declare-function geiser-edit-symbol "geiser-edit")
  28. (defun lispy--eval-scheme (str)
  29. "Eval STR as Scheme code."
  30. (unless (geiser-repl--connection*)
  31. (save-window-excursion
  32. (if geiser-impl--implementation
  33. (run-geiser geiser-impl--implementation)
  34. (call-interactively 'run-geiser))
  35. (geiser-mode 1)))
  36. (when (string-match "(\\(?:define\\|set!\\|struct\\)[ (]+\\(\\(?:\\w\\|\\s_\\)+\\)" str)
  37. (let ((name (match-string 1 str)))
  38. (setq str (format "(begin %s %s)" str name))))
  39. (with-current-buffer (geiser-repl--buffer-name geiser-impl--implementation)
  40. (let* ((code `(:eval (:scm ,str)))
  41. (ret (geiser-eval--send/wait code))
  42. (err (geiser-eval--retort-error ret))
  43. (output-str (cdr (assoc 'output ret)))
  44. (result-str (cadr (assoc 'result ret))))
  45. (cond (err
  46. (format "Error: %s" (string-trim output-str)))
  47. ((not (equal "" output-str))
  48. (concat
  49. (propertize
  50. output-str
  51. 'face 'font-lock-string-face)
  52. "\n"
  53. result-str))
  54. (t
  55. result-str)))))
  56. (defun lispy-goto-symbol-scheme (symbol)
  57. (geiser-edit-symbol (make-symbol symbol)))
  58. (provide 'le-scheme)
  59. ;;; le-scheme.el ends here