From: Eshel Yaron Date: Mon, 14 Oct 2024 17:03:00 +0000 (+0200) Subject: New command load-libraries-for-prefix X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=974a91342e8b8d2765a70914901511a7b56f6b64;p=emacs.git New command load-libraries-for-prefix --- diff --git a/lisp/files.el b/lisp/files.el index 8598f90c89b..730026e925f 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1274,6 +1274,38 @@ See `load-file' for a different interface to `load'." (put 'load-library 'minibuffer-action "load") +(defun load-libraries-for-prefix (prefix) + "Load libraries that define symbols whose name starts with PREFIX." + (interactive + (let* ((str (thing-at-point 'symbol)) + (def (if (gethash str definition-prefixes) str + (when (gethash (setq str (concat str "-")) definition-prefixes) + str)))) + (list (completing-read + (format-prompt "Load libraries for prefix" def) + (completion-table-with-metadata + definition-prefixes + `((affixation-function + . ,(lambda (cands) + (let ((max (seq-max (cons 0 (mapcar #'string-width cands))))) + (mapcar + (lambda (cand) + (list cand "" + (concat (make-string (1+ (- max (string-width cand))) ?\s) + (propertize + (string-join (seq-uniq (gethash cand definition-prefixes)) ",") + 'face 'completions-annotations + 'help-echo "library")))) + cands)))))) + (lambda (_prefix libraries) + (seq-some (lambda (library) + (not (featurep (intern-soft library)))) + libraries)) + t nil nil def)))) + (mapc #'load (gethash prefix definition-prefixes))) + +(put 'load-libraries-for-prefix 'minibuffer-action "load") + (defun require-with-check (feature &optional filename noerror) "If FEATURE is not already loaded, load it from FILENAME. This is like `require' except if FEATURE is already a member of the list