GNU bug report logs - #55038
29.0.50; Does macroexp-file-name return nil unnecessarily?

Previous Next

Package: emacs;

Reported by: Philip Kaludercic <philipk <at> posteo.net>

Date: Wed, 20 Apr 2022 14:11:01 UTC

Severity: normal

Found in version 29.0.50

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 55038 <at> debbugs.gnu.org
Subject: bug#55038: 29.0.50; Does macroexp-file-name return nil unnecessarily?
Date: Thu, 21 Apr 2022 09:20:22 -0400
> Consider a macro like
>
>         (defmacro foo ()
>           `(message "Defined in %s" ,(macroexp-file-name)))
>
> Why does this expand to
>
>         (message "Defined in %s" nil)
>
> when evaluated directly in a file (say using `eval-buffer' or
> `eval-last-sexp`).

No good reason.

> Shouldn't it be fair to return the file name of the buffer, if nothing
> else can be used:

In the case the code comes from the current buffer, yes.
OTOH if it comes from (say) `M-:`, no.

> diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
> index e4bc2df280..5df9d4b221 100644
> --- a/lisp/emacs-lisp/macroexp.el
> +++ b/lisp/emacs-lisp/macroexp.el
> @@ -143,7 +143,8 @@ macroexp-file-name
>    ;; so prefer using it over using `load-file-name'.
>    (let ((file (car (last current-load-list))))
>      (or (if (stringp file) file)
> -        (bound-and-true-p byte-compile-current-file))))
> +        (bound-and-true-p byte-compile-current-file)
> +        (buffer-file-name))))

I think we need to make `eval-buffer` and friends set a variable to
indicate when `buffer-file-name` can be used.


        Stefan





This bug report was last modified 3 years and 58 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.