Getting the source file pathname

Chaitanya Gupta mail at
Sat Dec 9 19:04:02 UTC 2017


I need the path of the source file from which a particular form is
loaded (similar to __FILE__ in C). Currently I have the following
macros in place:

(defmacro source-pathname ()
  (let ((compile-file-pathname *compile-file-pathname*))
    `(or ,compile-file-pathname (load-time-value *load-pathname*))))

(defmacro source-truename ()
  (let ((compile-file-truename *compile-file-truename*))
    `(or ,compile-file-truename (load-time-value *load-truename*))))

(defmacro source-directory ()
  `(make-pathname :defaults (source-truename)
                  :name nil :type nil))

This works fine when I use (LOAD ...), (LOAD (COMPILE-FILE ...)),
slime-load-file or slime-compile-and-load-file.

However it fails when I use slime-compile-defun, slime-eval-defun or
slime-eval-last-expression. Shouldn't slime bind
*compile-file-pathname*, *load-pathname*, etc. when these functions
are run?


More information about the slime-devel mailing list