forked from roadrunner1776/magik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magik-msg.el
executable file
·243 lines (206 loc) · 8.29 KB
/
magik-msg.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
;;; magik-msg.el --- mode for editing Magik msg and hmsg Message 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)
(defvar msb-menu-cond)
(require 'magik-utils)
(require 'magik-session))
(defgroup magik-msg nil
"Customise Magik Messages group."
:group 'magik
:group 'tools)
;; Imenu configuration
(defvar magik-msg-imenu-generic-expression
'(
(nil "^:\\(\\sw+\\)" 1) ;;Normal messages
(nil "^:\\s$\\(\\S$+\\)\\s$" 1) ;; | | Quoted messages
("Groups" "^+\\s-+\\(\\sw+\\)" 1)
)
"Imenu generic expression for Magik Message mode. See `imenu-generic-expression'.")
;; Font-lock configuration
(defcustom magik-msg-font-lock-keywords
(list
'("^\\(:\\sw*\\(\\s$\\S$*\\s$\\sw*\\)?\\)\\s-+\\(:\\sw+\\)"
(1 font-lock-function-name-face)
(3 font-lock-constant-face))
'("^\\([+]\\)\\s-+\\(\\sw*\\(\\s$\\S$*\\s$\\sw*\\)?\\)"
(1 font-lock-type-face)
(2 font-lock-keyword-face))
'("^:\\sw*\\(\\s$\\S$*\\s$\\sw*\\)?" . font-lock-function-name-face)
'("^#%\\s-*text_encoding.*$" . font-lock-warning-face)
'("#[0-9]+" . font-lock-variable-name-face)
'("#.*" . font-lock-comment-face)
)
"Default fontification of Magik Messages."
:group 'msg
:type 'sexp)
(defun magik-msg-customize ()
"Open Customization buffer for Msg Mode."
(interactive)
(customize-group 'msg))
(defun magik-msg-forward-message ()
"Put point at beginning of line of next message."
(interactive)
(if (not (looking-at "^:"))
(re-search-forward "^:" nil t)
(forward-char 1)
(or (re-search-forward "^:" nil t)
(goto-char (point-max))))
(beginning-of-line))
(defun magik-msg-backward-message ()
"Put point at beginning of line of previous message."
(interactive)
(if (not (looking-at "^:"))
(re-search-backward "^:" nil t)
(backward-char 1)
(or (re-search-backward "^:" nil t)
(goto-char (point-min))))
(beginning-of-line))
(defun magik-msg-mark-message ()
"Mark the current message."
;; also returns the value of mark.
(interactive)
(push-mark (point))
(magik-msg-forward-message)
(if (save-match-data (string-match "hmsg$" (buffer-name)))
nil
(re-search-backward "^\n" (- (point) 1) t))
(push-mark (point) nil t)
(magik-msg-backward-message))
;;;###autoload
(define-derived-mode magik-msg-mode nil "Message"
"Major mode for editing Magik Message files.
You can customize msg-mode with the `magik-msg-mode-hook`.
\\{magik-msg-mode-map}"
:group 'magik
:abbrev-table nil
(compat-call setq-local
require-final-newline t
imenu-generic-expression magik-msg-imenu-generic-expression
font-lock-defaults '(magik-msg-font-lock-keywords nil t)
outline-regexp "^:\\(\\sw+\\).*"))
(defvar magik-msg-menu nil
"Keymap for the Magik Message buffer menu bar.")
(easy-menu-define magik-msg-menu magik-msg-mode-map
"Menu for msg mode."
`(,"Message"
[,"Transmit Buffer" magik-msg-transmit-buffer (magik-utils-buffer-mode-list 'magik-session-mode)]
[,"Compile Message File" magik-msg-compile-module-messages (magik-utils-buffer-mode-list 'magik-session-mode)]
[,"Next" magik-msg-forward-message t]
[,"Previous" magik-msg-backward-message t]
[,"Mark Message" magik-msg-mark-message t]
"---"
[,"Customize" magik-msg-customize t]))
(defun magik-msg-transmit-buffer (&optional gis)
"Send the buffer to the GIS process.
The GIS process used is either that given by BUF or the variable `gis-buffer'."
(interactive)
(let ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Magik process buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(process (barf-if-no-gis gis))
(filename (buffer-file-name)))
;; Load messages
(message "%s loaded in buffer %s." filename gis)
(process-send-string
process
(concat
(magik-function "message_handler.compile_message_file" filename)
"\n$\n"))
gis))
(defun magik-msg-compile-module-messages (&optional gis)
"Compile all messages asociated with the module this buffer is assocaiated with in a GIS process.
The GIS process used is either that given by BUF or the variable `gis-buffer'."
(interactive)
(let ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Magik process buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(process (barf-if-no-gis gis))
(directory (file-name-directory (buffer-file-name))))
;; Load messages
(message "Compiling all module messages in %s. " gis)
(process-send-string
process
(format
"_proc(directory)
module << sw_module_manager.locate_module(directory)
sw_module_manager.compile_messages(module)
_endproc(%S)\n$\n"
directory))
gis))
(defun magik-msg-gis-drag-n-drop-load (gis filename)
"Interface to Drag 'n' Drop GIS mode.
Called by `gis-drag-n-drop-load' when a Msg file is dropped."
(let ((process (barf-if-no-gis gis)))
(message "%s loaded in buffer %s." filename gis)
(process-send-string
process
(concat
(magik-function "load_message_file" filename 'image_override)
"$\n"))))
(defvar magik-msg-multi-gis-processes nil
"Note whether more than one GIS has been used.")
;;; Package initialisation
(modify-syntax-entry ?: "w" magik-msg-mode-syntax-table)
(modify-syntax-entry ?_ "w" magik-msg-mode-syntax-table)
(modify-syntax-entry ?? "w" magik-msg-mode-syntax-table)
(modify-syntax-entry ?! "w" magik-msg-mode-syntax-table)
;; multi quote
(modify-syntax-entry ?| "$" magik-msg-mode-syntax-table)
;; variable intro
(modify-syntax-entry ?# "/" magik-msg-mode-syntax-table)
;;; Package registration
;;;###autoload
(or (assoc "\\.msg$" auto-mode-alist)
(push '("\\.msg$" . magik-msg-mode) auto-mode-alist))
(or (assoc "\\.hmsg$" auto-mode-alist)
(push '("\\.hmsg$" . magik-msg-mode) auto-mode-alist))
;; speedbar configuration
(with-eval-after-load 'speedbar
(speedbar-add-supported-extension ".msg")
(speedbar-add-supported-extension ".hmsg"))
;;MSB configuration
(defun magik-msg-msb-configuration ()
"Adds Msg files to msb menu, supposes that msb is already loaded."
(let* ((l (length msb-menu-cond))
(last (nth (1- l) msb-menu-cond))
(precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
(handle (1- (nth 1 last))))
(setcdr precdr (list
(list
'(eq major-mode 'magik-msg-mode)
handle
"Msg Files (%d)")
last))))
(with-eval-after-load 'msb
(magik-msg-msb-configuration))
(defvar magik-msg-f2-map (make-sparse-keymap)
"Keymap for the F2 function key in Magik Message buffers.")
(progn
;; ------------------------ magik msg mode ------------------------
(fset 'magik-msg-f2-map magik-msg-f2-map)
(define-key magik-msg-mode-map [f2] 'magik-msg-f2-map)
(define-key magik-msg-f2-map [down] 'magik-msg-forward-message)
(define-key magik-msg-f2-map [up] 'magik-msg-backward-message)
(define-key magik-msg-f2-map "b" 'magik-msg-transmit-buffer)
(define-key magik-msg-f2-map "c" 'magik-msg-compile-module-messages)
(define-key magik-msg-f2-map "m" 'magik-msg-mark-message))
(provide 'magik-msg)
;;; magik-msg.el ends here