branch: master
commit 63121eb44a515ed489face58e4b8e526dbe63481
Author: Artur Malabarba <[email protected]>
Commit: Artur Malabarba <[email protected]>
Restore point even when errors.
Fixes #23.
---
aggressive-indent.el | 46 ++++++++++++++++++++++++----------------------
1 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/aggressive-indent.el b/aggressive-indent.el
index 893567f..07bc7d5 100644
--- a/aggressive-indent.el
+++ b/aggressive-indent.el
@@ -276,28 +276,30 @@ until nothing more happens."
(let ((p (point-marker))
was-begining-of-line)
(set-marker-insertion-type p t)
- (goto-char r)
- (setq was-begining-of-line
- (= r (line-beginning-position)))
- ;; If L is at the end of a line, skip that line.
- (unless (= l r)
- (goto-char l)
- (when (= l (line-end-position))
- (cl-incf l)))
- ;; 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
- (indent-according-to-mode))
- ;; And then we indent each following line until nothing happens.
- (forward-line 1)
- (while (and (null (eobp))
- (/= (progn (skip-chars-forward "[:blank:]\n")
- (point))
- (progn (indent-according-to-mode)
- (point))))
- (forward-line 1))
- (goto-char p)))
+ (unwind-protect
+ (progn
+ (goto-char r)
+ (setq was-begining-of-line
+ (= r (line-beginning-position)))
+ ;; If L is at the end of a line, skip that line.
+ (unless (= l r)
+ (goto-char l)
+ (when (= l (line-end-position))
+ (cl-incf l)))
+ ;; 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
+ (indent-according-to-mode))
+ ;; And then we indent each following line until nothing happens.
+ (forward-line 1)
+ (while (and (null (eobp))
+ (/= (progn (skip-chars-forward "[:blank:]\n")
+ (point))
+ (progn (indent-according-to-mode)
+ (point))))
+ (forward-line 1)))
+ (goto-char p))))
(defun -softly-indent-region-and-on (l r &rest _)
"Indent current defun unobstrusively.