Search code examples
elisp

How do I get a list of functions defined in an emacs-lisp file


Is it possible to get a list of functions defined in an emacs-lisp file? I found this sort of related answer: How do I get a list of Emacs lisp non-interactive functions?, but it involves a map over all of the atoms defined, not just what is in a file.


Solution

  • If the file in question has already been loaded, then you can modify the code in the question you link to filter out the symbols defined in other files:

    (let ((funclist ()))
      (mapatoms
       (lambda (x)
         (when (and (fboundp x)                     ; does x name a function?
                    (let ((f (symbol-file x)))
                      (and f (string= (file-name-base f) "my-file.el"))))
           (push x funclist))))
      funclist)
    

    If the file has not been loaded, you would have to scan it with scan-sexps and find defun forms.

    You might, however, prefer to use etags or imenu instead of scanning the file yourself.