branch: externals/consult
commit 2251d55aa7c84ebbf11274f44ab6879d3808c2a7
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    Add consult-info-define
---
 CHANGELOG.org   |  5 +++++
 README.org      | 29 ++++++++++++-----------------
 consult-info.el | 15 +++++++++++++++
 3 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index d3003db89c..1179ffec0c 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -2,6 +2,11 @@
 #+author: Daniel Mendler
 #+language: en
 
+* Development
+
+- Add ~consult-info-define~ to conveniently define custom ~consult-info-*~ 
commands
+  to search through a subset of info manuals.
+
 * Version 2.1 (2025-03-11)
 
 - Remove obsolete ~consult--async-*~ APIs.
diff --git a/README.org b/README.org
index c5e11eaf17..3162a118b0 100644
--- a/README.org
+++ b/README.org
@@ -351,30 +351,25 @@ their descriptions.
 :end:
 
 #+findex: consult-info
+#+findex: consult-info-define
 #+findex: consult-man
 - =consult-man=: Find Unix man page, via Unix =apropos= or =man -k=. 
=consult-man= opens
   the selected man page using the Emacs =man= command. Supports live preview of
   the theme while scrolling through the candidates.
 - =consult-info=: Full text search through info pages. If the command is 
invoked
   from within an ~*info*~ buffer, it will search through the current manual. 
You
-  may want to create your own commands which search through a predefined set of
-  info pages, for example:
+  may want to create your own =consult-info-*= commands which search through a
+  predefined set of info pages. You can use the function =consult-info-define= 
to
+  define commands =consult-info-emacs=, =consult-info-completion=, 
=consult-info-org=,
+  and so on:
 #+begin_src emacs-lisp
-(defun consult-info-emacs ()
-  "Search through Emacs info pages."
-  (interactive)
-  (consult-info "emacs" "efaq" "elisp" "cl" "compat"))
-
-(defun consult-info-org ()
-  "Search through the Org info page."
-  (interactive)
-  (consult-info "org"))
-
-(defun consult-info-completion ()
-  "Search through completion info pages."
-  (interactive)
-  (consult-info "vertico" "consult" "marginalia" "orderless" "embark"
-                "corfu" "cape" "tempel"))
+(consult-info-define "emacs" "efaq" "elisp" "cl" "compat" "eshell")
+(consult-info-define 'completion
+                     "vertico" "consult" "marginalia" "orderless"
+                     "embark" "corfu" "cape" "tempel")
+(consult-info-define "org")
+(consult-info-define "gnus")
+(consult-info-define "magit")
 #+end_src
 
 ** Miscellaneous
diff --git a/consult-info.el b/consult-info.el
index 8aad712697..f594e1a354 100644
--- a/consult-info.el
+++ b/consult-info.el
@@ -200,5 +200,20 @@ CALLBACK receives the candidates."
        :add-history (thing-at-point 'symbol)
        :lookup #'consult--lookup-member))))
 
+;;;###autoload
+(progn ;; Wrapped with `progn' to preload `consult-info-define'.
+  (defun consult-info-define (name &rest manuals)
+    "Define `consult-info-NAME' command to search through MANUALS.
+MANUALS is a list of a strings. NAME can be a symbol or a string. If
+NAME is a string, it is added to the MANUALS list."
+    (let ((cmd (intern (format "consult-info-%s" name))))
+      (when (stringp name) (push name manuals))
+      (defalias cmd (lambda () (interactive) (apply #'consult-info manuals))
+        (format "Search via `consult-info' through the manual%s %s:\n\n%s"
+                (if (cdr manuals) "s" "")
+                (mapconcat (lambda (m) (format "\"%s\"" m)) manuals ", ")
+                (mapconcat (lambda (m) (format "  * Info node `(%s)'" m)) 
manuals "\n")))
+      cmd)))
+
 (provide 'consult-info)
 ;;; consult-info.el ends here

Reply via email to