From 2d12c3ed21b581d44376d8f068ddfdaad4a901e9 Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Tue, 11 Mar 2014 20:23:32 -0400 Subject: Emacs: always jump the cursor if needed on indent The rust-mode-indent-line function had a check, which ran after all the calculations for how to indent had already happened, that skipped actually performing the indent if the line was already at the right indentation. Because of that, the cursor did not jump to the indentation if the line wasn't changing. This was particularly annoying if there was nothing but spaces on the line and you were at the beginning of it--it looked like the indent just wasn't working. This removes the check and adds test cases to cover this. --- 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 b304df8..3a99af3 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -140,14 +140,14 @@ ;; Otherwise, we are continuing the same expression from the previous line, ;; so add one additional indent level (+ baseline rust-indent-offset)))))))))) - (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)))))) + + ;; 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