Class: Relisp::RubySlave

Inherits:
Slave show all
Defined in:
lib/relisp/slaves.rb

Overview

This class dedicates the ruby process to responding to queries from the emacs process that started it. See Relisp::Slave.

Constant Summary

Constants inherited from Slave

Slave::CONSTANTS, Slave::PREVIOUS_ELISP_RESULT, Slave::TRANSMISSION_CODES_REGEXP, Slave::VARIABLE_PREFIX

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Slave

#elisp_eval, #elisp_exec, #elisp_function?, #get_permanent_variable, #new_elisp_variable, #provide, #save_excursion, #with_current_buffer, #with_temp_buffer

Constructor Details

#initializeRubySlave

Can be provided with a block, in which case the block is run in the context of the slave. This makes slave methods available to the block without specifying an explicit receiver, and variables and functions defined in the block are in scope when requests from elisp are later evaluated.



248
249
250
251
252
253
254
255
256
# File 'lib/relisp/slaves.rb', line 248

def initialize
  super
  send_constants

  if block_given?
    yield self
    # start
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Relisp::Slave

Class Method Details

.startObject

Creates a new RubySlave and immediately starts it.



238
239
240
# File 'lib/relisp/slaves.rb', line 238

def self.start
  self.new.start
end

Instance Method Details

#startObject

Begin the main listening loop.



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/relisp/slaves.rb', line 260

def start
  write_to_emacs BEGIN_SLAVE_CODE
  write_to_emacs ANSWER_CODE

  begin
    loop do
      code = ''
      input = read_from_emacs
      until input.strip == QUESTION_CODE || input.strip == COMMAND_CODE
        code << input
        input = read_from_emacs
      end
      code.gsub!(/\n\z/, '')
      
      if input.strip == QUESTION_CODE
        write_to_emacs((eval code, @local_binding).to_elisp)
      else
        eval(code, @local_binding)
      end
      write_to_emacs ANSWER_CODE
    end
  rescue => dag_yo
    msg = dag_yo.message + "\n"
    dag_yo.backtrace.each do |b|
      msg << "  " + b + "\n" 
    end
    write_to_emacs msg.chomp
    #write_to_emacs(dag_yo.message)
    write_to_emacs ERROR_CODE
    retry
  end
end