]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/aggressive-indent/aggressive-indent.el
* aggressive-indent.el: Silence warning
[gnu-emacs-elpa] / packages / aggressive-indent / aggressive-indent.el
index 22647d14c0ecbad03678bbbdae3f6d86c54faafa..ac3ff96fab34d877fae1a6f8fdcdb468c167e327 100644 (file)
@@ -1,10 +1,10 @@
 ;;; aggressive-indent.el --- Minor mode to aggressively keep your code always indented  -*- lexical-binding:t -*-
 
-;; Copyright (C) 2014, 2015 Free Software Foundation, Inc
+;; Copyright (C) 2014, 2015, 2016 Free Software Foundation, Inc
 
 ;; Author: Artur Malabarba <emacs@endlessparentheses.com>
 ;; URL: https://github.com/Malabarba/aggressive-indent-mode
-;; Version: 1.6
+;; Version: 1.7
 ;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
 ;; Keywords: indent lisp maint tools
 ;; Prefix: aggressive-indent
@@ -300,8 +300,7 @@ messages.  L and R passed to `aggressive-indent-indent-defun'."
 Call `indent-region' between L and R, and then keep indenting
 until nothing more happens."
   (interactive "r")
-  (let ((p (point-marker))
-        was-begining-of-line)
+  (let ((p (point-marker)))
     (set-marker-insertion-type p t)
     (unwind-protect
         (progn
@@ -349,8 +348,26 @@ or messages."
   "List of (left right) limit of regions changed in the last command loop.")
 (make-variable-buffer-local 'aggressive-indent--changed-list)
 
-(defvar-local aggressive-indent--balanced-parens t
+(defvar aggressive-indent--balanced-parens t
   "Non-nil if the current-buffer has balanced parens.")
+(make-variable-buffer-local 'aggressive-indent--balanced-parens)
+
+(defun aggressive-indent--proccess-changed-list-and-indent ()
+  "Indent the regions in `aggressive-indent--changed-list'."
+  (let ((inhibit-modification-hooks t)
+        (inhibit-point-motion-hooks t)
+        (indent-function
+         (if (cl-member-if #'derived-mode-p aggressive-indent-modes-to-prefer-defun)
+             #'aggressive-indent--softly-indent-defun #'aggressive-indent--softly-indent-region-and-on)))
+    ;; Take the 10 most recent changes.
+    (let ((cell (nthcdr 10 aggressive-indent--changed-list)))
+      (when cell (setcdr cell nil)))
+    ;; (message "----------")
+    (while aggressive-indent--changed-list
+      ;; (message "%S" (car aggressive-indent--changed-list))
+      (apply indent-function (car aggressive-indent--changed-list))
+      (setq aggressive-indent--changed-list
+            (cdr aggressive-indent--changed-list)))))
 
 (defun aggressive-indent--indent-if-changed ()
   "Indent any region that changed in the last command loop."
@@ -361,15 +378,7 @@ or messages."
                     (aggressive-indent--run-user-hooks))
           (while-no-input
             (redisplay)
-            (let ((inhibit-modification-hooks t)
-                  (inhibit-point-motion-hooks t)
-                  (indent-function
-                   (if (cl-member-if #'derived-mode-p aggressive-indent-modes-to-prefer-defun)
-                       #'aggressive-indent--softly-indent-defun #'aggressive-indent--softly-indent-region-and-on)))
-              (while aggressive-indent--changed-list
-                (apply indent-function (car aggressive-indent--changed-list))
-                (setq aggressive-indent--changed-list
-                      (cdr aggressive-indent--changed-list))))))))))
+            (aggressive-indent--proccess-changed-list-and-indent)))))))
 
 (defun aggressive-indent--check-parens ()
   "Check if parens are balanced in the current buffer.
@@ -377,8 +386,7 @@ Store result in `aggressive-indent--balanced-parens'."
   (setq aggressive-indent--balanced-parens
         (save-excursion
           (ignore-errors
-            (check-parens)
-            t))))
+            (zerop (car (syntax-ppss (point-max))))))))
 
 (defun aggressive-indent--keep-track-of-changes (l r &rest _)
   "Store the limits (L and R) of each change in the buffer."
@@ -413,9 +421,11 @@ Store result in `aggressive-indent--balanced-parens'."
           (aggressive-indent--local-electric t))
         (aggressive-indent--check-parens)
         (add-hook 'after-change-functions #'aggressive-indent--keep-track-of-changes nil 'local)
+        (add-hook 'before-save-hook #'aggressive-indent--proccess-changed-list-and-indent nil 'local)
         (add-hook 'post-command-hook #'aggressive-indent--indent-if-changed nil 'local))
     ;; Clean the hooks
     (remove-hook 'after-change-functions #'aggressive-indent--keep-track-of-changes 'local)
+    (remove-hook 'before-save-hook #'aggressive-indent--proccess-changed-list-and-indent 'local)
     (remove-hook 'post-command-hook #'aggressive-indent--indent-if-changed 'local)
     (remove-hook 'post-command-hook #'aggressive-indent--softly-indent-defun 'local)))