Function: check-declare-scan

check-declare-scan is a byte-compiled function defined in check-declare.el.gz.

Signature

(check-declare-scan FILE)

Documentation

Scan FILE for declare-function calls.

Return a list with elements of the form (FNFILE FN ARGLIST FILEONLY), where only the first two elements need be present. This claims that FNFILE defines FN, with ARGLIST. FILEONLY non-nil means only check that FNFILE exists, not that it defines FN. This is for function definitions that we don't know how to recognize (e.g. some macros).

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/check-declare.el.gz
(defun check-declare-scan (file)
  "Scan FILE for `declare-function' calls.
Return a list with elements of the form (FNFILE FN ARGLIST FILEONLY),
where only the first two elements need be present.  This claims that FNFILE
defines FN, with ARGLIST.  FILEONLY non-nil means only check that FNFILE
exists, not that it defines FN.  This is for function definitions that we
don't know how to recognize (e.g. some macros)."
  (let (alist)
    (with-temp-buffer
      (insert-file-contents file)
      ;; FIXME we could theoretically be inside a string.
      (while (re-search-forward "^[ \t]*\\((declare-function\\)[ \t\n]" nil t)
        (let ((pos (match-beginning 1)))
          (goto-char pos)
          (let ((form (ignore-errors (read (current-buffer))))
                len fn formfile fnfile arglist fileonly)
            (if (and
                 ;; Exclude element of byte-compile-initial-macro-environment.
                 (or (listp (cdr form)) (setq form nil))
                 (> (setq len (length form)) 2)
                 (< len 6)
                 (setq formfile (nth 2 form))
                 (symbolp (setq fn (cadr form)))
                 (setq fn (symbol-name fn)) ; later we use as a search string
                 (stringp formfile)
                 (setq fnfile (check-declare-locate formfile file))
                 ;; Use t to distinguish unspecified arglist from empty one.
                 (or (eq t (setq arglist (if (> len 3)
                                             (nth 3 form)
                                           t)))
                     (listp arglist))
                 (symbolp (setq fileonly (nth 4 form))))
                (setq alist (cons (list fnfile fn arglist fileonly) alist))
              (when form
                (check-declare-warn file (or fn "unknown function")
                                    (if (stringp formfile) formfile
                                      "unknown file")
                                    "Malformed declaration"
                                    (line-number-at-pos pos))))))))
    alist))