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