Skip to content

Commit

Permalink
Merge pull request #33 from knu/pr-coffee-compiled-file-name
Browse files Browse the repository at this point in the history
Add a function coffee-compiled-file-name for ease of scripting.
  • Loading branch information
defunkt committed Jul 7, 2011
2 parents 2c3d17b + 62c84fb commit bfbd616
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 11 additions & 5 deletions README.md
Expand Up @@ -190,6 +190,13 @@ compile-on-save minor mode in `coffee-mode`. To enable it by default:

(add-hook 'coffee-mode-hook '(lambda () (coffee-cos-mode t)))

To enable it only if it looks like you may want to:

(add-hook 'coffee-mode-hook '(lambda ()
(and (file-exists-p (buffer-file-name))
(file-exists-p (coffee-compiled-file-name))
(coffee-cos-mode t))))

### coffee-repl

Starts a repl in a new buffer using `coffee-command`.
Expand Down Expand Up @@ -222,12 +229,11 @@ Naturally. Example:
(setq coffee-command "~/dev/coffee"))

;; Compile '.coffee' files on every save
(add-hook 'after-save-hook
'(lambda ()
(when (string-match "\.coffee$" (buffer-name))
(coffee-compile-file))))
(and (file-exists-p (buffer-file-name))
(file-exists-p (coffee-compiled-file-name))
(coffee-cos-mode t))))

(add-hook 'coffee-mode-hook '(lambda () (coffee-custom)))
(add-hook 'coffee-mode-hook 'coffee-custom))

## Configuration

Expand Down
7 changes: 6 additions & 1 deletion coffee-mode.el
Expand Up @@ -156,12 +156,17 @@ path."

(pop-to-buffer "*CoffeeREPL*"))

(defun coffee-compiled-file-name (&optional filename)
"Returns the name of the JavaScript file compiled from a CoffeeScript file.
If FILENAME is omitted, the current buffer's file name is used."
(concat (file-name-sans-extension (or filename (buffer-file-name))) ".js"))

(defun coffee-compile-file ()
"Compiles and saves the current file to disk. Doesn't open in a buffer.."
(interactive)
(let ((compiler-output (shell-command-to-string (coffee-command-compile (buffer-file-name)))))
(if (string= compiler-output "")
(message "Compiled and saved %s" (concat (substring (buffer-file-name) 0 -6) "js"))
(message "Compiled and saved %s" (coffee-compiled-file-name))
(message (car (split-string compiler-output "[\n\r]+"))))))

(defun coffee-compile-buffer ()
Expand Down

0 comments on commit bfbd616

Please sign in to comment.