Hi,

At Mon, 13 May 2002 16:27:44 +0900,
Jean-Hugues ROBERT wrote:
> However I still have an issue because I cannot bind that function to
> the key sequence that normally invokes ruby-load-file. I tried:
> (add-hook 'inf-ruby-load-hook
>    (function (lambda ()
>      (define-key ruby-mode-map "\C-c\C-l" 'ruby-load-current-buffer)
>    ))
> )
> ... But apparently this has no effects. As a workaround, I modified
> inf-ruby.el itself; works OK, but I would rather avoid doing that.

inf-ruby-load-hook is run only when inf-ruby.el is loaded, so
the add-hook after it has no effect.  If inf-ruby is already
loaded, you need to define-key directly.

Following function feeds the current buffer without prefix-arg
or prompts to select buffer, and pops up run-ruby buffer.
Also, in inferior-ruby-mode, inferior-ruby-load-buffer loads
selected buffer.

(defun ruby-load-buffer (&optional buffer)
  "Load buffer's Ruby file into the inferior Ruby process.
Saving the buffer first if needed."
  (interactive (list
		(if current-prefix-arg
		    (get-buffer (read-buffer "Load Ruby buffer: "
					     (current-buffer))))))
  (or buffer (setq buffer (current-buffer)))
  (let ((proc (ruby-proc)))
    (save-excursion
      (set-buffer buffer)
      (or (eq major-mode 'ruby-mode)
	  (error "Not ruby mode"))
      (save-buffer buffer))
    (pop-to-buffer (process-buffer proc))
    (comint-send-string
     proc
     (concat "(load '" (buffer-file-name buffer) "'\)\n"))))

(defun inferior-ruby-load-buffer (buffer)
  (interactive "bLoad Ruby buffer: ")
  (ruby-load-buffer (get-buffer buffer)))

(let ((hook (function (lambda ()
			(define-key ruby-mode-map "\C-c\C-l" 'ruby-load-buffer)
			(define-key inferior-ruby-mode-map "\C-cl" 'inferior-ruby-load-buffer)
			))))
  (if (featurep 'inf-ruby)
      (progn (require 'ruby-mode)
	     (funcall hook))
  (add-hook 'inf-ruby-load-hook hook)))

-- 
Nobu Nakada