It seems that declare-function + check-declare-file do not recognize functions defined via cl-defun.

I was happy using declare-function because it comes with check-declare-file that actually checks whether the declaration is consistent with the actual code in some other source file. However, when I upgraded the code for one of my declared functions, adding some keyword arguments and relying on cl-defun for handling them, check-declare-file could not validate and said that the function was not to be found.

Is there a workaround I could use? Or maybe declare-function is obsolete and there is some newer method I should use instead?

  • Please edit your question and add the exact error message. In what context did you encounter it? – NickD Jul 29 '20 at 21:40
  • @NickD. My initial description was quite confused. The error occurs when using check-declare-file. Thanks! – phs Jul 30 '20 at 5:56

At first note that check-declare-verify actually has a pattern for cl-defun in its regexp. So it should work.

If it does not maybe you should double-check and report an error if your code is not the source of the problem.

If it really turns out that you did not make any error and want to suppress the warning the doc string for declare-function answers your question:

(declare-function FN FILE &optional ARGLIST FILEONLY)

Optional FILEONLY non-nil means that check-declare will check only that FILE exists, not that it defines FN. This is intended for function definitions that check-declare does not recognize, e.g., defstruct.

So use a non-nil FILEONLY argument in check-declare for functions defined by cl-defun.

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.