Skip to content

Instantly share code, notes, and snippets.

@senny
Created September 22, 2010 06:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senny/591254 to your computer and use it in GitHub Desktop.
Save senny/591254 to your computer and use it in GitHub Desktop.
(defun ruby-send-region (start end)
"Send the current region to the inferior Ruby process."
(interactive "r")
(let (term (file (buffer-file-name)) line)
(save-excursion
(save-restriction
(widen)
(goto-char start)
(setq line (+ start (forward-line (- start)) 1))
(goto-char start)
(while (progn
(setq term (apply 'format ruby-send-terminator (random) (current-time)))
(re-search-forward (concat "^" (regexp-quote term) "$") end t)))))
;; compilation-parse-errors parses from second line.
(save-excursion
(let ((m (process-mark (inf-ruby-proc))))
(set-buffer (marker-buffer m))
(goto-char m)
(insert ruby-eval-separator "\n")
(set-marker m (point))))
(comint-send-string (inf-ruby-proc) (format "eval <<'%s', nil, %S, %d\n" term (if file file "") (if line line "")))
(comint-send-region (inf-ruby-proc) start end)
(comint-send-string (inf-ruby-proc) (concat "\n" term "\n"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment