From 3328a62d42ff3ca62c31366a4cd0cfd38a3ec663 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:01:32 -0500 Subject: Create and implement comparator creation macro This obsoletes `sx--<'. --- sx.el | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'sx.el') 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, -- cgit v1.2.3 From 67f1cd1dc24560a21eef8186590020d26d9e55d7 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:26:14 -0500 Subject: Fix letbinding `gpf' used to stand for `get-property-function', but this was abstracted into a `get-function'. The letbinding was never changed. This commit also conveniently allows me to say: Fix #226. --- sx.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 87907de..1cfba12 100644 --- a/sx.el +++ b/sx.el @@ -264,17 +264,17 @@ whenever BODY evaluates to nil." 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)))) + (let ((gf (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) + (defalias ',gf ,get-func) + (defalias ',cf ,compare-func) (defun ,name (a b) ,doc - (,cf (,gpf a) (,gpf b)))))) + (,cf (,gf a) (,gf b)))))) ;;; Printing request data -- cgit v1.2.3 From 6c4e7c6b95e8bd7d83e5d0f868d9fb3a70c7a974 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 16 Jan 2015 00:45:35 -0500 Subject: Don't define aliases with comparators The aliases were created in the fear that runtime would be slower to interpret the duplicated lambda expressions for get-func. After testing, this was found not to be the case. `funcall' is a much nicer solution. --- sx.el | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 1cfba12..829570f 100644 --- a/sx.el +++ b/sx.el @@ -264,17 +264,14 @@ whenever BODY evaluates to nil." 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 ((gf (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 ',gf ,get-func) - (defalias ',cf ,compare-func) - (defun ,name (a b) - ,doc - (,cf (,gf a) (,gf b)))))) + `(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 -- cgit v1.2.3