al-autoload.el 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ;;; al-autoload.el --- Additional functionality to autoload Emacs packages
  2. ;; Copyright © 2013-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (defvar al/autoloads-regexp
  17. (rx (group (* any) "-autoloads")
  18. ".el" (zero-or-one "c") string-end)
  19. "Regexp to match Emacs 'autoloads' file.")
  20. (defmacro al/autoload (file &rest symbols)
  21. "Autoload (unquoted) SYMBOLS from file as interactive commands."
  22. (declare (indent 1))
  23. `(progn
  24. ,@(mapcar (lambda (symbol)
  25. `(autoload ',symbol ,file nil t))
  26. symbols)))
  27. (defun al/autoloads-file (directory)
  28. "Return the name of 'autoloads' file for DIRECTORY."
  29. (let* ((dir (expand-file-name directory))
  30. (base (file-name-nondirectory (directory-file-name dir))))
  31. (expand-file-name (concat base "-autoloads.el") dir)))
  32. (defun al/find-autoloads (directory)
  33. "Return a list of Emacs 'autoloads' files in DIRECTORY.
  34. The files in the list do not have extensions (.el, .elc)."
  35. (cl-remove-duplicates
  36. (delq nil
  37. (mapcar (lambda (file)
  38. (when (string-match al/autoloads-regexp file)
  39. (match-string 1 file)))
  40. (directory-files directory 'full-name nil 'no-sort)))
  41. :test #'string=))
  42. (defun al/update-autoloads (&rest dirs)
  43. "Update the contents of 'autoloads' files for all DIRS."
  44. (require 'autoload)
  45. (dolist (dir dirs)
  46. (let ((generated-autoload-file (al/autoloads-file dir)))
  47. (update-directory-autoloads dir))))
  48. (provide 'al-autoload)
  49. ;;; al-autoload.el ends here