@@ -290,5 +290,49 @@ If SORT is non-nil, the result will be lexicographically sorted."
290290 (cl-remove-duplicates )
291291 (order)))))
292292
293+ (defun use-package-tags--unloaded-tags ()
294+ " Return a list of tags that are not in the current profile."
295+ (-difference (use-package-tags-collect-tags t :sort t )
296+ use-package-tags-current-profile))
297+
298+ ;;;### autoload
299+ (defun use-package-tags-load (tag )
300+ " Load packages with a TAG.
301+
302+ This function evalates `use-package' forms with the selected tag
303+ in `use-package-tags-init-files' .
304+
305+ After successfully loading all matching packages, the tag will be
306+ added to `use-package-tags-current-profile' , without saving the value
307+ to `custom-file' ."
308+ (interactive (list (completing-read " Load packages with tag: "
309+ (use-package-tags--unloaded-tags)
310+ nil 'match )))
311+ (cl-labels
312+ ((get-keyword (prop rest) (-some->> (member prop rest)
313+ (nth 1 )))
314+ (has-tag-p (tag rest)
315+ (let ((tags (cdr (get-keyword :tags rest))))
316+ (memq tag (cl-etypecase tags
317+ (list tags)
318+ (symbol (list tags)))))))
319+ (setq tag (cl-etypecase tag
320+ (tag tag)
321+ (string (intern tag))))
322+ (push tag use-package-tags-current-profile)
323+ (condition-case err
324+ (use-package-tags--with-package-forms
325+ (use-package-tags--source-buffer-list t )
326+ (let ((exp (read (current-buffer ))))
327+ (when (has-tag-p tag exp)
328+ (message " Loading package %s configured at %s ... "
329+ (nth 1 exp)
330+ (abbreviate-file-name (buffer-file-name )))
331+ (eval exp))))
332+ (error (progn
333+ (message " Error while loading the package: %s " err)
334+ (cl-delete tag use-package-tags-current-profile)
335+ (error err))))))
336+
293337(provide 'use-package-tags )
294338; ;; use-package-tags.el ends here
0 commit comments