1 ;;; vera-mode.el --- major mode for editing Vera files.
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Reto Zimmermann <reto@gnu.org>
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
9 ;; Keywords: languages vera
10 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html
12 (defconst vera-version
"2.18"
13 "Vera Mode version number.")
15 (defconst vera-time-stamp
"2007-06-11"
16 "Vera Mode time stamp for last update.")
18 ;; This file is part of GNU Emacs.
20 ;; GNU Emacs is free software; you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation; either version 2, or (at your option)
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs; see the file COPYING. If not, write to the
32 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
33 ;; Boston, MA 02110-1301, USA.
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; This package provides a simple Emacs major mode for editing Vera code.
40 ;; It includes the following features:
42 ;; - Syntax highlighting
44 ;; - Word/keyword completion
46 ;; - Works under GNU Emacs and XEmacs
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 ;; See comment string of function `vera-mode' or type `C-c C-h' in Emacs.
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 ;; Prerequisites: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X
58 ;; Put `vera-mode.el' into the `site-lisp' directory of your Emacs installation
59 ;; or into an arbitrary directory that is added to the load path by the
60 ;; following line in your Emacs start-up file (`.emacs'):
62 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
64 ;; If you already have the compiled `vera-mode.elc' file, put it in the same
65 ;; directory. Otherwise, byte-compile the source file:
66 ;; Emacs: M-x byte-compile-file -> vera-mode.el
67 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vera-mode.el
69 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
70 ;; directory of your Emacs installation or to your Emacs start-up file
73 ;; (autoload 'vera-mode "vera-mode" "Vera Mode" t)
74 ;; (setq auto-mode-alist (cons '("\\.vr[hi]?\\'" . vera-mode) auto-mode-alist))
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 (defconst vera-xemacs
(string-match "XEmacs" emacs-version
)
82 "Non-nil if XEmacs is used.")
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 "Customizations for Vera Mode."
93 (defcustom vera-basic-offset
2
94 "*Amount of basic offset used for indentation."
98 (defcustom vera-underscore-is-part-of-word nil
99 "*Non-nil means consider the underscore character `_' as part of word.
100 An identifier containing underscores is then treated as a single word in
101 select and move operations. All parts of an identifier separated by underscore
102 are treated as single words otherwise."
106 (defcustom vera-intelligent-tab t
107 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
108 That is, if preceeding character is part of a word then complete word,
109 else if not at beginning of line then insert tab,
110 else if last command was a `TAB' or `RET' then dedent one step,
111 else indent current line.
112 If nil, TAB always indents current line."
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124 (defvar vera-mode-map
()
125 "Keymap for Vera Mode.")
127 (setq vera-mode-map
(make-sparse-keymap))
128 ;; backspace/delete key bindings
129 (define-key vera-mode-map
[backspace] 'backward-delete-char-untabify)
130 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
131 (define-key vera-mode-map [delete] 'delete-char)
132 (define-key vera-mode-map [(meta delete)] 'kill-word))
133 ;; standard key bindings
134 (define-key vera-mode-map "\M-e" 'vera-forward-statement)
135 (define-key vera-mode-map "\M-a" 'vera-backward-statement)
136 (define-key vera-mode-map "\M-\C-e" 'vera-forward-same-indent)
137 (define-key vera-mode-map "\M-\C-a" 'vera-backward-same-indent)
138 ;; mode specific key bindings
139 (define-key vera-mode-map "\C-c\t" 'indent-according-to-mode)
140 (define-key vera-mode-map "\M-\C-\\" 'vera-indent-region)
141 (define-key vera-mode-map "\C-c\C-c" 'vera-comment-uncomment-region)
142 (define-key vera-mode-map "\C-c\C-f" 'vera-fontify-buffer)
143 (define-key vera-mode-map "\C-c\C-v" 'vera-version)
144 (define-key vera-mode-map "\M-\t" 'tab-to-tab-stop)
145 ;; electric key bindings
146 (define-key vera-mode-map "\t" 'vera-electric-tab)
147 (define-key vera-mode-map "\r" 'vera-electric-return)
148 (define-key vera-mode-map " " 'vera-electric-space)
149 (define-key vera-mode-map "{" 'vera-electric-opening-brace)
150 (define-key vera-mode-map "}" 'vera-electric-closing-brace)
151 (define-key vera-mode-map "#" 'vera-electric-pound)
152 (define-key vera-mode-map "*" 'vera-electric-star)
153 (define-key vera-mode-map "/" 'vera-electric-slash)
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
160 (easy-menu-define vera-mode-menu vera-mode-map
161 "Menu keymap for Vera Mode."
163 ["(Un)Comment Out Region" vera-comment-uncomment-region (mark)]
165 ["Move Forward Statement" vera-forward-statement t]
166 ["Move Backward Statement" vera-backward-statement t]
167 ["Move Forward Same Indent" vera-forward-same-indent t]
168 ["Move Backward Same Indent" vera-backward-same-indent t]
170 ["Indent Line" indent-according-to-mode t]
171 ["Indent Region" vera-indent-region (mark)]
172 ["Indent Buffer" vera-indent-buffer t]
174 ["Fontify Buffer" vera-fontify-buffer t]
176 ["Documentation" describe-mode]
177 ["Version" vera-version t]
178 ["Bug Report..." vera-submit-bug-report t]
181 ["Indentation Offset..." (customize-option 'vera-basic-offset) t]
182 ["Underscore is Part of Word"
183 (customize-set-variable 'vera-underscore-is-part-of-word
184 (not vera-underscore-is-part-of-word))
185 :style toggle :selected vera-underscore-is-part-of-word]
186 ["Use Intelligent Tab"
187 (customize-set-variable 'vera-intelligent-tab
188 (not vera-intelligent-tab))
189 :style toggle :selected vera-intelligent-tab]
191 ["Save Options" customize-save-customized t]
193 ["Customize..." vera-customize t])))
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
198 (defvar vera-mode-syntax-table
199 (let ((syntax-table (make-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)
217 (modify-syntax-entry ?\| "." syntax-table)
219 (modify-syntax-entry ?\" "\"" syntax-table)
221 (when vera-underscore-is-part-of-word
222 (modify-syntax-entry ?\_ "w" syntax-table))
224 (modify-syntax-entry ?\\ "\\" syntax-table)
225 ;; parentheses to match
226 (modify-syntax-entry ?\( "()" syntax-table)
227 (modify-syntax-entry ?\) ")(" syntax-table)
228 (modify-syntax-entry ?\[ "(]" syntax-table)
229 (modify-syntax-entry ?\] ")[" syntax-table)
230 (modify-syntax-entry ?\{ "(}" syntax-table)
231 (modify-syntax-entry ?\} "){" syntax-table)
234 (modify-syntax-entry ?\/ ". 1456" syntax-table) ; XEmacs
235 (modify-syntax-entry ?\/ ". 124b" syntax-table)) ; Emacs
236 (modify-syntax-entry ?\* ". 23" syntax-table)
238 (modify-syntax-entry ?\n "> b" syntax-table)
239 (modify-syntax-entry ?\^M "> b" syntax-table)
241 "Syntax table used in `vera-mode' buffers.")
243 (defvar vera-mode-ext-syntax-table
244 (let ((syntax-table (copy-syntax-table vera-mode-syntax-table)))
245 ;; extended syntax table including '_' (for simpler search regexps)
246 (modify-syntax-entry ?_ "w" syntax-table)
248 "Syntax table extended by `_' used in `vera-mode' buffers.")
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
253 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.vr[hi]?\\'" . vera-mode))
257 "Major mode for editing Vera code.
262 INDENTATION: Typing `TAB' at the beginning of a line indents the line.
263 The amount of indentation is specified by option `vera-basic-offset'.
264 Indentation can be done for an entire region \(`M-C-\\') or buffer (menu).
265 `TAB' always indents the line if option `vera-intelligent-tab' is nil.
267 WORD/COMMAND COMPLETION: Typing `TAB' after a (not completed) word looks
268 for a word in the buffer or a Vera keyword that starts alike, inserts it
269 and adjusts case. Re-typing `TAB' toggles through alternative word
272 Typing `TAB' after a non-word character inserts a tabulator stop (if not
273 at the beginning of a line). `M-TAB' always inserts a tabulator stop.
275 COMMENTS: `C-c C-c' comments out a region if not commented out, and
276 uncomments a region if already commented out.
278 HIGHLIGHTING (fontification): Vera keywords, predefined types and
279 constants, function names, declaration names, directives, as well as
280 comments and strings are highlighted using different colors.
282 VERA VERSION: OpenVera 1.4 and Vera version 6.2.8.
288 To submit a bug report, use the corresponding menu entry within Vera Mode.
289 Add a description of the problem and include a reproducible test case.
291 Feel free to send questions and enhancement requests to <reto@gnu.org>.
293 Official distribution is at
294 <http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html>.
297 The Vera Mode Maintainer
298 Reto Zimmermann <reto@gnu.org>
305 (kill-all-local-variables)
306 (setq major-mode 'vera-mode)
307 (setq mode-name "Vera")
308 ;; set maps and tables
309 (use-local-map vera-mode-map)
310 (set-syntax-table vera-mode-syntax-table)
311 ;; set local variables
313 (set (make-local-variable 'comment-start) "//")
314 (set (make-local-variable 'comment-end) "")
315 (set (make-local-variable 'comment-column) 40)
316 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *")
317 (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *//+")
318 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
319 (set (make-local-variable 'paragraph-start) "^$")
320 (set (make-local-variable 'paragraph-separate) paragraph-start)
321 (set (make-local-variable 'require-final-newline) t)
322 (set (make-local-variable 'indent-tabs-mode) nil)
323 (set (make-local-variable 'indent-line-function) 'vera-indent-line)
324 (set (make-local-variable 'parse-sexp-ignore-comments) t)
325 ;; initialize font locking
326 (set (make-local-variable 'font-lock-defaults)
327 '(vera-font-lock-keywords nil nil ((?\_ . "w"))))
329 (easy-menu-add vera-mode-menu)
331 (message "Vera Mode %s. Type C-c C-h for documentation." vera-version)
333 (run-hooks 'vera-mode-hook))
336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
343 (defconst vera-keywords
345 "after" "all" "any" "around" "assoc_index" "assoc_size" "async"
346 "bad_state" "bad_trans" "before" "begin" "big_endian" "bind"
347 "bin_activation" "bit_normal" "bit_reverse" "break" "breakpoint"
348 "case" "casex" "casez" "class" "constraint" "continue"
349 "coverage" "coverage_block" "coverage_def" "coverage_depth"
350 "coverage_goal" "coverage_group" "coverage_option" "coverage_val"
351 "cross_num_print_missing" "cross_auto_bin_max" "cov_comment"
352 "default" "depth" "dist" "do"
353 "else" "end" "enum" "exhaustive" "export" "extends" "extern"
354 "for" "foreach" "fork" "function"
355 "hdl_task" "hdl_node" "hide"
356 "if" "illegal_self_transition" "illegal_state" "illegal_transition"
357 "in" "interface" "invisible"
359 "little_endian" "local"
360 "m_bad_state" "m_bad_trans" "m_state" "m_trans"
361 "negedge" "new" "newcov" "non_rand" "none" "not" "null"
363 "packed" "port" "posedge" "proceed" "prod" "prodget" "prodset"
364 "program" "protected" "public"
365 "rand" "randc" "randcase" "randseq" "repeat" "return" "rules"
366 "sample" "sample_event" "shadow" "soft" "state" "static" "super"
367 "task" "terminate" "this" "trans" "typedef"
369 "var" "vca" "vector" "verilog_node" "verilog_task"
370 "vhdl_node" "vhdl_task" "virtual" "virtuals" "visible" "void"
371 "while" "wildcard" "with"
373 "List of Vera keywords.")
377 "integer" "bit" "reg" "string" "bind_var" "event"
378 "inout" "input" "output"
380 "NDRIVE" "NHOLD" "NRX" "NRZ" "NR0" "NR1" "NSAMPLE"
381 "PDRIVE" "PHOLD" "PRX" "PRZ" "PR0" "PR1" "PSAMPLE"
383 "List of Vera predefined types.")
385 (defconst vera-q-values
387 "gnr" "grx" "grz" "gr0" "gr1"
388 "nr" "rx" "rz" "r0" "r1"
389 "snr" "srx" "srz" "sr0" "sr1"
391 "List of Vera predefined VCA q_values.")
393 (defconst vera-functions
395 ;; system functions and tasks
397 "call_func" "call_task" "cast_assign" "close_conn" "cm_coverage"
398 "cm_get_coverage" "cm_get_limit"
399 "coverage_backup_database_file" "coverage_save_database"
401 "error" "error_mode" "error_wait" "exit"
402 "fclose" "feof" "ferror" "fflush" "flag" "fopen" "fprintf" "freadb"
403 "freadb" "freadh" "freadstr"
404 "get_bind" "get_bind_id" "get_conn_err" "get_cycle" "get_env"
405 "get_memsize" "get_plus_arg" "get_systime" "get_time" "get_time_unit"
409 "mailbox_get" "mailbox_put" "mailbox_receive" "mailbox_send"
410 "make_client" "make_server"
413 "query" "query_str" "query_x"
414 "rand48" "random" "region_enter" "region_exit" "rewind"
415 "semaphore_get" "semaphore_put" "setstate" "signal_connect" "simwave_plot"
416 "srandom" "sprintf" "sscanf" "stop" "suspend_thread" "sync"
417 "timeout" "trace" "trigger"
418 "unit_delay" "unlock_file" "up_connections"
419 "urand48" "urandom" "urandom_range"
420 "vera_bit_reverse" "vera_crc" "vera_pack" "vera_pack_big_endian"
421 "vera_plot" "vera_report_profile" "vera_unpack" "vera_unpack_big_endian"
422 "vsv_call_func" "vsv_call_task" "vsv_close_conn" "vsv_get_conn_err"
423 "vsv_make_client" "vsv_make_server" "vsv_up_connections"
424 "vsv_wait_for_done" "vsv_wait_for_input"
425 "wait_child" "wait_var"
427 "Configure" "DisableTrigger" "DoAction" "EnableCount" "EnableTrigger"
428 "Event" "GetAssert" "GetCount" "GetFirstAssert" "GetName" "GetNextAssert"
430 "atobin" "atohex" "atoi" "atooct"
431 "backref" "bittostr" "capacity" "compare" "constraint_mode"
434 "find" "find_index" "first" "first_index"
435 "get_at_least" "get_auto_bin" "get_cov_weight" "get_coverage_goal"
436 "get_cross_bin_max" "get_status" "get_status_msg" "getc"
438 "icompare" "insert" "inst_get_at_least" "inst_get_auto_bin_max"
439 "inst_get_collect" "inst_get_cov_weight" "inst_get_coverage_goal"
440 "inst_getcross_bin_max" "inst_query" "inst_set_at_least"
441 "inst_set_auto_bin_max" "inst_set_bin_activiation" "inst_set_collect"
442 "inst_set_cov_weight" "inst_set_coverage_goal" "inst_set_cross_bin_max"
444 "last" "last_index" "len" "load"
445 "match" "max" "max_index" "min" "min_index"
446 "object_compare" "object_copy" "object_print"
447 "pack" "pick_index" "pop_back" "pop_front" "post_pack" "post_randomize"
448 "post_unpack" "postmatch" "pre_pack" "pre_randomize" "prematch" "push_back"
451 "rand_mode" "randomize" "reserve" "reverse" "rsort"
452 "search" "set_at_least" "set_auto_bin_max" "set_bin_activiation"
453 "set_cov_weight" "set_coverage_goal" "set_cross_bin_max" "set_name" "size"
454 "sort" "substr" "sum"
455 "thismatch" "tolower" "toupper"
456 "unique_index" "unpack"
458 "new" "object_compare"
459 "post_boundary" "post_pack" "post_randomize" "post_unpack" "pre-randomize"
460 "pre_boundary" "pre_pack" "pre_unpack"
462 "List of Vera predefined system functions, tasks and class methods.")
464 (defconst vera-constants
467 "BAD_STATE" "BAD_TRANS"
468 "CALL" "CHECK" "CHGEDGE" "CLEAR" "COPY_NO_WAIT" "COPY_WAIT"
469 "CROSS" "CROSS_TRANS"
471 "EC_ARRAYX" "EC_CODE_END" "EC_CONFLICT" "EC_EVNTIMOUT" "EC_EXPECT"
472 "EC_FULLEXPECT" "EC_MBXTMOUT" "EC_NEXPECT" "EC_RETURN" "EC_RGNTMOUT"
473 "EC_SCONFLICT" "EC_SEMTMOUT" "EC_SEXPECT" "EC_SFULLEXPECT" "EC_SNEXTPECT"
474 "EC_USERSET" "EQ" "EVENT"
475 "FAIL" "FIRST" "FORK"
476 "GE" "GOAL" "GT" "HAND_SHAKE" "HI" "HIGH" "HNUM"
477 "LE" "LIC_EXIT" "LIC_PRERR" "LIC_PRWARN" "LIC_WAIT" "LO" "LOAD" "LOW" "LT"
479 "NAME" "NE" "NEGEDGE" "NEXT" "NO_OVERLAP" "NO_OVERLAP_STATE"
480 "NO_OVERLAP_TRANS" "NO_VARS" "NO_WAIT" "NUM" "NUM_BIN" "NUM_DET"
481 "OFF" "OK" "OK_LAST" "ON" "ONE_BLAST" "ONE_SHOT" "ORDER"
482 "PAST_IT" "PERCENT" "POSEDGE" "PROGRAM"
483 "RAWIN" "REGION" "REPORT"
484 "SAMPLE" "SAVE" "SEMAPHORE" "SET" "SILENT" "STATE" "STR"
485 "STR_ERR_OUT_OF_RANGE" "STR_ERR_REGEXP_SYNTAX" "SUM"
489 "stderr" "stdin" "stdout"
491 "List of Vera predefined constants.")
493 (defconst vera-rvm-types
495 "VeraListIterator_VeraListIterator_rvm_log"
496 "VeraListIterator_rvm_data" "VeraListIterator_rvm_log"
497 "VeraListNodeVeraListIterator_rvm_log" "VeraListNodervm_data"
498 "VeraListNodervm_log" "VeraList_VeraListIterator_rvm_log"
499 "VeraList_rvm_data" "VeraList_rvm_log"
500 "rvm_broadcast" "rvm_channel_class" "rvm_data" "rvm_data" "rvm_env"
501 "rvm_log" "rvm_log_modifier" "rvm_log_msg" "rvm_log_msg" "rvm_log_msg_info"
502 "rvm_log_watchpoint" "rvm_notify" "rvm_notify_event"
503 "rvm_notify_event_config" "rvm_scheduler" "rvm_scheduler_election"
504 "rvm_watchdog" "rvm_watchdog_port" "rvm_xactor" "rvm_xactor_callbacks"
506 "List of Vera-RVM keywords.")
508 (defconst vera-rvm-functions
510 "extern_rvm_atomic_gen" "extern_rvm_channel" "extern_rvm_scenario_gen"
511 "rvm_OO_callback" "rvm_atomic_gen" "rvm_atomic_gen_callbacks_decl"
512 "rvm_atomic_gen_decl" "rvm_atomic_scenario_decl" "rvm_channel"
513 "rvm_channel_" "rvm_channel_decl" "rvm_command" "rvm_cycle" "rvm_debug"
514 "rvm_error" "rvm_fatal" "rvm_note" "rvm_protocol" "rvm_report"
515 "rvm_scenario_decl" "rvm_scenario_election_decl" "rvm_scenario_gen"
516 "rvm_scenario_gen_callbacks_decl" "rvm_scenario_gen_decl"
517 "rvm_trace" "rvm_transaction" "rvm_user" "rvm_verbose" "rvm_warning"
519 "List of Vera-RVM functions.")
521 (defconst vera-rvm-constants
523 "RVM_NUMERIC_VERSION_MACROS" "RVM_VERSION" "RVM_MINOR" "RVM_PATCH"
524 "rvm_channel__SOURCE" "rvm_channel__SINK" "rvm_channel__NO_ACTIVE"
525 "rvm_channel__ACT_PENDING" "rvm_channel__ACT_STARTED"
526 "rvm_channel__ACT_COMPLETED" "rvm_channel__FULL" "rvm_channel__EMPTY"
527 "rvm_channel__PUT" "rvm_channel__GOT" "rvm_channel__PEEKED"
528 "rvm_channel__ACTIVATED" "rvm_channel__STARTED" "rvm_channel__COMPLETED"
529 "rvm_channel__REMOVED" "rvm_channel__LOCKED" "rvm_channel__UNLOCKED"
530 "rvm_data__EXECUTE" "rvm_data__STARTED" "rvm_data__ENDED"
531 "rvm_env__CFG_GENED" "rvm_env__BUILT" "rvm_env__DUT_CFGED"
532 "rvm_env__STARTED" "rvm_env__RESTARTED" "rvm_env__ENDED" "rvm_env__STOPPED"
533 "rvm_env__CLEANED" "rvm_env__DONE" "rvm_log__DEFAULT" "rvm_log__UNCHANGED"
534 "rvm_log__FAILURE_TYP" "rvm_log__NOTE_TYP" "rvm_log__DEBUG_TYP"
535 "rvm_log__REPORT_TYP" "rvm_log__NOTIFY_TYP" "rvm_log__TIMING_TYP"
536 "rvm_log__XHANDLING_TYP" "rvm_log__PROTOCOL_TYP" "rvm_log__TRANSACTION_TYP"
537 "rvm_log__COMMAND_TYP" "rvm_log__CYCLE_TYP" "rvm_log__USER_TYP_0"
538 "rvm_log__USER_TYP_1" "rvm_log__USER_TYP_2" "rvm_log__USER_TYP_3"
539 "rvm_log__DEFAULT_TYP" "rvm_log__ALL_TYPES" "rvm_log__FATAL_SEV"
540 "rvm_log__ERROR_SEV" "rvm_log__WARNING_SEV" "rvm_log__NORMAL_SEV"
541 "rvm_log__TRACE_SEV" "rvm_log__DEBUG_SEV" "rvm_log__VERBOSE_SEV"
542 "rvm_log__HIDDEN_SEV" "rvm_log__IGNORE_SEV" "rvm_log__DEFAULT_SEV"
543 "rvm_log__ALL_SEVERITIES" "rvm_log__CONTINUE" "rvm_log__COUNT_AS_ERROR"
544 "rvm_log__DEBUGGER" "rvm_log__DUMP" "rvm_log__STOP" "rvm_log__ABORT"
545 "rvm_notify__ONE_SHOT_TRIGGER" "rvm_notify__ONE_BLAST_TRIGGER"
546 "rvm_notify__HAND_SHAKE_TRIGGER" "rvm_notify__ON_OFF_TRIGGER"
547 "rvm_xactor__XACTOR_IDLE" "rvm_xactor__XACTOR_BUSY"
548 "rvm_xactor__XACTOR_STARTED" "rvm_xactor__XACTOR_STOPPED"
549 "rvm_xactor__XACTOR_RESET" "rvm_xactor__XACTOR_SOFT_RST"
550 "rvm_xactor__XACTOR_FIRM_RST" "rvm_xactor__XACTOR_HARD_RST"
551 "rvm_xactor__XACTOR_PROTOCOL_RST" "rvm_broadcast__AFAP"
552 "rvm_broadcast__ALAP" "rvm_watchdog__TIMEOUT"
553 "rvm_env__DUT_RESET" "rvm_log__INTERNAL_TYP"
554 "RVM_SCHEDULER_IS_XACTOR" "RVM_BROADCAST_IS_XACTOR"
556 "List of Vera-RVM predefined constants.")
558 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
559 (unless (fboundp 'regexp-opt)
560 (defun regexp-opt (strings &optional paren)
561 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
562 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
564 (defconst vera-keywords-regexp
565 (concat "\\<\\(" (regexp-opt vera-keywords) "\\)\\>")
566 "Regexp for Vera keywords.")
568 (defconst vera-types-regexp
569 (concat "\\<\\(" (regexp-opt vera-types) "\\)\\>")
570 "Regexp for Vera predefined types.")
572 (defconst vera-q-values-regexp
573 (concat "\\<\\(" (regexp-opt vera-q-values) "\\)\\>")
574 "Regexp for Vera predefined VCA q_values.")
576 (defconst vera-functions-regexp
577 (concat "\\<\\(" (regexp-opt vera-functions) "\\)\\>")
578 "Regexp for Vera predefined system functions, tasks and class methods.")
580 (defconst vera-constants-regexp
581 (concat "\\<\\(" (regexp-opt vera-constants) "\\)\\>")
582 "Regexp for Vera predefined constants.")
584 (defconst vera-rvm-types-regexp
585 (concat "\\<\\(" (regexp-opt vera-rvm-types) "\\)\\>")
586 "Regexp for Vera-RVM keywords.")
588 (defconst vera-rvm-functions-regexp
589 (concat "\\<\\(" (regexp-opt vera-rvm-functions) "\\)\\>")
590 "Regexp for Vera-RVM predefined system functions, tasks and class methods.")
592 (defconst vera-rvm-constants-regexp
593 (concat "\\<\\(" (regexp-opt vera-rvm-constants) "\\)\\>")
594 "Regexp for Vera-RVM predefined constants.")
597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
601 ;; XEmacs compatibility
604 (copy-face 'font-lock-reference-face 'font-lock-constant-face)
605 (copy-face 'font-lock-preprocessor-face 'font-lock-builtin-face))
607 (defun vera-font-lock-match-item (limit)
608 "Match, and move over, any declaration item after point. Adapted from
609 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
612 (narrow-to-region (point-min) limit)
614 (when (looking-at "\\s-*\\(\\w+\\)")
616 (goto-char (match-end 1))
618 (if (looking-at "\\(\\s-*\\(\\[[^]]*\\]\\s-*\\)?,\\)")
619 (goto-char (match-end 1))
623 (defvar vera-font-lock-keywords
625 ;; highlight keywords
626 (list vera-keywords-regexp 1 'font-lock-keyword-face)
628 (list vera-types-regexp 1 'font-lock-type-face)
629 ;; highlight RVM types
630 (list vera-rvm-types-regexp 1 'font-lock-type-face)
631 ;; highlight constants
632 (list vera-constants-regexp 1 'font-lock-constant-face)
633 ;; highlight RVM constants
634 (list vera-rvm-constants-regexp 1 'font-lock-constant-face)
635 ;; highlight q_values
636 (list vera-q-values-regexp 1 'font-lock-constant-face)
637 ;; highlight predefined functions, tasks and methods
638 (list vera-functions-regexp 1 'vera-font-lock-function)
639 ;; highlight predefined RVM functions
640 (list vera-rvm-functions-regexp 1 'vera-font-lock-function)
641 ;; highlight functions
642 '("\\<\\(\\w+\\)\\s-*(" 1 font-lock-function-name-face)
643 ;; highlight various declaration names
644 '("^\\s-*\\(port\\|program\\|task\\)\\s-+\\(\\w+\\)\\>"
645 2 font-lock-function-name-face)
646 '("^\\s-*bind\\s-+\\(\\w+\\)\\s-+\\(\\w+\\)\\>"
647 (1 font-lock-function-name-face) (2 font-lock-function-name-face))
648 ;; highlight interface declaration names
649 '("^\\s-*\\(class\\|interface\\)\\s-+\\(\\w+\\)\\>"
650 2 vera-font-lock-interface)
651 ;; highlight variable name definitions
652 (list (concat "^\\s-*" vera-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
653 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
654 (list (concat "^\\s-*" vera-rvm-types-regexp "\\s-*\\(\\[[^]]+\\]\\s-+\\)?")
655 '(vera-font-lock-match-item nil nil (1 font-lock-variable-name-face)))
657 '("\\([0-9]*'[bdoh][0-9a-fA-FxXzZ_]+\\)" 1 vera-font-lock-number)
658 ;; highlight filenames in #include directives
659 '("^#\\s-*include\\s-*\\(<[^>\"\n]*>?\\)"
660 1 font-lock-string-face)
661 ;; highlight directives and directive names
662 '("^#\\s-*\\(\\w+\\)\\>[ \t!]*\\(\\w+\\)?"
663 (1 font-lock-builtin-face) (2 font-lock-variable-name-face nil t))
664 ;; highlight `@', `$' and `#'
665 '("\\([@$#]\\)" 1 font-lock-keyword-face)
666 ;; highlight @ and # definitions
667 '("@\\s-*\\(\\w*\\)\\(\\s-*,\\s-*\\(\\w+\\)\\)?\\>[^.]"
668 (1 vera-font-lock-number) (3 vera-font-lock-number nil t))
669 ;; highlight interface signal name
670 '("\\(\\w+\\)\\.\\w+" 1 vera-font-lock-interface)
672 "Regular expressions to highlight in Vera Mode.")
674 (defvar vera-font-lock-number 'vera-font-lock-number
675 "Face name to use for @ definitions.")
677 (defvar vera-font-lock-function 'vera-font-lock-function
678 "Face name to use for predefined functions and tasks.")
680 (defvar vera-font-lock-interface 'vera-font-lock-interface
681 "Face name to use for interface names.")
683 (defface vera-font-lock-number
684 '((((class color) (background light)) (:foreground "Gold4"))
685 (((class color) (background dark)) (:foreground "BurlyWood1"))
686 (t (:italic t :bold t)))
687 "Font lock mode face used to highlight @ definitions."
688 :group 'font-lock-highlighting-faces)
689 (put 'vera-font-lock-number-face 'face-alias 'vera-font-lock-number)
691 (defface vera-font-lock-function
692 '((((class color) (background light)) (:foreground "DarkCyan"))
693 (((class color) (background dark)) (:foreground "Orchid1"))
694 (t (:italic t :bold t)))
695 "Font lock mode face used to highlight predefined functions and tasks."
696 :group 'font-lock-highlighting-faces)
697 (put 'vera-font-lock-function-face 'face-alias 'vera-font-lock-function)
699 (defface vera-font-lock-interface
700 '((((class color) (background light)) (:foreground "Grey40"))
701 (((class color) (background dark)) (:foreground "Grey80"))
702 (t (:italic t :bold t)))
703 "Font lock mode face used to highlight interface names."
704 :group 'font-lock-highlighting-faces)
705 (put 'vera-font-lock-interface-face 'face-alias 'vera-font-lock-interface)
707 (defun vera-fontify-buffer ()
710 (font-lock-fontify-buffer))
713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
717 (defvar vera-echo-syntactic-information-p nil
718 "If non-nil, syntactic info is echoed when the line is indented.")
720 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
723 (defconst vera-offsets-alist
724 '((comment . vera-lineup-C-comments)
725 (comment-intro . vera-lineup-comment)
733 (arglist-cont-nonempty . 0)
739 "Association list of syntactic element symbols and indentation offsets.
740 Adapted from `c-offsets-alist'.")
742 (defun vera-evaluate-offset (offset langelem symbol)
743 "OFFSET can be a number, a function, a variable, a list, or one of
746 ((eq offset '+) (setq offset vera-basic-offset))
747 ((eq offset '-) (setq offset (- vera-basic-offset)))
748 ((eq offset '++) (setq offset (* 2 vera-basic-offset)))
749 ((eq offset '--) (setq offset (* 2 (- vera-basic-offset))))
750 ((eq offset '*) (setq offset (/ vera-basic-offset 2)))
751 ((eq offset '/) (setq offset (/ (- vera-basic-offset) 2)))
752 ((functionp offset) (setq offset (funcall offset langelem)))
756 (while (and (not done) offset)
757 (setq done (vera-evaluate-offset (car offset) langelem symbol)
758 offset (cdr offset)))
762 ((not (numberp offset)) (setq offset (symbol-value offset))))
765 (defun vera-get-offset (langelem)
766 "Get offset from LANGELEM which is a cons cell of the form:
767 \(SYMBOL . RELPOS). The symbol is matched against
768 vera-offsets-alist and the offset found there is either returned,
769 or added to the indentation at RELPOS. If RELPOS is nil, then
770 the offset is simply returned."
771 (let* ((symbol (car langelem))
772 (relpos (cdr langelem))
773 (match (assq symbol vera-offsets-alist))
774 (offset (cdr-safe match)))
778 (setq offset (vera-evaluate-offset offset langelem symbol)))
780 (< relpos (save-excursion (beginning-of-line) (point))))
785 (vera-evaluate-offset offset langelem symbol))))
787 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
790 (defsubst vera-point (position)
791 "Returns the value of point at certain commonly referenced POSITIONs.
792 POSITION can be one of the following symbols:
793 bol -- beginning of line
795 boi -- back to indentation
796 ionl -- indentation of next line
797 iopl -- indentation of previous line
798 bonl -- beginning of next line
799 bopl -- beginning of previous line
800 This function does not modify point or mark."
803 ((eq position 'bol) (beginning-of-line))
804 ((eq position 'eol) (end-of-line))
805 ((eq position 'boi) (back-to-indentation))
806 ((eq position 'bonl) (forward-line 1))
807 ((eq position 'bopl) (forward-line -1))
808 ((eq position 'iopl) (forward-line -1) (back-to-indentation))
809 ((eq position 'ionl) (forward-line 1) (back-to-indentation))
810 (t (error "Unknown buffer position requested: %s" position)))
813 (defun vera-in-literal (&optional lim)
814 "Determine if point is in a Vera literal."
816 (let ((state (parse-partial-sexp (or lim (point-min)) (point))))
818 ((nth 3 state) 'string)
819 ((nth 4 state) 'comment)
822 (defun vera-in-comment-p ()
823 "Determine if point is in a Vera comment."
825 (re-search-backward "\\(/\\*\\)\\|\\(\\*/\\)" nil t)
828 (defun vera-skip-forward-literal ()
829 "Skip forward literal and return t if within one."
830 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
832 ((nth 3 state) (search-forward "\"") t) ; inside string
833 ((nth 7 state) (forward-line 1) t) ; inside // comment
834 ((nth 4 state) (search-forward "*/") t) ; inside /* */ comment
837 (defun vera-skip-backward-literal ()
838 "Skip backward literal and return t if within one."
839 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
841 ((nth 3 state) (search-backward "\"") t) ; inside string
842 ((nth 7 state) (search-backward "//") t) ; inside // comment
843 ((nth 4 state) (search-backward "/*") t) ; inside /* */ comment
846 (defsubst vera-re-search-forward (regexp &optional bound noerror)
847 "Like `re-search-forward', but skips over matches in literals."
848 (store-match-data '(nil nil))
849 (while (and (re-search-forward regexp bound noerror)
850 (vera-skip-forward-literal)
851 (progn (store-match-data '(nil nil))
852 (if bound (< (point) bound) t))))
855 (defsubst vera-re-search-backward (regexp &optional bound noerror)
856 "Like `re-search-backward', but skips over matches in literals."
857 (store-match-data '(nil nil))
858 (while (and (re-search-backward regexp bound noerror)
859 (vera-skip-backward-literal)
860 (progn (store-match-data '(nil nil))
861 (if bound (> (point) bound) t))))
864 (defun vera-forward-syntactic-ws (&optional lim skip-directive)
865 "Forward skip of syntactic whitespace."
867 (let* ((lim (or lim (point-max)))
869 (hugenum (point-max)))
870 (narrow-to-region lim (point))
871 (while (/= here (point))
873 (forward-comment hugenum)
874 (when (and skip-directive (looking-at "^\\s-*#"))
877 (defun vera-backward-syntactic-ws (&optional lim skip-directive)
878 "Backward skip over syntactic whitespace."
880 (let* ((lim (or lim (point-min)))
882 (hugenum (- (point-max))))
883 (when (< lim (point))
884 (narrow-to-region lim (point))
885 (while (/= here (point))
887 (forward-comment hugenum)
888 (when (and skip-directive
889 (save-excursion (back-to-indentation)
890 (= (following-char) ?\#)))
891 (beginning-of-line)))))))
893 (defmacro vera-prepare-search (&rest body)
894 "Switch to syntax table that includes '_', then execute BODY, and finally
895 restore the old environment. Used for consistent searching."
896 `(let ((current-syntax-table (syntax-table))
898 (restore-prog ; program to restore enviroment
900 ;; restore syntax table
901 (set-syntax-table current-syntax-table))))
902 ;; use extended syntax table
903 (set-syntax-table vera-mode-ext-syntax-table)
904 ;; execute BODY safely
908 (error (eval restore-prog) ; restore environment on error
909 (error (cadr info))))) ; pass error up
910 ;; restore environment
914 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
915 ;; comment indentation functions
917 (defsubst vera-langelem-col (langelem &optional preserve-point)
918 "Convenience routine to return the column of LANGELEM's relpos.
919 Leaves point at the relpos unless PRESERVE-POINT is non-nil."
920 (let ((here (point)))
921 (goto-char (cdr langelem))
922 (prog1 (current-column)
926 (defun vera-lineup-C-comments (langelem)
927 "Line up C block comment continuation lines.
928 Nicked from `c-lineup-C-comments'."
931 (stars (progn (back-to-indentation)
932 (skip-chars-forward "*")))
933 (langelem-col (vera-langelem-col langelem)))
934 (back-to-indentation)
935 (if (not (re-search-forward "/\\([*]+\\)" (vera-point 'eol) t))
937 (if (not (looking-at "[*]+"))
939 ;; we now have to figure out where this comment begins.
941 (back-to-indentation)
942 (if (looking-at "[*]+/")
943 (progn (goto-char (match-end 0))
944 (forward-comment -1))
945 (goto-char (cdr langelem))
946 (back-to-indentation))))
947 (- (current-column) langelem-col))
950 (skip-chars-forward " \t")
951 (- (current-column) langelem-col))
952 ;; how many stars on comment opening line? if greater than
953 ;; on current line, align left. if less than or equal,
954 ;; align right. this should also pick up Javadoc style
956 (if (> (length (match-string 1)) stars)
958 (back-to-indentation)
959 (- (current-column) -1 langelem-col))
960 (- (current-column) stars langelem-col)))))))
962 (defun vera-lineup-comment (langelem)
963 "Line up a comment start."
965 (back-to-indentation)
967 ;; not indent if at beginning of line
969 ;; otherwise indent accordingly
970 (goto-char (cdr langelem))
973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
976 (defconst vera-beg-block-re "{\\|\\<\\(begin\\|fork\\)\\>")
978 (defconst vera-end-block-re "}\\|\\<\\(end\\|join\\(\\s-+\\(all\\|any\\|none\\)\\)?\\)\\>")
980 (defconst vera-beg-substatement-re "\\<\\(else\\|for\\|if\\|repeat\\|while\\)\\>")
982 (defun vera-corresponding-begin (&optional recursive)
983 "Find corresponding block begin if cursor is at a block end."
984 (while (and (vera-re-search-backward
985 (concat "\\(" vera-end-block-re "\\)\\|" vera-beg-block-re)
988 (vera-corresponding-begin t))
989 (unless recursive (vera-beginning-of-substatement)))
991 (defun vera-corresponding-if ()
992 "Find corresponding `if' if cursor is at `else'."
993 (while (and (vera-re-search-backward "}\\|\\<\\(if\\|else\\)\\>" nil t)
994 (not (equal (match-string 0) "if")))
995 (if (equal (match-string 0) "else")
996 (vera-corresponding-if)
1000 (defun vera-beginning-of-statement ()
1001 "Go to beginning of current statement."
1005 ;; search for end of previous statement
1007 (and (vera-re-search-backward
1008 (concat "[);]\\|" vera-beg-block-re
1009 "\\|" vera-end-block-re) nil t)
1010 (equal (match-string 0) ")"))
1013 (setq pos (match-beginning 0))
1014 ;; go back to beginning of current statement
1015 (goto-char (or (match-end 0) 0))
1016 (vera-forward-syntactic-ws nil t)
1017 (when (looking-at "(")
1019 (vera-forward-syntactic-ws nil t))
1020 ;; if "else" found, go to "if" and search again
1021 (when (looking-at "\\<else\\>")
1022 (vera-corresponding-if)
1025 ;; if search is repeated, go to beginning of last search
1028 (defun vera-beginning-of-substatement ()
1029 "Go to beginning of current substatement."
1032 ;; go to beginning of statement
1033 (vera-beginning-of-statement)
1035 ;; go forward all substatement opening statements until at LIM
1036 (while (and (< (point) lim)
1037 (vera-re-search-forward vera-beg-substatement-re lim t))
1038 (setq pos (match-beginning 0)))
1039 (vera-forward-syntactic-ws nil t)
1040 (when (looking-at "(")
1042 (vera-forward-syntactic-ws nil t))
1043 (when (< (point) lim)
1047 (defun vera-forward-statement ()
1048 "Move forward one statement."
1050 (vera-prepare-search
1051 (while (and (vera-re-search-forward
1052 (concat "[(;]\\|" vera-beg-block-re "\\|" vera-end-block-re)
1054 (equal (match-string 0) "("))
1057 (vera-beginning-of-substatement)))
1059 (defun vera-backward-statement ()
1060 "Move backward one statement."
1062 (vera-prepare-search
1063 (vera-backward-syntactic-ws nil t)
1064 (unless (= (preceding-char) ?\))
1066 (vera-beginning-of-substatement)))
1068 (defun vera-forward-same-indent ()
1069 "Move forward to next line with same indent."
1072 (indent (current-indentation)))
1073 (beginning-of-line 2)
1074 (while (and (not (eobp))
1075 (or (looking-at "^\\s-*$")
1076 (> (current-indentation) indent)))
1077 (beginning-of-line 2))
1078 (if (= (current-indentation) indent)
1079 (back-to-indentation)
1080 (message "No following line with same indent found in this block")
1083 (defun vera-backward-same-indent ()
1084 "Move backward to previous line with same indent."
1087 (indent (current-indentation)))
1088 (beginning-of-line -0)
1089 (while (and (not (bobp))
1090 (or (looking-at "^\\s-*$")
1091 (> (current-indentation) indent)))
1092 (beginning-of-line -0))
1093 (if (= (current-indentation) indent)
1094 (back-to-indentation)
1095 (message "No preceding line with same indent found in this block")
1098 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1101 (defmacro vera-add-syntax (symbol &optional relpos)
1102 "A simple macro to append the syntax in SYMBOL to the syntax list.
1103 try to increase performance by using this macro."
1104 `(setq syntax (cons (cons ,symbol ,(or relpos 0)) syntax)))
1106 (defun vera-guess-basic-syntax ()
1107 "Determine syntactic context of current line of code."
1110 (let ((indent-point (point))
1111 syntax state placeholder pos)
1112 ;; determine syntax state
1113 (setq state (parse-partial-sexp (point-min) (point)))
1115 ;; CASE 1: in a comment?
1118 (while (and (zerop (forward-line -1))
1119 (looking-at "^\\s-*$")))
1120 (vera-add-syntax 'comment (vera-point 'boi)))
1121 ;; CASE 2: in a string?
1123 (vera-add-syntax 'string))
1124 ;; CASE 3: at a directive?
1125 ((save-excursion (back-to-indentation) (= (following-char) ?\#))
1126 (vera-add-syntax 'directive (point)))
1127 ;; CASE 4: after an opening parenthesis (argument list continuation)?
1129 (or (= (char-after (nth 1 state)) ?\()
1130 ;; also for concatenation (opening '{' and ',' on eol/eopl)
1131 (and (= (char-after (nth 1 state)) ?\{)
1133 (vera-backward-syntactic-ws) (= (char-before) ?,))
1135 (end-of-line) (= (char-before) ?,))))))
1136 (goto-char (1+ (nth 1 state)))
1137 ;; is there code after the opening parenthesis on the same line?
1138 (if (looking-at "\\s-*$")
1139 (vera-add-syntax 'arglist-cont (vera-point 'boi))
1140 (vera-add-syntax 'arglist-cont-nonempty (point))))
1141 ;; CASE 5: at a block closing?
1142 ((save-excursion (back-to-indentation) (looking-at vera-end-block-re))
1143 ;; look for the corresponding begin
1144 (vera-corresponding-begin)
1145 (vera-add-syntax 'block-close (vera-point 'boi)))
1146 ;; CASE 6: at a block intro (the first line after a block opening)?
1147 ((and (save-excursion
1148 (vera-backward-syntactic-ws nil t)
1149 ;; previous line ends with a block opening?
1150 (or (/= (skip-chars-backward "{") 0) (backward-word 1))
1151 (when (looking-at vera-beg-block-re)
1152 ;; go to beginning of substatement
1153 (vera-beginning-of-substatement)
1154 (setq placeholder (point))))
1155 ;; not if "fork" is followed by "{"
1157 (not (and (progn (back-to-indentation) (looking-at "{"))
1158 (progn (goto-char placeholder)
1159 (looking-at "\\<fork\\>"))))))
1160 (goto-char placeholder)
1161 (vera-add-syntax 'block-intro (vera-point 'boi)))
1162 ;; CASE 7: at the beginning of an else clause?
1163 ((save-excursion (back-to-indentation) (looking-at "\\<else\\>"))
1164 ;; find corresponding if
1165 (vera-corresponding-if)
1166 (vera-add-syntax 'else-clause (vera-point 'boi)))
1167 ;; CASE 8: at the beginning of a statement?
1168 ;; is the previous command completed?
1169 ((or (save-excursion
1170 (vera-backward-syntactic-ws nil t)
1171 (setq placeholder (point))
1172 ;; at the beginning of the buffer?
1174 ;; previous line ends with a semicolon or
1175 ;; is a block opening or closing?
1176 (when (or (/= (skip-chars-backward "{};") 0)
1177 (progn (back-to-indentation)
1178 (looking-at (concat vera-beg-block-re "\\|"
1179 vera-end-block-re))))
1180 ;; if at a block closing, go to beginning
1181 (when (looking-at vera-end-block-re)
1182 (vera-corresponding-begin))
1183 ;; go to beginning of the statement
1184 (vera-beginning-of-statement)
1185 (setq placeholder (point)))
1187 (when (progn (back-to-indentation) (looking-at "#"))
1188 ;; go to previous statement
1189 (vera-beginning-of-statement)
1190 (setq placeholder (point)))))
1191 ;; at a block opening?
1192 (when (save-excursion (back-to-indentation)
1193 (looking-at vera-beg-block-re))
1194 ;; go to beginning of the substatement
1195 (vera-beginning-of-substatement)
1196 (setq placeholder (point))))
1197 (goto-char placeholder)
1198 (vera-add-syntax 'statement (vera-point 'boi)))
1199 ;; CASE 9: at the beginning of a substatement?
1200 ;; is this line preceeded by a substatement opening statement?
1201 ((save-excursion (vera-backward-syntactic-ws nil t)
1202 (when (= (preceding-char) ?\)) (backward-sexp))
1204 (setq placeholder (point))
1205 (looking-at vera-beg-substatement-re))
1206 (goto-char placeholder)
1207 (vera-add-syntax 'substatement (vera-point 'boi)))
1208 ;; CASE 10: it must be a statement continuation!
1210 ;; go to beginning of statement
1211 (vera-beginning-of-substatement)
1212 (vera-add-syntax 'statement-cont (vera-point 'boi))))
1213 ;; special case: look for a comment start
1214 (goto-char indent-point)
1215 (skip-chars-forward " \t")
1216 (when (looking-at comment-start)
1217 (vera-add-syntax 'comment-intro))
1221 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1222 ;; indentation functions
1224 (defun vera-indent-line ()
1225 "Indent the current line as Vera code. Optional SYNTAX is the
1226 syntactic information for the current line. Returns the amount of
1227 indentation change (in columns)."
1229 (vera-prepare-search
1230 (let* ((syntax (vera-guess-basic-syntax))
1231 (pos (- (point-max) (point)))
1232 (indent (apply '+ (mapcar 'vera-get-offset syntax)))
1233 (shift-amt (- (current-indentation) indent)))
1234 (when vera-echo-syntactic-information-p
1235 (message "syntax: %s, indent= %d" syntax indent))
1236 (unless (zerop shift-amt)
1238 (delete-region (point) (vera-point 'boi))
1240 (if (< (point) (vera-point 'boi))
1241 (back-to-indentation)
1242 ;; If initial point was within line's indentation, position after
1243 ;; the indentation. Else stay at same point in text.
1244 (when (> (- (point-max) pos) (point))
1245 (goto-char (- (point-max) pos))))
1248 (defun vera-indent-buffer ()
1249 "Indent whole buffer as Vera code.
1250 Calls `indent-region' for whole buffer."
1252 (message "Indenting buffer...")
1253 (indent-region (point-min) (point-max) nil)
1254 (message "Indenting buffer...done"))
1256 (defun vera-indent-region (start end column)
1257 "Indent region as Vera code."
1258 (interactive "r\nP")
1259 (message "Indenting region...")
1260 (indent-region start end column)
1261 (message "Indenting region...done"))
1263 (defsubst vera-indent-block-closing ()
1264 "If previous word is a block closing or `else', indent line again."
1265 (when (= (char-syntax (preceding-char)) ?w)
1268 (when (and (not (vera-in-literal))
1269 (looking-at (concat vera-end-block-re "\\|\\<else\\>")))
1270 (indent-according-to-mode)))))
1272 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1275 (defun vera-electric-tab (&optional prefix-arg)
1276 "If preceeding character is part of a word or a paren then hippie-expand,
1277 else if right of non whitespace on line then tab-to-tab-stop,
1278 else if last command was a tab or return then dedent one step or if a comment
1279 toggle between normal indent and inline comment indent,
1280 else indent `correctly'.
1281 If `vera-intelligent-tab' is nil, always indent line."
1283 (if vera-intelligent-tab
1285 (cond ((memq (char-syntax (preceding-char)) '(?w ?_))
1286 (let ((case-fold-search t)
1288 (hippie-expand-only-buffers
1289 (or (and (boundp 'hippie-expand-only-buffers)
1290 hippie-expand-only-buffers)
1292 (vera-expand-abbrev prefix-arg)))
1293 ((> (current-column) (current-indentation))
1295 ((and (or (eq last-command 'vera-electric-tab)
1296 (eq last-command 'vera-electric-return))
1297 (/= 0 (current-indentation)))
1298 (backward-delete-char-untabify vera-basic-offset nil))
1299 (t (indent-according-to-mode)))
1300 (setq this-command 'vera-electric-tab))
1301 (indent-according-to-mode)))
1303 (defun vera-electric-return ()
1304 "Insert newline and indent. Indent current line if it is a block closing."
1306 (vera-indent-block-closing)
1307 (newline-and-indent))
1309 (defun vera-electric-space (arg)
1310 "Insert a space. Indent current line if it is a block closing."
1313 (vera-indent-block-closing))
1314 (self-insert-command (prefix-numeric-value arg)))
1316 (defun vera-electric-opening-brace (arg)
1317 "Outdent opening brace."
1319 (self-insert-command (prefix-numeric-value arg))
1321 (indent-according-to-mode)))
1323 (defun vera-electric-closing-brace (arg)
1324 "Outdent closing brace."
1326 (self-insert-command (prefix-numeric-value arg))
1328 (indent-according-to-mode)))
1330 (defun vera-electric-pound (arg)
1331 "Insert `#' and indent as directive it first character of line."
1333 (self-insert-command (prefix-numeric-value arg))
1337 (skip-chars-backward " \t")
1339 (delete-horizontal-space)))))
1341 (defun vera-electric-star (arg)
1342 "Insert a star character. Nicked from `c-electric-star'."
1344 (self-insert-command (prefix-numeric-value arg))
1346 (memq (vera-in-literal) '(comment))
1347 (eq (char-before) ?*)
1350 (skip-chars-backward "*")
1351 (if (eq (char-before) ?/)
1353 (skip-chars-backward " \t")
1355 (indent-according-to-mode)))
1357 (defun vera-electric-slash (arg)
1358 "Insert a slash character. Nicked from `c-electric-slash'."
1360 (let* ((ch (char-before))
1361 (indentp (and (not arg)
1362 (eq last-command-char ?/)
1364 (not (vera-in-literal)))
1366 (vera-in-literal))))))
1367 (self-insert-command (prefix-numeric-value arg))
1369 (indent-according-to-mode))))
1372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1377 ;; Hippie expand customization (for expansion of Vera commands)
1379 (defvar vera-abbrev-list
1380 (append (list nil) vera-keywords
1381 (list nil) vera-types
1382 (list nil) vera-functions
1383 (list nil) vera-constants
1384 (list nil) vera-rvm-types
1385 (list nil) vera-rvm-functions
1386 (list nil) vera-rvm-constants)
1387 "Predefined abbreviations for Vera.")
1389 (defvar vera-expand-upper-case nil)
1391 (eval-when-compile (require 'hippie-exp))
1393 (defun vera-try-expand-abbrev (old)
1394 "Try expanding abbreviations from `vera-abbrev-list'."
1396 (he-init-string (he-dabbrev-beg) (point))
1397 (setq he-expand-list
1398 (let ((abbrev-list vera-abbrev-list)
1399 (sel-abbrev-list '()))
1401 (when (or (not (stringp (car abbrev-list)))
1403 (concat "^" he-search-string) (car abbrev-list)))
1404 (setq sel-abbrev-list
1405 (cons (car abbrev-list) sel-abbrev-list)))
1406 (setq abbrev-list (cdr abbrev-list)))
1407 (nreverse sel-abbrev-list))))
1408 (while (and he-expand-list
1409 (or (not (stringp (car he-expand-list)))
1410 (he-string-member (car he-expand-list) he-tried-table t)))
1411 (unless (stringp (car he-expand-list))
1412 (setq vera-expand-upper-case (car he-expand-list)))
1413 (setq he-expand-list (cdr he-expand-list)))
1414 (if (null he-expand-list)
1415 (progn (when old (he-reset-string))
1417 (he-substitute-string
1418 (if vera-expand-upper-case
1419 (upcase (car he-expand-list))
1420 (car he-expand-list))
1422 (setq he-expand-list (cdr he-expand-list))
1425 ;; function for expanding abbrevs and dabbrevs
1426 (defun vera-expand-abbrev (arg))
1427 (fset 'vera-expand-abbrev (make-hippie-expand-function
1428 '(try-expand-dabbrev
1429 try-expand-dabbrev-all-buffers
1430 vera-try-expand-abbrev)))
1432 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1435 (defun vera-comment-uncomment-region (beg end &optional arg)
1436 "Comment region if not commented, uncomment region if already commented."
1437 (interactive "r\nP")
1439 (if (looking-at (regexp-quote comment-start))
1440 (comment-region beg end '(4))
1441 (comment-region beg end)))
1443 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1446 (defun vera-customize ()
1447 "Call the customize function with `vera' as argument."
1449 (customize-group 'vera))
1451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1454 ;; remove ".vr" from `completion-ignored-extensions'
1455 (setq completion-ignored-extensions
1456 (delete ".vr" completion-ignored-extensions))
1459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1463 (defconst vera-mode-help-address "Reto Zimmermann <reto@gnu.org>"
1464 "Address for Vera Mode bug reports.")
1466 ;; get reporter-submit-bug-report when byte-compiling
1468 (require 'reporter))
1470 (defun vera-submit-bug-report ()
1471 "Submit via mail a bug report on Vera Mode."
1475 (y-or-n-p "Do you want to submit a report on Vera Mode? ")
1477 (let ((reporter-prompt-for-summary-p t))
1478 (reporter-submit-bug-report
1479 vera-mode-help-address
1480 (concat "Vera Mode " vera-version)
1482 ;; report all important variables
1484 'vera-underscore-is-part-of-word
1485 'vera-intelligent-tab
1491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1493 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1495 (defun vera-version ()
1496 "Echo the current version of Vera Mode in the minibuffer."
1498 (message "Vera Mode %s (%s)" vera-version vera-time-stamp))
1501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1503 (provide 'vera-mode)
1505 ;;; vera-mode.el ends here