]> code.delx.au - gnu-emacs-elpa/commitdiff
Use the do-softly macro
authorArtur Malabarba <bruce.connor.am@gmail.com>
Wed, 29 Oct 2014 19:21:23 +0000 (19:21 +0000)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Wed, 29 Oct 2014 19:21:23 +0000 (19:21 +0000)
aggressive-indent.el

index e5c5648db8f51f9e7b390ee63951d4691631b550..7d6f519244f3b66f79e9092d6a95df858543a918 100644 (file)
 (require 'cl-lib)
 (require 'names)
 
+(defmacro aggressive-indent--do-softly (&rest body)
+  "Execute body unobstrusively.
+This means:
+ 1. Do nothing in several situations, specified by
+    `aggressive-indent-dont-indent-if' and
+    `aggressive-indent--internal-dont-indent-if'.
+ 2. Silence all messages.
+ 3. Never throw errors.
+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
 (define-namespace aggressive-indent- :group indent
 
@@ -219,24 +237,6 @@ 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.
@@ -253,13 +253,7 @@ Throw an error if parentheses are unbalanced."
   "Indent current defun unobstrusively.
 Like `aggressive-indent-indent-defun', but wrapped in a
 `aggressive-indent--do-softly'."
-  (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))
-        (indent-defun)))))
+  (aggressive-indent--do-softly (indent-defun)))
 
 :autoload
 (defun indent-region-and-on (l r)
@@ -299,13 +293,7 @@ until nothing more happens."
   "Indent current defun unobstrusively.
 Like `aggressive-indent-indent-region-and-on', but wrapped in a
 `aggressive-indent--do-softly'."
-  (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))
-        (indent-region-and-on l r)))))
+  (aggressive-indent--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.")