Fork me on GitHub
#emacs
<
2020-10-18
>
bartuka02:10:57

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

bartuka02:10:54

(file-name-directory load-file-name) (Y)

ericdallo03:10:18

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

bartuka12:10:54

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))

👍 1
sogaiu12:10:11

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

dakra07:10:17

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

sogaiu09:10:07

thanks for sharing that