/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. ;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
  3. ;; See http://factorcode.org/license.txt for BSD license.
  4. ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
  5. ;; Keywords: languages
  6. ;;; Commentary:
  7. ;; Basic definitions likely to be used by all FUEL modules.
  8. ;;; Code:
  9. (defconst fuel-version "1.0")
  10. ;;;###autoload
  11. (defsubst fuel-version ()
  12. "Echoes FUEL's version."
  13. (interactive)
  14. (message "FUEL %s" fuel-version))
  15. ;;; Customization:
  16. ;;;###autoload
  17. (defgroup fuel nil
  18. "Factor's Ultimate Emacs Library."
  19. :group 'languages)
  20. ;;; Emacs compatibility:
  21. (eval-after-load "ring"
  22. '(when (not (fboundp 'ring-member))
  23. (defun ring-member (ring item)
  24. (catch 'found
  25. (dotimes (ind (ring-length ring) nil)
  26. (when (equal item (ring-ref ring ind))
  27. (throw 'found ind)))))))
  28. (when (not (fboundp 'completion-table-dynamic))
  29. (defun completion-table-dynamic (fun)
  30. (lexical-let ((fun fun))
  31. (lambda (string pred action)
  32. (with-current-buffer (let ((win (minibuffer-selected-window)))
  33. (if (window-live-p win) (window-buffer win)
  34. (current-buffer)))
  35. (complete-with-action action (funcall fun string) string pred))))))
  36. (when (not (fboundp 'looking-at-p))
  37. (defsubst looking-at-p (regexp)
  38. (let ((inhibit-changing-match-data t))
  39. (looking-at regexp))))
  40. ;;; Utilities
  41. (defun fuel--shorten-str (str len)
  42. (let ((sl (length str)))
  43. (if (<= sl len) str
  44. (let* ((sep " ... ")
  45. (sepl (length sep))
  46. (segl (/ (- len sepl) 2)))
  47. (format "%s%s%s"
  48. (substring str 0 segl)
  49. sep
  50. (substring str (- sl segl)))))))
  51. (defun fuel--shorten-region (begin end len)
  52. (fuel--shorten-str (mapconcat 'identity
  53. (split-string (buffer-substring begin end) nil t)
  54. " ")
  55. len))
  56. (defsubst fuel--region-to-string (begin &optional end)
  57. (let ((end (or end (point))))
  58. (if (< begin end)
  59. (mapconcat 'identity
  60. (split-string (buffer-substring-no-properties begin end)
  61. nil
  62. t)
  63. " ")
  64. "")))
  65. (defsubst empty-string-p (str) (equal str ""))
  66. (defun fuel--string-prefix-p (prefix str)
  67. (and (>= (length str) (length prefix))
  68. (string= (substring-no-properties str 0 (length prefix))
  69. (substring-no-properties prefix))))
  70. (defun fuel--respecting-message (format &rest format-args)
  71. "Display TEXT as a message, without hiding any minibuffer contents."
  72. (let ((text (format " [%s]" (apply #'format format format-args))))
  73. (if (minibuffer-window-active-p (minibuffer-window))
  74. (minibuffer-message text)
  75. (message "%s" text))))
  76. (provide 'fuel-base)
  77. ;;; fuel-base.el ends here