[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/helm 3c0820d6c6 1/3: Improve helm-acase
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/helm 3c0820d6c6 1/3: Improve helm-acase |
Date: |
Mon, 19 Feb 2024 13:00:13 -0500 (EST) |
branch: elpa/helm
commit 3c0820d6c64a52e18468ee961a408727bc0b9c23
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Improve helm-acase
It is now able to handle sexps.
---
helm-files.el | 6 +++---
helm-lib.el | 25 +++++++++++++++----------
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/helm-files.el b/helm-files.el
index 85d083c043..a6fa3ac5b3 100644
--- a/helm-files.el
+++ b/helm-files.el
@@ -5335,9 +5335,9 @@ arg."
(abbreviate-file-name candidate))
(t (file-relative-name candidate)))
(helm-acase prefarg
- ('(4) (abbreviate-file-name candidate))
- ('(16) (file-relative-name candidate))
- ('(64) (helm-basename candidate))
+ ((4) (abbreviate-file-name candidate))
+ ((16) (file-relative-name candidate))
+ ((64) (helm-basename candidate))
(t candidate))))
(cl-defun helm-find-files-history (arg &key (comp-read t))
diff --git a/helm-lib.el b/helm-lib.el
index 72c123dd0f..7bb3650644 100644
--- a/helm-lib.el
+++ b/helm-lib.el
@@ -566,20 +566,25 @@ is usable in next condition."
(helm-aand ,@(cdr conditions))))))
(defmacro helm-acase (expr &rest clauses)
- "A simple anaphoric `cl-case' implementation handling strings.
-EXPR is bound to a temporary variable called `it' which is usable
-in CLAUSES to refer to EXPR.
-NOTE: Duplicate keys in CLAUSES are deliberately not handled.
+ "A simple anaphoric case implementation.
+The car of each clause can be any object that will be compared
+with `equal' or an expression starting with `guard' which should
+return a boolean. EXPR is bound to a temporary variable called
+`it' which is usable in CLAUSES to refer to EXPR. The car of
+each CLAUSES doesn't need to be quoted.
\(fn EXPR (KEYLIST BODY...)...)"
(declare (indent 1) (debug (form &rest (sexp body))))
(unless (null clauses)
- (let ((clause1 (car clauses)))
- `(let ((key ',(car clause1))
- (it ,expr))
- (if (or (equal it key)
- (and (listp key) (member it key))
- (eq key t))
+ (let* ((clause1 (car clauses))
+ (key (car clause1))
+ (sexp (and (eq 'guard (car-safe key))
+ (cadr key))))
+ `(let ((it ,expr))
+ (if (or (equal it ',key)
+ (and (listp ',key) (member it ',key))
+ (eq ',key t)
+ (and (listp ',key) ,sexp))
(progn ,@(cdr clause1))
(helm-acase it ,@(cdr clauses)))))))