summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wanstrath <chris@ozmm.org>2010-03-07 03:31:56 -0800
committerChris Wanstrath <chris@ozmm.org>2010-03-07 03:31:56 -0800
commit193e50d7fd1cbec68e88ab23ccf8f154051fa8ed (patch)
treeab5256fab0447fbe5d823bbfb416aebc3af9bccc
parent26133caa6a27871a4f43faa95a2bd0cb2af03314 (diff)
downloademacs-193e50d7fd1cbec68e88ab23ccf8f154051fa8ed.tar.gz
Bugfix: Indentation works when point is at beginning of the line
-rw-r--r--coffee-mode.el41
1 files changed, 22 insertions, 19 deletions
diff --git a/coffee-mode.el b/coffee-mode.el
index b96e01a996e..1eb3e07fab3 100644
--- a/coffee-mode.el
+++ b/coffee-mode.el
@@ -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."