From 08006607ab96e1b4bdfd12ddb43d143d28763e76 Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Sat, 22 Feb 2014 03:36:11 -0500 Subject: 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. --- rust-mode.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'rust-mode.el') 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 -- cgit v1.2.3