From: George Ogata Date: 2002-08-15T11:14:06+09:00 Subject: Re: ruby-mode / inferior ruby This isn't an answer to your problem, but you may find it useful nonetheless. I generally don't find loading a selected chunk of the buffer too helpful. What I do instead is load the whole buffer into the inferior process. Here's the section of my .xemacs/init.el devoted to ruby-mode: ;;;; ruby-mode (defun g0-ruby-load-buffer () "Save current buffer, and load it into an inferior ruby process. If there is no inferior ruby process running, start one. Otherwise, load the current buffer into the currently running process. Switch to `ruby-buffer'." (interactive) (save-buffer) (let ((bufname (buffer-name)) (pop-up-windows t)) (run-ruby ruby-program-name) (ruby-load-file bufname))) (defun g0-ruby-end-block () "Insert an indented \"end\" on its own line. If the current line contains only whitespace, insert it on the current line. Otherwise, insert the \"end\" line after the current line. Insert a newline after the \"end\" and leave point after it." (interactive) (unless (string-match "^[ \\t\\r\\f]*$" (buffer-substring (point-at-bol) (point-at-eol))) (end-of-line) (insert ?\n)) (insert "end") (indent-for-tab-command)) (defun g0-ruby-toggle-irb-program () "Toggle `ruby-program-name' between \"ruby\" and \"ruby1.7\"." (interactive) (setq ruby-program-name (if (and (boundp 'ruby-program-name) (string= ruby-program-name "irb --inf-ruby-mode")) "irb1.7 --inf-ruby-mode" "irb --inf-ruby-mode")) (message "Using ruby: %s" ruby-program-name)) ;; for some ghastly reason, inf-ruby.el adds to ruby-mode-hook a ;; lambda that calls inf-ruby-keys, which resets the default ;; ruby-mode-map. (setq ruby-mode-hook nil) (add-to-hook 'ruby-mode-hook (define-key ruby-mode-map [(control ?c) (control ?l)] 'g0-ruby-load-buffer)) (add-to-hook 'ruby-mode-hook (define-key ruby-mode-map [(meta return)] 'g0-ruby-end-block)) (add-to-hook 'ruby-mode-hook (define-key ruby-mode-map [(control ?c) (control ?p)] 'g0-ruby-toggle-irb-program)) (add-to-hook 'inferior-ruby-mode-hook (define-key ruby-mode-map [(control ?c) (control ?l)] 'g0-ruby-load-buffer)) (add-to-hook 'inferior-ruby-mode-hook (define-key ruby-mode-map [(meta return)] 'g0-ruby-end-block)) (add-to-hook 'inferior-ruby-mode-hook (define-key ruby-mode-map [(control ?c) (control ?p)] 'g0-ruby-toggle-irb-program)) Couple of notes: - This defines keys: + C-cC-l -- throw the current buffer into IRB. + C-cC-p -- toggle the ruby-program-name between "ruby" and "ruby1.7". + M-RET -- Shove an "end" in the buffer, with a bit of intelligence with regard to placement. It won't not insert it if there's no matching def/class/begin/..., though. Might add that later. - I wrote this for XEmacs. It mightn't work on FSF Emacs. - That nasty comment about inf-ruby.el may no longer apply. I wrote this a few versions ago. Perhaps I'm the evil one for thinking it's evil, anyway.