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 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-h m' 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 (let ((map (make-sparse-keymap)))
127 ;; Backspace/delete key bindings.
128 (define-key map [backspace] 'backward-delete-char-untabify)
129 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
130 (define-key map [delete] 'delete-char)
131 (define-key map [(meta delete)] 'kill-word))
132 ;; Standard key bindings.
133 (define-key map "\M-e" 'vera-forward-statement)
134 (define-key map "\M-a" 'vera-backward-statement)
135 (define-key map "\M-\C-e" 'vera-forward-same-indent)
136 (define-key map "\M-\C-a" 'vera-backward-same-indent)
137 ;; Mode specific key bindings.
138 (define-key map "\C-c\t" 'indent-according-to-mode)
139 (define-key map "\M-\C-\\" 'vera-indent-region)
140 (define-key map "\C-c\C-c" 'vera-comment-uncomment-region)
141 (define-key map "\C-c\C-f" 'vera-fontify-buffer)
142 (define-key map "\C-c\C-v" 'vera-version)
143 (define-key map "\M-\t" 'tab-to-tab-stop)
144 ;; Electric key bindings.
145 (define-key map "\t" 'vera-electric-tab)
146 (define-key map "\r" 'vera-electric-return)
147 (define-key map " " 'vera-electric-space)
148 (define-key map "{" 'vera-electric-opening-brace)
149 (define-key map "}" 'vera-electric-closing-brace)
150 (define-key map "#" 'vera-electric-pound)
151 (define-key map "*" 'vera-electric-star)
152 (define-key map "/" 'vera-electric-slash)
153 map)
154 "Keymap for Vera Mode.")
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 (let (ret)
848 (while (and (setq ret (re-search-forward regexp bound noerror))
849 (vera-skip-forward-literal)
850 (if bound (< (point) bound) t)))
851 ret))
852
853 (defsubst vera-re-search-backward (regexp &optional bound noerror)
854 "Like `re-search-backward', but skips over matches in literals."
855 (let (ret)
856 (while (and (setq ret (re-search-backward regexp bound noerror))
857 (vera-skip-backward-literal)
858 (if bound (> (point) bound) t)))
859 ret))
860
861 (defun vera-forward-syntactic-ws (&optional lim skip-directive)
862 "Forward skip of syntactic whitespace."
863 (save-restriction
864 (let* ((lim (or lim (point-max)))
865 (here lim)
866 (hugenum (point-max)))
867 (narrow-to-region (point) lim)
868 (while (/= here (point))
869 (setq here (point))
870 (forward-comment hugenum)
871 (when (and skip-directive (looking-at "^\\s-*#"))
872 (end-of-line))))))
873
874 (defun vera-backward-syntactic-ws (&optional lim skip-directive)
875 "Backward skip over syntactic whitespace."
876 (save-restriction
877 (let* ((lim (or lim (point-min)))
878 (here lim)
879 (hugenum (- (point-max))))
880 (when (< lim (point))
881 (narrow-to-region lim (point))
882 (while (/= here (point))
883 (setq here (point))
884 (forward-comment hugenum)
885 (when (and skip-directive
886 (save-excursion (back-to-indentation)
887 (= (following-char) ?\#)))
888 (beginning-of-line)))))))
889
890 (defmacro vera-prepare-search (&rest body)
891 "Execute BODY with a syntax table that includes '_'."
892 `(with-syntax-table vera-mode-ext-syntax-table ,@body))
893
894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
895 ;; comment indentation functions
896
897 (defsubst vera-langelem-col (langelem &optional preserve-point)
898 "Convenience routine to return the column of LANGELEM's relpos.
899 Leaves point at the relpos unless PRESERVE-POINT is non-nil."
900 (let ((here (point)))
901 (goto-char (cdr langelem))
902 (prog1 (current-column)
903 (if preserve-point
904 (goto-char here)))))
905
906 (defun vera-lineup-C-comments (langelem)
907 "Line up C block comment continuation lines.
908 Nicked from `c-lineup-C-comments'."
909 (save-excursion
910 (let ((here (point))
911 (stars (progn (back-to-indentation)
912 (skip-chars-forward "*")))
913 (langelem-col (vera-langelem-col langelem)))
914 (back-to-indentation)
915 (if (not (re-search-forward "/\\([*]+\\)" (vera-point 'eol) t))
916 (progn
917 (if (not (looking-at "[*]+"))
918 (progn
919 ;; we now have to figure out where this comment begins.
920 (goto-char here)
921 (back-to-indentation)
922 (if (looking-at "[*]+/")
923 (progn (goto-char (match-end 0))
924 (forward-comment -1))
925 (goto-char (cdr langelem))
926 (back-to-indentation))))
927 (- (current-column) langelem-col))
928 (if (zerop stars)
929 (progn
930 (skip-chars-forward " \t")
931 (- (current-column) langelem-col))
932 ;; how many stars on comment opening line? if greater than
933 ;; on current line, align left. if less than or equal,
934 ;; align right. this should also pick up Javadoc style
935 ;; comments.
936 (if (> (length (match-string 1)) stars)
937 (progn
938 (back-to-indentation)
939 (- (current-column) -1 langelem-col))
940 (- (current-column) stars langelem-col)))))))
941
942 (defun vera-lineup-comment (langelem)
943 "Line up a comment start."
944 (save-excursion
945 (back-to-indentation)
946 (if (bolp)
947 ;; not indent if at beginning of line
948 -1000
949 ;; otherwise indent accordingly
950 (goto-char (cdr langelem))
951 (current-column))))
952
953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
954 ;; move functions
955
956 (defconst vera-beg-block-re "{\\|\\<\\(begin\\|fork\\)\\>")
957
958 (defconst vera-end-block-re "}\\|\\<\\(end\\|join\\(\\s-+\\(all\\|any\\|none\\)\\)?\\)\\>")
959
960 (defconst vera-beg-substatement-re "\\<\\(else\\|for\\|if\\|repeat\\|while\\)\\>")
961
962 (defun vera-corresponding-begin (&optional recursive)
963 "Find corresponding block begin if cursor is at a block end."
964 (while (and (vera-re-search-backward
965 (concat "\\(" vera-end-block-re "\\)\\|" vera-beg-block-re)
966 nil t)
967 (match-string 1))
968 (vera-corresponding-begin t))
969 (unless recursive (vera-beginning-of-substatement)))
970
971 (defun vera-corresponding-if ()
972 "Find corresponding `if' if cursor is at `else'."
973 (while (and (vera-re-search-backward "}\\|\\<\\(if\\|else\\)\\>" nil t)
974 (not (equal (match-string 0) "if")))
975 (if (equal (match-string 0) "else")
976 (vera-corresponding-if)
977 (forward-char)
978 (backward-sexp))))
979
980 (defun vera-beginning-of-statement ()
981 "Go to beginning of current statement."
982 (let (pos)
983 (while
984 (progn
985 ;; search for end of previous statement
986 (while
987 (and (vera-re-search-backward
988 (concat "[);]\\|" vera-beg-block-re
989 "\\|" vera-end-block-re) nil t)
990 (equal (match-string 0) ")"))
991 (forward-char)
992 (backward-sexp))
993 (setq pos (match-beginning 0))
994 ;; go back to beginning of current statement
995 (goto-char (or (match-end 0) 0))
996 (vera-forward-syntactic-ws nil t)
997 (when (looking-at "(")
998 (forward-sexp)
999 (vera-forward-syntactic-ws nil t))
1000 ;; if "else" found, go to "if" and search again
1001 (when (looking-at "\\<else\\>")
1002 (vera-corresponding-if)
1003 (setq pos (point))
1004 t))
1005 ;; if search is repeated, go to beginning of last search
1006 (goto-char pos))))
1007
1008 (defun vera-beginning-of-substatement ()
1009 "Go to beginning of current substatement."
1010 (let ((lim (point))
1011 pos)
1012 ;; go to beginning of statement
1013 (vera-beginning-of-statement)
1014 (setq pos (point))
1015 ;; go forward all substatement opening statements until at LIM
1016 (while (and (< (point) lim)
1017 (vera-re-search-forward vera-beg-substatement-re lim t))
1018 (setq pos (match-beginning 0)))
1019 (vera-forward-syntactic-ws nil t)
1020 (when (looking-at "(")
1021 (forward-sexp)
1022 (vera-forward-syntactic-ws nil t))
1023 (when (< (point) lim)
1024 (setq pos (point)))
1025 (goto-char pos)))
1026
1027 (defun vera-forward-statement ()
1028 "Move forward one statement."
1029 (interactive)
1030 (vera-prepare-search
1031 (while (and (vera-re-search-forward
1032 (concat "[(;]\\|" vera-beg-block-re "\\|" vera-end-block-re)
1033 nil t)
1034 (equal (match-string 0) "("))
1035 (backward-char)
1036 (forward-sexp))
1037 (vera-beginning-of-substatement)))
1038
1039 (defun vera-backward-statement ()
1040 "Move backward one statement."
1041 (interactive)
1042 (vera-prepare-search
1043 (vera-backward-syntactic-ws nil t)
1044 (unless (= (preceding-char) ?\))
1045 (backward-char))
1046 (vera-beginning-of-substatement)))
1047
1048 (defun vera-forward-same-indent ()
1049 "Move forward to next line with same indent."
1050 (interactive)
1051 (let ((pos (point))
1052 (indent (current-indentation)))
1053 (beginning-of-line 2)
1054 (while (and (not (eobp))
1055 (or (looking-at "^\\s-*$")
1056 (> (current-indentation) indent)))
1057 (beginning-of-line 2))
1058 (if (= (current-indentation) indent)
1059 (back-to-indentation)
1060 (message "No following line with same indent found in this block")
1061 (goto-char pos))))
1062
1063 (defun vera-backward-same-indent ()
1064 "Move backward to previous line with same indent."
1065 (interactive)
1066 (let ((pos (point))
1067 (indent (current-indentation)))
1068 (beginning-of-line -0)
1069 (while (and (not (bobp))
1070 (or (looking-at "^\\s-*$")
1071 (> (current-indentation) indent)))
1072 (beginning-of-line -0))
1073 (if (= (current-indentation) indent)
1074 (back-to-indentation)
1075 (message "No preceding line with same indent found in this block")
1076 (goto-char pos))))
1077
1078 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1079 ;; syntax analysis
1080
1081 (defmacro vera-add-syntax (symbol &optional relpos)
1082 "A simple macro to append the syntax in SYMBOL to the syntax list.
1083 try to increase performance by using this macro."
1084 `(setq syntax (cons (cons ,symbol ,(or relpos 0)) syntax)))
1085
1086 (defun vera-guess-basic-syntax ()
1087 "Determine syntactic context of current line of code."
1088 (save-excursion
1089 (beginning-of-line)
1090 (let ((indent-point (point))
1091 syntax state placeholder pos)
1092 ;; determine syntax state
1093 (setq state (parse-partial-sexp (point-min) (point)))
1094 (cond
1095 ;; CASE 1: in a comment?
1096 ((nth 4 state)
1097 ;; skip empty lines
1098 (while (and (zerop (forward-line -1))
1099 (looking-at "^\\s-*$")))
1100 (vera-add-syntax 'comment (vera-point 'boi)))
1101 ;; CASE 2: in a string?
1102 ((nth 3 state)
1103 (vera-add-syntax 'string))
1104 ;; CASE 3: at a directive?
1105 ((save-excursion (back-to-indentation) (= (following-char) ?\#))
1106 (vera-add-syntax 'directive (point)))
1107 ;; CASE 4: after an opening parenthesis (argument list continuation)?
1108 ((and (nth 1 state)
1109 (or (= (char-after (nth 1 state)) ?\()
1110 ;; also for concatenation (opening '{' and ',' on eol/eopl)
1111 (and (= (char-after (nth 1 state)) ?\{)
1112 (or (save-excursion
1113 (vera-backward-syntactic-ws) (= (char-before) ?,))
1114 (save-excursion
1115 (end-of-line) (= (char-before) ?,))))))
1116 (goto-char (1+ (nth 1 state)))
1117 ;; is there code after the opening parenthesis on the same line?
1118 (if (looking-at "\\s-*$")
1119 (vera-add-syntax 'arglist-cont (vera-point 'boi))
1120 (vera-add-syntax 'arglist-cont-nonempty (point))))
1121 ;; CASE 5: at a block closing?
1122 ((save-excursion (back-to-indentation) (looking-at vera-end-block-re))
1123 ;; look for the corresponding begin
1124 (vera-corresponding-begin)
1125 (vera-add-syntax 'block-close (vera-point 'boi)))
1126 ;; CASE 6: at a block intro (the first line after a block opening)?
1127 ((and (save-excursion
1128 (vera-backward-syntactic-ws nil t)
1129 ;; previous line ends with a block opening?
1130 (or (/= (skip-chars-backward "{") 0) (backward-word 1))
1131 (when (looking-at vera-beg-block-re)
1132 ;; go to beginning of substatement
1133 (vera-beginning-of-substatement)
1134 (setq placeholder (point))))
1135 ;; not if "fork" is followed by "{"
1136 (save-excursion
1137 (not (and (progn (back-to-indentation) (looking-at "{"))
1138 (progn (goto-char placeholder)
1139 (looking-at "\\<fork\\>"))))))
1140 (goto-char placeholder)
1141 (vera-add-syntax 'block-intro (vera-point 'boi)))
1142 ;; CASE 7: at the beginning of an else clause?
1143 ((save-excursion (back-to-indentation) (looking-at "\\<else\\>"))
1144 ;; find corresponding if
1145 (vera-corresponding-if)
1146 (vera-add-syntax 'else-clause (vera-point 'boi)))
1147 ;; CASE 8: at the beginning of a statement?
1148 ;; is the previous command completed?
1149 ((or (save-excursion
1150 (vera-backward-syntactic-ws nil t)
1151 (setq placeholder (point))
1152 ;; at the beginning of the buffer?
1153 (or (bobp)
1154 ;; previous line ends with a semicolon or
1155 ;; is a block opening or closing?
1156 (when (or (/= (skip-chars-backward "{};") 0)
1157 (progn (back-to-indentation)
1158 (looking-at (concat vera-beg-block-re "\\|"
1159 vera-end-block-re))))
1160 ;; if at a block closing, go to beginning
1161 (when (looking-at vera-end-block-re)
1162 (vera-corresponding-begin))
1163 ;; go to beginning of the statement
1164 (vera-beginning-of-statement)
1165 (setq placeholder (point)))
1166 ;; at a directive?
1167 (when (progn (back-to-indentation) (looking-at "#"))
1168 ;; go to previous statement
1169 (vera-beginning-of-statement)
1170 (setq placeholder (point)))))
1171 ;; at a block opening?
1172 (when (save-excursion (back-to-indentation)
1173 (looking-at vera-beg-block-re))
1174 ;; go to beginning of the substatement
1175 (vera-beginning-of-substatement)
1176 (setq placeholder (point))))
1177 (goto-char placeholder)
1178 (vera-add-syntax 'statement (vera-point 'boi)))
1179 ;; CASE 9: at the beginning of a substatement?
1180 ;; is this line preceded by a substatement opening statement?
1181 ((save-excursion (vera-backward-syntactic-ws nil t)
1182 (when (= (preceding-char) ?\)) (backward-sexp))
1183 (backward-word 1)
1184 (setq placeholder (point))
1185 (looking-at vera-beg-substatement-re))
1186 (goto-char placeholder)
1187 (vera-add-syntax 'substatement (vera-point 'boi)))
1188 ;; CASE 10: it must be a statement continuation!
1189 (t
1190 ;; go to beginning of statement
1191 (vera-beginning-of-substatement)
1192 (vera-add-syntax 'statement-cont (vera-point 'boi))))
1193 ;; special case: look for a comment start
1194 (goto-char indent-point)
1195 (skip-chars-forward " \t")
1196 (when (looking-at comment-start)
1197 (vera-add-syntax 'comment-intro))
1198 ;; return syntax
1199 syntax)))
1200
1201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1202 ;; indentation functions
1203
1204 (defun vera-indent-line ()
1205 "Indent the current line as Vera code.
1206 Return the amount of indentation change (in columns)."
1207 (interactive)
1208 (vera-prepare-search
1209 (let* ((syntax (vera-guess-basic-syntax))
1210 (pos (- (point-max) (point)))
1211 (indent (apply '+ (mapcar 'vera-get-offset syntax)))
1212 (shift-amt (- (current-indentation) indent)))
1213 (when vera-echo-syntactic-information-p
1214 (message "syntax: %s, indent= %d" syntax indent))
1215 (unless (zerop shift-amt)
1216 (beginning-of-line)
1217 (delete-region (point) (vera-point 'boi))
1218 (indent-to indent))
1219 (if (< (point) (vera-point 'boi))
1220 (back-to-indentation)
1221 ;; If initial point was within line's indentation, position after
1222 ;; the indentation. Else stay at same point in text.
1223 (when (> (- (point-max) pos) (point))
1224 (goto-char (- (point-max) pos))))
1225 shift-amt)))
1226
1227 (defun vera-indent-buffer ()
1228 "Indent whole buffer as Vera code.
1229 Calls `indent-region' for whole buffer."
1230 (interactive)
1231 (message "Indenting buffer...")
1232 (indent-region (point-min) (point-max) nil)
1233 (message "Indenting buffer...done"))
1234
1235 (defun vera-indent-region (start end column)
1236 "Indent region as Vera code."
1237 (interactive "r\nP")
1238 (message "Indenting region...")
1239 (indent-region start end column)
1240 (message "Indenting region...done"))
1241
1242 (defsubst vera-indent-block-closing ()
1243 "If previous word is a block closing or `else', indent line again."
1244 (when (= (char-syntax (preceding-char)) ?w)
1245 (save-excursion
1246 (backward-word 1)
1247 (when (and (not (vera-in-literal))
1248 (looking-at (concat vera-end-block-re "\\|\\<else\\>")))
1249 (indent-according-to-mode)))))
1250
1251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1252 ;; electrifications
1253
1254 (defun vera-electric-tab (&optional prefix-arg)
1255 "Do what I mean (indent, expand, tab, change indent, etc..).
1256 If preceding character is part of a word or a paren then `hippie-expand',
1257 else if right of non whitespace on line then `tab-to-tab-stop',
1258 else if last command was a tab or return then dedent one step or if a comment
1259 toggle between normal indent and inline comment indent,
1260 else indent `correctly'.
1261 If `vera-intelligent-tab' is nil, always indent line."
1262 (interactive "*P")
1263 (if vera-intelligent-tab
1264 (progn
1265 (cond ((memq (char-syntax (preceding-char)) '(?w ?_))
1266 (let ((case-fold-search t)
1267 (case-replace nil)
1268 (hippie-expand-only-buffers
1269 (or (and (boundp 'hippie-expand-only-buffers)
1270 hippie-expand-only-buffers)
1271 '(vera-mode))))
1272 (vera-expand-abbrev prefix-arg)))
1273 ((> (current-column) (current-indentation))
1274 (tab-to-tab-stop))
1275 ((and (or (eq last-command 'vera-electric-tab)
1276 (eq last-command 'vera-electric-return))
1277 (/= 0 (current-indentation)))
1278 (backward-delete-char-untabify vera-basic-offset nil))
1279 (t (indent-according-to-mode)))
1280 (setq this-command 'vera-electric-tab))
1281 (indent-according-to-mode)))
1282
1283 (defun vera-electric-return ()
1284 "Insert newline and indent. Indent current line if it is a block closing."
1285 (interactive)
1286 (vera-indent-block-closing)
1287 (newline-and-indent))
1288
1289 (defun vera-electric-space (arg)
1290 "Insert a space. Indent current line if it is a block closing."
1291 (interactive "*P")
1292 (unless arg
1293 (vera-indent-block-closing))
1294 (self-insert-command (prefix-numeric-value arg)))
1295
1296 (defun vera-electric-opening-brace (arg)
1297 "Outdent opening brace."
1298 (interactive "*P")
1299 (self-insert-command (prefix-numeric-value arg))
1300 (unless arg
1301 (indent-according-to-mode)))
1302
1303 (defun vera-electric-closing-brace (arg)
1304 "Outdent closing brace."
1305 (interactive "*P")
1306 (self-insert-command (prefix-numeric-value arg))
1307 (unless arg
1308 (indent-according-to-mode)))
1309
1310 (defun vera-electric-pound (arg)
1311 "Insert `#' and indent as directive it first character of line."
1312 (interactive "*P")
1313 (self-insert-command (prefix-numeric-value arg))
1314 (unless arg
1315 (save-excursion
1316 (backward-char)
1317 (skip-chars-backward " \t")
1318 (when (bolp)
1319 (delete-horizontal-space)))))
1320
1321 (defun vera-electric-star (arg)
1322 "Insert a star character. Nicked from `c-electric-star'."
1323 (interactive "*P")
1324 (self-insert-command (prefix-numeric-value arg))
1325 (if (and (not arg)
1326 (memq (vera-in-literal) '(comment))
1327 (eq (char-before) ?*)
1328 (save-excursion
1329 (forward-char -1)
1330 (skip-chars-backward "*")
1331 (if (eq (char-before) ?/)
1332 (forward-char -1))
1333 (skip-chars-backward " \t")
1334 (bolp)))
1335 (indent-according-to-mode)))
1336
1337 (defun vera-electric-slash (arg)
1338 "Insert a slash character. Nicked from `c-electric-slash'."
1339 (interactive "*P")
1340 (let* ((ch (char-before))
1341 (indentp (and (not arg)
1342 (eq last-command-char ?/)
1343 (or (and (eq ch ?/)
1344 (not (vera-in-literal)))
1345 (and (eq ch ?*)
1346 (vera-in-literal))))))
1347 (self-insert-command (prefix-numeric-value arg))
1348 (when indentp
1349 (indent-according-to-mode))))
1350
1351
1352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1353 ;;; Miscellaneous
1354 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1355
1356 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1357 ;; Hippie expand customization (for expansion of Vera commands)
1358
1359 (defvar vera-abbrev-list
1360 (append (list nil) vera-keywords
1361 (list nil) vera-types
1362 (list nil) vera-functions
1363 (list nil) vera-constants
1364 (list nil) vera-rvm-types
1365 (list nil) vera-rvm-functions
1366 (list nil) vera-rvm-constants)
1367 "Predefined abbreviations for Vera.")
1368
1369 (defvar vera-expand-upper-case nil)
1370
1371 (eval-when-compile (require 'hippie-exp))
1372
1373 (defun vera-try-expand-abbrev (old)
1374 "Try expanding abbreviations from `vera-abbrev-list'."
1375 (unless old
1376 (he-init-string (he-dabbrev-beg) (point))
1377 (setq he-expand-list
1378 (let ((abbrev-list vera-abbrev-list)
1379 (sel-abbrev-list '()))
1380 (while abbrev-list
1381 (when (or (not (stringp (car abbrev-list)))
1382 (string-match
1383 (concat "^" he-search-string) (car abbrev-list)))
1384 (setq sel-abbrev-list
1385 (cons (car abbrev-list) sel-abbrev-list)))
1386 (setq abbrev-list (cdr abbrev-list)))
1387 (nreverse sel-abbrev-list))))
1388 (while (and he-expand-list
1389 (or (not (stringp (car he-expand-list)))
1390 (he-string-member (car he-expand-list) he-tried-table t)))
1391 (unless (stringp (car he-expand-list))
1392 (setq vera-expand-upper-case (car he-expand-list)))
1393 (setq he-expand-list (cdr he-expand-list)))
1394 (if (null he-expand-list)
1395 (progn (when old (he-reset-string))
1396 nil)
1397 (he-substitute-string
1398 (if vera-expand-upper-case
1399 (upcase (car he-expand-list))
1400 (car he-expand-list))
1401 t)
1402 (setq he-expand-list (cdr he-expand-list))
1403 t))
1404
1405 ;; function for expanding abbrevs and dabbrevs
1406 (defalias 'vera-expand-abbrev
1407 (make-hippie-expand-function '(try-expand-dabbrev
1408 try-expand-dabbrev-all-buffers
1409 vera-try-expand-abbrev)))
1410
1411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1412 ;; Comments
1413
1414 (defun vera-comment-uncomment-region (beg end &optional arg)
1415 "Comment region if not commented, uncomment region if already commented."
1416 (interactive "r\nP")
1417 (goto-char beg)
1418 (if (looking-at comment-start-skip)
1419 (comment-region beg end '(4))
1420 (comment-region beg end)))
1421
1422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1423 ;; Help functions
1424
1425 (defun vera-customize ()
1426 "Call the customize function with `vera' as argument."
1427 (interactive)
1428 (customize-group 'vera))
1429
1430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1431 ;; Other
1432
1433 ;; remove ".vr" from `completion-ignored-extensions'
1434 (setq completion-ignored-extensions
1435 (delete ".vr" completion-ignored-extensions))
1436
1437
1438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1439 ;;; Bug reports
1440 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1441
1442 (defconst vera-mode-help-address "Reto Zimmermann <reto@gnu.org>"
1443 "Address for Vera Mode bug reports.")
1444
1445 ;; get reporter-submit-bug-report when byte-compiling
1446 (eval-when-compile
1447 (require 'reporter))
1448
1449 (defun vera-submit-bug-report ()
1450 "Submit via mail a bug report on Vera Mode."
1451 (interactive)
1452 ;; load in reporter
1453 (and
1454 (y-or-n-p "Do you want to submit a report on Vera Mode? ")
1455 (require 'reporter)
1456 (let ((reporter-prompt-for-summary-p t))
1457 (reporter-submit-bug-report
1458 vera-mode-help-address
1459 (concat "Vera Mode " vera-version)
1460 (list
1461 ;; report all important variables
1462 'vera-basic-offset
1463 'vera-underscore-is-part-of-word
1464 'vera-intelligent-tab
1465 )
1466 nil nil
1467 "Hi Reto,"))))
1468
1469
1470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1471 ;;; Documentation
1472 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1473
1474 (defun vera-version ()
1475 "Echo the current version of Vera Mode in the minibuffer."
1476 (interactive)
1477 (message "Vera Mode %s (%s)" vera-version vera-time-stamp))
1478
1479
1480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1481
1482 (provide 'vera-mode)
1483
1484 ;; arch-tag: 22eae722-7ac5-47ac-a713-c4db1cf623a9
1485 ;;; vera-mode.el ends here