1 ;; Copyright (C) 2007 Vesa Karvonen
3 ;; MLton is released under a BSD-style license.
4 ;; See the file MLton-LICENSE for details.
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 (defun bg-build-cons-once (entry list
)
13 (cons entry
(remove* entry list
:test
(function equal
))))
15 (defun bg-build-flatmap (fn list
)
16 (apply (function append
) (mapcar fn list
)))
18 (defun bg-build-remove-from-assoc (alist key
)
23 (equal key
(car key-value
))))))
25 (defun bg-build-replace-in-assoc (alist key value
)
26 (cons (cons key value
)
27 (bg-build-remove-from-assoc alist key
)))
29 (defun bg-build-assoc-cdr (key alist
)
30 "Same as (cdr (assoc key alist)) except that doesn't attempt to call cdr
32 (let ((key-value (assoc key alist
)))
36 (defun bg-build-const (value)
37 "Returns a function that returns the given value."
38 (lexical-let ((value value
))
42 (defun bg-build-kill-current-buffer ()
43 "Kills the current buffer."
45 (kill-buffer (current-buffer)))
47 (defun bg-build-make-hash-table ()
48 "Makes a hash table with `equal' semantics."
49 (make-hash-table :test
'equal
:size
1))
51 (defun bg-build-point-at-current-line ()
52 "Returns point at the beginning of the current line."
57 (defun bg-build-current-line ()
58 "Returns the current line number counting from 1."
59 (+ 1 (count-lines 1 (bg-build-point-at-current-line))))
61 (defun bg-build-time-to-double (time)
62 "Converts a time to a double."
63 (+ (* (car time
) 65536.0)
65 (if (cddr time
) (* (caddr time
) 1e-06) 0)))
67 (defun bg-build-attr-newer?
(attr1 attr2
)
68 "Returns non-nil iff the modification time of `attr1' is later than the
69 modification time of `attr2'. Note that this also returns nil when either
70 one of the modification times is nil."
72 (> (bg-build-time-to-double (nth 5 attr1
))
73 (bg-build-time-to-double (nth 5 attr2
)))))
75 (defun bg-build-pos-to-point (pos)
76 "Returns the value of point in the current buffer at the position given
77 as a (line . col) pair."
80 (+ (point) (cdr pos
))))
82 (defun bg-build-point-to-pos (point)
83 "Returns the position as a (line . col) pair corresponding to the
84 specified point in the current buffer."
88 (let ((line (+ (count-lines 1 (point)) 1))
89 (col (- point
(point))))
92 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
94 (provide 'bg-build-util
)