From 53c4675d555787e5386176861ff38987065a1d39 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Thu, 12 Sep 2024 18:05:00 +0300 Subject: [PATCH] purescript-indentation.el: don't modify buffer if indentation unchanged Currently calling indentation on a line that is already indented as expected results in buffer being modified despite no changes being actually done. Avoid this by checking if current indentation already matches the one we just calculated and only reindenting on mismatch. --- purescript-indentation.el | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/purescript-indentation.el b/purescript-indentation.el index 781ae94..0adec57 100644 --- a/purescript-indentation.el +++ b/purescript-indentation.el @@ -196,17 +196,18 @@ autofill-mode." (end-of-line)))) (defun purescript-indentation-reindent (col) - (beginning-of-line) - (delete-region (point) - (progn - (when (and (eq purescript-literate 'bird) - (eq (char-after) ?>)) - (forward-char)) - (skip-syntax-forward "-") - (point))) - (when (eq purescript-literate 'bird) - (insert ">")) - (indent-to col)) + (unless (= col (purescript-indentation-current-indentation)) + (beginning-of-line) + (delete-region (point) + (progn + (when (and (eq purescript-literate 'bird) + (eq (char-after) ?>)) + (forward-char)) + (skip-syntax-forward "-") + (point))) + (when (eq purescript-literate 'bird) + (insert ">")) + (indent-to col))) (defun purescript-indentation-current-indentation () (if (eq purescript-literate 'bird)