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 ;;; Sugars
(defun dir! () (defmacro file! ()
"Returns the directory of the emacs lisp file this function is called from." "Return the file of the file this macro was called."
(when-let (path (file!)) (or (macroexp-file-name)
(directory-file-name (file-name-directory path)))) load-file-name
buffer-file-name ; for `eval'
(error "file!: cannot deduce the current file path")))
(defun file! () (defmacro dir! ()
"Return the emacs lisp file this function is called from." "Return the directory of the file this macro was called."
(cond (load-in-progress load-file-name) (file-name-directory (macroexpand '(file!))))
((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"))))
;; REVIEW Should I deprecate this? The macro's name is so long... ;; REVIEW Should I deprecate this? The macro's name is so long...
(defalias 'letenv! 'with-environment-variables) (defalias 'letenv! 'with-environment-variables)