relisp 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (C) 2009 <don@ohspite.net>
2
+ # Copyright (C) 2009, 2010 Don March
3
3
  #
4
4
  # This file is part of Relisp.
5
5
  #
@@ -77,25 +77,26 @@
77
77
  # the +to_elisp+ method actually results in elisp code that, when run,
78
78
  # returns the appropriate object.
79
79
 
80
+ Relisp::Integer = Integer
81
+ Relisp::Float = Float
82
+ Relisp::Symbol = Symbol
83
+ Relisp::String = String
84
+ Relisp::HashTable = Hash
85
+
80
86
  module Relisp
81
87
 
82
- Integer = 1.class
83
88
  class Integer
84
89
  def self.from_elisp(object)
85
90
  object[:string].to_i
86
91
  end
87
92
  end
88
93
 
89
-
90
- Float = (3.14).class
91
94
  class Float
92
95
  def self.from_elisp(object)
93
96
  object[:string].to_f
94
97
  end
95
98
  end
96
99
 
97
-
98
- Symbol = :flag.class
99
100
  class Symbol
100
101
  def self.from_elisp(object)
101
102
  if object[:string] == 'nil'
@@ -103,11 +104,13 @@ module Relisp
103
104
  elsif object[:string] == 't'
104
105
  true
105
106
  else
107
+ # object[:string].gsub('-', '_').to_sym
106
108
  object[:string].to_sym
107
109
  end
108
110
  end
109
111
 
110
112
  def to_elisp
113
+ # "'" + self.to_s.gsub('_', '-')
111
114
  "'" + self.to_s
112
115
  end
113
116
 
@@ -134,48 +137,6 @@ module Relisp
134
137
  end
135
138
  end
136
139
 
137
- #
138
- # class Cons < Proxy
139
- # def self.from_elisp(object)
140
- # slave = object[:slave]
141
- # object_variable = slave.get_permanent_variable(object[:variable])
142
- # car = slave.elisp_eval("(car #{object_variable})")
143
- # cdr = slave.elisp_eval("(cdr #{object_variable})")
144
- # new(car, cdr)
145
- # end
146
-
147
- # def initialize(car, cdr)
148
- # @car = car
149
- # @cdr = cdr
150
- # end
151
-
152
- # attr_accessor :car, :cdr
153
-
154
- # def to_list
155
- # end
156
-
157
- # def inspect
158
- # to_s
159
- # end
160
-
161
- # def to_s
162
- # str = "(" + car.inspect
163
- # if @cdr
164
- # cdr = @cdr
165
- # while cdr.kind_of?(Cons)
166
- # str << " #{cdr.car.inspect}"
167
- # cdr = cdr.cdr
168
- # end
169
- # str << " . #{cdr.inspect}" unless cdr == nil
170
- # str << ")"
171
- # end
172
- # end
173
-
174
- # def to_elisp
175
- # str = "(cons #{@car.to_elisp} #{@cdr.to_elisp})"
176
- # end
177
- # end
178
-
179
140
  # A proxy to an Emacs cons. If the cons is actually a list, the
180
141
  # to_list method will convert it a subclass of Array so that all of
181
142
  # the ruby Array stuff is available.
@@ -209,41 +170,18 @@ module Relisp
209
170
  @slave.setcdr(@elisp_variable.value, newcdr)
210
171
  end
211
172
 
212
- # Return the +car+ of the Cons. (+car+).
213
- #
214
- def car
215
- @slave.car(@elisp_variable.value)
216
- end
173
+ ##
174
+ # :method: car
175
+ # car, cdr, cadr, etc. are taken care of by Proxy.method_missing.
217
176
 
218
- # Return the +cdr+ of the Cons. (+cdr+).
219
- #
220
- def cdr
221
- @slave.cdr(@elisp_variable.value)
222
- end
177
+ ##
178
+ # :method: cdr
223
179
 
