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