summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorMicah Chalmer <micah@micahchalmer.net>2014-02-22 03:36:11 -0500
committerMicah Chalmer <micah@micahchalmer.net>2014-02-22 22:55:30 -0500
commit08006607ab96e1b4bdfd12ddb43d143d28763e76 (patch)
treed874aa5f54f0142a7b2c91f6b8557afe349aa5d1 /rust-mode.el
parentbee96e838de53fa7aee7cfc9ea689fcad3816725 (diff)
downloadrust-mode-08006607ab96e1b4bdfd12ddb43d143d28763e76.tar.gz
Emacs: stay at the correct position when indenting
When indenting a non-blank line, stay at the same cursor position relative to the content after indenting.
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el16
1 files changed, 8 insertions, 8 deletions
diff --git a/rust-mode.el b/rust-mode.el
index 988b869..a2e1fc0 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -114,14 +114,14 @@
;; Otherwise we're in a column-zero definition
(t 0))))))
- (cond
- ;; If we're to the left of the indentation, reindent and jump to it.
- ((<= (current-column) indent)
- (indent-line-to indent))
-
- ;; We're to the right; if it needs indent, do so but save excursion.
- ((not (eq (current-indentation) indent))
- (save-excursion (indent-line-to indent))))))
+ (when (not (eq (current-indentation) indent))
+ ;; If we're at the beginning of the line (before or at the current
+ ;; indentation), jump with the indentation change. Otherwise, save the
+ ;; excursion so that adding the indentations will leave us at the
+ ;; equivalent position within the line to where we were before.
+ (if (<= (current-column) (current-indentation))
+ (indent-line-to indent)
+ (save-excursion (indent-line-to indent))))))
;; Font-locking definitions and helpers