;; Author: Artur Malabarba <emacs@endlessparentheses.com>
;; URL: http://github.com/Malabarba/aggressive-indent-mode
-;; Version: 1.1
+;; Version: 1.2
;; Package-Requires: ((emacs "24.1") (names "20150125.9") (cl-lib "0.5"))
;; Keywords: indent lisp maint tools
;; Prefix: aggressive-indent
'((memq this-command aggressive-indent-protected-commands)
(region-active-p)
buffer-read-only
+ undo-in-progress
(null (buffer-modified-p))
(and (boundp 'smerge-mode) smerge-mode)
- (string-match "\\`[[:blank:]]*\n?\\'" (or (thing-at-point 'line) ""))
+ (let ((line (thing-at-point 'line)))
+ (when (stringp line)
+ (or (string-match "\\`[[:blank:]]*\n?\\'" line)
+ ;; If the user is starting to type a comment.
+ (and (stringp comment-start)
+ (string-match (concat "\\`[[:blank:]]*"
+ (substring comment-start 0 1)
+ "[[:blank:]]*$")
+ line)))))
(let ((sp (syntax-ppss)))
;; Comments.
(or (and (not aggressive-indent-comments-too) (elt sp 4))
'(when (boundp 'ac-completing)
(add-to-list 'aggressive-indent--internal-dont-indent-if
'ac-completing)))
+(eval-after-load 'multiple-cursors-core
+ '(when (boundp 'multiple-cursors-mode)
+ (add-to-list 'aggressive-indent--internal-dont-indent-if
+ 'multiple-cursors-mode)))
(eval-after-load 'iedit
'(when (boundp 'iedit-mode)
(add-to-list 'aggressive-indent--internal-dont-indent-if
"Indent current defun unobstrusively.
Like `aggressive-indent-indent-defun', but without errors or
messages. L and R passed to `aggressive-indent-indent-defun'."
- (unless (or (run-hook-wrapped
- 'aggressive-indent--internal-dont-indent-if
- #'eval)
- (aggressive-indent--run-user-hooks))
- (cl-letf (((symbol-function 'message) #'ignore))
- (ignore-errors (indent-defun l r)))))
+ (cl-letf (((symbol-function 'message) #'ignore))
+ (ignore-errors (indent-defun l r))))
:autoload
(defun indent-region-and-on (l r)
(point-limit (if (and eod (< (point) eod))
eod (point-max-marker))))
(while (and (null (eobp))
- (< (point) point-limit)
- (/= (point)
- (progn (indent-according-to-mode)
- (point))))
+ (let ((op (point))
+ (np (progn (indent-according-to-mode)
+ (point))))
+ ;; As long as we're indenting things to the
+ ;; left, keep indenting.
+ (or (< np op)
+ ;; If we're indenting to the right, or
+ ;; not at all, stop at the limit.
+ (< (point) point-limit))))
(forward-line 1)
(skip-chars-forward "[:blank:]\n"))))
(goto-char p))))
"Indent region between L and R, and a bit more.
Like `aggressive-indent-indent-region-and-on', but without errors
or messages."
- (unless (or (run-hook-wrapped
- 'aggressive-indent--internal-dont-indent-if
- #'eval)
- (aggressive-indent--run-user-hooks))
- (cl-letf (((symbol-function 'message) #'ignore))
- (ignore-errors (indent-region-and-on l r)))))
+ (cl-letf (((symbol-function 'message) #'ignore))
+ (ignore-errors (indent-region-and-on l r))))
(defvar -changed-list nil
"List of (left right) limit of regions changed in the last command loop.")
(defun -indent-if-changed ()
"Indent any region that changed in the last command loop."
(when -changed-list
- (while-no-input
- (let ((inhibit-modification-hooks t)
- (inhibit-point-motion-hooks t)
- (indent-function
- (if (cl-member-if #'derived-mode-p modes-to-prefer-defun)
- #'-softly-indent-defun
- #'-softly-indent-region-and-on)))
- (while -changed-list
- (apply indent-function (car -changed-list))
- (setq -changed-list (cdr -changed-list)))))))
+ (unless (or (run-hook-wrapped 'aggressive-indent--internal-dont-indent-if #'eval)
+ (aggressive-indent--run-user-hooks))
+ (while-no-input
+ (let ((inhibit-modification-hooks t)
+ (inhibit-point-motion-hooks t)
+ (indent-function
+ (if (cl-member-if #'derived-mode-p modes-to-prefer-defun)
+ #'-softly-indent-defun
+ #'-softly-indent-region-and-on)))
+ (while -changed-list
+ (apply indent-function (car -changed-list))
+ (setq -changed-list (cdr -changed-list))))))))
(defun -keep-track-of-changes (l r &rest _)
"Store the limits (L and R) of each change in the buffer."