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