Skip to content

Commit

Permalink
Remove custom debug code; should use the standard Emacs debugging too…
Browse files Browse the repository at this point in the history
…ls instead.
  • Loading branch information
rrthomas committed May 8, 2012
1 parent be2305f commit 66c326b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 76 deletions.
9 changes: 0 additions & 9 deletions README.md
Expand Up @@ -225,9 +225,6 @@ Naturally. Example:
;; If you don't want your compiled files to be wrapped ;; If you don't want your compiled files to be wrapped
(setq coffee-args-compile '("-c" "--bare")) (setq coffee-args-compile '("-c" "--bare"))


;; *Messages* spam
(setq coffee-debug-mode t)

;; Emacs key binding ;; Emacs key binding
(define-key coffee-mode-map [(meta r)] 'coffee-compile-buffer) (define-key coffee-mode-map [(meta r)] 'coffee-compile-buffer)


Expand All @@ -249,12 +246,6 @@ customize-group` with "coffee" as the group.
You can also customize then with `coffee-mode-hook`, as demonstrated You can also customize then with `coffee-mode-hook`, as demonstrated
above. above.


### coffee-debug-mode

Whether to run in debug mode or not. Logs to `*Messages*`.

Default: `t`

### coffee-js-mode ### coffee-js-mode


The mode to use when viewing compiled JavaScript. The mode to use when viewing compiled JavaScript.
Expand Down
81 changes: 14 additions & 67 deletions coffee-mode.el
Expand Up @@ -73,11 +73,6 @@
"A CoffeeScript major mode." "A CoffeeScript major mode."
:group 'languages) :group 'languages)


(defcustom coffee-debug-mode nil
"Whether to run in debug mode or not. Logs to `*Messages*'."
:type 'boolean
:group 'coffee-mode)

(defcustom coffee-js-mode 'js2-mode (defcustom coffee-js-mode 'js2-mode
"The mode to use when viewing compiled JavaScript." "The mode to use when viewing compiled JavaScript."
:type 'string :type 'string
Expand Down Expand Up @@ -111,16 +106,6 @@ path."
:type 'list :type 'list
:group 'coffee) :group 'coffee)


