aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-18 15:34:10 -0500
committerSean Allred <code@seanallred.com>2014-11-18 15:34:10 -0500
commit821bf636028a38562e18d0da0818cd5d09748f97 (patch)
treedc0514c652c49f11619fec77021ab19268e7dbbb /sx.el
parent85268ef6fa01b407e712df8199816f9639a5e539 (diff)
parent93ba268e78dd4967343f479403719a2e20ebc5bd (diff)
Merge pull request #71 from vermiculus/hidden-questions
Hidden questions
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el15
1 files changed, 15 insertions, 0 deletions
diff --git a/sx.el b/sx.el
index 64c555c..387c6bb 100644
--- a/sx.el
+++ b/sx.el
@@ -27,6 +27,21 @@
;;; Utility Functions
+(defmacro sx-sorted-insert-skip-first (newelt list &optional predicate)
+ "Inserted NEWELT into LIST sorted by PREDICATE.
+This is designed for the (site id id ...) lists. So the first car
+is intentionally skipped."
+ `(let ((tail ,list)
+ (x ,newelt))
+ ;; The first element is never less-than.
+ (while (and
+ ;; We're at the end.
+ (cdr-safe tail)
+ ;; We're at the right place.
+ (,(or predicate #'<) x (cadr tail)))
+ (setq tail (cdr tail)))
+ (setcdr tail (cons x (cdr tail)))))
+
(defun sx-message (format-string &rest args)
"Display a message"
(message "[stack] %s" (apply #'format format-string args)))