]> git.eshelyaron.com Git - emacs.git/commitdiff
New command load-libraries-for-prefix
authorEshel Yaron <me@eshelyaron.com>
Mon, 14 Oct 2024 17:03:00 +0000 (19:03 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 14 Oct 2024 17:03:00 +0000 (19:03 +0200)
lisp/files.el

index 8598f90c89bfab189e47b2216547c0d5dc2cc56e..730026e925fac1b57b46dbe819f015a4455b0ffe 100644 (file)
@@ -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