1

Assuming that a ELPA directory contains only one version of each Elpa-compliant packages, are the names of all Emacs Lisp files sharing the same namespace?

AFAIK Emacs Lisp does not support the concept of package scope for module name (as other languages like Python support). I would therefore have assumed that all Emacs Lisp files share the same name space. However, some file names in different packages that have the same name but different content, as in the following case:

  • lispy-20210121.926/elpa.el
  • ivy-20210311.1638/elpa.el

How does Emacs deal with this?

2 Answers 2

1

The two files you reference (elpa.el) are used only in installing those packages. If you check the package sources, you'll see that they are only referenced from the Makefile. After the packages are installed, Emacs doesn't need to find them again, so it doesn't matter that they have conflicting names.

Usually, Emacs refers to the load-path to see which directories it should search for files. The load function is used to load files by name:

(load "my-file")

Will search through the load-path until it finds a file with the name my-file.elc, my-file.el, my-file, and possibly a few other variants depending on your system. As soon as it finds a file with a matching name, it loads it and stops looking. If there is a second file with the same name further down in the load path, it is ignored. You can use the command M-x list-load-path-shadows to get a list of all such ignored files.

Consequently, files in a package will be generally be named in a way that is unique to that package (e.g., with a lispy- or ivy-) prefix, with a few exceptions like the one above.

1

All packages share the same namespace as Elisp does not support separate namespaces.

Packages usually deal with this by prefixing every symbol with a short, unique string. For example, every function in the ivy package is prefixed with "ivy-".

4
  • How does Emacs deal with files like elpa.el that is located into 2 directories like the ones I showed (lispy and ivy)?
    – PRouleau
    Jun 30, 2021 at 20:47
  • They have different paths so there is nothing to disambiguate. Now if you could create two files with the same exact pathname, that would be a problem, but filesystems do not allow that.
    – NickD
    Jun 30, 2021 at 22:49
  • Thanks @NickD. Therefore I assume that to load one specific elpa.el you'd have to provide the path to the file. You wouldn't be able to just (require elpa) (assuming the file provides 'elpa) without providing the explicit filename in the require call. Is my understanding correct?
    – PRouleau
    Jul 1, 2021 at 18:37
  • Yes, to the first question. The second question is a bit ambiguous: you can certainly (require 'elpa), but which one you get would depend on the order of directories in load-path.
    – NickD
    Jul 2, 2021 at 0:56

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.