eliscript 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +135 -0
  3. package/bin/eliscript +16 -0
  4. package/bin/eliscript-bootstrap +15 -0
  5. package/bin/eliscript-build +15 -0
  6. package/bin/eliscript-check +15 -0
  7. package/bin/eliscript-eval +15 -0
  8. package/bin/eliscript-format +15 -0
  9. package/bin/eliscript-org +10 -0
  10. package/bin/eliscript-portable +17 -0
  11. package/bin/eliscript-seed +10 -0
  12. package/bin/eliscript-seed-build +10 -0
  13. package/bin/eliscript-watch +15 -0
  14. package/bootstrap/README.md +100 -0
  15. package/bootstrap/compiler/analyzer.eli +1426 -0
  16. package/bootstrap/compiler/compiler.eli +472 -0
  17. package/bootstrap/compiler/emitter.eli +1745 -0
  18. package/bootstrap/compiler/expander.eli +2522 -0
  19. package/bootstrap/compiler/formatter.eli +359 -0
  20. package/bootstrap/compiler/ir.eli +297 -0
  21. package/bootstrap/compiler/lower.eli +661 -0
  22. package/bootstrap/compiler/project.eli +1120 -0
  23. package/bootstrap/compiler/reader.eli +321 -0
  24. package/bootstrap/compiler/source-map.eli +165 -0
  25. package/bootstrap/compiler/symbol.eli +92 -0
  26. package/bootstrap/compiler/syntax.eli +54 -0
  27. package/bootstrap/compiler/transient-analysis.eli +825 -0
  28. package/bootstrap/host/build.mjs +28 -0
  29. package/bootstrap/host/bun.mjs +282 -0
  30. package/bootstrap/host/check-cli.mjs +163 -0
  31. package/bootstrap/host/eliscript-cli.mjs +36 -0
  32. package/bootstrap/host/evaluation-cli.mjs +401 -0
  33. package/bootstrap/host/evaluation.mjs +560 -0
  34. package/bootstrap/host/format-cli.mjs +139 -0
  35. package/bootstrap/host/project-cli.mjs +295 -0
  36. package/bootstrap/host/project.mjs +1080 -0
  37. package/bootstrap/host/watch-cli.mjs +129 -0
  38. package/bootstrap/host/watch.mjs +267 -0
  39. package/browser/host.mjs +357 -0
  40. package/browser/worker.mjs +60 -0
  41. package/compiler/README.md +118 -0
  42. package/compiler/eliscript-analyzer.el +716 -0
  43. package/compiler/eliscript-cli.el +108 -0
  44. package/compiler/eliscript-diagnostic.el +158 -0
  45. package/compiler/eliscript-emitter.el +1351 -0
  46. package/compiler/eliscript-evaluation.el +259 -0
  47. package/compiler/eliscript-expander.el +1630 -0
  48. package/compiler/eliscript-form.el +79 -0
  49. package/compiler/eliscript-ir-emitter.el +1460 -0
  50. package/compiler/eliscript-ir.el +356 -0
  51. package/compiler/eliscript-lower.el +463 -0
  52. package/compiler/eliscript-macro-eval.el +811 -0
  53. package/compiler/eliscript-parameters.el +324 -0
  54. package/compiler/eliscript-portable.el +492 -0
  55. package/compiler/eliscript-project-cli.el +156 -0
  56. package/compiler/eliscript-project.el +1676 -0
  57. package/compiler/eliscript-reader.el +421 -0
  58. package/compiler/eliscript-source-map.el +192 -0
  59. package/compiler/eliscript-symbol.el +101 -0
  60. package/compiler/eliscript-transient-analysis.el +817 -0
  61. package/compiler/eliscript.el +239 -0
  62. package/dist/bootstrap/analyzer.mjs +968 -0
  63. package/dist/bootstrap/analyzer.mjs.map +1 -0
  64. package/dist/bootstrap/compiler.mjs +228 -0
  65. package/dist/bootstrap/compiler.mjs.map +1 -0
  66. package/dist/bootstrap/emitter.mjs +1173 -0
  67. package/dist/bootstrap/emitter.mjs.map +1 -0
  68. package/dist/bootstrap/expander.mjs +1469 -0
  69. package/dist/bootstrap/expander.mjs.map +1 -0
  70. package/dist/bootstrap/formatter.mjs +304 -0
  71. package/dist/bootstrap/formatter.mjs.map +1 -0
  72. package/dist/bootstrap/ir.mjs +193 -0
  73. package/dist/bootstrap/ir.mjs.map +1 -0
  74. package/dist/bootstrap/lower.mjs +344 -0
  75. package/dist/bootstrap/lower.mjs.map +1 -0
  76. package/dist/bootstrap/project.mjs +585 -0
  77. package/dist/bootstrap/project.mjs.map +1 -0
  78. package/dist/bootstrap/reader.mjs +259 -0
  79. package/dist/bootstrap/reader.mjs.map +1 -0
  80. package/dist/bootstrap/source-map.mjs +154 -0
  81. package/dist/bootstrap/source-map.mjs.map +1 -0
  82. package/dist/bootstrap/symbol.mjs +74 -0
  83. package/dist/bootstrap/symbol.mjs.map +1 -0
  84. package/dist/bootstrap/syntax.mjs +38 -0
  85. package/dist/bootstrap/syntax.mjs.map +1 -0
  86. package/dist/bootstrap/transient-analysis.mjs +660 -0
  87. package/dist/bootstrap/transient-analysis.mjs.map +1 -0
  88. package/dist/browser/compiler.js +6491 -0
  89. package/editor/README.md +83 -0
  90. package/editor/eliscript-mode.el +878 -0
  91. package/editor/eliscript-repl.el +501 -0
  92. package/package.json +163 -0
  93. package/platform/README.md +48 -0
  94. package/platform/browser.mjs +204 -0
  95. package/platform/worker.mjs +166 -0
  96. package/runtime/README.md +296 -0
  97. package/runtime/core/collection-internals.mjs +512 -0
  98. package/runtime/core/collection.mjs +645 -0
  99. package/runtime/core/data-text.mjs +532 -0
  100. package/runtime/core/data.mjs +268 -0
  101. package/runtime/core/identifier.mjs +314 -0
  102. package/runtime/core/lazy-sequence.mjs +244 -0
  103. package/runtime/core/list-internals.mjs +18 -0
  104. package/runtime/core/list.mjs +273 -0
  105. package/runtime/core/map-internals.mjs +793 -0
  106. package/runtime/core/map.mjs +394 -0
  107. package/runtime/core/metadata-internals.mjs +14 -0
  108. package/runtime/core/metadata.mjs +44 -0
  109. package/runtime/core/object-impl.mjs +65 -0
  110. package/runtime/core/object-impl.mjs.map +1 -0
  111. package/runtime/core/object.mjs +13 -0
  112. package/runtime/core/order.mjs +234 -0
  113. package/runtime/core/persistent-kind.mjs +43 -0
  114. package/runtime/core/protocol-error.mjs +36 -0
  115. package/runtime/core/protocol-impl.mjs +326 -0
  116. package/runtime/core/protocol-impl.mjs.map +1 -0
  117. package/runtime/core/protocol.mjs +14 -0
  118. package/runtime/core/queue-internals.mjs +27 -0
  119. package/runtime/core/queue.mjs +238 -0
  120. package/runtime/core/record.mjs +346 -0
  121. package/runtime/core/regex.mjs +184 -0
  122. package/runtime/core/sequence.mjs +632 -0
  123. package/runtime/core/set-algebra.mjs +287 -0
  124. package/runtime/core/set-internals.mjs +33 -0
  125. package/runtime/core/set.mjs +378 -0
  126. package/runtime/core/sorted-internals.mjs +215 -0
  127. package/runtime/core/sorted.mjs +598 -0
  128. package/runtime/core/text-impl.mjs +95 -0
  129. package/runtime/core/text-impl.mjs.map +1 -0
  130. package/runtime/core/text.mjs +15 -0
  131. package/runtime/core/transducer.mjs +668 -0
  132. package/runtime/core/transient-internals.mjs +38 -0
  133. package/runtime/core/transient.mjs +53 -0
  134. package/runtime/core/truth.mjs +3 -0
  135. package/runtime/core/type.mjs +262 -0
  136. package/runtime/core/value-internals.mjs +188 -0
  137. package/runtime/core/value.mjs +93 -0
  138. package/runtime/core/vector-internals.mjs +102 -0
  139. package/runtime/core/vector.mjs +951 -0
  140. package/runtime/literals.mjs +34 -0
  141. package/runtime/source-mapping.mjs +220 -0
  142. package/runtime/testing/list.mjs +52 -0
  143. package/runtime/testing/map.mjs +145 -0
  144. package/runtime/testing/queue.mjs +49 -0
  145. package/runtime/testing/set.mjs +61 -0
  146. package/runtime/testing/sorted.mjs +105 -0
  147. package/runtime/testing/value.mjs +17 -0
  148. package/runtime/testing/vector.mjs +102 -0
  149. package/runtime/worker-value-codec.mjs +565 -0
  150. package/runtime/worker-value-stream.mjs +786 -0
  151. package/runtime/worker.mjs +975 -0
  152. package/stdlib/README.md +774 -0
  153. package/stdlib/bit.eli +36 -0
  154. package/stdlib/core/collection.eli +134 -0
  155. package/stdlib/core/data-text.eli +16 -0
  156. package/stdlib/core/data.eli +306 -0
  157. package/stdlib/core/identifier.eli +32 -0
  158. package/stdlib/core/lazy-sequence.eli +63 -0
  159. package/stdlib/core/metadata.eli +20 -0
  160. package/stdlib/core/object.eli +89 -0
  161. package/stdlib/core/order.eli +133 -0
  162. package/stdlib/core/protocol.eli +387 -0
  163. package/stdlib/core/record.eli +16 -0
  164. package/stdlib/core/regex.eli +17 -0
  165. package/stdlib/core/seq.eli +701 -0
  166. package/stdlib/core/set.eli +312 -0
  167. package/stdlib/core/sorted.eli +53 -0
  168. package/stdlib/core/text.eli +103 -0
  169. package/stdlib/core/transducer.eli +59 -0
  170. package/stdlib/core/transient.eli +24 -0
  171. package/stdlib/core/type.eli +19 -0
  172. package/stdlib/core/walk.eli +195 -0
  173. package/stdlib/core/zipper.eli +508 -0
  174. package/stdlib/data-text.eli +1092 -0
  175. package/stdlib/data.eli +42 -0
  176. package/stdlib/deferred.eli +70 -0
  177. package/stdlib/function.eli +120 -0
  178. package/stdlib/hierarchy.eli +245 -0
  179. package/stdlib/identifier.eli +147 -0
  180. package/stdlib/interop/js.eli +616 -0
  181. package/stdlib/json.eli +870 -0
  182. package/stdlib/metadata.eli +56 -0
  183. package/stdlib/multimethod.eli +464 -0
  184. package/stdlib/numeric.eli +193 -0
  185. package/stdlib/object.eli +96 -0
  186. package/stdlib/persistent-list.eli +145 -0
  187. package/stdlib/persistent-map.eli +724 -0
  188. package/stdlib/persistent-queue.eli +32 -0
  189. package/stdlib/persistent-set.eli +236 -0
  190. package/stdlib/persistent-vector.eli +342 -0
  191. package/stdlib/result.eli +141 -0
  192. package/stdlib/sequence.eli +106 -0
  193. package/stdlib/state/atom.eli +265 -0
  194. package/stdlib/text.eli +88 -0
  195. package/stdlib/value.eli +325 -0
