Getting the source file pathname

Hi, 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? Thanks, Chaitanya

On Sat, Dec 9, 2017 at 7:04 PM, Chaitanya Gupta <mail@chaitanyagupta.com> wrote:
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?
Regarding slime-compile-defun, maybe. However, it's not straightforward because we call COMPILE-FILE and LOAD and it's those two functions take care of binding these special variables. For the eval functions, maybe not. They're more akin to calling EVAL on the expression (or typing it out at the REPL). (Try for instance slime-eval-last-expression with this expression: (eval-when (:load-toplevel) (print 'hello)).) Cheers, -- Luís Oliveira http://kerno.org/~luis/

On 10 December 2017 at 01:35, Luís Oliveira <luismbo@gmail.com> wrote:
Regarding slime-compile-defun, maybe. However, it's not straightforward because we call COMPILE-FILE and LOAD and it's those two functions take care of binding these special variables.
For the eval functions, maybe not. They're more akin to calling EVAL on the expression (or typing it out at the REPL). (Try for instance slime-eval-last-expression with this expression: (eval-when (:load-toplevel) (print 'hello)).)
Good point. Perhaps we can bind a symbol in the SWANK package instead?
Cheers,
-- Luís Oliveira http://kerno.org/~luis/

On 10 December 2017 at 01:46, Chaitanya Gupta <mail@chaitanyagupta.com> wrote:
On 10 December 2017 at 01:35, Luís Oliveira <luismbo@gmail.com> wrote:
Regarding slime-compile-defun, maybe. However, it's not straightforward because we call COMPILE-FILE and LOAD and it's those two functions take care of binding these special variables.
For the eval functions, maybe not. They're more akin to calling EVAL on the expression (or typing it out at the REPL). (Try for instance slime-eval-last-expression with this expression: (eval-when (:load-toplevel) (print 'hello)).)
Good point. Perhaps we can bind a symbol in the SWANK package instead?
Just read the hyperspec again and it says: "The consequences are unspecified if an attempt is made to assign or bind either of these variables." http://www.lispworks.com/documentation/HyperSpec/Body/v_cmp_fi.htm http://www.lispworks.com/documentation/HyperSpec/Body/v_ld_pns.htm So binding the CL variables is not guaranteed to work anyways :-( Chaitanya
Cheers,
-- Luís Oliveira http://kerno.org/~luis/
participants (2)
-
Chaitanya Gupta
-
Luís Oliveira