224
- # Return the +car+ of the +car+ of the Cons. (+caar+)
225
- #
226
- def caar
227
- @slave.caar(@elisp_variable.value)
228
- end
180
+ ##
181
+ # :method: cadr
229
182
 
230
- # Return the +car+ of the +cdr+ of the Cons. (+cadr+)
231
- #
232
- def cadr
233
- @slave.cadr(@elisp_variable.value)
234
- end
235
-
236
- # Return the +cdr+ of the +car+ of the Cons. (+cdar+)
237
- #
238
- def cdar
239
- @slave.cadr(@elisp_variable.value)
240
- end
241
-
242
- # Return the +cdr+ of the +cdr+ of the Cons. (+cddr+)
243
- #
244
- def cddr
245
- @slave.cadr(@elisp_variable.value)
246
- end
183
+ ##
184
+ # :method: cdar
247
185
 
248
186
  # This function will NOT return true whenever the elisp function
249
187
  # <tt>listp</tt> is true. The elisp function is true whenever the
@@ -253,15 +191,21 @@ module Relisp
253
191
  # using the elisp function +list+.
254
192
  #
255
193
  def list?
256
- current_cdr = cdr
257
- while current_cdr.kind_of?(Cons)
258
- current_cdr = current_cdr.cdr
259
- end
260
- if current_cdr.nil?
261
- return true
262
- else
263
- return false
194
+ # current_cdr = cdr
195
+ # while current_cdr.kind_of?(Cons)
196
+ # current_cdr = current_cdr.cdr
197
+ # end
198
+ # return ! current_cdr.nil?
199
+
200
+ current_cdr_var = @slave.new_elisp_variable
201
+ @slave.elisp_exec "(setq #{current_cdr_var} (cdr #{to_elisp}))"
202
+ while @slave.elisp_eval "(consp #{current_cdr_var})"
203
+ @slave.elisp_exec "(setq #{current_cdr_var} (cdr #{current_cdr_var}))"
264
204
  end
205
+ cdr = @slave.elisp_eval "#{current_cdr_var}"
206
+ @slave.elisp_exec "(makunbound '#{current_cdr_var})"
207
+
208
+ return ! cdr
265
209
  end
266
210
 
267
211
  # Translate the cons cell into a Relisp::List, a subclass of
@@ -269,25 +213,43 @@ module Relisp
269
213
  #
270
214
  def to_list
271
215
  list_array = []
272
- list_array << car
273
- current_cdr = cdr
274
- while current_cdr.kind_of?(Cons)
275
- list_array << current_cdr.car
276
- current_cdr = current_cdr.cdr
216
+
217
+ # list_array << @slave.elisp_eval("(car #{to_elisp})")
218
+ # current_cdr = @slave.elisp_eval("(cdr #{to_elisp})")
219
+ # while current_cdr.kind_of?(Cons)
220
+ # list_array << @slave.elisp_eval("(car #{current_cdr.to_elisp})")
221
+ # current_cdr = @slave.elisp_eval("(cdr #{current_cdr.to_elisp})")
222
+ # end
223
+
224
+ # if current_cdr.nil?
225
+ # return Relisp::List.new(list_array)
226
+ # else
227
+ # return false
228
+ # end
229
+
230
+ current_cdr_var = @slave.new_elisp_variable
231
+
232
+ list_array << @slave.elisp_eval("(car #{to_elisp})")
233
+ @slave.elisp_exec "(setq #{current_cdr_var} (cdr #{to_elisp}))"
234
+ while @slave.elisp_eval "(consp #{current_cdr_var})"
235
+ list_array << @slave.elisp_eval("(car #{current_cdr_var})")
236
+ @slave.elisp_exec "(setq #{current_cdr_var} (cdr #{current_cdr_var}))"
277
237
  end
278
238
 