@@ -0,0 +1,878 @@
1
+ ;;; eliscript-mode.el --- Major mode for Eliscript source -*- lexical-binding: t; -*-
2
+
3
+ ;; Author: 刘冲 <mail@liuchong.dev>
4
+ ;; Maintainer: 刘冲 <mail@liuchong.dev>
5
+ ;; Version: 0.0.1
6
+ ;; Package-Requires: ((emacs "29.1"))
7
+ ;; Keywords: languages, lisp
8
+ ;; URL: https://github.com/liuchong/eliscript
9
+
10
+ ;;; Commentary:
11
+
12
+ ;; Syntax-aware editing, navigation, project discovery, and formatter
13
+ ;; integration for Eliscript source files.
14
+
15
+ ;;; Code:
16
+
17
+ (require 'compile)
18
+ (require 'imenu)
19
+ (require 'json)
20
+ (require 'flymake)
21
+ (require 'project)
22
+ (require 'seq)
23
+ (require 'subr-x)
24
+
25
+ (defgroup eliscript nil
26
+ "Editing and tool integration for Eliscript."
27
+ :group 'languages
28
+ :prefix "eliscript-")
29
+
30
+ (defcustom eliscript-mode-format-command '("eliscript-format")
31
+ "Command and fixed arguments used to format the current buffer."
32
+ :type '(repeat string)
33
+ :group 'eliscript)
34
+
35
+ (defcustom eliscript-mode-check-command '("eliscript-check")
36
+ "Command and fixed arguments used to check the current project."
37
+ :type '(repeat string)
38
+ :group 'eliscript)
39
+
40
+ (defcustom eliscript-mode-build-command '("eliscript-build")
41
+ "Command and fixed arguments used to build Eliscript projects."
42
+ :type '(repeat string)
43
+ :group 'eliscript)
44
+
45
+ (defcustom eliscript-mode-eval-command '("eliscript-eval" "--stdio")
46
+ "Command and fixed arguments used for persistent evaluation sessions."
47
+ :type '(repeat string)
48
+ :group 'eliscript)
49
+
50
+ (defcustom eliscript-mode-watch-command '("eliscript-watch" "--json")
51
+ "Command and fixed arguments used for project watch sessions."
52
+ :type '(repeat string)
53
+ :group 'eliscript)
54
+
55
+ (defcustom eliscript-mode-build-directory "dist"
56
+ "Output directory used for builds without `eliscript.json'.
57
+
58
+ Relative paths are resolved from the discovered project root."
59
+ :type 'string
60
+ :group 'eliscript)
61
+
62
+ (define-error 'eliscript-mode-error "Eliscript editor integration error")
63
+
64
+ (defvar eliscript-mode-watch-event-hook nil
65
+ "Hook run with one validated project watch event argument.")
66
+
67
+ (defvar eliscript-mode--watch-processes (make-hash-table :test #'equal)
68
+ "Canonical project roots mapped to their live watch processes.")
69
+
70
+ (defconst eliscript-mode--function-heads
71
+ '("defasync" "defmulti" "defn" "defportable" "defprotocol" "defun"))
72
+
73
+ (defconst eliscript-mode--macro-heads '("defmacro"))
74
+
75
+ (defconst eliscript-mode--variable-heads '("defconst" "defvar"))
76
+
77
+ (defconst eliscript-mode--top-level-heads
78
+ '("defasync" "defconst" "defmacro" "defmethod" "defmulti" "defn"
79
+ "defportable" "defprotocol" "defun" "defvar" "export" "export-default"
80
+ "extend-category" "extend-default" "extend-type"
81
+ "import" "import-portable" "module"))
82
+
83
+ (defconst eliscript-mode--special-heads
84
+ '("->" "->>" "and" "apply" "as->" "async" "await" "case" "catch" "cond" "condp" "cond->" "cond->>"
85
+ "do" "finally" "fn" "funcall" "if" "if-let" "if-some" "js*" "js-array" "js-call"
86
+ "js-cons" "js-length" "js-nth" "js-object" "lambda" "let"
87
+ "let*" "letfn" "loop" "new" "or" "progn" "quote" "recur" "set!" "setq"
88
+ "some->" "some->>" "throw" "try" "unless" "when" "when-let" "when-some" "while"))
89
+
90
+ (defconst eliscript-mode--definition-heads
91
+ (append eliscript-mode--function-heads
92
+ eliscript-mode--macro-heads
93
+ eliscript-mode--variable-heads))
94
+
95
+ (defconst eliscript-mode--name-regexp "\\([^][(){}\"; \t\r\n]+\\)")
96
+
97
+ (defconst eliscript-mode--compilation-regexp
98
+ '(eliscript
99
+ "^eliscript-build: \\(.+\\):\\([0-9]+\\):\\([0-9]+\\): " 1 2 3)
100
+ "Compilation regexp for located Eliscript build diagnostics.")
101
+
102
+ (add-to-list 'compilation-error-regexp-alist-alist
103
+ eliscript-mode--compilation-regexp)
104
+
105
+ (defconst eliscript-mode--definition-regexp
106
+ (concat "^[ \t]*(\\(?:"
107
+ (regexp-opt eliscript-mode--definition-heads)
108
+ "\\)\\_>"))
109
+
110
+ (defconst eliscript-mode--function-definition-regexp
111
+ (concat "^[ \t]*(\\(?:"
112
+ (regexp-opt eliscript-mode--function-heads)
113
+ "\\)\\_>[ \t]+"
114
+ eliscript-mode--name-regexp))
115
+
116
+ (defconst eliscript-mode--macro-definition-regexp
117
+ (concat "^[ \t]*(\\(?:"
118
+ (regexp-opt eliscript-mode--macro-heads)
119
+ "\\)\\_>[ \t]+"
120
+ eliscript-mode--name-regexp))
121
+
122
+ (defconst eliscript-mode--variable-definition-regexp
123
+ (concat "^[ \t]*(\\(?:"
124
+ (regexp-opt eliscript-mode--variable-heads)
125
+ "\\)\\_>[ \t]+"
126
+ eliscript-mode--name-regexp))
127
+
128
+ (defconst eliscript-mode--module-regexp
129
+ (concat "^[ \t]*(module\\_>[ \t]+" eliscript-mode--name-regexp))
130
+
131
+ (defconst eliscript-mode-font-lock-keywords
132
+ `((,(concat "(\\("
133
+ (regexp-opt eliscript-mode--function-heads)
134
+ "\\)\\_>[ \t\n]+"
135
+ eliscript-mode--name-regexp)
136
+ (1 font-lock-keyword-face)
137
+ (2 font-lock-function-name-face))
138
+ (,(concat "(\\("
139
+ (regexp-opt eliscript-mode--macro-heads)
140
+ "\\)\\_>[ \t\n]+"
141
+ eliscript-mode--name-regexp)
142
+ (1 font-lock-keyword-face)
143
+ (2 font-lock-function-name-face))
144
+ (,(concat "(\\("
145
+ (regexp-opt eliscript-mode--variable-heads)
146
+ "\\)\\_>[ \t\n]+"
147
+ eliscript-mode--name-regexp)
148
+ (1 font-lock-keyword-face)
149
+ (2 font-lock-variable-name-face))
150
+ (,(concat "(\\(module\\)\\_>[ \t\n]+" eliscript-mode--name-regexp)
151
+ (1 font-lock-keyword-face)
152
+ (2 font-lock-type-face))
153
+ (,(concat "(\\("
154
+ (regexp-opt (append eliscript-mode--top-level-heads
155
+ eliscript-mode--special-heads))
156
+ "\\)\\_>")
157
+ (1 font-lock-keyword-face))
158
+ ("\\_<\\(?:false\\|nil\\|t\\|undefined\\)\\_>"
159
+ . font-lock-constant-face)
160
+ ("\\_<:[^][(){}\"; \t\r\n]+\\_>" . font-lock-constant-face)
161
+ ("\\_<&\\(?:body\\|optional\\|rest\\)\\_>" . font-lock-builtin-face)))
162
+
163
+ (defvar eliscript-mode-syntax-table
164
+ (let ((table (make-syntax-table)))
165
+ (modify-syntax-entry ?\; "<" table)
166
+ (modify-syntax-entry ?\n ">" table)
167
+ (modify-syntax-entry ?\" "\"" table)
168
+ (modify-syntax-entry ?\( "()" table)
169
+ (modify-syntax-entry ?\) ")(" table)
170
+ (modify-syntax-entry ?\[ "(]" table)
171
+ (modify-syntax-entry ?\] ")[" table)
172
+ (modify-syntax-entry ?\{ "(}" table)
173
+ (modify-syntax-entry ?\} "){" table)
174
+ (dolist (character '(?' ?` ?, ?#))
175
+ (modify-syntax-entry character "'" table))
176
+ (dolist (character '(?- ?+ ?* ?/ ?< ?> ?= ?! ?? ?_ ?. ?$ ?% ?& ?:))
177
+ (modify-syntax-entry character "_" table))
178
+ table)
179
+ "Syntax table used by `eliscript-mode'.")
180
+
181
+ (defconst eliscript-mode-imenu-generic-expression
182
+ `(("Modules" ,eliscript-mode--module-regexp 1)
183
+ ("Functions" ,eliscript-mode--function-definition-regexp 1)
184
+ ("Macros" ,eliscript-mode--macro-definition-regexp 1)
185
+ ("Variables" ,eliscript-mode--variable-definition-regexp 1)))
186
+
187
+ (defvar eliscript-mode-map
188
+ (let ((map (make-sparse-keymap)))
189
+ (define-key map (kbd "C-c C-f") #'eliscript-mode-format-buffer)
190
+ (define-key map (kbd "C-c C-k") #'eliscript-mode-check-buffer)
191
+ (define-key map (kbd "C-c C-b") #'eliscript-mode-compile-buffer)
192
+ (define-key map (kbd "C-c C-c") #'eliscript-mode-compile-file)
193
+ (define-key map (kbd "C-c C-p") #'eliscript-mode-compile-project)
194
+ (define-key map (kbd "C-c C-n") #'eliscript-mode-next-error)
195
+ (define-key map (kbd "C-c C-r") #'eliscript-mode-previous-error)
196
+ (define-key map (kbd "C-c C-e") #'eliscript-mode-eval-last-form)
197
+ (define-key map (kbd "C-M-x") #'eliscript-mode-eval-defun)
198
+ (define-key map (kbd "C-c C-l") #'eliscript-mode-eval-buffer)
199
+ (define-key map (kbd "C-c C-z") #'eliscript-mode-show-repl)
200
+ (define-key map (kbd "C-c C-q") #'eliscript-mode-stop-repl)
201
+ map)
202
+ "Keymap used by `eliscript-mode'.")
203
+
204
+ (defvar-local eliscript-mode--flymake-process nil)
205
+
206
+ (define-compilation-mode eliscript-compilation-mode "Eliscript-Compilation"
207
+ "Compilation mode for Eliscript project builds."
208
+ (setq-local compilation-error-regexp-alist '(eliscript)))
209
+
210
+ (defun eliscript-mode--line-indentation ()
211
+ "Return canonical structural indentation for the current line."
212
+ (let* ((line-start (line-beginning-position))
213
+ (state (syntax-ppss line-start)))
214
+ (if (nth 3 state)
215
+ (current-indentation)
216
+ (save-excursion
217
+ (back-to-indentation)
218
+ (* 2 (max 0 (- (car state)
219
+ (if (looking-at-p "[])}]") 1 0))))))))
220
+
221
+ (defun eliscript-mode--indent-line ()
222
+ "Indent the current line according to Eliscript structural depth."
223
+ (let ((offset (- (current-column) (current-indentation)))
224
+ (indentation (eliscript-mode--line-indentation)))
225
+ (indent-line-to indentation)
226
+ (when (> offset 0)
227
+ (move-to-column (+ indentation offset)))))
228
+
229
+ (defun eliscript-mode--definition-open-position (start)
230
+ "Return the opening delimiter position for definition at START."
231
+ (save-excursion
232
+ (goto-char start)
233
+ (search-forward "(" (line-end-position) t)
234
+ (1- (point))))
235
+
236
+ (defun eliscript-mode--current-definition-start ()
237
+ "Return the top-level definition containing point, or nil."
238
+ (let ((position (point))
239
+ start)
240
+ (save-excursion
241
+ (beginning-of-line)
242
+ (unless (looking-at eliscript-mode--definition-regexp)
243
+ (goto-char position)
244
+ (when (re-search-backward eliscript-mode--definition-regexp nil t)
245
+ (setq start (match-beginning 0))))
246
+ (unless start
247
+ (when (looking-at eliscript-mode--definition-regexp)
248
+ (setq start (match-beginning 0))))
249
+ (when start
250
+ (let* ((open (eliscript-mode--definition-open-position start))
251
+ (end (condition-case nil (scan-sexps open 1)
252
+ (scan-error nil))))
253
+ (and end (<= start position) (<= position end) start))))))
254
+
255
+ (defun eliscript-mode--beginning-of-defun (&optional arg)
256
+ "Move backward ARG top-level Eliscript definitions."
257
+ (let ((count (or arg 1)))
258
+ (if (< count 0)
259
+ (eliscript-mode--end-of-defun (- count))
260
+ (catch 'missing
261
+ (dotimes (index count)
262
+ (let ((start (and (= index 0)
263
+ (eliscript-mode--current-definition-start))))
264
+ (unless start
265
+ (beginning-of-line)
266
+ (unless (re-search-backward
267
+ eliscript-mode--definition-regexp nil t)
268
+ (goto-char (point-min))
269
+ (throw 'missing nil))
270
+ (setq start (match-beginning 0)))
271
+ (goto-char start)))
272
+ t))))
273
+
274
+ (defun eliscript-mode--end-of-defun (&optional arg)
275
+ "Move forward ARG top-level Eliscript definitions."
276
+ (let ((count (or arg 1)))
277
+ (if (< count 0)
278
+ (eliscript-mode--beginning-of-defun (- count))
279
+ (catch 'missing
280
+ (dotimes (index count)
281
+ (let ((start (and (= index 0)
282
+ (eliscript-mode--current-definition-start))))
283
+ (unless start
284
+ (unless (re-search-forward
285
+ eliscript-mode--definition-regexp nil t)
286
+ (goto-char (point-max))
287
+ (throw 'missing nil))
288
+ (setq start (match-beginning 0)))
289
+ (let* ((open (eliscript-mode--definition-open-position start))
290
+ (end (condition-case nil (scan-sexps open 1)
291
+ (scan-error nil))))
292
+ (unless end
293
+ (goto-char (point-max))
294
+ (throw 'missing nil))
295
+ (goto-char end))))
296
+ t))))
297
+
298
+ (defun eliscript-mode-project-root (&optional directory)
299
+ "Return the Eliscript project root containing DIRECTORY.
300
+
301
+ Prefer the nearest `eliscript.json', then fall back to `project.el'."
302
+ (let* ((candidate (or directory buffer-file-name default-directory))
303
+ (start (file-name-as-directory
304
+ (expand-file-name
305
+ (if (file-directory-p candidate)
306
+ candidate
307
+ (or (file-name-directory candidate)
308
+ default-directory)))))
309
+ (configuration-root
310
+ (locate-dominating-file start "eliscript.json")))
311
+ (or (and configuration-root
312
+ (file-name-as-directory
313
+ (expand-file-name configuration-root)))
314
+ (when-let* ((current-project (project-current nil start)))
315
+ (file-name-as-directory
316
+ (expand-file-name (project-root current-project)))))))
317
+
318
+ (defun eliscript-mode--formatter-program ()
319
+ "Resolve and validate `eliscript-mode-format-command'."
320
+ (unless (and (consp eliscript-mode-format-command)
321
+ (seq-every-p #'stringp eliscript-mode-format-command)
322
+ (not (string-empty-p (car eliscript-mode-format-command))))
323
+ (signal 'eliscript-mode-error
324
+ '("eliscript-mode-format-command must be non-empty strings")))
325
+ (let* ((configured (car eliscript-mode-format-command))
326
+ (program (if (file-name-absolute-p configured)
327
+ (and (file-executable-p configured) configured)
328
+ (executable-find configured))))
329
+ (or program
330
+ (signal 'eliscript-mode-error
331
+ (list (format "formatter executable not found: %s"
332
+ configured))))))
333
+
334
+ (defun eliscript-mode--check-program ()
335
+ "Resolve and validate `eliscript-mode-check-command'."
336
+ (unless (and (consp eliscript-mode-check-command)
337
+ (seq-every-p #'stringp eliscript-mode-check-command)
338
+ (not (string-empty-p (car eliscript-mode-check-command))))
339
+ (signal 'eliscript-mode-error
340
+ '("eliscript-mode-check-command must be non-empty strings")))
341
+ (let* ((configured (car eliscript-mode-check-command))
342
+ (program (if (file-name-absolute-p configured)
343
+ (and (file-executable-p configured) configured)
344
+ (executable-find configured))))
345
+ (or program
346
+ (signal 'eliscript-mode-error
347
+ (list (format "checker executable not found: %s"
348
+ configured))))))
349
+
350
+ (defun eliscript-mode--build-program ()
351
+ "Resolve and validate `eliscript-mode-build-command'."
352
+ (unless (and (consp eliscript-mode-build-command)
353
+ (seq-every-p #'stringp eliscript-mode-build-command)
354
+ (not (string-empty-p (car eliscript-mode-build-command))))
355
+ (signal 'eliscript-mode-error
356
+ '("eliscript-mode-build-command must be non-empty strings")))
357
+ (let* ((configured (car eliscript-mode-build-command))
358
+ (program (if (file-name-absolute-p configured)
359
+ (and (file-executable-p configured) configured)
360
+ (executable-find configured))))
361
+ (or program
362
+ (signal 'eliscript-mode-error
363
+ (list (format "builder executable not found: %s"
364
+ configured))))))
365
+
366
+ (defun eliscript-mode--watch-program ()
367
+ "Resolve and validate `eliscript-mode-watch-command'."
368
+ (unless (and (consp eliscript-mode-watch-command)
369
+ (seq-every-p #'stringp eliscript-mode-watch-command)
370
+ (not (string-empty-p (car eliscript-mode-watch-command))))
371
+ (signal 'eliscript-mode-error
372
+ '("eliscript-mode-watch-command must be non-empty strings")))
373
+ (let* ((configured (car eliscript-mode-watch-command))
374
+ (program (if (file-name-absolute-p configured)
375
+ (and (file-executable-p configured) configured)
376
+ (executable-find configured))))
377
+ (or program
378
+ (signal 'eliscript-mode-error
379
+ (list (format "watch executable not found: %s"
380
+ configured))))))
381
+
382
+ (defun eliscript-mode--watch-context (&optional directory)
383
+ "Return canonical watch context containing DIRECTORY."
384
+ (let* ((root (or (eliscript-mode-project-root directory)
385
+ (file-name-as-directory
386
+ (expand-file-name (or directory default-directory)))))
387
+ (canonical-root (file-name-as-directory (file-truename root)))
388
+ (configuration (expand-file-name "eliscript.json" root)))
389
+ (list :root canonical-root
390
+ :configuration (and (file-regular-p configuration)
391
+ (file-truename configuration)))))
392
+
393
+ (defun eliscript-mode--watch-arguments (context)
394
+ "Return public watch-command arguments for CONTEXT."
395
+ (append (cdr eliscript-mode-watch-command)
396
+ (if-let* ((configuration (plist-get context :configuration)))
397
+ (list "--config" configuration)
398
+ (list "--root" (plist-get context :root)))))
399
+
400
+ (defun eliscript-mode--watch-event-from-json (source)
401
+ "Decode and validate one watch event from JSON SOURCE."
402
+ (condition-case error-data
403
+ (let* ((event (json-parse-string source
404
+ :object-type 'alist
405
+ :array-type 'list
406
+ :null-object nil
407
+ :false-object nil))
408
+ (kind (alist-get 'event event))
409
+ (sequence (alist-get 'sequence event))
410
+ (root (alist-get 'root event)))
411
+ (unless (and (equal (alist-get 'format event)
412
+ "eliscript-watch-event")
413
+ (= (or (alist-get 'version event) 0) 1)
414
+ (integerp sequence)
415
+ (>= sequence 0)
416
+ (member kind '("ready" "change" "error"))
417
+ (stringp root)
418
+ (not (string-empty-p root)))
419
+ (signal 'eliscript-mode-error '("invalid project watch event")))
420
+ event)
421
+ (json-parse-error
422
+ (signal 'eliscript-mode-error
423
+ (list (format "invalid project watch JSON: %s"
424
+ (error-message-string error-data)))))))
425
+
426
+ (defun eliscript-mode--refresh-watch-buffers (root)
427
+ "Request diagnostics for live Eliscript buffers below ROOT."
428
+ (dolist (buffer (buffer-list))
429
+ (when (buffer-live-p buffer)
430
+ (with-current-buffer buffer
431
+ (when (and (derived-mode-p 'eliscript-mode)
432
+ flymake-mode
433
+ buffer-file-name
434
+ (file-in-directory-p
435
+ (file-truename buffer-file-name) root))
436
+ (flymake-start))))))
437
+
438
+ (defun eliscript-mode--handle-watch-event (process event)
439
+ "Apply validated EVENT received from watch PROCESS."
440
+ (let* ((event-root (file-name-as-directory
441
+ (file-truename (alist-get 'root event))))
442
+ (expected-root (process-get process 'eliscript-watch-event-root))
443
+ (sequence (alist-get 'sequence event))
444
+ (last-sequence (process-get process 'eliscript-watch-sequence)))
445
+ (when (and expected-root (not (equal expected-root event-root)))
446
+ (signal 'eliscript-mode-error '("project watch root changed")))
447
+ (unless (or (and (null last-sequence) (= sequence 0))
448
+ (and (integerp last-sequence) (> sequence last-sequence)))
449
+ (signal 'eliscript-mode-error '("project watch sequence is not increasing")))
450
+ (process-put process 'eliscript-watch-event-root event-root)
451
+ (process-put process 'eliscript-watch-sequence sequence)
452
+ (run-hook-with-args 'eliscript-mode-watch-event-hook event)
453
+ (when (equal (alist-get 'event event) "change")
454
+ (eliscript-mode--refresh-watch-buffers event-root))))
455
+
456
+ (defun eliscript-mode--watch-filter (process output)
457
+ "Decode complete watch events from PROCESS OUTPUT."
458
+ (let ((source (concat (or (process-get process 'eliscript-watch-partial) "")
459
+ output))
460
+ line-end)
461
+ (while (setq line-end (string-match "\n" source))
462
+ (let ((line (substring source 0 line-end)))
463
+ (setq source (substring source (1+ line-end)))
464
+ (unless (string-empty-p line)
465
+ (condition-case error-data
466
+ (eliscript-mode--handle-watch-event
467
+ process (eliscript-mode--watch-event-from-json line))
468
+ (error
469
+ (process-put process 'eliscript-watch-error
470
+ (error-message-string error-data))
471
+ (delete-process process))))))
472
+ (process-put process 'eliscript-watch-partial source)))
473
+
474
+ (defun eliscript-mode--watch-sentinel (process _event)
475
+ "Release project ownership after watch PROCESS exits."
476
+ (when (memq (process-status process) '(exit signal failed))
477
+ (let ((root (process-get process 'eliscript-watch-root)))
478
+ (when (eq process (gethash root eliscript-mode--watch-processes))
479
+ (remhash root eliscript-mode--watch-processes)))))
480
+
481
+ (defun eliscript-mode-watch-project (&optional directory)
482
+ "Start or reuse the watch session containing DIRECTORY."
483
+ (interactive)
484
+ (let* ((context (eliscript-mode--watch-context directory))
485
+ (root (plist-get context :root))
486
+ (existing (gethash root eliscript-mode--watch-processes)))
487
+ (if (process-live-p existing)
488
+ existing
489
+ (let* ((default-directory root)
490
+ (program (eliscript-mode--watch-program))
491
+ (buffer (get-buffer-create
492
+ (format "*Eliscript watch %s*" root)))
493
+ (process
494
+ (make-process
495
+ :name (format "eliscript-watch:%s" root)
496
+ :buffer buffer
497
+ :stderr buffer
498
+ :command (cons program
499
+ (eliscript-mode--watch-arguments context))
500
+ :connection-type 'pipe
501
+ :coding 'utf-8-unix
502
+ :noquery t
503
+ :filter #'eliscript-mode--watch-filter
504
+ :sentinel #'eliscript-mode--watch-sentinel)))
505
+ (process-put process 'eliscript-watch-root root)
506
+ (process-put process 'eliscript-watch-partial "")
507
+ (puthash root process eliscript-mode--watch-processes)
508
+ process))))
509
+
510
+ (defun eliscript-mode-watch-project-p (&optional directory)
511
+ "Return non-nil when DIRECTORY has a live project watch session."
512
+ (let* ((context (eliscript-mode--watch-context directory))
513
+ (process (gethash (plist-get context :root)
514
+ eliscript-mode--watch-processes)))
515
+ (and (process-live-p process) process)))
516
+
517
+ (defun eliscript-mode-stop-watch (&optional directory)
518
+ "Stop the project watch session containing DIRECTORY."
519
+ (interactive)
520
+ (let* ((context (eliscript-mode--watch-context directory))
521
+ (root (plist-get context :root))
522
+ (process (gethash root eliscript-mode--watch-processes)))
523
+ (remhash root eliscript-mode--watch-processes)
524
+ (when (process-live-p process)
525
+ (delete-process process))
526
+ (and process t)))
527
+
528
+ (defun eliscript-mode--build-context ()
529
+ "Return the current file, project root, configuration, and output path."
530
+ (unless buffer-file-name
531
+ (signal 'eliscript-mode-error
532
+ '("project building requires a file-backed buffer")))
533
+ (unless (and (stringp eliscript-mode-build-directory)
534
+ (not (string-empty-p eliscript-mode-build-directory)))
535
+ (signal 'eliscript-mode-error
536
+ '("eliscript-mode-build-directory must be a non-empty path")))
537
+ (let* ((file (expand-file-name buffer-file-name))
538
+ (root (or (eliscript-mode-project-root)
539
+ (file-name-directory file)))
540
+ (configuration (expand-file-name "eliscript.json" root))
541
+ (configured (file-regular-p configuration))
542
+ (output (if (file-name-absolute-p eliscript-mode-build-directory)
543
+ eliscript-mode-build-directory
544
+ (expand-file-name eliscript-mode-build-directory root))))
545
+ (list :file file
546
+ :root root
547
+ :configuration (and configured configuration)
548
+ :output output)))
549
+
550
+ (defun eliscript-mode--build-arguments (scope)
551
+ "Return public build-command arguments for SCOPE."
552
+ (let* ((context (eliscript-mode--build-context))
553
+ (file (plist-get context :file))
554
+ (root (plist-get context :root))
555
+ (configuration (plist-get context :configuration))
556
+ (output (plist-get context :output))
557
+ (base
558
+ (pcase scope
559
+ ('project
560
+ (unless configuration
561
+ (signal 'eliscript-mode-error
562
+ '("project compilation requires eliscript.json")))
563
+ (list "--config" configuration))
564
+ ('file
565
+ (if configuration
566
+ (list "--config" configuration file)
567
+ (list "--root" root "--out-dir" output file)))
568
+ ('buffer
569
+ (append
570
+ (if configuration
571
+ (list "--config" configuration)
572
+ (list "--root" root "--out-dir" output file))
573
+ (list "--stdin-file" file "--no-cache")))
574
+ (_
575
+ (signal 'eliscript-mode-error
576
+ (list (format "unsupported build scope: %s" scope)))))))
577
+ (append (cdr eliscript-mode-build-command)
578
+ base
579
+ (list "--diagnostic-format" "human"))))
580
+
581
+ (defun eliscript-mode--start-build (scope &optional send-buffer)
582
+ "Start an Eliscript build for SCOPE and optionally SEND-BUFFER on stdin."
583
+ (let* ((source-buffer (current-buffer))
584
+ (context (eliscript-mode--build-context))
585
+ (default-directory (plist-get context :root))
586
+ (program (eliscript-mode--build-program))
587
+ (arguments (eliscript-mode--build-arguments scope))
588
+ (command
589
+ (mapconcat #'shell-quote-argument
590
+ (cons program arguments) " "))
591
+ (buffer-name (format "*Eliscript %s build*" scope))
592
+ (compilation-buffer
593
+ (compilation-start
594
+ command 'eliscript-compilation-mode
595
+ (lambda (_mode) buffer-name))))
596
+ (when send-buffer
597
+ (let ((process (get-buffer-process compilation-buffer)))
598
+ (unless (process-live-p process)
599
+ (signal 'eliscript-mode-error
600
+ '("builder process did not start")))
601
+ (with-current-buffer source-buffer
602
+ (save-restriction
603
+ (widen)
604
+ (process-send-region process (point-min) (point-max))))
605
+ (process-send-eof process)))
606
+ compilation-buffer))
607
+
608
+ (defun eliscript-mode-compile-buffer ()
609
+ "Build the project using the current unsaved buffer contents."
610
+ (interactive)
611
+ (eliscript-mode--start-build 'buffer t))
612
+
613
+ (defun eliscript-mode-compile-file ()
614
+ "Build the visited Eliscript file from its saved contents."
615
+ (interactive)
616
+ (when (buffer-modified-p)
617
+ (signal 'eliscript-mode-error
618
+ '("buffer is modified; save it or use compile-buffer")))
619
+ (eliscript-mode--start-build 'file))
620
+
621
+ (defun eliscript-mode-compile-project ()
622
+ "Build the configured Eliscript project."
623
+ (interactive)
624
+ (eliscript-mode--start-build 'project))
625
+
626
+ (defun eliscript-mode-next-error (&optional count reset)
627
+ "Visit the next Eliscript build diagnostic.
628
+
629
+ With COUNT, move that many diagnostics. RESET starts from the beginning."
630
+ (interactive "p")
631
+ (next-error count reset))
632
+
633
+ (defun eliscript-mode-previous-error (&optional count)
634
+ "Visit the previous Eliscript build diagnostic by COUNT entries."
635
+ (interactive "p")
636
+ (previous-error count))
637
+
638
+ (defun eliscript-mode--check-arguments ()
639
+ "Return project-aware checker arguments for the current buffer."
640
+ (unless buffer-file-name
641
+ (signal 'eliscript-mode-error
642
+ '("project checking requires a file-backed buffer")))
643
+ (let* ((root (or (eliscript-mode-project-root)
644
+ (file-name-directory (expand-file-name buffer-file-name))))
645
+ (configuration (expand-file-name "eliscript.json" root))
646
+ (project-arguments
647
+ (if (file-regular-p configuration)
648
+ (list "--config" configuration)
649
+ (list "--root" root buffer-file-name))))
650
+ (append (cdr eliscript-mode-check-command)
651
+ project-arguments
652
+ (list "--stdin-file" buffer-file-name
653
+ "--json" "--diagnostic-format" "json"))))
654
+
655
+ (defun eliscript-mode--diagnostic-position (position fallback)
656
+ "Convert diagnostic POSITION to a buffer position, or use FALLBACK."
657
+ (let ((offset (and (listp position) (alist-get 'offset position))))
658
+ (if (and (integerp offset) (>= offset 0))
659
+ (min (point-max) (+ (point-min) offset))
660
+ fallback)))
661
+
662
+ (defun eliscript-mode--diagnostic-from-json (source)
663
+ "Return a Flymake diagnostic decoded from JSON SOURCE, or nil."
664
+ (condition-case nil
665
+ (let* ((value (json-parse-string source
666
+ :object-type 'alist
667
+ :array-type 'list
668
+ :null-object nil
669
+ :false-object nil))
670
+ (location (alist-get 'location value))
671
+ (filename (alist-get 'file location))
672
+ (same-file
673
+ (or (null filename)
674
+ (and buffer-file-name
675
+ (equal (ignore-errors (file-truename filename))
676
+ (ignore-errors
677
+ (file-truename buffer-file-name)))))))
678
+ (when (and (equal (alist-get 'format value) "eliscript-diagnostic")
679
+ (= (or (alist-get 'version value) 0) 1)
680
+ same-file)
681
+ (let* ((start (eliscript-mode--diagnostic-position
682
+ (alist-get 'start location) (point-min)))
683
+ (raw-end (eliscript-mode--diagnostic-position
684
+ (alist-get 'end location) start))
685
+ (end (max start (min (point-max) raw-end)))
686
+ (severity (alist-get 'severity value))
687
+ (type (cond
688
+ ((equal severity "warning") :warning)
689
+ ((equal severity "info") :note)
690
+ (t :error))))
691
+ (flymake-make-diagnostic
692
+ (current-buffer) start end type
693
+ (format "%s: %s"
694
+ (or (alist-get 'code value) "ELI-C0001")
695
+ (or (alist-get 'message value)
696
+ "Eliscript check failed"))))))
697
+ (error nil)))
698
+
699
+ (defun eliscript-mode--stop-flymake-process ()
700
+ "Stop the checker process owned by the current buffer."
701
+ (when (process-live-p eliscript-mode--flymake-process)
702
+ (kill-process eliscript-mode--flymake-process))
703
+ (setq eliscript-mode--flymake-process nil))
704
+
705
+ (defun eliscript-mode-flymake-backend (report-fn &rest _arguments)
706
+ "Check the current project asynchronously and call REPORT-FN."
707
+ (eliscript-mode--stop-flymake-process)
708
+ (let* ((source-buffer (current-buffer))
709
+ (generation (buffer-chars-modified-tick))
710
+ (output-buffer (generate-new-buffer " *eliscript-check-output*"))
711
+ (error-buffer (generate-new-buffer " *eliscript-check-error*"))
712
+ (program (eliscript-mode--check-program))
713
+ (command (cons program (eliscript-mode--check-arguments)))
714
+ process
715
+ stderr-process
716
+ finished-process
717
+ stderr-complete
718
+ reported
719
+ finish-fn)
720
+ (setq
721
+ finish-fn
722
+ (lambda ()
723
+ (when (and finished-process stderr-complete (not reported))
724
+ (setq reported t)
725
+ (unwind-protect
726
+ (when (buffer-live-p source-buffer)
727
+ (with-current-buffer source-buffer
728
+ (when (and
729
+ (eq finished-process
730
+ eliscript-mode--flymake-process)
731
+ (= generation (buffer-chars-modified-tick)))
732
+ (setq eliscript-mode--flymake-process nil)
733
+ (if (and
734
+ (eq (process-status finished-process) 'exit)
735
+ (zerop (process-exit-status finished-process)))
736
+ (funcall report-fn nil)
737
+ (let* ((json-source
738
+ (with-current-buffer error-buffer
739
+ (string-trim (buffer-string))))
740
+ (diagnostic
741
+ (eliscript-mode--diagnostic-from-json
742
+ json-source)))
743
+ (funcall report-fn
744
+ (if diagnostic (list diagnostic) nil)))))))
745
+ (when (buffer-live-p output-buffer)
746
+ (kill-buffer output-buffer))
747
+ (when (buffer-live-p error-buffer)
748
+ (kill-buffer error-buffer))))))
749
+ (condition-case error-data
750
+ (progn
751
+ (setq stderr-process
752
+ (make-pipe-process
753
+ :name "eliscript-check-stderr"
754
+ :buffer error-buffer
755
+ :coding 'utf-8-unix
756
+ :noquery t
757
+ :sentinel
758
+ (lambda (finished _event)
759
+ (when (memq (process-status finished)
760
+ '(exit signal closed failed))
761
+ (setq stderr-complete t)
762
+ (funcall finish-fn)))))
763
+ (setq process
764
+ (make-process
765
+ :name "eliscript-check"
766
+ :buffer output-buffer
767
+ :stderr stderr-process
768
+ :command command
769
+ :connection-type 'pipe
770
+ :coding 'utf-8-unix
771
+ :noquery t
772
+ :sentinel
773
+ (lambda (finished _event)
774
+ (when (memq (process-status finished) '(exit signal))
775
+ (setq finished-process finished)
776
+ (funcall finish-fn)))))
777
+ (setq eliscript-mode--flymake-process process)
778
+ (save-restriction
779
+ (widen)
780
+ (process-send-region process (point-min) (point-max)))
781
+ (process-send-eof process))
782
+ (error
783
+ (setq eliscript-mode--flymake-process nil)
784
+ (when (process-live-p process) (kill-process process))
785
+ (when (and (processp stderr-process)
786
+ (process-live-p stderr-process))
787
+ (delete-process stderr-process))
788
+ (when (buffer-live-p output-buffer) (kill-buffer output-buffer))
789
+ (when (buffer-live-p error-buffer) (kill-buffer error-buffer))
790
+ (signal (car error-data) (cdr error-data))))))
791
+
792
+ (defun eliscript-mode-check-buffer ()
793
+ "Check the current project and expose diagnostics through Flymake."
794
+ (interactive)
795
+ (unless flymake-mode (flymake-mode 1))
796
+ (flymake-start))
797
+
798
+ (defun eliscript-mode--read-file (filename)
799
+ "Return the complete contents of FILENAME as a string."
800
+ (with-temp-buffer
801
+ (insert-file-contents filename)
802
+ (buffer-string)))
803
+
804
+ (defun eliscript-mode-format-buffer ()
805
+ "Format the current buffer with the public self-hosted formatter.
806
+
807
+ The visited file is not saved. On failure the buffer remains unchanged."
808
+ (interactive)
809
+ (barf-if-buffer-read-only)
810
+ (let ((program (eliscript-mode--formatter-program))
811
+ (arguments (cdr eliscript-mode-format-command))
812
+ (source-file (make-temp-file "eliscript-mode-" nil ".eli"))
813
+ (error-file (make-temp-file "eliscript-mode-error-"))
814
+ (output-buffer (generate-new-buffer " *eliscript-format*"))
815
+ status)
816
+ (unwind-protect
817
+ (progn
818
+ (save-restriction
819
+ (widen)
820
+ (let ((coding-system-for-write 'utf-8-unix))
821
+ (write-region (point-min) (point-max) source-file nil 'silent)))
822
+ (let ((default-directory
823
+ (or (eliscript-mode-project-root) default-directory)))
824
+ (setq status
825
+ (apply #'process-file program nil
826
+ (list output-buffer error-file) nil
827
+ (append arguments (list source-file)))))
828
+ (unless (and (integerp status) (zerop status))
829
+ (let ((detail (string-trim
830
+ (eliscript-mode--read-file error-file))))
831
+ (signal 'eliscript-mode-error
832
+ (list (if (string-empty-p detail)
833
+ (format "formatter exited with status %s" status)
834
+ detail)))))
835
+ (save-restriction
836
+ (widen)
837
+ (unless (string= (buffer-string)
838
+ (with-current-buffer output-buffer
839
+ (buffer-string)))
840
+ (replace-region-contents
841
+ (point-min) (point-max)
842
+ (if (< emacs-major-version 31)
843
+ (lambda () output-buffer)
844
+ output-buffer))
845
+ t)))
846
+ (when (buffer-live-p output-buffer)
847
+ (kill-buffer output-buffer))
848
+ (delete-file source-file)
849
+ (delete-file error-file))))
850
+
851
+ ;;;###autoload
852
+ (define-derived-mode eliscript-mode prog-mode "Eliscript"
853
+ "Major mode for editing Eliscript source."
854
+ :syntax-table eliscript-mode-syntax-table
855
+ (setq-local comment-start "; ")
856
+ (setq-local comment-end "")
857
+ (setq-local comment-start-skip ";+\s-*")
858
+ (setq-local indent-tabs-mode nil)
859
+ (setq-local indent-line-function #'eliscript-mode--indent-line)
860
+ (setq-local font-lock-defaults '(eliscript-mode-font-lock-keywords))
861
+ (setq-local imenu-generic-expression
862
+ eliscript-mode-imenu-generic-expression)
863
+ (setq-local beginning-of-defun-function
864
+ #'eliscript-mode--beginning-of-defun)
865
+ (setq-local end-of-defun-function #'eliscript-mode--end-of-defun)
866
+ (setq-local parse-sexp-ignore-comments t)
867
+ (add-hook 'flymake-diagnostic-functions
868
+ #'eliscript-mode-flymake-backend nil t)
869
+ (add-hook 'kill-buffer-hook #'eliscript-mode--stop-flymake-process nil t))
870
+
871
+ ;;;###autoload
872
+ (add-to-list 'auto-mode-alist '("\\.eli\\'" . eliscript-mode))
873
+
874
+ (require 'eliscript-repl)
875
+
876
+ (provide 'eliscript-mode)
877
+
878
+ ;;; eliscript-mode.el ends here