]> code.delx.au - gnu-emacs/blob - lisp/progmodes/vera-mode.el
Add 2011 to FSF/AIST copyright years.
[gnu-emacs] / lisp / progmodes / vera-mode.el
1 ;;; vera-mode.el --- major mode for editing Vera files.
2
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5
6 ;; Author: Reto Zimmermann <reto@gnu.org>
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
8 ;; Version: 2.28
9 ;; Keywords: languages vera
10 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html
11
12 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
13 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
14 ;; filed in the Emacs bug reporting system against this file, a copy
15 ;; of the bug report be sent to the maintainer's email address.
16
17 (defconst vera-version "2.18"
18 "Vera Mode version number.")
19
20 (defconst vera-time-stamp "2007-06-21"
21 "Vera Mode time stamp for last update.")
22
23 ;; This file is part of GNU Emacs.
24
25 ;; GNU Emacs is free software: you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation, either version 3 of the License, or
28 ;; (at your option) any later version.
29
30 ;; GNU Emacs is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 ;; GNU General Public License for more details.
34
35 ;; You should have received a copy of the GNU General Public License
36 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;; Commentary:
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41
42 ;; This package provides a simple Emacs major mode for editing Vera code.
43 ;; It includes the following features:
44
45 ;; - Syntax highlighting
46 ;; - Indentation
47 ;; - Word/keyword completion
48 ;; - Block commenting
49 ;; - Works under GNU Emacs and XEmacs
50
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ;; Documentation
53
54 ;; See comment string of function `vera-mode' or type `C-h m' in Emacs.
55
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 ;; Installation
58
59 ;; Prerequisites: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X
60
61 ;; Put `vera-mode.el' into the `site-lisp' directory of your Emacs installation
62 ;; or into an arbitrary directory that is added to the load path by the
63 ;; following line in your Emacs start-up file (`.emacs'):
64
65 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
66
67 ;; If you already have the compiled `vera-mode.elc' file, put it in the same
68 ;; directory. Otherwise, byte-compile the source file:
69 ;; Emacs: M-x byte-compile-file -> vera-mode.el
70 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vera-mode.el
71
72 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
73 ;; directory of your Emacs installation or to your Emacs start-up file
74 ;; (`.emacs'):
75
76 ;; (autoload 'vera-mode "vera-mode" "Vera Mode" t)
77 ;; (setq auto-mode-alist (cons '("\\.vr[hi]?\\'" . vera-mode) auto-mode-alist))
78
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80
81 ;;; Code:
82
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84 ;;; Variables
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86
87 (defgroup vera nil
88 "Customizations for Vera Mode."
89 :prefix "vera-"
90 :version "22.2"
91 :group 'languages)
92
93 (defcustom vera-basic-offset 2
94 "*Amount of basic offset used for indentation."
95 :type 'integer
96 :group 'vera)
97
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."
103 :type 'boolean
104 :group 'vera)
105
106 (defcustom vera-intelligent-tab t
107 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
108 That is, if preceding 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."
113 :type 'boolean
114 :group 'vera)
115
116
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118 ;;; Mode definitions
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122 ;; Key bindings
123
124 (defvar vera-mode-map
125 (let ((map (make-sparse-keymap)))
126 ;; Backspace/delete key bindings.
127 (define-key map [backspace] 'backward-delete-char-untabify)
128 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
129 (define-key map [delete] 'delete-char)
130 (define-key map [(meta delete)] 'kill-word))
131 ;; Standard key bindings.
132 (define-key map "\M-e" 'vera-forward-statement)
133 (define-key map "\M-a" 'vera-backward-statement)
134 (define-key map "\M-\C-e" 'vera-forward-same-indent)
135 (define-key map "\M-\C-a" 'vera-backward-same-indent)
136 ;; Mode specific key bindings.
137 (define-key map "\C-c\t" 'indent-according-to-mode)
138 (define-key map "\M-\C-\\" 'vera-indent-region)
139 (define-key map "\C-c\C-c" 'vera-comment-uncomment-region)
140 (define-key map "\C-c\C-f" 'vera-fontify-buffer)
141 (define-key map "\C-c\C-v" 'vera-version)
142 (define-key map "\M-\t" 'tab-to-tab-stop)
143 ;; Electric key bindings.
144 (define-key map "\t" 'vera-electric-tab)
145 (define-key map "\r" 'vera-electric-return)
146 (define-key map " " 'vera-electric-space)
147 (define-key map "{" 'vera-electric-opening-brace)
148 (define-key map "}" 'vera-electric-closing-brace)
149 (define-key map "#" 'vera-electric-pound)
150 (define-key map "*" 'vera-electric-star)
151 (define-key map "/" 'vera-electric-slash)
152 map)
153 "Keymap for Vera Mode.")
154
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
156 ;; Menu
157
158 (require 'easymenu)
159
160 (easy-menu-define vera-mode-menu vera-mode-map
161 "Menu keymap for Vera Mode."
162 '("Vera"
163 ["(Un)Comment Out Region" vera-comment-uncomment-region (mark)]
164 "--"
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]
169 "--"
170 ["Indent Line" indent-according-to-mode t]
171 ["Indent Region" vera-indent-region (mark)]
172 ["Indent Buffer" vera-indent-buffer t]
173 "--"
174 ["Fontify Buffer" vera-fontify-buffer t]
175 "--"
176 ["Documentation" describe-mode]
177 ["Version" vera-version t]
178 ["Bug Report..." vera-submit-bug-report t]
179 "--"
180 ("Options"
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]
190 "--"
191 ["Save Options" customize-save-customized t]
192 "--"
193 ["Customize..." vera-customize t])))
194
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 ;; Syntax table
197
198 (defvar vera-mode-syntax-table
199 (let ((syntax-table (make-syntax-table)))
200 ;; punctuation
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)
218 ;; string
219 (modify-syntax-entry ?\" "\"" syntax-table)
220 ;; underscore
221 (when vera-underscore-is-part-of-word
222 (modify-syntax-entry ?\_ "w" syntax-table))
223 ;; escape
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)
232 ;; comment
233 (if (featurep 'xemacs)
234 (modify-syntax-entry ?\/ ". 1456" syntax-table) ; XEmacs
235 (modify-syntax-entry ?\/ ". 124b" syntax-table)) ; Emacs
236 (modify-syntax-entry ?\* ". 23" syntax-table)
237 ;; newline and CR
238 (modify-syntax-entry ?\n "> b" syntax-table)
239 (modify-syntax-entry ?\^M "> b" syntax-table)
240 syntax-table)
241 "Syntax table used in `vera-mode' buffers.")
242
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)
247 syntax-table)
248 "Syntax table extended by `_' used in `vera-mode' buffers.")
249
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
251 ;; Mode definition
252
253 ;;;###autoload (add-to-list 'auto-mode-alist (cons (purecopy "\\.vr[hi]?\\'") 'vera-mode))
254
255 ;;;###autoload
256 (defun vera-mode ()
257 "Major mode for editing Vera code.
258
259 Usage:
260 ------
261
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.
266
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
270 completions.
271
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.
274
275 COMMENTS: `C-c C-c' comments out a region if not commented out, and
276 uncomments a region if already commented out.
277
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.
281
282 VERA VERSION: OpenVera 1.4 and Vera version 6.2.8.
283
284
285 Maintenance:
286 ------------
287
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.
290
291 Feel free to send questions and enhancement requests to <reto@gnu.org>.
292
293 Official distribution is at
294 URL `http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html'
295
296
297 The Vera Mode Maintainer
298 Reto Zimmermann <reto@gnu.org>
299
300 Key bindings:
301 -------------
302
303 \\{vera-mode-map}"
304 (interactive)
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
312 (require 'cc-cmds)
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) " *\\*+/\\| *\n")
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"))))
328 ;; add menu (XEmacs)
329 (easy-menu-add vera-mode-menu)
330 ;; miscellaneous
331 (message "Vera Mode %s. Type C-c C-h for documentation." vera-version)
332 ;; run hooks
333 (run-hooks 'vera-mode-hook))
334
335
336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
337 ;;; Vera definitions
338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
339
340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
341 ;;; Keywords
342
343 (defconst vera-keywords
344 '(
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"
358 "join"
359 "little_endian" "local"
360 "m_bad_state" "m_bad_trans" "m_state" "m_trans"
361 "negedge" "new" "newcov" "non_rand" "none" "not" "null"
362 "or" "ordered"
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"
368 "unpacked"
369 "var" "vca" "vector" "verilog_node" "verilog_task"
370 "vhdl_node" "vhdl_task" "virtual" "virtuals" "visible" "void"
371 "while" "wildcard" "with"
372 )
373 "List of Vera keywords.")
374
375 (defconst vera-types
376 '(
377 "integer" "bit" "reg" "string" "bind_var" "event"
378 "inout" "input" "output"
379 "ASYNC" "CLOCK"
380 "NDRIVE" "NHOLD" "NRX" "NRZ" "NR0" "NR1" "NSAMPLE"
381 "PDRIVE" "PHOLD" "PRX" "PRZ" "PR0" "PR1" "PSAMPLE"
382 )
383 "List of Vera predefined types.")
384
385 (defconst vera-q-values
386 '(
387 "gnr" "grx" "grz" "gr0" "gr1"
388 "nr" "rx" "rz" "r0" "r1"
389 "snr" "srx" "srz" "sr0" "sr1"
390 )
391 "List of Vera predefined VCA q_values.")
392
393 (defconst vera-functions
394 '(
395 ;; system functions and tasks
396 "alloc"
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"
400 "delay"
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"
406 "getstate"
407 "initstate"
408 "lock_file"
409 "mailbox_get" "mailbox_put" "mailbox_receive" "mailbox_send"
410 "make_client" "make_server"
411 "os_command"
412 "printf" "psprintf"
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"
426 ;; class methods
427 "Configure" "DisableTrigger" "DoAction" "EnableCount" "EnableTrigger"
428 "Event" "GetAssert" "GetCount" "GetFirstAssert" "GetName" "GetNextAssert"
429 "Wait"
430 "atobin" "atohex" "atoi" "atooct"
431 "backref" "bittostr" "capacity" "compare" "constraint_mode"
432 "delete"
433 "empty"
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"
437 "hash"
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"
443 "itoa"
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"
449 "push_front" "putc"
450 "query" "query_str"
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"
457 ;; empty methods
458 "new" "object_compare"
459 "post_boundary" "post_pack" "post_randomize" "post_unpack" "pre-randomize"
460 "pre_boundary" "pre_pack" "pre_unpack"
461 )
462 "List of Vera predefined system functions, tasks and class methods.")
463
464 (defconst vera-constants
465 '(
466 "ALL" "ANY"
467 "BAD_STATE" "BAD_TRANS"
468 "CALL" "CHECK" "CHGEDGE" "CLEAR" "COPY_NO_WAIT" "COPY_WAIT"
469 "CROSS" "CROSS_TRANS"
470 "DEBUG" "DELETE"
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"
478 "MAILBOX" "MAX_COM"
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"
486 "TRANS"
487 "VERBOSE"
488 "WAIT"
489 "stderr" "stdin" "stdout"
490 )
491 "List of Vera predefined constants.")
492
493 (defconst vera-rvm-types
494 '(
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"
505 )
506 "List of Vera-RVM keywords.")
507
508 (defconst vera-rvm-functions
509 '(
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"
518 )
519 "List of Vera-RVM functions.")
520
521 (defconst vera-rvm-constants
522 '(
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"
555 )
556 "List of Vera-RVM predefined constants.")
557
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))))
563
564 (defconst vera-keywords-regexp
565 (concat "\\<\\(" (regexp-opt vera-keywords) "\\)\\>")
566 "Regexp for Vera keywords.")
567
568 (defconst vera-types-regexp
569 (concat "\\<\\(" (regexp-opt vera-types) "\\)\\>")
570 "Regexp for Vera predefined types.")
571
572 (defconst vera-q-values-regexp
573 (concat "\\<\\(" (regexp-opt vera-q-values) "\\)\\>")
574 "Regexp for Vera predefined VCA q_values.")
575
576 (defconst vera-functions-regexp
577 (concat "\\<\\(" (regexp-opt vera-functions) "\\)\\>")
578 "Regexp for Vera predefined system functions, tasks and class methods.")
579
580 (defconst vera-constants-regexp
581 (concat "\\<\\(" (regexp-opt vera-constants) "\\)\\>")
582 "Regexp for Vera predefined constants.")
583
584 (defconst vera-rvm-types-regexp
585 (concat "\\<\\(" (regexp-opt vera-rvm-types) "\\)\\>")
586 "Regexp for Vera-RVM keywords.")
587
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.")
591
592 (defconst vera-rvm-constants-regexp
593 (concat "\\<\\(" (regexp-opt vera-rvm-constants) "\\)\\>")
594 "Regexp for Vera-RVM predefined constants.")
595
596
597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
598 ;;; Font locking
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
600
601 ;; XEmacs compatibility
602 (when (featurep 'xemacs)
603 (require 'font-lock)
604 (copy-face 'font-lock-reference-face 'font-lock-constant-face)
605 (copy-face 'font-lock-preprocessor-face 'font-lock-builtin-face))
606
607 (defun vera-font-lock-match-item (limit)
608 "Match, and move over, any declaration item after point.
609 Adapted from `font-lock-match-c-style-declaration-item-and-skip-to-next'."
610 (condition-case nil
611 (save-restriction
612 (narrow-to-region (point-min) limit)
613 ;; match item
614 (when (looking-at "\\s-*\\(\\w+\\)")
615 (save-match-data
616 (goto-char (match-end 1))
617 ;; move to next item
618 (if (looking-at "\\(\\s-*\\(\\[[^]]*\\]\\s-*\\)?,\\)")
619 (goto-char (match-end 1))
620 (end-of-line) t))))
621 (error t)))
622
623 (defvar vera-font-lock-keywords
624 (list
625 ;; highlight keywords
626 (list vera-keywords-regexp 1 'font-lock-keyword-face)
627 ;; highlight types
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)))
656 ;; highlight numbers
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)
671 )
672 "Regular expressions to highlight in Vera Mode.")
673
674 (defvar vera-font-lock-number 'vera-font-lock-number
675 "Face name to use for @ definitions.")
676
677 (defvar vera-font-lock-function 'vera-font-lock-function
678 "Face name to use for predefined functions and tasks.")
679
680 (defvar vera-font-lock-interface 'vera-font-lock-interface
681 "Face name to use for interface names.")
682
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
690 (defface vera-font-lock-function
691 '((((class color) (background light)) (:foreground "DarkCyan"))
692 (((class color) (background dark)) (:foreground "Orchid1"))
693 (t (:italic t :bold t)))
694 "Font lock mode face used to highlight predefined functions and tasks."
695 :group 'font-lock-highlighting-faces)
696
697 (defface vera-font-lock-interface
698 '((((class color) (background light)) (:foreground "Grey40"))
699 (((class color) (background dark)) (:foreground "Grey80"))
700 (t (:italic t :bold t)))
701 "Font lock mode face used to highlight interface names."
702 :group 'font-lock-highlighting-faces)
703
704 (defalias 'vera-fontify-buffer 'font-lock-fontify-buffer)
705
706 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
707 ;;; Indentation
708 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
709
710 (defvar vera-echo-syntactic-information-p nil
711 "If non-nil, syntactic info is echoed when the line is indented.")
712
713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
714 ;; offset functions
715
716 (defconst vera-offsets-alist
717 '((comment . vera-lineup-C-comments)
718 (comment-intro . vera-lineup-comment)
719 (string . -1000)
720 (directive . -1000)
721 (block-open . 0)
722 (block-intro . +)
723 (block-close . 0)
724 (arglist-intro . +)
725 (arglist-cont . +)
726 (arglist-cont-nonempty . 0)
727 (arglist-close . 0)
728 (statement . 0)
729 (statement-cont . +)
730 (substatement . +)
731 (else-clause . 0))
732 "Association list of syntactic element symbols and indentation offsets.
733 Adapted from `c-offsets-alist'.")
734
735 (defun vera-evaluate-offset (offset langelem symbol)
736 "OFFSET can be a number, a function, a variable, a list, or one of
737 the symbols + or -."
738 (cond
739 ((eq offset '+) (setq offset vera-basic-offset))
740 ((eq offset '-) (setq offset (- vera-basic-offset)))
741 ((eq offset '++) (setq offset (* 2 vera-basic-offset)))
742 ((eq offset '--) (setq offset (* 2 (- vera-basic-offset))))
743 ((eq offset '*) (setq offset (/ vera-basic-offset 2)))
744 ((eq offset '/) (setq offset (/ (- vera-basic-offset) 2)))
745 ((functionp offset) (setq offset (funcall offset langelem)))
746 ((listp offset)
747 (setq offset
748 (let (done)
749 (while (and (not done) offset)
750 (setq done (vera-evaluate-offset (car offset) langelem symbol)
751 offset (cdr offset)))
752 (if (not done)
753 0
754 done))))
755 ((not (numberp offset)) (setq offset (symbol-value offset))))
756 offset)
757
758 (defun vera-get-offset (langelem)
759 "Get offset from LANGELEM which is a cons cell of the form:
760 \(SYMBOL . RELPOS). The symbol is matched against
761 vera-offsets-alist and the offset found there is either returned,
762 or added to the indentation at RELPOS. If RELPOS is nil, then
763 the offset is simply returned."
764 (let* ((symbol (car langelem))
765 (relpos (cdr langelem))
766 (match (assq symbol vera-offsets-alist))
767 (offset (cdr-safe match)))
768 (if (not match)
769 (setq offset 0
770 relpos 0)
771 (setq offset (vera-evaluate-offset offset langelem symbol)))
772 (+ (if (and relpos
773 (< relpos (save-excursion (beginning-of-line) (point))))
774 (save-excursion
775 (goto-char relpos)
776 (current-column))
777 0)
778 (vera-evaluate-offset offset langelem symbol))))
779
780 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
781 ;; help functions
782
783 (defsubst vera-point (position)
784 "Return the value of point at certain commonly referenced POSITIONs.
785 POSITION can be one of the following symbols:
786 bol -- beginning of line
787 eol -- end of line
788 boi -- back to indentation
789 ionl -- indentation of next line
790 iopl -- indentation of previous line
791 bonl -- beginning of next line
792 bopl -- beginning of previous line
793 This function does not modify point or mark."
794 (save-excursion
795 (cond
796 ((eq position 'bol) (beginning-of-line))
797 ((eq position 'eol) (end-of-line))
798 ((eq position 'boi) (back-to-indentation))
799 ((eq position 'bonl) (forward-line 1))
800 ((eq position 'bopl) (forward-line -1))
801 ((eq position 'iopl) (forward-line -1) (back-to-indentation))
802 ((eq position 'ionl) (forward-line 1) (back-to-indentation))
803 (t (error "Unknown buffer position requested: %s" position)))
804 (point)))
805
806 (defun vera-in-literal (&optional lim)
807 "Determine if point is in a Vera literal."
808 (save-excursion
809 (let ((state (parse-partial-sexp (or lim (point-min)) (point))))
810 (cond
811 ((nth 3 state) 'string)
812 ((nth 4 state) 'comment)
813 (t nil)))))
814
815 (defun vera-skip-forward-literal ()
816 "Skip forward literal and return t if within one."
817 (let ((state (save-excursion
818 (if (fboundp 'syntax-ppss)
819 (syntax-ppss)
820 (parse-partial-sexp (point-min) (point))))))
821 (when (nth 8 state)
822 ;; Inside a string or comment.
823 (goto-char (nth 8 state))
824 (if (nth 3 state)
825 ;; A string.
826 (condition-case nil (forward-sexp 1)
827 ;; Can't find end of string: it extends til end of buffer.
828 (error (goto-char (point-max))))
829 ;; A comment.
830 (forward-comment 1))
831 t)))
832
833 (defun vera-skip-backward-literal ()
834 "Skip backward literal and return t if within one."
835 (let ((state (save-excursion
836 (if (fboundp 'syntax-ppss)
837 (syntax-ppss)
838 (parse-partial-sexp (point-min) (point))))))
839 (when (nth 8 state)
840 ;; Inside a string or comment.
841 (goto-char (nth 8 state))
842 t)))
843
844 (defsubst vera-re-search-forward (regexp &optional bound noerror)
845 "Like `re-search-forward', but skips over matches in literals."
846 (let (ret)
847 (while (and (setq ret (re-search-forward regexp bound noerror))
848 (vera-skip-forward-literal)
849 (if bound (< (point) bound) t)))
850 ret))
851
852 (defsubst vera-re-search-backward (regexp &optional bound noerror)
853 "Like `re-search-backward', but skips over matches in literals."
854 (let (ret)
855 (while (and (setq ret (re-search-backward regexp bound noerror))
856 (vera-skip-backward-literal)
857 (if bound (> (point) bound) t)))
858 ret))
859
860 (defun vera-forward-syntactic-ws (&optional lim skip-directive)
861 "Forward skip of syntactic whitespace."
862 (save-restriction
863 (let* ((lim (or lim (point-max)))
864 (here lim)
865 (hugenum (point-max)))
866 (narrow-to-region (point) lim)
867 (while (/= here (point))
868 (setq here (point))
869 (forward-comment hugenum)
870 (when (and skip-directive (looking-at "^\\s-*#"))
871 (end-of-line))))))
872
873 (defun vera-backward-syntactic-ws (&optional lim skip-directive)
874 "Backward skip over syntactic whitespace."
875 (save-restriction
876 (let* ((lim (or lim (point-min)))
877 (here lim)
878 (hugenum (- (point-max))))
879 (when (< lim (point))
880 (narrow-to-region lim (point))
881 (while (/= here (point))
882 (setq here (point))
883 (forward-comment hugenum)
884 (when (and skip-directive
885 (save-excursion (back-to-indentation)
886 (= (following-char) ?\#)))
887 (beginning-of-line)))))))
888
889 (defmacro vera-prepare-search (&rest body)
890 "Execute BODY with a syntax table that includes '_'."
891 `(with-syntax-table vera-mode-ext-syntax-table ,@body))
892
893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
894 ;; comment indentation functions
895
896 (defsubst vera-langelem-col (langelem &optional preserve-point)
897 "Convenience routine to return the column of LANGELEM's relpos.
898 Leaves point at the relpos unless PRESERVE-POINT is non-nil."
899 (let ((here (point)))
900 (goto-char (cdr langelem))
901 (prog1 (current-column)
902 (if preserve-point
903 (goto-char here)))))
904
905 (defun vera-lineup-C-comments (langelem)
906 "Line up C block comment continuation lines.
907 Nicked from `c-lineup-C-comments'."
908 (save-excursion
909 (let ((here (point))
910 (stars (progn (back-to-indentation)
911 (skip-chars-forward "*")))
912 (langelem-col (vera-langelem-col langelem)))
913 (back-to-indentation)
914 (if (not (re-search-forward "/\\([*]+\\)" (vera-point 'eol) t))
915 (progn
916 (if (not (looking-at "[*]+"))
917 (progn
918 ;; we now have to figure out where this comment begins.
919 (goto-char here)
920 (back-to-indentation)
921 (if (looking-at "[*]+/")
922 (progn (goto-char (match-end 0))
923 (forward-comment -1))
924 (goto-char (cdr langelem))
925 (back-to-indentation))))
926 (- (current-column) langelem-col))
927 (if (zerop stars)
928 (progn
929 (skip-chars-forward " \t")
930 (- (current-column) langelem-col))
931 ;; how many stars on comment opening line? if greater than
932 ;; on current line, align left. if less than or equal,
933 ;; align right. this should also pick up Javadoc style
934 ;; comments.
935 (if (> (length (match-string 1)) stars)
936 (progn
937 (back-to-indentation)
938 (- (current-column) -1 langelem-col))
939 (- (current-column) stars langelem-col)))))))
940
941 (defun vera-lineup-comment (langelem)
942 "Line up a comment start."
943 (save-excursion
944 (back-to-indentation)
945 (if (bolp)
946 ;; not indent if at beginning of line
947 -1000
948 ;; otherwise indent accordingly
949 (goto-char (cdr langelem))
950 (current-column))))
951
952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
953 ;; move functions
954
955 (defconst vera-beg-block-re "{\\|\\<\\(begin\\|fork\\)\\>")
956
957 (defconst vera-end-block-re "}\\|\\<\\(end\\|join\\(\\s-+\\(all\\|any\\|none\\)\\)?\\)\\>")
958
959 (defconst vera-beg-substatement-re "\\<\\(else\\|for\\|if\\|repeat\\|while\\)\\>")
960
961 (defun vera-corresponding-begin (&optional recursive)
962 "Find corresponding block begin if cursor is at a block end."
963 (while (and (vera-re-search-backward
964 (concat "\\(" vera-end-block-re "\\)\\|" vera-beg-block-re)
965 nil t)
966 (match-string 1))
967 (vera-corresponding-begin t))
968 (unless recursive (vera-beginning-of-substatement)))
969
970 (defun vera-corresponding-if ()
971 "Find corresponding `if' if cursor is at `else'."
972 (while (and (vera-re-search-backward "}\\|\\<\\(if\\|else\\)\\>" nil t)
973 (not (equal (match-string 0) "if")))
974 (if (equal (match-string 0) "else")
975 (vera-corresponding-if)
976 (forward-char)
977 (backward-sexp))))
978
979 (defun vera-beginning-of-statement ()
980 "Go to beginning of current statement."
981 (let (pos)
982 (while
983 (progn
984 ;; search for end of previous statement
985 (while
986 (and (vera-re-search-backward
987 (concat "[);]\\|" vera-beg-block-re
988 "\\|" vera-end-block-re) nil t)
989 (equal (match-string 0) ")"))
990 (forward-char)
991 (backward-sexp))
992 (setq pos (match-beginning 0))
993 ;; go back to beginning of current statement
994 (goto-char (or (match-end 0) 0))
995 (vera-forward-syntactic-ws nil t)
996 (when (looking-at "(")
997 (forward-sexp)
998 (vera-forward-syntactic-ws nil t))
999 ;; if "else" found, go to "if" and search again
1000 (when (looking-at "\\<else\\>")
1001 (vera-corresponding-if)
1002 (setq pos (point))
1003 t))
1004 ;; if search is repeated, go to beginning of last search
1005 (goto-char pos))))
1006
1007 (defun vera-beginning-of-substatement ()
1008 "Go to beginning of current substatement."
1009 (let ((lim (point))
1010 pos)
1011 ;; go to beginning of statement
1012 (vera-beginning-of-statement)
1013 (setq pos (point))
1014 ;; go forward all substatement opening statements until at LIM
1015 (while (and (< (point) lim)
1016 (vera-re-search-forward vera-beg-substatement-re lim t))
1017 (setq pos (match-beginning 0)))
1018 (vera-forward-syntactic-ws nil t)
1019 (when (looking-at "(")
1020 (forward-sexp)
1021 (vera-forward-syntactic-ws nil t))
1022 (when (< (point) lim)
1023 (setq pos (point)))
1024 (goto-char pos)))
1025
1026 (defun vera-forward-statement ()
1027 "Move forward one statement."
1028 (interactive)
1029 (vera-prepare-search
1030 (while (and (vera-re-search-forward
1031 (concat "[(;]\\|" vera-beg-block-re "\\|" vera-end-block-re)
1032 nil t)
1033 (equal (match-string 0) "("))
1034 (backward-char)
1035 (forward-sexp))
1036 (vera-beginning-of-substatement)))
1037
1038 (defun vera-backward-statement ()
1039 "Move backward one statement."
1040 (interactive)
1041 (vera-prepare-search
1042 (vera-backward-syntactic-ws nil t)
1043 (unless (= (preceding-char) ?\))
1044 (backward-char))
1045 (vera-beginning-of-substatement)))
1046
1047 (defun vera-forward-same-indent ()
1048 "Move forward to next line with same indent."
1049 (interactive)
1050 (let ((pos (point))
1051 (indent (current-indentation)))
1052 (beginning-of-line 2)
1053 (while (and (not (eobp))
1054 (or (looking-at "^\\s-*$")
1055 (> (current-indentation) indent)))
1056 (beginning-of-line 2))
1057 (if (= (current-indentation) indent)
1058 (back-to-indentation)
1059 (message "No following line with same indent found in this block")
1060 (goto-char pos))))
1061
1062 (defun vera-backward-same-indent ()
1063 "Move backward to previous line with same indent."
1064 (interactive)
1065 (let ((pos (point))
1066 (indent (current-indentation)))
1067 (beginning-of-line -0)
1068 (while (and (not (bobp))
1069 (or (looking-at "^\\s-*$")
1070 (> (current-indentation) indent)))
1071 (beginning-of-line -0))
1072 (if (= (current-indentation) indent)
1073 (back-to-indentation)
1074 (message "No preceding line with same indent found in this block")
1075 (goto-char pos))))
1076
1077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1078 ;; syntax analysis
1079
1080 (defmacro vera-add-syntax (symbol &optional relpos)
1081 "A simple macro to append the syntax in SYMBOL to the syntax list.
1082 try to increase performance by using this macro."
1083 `(setq syntax (cons (cons ,symbol ,(or relpos 0)) syntax)))
1084
1085 (defun vera-guess-basic-syntax ()
1086 "Determine syntactic context of current line of code."
1087 (save-excursion
1088 (beginning-of-line)
1089 (let ((indent-point (point))
1090 syntax state placeholder pos)
1091 ;; determine syntax state
1092 (setq state (parse-partial-sexp (point-min) (point)))
1093 (cond
1094 ;; CASE 1: in a comment?
1095 ((nth 4 state)
1096 ;; skip empty lines
1097 (while (and (zerop (forward-line -1))
1098 (looking-at "^\\s-*$")))
1099 (vera-add-syntax 'comment (vera-point 'boi)))
1100 ;; CASE 2: in a string?
1101 ((nth 3 state)
1102 (vera-add-syntax 'string))
1103 ;; CASE 3: at a directive?
1104 ((save-excursion (back-to-indentation) (= (following-char) ?\#))
1105 (vera-add-syntax 'directive (point)))
1106 ;; CASE 4: after an opening parenthesis (argument list continuation)?
1107 ((and (nth 1 state)
1108 (or (= (char-after (nth 1 state)) ?\()
1109 ;; also for concatenation (opening '{' and ',' on eol/eopl)
1110 (and (= (char-after (nth 1 state)) ?\{)
1111 (or (save-excursion
1112 (vera-backward-syntactic-ws) (= (char-before) ?,))
1113 (save-excursion
1114 (end-of-line) (= (char-before) ?,))))))
1115 (goto-char (1+ (nth 1 state)))
1116 ;; is there code after the opening parenthesis on the same line?
1117 (if (looking-at "\\s-*$")
1118 (vera-add-syntax 'arglist-cont (vera-point 'boi))
1119 (vera-add-syntax 'arglist-cont-nonempty (point))))
1120 ;; CASE 5: at a block closing?
1121 ((save-excursion (back-to-indentation) (looking-at vera-end-block-re))
1122 ;; look for the corresponding begin
1123 (vera-corresponding-begin)
1124 (vera-add-syntax 'block-close (vera-point 'boi)))
1125 ;; CASE 6: at a block intro (the first line after a block opening)?
1126 ((and (save-excursion
1127 (vera-backward-syntactic-ws nil t)
1128 ;; previous line ends with a block opening?
1129 (or (/= (skip-chars-backward "{") 0) (backward-word 1))
1130 (when (looking-at vera-beg-block-re)
1131 ;; go to beginning of substatement
1132 (vera-beginning-of-substatement)
1133 (setq placeholder (point))))
1134 ;; not if "fork" is followed by "{"
1135 (save-excursion
1136 (not (and (progn (back-to-indentation) (looking-at "{"))
1137 (progn (goto-char placeholder)
1138 (looking-at "\\<fork\\>"))))))
1139 (goto-char placeholder)
1140 (vera-add-syntax 'block-intro (vera-point 'boi)))
1141 ;; CASE 7: at the beginning of an else clause?
1142 ((save-excursion (back-to-indentation) (looking-at "\\<else\\>"))
1143 ;; find corresponding if
1144 (vera-corresponding-if)
1145 (vera-add-syntax 'else-clause (vera-point 'boi)))
1146 ;; CASE 8: at the beginning of a statement?
1147 ;; is the previous command completed?
1148 ((or (save-excursion
1149 (vera-backward-syntactic-ws nil t)
1150 (setq placeholder (point))
1151 ;; at the beginning of the buffer?
1152 (or (bobp)
1153 ;; previous line ends with a semicolon or
1154 ;; is a block opening or closing?
1155 (when (or (/= (skip-chars-backward "{};") 0)
1156 (progn (back-to-indentation)
1157 (looking-at (concat vera-beg-block-re "\\|"
1158 vera-end-block-re))))
1159 ;; if at a block closing, go to beginning
1160 (when (looking-at vera-end-block-re)
1161 (vera-corresponding-begin))
1162 ;; go to beginning of the statement
1163 (vera-beginning-of-statement)
1164 (setq placeholder (point)))
1165 ;; at a directive?
1166 (when (progn (back-to-indentation) (looking-at "#"))
1167 ;; go to previous statement
1168 (vera-beginning-of-statement)
1169 (setq placeholder (point)))))
1170 ;; at a block opening?
1171 (when (save-excursion (back-to-indentation)
1172 (looking-at vera-beg-block-re))
1173 ;; go to beginning of the substatement
1174 (vera-beginning-of-substatement)
1175 (setq placeholder (point))))
1176 (goto-char placeholder)
1177 (vera-add-syntax 'statement (vera-point 'boi)))
1178 ;; CASE 9: at the beginning of a substatement?
1179 ;; is this line preceded by a substatement opening statement?
1180 ((save-excursion (vera-backward-syntactic-ws nil t)
1181 (when (= (preceding-char) ?\)) (backward-sexp))
1182 (backward-word 1)
1183 (setq placeholder (point))
1184 (looking-at vera-beg-substatement-re))
1185 (goto-char placeholder)
1186 (vera-add-syntax 'substatement (vera-point 'boi)))
1187 ;; CASE 10: it must be a statement continuation!
1188 (t
1189 ;; go to beginning of statement
1190 (vera-beginning-of-substatement)
1191 (vera-add-syntax 'statement-cont (vera-point 'boi))))
1192 ;; special case: look for a comment start
1193 (goto-char indent-point)
1194 (skip-chars-forward " \t")
1195 (when (looking-at comment-start)
1196 (vera-add-syntax 'comment-intro))
1197 ;; return syntax
1198 syntax)))
1199
1200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1201 ;; indentation functions
1202
1203 (defun vera-indent-line ()
1204 "Indent the current line as Vera code.
1205 Return the amount of indentation change (in columns)."
1206 (interactive)
1207 (vera-prepare-search
1208 (let* ((syntax (vera-guess-basic-syntax))
1209 (pos (- (point-max) (point)))
1210 (indent (apply '+ (mapcar 'vera-get-offset syntax)))
1211 (shift-amt (- (current-indentation) indent)))
1212 (when vera-echo-syntactic-information-p
1213 (message "syntax: %s, indent= %d" syntax indent))
1214 (unless (zerop shift-amt)
1215 (beginning-of-line)
1216 (delete-region (point) (vera-point 'boi))
1217 (indent-to indent))
1218 (if (< (point) (vera-point 'boi))
1219 (back-to-indentation)
1220 ;; If initial point was within line's indentation, position after
1221 ;; the indentation. Else stay at same point in text.
1222 (when (> (- (point-max) pos) (point))
1223 (goto-char (- (point-max) pos))))
1224 shift-amt)))
1225
1226 (defun vera-indent-buffer ()
1227 "Indent whole buffer as Vera code.
1228 Calls `indent-region' for whole buffer."
1229 (interactive)
1230 (message "Indenting buffer...")
1231 (indent-region (point-min) (point-max) nil)
1232 (message "Indenting buffer...done"))
1233
1234 (defun vera-indent-region (start end column)
1235 "Indent region as Vera code."
1236 (interactive "r\nP")
1237 (message "Indenting region...")
1238 (indent-region start end column)
1239 (message "Indenting region...done"))
1240
1241 (defsubst vera-indent-block-closing ()
1242 "If previous word is a block closing or `else', indent line again."
1243 (when (= (char-syntax (preceding-char)) ?w)
1244 (save-excursion
1245 (backward-word 1)
1246 (when (and (not (vera-in-literal))
1247 (looking-at (concat vera-end-block-re "\\|\\<else\\>")))
1248 (indent-according-to-mode)))))
1249
1250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1251 ;; electrifications
1252
1253 (defun vera-electric-tab (&optional prefix-arg)
1254 "Do what I mean (indent, expand, tab, change indent, etc..).
1255 If preceding character is part of a word or a paren then `hippie-expand',
1256 else if right of non whitespace on line then `tab-to-tab-stop',
1257 else if last command was a tab or return then dedent one step or if a comment
1258 toggle between normal indent and inline comment indent,
1259 else indent `correctly'.
1260 If `vera-intelligent-tab' is nil, always indent line."
1261 (interactive "*P")
1262 (if vera-intelligent-tab
1263 (progn
1264 (cond ((and (not (featurep 'xemacs)) (use-region-p))
1265 (vera-indent-region (region-beginning) (region-end) nil))
1266 ((memq (char-syntax (preceding-char)) '(?w ?_))
1267 (let ((case-fold-search t)
1268 (case-replace nil)
1269 (hippie-expand-only-buffers
1270 (or (and (boundp 'hippie-expand-only-buffers)
1271 hippie-expand-only-buffers)
1272 '(vera-mode))))
1273 (vera-expand-abbrev prefix-arg)))
1274 ((> (current-column) (current-indentation))
1275 (tab-to-tab-stop))
1276 ((and (or (eq last-command 'vera-electric-tab)
1277 (eq last-command 'vera-electric-return))
1278 (/= 0 (current-indentation)))
1279 (backward-delete-char-untabify vera-basic-offset nil))
1280 (t (indent-according-to-mode)))
1281 (setq this-command 'vera-electric-tab))
1282 (indent-according-to-mode)))
1283
1284 (defun vera-electric-return ()
1285 "Insert newline and indent. Indent current line if it is a block closing."
1286 (interactive)
1287 (vera-indent-block-closing)
1288 (newline-and-indent))
1289
1290 (defun vera-electric-space (arg)
1291 "Insert a space. Indent current line if it is a block closing."
1292 (interactive "*P")
1293 (unless arg
1294 (vera-indent-block-closing))
1295 (self-insert-command (prefix-numeric-value arg)))
1296
1297 (defun vera-electric-opening-brace (arg)
1298 "Outdent opening brace."
1299 (interactive "*P")
1300 (self-insert-command (prefix-numeric-value arg))
1301 (unless arg
1302 (indent-according-to-mode)))
1303
1304 (defun vera-electric-closing-brace (arg)
1305 "Outdent closing brace."
1306 (interactive "*P")
1307 (self-insert-command (prefix-numeric-value arg))
1308 (unless arg
1309 (indent-according-to-mode)))
1310
1311 (defun vera-electric-pound (arg)
1312 "Insert `#' and indent as directive it first character of line."
1313 (interactive "*P")
1314 (self-insert-command (prefix-numeric-value arg))
1315 (unless arg
1316 (save-excursion
1317 (backward-char)
1318 (skip-chars-backward " \t")
1319 (when (bolp)
1320 (delete-horizontal-space)))))
1321
1322 (defun vera-electric-star (arg)
1323 "Insert a star character. Nicked from `c-electric-star'."
1324 (interactive "*P")
1325 (self-insert-command (prefix-numeric-value arg))
1326 (if (and (not arg)
1327 (memq (vera-in-literal) '(comment))
1328 (eq (char-before) ?*)
1329 (save-excursion
1330 (forward-char -1)
1331 (skip-chars-backward "*")
1332 (if (eq (char-before) ?/)
1333 (forward-char -1))
1334 (skip-chars-backward " \t")
1335 (bolp)))
1336 (indent-according-to-mode)))
1337
1338 (defun vera-electric-slash (arg)
1339 "Insert a slash character. Nicked from `c-electric-slash'."
1340 (interactive "*P")
1341 (let* ((ch (char-before))
1342 (indentp (and (not arg)
1343 (eq last-command-event ?/)
1344 (or (and (eq ch ?/)
1345 (not (vera-in-literal)))
1346 (and (eq ch ?*)
1347 (vera-in-literal))))))
1348 (self-insert-command (prefix-numeric-value arg))
1349 (when indentp
1350 (indent-according-to-mode))))
1351
1352
1353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1354 ;;; Miscellaneous
1355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1356
1357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1358 ;; Hippie expand customization (for expansion of Vera commands)
1359
1360 (defvar vera-abbrev-list
1361 (append (list nil) vera-keywords
1362 (list nil) vera-types
1363 (list nil) vera-functions
1364 (list nil) vera-constants
1365 (list nil) vera-rvm-types
1366 (list nil) vera-rvm-functions
1367 (list nil) vera-rvm-constants)
1368 "Predefined abbreviations for Vera.")
1369
1370 (defvar vera-expand-upper-case nil)
1371
1372 (eval-when-compile (require 'hippie-exp))
1373
1374 (defun vera-try-expand-abbrev (old)
1375 "Try expanding abbreviations from `vera-abbrev-list'."
1376 (unless old
1377 (he-init-string (he-dabbrev-beg) (point))
1378 (setq he-expand-list
1379 (let ((abbrev-list vera-abbrev-list)
1380 (sel-abbrev-list '()))
1381 (while abbrev-list
1382 (when (or (not (stringp (car abbrev-list)))
1383 (string-match
1384 (concat "^" he-search-string) (car abbrev-list)))
1385 (setq sel-abbrev-list
1386 (cons (car abbrev-list) sel-abbrev-list)))
1387 (setq abbrev-list (cdr abbrev-list)))
1388 (nreverse sel-abbrev-list))))
1389 (while (and he-expand-list
1390 (or (not (stringp (car he-expand-list)))
1391 (he-string-member (car he-expand-list) he-tried-table t)))
1392 (unless (stringp (car he-expand-list))
1393 (setq vera-expand-upper-case (car he-expand-list)))
1394 (setq he-expand-list (cdr he-expand-list)))
1395 (if (null he-expand-list)
1396 (progn (when old (he-reset-string))
1397 nil)
1398 (he-substitute-string
1399 (if vera-expand-upper-case
1400 (upcase (car he-expand-list))
1401 (car he-expand-list))
1402 t)
1403 (setq he-expand-list (cdr he-expand-list))
1404 t))
1405
1406 ;; function for expanding abbrevs and dabbrevs
1407 (defalias 'vera-expand-abbrev
1408 (make-hippie-expand-function '(try-expand-dabbrev
1409 try-expand-dabbrev-all-buffers
1410 vera-try-expand-abbrev)))
1411
1412 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1413 ;; Comments
1414
1415 (defun vera-comment-uncomment-region (beg end &optional arg)
1416 "Comment region if not commented, uncomment region if already commented."
1417 (interactive "r\nP")
1418 (goto-char beg)
1419 (if (looking-at comment-start-skip)
1420 (comment-region beg end '(4))
1421 (comment-region beg end)))
1422
1423 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1424 ;; Help functions
1425
1426 (defun vera-customize ()
1427 "Call the customize function with `vera' as argument."
1428 (interactive)
1429 (customize-group 'vera))
1430
1431 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1432 ;; Other
1433
1434 ;; remove ".vr" from `completion-ignored-extensions'
1435 (setq completion-ignored-extensions
1436 (delete ".vr" completion-ignored-extensions))
1437
1438
1439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1440 ;;; Bug reports
1441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1442
1443 (defconst vera-mode-help-address "Reto Zimmermann <reto@gnu.org>"
1444 "Address for Vera Mode bug reports.")
1445
1446 ;; get reporter-submit-bug-report when byte-compiling
1447 (eval-when-compile
1448 (require 'reporter))
1449
1450 (defun vera-submit-bug-report ()
1451 "Submit via mail a bug report on Vera Mode."
1452 (interactive)
1453 ;; load in reporter
1454 (and
1455 (y-or-n-p "Do you want to submit a report on Vera Mode? ")
1456 (require 'reporter)
1457 (let ((reporter-prompt-for-summary-p t))
1458 (reporter-submit-bug-report
1459 vera-mode-help-address
1460 (concat "Vera Mode " vera-version)
1461 (list
1462 ;; report all important variables
1463 'vera-basic-offset
1464 'vera-underscore-is-part-of-word
1465 'vera-intelligent-tab
1466 )
1467 nil nil
1468 "Hi Reto,"))))
1469
1470
1471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1472 ;;; Documentation
1473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1474
1475 (defun vera-version ()
1476 "Echo the current version of Vera Mode in the minibuffer."
1477 (interactive)
1478 (message "Vera Mode %s (%s)" vera-version vera-time-stamp))
1479
1480
1481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1482
1483 (provide 'vera-mode)
1484
1485 ;; arch-tag: 22eae722-7ac5-47ac-a713-c4db1cf623a9
1486 ;;; vera-mode.el ends here