Browse files

Merge pull request #82 from tmcgilchrist/inferior-coffee

Add functions to send buffer, region and line to the CoffeeREPL.
  • Loading branch information...
2 parents 55ce03d + 3e2bcb4 commit a76b6771e2e9913a9752f3f93d7ae39eb0a3ff85 @telaviv telaviv committed Mar 19, 2013
Showing with 31 additions and 3 deletions.
  1. +31 −3 coffee-mode.el
@@ -182,6 +182,11 @@
:type 'string
:group 'coffee)
+(defcustom coffee-repl-buffer "*CoffeeREPL*"
+ "The name of the CoffeeREPL buffer."
+ :type 'string
+ :group 'coffee)
(defcustom coffee-compile-jump-to-error t
"Whether to jump to the first error if compilation fails.
Since the coffee compiler does not always include a line number in
@@ -231,25 +236,27 @@ with CoffeeScript."
(define-key map "\177" 'coffee-dedent-line-backspace)
(define-key map (kbd "C-c C-<") 'coffee-indent-shift-left)
(define-key map (kbd "C-c C->") 'coffee-indent-shift-right)
+ (define-key map (kbd "C-c C-l") 'coffee-send-line)
+ (define-key map (kbd "C-c C-r") 'coffee-send-region)
+ (define-key map (kbd "C-c C-b") 'coffee-send-buffer)
(define-key map (kbd "<backtab>") 'coffee-indent-shift-left)
"Keymap for CoffeeScript major mode.")
;; Commands
(defun coffee-repl ()
"Launch a CoffeeScript REPL using `coffee-command' as an inferior mode."
- (unless (comint-check-proc "*CoffeeREPL*")
+ (unless (comint-check-proc coffee-repl-buffer)
(apply 'make-comint "CoffeeREPL"
nil (append (list "NODE_NO_READLINE=1" coffee-command) coffee-args-repl))))
- (pop-to-buffer "*CoffeeREPL*"))
+ (pop-to-buffer coffee-repl-buffer))
(defun coffee-compiled-file-name (&optional filename)
(let ((working-on-file (expand-file-name (or filename (buffer-file-name)))))
@@ -308,6 +315,27 @@ called `coffee-compiled-buffer-name'."
(with-current-buffer buffer
(let ((buffer-file-name "tmp.js")) (set-auto-mode)))))
+(defun coffee-get-repl-proc ()
+ (unless (comint-check-proc coffee-repl-buffer)
+ (coffee-repl))
+ (get-buffer-process coffee-repl-buffer))
+(defun coffee-send-line ()
+ "Send the current line to the inferior Coffee process."
+ (interactive)
+ (coffee-send-region (line-beginning-position) (line-end-position)))
+(defun coffee-send-region (start end)
+ "Send the current region to the inferior Coffee process."
+ (interactive "r")
+ (comint-simple-send (coffee-get-repl-proc)
+ (buffer-substring-no-properties start end)))
+(defun coffee-send-buffer ()
+ "Send the current buffer to the inferior Coffee process."
+ (interactive)
+ (coffee-send-region (point-min) (point-max)))
(defun coffee-js2coffee-replace-region (start end)
"Convert JavaScript in the region into CoffeeScript."
(interactive "r")

0 comments on commit a76b677

Please sign in to comment.