@@ -223,23 +223,36 @@ PROJECT-DIR is the absolute path of the project directory."
223223 " Return the absolute path to the project directory in the given CONTEXT."
224224 (cdr (assoc 'project-dir context)))
225225
226- (defun ede-php-autoload-composer-define-visitor (visitor )
226+ (defun ede-php-autoload-composer-define-visitor (visitor &optional step )
227227 " Add a new VISITOR to the list of composer visitors.
228228
229229A visitor is a function that takes a context and the current list
230230of autoloads, and returns a new list of autoloads.
231231
232232All visitors are executed when a composer project is detected, to
233- generate the composer autoloads."
234- (add-to-list 'ede-php-autoload-composer--visitors visitor))
235-
236- (defun ede-php-autoload-composer--run-visitors (context autoloads )
233+ generate the composer autoloads.
234+
235+ STEP is the autoload construction step at which the visitor
236+ should execute. It can be `:early' , `:normal' or `:late. It
237+ defaults to `:normal'.' "
238+ (let* ((real-step (or step :normal ))
239+ (pair (assoc real-step ede-php-autoload-composer--visitors)))
240+ (if pair
241+ (setf (cdr pair) (push visitor (cdr pair)))
242+ (add-to-list 'ede-php-autoload-composer--visitors (cons real-step (list visitor))))))
243+
244+ (defun ede-php-autoload-composer--run-visitors (visitors context autoloads )
237245 " Run all the visitors on a specified CONTEXT, with the initial AUTOLOADS.
238246
239247Returns the new list of autoloads."
240- (let ((current-autoloads autoloads))
241- (dolist (visitor ede-php-autoload-composer--visitors)
242- (setq current-autoloads (funcall visitor context current-autoloads)))
248+ (let ((current-autoloads autoloads)
249+ step-visitors)
250+
251+ (dolist (step '(:early :normal :late ))
252+ (setq step-visitors (cdr (assoc step visitors)))
253+ (dolist (visitor step-visitors)
254+ (setq current-autoloads (funcall visitor context current-autoloads))))
255+
243256 current-autoloads))
244257
245258; ; Basic visitors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -287,7 +300,7 @@ information into AUTOLOADS."
287300 (lock-file (expand-file-name ede-php-autoload-composer-lock-file project-dir))
288301 (composer-lock (when (file-exists-p lock-file) (json-read-file lock-file)))
289302 (context (ede-php-autoload-composer-make-context composer-data composer-lock project-dir)))
290- (ede-php-autoload-composer--run-visitors context autoloads)))
303+ (ede-php-autoload-composer--run-visitors ede-php-autoload-composer--visitors context autoloads)))
291304
292305
293306(provide 'ede-php-autoload-composer )
0 commit comments