[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master cbbc361 1/3: [Fix #77] Only reindent if parens are balance

From: Artur Malabarba
Subject: [elpa] master cbbc361 1/3: [Fix #77] Only reindent if parens are balanced
Date: Mon, 04 Apr 2016 13:33:56 +0000

branch: master
commit cbbc361a1c27aa0a05e8868ac91f9986737708b2
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>

    [Fix #77] Only reindent if parens are balanced
 aggressive-indent.el |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/aggressive-indent.el b/aggressive-indent.el
index 764a332..0c61837 100644
--- a/aggressive-indent.el
+++ b/aggressive-indent.el
@@ -368,10 +368,24 @@ or messages."
                 (setq aggressive-indent--changed-list
                       (cdr aggressive-indent--changed-list))))))))))
+(defvar-local aggressive-indent--balanced-parens t
+  "Non-nil if the current-buffer has balanced parens.")
+(defun aggressive-indent--check-parens ()
+  "Check if parens are balanced in the current buffer.
+Store result in `aggressive-indent--balanced-parens'."
+  (setq aggressive-indent--balanced-parens
+        (ignore-errors
+          (save-restriction
+            (narrow-to-defun)
+            (check-parens)
+            t))))
 (defun aggressive-indent--keep-track-of-changes (l r &rest _)
   "Store the limits (L and R) of each change in the buffer."
   (when aggressive-indent-mode
-    (push (list l r) aggressive-indent--changed-list)))
+    (push (list l r) aggressive-indent--changed-list)
+    (aggressive-indent--check-parens)))
 ;;; Minor modes
@@ -393,11 +407,12 @@ or messages."
                    (memq major-mode '(text-mode fundamental-mode))
           (aggressive-indent-mode -1)
-        ;; Should electric indent be ON or OFF?        
+        ;; Should electric indent be ON or OFF?
         (if (or (eq aggressive-indent-dont-electric-modes t)
                 (cl-member-if #'derived-mode-p 
             (aggressive-indent--local-electric nil)
           (aggressive-indent--local-electric t))
+        (aggressive-indent--check-parens)
         (add-hook 'after-change-functions 
#'aggressive-indent--keep-track-of-changes nil 'local)
         (add-hook 'post-command-hook #'aggressive-indent--indent-if-changed 
nil 'local))
     ;; Clean the hooks

reply via email to

[Prev in Thread] Current Thread [Next in Thread]