Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added coffee-compile-jump-to-error.

  • Loading branch information...
commit 14a0d566c6bb909e0b191aec60da61cdb0bb6878 1 parent b4b2a53
@errge errge authored committed
Showing with 29 additions and 1 deletion.
  1. +14 −0 README.md
  2. +15 −1 coffee-mode.el
View
14 README.md
@@ -163,6 +163,11 @@ Operating on "basic.coffee" and running this command will save a
"basic.js" in the same directory. Subsequent runs will overwrite the
file.
+If there are compilation errors and we the compiler have returned a
+line number to us for the first error, the point is moved to that
+line, so you can investigate. If this annoys you, you can set
+`coffee-compile-jump-to-error` to `nil`.
+
### coffee-compile-buffer
Compiles the current buffer to JavaScript using the command specified
@@ -293,6 +298,15 @@ The name of the scratch buffer used when compiling CoffeeScript.
Default: `"*coffee-compiled*"`
+### coffee-compile-jump-to-error
+
+Whether to jump to the first error if compilation fails. Please note
+that the coffee compiler doesn't always give a line number for the
+issue and in that case it is not possible to jump to the error, of
+course.
+
+Default: `t`
+
## Thanks
* Jeremy Ashkenas for CoffeeScript
View
16 coffee-mode.el
@@ -114,6 +114,14 @@ path."
:type 'string
:group 'coffee)
+(defcustom coffee-compile-jump-to-error t
+ "Whether to jump to the first error if compilation fails.
+Please note that the coffee compiler doesn't always give a line
+number for the issue and in that case it is not possible to jump
+to the error, of course."
+ :type 'boolean
+ :group 'coffee)
+
(defvar coffee-mode-hook nil
"A hook for you to run your own code when the mode is loaded.")
@@ -167,7 +175,13 @@ If FILENAME is omitted, the current buffer's file name is used."
(let ((compiler-output (shell-command-to-string (coffee-command-compile (buffer-file-name)))))
(if (string= compiler-output "")
(message "Compiled and saved %s" (coffee-compiled-file-name))
- (message (car (split-string compiler-output "[\n\r]+"))))))
+ (let* ((msg (car (split-string compiler-output "[\n\r]+")))
+ (line (and (string-match "on line \\([0-9]+\\)" msg)
+ (string-to-number (match-string 1 msg)))))
+ (message msg)
+ (when (and coffee-compile-jump-to-error line (> line 0))
+ (goto-char (point-min))
+ (forward-line (1- line)))))))
(defun coffee-compile-buffer ()
"Compiles the current buffer and displays the JS in another buffer."
Please sign in to comment.
Something went wrong with that request. Please try again.