[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kubed 6c8dabc369 47/70: New user option 'kubed-list-fil
From: |
ELPA Syncer |
Subject: |
[elpa] externals/kubed 6c8dabc369 47/70: New user option 'kubed-list-filter-operator-alist' |
Date: |
Tue, 6 Aug 2024 06:58:32 -0400 (EDT) |
branch: externals/kubed
commit 6c8dabc369f6b642ec00bfab3158f2ce3a63979c
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
New user option 'kubed-list-filter-operator-alist'
* kubed.el (kubed-list-filter-operator-alist): New option.
(kubed-list-interpret-atomic-filter)
(kubed-list-validate-atomic-filter): Use it instead of hardcoding
operators "=" and "~".
(kubed-list-set-filter): Adjust docstring.
---
kubed.el | 47 ++++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/kubed.el b/kubed.el
index 61c35cf82c..cf85e60e75 100644
--- a/kubed.el
+++ b/kubed.el
@@ -93,6 +93,19 @@ obtaining new information from Kuberenetes clusters.")
(message "Kubed \"all namespaces\" mode is now %s"
(if kubed-all-namespaces-mode "ON" "OFF")))
+(defcustom kubed-list-filter-operator-alist
+ '((= . string=)
+ (~ . string-match-p))
+ "Association list of filter operators and functions that implement them.
+
+Element of this list are cons cells (OP . FN), where OP is a symbol that
+is used as a filter operator and FN is a function that implements OP.
+FN takes two arguments, a string STR and a parameter VAL. FN should
+return non-nil if STR and VAL are related according to OP: to determine
+if a line in which column COL is STR satisfies the filter (OP COL VAL),
+Kubed checks if the form (FN STR VAL) evaluates to non-nil."
+ :type '(alist :key-type (symbol :tag "Operator") :value-type function))
+
(defun kubed-list-interpret-atomic-filter (atom)
"Return function that implements atomic filter ATOM."
(if (eq (car-safe atom) 'quote)
@@ -101,10 +114,8 @@ obtaining new information from Kuberenetes clusters.")
(let* ((column-number (tabulated-list--column-number (symbol-name (nth 1
atom))))
(value (nth 2 atom))
(value (if (stringp value) value (prin1-to-string value)))
- (op (cond
- ((eq (car atom) '=) #'string=)
- ((eq (car atom) '~) #'string-match-p)
- (t (user-error "Unknown filter operator `%S'" (car atom))))))
+ (op (alist-get (car atom) kubed-list-filter-operator-alist)))
+ (unless op (user-error "Unknown filter operator `%S'" (car atom)))
(lambda (x) (funcall op value (aref (cadr x) column-number))))))
(defvar-local kubed-list-filter nil "Filter in effect in the current buffer.")
@@ -153,10 +164,10 @@ If FILTER is omitted or nil, it defaults to
`kubed-list-filter'."
(format (substitute-quotes
"Invalid atomic filter `%S', must have three elements")
atom)))
- (unless (memq (car atom) '(= ~))
+ (unless (assq (car atom) kubed-list-filter-operator-alist)
(throw 'validation-error
(format (substitute-quotes
- "Invalid filter operator `%S', must be one of `=', `~'")
+ "No operator `%S' in `kubed-list-filter-operator-alist'")
(car atom))))
(unless (ignore-errors
(tabulated-list--column-number (symbol-name (nth 1 atom))))
@@ -251,7 +262,9 @@ of the error, push a mark before moving point."
(argi (cadr fn-argi)))
(if (= argi 0)
;; Complete operators.
- (list (car bounds) (cdr bounds) '("=" "~"))
+ (list
+ (car bounds) (cdr bounds)
+ (mapcar #'car kubed-list-filter-operator-alist))
(when (car fn-argi)
(cond
((= argi 1)
@@ -281,16 +294,14 @@ of the error, push a mark before moving point."
"Set the filter of the current buffer to FILTER.
FILTER determines which resources to keep. FILTER can be an atomic
-filter, which is a list (OP COL VAL), where OP is one of the symbols
-\\+`=' and `~', COL is a symbol whose name is a column name, and VAL is
-a string or an object whose printed representation is compared to the
-value of the column COL according to OP. If OP is \\+`=' it says to
-compare with `string=', if OP is `~' it says to use `string-match-p'.
-For example, the atomic filter (= Name foobar) keeps only resources
+filter, which is a list (OP COL VAL), where OP is an operator defined in
+`kubed-list-filter-operator-alist' (which see), COL is a symbol whose
+name is a column name, and VAL is a string or an object whose printed
+representation is compared to the value of the column COL according to
+OP. For example, the atomic filter (= Name foobar) keeps only resources
whose name is \"foobar\". (= Name \"foobar\") does exactly the same.
-You can also negate an atomic filter by quoting it, for instance
-\\='(~ Namespace kube) filters out all resources in namespaces that
-include \"kube\" as a substring.
+To negate an atomic filter, quote it. E.g. use \\='(~ Namespace kube)
+to hide all resources in namespaces whose name contains \"kube\".
FILTER can also be a list of sub-filters (SUB1 SUB2 ...) where each
sub-filter is either an atomic filter or a list of atomic filters. If a
@@ -311,7 +322,9 @@ More examples:
Interactively, prompt for FILTER sans the outermost set of parenthesis.
For example, enter \"= Name foobar\" in the minibuffer to specify the
-atomic FILTER (= Name foobar)."
+atomic FILTER (= Name foobar).
+
+See also Info node \"(kubed) List Filter\"."
(interactive (list (kubed-list-read-filter "Set filter")) kubed-list-mode)
(when-let ((validation-error (kubed-list-validate-filter filter)))
(user-error validation-error))
- [elpa] externals/kubed 018d529c3b 33/70: New command 'kubed-transient-rollout', (continued)
- [elpa] externals/kubed 018d529c3b 33/70: New command 'kubed-transient-rollout', ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 1a6d51981c 02/70: ; * README.md (Getting Started): Fix typo, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed b7227ed155 12/70: ; README.md: Add figure showing pods context menu., ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 9aa3c97dcc 14/70: Extend resource name reading functions with namespace arg, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 1047609241 26/70: * kubed.texi (Extending Kubed): Populate., ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 667ccdb4a2 27/70: New commands for creating jobs from cronjobs, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 144e0cf167 32/70: New command 'kubed-watch-deployment-status', ELPA Syncer, 2024/08/06
- [elpa] externals/kubed bd3ebf3827 37/70: New command 'kubed-list-set-filter' in list buffers, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 2f062f5175 44/70: Document a couple more 'tabulated-list-mode' commands, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 83e71ecb32 42/70: New commands for table navigation, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 6c8dabc369 47/70: New user option 'kubed-list-filter-operator-alist',
ELPA Syncer <=
- [elpa] externals/kubed bccc588b20 39/70: ; * kubed.el (kubed-list-read-filter): Fix typo., ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 7c75a19dd4 48/70: (List Filter): Document 'kubed-list-filter-operator-alist', ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 7c46d70a61 49/70: Update NEWS.org and bump version to 0.2.0, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed eb966a2aed 51/70: New command 'kubed-list-copy-as-kill', ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 238f38c847 52/70: New commands that run kubectl with resource at point as arg, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 98ad4e1b53 56/70: ; Move some user option definitions together, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 9afecde975 60/70: ; Tweak autoloading for transients, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed df1cf34e37 58/70: New transient menu for displaying resources, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 5899ab69b0 63/70: Support bookmarking resource list buffers, ELPA Syncer, 2024/08/06
- [elpa] externals/kubed 25c79c51bf 66/70: ; Update NEWS.org and bump version to 0.3.0, ELPA Syncer, 2024/08/06