PageRenderTime 73ms CodeModel.GetById 64ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/misc/fuel/fuel-base.el

http://github.com/abeaumont/factor
Emacs Lisp | 101 lines | 66 code | 21 blank | 14 comment | 0 complexity | dfbb9268ff4c303c32933450686be8e5 MD5 | raw file
  1;;; fuel-base.el --- Basic FUEL support code
  2
  3;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
  4;; See http://factorcode.org/license.txt for BSD license.
  5
  6;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
  7;; Keywords: languages
  8
  9;;; Commentary:
 10
 11;; Basic definitions likely to be used by all FUEL modules.
 12
 13;;; Code:
 14
 15(defconst fuel-version "1.0")
 16
 17;;;###autoload
 18(defsubst fuel-version ()
 19  "Echoes FUEL's version."
 20  (interactive)
 21  (message "FUEL %s" fuel-version))
 22
 23
 24;;; Customization:
 25
 26;;;###autoload
 27(defgroup fuel nil
 28  "Factor's Ultimate Emacs Library."
 29  :group 'languages)
 30
 31
 32;;; Emacs compatibility:
 33
 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)))))))
 41
 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))))))
 50
 51(when (not (fboundp 'looking-at-p))
 52  (defsubst looking-at-p (regexp)
 53    (let ((inhibit-changing-match-data t))
 54      (looking-at regexp))))
 55
 56
 57;;; Utilities
 58
 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)))))))
 69
 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))
 75
 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
 82                                 t)
 83                   " ")
 84      "")))
 85
 86(defsubst empty-string-p (str) (equal str ""))
 87
 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))))
 92
 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))))
 99
100(provide 'fuel-base)
101;;; fuel-base.el ends here