Skip to content

Commit

Permalink
Bugfix: Indenting blank lines with TAB
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Mar 8, 2010
1 parent b7ee8b8 commit df7ae3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
37 changes: 23 additions & 14 deletions coffee-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit df7ae3b

Please sign in to comment.