1 ;;; vera-mode.el --- major mode for editing Vera files
3 ;; Copyright (C) 1997-2012 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."
105 (defcustom vera-intelligent-tab t
106 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
107 That is, if preceding character is part of a word then complete word,
108 else if not at beginning of line then insert tab,
109 else if last command was a `TAB' or `RET' then dedent one step,
110 else indent current line.
111 If nil, TAB always indents current line."
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
123 (defvar vera-mode-map
124 (let ((map (make-sparse-keymap)))
125 ;; Backspace/delete key bindings.
126 (define-key map
[backspace] 'backward-delete-char-untabify)
127 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
128 (define-key map [delete] 'delete-char)
129 (define-key map [(meta delete)] 'kill-word))
130 ;; Standard key bindings.
131 (define-key map "\M-e" 'vera-forward-statement)
132 (define-key map "\M-a" 'vera-backward-statement)
133 (define-key map "\M-\C-e" 'vera-forward-same-indent)
134 (define-key map "\M-\C-a" 'vera-backward-same-indent)
135 ;; Mode specific key bindings.
136 (define-key map "\C-c\t" 'indent-according-to-mode)
137 (define-key map "\M-\C-\\" 'vera-indent-region)
138 (define-key map "\C-c\C-c" 'vera-comment-uncomment-region)
139 (define-key map "\C-c\C-f" 'vera-fontify-buffer)
140 (define-key map "\C-c\C-v" 'vera-version)
141 (define-key map "\M-\t" 'tab-to-tab-stop)
142 ;; Electric key bindings.
143 (define-key map "\t" 'vera-electric-tab)
144 (define-key map "\r" 'vera-electric-return)
145 (define-key map " " 'vera-electric-space)
146 (define-key map "{" 'vera-electric-opening-brace)
147 (define-key map "}" 'vera-electric-closing-brace)
148 (define-key map "#" 'vera-electric-pound)
149 (define-key map "*" 'vera-electric-star)
150 (define-key map "/" 'vera-electric-slash)
152 "Keymap for Vera Mode.")
154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 (easy-menu-define vera-mode-menu vera-mode-map
160 "Menu keymap for Vera Mode."
162 ["(Un)Comment Out Region" vera-comment-uncomment-region (mark)]
164 ["Move Forward Statement" vera-forward-statement t]
165 ["Move Backward Statement" vera-backward-statement t]
166 ["Move Forward Same Indent" vera-forward-same-indent t]
167 ["Move Backward Same Indent" vera-backward-same-indent t]
169 ["Indent Line" indent-according-to-mode t]
170 ["Indent Region" vera-indent-region (mark)]
171 ["Indent Buffer" vera-indent-buffer t]
173 ["Fontify Buffer" vera-fontify-buffer t]
175 ["Documentation" describe-mode]
176 ["Version" vera-version t]
177 ["Bug Report..." vera-submit-bug-report t]
180 ["Indentation Offset..." (customize-option 'vera-basic-offset) t]
181 ["Underscore is Part of Word"
182 (customize-set-variable 'vera-underscore-is-part-of-word
183 (not vera-underscore-is-part-of-word))
184 :style toggle :selected vera-underscore-is-part-of-word]
185 ["Use Intelligent Tab"
186 (customize-set-variable 'vera-intelligent-tab
187 (not vera-intelligent-tab))
188 :style toggle :selected vera-intelligent-tab]
190 ["Save Options" customize-save-customized t]
192 ["Customize..." vera-customize t])))
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197 (defvar vera-mode-syntax-table
198 (let ((syntax-table (make-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 (modify-syntax-entry ?\\ "." syntax-table)
216 (modify-syntax-entry ?\| "." syntax-table)
218 (modify-syntax-entry ?\" "\"" syntax-table)
220 (when vera-underscore-is-part-of-word
221 (modify-syntax-entry ?\_ "w" syntax-table))
223 (modify-syntax-entry ?\\ "\\" syntax-table)
224 ;; parentheses to match
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 (modify-syntax-entry ?\{ "(}" syntax-table)
230 (modify-syntax-entry ?\} "){" syntax-table)
232 (if (featurep 'xemacs)
233 (modify-syntax-entry ?\/ ". 1456" syntax-table) ; XEmacs
234 (modify-syntax-entry ?\/ ". 124b" syntax-table)) ; Emacs
235 (modify-syntax-entry ?\* ". 23" syntax-table)
237 (modify-syntax-entry ?\n "> b" syntax-table)
238 (modify-syntax-entry ?\^M "> b" syntax-table)
240 "Syntax table used in `vera-mode' buffers.")
242 (defvar vera-mode-ext-syntax-table
243 (let ((syntax-table (copy-syntax-table vera-mode-syntax-table)))
244 ;; extended syntax table including '_' (for simpler search regexps)
245 (modify-syntax-entry ?_ "w" syntax-table)
247 "Syntax table extended by `_' used in `vera-mode' buffers.")
249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 ;;;###autoload (add-to-list 'auto-mode-alist (cons (purecopy "\\.vr[hi]?\\'") 'vera-mode))
255 (define-derived-mode vera-mode prog-mode "Vera"
256 "Major mode for editing Vera code.
261 INDENTATION: Typing `TAB' at the beginning of a line indents the line.
262 The amount of indentation is specified by option `vera-basic-offset'.
263 Indentation can be done for an entire region \(`M-C-\\') or buffer (menu).
264 `TAB' always indents the line if option `vera-intelligent-tab' is nil.
266 WORD/COMMAND COMPLETION: Typing `TAB' after a (not completed) word looks
267 for a word in the buffer or a Vera keyword that starts alike, inserts it
268 and adjusts case. Re-typing `TAB' toggles through alternative word
271 Typing `TAB' after a non-word character inserts a tabulator stop (if not
272 at the beginning of a line). `M-TAB' always inserts a tabulator stop.
274 COMMENTS: `C-c C-c' comments out a region if not commented out, and
275 uncomments a region if already commented out.
277 HIGHLIGHTING (fontification): Vera keywords, predefined types and
278 constants, function names, declaration names, directives, as well as
279 comments and strings are highlighted using different colors.
281 VERA VERSION: OpenVera 1.4 and Vera version 6.2.8.
287 To submit a bug report, use the corresponding menu entry within Vera Mode.
288 Add a description of the problem and include a reproducible test case.
290 Feel free to send questions and enhancement requests to <reto@gnu.org>.
292 Official distribution is at
293 URL `http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html'
296 The Vera Mode Maintainer
297 Reto Zimmermann <reto@gnu.org>
303 ;; set local variables
305 (set (make-local-variable 'comment-start) "//")
306 (set (make-local-variable 'comment-end) "")
307 (set (make-local-variable 'comment-column) 40)
308 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *")
309 (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *\n")
310 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
311 (set (make-local-variable 'paragraph-start) "^$")
312 (set (make-local-variable 'paragraph-separate) paragraph-start)
313 (set (make-local-variable 'indent-tabs-mode) nil)
314 (set (make-local-variable 'indent-line-function) 'vera-indent-line)
315 (set (make-local-variable 'parse-sexp-ignore-comments) t)
316 ;; initialize font locking
317 (set (make-local-variable 'font-lock-defaults)
318 '(vera-font-lock-keywords nil nil ((?\_ . "w"))))
320 (easy-menu-add vera-mode-menu)
322 (message "Vera Mode %s. Type C-c C-h for documentation." vera-version))
325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
332 (defconst vera-keywords
334 "after" "all" "any" "around" "assoc_index" "assoc_size" "async"
335 "bad_state" "bad_trans" "before" "begin" "big_endian" "bind"
336 "bin_activation" "bit_normal" "bit_reverse" "break" "breakpoint"
337 "case" "casex" "casez" "class" "constraint" "continue"
338 "coverage" "coverage_block" "coverage_def" "coverage_depth"
339 "coverage_goal" "coverage_group" "coverage_option" "coverage_val"
340 "cross_num_print_missing" "cross_auto_bin_max" "cov_comment"
341 "default" "depth" "dist" "do"
342 "else" "end" "enum" "exhaustive" "export" "extends" "extern"
343 "for" "foreach" "fork" "function"
344 "hdl_task" "hdl_node" "hide"
345 "if" "illegal_self_transition" "illegal_state" "illegal_transition"
346 "in" "interface" "invisible"
348 "little_endian" "local"
349 "m_bad_state" "m_bad_trans" "m_state" "m_trans"
350 "negedge" "new" "newcov" "non_rand" "none" "not" "null"
352 "packed" "port" "posedge" "proceed" "prod" "prodget" "prodset"
353 "program" "protected" "public"
354 "rand" "randc" "randcase" "randseq" "repeat" "return" "rules"
355 "sample" "sample_event" "shadow" "soft" "state" "static" "super"
356 "task" "terminate" "this" "trans" "typedef"
358 "var" "vca" "vector" "verilog_node" "verilog_task"
359 "vhdl_node" "vhdl_task" "virtual" "virtuals" "visible" "void"
360 "while" "wildcard" "with"
362 "List of Vera keywords.")
366 "integer" "bit" "reg" "string" "bind_var" "event"
367 "inout" "input" "output"
369 "NDRIVE" "NHOLD" "NRX" "NRZ" "NR0" "NR1" "NSAMPLE"
370 "PDRIVE" "PHOLD" "PRX" "PRZ" "PR0" "PR1" "PSAMPLE"
372 "List of Vera predefined types.")
374 (defconst vera-q-values
376 "gnr" "grx" "grz" "gr0" "gr1"
377 "nr" "rx" "rz" "r0" "r1"
378 "snr" "srx" "srz" "sr0" "sr1"
380 "List of Vera predefined VCA q_values.")
382 (defconst vera-functions
384 ;; system functions and tasks
386 "call_func" "call_task" "cast_assign" "close_conn" "cm_coverage"
387 "cm_get_coverage" "cm_get_limit"
388 "coverage_backup_database_file" "coverage_save_database"
390 "error" "error_mode" "error_wait" "exit"
391 "fclose" "feof" "ferror" "fflush" "flag" "fopen" "fprintf" "freadb"
392 "freadb" "freadh" "freadstr"
393 "get_bind" "get_bind_id" "get_conn_err" "get_cycle" "get_env"
394 "get_memsize" "get_plus_arg" "get_systime" "get_time" "get_time_unit"
398 "mailbox_get" "mailbox_put" "mailbox_receive" "mailbox_send"
399 "make_client" "make_server"
402 "query" "query_str" "query_x"
403 "rand48" "random" "region_enter" "region_exit" "rewind"
404 "semaphore_get" "semaphore_put" "setstate" "signal_connect" "simwave_plot"
405 "srandom" "sprintf" "sscanf" "stop" "suspend_thread" "sync"
406 "timeout" "trace" "trigger"
407 "unit_delay" "unlock_file" "up_connections"
408 "urand48" "urandom" "urandom_range"
409 "vera_bit_reverse" "vera_crc" "vera_pack" "vera_pack_big_endian"
410 "vera_plot" "vera_report_profile" "vera_unpack" "vera_unpack_big_endian"
411 "vsv_call_func" "vsv_call_task" "vsv_close_conn" "vsv_get_conn_err"
412 "vsv_make_client" "vsv_make_server" "vsv_up_connections"
413 "vsv_wait_for_done" "vsv_wait_for_input"
414 "wait_child" "wait_var"
416 "Configure" "DisableTrigger" "DoAction" "EnableCount" "EnableTrigger"
417 "Event" "GetAssert" "GetCount" "GetFirstAssert" "GetName" "GetNextAssert"
419 "atobin" "atohex" "atoi" "atooct"
420 "backref" "bittostr" "capacity" "compare" "constraint_mode"
423 "find" "find_index" "first" "first_index"
424 "get_at_least" "get_auto_bin" "get_cov_weight" "get_coverage_goal"
425 "get_cross_bin_max" "get_status" "get_status_msg" "getc"
427 "icompare" "insert" "inst_get_at_least" "inst_get_auto_bin_max"
428 "inst_get_collect" "inst_get_cov_weight" "inst_get_coverage_goal"
429 "inst_getcross_bin_max" "inst_query" "inst_set_at_least"
430 "inst_set_auto_bin_max" "inst_set_bin_activation" "inst_set_collect"
431 "inst_set_cov_weight" "inst_set_coverage_goal" "inst_set_cross_bin_max"
433 "last" "last_index" "len" "load"
434 "match" "max" "max_index" "min" "min_index"
435 "object_compare" "object_copy" "object_print"
436 "pack" "pick_index" "pop_back" "pop_front" "post_pack" "post_randomize"
437 "post_unpack" "postmatch" "pre_pack" "pre_randomize" "prematch" "push_back"
440 "rand_mode" "randomize" "reserve" "reverse" "rsort"
441 "search" "set_at_least" "set_auto_bin_max" "set_bin_activation"
442 "set_cov_weight" "set_coverage_goal" "set_cross_bin_max" "set_name" "size"
443 "sort" "substr" "sum"
444 "thismatch" "tolower" "toupper"
445 "unique_index" "unpack"
447 "new" "object_compare"
448 "post_boundary" "post_pack" "post_randomize" "post_unpack" "pre-randomize"
449 "pre_boundary" "pre_pack" "pre_unpack"
451 "List of Vera predefined system functions, tasks and class methods.")
453 (defconst vera-constants
456 "BAD_STATE" "BAD_TRANS"
457 "CALL" "CHECK" "CHGEDGE" "CLEAR" "COPY_NO_WAIT" "COPY_WAIT"
458 "CROSS" "CROSS_TRANS"
460 "EC_ARRAYX" "EC_CODE_END" "EC_CONFLICT" "EC_EVNTIMOUT" "EC_EXPECT"
461 "EC_FULLEXPECT" "EC_MBXTMOUT" "EC_NEXPECT" "EC_RETURN" "EC_RGNTMOUT"
462 "EC_SCONFLICT" "EC_SEMTMOUT" "EC_SEXPECT" "EC_SFULLEXPECT" "EC_SNEXTPECT"
463 "EC_USERSET" "EQ" "EVENT"
464 "FAIL" "FIRST" "FORK"
465 "GE" "GOAL" "GT" "HAND_SHAKE" "HI" "HIGH" "HNUM"
466 "LE" "LIC_EXIT" "LIC_PRERR" "LIC_PRWARN" "LIC_WAIT" "LO" "LOAD" "LOW" "LT"
468 "NAME" "NE" "NEGEDGE" "NEXT" "NO_OVERLAP" "NO_OVERLAP_STATE"
469 "NO_OVERLAP_TRANS" "NO_VARS" "NO_WAIT" "NUM" "NUM_BIN" "NUM_DET"
470 "OFF" "OK" "OK_LAST" "ON" "ONE_BLAST" "ONE_SHOT" "ORDER"
471 "PAST_IT" "PERCENT" "POSEDGE" "PROGRAM"
472 "RAWIN" "REGION" "REPORT"
473 "SAMPLE" "SAVE" "SEMAPHORE" "SET" "SILENT" "STATE" "STR"
474 "STR_ERR_OUT_OF_RANGE" "STR_ERR_REGEXP_SYNTAX" "SUM"
478 "stderr" "stdin" "stdout"
480 "List of Vera predefined constants.")
482 (defconst vera-rvm-types
484 "VeraListIterator_VeraListIterator_rvm_log"
485 "VeraListIterator_rvm_data" "VeraListIterator_rvm_log"
486 "VeraListNodeVeraListIterator_rvm_log" "VeraListNodervm_data"
487 "VeraListNodervm_log" "VeraList_VeraListIterator_rvm_log"
488 "VeraList_rvm_data" "VeraList_rvm_log"
489 "rvm_broadcast" "rvm_channel_class" "rvm_data" "rvm_data" "rvm_env"
490 "rvm_log" "rvm_log_modifier" "rvm_log_msg" "rvm_log_msg" "rvm_log_msg_info"
491 "rvm_log_watchpoint" "rvm_notify" "rvm_notify_event"
492 "rvm_notify_event_config" "rvm_scheduler" "rvm_scheduler_election"
493 "rvm_watchdog" "rvm_watchdog_port" "rvm_xactor" "rvm_xactor_callbacks"
495 "List of Vera-RVM keywords.")
497 (defconst vera-rvm-functions
499 "extern_rvm_atomic_gen" "extern_rvm_channel" "extern_rvm_scenario_gen"
500 "rvm_OO_callback" "rvm_atomic_gen" "rvm_atomic_gen_callbacks_decl"
501 "rvm_atomic_gen_decl" "rvm_atomic_scenario_decl" "rvm_channel"
502 "rvm_channel_" "rvm_channel_decl" "rvm_command" "rvm_cycle" "rvm_debug"
503 "rvm_error" "rvm_fatal" "rvm_note" "rvm_protocol" "rvm_report"
504 "rvm_scenario_decl" "rvm_scenario_election_decl" "rvm_scenario_gen"
505 "rvm_scenario_gen_callbacks_decl" "rvm_scenario_gen_decl"
506 "rvm_trace" "rvm_transaction" "rvm_user" "rvm_verbose" "rvm_warning"
508 "List of Vera-RVM functions.")
510 (defconst vera-rvm-constants
512 "RVM_NUMERIC_VERSION_MACROS" "RVM_VERSION" "RVM_MINOR" "RVM_PATCH"
513 "rvm_channel__SOURCE" "rvm_channel__SINK" "rvm_channel__NO_ACTIVE"
514 "rvm_channel__ACT_PENDING" "rvm_channel__ACT_STARTED"
515 "rvm_channel__ACT_COMPLETED" "rvm_channel__FULL" "rvm_channel__EMPTY"
516 "rvm_channel__PUT" "rvm_channel__GOT" "rvm_channel__PEEKED"
517 "rvm_channel__ACTIVATED" "rvm_channel__STARTED" "rvm_channel__COMPLETED"
518 "rvm_channel__REMOVED" "rvm_channel__LOCKED" "rvm_channel__UNLOCKED"
519 "rvm_data__EXECUTE" "rvm_data__STARTED" "rvm_data__ENDED"
520 "rvm_env__CFG_GENED" "rvm_env__BUILT" "rvm_env__DUT_CFGED"
521 "rvm_env__STARTED" "rvm_env__RESTARTED" "rvm_env__ENDED" "rvm_env__STOPPED"
522 "rvm_env__CLEANED" "rvm_env__DONE" "rvm_log__DEFAULT" "rvm_log__UNCHANGED"
523 "rvm_log__FAILURE_TYP" "rvm_log__NOTE_TYP" "rvm_log__DEBUG_TYP"
524 "rvm_log__REPORT_TYP" "rvm_log__NOTIFY_TYP" "rvm_log__TIMING_TYP"
525 "rvm_log__XHANDLING_TYP" "rvm_log__PROTOCOL_TYP" "rvm_log__TRANSACTION_TYP"
526 "rvm_log__COMMAND_TYP" "rvm_log__CYCLE_TYP" "rvm_log__USER_TYP_0"
527 "rvm_log__USER_TYP_1" "rvm_log__USER_TYP_2" "rvm_log__USER_TYP_3"
528 "rvm_log__DEFAULT_TYP" "rvm_log__ALL_TYPES" "rvm_log__FATAL_SEV"
529 "rvm_log__ERROR_SEV" "rvm_log__WARNING_SEV" "rvm_log__NORMAL_SEV"
530 "rvm_log__TRACE_SEV" "rvm_log__DEBUG_SEV" "rvm_log__VERBOSE_SEV"
531 "rvm_log__HIDDEN_SEV" "rvm_log__IGNORE_SEV" "rvm_log__DEFAULT_SEV"
532 "rvm_log__ALL_SEVERITIES" "rvm_log__CONTINUE" "rvm_log__COUNT_AS_ERROR"
533 "rvm_log__DEBUGGER" "rvm_log__DUMP" "rvm_log__STOP" "rvm_log__ABORT"
534 "rvm_notify__ONE_SHOT_TRIGGER" "rvm_notify__ONE_BLAST_TRIGGER"
535 "rvm_notify__HAND_SHAKE_TRIGGER" "rvm_notify__ON_OFF_TRIGGER"
536 "rvm_xactor__XACTOR_IDLE" "rvm_xactor__XACTOR_BUSY"
537 "rvm_xactor__XACTOR_STARTED" "rvm_xactor__XACTOR_STOPPED"
538 "rvm_xactor__XACTOR_RESET" "rvm_xactor__XACTOR_SOFT_RST"
539 "rvm_xactor__XACTOR_FIRM_RST" "rvm_xactor__XACTOR_HARD_RST"
540 "rvm_xactor__XACTOR_PROTOCOL_RST" "rvm_broadcast__AFAP"
541 "rvm_broadcast__ALAP" "rvm_watchdog__TIMEOUT"
542 "rvm_env__DUT_RESET" "rvm_log__INTERNAL_TYP"
543 "RVM_SCHEDULER_IS_XACTOR" "RVM_BROADCAST_IS_XACTOR"
545 "List of Vera-RVM predefined constants.")
547 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
548 (unless (fboundp 'regexp-opt)
549 (defun regexp-opt (strings &optional paren)
550 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
551 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
553 (defconst vera-keywords-regexp
554 (concat "\\<\\(" (regexp-opt vera-keywords) "\\)\\>")
555 "Regexp for Vera keywords.")
557 (defconst vera-types-regexp
558 (concat "\\<\\(" (regexp-opt vera-types) "\\)\\>")
559 "Regexp for Vera predefined types.")
561 (defconst vera-q-values-regexp
562 (concat "\\<\\(" (regexp-opt vera-q-values) "\\)\\>")
563 "Regexp for Vera predefined VCA q_values.")
565 (defconst vera-functions-regexp
566 (concat "\\<\\(" (regexp-opt vera-functions) "\\)\\>")
567 "Regexp for Vera predefined system functions, tasks and class methods.")
569 (defconst vera-constants-regexp
570 (concat "\\<\\(" (regexp-opt vera-constants) "\\)\\>")
571 "Regexp for Vera predefined constants.")
573 (defconst vera-rvm-types-regexp
574 (concat "\\<\\(" (regexp-opt vera-rvm-types) "\\)\\>")
575 "Regexp for Vera-RVM keywords.")
577 (defconst vera-rvm-functions-regexp
578 (concat "\\<\\(" (regexp-opt vera-rvm-functions) "\\)\\>")
579 "Regexp for Vera-RVM predefined system functions, tasks and class methods.")
581 (defconst vera-rvm-constants-regexp
582 (concat "\\<\\(" (regexp-opt vera-rvm-constants) "\\)\\>")
583 "Regexp for Vera-RVM predefined constants.")
586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
588 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
590 ;; XEmacs compatibility
591 (when (featurep 'xemacs)
593 (copy-face 'font-lock-reference-face 'font-lock-constant-face)
594 (copy-face 'font-lock-preprocessor-face 'font-lock-builtin-face))
596 (defun vera-font-lock-match-item (limit)
597 "Match, and move over, any declaration item after point.
598 Adapted from `font-lock-match-c-style-declaration-item-and-skip-to-next'."
601 (narrow-to-region (point-min) limit)
603 (when (looking-at "\\s-*\\(\\w+\\)")
605 (goto-char (match-end 1))
607 (if (looking-at "\\(\\s-*\\(\\[[^]]*\\]\\s-*\\)?,\\)")
608 (goto-char (match-end 1))
612 (defvar vera-font-lock-keywords
614 ;; highlight keywords
615 (list vera-keywords-regexp 1 'font-lock-keyword-face)
617 (list vera-types-regexp 1 'font-lock-type-face)
618 ;; highlight RVM types
619 (list vera-rvm-types-regexp 1 'font-lock-type-face)
620 ;; highlight constants
621 (list vera-constants-regexp 1 'font-lock-constant-face)
622 ;; highlight RVM constants
623 (list vera-rvm-constants-regexp 1 'font-lock-constant-face)
624 ;; highlight q_values
625 (list vera-q-values-regexp 1 'font-lock-constant-face)
626 ;; highlight predefined functions, tasks and methods
627 (list vera-functions-regexp 1 'vera-font-lock-function)
628 ;; highlight predefined RVM functions
629 (list vera-rvm-functions-regexp 1 'vera-font-lock-function)
630 ;; highlight functions
631 '("\\<\\(\\w+\\)\\s-*(" 1 font-lock-function-name-face)
632 ;; highlight various declaration names
633 '("^\\s-*\\(port\\|program\\|task\\)\\s-+\\(\\w+\\)\\>"
634 2 font-lock-function-name-face)
635 '("^\\s-*bind\\s-+\\(\\w+\\)\\s-+\\(\\w+\\)\\>"
636 (1 font-lock-function-name-face) (2 font-lock-function-name-face))
637 ;; highlight interface declaration names
638 '("^\\s-*\\(class\\|interface\\)\\s-+\\(\\w+\\)\\>"
639 2 vera-font-lock-interface)
640 ;; highlight variable name definitions
641 (list (concat "^\\s-*" vera-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
642 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
643 (list (concat "^\\s-*" vera-rvm-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
644 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
646 '("\\([0-9]*'[bdoh][0-9a-fA-FxXzZ_]+\\)" 1 vera-font-lock-number)
647 ;; highlight filenames in #include directives
648 '("^#\\s-*include\\s-*\\(<[^>\"\n]*>?\\)"
649 1 font-lock-string-face)
650 ;; highlight directives and directive names
651 '("^#\\s-*\\(\\w+\\)\\>[ \t!]*\\(\\w+\\)?"
652 (1 font-lock-builtin-face) (2 font-lock-variable-name-face nil t))
653 ;; highlight `@', `$' and `#'
654 '("\\([@$#]\\)" 1 font-lock-keyword-face)
655 ;; highlight @ and # definitions
656 '("@\\s-*\\(\\w*\\)\\(\\s-*,\\s-*\\(\\w+\\)\\)?\\>[^.]"
657 (1 vera-font-lock-number) (3 vera-font-lock-number nil t))
658 ;; highlight interface signal name
659 '("\\(\\w+\\)\\.\\w+" 1 vera-font-lock-interface)
661 "Regular expressions to highlight in Vera Mode.")
663 (defvar vera-font-lock-number 'vera-font-lock-number
664 "Face name to use for @ definitions.")
666 (defvar vera-font-lock-function 'vera-font-lock-function
667 "Face name to use for predefined functions and tasks.")
669 (defvar vera-font-lock-interface 'vera-font-lock-interface
670 "Face name to use for interface names.")
672 (defface vera-font-lock-number
673 '((((class color) (background light)) (:foreground "Gold4"))
674 (((class color) (background dark)) (:foreground "BurlyWood1"))
675 (t (:italic t :bold t)))
676 "Font lock mode face used to highlight @ definitions."
677 :group 'font-lock-highlighting-faces)
679 (defface vera-font-lock-function
680 '((((class color) (background light)) (:foreground "DarkCyan"))
681 (((class color) (background dark)) (:foreground "Orchid1"))
682 (t (:italic t :bold t)))
683 "Font lock mode face used to highlight predefined functions and tasks."
684 :group 'font-lock-highlighting-faces)
686 (defface vera-font-lock-interface
687 '((((class color) (background light)) (:foreground "Grey40"))
688 (((class color) (background dark)) (:foreground "Grey80"))
689 (t (:italic t :bold t)))
690 "Font lock mode face used to highlight interface names."
691 :group 'font-lock-highlighting-faces)
693 (defalias 'vera-fontify-buffer 'font-lock-fontify-buffer)
695 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
699 (defvar vera-echo-syntactic-information-p nil
700 "If non-nil, syntactic info is echoed when the line is indented.")
702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
705 (defconst vera-offsets-alist
706 '((comment . vera-lineup-C-comments)
707 (comment-intro . vera-lineup-comment)
715 (arglist-cont-nonempty . 0)
721 "Association list of syntactic element symbols and indentation offsets.
722 Adapted from `c-offsets-alist'.")
724 (defun vera-evaluate-offset (offset langelem symbol)
725 "OFFSET can be a number, a function, a variable, a list, or one of
728 ((eq offset '+) (setq offset vera-basic-offset))
729 ((eq offset '-) (setq offset (- vera-basic-offset)))
730 ((eq offset '++) (setq offset (* 2 vera-basic-offset)))
731 ((eq offset '--) (setq offset (* 2 (- vera-basic-offset))))
732 ((eq offset '*) (setq offset (/ vera-basic-offset 2)))
733 ((eq offset '/) (setq offset (/ (- vera-basic-offset) 2)))
734 ((functionp offset) (setq offset (funcall offset langelem)))
738 (while (and (not done) offset)
739 (setq done (vera-evaluate-offset (car offset) langelem symbol)
740 offset (cdr offset)))
744 ((not (numberp offset)) (setq offset (symbol-value offset))))
747 (defun vera-get-offset (langelem)
748 "Get offset from LANGELEM which is a cons cell of the form:
749 \(SYMBOL . RELPOS). The symbol is matched against
750 vera-offsets-alist and the offset found there is either returned,
751 or added to the indentation at RELPOS. If RELPOS is nil, then
752 the offset is simply returned."
753 (let* ((symbol (car langelem))
754 (relpos (cdr langelem))
755 (match (assq symbol vera-offsets-alist))
756 (offset (cdr-safe match)))
760 (setq offset (vera-evaluate-offset offset langelem symbol)))
762 (< relpos (line-beginning-position)))
767 (vera-evaluate-offset offset langelem symbol))))
769 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
772 (defsubst vera-point (position)
773 "Return the value of point at certain commonly referenced POSITIONs.
774 POSITION can be one of the following symbols:
775 bol -- beginning of line
777 boi -- back to indentation
778 ionl -- indentation of next line
779 iopl -- indentation of previous line
780 bonl -- beginning of next line
781 bopl -- beginning of previous line
782 This function does not modify point or mark."
785 ((eq position 'bol) (beginning-of-line))
786 ((eq position 'eol) (end-of-line))
787 ((eq position 'boi) (back-to-indentation))
788 ((eq position 'bonl) (forward-line 1))
789 ((eq position 'bopl) (forward-line -1))
790 ((eq position 'iopl) (forward-line -1) (back-to-indentation))
791 ((eq position 'ionl) (forward-line 1) (back-to-indentation))
792 (t (error "Unknown buffer position requested: %s" position)))
795 (defun vera-in-literal (&optional lim)
796 "Determine if point is in a Vera literal."
798 (let ((state (parse-partial-sexp (or lim (point-min)) (point))))
800 ((nth 3 state) 'string)
801 ((nth 4 state) 'comment)
804 (defun vera-skip-forward-literal ()
805 "Skip forward literal and return t if within one."
806 (let ((state (save-excursion
807 (if (fboundp 'syntax-ppss)
809 (parse-partial-sexp (point-min) (point))))))
811 ;; Inside a string or comment.
812 (goto-char (nth 8 state))
815 (condition-case nil (forward-sexp 1)
816 ;; Can't find end of string: it extends til end of buffer.
817 (error (goto-char (point-max))))
822 (defun vera-skip-backward-literal ()
823 "Skip backward literal and return t if within one."
824 (let ((state (save-excursion
825 (if (fboundp 'syntax-ppss)
827 (parse-partial-sexp (point-min) (point))))))
829 ;; Inside a string or comment.
830 (goto-char (nth 8 state))
833 (defsubst vera-re-search-forward (regexp &optional bound noerror)
834 "Like `re-search-forward', but skips over matches in literals."
836 (while (and (setq ret (re-search-forward regexp bound noerror))
837 (vera-skip-forward-literal)
838 (if bound (< (point) bound) t)))
841 (defsubst vera-re-search-backward (regexp &optional bound noerror)
842 "Like `re-search-backward', but skips over matches in literals."
844 (while (and (setq ret (re-search-backward regexp bound noerror))
845 (vera-skip-backward-literal)
846 (if bound (> (point) bound) t)))
849 (defun vera-forward-syntactic-ws (&optional lim skip-directive)
850 "Forward skip of syntactic whitespace."
852 (let* ((lim (or lim (point-max)))
854 (hugenum (point-max)))
855 (narrow-to-region (point) lim)
856 (while (/= here (point))
858 (forward-comment hugenum)
859 (when (and skip-directive (looking-at "^\\s-*#"))
862 (defun vera-backward-syntactic-ws (&optional lim skip-directive)
863 "Backward skip over syntactic whitespace."
865 (let* ((lim (or lim (point-min)))
867 (hugenum (- (point-max))))
868 (when (< lim (point))
869 (narrow-to-region lim (point))
870 (while (/= here (point))
872 (forward-comment hugenum)
873 (when (and skip-directive
874 (save-excursion (back-to-indentation)
875 (= (following-char) ?\#)))
876 (beginning-of-line)))))))
878 (defmacro vera-prepare-search (&rest body)
879 "Execute BODY with a syntax table that includes '_'."
880 `(with-syntax-table vera-mode-ext-syntax-table ,@body))
882 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
883 ;; comment indentation functions
885 (defsubst vera-langelem-col (langelem &optional preserve-point)
886 "Convenience routine to return the column of LANGELEM's relpos.
887 Leaves point at the relpos unless PRESERVE-POINT is non-nil."
888 (let ((here (point)))
889 (goto-char (cdr langelem))
890 (prog1 (current-column)
894 (defun vera-lineup-C-comments (langelem)
895 "Line up C block comment continuation lines.
896 Nicked from `c-lineup-C-comments'."
899 (stars (progn (back-to-indentation)
900 (skip-chars-forward "*")))
901 (langelem-col (vera-langelem-col langelem)))
902 (back-to-indentation)
903 (if (not (re-search-forward "/\\([*]+\\)" (vera-point 'eol) t))
905 (if (not (looking-at "[*]+"))
907 ;; we now have to figure out where this comment begins.
909 (back-to-indentation)
910 (if (looking-at "[*]+/")
911 (progn (goto-char (match-end 0))
912 (forward-comment -1))
913 (goto-char (cdr langelem))
914 (back-to-indentation))))
915 (- (current-column) langelem-col))
918 (skip-chars-forward " \t")
919 (- (current-column) langelem-col))
920 ;; how many stars on comment opening line? if greater than
921 ;; on current line, align left. if less than or equal,
922 ;; align right. this should also pick up Javadoc style
924 (if (> (length (match-string 1)) stars)
926 (back-to-indentation)
927 (- (current-column) -1 langelem-col))
928 (- (current-column) stars langelem-col)))))))
930 (defun vera-lineup-comment (langelem)
931 "Line up a comment start."
933 (back-to-indentation)
935 ;; not indent if at beginning of line
937 ;; otherwise indent accordingly
938 (goto-char (cdr langelem))
941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
944 (defconst vera-beg-block-re "{\\|\\<\\(begin\\|fork\\)\\>")
946 (defconst vera-end-block-re "}\\|\\<\\(end\\|join\\(\\s-+\\(all\\|any\\|none\\)\\)?\\)\\>")
948 (defconst vera-beg-substatement-re "\\<\\(else\\|for\\|if\\|repeat\\|while\\)\\>")
950 (defun vera-corresponding-begin (&optional recursive)
951 "Find corresponding block begin if cursor is at a block end."
952 (while (and (vera-re-search-backward
953 (concat "\\(" vera-end-block-re "\\)\\|" vera-beg-block-re)
956 (vera-corresponding-begin t))
957 (unless recursive (vera-beginning-of-substatement)))
959 (defun vera-corresponding-if ()
960 "Find corresponding `if' if cursor is at `else'."
961 (while (and (vera-re-search-backward "}\\|\\<\\(if\\|else\\)\\>" nil t)
962 (not (equal (match-string 0) "if")))
963 (if (equal (match-string 0) "else")
964 (vera-corresponding-if)
968 (defun vera-beginning-of-statement ()
969 "Go to beginning of current statement."
973 ;; search for end of previous statement
975 (and (vera-re-search-backward
976 (concat "[);]\\|" vera-beg-block-re
977 "\\|" vera-end-block-re) nil t)
978 (equal (match-string 0) ")"))
981 (setq pos (match-beginning 0))
982 ;; go back to beginning of current statement
983 (goto-char (or (match-end 0) 0))
984 (vera-forward-syntactic-ws nil t)
985 (when (looking-at "(")
987 (vera-forward-syntactic-ws nil t))
988 ;; if "else" found, go to "if" and search again
989 (when (looking-at "\\<else\\>")
990 (vera-corresponding-if)
993 ;; if search is repeated, go to beginning of last search
996 (defun vera-beginning-of-substatement ()
997 "Go to beginning of current substatement."
1000 ;; go to beginning of statement
1001 (vera-beginning-of-statement)
1003 ;; go forward all substatement opening statements until at LIM
1004 (while (and (< (point) lim)
1005 (vera-re-search-forward vera-beg-substatement-re lim t))
1006 (setq pos (match-beginning 0)))
1007 (vera-forward-syntactic-ws nil t)
1008 (when (looking-at "(")
1010 (vera-forward-syntactic-ws nil t))
1011 (when (< (point) lim)
1015 (defun vera-forward-statement ()
1016 "Move forward one statement."
1018 (vera-prepare-search
1019 (while (and (vera-re-search-forward
1020 (concat "[(;]\\|" vera-beg-block-re "\\|" vera-end-block-re)
1022 (equal (match-string 0) "("))
1025 (vera-beginning-of-substatement)))
1027 (defun vera-backward-statement ()
1028 "Move backward one statement."
1030 (vera-prepare-search
1031 (vera-backward-syntactic-ws nil t)
1032 (unless (= (preceding-char) ?\))
1034 (vera-beginning-of-substatement)))
1036 (defun vera-forward-same-indent ()
1037 "Move forward to next line with same indent."
1040 (indent (current-indentation)))
1041 (beginning-of-line 2)
1042 (while (and (not (eobp))
1043 (or (looking-at "^\\s-*$")
1044 (> (current-indentation) indent)))
1045 (beginning-of-line 2))
1046 (if (= (current-indentation) indent)
1047 (back-to-indentation)
1048 (message "No following line with same indent found in this block")
1051 (defun vera-backward-same-indent ()
1052 "Move backward to previous line with same indent."
1055 (indent (current-indentation)))
1056 (beginning-of-line -0)
1057 (while (and (not (bobp))
1058 (or (looking-at "^\\s-*$")
1059 (> (current-indentation) indent)))
1060 (beginning-of-line -0))
1061 (if (= (current-indentation) indent)
1062 (back-to-indentation)
1063 (message "No preceding line with same indent found in this block")
1066 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1069 (defmacro vera-add-syntax (symbol &optional relpos)
1070 "A simple macro to append the syntax in SYMBOL to the syntax list.
1071 try to increase performance by using this macro."
1072 `(setq syntax (cons (cons ,symbol ,(or relpos 0)) syntax)))
1074 (defun vera-guess-basic-syntax ()
1075 "Determine syntactic context of current line of code."
1078 (let ((indent-point (point))
1079 syntax state placeholder)
1080 ;; determine syntax state
1081 (setq state (parse-partial-sexp (point-min) (point)))
1083 ;; CASE 1: in a comment?
1086 (while (and (zerop (forward-line -1))
1087 (looking-at "^\\s-*$")))
1088 (vera-add-syntax 'comment (vera-point 'boi)))
1089 ;; CASE 2: in a string?
1091 (vera-add-syntax 'string))
1092 ;; CASE 3: at a directive?
1093 ((save-excursion (back-to-indentation) (= (following-char) ?\#))
1094 (vera-add-syntax 'directive (point)))
1095 ;; CASE 4: after an opening parenthesis (argument list continuation)?
1097 (or (= (char-after (nth 1 state)) ?\()
1098 ;; also for concatenation (opening '{' and ',' on eol/eopl)
1099 (and (= (char-after (nth 1 state)) ?\{)
1101 (vera-backward-syntactic-ws) (= (char-before) ?,))
1103 (end-of-line) (= (char-before) ?,))))))
1104 (goto-char (1+ (nth 1 state)))
1105 ;; is there code after the opening parenthesis on the same line?
1106 (if (looking-at "\\s-*$")
1107 (vera-add-syntax 'arglist-cont (vera-point 'boi))
1108 (vera-add-syntax 'arglist-cont-nonempty (point))))
1109 ;; CASE 5: at a block closing?
1110 ((save-excursion (back-to-indentation) (looking-at vera-end-block-re))
1111 ;; look for the corresponding begin
1112 (vera-corresponding-begin)
1113 (vera-add-syntax 'block-close (vera-point 'boi)))
1114 ;; CASE 6: at a block intro (the first line after a block opening)?
1115 ((and (save-excursion
1116 (vera-backward-syntactic-ws nil t)
1117 ;; previous line ends with a block opening?
1118 (or (/= (skip-chars-backward "{") 0) (backward-word 1))
1119 (when (looking-at vera-beg-block-re)
1120 ;; go to beginning of substatement
1121 (vera-beginning-of-substatement)
1122 (setq placeholder (point))))
1123 ;; not if "fork" is followed by "{"
1125 (not (and (progn (back-to-indentation) (looking-at "{"))
1126 (progn (goto-char placeholder)
1127 (looking-at "\\<fork\\>"))))))
1128 (goto-char placeholder)
1129 (vera-add-syntax 'block-intro (vera-point 'boi)))
1130 ;; CASE 7: at the beginning of an else clause?
1131 ((save-excursion (back-to-indentation) (looking-at "\\<else\\>"))
1132 ;; find corresponding if
1133 (vera-corresponding-if)
1134 (vera-add-syntax 'else-clause (vera-point 'boi)))
1135 ;; CASE 8: at the beginning of a statement?
1136 ;; is the previous command completed?
1137 ((or (save-excursion
1138 (vera-backward-syntactic-ws nil t)
1139 (setq placeholder (point))
1140 ;; at the beginning of the buffer?
1142 ;; previous line ends with a semicolon or
1143 ;; is a block opening or closing?
1144 (when (or (/= (skip-chars-backward "{};") 0)
1145 (progn (back-to-indentation)
1146 (looking-at (concat vera-beg-block-re "\\|"
1147 vera-end-block-re))))
1148 ;; if at a block closing, go to beginning
1149 (when (looking-at vera-end-block-re)
1150 (vera-corresponding-begin))
1151 ;; go to beginning of the statement
1152 (vera-beginning-of-statement)
1153 (setq placeholder (point)))
1155 (when (progn (back-to-indentation) (looking-at "#"))
1156 ;; go to previous statement
1157 (vera-beginning-of-statement)
1158 (setq placeholder (point)))))
1159 ;; at a block opening?
1160 (when (save-excursion (back-to-indentation)
1161 (looking-at vera-beg-block-re))
1162 ;; go to beginning of the substatement
1163 (vera-beginning-of-substatement)
1164 (setq placeholder (point))))
1165 (goto-char placeholder)
1166 (vera-add-syntax 'statement (vera-point 'boi)))
1167 ;; CASE 9: at the beginning of a substatement?
1168 ;; is this line preceded by a substatement opening statement?
1169 ((save-excursion (vera-backward-syntactic-ws nil t)
1170 (when (= (preceding-char) ?\)) (backward-sexp))
1172 (setq placeholder (point))
1173 (looking-at vera-beg-substatement-re))
1174 (goto-char placeholder)
1175 (vera-add-syntax 'substatement (vera-point 'boi)))
1176 ;; CASE 10: it must be a statement continuation!
1178 ;; go to beginning of statement
1179 (vera-beginning-of-substatement)
1180 (vera-add-syntax 'statement-cont (vera-point 'boi))))
1181 ;; special case: look for a comment start
1182 (goto-char indent-point)
1183 (skip-chars-forward " \t")
1184 (when (looking-at comment-start)
1185 (vera-add-syntax 'comment-intro))
1189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1190 ;; indentation functions
1192 (defun vera-indent-line ()
1193 "Indent the current line as Vera code.
1194 Return the amount of indentation change (in columns)."
1196 (vera-prepare-search
1197 (let* ((syntax (vera-guess-basic-syntax))
1198 (pos (- (point-max) (point)))
1199 (indent (apply '+ (mapcar 'vera-get-offset syntax)))
1200 (shift-amt (- (current-indentation) indent)))
1201 (when vera-echo-syntactic-information-p
1202 (message "syntax: %s, indent= %d" syntax indent))
1203 (unless (zerop shift-amt)
1205 (delete-region (point) (vera-point 'boi))
1207 (if (< (point) (vera-point 'boi))
1208 (back-to-indentation)
1209 ;; If initial point was within line's indentation, position after
1210 ;; the indentation. Else stay at same point in text.
1211 (when (> (- (point-max) pos) (point))
1212 (goto-char (- (point-max) pos))))
1215 (defun vera-indent-buffer ()
1216 "Indent whole buffer as Vera code.
1217 Calls `indent-region' for whole buffer."
1219 (message "Indenting buffer...")
1220 (indent-region (point-min) (point-max) nil)
1221 (message "Indenting buffer...done"))
1223 (defun vera-indent-region (start end column)
1224 "Indent region as Vera code."
1225 (interactive "r\nP")
1226 (message "Indenting region...")
1227 (indent-region start end column)
1228 (message "Indenting region...done"))
1230 (defsubst vera-indent-block-closing ()
1231 "If previous word is a block closing or `else', indent line again."
1232 (when (= (char-syntax (preceding-char)) ?w)
1235 (when (and (not (vera-in-literal))
1236 (looking-at (concat vera-end-block-re "\\|\\<else\\>")))
1237 (indent-according-to-mode)))))
1239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1242 (defun vera-electric-tab (&optional prefix)
1243 "Do what I mean (indent, expand, tab, change indent, etc..).
1244 If preceding character is part of a word or a paren then `hippie-expand',
1245 else if right of non whitespace on line then `tab-to-tab-stop',
1246 else if last command was a tab or return then dedent one step or if a comment
1247 toggle between normal indent and inline comment indent,
1248 else indent `correctly'.
1249 If `vera-intelligent-tab' is nil, always indent line."
1251 (if vera-intelligent-tab
1253 (cond ((and (not (featurep 'xemacs)) (use-region-p))
1254 (vera-indent-region (region-beginning) (region-end) nil))
1255 ((memq (char-syntax (preceding-char)) '(?w ?_))
1256 (let ((case-fold-search t)
1258 (hippie-expand-only-buffers
1259 (or (and (boundp 'hippie-expand-only-buffers)
1260 hippie-expand-only-buffers)
1262 (vera-expand-abbrev prefix)))
1263 ((> (current-column) (current-indentation))
1265 ((and (or (eq last-command 'vera-electric-tab)
1266 (eq last-command 'vera-electric-return))
1267 (/= 0 (current-indentation)))
1268 (backward-delete-char-untabify vera-basic-offset nil))
1269 (t (indent-according-to-mode)))
1270 (setq this-command 'vera-electric-tab))
1271 (indent-according-to-mode)))
1273 (defun vera-electric-return ()
1274 "Insert newline and indent. Indent current line if it is a block closing."
1276 (vera-indent-block-closing)
1277 (newline-and-indent))
1279 (defun vera-electric-space (arg)
1280 "Insert a space. Indent current line if it is a block closing."
1283 (vera-indent-block-closing))
1284 (self-insert-command (prefix-numeric-value arg)))
1286 (defun vera-electric-opening-brace (arg)
1287 "Outdent opening brace."
1289 (self-insert-command (prefix-numeric-value arg))
1291 (indent-according-to-mode)))
1293 (defun vera-electric-closing-brace (arg)
1294 "Outdent closing brace."
1296 (self-insert-command (prefix-numeric-value arg))
1298 (indent-according-to-mode)))
1300 (defun vera-electric-pound (arg)
1301 "Insert `#' and indent as directive it first character of line."
1303 (self-insert-command (prefix-numeric-value arg))
1307 (skip-chars-backward " \t")
1309 (delete-horizontal-space)))))
1311 (defun vera-electric-star (arg)
1312 "Insert a star character. Nicked from `c-electric-star'."
1314 (self-insert-command (prefix-numeric-value arg))
1316 (memq (vera-in-literal) '(comment))
1317 (eq (char-before) ?*)
1320 (skip-chars-backward "*")
1321 (if (eq (char-before) ?/)
1323 (skip-chars-backward " \t")
1325 (indent-according-to-mode)))
1327 (defun vera-electric-slash (arg)
1328 "Insert a slash character. Nicked from `c-electric-slash'."
1330 (let* ((ch (char-before))
1331 (indentp (and (not arg)
1332 (eq last-command-event ?/)
1334 (not (vera-in-literal)))
1336 (vera-in-literal))))))
1337 (self-insert-command (prefix-numeric-value arg))
1339 (indent-according-to-mode))))
1342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1347 ;; Hippie expand customization (for expansion of Vera commands)
1349 (defvar vera-abbrev-list
1350 (append (list nil) vera-keywords
1351 (list nil) vera-types
1352 (list nil) vera-functions
1353 (list nil) vera-constants
1354 (list nil) vera-rvm-types
1355 (list nil) vera-rvm-functions
1356 (list nil) vera-rvm-constants)
1357 "Predefined abbreviations for Vera.")
1359 (defvar vera-expand-upper-case nil)
1361 (eval-when-compile (require 'hippie-exp))
1363 (defun vera-try-expand-abbrev (old)
1364 "Try expanding abbreviations from `vera-abbrev-list'."
1366 (he-init-string (he-dabbrev-beg) (point))
1367 (setq he-expand-list
1368 (let ((abbrev-list vera-abbrev-list)
1369 (sel-abbrev-list '()))
1371 (when (or (not (stringp (car abbrev-list)))
1373 (concat "^" he-search-string) (car abbrev-list)))
1374 (setq sel-abbrev-list
1375 (cons (car abbrev-list) sel-abbrev-list)))
1376 (setq abbrev-list (cdr abbrev-list)))
1377 (nreverse sel-abbrev-list))))
1378 (while (and he-expand-list
1379 (or (not (stringp (car he-expand-list)))
1380 (he-string-member (car he-expand-list) he-tried-table t)))
1381 (unless (stringp (car he-expand-list))
1382 (setq vera-expand-upper-case (car he-expand-list)))
1383 (setq he-expand-list (cdr he-expand-list)))
1384 (if (null he-expand-list)
1385 (progn (when old (he-reset-string))
1387 (he-substitute-string
1388 (if vera-expand-upper-case
1389 (upcase (car he-expand-list))
1390 (car he-expand-list))
1392 (setq he-expand-list (cdr he-expand-list))
1395 ;; function for expanding abbrevs and dabbrevs
1396 (defalias 'vera-expand-abbrev
1397 (make-hippie-expand-function '(try-expand-dabbrev
1398 try-expand-dabbrev-all-buffers
1399 vera-try-expand-abbrev)))
1401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1404 (defun vera-comment-uncomment-region (beg end &optional _arg)
1405 "Comment region if not commented, uncomment region if already commented."
1406 (interactive "r\nP")
1408 (if (looking-at comment-start-skip)
1409 (comment-region beg end '(4))
1410 (comment-region beg end)))
1412 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1415 (defun vera-customize ()
1416 "Call the customize function with `vera' as argument."
1418 (customize-group 'vera))
1420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1423 ;; remove ".vr" from `completion-ignored-extensions'
1424 (setq completion-ignored-extensions
1425 (delete ".vr" completion-ignored-extensions))
1428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1432 (defconst vera-mode-help-address "Reto Zimmermann <reto@gnu.org>"
1433 "Address for Vera Mode bug reports.")
1435 ;; get reporter-submit-bug-report when byte-compiling
1437 (require 'reporter))
1439 (defun vera-submit-bug-report ()
1440 "Submit via mail a bug report on Vera Mode."
1444 (y-or-n-p "Do you want to submit a report on Vera Mode? ")
1446 (let ((reporter-prompt-for-summary-p t))
1447 (reporter-submit-bug-report
1448 vera-mode-help-address
1449 (concat "Vera Mode " vera-version)
1451 ;; report all important variables
1453 'vera-underscore-is-part-of-word
1454 'vera-intelligent-tab
1460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1464 (defun vera-version ()
1465 "Echo the current version of Vera Mode in the minibuffer."
1467 (message "Vera Mode %s (%s)" vera-version vera-time-stamp))
1470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1472 (provide 'vera-mode)
1474 ;;; vera-mode.el ends here