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