all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: dynamic variables and advice
Date: Thu, 03 Mar 2022 10:03:22 -0500	[thread overview]
Message-ID: <jwvh78frseq.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 20220303.121042.104668854711893143.enometh@meer.net

> I was trying to use the add-function facility to make dired and friends
> prompt only for directories. the naive approach with a lot of printf
> debugging -
>
> #+begin_src elisp
> (defvar read-file-name--directories-p nil
>   "dynamic variable which should be let-bound in an :around advice
> and should be used in a :filter-args advice.")
>
> (defun read-file-name--maybe-filter-directories (args)
>   "filter-args advice for read-file-name."
>   (cl-destructuring-bind (prompt &optional dir default-filename
> 				 mustmatch initial predicate)
>       args
>     (let ((ret (list prompt dir default-filename mustmatch initial
> 		     (or predicate
> 			 (and read-file-name--maybe-filter-directories-p
> 			      #'file-directory-p)))))
>       (message "rfn-mfd: rfnmfd=%s this-command=%s ret=%s"
> 	       read-file-name--maybe-filter-directories-p  this-command ret)
>       ret)))
>
> (advice-add 'read-file-name
> 	    :filter-args 'read-file-name--maybe-filter-directories)
>
> (defun rfnmfd-yes (oldfun &rest args)
>   "an around advice function which sets rfn-mfd-p to t"
>   (let ((read-file-name--mabe-filter-directories-p t))
>     (message "rfnmfd-yes: begin")
>     (prog1 (apply oldfun args)
>       (message "rfnmfd-yes: done"))))
>
> (advice-add 'dired-read-dir-and-switches :around 'rfnmfd-yes)
> #+end_src
>
> Now when I call M-x dired the around advice for
> dired-read-dir-and-switches runs, and it binds
> read-file-name--directories-p to t and eventually goes on to call
> read-file-name where the filter-args advice kicks in.
>
> but in filter-args advice my dynamic variable  is bound to nil and not
> to t as I'd expect.
>
> How is my expectation wrong or what is actually happening?

A typo, "maybe"?
[ Pun intended.  ]


        Stefan




  reply	other threads:[~2022-03-03 15:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03  6:40 dynamic variables and advice Madhu
2022-03-03 15:03 ` Stefan Monnier via Users list for the GNU Emacs text editor [this message]
2022-03-04  2:48   ` Madhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvh78frseq.fsf-monnier+emacs@gnu.org \
    --to=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.