(defcustom coffee-cygwin-mode t
"For Windows systems, add support for Cygwin-style absolute paths."
:type 'boolean
:group 'coffee)

(defcustom coffee-cygwin-prefix "/cygdrive/C"
"The prefix with which to replace the drive-letter for your Windows partition, e.g. 'C:' would be replaced by '/c/cygdrive'."
:type 'string
:group 'coffee)

(defcustom coffee-compiled-buffer-name "*coffee-compiled*" (defcustom coffee-compiled-buffer-name "*coffee-compiled*"
"The name of the scratch buffer used when compiling CoffeeScript." "The name of the scratch buffer used when compiling CoffeeScript."
:type 'string :type 'string
Expand Down Expand Up @@ -163,19 +148,6 @@ was called."
;; Macros ;; Macros
;; ;;


(defmacro setd (var val)
"Like setq but optionally logs the variable's value using `coffee-debug'."
(if (and (boundp 'coffee-debug-mode) coffee-debug-mode)
`(progn
(coffee-debug "%s: %s" ',var ,val)
(setq ,var ,val))
`(setq ,var ,val)))

(defun coffee-debug (string &rest args)
"Print a message when in debug mode."
(when coffee-debug-mode
(apply 'message (append (list string) args))))

(defmacro coffee-line-as-string () (defmacro coffee-line-as-string ()
"Returns the current line as a string." "Returns the current line as a string."
`(buffer-substring (point-at-bol) (point-at-eol))) `(buffer-substring (point-at-bol) (point-at-eol)))
Expand Down Expand Up @@ -207,12 +179,12 @@ If FILENAME is omitted, the current buffer's file name is used."
(if (string= compiler-output "") (if (string= compiler-output "")
(message "Compiled and saved %s" (coffee-compiled-file-name)) (message "Compiled and saved %s" (coffee-compiled-file-name))
(let* ((msg (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) (line (and (string-match "on line \\([0-9]+\\)" msg)
(string-to-number (match-string 1 msg))))) (string-to-number (match-string 1 msg)))))
(message msg) (message msg)
(when (and coffee-compile-jump-to-error line (> line 0)) (when (and coffee-compile-jump-to-error line (> line 0))
(goto-char (point-min)) (goto-char (point-min))
(forward-line (1- line))))))) (forward-line (1- line)))))))


(defun coffee-compile-buffer () (defun coffee-compile-buffer ()
"Compiles the current buffer and displays the JS in another buffer." "Compiles the current buffer and displays the JS in another buffer."
Expand Down Expand Up @@ -244,7 +216,7 @@ If FILENAME is omitted, the current buffer's file name is used."
(when buffer (when buffer
(kill-buffer buffer))) (kill-buffer buffer)))


(call-process-region start end (call-process-region start end
js2coffee-command nil js2coffee-command nil
(current-buffer) (current-buffer)
) )
Expand Down Expand Up @@ -275,7 +247,7 @@ If FILENAME is omitted, the current buffer's file name is used."
"Run `coffee-run-cmd' with the --watch flag enabled for a directory or file" "Run `coffee-run-cmd' with the --watch flag enabled for a directory or file"
(interactive "fDirectory or File: ") (interactive "fDirectory or File: ")
(let ((coffee-compiled-buffer-name coffee-watch-buffer-name) (let ((coffee-compiled-buffer-name coffee-watch-buffer-name)
(args (mapconcat 'identity (append coffee-args-compile (list "--watch" (coffee-universal-path dir-or-file))) " "))) (args (mapconcat 'identity (append coffee-args-compile (list "--watch" (expand-file-name dir-or-file))) " ")))
(coffee-run-cmd args))) (coffee-run-cmd args)))


;; ;;
Expand Down Expand Up @@ -376,21 +348,9 @@ For detail, see `comment-dwim'."
(let ((deactivate-mark nil) (comment-start "#") (comment-end "")) (let ((deactivate-mark nil) (comment-start "#") (comment-end ""))
(comment-dwim arg))) (comment-dwim arg)))


(defun coffee-cygwin-path (expanded-file-name)
"Given an expanded file name, derive the absolute Cygwin path based on `coffee-cygwin-prefix'."
(replace-regexp-in-string "^[a-zA-Z]:" coffee-cygwin-prefix expanded-file-name t))

(defun coffee-universal-path (file-name)
"Handle different paths for different OS configurations for CoffeeScript"
(let ((full-file-name (expand-file-name file-name)))
(if (and (equal system-type 'windows-nt)
coffee-cygwin-mode)
(coffee-cygwin-path full-file-name)
full-file-name)))

(defun coffee-command-compile (file-name) (defun coffee-command-compile (file-name)
"The `coffee-command' with args to compile a file." "The `coffee-command' with args to compile a file."
(let ((full-file-name (coffee-universal-path file-name))) (let ((full-file-name (expand-file-name file-name)))
(mapconcat 'identity (append (list coffee-command) coffee-args-compile (list full-file-name)) " "))) (mapconcat 'identity (append (list coffee-command) coffee-args-compile (list full-file-name)) " ")))


(defun coffee-run-cmd (args) (defun coffee-run-cmd (args)
Expand Down Expand Up @@ -462,8 +422,6 @@ For detail, see `comment-dwim'."
(point-max) (point-max)
t) t)


(coffee-debug "Match: %s" (match-string 0))

;; If this is the start of a new namespace, save the namespace's ;; If this is the start of a new namespace, save the namespace's
;; indentation level and name. ;; indentation level and name.
(when (match-string 8) (when (match-string 8)
Expand All @@ -474,10 +432,7 @@ For detail, see `comment-dwim'."
(setq ns-name (concat ns-name "::")) (setq ns-name (concat ns-name "::"))


;; Save the indentation level. ;; Save the indentation level.
(setq ns-indent (length (match-string 1))) (setq ns-indent (length (match-string 1))))

;; Debug
(coffee-debug "ns: Found %s with indent %s" ns-name ns-indent))


;; If this is an assignment, save the token being ;; If this is an assignment, save the token being
;; assigned. `Please.print:` will be `Please.print`, `block:` ;; assigned. `Please.print:` will be `Please.print`, `block:`
Expand All @@ -495,12 +450,9 @@ For detail, see `comment-dwim'."
(when (and ns-name (> indent ns-indent)) (when (and ns-name (> indent ns-indent))
(setq assign (concat ns-name assign))) (setq assign (concat ns-name assign)))


(coffee-debug "=: Found %s with indent %s" assign indent)

;; Clear the namespace if we're no longer indented deeper ;; Clear the namespace if we're no longer indented deeper
;; than it. ;; than it.
(when (and ns-name (<= indent ns-indent)) (when (and ns-name (<= indent ns-indent))
(coffee-debug "ns: Clearing %s" ns-name)
(setq ns-name nil) (setq ns-name nil)
(setq ns-indent nil)) (setq ns-indent nil))


Expand All @@ -525,23 +477,18 @@ For detail, see `comment-dwim'."
(save-excursion (save-excursion
(let ((prev-indent 0) (cur-indent 0)) (let ((prev-indent 0) (cur-indent 0))
;; Figure out the indentation of the previous line ;; Figure out the indentation of the previous line
(setd prev-indent (coffee-previous-indent)) (setq prev-indent (coffee-previous-indent))


;; Figure out the current line's indentation ;; Figure out the current line's indentation
(setd cur-indent (current-indentation)) (setq cur-indent (current-indentation))


;; Shift one column to the left ;; Shift one column to the left
(beginning-of-line) (beginning-of-line)
(insert-tab) (insert-tab)


(coffee-debug "point: %s" (point))
(coffee-debug "point-at-bol: %s" (point-at-bol))

(when (= (point-at-bol) (point)) (when (= (point-at-bol) (point))
(forward-char coffee-tab-width)) (forward-char coffee-tab-width))


(coffee-debug "New indent: %s" (current-indentation))

;; We're too far, remove all indentation. ;; We're too far, remove all indentation.
(when (> (- (current-indentation) prev-indent) coffee-tab-width) (when (> (- (current-indentation) prev-indent) coffee-tab-width)
(backward-to-indentation 0) (backward-to-indentation 0)
Expand Down Expand Up @@ -616,7 +563,7 @@ line? Returns `t' or `nil'. See the README for more details."
;; If the next few characters match one of our magic indenter ;; If the next few characters match one of our magic indenter
;; keywords, we want to indent the line we were on originally. ;; keywords, we want to indent the line we were on originally.
(when (looking-at (coffee-indenters-bol-regexp)) (when (looking-at (coffee-indenters-bol-regexp))
(setd indenter-at-bol t)) (setq indenter-at-bol t))


;; If that didn't match, go to the back of the line and check to ;; If that didn't match, go to the back of the line and check to
;; see if the last character matches one of our indenter ;; see if the last character matches one of our indenter
Expand All @@ -628,7 +575,7 @@ line? Returns `t' or `nil'. See the README for more details."
(when (some (lambda (char) (when (some (lambda (char)
(= (char-before) char)) (= (char-before) char))
coffee-indenters-eol) coffee-indenters-eol)
(setd indenter-at-eol t))) (setq indenter-at-eol t)))


;; If we found an indenter, return `t'. ;; If we found an indenter, return `t'.
(or indenter-at-bol indenter-at-eol)))) (or indenter-at-bol indenter-at-eol))))
Expand Down

0 comments on commit 66c326b

Please sign in to comment.