Class: Relisp::ElispSlave

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

Overview

Provides an interface to an instance of emacs started as an IO object. See Relisp::Slave.

Constant Summary

Constants inherited from Slave

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

Instance Attribute 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

#initialize(cli_options = "--no-site-file --no-init-file", load_files = []) ⇒ ElispSlave

Start an emacs process, load the relisp library, and force the process to become a slave to ruby’s bidding. The string cli_options specifies arguments to pass to emacs on the command line, and load_files is array of files to load (with the ‘-l’ command line option) after the relisp.el library.



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/relisp/slaves.rb', line 323

def initialize(cli_options = "--no-site-file --no-init-file", load_files = [])
  super()
  # leave off '.el' to load relisp.elc if available
  elisp_path = File.expand_path(File.join(File.dirname(__FILE__), '../../src/relisp'))

  emacs_command = if RUBY_PLATFORM.downcase.include?('mswin')
                    "start emacs --batch "
                  else
                    "emacs --batch "
                  end
  emacs_command << cli_options
  emacs_command << " -l \"#{elisp_path}\""
  load_files.each do |file|
    emacs_command << " -l \"#{file}\""
  end
  emacs_command << " --eval '(relisp-become-slave)'"
  # In batch mode, emacs sends its normal output to stderr for
  # some reason.  I'm sure it's a good one...
  emacs_command << " 2>&1"
  @emacs_pipe = IO.popen(emacs_command, "w+")

  # gobble whatever output until emacs reports for duty
  until read_from_emacs.strip == "SEND CONSTANTS"; end
  send_constants
end

Dynamic Method Handling

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

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



349
350
351
# File 'lib/relisp/slaves.rb', line 349

def debug
  @debug
end

Instance Method Details

#debuggingObject

When given a block, runs the block with debugging turned on and then restores the former status of debug messages. Otherwise, toggles the status of debug messages.



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/relisp/slaves.rb', line 355

def debugging
  if block_given?
    debug_original_val = @debug
    begin
      @debug = true
      puts
      puts "-----------------"
      result = yield
    ensure
      @debug = debug_original_val
      puts "-----------------"
    end
    return result
  else
    @debug = ! @debug
  end
end