[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vertico e3515d7007 2/3: vertico-multiform: Add regexp s
From: |
ELPA Syncer |
Subject: |
[elpa] externals/vertico e3515d7007 2/3: vertico-multiform: Add regexp support for vertico-multiform-command-modes/settings |
Date: |
Thu, 30 Dec 2021 01:57:59 -0500 (EST) |
branch: externals/vertico
commit e3515d700716fbd6070fe0cdcf689b3f62ad31ab
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
vertico-multiform: Add regexp support for
vertico-multiform-command-modes/settings
See feedback by @gcv in https://github.com/minad/vertico/issues/149
---
extensions/vertico-multiform.el | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/extensions/vertico-multiform.el b/extensions/vertico-multiform.el
index dce1b30a4d..fce16a0b31 100644
--- a/extensions/vertico-multiform.el
+++ b/extensions/vertico-multiform.el
@@ -49,10 +49,10 @@
(require 'vertico)
(defcustom vertico-multiform-command-modes nil
- "Alist of commands and list of modes to turn on per command.
+ "Alist of commands/regexps and list of modes to turn on per command.
Takes precedence over `vertico-multiform-category-modes'."
:group 'vertico
- :type '(alist :key-type symbol :value-type (repeat symbol)))
+ :type '(alist :key-type (choice symbol regexp) :value-type (repeat symbol)))
(defcustom vertico-multiform-category-modes nil
"Alist of categories and list of modes to turn on per category.
@@ -61,10 +61,10 @@ Has lower precedence than
`vertico-multiform-command-modes'."
:type '(alist :key-type symbol :value-type (repeat symbol)))
(defcustom vertico-multiform-command-settings nil
- "Alist of commands and alist of variables to set per command.
+ "Alist of commands/regexps and alist of variables to set per command.
Takes precedence over `vertico-multiform-category-settings'."
:group 'vertico
- :type '(alist :key-type symbol
+ :type '(alist :key-type (choice symbol regexp)
:value-type (alist :key-type symbol :value-type sexp)))
(defcustom vertico-multiform-category-settings nil
@@ -83,6 +83,16 @@ Has lower precedence than
`vertico-multiform-command-settings'."
(dolist (f (car vertico-multiform--stack))
(funcall f arg)))))
+(defun vertico-multiform--lookup (key list)
+ "Lookup symbolic KEY in LIST.
+The keys in LIST can be symbols or regexps."
+ (and (symbolp key)
+ (cl-loop for x in list
+ if (if (symbolp (car x))
+ (eq key (car x))
+ (string-match-p (car x) (symbol-name key)))
+ return (cdr x))))
+
(defun vertico-multiform--setup ()
"Enable modes at minibuffer setup."
(let ((cat (completion-metadata-get
@@ -101,13 +111,13 @@ Has lower precedence than
`vertico-multiform-command-settings'."
(pop vertico-multiform--stack))))
(add-hook 'minibuffer-exit-hook exit)
(dolist (x (or (and cat (alist-get cat
vertico-multiform-category-settings))
- (alist-get this-command
vertico-multiform-command-settings)))
+ (vertico-multiform--lookup this-command
vertico-multiform-command-settings)))
(set (make-local-variable (car x)) (cdr x)))
(push (mapcar (lambda (m)
(let ((v (intern (format "vertico-%s-mode" m))))
(if (fboundp v) v m)))
(or (and cat (alist-get cat
vertico-multiform-category-modes))
- (alist-get this-command
vertico-multiform-command-modes)))
+ (vertico-multiform--lookup this-command
vertico-multiform-command-modes)))
vertico-multiform--stack)
(vertico-multiform--toggle 1)
(vertico--setup)))