unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18341: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook
@ 2014-08-28  4:54 Leo Liu
  2014-08-28 13:12 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Leo Liu @ 2014-08-28  4:54 UTC (permalink / raw)
  To: 18341


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)))))





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18341: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook
  2014-08-28  4:54 bug#18341: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook Leo Liu
@ 2014-08-28 13:12 ` Stefan Monnier
  2014-08-29  1:14   ` Leo Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-08-28 13:12 UTC (permalink / raw)
  To: Leo Liu; +Cc: 18341

> +(defmacro minibuffer-with-setup-hook (fun append &rest body)

Maybe a simpler change is to let FUN be of the form (:append FUN).


        Stefan





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18341: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook
  2014-08-28 13:12 ` Stefan Monnier
@ 2014-08-29  1:14   ` Leo Liu
  2014-08-29  2:03     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Leo Liu @ 2014-08-29  1:14 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18341

On 2014-08-28 09:12 -0400, Stefan Monnier wrote:
> Maybe a simpler change is to let FUN be of the form (:append FUN).

Make sense ;)

=== modified file 'lisp/files.el'
--- lisp/files.el	2014-08-12 02:35:24 +0000
+++ lisp/files.el	2014-08-29 01:11:08 +0000
@@ -1375,6 +1375,9 @@
 
 (defmacro minibuffer-with-setup-hook (fun &rest body)
   "Temporarily add FUN to `minibuffer-setup-hook' while executing BODY.
+FUN can also (:append FUN1), in which case FUN1 is appended to
+`minibuffer-setup-hook'.
+
 BODY should use the minibuffer at most once.
 Recursive uses of the minibuffer are unaffected (FUN is not
 called additional times).
@@ -1383,7 +1386,11 @@
 rather than FUN itself, to `minibuffer-setup-hook'."
   (declare (indent 1) (debug t))
   (let ((hook (make-symbol "setup-hook"))
-        (funsym (make-symbol "fun")))
+        (funsym (make-symbol "fun"))
+	(append nil))
+    (when (eq (car-safe fun) :append)
+      (setq append t)
+      (pop fun))
     `(let ((,funsym ,fun)
            ,hook)
        (setq ,hook
@@ -1394,7 +1401,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)))))





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18341: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook
  2014-08-29  1:14   ` Leo Liu
@ 2014-08-29  2:03     ` Stefan Monnier
  2014-08-29  2:51       ` Leo Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-08-29  2:03 UTC (permalink / raw)
  To: Leo Liu; +Cc: 18341

> +    (when (eq (car-safe fun) :append)
> +      (setq append t)

Please make it '(t) so you can use ,@append and get marginally cleaner
macroexpanded code when :append is not used.

> +      (pop fun))

I think this implements (:append . FUN) rather than (:append FUN).
Other than that, feel free to install into trunk.


        Stefan





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18341: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook
  2014-08-29  2:03     ` Stefan Monnier
@ 2014-08-29  2:51       ` Leo Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Leo Liu @ 2014-08-29  2:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18341-done

version: 24.5

On 2014-08-28 22:03 -0400, Stefan Monnier wrote:
> Please make it '(t) so you can use ,@append and get marginally cleaner
> macroexpanded code when :append is not used.
>
>> +      (pop fun))
>
> I think this implements (:append . FUN) rather than (:append FUN).
> Other than that, feel free to install into trunk.

Thanks for these comments and sorry for my mistakes.

Leo





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-29  2:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-28  4:54 bug#18341: 24.4.50; [patch] control where hook is added minibuffer-with-setup-hook Leo Liu
2014-08-28 13:12 ` Stefan Monnier
2014-08-29  1:14   ` Leo Liu
2014-08-29  2:03     ` Stefan Monnier
2014-08-29  2:51       ` Leo Liu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).