Normally to find which file corresponds to a loaded feature, one could use the (locate-library LIBRARY &optional NOSUFFIX PATH INTERACTIVE-CALL) function.

However, if the user used the function (load-file FILE) a file that is not located in a directory listed in load-path can be loaded. A call to locate-library will not find it.

Also, lets say that there are several files that provide the same FEATURE because they have the same (provide FEATURE) form in them, and they are all stored in a directory listed in the load-path and one of them is loaded, locate-library will always report the file it finds with what is the content of the load-path at the moment of the execution of locate-library. This may happen in the following scenarioS:

  • while developing where several copies of the file exists in various directories or,
  • on projects that create the final distributed file from a set of smaller files.

I am trying to find a way to identify the path of the file that was originally used to load the existing feature, regardless of any modification that might have occurred to load-path after the file was loaded and even if the file was loaded from a load-file call.

Is this feasible?

1 Answer 1


Global variable load-history records the files you've loaded (no matter how), and the definitions they contain.

Assuming you know the file name of the file that provides the feature, you can use this, where FILENAME is the file name as a string.

(load-history-filename-element (load-history-regexp FILENAME))

C-h f load-history-regexp:

load-history-regexp is a compiled Lisp function in subr.el.

(load-history-regexp FILE)

Form a regexp to find FILE in load-history.

FILE, a string, is described in the function eval-after-load.

C-h f load-history-filename-element:

load-history-filename-element is a compiled Lisp function in subr.el.

(load-history-filename-element FILE-REGEXP)

Get the first elt of load-history whose car matches FILE-REGEXP.

Return nil if there isn't one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.