-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmagik-product.el
executable file
·167 lines (135 loc) · 5.68 KB
/
magik-product.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
;;; magik-product.el --- mode for editing Magik product.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))
(defgroup magik-product nil
"Customise Magik product.def files group."
:group 'magik
:group 'tools)
;; Imenu configuration
(defvar magik-product-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-product-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 product.def files."
:group 'magik-product
:type 'sexp)
(defun magik-product-customize ()
"Open Customization buffer for Product Mode."
(interactive)
(customize-group 'magik-product))
;;;###autoload
(define-derived-mode magik-product-mode nil "Product"
"Major mode for editing Magik product.def files.
You can customize Product Mode with the `magik-product-mode-hook`.
\\{magik-product-mode-map}"
:group 'magik
:abbrev-table nil
:syntax-table nil
(compat-call setq-local
require-final-newline t
imenu-generic-expression magik-product-imenu-generic-expression
font-lock-defaults '(magik-product-font-lock-keywords nil t)))
(defvar magik-product-menu nil
"Keymap for the Magik product.def buffer menu bar.")
(easy-menu-define magik-product-menu magik-product-mode-map
"Menu for Product mode."
`(,"Product"
[,"Add product" magik-product-transmit-buffer (magik-utils-buffer-mode-list 'magik-session-mode)]
[,"Reinitialise product" magik-product-reinitialise (magik-utils-buffer-mode-list 'magik-session-mode)]
"---"
[,"Customize" magik-product-customize t]))
(defvar magik-product-mode-syntax-table nil
"Syntax table in use in Product Mode buffers.")
(defun magik-product-name ()
"Return current Product's name as a string."
(save-excursion
(goto-char (point-min))
(current-word)))
(defun magik-product-reinitialise (&optional gis)
"Reinitialise this product in GIS."
(interactive)
(let* ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Magik Session buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(process (barf-if-no-gis gis)))
(display-buffer gis t)
(process-send-string
process
(concat ;; the .products[] interface is used for backwards compatibility.
"smallworld_product"
".products[:|" (magik-product-name) "|]"
".reinitialise()\n$\n"))
gis))
(defun magik-product-transmit-add-product (filename process)
"Add the product FILENAME to the GIS PROCESS."
(process-send-string
process
(concat
(magik-function "smallworld_product.add_product" filename)
"\n$\n")))
(defun magik-product-transmit-buffer (&optional gis)
"Send current buffer to GIS."
(interactive)
(let* ((gis (magik-utils-get-buffer-mode gis
'magik-session-mode
"Enter Magik Session buffer:"
magik-session-buffer
'magik-session-buffer-alist-prefix-function))
(process (barf-if-no-gis gis))
(filename (buffer-file-name)))
(pop-to-buffer gis t)
(magik-product-transmit-add-product filename process)
gis))
(defun magik-product-drag-n-drop-load (gis filename)
"Interface to Drag and Drop GIS mode.
Called by `magik-session-drag-n-drop-load' when a Product FILENAME is dropped."
(let ((process (barf-if-no-gis gis)))
(magik-product-transmit-add-product filename process)
gis))
;;; Package initialisation
(modify-syntax-entry ?_ "w" magik-product-mode-syntax-table)
(modify-syntax-entry ?# "<" magik-product-mode-syntax-table)
(modify-syntax-entry ?\n ">" magik-product-mode-syntax-table)
;;; Package registration
;;;###autoload
(add-to-list 'auto-mode-alist '("product.def\\'" . magik-product-mode))
(defvar magik-product-f2-map (make-sparse-keymap)
"Keymap for the F2 function key in Magik product.def buffers.")
(progn
;; ------------------------ magik product mode ------------------------
(fset 'magik-product-f2-map magik-product-f2-map)
(define-key magik-product-mode-map [f2] 'magik-product-f2-map)
(define-key magik-product-f2-map "b" 'magik-product-transmit-buffer)
(define-key magik-product-f2-map "r" 'magik-product-reinitialise))
(provide 'magik-product)
;;; magik-product.el ends here