1 ;;; vera-mode.el --- major mode for editing Vera files
3 ;; Copyright (C) 1997-2014 Free Software Foundation, Inc.
5 ;; Author: Reto Zimmermann <reto@gnu.org>
6 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
8 ;; Keywords: languages vera
9 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html
11 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
13 ;; filed in the Emacs bug reporting system against this file, a copy
14 ;; of the bug report be sent to the maintainer's email address.
16 (defconst vera-version
"2.18"
17 "Vera Mode version number.")
19 (defconst vera-time-stamp
"2007-06-21"
20 "Vera Mode time stamp for last update.")
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; This package provides a simple Emacs major mode for editing Vera code.
42 ;; It includes the following features:
44 ;; - Syntax highlighting
46 ;; - Word/keyword completion
48 ;; - Works under GNU Emacs and XEmacs
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53 ;; See comment string of function `vera-mode' or type `C-h m' in Emacs.
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 ;; Prerequisites: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X
60 ;; Put `vera-mode.el' into the `site-lisp' directory of your Emacs installation
61 ;; or into an arbitrary directory that is added to the load path by the
62 ;; following line in your Emacs start-up file (`.emacs'):
64 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
66 ;; If you already have the compiled `vera-mode.elc' file, put it in the same
67 ;; directory. Otherwise, byte-compile the source file:
68 ;; Emacs: M-x byte-compile-file -> vera-mode.el
69 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vera-mode.el
71 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
72 ;; directory of your Emacs installation or to your Emacs start-up file
75 ;; (autoload 'vera-mode "vera-mode" "Vera Mode" t)
76 ;; (setq auto-mode-alist (cons '("\\.vr[hi]?\\'" . vera-mode) auto-mode-alist))
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 "Customizations for Vera Mode."
92 (defcustom vera-basic-offset
2
93 "Amount of basic offset used for indentation."
97 (defcustom vera-underscore-is-part-of-word nil
98 "Non-nil means consider the underscore character `_' as part of word.
99 An identifier containing underscores is then treated as a single word in
100 select and move operations. All parts of an identifier separated by underscore
101 are treated as single words otherwise."
104 (make-obsolete-variable 'vera-underscore-is-part-of-word
105 'superword-mode
"24.4")
107 (defcustom vera-intelligent-tab t
108 "Non-nil means `TAB' does indentation, word completion and tab insertion.
109 That is, if preceding character is part of a word then complete word,
110 else if not at beginning of line then insert tab,
111 else if last command was a `TAB' or `RET' then dedent one step,
112 else indent current line.
113 If nil, TAB always indents current line."
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
125 (defvar vera-mode-map
126 (let ((map (make-sparse-keymap)))
127 ;; Backspace/delete key bindings.
128 (define-key map
[backspace] 'backward-delete-char-untabify)
129 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
130 (define-key map [delete] 'delete-char)
131 (define-key map [(meta delete)] 'kill-word))
132 ;; Standard key bindings.
133 (define-key map "\M-e" 'vera-forward-statement)
134 (define-key map "\M-a" 'vera-backward-statement)
135 (define-key map "\M-\C-e" 'vera-forward-same-indent)
136 (define-key map "\M-\C-a" 'vera-backward-same-indent)
137 ;; Mode specific key bindings.
138 (define-key map "\C-c\t" 'indent-according-to-mode)
139 (define-key map "\M-\C-\\" 'vera-indent-region)
140 (define-key map "\C-c\C-c" 'vera-comment-uncomment-region)
141 (define-key map "\C-c\C-f" 'vera-fontify-buffer)
142 (define-key map "\C-c\C-v" 'vera-version)
143 (define-key map "\M-\t" 'tab-to-tab-stop)
144 ;; Electric key bindings.
145 (define-key map "\t" 'vera-electric-tab)
146 (define-key map "\r" 'vera-electric-return)
147 (define-key map " " 'vera-electric-space)
148 (define-key map "{" 'vera-electric-opening-brace)
149 (define-key map "}" 'vera-electric-closing-brace)
150 (define-key map "#" 'vera-electric-pound)
151 (define-key map "*" 'vera-electric-star)
152 (define-key map "/" 'vera-electric-slash)
154 "Keymap for Vera Mode.")
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 (easy-menu-define vera-mode-menu vera-mode-map
162 "Menu keymap for Vera Mode."
164 ["(Un)Comment Out Region" vera-comment-uncomment-region (mark)]
166 ["Move Forward Statement" vera-forward-statement t]
167 ["Move Backward Statement" vera-backward-statement t]
168 ["Move Forward Same Indent" vera-forward-same-indent t]
169 ["Move Backward Same Indent" vera-backward-same-indent t]
171 ["Indent Line" indent-according-to-mode t]
172 ["Indent Region" vera-indent-region (mark)]
173 ["Indent Buffer" vera-indent-buffer t]
175 ["Fontify Buffer" vera-fontify-buffer t]
177 ["Documentation" describe-mode]
178 ["Version" vera-version t]
179 ["Bug Report..." vera-submit-bug-report t]
182 ["Indentation Offset..." (customize-option 'vera-basic-offset) t]
183 ["Underscore is Part of Word"
184 (customize-set-variable 'vera-underscore-is-part-of-word
185 (not vera-underscore-is-part-of-word))
186 :style toggle :selected vera-underscore-is-part-of-word]
187 ["Use Intelligent Tab"
188 (customize-set-variable 'vera-intelligent-tab
189 (not vera-intelligent-tab))
190 :style toggle :selected vera-intelligent-tab]
192 ["Save Options" customize-save-customized t]
194 ["Customize..." vera-customize t])))
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
199 (defvar vera-mode-syntax-table
200 (let ((syntax-table (make-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 (modify-syntax-entry ?\| "." syntax-table)
220 (modify-syntax-entry ?\" "\"" syntax-table)
222 (when vera-underscore-is-part-of-word
223 (modify-syntax-entry ?\_ "w" syntax-table))
225 (modify-syntax-entry ?\\ "\\" syntax-table)
226 ;; parentheses to match
227 (modify-syntax-entry ?\( "()" syntax-table)
228 (modify-syntax-entry ?\) ")(" syntax-table)
229 (modify-syntax-entry ?\[ "(]" syntax-table)
230 (modify-syntax-entry ?\] ")[" syntax-table)
231 (modify-syntax-entry ?\{ "(}" syntax-table)
232 (modify-syntax-entry ?\} "){" syntax-table)
234 (if (featurep 'xemacs)
235 (modify-syntax-entry ?\/ ". 1456" syntax-table) ; XEmacs
236 (modify-syntax-entry ?\/ ". 124b" syntax-table)) ; Emacs
237 (modify-syntax-entry ?\* ". 23" syntax-table)
239 (modify-syntax-entry ?\n "> b" syntax-table)
240 (modify-syntax-entry ?\^M "> b" syntax-table)
242 "Syntax table used in `vera-mode' buffers.")
244 (defvar vera-mode-ext-syntax-table
245 (let ((syntax-table (copy-syntax-table vera-mode-syntax-table)))
246 ;; extended syntax table including '_' (for simpler search regexps)
247 (modify-syntax-entry ?_ "w" syntax-table)
249 "Syntax table extended by `_' used in `vera-mode' buffers.")
251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254 ;;;###autoload (add-to-list 'auto-mode-alist (cons (purecopy "\\.vr[hi]?\\'") 'vera-mode))
257 (define-derived-mode vera-mode prog-mode "Vera"
258 "Major mode for editing Vera code.
263 INDENTATION: Typing `TAB' at the beginning of a line indents the line.
264 The amount of indentation is specified by option `vera-basic-offset'.
265 Indentation can be done for an entire region \(`M-C-\\') or buffer (menu).
266 `TAB' always indents the line if option `vera-intelligent-tab' is nil.
268 WORD/COMMAND COMPLETION: Typing `TAB' after a (not completed) word looks
269 for a word in the buffer or a Vera keyword that starts alike, inserts it
270 and adjusts case. Re-typing `TAB' toggles through alternative word
273 Typing `TAB' after a non-word character inserts a tabulator stop (if not
274 at the beginning of a line). `M-TAB' always inserts a tabulator stop.
276 COMMENTS: `C-c C-c' comments out a region if not commented out, and
277 uncomments a region if already commented out.
279 HIGHLIGHTING (fontification): Vera keywords, predefined types and
280 constants, function names, declaration names, directives, as well as
281 comments and strings are highlighted using different colors.
283 VERA VERSION: OpenVera 1.4 and Vera version 6.2.8.
289 To submit a bug report, use the corresponding menu entry within Vera Mode.
290 Add a description of the problem and include a reproducible test case.
292 Feel free to send questions and enhancement requests to <reto@gnu.org>.
294 Official distribution is at
295 URL `http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html'
298 The Vera Mode Maintainer
299 Reto Zimmermann <reto@gnu.org>
305 ;; set local variables
307 (set (make-local-variable 'comment-start) "//")
308 (set (make-local-variable 'comment-end) "")
309 (set (make-local-variable 'comment-column) 40)
310 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *")
311 (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *\n")
312 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
313 (set (make-local-variable 'paragraph-start) "^$")
314 (set (make-local-variable 'paragraph-separate) paragraph-start)
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"))))
322 (easy-menu-add vera-mode-menu)
324 (message "Vera Mode %s. Type C-c C-h for documentation." vera-version))
327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
334 (defconst vera-keywords
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"
350 "little_endian" "local"
351 "m_bad_state" "m_bad_trans" "m_state" "m_trans"
352 "negedge" "new" "newcov" "non_rand" "none" "not" "null"
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"
360 "var" "vca" "vector" "verilog_node" "verilog_task"
361 "vhdl_node" "vhdl_task" "virtual" "virtuals" "visible" "void"
362 "while" "wildcard" "with"
364 "List of Vera keywords.")
368 "integer" "bit" "reg" "string" "bind_var" "event"
369 "inout" "input" "output"
371 "NDRIVE" "NHOLD" "NRX" "NRZ" "NR0" "NR1" "NSAMPLE"
372 "PDRIVE" "PHOLD" "PRX" "PRZ" "PR0" "PR1" "PSAMPLE"
374 "List of Vera predefined types.")
376 (defconst vera-q-values
378 "gnr" "grx" "grz" "gr0" "gr1"
379 "nr" "rx" "rz" "r0" "r1"
380 "snr" "srx" "srz" "sr0" "sr1"
382 "List of Vera predefined VCA q_values.")
384 (defconst vera-functions
386 ;; system functions and tasks
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"
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"
400 "mailbox_get" "mailbox_put" "mailbox_receive" "mailbox_send"
401 "make_client" "make_server"
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"
418 "Configure" "DisableTrigger" "DoAction" "EnableCount" "EnableTrigger"
419 "Event" "GetAssert" "GetCount" "GetFirstAssert" "GetName" "GetNextAssert"
421 "atobin" "atohex" "atoi" "atooct"
422 "backref" "bittostr" "capacity" "compare" "constraint_mode"
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"
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_activation" "inst_set_collect"
433 "inst_set_cov_weight" "inst_set_coverage_goal" "inst_set_cross_bin_max"
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"
442 "rand_mode" "randomize" "reserve" "reverse" "rsort"
443 "search" "set_at_least" "set_auto_bin_max" "set_bin_activation"
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"
449 "new" "object_compare"
450 "post_boundary" "post_pack" "post_randomize" "post_unpack" "pre-randomize"
451 "pre_boundary" "pre_pack" "pre_unpack"
453 "List of Vera predefined system functions, tasks and class methods.")
455 (defconst vera-constants
458 "BAD_STATE" "BAD_TRANS"
459 "CALL" "CHECK" "CHGEDGE" "CLEAR" "COPY_NO_WAIT" "COPY_WAIT"
460 "CROSS" "CROSS_TRANS"
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"
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"
480 "stderr" "stdin" "stdout"
482 "List of Vera predefined constants.")
484 (defconst vera-rvm-types
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"
497 "List of Vera-RVM keywords.")
499 (defconst vera-rvm-functions
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"
510 "List of Vera-RVM functions.")
512 (defconst vera-rvm-constants
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"
547 "List of Vera-RVM predefined constants.")
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))))
555 (defconst vera-keywords-regexp
556 (concat "\\<\\(" (regexp-opt vera-keywords) "\\)\\>")
557 "Regexp for Vera keywords.")
559 (defconst vera-types-regexp
560 (concat "\\<\\(" (regexp-opt vera-types) "\\)\\>")
561 "Regexp for Vera predefined types.")
563 (defconst vera-q-values-regexp
564 (concat "\\<\\(" (regexp-opt vera-q-values) "\\)\\>")
565 "Regexp for Vera predefined VCA q_values.")
567 (defconst vera-functions-regexp
568 (concat "\\<\\(" (regexp-opt vera-functions) "\\)\\>")
569 "Regexp for Vera predefined system functions, tasks and class methods.")
571 (defconst vera-constants-regexp
572 (concat "\\<\\(" (regexp-opt vera-constants) "\\)\\>")
573 "Regexp for Vera predefined constants.")
575 (defconst vera-rvm-types-regexp
576 (concat "\\<\\(" (regexp-opt vera-rvm-types) "\\)\\>")
577 "Regexp for Vera-RVM keywords.")
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.")
583 (defconst vera-rvm-constants-regexp
584 (concat "\\<\\(" (regexp-opt vera-rvm-constants) "\\)\\>")
585 "Regexp for Vera-RVM predefined constants.")
588 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
592 (defun vera-font-lock-match-item (limit)
593 "Match, and move over, any declaration item after point.
594 Adapted from `font-lock-match-c-style-declaration-item-and-skip-to-next'."
597 (narrow-to-region (point-min) limit)
599 (when (looking-at "\\s-*\\(\\w+\\)")
601 (goto-char (match-end 1))
603 (if (looking-at "\\(\\s-*\\(\\[[^]]*\\]\\s-*\\)?,\\)")
604 (goto-char (match-end 1))
608 (defvar vera-font-lock-keywords
610 ;; highlight keywords
611 (list vera-keywords-regexp 1 'font-lock-keyword-face)
613 (list vera-types-regexp 1 'font-lock-type-face)
614 ;; highlight RVM types
615 (list vera-rvm-types-regexp 1 'font-lock-type-face)
616 ;; highlight constants
617 (list vera-constants-regexp 1 'font-lock-constant-face)
618 ;; highlight RVM constants
619 (list vera-rvm-constants-regexp 1 'font-lock-constant-face)
620 ;; highlight q_values
621 (list vera-q-values-regexp 1 'font-lock-constant-face)
622 ;; highlight predefined functions, tasks and methods
623 (list vera-functions-regexp 1 'vera-font-lock-function)
624 ;; highlight predefined RVM functions
625 (list vera-rvm-functions-regexp 1 'vera-font-lock-function)
626 ;; highlight functions
627 '("\\<\\(\\w+\\)\\s-*(" 1 font-lock-function-name-face)
628 ;; highlight various declaration names
629 '("^\\s-*\\(port\\|program\\|task\\)\\s-+\\(\\w+\\)\\>"
630 2 font-lock-function-name-face)
631 '("^\\s-*bind\\s-+\\(\\w+\\)\\s-+\\(\\w+\\)\\>"
632 (1 font-lock-function-name-face) (2 font-lock-function-name-face))
633 ;; highlight interface declaration names
634 '("^\\s-*\\(class\\|interface\\)\\s-+\\(\\w+\\)\\>"
635 2 vera-font-lock-interface)
636 ;; highlight variable name definitions
637 (list (concat "^\\s-*" vera-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
638 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
639 (list (concat "^\\s-*" vera-rvm-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
640 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
642 '("\\([0-9]*'[bdoh][0-9a-fA-FxXzZ_]+\\)" 1 vera-font-lock-number)
643 ;; highlight filenames in #include directives
644 '("^#\\s-*include\\s-*\\(<[^>\"\n]*>?\\)"
645 1 font-lock-string-face)
646 ;; highlight directives and directive names
647 '("^#\\s-*\\(\\w+\\)\\>[ \t!]*\\(\\w+\\)?"
648 (1 font-lock-builtin-face) (2 font-lock-variable-name-face nil t))
649 ;; highlight `@', `$' and `#'
650 '("\\([@$#]\\)" 1 font-lock-keyword-face)
651 ;; highlight @ and # definitions
652 '("@\\s-*\\(\\w*\\)\\(\\s-*,\\s-*\\(\\w+\\)\\)?\\>[^.]"
653 (1 vera-font-lock-number) (3 vera-font-lock-number nil t))
654 ;; highlight interface signal name
655 '("\\(\\w+\\)\\.\\w+" 1 vera-font-lock-interface)
657 "Regular expressions to highlight in Vera Mode.")
659 (defvar vera-font-lock-number 'vera-font-lock-number
660 "Face name to use for @ definitions.")
662 (defvar vera-font-lock-function 'vera-font-lock-function
663 "Face name to use for predefined functions and tasks.")
665 (defvar vera-font-lock-interface 'vera-font-lock-interface
666 "Face name to use for interface names.")
668 (defface vera-font-lock-number
669 '((((class color) (background light)) :foreground "Gold4")
670 (((class color) (background dark)) :foreground "BurlyWood1")
671 (t :slant italic :weight bold))
672 "Font lock mode face used to highlight @ definitions."
673 :group 'font-lock-highlighting-faces)
675 (defface vera-font-lock-function
676 '((((class color) (background light)) :foreground "DarkCyan")
677 (((class color) (background dark)) :foreground "Orchid1")
678 (t :slant italic :weight bold))
679 "Font lock mode face used to highlight predefined functions and tasks."
680 :group 'font-lock-highlighting-faces)
682 (defface vera-font-lock-interface
683 '((((class color) (background light)) :foreground "Grey40")
684 (((class color) (background dark)) :foreground "Grey80")
685 (t :slant italic :weight bold))
686 "Font lock mode face used to highlight interface names."
687 :group 'font-lock-highlighting-faces)
689 (defalias 'vera-fontify-buffer 'font-lock-fontify-buffer)
691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
695 (defvar vera-echo-syntactic-information-p nil
696 "If non-nil, syntactic info is echoed when the line is indented.")
698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
701 (defconst vera-offsets-alist
702 '((comment . vera-lineup-C-comments)
703 (comment-intro . vera-lineup-comment)
711 (arglist-cont-nonempty . 0)
717 "Association list of syntactic element symbols and indentation offsets.
718 Adapted from `c-offsets-alist'.")
720 (defun vera-evaluate-offset (offset langelem symbol)
721 "OFFSET can be a number, a function, a variable, a list, or one of
724 ((eq offset '+) (setq offset vera-basic-offset))
725 ((eq offset '-) (setq offset (- vera-basic-offset)))
726 ((eq offset '++) (setq offset (* 2 vera-basic-offset)))
727 ((eq offset '--) (setq offset (* 2 (- vera-basic-offset))))
728 ((eq offset '*) (setq offset (/ vera-basic-offset 2)))
729 ((eq offset '/) (setq offset (/ (- vera-basic-offset) 2)))
730 ((functionp offset) (setq offset (funcall offset langelem)))
734 (while (and (not done) offset)
735 (setq done (vera-evaluate-offset (car offset) langelem symbol)
736 offset (cdr offset)))
740 ((not (numberp offset)) (setq offset (symbol-value offset))))
743 (defun vera-get-offset (langelem)
744 "Get offset from LANGELEM which is a cons cell of the form:
745 \(SYMBOL . RELPOS). The symbol is matched against
746 vera-offsets-alist and the offset found there is either returned,
747 or added to the indentation at RELPOS. If RELPOS is nil, then
748 the offset is simply returned."
749 (let* ((symbol (car langelem))
750 (relpos (cdr langelem))
751 (match (assq symbol vera-offsets-alist))
752 (offset (cdr-safe match)))
756 (setq offset (vera-evaluate-offset offset langelem symbol)))
758 (< relpos (line-beginning-position)))
763 (vera-evaluate-offset offset langelem symbol))))
765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
768 (defsubst vera-point (position)
769 "Return the value of point at certain commonly referenced POSITIONs.
770 POSITION can be one of the following symbols:
771 bol -- beginning of line
773 boi -- back to indentation
774 ionl -- indentation of next line
775 iopl -- indentation of previous line
776 bonl -- beginning of next line
777 bopl -- beginning of previous line
778 This function does not modify point or mark."
781 ((eq position 'bol) (beginning-of-line))
782 ((eq position 'eol) (end-of-line))
783 ((eq position 'boi) (back-to-indentation))
784 ((eq position 'bonl) (forward-line 1))
785 ((eq position 'bopl) (forward-line -1))
786 ((eq position 'iopl) (forward-line -1) (back-to-indentation))
787 ((eq position 'ionl) (forward-line 1) (back-to-indentation))
788 (t (error "Unknown buffer position requested: %s" position)))
791 (defun vera-in-literal (&optional lim)
792 "Determine if point is in a Vera literal."
794 (let ((state (parse-partial-sexp (or lim (point-min)) (point))))
796 ((nth 3 state) 'string)
797 ((nth 4 state) 'comment)
800 (defun vera-skip-forward-literal ()
801 "Skip forward literal and return t if within one."
802 (let ((state (save-excursion
803 (if (fboundp 'syntax-ppss)
805 (parse-partial-sexp (point-min) (point))))))
807 ;; Inside a string or comment.
808 (goto-char (nth 8 state))
811 (condition-case nil (forward-sexp 1)
812 ;; Can't find end of string: it extends til end of buffer.
813 (error (goto-char (point-max))))
818 (defun vera-skip-backward-literal ()
819 "Skip backward literal and return t if within one."
820 (let ((state (save-excursion
821 (if (fboundp 'syntax-ppss)
823 (parse-partial-sexp (point-min) (point))))))
825 ;; Inside a string or comment.
826 (goto-char (nth 8 state))
829 (defsubst vera-re-search-forward (regexp &optional bound noerror)
830 "Like `re-search-forward', but skips over matches in literals."
832 (while (and (setq ret (re-search-forward regexp bound noerror))
833 (vera-skip-forward-literal)
834 (if bound (< (point) bound) t)))
837 (defsubst vera-re-search-backward (regexp &optional bound noerror)
838 "Like `re-search-backward', but skips over matches in literals."
840 (while (and (setq ret (re-search-backward regexp bound noerror))
841 (vera-skip-backward-literal)
842 (if bound (> (point) bound) t)))
845 (defun vera-forward-syntactic-ws (&optional lim skip-directive)
846 "Forward skip of syntactic whitespace."
848 (let* ((lim (or lim (point-max)))
850 (hugenum (point-max)))
851 (narrow-to-region (point) lim)
852 (while (/= here (point))
854 (forward-comment hugenum)
855 (when (and skip-directive (looking-at "^\\s-*#"))
858 (defun vera-backward-syntactic-ws (&optional lim skip-directive)
859 "Backward skip over syntactic whitespace."
861 (let* ((lim (or lim (point-min)))
863 (hugenum (- (point-max))))
864 (when (< lim (point))
865 (narrow-to-region lim (point))
866 (while (/= here (point))
868 (forward-comment hugenum)
869 (when (and skip-directive
870 (save-excursion (back-to-indentation)
871 (= (following-char) ?\#)))
872 (beginning-of-line)))))))
874 (defmacro vera-prepare-search (&rest body)
875 "Execute BODY with a syntax table that includes '_'."
876 `(with-syntax-table vera-mode-ext-syntax-table ,@body))
878 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
879 ;; comment indentation functions
881 (defsubst vera-langelem-col (langelem &optional preserve-point)
882 "Convenience routine to return the column of LANGELEM's relpos.
883 Leaves point at the relpos unless PRESERVE-POINT is non-nil."
884 (let ((here (point)))
885 (goto-char (cdr langelem))
886 (prog1 (current-column)
890 (defun vera-lineup-C-comments (langelem)
891 "Line up C block comment continuation lines.
892 Nicked from `c-lineup-C-comments'."
895 (stars (progn (back-to-indentation)
896 (skip-chars-forward "*")))
897 (langelem-col (vera-langelem-col langelem)))
898 (back-to-indentation)
899 (if (not (re-search-forward "/\\([*]+\\)" (vera-point 'eol) t))
901 (if (not (looking-at "[*]+"))
903 ;; we now have to figure out where this comment begins.
905 (back-to-indentation)
906 (if (looking-at "[*]+/")
907 (progn (goto-char (match-end 0))
908 (forward-comment -1))
909 (goto-char (cdr langelem))
910 (back-to-indentation))))
911 (- (current-column) langelem-col))
914 (skip-chars-forward " \t")
915 (- (current-column) langelem-col))
916 ;; how many stars on comment opening line? if greater than
917 ;; on current line, align left. if less than or equal,
918 ;; align right. this should also pick up Javadoc style
920 (if (> (length (match-string 1)) stars)
922 (back-to-indentation)
923 (- (current-column) -1 langelem-col))
924 (- (current-column) stars langelem-col)))))))
926 (defun vera-lineup-comment (langelem)
927 "Line up a comment start."
929 (back-to-indentation)
931 ;; not indent if at beginning of line
933 ;; otherwise indent accordingly
934 (goto-char (cdr langelem))
937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
940 (defconst vera-beg-block-re "{\\|\\<\\(begin\\|fork\\)\\>")
942 (defconst vera-end-block-re "}\\|\\<\\(end\\|join\\(\\s-+\\(all\\|any\\|none\\)\\)?\\)\\>")
944 (defconst vera-beg-substatement-re "\\<\\(else\\|for\\|if\\|repeat\\|while\\)\\>")
946 (defun vera-corresponding-begin (&optional recursive)
947 "Find corresponding block begin if cursor is at a block end."
948 (while (and (vera-re-search-backward
949 (concat "\\(" vera-end-block-re "\\)\\|" vera-beg-block-re)
952 (vera-corresponding-begin t))
953 (unless recursive (vera-beginning-of-substatement)))
955 (defun vera-corresponding-if ()
956 "Find corresponding `if' if cursor is at `else'."
957 (while (and (vera-re-search-backward "}\\|\\<\\(if\\|else\\)\\>" nil t)
958 (not (equal (match-string 0) "if")))
959 (if (equal (match-string 0) "else")
960 (vera-corresponding-if)
964 (defun vera-beginning-of-statement ()
965 "Go to beginning of current statement."
969 ;; search for end of previous statement
971 (and (vera-re-search-backward
972 (concat "[);]\\|" vera-beg-block-re
973 "\\|" vera-end-block-re) nil t)
974 (equal (match-string 0) ")"))
977 (setq pos (match-beginning 0))
978 ;; go back to beginning of current statement
979 (goto-char (or (match-end 0) 0))
980 (vera-forward-syntactic-ws nil t)
981 (when (looking-at "(")
983 (vera-forward-syntactic-ws nil t))
984 ;; if "else" found, go to "if" and search again
985 (when (looking-at "\\<else\\>")
986 (vera-corresponding-if)
989 ;; if search is repeated, go to beginning of last search
992 (defun vera-beginning-of-substatement ()
993 "Go to beginning of current substatement."
996 ;; go to beginning of statement
997 (vera-beginning-of-statement)
999 ;; go forward all substatement opening statements until at LIM
1000 (while (and (< (point) lim)
1001 (vera-re-search-forward vera-beg-substatement-re lim t))
1002 (setq pos (match-beginning 0)))
1003 (vera-forward-syntactic-ws nil t)
1004 (when (looking-at "(")
1006 (vera-forward-syntactic-ws nil t))
1007 (when (< (point) lim)
1011 (defun vera-forward-statement ()
1012 "Move forward one statement."
1014 (vera-prepare-search
1015 (while (and (vera-re-search-forward
1016 (concat "[(;]\\|" vera-beg-block-re "\\|" vera-end-block-re)
1018 (equal (match-string 0) "("))
1021 (vera-beginning-of-substatement)))
1023 (defun vera-backward-statement ()
1024 "Move backward one statement."
1026 (vera-prepare-search
1027 (vera-backward-syntactic-ws nil t)
1028 (unless (= (preceding-char) ?\))
1030 (vera-beginning-of-substatement)))
1032 (defun vera-forward-same-indent ()
1033 "Move forward to next line with same indent."
1036 (indent (current-indentation)))
1037 (beginning-of-line 2)
1038 (while (and (not (eobp))
1039 (or (looking-at "^\\s-*$")
1040 (> (current-indentation) indent)))
1041 (beginning-of-line 2))
1042 (if (= (current-indentation) indent)
1043 (back-to-indentation)
1044 (message "No following line with same indent found in this block")
1047 (defun vera-backward-same-indent ()
1048 "Move backward to previous line with same indent."
1051 (indent (current-indentation)))
1052 (beginning-of-line -0)
1053 (while (and (not (bobp))
1054 (or (looking-at "^\\s-*$")
1055 (> (current-indentation) indent)))
1056 (beginning-of-line -0))
1057 (if (= (current-indentation) indent)
1058 (back-to-indentation)
1059 (message "No preceding line with same indent found in this block")
1062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1065 (defmacro vera-add-syntax (symbol &optional relpos)
1066 "A simple macro to append the syntax in SYMBOL to the syntax list.
1067 try to increase performance by using this macro."
1068 `(setq syntax (cons (cons ,symbol ,(or relpos 0)) syntax)))
1070 (defun vera-guess-basic-syntax ()
1071 "Determine syntactic context of current line of code."
1074 (let ((indent-point (point))
1075 syntax state placeholder)
1076 ;; determine syntax state
1077 (setq state (parse-partial-sexp (point-min) (point)))
1079 ;; CASE 1: in a comment?
1082 (while (and (zerop (forward-line -1))
1083 (looking-at "^\\s-*$")))
1084 (vera-add-syntax 'comment (vera-point 'boi)))
1085 ;; CASE 2: in a string?
1087 (vera-add-syntax 'string))
1088 ;; CASE 3: at a directive?
1089 ((save-excursion (back-to-indentation) (= (following-char) ?\#))
1090 (vera-add-syntax 'directive (point)))
1091 ;; CASE 4: after an opening parenthesis (argument list continuation)?
1093 (or (= (char-after (nth 1 state)) ?\()
1094 ;; also for concatenation (opening '{' and ',' on eol/eopl)
1095 (and (= (char-after (nth 1 state)) ?\{)
1097 (vera-backward-syntactic-ws) (= (char-before) ?,))
1099 (end-of-line) (= (char-before) ?,))))))
1100 (goto-char (1+ (nth 1 state)))
1101 ;; is there code after the opening parenthesis on the same line?
1102 (if (looking-at "\\s-*$")
1103 (vera-add-syntax 'arglist-cont (vera-point 'boi))
1104 (vera-add-syntax 'arglist-cont-nonempty (point))))
1105 ;; CASE 5: at a block closing?
1106 ((save-excursion (back-to-indentation) (looking-at vera-end-block-re))
1107 ;; look for the corresponding begin
1108 (vera-corresponding-begin)
1109 (vera-add-syntax 'block-close (vera-point 'boi)))
1110 ;; CASE 6: at a block intro (the first line after a block opening)?
1111 ((and (save-excursion
1112 (vera-backward-syntactic-ws nil t)
1113 ;; previous line ends with a block opening?
1114 (or (/= (skip-chars-backward "{") 0) (backward-word 1))
1115 (when (looking-at vera-beg-block-re)
1116 ;; go to beginning of substatement
1117 (vera-beginning-of-substatement)
1118 (setq placeholder (point))))
1119 ;; not if "fork" is followed by "{"
1121 (not (and (progn (back-to-indentation) (looking-at "{"))
1122 (progn (goto-char placeholder)
1123 (looking-at "\\<fork\\>"))))))
1124 (goto-char placeholder)
1125 (vera-add-syntax 'block-intro (vera-point 'boi)))
1126 ;; CASE 7: at the beginning of an else clause?
1127 ((save-excursion (back-to-indentation) (looking-at "\\<else\\>"))
1128 ;; find corresponding if
1129 (vera-corresponding-if)
1130 (vera-add-syntax 'else-clause (vera-point 'boi)))
1131 ;; CASE 8: at the beginning of a statement?
1132 ;; is the previous command completed?
1133 ((or (save-excursion
1134 (vera-backward-syntactic-ws nil t)
1135 (setq placeholder (point))
1136 ;; at the beginning of the buffer?
1138 ;; previous line ends with a semicolon or
1139 ;; is a block opening or closing?
1140 (when (or (/= (skip-chars-backward "{};") 0)
1141 (progn (back-to-indentation)
1142 (looking-at (concat vera-beg-block-re "\\|"
1143 vera-end-block-re))))
1144 ;; if at a block closing, go to beginning
1145 (when (looking-at vera-end-block-re)
1146 (vera-corresponding-begin))
1147 ;; go to beginning of the statement
1148 (vera-beginning-of-statement)
1149 (setq placeholder (point)))
1151 (when (progn (back-to-indentation) (looking-at "#"))
1152 ;; go to previous statement
1153 (vera-beginning-of-statement)
1154 (setq placeholder (point)))))
1155 ;; at a block opening?
1156 (when (save-excursion (back-to-indentation)
1157 (looking-at vera-beg-block-re))
1158 ;; go to beginning of the substatement
1159 (vera-beginning-of-substatement)
1160 (setq placeholder (point))))
1161 (goto-char placeholder)
1162 (vera-add-syntax 'statement (vera-point 'boi)))
1163 ;; CASE 9: at the beginning of a substatement?
1164 ;; is this line preceded by a substatement opening statement?
1165 ((save-excursion (vera-backward-syntactic-ws nil t)
1166 (when (= (preceding-char) ?\)) (backward-sexp))
1168 (setq placeholder (point))
1169 (looking-at vera-beg-substatement-re))
1170 (goto-char placeholder)
1171 (vera-add-syntax 'substatement (vera-point 'boi)))
1172 ;; CASE 10: it must be a statement continuation!
1174 ;; go to beginning of statement
1175 (vera-beginning-of-substatement)
1176 (vera-add-syntax 'statement-cont (vera-point 'boi))))
1177 ;; special case: look for a comment start
1178 (goto-char indent-point)
1179 (skip-chars-forward " \t")
1180 (when (looking-at comment-start)
1181 (vera-add-syntax 'comment-intro))
1185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1186 ;; indentation functions
1188 (defun vera-indent-line ()
1189 "Indent the current line as Vera code.
1190 Return the amount of indentation change (in columns)."
1192 (vera-prepare-search
1193 (let* ((syntax (vera-guess-basic-syntax))
1194 (pos (- (point-max) (point)))
1195 (indent (apply '+ (mapcar 'vera-get-offset syntax)))
1196 (shift-amt (- (current-indentation) indent)))
1197 (when vera-echo-syntactic-information-p
1198 (message "syntax: %s, indent= %d" syntax indent))
1199 (unless (zerop shift-amt)
1201 (delete-region (point) (vera-point 'boi))
1203 (if (< (point) (vera-point 'boi))
1204 (back-to-indentation)
1205 ;; If initial point was within line's indentation, position after
1206 ;; the indentation. Else stay at same point in text.
1207 (when (> (- (point-max) pos) (point))
1208 (goto-char (- (point-max) pos))))
1211 (defun vera-indent-buffer ()
1212 "Indent whole buffer as Vera code.
1213 Calls `indent-region' for whole buffer."
1215 (message "Indenting buffer...")
1216 (indent-region (point-min) (point-max) nil)
1217 (message "Indenting buffer...done"))
1219 (defun vera-indent-region (start end column)
1220 "Indent region as Vera code."
1221 (interactive "r\nP")
1222 (message "Indenting region...")
1223 (indent-region start end column)
1224 (message "Indenting region...done"))
1226 (defsubst vera-indent-block-closing ()
1227 "If previous word is a block closing or `else', indent line again."
1228 (when (= (char-syntax (preceding-char)) ?w)
1231 (when (and (not (vera-in-literal))
1232 (looking-at (concat vera-end-block-re "\\|\\<else\\>")))
1233 (indent-according-to-mode)))))
1235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1238 (defun vera-electric-tab (&optional prefix)
1239 "Do what I mean (indent, expand, tab, change indent, etc..).
1240 If preceding character is part of a word or a paren then `hippie-expand',
1241 else if right of non whitespace on line then `tab-to-tab-stop',
1242 else if last command was a tab or return then dedent one step or if a comment
1243 toggle between normal indent and inline comment indent,
1244 else indent `correctly'.
1245 If `vera-intelligent-tab' is nil, always indent line."
1247 (if vera-intelligent-tab
1249 (cond ((and (not (featurep 'xemacs)) (use-region-p))
1250 (vera-indent-region (region-beginning) (region-end) nil))
1251 ((memq (char-syntax (preceding-char)) '(?w ?_))
1252 (let ((case-fold-search t)
1254 (hippie-expand-only-buffers
1255 (or (and (boundp 'hippie-expand-only-buffers)
1256 hippie-expand-only-buffers)
1258 (vera-expand-abbrev prefix)))
1259 ((> (current-column) (current-indentation))
1261 ((and (or (eq last-command 'vera-electric-tab)
1262 (eq last-command 'vera-electric-return))
1263 (/= 0 (current-indentation)))
1264 (backward-delete-char-untabify vera-basic-offset nil))
1265 (t (indent-according-to-mode)))
1266 (setq this-command 'vera-electric-tab))
1267 (indent-according-to-mode)))
1269 (defun vera-electric-return ()
1270 "Insert newline and indent. Indent current line if it is a block closing."
1272 (vera-indent-block-closing)
1273 (newline-and-indent))
1275 (defun vera-electric-space (arg)
1276 "Insert a space. Indent current line if it is a block closing."
1279 (vera-indent-block-closing))
1280 (self-insert-command (prefix-numeric-value arg)))
1282 (defun vera-electric-opening-brace (arg)
1283 "Outdent opening brace."
1285 (self-insert-command (prefix-numeric-value arg))
1287 (indent-according-to-mode)))
1289 (defun vera-electric-closing-brace (arg)
1290 "Outdent closing brace."
1292 (self-insert-command (prefix-numeric-value arg))
1294 (indent-according-to-mode)))
1296 (defun vera-electric-pound (arg)
1297 "Insert `#' and indent as directive it first character of line."
1299 (self-insert-command (prefix-numeric-value arg))
1303 (skip-chars-backward " \t")
1305 (delete-horizontal-space)))))
1307 (defun vera-electric-star (arg)
1308 "Insert a star character. Nicked from `c-electric-star'."
1310 (self-insert-command (prefix-numeric-value arg))
1312 (memq (vera-in-literal) '(comment))
1313 (eq (char-before) ?*)
1316 (skip-chars-backward "*")
1317 (if (eq (char-before) ?/)
1319 (skip-chars-backward " \t")
1321 (indent-according-to-mode)))
1323 (defun vera-electric-slash (arg)
1324 "Insert a slash character. Nicked from `c-electric-slash'."
1326 (let* ((ch (char-before))
1327 (indentp (and (not arg)
1328 (eq last-command-event ?/)
1330 (not (vera-in-literal)))
1332 (vera-in-literal))))))
1333 (self-insert-command (prefix-numeric-value arg))
1335 (indent-according-to-mode))))
1338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1343 ;; Hippie expand customization (for expansion of Vera commands)
1345 (defvar vera-abbrev-list
1346 (append (list nil) vera-keywords
1347 (list nil) vera-types
1348 (list nil) vera-functions
1349 (list nil) vera-constants
1350 (list nil) vera-rvm-types
1351 (list nil) vera-rvm-functions
1352 (list nil) vera-rvm-constants)
1353 "Predefined abbreviations for Vera.")
1355 (defvar vera-expand-upper-case nil)
1357 (eval-when-compile (require 'hippie-exp))
1358 (declare-function he-init-string "hippie-exp" (beg end))
1359 (declare-function he-dabbrev-beg "hippie-exp" ())
1360 (declare-function he-string-member "hippie-exp" (str lst &optional trans-case))
1361 (declare-function he-reset-string "hippie-exp" ())
1362 (declare-function he-substitute-string "hippie-exp" (str &optional trans-case))
1364 (defun vera-try-expand-abbrev (old)
1365 "Try expanding abbreviations from `vera-abbrev-list'."
1367 (he-init-string (he-dabbrev-beg) (point))
1368 (setq he-expand-list
1369 (let ((abbrev-list vera-abbrev-list)
1370 (sel-abbrev-list '()))
1372 (when (or (not (stringp (car abbrev-list)))
1374 (concat "^" he-search-string) (car abbrev-list)))
1375 (setq sel-abbrev-list
1376 (cons (car abbrev-list) sel-abbrev-list)))
1377 (setq abbrev-list (cdr abbrev-list)))
1378 (nreverse sel-abbrev-list))))
1379 (while (and he-expand-list
1380 (or (not (stringp (car he-expand-list)))
1381 (he-string-member (car he-expand-list) he-tried-table t)))
1382 (unless (stringp (car he-expand-list))
1383 (setq vera-expand-upper-case (car he-expand-list)))
1384 (setq he-expand-list (cdr he-expand-list)))
1385 (if (null he-expand-list)
1386 (progn (when old (he-reset-string))
1388 (he-substitute-string
1389 (if vera-expand-upper-case
1390 (upcase (car he-expand-list))
1391 (car he-expand-list))
1393 (setq he-expand-list (cdr he-expand-list))
1396 ;; function for expanding abbrevs and dabbrevs
1397 (defalias 'vera-expand-abbrev
1398 (make-hippie-expand-function '(try-expand-dabbrev
1399 try-expand-dabbrev-all-buffers
1400 vera-try-expand-abbrev)))
1402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1405 (defun vera-comment-uncomment-region (beg end &optional _arg)
1406 "Comment region if not commented, uncomment region if already commented."
1407 (interactive "r\nP")
1409 (if (looking-at comment-start-skip)
1410 (comment-region beg end '(4))
1411 (comment-region beg end)))
1413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1416 (defun vera-customize ()
1417 "Call the customize function with `vera' as argument."
1419 (customize-group 'vera))
1421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1424 ;; remove ".vr" from `completion-ignored-extensions'
1425 (setq completion-ignored-extensions
1426 (delete ".vr" completion-ignored-extensions))
1429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1431 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1433 (defconst vera-mode-help-address
1434 "Reto Zimmermann <reto@gnu.org>, bug-gnu-emacs@gnu.org"
1435 "Address for Vera Mode bug reports.")
1437 ;; get reporter-submit-bug-report when byte-compiling
1439 (require 'reporter))
1441 (defun vera-submit-bug-report ()
1442 "Submit via mail a bug report on Vera Mode."
1446 (y-or-n-p "Do you want to submit a report on Vera Mode? ")
1448 (let ((reporter-prompt-for-summary-p t))
1449 (reporter-submit-bug-report
1450 vera-mode-help-address
1451 (concat "Vera Mode " vera-version)
1453 ;; report all important variables
1455 'vera-underscore-is-part-of-word
1456 'vera-intelligent-tab
1462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1466 (defun vera-version ()
1467 "Echo the current version of Vera Mode in the minibuffer."
1469 (message "Vera Mode %s (%s)" vera-version vera-time-stamp))
1472 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1474 (provide 'vera-mode)
1476 ;;; vera-mode.el ends here