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