Is require idempotent? i.e. do

(require 'helm)


(require 'helm)
(require 'helm)

end with the same result?


Yes. From Named Features (emphasis mine):

A feature name is a symbol that stands for a collection of functions, variables, etc. The file that defines them should provide the feature. Another program that uses them may ensure they are defined by requiring the feature. This loads the file of definitions if it hasn't been loaded already.

To require the presence of a feature, call require with the feature name as argument. require looks in the global variable features to see whether the desired feature has been provided already. If not, it loads the feature from the appropriate file. This file should call provide at the top level to add the feature to features; if it fails to do so, require signals an error.

| improve this answer | |
  • Accepted for quoting the docs. – PythonNut Feb 16 '15 at 18:19
  • Please incorporate the information from Gilles's answer here. Or, @Gilles, putting this answer into yours would work, too. – daveloyall Apr 6 '15 at 20:33

Yes, provided that the code in helm.el or helm.elc respects the rule that it must call (provide 'helm). The call (provide 'helm) marks the symbol helm as a loaded feature, and this causes the second call to (require 'helm) to do nothing.

If the loaded package does not call provide then require signals an error, and the feature is not marked as loaded, so a second call to (require 'helm) would attempt the loading again (and typically fail again for the same reason).

| improve this answer | |
  • +1 Thanks for the extra info. It resolved my confusion after reading the docs. – PythonNut Feb 16 '15 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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