>From 227fea1c404783b93540a1ca2c4c838f9c86ebba Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Sun, 21 Jun 2020 23:09:53 -0400 Subject: [PATCH] lisp: autoload.el: Add a keyword argument to update-directory-autoloads. This provides a way to explicitly specify the GENERATED-AUTOLOAD-FILE file name to use for the generated autoload definitions, which is more convenient when using lexical scoping. Previously, the user had to use dynamic scoping and bind the variable before calling `update-directory-autoloads'. This was discussed in . * lisp/emacs-lisp/autoload.el (update-directory-autoloads): Define the procedure using cl-defun, and add a :generated-autoload-file keyword argument. Update doc. Honor :generated-autoload-file keyword argument, and remove it and its associated value from DIRS, if present. --- lisp/emacs-lisp/autoload.el | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el index ede4edcd57..423cc67e99 100644 --- a/lisp/emacs-lisp/autoload.el +++ b/lisp/emacs-lisp/autoload.el @@ -32,6 +32,8 @@ (require 'lisp-mode) ;for `doc-string-elt' properties. (require 'lisp-mnt) +(require 'seq) + (eval-when-compile (require 'cl-lib)) (defvar generated-autoload-file nil @@ -1023,7 +1025,10 @@ removes any prior now out-of-date autoload entries." (delete-region begin (point))) ;;;###autoload -(defun update-directory-autoloads (&rest dirs) +(cl-defun update-directory-autoloads (&rest dirs + &key (generated-autoload-file + generated-autoload-file) + &allow-other-keys) "Update autoload definitions for Lisp files in the directories DIRS. In an interactive call, you must give one argument, the name of a single directory. In a call from Lisp, you can supply multiple @@ -1035,11 +1040,26 @@ directory or directories specified. In an interactive call, prompt for a default output file for the autoload definitions, and temporarily bind the variable `generated-autoload-file' to this value. When called from Lisp, -use the existing value of `generated-autoload-file'. If any Lisp -file binds `generated-autoload-file' as a file-local variable, -write its autoloads into the specified file instead." +use the existing value of `generated-autoload-file'. +Alternatively, `generated-autoload-file' can also be provided +using a Common Lisp style keyword ':generated-autoload-file' +argument. If any Lisp file binds `generated-autoload-file' as a +file-local variable, write its autoloads into the specified file +instead." (interactive "DUpdate autoloads from directory: ") - (let* ((files-re (let ((tmp nil)) + (let* (;; Honor the :generated-autoload-file keyword argument. + (generated-autoload-file-arg (seq-position + dirs ':generated-autoload-file)) + (generated-autoload-file (if generated-autoload-file-arg + (elt dirs + (1+ generated-autoload-file-arg)) + generated-autoload-file)) + ;; Cleanup dirs from such keyword argument, if any. + (dirs (if generated-autoload-file-arg + (delete generated-autoload-file + (delete ':generated-autoload-file dirs)) + dirs)) + (files-re (let ((tmp nil)) (dolist (suf (get-load-suffixes)) ;; We don't use module-file-suffix below because ;; we don't want to depend on whether Emacs was -- 2.26.2