3

I have a lot of code in my init file like this:

(when library-is-available
  ;; Code that use that uses functions from library
)

However, I get warnings that the functions that I am using are not known to be defined. What is an easy way to avoid these warnings? Can I perhaps ignore these code parts and not include them in the compiled file?

1
  • what about something like this?: (eval-when-compile (require 'cl-lib)) (defun foo () (cl-incf (point)))
    – jue
    Mar 29 at 23:39
3

Node Warning Tips of the Elisp manual tells us:

• To avoid a compiler warning about an undefined function that you know will be defined, use a declare-function statement (see Declaring Functions).

• If you use many functions, macros, and variables from a certain file, you can add a require (see require: Named Features) for that package to avoid compilation warnings for them, like this:

     (require 'foo)

If you need only macros from some file, you can require it only at compile time (see Eval During Compile). For instance,

     (eval-when-compile
       (require 'foo))

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.