Subject: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook

From: Leo Liu <[email-masked]>
Date: Thu, 28 Aug 2014 12:54:45 +0800

Any objection to extending minibuffer-with-setup-hook so that one can
control where the hook is added.

I have often wanted the `append' option because other hook functions can
cancel my work. Will fix the doc-string once the patch is accepted.

Thanks,
Leo

=== modified file 'lisp/files.el'
--- lisp/files.el	2014-08-12 02:35:24 +0000
+++ lisp/files.el	2014-08-28 04:46:15 +0000
@@ -1373,7 +1373,7 @@
 	 'confirm)
 	(t nil)))
 
-(defmacro minibuffer-with-setup-hook (fun &rest body)
+(defmacro minibuffer-with-setup-hook (fun append &rest body)
   "Temporarily add FUN to `minibuffer-setup-hook' while executing BODY.
 BODY should use the minibuffer at most once.
 Recursive uses of the minibuffer are unaffected (FUN is not
@@ -1381,9 +1381,11 @@
 
 This macro actually adds an auxiliary function that calls FUN,
 rather than FUN itself, to `minibuffer-setup-hook'."
-  (declare (indent 1) (debug t))
+  (declare (indent 2) (debug t))
   (let ((hook (make-symbol "setup-hook"))
-        (funsym (make-symbol "fun")))
+        (funsym (make-symbol "fun"))
+        (body (if (booleanp append) body (push append body)))
+        (append (and (booleanp append) append)))
     `(let ((,funsym ,fun)
            ,hook)
        (setq ,hook
@@ -1394,7 +1396,7 @@
 	       (funcall ,funsym)))
        (unwind-protect
 	   (progn
-	     (add-hook 'minibuffer-setup-hook ,hook)
+	     (add-hook 'minibuffer-setup-hook ,hook ,append)
 	     ,@body)
 	 (remove-hook 'minibuffer-setup-hook ,hook)))))