what would be the recommended way to define the path of a file to be read by an emacs package? for example, I wrote a package pkg.el
and it has a json file in the same folder that needs to be read when the user call M-x my-command
but I don't know where the pkg was cloned by the user
(file-name-directory load-file-name)
(Y)
I'm not sure it is this what you are looking for, but there is locate-user-emacs-file
which returns the user emacs path, lsp-mode
use this, example: https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L6795
It's not the same behavior. I have a large populated json file and wanted to read from it. The following code did the trick:
(expand-file-name
"sources/data.json"
(if load-file-name
(file-name-directory load-file-name)
default-directory))
the full code can be found here: https://github.com/wandersoncferreira/oblique-strategies
i don't know how robust it is, but i've used this sort of approach in the past: https://github.com/sogaiu/adorn/blob/master/emacs/adorn.el#L54-L59
There was recently discussion about this on emacs-devel because native-comp puts files in a different directory than your normal .el or .elc files
This is the solution in vterm: https://github.com/akermu/emacs-libvterm/blob/01a1332ebb11daca5408f7fcb8a08454b0176e79/vterm.el#L105-L112
thanks for sharing that