blob: 29d91f37bbac56e1b6c1fb537688745b149e4d01 (
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
;;; geiser-chez.el -- Chez Scheme's implementation of the geiser protocols
;; Author: Peter <craven@gmx.net>
;; Maintainer:
;; Keywords: languages, chez, scheme, geiser
;; Homepage: https://gitlab.com/emacs-geiser/chez
;; Package-Requires: ((emacs "24.4") (geiser-core "1.0"))
;; SPDX-License-Identifier: BSD-3-Clause
;; Version: 0.1
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Modified BSD License. You should
;; have received a copy of the license along with this program. If
;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
;;; Code:
(require 'geiser-connection)
(require 'geiser-syntax)
(require 'geiser-custom)
(require 'geiser-base)
(require 'geiser-eval)
(require 'geiser-edit)
(require 'geiser-log)
(require 'geiser)
(require 'compile)
(require 'info-look)
(eval-when-compile (require 'cl-lib))
;;; Customization:
(defgroup geiser-chez nil
"Customization for Geiser's Chez Scheme flavour."
:group 'geiser)
(geiser-custom--defcustom geiser-chez-binary
"scheme"
"Name to use to call the Chez Scheme executable when starting a REPL."
:type '(choice string (repeat string))
:group 'geiser-chez)
(geiser-custom--defcustom geiser-chez-init-file "~/.chez-geiser"
"Initialization file with user code for the Chez REPL."
:type 'string
:group 'geiser-chez)
(geiser-custom--defcustom geiser-chez-extra-command-line-parameters '()
"Additional parameters to supply to the Chez binary."
:type '(repeat string)
:group 'geiser-chez)
;;; REPL support:
(defun geiser-chez--binary ()
(if (listp geiser-chez-binary)
(car geiser-chez-binary)
geiser-chez-binary))
(defvar geiser-chez-scheme-dir
(expand-file-name "src" (file-name-directory load-file-name))
"Directory where the Chez scheme geiser modules are installed.")
(defun geiser-chez--parameters ()
"Return a list with all parameters needed to start Chez Scheme.
This function uses `geiser-chez-init-file' if it exists."
(let ((init-file (and (stringp geiser-chez-init-file)
(expand-file-name geiser-chez-init-file))))
`(,@(and init-file (file-readable-p init-file) (list init-file))
,(expand-file-name "geiser/geiser.ss" geiser-chez-scheme-dir)
,@geiser-chez-extra-command-line-parameters)))
(defconst geiser-chez--prompt-regexp "> ")
;;; Evaluation support:
(defun geiser-chez--geiser-procedure (proc &rest args)
(cl-case proc
((eval compile)
(let ((form (mapconcat 'identity (cdr args) " "))
(module (cond ((string-equal "'()" (car args))
"'()")
((and (car args))
(concat "'" (car args)))
(t
"#f"))))
(format "(geiser:eval %s '%s)" module form)))
((load-file compile-file)
(format "(geiser:load-file %s)" (car args)))
((no-values)
"(geiser:no-values)")
(t
(let ((form (mapconcat 'identity args " ")))
(format "(geiser:%s %s)" proc form)))))
(defun geiser-chez--get-module (&optional module)
(cond ((null module)
:f)
((listp module) module)
((stringp module)
(condition-case nil
(car (geiser-syntax--read-from-string module))
(error :f)))
(t :f)))
(defun geiser-chez--symbol-begin (module)
(if module
(max (save-excursion (beginning-of-line) (point))
(save-excursion (skip-syntax-backward "^(>") (1- (point))))
(save-excursion (skip-syntax-backward "^'-()>") (point))))
(defun geiser-chez--import-command (module)
(format "(import %s)" module))
(defun geiser-chez--exit-command () "(exit 0)")
;;
;; ;;; REPL startup
(defconst geiser-chez-minimum-version "9.4")
(defun geiser-chez--version (binary)
(car (process-lines binary "--version")))
(defun geiser-chez--startup (remote)
(let ((geiser-log-verbose-p t))
(compilation-setup t)
(geiser-eval--send/wait "(begin (import (geiser)) (write `((result ) (output . \"\"))) (newline))")))
(defun geiser-chez--display-error (module key msg)
(when (stringp msg)
(save-excursion (insert msg))
(geiser-edit--buttonize-files))
(and (or (eq key 'chez-error-message)
(not key))
(not (zerop (length msg)))
msg))
;;; Implementation definition:
(define-geiser-implementation chez
(binary geiser-chez--binary)
(arglist geiser-chez--parameters)
(version-command geiser-chez--version)
(minimum-version geiser-chez-minimum-version)
(repl-startup geiser-chez--startup)
(prompt-regexp geiser-chez--prompt-regexp)
(debugger-prompt-regexp nil) ;; geiser-chez--debugger-prompt-regexp
;; (enter-debugger geiser-chez--enter-debugger)
(marshall-procedure geiser-chez--geiser-procedure)
(find-module geiser-chez--get-module)
;; (enter-command geiser-chez--enter-command)
(exit-command geiser-chez--exit-command)
(import-command geiser-chez--import-command)
(find-symbol-begin geiser-chez--symbol-begin)
(display-error geiser-chez--display-error)
;; (external-help geiser-chez--manual-look-up)
;; (check-buffer geiser-chez--guess)
;; (keywords geiser-chez--keywords)
;; (case-sensitive geiser-chez-case-sensitive-p)
)
(geiser-impl--add-to-alist 'regexp "\\.ss$" 'chez t)
(geiser-impl--add-to-alist 'regexp "\\.def$" 'chez t)
(provide 'geiser-chez)
|