fix(lib): convert file! and dir! to macros

To ensure that they're expanded at a file's top-level, while expanded,
where they're used. It also fixes a few inlined uses of the file!
macro (e.g. in `load!`, as reported in #6764), which was prematurely
committed ahead of this change.

Close: #6764
Amend: a179b8d262
This commit is contained in:
Henrik Lissner 2022-09-08 13:14:18 +02:00
parent 46e23f37ba
commit 7e0c2ed8a3
No known key found for this signature in database
GPG Key ID: B60957CA074D39A3

View File

@ -243,19 +243,16 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions."
;;
;;; Sugars
(defun dir! ()
"Returns the directory of the emacs lisp file this function is called from."
(when-let (path (file!))
(directory-file-name (file-name-directory path))))
(defmacro file! ()
"Return the file of the file this macro was called."
(or (macroexp-file-name)
load-file-name
buffer-file-name ; for `eval'
(error "file!: cannot deduce the current file path")))
(defun file! ()
"Return the emacs lisp file this function is called from."
(cond (load-in-progress load-file-name)
((bound-and-true-p byte-compile-current-file))
((stringp (car-safe current-load-list))
(car current-load-list))
(buffer-file-name)
((error "Cannot get this file-path"))))
(defmacro dir! ()
"Return the directory of the file this macro was called."
(file-name-directory (macroexpand '(file!))))
;; REVIEW Should I deprecate this? The macro's name is so long...
(defalias 'letenv! 'with-environment-variables)