aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2015-01-15 00:01:32 -0500
committerSean Allred <code@seanallred.com>2015-01-15 00:07:12 -0500
commit3328a62d42ff3ca62c31366a4cd0cfd38a3ec663 (patch)
tree7aa50782f1408fde2280933455beb2afe844dec7 /sx.el
parent766d008e12d7164053bda6d56f336af442109232 (diff)
Create and implement comparator creation macro
This obsoletes `sx--<'.
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el24
1 files changed, 17 insertions, 7 deletions
diff --git a/sx.el b/sx.el
index e080271..87907de 100644
--- a/sx.el
+++ b/sx.el
@@ -259,6 +259,23 @@ 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))
+ (let ((gpf (intern (format " %S--get-prop-function" name)))
+ (cf (intern (format " %S--compare-function" name))))
+ ;; Leading space to hide from completion systems
+ `(progn
+ ;; In using `defalias', the macro supports both function
+ ;; symbols and lambda expressions.
+ (defalias ',gpf ,get-func)
+ (defalias ',cf ,compare-func)
+ (defun ,name (a b)
+ ,doc
+ (,cf (,gpf a) (,gpf b))))))
+
;;; Printing request data
(defvar sx--overlays nil
@@ -349,13 +366,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,