1 | ;;
|
---|
2 | ;; TOPPERS Software
|
---|
3 | ;; Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
4 | ;;
|
---|
5 | ;; Copyright (C) 2010 by TAKUYA
|
---|
6 | ;; Embedded and Real-Time Systems Laboratory
|
---|
7 | ;; Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
8 | ;;
|
---|
9 | ;; ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
10 | ;; Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
11 | ;; ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
12 | ;; (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
13 | ;; \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
14 | ;; XR[hÉÜÜêÄ¢é±ÆD
|
---|
15 | ;; (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
16 | ;; pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
17 | gip
|
---|
18 | ;; Ò}j
|
---|
19 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
20 | ;; ̳ÛØKèðfÚ·é±ÆD
|
---|
21 | ;; (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
22 | ;; pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
23 | ;; ÆD
|
---|
24 | ;; (a) Äzzɺ¤hL
|
---|
25 | gipÒ}j
|
---|
26 | AÈÇjÉCãLÌ
|
---|
27 | ;; ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
28 | ;; (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
29 | ;; ñ·é±ÆD
|
---|
30 | ;; (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
31 | ;; Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
32 | ;; ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
33 | ;; RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
34 | ;; ÆÓ·é±ÆD
|
---|
35 | ;;
|
---|
36 | ;; {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
37 | ;; æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
38 | ;; ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
39 | ;; AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
40 | ;; ÌÓCðíÈ¢D
|
---|
41 | ;;
|
---|
42 | ;;
|
---|
43 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
44 | ;;
|
---|
45 | ;; cdl-mode for xyzzy
|
---|
46 | ;;
|
---|
47 | ;;
|
---|
48 | ;; [hû@D
|
---|
49 | ;; 1. cdl-mode.l ð site-lisp/ ̺ÉC
|
---|
50 | ;; CDL ð etc/ ̺ɻê¼ê¨D
|
---|
51 | ;; 2. ºLð .xyzzy ÉÇÁ·éD
|
---|
52 | ;;
|
---|
53 | ;; (require "cdl-mode")
|
---|
54 | ;; (push '("\\.cdl$" . cdl-mode) *auto-mode-alist*)
|
---|
55 | ;;
|
---|
56 |
|
---|
57 | (provide "cdl-mode")
|
---|
58 |
|
---|
59 | (in-package "editor")
|
---|
60 |
|
---|
61 | (export '(*cdl-mode-hook* cdl-indent-level cdl-continued-statement-offset
|
---|
62 | cdl-argdecl-indent cdl-brace-offset cdl-brace-imaginary-offset
|
---|
63 | cdl-label-offset cdl-comment-indent))
|
---|
64 | (export '(cdl-mode cdl-indent-line cdl-newline-and-indent cdl-electric-insert
|
---|
65 | cdl-electric-close indent-cpp-directive
|
---|
66 | *cdl-keyword-file* *cdl-indent-tabs-mode*
|
---|
67 | *cdl-tab-always-indent* *cdl-comment-column*
|
---|
68 | *cdl-comment-c++-style*))
|
---|
69 |
|
---|
70 | (defvar *cdl-mode-hook* nil)
|
---|
71 |
|
---|
72 | (unless (boundp 'cdl-indent-level)
|
---|
73 | (setq cdl-indent-level 2)
|
---|
74 | (setq cdl-continued-statement-offset 2)
|
---|
75 | (setq cdl-argdecl-indent 5)
|
---|
76 | (setq cdl-brace-offset 0)
|
---|
77 | (setq cdl-brace-imaginary-offset 0)
|
---|
78 | (setq cdl-label-offset -2)
|
---|
79 | (setq cdl-comment-indent 2))
|
---|
80 |
|
---|
81 | (defvar *cdl-tab-always-indent* t)
|
---|
82 |
|
---|
83 | (defvar *cdl-indent-tabs-mode* nil)
|
---|
84 | (defvar *cdl-comment-column* nil)
|
---|
85 | (defvar *cdl-comment-c++-style* nil)
|
---|
86 |
|
---|
87 | (defvar *cdl-keyword-hash-table* nil)
|
---|
88 | (defvar *cdl-keyword-file* "CDL")
|
---|
89 |
|
---|
90 | (defvar *cdl-mode-syntax-table* nil)
|
---|
91 | (unless *cdl-mode-syntax-table*
|
---|
92 | (setq *cdl-mode-syntax-table* (make-syntax-table))
|
---|
93 | (do ((x #x21 (1+ x)))((>= x #x7f))
|
---|
94 | (let ((c (code-char x)))
|
---|
95 | (unless (alphanumericp c)
|
---|
96 | (set-syntax-punctuation *cdl-mode-syntax-table* c))))
|
---|
97 | (set-syntax-option *cdl-mode-syntax-table*
|
---|
98 | *syntax-option-c-preprocessor*)
|
---|
99 | (set-syntax-string *cdl-mode-syntax-table* #\")
|
---|
100 | (set-syntax-string *cdl-mode-syntax-table* #\')
|
---|
101 | (set-syntax-escape *cdl-mode-syntax-table* #\\)
|
---|
102 | (set-syntax-symbol *cdl-mode-syntax-table* #\_)
|
---|
103 | (set-syntax-symbol *cdl-mode-syntax-table* #\#)
|
---|
104 | (set-syntax-match *cdl-mode-syntax-table* #\( #\))
|
---|
105 | (set-syntax-match *cdl-mode-syntax-table* #\{ #\})
|
---|
106 | (set-syntax-match *cdl-mode-syntax-table* #\[ #\])
|
---|
107 | (set-syntax-start-multi-comment *cdl-mode-syntax-table* "/*")
|
---|
108 | (set-syntax-end-multi-comment *cdl-mode-syntax-table* "*/")
|
---|
109 | (set-syntax-start-c++-comment *cdl-mode-syntax-table* #\/)
|
---|
110 | (set-syntax-end-c++-comment *cdl-mode-syntax-table* #\LFD))
|
---|
111 |
|
---|
112 | (defvar *cdl-mode-map* nil)
|
---|
113 | (unless *cdl-mode-map*
|
---|
114 | (setq *cdl-mode-map* (make-sparse-keymap))
|
---|
115 | (define-key *cdl-mode-map* #\{ 'cdl-electric-insert)
|
---|
116 | (define-key *cdl-mode-map* #\: 'cdl-electric-insert)
|
---|
117 | (define-key *cdl-mode-map* #\# 'cdl-electric-insert)
|
---|
118 | (define-key *cdl-mode-map* #\} 'cdl-electric-close)
|
---|
119 | (define-key *cdl-mode-map* #\C-h 'backward-delete-char-untabify-or-selection)
|
---|
120 | (define-key *cdl-mode-map* #\TAB 'cdl-indent-line)
|
---|
121 | (define-key *cdl-mode-map* #\C-M-q 'indent-sexp)
|
---|
122 | (define-key *cdl-mode-map* #\RET 'cdl-newline-and-indent))
|
---|
123 |
|
---|
124 | (defvar *cdl-mode-abbrev-table* nil)
|
---|
125 | (unless *cdl-mode-abbrev-table*
|
---|
126 | (define-abbrev-table '*cdl-mode-abbrev-table*))
|
---|
127 |
|
---|
128 | (defun cdl-indent-line ()
|
---|
129 | (interactive "*")
|
---|
130 | (if (or (not (interactive-p))
|
---|
131 | *cdl-tab-always-indent*
|
---|
132 | (save-excursion
|
---|
133 | (skip-chars-backward " \t")
|
---|
134 | (bolp)))
|
---|
135 | (case (save-excursion
|
---|
136 | (goto-bol)
|
---|
137 | (parse-point-syntax))
|
---|
138 | (:string)
|
---|
139 | (:comment
|
---|
140 | (let ((column (calc-cdl-comment-indent)))
|
---|
141 | (when (integerp column)
|
---|
142 | (smart-indentation column))))
|
---|
143 | (t
|
---|
144 | (let ((column (calc-c-indent)))
|
---|
145 | (when (integerp column)
|
---|
146 | (smart-indentation column)))))
|
---|
147 | (insert "\t"))
|
---|
148 | t)
|
---|
149 |
|
---|
150 | (defun cdl-newline-and-indent (&optional (arg 1))
|
---|
151 | (interactive "*p")
|
---|
152 | (delete-trailing-spaces)
|
---|
153 | (insert #\LFD arg)
|
---|
154 | (cdl-indent-line))
|
---|
155 |
|
---|
156 | (defun cdl-electric-insert (&optional (arg 1))
|
---|
157 | (interactive "*p")
|
---|
158 | (unless (prog1
|
---|
159 | (parse-point-syntax)
|
---|
160 | (self-insert-command arg))
|
---|
161 | (cdl-indent-line))
|
---|
162 | t)
|
---|
163 |
|
---|
164 | (defun cdl-electric-close (&optional (arg 1))
|
---|
165 | (interactive "*p")
|
---|
166 | (unless (prog1
|
---|
167 | (parse-point-syntax)
|
---|
168 | (self-insert-command arg))
|
---|
169 | (cdl-indent-line))
|
---|
170 | (save-excursion
|
---|
171 | (forward-char -1)
|
---|
172 | (and (goto-matched-parenthesis)
|
---|
173 | (show-matched-parenthesis)))
|
---|
174 | t)
|
---|
175 |
|
---|
176 | (defun cpp-indent-to (to)
|
---|
177 | (skip-chars-forward " \t")
|
---|
178 | (when (/= to (current-column))
|
---|
179 | (delete-horizontal-spaces)
|
---|
180 | (indent-to to)))
|
---|
181 |
|
---|
182 | (defun indent-cpp-directive ()
|
---|
183 | (interactive)
|
---|
184 | (save-excursion
|
---|
185 | (let ((column 1))
|
---|
186 | (goto-char (point-min))
|
---|
187 | (while (scan-buffer "^#" :regexp t)
|
---|
188 | (forward-char 1)
|
---|
189 | (cond ((looking-at "[ \t]*if")
|
---|
190 | (cpp-indent-to column)
|
---|
191 | (setq column (1+ column)))
|
---|
192 | ((looking-at "[ \t]*el\\(se\\|if\\)")
|
---|
193 | (cpp-indent-to (1- column)))
|
---|
194 | ((looking-at "[ \t]*endif")
|
---|
195 | (setq column (1- column))
|
---|
196 | (when (zerop column)
|
---|
197 | (error "Unmatched \"#endif\" at line ~d" (current-line-number)))
|
---|
198 | (cpp-indent-to column))
|
---|
199 | (t (cpp-indent-to column)
|
---|
200 | (if (looking-for "define")
|
---|
201 | (while (and (progn
|
---|
202 | (goto-eol)
|
---|
203 | (forward-char -1)
|
---|
204 | (looking-for "\\"))
|
---|
205 | (forward-line 1))
|
---|
206 | (cdl-indent-line))))))
|
---|
207 | (when (/= column 1)
|
---|
208 | (error "Unmatched \"#if\" or \"#ifdef\""))))
|
---|
209 | t)
|
---|
210 |
|
---|
211 | (defun cdl-comment-indent ()
|
---|
212 | (save-excursion
|
---|
213 | (let ((opoint (point)))
|
---|
214 | (goto-bol)
|
---|
215 | (cond ((looking-at "/\\*\\|//")
|
---|
216 | 0)
|
---|
217 | (t
|
---|
218 | (skip-chars-forward " \t")
|
---|
219 | (cond ((looking-at "}[ \t]*\\($\\|/\\*\\|//\\)")
|
---|
220 | (+ (current-column) 2))
|
---|
221 | ((looking-at "#[ \t]*\\(endif\\|else\\)\\>")
|
---|
222 | (goto-char (match-end 1))
|
---|
223 | (+ (current-column) 2))
|
---|
224 | ((or (looking-at "/\\*\\|//")
|
---|
225 | (eolp))
|
---|
226 | (calc-c-indent))
|
---|
227 | ((zerop comment-column)
|
---|
228 | 0)
|
---|
229 | (t
|
---|
230 | (goto-char opoint)
|
---|
231 | (skip-chars-backward " \t")
|
---|
232 | (max (1+ (current-column)) comment-column))))))))
|
---|
233 |
|
---|
234 | (defvar-local cdl-comment-indent-variable 'cdl-comment-indent)
|
---|
235 |
|
---|
236 | (defun calc-cdl-comment-indent ()
|
---|
237 | (save-excursion
|
---|
238 | (goto-bol)
|
---|
239 | (skip-chars-forward " \t")
|
---|
240 | (let ((eolp (eolp)))
|
---|
241 | (when (and (or eolp (looking-for "*"))
|
---|
242 | (scan-buffer "/*" :reverse t))
|
---|
243 | (while (and (eq (parse-point-syntax) ':comment)
|
---|
244 | (scan-buffer "/*" :reverse t :no-dup t)))
|
---|
245 | (+ (current-column)
|
---|
246 | (if eolp
|
---|
247 | (if (symbolp cdl-comment-indent-variable)
|
---|
248 | (symbol-value cdl-comment-indent-variable)
|
---|
249 | 0)
|
---|
250 | 1))))))
|
---|
251 |
|
---|
252 | (autoload 'cdl-build-summary-of-functions "cfns" nil)
|
---|
253 | (autoload 'cdl-maketags "cfns")
|
---|
254 | (pushnew '(cdl-maketags "*.c" "*.cpp" "*.cxx" "*.cc" "*.h" "*.hpp" "*.hxx" "*.inl")
|
---|
255 | *maketags-list* :key #'car)
|
---|
256 |
|
---|
257 | (defun cdl-tags-find-target ()
|
---|
258 | (let* ((opoint (point))
|
---|
259 | (tail (progn
|
---|
260 | (skip-chars-forward "a-zA-Z0-9_")
|
---|
261 | (point)))
|
---|
262 | (name (buffer-substring tail
|
---|
263 | (progn
|
---|
264 | (skip-chars-backward "a-zA-Z0-9_")
|
---|
265 | (when (or (looking-back "::~")
|
---|
266 | (looking-back "->~")
|
---|
267 | (looking-back ".~"))
|
---|
268 | (forward-char -1))
|
---|
269 | (point))))
|
---|
270 | class)
|
---|
271 | (cond ((looking-back "::")
|
---|
272 | (forward-char -2)
|
---|
273 | (let ((point (point)))
|
---|
274 | (when (looking-back ">")
|
---|
275 | (let ((depth 1))
|
---|
276 | (loop
|
---|
277 | (forward-char -1)
|
---|
278 | (skip-chars-backward "^<>")
|
---|
279 | (cond ((looking-back ">")
|
---|
280 | (incf depth))
|
---|
281 | ((looking-back "<")
|
---|
282 | (decf depth)
|
---|
283 | (when (zerop depth)
|
---|
284 | (forward-char -1)
|
---|
285 | (return)))
|
---|
286 | (t
|
---|
287 | (return)))))
|
---|
288 | (skip-chars-backward " \t\n\f")
|
---|
289 | (setq point (point)))
|
---|
290 | (setq class (buffer-substring point
|
---|
291 | (progn
|
---|
292 | (skip-chars-backward "a-zA-Z0-9_")
|
---|
293 | (point))))))
|
---|
294 | (t
|
---|
295 | (goto-char tail)
|
---|
296 | (when (looking-for "::")
|
---|
297 | (forward-char 2)
|
---|
298 | (setq class name)
|
---|
299 | (setq name (buffer-substring
|
---|
300 | (point)
|
---|
301 | (progn
|
---|
302 | (skip-chars-forward "a-zA-Z0-9_")
|
---|
303 | (point)))))))
|
---|
304 | (goto-char opoint)
|
---|
305 | (values class name '(function structure))))
|
---|
306 |
|
---|
307 | (defun cdl-tags-find-point-1 (re start reverse structurep lgoal)
|
---|
308 | (let* ((limit (if reverse
|
---|
309 | (- start *jump-tag-limit*)
|
---|
310 | (+ start *jump-tag-limit*)))
|
---|
311 | (goal (progn
|
---|
312 | (goto-char start)
|
---|
313 | (while (scan-buffer re :regexp t :limit limit :tail t :reverse reverse)
|
---|
314 | (let ((opoint (point))
|
---|
315 | (point0 (match-beginning 0))
|
---|
316 | (start (match-end 1)))
|
---|
317 | (unless structurep
|
---|
318 | (forward-char -1)
|
---|
319 | (forward-sexp 1 t))
|
---|
320 | (skip-white-forward)
|
---|
321 | (unless (looking-for ";")
|
---|
322 | (return start))
|
---|
323 | (goto-char (if reverse (1- point0) opoint)))))))
|
---|
324 | (if lgoal
|
---|
325 | (if goal
|
---|
326 | (if (< (abs (- lgoal start)) (abs (- goal start)))
|
---|
327 | lgoal goal)
|
---|
328 | lgoal)
|
---|
329 | goal)))
|
---|
330 |
|
---|
331 | (defun cdl-tags-find-point (class name type point)
|
---|
332 | (let* ((structurep (eq type 'structure))
|
---|
333 | (re (compile-regexp (if structurep
|
---|
334 | (concat "\\_<\\(?:struct\\|class\\|interface\\)[ \t\n\f]+\\("
|
---|
335 | name "\\)\\_>")
|
---|
336 | (concat "\\_<\\(" name "\\)[ \t\n\f]*("))))
|
---|
337 | goal)
|
---|
338 | (setq goal (cdl-tags-find-point-1 re point t structurep nil))
|
---|
339 | (setq goal (cdl-tags-find-point-1 re point nil structurep goal))
|
---|
340 | goal))
|
---|
341 |
|
---|
342 | ;; Fï·éL[[hi³K\»j
|
---|
343 |
|
---|
344 | (defvar *cdl-regexp-keyword-list* nil)
|
---|
345 | (setq *cdl-regexp-keyword-list*
|
---|
346 | (compile-regexp-keyword-list
|
---|
347 | '(
|
---|
348 | ("\\([\[]\\)\\(in\\|out\\|inout\\|oneway\\)\\([\]]\\)" nil (:keyword 2) nil 2 2)
|
---|
349 | )
|
---|
350 | ))
|
---|
351 | ; ("³K\»" 嶬¶ÌæÊðµÈ¢H color LøÍÍ Ç±©ç DZÜÅ)
|
---|
352 |
|
---|
353 | (defun cdl-mode ()
|
---|
354 | (interactive)
|
---|
355 | (kill-all-local-variables)
|
---|
356 | (setq mode-name "CDL")
|
---|
357 | (setq buffer-mode 'cdl-mode)
|
---|
358 | (use-syntax-table *cdl-mode-syntax-table*)
|
---|
359 | (use-keymap *cdl-mode-map*)
|
---|
360 | (make-local-variable 'mode-specific-indent-command)
|
---|
361 | (setq mode-specific-indent-command 'cdl-indent-line)
|
---|
362 | (make-local-variable 'paragraph-start)
|
---|
363 | (setq paragraph-start "^$\\|\f")
|
---|
364 | (make-local-variable 'paragraph-separate)
|
---|
365 | (setq paragraph-separate paragraph-start)
|
---|
366 | (make-local-variable 'indent-tabs-mode)
|
---|
367 | (setq indent-tabs-mode *cdl-indent-tabs-mode*)
|
---|
368 | (make-local-variable 'tags-find-target)
|
---|
369 | (setq tags-find-target #'cdl-tags-find-target)
|
---|
370 | (make-local-variable 'tags-find-point)
|
---|
371 | (setq tags-find-point #'cdl-tags-find-point)
|
---|
372 | (make-local-variable 'build-summary-function)
|
---|
373 | (setq build-summary-function 'cdl-build-summary-of-functions)
|
---|
374 | (and *cdl-keyword-file*
|
---|
375 | (null *cdl-keyword-hash-table*)
|
---|
376 | (setq *cdl-keyword-hash-table*
|
---|
377 | (load-keyword-file *cdl-keyword-file*)))
|
---|
378 | (when *cdl-keyword-hash-table*
|
---|
379 | (make-local-variable 'keyword-hash-table)
|
---|
380 | (setq keyword-hash-table *cdl-keyword-hash-table*))
|
---|
381 | (setq *local-abbrev-table* *cdl-mode-abbrev-table*)
|
---|
382 | (if *cdl-comment-c++-style*
|
---|
383 | (setq comment-start "// " comment-end "")
|
---|
384 | (setq comment-start "/* " comment-end " */"))
|
---|
385 | (setq comment-start-skip "/\\(\\*+\\|/\\)[ \t]*")
|
---|
386 | (setq comment-indent-function 'cdl-comment-indent)
|
---|
387 | (when *cdl-comment-column*
|
---|
388 | (setq comment-column *cdl-comment-column*))
|
---|
389 | (make-local-variable 'regexp-keyword-list)
|
---|
390 | (setq regexp-keyword-list *cdl-regexp-keyword-list*)
|
---|
391 | (run-hooks '*cdl-mode-hook*))
|
---|