relisp 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/README +22 -22
- data/Rakefile +4 -3
- data/examples/elisp_master/elisp_master.el +70 -34
- data/examples/elisp_master/ruby_slave.rb +37 -0
- data/examples/elisp_master/ruby_slave2.rb +33 -0
- data/examples/ruby_master/basic.rb +20 -0
- data/examples/ruby_master/debugging.rb +32 -0
- data/examples/ruby_master/elisp_data_types.rb +26 -0
- data/examples/ruby_master/method_missing.rb +24 -0
- data/examples/ruby_master/recursive_calling.rb +11 -0
- data/lib/relisp/elisp_functions.rb +30 -13
- data/lib/relisp/slaves.rb +39 -35
- data/lib/relisp/type_conversion/editing_types.rb +677 -643
- data/lib/relisp/type_conversion/programming_types.rb +70 -117
- data/lib/relisp/type_conversion.rb +43 -2
- data/lib/relisp.rb +5 -2
- data/manual_test/tests.el +0 -2
- data/manual_test/tests.rb +0 -29
- data/src/relisp.el +223 -220
- data/test/test_editing_types.rb +4 -3
- data/test/test_elisp_functions.rb +0 -1
- data/test/test_programming_types.rb +5 -4
- data/test/test_slaves.rb +2 -1
- metadata +15 -10
- data/examples/elisp_master/ruby_slave +0 -26
- data/examples/ruby_master/ruby_master_example +0 -27
- data/setup.rb +0 -1598
data/src/relisp.el
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
;;; relisp.el --- library for ruby/elisp interaction
|
2
2
|
|
3
|
-
;; Copyright (C) 2009
|
3
|
+
;; Copyright (C) 2009, 2010 Don March
|
4
|
+
|
5
|
+
;; Author: Don March <don@ohspite.net>
|
6
|
+
;; Created: 2009-01-25
|
7
|
+
;; Version: 1.1.0
|
8
|
+
;; Keywords: ruby emacs elisp bridge
|
4
9
|
|
5
10
|
;; This file is part of Relisp.
|
6
11
|
|
7
12
|
;; Relisp is free software; you can redistribute it and/or modify it
|
8
13
|
;; under the terms of the GNU General Public License as published by
|
9
|
-
;; the Free Software Foundation; either version
|
14
|
+
;; the Free Software Foundation; either version 3 of the License, or
|
10
15
|
;; (at your option) any later version.
|
11
16
|
|
12
17
|
;; Relisp is distributed in the hope that it will be useful, but
|
@@ -19,188 +24,101 @@
|
|
19
24
|
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
20
25
|
;; 02110-1301 USA
|
21
26
|
|
27
|
+
;;; Code:
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
(defun relisp-trim-leading-whitespace (str)
|
30
|
-
"Remove leading whitespace characters from STR."
|
31
|
-
(let ((s (if (symbolp str)(symbol-name str) str))
|
32
|
-
(whitespace-regexp "\\( \\|\f\\|\t\\|\n\\)"))
|
33
|
-
(save-excursion
|
34
|
-
(while (and
|
35
|
-
(not (null (string-match (concat "^" whitespace-regexp) s)))
|
36
|
-
(> (length s) (string-match (concat "^" whitespace-regexp) s)))
|
37
|
-
(setq s (replace-match "" t nil s))))
|
38
|
-
s))
|
39
|
-
|
40
|
-
(defun relisp-trim-trailing-whitespace (str)
|
41
|
-
"Remove trailing whitespace characters from STR."
|
42
|
-
(let ((s (if (symbolp str)(symbol-name str) str))
|
43
|
-
(whitespace-regexp "\\( \\|\f\\|\t\\|\n\\)"))
|
44
|
-
(save-excursion
|
45
|
-
(while (and
|
46
|
-
(not (null (string-match (concat whitespace-regexp "$") s)))
|
47
|
-
(> (length s) (string-match (concat whitespace-regexp "$") s)))
|
48
|
-
(setq s (replace-match "" t nil s))))
|
49
|
-
s))
|
50
|
-
|
51
|
-
(defun relisp-strip (str)
|
52
|
-
"Remove leading and trailing whitespace from STR."
|
53
|
-
(relisp-trim-leading-whitespace (relisp-trim-trailing-whitespace str)))
|
54
|
-
|
55
|
-
;;; now real stuff
|
56
|
-
|
57
|
-
(defvar relisp-slave-name "relisp-slave" "Name of the relisp ruby slave process.")
|
58
|
-
(defvar relisp-buffer-name "*Relisp*" "Name of the relisp output buffer.")
|
29
|
+
(defvar relisp-slave-name "relisp-slave"
|
30
|
+
"Name of the relisp ruby slave process.")
|
31
|
+
(defvar relisp-buffer-name "*Relisp*"
|
32
|
+
"Name of the relisp output buffer.")
|
33
|
+
(defvar relisp-endofmessage-regexp nil
|
34
|
+
"A regexp that matches codes indicating a message termination.")
|
59
35
|
|
60
36
|
;; to prohibit free variable warnings
|
61
37
|
(defvar relisp-emacs-master-p t)
|
62
38
|
(defvar relisp-slave-process)
|
63
|
-
(defvar relisp-ruby-output)
|
64
39
|
(defvar relisp-begin-answer-code)
|
65
40
|
(defvar relisp-answer-code)
|
66
41
|
(defvar relisp-question-code)
|
67
42
|
(defvar relisp-command-code)
|
68
43
|
(defvar relisp-error-code)
|
69
|
-
(defvar relisp-
|
44
|
+
(defvar relisp-begin-slave-code)
|
70
45
|
(defvar relisp-previous-result)
|
71
46
|
|
72
|
-
(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
(get-buffer-create relisp-buffer-name)
|
77
|
-
(unless (string-match (relisp-endofmessage-regexp) (relisp-strip text))
|
78
|
-
(set-buffer relisp-buffer-name)
|
79
|
-
(goto-char (point-max))
|
80
|
-
(insert text "\n")))))
|
47
|
+
(put 'relisp-ruby-error
|
48
|
+
'error-conditions '(error relisp-ruby-error))
|
49
|
+
(put 'relisp-ruby-error
|
50
|
+
'error-message "Error in ruby process")
|
81
51
|
|
82
|
-
(defun relisp-
|
83
|
-
"Send MESSAGE to the ruby
|
52
|
+
(defun relisp-ruby-send (message &optional process)
|
53
|
+
"Send MESSAGE to the slave or master ruby PROCESS.
|
54
|
+
PROCESS defaults to `relisp-slave-process' when nil."
|
84
55
|
(if relisp-emacs-master-p
|
85
|
-
(
|
56
|
+
(progn
|
57
|
+
(or process (setq process relisp-slave-process))
|
58
|
+
(process-send-string process (concat message "\n")))
|
86
59
|
(message message)))
|
87
60
|
|
88
|
-
(defun relisp-
|
89
|
-
"Accept
|
90
|
-
(
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
(
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
(
|
105
|
-
|
106
|
-
(let ((output "")
|
107
|
-
|
108
|
-
|
109
|
-
(setq output-line (read-from-minibuffer ""))
|
110
|
-
(setq output (concat output output-line)))
|
61
|
+
(defun relisp-ruby-slave-read (&optional process terminator-regexp)
|
62
|
+
"Accept a full message from ruby slave."
|
63
|
+
(or process (setq process relisp-slave-process))
|
64
|
+
(or terminator-regexp
|
65
|
+
(setq terminator-regexp relisp-endofmessage-regexp))
|
66
|
+
(let ((buffer (process-buffer process)))
|
67
|
+
(with-current-buffer buffer
|
68
|
+
(delete-region (point-min) (point-max)))
|
69
|
+
(while (and (relisp-slave-alive-p process)
|
70
|
+
(not (string-match terminator-regexp
|
71
|
+
(with-current-buffer buffer (buffer-string)))))
|
72
|
+
(accept-process-output process nil nil t))
|
73
|
+
(with-current-buffer buffer (buffer-string))))
|
74
|
+
|
75
|
+
(defun relisp-ruby-master-read (&optional terminator-regexp)
|
76
|
+
"Accept a full message from ruby master."
|
77
|
+
(or terminator-regexp
|
78
|
+
(setq terminator-regexp relisp-endofmessage-regexp))
|
79
|
+
(let ((output ""))
|
80
|
+
(while (not (string-match terminator-regexp output))
|
81
|
+
(setq output (concat output (read-from-minibuffer ""))))
|
111
82
|
output))
|
112
83
|
|
113
|
-
(defun relisp-
|
114
|
-
"
|
115
|
-
(
|
116
|
-
"\\|" relisp-command-code
|
117
|
-
"\\|" relisp-answer-code
|
118
|
-
"\\|" relisp-error-code
|
119
|
-
"\\)"
|
120
|
-
"[[:space:]]*"))
|
121
|
-
|
122
|
-
(defun relisp-receive-answer nil
|
123
|
-
"Handle messages from emacs after ruby-eval or ruby-exec are called."
|
124
|
-
(let ((message (relisp-read-from-ruby)))
|
125
|
-
(while (or (string-match relisp-question-code message)
|
126
|
-
(string-match relisp-command-code message))
|
127
|
-
(if (string-match relisp-question-code message)
|
128
|
-
(relisp-answer-ruby message)
|
129
|
-
(relisp-obey-ruby message))
|
130
|
-
(setq message (relisp-read-from-ruby)))
|
131
|
-
message))
|
132
|
-
|
133
|
-
(defun ruby-exec (ruby-code)
|
134
|
-
"Have ruby evaluate RUBY-CODE without returning the result.
|
135
|
-
Reads input from the minibuffer unless an argument is
|
136
|
-
given."
|
137
|
-
(interactive "Mruby> ")
|
138
|
-
(let (message result)
|
139
|
-
(if (and relisp-emacs-master-p (not (relisp-slave-alive-p)))
|
140
|
-
(relisp-start-slave))
|
141
|
-
(relisp-log (concat "lisp!> " ruby-code))
|
142
|
-
(relisp-write-to-ruby (relisp-form-command ruby-code))
|
143
|
-
(setq message (relisp-receive-answer))
|
144
|
-
(setq relisp-ruby-return (relisp-strip (car (split-string message relisp-answer-code))))
|
145
|
-
(relisp-log "")
|
146
|
-
(setq result (if (string-match (concat "\n?" relisp-error-code "[[:space:]]*") relisp-ruby-return)
|
147
|
-
(concat "RUBY ERROR: " (replace-match "" nil t relisp-ruby-return))
|
148
|
-
nil))
|
149
|
-
(if (and (interactive-p) (not (null result)))
|
150
|
-
(message (prin1-to-string result)))
|
151
|
-
result))
|
152
|
-
|
153
|
-
(defun ruby-eval (ruby-code)
|
154
|
-
"Have ruby evaluate RUBY-CODE and return the result.
|
155
|
-
The result is an elisp object equivalent to the ruby result of
|
156
|
-
RUBY-CODE. Reads input from the minibuffer unless an argument is
|
157
|
-
given."
|
158
|
-
(interactive "Mruby> ")
|
159
|
-
(let (message result)
|
160
|
-
(if (and relisp-emacs-master-p (not (relisp-slave-alive-p)))
|
161
|
-
(relisp-start-slave))
|
162
|
-
(relisp-log (concat "lisp?> " ruby-code))
|
163
|
-
(relisp-write-to-ruby (relisp-form-question ruby-code))
|
164
|
-
(setq message (relisp-receive-answer))
|
165
|
-
(setq relisp-ruby-return (relisp-strip (car (split-string message relisp-answer-code))))
|
166
|
-
(relisp-log (concat "ruby=> " relisp-ruby-return "\n"))
|
167
|
-
(setq result (if (string-match (concat "\n?" relisp-error-code "[[:space:]]*") relisp-ruby-return)
|
168
|
-
(concat "RUBY ERROR: " (replace-match "" nil t relisp-ruby-return))
|
169
|
-
(eval (read (relisp-trim-trailing-whitespace relisp-ruby-return)))))
|
170
|
-
(if (interactive-p)
|
171
|
-
(message (prin1-to-string result)))
|
172
|
-
result))
|
173
|
-
|
174
|
-
(defun relisp-answer-ruby (question)
|
175
|
-
"Evaluate the QUESTION from ruby and send ruby the result."
|
176
|
-
(setq question (relisp-strip (car (split-string question relisp-question-code))))
|
177
|
-
(relisp-log (concat "ruby?> " question))
|
178
|
-
(setq question (read question))
|
179
|
-
(condition-case error-description
|
84
|
+
(defun relisp-ruby-read (&optional process terminator-regexp)
|
85
|
+
"Accept ruby message, stopping at a match to TERMINATOR-REGEXP."
|
86
|
+
(if relisp-emacs-master-p
|
180
87
|
(progn
|
181
|
-
(
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
(
|
192
|
-
|
193
|
-
|
194
|
-
(
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
88
|
+
(relisp-ruby-slave-read process terminator-regexp))
|
89
|
+
(relisp-ruby-master-read terminator-regexp)))
|
90
|
+
|
91
|
+
;; From here on out, no more process stuff
|
92
|
+
|
93
|
+
(defun relisp-strip (str &optional side)
|
94
|
+
"Return STR stripped of leading and/or trailing whitespace.
|
95
|
+
|
96
|
+
If SIDE is 'start (or 'leading) or 'end (or 'trailing), only trim
|
97
|
+
whitespace on that side of the string."
|
98
|
+
(when (not (memq side '(end trailing)))
|
99
|
+
(when (string-match "^[\n\t\r\f\v ]+" str)
|
100
|
+
(setq str (replace-match "" nil nil str))))
|
101
|
+
(when (not (memq side '(start leading)))
|
102
|
+
(when (string-match "[\n\t\r\f\v ]+$" str)
|
103
|
+
(setq str (replace-match "" nil nil str))))
|
104
|
+
str)
|
105
|
+
|
106
|
+
(defun relisp-log (&optional text)
|
107
|
+
"Insert TEXT at the end of the log buffer, when emacs is mater."
|
108
|
+
(or text (setq text ""))
|
109
|
+
(when (and relisp-emacs-master-p
|
110
|
+
(if (and (boundp 'relisp-endofmessage-regexp)
|
111
|
+
relisp-endofmessage-regexp)
|
112
|
+
(and (not (string-match relisp-endofmessage-regexp (relisp-strip text)))
|
113
|
+
(not (string-match relisp-begin-slave-code (relisp-strip text))))
|
114
|
+
t)
|
115
|
+
(with-current-buffer (get-buffer-create relisp-buffer-name)
|
116
|
+
(goto-char (point-max))
|
117
|
+
(insert text "\n")))))
|
203
118
|
|
119
|
+
;; relisp-form-command and -question convert the argument to a string,
|
120
|
+
;; if necessary, to catch end cases like `nil', but -form-answer and
|
121
|
+
;; -error always take raw code as arguments.
|
204
122
|
(defun relisp-form-command (code)
|
205
123
|
"Return a string that tells ruby to evaluate CODE."
|
206
124
|
(unless (stringp code)
|
@@ -224,94 +142,179 @@ given."
|
|
224
142
|
(concat code "\n" relisp-error-code))
|
225
143
|
|
226
144
|
(defun relisp-to-ruby (object)
|
227
|
-
"Return a string that, when evaluated in ruby, results in OBJECT.
|
145
|
+
"Return a string that, when evaluated in ruby, results in OBJECT.
|
146
|
+
This function is deprecated."
|
228
147
|
(let ((var (ruby-eval "new_elisp_variable")))
|
229
148
|
(set var object)
|
230
149
|
(concat "elisp_eval('" (prin1-to-string var) "')")))
|
231
150
|
|
151
|
+
(defun relisp-ruby-receive (&optional process safe)
|
152
|
+
"Handle messages from emacs after ruby-eval or ruby-exec are called."
|
153
|
+
(let ((message (relisp-ruby-read process))
|
154
|
+
question)
|
155
|
+
(while (or (setq questionp (string-match relisp-question-code message))
|
156
|
+
(string-match relisp-command-code message))
|
157
|
+
(relisp-exec (relisp-strip (car (split-string message relisp-endofmessage-regexp)))
|
158
|
+
questionp)
|
159
|
+
(setq message (relisp-ruby-read process)))
|
160
|
+
(setq message (relisp-strip (car (split-string message relisp-answer-code))))
|
161
|
+
(relisp-log (concat "ruby=> " message "\n"))
|
162
|
+
(when (and (not safe) (string-match relisp-error-code message))
|
163
|
+
(signal 'relisp-ruby-error (list (replace-match "" nil t message))))
|
164
|
+
message))
|
165
|
+
|
166
|
+
(defun ruby-exec (ruby-code &optional process return)
|
167
|
+
"Have ruby evaluate RUBY-CODE, returning result if RETURN is non-nil.
|
168
|
+
The result is an elisp object equivalent to the ruby result of
|
169
|
+
RUBY-CODE. Reads input from the minibuffer unless an argument is
|
170
|
+
given."
|
171
|
+
(interactive "Mruby> ")
|
172
|
+
(let (result)
|
173
|
+
(if (and relisp-emacs-master-p (not (relisp-slave-alive-p)))
|
174
|
+
(relisp-start-slave))
|
175
|
+
(relisp-log (concat "lisp"
|
176
|
+
(if return "?" "!")
|
177
|
+
"> " ruby-code))
|
178
|
+
(relisp-ruby-send (if return
|
179
|
+
(relisp-form-question ruby-code)
|
180
|
+
(relisp-form-command ruby-code))
|
181
|
+
process)
|
182
|
+
(setq result (if return (eval (read (relisp-ruby-receive process)))
|
183
|
+
(relisp-ruby-receive process)))
|
184
|
+
(when (and return (interactive-p))
|
185
|
+
(message (prin1-to-string result)))
|
186
|
+
result))
|
187
|
+
|
188
|
+
(defun ruby-eval (ruby-code &optional process)
|
189
|
+
"Have ruby evaluate RUBY-CODE and return the result."
|
190
|
+
(ruby-exec ruby-code process t))
|
191
|
+
|
192
|
+
(defun relisp-exec (lisp-code &optional return)
|
193
|
+
"Evaluate the LISP-CODE from ruby.
|
194
|
+
Send ruby the result if RETURN is non-nil."
|
195
|
+
(relisp-log (concat (if return "ruby?> " "ruby! ")
|
196
|
+
lisp-code))
|
197
|
+
(setq lisp-code (read lisp-code))
|
198
|
+
(condition-case error-description
|
199
|
+
(progn
|
200
|
+
(set relisp-previous-result (eval lisp-code))
|
201
|
+
(if (not return)
|
202
|
+
(relisp-ruby-send (relisp-form-answer nil))
|
203
|
+
(relisp-log (concat "lisp=> "
|
204
|
+
(prin1-to-string (type-of (symbol-value relisp-previous-result)))))
|
205
|
+
(relisp-log (concat " => "
|
206
|
+
(prin1-to-string (symbol-value relisp-previous-result))))
|
207
|
+
(relisp-ruby-send relisp-begin-answer-code)
|
208
|
+
(relisp-ruby-send (prin1-to-string (type-of (symbol-value relisp-previous-result))))
|
209
|
+
(relisp-ruby-send (relisp-form-answer (symbol-value relisp-previous-result)))))
|
210
|
+
(error (relisp-ruby-send
|
211
|
+
(relisp-form-error
|
212
|
+
(error-message-string error-description))))))
|
213
|
+
|
214
|
+
(defun relisp-eval (lisp-code)
|
215
|
+
"Evaluate the LISP-CODE from ruby and send ruby the result."
|
216
|
+
(relisp-exec lisp-code t))
|
217
|
+
|
232
218
|
(defun relisp-get-constant nil
|
233
219
|
"Return the next constant passed from ruby.
|
234
220
|
Intended to be called from relisp-get-constants."
|
235
|
-
(
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
(let ((result (relisp-strip relisp-ruby-output)))
|
241
|
-
(setq relisp-ruby-output "")
|
242
|
-
result))
|
243
|
-
(message "(prompt)")
|
244
|
-
(read-from-minibuffer "")))
|
221
|
+
(relisp-ruby-send "(prompt)")
|
222
|
+
(relisp-strip (relisp-ruby-read nil
|
223
|
+
(if relisp-emacs-master-p
|
224
|
+
"\n"
|
225
|
+
"."))))
|
245
226
|
|
246
227
|
(defun relisp-get-constants nil
|
247
228
|
"Sets all relisp constants shared between ruby and emacs.
|
248
229
|
Intended to be called from relisp-start-slave and
|
249
230
|
relisp-become-slave."
|
250
|
-
(
|
251
|
-
|
252
|
-
(setq relisp-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
231
|
+
(when (not relisp-emacs-master-p)
|
232
|
+
(relisp-ruby-send "SEND CONSTANTS"))
|
233
|
+
(setq relisp-question-code (relisp-get-constant)
|
234
|
+
relisp-command-code (relisp-get-constant)
|
235
|
+
relisp-begin-answer-code (relisp-get-constant)
|
236
|
+
relisp-answer-code (relisp-get-constant)
|
237
|
+
relisp-error-code (relisp-get-constant)
|
238
|
+
relisp-begin-slave-code (relisp-get-constant)
|
239
|
+
relisp-previous-result (read (relisp-get-constant)))
|
240
|
+
(relisp-ruby-send "(got constants)")
|
241
|
+
(setq relisp-endofmessage-regexp
|
242
|
+
(concat relisp-question-code "\\|"
|
243
|
+
relisp-command-code "\\|"
|
244
|
+
relisp-answer-code "\\|"
|
245
|
+
relisp-error-code)))
|
246
|
+
|
247
|
+
(defun relisp-start-slave (&optional slave-path new)
|
258
248
|
"Start a ruby slave process to do emacs's bidding.
|
259
249
|
If SLAVE-PATH is given, then that Ruby file is read and the
|
260
250
|
Relisp::RubySlave object must be started in that file. Otherwise
|
261
251
|
emacs starts a ruby process and starts a RubySlave on its own."
|
262
252
|
(interactive)
|
263
253
|
(setq relisp-emacs-master-p t)
|
264
|
-
(relisp-stop-slave)
|
265
|
-
(
|
266
|
-
|
267
|
-
(
|
254
|
+
(unless new (relisp-stop-slave))
|
255
|
+
(if (and slave-path
|
256
|
+
(not (string= slave-path "")))
|
257
|
+
(if (file-exists-p slave-path)
|
258
|
+
(setq relisp-slave-process (start-process relisp-slave-name nil "ruby" slave-path))
|
259
|
+
(error (concat "Ruby slave does not exist: " slave-path)))
|
268
260
|
(setq relisp-slave-process (start-process relisp-slave-name nil
|
269
261
|
"ruby"
|
262
|
+
"-rubygems"
|
270
263
|
"-x"))
|
271
|
-
(process-send-string relisp-slave-
|
272
|
-
|
264
|
+
(process-send-string relisp-slave-process
|
265
|
+
; with `-x' ruby ignores everything until a
|
266
|
+
; line with `#! ruby'.
|
267
|
+
(concat "#! ruby"
|
268
|
+
;; something really weird is going on
|
269
|
+
;; with the bindings here; if you
|
270
|
+
;; comment out any of the next 3
|
271
|
+
;; lines then $: isn't set
|
272
|
+
;; properly. `$__RELISP__' is a
|
273
|
+
;; throwaway variable.
|
273
274
|
"$:.unshift File.join(File.dirname('" (symbol-file 'relisp-slave-name) "'), '../lib')\n"
|
274
|
-
"
|
275
|
+
"$__RELISP__=$:\n"
|
276
|
+
"$__RELISP__.unshift File.join(File.dirname('" (symbol-file 'relisp-slave-name) "'), '../lib')\n"
|
275
277
|
"require 'relisp'\n"
|
276
278
|
"Relisp::RubySlave.new.start\n"
|
277
279
|
"__END__\n")))
|
278
|
-
(set-process-
|
280
|
+
(set-process-buffer relisp-slave-process
|
281
|
+
(generate-new-buffer (concat " " (process-name relisp-slave-process))))
|
279
282
|
(relisp-get-constants)
|
283
|
+
(relisp-log (concat "started: " (prin1-to-string relisp-slave-process)))
|
284
|
+
; gobble up initial ruby messages and respond
|
285
|
+
(while (and (relisp-slave-alive-p)
|
286
|
+
(not (string= relisp-begin-slave-code
|
287
|
+
(relisp-ruby-receive relisp-slave-process)))))
|
288
|
+
(if (relisp-slave-alive-p)
|
289
|
+
(relisp-log (concat "startup finished: " (prin1-to-string relisp-slave-process)))
|
290
|
+
(relisp-log (concat "finished: " (prin1-to-string relisp-slave-process))))
|
280
291
|
relisp-slave-process)
|
281
292
|
|
282
293
|
(defun relisp-become-slave nil
|
283
294
|
"Convert the emacs process into a slave. Only called by ruby."
|
284
295
|
(setq relisp-emacs-master-p nil)
|
285
|
-
;; get constants
|
286
|
-
(message "SEND CONSTANTS")
|
287
296
|
(relisp-get-constants)
|
288
|
-
(
|
289
|
-
(
|
290
|
-
(setq input "")
|
291
|
-
(setq input-line "")
|
292
|
-
(while (and (null (string-match relisp-question-code (relisp-strip input-line)))
|
293
|
-
(null (string-match relisp-command-code (relisp-strip input-line))))
|
294
|
-
(setq input-line (read-from-minibuffer ""))
|
295
|
-
(setq input (concat input input-line)))
|
296
|
-
(if (string-match relisp-question-code (relisp-strip input-line))
|
297
|
-
(relisp-answer-ruby input)
|
298
|
-
(relisp-obey-ruby input)))))
|
299
|
-
|
300
|
-
(defun relisp-slave-output-filter (process output-line)
|
301
|
-
"Listen to PROCESS and add each OUTPUT-LINE to `relisp-ruby-output'."
|
302
|
-
(setq relisp-ruby-output (concat relisp-ruby-output output-line)))
|
303
|
-
|
304
|
-
(defun relisp-stop-slave nil
|
305
|
-
"Kill the ruby slave process."
|
306
|
-
(interactive)
|
307
|
-
(if (boundp 'relisp-slave-process)
|
308
|
-
(delete-process relisp-slave-process)))
|
297
|
+
(while t ;; loop is only a CL function, I guess
|
298
|
+
(relisp-ruby-receive nil t)))
|
309
299
|
|
310
|
-
(defun relisp-slave
|
311
|
-
"
|
312
|
-
(
|
313
|
-
|
314
|
-
|
315
|
-
|
300
|
+
(defun relisp-stop-slave (&optional process)
|
301
|
+
"Kill the ruby slave PROCESS."
|
302
|
+
(interactive)
|
303
|
+
(or process (if (boundp 'relisp-slave-process)
|
304
|
+
(setq process relisp-slave-process)))
|
305
|
+
(when (and process
|
306
|
+
(relisp-slave-alive-p process))
|
307
|
+
(kill-buffer (process-buffer process))
|
308
|
+
(relisp-log (concat "stopped: " (prin1-to-string process)))
|
309
|
+
(delete-process process)))
|
310
|
+
|
311
|
+
(defun relisp-slave-alive-p (&optional process)
|
312
|
+
"Return whether the ruby slave PROCESS is alive and well."
|
313
|
+
(if process
|
314
|
+
(equal (process-status process) 'run)
|
315
|
+
(and (boundp 'relisp-slave-process)
|
316
|
+
(equal (process-status relisp-slave-process) 'run))))
|
316
317
|
|
317
318
|
(provide 'relisp)
|
319
|
+
|
320
|
+
;;; relisp.el ends here
|
data/test/test_editing_types.rb
CHANGED
@@ -31,7 +31,7 @@ module TestRelisp
|
|
31
31
|
test_buffer_name = "*relisp-test-buffer*"
|
32
32
|
buffer = @emacs.elisp_eval( "(create-file-buffer \"#{test_buffer_name}\") " )
|
33
33
|
assert_kind_of Relisp::Buffer, buffer
|
34
|
-
buffer_names = @emacs.elisp_eval( '(buffer-list)' ).to_list.map { |
|
34
|
+
buffer_names = @emacs.elisp_eval( '(buffer-list)' ).to_list.map { |b| b.name }
|
35
35
|
assert buffer_names.include?(test_buffer_name)
|
36
36
|
end
|
37
37
|
|
@@ -61,7 +61,7 @@ module TestRelisp
|
|
61
61
|
test_buffer_name = "*relisp-test-buffer*"
|
62
62
|
buffer = @emacs.elisp_eval( "(create-file-buffer \"#{test_buffer_name}\") " )
|
63
63
|
assert_kind_of Relisp::Buffer, buffer
|
64
|
-
buffer_names = @emacs.elisp_eval( '(buffer-list)' ).to_list.map { |
|
64
|
+
buffer_names = @emacs.elisp_eval( '(buffer-list)' ).to_list.map { |b| b.name }
|
65
65
|
assert buffer_names.include?(test_buffer_name)
|
66
66
|
end
|
67
67
|
|
@@ -488,7 +488,8 @@ module TestRelisp
|
|
488
488
|
|
489
489
|
class TestFrame < Test::Unit::TestCase
|
490
490
|
def setup
|
491
|
-
@emacs = Relisp::ElispSlave.new
|
491
|
+
# @emacs = Relisp::ElispSlave.new
|
492
|
+
@emacs = EMACS
|
492
493
|
end
|
493
494
|
|
494
495
|
def test_class_from_elisp
|
@@ -128,8 +128,10 @@ module TestRelisp
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def test_initialize
|
131
|
-
new_cons = Relisp::Cons.new(
|
131
|
+
new_cons = Relisp::Cons.new(4, 5, @emacs)
|
132
132
|
assert_equal :cons, @emacs.type_of(new_cons)
|
133
|
+
assert_equal 4, new_cons.car
|
134
|
+
assert_equal 5, new_cons.cdr
|
133
135
|
end
|
134
136
|
|
135
137
|
def test_car
|
@@ -167,10 +169,9 @@ module TestRelisp
|
|
167
169
|
result = @emacs.elisp_eval( "'(1 2 3)" ).to_list
|
168
170
|
assert_equal [1, 2, 3], result
|
169
171
|
result = @emacs.elisp_eval( "'(1 . 2)" )
|
170
|
-
|
172
|
+
assert_raise(RuntimeError) { result.to_list }
|
171
173
|
end
|
172
|
-
|
173
|
-
end
|
174
|
+
end
|
174
175
|
|
175
176
|
class TestList < Test::Unit::TestCase
|
176
177
|
def setup
|
data/test/test_slaves.rb
CHANGED
@@ -5,11 +5,12 @@ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
|
|
5
5
|
$:.unshift File.dirname(__FILE__) + "/../lib"
|
6
6
|
require 'relisp'
|
7
7
|
|
8
|
-
EMACS
|
8
|
+
EMACS ||= Relisp::ElispSlave.new
|
9
9
|
|
10
10
|
module TestRelisp
|
11
11
|
class TestElispSlave < Test::Unit::TestCase
|
12
12
|
def setup
|
13
|
+
# @emacs = Relisp::ElispSlave.new
|
13
14
|
@emacs = EMACS
|
14
15
|
end
|
15
16
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relisp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Don
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-05 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,8 +49,13 @@ files:
|
|
49
49
|
- README
|
50
50
|
- Rakefile
|
51
51
|
- examples/elisp_master/elisp_master.el
|
52
|
-
- examples/elisp_master/ruby_slave
|
53
|
-
- examples/
|
52
|
+
- examples/elisp_master/ruby_slave.rb
|
53
|
+
- examples/elisp_master/ruby_slave2.rb
|
54
|
+
- examples/ruby_master/basic.rb
|
55
|
+
- examples/ruby_master/debugging.rb
|
56
|
+
- examples/ruby_master/elisp_data_types.rb
|
57
|
+
- examples/ruby_master/method_missing.rb
|
58
|
+
- examples/ruby_master/recursive_calling.rb
|
54
59
|
- lib/relisp.rb
|
55
60
|
- lib/relisp/elisp_functions.rb
|
56
61
|
- lib/relisp/slaves.rb
|
@@ -59,7 +64,6 @@ files:
|
|
59
64
|
- lib/relisp/type_conversion/programming_types.rb
|
60
65
|
- manual_test/tests.el
|
61
66
|
- manual_test/tests.rb
|
62
|
-
- setup.rb
|
63
67
|
- src/relisp.el
|
64
68
|
- test/test_editing_types.rb
|
65
69
|
- test/test_elisp_functions.rb
|
@@ -76,13 +80,14 @@ post_install_message: |
|
|
76
80
|
The gem is installed, and you can now call elisp from ruby. But if
|
77
81
|
you want to call ruby from emacs (and you do, right?) you need to go
|
78
82
|
into the 'src' directory of this gem and copy 'relisp.el' and/or
|
79
|
-
'relisp.elc' to your elisp folder (probably
|
80
|
-
might want to add the
|
83
|
+
'relisp.elc' to your elisp folder (probably something like
|
84
|
+
'~/.emacs.d/site-lisp' or '~/.elisp'). Then you might want to add the
|
85
|
+
lines
|
81
86
|
|
82
87
|
(autoload 'relisp-start-slave "relisp" nil t)
|
83
88
|
(autoload 'ruby-eval "relisp" nil t)
|
84
89
|
|
85
|
-
to your emacs initialization file (
|
90
|
+
to your emacs initialization file ('~/.emacs' or ~/.emacs.d/init.el).
|
86
91
|
|
87
92
|
If you don't know where to find the files for this gem, run the
|
88
93
|
command "gem env gemdir". Or you can download the tarball for this
|