[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get the directory of a package?
From: |
Eric Abrahamsen |
Subject: |
Re: How to get the directory of a package? |
Date: |
Tue, 02 Feb 2021 21:14:22 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Marcin Borkowski <mbork@mbork.pl> writes:
> OK,
>
>> assume that I'm writing a package which wants to use a file from the
>> same directory the .el (or .elc) file of the package is located in. How
>> can the package know where in the filesystem it is located?
>>
>> Bonus points for a method which works not only with `require', but also
>> with `load-file' and `eval-buffer' (in the last case,
>> `default-directory' will probably work, but I skimmed through all
>> variables and functions matching `directory$' and nothing seemed to be
>> what I'm looking for).
>
> so I think I've found the answer. Is this correct? Are there possibly
> some edge cases I didn't think about?
>
> (if load-file-name
> (file-name-directory load-file-name)
> default-directory)
I stole the following bit of code to find "this file" from 'ert-x, it
was a bit of cargo-culting as I'm not entirely sure when/how the various
conditions would be true:
(or (bound-and-true-p byte-compile-current-file)
(and load-in-progress load-file-name)
buffer-file-name)
Might be helpful?