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