[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/taxy 09724dd 10/39: Add: taxy-take-keyed
From: |
ELPA Syncer |
Subject: |
[elpa] externals/taxy 09724dd 10/39: Add: taxy-take-keyed |
Date: |
Fri, 27 Aug 2021 10:57:31 -0400 (EDT) |
branch: externals/taxy
commit 09724dd73010a3ef1e799f20c6fe6daf121eb153
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add: taxy-take-keyed
---
README.org | 17 ++---------------
taxy.el | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/README.org b/README.org
index e3784ab..b4b07c2 100644
--- a/README.org
+++ b/README.org
@@ -151,20 +151,7 @@ You may not always know in advance what taxonomy a set of
objects fits into, so
:taxys (list
(make-taxy
:name "Modes"
- :take (lambda (buffer taxy)
- (let* ((key (buffery-major-mode buffer))
- (key-taxy
- (or (cl-find-if (lambda (taxy-key)
- (equal key taxy-key))
- (taxy-taxys taxy)
- :key #'taxy-key)
- (car
- (push (make-taxy
- :name key :key key
- :predicate (lambda (buffer)
- (equal key
(buffery-major-mode buffer))))
- (taxy-taxys taxy))))))
- (push buffer (taxy-objects key-taxy))))))))
+ :take (apply-partially #'taxy-take-keyed
#'buffery-major-mode)))))
;; Note the use of `taxy-copy' to avoid mutating the original taxy
definition.
(taxy-simple
@@ -172,7 +159,7 @@ You may not always know in advance what taxonomy a set of
objects fits into, so
(taxy-copy buffery)))
#+END_SRC
-Which produces this taxonomy of buffers:
+The taxy's ~:take~ function is set to the ~taxy-take-keyed~ function,
partially applied with the ~buffery-major-mode~ function as its ~key-fn~
(~taxy-fill~ supplies the buffer and the taxy as arguments), and it produces
this taxonomy of buffers:
#+BEGIN_SRC elisp
("Buffers"
diff --git a/taxy.el b/taxy.el
index 621e0fd..7aafb88 100644
--- a/taxy.el
+++ b/taxy.el
@@ -95,6 +95,25 @@ useful form after classification."
collect (taxy-apply fn taxy)))
taxy)
+(cl-defun taxy-take-keyed (key-fn object taxy &key (key-name-fn #'identity))
+ "Take OBJECT into TAXY, adding new taxys dynamically.
+Places OBJECT into a taxy in TAXY for the value returned by
+KEY-FN called with OBJECT. The new taxy's name is that returned
+by KEY-NAME-FN called with OBJECT."
+ (let* ((key (funcall key-fn object))
+ (key-taxy
+ (or (cl-find-if (lambda (taxy-key)
+ (equal key taxy-key))
+ (taxy-taxys taxy)
+ :key #'taxy-key)
+ (car
+ (push (make-taxy
+ :name (funcall key-name-fn key) :key key
+ :predicate (lambda (object)
+ (equal key (funcall key-fn object))))
+ (taxy-taxys taxy))))))
+ (push object (taxy-objects key-taxy))))
+
;;;; Footer
(provide 'taxy)
- [elpa] branch externals/taxy created (now 2c044ed), ELPA Syncer, 2021/08/27
- [elpa] externals/taxy dbad5b9 01/39: Let there be taxonomy!, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 8797141 02/39: Dynamic, consuming, and non-consuming, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 6c5b7c7 07/39: Add: taxy-apply, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 02217c4 11/39: Docs: Add comments, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 408a32b 09/39: Docs: Tidy, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 09724dd 10/39: Add: taxy-take-keyed,
ELPA Syncer <=
- [elpa] externals/taxy 9d44dba 13/39: Change: taxy-apply -> taxy-map, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 6eff6ae 18/39: Docs: Put Contents first, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 0a57638 17/39: Docs: Mention threading macros, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 0dce844 16/39: Docs: Add example of incremental filling, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy e09dc38 32/39: Add: (taxy-mapc*) And musicy.el example, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy bd28836 24/39: Meta: Headers, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy f0b926f 34/39: Add: Diredy example, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 21e6fa6 22/39: Docs: Commentary, header, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy e56ae33 26/39: Meta: .gitignore, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 15eb9b7 31/39: Docs: Tidy, ELPA Syncer, 2021/08/27