Hello,


I was looking for a convenient function so that typing a key sequence
inside a ruby-mode buffer would directly save the buffer and load the
file in IRB, without asking any questions (ruby-load-file asks questions).

>Do you want to load current buffer?
>
>(defun ruby-load-buffer (buffer)
>    "Load current Ruby file into the inferior Ruby process.
>     Saving it first if needed."
>   (interactive "bLoad Ruby buffer: ")
>   (setq buffer (get-buffer buffer))
>   (save-excursion
>     (set-buffer buffer)
>     (or (eq major-mode 'ruby-mode)
>         (error "Not ruby mode"))
>     (save-buffer buffer))
>   (comint-send-string (ruby-proc) (concat "(load '"
>                                           (buffer-file-name buffer)
>                                           "'\)\n")))
>--
>Nobu Nakada

Thanks Nobu. This is almost what I need. I modified it so that it won't
ask for the name of the buffer to load either:

(defun ruby-load-current-buffer ()
   "Load current buffer's Ruby file into the inferior Ruby process.
    Saving the current buffer first if needed."
   (interactive)
   (let ((buffer (current-buffer)))
     (or (eq major-mode 'ruby-mode)
       (error "Not ruby mode"))
     (save-buffer buffer)
     (comint-send-string
       (ruby-proc)
       (concat "(load '" (buffer-file-name buffer) "'\)\n")
     )
   )
)

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.

Thanks again for your precious help.

Yours,

Jean-Hugues

-------------------------------------------------------------------------
Web:  http://hdl.handle.net/1030.37/1.1
Phone: +33 (0) 4 92 27 74 17