unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Philip Kaludercic <philipk@posteo.net>
Cc: 55038@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	[thread overview]
Message-ID: <jwv5yn2efuu.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <875yn3zw07.fsf@posteo.net> (Philip Kaludercic's message of "Wed,  20 Apr 2022 14:10:00 +0000")

> 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






      parent reply	other threads:[~2022-04-21 13:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-20 14:10 bug#55038: 29.0.50; Does macroexp-file-name return nil unnecessarily? Philip Kaludercic
2022-04-21 11:57 ` Lars Ingebrigtsen
2022-04-21 13:20 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=jwv5yn2efuu.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=55038@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=philipk@posteo.net \
    /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 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).