Mercurial > emacs
comparison lisp/progmodes/vera-mode.el @ 78032:cac7f84f6e31
progmodes/vera-mode.el: New file.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Wed, 20 Jun 2007 15:22:59 +0000 |
parents | |
children | 3475e1b1a4e4 |
comparison
equal
deleted
inserted
replaced
78031:8ed0b9c9f6fc | 78032:cac7f84f6e31 |
---|---|
1 ;;; vera-mode.el --- major mode for editing Vera files. | |
2 | |
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, | |
4 ;; 2006, 2007 Free Software Foundation, Inc. | |
5 | |
6 ;; Author: Reto Zimmermann <reto@gnu.org> | |
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org> | |
8 ;; Version: 2.26 | |
9 ;; Keywords: languages vera | |
10 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html | |
11 | |
12 (defconst vera-version "2.18" | |
13 "Vera Mode version number.") | |
14 | |
15 (defconst vera-time-stamp "2007-06-11" | |
16 "Vera Mode time stamp for last update.") | |
17 | |
18 ;; This file is not part of GNU Emacs. | |
19 | |
20 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
21 ;; it under the terms of the GNU General Public License as published by | |
22 ;; the Free Software Foundation; either version 2, or (at your option) | |
23 ;; any later version. | |
24 | |
25 ;; GNU Emacs is distributed in the hope that it will be useful, | |
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28 ;; GNU General Public License for more details. | |
29 | |
30 ;; You should have received a copy of the GNU General Public License | |
31 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
32 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
33 ;; Boston, MA 02111-1307, USA. | |
34 | |
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
36 ;;; Commentary: | |
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
38 | |
39 ;; This package provides a simple Emacs major mode for editing Vera code. | |
40 ;; It includes the following features: | |
41 | |
42 ;; - Syntax highlighting | |
43 ;; - Indentation | |
44 ;; - Word/keyword completion | |
45 ;; - Block commenting | |
46 ;; - Works under GNU Emacs and XEmacs | |
47 | |
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
49 ;; Documentation | |
50 | |
51 ;; See comment string of function `vera-mode' or type `C-c C-h' in Emacs. | |
52 | |
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
54 ;; Installation | |
55 | |
56 ;; Prerequisites: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X | |
57 | |
58 ;; Put `vera-mode.el' into the `site-lisp' directory of your Emacs installation | |
59 ;; or into an arbitrary directory that is added to the load path by the | |
60 ;; following line in your Emacs start-up file (`.emacs'): | |
61 | |
62 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path)) | |
63 | |
64 ;; If you already have the compiled `vera-mode.elc' file, put it in the same | |
65 ;; directory. Otherwise, byte-compile the source file: | |
66 ;; Emacs: M-x byte-compile-file -> vera-mode.el | |
67 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vera-mode.el | |
68 | |
69 ;; Add the following lines to the `site-start.el' file in the `site-lisp' | |
70 ;; directory of your Emacs installation or to your Emacs start-up file | |
71 ;; (`.emacs'): | |
72 | |
73 ;; (autoload 'vera-mode "vera-mode" "Vera Mode" t) | |
74 ;; (setq auto-mode-alist (cons '("\\.vr[hi]?\\'" . vera-mode) auto-mode-alist)) | |
75 | |
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
77 | |
78 ;;; Code: | |
79 | |
80 ;; XEmacs handling | |
81 (defconst vera-xemacs (string-match "XEmacs" emacs-version) | |
82 "Non-nil if XEmacs is used.") | |
83 | |
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
85 ;;; Variables | |
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
87 | |
88 (defgroup vera nil | |
89 "Customizations for Vera Mode." | |
90 :prefix "vera-" | |
91 :version "22.2" | |
92 :group 'languages) | |
93 | |
94 (defcustom vera-basic-offset 2 | |
95 "*Amount of basic offset used for indentation." | |
96 :type 'integer | |
97 :group 'vera) | |
98 | |
99 (defcustom vera-underscore-is-part-of-word nil | |
100 "*Non-nil means consider the underscore character `_' as part of word. | |
101 An identifier containing underscores is then treated as a single word in | |
102 select and move operations. All parts of an identifier separated by underscore | |
103 are treated as single words otherwise." | |
104 :type 'boolean | |
105 :group 'vera) | |
106 | |
107 (defcustom vera-intelligent-tab t | |
108 "*Non-nil means `TAB' does indentation, word completion and tab insertion. | |
109 That is, if preceeding character is part of a word then complete word, | |
110 else if not at beginning of line then insert tab, | |
111 else if last command was a `TAB' or `RET' then dedent one step, | |
112 else indent current line. | |
113 If nil, TAB always indents current line." | |
114 :type 'boolean | |
115 :group 'vera) | |
116 | |
117 | |
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
119 ;;; Mode definitions | |
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
121 | |
122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
123 ;; Key bindings | |
124 | |
125 (defvar vera-mode-map () | |
126 "Keymap for Vera Mode.") | |
127 | |
128 (setq vera-mode-map (make-sparse-keymap)) | |
129 ;; backspace/delete key bindings | |
130 (define-key vera-mode-map [backspace] 'backward-delete-char-untabify) | |
131 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable | |
132 (define-key vera-mode-map [delete] 'delete-char) | |
133 (define-key vera-mode-map [(meta delete)] 'kill-word)) | |
134 ;; standard key bindings | |
135 (define-key vera-mode-map "\M-e" 'vera-forward-statement) | |
136 (define-key vera-mode-map "\M-a" 'vera-backward-statement) | |
137 (define-key vera-mode-map "\M-\C-e" 'vera-forward-same-indent) | |
138 (define-key vera-mode-map "\M-\C-a" 'vera-backward-same-indent) | |
139 ;; mode specific key bindings | |
140 (define-key vera-mode-map "\C-c\t" 'indent-according-to-mode) | |
141 (define-key vera-mode-map "\M-\C-\\" 'vera-indent-region) | |
142 (define-key vera-mode-map "\C-c\C-c" 'vera-comment-uncomment-region) | |
143 (define-key vera-mode-map "\C-c\C-f" 'vera-fontify-buffer) | |
144 (define-key vera-mode-map "\C-c\C-v" 'vera-version) | |
145 (define-key vera-mode-map "\M-\t" 'tab-to-tab-stop) | |
146 ;; electric key bindings | |
147 (define-key vera-mode-map "\t" 'vera-electric-tab) | |
148 (define-key vera-mode-map "\r" 'vera-electric-return) | |
149 (define-key vera-mode-map " " 'vera-electric-space) | |
150 (define-key vera-mode-map "{" 'vera-electric-opening-brace) | |
151 (define-key vera-mode-map "}" 'vera-electric-closing-brace) | |
152 (define-key vera-mode-map "#" 'vera-electric-pound) | |
153 (define-key vera-mode-map "*" 'vera-electric-star) | |
154 (define-key vera-mode-map "/" 'vera-electric-slash) | |
155 | |
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
157 ;; Menu | |
158 | |
159 (require 'easymenu) | |
160 | |
161 (easy-menu-define vera-mode-menu vera-mode-map | |
162 "Menu keymap for Vera Mode." | |
163 '("Vera" | |
164 ["(Un)Comment Out Region" vera-comment-uncomment-region (mark)] | |
165 "--" | |
166 ["Move Forward Statement" vera-forward-statement t] | |
167 ["Move Backward Statement" vera-backward-statement t] | |
168 ["Move Forward Same Indent" vera-forward-same-indent t] | |
169 ["Move Backward Same Indent" vera-backward-same-indent t] | |
170 "--" | |
171 ["Indent Line" indent-according-to-mode t] | |
172 ["Indent Region" vera-indent-region (mark)] | |
173 ["Indent Buffer" vera-indent-buffer t] | |
174 "--" | |
175 ["Fontify Buffer" vera-fontify-buffer t] | |
176 "--" | |
177 ["Documentation" describe-mode] | |
178 ["Version" vera-version t] | |
179 ["Bug Report..." vera-submit-bug-report t] | |
180 "--" | |
181 ("Options" | |
182 ["Indentation Offset..." (customize-option 'vera-basic-offset) t] | |
183 ["Underscore is Part of Word" | |
184 (customize-set-variable 'vera-underscore-is-part-of-word | |
185 (not vera-underscore-is-part-of-word)) | |
186 :style toggle :selected vera-underscore-is-part-of-word] | |
187 ["Use Intelligent Tab" | |
188 (customize-set-variable 'vera-intelligent-tab | |
189 (not vera-intelligent-tab)) | |
190 :style toggle :selected vera-intelligent-tab] | |
191 "--" | |
192 ["Save Options" customize-save-customized t] | |
193 "--" | |
194 ["Customize..." vera-customize t]))) | |
195 | |
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
197 ;; Syntax table | |
198 | |
199 (defvar vera-mode-syntax-table | |
200 (let ((syntax-table (make-syntax-table))) | |
201 ;; punctuation | |
202 (modify-syntax-entry ?\# "." syntax-table) | |
203 (modify-syntax-entry ?\$ "." syntax-table) | |
204 (modify-syntax-entry ?\% "." syntax-table) | |
205 (modify-syntax-entry ?\& "." syntax-table) | |
206 (modify-syntax-entry ?\' "." syntax-table) | |
207 (modify-syntax-entry ?\* "." syntax-table) | |
208 (modify-syntax-entry ?\- "." syntax-table) | |
209 (modify-syntax-entry ?\+ "." syntax-table) | |
210 (modify-syntax-entry ?\. "." syntax-table) | |
211 (modify-syntax-entry ?\/ "." syntax-table) | |
212 (modify-syntax-entry ?\: "." syntax-table) | |
213 (modify-syntax-entry ?\; "." syntax-table) | |
214 (modify-syntax-entry ?\< "." syntax-table) | |
215 (modify-syntax-entry ?\= "." syntax-table) | |
216 (modify-syntax-entry ?\> "." syntax-table) | |
217 (modify-syntax-entry ?\\ "." syntax-table) | |
218 (modify-syntax-entry ?\| "." syntax-table) | |
219 ;; string | |
220 (modify-syntax-entry ?\" "\"" syntax-table) | |
221 ;; underscore | |
222 (when vera-underscore-is-part-of-word | |
223 (modify-syntax-entry ?\_ "w" syntax-table)) | |
224 ;; escape | |
225 (modify-syntax-entry ?\\ "\\" syntax-table) | |
226 ;; parentheses to match | |
227 (modify-syntax-entry ?\( "()" syntax-table) | |
228 (modify-syntax-entry ?\) ")(" syntax-table) | |
229 (modify-syntax-entry ?\[ "(]" syntax-table) | |
230 (modify-syntax-entry ?\] ")[" syntax-table) | |
231 (modify-syntax-entry ?\{ "(}" syntax-table) | |
232 (modify-syntax-entry ?\} "){" syntax-table) | |
233 ;; comment | |
234 (if vera-xemacs | |
235 (modify-syntax-entry ?\/ ". 1456" syntax-table) ; XEmacs | |
236 (modify-syntax-entry ?\/ ". 124b" syntax-table)) ; Emacs | |
237 (modify-syntax-entry ?\* ". 23" syntax-table) | |
238 ;; newline and CR | |
239 (modify-syntax-entry ?\n "> b" syntax-table) | |
240 (modify-syntax-entry ?\^M "> b" syntax-table) | |
241 syntax-table) | |
242 "Syntax table used in `vera-mode' buffers.") | |
243 | |
244 (defvar vera-mode-ext-syntax-table | |
245 (let ((syntax-table (copy-syntax-table vera-mode-syntax-table))) | |
246 ;; extended syntax table including '_' (for simpler search regexps) | |
247 (modify-syntax-entry ?_ "w" syntax-table) | |
248 syntax-table) | |
249 "Syntax table extended by `_' used in `vera-mode' buffers.") | |
250 | |
251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
252 ;; Mode definition | |
253 | |
254 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.vr[hi]?\\'" . vera-mode)) | |
255 | |
256 ;;;###autoload | |
257 (defun vera-mode () | |
258 "Major mode for editing Vera code. | |
259 | |
260 Usage: | |
261 ------ | |
262 | |
263 INDENTATION: Typing `TAB' at the beginning of a line indents the line. | |
264 The amount of indentation is specified by option `vera-basic-offset'. | |
265 Indentation can be done for an entire region \(`M-C-\\') or buffer (menu). | |
266 `TAB' always indents the line if option `vera-intelligent-tab' is nil. | |
267 | |
268 WORD/COMMAND COMPLETION: Typing `TAB' after a (not completed) word looks | |
269 for a word in the buffer or a Vera keyword that starts alike, inserts it | |
270 and adjusts case. Re-typing `TAB' toggles through alternative word | |
271 completions. | |
272 | |
273 Typing `TAB' after a non-word character inserts a tabulator stop (if not | |
274 at the beginning of a line). `M-TAB' always inserts a tabulator stop. | |
275 | |
276 COMMENTS: `C-c C-c' comments out a region if not commented out, and | |
277 uncomments a region if already commented out. | |
278 | |
279 HIGHLIGHTING (fontification): Vera keywords, predefined types and | |
280 constants, function names, declaration names, directives, as well as | |
281 comments and strings are highlighted using different colors. | |
282 | |
283 VERA VERSION: OpenVera 1.4 and Vera version 6.2.8. | |
284 | |
285 | |
286 Maintenance: | |
287 ------------ | |
288 | |
289 To submit a bug report, use the corresponding menu entry within Vera Mode. | |
290 Add a description of the problem and include a reproducible test case. | |
291 | |
292 Feel free to send questions and enhancement requests to <reto@gnu.org>. | |
293 | |
294 Official distribution is at | |
295 <http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html>. | |
296 | |
297 | |
298 The Vera Mode Maintainer | |
299 Reto Zimmermann <reto@gnu.org> | |
300 | |
301 Key bindings: | |
302 ------------- | |
303 | |
304 \\{vera-mode-map}" | |
305 (interactive) | |
306 (kill-all-local-variables) | |
307 (setq major-mode 'vera-mode) | |
308 (setq mode-name "Vera") | |
309 ;; set maps and tables | |
310 (use-local-map vera-mode-map) | |
311 (set-syntax-table vera-mode-syntax-table) | |
312 ;; set local variables | |
313 (require 'cc-cmds) | |
314 (set (make-local-variable 'comment-start) "//") | |
315 (set (make-local-variable 'comment-end) "") | |
316 (set (make-local-variable 'comment-column) 40) | |
317 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *") | |
318 (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *//+") | |
319 (set (make-local-variable 'comment-indent-function) 'c-comment-indent) | |
320 (set (make-local-variable 'paragraph-start) "^$") | |
321 (set (make-local-variable 'paragraph-separate) paragraph-start) | |
322 (set (make-local-variable 'require-final-newline) t) | |
323 (set (make-local-variable 'indent-tabs-mode) nil) | |
324 (set (make-local-variable 'indent-line-function) 'vera-indent-line) | |
325 (set (make-local-variable 'parse-sexp-ignore-comments) t) | |
326 ;; initialize font locking | |
327 (set (make-local-variable 'font-lock-defaults) | |
328 '(vera-font-lock-keywords nil nil ((?\_ . "w")))) | |
329 ;; add menu (XEmacs) | |
330 (easy-menu-add vera-mode-menu) | |
331 ;; miscellaneous | |
332 (message "Vera Mode %s. Type C-c C-h for documentation." vera-version) | |
333 ;; run hooks | |
334 (run-hooks 'vera-mode-hook)) | |
335 | |
336 | |
337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
338 ;;; Vera definitions | |
339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
340 | |
341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
342 ;;; Keywords | |
343 | |
344 (defconst vera-keywords | |
345 '( | |
346 "after" "all" "any" "around" "assoc_index" "assoc_size" "async" | |
347 "bad_state" "bad_trans" "before" "begin" "big_endian" "bind" | |
348 "bin_activation" "bit_normal" "bit_reverse" "break" "breakpoint" | |
349 "case" "casex" "casez" "class" "constraint" "continue" | |
350 "coverage" "coverage_block" "coverage_def" "coverage_depth" | |
351 "coverage_goal" "coverage_group" "coverage_option" "coverage_val" | |
352 "cross_num_print_missing" "cross_auto_bin_max" "cov_comment" | |
353 "default" "depth" "dist" "do" | |
354 "else" "end" "enum" "exhaustive" "export" "extends" "extern" | |
355 "for" "foreach" "fork" "function" | |
356 "hdl_task" "hdl_node" "hide" | |
357 "if" "illegal_self_transition" "illegal_state" "illegal_transition" | |
358 "in" "interface" "invisible" | |
359 "join" | |
360 "little_endian" "local" | |
361 "m_bad_state" "m_bad_trans" "m_state" "m_trans" | |
362 "negedge" "new" "newcov" "non_rand" "none" "not" "null" | |
363 "or" "ordered" | |
364 "packed" "port" "posedge" "proceed" "prod" "prodget" "prodset" | |
365 "program" "protected" "public" | |
366 "rand" "randc" "randcase" "randseq" "repeat" "return" "rules" | |
367 "sample" "sample_event" "shadow" "soft" "state" "static" "super" | |
368 "task" "terminate" "this" "trans" "typedef" | |
369 "unpacked" | |
370 "var" "vca" "vector" "verilog_node" "verilog_task" | |
371 "vhdl_node" "vhdl_task" "virtual" "virtuals" "visible" "void" | |
372 "while" "wildcard" "with" | |
373 ) | |
374 "List of Vera keywords.") | |
375 | |
376 (defconst vera-types | |
377 '( | |
378 "integer" "bit" "reg" "string" "bind_var" "event" | |
379 "inout" "input" "output" | |
380 "ASYNC" "CLOCK" | |
381 "NDRIVE" "NHOLD" "NRX" "NRZ" "NR0" "NR1" "NSAMPLE" | |
382 "PDRIVE" "PHOLD" "PRX" "PRZ" "PR0" "PR1" "PSAMPLE" | |
383 ) | |
384 "List of Vera predefined types.") | |
385 | |
386 (defconst vera-q-values | |
387 '( | |
388 "gnr" "grx" "grz" "gr0" "gr1" | |
389 "nr" "rx" "rz" "r0" "r1" | |
390 "snr" "srx" "srz" "sr0" "sr1" | |
391 ) | |
392 "List of Vera predefined VCA q_values.") | |
393 | |
394 (defconst vera-functions | |
395 '( | |
396 ;; system functions and tasks | |
397 "alloc" | |
398 "call_func" "call_task" "cast_assign" "close_conn" "cm_coverage" | |
399 "cm_get_coverage" "cm_get_limit" | |
400 "coverage_backup_database_file" "coverage_save_database" | |
401 "delay" | |
402 "error" "error_mode" "error_wait" "exit" | |
403 "fclose" "feof" "ferror" "fflush" "flag" "fopen" "fprintf" "freadb" | |
404 "freadb" "freadh" "freadstr" | |
405 "get_bind" "get_bind_id" "get_conn_err" "get_cycle" "get_env" | |
406 "get_memsize" "get_plus_arg" "get_systime" "get_time" "get_time_unit" | |
407 "getstate" | |
408 "initstate" | |
409 "lock_file" | |
410 "mailbox_get" "mailbox_put" "mailbox_receive" "mailbox_send" | |
411 "make_client" "make_server" | |
412 "os_command" | |
413 "printf" "psprintf" | |
414 "query" "query_str" "query_x" | |
415 "rand48" "random" "region_enter" "region_exit" "rewind" | |
416 "semaphore_get" "semaphore_put" "setstate" "signal_connect" "simwave_plot" | |
417 "srandom" "sprintf" "sscanf" "stop" "suspend_thread" "sync" | |
418 "timeout" "trace" "trigger" | |
419 "unit_delay" "unlock_file" "up_connections" | |
420 "urand48" "urandom" "urandom_range" | |
421 "vera_bit_reverse" "vera_crc" "vera_pack" "vera_pack_big_endian" | |
422 "vera_plot" "vera_report_profile" "vera_unpack" "vera_unpack_big_endian" | |
423 "vsv_call_func" "vsv_call_task" "vsv_close_conn" "vsv_get_conn_err" | |
424 "vsv_make_client" "vsv_make_server" "vsv_up_connections" | |
425 "vsv_wait_for_done" "vsv_wait_for_input" | |
426 "wait_child" "wait_var" | |
427 ;; class methods | |
428 "Configure" "DisableTrigger" "DoAction" "EnableCount" "EnableTrigger" | |
429 "Event" "GetAssert" "GetCount" "GetFirstAssert" "GetName" "GetNextAssert" | |
430 "Wait" | |
431 "atobin" "atohex" "atoi" "atooct" | |
432 "backref" "bittostr" "capacity" "compare" "constraint_mode" | |
433 "delete" | |
434 "empty" | |
435 "find" "find_index" "first" "first_index" | |
436 "get_at_least" "get_auto_bin" "get_cov_weight" "get_coverage_goal" | |
437 "get_cross_bin_max" "get_status" "get_status_msg" "getc" | |
438 "hash" | |
439 "icompare" "insert" "inst_get_at_least" "inst_get_auto_bin_max" | |
440 "inst_get_collect" "inst_get_cov_weight" "inst_get_coverage_goal" | |
441 "inst_getcross_bin_max" "inst_query" "inst_set_at_least" | |
442 "inst_set_auto_bin_max" "inst_set_bin_activiation" "inst_set_collect" | |
443 "inst_set_cov_weight" "inst_set_coverage_goal" "inst_set_cross_bin_max" | |
444 "itoa" | |
445 "last" "last_index" "len" "load" | |
446 "match" "max" "max_index" "min" "min_index" | |
447 "object_compare" "object_copy" "object_print" | |
448 "pack" "pick_index" "pop_back" "pop_front" "post_pack" "post_randomize" | |
449 "post_unpack" "postmatch" "pre_pack" "pre_randomize" "prematch" "push_back" | |
450 "push_front" "putc" | |
451 "query" "query_str" | |
452 "rand_mode" "randomize" "reserve" "reverse" "rsort" | |
453 "search" "set_at_least" "set_auto_bin_max" "set_bin_activiation" | |
454 "set_cov_weight" "set_coverage_goal" "set_cross_bin_max" "set_name" "size" | |
455 "sort" "substr" "sum" | |
456 "thismatch" "tolower" "toupper" | |
457 "unique_index" "unpack" | |
458 ;; empty methods | |
459 "new" "object_compare" | |
460 "post_boundary" "post_pack" "post_randomize" "post_unpack" "pre-randomize" | |
461 "pre_boundary" "pre_pack" "pre_unpack" | |
462 ) | |
463 "List of Vera predefined system functions, tasks and class methods.") | |
464 | |
465 (defconst vera-constants | |
466 '( | |
467 "ALL" "ANY" | |
468 "BAD_STATE" "BAD_TRANS" | |
469 "CALL" "CHECK" "CHGEDGE" "CLEAR" "COPY_NO_WAIT" "COPY_WAIT" | |
470 "CROSS" "CROSS_TRANS" | |
471 "DEBUG" "DELETE" | |
472 "EC_ARRAYX" "EC_CODE_END" "EC_CONFLICT" "EC_EVNTIMOUT" "EC_EXPECT" | |
473 "EC_FULLEXPECT" "EC_MBXTMOUT" "EC_NEXPECT" "EC_RETURN" "EC_RGNTMOUT" | |
474 "EC_SCONFLICT" "EC_SEMTMOUT" "EC_SEXPECT" "EC_SFULLEXPECT" "EC_SNEXTPECT" | |
475 "EC_USERSET" "EQ" "EVENT" | |
476 "FAIL" "FIRST" "FORK" | |
477 "GE" "GOAL" "GT" "HAND_SHAKE" "HI" "HIGH" "HNUM" | |
478 "LE" "LIC_EXIT" "LIC_PRERR" "LIC_PRWARN" "LIC_WAIT" "LO" "LOAD" "LOW" "LT" | |
479 "MAILBOX" "MAX_COM" | |
480 "NAME" "NE" "NEGEDGE" "NEXT" "NO_OVERLAP" "NO_OVERLAP_STATE" | |
481 "NO_OVERLAP_TRANS" "NO_VARS" "NO_WAIT" "NUM" "NUM_BIN" "NUM_DET" | |
482 "OFF" "OK" "OK_LAST" "ON" "ONE_BLAST" "ONE_SHOT" "ORDER" | |
483 "PAST_IT" "PERCENT" "POSEDGE" "PROGRAM" | |
484 "RAWIN" "REGION" "REPORT" | |
485 "SAMPLE" "SAVE" "SEMAPHORE" "SET" "SILENT" "STATE" "STR" | |
486 "STR_ERR_OUT_OF_RANGE" "STR_ERR_REGEXP_SYNTAX" "SUM" | |
487 "TRANS" | |
488 "VERBOSE" | |
489 "WAIT" | |
490 "stderr" "stdin" "stdout" | |
491 ) | |
492 "List of Vera predefined constants.") | |
493 | |
494 (defconst vera-rvm-types | |
495 '( | |
496 "VeraListIterator_VeraListIterator_rvm_log" | |
497 "VeraListIterator_rvm_data" "VeraListIterator_rvm_log" | |
498 "VeraListNodeVeraListIterator_rvm_log" "VeraListNodervm_data" | |
499 "VeraListNodervm_log" "VeraList_VeraListIterator_rvm_log" | |
500 "VeraList_rvm_data" "VeraList_rvm_log" | |
501 "rvm_broadcast" "rvm_channel_class" "rvm_data" "rvm_data" "rvm_env" | |
502 "rvm_log" "rvm_log_modifier" "rvm_log_msg" "rvm_log_msg" "rvm_log_msg_info" | |
503 "rvm_log_watchpoint" "rvm_notify" "rvm_notify_event" | |
504 "rvm_notify_event_config" "rvm_scheduler" "rvm_scheduler_election" | |
505 "rvm_watchdog" "rvm_watchdog_port" "rvm_xactor" "rvm_xactor_callbacks" | |
506 ) | |
507 "List of Vera-RVM keywords.") | |
508 | |
509 (defconst vera-rvm-functions | |
510 '( | |
511 "extern_rvm_atomic_gen" "extern_rvm_channel" "extern_rvm_scenario_gen" | |
512 "rvm_OO_callback" "rvm_atomic_gen" "rvm_atomic_gen_callbacks_decl" | |
513 "rvm_atomic_gen_decl" "rvm_atomic_scenario_decl" "rvm_channel" | |
514 "rvm_channel_" "rvm_channel_decl" "rvm_command" "rvm_cycle" "rvm_debug" | |
515 "rvm_error" "rvm_fatal" "rvm_note" "rvm_protocol" "rvm_report" | |
516 "rvm_scenario_decl" "rvm_scenario_election_decl" "rvm_scenario_gen" | |
517 "rvm_scenario_gen_callbacks_decl" "rvm_scenario_gen_decl" | |
518 "rvm_trace" "rvm_transaction" "rvm_user" "rvm_verbose" "rvm_warning" | |
519 ) | |
520 "List of Vera-RVM functions.") | |
521 | |
522 (defconst vera-rvm-constants | |
523 '( | |
524 "RVM_NUMERIC_VERSION_MACROS" "RVM_VERSION" "RVM_MINOR" "RVM_PATCH" | |
525 "rvm_channel__SOURCE" "rvm_channel__SINK" "rvm_channel__NO_ACTIVE" | |
526 "rvm_channel__ACT_PENDING" "rvm_channel__ACT_STARTED" | |
527 "rvm_channel__ACT_COMPLETED" "rvm_channel__FULL" "rvm_channel__EMPTY" | |
528 "rvm_channel__PUT" "rvm_channel__GOT" "rvm_channel__PEEKED" | |
529 "rvm_channel__ACTIVATED" "rvm_channel__STARTED" "rvm_channel__COMPLETED" | |
530 "rvm_channel__REMOVED" "rvm_channel__LOCKED" "rvm_channel__UNLOCKED" | |
531 "rvm_data__EXECUTE" "rvm_data__STARTED" "rvm_data__ENDED" | |
532 "rvm_env__CFG_GENED" "rvm_env__BUILT" "rvm_env__DUT_CFGED" | |
533 "rvm_env__STARTED" "rvm_env__RESTARTED" "rvm_env__ENDED" "rvm_env__STOPPED" | |
534 "rvm_env__CLEANED" "rvm_env__DONE" "rvm_log__DEFAULT" "rvm_log__UNCHANGED" | |
535 "rvm_log__FAILURE_TYP" "rvm_log__NOTE_TYP" "rvm_log__DEBUG_TYP" | |
536 "rvm_log__REPORT_TYP" "rvm_log__NOTIFY_TYP" "rvm_log__TIMING_TYP" | |
537 "rvm_log__XHANDLING_TYP" "rvm_log__PROTOCOL_TYP" "rvm_log__TRANSACTION_TYP" | |
538 "rvm_log__COMMAND_TYP" "rvm_log__CYCLE_TYP" "rvm_log__USER_TYP_0" | |
539 "rvm_log__USER_TYP_1" "rvm_log__USER_TYP_2" "rvm_log__USER_TYP_3" | |
540 "rvm_log__DEFAULT_TYP" "rvm_log__ALL_TYPES" "rvm_log__FATAL_SEV" | |
541 "rvm_log__ERROR_SEV" "rvm_log__WARNING_SEV" "rvm_log__NORMAL_SEV" | |
542 "rvm_log__TRACE_SEV" "rvm_log__DEBUG_SEV" "rvm_log__VERBOSE_SEV" | |
543 "rvm_log__HIDDEN_SEV" "rvm_log__IGNORE_SEV" "rvm_log__DEFAULT_SEV" | |
544 "rvm_log__ALL_SEVERITIES" "rvm_log__CONTINUE" "rvm_log__COUNT_AS_ERROR" | |
545 "rvm_log__DEBUGGER" "rvm_log__DUMP" "rvm_log__STOP" "rvm_log__ABORT" | |
546 "rvm_notify__ONE_SHOT_TRIGGER" "rvm_notify__ONE_BLAST_TRIGGER" | |
547 "rvm_notify__HAND_SHAKE_TRIGGER" "rvm_notify__ON_OFF_TRIGGER" | |
548 "rvm_xactor__XACTOR_IDLE" "rvm_xactor__XACTOR_BUSY" | |
549 "rvm_xactor__XACTOR_STARTED" "rvm_xactor__XACTOR_STOPPED" | |
550 "rvm_xactor__XACTOR_RESET" "rvm_xactor__XACTOR_SOFT_RST" | |
551 "rvm_xactor__XACTOR_FIRM_RST" "rvm_xactor__XACTOR_HARD_RST" | |
552 "rvm_xactor__XACTOR_PROTOCOL_RST" "rvm_broadcast__AFAP" | |
553 "rvm_broadcast__ALAP" "rvm_watchdog__TIMEOUT" | |
554 "rvm_env__DUT_RESET" "rvm_log__INTERNAL_TYP" | |
555 "RVM_SCHEDULER_IS_XACTOR" "RVM_BROADCAST_IS_XACTOR" | |
556 ) | |
557 "List of Vera-RVM predefined constants.") | |
558 | |
559 ;; `regexp-opt' undefined (`xemacs-devel' not installed) | |
560 (unless (fboundp 'regexp-opt) | |
561 (defun regexp-opt (strings &optional paren) | |
562 (let ((open (if paren "\\(" "")) (close (if paren "\\)" ""))) | |
563 (concat open (mapconcat 'regexp-quote strings "\\|") close)))) | |
564 | |
565 (defconst vera-keywords-regexp | |
566 (concat "\\<\\(" (regexp-opt vera-keywords) "\\)\\>") | |
567 "Regexp for Vera keywords.") | |
568 | |
569 (defconst vera-types-regexp | |
570 (concat "\\<\\(" (regexp-opt vera-types) "\\)\\>") | |
571 "Regexp for Vera predefined types.") | |
572 | |
573 (defconst vera-q-values-regexp | |
574 (concat "\\<\\(" (regexp-opt vera-q-values) "\\)\\>") | |
575 "Regexp for Vera predefined VCA q_values.") | |
576 | |
577 (defconst vera-functions-regexp | |
578 (concat "\\<\\(" (regexp-opt vera-functions) "\\)\\>") | |
579 "Regexp for Vera predefined system functions, tasks and class methods.") | |
580 | |
581 (defconst vera-constants-regexp | |
582 (concat "\\<\\(" (regexp-opt vera-constants) "\\)\\>") | |
583 "Regexp for Vera predefined constants.") | |
584 | |
585 (defconst vera-rvm-types-regexp | |
586 (concat "\\<\\(" (regexp-opt vera-rvm-types) "\\)\\>") | |
587 "Regexp for Vera-RVM keywords.") | |
588 | |
589 (defconst vera-rvm-functions-regexp | |
590 (concat "\\<\\(" (regexp-opt vera-rvm-functions) "\\)\\>") | |
591 "Regexp for Vera-RVM predefined system functions, tasks and class methods.") | |
592 | |
593 (defconst vera-rvm-constants-regexp | |
594 (concat "\\<\\(" (regexp-opt vera-rvm-constants) "\\)\\>") | |
595 "Regexp for Vera-RVM predefined constants.") | |
596 | |
597 | |
598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
599 ;;; Font locking | |
600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
601 | |
602 ;; XEmacs compatibility | |
603 (when vera-xemacs | |
604 (require 'font-lock) | |
605 (copy-face 'font-lock-reference-face 'font-lock-constant-face) | |
606 (copy-face 'font-lock-preprocessor-face 'font-lock-builtin-face)) | |
607 | |
608 (defun vera-font-lock-match-item (limit) | |
609 "Match, and move over, any declaration item after point. Adapted from | |
610 `font-lock-match-c-style-declaration-item-and-skip-to-next'." | |
611 (condition-case nil | |
612 (save-restriction | |
613 (narrow-to-region (point-min) limit) | |
614 ;; match item | |
615 (when (looking-at "\\s-*\\(\\w+\\)") | |
616 (save-match-data | |
617 (goto-char (match-end 1)) | |
618 ;; move to next item | |
619 (if (looking-at "\\(\\s-*\\(\\[[^]]*\\]\\s-*\\)?,\\)") | |
620 (goto-char (match-end 1)) | |
621 (end-of-line) t)))) | |
622 (error t))) | |
623 | |
624 (defvar vera-font-lock-keywords | |
625 (list | |
626 ;; highlight keywords | |
627 (list vera-keywords-regexp 1 'font-lock-keyword-face) | |
628 ;; highlight types | |
629 (list vera-types-regexp 1 'font-lock-type-face) | |
630 ;; highlight RVM types | |
631 (list vera-rvm-types-regexp 1 'font-lock-type-face) | |
632 ;; highlight constants | |
633 (list vera-constants-regexp 1 'font-lock-constant-face) | |
634 ;; highlight RVM constants | |
635 (list vera-rvm-constants-regexp 1 'font-lock-constant-face) | |
636 ;; highlight q_values | |
637 (list vera-q-values-regexp 1 'font-lock-constant-face) | |
638 ;; highlight predefined functions, tasks and methods | |
639 (list vera-functions-regexp 1 'vera-font-lock-function) | |
640 ;; highlight predefined RVM functions | |
641 (list vera-rvm-functions-regexp 1 'vera-font-lock-function) | |
642 ;; highlight functions | |
643 '("\\<\\(\\w+\\)\\s-*(" 1 font-lock-function-name-face) | |
644 ;; highlight various declaration names | |
645 '("^\\s-*\\(port\\|program\\|task\\)\\s-+\\(\\w+\\)\\>" | |
646 2 font-lock-function-name-face) | |
647 '("^\\s-*bind\\s-+\\(\\w+\\)\\s-+\\(\\w+\\)\\>" | |
648 (1 font-lock-function-name-face) (2 font-lock-function-name-face)) | |
649 ;; highlight interface declaration names | |
650 '("^\\s-*\\(class\\|interface\\)\\s-+\\(\\w+\\)\\>" | |
651 2 vera-font-lock-interface) | |
652 ;; highlight variable name definitions | |
653 (list (concat "^\\s-*" vera-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?") | |
654 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face))) | |
655 (list (concat "^\\s-*" vera-rvm-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?") | |
656 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face))) | |
657 ;; highlight numbers | |
658 '("\\([0-9]*'[bdoh][0-9a-fA-FxXzZ_]+\\)" 1 vera-font-lock-number) | |
659 ;; highlight filenames in #include directives | |
660 '("^#\\s-*include\\s-*\\(<[^>\"\n]*>?\\)" | |
661 1 font-lock-string-face) | |
662 ;; highlight directives and directive names | |
663 '("^#\\s-*\\(\\w+\\)\\>[ \t!]*\\(\\w+\\)?" | |
664 (1 font-lock-builtin-face) (2 font-lock-variable-name-face nil t)) | |
665 ;; highlight `@', `$' and `#' | |
666 '("\\([@$#]\\)" 1 font-lock-keyword-face) | |
667 ;; highlight @ and # definitions | |
668 '("@\\s-*\\(\\w*\\)\\(\\s-*,\\s-*\\(\\w+\\)\\)?\\>[^.]" | |
669 (1 vera-font-lock-number) (3 vera-font-lock-number nil t)) | |
670 ;; highlight interface signal name | |
671 '("\\(\\w+\\)\\.\\w+" 1 vera-font-lock-interface) | |
672 ) | |
673 "Regular expressions to highlight in Vera Mode.") | |
674 | |
675 (defvar vera-font-lock-number 'vera-font-lock-number | |
676 "Face name to use for @ definitions.") | |
677 | |
678 (defvar vera-font-lock-function 'vera-font-lock-function | |
679 "Face name to use for predefined functions and tasks.") | |
680 | |
681 (defvar vera-font-lock-interface 'vera-font-lock-interface | |
682 "Face name to use for interface names.") | |
683 | |
684 (defface vera-font-lock-number | |
685 '((((class color) (background light)) (:foreground "Gold4")) | |
686 (((class color) (background dark)) (:foreground "BurlyWood1")) | |
687 (t (:italic t :bold t))) | |
688 "Font lock mode face used to highlight @ definitions." | |
689 :group 'font-lock-highlighting-faces) | |
690 (put 'vera-font-lock-number-face 'face-alias 'vera-font-lock-number) | |
691 | |
692 (defface vera-font-lock-function | |
693 '((((class color) (background light)) (:foreground "DarkCyan")) | |
694 (((class color) (background dark)) (:foreground "Orchid1")) | |
695 (t (:italic t :bold t))) | |
696 "Font lock mode face used to highlight predefined functions and tasks." | |
697 :group 'font-lock-highlighting-faces) | |
698 (put 'vera-font-lock-function-face 'face-alias 'vera-font-lock-function) | |
699 | |
700 (defface vera-font-lock-interface | |
701 '((((class color) (background light)) (:foreground "Grey40")) | |
702 (((class color) (background dark)) (:foreground "Grey80")) | |
703 (t (:italic t :bold t))) | |
704 "Font lock mode face used to highlight interface names." | |
705 :group 'font-lock-highlighting-faces) | |
706 (put 'vera-font-lock-interface-face 'face-alias 'vera-font-lock-interface) | |
707 | |
708 (defun vera-fontify-buffer () | |
709 "Fontify buffer." | |
710 (interactive) | |
711 (font-lock-fontify-buffer)) | |
712 | |
713 | |
714 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
715 ;;; Indentation | |
716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
717 | |
718 (defvar vera-echo-syntactic-information-p nil | |
719 "If non-nil, syntactic info is echoed when the line is indented.") | |
720 | |
721 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
722 ;; offset functions | |
723 | |
724 (defconst vera-offsets-alist | |
725 '((comment . vera-lineup-C-comments) | |
726 (comment-intro . vera-lineup-comment) | |
727 (string . -1000) | |
728 (directive . -1000) | |
729 (block-open . 0) | |
730 (block-intro . +) | |
731 (block-close . 0) | |
732 (arglist-intro . +) | |
733 (arglist-cont . +) | |
734 (arglist-cont-nonempty . 0) | |
735 (arglist-close . 0) | |
736 (statement . 0) | |
737 (statement-cont . +) | |
738 (substatement . +) | |
739 (else-clause . 0)) | |
740 "Association list of syntactic element symbols and indentation offsets. | |
741 Adapted from `c-offsets-alist'.") | |
742 | |
743 (defun vera-evaluate-offset (offset langelem symbol) | |
744 "OFFSET can be a number, a function, a variable, a list, or one of | |
745 the symbols + or -." | |
746 (cond | |
747 ((eq offset '+) (setq offset vera-basic-offset)) | |
748 ((eq offset '-) (setq offset (- vera-basic-offset))) | |
749 ((eq offset '++) (setq offset (* 2 vera-basic-offset))) | |
750 ((eq offset '--) (setq offset (* 2 (- vera-basic-offset)))) | |
751 ((eq offset '*) (setq offset (/ vera-basic-offset 2))) | |
752 ((eq offset '/) (setq offset (/ (- vera-basic-offset) 2))) | |
753 ((functionp offset) (setq offset (funcall offset langelem))) | |
754 ((listp offset) | |
755 (setq offset | |
756 (let (done) | |
757 (while (and (not done) offset) | |
758 (setq done (vera-evaluate-offset (car offset) langelem symbol) | |
759 offset (cdr offset))) | |
760 (if (not done) | |
761 0 | |
762 done)))) | |
763 ((not (numberp offset)) (setq offset (symbol-value offset)))) | |
764 offset) | |
765 | |
766 (defun vera-get-offset (langelem) | |
767 "Get offset from LANGELEM which is a cons cell of the form: | |
768 \(SYMBOL . RELPOS). The symbol is matched against | |
769 vera-offsets-alist and the offset found there is either returned, | |
770 or added to the indentation at RELPOS. If RELPOS is nil, then | |
771 the offset is simply returned." | |
772 (let* ((symbol (car langelem)) | |
773 (relpos (cdr langelem)) | |
774 (match (assq symbol vera-offsets-alist)) | |
775 (offset (cdr-safe match))) | |
776 (if (not match) | |
777 (setq offset 0 | |
778 relpos 0) | |
779 (setq offset (vera-evaluate-offset offset langelem symbol))) | |
780 (+ (if (and relpos | |
781 (< relpos (save-excursion (beginning-of-line) (point)))) | |
782 (save-excursion | |
783 (goto-char relpos) | |
784 (current-column)) | |
785 0) | |
786 (vera-evaluate-offset offset langelem symbol)))) | |
787 | |
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
789 ;; help functions | |
790 | |
791 (defsubst vera-point (position) | |
792 "Returns the value of point at certain commonly referenced POSITIONs. | |
793 POSITION can be one of the following symbols: | |
794 bol -- beginning of line | |
795 eol -- end of line | |
796 boi -- back to indentation | |
797 ionl -- indentation of next line | |
798 iopl -- indentation of previous line | |
799 bonl -- beginning of next line | |
800 bopl -- beginning of previous line | |
801 This function does not modify point or mark." | |
802 (save-excursion | |
803 (cond | |
804 ((eq position 'bol) (beginning-of-line)) | |
805 ((eq position 'eol) (end-of-line)) | |
806 ((eq position 'boi) (back-to-indentation)) | |
807 ((eq position 'bonl) (forward-line 1)) | |
808 ((eq position 'bopl) (forward-line -1)) | |
809 ((eq position 'iopl) (forward-line -1) (back-to-indentation)) | |
810 ((eq position 'ionl) (forward-line 1) (back-to-indentation)) | |
811 (t (error "Unknown buffer position requested: %s" position))) | |
812 (point))) | |
813 | |
814 (defun vera-in-literal (&optional lim) | |
815 "Determine if point is in a Vera literal." | |
816 (save-excursion | |
817 (let ((state (parse-partial-sexp (or lim (point-min)) (point)))) | |
818 (cond | |
819 ((nth 3 state) 'string) | |
820 ((nth 4 state) 'comment) | |
821 (t nil))))) | |
822 | |
823 (defun vera-in-comment-p () | |
824 "Determine if point is in a Vera comment." | |
825 (save-excursion | |
826 (re-search-backward "\\(/\\*\\)\\|\\(\\*/\\)" nil t) | |
827 (match-string 1))) | |
828 | |
829 (defun vera-skip-forward-literal () | |
830 "Skip forward literal and return t if within one." | |
831 (let ((state (save-excursion (parse-partial-sexp (point-min) (point))))) | |
832 (cond | |
833 ((nth 3 state) (search-forward "\"") t) ; inside string | |
834 ((nth 7 state) (forward-line 1) t) ; inside // comment | |
835 ((nth 4 state) (search-forward "*/") t) ; inside /* */ comment | |
836 (t nil)))) | |
837 | |
838 (defun vera-skip-backward-literal () | |
839 "Skip backward literal and return t if within one." | |
840 (let ((state (save-excursion (parse-partial-sexp (point-min) (point))))) | |
841 (cond | |
842 ((nth 3 state) (search-backward "\"") t) ; inside string | |
843 ((nth 7 state) (search-backward "//") t) ; inside // comment | |
844 ((nth 4 state) (search-backward "/*") t) ; inside /* */ comment | |
845 (t nil)))) | |
846 | |
847 (defsubst vera-re-search-forward (regexp &optional bound noerror) | |
848 "Like `re-search-forward', but skips over matches in literals." | |
849 (store-match-data '(nil nil)) | |
850 (while (and (re-search-forward regexp bound noerror) | |
851 (vera-skip-forward-literal) | |
852 (progn (store-match-data '(nil nil)) | |
853 (if bound (< (point) bound) t)))) | |
854 (match-end 0)) | |
855 | |
856 (defsubst vera-re-search-backward (regexp &optional bound noerror) | |
857 "Like `re-search-backward', but skips over matches in literals." | |
858 (store-match-data '(nil nil)) | |
859 (while (and (re-search-backward regexp bound noerror) | |
860 (vera-skip-backward-literal) | |
861 (progn (store-match-data '(nil nil)) | |
862 (if bound (> (point) bound) t)))) | |
863 (match-end 0)) | |
864 | |
865 (defun vera-forward-syntactic-ws (&optional lim skip-directive) | |
866 "Forward skip of syntactic whitespace." | |
867 (save-restriction | |
868 (let* ((lim (or lim (point-max))) | |
869 (here lim) | |
870 (hugenum (point-max))) | |
871 (narrow-to-region lim (point)) | |
872 (while (/= here (point)) | |
873 (setq here (point)) | |
874 (forward-comment hugenum) | |
875 (when (and skip-directive (looking-at "^\\s-*#")) | |
876 (end-of-line)))))) | |
877 | |
878 (defun vera-backward-syntactic-ws (&optional lim skip-directive) | |
879 "Backward skip over syntactic whitespace." | |
880 (save-restriction | |
881 (let* ((lim (or lim (point-min))) | |
882 (here lim) | |
883 (hugenum (- (point-max)))) | |
884 (when (< lim (point)) | |
885 (narrow-to-region lim (point)) | |
886 (while (/= here (point)) | |
887 (setq here (point)) | |
888 (forward-comment hugenum) | |
889 (when (and skip-directive | |
890 (save-excursion (back-to-indentation) | |
891 (= (following-char) ?\#))) | |
892 (beginning-of-line))))))) | |
893 | |
894 (defmacro vera-prepare-search (&rest body) | |
895 "Switch to syntax table that includes '_', then execute BODY, and finally | |
896 restore the old environment. Used for consistent searching." | |
897 `(let ((current-syntax-table (syntax-table)) | |
898 result | |
899 (restore-prog ; program to restore enviroment | |
900 '(progn | |
901 ;; restore syntax table | |
902 (set-syntax-table current-syntax-table)))) | |
903 ;; use extended syntax table | |
904 (set-syntax-table vera-mode-ext-syntax-table) | |
905 ;; execute BODY safely | |
906 (setq result | |
907 (condition-case info | |
908 (progn ,@body) | |
909 (error (eval restore-prog) ; restore environment on error | |
910 (error (cadr info))))) ; pass error up | |
911 ;; restore environment | |
912 (eval restore-prog) | |
913 result)) | |
914 | |
915 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
916 ;; comment indentation functions | |
917 | |
918 (defsubst vera-langelem-col (langelem &optional preserve-point) | |
919 "Convenience routine to return the column of LANGELEM's relpos. | |
920 Leaves point at the relpos unless PRESERVE-POINT is non-nil." | |
921 (let ((here (point))) | |
922 (goto-char (cdr langelem)) | |
923 (prog1 (current-column) | |
924 (if preserve-point | |
925 (goto-char here))))) | |
926 | |
927 (defun vera-lineup-C-comments (langelem) | |
928 "Line up C block comment continuation lines. | |
929 Nicked from `c-lineup-C-comments'." | |
930 (save-excursion | |
931 (let ((here (point)) | |
932 (stars (progn (back-to-indentation) | |
933 (skip-chars-forward "*"))) | |
934 (langelem-col (vera-langelem-col langelem))) | |
935 (back-to-indentation) | |
936 (if (not (re-search-forward "/\\([*]+\\)" (vera-point 'eol) t)) | |
937 (progn | |
938 (if (not (looking-at "[*]+")) | |
939 (progn | |
940 ;; we now have to figure out where this comment begins. | |
941 (goto-char here) | |
942 (back-to-indentation) | |
943 (if (looking-at "[*]+/") | |
944 (progn (goto-char (match-end 0)) | |
945 (forward-comment -1)) | |
946 (goto-char (cdr langelem)) | |
947 (back-to-indentation)))) | |
948 (- (current-column) langelem-col)) | |
949 (if (zerop stars) | |
950 (progn | |
951 (skip-chars-forward " \t") | |
952 (- (current-column) langelem-col)) | |
953 ;; how many stars on comment opening line? if greater than | |
954 ;; on current line, align left. if less than or equal, | |
955 ;; align right. this should also pick up Javadoc style | |
956 ;; comments. | |
957 (if (> (length (match-string 1)) stars) | |
958 (progn | |
959 (back-to-indentation) | |
960 (- (current-column) -1 langelem-col)) | |
961 (- (current-column) stars langelem-col))))))) | |
962 | |
963 (defun vera-lineup-comment (langelem) | |
964 "Line up a comment start." | |
965 (save-excursion | |
966 (back-to-indentation) | |
967 (if (bolp) | |
968 ;; not indent if at beginning of line | |
969 -1000 | |
970 ;; otherwise indent accordingly | |
971 (goto-char (cdr langelem)) | |
972 (current-column)))) | |
973 | |
974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
975 ;; move functions | |
976 | |
977 (defconst vera-beg-block-re "{\\|\\<\\(begin\\|fork\\)\\>") | |
978 | |
979 (defconst vera-end-block-re "}\\|\\<\\(end\\|join\\(\\s-+\\(all\\|any\\|none\\)\\)?\\)\\>") | |
980 | |
981 (defconst vera-beg-substatement-re "\\<\\(else\\|for\\|if\\|repeat\\|while\\)\\>") | |
982 | |
983 (defun vera-corresponding-begin (&optional recursive) | |
984 "Find corresponding block begin if cursor is at a block end." | |
985 (while (and (vera-re-search-backward | |
986 (concat "\\(" vera-end-block-re "\\)\\|" vera-beg-block-re) | |
987 nil t) | |
988 (match-string 1)) | |
989 (vera-corresponding-begin t)) | |
990 (unless recursive (vera-beginning-of-substatement))) | |
991 | |
992 (defun vera-corresponding-if () | |
993 "Find corresponding `if' if cursor is at `else'." | |
994 (while (and (vera-re-search-backward "}\\|\\<\\(if\\|else\\)\\>" nil t) | |
995 (not (equal (match-string 0) "if"))) | |
996 (if (equal (match-string 0) "else") | |
997 (vera-corresponding-if) | |
998 (forward-char) | |
999 (backward-sexp)))) | |
1000 | |
1001 (defun vera-beginning-of-statement () | |
1002 "Go to beginning of current statement." | |
1003 (let (pos) | |
1004 (while | |
1005 (progn | |
1006 ;; search for end of previous statement | |
1007 (while | |
1008 (and (vera-re-search-backward | |
1009 (concat "[);]\\|" vera-beg-block-re | |
1010 "\\|" vera-end-block-re) nil t) | |
1011 (equal (match-string 0) ")")) | |
1012 (forward-char) | |
1013 (backward-sexp)) | |
1014 (setq pos (match-beginning 0)) | |
1015 ;; go back to beginning of current statement | |
1016 (goto-char (or (match-end 0) 0)) | |
1017 (vera-forward-syntactic-ws nil t) | |
1018 (when (looking-at "(") | |
1019 (forward-sexp) | |
1020 (vera-forward-syntactic-ws nil t)) | |
1021 ;; if "else" found, go to "if" and search again | |
1022 (when (looking-at "\\<else\\>") | |
1023 (vera-corresponding-if) | |
1024 (setq pos (point)) | |
1025 t)) | |
1026 ;; if search is repeated, go to beginning of last search | |
1027 (goto-char pos)))) | |
1028 | |
1029 (defun vera-beginning-of-substatement () | |
1030 "Go to beginning of current substatement." | |
1031 (let ((lim (point)) | |
1032 pos) | |
1033 ;; go to beginning of statement | |
1034 (vera-beginning-of-statement) | |
1035 (setq pos (point)) | |
1036 ;; go forward all substatement opening statements until at LIM | |
1037 (while (and (< (point) lim) | |
1038 (vera-re-search-forward vera-beg-substatement-re lim t)) | |
1039 (setq pos (match-beginning 0))) | |
1040 (vera-forward-syntactic-ws nil t) | |
1041 (when (looking-at "(") | |
1042 (forward-sexp) | |
1043 (vera-forward-syntactic-ws nil t)) | |
1044 (when (< (point) lim) | |
1045 (setq pos (point))) | |
1046 (goto-char pos))) | |
1047 | |
1048 (defun vera-forward-statement () | |
1049 "Move forward one statement." | |
1050 (interactive) | |
1051 (vera-prepare-search | |
1052 (while (and (vera-re-search-forward | |
1053 (concat "[(;]\\|" vera-beg-block-re "\\|" vera-end-block-re) | |
1054 nil t) | |
1055 (equal (match-string 0) "(")) | |
1056 (backward-char) | |
1057 (forward-sexp)) | |
1058 (vera-beginning-of-substatement))) | |
1059 | |
1060 (defun vera-backward-statement () | |
1061 "Move backward one statement." | |
1062 (interactive) | |
1063 (vera-prepare-search | |
1064 (vera-backward-syntactic-ws nil t) | |
1065 (unless (= (preceding-char) ?\)) | |
1066 (backward-char)) | |
1067 (vera-beginning-of-substatement))) | |
1068 | |
1069 (defun vera-forward-same-indent () | |
1070 "Move forward to next line with same indent." | |
1071 (interactive) | |
1072 (let ((pos (point)) | |
1073 (indent (current-indentation))) | |
1074 (beginning-of-line 2) | |
1075 (while (and (not (eobp)) | |
1076 (or (looking-at "^\\s-*$") | |
1077 (> (current-indentation) indent))) | |
1078 (beginning-of-line 2)) | |
1079 (if (= (current-indentation) indent) | |
1080 (back-to-indentation) | |
1081 (message "No following line with same indent found in this block") | |
1082 (goto-char pos)))) | |
1083 | |
1084 (defun vera-backward-same-indent () | |
1085 "Move backward to previous line with same indent." | |
1086 (interactive) | |
1087 (let ((pos (point)) | |
1088 (indent (current-indentation))) | |
1089 (beginning-of-line -0) | |
1090 (while (and (not (bobp)) | |
1091 (or (looking-at "^\\s-*$") | |
1092 (> (current-indentation) indent))) | |
1093 (beginning-of-line -0)) | |
1094 (if (= (current-indentation) indent) | |
1095 (back-to-indentation) | |
1096 (message "No preceding line with same indent found in this block") | |
1097 (goto-char pos)))) | |
1098 | |
1099 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1100 ;; syntax analysis | |
1101 | |
1102 (defmacro vera-add-syntax (symbol &optional relpos) | |
1103 "A simple macro to append the syntax in SYMBOL to the syntax list. | |
1104 try to increase performance by using this macro." | |
1105 `(setq syntax (cons (cons ,symbol ,(or relpos 0)) syntax))) | |
1106 | |
1107 (defun vera-guess-basic-syntax () | |
1108 "Determine syntactic context of current line of code." | |
1109 (save-excursion | |
1110 (beginning-of-line) | |
1111 (let ((indent-point (point)) | |
1112 syntax state placeholder pos) | |
1113 ;; determine syntax state | |
1114 (setq state (parse-partial-sexp (point-min) (point))) | |
1115 (cond | |
1116 ;; CASE 1: in a comment? | |
1117 ((nth 4 state) | |
1118 ;; skip empty lines | |
1119 (while (and (zerop (forward-line -1)) | |
1120 (looking-at "^\\s-*$"))) | |
1121 (vera-add-syntax 'comment (vera-point 'boi))) | |
1122 ;; CASE 2: in a string? | |
1123 ((nth 3 state) | |
1124 (vera-add-syntax 'string)) | |
1125 ;; CASE 3: at a directive? | |
1126 ((save-excursion (back-to-indentation) (= (following-char) ?\#)) | |
1127 (vera-add-syntax 'directive (point))) | |
1128 ;; CASE 4: after an opening parenthesis (argument list continuation)? | |
1129 ((and (nth 1 state) | |
1130 (or (= (char-after (nth 1 state)) ?\() | |
1131 ;; also for concatenation (opening '{' and ',' on eol/eopl) | |
1132 (and (= (char-after (nth 1 state)) ?\{) | |
1133 (or (save-excursion | |
1134 (vera-backward-syntactic-ws) (= (char-before) ?,)) | |
1135 (save-excursion | |
1136 (end-of-line) (= (char-before) ?,)))))) | |
1137 (goto-char (1+ (nth 1 state))) | |
1138 ;; is there code after the opening parenthesis on the same line? | |
1139 (if (looking-at "\\s-*$") | |
1140 (vera-add-syntax 'arglist-cont (vera-point 'boi)) | |
1141 (vera-add-syntax 'arglist-cont-nonempty (point)))) | |
1142 ;; CASE 5: at a block closing? | |
1143 ((save-excursion (back-to-indentation) (looking-at vera-end-block-re)) | |
1144 ;; look for the corresponding begin | |
1145 (vera-corresponding-begin) | |
1146 (vera-add-syntax 'block-close (vera-point 'boi))) | |
1147 ;; CASE 6: at a block intro (the first line after a block opening)? | |
1148 ((and (save-excursion | |
1149 (vera-backward-syntactic-ws nil t) | |
1150 ;; previous line ends with a block opening? | |
1151 (or (/= (skip-chars-backward "{") 0) (backward-word 1)) | |
1152 (when (looking-at vera-beg-block-re) | |
1153 ;; go to beginning of substatement | |
1154 (vera-beginning-of-substatement) | |
1155 (setq placeholder (point)))) | |
1156 ;; not if "fork" is followed by "{" | |
1157 (save-excursion | |
1158 (not (and (progn (back-to-indentation) (looking-at "{")) | |
1159 (progn (goto-char placeholder) | |
1160 (looking-at "\\<fork\\>")))))) | |
1161 (goto-char placeholder) | |
1162 (vera-add-syntax 'block-intro (vera-point 'boi))) | |
1163 ;; CASE 7: at the beginning of an else clause? | |
1164 ((save-excursion (back-to-indentation) (looking-at "\\<else\\>")) | |
1165 ;; find corresponding if | |
1166 (vera-corresponding-if) | |
1167 (vera-add-syntax 'else-clause (vera-point 'boi))) | |
1168 ;; CASE 8: at the beginning of a statement? | |
1169 ;; is the previous command completed? | |
1170 ((or (save-excursion | |
1171 (vera-backward-syntactic-ws nil t) | |
1172 (setq placeholder (point)) | |
1173 ;; at the beginning of the buffer? | |
1174 (or (bobp) | |
1175 ;; previous line ends with a semicolon or | |
1176 ;; is a block opening or closing? | |
1177 (when (or (/= (skip-chars-backward "{};") 0) | |
1178 (progn (back-to-indentation) | |
1179 (looking-at (concat vera-beg-block-re "\\|" | |
1180 vera-end-block-re)))) | |
1181 ;; if at a block closing, go to beginning | |
1182 (when (looking-at vera-end-block-re) | |
1183 (vera-corresponding-begin)) | |
1184 ;; go to beginning of the statement | |
1185 (vera-beginning-of-statement) | |
1186 (setq placeholder (point))) | |
1187 ;; at a directive? | |
1188 (when (progn (back-to-indentation) (looking-at "#")) | |
1189 ;; go to previous statement | |
1190 (vera-beginning-of-statement) | |
1191 (setq placeholder (point))))) | |
1192 ;; at a block opening? | |
1193 (when (save-excursion (back-to-indentation) | |
1194 (looking-at vera-beg-block-re)) | |
1195 ;; go to beginning of the substatement | |
1196 (vera-beginning-of-substatement) | |
1197 (setq placeholder (point)))) | |
1198 (goto-char placeholder) | |
1199 (vera-add-syntax 'statement (vera-point 'boi))) | |
1200 ;; CASE 9: at the beginning of a substatement? | |
1201 ;; is this line preceeded by a substatement opening statement? | |
1202 ((save-excursion (vera-backward-syntactic-ws nil t) | |
1203 (when (= (preceding-char) ?\)) (backward-sexp)) | |
1204 (backward-word 1) | |
1205 (setq placeholder (point)) | |
1206 (looking-at vera-beg-substatement-re)) | |
1207 (goto-char placeholder) | |
1208 (vera-add-syntax 'substatement (vera-point 'boi))) | |
1209 ;; CASE 10: it must be a statement continuation! | |
1210 (t | |
1211 ;; go to beginning of statement | |
1212 (vera-beginning-of-substatement) | |
1213 (vera-add-syntax 'statement-cont (vera-point 'boi)))) | |
1214 ;; special case: look for a comment start | |
1215 (goto-char indent-point) | |
1216 (skip-chars-forward " \t") | |
1217 (when (looking-at comment-start) | |
1218 (vera-add-syntax 'comment-intro)) | |
1219 ;; return syntax | |
1220 syntax))) | |
1221 | |
1222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1223 ;; indentation functions | |
1224 | |
1225 (defun vera-indent-line () | |
1226 "Indent the current line as Vera code. Optional SYNTAX is the | |
1227 syntactic information for the current line. Returns the amount of | |
1228 indentation change (in columns)." | |
1229 (interactive) | |
1230 (vera-prepare-search | |
1231 (let* ((syntax (vera-guess-basic-syntax)) | |
1232 (pos (- (point-max) (point))) | |
1233 (indent (apply '+ (mapcar 'vera-get-offset syntax))) | |
1234 (shift-amt (- (current-indentation) indent))) | |
1235 (when vera-echo-syntactic-information-p | |
1236 (message "syntax: %s, indent= %d" syntax indent)) | |
1237 (unless (zerop shift-amt) | |
1238 (beginning-of-line) | |
1239 (delete-region (point) (vera-point 'boi)) | |
1240 (indent-to indent)) | |
1241 (if (< (point) (vera-point 'boi)) | |
1242 (back-to-indentation) | |
1243 ;; If initial point was within line's indentation, position after | |
1244 ;; the indentation. Else stay at same point in text. | |
1245 (when (> (- (point-max) pos) (point)) | |
1246 (goto-char (- (point-max) pos)))) | |
1247 shift-amt))) | |
1248 | |
1249 (defun vera-indent-buffer () | |
1250 "Indent whole buffer as Vera code. | |
1251 Calls `indent-region' for whole buffer." | |
1252 (interactive) | |
1253 (message "Indenting buffer...") | |
1254 (indent-region (point-min) (point-max) nil) | |
1255 (message "Indenting buffer...done")) | |
1256 | |
1257 (defun vera-indent-region (start end column) | |
1258 "Indent region as Vera code." | |
1259 (interactive "r\nP") | |
1260 (message "Indenting region...") | |
1261 (indent-region start end column) | |
1262 (message "Indenting region...done")) | |
1263 | |
1264 (defsubst vera-indent-block-closing () | |
1265 "If previous word is a block closing or `else', indent line again." | |
1266 (when (= (char-syntax (preceding-char)) ?w) | |
1267 (save-excursion | |
1268 (backward-word 1) | |
1269 (when (and (not (vera-in-literal)) | |
1270 (looking-at (concat vera-end-block-re "\\|\\<else\\>"))) | |
1271 (indent-according-to-mode))))) | |
1272 | |
1273 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1274 ;; electrifications | |
1275 | |
1276 (defun vera-electric-tab (&optional prefix-arg) | |
1277 "If preceeding character is part of a word or a paren then hippie-expand, | |
1278 else if right of non whitespace on line then tab-to-tab-stop, | |
1279 else if last command was a tab or return then dedent one step or if a comment | |
1280 toggle between normal indent and inline comment indent, | |
1281 else indent `correctly'. | |
1282 If `vera-intelligent-tab' is nil, always indent line." | |
1283 (interactive "*P") | |
1284 (if vera-intelligent-tab | |
1285 (progn | |
1286 (cond ((memq (char-syntax (preceding-char)) '(?w ?_)) | |
1287 (let ((case-fold-search t) | |
1288 (case-replace nil) | |
1289 (hippie-expand-only-buffers | |
1290 (or (and (boundp 'hippie-expand-only-buffers) | |
1291 hippie-expand-only-buffers) | |
1292 '(vera-mode)))) | |
1293 (vera-expand-abbrev prefix-arg))) | |
1294 ((> (current-column) (current-indentation)) | |
1295 (tab-to-tab-stop)) | |
1296 ((and (or (eq last-command 'vera-electric-tab) | |
1297 (eq last-command 'vera-electric-return)) | |
1298 (/= 0 (current-indentation))) | |
1299 (backward-delete-char-untabify vera-basic-offset nil)) | |
1300 (t (indent-according-to-mode))) | |
1301 (setq this-command 'vera-electric-tab)) | |
1302 (indent-according-to-mode))) | |
1303 | |
1304 (defun vera-electric-return () | |
1305 "Insert newline and indent. Indent current line if it is a block closing." | |
1306 (interactive) | |
1307 (vera-indent-block-closing) | |
1308 (newline-and-indent)) | |
1309 | |
1310 (defun vera-electric-space (arg) | |
1311 "Insert a space. Indent current line if it is a block closing." | |
1312 (interactive "*P") | |
1313 (unless arg | |
1314 (vera-indent-block-closing)) | |
1315 (self-insert-command (prefix-numeric-value arg))) | |
1316 | |
1317 (defun vera-electric-opening-brace (arg) | |
1318 "Outdent opening brace." | |
1319 (interactive "*P") | |
1320 (self-insert-command (prefix-numeric-value arg)) | |
1321 (unless arg | |
1322 (indent-according-to-mode))) | |
1323 | |
1324 (defun vera-electric-closing-brace (arg) | |
1325 "Outdent closing brace." | |
1326 (interactive "*P") | |
1327 (self-insert-command (prefix-numeric-value arg)) | |
1328 (unless arg | |
1329 (indent-according-to-mode))) | |
1330 | |
1331 (defun vera-electric-pound (arg) | |
1332 "Insert `#' and indent as directive it first character of line." | |
1333 (interactive "*P") | |
1334 (self-insert-command (prefix-numeric-value arg)) | |
1335 (unless arg | |
1336 (save-excursion | |
1337 (backward-char) | |
1338 (skip-chars-backward " \t") | |
1339 (when (bolp) | |
1340 (delete-horizontal-space))))) | |
1341 | |
1342 (defun vera-electric-star (arg) | |
1343 "Insert a star character. Nicked from `c-electric-star'." | |
1344 (interactive "*P") | |
1345 (self-insert-command (prefix-numeric-value arg)) | |
1346 (if (and (not arg) | |
1347 (memq (vera-in-literal) '(comment)) | |
1348 (eq (char-before) ?*) | |
1349 (save-excursion | |
1350 (forward-char -1) | |
1351 (skip-chars-backward "*") | |
1352 (if (eq (char-before) ?/) | |
1353 (forward-char -1)) | |
1354 (skip-chars-backward " \t") | |
1355 (bolp))) | |
1356 (indent-according-to-mode))) | |
1357 | |
1358 (defun vera-electric-slash (arg) | |
1359 "Insert a slash character. Nicked from `c-electric-slash'." | |
1360 (interactive "*P") | |
1361 (let* ((ch (char-before)) | |
1362 (indentp (and (not arg) | |
1363 (eq last-command-char ?/) | |
1364 (or (and (eq ch ?/) | |
1365 (not (vera-in-literal))) | |
1366 (and (eq ch ?*) | |
1367 (vera-in-literal)))))) | |
1368 (self-insert-command (prefix-numeric-value arg)) | |
1369 (when indentp | |
1370 (indent-according-to-mode)))) | |
1371 | |
1372 | |
1373 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1374 ;;; Miscellaneous | |
1375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1376 | |
1377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1378 ;; Hippie expand customization (for expansion of Vera commands) | |
1379 | |
1380 (defvar vera-abbrev-list | |
1381 (append (list nil) vera-keywords | |
1382 (list nil) vera-types | |
1383 (list nil) vera-functions | |
1384 (list nil) vera-constants | |
1385 (list nil) vera-rvm-types | |
1386 (list nil) vera-rvm-functions | |
1387 (list nil) vera-rvm-constants) | |
1388 "Predefined abbreviations for Vera.") | |
1389 | |
1390 (defvar vera-expand-upper-case nil) | |
1391 | |
1392 (eval-when-compile (require 'hippie-exp)) | |
1393 | |
1394 (defun vera-try-expand-abbrev (old) | |
1395 "Try expanding abbreviations from `vera-abbrev-list'." | |
1396 (unless old | |
1397 (he-init-string (he-dabbrev-beg) (point)) | |
1398 (setq he-expand-list | |
1399 (let ((abbrev-list vera-abbrev-list) | |
1400 (sel-abbrev-list '())) | |
1401 (while abbrev-list | |
1402 (when (or (not (stringp (car abbrev-list))) | |
1403 (string-match | |
1404 (concat "^" he-search-string) (car abbrev-list))) | |
1405 (setq sel-abbrev-list | |
1406 (cons (car abbrev-list) sel-abbrev-list))) | |
1407 (setq abbrev-list (cdr abbrev-list))) | |
1408 (nreverse sel-abbrev-list)))) | |
1409 (while (and he-expand-list | |
1410 (or (not (stringp (car he-expand-list))) | |
1411 (he-string-member (car he-expand-list) he-tried-table t))) | |
1412 (unless (stringp (car he-expand-list)) | |
1413 (setq vera-expand-upper-case (car he-expand-list))) | |
1414 (setq he-expand-list (cdr he-expand-list))) | |
1415 (if (null he-expand-list) | |
1416 (progn (when old (he-reset-string)) | |
1417 nil) | |
1418 (he-substitute-string | |
1419 (if vera-expand-upper-case | |
1420 (upcase (car he-expand-list)) | |
1421 (car he-expand-list)) | |
1422 t) | |
1423 (setq he-expand-list (cdr he-expand-list)) | |
1424 t)) | |
1425 | |
1426 ;; function for expanding abbrevs and dabbrevs | |
1427 (defun vera-expand-abbrev (arg)) | |
1428 (fset 'vera-expand-abbrev (make-hippie-expand-function | |
1429 '(try-expand-dabbrev | |
1430 try-expand-dabbrev-all-buffers | |
1431 vera-try-expand-abbrev))) | |
1432 | |
1433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1434 ;; Comments | |
1435 | |
1436 (defun vera-comment-uncomment-region (beg end &optional arg) | |
1437 "Comment region if not commented, uncomment region if already commented." | |
1438 (interactive "r\nP") | |
1439 (goto-char beg) | |
1440 (if (looking-at (regexp-quote comment-start)) | |
1441 (comment-region beg end '(4)) | |
1442 (comment-region beg end))) | |
1443 | |
1444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1445 ;; Help functions | |
1446 | |
1447 (defun vera-customize () | |
1448 "Call the customize function with `vera' as argument." | |
1449 (interactive) | |
1450 (customize-group 'vera)) | |
1451 | |
1452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1453 ;; Other | |
1454 | |
1455 ;; remove ".vr" from `completion-ignored-extensions' | |
1456 (setq completion-ignored-extensions | |
1457 (delete ".vr" completion-ignored-extensions)) | |
1458 | |
1459 | |
1460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1461 ;;; Bug reports | |
1462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1463 | |
1464 (defconst vera-mode-help-address "Reto Zimmermann <reto@gnu.org>" | |
1465 "Address for Vera Mode bug reports.") | |
1466 | |
1467 ;; get reporter-submit-bug-report when byte-compiling | |
1468 (eval-when-compile | |
1469 (require 'reporter)) | |
1470 | |
1471 (defun vera-submit-bug-report () | |
1472 "Submit via mail a bug report on Vera Mode." | |
1473 (interactive) | |
1474 ;; load in reporter | |
1475 (and | |
1476 (y-or-n-p "Do you want to submit a report on Vera Mode? ") | |
1477 (require 'reporter) | |
1478 (let ((reporter-prompt-for-summary-p t)) | |
1479 (reporter-submit-bug-report | |
1480 vera-mode-help-address | |
1481 (concat "Vera Mode " vera-version) | |
1482 (list | |
1483 ;; report all important variables | |
1484 'vera-basic-offset | |
1485 'vera-underscore-is-part-of-word | |
1486 'vera-intelligent-tab | |
1487 ) | |
1488 nil nil | |
1489 "Hi Reto,")))) | |
1490 | |
1491 | |
1492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1493 ;;; Documentation | |
1494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1495 | |
1496 (defun vera-version () | |
1497 "Echo the current version of Vera Mode in the minibuffer." | |
1498 (interactive) | |
1499 (message "Vera Mode %s (%s)" vera-version vera-time-stamp)) | |
1500 | |
1501 | |
1502 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1503 | |
1504 (provide 'vera-mode) | |
1505 | |
1506 ;;; vera-mode.el ends here |