summaryrefslogtreecommitdiff
path: root/elisp/geiser-larceny.el
blob: 7cc38163a17eb1da527d5f71383de329597298f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;; geiser-larceny.el -- larceny's implementation of the geiser protocols

;; Copyright (C) 2009 Jose Antonio Ortega Ruiz

;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Start date: Sun Mar 15, 2009 03:08

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3 of the License, or
;; (at your option) any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Comentary:

;; Implementation of all required Elisp Geiser protocols for Larceny.

;;; Code:

(require 'geiser-eval)
(require 'geiser-impl)
(require 'geiser-syntax)
(require 'geiser-custom)
(require 'geiser-base)


;;; Customization:

(defgroup geiser-larceny nil
  "Customization for Geiser's Larceny flavour."
  :group 'geiser)

(defcustom geiser-larceny-binary
  (cond ((eq system-type 'windows-nt) "larceny.exe")
        ((eq system-type 'darwin) "larceny")
        (t "larceny"))
  "Name to use to call the Larceny executable when starting a REPL."
  :type 'string
  :group 'geiser-larceny)

(defcustom geiser-larceny-mode 'err5rs
  "Mode to use when starting the Larceny REPL."
  :type '(choice (const :tag "ERR5RS" err5rs)
                 (const :tag "R5RS" 'r5rs))
  :group 'geiser-larceny)


;;; REPL support:

(defun geiser-larceny-parameters ()
  "Return a list with all parameters needed to start Larceny."
  `(,(if (eq 'r5rs geiser-larceny-mode) "-r5rs" "-err5rs")
    "-path" ,(expand-file-name "larceny/" geiser-scheme-dir)))

(defconst geiser-larceny-prompt-regexp "^\\(debug\\)?> ")

(defun geiser-larceny--startup ()
  (when (eq 'err5rs geiser-larceny-mode)
    (geiser-eval--send/wait '(import (rnrs))))
  (geiser-eval--send/wait '(require (geiser))))

(defun switch-to-larceny (&optional ask)
  (interactive "P")
  (switch-to-geiser ask 'larceny))

(defun run-larceny ()
  "Run Geiser using Larceny."
  (interactive)
  (run-geiser 'larceny))


;;; Evaluation support:

(defun geiser-larceny-geiser-procedure (proc)
  "Translate a bare procedure symbol to one executable in Larceny's
context. Return NULL for unsupported ones; at the very least,
EVAL, COMPILE, LOAD-FILE and COMPILE-FILE should be supported."
  (intern (format "ge:%s" proc)))

(defconst geiser-larceny--module-re
  "(library +\\(([^)]+)\\)")

(defun geiser-larceny-get-module (&optional module)
  "Return a scheme datum representing the current module.
If MODULE is provided, transform it to such a datum."
  (cond ((null module)
         (save-excursion
           (goto-char (point-min))
           (if (re-search-forward geiser-larceny--module-re nil t)
               (geiser-larceny-get-module (match-string-no-properties 1))
             :f)))
        ((listp module) module)
        ((stringp module) (or (ignore-errors (car (read-from-string module))) :f))
        (t :f)))


;;; Trying to ascertain whether a buffer is Larceny Scheme:

(defun geiser-larceny-guess ()
  "Return `t' if the current buffer looks like a Larceny file."
  (listp (geiser-larceny-get-module)) t)


;;; Register this implementation:

(geiser-impl--register 'larceny)



(provide 'geiser-larceny)
;;; geiser-larceny.el ends here