Permalink
Browse files

Bugfix: Indenting blank lines with TAB

  • Loading branch information...
1 parent b7ee8b8 commit df7ae3bc3f474d15282eae829a35ed0ccad441f5 @defunkt committed Mar 8, 2010
Showing with 23 additions and 16 deletions.
  1. +0 −2 README.md
  2. +23 −14 coffee-mode.el
View
2 README.md
@@ -213,8 +213,6 @@ Naturally. Example:
## Bugs
-Indentation on pure whitespace lines is a bit wonky.
-
Prototype accessor assignments like `String::length: -> 10` don't look
great.
View
37 coffee-mode.el
@@ -49,7 +49,6 @@
;; js2-mode for guidance.
;; TODO:
-;; - Fix indentation toggling on blank (pure whitespace) lines
;; - Execute {buffer,region,line} and show output in new buffer
;; - Make prototype accessor assignments like `String::length: -> 10` pretty.
;; - mirror-mode - close brackets and parens automatically
@@ -403,22 +402,32 @@ For detail, see `comment-dwim'."
"Indent current line as CoffeeScript."
(interactive)
- (save-excursion
- (let ((prev-indent 0) (cur-indent 0))
- ;; Figure out the indentation of the previous line
- (setd prev-indent (coffee-previous-indent))
+ (if (= (point) (point-at-bol))
+ (insert-tab)
+ (save-excursion
+ (let ((prev-indent 0) (cur-indent 0))
+ ;; Figure out the indentation of the previous line
+ (setd prev-indent (coffee-previous-indent))
- ;; Figure out the current line's indentation
- (setd cur-indent (current-indentation))
+ ;; Figure out the current line's indentation
+ (setd cur-indent (current-indentation))
- ;; Shift one column to the left
- (backward-to-indentation 0)
- (insert-tab)
+ ;; Shift one column to the left
+ (beginning-of-line)
+ (insert-tab)
+
+ (coffee-debug "point: %s" (point))
+ (coffee-debug "point-at-bol: %s" (point-at-bol))
+
+ (when (= (point-at-bol) (point))
+ (forward-char tab-width))
+
+ (coffee-debug "New indent: %s" (current-indentation))
- ;; We're too far, remove all indentation.
- (when (> (- (current-indentation) prev-indent) tab-width)
- (backward-to-indentation 0)
- (delete-region (point-at-bol) (point))))))
+ ;; We're too far, remove all indentation.
+ (when (> (- (current-indentation) prev-indent) tab-width)
+ (backward-to-indentation 0)
+ (delete-region (point-at-bol) (point)))))))
(defun coffee-previous-indent ()
"Return the indentation level of the previous non-blank line."

0 comments on commit df7ae3b

Please sign in to comment.