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