Permalink
Browse files

Merge pull request #33 from knu/pr-coffee-compiled-file-name

Add a function coffee-compiled-file-name for ease of scripting.
  • Loading branch information...
2 parents 2c3d17b + 62c84fb commit bfbd616a226412c43c5a5d82a4f418157c16b560 @defunkt committed Jul 7, 2011
Showing with 17 additions and 6 deletions.
  1. +11 −5 README.md
  2. +6 −1 coffee-mode.el
View
16 README.md
@@ -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`.
@@ -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
View
7 coffee-mode.el
@@ -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 ()

0 comments on commit bfbd616

Please sign in to comment.