Permalink
Browse files

Bugfix: Indentation works when point is at beginning of the line

  • Loading branch information...
1 parent ce05b32 commit 97ef92b61c61df487ac194ec95b9b2f1fa8b09f8 @defunkt committed Mar 7, 2010
Showing with 22 additions and 19 deletions.
  1. +22 −19 coffee-mode.el
View
@@ -241,27 +241,30 @@ 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
- (forward-line -1)
- (setq prev-indent (current-indentation))
- (coffee-debug "prev-indent %s" prev-indent)
-
- ;; Figure out the current line's indentation
- (forward-line 1)
- (setq cur-indent (current-indentation))
- (coffee-debug "cur-indent %s" cur-indent)
-
- ;; Shift one column to the left
- (backward-to-indentation 0)
- (coffee-debug "backward cur-indent %s" (current-indentation))
+ ;; Bail early by indenting if point as the front of the line.
+ (if (= (point) (point-at-bol))
(insert-tab)
-
- ;; We're too far, remove all indentation.
- (when (> (- (current-indentation) prev-indent) tab-width)
+ (save-excursion
+ (let ((prev-indent 0) (cur-indent 0))
+ ;; Figure out the indentation of the previous line
+ (forward-line -1)
+ (setq prev-indent (current-indentation))
+ (coffee-debug "prev-indent %s" prev-indent)
+
+ ;; Figure out the current line's indentation
+ (forward-line 1)
+ (setq cur-indent (current-indentation))
+ (coffee-debug "cur-indent %s" cur-indent)
+
+ ;; Shift one column to the left
(backward-to-indentation 0)
- (delete-region (point-at-bol) (point))))))
+ (coffee-debug "backward cur-indent %s" (current-indentation))
+ (insert-tab)
+
+ ;; 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-newline-and-indent ()
"Inserts a newline and indents it to the same level as the previous line."

0 comments on commit 97ef92b

Please sign in to comment.