279
- if current_cdr.nil?
280
- return Relisp::List.new(list_array)
281
- else
282
- return false
239
+ cdr = @slave.elisp_eval "#{current_cdr_var}"
240
+
241
+ @slave.elisp_exec "(makunbound '#{current_cdr_var})"
242
+
243
+ if cdr
244
+ raise "Not a list: #{cdr}"
283
245
  end
246
+
247
+ return Relisp::List.new(list_array)
284
248
  end
285
249
 
286
250
  alias to_a to_list
287
-
288
251
  end
289
252
 
290
-
291
253
  class List < Array
292
254
  def self.from_elisp(object)
293
255
  new(super(object))
@@ -302,8 +264,6 @@ module Relisp
302
264
  end
303
265
  end
304
266
 
305
-
306
- String = "words, words, words".class
307
267
  class String
308
268
  def self.from_elisp(object)
309
269
  new(eval(object[:string]))
@@ -314,7 +274,6 @@ module Relisp
314
274
  end
315
275
  end
316
276
 
317
-
318
277
  class Vector < Array
319
278
  def self.from_elisp(object)
320
279
  new(super(object))
@@ -329,8 +288,6 @@ module Relisp
329
288
  end
330
289
  end
331
290
 
332
-
333
- HashTable = {:money => "power"}.class
334
291
  class HashTable
335
292
  def self.from_elisp(object)
336
293
  slave = object[:slave]
@@ -344,11 +301,11 @@ module Relisp
344
301
  slave.elisp_exec( "(setq #{keys_var} nil)" )
345
302
  slave.elisp_exec( "(setq #{vals_var} nil)" )
