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