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))))))
54 (defun fuel--shorten-str (str len)
55 (let ((sl (length str)))
59 (segl (/ (- len sepl) 2)))
61 (substring str 0 segl)
63 (substring str (- sl segl)))))))
65 (defun fuel--shorten-region (begin end len)
66 (fuel--shorten-str (mapconcat 'identity
67 (split-string (buffer-substring begin end) nil t)
71 (defsubst empty-string-p (str) (equal str ""))
73 (defun fuel--string-prefix-p (prefix str)
74 (and (>= (length str) (length prefix))
75 (string= (substring-no-properties 0 (length prefix) str)
76 (substring-no-properties prefix))))
78 (defun fuel--respecting-message (format &rest format-args)
79 "Display TEXT as a message, without hiding any minibuffer contents."
80 (let ((text (format " [%s]" (apply #'format format format-args))))
81 (if (minibuffer-window-active-p (minibuffer-window))
82 (minibuffer-message text)
83 (message "%s" text))))
86 ;;; fuel-base.el ends here