1 ;;; fuel-base.el --- Basic FUEL support code
3 ;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
4 ;; See http://factorcode.org/license.txt for BSD license.
6 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
11 ;; Basic definitions likely to be used by all FUEL modules.
15 (defconst fuel-version
"1.0")
18 (defsubst fuel-version
()
19 "Echoes FUEL's version."
21 (message "FUEL %s" fuel-version
))
28 "Factor's Ultimate Emacs Library."
32 ;;; Emacs compatibility:
34 (eval-after-load "ring"
35 '(when (not (fboundp 'ring-member
))
36 (defun ring-member (ring item
)
38 (dotimes (ind (ring-length ring
) nil
)
39 (when (equal item
(ring-ref ring ind
))
40 (throw 'found ind
)))))))
42 (when (not (fboundp 'completion-table-dynamic
))
43 (defun completion-table-dynamic (fun)
44 (lexical-let ((fun fun
))
45 (lambda (string pred action
)
46 (with-current-buffer (let ((win (minibuffer-selected-window)))
47 (if (window-live-p win
) (window-buffer win
)
49 (complete-with-action action
(funcall fun string
) string pred
))))))
51 (when (not (fboundp 'looking-at-p
))
52 (defsubst looking-at-p
(regexp)
53 (let ((inhibit-changing-match-data t
))
54 (looking-at regexp
))))
59 (defun fuel--shorten-str (str len
)
60 (let ((sl (length str
)))
64 (segl (/ (- len sepl
) 2)))
66 (substring str
0 segl
)
68 (substring str
(- sl segl
)))))))
70 (defun fuel--shorten-region (begin end len
)
71 (fuel--shorten-str (mapconcat 'identity
72 (split-string (buffer-substring begin end
) nil t
)
76 (defsubst fuel--region-to-string
(begin &optional end
)
77 (let ((end (or end
(point))))
80 (split-string (buffer-substring-no-properties begin end
)
86 (defsubst empty-string-p
(str) (equal str
""))
88 (defun fuel--string-prefix-p (prefix str
)
89 (and (>= (length str
) (length prefix
))
90 (string= (substring-no-properties str
0 (length prefix
))
91 (substring-no-properties prefix
))))
93 (defun fuel--respecting-message (format &rest format-args
)
94 "Display TEXT as a message, without hiding any minibuffer contents."
95 (let ((text (format " [%s]" (apply #'format format format-args
))))
96 (if (minibuffer-window-active-p (minibuffer-window))
97 (minibuffer-message text
)
98 (message "%s" text
))))
101 ;;; fuel-base.el ends here