Skip to content

Commit

Permalink
Merge pull request #82 from tmcgilchrist/inferior-coffee
Browse files Browse the repository at this point in the history
Add functions to send buffer, region and line to the CoffeeREPL.
  • Loading branch information
telaviv committed Mar 19, 2013
2 parents 55ce03d + 3e2bcb4 commit a76b677
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions coffee-mode.el
Expand Up @@ -182,6 +182,11 @@
:type 'string :type 'string
:group 'coffee) :group 'coffee)


(defcustom coffee-repl-buffer "*CoffeeREPL*"
"The name of the CoffeeREPL buffer."
:type 'string
:group 'coffee)

(defcustom coffee-compile-jump-to-error t (defcustom coffee-compile-jump-to-error t
"Whether to jump to the first error if compilation fails. "Whether to jump to the first error if compilation fails.
Since the coffee compiler does not always include a line number in Since the coffee compiler does not always include a line number in
Expand Down Expand Up @@ -231,25 +236,27 @@ with CoffeeScript."
(define-key map "\177" 'coffee-dedent-line-backspace) (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-left)
(define-key map (kbd "C-c C->") 'coffee-indent-shift-right) (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) (define-key map (kbd "<backtab>") 'coffee-indent-shift-left)
map) map)
"Keymap for CoffeeScript major mode.") "Keymap for CoffeeScript major mode.")


;; ;;
;; Commands ;; Commands
;; ;;

(defun coffee-repl () (defun coffee-repl ()
"Launch a CoffeeScript REPL using `coffee-command' as an inferior mode." "Launch a CoffeeScript REPL using `coffee-command' as an inferior mode."
(interactive) (interactive)


(unless (comint-check-proc "*CoffeeREPL*") (unless (comint-check-proc coffee-repl-buffer)
(set-buffer (set-buffer
(apply 'make-comint "CoffeeREPL" (apply 'make-comint "CoffeeREPL"
"env" "env"
nil (append (list "NODE_NO_READLINE=1" coffee-command) coffee-args-repl)))) 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) (defun coffee-compiled-file-name (&optional filename)
(let ((working-on-file (expand-file-name (or filename (buffer-file-name))))) (let ((working-on-file (expand-file-name (or filename (buffer-file-name)))))
Expand Down Expand Up @@ -308,6 +315,27 @@ called `coffee-compiled-buffer-name'."
(with-current-buffer buffer (with-current-buffer buffer
(let ((buffer-file-name "tmp.js")) (set-auto-mode))))) (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) (defun coffee-js2coffee-replace-region (start end)
"Convert JavaScript in the region into CoffeeScript." "Convert JavaScript in the region into CoffeeScript."
(interactive "r") (interactive "r")
Expand Down

0 comments on commit a76b677

Please sign in to comment.