summaryrefslogtreecommitdiffstats
path: root/util.tl
blob: e987423f672dc375a2ecdcada4b0a102895e023e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(defun move-impl (items keys ins-pos)
  (let ((key-items (mapcar (op find @1 items) keys))
        (rm-items [set-diff items keys equal]))
    (append [rm-items 0..ins-pos]
            key-items
            [rm-items ins-pos..:])))

(defun minpos (items keys)
  [reduce-left min (mapcar (op posqual @1 items) keys) (length items)])

(defun move-up (items keys)
  (move-impl items keys
             (max 0 (pred (minpos items keys)))))

(defun move-down (items keys)
  (move-impl items keys
             (succ (minpos items keys))))

(defun move-front (items keys)
  (move-impl items keys 0))

(defun move-tail (items keys)
  (move-impl items keys (length items)))

(defun html-encode-with-http (str)
  (let* ((pairs (tuples 2 (tok-str str #/https?:\/\/\S+/ t))))
    (cat-str
      (mappend (tb ((text : link))
                 (list (html-encode text)
                       (if link `<sup>[<a href="@link">link</a>]</sup>`)))
               pairs))))