-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuel-base.el
125 lines (105 loc) · 4.05 KB
/
fuel-base.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
;;; fuel-base.el --- Basic FUEL support code -*- lexical-binding: t -*-
;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
;; See https://factorcode.org/license.txt for BSD license.
;; Author: Jose Antonio Ortega Ruiz <[email protected]>
;; Keywords: languages, fuel, factor
;;; Commentary:
;; Basic definitions likely to be used by all FUEL modules.
;;; Code:
(defconst fuel-version "1.1")
;;;###autoload
(defsubst fuel-version ()
"Echoes FUEL's version."
(interactive)
(message "FUEL %s" fuel-version))
;;; Customization:
;;;###autoload
(defgroup fuel nil
"Factor's Ultimate Emacs Library."
:group 'languages)
;;; Compatibility with Emacs 24.3
(unless (fboundp 'setq-local)
(defmacro setq-local (var val)
(list 'set (list 'make-local-variable (list 'quote var)) val)))
(unless (fboundp 'defvar-local)
(defmacro defvar-local (var val &optional docstring)
(declare (debug defvar) (doc-string 3))
(list 'progn (list 'defvar var val docstring)
(list 'make-variable-buffer-local (list 'quote var)))))
(unless (fboundp 'alist-get)
(defun alist-get (key alist)
(cdr (assoc key alist))))
;;; Utilities:
(defun fuel-shorten-str (str len)
(let ((sl (length str)))
(if (<= sl len) str
(let* ((sep " ... ")
(sepl (length sep))
(segl (/ (- len sepl) 2)))
(format "%s%s%s" (substring str 0 segl)
sep (substring str (- sl segl)))))))
(defun fuel-shorten-region (begin end len)
(fuel-shorten-str
(mapconcat 'identity
(split-string (buffer-substring begin end) nil t) " ") len))
(defsubst fuel-region-to-string (begin &optional end)
(let ((end (or end (point))))
(if (< begin end)
(mapconcat 'identity
(split-string (buffer-substring-no-properties begin end)
nil t) " ") "")))
(defun fuel-respecting-message (format &rest format-args)
"Display TEXT as a message, without hiding any minibuffer contents."
(let ((text (format " [%s]" (apply #'format format format-args))))
(if (minibuffer-window-active-p (minibuffer-window))
(minibuffer-message text)
(message "%s" text))))
(defun fuel-mode--read-file (arg)
(let* ((file (or (and arg (read-file-name "File: " nil (buffer-file-name) t))
(buffer-file-name)))
(file (expand-file-name file))
(buffer (find-file-noselect file)))
(when (and buffer
(buffer-modified-p buffer)
(y-or-n-p "Save file? "))
(save-buffer buffer))
(cons file buffer)))
;; I think it is correct to put almost all punctuation characters in
;; the word class because Factor words can be made up of almost
;; anything. Otherwise you get incredibly annoying regexps.
(defun fuel-syntax-table ()
(let ((table (make-syntax-table prog-mode-syntax-table)))
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?# "_" table)
(modify-syntax-entry ?! "_" table)
(modify-syntax-entry ?\n "> " table)
(modify-syntax-entry ?$ "_" table)
(modify-syntax-entry ?@ "_" table)
(modify-syntax-entry ?? "_" table)
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?: "_" table)
(modify-syntax-entry ?< "_" table)
(modify-syntax-entry ?> "_" table)
(modify-syntax-entry ?. "_" table)
(modify-syntax-entry ?, "_" table)
(modify-syntax-entry ?& "_" table)
(modify-syntax-entry ?| "_" table)
(modify-syntax-entry ?% "_" table)
(modify-syntax-entry ?= "_" table)
(modify-syntax-entry ?/ "_" table)
(modify-syntax-entry ?+ "_" table)
(modify-syntax-entry ?* "_" table)
(modify-syntax-entry ?- "_" table)
(modify-syntax-entry ?\; "_" table)
(modify-syntax-entry ?\' "_" table)
(modify-syntax-entry ?^ "_" table)
(modify-syntax-entry ?~ "_" table)
(modify-syntax-entry ?\( "()" table)
(modify-syntax-entry ?\) ")(" table)
(modify-syntax-entry ?\{ "(}" table)
(modify-syntax-entry ?\} "){" table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)
table))
(provide 'fuel-base)
;;; fuel-base.el ends here