Use windows-1252 encoding for stdin/stdout on Windows
[factor/jcg.git] / misc / fuel / fuel-base.el
blob5e8364e3a7e561cb3b35a370e705bfbead07eaf5
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>
7 ;; Keywords: languages
9 ;;; Commentary:
11 ;; Basic definitions likely to be used by all FUEL modules.
13 ;;; Code:
15 (defconst fuel-version "1.0")
17 ;;;###autoload
18 (defsubst fuel-version ()
19 "Echoes FUEL's version."
20 (interactive)
21 (message "FUEL %s" fuel-version))
24 ;;; Customization:
26 ;;;###autoload
27 (defgroup fuel nil
28 "Factor's Ultimate Emacs Library."
29 :group 'languages)
32 ;;; Emacs compatibility:
34 (eval-after-load "ring"
35 '(when (not (fboundp 'ring-member))
36 (defun ring-member (ring item)
37 (catch 'found
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)
48 (current-buffer)))
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))))
57 ;;; Utilities
59 (defun fuel--shorten-str (str len)
60 (let ((sl (length str)))
61 (if (<= sl len) str
62 (let* ((sep " ... ")
63 (sepl (length sep))
64 (segl (/ (- len sepl) 2)))
65 (format "%s%s%s"
66 (substring str 0 segl)
67 sep
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)
73 " ")
74 len))
76 (defsubst fuel--region-to-string (begin &optional end)
77 (let ((end (or end (point))))
78 (if (< begin end)
79 (mapconcat 'identity
80 (split-string (buffer-substring-no-properties begin end)
81 nil
83 " ")
84 "")))
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))))
100 (provide 'fuel-base)
101 ;;; fuel-base.el ends here