GNU bug report logs -
#55038
29.0.50; Does macroexp-file-name return nil unnecessarily?
Previous Next
Full log
Message #11 received at 55038 <at> debbugs.gnu.org (full text, mbox):
> 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 57 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.