GNU bug report logs - #28910
27.0.50; Equivalent to __FILE__

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Fri, 20 Oct 2017 12:41:01 UTC

Severity: wishlist

Found in version 27.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 28910 in the body.
You can then email your comments to 28910 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#28910; Package emacs. (Fri, 20 Oct 2017 12:41:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 20 Oct 2017 12:41:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; Equivalent to __FILE__
Date: Fri, 20 Oct 2017 08:40:11 -0400
Package: Emacs
Version: 27.0.50


We should provide some `current-source-file-name` function which macros
can use to find get the name of the source file in which they were invoked.

Currently, some packages use a mix of load-file-name and
byte-compile-current-file to get that information, but it's hackish.

It'll be difficult to implement `current-source-file-name` in a way that
works reliably in all cases, but at least by providing this function we
can isolate the hack in a single place (and hope to refine it over time,
e.g. by tweaking bytecomp.el and lread.c so as to provide *better*
underlying information).

Along the same lines, it'd be great to provide
`current-source-definition-name` or even `current-source-line-number`.


        Stefan



In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2017-10-14 built on pastel
Repository revision: 300abf7bdd75ec44a497b3eb6ba86e242118ded1
Windowing system distributor 'The X.Org Foundation', version 11.0.11902000
System Description:	Debian GNU/Linux 9.1 (stretch)

Recent messages:
Marking diary entries...done
Preparing diary...done
Mark set [3 times]
Saving file /home/monnier/share/etc/diary...
Wrote /home/monnier/share/etc/diary
Marking diary entries...done

Warning: hide-sublevels is obsolete! [2 times]
Mark saved where search started
Mark set

Configured using:
 'configure -C --enable-checking --with-modules --enable-check-lisp-object-type
 'CFLAGS=-Wall -g3 -Og -Wno-pointer-sign'
 PKG_CONFIG_PATH=/home/monnier/lib/pkgconfig'

Configured features:
XAW3D XPM JPEG TIFF GIF PNG SOUND GPM DBUS NOTIFY GNUTLS LIBXML2
FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 MODULES

Important settings:
  value of $LANG: fr_CH.UTF-8
  locale-coding-system: utf-8-unix

Major mode: InactiveMinibuffer

Minor modes in effect:
  diff-auto-refine-mode: t
  electric-pair-mode: t
  global-reveal-mode: t
  reveal-mode: t
  auto-insert-mode: t
  savehist-mode: t
  minibuffer-electric-default-mode: t
  global-compact-docstrings-mode: t
  url-handler-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  global-prettify-symbols-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
/home/monnier/src/emacs/elpa/packages/svg/svg hides /home/monnier/src/emacs/work/lisp/svg
/home/monnier/src/emacs/elpa/packages/ada-mode/ada-prj hides /home/monnier/src/emacs/work/lisp/progmodes/ada-prj
/home/monnier/src/emacs/elpa/packages/ada-mode/ada-stmt hides /home/monnier/src/emacs/work/lisp/progmodes/ada-stmt
/home/monnier/src/emacs/elpa/packages/ada-mode/ada-mode hides /home/monnier/src/emacs/work/lisp/progmodes/ada-mode
/home/monnier/src/emacs/elpa/packages/ada-mode/ada-xref hides /home/monnier/src/emacs/work/lisp/progmodes/ada-xref
/home/monnier/src/emacs/elpa/packages/hyperbole/set hides /home/monnier/src/emacs/work/lisp/emacs-lisp/set
/home/monnier/src/emacs/elpa/packages/crisp/crisp hides /home/monnier/src/emacs/work/lisp/obsolete/crisp
/home/monnier/src/emacs/elpa/packages/landmark/landmark hides /home/monnier/src/emacs/work/lisp/obsolete/landmark

Features:
(sort mail-extr emacsbug message rmc puny format-spec rfc822 mml mml-sec
epa derived epg gnus-util rmail rmail-loaddefs mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils misearch multi-isearch
autoload lisp-mnt xscheme unsafep trace testcover shadow scheme
re-builder profiler inf-lisp ielm gmm-utils ert pp ewoc debug elp edebug
cl-indent map eieio-opt speedbar sb-image ezimage dframe find-func
cl-extra help-fns radix-tree executable copyright view cal-china lunar
solar cal-dst cal-bahai cal-islam cal-hebrew holidays hol-loaddefs
cal-french vc-git diff-mode diary-lib diary-loaddefs cal-move cal-menu
calendar cal-loaddefs cus-edit cus-start cus-load wid-edit filecache
autorevert filenotify doc-view jka-compr image-mode dired dired-loaddefs
server time-date flymake-proc flymake subr-x compile comint ansi-color
ring warnings noutline outline easy-mmode flyspell ispell checkdoc
thingatpt help-mode load-dir elec-pair reveal autoinsert proof-site
proof-autoloads cl pg-vars savehist minibuf-eldef disp-table
compact-docstrings cl-seq inline kotl-loaddefs advice info
realgud-recursive-autoloads finder-inf url-auth package easymenu
epg-config url-handlers url-parse auth-source eieio eieio-core cl-macs
eieio-loaddefs password-cache url-vars seq byte-opt gv bytecomp
byte-compile cconv cl-loaddefs cl-lib bbdb-autoloads vm-autoloads
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind inotify
dynamic-setting font-render-setting x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 233751 23426)
 (symbols 48 30526 0) (miscs 40 4438 355) (strings 32 78956 4837)
 (string-bytes 1 2417807)
 (vectors 16 38720) (vector-slots 8 1465001 121641) (floats 8 681 243)
 (intervals 56 3041 202)
 (buffers 992 24))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28910; Package emacs. (Fri, 20 Oct 2017 12:48:01 GMT) Full text and rfc822 format available.

