1 ;;; vera-mode.el --- major mode for editing Vera files
3 ;; Copyright (C) 1997-2013 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 (defun vera-font-lock-match-item (limit)
591 "Match, and move over, any declaration item after point.
592 Adapted from `font-lock-match-c-style-declaration-item-and-skip-to-next'."
595 (narrow-to-region (point-min) limit)
597 (when (looking-at "\\s-*\\(\\w+\\)")
599 (goto-char (match-end 1))
601 (if (looking-at "\\(\\s-*\\(\\[[^]]*\\]\\s-*\\)?,\\)")
602 (goto-char (match-end 1))
606 (defvar vera-font-lock-keywords
608 ;; highlight keywords
609 (list vera-keywords-regexp 1 'font-lock-keyword-face)
611 (list vera-types-regexp 1 'font-lock-type-face)
612 ;; highlight RVM types
613 (list vera-rvm-types-regexp 1 'font-lock-type-face)
614 ;; highlight constants
615 (list vera-constants-regexp 1 'font-lock-constant-face)
616 ;; highlight RVM constants
617 (list vera-rvm-constants-regexp 1 'font-lock-constant-face)
618 ;; highlight q_values
619 (list vera-q-values-regexp 1 'font-lock-constant-face)
620 ;; highlight predefined functions, tasks and methods
621 (list vera-functions-regexp 1 'vera-font-lock-function)
622 ;; highlight predefined RVM functions
623 (list vera-rvm-functions-regexp 1 'vera-font-lock-function)
624 ;; highlight functions
625 '("\\<\\(\\w+\\)\\s-*(" 1 font-lock-function-name-face)
626 ;; highlight various declaration names
627 '("^\\s-*\\(port\\|program\\|task\\)\\s-+\\(\\w+\\)\\>"
628 2 font-lock-function-name-face)
629 '("^\\s-*bind\\s-+\\(\\w+\\)\\s-+\\(\\w+\\)\\>"
630 (1 font-lock-function-name-face) (2 font-lock-function-name-face))
631 ;; highlight interface declaration names
632 '("^\\s-*\\(class\\|interface\\)\\s-+\\(\\w+\\)\\>"
633 2 vera-font-lock-interface)
634 ;; highlight variable name definitions
635 (list (concat "^\\s-*" vera-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
636 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
637 (list (concat "^\\s-*" vera-rvm-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
638 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
640 '("\\([0-9]*'[bdoh][0-9a-fA-FxXzZ_]+\\)" 1 vera-font-lock-number)
641 ;; highlight filenames in #include directives
642 '("^#\\s-*include\\s-*\\(<[^>\"\n]*>?\\)"
643 1 font-lock-string-face)
644 ;; highlight directives and directive names
645 '("^#\\s-*\\(\\w+\\)\\>[ \t!]*\\(\\w+\\)?"
646 (1 font-lock-builtin-face) (2 font-lock-variable-name-face nil t))
647 ;; highlight `@', `$' and `#'
648 '("\\([@$#]\\)" 1 font-lock-keyword-face)
649 ;; highlight @ and # definitions
650 '("@\\s-*\\(\\w*\\)\\(\\s-*,\\s-*\\(\\w+\\)\\)?\\>[^.]"
651 (1 vera-font-lock-number) (3 vera-font-lock-number nil t))
652 ;; highlight interface signal name
653 '("\\(\\w+\\)\\.\\w+" 1 vera-font-lock-interface)
655 "Regular expressions to highlight in Vera Mode.")
657 (defvar vera-font-lock-number 'vera-font-lock-number
658 "Face name to use for @ definitions.")
660 (defvar vera-font-lock-function 'vera-font-lock-function
661 "Face name to use for predefined functions and tasks.")
663 (defvar vera-font-lock-interface 'vera-font-lock-interface
664 "Face name to use for interface names.")
666 (defface vera-font-lock-number
667 '((((class color) (background light)) :foreground "Gold4")
668 (((class color) (background dark)) :foreground "BurlyWood1")
669 (t :slant italic :weight bold))
670 "Font lock mode face used to highlight @ definitions."
671 :group 'font-lock-highlighting-faces)
673 (defface vera-font-lock-function
674 '((((class color) (background light)) :foreground "DarkCyan")
675 (((class color) (background dark)) :foreground "Orchid1")
676 (t :slant italic :weight bold))
677 "Font lock mode face used to highlight predefined functions and tasks."
678 :group 'font-lock-highlighting-faces)
680 (defface vera-font-lock-interface
681 '((((class color) (background light)) :foreground "Grey40")
682 (((class color) (background dark)) :foreground "Grey80")
683 (t :slant italic :weight bold))
684 "Font lock mode face used to highlight interface names."
685 :group 'font-lock-highlighting-faces)
687 (defalias 'vera-fontify-buffer 'font-lock-fontify-buffer)
689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
693 (defvar vera-echo-syntactic-information-p nil
694 "If non-nil, syntactic info is echoed when the line is indented.")
696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
699 (defconst vera-offsets-alist
700 '((comment . vera-lineup-C-comments)
701 (comment-intro . vera-lineup-comment)
709 (arglist-cont-nonempty . 0)
715 "Association list of syntactic element symbols and indentation offsets.
716 Adapted from `c-offsets-alist'.")
718 (defun vera-evaluate-offset (offset langelem symbol)
719 "OFFSET can be a number, a function, a variable, a list, or one of
722 ((eq offset '+) (setq offset vera-basic-offset))
723 ((eq offset '-) (setq offset (- vera-basic-offset)))
724 ((eq offset '++) (setq offset (* 2 vera-basic-offset)))
725 ((eq offset '--) (setq offset (* 2 (- vera-basic-offset))))
726 ((eq offset '*) (setq offset (/ vera-basic-offset 2)))
727 ((eq offset '/) (setq offset (/ (- vera-basic-offset) 2)))
728 ((functionp offset) (setq offset (funcall offset langelem)))
732 (while (and (not done) offset)
733 (setq done (vera-evaluate-offset (car offset) langelem symbol)
734 offset (cdr offset)))
738 ((not (numberp offset)) (setq offset (symbol-value offset))))
741 (defun vera-get-offset (langelem)
742 "Get offset from LANGELEM which is a cons cell of the form:
743 \(SYMBOL . RELPOS). The symbol is matched against
744 vera-offsets-alist and the offset found there is either returned,
745 or added to the indentation at RELPOS. If RELPOS is nil, then
746 the offset is simply returned."
747 (let* ((symbol (car langelem))
748 (relpos (cdr langelem))
749 (match (assq symbol vera-offsets-alist))
750 (offset (cdr-safe match)))
754 (setq offset (vera-evaluate-offset offset langelem symbol)))
756 (< relpos (line-beginning-position)))
761 (vera-evaluate-offset offset langelem symbol))))
763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
766 (defsubst vera-point (position)
767 "Return the value of point at certain commonly referenced POSITIONs.
768 POSITION can be one of the following symbols:
769 bol -- beginning of line
771 boi -- back to indentation
772 ionl -- indentation of next line
773 iopl -- indentation of previous line
774 bonl -- beginning of next line
775 bopl -- beginning of previous line
776 This function does not modify point or mark."
779 ((eq position 'bol) (beginning-of-line))
780 ((eq position 'eol) (end-of-line))
781 ((eq position 'boi) (back-to-indentation))
782 ((eq position 'bonl) (forward-line 1))
783 ((eq position 'bopl) (forward-line -1))
784 ((eq position 'iopl) (forward-line -1) (back-to-indentation))
785 ((eq position 'ionl) (forward-line 1) (back-to-indentation))
786 (t (error "Unknown buffer position requested: %s" position)))
789 (defun vera-in-literal (&optional lim)
790 "Determine if point is in a Vera literal."
792 (let ((state (parse-partial-sexp (or lim (point-min)) (point))))
794 ((nth 3 state) 'string)
795 ((nth 4 state) 'comment)
798 (defun vera-skip-forward-literal ()
799 "Skip forward literal and return t if within one."
800 (let ((state (save-excursion
801 (if (fboundp 'syntax-ppss)
803 (parse-partial-sexp (point-min) (point))))))
805 ;; Inside a string or comment.
806 (goto-char (nth 8 state))
809 (condition-case nil (forward-sexp 1)
810 ;; Can't find end of string: it extends til end of buffer.
811 (error (goto-char (point-max))))
816 (defun vera-skip-backward-literal ()
817 "Skip backward literal and return t if within one."
818 (let ((state (save-excursion
819 (if (fboundp 'syntax-ppss)
821 (parse-partial-sexp (point-min) (point))))))
823 ;; Inside a string or comment.
824 (goto-char (nth 8 state))
827 (defsubst vera-re-search-forward (regexp &optional bound noerror)
828 "Like `re-search-forward', but skips over matches in literals."
830 (while (and (setq ret (re-search-forward regexp bound noerror))
831 (vera-skip-forward-literal)
832 (if bound (< (point) bound) t)))
835 (defsubst vera-re-search-backward (regexp &optional bound noerror)
836 "Like `re-search-backward', but skips over matches in literals."
838 (while (and (setq ret (re-search-backward regexp bound noerror))
839 (vera-skip-backward-literal)
840 (if bound (> (point) bound) t)))
843 (defun vera-forward-syntactic-ws (&optional lim skip-directive)
844 "Forward skip of syntactic whitespace."
846 (let* ((lim (or lim (point-max)))
848 (hugenum (point-max)))
849 (narrow-to-region (point) lim)
850 (while (/= here (point))
852 (forward-comment hugenum)
853 (when (and skip-directive (looking-at "^\\s-*#"))
856 (defun vera-backward-syntactic-ws (&optional lim skip-directive)
857 "Backward skip over syntactic whitespace."
859 (let* ((lim (or lim (point-min)))
861 (hugenum (- (point-max))))
862 (when (< lim (point))
863 (narrow-to-region lim (point))
864 (while (/= here (point))
866 (forward-comment hugenum)
867 (when (and skip-directive
868 (save-excursion (back-to-indentation)
869 (= (following-char) ?\#)))
870 (beginning-of-line)))))))
872 (defmacro vera-prepare-search (&rest body)
873 "Execute BODY with a syntax table that includes '_'."
874 `(with-syntax-table vera-mode-ext-syntax-table ,@body))
876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
877 ;; comment indentation functions
879 (defsubst vera-langelem-col (langelem &optional preserve-point)
880 "Convenience routine to return the column of LANGELEM's relpos.
881 Leaves point at the relpos unless PRESERVE-POINT is non-nil."
882 (let ((here (point)))
883 (goto-char (cdr langelem))
884 (prog1 (current-column)
888 (defun vera-lineup-C-comments (langelem)
889 "Line up C block comment continuation lines.
890 Nicked from `c-lineup-C-comments'."
893 (stars (progn (back-to-indentation)
894 (skip-chars-forward "*")))
895 (langelem-col (vera-langelem-col langelem)))
896 (back-to-indentation)
897 (if (not (re-search-forward "/\\([*]+\\)" (vera-point 'eol) t))
899 (if (not (looking-at "[*]+"))
901 ;; we now have to figure out where this comment begins.
903 (back-to-indentation)
904 (if (looking-at "[*]+/")
905 (progn (goto-char (match-end 0))
906 (forward-comment -1))
907 (goto-char (cdr langelem))
908 (back-to-indentation))))
909 (- (current-column) langelem-col))
912 (skip-chars-forward " \t")
913 (- (current-column) langelem-col))
914 ;; how many stars on comment opening line? if greater than
915 ;; on current line, align left. if less than or equal,
916 ;; align right. this should also pick up Javadoc style
918 (if (> (length (match-string 1)) stars)
920 (back-to-indentation)
921 (- (current-column) -1 langelem-col))
922 (- (current-column) stars langelem-col)))))))
924 (defun vera-lineup-comment (langelem)
925 "Line up a comment start."
927 (back-to-indentation)
929 ;; not indent if at beginning of line
931 ;; otherwise indent accordingly
932 (goto-char (cdr langelem))
935 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
938 (defconst vera-beg-block-re "{\\|\\<\\(begin\\|fork\\)\\>")
940 (defconst vera-end-block-re "}\\|\\<\\(end\\|join\\(\\s-+\\(all\\|any\\|none\\)\\)?\\)\\>")
942 (defconst vera-beg-substatement-re "\\<\\(else\\|for\\|if\\|repeat\\|while\\)\\>")
944 (defun vera-corresponding-begin (&optional recursive)
945 "Find corresponding block begin if cursor is at a block end."
946 (while (and (vera-re-search-backward
947 (concat "\\(" vera-end-block-re "\\)\\|" vera-beg-block-re)
950 (vera-corresponding-begin t))
951 (unless recursive (vera-beginning-of-substatement)))
953 (defun vera-corresponding-if ()
954 "Find corresponding `if' if cursor is at `else'."
955 (while (and (vera-re-search-backward "}\\|\\<\\(if\\|else\\)\\>" nil t)
956 (not (equal (match-string 0) "if")))
957 (if (equal (match-string 0) "else")
958 (vera-corresponding-if)
962 (defun vera-beginning-of-statement ()
963 "Go to beginning of current statement."
967 ;; search for end of previous statement
969 (and (vera-re-search-backward
970 (concat "[);]\\|" vera-beg-block-re
971 "\\|" vera-end-block-re) nil t)
972 (equal (match-string 0) ")"))
975 (setq pos (match-beginning 0))
976 ;; go back to beginning of current statement
977 (goto-char (or (match-end 0) 0))
978 (vera-forward-syntactic-ws nil t)
979 (when (looking-at "(")
981 (vera-forward-syntactic-ws nil t))
982 ;; if "else" found, go to "if" and search again
983 (when (looking-at "\\<else\\>")
984 (vera-corresponding-if)
987 ;; if search is repeated, go to beginning of last search
990 (defun vera-beginning-of-substatement ()
991 "Go to beginning of current substatement."
994 ;; go to beginning of statement
995 (vera-beginning-of-statement)
997 ;; go forward all substatement opening statements until at LIM
998 (while (and (< (point) lim)
999 (vera-re-search-forward vera-beg-substatement-re lim t))
1000 (setq pos (match-beginning 0)))
1001 (vera-forward-syntactic-ws nil t)
1002 (when (looking-at "(")
1004 (vera-forward-syntactic-ws nil t))
1005 (when (< (point) lim)
1009 (defun vera-forward-statement ()
1010 "Move forward one statement."
1012 (vera-prepare-search
1013 (while (and (vera-re-search-forward
1014 (concat "[(;]\\|" vera-beg-block-re "\\|" vera-end-block-re)
1016 (equal (match-string 0) "("))
1019 (vera-beginning-of-substatement)))
1021 (defun vera-backward-statement ()
1022 "Move backward one statement."
1024 (vera-prepare-search
1025 (vera-backward-syntactic-ws nil t)
1026 (unless (= (preceding-char) ?\))
1028 (vera-beginning-of-substatement)))
1030 (defun vera-forward-same-indent ()
1031 "Move forward to next line with same indent."
1034 (indent (current-indentation)))
1035 (beginning-of-line 2)
1036 (while (and (not (eobp))
1037 (or (looking-at "^\\s-*$")
1038 (> (current-indentation) indent)))
1039 (beginning-of-line 2))
1040 (if (= (current-indentation) indent)
1041 (back-to-indentation)
1042 (message "No following line with same indent found in this block")
1045 (defun vera-backward-same-indent ()
1046 "Move backward to previous line with same indent."
1049 (indent (current-indentation)))
1050 (beginning-of-line -0)
1051 (while (and (not (bobp))
1052 (or (looking-at "^\\s-*$")
1053 (> (current-indentation) indent)))
1054 (beginning-of-line -0))
1055 (if (= (current-indentation) indent)
1056 (back-to-indentation)
1057 (message "No preceding line with same indent found in this block")
1060 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1063 (defmacro vera-add-syntax (symbol &optional relpos)
1064 "A simple macro to append the syntax in SYMBOL to the syntax list.
1065 try to increase performance by using this macro."
1066 `(setq syntax (cons (cons ,symbol ,(or relpos 0)) syntax)))
1068 (defun vera-guess-basic-syntax ()
1069 "Determine syntactic context of current line of code."
1072 (let ((indent-point (point))
1073 syntax state placeholder)
1074 ;; determine syntax state
1075 (setq state (parse-partial-sexp (point-min) (point)))
1077 ;; CASE 1: in a comment?
1080 (while (and (zerop (forward-line -1))
1081 (looking-at "^\\s-*$")))
1082 (vera-add-syntax 'comment (vera-point 'boi)))
1083 ;; CASE 2: in a string?
1085 (vera-add-syntax 'string))
1086 ;; CASE 3: at a directive?
1087 ((save-excursion (back-to-indentation) (= (following-char) ?\#))
1088 (vera-add-syntax 'directive (point)))
1089 ;; CASE 4: after an opening parenthesis (argument list continuation)?
1091 (or (= (char-after (nth 1 state)) ?\()
1092 ;; also for concatenation (opening '{' and ',' on eol/eopl)
1093 (and (= (char-after (nth 1 state)) ?\{)
1095 (vera-backward-syntactic-ws) (= (char-before) ?,))
1097 (end-of-line) (= (char-before) ?,))))))
1098 (goto-char (1+ (nth 1 state)))
1099 ;; is there code after the opening parenthesis on the same line?
1100 (if (looking-at "\\s-*$")
1101 (vera-add-syntax 'arglist-cont (vera-point 'boi))
1102 (vera-add-syntax 'arglist-cont-nonempty (point))))
1103 ;; CASE 5: at a block closing?
1104 ((save-excursion (back-to-indentation) (looking-at vera-end-block-re))
1105 ;; look for the corresponding begin
1106 (vera-corresponding-begin)
1107 (vera-add-syntax 'block-close (vera-point 'boi)))
1108 ;; CASE 6: at a block intro (the first line after a block opening)?
1109 ((and (save-excursion
1110 (vera-backward-syntactic-ws nil t)
1111 ;; previous line ends with a block opening?
1112 (or (/= (skip-chars-backward "{") 0) (backward-word 1))
1113 (when (looking-at vera-beg-block-re)
1114 ;; go to beginning of substatement
1115 (vera-beginning-of-substatement)
1116 (setq placeholder (point))))
1117 ;; not if "fork" is followed by "{"
1119 (not (and (progn (back-to-indentation) (looking-at "{"))
1120 (progn (goto-char placeholder)
1121 (looking-at "\\<fork\\>"))))))
1122 (goto-char placeholder)
1123 (vera-add-syntax 'block-intro (vera-point 'boi)))
1124 ;; CASE 7: at the beginning of an else clause?
1125 ((save-excursion (back-to-indentation) (looking-at "\\<else\\>"))
1126 ;; find corresponding if
1127 (vera-corresponding-if)
1128 (vera-add-syntax 'else-clause (vera-point 'boi)))
1129 ;; CASE 8: at the beginning of a statement?
1130 ;; is the previous command completed?
1131 ((or (save-excursion
1132 (vera-backward-syntactic-ws nil t)
1133 (setq placeholder (point))
1134 ;; at the beginning of the buffer?
1136 ;; previous line ends with a semicolon or
1137 ;; is a block opening or closing?
1138 (when (or (/= (skip-chars-backward "{};") 0)
1139 (progn (back-to-indentation)
1140 (looking-at (concat vera-beg-block-re "\\|"
1141 vera-end-block-re))))
1142 ;; if at a block closing, go to beginning
1143 (when (looking-at vera-end-block-re)
1144 (vera-corresponding-begin))
1145 ;; go to beginning of the statement
1146 (vera-beginning-of-statement)
1147 (setq placeholder (point)))
1149 (when (progn (back-to-indentation) (looking-at "#"))
1150 ;; go to previous statement
1151 (vera-beginning-of-statement)
1152 (setq placeholder (point)))))
1153 ;; at a block opening?
1154 (when (save-excursion (back-to-indentation)
1155 (looking-at vera-beg-block-re))
1156 ;; go to beginning of the substatement
1157 (vera-beginning-of-substatement)
1158 (setq placeholder (point))))
1159 (goto-char placeholder)
1160 (vera-add-syntax 'statement (vera-point 'boi)))
1161 ;; CASE 9: at the beginning of a substatement?
1162 ;; is this line preceded by a substatement opening statement?
1163 ((save-excursion (vera-backward-syntactic-ws nil t)
1164 (when (= (preceding-char) ?\)) (backward-sexp))
1166 (setq placeholder (point))
1167 (looking-at vera-beg-substatement-re))
1168 (goto-char placeholder)
1169 (vera-add-syntax 'substatement (vera-point 'boi)))
1170 ;; CASE 10: it must be a statement continuation!
1172 ;; go to beginning of statement
1173 (vera-beginning-of-substatement)
1174 (vera-add-syntax 'statement-cont (vera-point 'boi))))
1175 ;; special case: look for a comment start
1176 (goto-char indent-point)
1177 (skip-chars-forward " \t")
1178 (when (looking-at comment-start)
1179 (vera-add-syntax 'comment-intro))
1183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1184 ;; indentation functions
1186 (defun vera-indent-line ()
1187 "Indent the current line as Vera code.
1188 Return the amount of indentation change (in columns)."
1190 (vera-prepare-search
1191 (let* ((syntax (vera-guess-basic-syntax))
1192 (pos (- (point-max) (point)))
1193 (indent (apply '+ (mapcar 'vera-get-offset syntax)))
1194 (shift-amt (- (current-indentation) indent)))
1195 (when vera-echo-syntactic-information-p
1196 (message "syntax: %s, indent= %d" syntax indent))
1197 (unless (zerop shift-amt)
1199 (delete-region (point) (vera-point 'boi))
1201 (if (< (point) (vera-point 'boi))
1202 (back-to-indentation)
1203 ;; If initial point was within line's indentation, position after
1204 ;; the indentation. Else stay at same point in text.
1205 (when (> (- (point-max) pos) (point))
1206 (goto-char (- (point-max) pos))))
1209 (defun vera-indent-buffer ()
1210 "Indent whole buffer as Vera code.
1211 Calls `indent-region' for whole buffer."
1213 (message "Indenting buffer...")
1214 (indent-region (point-min) (point-max) nil)
1215 (message "Indenting buffer...done"))
1217 (defun vera-indent-region (start end column)
1218 "Indent region as Vera code."
1219 (interactive "r\nP")
1220 (message "Indenting region...")
1221 (indent-region start end column)
1222 (message "Indenting region...done"))
1224 (defsubst vera-indent-block-closing ()
1225 "If previous word is a block closing or `else', indent line again."
1226 (when (= (char-syntax (preceding-char)) ?w)
1229 (when (and (not (vera-in-literal))
1230 (looking-at (concat vera-end-block-re "\\|\\<else\\>")))
1231 (indent-according-to-mode)))))
1233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1236 (defun vera-electric-tab (&optional prefix)
1237 "Do what I mean (indent, expand, tab, change indent, etc..).
1238 If preceding character is part of a word or a paren then `hippie-expand',
1239 else if right of non whitespace on line then `tab-to-tab-stop',
1240 else if last command was a tab or return then dedent one step or if a comment
1241 toggle between normal indent and inline comment indent,
1242 else indent `correctly'.
1243 If `vera-intelligent-tab' is nil, always indent line."
1245 (if vera-intelligent-tab
1247 (cond ((and (not (featurep 'xemacs)) (use-region-p))
1248 (vera-indent-region (region-beginning) (region-end) nil))
1249 ((memq (char-syntax (preceding-char)) '(?w ?_))
1250 (let ((case-fold-search t)
1252 (hippie-expand-only-buffers
1253 (or (and (boundp 'hippie-expand-only-buffers)
1254 hippie-expand-only-buffers)
1256 (vera-expand-abbrev prefix)))
1257 ((> (current-column) (current-indentation))
1259 ((and (or (eq last-command 'vera-electric-tab)
1260 (eq last-command 'vera-electric-return))
1261 (/= 0 (current-indentation)))
1262 (backward-delete-char-untabify vera-basic-offset nil))
1263 (t (indent-according-to-mode)))
1264 (setq this-command 'vera-electric-tab))
1265 (indent-according-to-mode)))
1267 (defun vera-electric-return ()
1268 "Insert newline and indent. Indent current line if it is a block closing."
1270 (vera-indent-block-closing)
1271 (newline-and-indent))
1273 (defun vera-electric-space (arg)
1274 "Insert a space. Indent current line if it is a block closing."
1277 (vera-indent-block-closing))
1278 (self-insert-command (prefix-numeric-value arg)))
1280 (defun vera-electric-opening-brace (arg)
1281 "Outdent opening brace."
1283 (self-insert-command (prefix-numeric-value arg))
1285 (indent-according-to-mode)))
1287 (defun vera-electric-closing-brace (arg)
1288 "Outdent closing brace."
1290 (self-insert-command (prefix-numeric-value arg))
1292 (indent-according-to-mode)))
1294 (defun vera-electric-pound (arg)
1295 "Insert `#' and indent as directive it first character of line."
1297 (self-insert-command (prefix-numeric-value arg))
1301 (skip-chars-backward " \t")
1303 (delete-horizontal-space)))))
1305 (defun vera-electric-star (arg)
1306 "Insert a star character. Nicked from `c-electric-star'."
1308 (self-insert-command (prefix-numeric-value arg))
1310 (memq (vera-in-literal) '(comment))
1311 (eq (char-before) ?*)
1314 (skip-chars-backward "*")
1315 (if (eq (char-before) ?/)
1317 (skip-chars-backward " \t")
1319 (indent-according-to-mode)))
1321 (defun vera-electric-slash (arg)
1322 "Insert a slash character. Nicked from `c-electric-slash'."
1324 (let* ((ch (char-before))
1325 (indentp (and (not arg)
1326 (eq last-command-event ?/)
1328 (not (vera-in-literal)))
1330 (vera-in-literal))))))
1331 (self-insert-command (prefix-numeric-value arg))
1333 (indent-according-to-mode))))
1336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1341 ;; Hippie expand customization (for expansion of Vera commands)
1343 (defvar vera-abbrev-list
1344 (append (list nil) vera-keywords
1345 (list nil) vera-types
1346 (list nil) vera-functions
1347 (list nil) vera-constants
1348 (list nil) vera-rvm-types
1349 (list nil) vera-rvm-functions
1350 (list nil) vera-rvm-constants)
1351 "Predefined abbreviations for Vera.")
1353 (defvar vera-expand-upper-case nil)
1355 (eval-when-compile (require 'hippie-exp))
1357 (defun vera-try-expand-abbrev (old)
1358 "Try expanding abbreviations from `vera-abbrev-list'."
1360 (he-init-string (he-dabbrev-beg) (point))
1361 (setq he-expand-list
1362 (let ((abbrev-list vera-abbrev-list)
1363 (sel-abbrev-list '()))
1365 (when (or (not (stringp (car abbrev-list)))
1367 (concat "^" he-search-string) (car abbrev-list)))
1368 (setq sel-abbrev-list
1369 (cons (car abbrev-list) sel-abbrev-list)))
1370 (setq abbrev-list (cdr abbrev-list)))
1371 (nreverse sel-abbrev-list))))
1372 (while (and he-expand-list
1373 (or (not (stringp (car he-expand-list)))
1374 (he-string-member (car he-expand-list) he-tried-table t)))
1375 (unless (stringp (car he-expand-list))
1376 (setq vera-expand-upper-case (car he-expand-list)))
1377 (setq he-expand-list (cdr he-expand-list)))
1378 (if (null he-expand-list)
1379 (progn (when old (he-reset-string))
1381 (he-substitute-string
1382 (if vera-expand-upper-case
1383 (upcase (car he-expand-list))
1384 (car he-expand-list))
1386 (setq he-expand-list (cdr he-expand-list))
1389 ;; function for expanding abbrevs and dabbrevs
1390 (defalias 'vera-expand-abbrev
1391 (make-hippie-expand-function '(try-expand-dabbrev
1392 try-expand-dabbrev-all-buffers
1393 vera-try-expand-abbrev)))
1395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1398 (defun vera-comment-uncomment-region (beg end &optional _arg)
1399 "Comment region if not commented, uncomment region if already commented."
1400 (interactive "r\nP")
1402 (if (looking-at comment-start-skip)
1403 (comment-region beg end '(4))
1404 (comment-region beg end)))
1406 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1409 (defun vera-customize ()
1410 "Call the customize function with `vera' as argument."
1412 (customize-group 'vera))
1414 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1417 ;; remove ".vr" from `completion-ignored-extensions'
1418 (setq completion-ignored-extensions
1419 (delete ".vr" completion-ignored-extensions))
1422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1424 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1426 (defconst vera-mode-help-address
1427 "Reto Zimmermann <reto@gnu.org>, bug-gnu-emacs@gnu.org"
1428 "Address for Vera Mode bug reports.")
1430 ;; get reporter-submit-bug-report when byte-compiling
1432 (require 'reporter))
1434 (defun vera-submit-bug-report ()
1435 "Submit via mail a bug report on Vera Mode."
1439 (y-or-n-p "Do you want to submit a report on Vera Mode? ")
1441 (let ((reporter-prompt-for-summary-p t))
1442 (reporter-submit-bug-report
1443 vera-mode-help-address
1444 (concat "Vera Mode " vera-version)
1446 ;; report all important variables
1448 'vera-underscore-is-part-of-word
1449 'vera-intelligent-tab
1455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1457 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1459 (defun vera-version ()
1460 "Echo the current version of Vera Mode in the minibuffer."
1462 (message "Vera Mode %s (%s)" vera-version vera-time-stamp))
1465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1467 (provide 'vera-mode)
1469 ;;; vera-mode.el ends here