[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e4d3601 026/108: Implement a smarter engine for non-lisp m
From: |
Artur Malabarba |
Subject: |
[elpa] master e4d3601 026/108: Implement a smarter engine for non-lisp modes. |
Date: |
Wed, 25 Mar 2015 18:38:54 +0000 |
branch: master
commit e4d3601c86056576768311db16f1ba8f485d0a1c
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>
Implement a smarter engine for non-lisp modes.
Now should really fix #7.
---
aggressive-indent.el | 41 +++++++++++++++++++++++++++++++++--------
1 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/aggressive-indent.el b/aggressive-indent.el
index 9854c42..4f56c1a 100644
--- a/aggressive-indent.el
+++ b/aggressive-indent.el
@@ -80,6 +80,7 @@
;;
;;; Change Log:
+;; 0.3 - 2014/10/23 - Implement a smarter engine for non-lisp modes.
;; 0.2 - 2014/10/20 - Reactivate `electric-indent-mode'.
;; 0.2 - 2014/10/19 - Add variable `aggressive-indent-dont-indent-if', so the
user can prevent indentation.
;; 0.1 - 2014/10/15 - Release.
@@ -91,7 +92,7 @@
;;;###autoload
(define-namespace aggressive-indent- :group indent
-(defconst version "0.2" "Version of the aggressive-indent.el package.")
+(defconst version "0.3" "Version of the aggressive-indent.el package.")
(defun bug-report ()
"Opens github issues page in a web browser. Please send any bugs you find.
Please include your emacs and aggressive-indent versions."
@@ -165,7 +166,7 @@ buffer change."
(eval-after-load 'css-mode
'(add-hook
'css-mode-hook
- (lambda () (unless defun-prompt-regexp
+ (lambda () (unless defun-prompt-regexp
(setq-local defun-prompt-regexp "^[^[:blank:]].*")))))
(defcustom dont-indent-if '()
@@ -180,10 +181,10 @@ See `aggressive-indent--internal-dont-indent-if' for
usage examples."
:package-version '(aggressive-indent . "0.2"))
(defvar -error-message
- "One of the forms in `aggressive-indent-dont-indent-if' had the following
error, I've disabled it until you fix it: %S"
+ "One of the forms in `aggressive-indent-dont-indent-if' had the following
error, I've disabled it until you fix it: %S"
"Error message thrown by `aggressive-indent-dont-indent-if'.")
-(defvar -has-errored nil
+(defvar -has-errored nil
"Keep track of whether `aggressive-indent-dont-indent-if' is throwing.
This is used to prevent an infinite error loop on the user.")
@@ -248,7 +249,7 @@ until nothing more happens."
(goto-char r)
(setq was-begining-of-line
(= r (line-beginning-position)))
- ;; Indent the affected region.
+ ;; Indent the affected region.
(unless (= l r) (indent-region l r))
;; `indent-region' doesn't do anything if R was the beginning of a line,
so we indent manually there.
(when was-begining-of-line
@@ -268,6 +269,27 @@ Like `aggressive-indent-indent-region-and-on', but wrapped
in a
`aggressive-indent--do-softly'."
(-do-softly (indent-region-and-on l r)))
+(defvar changed-list-right nil
+ "List of right limit of regions changed in the last command loop.")
+
+(defvar changed-list-left nil
+ "List of left limit of regions changed in the last command loop.")
+
+(defun -indent-if-changed ()
+ "Indent any region that changed in the last command loop."
+ (let ((inhibit-modification-hooks t))
+ (when changed-list-left
+ (-softly-indent-region-and-on
+ (apply #'min changed-list-left)
+ (apply #'max changed-list-right))
+ (setq changed-list-left nil
+ changed-list-right nil))))
+
+(defun -keep-track-of-changes (l r &rest _)
+ "Store the limits of each change that happens in the buffer."
+ (push l changed-list-left)
+ (push r changed-list-right))
+
;;; Minor modes
:autoload
@@ -282,9 +304,12 @@ Like `aggressive-indent-indent-region-and-on', but wrapped
in a
(electric-indent-local-mode 1))
(if (cl-member-if #'derived-mode-p modes-to-prefer-defun)
(add-hook 'post-command-hook #'-softly-indent-defun nil 'local)
- (add-hook 'after-change-functions #'-softly-indent-region-and-on nil
'local)))
- (remove-hook 'post-command-hook #'-softly-indent-defun 'local)
- (remove-hook 'after-change-functions #'-softly-indent-region-and-on
'local)))
+ (add-hook 'after-change-functions #'-keep-track-of-changes nil
'local)
+ (add-hook 'post-command-hook #'-indent-if-changed nil 'local)))
+ ;; Clean the hooks
+ (remove-hook 'after-change-functions #'-keep-track-of-changes 'local)
+ (remove-hook 'post-command-hook #'-indent-if-changed 'local)
+ (remove-hook 'post-command-hook #'-softly-indent-defun 'local)))
:autoload
(define-globalized-minor-mode global-aggressive-indent-mode
- [elpa] master 7cd4e57 015/108: Fix Version, (continued)
- [elpa] master 7cd4e57 015/108: Fix Version, Artur Malabarba, 2015/03/25
- [elpa] master aebe081 020/108: Improve css-mode support, Artur Malabarba, 2015/03/25
- [elpa] master 1c74518 023/108: Fix last-command -> this-command bug, Artur Malabarba, 2015/03/25
- [elpa] master ebcafdb 022/108: Version Bump, Artur Malabarba, 2015/03/25
- [elpa] master a07019e 021/108: Move up the screencast, Artur Malabarba, 2015/03/25
- [elpa] master 8af72c5 024/108: Factor out the soft part into a macro., Artur Malabarba, 2015/03/25
- [elpa] master 7c3cb86 017/108: Add demo screenshot, Artur Malabarba, 2015/03/25
- [elpa] master 6a4296b 028/108: Add demo for non-Lisp mode, Artur Malabarba, 2015/03/25
- [elpa] master 215ddf7 030/108: Don't use do-softly for now., Artur Malabarba, 2015/03/25
- [elpa] master 81fadf1 029/108: Add modes to prefer defun., Artur Malabarba, 2015/03/25
- [elpa] master e4d3601 026/108: Implement a smarter engine for non-lisp modes.,
Artur Malabarba <=
- [elpa] master e774765 031/108: Merge branch 'region-indent', Artur Malabarba, 2015/03/25
- [elpa] master 7762250 032/108: Don't indent on empty line., Artur Malabarba, 2015/03/25
- [elpa] master 6e1d5a1 027/108: Merge pull request #12 from Bruce-Connor/region-indent, Artur Malabarba, 2015/03/25
- [elpa] master c15c56d 033/108: Skip empty lines when indenting blocks, Artur Malabarba, 2015/03/25
- [elpa] master 82c5d78 034/108: Merge pull request #17 from pmachata/master, Artur Malabarba, 2015/03/25
- [elpa] master b4b8dc3 037/108: Merge branch 'master' of github.com:Bruce-Connor/aggressive-indent-mode, Artur Malabarba, 2015/03/25
- [elpa] master 820db3c 035/108: Don't indent inside comments, but allow as an option., Artur Malabarba, 2015/03/25
- [elpa] master 201ec03 025/108: Indent changed region instead of defun for modes which aren't emacs-lisp., Artur Malabarba, 2015/03/25
- [elpa] master c4957eb 041/108: Fix bug on buffers with no final newline., Artur Malabarba, 2015/03/25
- [elpa] master d3948b0 036/108: Don't execute syntax-ppss if the controlling variable is t., Artur Malabarba, 2015/03/25