Message #8 received at 28910 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>, 28910 <at> debbugs.gnu.org
Subject: Re: bug#28910: 27.0.50; Equivalent to __FILE__
Date: Fri, 20 Oct 2017 15:47:27 +0300
On 10/20/17 3:40 PM, Stefan Monnier wrote:

> Currently, some packages use a mix of load-file-name and
> byte-compile-current-file to get that information, but it's hackish.

FWIW, I've used (or load-file-name (buffer-file-name)) in a couple of 
packages, and that's worked well for my purposes.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28910; Package emacs. (Fri, 20 Oct 2017 17:41:02 GMT) Full text and rfc822 format available.

Message #11 received at 28910 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 28910 <at> debbugs.gnu.org
Subject: Re: bug#28910: 27.0.50; Equivalent to __FILE__
Date: Fri, 20 Oct 2017 13:39:52 -0400
>> Currently, some packages use a mix of load-file-name and
>> byte-compile-current-file to get that information, but it's hackish.
> FWIW, I've used (or load-file-name (buffer-file-name)) in a couple of
> packages, and that's worked well for my purposes.

Obviously, it won't work if you need it during macro expansion.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28910; Package emacs. (Sun, 29 Oct 2017 15:43:02 GMT) Full text and rfc822 format available.

Message #14 received at 28910 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 28910 <at> debbugs.gnu.org
Subject: Re: bug#28910: 27.0.50; Equivalent to __FILE__
Date: Sun, 29 Oct 2017 15:42:02 +0000
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> schrieb am Fr., 20. Okt. 2017 um
14:42 Uhr:

> We should provide some `current-source-file-name` function which macros
> can use to find get the name of the source file in which they were invoked.
>

`f-this-file' from the `f' package is some prior art, but I guess it also
doesn't work correctly with macros.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28910; Package emacs. (Thu, 02 Nov 2017 17:55:01 GMT) Full text and rfc822 format available.

Message #17 received at 28910 <at> debbugs.gnu.org (full text, mbox):

From: phillip.lord <at> russet.org.uk (Phillip Lord)
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 28910 <at> debbugs.gnu.org
Subject: Re: bug#28910: 27.0.50; Equivalent to __FILE__
Date: Thu, 02 Nov 2017 17:53:56 +0000
Philipp Stephani <p.stephani2 <at> gmail.com> writes:

> Stefan Monnier <monnier <at> iro.umontreal.ca> schrieb am Fr., 20. Okt. 2017 um
> 14:42 Uhr:
>
>> We should provide some `current-source-file-name` function which macros
>> can use to find get the name of the source file in which they were invoked.
>>
>
> `f-this-file' from the `f' package is some prior art, but I guess it also
> doesn't work correctly with macros.

emacs-load-relative uses the name "__FILE__" for the same thing.

Phil




Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Mon, 10 May 2021 17:00:02 GMT) Full text and rfc822 format available.

Notification sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
bug acknowledged by developer. (Mon, 10 May 2021 17:00:03 GMT) Full text and rfc822 format available.

Message #22 received at 28910-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: phillip.lord <at> russet.org.uk (Phillip Lord)
Cc: 28910-done <at> debbugs.gnu.org, Philipp Stephani <p.stephani2 <at> gmail.com>,
 Rocky Bernstein <rocky <at> gnu.org>
Subject: Re: bug#28910: 27.0.50; Equivalent to __FILE__
Date: Mon, 10 May 2021 12:59:40 -0400
Phillip Lord [2017-11-02 17:53:56] wrote:
> Philipp Stephani <p.stephani2 <at> gmail.com> writes:
>> Stefan Monnier <monnier <at> iro.umontreal.ca> schrieb am Fr., 20. Okt. 2017 um
>> 14:42 Uhr:
>>> We should provide some `current-source-file-name` function which macros
>>> can use to find get the name of the source file in which they were invoked.
>> `f-this-file' from the `f' package is some prior art, but I guess it also
>> doesn't work correctly with macros.
> emacs-load-relative uses the name "__FILE__" for the same thing.

Emacs's `master` now has the `macroexp-file-name` function which
provides this functionality.  So I guess `emacs-load-relative` could now
redefine __FILE__ as

    (defmacro __FILE__ () (macroexp-file-name))

tho oddly it seems that it defines `__FILE__` as a function rather than
a macro, so maybe it should be

    (defalias '__FILE__ #'macroexp-file-name)

but that doesn't match the semantics I expect from something called
`__FILE__`.

In any case, my original request is now satisfied, so I'm closing this.


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 08 Jun 2021 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 322 days ago.

Previous Next


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