emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master 8af72c5 024/108: Factor out the soft part into a macro.


From: Artur Malabarba
Subject: [elpa] master 8af72c5 024/108: Factor out the soft part into a macro.
Date: Wed, 25 Mar 2015 18:38:53 +0000

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

    Factor out the soft part into a macro.
---
 aggressive-indent.el |   42 ++++++++++++++++++++++++------------------
 1 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/aggressive-indent.el b/aggressive-indent.el
index 4b5d359..a88204b 100644
--- a/aggressive-indent.el
+++ b/aggressive-indent.el
@@ -172,24 +172,6 @@ See `aggressive-indent--internal-dont-indent-if' for usage 
examples."
   "Keep track of whether `aggressive-indent-dont-indent-if' is throwing.
 This is used to prevent an infinite error loop on the user.")
 
-(defun -softly-indent-defun ()
-  "Indent current defun unobstrusively.
-Like `aggressive-indent-indent-defun', except do nothing if
-mark is active (to avoid deactivaing it), or if buffer is not
-modified (to avoid creating accidental modifications).
-Also, never throw errors nor messages.
-
-Meant for use in hooks. Interactively, use the other one.
-Indentation is not performed if any of the forms in
-`dont-indent-if' evaluates to non-nil."
-  (unless (or (run-hook-wrapped
-               'aggressive-indent--internal-dont-indent-if
-               #'eval)
-              (-run-user-hooks))
-    (ignore-errors
-      (cl-letf (((symbol-function 'message) #'ignore))
-        (indent-defun)))))
-
 (defun -run-user-hooks ()
   "Safely run forms in `aggressive-indent-dont-indent-if'.
 If any of them errors out, we only report it once until it stops
@@ -203,6 +185,24 @@ erroring again."
             (setq -has-errored t)
             (message -error-message er))))))
 
+(defmacro -do-softly (&rest body)
+  "Execute body unobstrusively.
+This means: do nothing if mark is active (to avoid deactivaing
+it), or if buffer is not modified (to avoid creating accidental
+modifications), or if any of the forms in
+`aggressive-indent-dont-indent-if' evaluates to non-nil.
+
+Also, never throw errors nor messages.
+Meant for use in functions which go in hooks."
+  (declare (debug t))
+  `(unless (or (run-hook-wrapped
+                'aggressive-indent--internal-dont-indent-if
+                #'eval)
+               (aggressive-indent--run-user-hooks))
+     (ignore-errors
+       (cl-letf (((symbol-function 'message) #'ignore))
+         ,@body))))
+
 :autoload
 (defun indent-defun ()
   "Indent current defun.
@@ -215,6 +215,12 @@ Throw an error if parentheses are unbalanced."
      (save-excursion (end-of-defun 1) (point)))
     (goto-char p)))
 
+(defun -softly-indent-defun ()
+  "Indent current defun unobstrusively.
+Like `aggressive-indent-indent-defun', but wrapped in a
+`aggressive-indent--do-softly'."
+  (-do-softly (indent-defun)))
+
 
 ;;; Minor modes
 :autoload



reply via email to

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