]> git.eshelyaron.com Git - emacs.git/commitdiff
(minibuffer-with-setup-hook): New macro.
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 28 Mar 2005 19:58:58 +0000 (19:58 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 28 Mar 2005 19:58:58 +0000 (19:58 +0000)
(find-file-read-args): Use it to avoid let-binding
minibuffer-with-setup-hook (which breaks turning on/off
file-name-shadow-mode while in the prompt).

lisp/files.el

index b6ef1dea31fe727260580e39cc478a53440669c5..15d6f794e1690d7108ea3ee258dafc6de390784f 100644 (file)
@@ -928,20 +928,31 @@ documentation for additional customization information."
 (defvar find-file-default nil
   "Used within `find-file-read-args'.")
 
+(defmacro minibuffer-with-setup-hook (fun &rest body)
+  "Add FUN to `minibuffer-setup-hook' while executing BODY.
+BODY should use the minibuffer at most once.
+Recursive uses of the minibuffer will not be affected."
+  (declare (indent 1) (debug t))
+  (let ((hook (make-symbol "setup-hook")))
+    `(let ((,hook
+           (lambda ()
+             ;; Clear out this hook so it does not interfere
+             ;; with any recursive minibuffer usage.
+             (remove-hook 'minibuffer-setup-hook ,hook)
+             (,fun))))
+       (unwind-protect
+          (progn
+            (add-hook 'minibuffer-setup-hook ,hook)
+            ,@body)
+        (remove-hook 'minibuffer-setup-hook ,hook)))))
+
 (defun find-file-read-args (prompt mustmatch)
   (list (let ((find-file-default
               (and buffer-file-name
-                   (abbreviate-file-name buffer-file-name)))
-             (munge-default-fun
-              (lambda ()
-                (setq minibuffer-default find-file-default)
-                ;; Clear out this hook so it does not interfere
-                ;; with any recursive minibuffer usage.
-                (pop minibuffer-setup-hook)))
-             (minibuffer-setup-hook
-              minibuffer-setup-hook))
-         (add-hook 'minibuffer-setup-hook munge-default-fun)
-         (read-file-name prompt nil default-directory mustmatch))
+                   (abbreviate-file-name buffer-file-name))))
+         (minibuffer-with-setup-hook
+             (lambda () (setq minibuffer-default find-file-default))
+           (read-file-name prompt nil default-directory mustmatch)))
        t))
 
 (defun find-file (filename &optional wildcards)