[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/taxy d682c37 13/42: Add: (taxy-make-take-function)
From: |
ELPA Syncer |
Subject: |
[elpa] externals/taxy d682c37 13/42: Add: (taxy-make-take-function) |
Date: |
Wed, 15 Sep 2021 12:57:28 -0400 (EDT) |
branch: externals/taxy
commit d682c3727521db91d7c517bf56a91b38d8f7855d
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add: (taxy-make-take-function)
---
taxy.el | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/taxy.el b/taxy.el
index 3fbbb5d..40b66e3 100644
--- a/taxy.el
+++ b/taxy.el
@@ -263,9 +263,11 @@ KEY is passed to `cl-sort', which see."
(defalias 'taxy-sort* #'taxy-sort-taxys)
-;;;; Defining key functions
+;;;; Key functions
-;; Utilities to define key functions and helpers in a standard way.
+;; Utilities to define key and take functions in a standard way.
+
+;; TODO: Document these.
(defmacro taxy-define-key-definer (name variable prefix docstring)
"Define a macro NAME that defines a key-function-defining macro.
@@ -304,6 +306,47 @@ item being tested, bound within the function to `item'."
(fset ',fn-symbol ,fn)
(setf (map-elt ,variable ',name) ',fn-symbol))))))
+(defun taxy-make-take-function (keys aliases)
+ "Return a `taxy' \"take\" function for KEYS.
+Each of KEYS should be a function alias defined in ALIASES, or a
+list of such KEY-FNS (recursively, ad infinitum, approximately).
+ALIASES should be an alist mapping aliases to functions (such as
+defined with a definer defined by `taxy-define-key-definer')."
+ (let ((macrolets (cl-loop for (name . fn) in aliases
+ collect `(,name ',fn))))
+ (cl-labels ((expand-form
+ ;; Is using (cadr (macroexpand-all ...)) really better than
`eval'?
+ (form) (cadr (macroexpand-all
+ `(cl-symbol-macrolet (,@macrolets)
+ ,form))))
+ (quote-fn
+ (fn) (pcase fn
+ ((pred symbolp) (expand-form fn))
+ (`(,(and (or 'and 'or 'not) boolean) . ,(and args (map
:name :keys)))
+ ;; Well, that pcase expression isn't confusing at
all... ;)
+ ;; (cl-assert name t "Boolean key functions require
a NAME")
+ ;; (cl-assert keys t "Boolean key functions require
KEYS")
+ `(lambda (buffer)
+ (when (cl-loop for fn in ',(mapcar #'quote-fn (or
keys args))
+ ,(pcase boolean
+ ('and 'always)
+ ('or 'thereis)
+ ('not 'never))
+ (funcall fn buffer))
+ (or ,name ""))))
+ (`(,(and (pred symbolp) fn)
+ . ,(and args (guard (cl-typecase (car args)
+ ((or keyword (and atom (not
symbol)))
+ t)))))
+ ;; Key with args: replace with a lambda that
+ ;; calls that key's function with given args.
+ `(lambda (element)
+ (,(expand-form fn) element ,@args)))
+ ((pred listp) (mapcar #'quote-fn fn)))))
+ (setf keys (mapcar #'quote-fn keys))
+ `(lambda (item taxy)
+ (taxy-take-keyed ',keys item taxy)))))
+
;;;; Footer
(provide 'taxy)
- [elpa] externals/taxy 5020b43 31/42: Change: (deffy-goto-form) Bug #50576 is fixed., (continued)
- [elpa] externals/taxy 5020b43 31/42: Change: (deffy-goto-form) Bug #50576 is fixed., ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 0826a47 02/42: WIP: taxy-magit-section column/table formatting, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy d456f88 24/42: Add: (deffy-side-window-action), ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 3787f4f 25/42: Fix: (deffy-buffer) Ensure file name, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 7ecc461 15/42: Fix: (taxy-magit-section-define-column-definer) Use defcustoms, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 8b7a95a 35/42: Docs: Clarify, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 2f4d9c3 05/42: Add: (taxy-magit-section-insert-indent-items), ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 9f9cfef 34/42: Docs: Reorder sections, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 7a63677 08/42: Add: (taxy-define-key-definer), ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 69872e4 06/42: Docs: Update readme, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy d682c37 13/42: Add: (taxy-make-take-function),
ELPA Syncer <=
- [elpa] externals/taxy 8d108ef 18/42: WIP: Rename elispy to deffy, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 468e9b9 01/42: Meta: Add .dir-locals.el, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 2430282 20/42: Tidy: Indentation, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy b37dd39 17/42: WIP: Tidy, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 43b8504 36/42: Docs: Update changelog, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 16d4e50 23/42: Fix/Tidy: (deffy-buffer), ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 45372f6 27/42: Fix: (taxy-magit-section-format-items) Width, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 956efdd 37/42: Comment: Update TODO, ELPA Syncer, 2021/09/15
- [elpa] externals/taxy ade9a02 42/42: Merge branch 'wip/magit-section-column-formatting', ELPA Syncer, 2021/09/15
- [elpa] externals/taxy 5227980 40/42: Docs: (taxy-magit-section-define-column-definer) Add docstring, ELPA Syncer, 2021/09/15