aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2015-01-16 00:54:32 -0500
committerSean Allred <code@seanallred.com>2015-01-16 00:54:32 -0500
commitfe140f7891257890687ec6e3243d66f1aa95fc65 (patch)
treecee86917c73725c7f8d3a33e0f4cf85ae76a1efb /sx.el
parent22f86c35499f994f0eb7532b8eb27b0d990d889d (diff)
parent6c4e7c6b95e8bd7d83e5d0f868d9fb3a70c7a974 (diff)
Merge pull request #228 from vermiculus/vermiculus/sort-answers
Customizable sorting; Fix #226. Generalization of #225.
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el21
1 files changed, 14 insertions, 7 deletions
diff --git a/sx.el b/sx.el
index 36ecfca..a385a84 100644
--- a/sx.el
+++ b/sx.el
@@ -259,6 +259,20 @@ whenever BODY evaluates to nil."
:filter (lambda (&optional _)
(when (progn ,@body) ,def)))))
+(defmacro sx--create-comparator (name doc compare-func get-func)
+ "Define a new comparator called NAME with documentation DOC.
+COMPARE-FUNC is a function that takes the return value of
+GET-FUNC and performs the actual comparison."
+ (declare (indent 1) (doc-string 2))
+ `(progn
+ ;; In using `defalias', the macro supports both function
+ ;; symbols and lambda expressions.
+ (defun ,name (a b)
+ ,doc
+ (funcall ,compare-func
+ (funcall ,get-func a)
+ (funcall ,get-func b)))))
+
;;; Printing request data
(defvar sx--overlays nil
@@ -354,13 +368,6 @@ Run after `sx-init--internal-hook'."
This is used internally to set initial values for variables such
as filters.")
-(defun sx--< (property x y &optional predicate)
- "Non-nil if PROPERTY attribute of alist X is less than that of Y.
-With optional argument PREDICATE, use it instead of `<'."
- (funcall (or predicate #'<)
- (cdr (assoc property x))
- (cdr (assoc property y))))
-
(defmacro sx-init-variable (variable value &optional setter)
"Set VARIABLE to VALUE using SETTER.
SETTER should be a function of two arguments. If SETTER is nil,