346
303
  slave.elisp_exec( "(maphash (lambda (key val)
347
- (setq #{keys_var} (append #{keys_var} (list key)))
348
- (setq #{vals_var} (append #{vals_var} (list val)))) #{object_variable})" )
349
- keys = slave.elisp_eval( keys_var )
350
- vals = slave.elisp_eval( vals_var )
351
- keys ||= nil
304
+ (setq #{keys_var} (append #{keys_var} (list key)))
305
+ (setq #{vals_var} (append #{vals_var} (list val))))
306
+ #{object_variable})" )
307
+ keys = Cons.new(keys_var, slave)
308
+ vals = Cons.new(vals_var, slave)
352
309
  keys = keys.to_list
353
310
  vals = vals.to_list
354
311
  hash = Hash.new
@@ -356,9 +313,9 @@ module Relisp
356
313
  hash[keys[i]] = vals[i]
357
314
  end
358
315
 
359
- slave.makunbound(object_variable)
360
- slave.makunbound(keys_var)
361
- slave.makunbound(vals_var)
316
+ [:object_variable, :keys_var, :vals_var]. each do |var|
317
+ slave.elisp_exec "(makunbound '#{var})"
318
+ end
362
319
 
363
320
  return hash
364
321
  end
@@ -375,7 +332,6 @@ module Relisp
375
332
 
376
333
  end
377
334
 
378
-
379
335
  # Every object is given a default +to_elisp+ method, and classes get a
380
336
  # dummy +from_elisp+ method.
381
337
  #
@@ -402,22 +358,19 @@ class NilClass
402
358
  end
403
359
  end
404
360
 
405
-
406
361
  class TrueClass
407
362
  def to_elisp
408
363
  "t"
409
364
  end
410
365
  end
411
366
 
412
-
413
367
  class FalseClass
414
- # Falseness in elisp is represented by 'nil'.
368
+ # Because falseness in elisp is represented by 'nil'.
415
369
  def to_elisp
416
370
  nil.to_elisp
417
371
  end
418
372
  end
419
373
 
420
-
421
374
  # The normal Array class is modified so that an array can be converted
422
375
  # to either Relisp::List or Relisp::Vector.
423
376
  #
@@ -1,3 +1,25 @@
1
+ #--
2
+ # Copyright (C) 2009, 2010 Don March
3
+ #
4
+ # This file is part of Relisp.
5
+ #
6
+ # Relisp is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Relisp is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+ #++
20
+ #
21
+ #
22
+
1
23
  module Relisp
2
24
 
3
25
  # Proxy contains the code that creates a wrapper around a variable
@@ -5,7 +27,8 @@ module Relisp
5
27
  #
6
28
  class Proxy
7
29
  def self.from_elisp(object)
8
- new(object[:variable], object[:slave])
30
+ slave = object[:slave]
31
+ new(slave.get_permanent_variable(object[:variable]), slave)
9
32
  end
10
33
 
11
34
  # If the last argument is a Relisp::Slave, it gets pulled off and
@@ -23,7 +46,8 @@ module Relisp
23
46
  end
24
47
 
25
48
  if args[0].kind_of?(Symbol) && args[1].nil?
26
- @elisp_variable = @slave.get_permanent_variable(args[0])
49
+ # @elisp_variable = @slave.get_permanent_variable(args[0])
50
+ @elisp_variable = args[0]
27
51
  elisp_type= ""
28
52
  self.class.to_s.split("::").last.split(//).each_with_index do |char, index|
29
53
  unless index==0 || char == char.downcase
@@ -47,14 +71,31 @@ module Relisp
47
71
  @elisp_variable
48
72
  end
49
73
 
74
+ def makunbound
75
+ @slave.makunbound @elisp_variable
76
+ end
77
+
78
+ def self.elisp_alias(ruby_name, elisp_name)
79
+ class_eval <<-EOM
80
+ def #{ruby_name}
81
+ call_on_self :#{elisp_name}
82
+ end
83
+ EOM
84
+ end
85
+
50
86
  private
51
87
 
52
88
  def call_on_self(function, *args)
53
89
  @slave.send(function, @elisp_variable.value, *args)
54
90
  end
91
+
92
+ def method_missing(function, *args)
93
+ call_on_self(function, *args)
94
+ end
55
95
  end
56
96
 
57
97
  end
58
98
 
59
99
  require 'relisp/type_conversion/editing_types'
60
100
  require 'relisp/type_conversion/programming_types'
101
+
data/lib/relisp.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (C) 2009 <don@ohspite.net>
2
+ # Copyright (C) 2009, 2010 Don March
3
3
  #
4
4
  # This file is part of Relisp.
5
5
  #
@@ -19,11 +19,14 @@
19
19
  #++
20
20
 
21
21
  module Relisp
22
- VERSION = '1.0.1'
22
+ VERSION = '1.1.0'
23
23
 
24
24
  class ElispError < RuntimeError; end
25
25
  end
26
26
 
27
+ $:.unshift File.dirname(__FILE__)
28
+
27
29
  require 'relisp/type_conversion'
28
30
  require 'relisp/elisp_functions'
29
31
  require 'relisp/slaves'
32
+
data/manual_test/tests.el CHANGED
@@ -16,5 +16,3 @@
16
16
  ;; should move text down and return t
17
17
  (ruby-eval "window_scroll_down")
18
18
 
19
- ;; create some windows and move them horizontally and vertically
20
- (ruby-eval "window_shrink")
data/manual_test/tests.rb CHANGED
@@ -31,34 +31,5 @@ def window_scroll_down
31
31
  selected_window.visible?(1)
32
32
  end
33
33
 
34
- def window_shrink
35
- w = selected_window
36
- w2 = w.split_vertically
37
- w3 = w2.split_horizontally
38
- 10.times do
39
- w.shrink(1)
40
- redisplay
41
- sleep 0.01
42
- end
43
- 10.times do
44
- w.enlarge(1)
45
- redisplay
46
- sleep 0.01
47
- end
48
- 10.times do
49
- w2.shrink(0,1)
50
- redisplay
51
- sleep 0.01
52
- end
53
- 10.times do
54
- w2.enlarge(0,1)
55
- redisplay
56
- sleep 0.01
57
- end
58
-
59
- w2.delete
60
- w3.delete
61
- end
62
-
63
34
  slave.start
64
35