Providing and Requiring Emacs Lisp Package Package Functions (How)

I've been writing Emacs Lisp packages for a while now. However, I have yet to find / come across a SINGLE example using require and provide helper functions. To be honest, the explanation given in the Emacs Lisp manual is absolutely ridiculous. It tells you why you want to use helper functions, but it doesn't show you how to use them. It doesn't even tell you whether the parameters to the helper function should require and provide should be characters for files in path or filenames. Hence my question ...

Can anyone provide a simple example of how sub-functions work? In particular:

  • Can you give me a simple example of a package providing one function and two helper functions?
  • Can you give me an example that requires the above function and only one of the two helper functions provided by the package in 1

Thank you very much in advance,

Pablo

+3


source to share


1 answer


Disclaimer: I didn't even know sub-functions were the subject until I read this question.

Subfunctions seem to refer to complex functions that may have some functionality on one platform (eg Linux) but not another (eg Windows), or some similar situation. Users of this feature can test the subfunction and do workarounds if they don't.

As for using subelements, you just add the list argument, for example (provide 'foo '(bar baz))

, but most likely with some programmatically generated list like



(setq foo--subfeatures ())
(when (barp) 
  (setq foo--subfeatures (cons 'bar foo--subfeatures))) 
(provide 'foo foo--subfeatures)

      

Then check (featurep 'foo 'bar)

to see if it foo

has connotations bar

. Subitems are just symbols. A built-in example of a function with subelements is one make-network-process

that is implemented in C, but the mechanism for a subfunction should be pretty clear even if you are not familiar with C. Another example in lisp is provide

in files.el

and the corresponding featurep

in tramp-compat.el

.

Doesn't seem to require

care about sub-elements at all; its task is to load the function if it is not loaded and the function is loaded with all subelements. Sub- subfeatures

functions are implemented as a list in a function symbol property , e.g. (get 'foo 'subfeatures) -> (bar baz)

... It looks like it is provide

overwriting the property, so only the last call is relevant provide

.

+4


source







All Articles