forked from roadrunner1776/magik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magik-module.el
executable file
·336 lines (292 loc) · 12.2 KB
/
magik-module.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
;;; magik-module.el --- mode for editing Magik module.def files.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(eval-when-compile
(require 'easymenu)
(require 'font-lock)
(require 'magik-utils)
(require 'magik-session))
(require 'compat)
(defgroup magik-module nil
"Customise Magik module.def files group."
:group 'magik
:group 'tools)
(defcustom magik-module-option-save-magikc t
"*If t, save .magikc files when loading module."
:group 'smallworld
:type 'boolean)
(defcustom magik-module-option-force-reload t
"*If t, save .magikc files when loading module."
:group 'smallworld
:type 'boolean)
;; Imenu configuration
(defvar magik-module-imenu-generic-expression
'(
(nil "^\\(\\sw+\\)\\s-*\n\\(.\\|\n\\)*\nend\\s-*$" 1)
)
"Imenu generic expression for Magik Message mode. See `imenu-generic-expression'.")
;; Font-lock configuration
(defcustom magik-module-font-lock-keywords
(list
'("^end\\s-*$" . font-lock-keyword-face)
'("^hidden$" . font-lock-keyword-face)
'("^\\(language\\)\\s-+\\(\\sw+\\)"
(1 font-lock-keyword-face)
(2 font-lock-type-face))
'("^\\(\\sw+\\)\\s-*$" . font-lock-variable-name-face)
'("^\\(\\sw+\\s-*\\sw*\\)\\s-*\\([0-9]*\\s-*[0-9]*\\)"
(1 font-lock-function-name-face)
(2 font-lock-constant-face))
)
"Default fontification of module.def files."
:group 'module
:type 'sexp)
(defun magik-module-customize ()
"Open Customization buffer for Module Mode."
(interactive)
(customize-group 'magik-module))
;;;###autoload
(define-derived-mode magik-module-mode nil "Module"
"Major mode for editing Magik module.def files.
You can customize Module Mode with the `magik-module-mode-hook`.
\\{magik-module-mode-map}"
:group 'magik
:abbrev-table nil
(compat-call setq-local
require-final-newline t
imenu-generic-expression magik-module-imenu-generic-expression
font-lock-defaults '(magik-module-font-lock-keywords nil t)))
(defvar magik-module-menu nil
"Keymap for the Magik module.def buffer menu bar.")
(easy-menu-define magik-module-menu magik-module-mode-map
"Menu for Module mode."
`(,"Module"
[,"Load" magik-module-transmit-buffer (magik-utils-buffer-mode-list 'magik-session-mode)]
[,"Reload definition" magik-module-reload-module-definition (magik-utils-buffer-mode-list 'magik-session-mode)]
[,"Compile messages" magik-module-compile-messages (magik-utils-buffer-mode-list 'magik-session-mode)]
[,"Remove" magik-module-remove-module (magik-utils-buffer-mode-list 'magik-session-mode)]
(,"Set Options..."
[,"Set :save_magikc? to _false"
(magik-module-toggle-save-magikc -1)
:active (magik-utils-buffer-mode-list 'magik-session-mode)
:style radio
:selected (null module-option-save-magikc)
:keys "M-- M-1 <f2> m, <f2> m"]
[,"Set :save_magikc? to _true"
(magik-module-toggle-save-magikc 1)
:active (magik-utils-buffer-mode-list 'magik-session-mode)
:style radio
:selected module-option-save-magikc
:keys "M-1 <f2> m, <f2> m"]
"---"
[,"Set :force_reload? to _false"
(magik-module-toggle-force-reload -1)
:active (magik-utils-buffer-mode-list 'magik-session-mode)
:style radio
:selected (null module-option-force-reload)
:keys "M-- M-1 <f2> r, <f2> r"]
[,"Set :force_reload? to :prerequisites"
(magik-module-toggle-force-reload 'prerequisites)
:active (magik-utils-buffer-mode-list 'magik-session-mode)
:style radio
:selected (eq module-option-force-reload 'prerequisites)
:keys "C-u <f2> r"]
[,"Set :force_reload? to _true"
(magik-module-toggle-force-reload 1)
:active (magik-utils-buffer-mode-list 'magik-session-mode)
:style radio
:selected (eq module-option-force-reload t)
:keys "M-1 <f2> r, <f2> r"])
"---"
[,"Customize" magik-module-customize t]))
(defvar magik-module-mode-syntax-table nil
"Syntax table in use in Module Mode buffers.")
;; Imenu configuration
(defvar magik-module-imenu-generic-expression
'(
(nil "^\\(\\sw+\\)\\s-*\n\\(.\\|\n\\)*\nend\\s-*$" 1)
)
"Imenu generic expression for Magik Message mode. See `imenu-generic-expression'.")
;; Font-lock configuration
(defcustom magik-module-font-lock-keywords
(list
'("^end\\s-*$" . font-lock-keyword-face)
'("^hidden$" . font-lock-keyword-face)
'("^\\(language\\)\\s-+\\(\\sw+\\)"
(1 font-lock-keyword-face)
(2 font-lock-type-face))
'("^\\(\\sw+\\)\\s-*$" . font-lock-variable-name-face)
'("^\\(\\sw+\\s-*\\sw*\\)\\s-*\\([0-9]*\\s-*[0-9]*\\)"
(1 font-lock-function-name-face)
(2 font-lock-constant-face))
)
"Default fontification of module.def files."
:group 'module
:type 'sexp)
(defun magik-module-customize ()
"Open Customization buffer for Module Mode."
(interactive)
(customize-group 'magik-module))
(defun magik-module-toggle-save-magikc (arg)
"Toggle saving of .magikc files when loading module."
(interactive "P")
(setq magik-module-option-save-magikc
(if (null arg)
(not magik-module-option-save-magikc)
(> (prefix-numeric-value arg) 0)))
(message "Set :save_magikc? to %s"
(magik-function-convert magik-module-option-save-magikc)))
(defun magik-module-toggle-force-reload (arg)
"Toggle force_reload? option when loading module.
If called with a non-integer prefix key then the :prerequisites
option is set."
(interactive "P")
(setq magik-module-option-force-reload
(cond ((null arg)
(not magik-module-option-force-reload))
((symbolp arg)
arg)
((and current-prefix-arg (not (integerp current-prefix-arg)))
'prerequisites)
(t
(> (prefix-numeric-value arg) 0))))
(message "Set :force_reload? option to %s"
(magik-function-convert magik-module-option-force-reload)))
(defun magik-module-name ()
"Return current Module's name as a string."
(save-excursion
(goto-char (point-min))
(current-word)))
(defun magik-module-reload-module-definition (&optional gis)
"Reload the module definition in the GIS process."
(interactive)
(let* ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Gis process buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(module (intern (concat "|" (magik-module-name) "|")))
(process (barf-if-no-gis gis)))
(message "%s reloaded in buffer %s." (magik-module-name) gis)
(display-buffer gis t)
(process-send-string
process
(concat
(magik-function "sw_module_manager.reload_module_definition" module) ;include version number?
"$\n"))
gis))
(defun magik-module-compile-messages (&optional gis)
"Compile all the Module's messages in the GIS process."
(interactive)
(let* ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Gis process buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(module (intern (concat "|" (magik-module-name) "|")))
(process (barf-if-no-gis gis)))
(message "Compiled messages for %s in buffer %s." (magik-module-name) gis)
(display-buffer gis t)
(process-send-string
process
(concat
(magik-function
"_proc(module_name, version)
_if (a_module << sw_module_manager.module(module_name, version, _true)) _isnt _unset
_then
a_module.compile_messages()
_endif
_endproc"
module 'unset) ;include version number?
"\n$\n"))
gis))
(defun magik-module-remove-module (&optional gis)
"Remove the module definition from the GIS process.
If module definition is not known to the Magik GIS it is loaded as
a standalone module."
(interactive)
(let* ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Gis process buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(module (intern (concat "|" (magik-module-name) "|")))
(process (barf-if-no-gis gis)))
(display-buffer gis t)
(process-send-string
process
(concat
(magik-function "sw_module_manager.remove_module" module)
"$\n"))
gis))
(defun magik-module-transmit-load-module (filename process)
"Load the module into the GIS process.
If module definition is not known to the Magik GIS it is loaded as
a standalone module."
(let ((module (intern (concat "|" (magik-module-name) "|"))))
(process-send-string
process
(concat
"_try\n"
(magik-function "sw_module_manager.load_module" module 'unset
'save_magikc? magik-module-option-save-magikc
'force_reload? magik-module-option-force-reload)
"_when sw_module_no_such_module\n"
(magik-function "sw_module_manager.load_standalone_module_definition" filename
'save_magikc? magik-module-option-save-magikc
'force_reload? magik-module-option-force-reload)
"_endtry\n"
"$\n"))))
(defun magik-module-transmit-buffer (&optional gis)
"Send current buffer to GIS."
(interactive)
(let* ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Gis process buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(process (barf-if-no-gis gis))
(filename (buffer-file-name)))
(message "%s loaded in buffer %s." (magik-module-name) gis)
(display-buffer gis t)
(magik-module-transmit-load-module filename process)
gis))
(defun magik-module-gis-drag-n-drop-load (gis filename)
"Interface to Drag 'n' Drop GIS mode.
Called by `gis-drag-n-drop-load' when a Module file is dropped."
(let ((process (barf-if-no-gis gis)))
(magik-module-transmit-load-module filename process)
gis))
;;; Package initialisation
(modify-syntax-entry ?_ "w" magik-module-mode-syntax-table)
(modify-syntax-entry ?# "<" magik-module-mode-syntax-table)
(modify-syntax-entry ?\n ">" magik-module-mode-syntax-table)
;;; Package registration
;;;###autoload
(or (assoc "module\\.def$" auto-mode-alist)
(push '("module\\.def$" . magik-module-mode) auto-mode-alist))
(defvar magik-module-f2-map (make-sparse-keymap)
"Keymap for the F2 function key in Magik module.def buffers.")
(progn
;; ------------------------ magik module mode ------------------------
(fset 'magik-module-f2-map magik-module-f2-map)
(define-key magik-module-mode-map [f2] 'magik-module-f2-map)
(define-key magik-module-f2-map "b" 'magik-module-transmit-buffer)
(define-key magik-module-f2-map "c" 'magik-module-compile-messages)
(define-key magik-module-f2-map "d" 'magik-module-reload-module-definition)
(define-key magik-module-f2-map "m" 'magik-module-toggle-save-magikc)
(define-key magik-module-f2-map "r" 'magik-module-toggle-force-reload)
(define-key magik-module-f2-map "R" 'magik-module-remove-module))
(provide 'magik-module)
;;; magik-module.el ends here