]> code.delx.au - gnu-emacs/blob - lisp/progmodes/vhdl-mode.el
Avoid hard-coding "M-x command" in docstrings
[gnu-emacs] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992-2015 Free Software Foundation, Inc.
4
5 ;; Authors: Reto Zimmermann <reto@gnu.org>
6 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
8 ;; Keywords: languages vhdl
9 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
10
11 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
13 ;; filed in the Emacs bug reporting system against this file, a copy
14 ;; of the bug report be sent to the maintainer's email address.
15
16 (defconst vhdl-version "3.37.1"
17 "VHDL Mode version number.")
18
19 (defconst vhdl-time-stamp "2015-01-15"
20 "VHDL Mode time stamp for last update.")
21
22 ;; This file is part of GNU Emacs.
23
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
28
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
33
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
36
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Commentary:
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
43
44 ;; - Syntax highlighting
45 ;; - Indentation
46 ;; - Template insertion (electrification)
47 ;; - Insertion of file headers
48 ;; - Insertion of user-specified models
49 ;; - Port translation / testbench generation
50 ;; - Structural composition
51 ;; - Configuration generation
52 ;; - Sensitivity list updating
53 ;; - File browser
54 ;; - Design hierarchy browser
55 ;; - Source file compilation (syntax analysis)
56 ;; - Makefile generation
57 ;; - Code hiding
58 ;; - Word/keyword completion
59 ;; - Block commenting
60 ;; - Code fixing/alignment/beautification
61 ;; - PostScript printing
62 ;; - VHDL'87/'93/'02/'08 and VHDL-AMS supported
63 ;; - Comprehensive menu
64 ;; - Fully customizable
65 ;; - Works under GNU Emacs (recommended) and XEmacs
66
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Documentation
69
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
71
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; Emacs Versions
74
75 ;; this updated version was only tested on: GNU Emacs 24.1
76
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; Installation
79
80 ;; Prerequisites: GNU Emacs 20/21/22/23/24, XEmacs 20/21.
81
82 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
83 ;; or into an arbitrary directory that is added to the load path by the
84 ;; following line in your Emacs start-up file `.emacs':
85
86 ;; (push (expand-file-name "<directory-name>") load-path)
87
88 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
89 ;; directory. Otherwise, byte-compile the source file:
90 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
91 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
92
93 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
94 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
95 ;; (not required in Emacs 20 and higher):
96
97 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
98 ;; (push '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist)
99
100 ;; More detailed installation instructions are included in the official
101 ;; VHDL Mode distribution.
102
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 ;; Acknowledgments
105
106 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
107 ;; and Steve Grout.
108
109 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
110 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
111
112 ;; Many thanks to all the users who sent me bug reports and enhancement
113 ;; requests.
114 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
115 ;; enhancement suggestions and the fruitful discussions.
116 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
117 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
118
119 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
120 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
121 ;; giving me the opportunity to develop this code.
122 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
123 ;; of the Swiss Government.
124
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126
127 ;;; Code:
128
129 ;; Emacs 21+ handling
130 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
131 "Non-nil if GNU Emacs 21, 22, ... is used.")
132 ;; Emacs 22+ handling
133 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
134 "Non-nil if GNU Emacs 22, ... is used.")
135
136 (defvar compilation-file-regexp-alist)
137 (defvar conf-alist)
138 (defvar conf-entry)
139 (defvar conf-key)
140 (defvar ent-alist)
141 (defvar itimer-version)
142 (defvar lazy-lock-defer-contextually)
143 (defvar lazy-lock-defer-on-scrolling)
144 (defvar lazy-lock-defer-on-the-fly)
145 (defvar speedbar-attached-frame)
146
147
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 ;;; Variables
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151
152 ;; help function for user options
153 (defun vhdl-custom-set (variable value &rest functions)
154 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
155 (if (fboundp 'custom-set-default)
156 (custom-set-default variable value)
157 (set-default variable value))
158 (while functions
159 (when (fboundp (car functions)) (funcall (car functions)))
160 (setq functions (cdr functions))))
161
162 (defun vhdl-widget-directory-validate (widget)
163 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
164 '/' or is empty)."
165 (let ((val (widget-value widget)))
166 (unless (string-match "^\\(\\|.*/\\)$" val)
167 (widget-put widget :error "Invalid directory entry: must end with '/'")
168 widget)))
169
170 ;; help string for user options
171 (defconst vhdl-name-doc-string "
172
173 FROM REGEXP is a regular expression matching the original name:
174 \".*\" matches the entire string
175 \"\\(...\\)\" matches a substring
176 TO STRING specifies the string to be inserted as new name:
177 \"\\&\" means substitute entire matched text
178 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
179 Examples:
180 \".*\" \"\\&\" inserts original string
181 \".*\" \"\\&_i\" attaches \"_i\" to original string
182 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
183 \".*\" \"foo\" inserts constant string \"foo\"
184 \".*\" \"\" inserts empty string")
185
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; User variables (customization options)
188
189 (defgroup vhdl nil
190 "Customizations for VHDL Mode."
191 :prefix "vhdl-"
192 :group 'languages
193 ; :version "21.2" ; comment out for XEmacs
194 )
195
196 (defgroup vhdl-mode nil
197 "Customizations for modes."
198 :group 'vhdl)
199
200 (defcustom vhdl-indent-tabs-mode nil
201 "Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
205
206
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
210
211 (defcustom vhdl-compiler-alist
212 '(
213 ;; 60: docal <= false;
214 ;; ^^^^^
215 ;; [Error] Assignment error: variable is illegal target of signal assignment
216 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
217 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
218 ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("^Compiling file \\(.+\\)" 1)
219 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
220 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
221 ;; Aldec
222 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
223 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
224 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
225 ("^.* ERROR [^:]+: \".*\" \"\\([^ \t\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
226 nil)
227 ;; Cadence Leapfrog: cv -file test.vhd
228 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
229 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
230 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
231 ("^duluth: \\*E,[0-9]+ (\\([^ \t\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
232 ("\\1/entity" "\\2/\\1" "\\1/configuration"
233 "\\1/package" "\\1/body" downcase))
234 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
235 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
236 ;; (PLL_400X_TOP) is not declared [10.3].
237 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
238 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
239 ("^ncvhdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
240 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
241 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
242 ;; ghdl vhdl
243 ;; ghdl -a bad_counter.vhdl
244 ;; bad_counter.vhdl:13:14: operator "=" is overloaded
245 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
246 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
247 ("^ghdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
248 ("\\1/entity" "\\2/\\1" "\\1/configuration"
249 "\\1/package" "\\1/body" downcase))
250 ;; IBM Compiler
251 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
252 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
253 nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
254 ("^[0-9]+ COACHDL.*: File: \\([^ \t\n]+\\), *line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
255 nil)
256 ;; Ikos Voyager: analyze test.vhd
257 ;; analyze test.vhd
258 ;; E L4/C5: this library unit is inaccessible
259 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
260 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
261 ("^E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
262 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
263 nil)
264 ;; ModelSim, Model Technology: vcom test.vhd
265 ;; ERROR: test.vhd(14): Unknown identifier: positiv
266 ;; WARNING[2]: test.vhd(85): Possible infinite loop
267 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
268 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
269 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
270 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
271 ("^\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\[[0-9]+\]\\)? \\([^ \t\n]+\\)(\\([0-9]+\\)):" 3 4 nil) ("" 0)
272 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
273 "\\1/_primary.dat" "\\1/body.dat" downcase))
274 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
275 ;; test.vhd:34: error message
276 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
277 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
278 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
279 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
280 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
281 ;; Quartus compiler
282 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
283 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
284 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
285 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
286 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
287 ("Quartus" "make" "-work \\1" "make" "-f \\1"
288 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
289 ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
290 nil)
291 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
292 ;; ERROR: test.vhd(24): near "dnd": expecting: END
293 ;; WARNING[4]: test.vhd(30): A space is required between ...
294 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
295 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
296 ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
297 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
298 "\\1/_primary.dat" "\\1/body.dat" downcase))
299 ;; Savant: scram -publish-cc test.vhd
300 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
301 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
303 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
304 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
305 "\\1_config.vhdl" "\\1_package.vhdl"
306 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
307 ;; Simili: vhdlp -work test.vhd
308 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
309 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
310 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
311 ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
312 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
313 "\\1/prim.var" "\\1/_body.var" downcase))
314 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
315 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
316 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
317 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
318 ("^ *ERROR\[[0-9]+\]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
319 nil)
320 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
321 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
322 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
323 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
324 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
325 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
326 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
327 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
328 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
329 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
330 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
331 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
332 ;; Synplify:
333 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
334 ("Synplify" "n/a" "n/a" "make" "-f \\1"
335 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
336 ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
337 nil)
338 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
339 ;; Compiling "test.vhd" line 1...
340 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
341 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
342 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
343 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
344 ("^ *Compiling \"\\(.+\\)\" " 1)
345 nil)
346 ;; VeriBest: vc vhdl test.vhd
347 ;; (no file name printed out!)
348 ;; 32: Z <= A and BitA ;
349 ;; ^^^^
350 ;; [Error] Name BITA is unknown
351 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
352 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
353 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
354 nil)
355 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
356 ;; Compiling "test.vhd" line 1...
357 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
358 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
359 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
360 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
361 ("^ *Compiling \"\\(.+\\)\" " 1)
362 nil)
363 ;; Xilinx XST:
364 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
365 ("Xilinx XST" "xflow" "" "make" "-f \\1"
366 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
367 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\." 1 2 nil) ("" 0)
368 nil)
369 )
370 "List of available VHDL compilers and their properties.
371 Each list entry specifies the following items for a compiler:
372 Compiler:
373 Compiler name : name used in option `vhdl-compiler' to choose compiler
374 Compile command : command used for source file compilation
375 Compile options : compile options (\"\\1\" inserts library name)
376 Make command : command used for compilation using a Makefile
377 Make options : make options (\"\\1\" inserts Makefile name)
378 Generate Makefile: use built-in function or command to generate a Makefile
379 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
380 Library command : command to create library directory \(\"\\1\" inserts
381 library directory, \"\\2\" inserts library name)
382 Compile directory: where compilation is run and the Makefile is placed
383 Library directory: directory of default library
384 Makefile name : name of Makefile (default is \"Makefile\")
385 ID string : compiler identification string (see `vhdl-project-alist')
386 Error message:
387 Regexp : regular expression to match error messages (*)
388 File subexp index: index of subexpression that matches the file name
389 Line subexp index: index of subexpression that matches the line number
390 Column subexp idx: index of subexpression that matches the column number
391 File message:
392 Regexp : regular expression to match a file name message
393 File subexp index: index of subexpression that matches the file name
394 Unit-to-file name mapping: mapping of library unit names to names of files
395 generated by the compiler (used for Makefile generation)
396 To string : string a name is mapped to (\"\\1\" inserts the unit name,
397 \"\\2\" inserts the entity name for architectures,
398 \"\\3\" inserts the library name)
399 Case adjustment : adjust case of inserted unit names
400
401 \(*) The regular expression must match the error message starting from the
402 beginning of the line (but not necessarily to the end of the line).
403
404 Compile options allows insertion of the library name (see `vhdl-project-alist')
405 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
406
407 For Makefile generation, the built-in function can be used (requires
408 specification of the unit-to-file name mapping). Alternatively, an
409 external command can be specified. Work directory allows specification of
410 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
411 used for Makefile generation). To use another library name than \"work\",
412 customize `vhdl-project-alist'. The library command is inserted in Makefiles
413 to automatically create the library directory if not existent.
414
415 Compile options, compile directory, library directory, and Makefile name are
416 overwritten by the project settings if a project is defined (see
417 `vhdl-project-alist'). Directory paths are relative to the source file
418 directory.
419
420 Some compilers do not include the file name in the error message, but print
421 out a file name message in advance. In this case, set \"File Subexp Index\"
422 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
423 If no file name at all is printed out, set both \"File Message\" entries to 0
424 \(a default file name message will be printed out instead, does not work in
425 XEmacs).
426
427 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
428 assigning its name to option `vhdl-compiler'.
429
430 Please send any missing or erroneous compiler properties to the maintainer for
431 updating.
432
433 NOTE: Activate new error and file message regexps and reflect the new setting
434 in the choice list of option `vhdl-compiler' by restarting Emacs."
435 :type '(repeat
436 (list :tag "Compiler" :indent 2
437 (string :tag "Compiler name ")
438 (string :tag "Compile command ")
439 (string :tag "Compile options " "-work \\1")
440 (string :tag "Make command " "make")
441 (string :tag "Make options " "-f \\1")
442 (choice :tag "Generate Makefile "
443 (const :tag "Built-in function" nil)
444 (string :tag "Command" "vmake \\2 > \\1"))
445 (string :tag "Library command " "mkdir \\1")
446 (directory :tag "Compile directory "
447 :validate vhdl-widget-directory-validate "./")
448 (directory :tag "Library directory "
449 :validate vhdl-widget-directory-validate "work/")
450 (file :tag "Makefile name " "Makefile")
451 (string :tag "ID string ")
452 (list :tag "Error message" :indent 4
453 (regexp :tag "Regexp ")
454 (choice :tag "File subexp "
455 (integer :tag "Index")
456 (const :tag "No file name" nil))
457 (integer :tag "Line subexp index")
458 (choice :tag "Column subexp "
459 (integer :tag "Index")
460 (const :tag "No column number" nil)))
461 (list :tag "File message" :indent 4
462 (regexp :tag "Regexp ")
463 (integer :tag "File subexp index"))
464 (choice :tag "Unit-to-file name mapping"
465 :format "%t: %[Value Menu%] %v\n"
466 (const :tag "Not defined" nil)
467 (list :tag "To string" :indent 4
468 (string :tag "Entity " "\\1.vhd")
469 (string :tag "Architecture " "\\2_\\1.vhd")
470 (string :tag "Configuration " "\\1.vhd")
471 (string :tag "Package " "\\1.vhd")
472 (string :tag "Package Body " "\\1_body.vhd")
473 (choice :tag "Case adjustment "
474 (const :tag "None" identity)
475 (const :tag "Upcase" upcase)
476 (const :tag "Downcase" downcase))))))
477 :set (lambda (variable value)
478 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
479 :version "24.4"
480 :group 'vhdl-compile)
481
482 (defcustom vhdl-compiler "GHDL"
483 "Specifies the VHDL compiler to be used for syntax analysis.
484 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
485 :type (let ((alist vhdl-compiler-alist) list)
486 (while alist
487 (push (list 'const (caar alist)) list)
488 (setq alist (cdr alist)))
489 (append '(choice) (nreverse list)))
490 :group 'vhdl-compile)
491
492 (defcustom vhdl-compile-use-local-error-regexp nil
493 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
494 In this case, only error message regexps for VHDL compilers are active if
495 compilation is started from a VHDL buffer. Otherwise, the error message
496 regexps are appended to the predefined global regexps, and all regexps are
497 active all the time. Note that by doing that, the predefined global regexps
498 might result in erroneous parsing of error messages for some VHDL compilers.
499
500 NOTE: Activate the new setting by restarting Emacs."
501 :version "25.1" ; t -> nil
502 :type 'boolean
503 :group 'vhdl-compile)
504
505 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
506 "List of default target names in Makefiles.
507 Automatically generated Makefiles include three default targets to compile
508 the entire design, clean the entire design and to create the design library.
509 This option allows you to change the names of these targets to avoid conflicts
510 with other user Makefiles."
511 :type '(list (string :tag "Compile entire design")
512 (string :tag "Clean entire design ")
513 (string :tag "Create design library"))
514 :version "24.3"
515 :group 'vhdl-compile)
516
517 (defcustom vhdl-makefile-generation-hook nil
518 "Functions to run at the end of Makefile generation.
519 Allows you to insert user specific parts into a Makefile.
520
521 Example:
522 \(lambda nil
523 \(re-search-backward \"^# Rule for compiling entire design\")
524 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
525 :type 'hook
526 :group 'vhdl-compile)
527
528 (defcustom vhdl-default-library "work"
529 "Name of default library.
530 Is overwritten by project settings if a project is active."
531 :type 'string
532 :group 'vhdl-compile)
533
534
535 (defgroup vhdl-project nil
536 "Customizations for projects."
537 :group 'vhdl)
538
539 (defcustom vhdl-project-alist
540 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
541 "~/example1/" ("src/system/" "src/components/") ""
542 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
543 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
544 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
545 ("Example 2" "Individual source files, multiple compilers in different directories"
546 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
547 nil "\\1/" "work" "\\1/work/" "Makefile" "")
548 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
549 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
550 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
551 -------------------------------------------------------------------------------
552 -- This is a multi-line project description
553 -- that can be used as a project dependent part of the file header.
554 "))
555 "List of projects and their properties.
556 Name : name used in option `vhdl-project' to choose project
557 Title : title of project (single-line string)
558 Default directory: default project directory (absolute path)
559 Sources : a) source files : path + \"/\" + file name
560 b) directory : path + \"/\"
561 c) directory tree: \"-r \" + path + \"/\"
562 Exclude regexp : matches file/directory names to be excluded as sources
563 Compile options : project-specific options for each compiler
564 Compiler name : name of compiler for which these options are valid
565 Compile options: project-specific compiler options
566 (\"\\1\" inserts library name, \"\\2\" default options)
567 Make options: project-specific make options
568 (\"\\1\" inserts Makefile name, \"\\2\" default options)
569 Exceptions : file-specific exceptions
570 File name regexp: matches file names for which exceptions are valid
571 - Options : file-specific compiler options string
572 (\"\\1\" inserts library name, \"\\2\" default options,
573 \"\\3\" project-specific options)
574 - Do not compile: do not compile this file (in Makefile)
575 Compile directory: where compilation is run and the Makefile is placed
576 \(\"\\1\" inserts compiler ID string)
577 Library name : name of library (default is \"work\")
578 Library directory: path to library (\"\\1\" inserts compiler ID string)
579 Makefile name : name of Makefile
580 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
581 Description : description of project (multi-line string)
582
583 Project title and description are used to insert into the file header (see
584 option `vhdl-file-header').
585
586 The default directory must have an absolute path (use `M-TAB' for completion).
587 All other paths can be absolute or relative to the default directory. All
588 paths must end with '/'.
589
590 The design units found in the sources (files and directories) are shown in the
591 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
592 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
593 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
594 specified, the default directory is taken as source directory. Otherwise,
595 the default directory is only taken as source directory if there is a sources
596 entry with the empty string or \"./\". Exclude regexp allows you to filter
597 out specific file and directory names from the list of sources (e.g. CVS
598 directories).
599
600 Files are compiled in the compile directory. Makefiles are also placed into
601 the compile directory. Library directory specifies which directory the
602 compiler compiles into (used to generate the Makefile).
603
604 Since different compile/library directories and Makefiles may exist for
605 different compilers within one project, these paths and names allow the
606 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
607 Compile options, compile directory, library directory, and Makefile name
608 overwrite the settings of the current compiler.
609
610 File-specific compiler options (highest priority) overwrite project-specific
611 options which overwrite default options (lowest priority). Lower priority
612 options can be inserted in higher priority options. This allows you to reuse
613 default options (e.g. \"-file\") in project- or file-specific options (e.g.
614 \"-93 -file\").
615
616 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
617 by restarting Emacs."
618 :type `(repeat
619 (list :tag "Project" :indent 2
620 (string :tag "Name ")
621 (string :tag "Title ")
622 (directory :tag "Default directory"
623 :validate vhdl-widget-directory-validate
624 ,(abbreviate-file-name default-directory))
625 (repeat :tag "Sources " :indent 4
626 (directory :format " %v" "./"))
627 (regexp :tag "Exclude regexp ")
628 (repeat
629 :tag "Compile options " :indent 4
630 (list :tag "Compiler" :indent 6
631 ,(let ((alist vhdl-compiler-alist) list)
632 (while alist
633 (push (list 'const (caar alist)) list)
634 (setq alist (cdr alist)))
635 (append '(choice :tag "Compiler name")
636 (nreverse list)))
637 (string :tag "Compile options" "\\2")
638 (string :tag "Make options " "\\2")
639 (repeat
640 :tag "Exceptions " :indent 8
641 (cons :format "%v"
642 (regexp :tag "File name regexp ")
643 (choice :format "%[Value Menu%] %v"
644 (string :tag "Options" "\\3")
645 (const :tag "Do not compile" nil))))))
646 (directory :tag "Compile directory"
647 :validate vhdl-widget-directory-validate "./")
648 (string :tag "Library name " "work")
649 (directory :tag "Library directory"
650 :validate vhdl-widget-directory-validate "work/")
651 (file :tag "Makefile name " "Makefile")
652 (string :tag "Description: (type `C-j' for newline)"
653 :format "%t\n%v\n")))
654 :set (lambda (variable value)
655 (vhdl-custom-set variable value
656 'vhdl-update-mode-menu
657 'vhdl-speedbar-refresh))
658 :group 'vhdl-project)
659
660 (defcustom vhdl-project nil
661 "Specifies the default for the current project.
662 Select a project name from the ones defined in option `vhdl-project-alist'.
663 Is used to determine the project title and description to be inserted in file
664 headers and the source files/directories to be scanned in the hierarchy
665 browser. The current project can also be changed temporarily in the menu."
666 :type (let ((alist vhdl-project-alist) list)
667 (while alist
668 (push (list 'const (caar alist)) list)
669 (setq alist (cdr alist)))
670 (append '(choice (const :tag "None" nil) (const :tag "--"))
671 (nreverse list)))
672 :group 'vhdl-project)
673
674 (defcustom vhdl-project-file-name '("\\1.prj")
675 "List of file names/paths for importing/exporting project setups.
676 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
677 replaced by the user name (allows you to have user-specific project setups).
678 The first entry is used as file name to import/export individual project
679 setups. All entries are used to automatically import project setups at
680 startup (see option `vhdl-project-auto-load'). Projects loaded from the
681 first entry are automatically made current. Hint: specify local project
682 setups in first entry, global setups in following entries; loading a local
683 project setup will make it current, while loading the global setups
684 is done without changing the current project.
685 Names can also have an absolute path (i.e. project setups can be stored
686 in global directories)."
687 :type '(repeat (string :tag "File name" "\\1.prj"))
688 :group 'vhdl-project)
689
690 (defcustom vhdl-project-auto-load '(startup)
691 "Automatically load project setups from files.
692 All project setup files that match the file names specified in option
693 `vhdl-project-file-name' are automatically loaded. The project of the
694 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
695 entry is activated.
696 A project setup file can be obtained by exporting a project (see menu).
697 At startup: project setup file is loaded at Emacs startup"
698 :type '(set (const :tag "At startup" startup))
699 :group 'vhdl-project)
700
701 (defcustom vhdl-project-sort t
702 "Non-nil means projects are displayed in alphabetical order."
703 :type 'boolean
704 :group 'vhdl-project)
705
706
707 (defgroup vhdl-style nil
708 "Customizations for coding styles."
709 :group 'vhdl
710 :group 'vhdl-template
711 :group 'vhdl-port
712 :group 'vhdl-compose)
713
714 (defcustom vhdl-standard '(93 nil)
715 "VHDL standards used.
716 Basic standard:
717 VHDL'87 : IEEE Std 1076-1987
718 VHDL'93/02 : IEEE Std 1076-1993/2002
719 VHDL'08 : IEEE Std 1076-2008
720 Additional standards:
721 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
722 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
723
724 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
725 \"Activate Options\"."
726 :type '(list (choice :tag "Basic standard"
727 (const :tag "VHDL'87" 87)
728 (const :tag "VHDL'93/02" 93)
729 (const :tag "VHDL'08" 08))
730 (set :tag "Additional standards" :indent 2
731 (const :tag "VHDL-AMS" ams)
732 (const :tag "Math packages" math)))
733 :set (lambda (variable value)
734 (vhdl-custom-set variable value
735 'vhdl-template-map-init
736 'vhdl-mode-abbrev-table-init
737 'vhdl-template-construct-alist-init
738 'vhdl-template-package-alist-init
739 'vhdl-update-mode-menu
740 'vhdl-words-init 'vhdl-font-lock-init))
741 :group 'vhdl-style)
742
743 (defcustom vhdl-basic-offset 2
744 "Amount of basic offset used for indentation.
745 This value is used by + and - symbols in `vhdl-offsets-alist'."
746 :type 'integer
747 :group 'vhdl-style)
748
749 (defcustom vhdl-upper-case-keywords nil
750 "Non-nil means convert keywords to upper case.
751 This is done when typed or expanded or by the fix case functions."
752 :type 'boolean
753 :set (lambda (variable value)
754 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
755 :group 'vhdl-style)
756
757 (defcustom vhdl-upper-case-types nil
758 "Non-nil means convert standardized types to upper case.
759 This is done when expanded or by the fix case functions."
760 :type 'boolean
761 :set (lambda (variable value)
762 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
763 :group 'vhdl-style)
764
765 (defcustom vhdl-upper-case-attributes nil
766 "Non-nil means convert standardized attributes to upper case.
767 This is done when expanded or by the fix case functions."
768 :type 'boolean
769 :set (lambda (variable value)
770 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
771 :group 'vhdl-style)
772
773 (defcustom vhdl-upper-case-enum-values nil
774 "Non-nil means convert standardized enumeration values to upper case.
775 This is done when expanded or by the fix case functions."
776 :type 'boolean
777 :set (lambda (variable value)
778 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
779 :group 'vhdl-style)
780
781 (defcustom vhdl-upper-case-constants t
782 "Non-nil means convert standardized constants to upper case.
783 This is done when expanded."
784 :type 'boolean
785 :set (lambda (variable value)
786 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
787 :group 'vhdl-style)
788
789 (defcustom vhdl-use-direct-instantiation 'standard
790 "Non-nil means use VHDL'93 direct component instantiation.
791 Never : never
792 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
793 Always : always"
794 :type '(choice (const :tag "Never" never)
795 (const :tag "Standard" standard)
796 (const :tag "Always" always))
797 :group 'vhdl-style)
798
799 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
800 "Non-nil means include array indices / record fields in sensitivity list.
801 If a signal read in a process is a record field or pointed to by an array
802 index, the record field or array index is included with the record name in
803 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
804 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
805 :type 'boolean
806 :version "24.3"
807 :group 'vhdl-style)
808
809 (defgroup vhdl-naming nil
810 "Customizations for naming conventions."
811 :group 'vhdl)
812
813 (defcustom vhdl-entity-file-name '(".*" . "\\&")
814 (concat
815 "Specifies how the entity file name is obtained.
816 The entity file name can be obtained by modifying the entity name (e.g.
817 attaching or stripping off a substring). The file extension is automatically
818 taken from the file name of the current buffer."
819 vhdl-name-doc-string)
820 :type '(cons (regexp :tag "From regexp")
821 (string :tag "To string "))
822 :group 'vhdl-naming
823 :group 'vhdl-compose)
824
825 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
826 (concat
827 "Specifies how the architecture file name is obtained.
828 The architecture file name can be obtained by modifying the entity
829 and/or architecture name (e.g. attaching or stripping off a substring). The
830 file extension is automatically taken from the file name of the current
831 buffer. The string that is matched against the regexp is the concatenation
832 of the entity and the architecture name separated by a space. This gives
833 access to both names (see default setting as example)."
834 vhdl-name-doc-string)
835 :type '(cons (regexp :tag "From regexp")
836 (string :tag "To string "))
837 :group 'vhdl-naming
838 :group 'vhdl-compose)
839
840 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
841 (concat
842 "Specifies how the configuration file name is obtained.
843 The configuration file name can be obtained by modifying the configuration
844 name (e.g. attaching or stripping off a substring). The file extension is
845 automatically taken from the file name of the current buffer."
846 vhdl-name-doc-string)
847 :type '(cons (regexp :tag "From regexp")
848 (string :tag "To string "))
849 :group 'vhdl-naming
850 :group 'vhdl-compose)
851
852 (defcustom vhdl-package-file-name '(".*" . "\\&")
853 (concat
854 "Specifies how the package file name is obtained.
855 The package file name can be obtained by modifying the package name (e.g.
856 attaching or stripping off a substring). The file extension is automatically
857 taken from the file name of the current buffer. Package files can be created
858 in a different directory by prepending a relative or absolute path to the
859 file name."
860 vhdl-name-doc-string)
861 :type '(cons (regexp :tag "From regexp")
862 (string :tag "To string "))
863 :group 'vhdl-naming
864 :group 'vhdl-compose)
865
866 (defcustom vhdl-file-name-case 'identity
867 "Specifies how to change case for obtaining file names.
868 When deriving a file name from a VHDL unit name, case can be changed as
869 follows:
870 As Is: case is not changed (taken as is)
871 Lower Case: whole name is changed to lower case
872 Upper Case: whole name is changed to upper case
873 Capitalize: first letter of each word in name is capitalized"
874 :type '(choice (const :tag "As Is" identity)
875 (const :tag "Lower Case" downcase)
876 (const :tag "Upper Case" upcase)
877 (const :tag "Capitalize" capitalize))
878 :group 'vhdl-naming
879 :group 'vhdl-compose)
880
881
882 (defgroup vhdl-template nil
883 "Customizations for electrification."
884 :group 'vhdl)
885
886 (defcustom vhdl-electric-keywords '(vhdl user)
887 "Type of keywords for which electrification is enabled.
888 VHDL keywords: invoke built-in templates
889 User keywords: invoke user models (see option `vhdl-model-alist')"
890 :type '(set (const :tag "VHDL keywords" vhdl)
891 (const :tag "User model keywords" user))
892 :set (lambda (variable value)
893 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
894 :group 'vhdl-template)
895
896 (defcustom vhdl-optional-labels 'process
897 "Constructs for which labels are to be queried.
898 Template generators prompt for optional labels for:
899 None : no constructs
900 Processes only: processes only (also procedurals in VHDL-AMS)
901 All constructs: all constructs with optional labels and keyword END"
902 :type '(choice (const :tag "None" none)
903 (const :tag "Processes only" process)
904 (const :tag "All constructs" all))
905 :group 'vhdl-template)
906
907 (defcustom vhdl-insert-empty-lines 'unit
908 "Specifies whether to insert empty lines in some templates.
909 This improves readability of code. Empty lines are inserted in:
910 None : no constructs
911 Design units only: entities, architectures, configurations, packages only
912 All constructs : also all constructs with BEGIN...END parts
913
914 Replaces option `vhdl-additional-empty-lines'."
915 :type '(choice (const :tag "None" none)
916 (const :tag "Design units only" unit)
917 (const :tag "All constructs" all))
918 :group 'vhdl-template
919 :group 'vhdl-port
920 :group 'vhdl-compose)
921
922 (defcustom vhdl-argument-list-indent nil
923 "Non-nil means indent argument lists relative to opening parenthesis.
924 That is, argument, association, and port lists start on the same line as the
925 opening parenthesis and subsequent lines are indented accordingly.
926 Otherwise, lists start on a new line and are indented as normal code."
927 :type 'boolean
928 :group 'vhdl-template
929 :group 'vhdl-port
930 :group 'vhdl-compose)
931
932 (defcustom vhdl-association-list-with-formals t
933 "Non-nil means write association lists with formal parameters.
934 Templates prompt for formal and actual parameters (ports/generics).
935 When pasting component instantiations, formals are included.
936 If nil, only a list of actual parameters is entered."
937 :type 'boolean
938 :group 'vhdl-template
939 :group 'vhdl-port
940 :group 'vhdl-compose)
941
942 (defcustom vhdl-conditions-in-parenthesis nil
943 "Non-nil means place parenthesis around condition expressions."
944 :type 'boolean
945 :group 'vhdl-template)
946
947 (defcustom vhdl-sensitivity-list-all t
948 "Non-nil means use 'all' keyword in sensitivity list."
949 :version "25.1"
950 :type 'boolean
951 :group 'vhdl-template)
952
953 (defcustom vhdl-zero-string "'0'"
954 "String to use for a logic zero."
955 :type 'string
956 :group 'vhdl-template)
957
958 (defcustom vhdl-one-string "'1'"
959 "String to use for a logic one."
960 :type 'string
961 :group 'vhdl-template)
962
963
964 (defgroup vhdl-header nil
965 "Customizations for file header."
966 :group 'vhdl-template
967 :group 'vhdl-compose)
968
969 (defcustom vhdl-file-header "\
970 -------------------------------------------------------------------------------
971 -- Title : <title string>
972 -- Project : <project>
973 -------------------------------------------------------------------------------
974 -- File : <filename>
975 -- Author : <author>
976 -- Company : <company>
977 -- Created : <date>
978 -- Last update: <date>
979 -- Platform : <platform>
980 -- Standard : <standard>
981 <projectdesc>-------------------------------------------------------------------------------
982 -- Description: <cursor>
983 <copyright>-------------------------------------------------------------------------------
984 -- Revisions :
985 -- Date Version Author Description
986 -- <date> 1.0 <login>\tCreated
987 -------------------------------------------------------------------------------
988
989 "
990 "String or file to insert as file header.
991 If the string specifies an existing file name, the contents of the file is
992 inserted, otherwise the string itself is inserted as file header.
993 Type `C-j' for newlines.
994 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
995 if the header needs to be version controlled.
996
997 The following keywords for template generation are supported:
998 <filename> : replaced by the name of the buffer
999 <author> : replaced by the user name and email address
1000 \(`user-full-name',`mail-host-address', `user-mail-address')
1001 <authorfull> : replaced by the user full name (`user-full-name')
1002 <login> : replaced by user login name (`user-login-name')
1003 <company> : replaced by contents of option `vhdl-company-name'
1004 <date> : replaced by the current date
1005 <year> : replaced by the current year
1006 <project> : replaced by title of current project (`vhdl-project')
1007 <projectdesc> : replaced by description of current project (`vhdl-project')
1008 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1009 <platform> : replaced by contents of option `vhdl-platform-spec'
1010 <standard> : replaced by the VHDL language standard(s) used
1011 <... string> : replaced by a queried string (\"...\" is the prompt word)
1012 <title string>: replaced by file title in automatically generated files
1013 <cursor> : final cursor position
1014
1015 The (multi-line) project description <projectdesc> can be used as a project
1016 dependent part of the file header and can also contain the above keywords."
1017 :type 'string
1018 :group 'vhdl-header)
1019
1020 (defcustom vhdl-file-footer ""
1021 "String or file to insert as file footer.
1022 If the string specifies an existing file name, the contents of the file is
1023 inserted, otherwise the string itself is inserted as file footer (i.e. at
1024 the end of the file).
1025 Type `C-j' for newlines.
1026 The same keywords as in option `vhdl-file-header' can be used."
1027 :type 'string
1028 :group 'vhdl-header)
1029
1030 (defcustom vhdl-company-name ""
1031 "Name of company to insert in file header.
1032 See option `vhdl-file-header'."
1033 :type 'string
1034 :group 'vhdl-header)
1035
1036 (defcustom vhdl-copyright-string "\
1037 -------------------------------------------------------------------------------
1038 -- Copyright (c) <year> <company>
1039 "
1040 "Copyright string to insert in file header.
1041 Can be multi-line string (type `C-j' for newline) and contain other file
1042 header keywords (see option `vhdl-file-header')."
1043 :type 'string
1044 :group 'vhdl-header)
1045
1046 (defcustom vhdl-platform-spec ""
1047 "Specification of VHDL platform to insert in file header.
1048 The platform specification should contain names and versions of the
1049 simulation and synthesis tools used.
1050 See option `vhdl-file-header'."
1051 :type 'string
1052 :group 'vhdl-header)
1053
1054 (defcustom vhdl-date-format "%Y-%m-%d"
1055 "Specifies the date format to use in the header.
1056 This string is passed as argument to the command `format-time-string'.
1057 For more information on format strings, see the documentation for the
1058 `format-time-string' command (C-h f `format-time-string')."
1059 :type 'string
1060 :group 'vhdl-header)
1061
1062 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1063 "Prefix string of modification date in VHDL file header.
1064 If actualization of the modification date is called (menu,
1065 `\\[vhdl-template-modify]'), this string is searched and the rest
1066 of the line replaced by the current date."
1067 :type 'string
1068 :group 'vhdl-header)
1069
1070 (defcustom vhdl-modify-date-on-saving t
1071 "Non-nil means update the modification date when the buffer is saved.
1072 Calls function `\\[vhdl-template-modify]').
1073
1074 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1075 \"Activate Options\"."
1076 :type 'boolean
1077 :group 'vhdl-header)
1078
1079
1080 (defgroup vhdl-sequential-process nil
1081 "Customizations for sequential processes."
1082 :group 'vhdl-template)
1083
1084 (defcustom vhdl-reset-kind 'async
1085 "Specifies which kind of reset to use in sequential processes."
1086 :type '(choice (const :tag "None" none)
1087 (const :tag "Synchronous" sync)
1088 (const :tag "Asynchronous" async)
1089 (const :tag "Query" query))
1090 :group 'vhdl-sequential-process)
1091
1092 (defcustom vhdl-reset-active-high nil
1093 "Non-nil means reset in sequential processes is active high.
1094 Otherwise, reset is active low."
1095 :type 'boolean
1096 :group 'vhdl-sequential-process)
1097
1098 (defcustom vhdl-clock-rising-edge t
1099 "Non-nil means rising edge of clock triggers sequential processes.
1100 Otherwise, falling edge triggers."
1101 :type 'boolean
1102 :group 'vhdl-sequential-process)
1103
1104 (defcustom vhdl-clock-edge-condition 'standard
1105 "Syntax of the clock edge condition.
1106 Standard: \"clk'event and clk = '1'\"
1107 Function: \"rising_edge(clk)\""
1108 :type '(choice (const :tag "Standard" standard)
1109 (const :tag "Function" function))
1110 :group 'vhdl-sequential-process)
1111
1112 (defcustom vhdl-clock-name ""
1113 "Name of clock signal to use in templates."
1114 :type 'string
1115 :group 'vhdl-sequential-process)
1116
1117 (defcustom vhdl-reset-name ""
1118 "Name of reset signal to use in templates."
1119 :type 'string
1120 :group 'vhdl-sequential-process)
1121
1122
1123 (defgroup vhdl-model nil
1124 "Customizations for user models."
1125 :group 'vhdl)
1126
1127 (defcustom vhdl-model-alist
1128 '(("Example Model"
1129 "<label> : process (<clock>, <reset>)
1130 begin -- process <label>
1131 if <reset> = '0' then -- asynchronous reset (active low)
1132 <cursor>
1133 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1134 if <enable> = '1' then -- synchronous load
1135
1136 end if;
1137 end if;
1138 end process <label>;"
1139 "e" ""))
1140 "List of user models.
1141 VHDL models (templates) can be specified by the user in this list. They can be
1142 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1143 electrification (i.e. overriding existing or creating new keywords, see
1144 option `vhdl-electric-keywords').
1145 Name : name of model (string of words and spaces)
1146 String : string or name of file to be inserted as model (newline: `C-j')
1147 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1148 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1149 Keyword : keyword to invoke model
1150
1151 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1152 A prompt that appears several times is queried once and replaced throughout
1153 the model. Special prompts are:
1154 <clock> : name specified in `vhdl-clock-name' (if not empty)
1155 <reset> : name specified in `vhdl-reset-name' (if not empty)
1156 <cursor>: final cursor position
1157 File header prompts (see variable `vhdl-file-header') are automatically
1158 replaced, so that user models can also be used to insert different types of
1159 headers.
1160
1161 If the string specifies an existing file name, the contents of the file is
1162 inserted, otherwise the string itself is inserted.
1163 The code within the models should be correctly indented.
1164 Type `C-j' for newlines.
1165
1166 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1167 \"Activate Options\"."
1168 :type '(repeat (list :tag "Model" :indent 2
1169 (string :tag "Name ")
1170 (string :tag "String : (type `C-j' for newline)"
1171 :format "%t\n%v")
1172 (sexp :tag "Key binding" x)
1173 (string :tag "Keyword " :format "%t: %v\n")))
1174 :set (lambda (variable value)
1175 (vhdl-custom-set variable value
1176 'vhdl-model-map-init
1177 'vhdl-model-defun
1178 'vhdl-mode-abbrev-table-init
1179 'vhdl-update-mode-menu))
1180 :group 'vhdl-model)
1181
1182
1183 (defgroup vhdl-compose nil
1184 "Customizations for structural composition."
1185 :group 'vhdl)
1186
1187 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1188 (concat
1189 "Specifies how the component architecture name is obtained.
1190 The component architecture name can be obtained by modifying the entity name
1191 \(e.g. attaching or stripping off a substring).
1192 If TO STRING is empty, the architecture name is queried."
1193 vhdl-name-doc-string)
1194 :type '(cons (regexp :tag "From regexp")
1195 (string :tag "To string "))
1196 :group 'vhdl-compose)
1197
1198 (defcustom vhdl-compose-configuration-name
1199 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1200 (concat
1201 "Specifies how the configuration name is obtained.
1202 The configuration name can be obtained by modifying the entity and/or
1203 architecture name (e.g. attaching or stripping off a substring). The string
1204 that is matched against the regexp is the concatenation of the entity and the
1205 architecture name separated by a space. This gives access to both names (see
1206 default setting as example)."
1207 vhdl-name-doc-string)
1208 :type '(cons (regexp :tag "From regexp")
1209 (string :tag "To string "))
1210 :group 'vhdl-compose)
1211
1212 (defcustom vhdl-components-package-name
1213 '((".*" . "\\&_components") . "components")
1214 (concat
1215 "Specifies how the name for the components package is obtained.
1216 The components package is a package containing all component declarations for
1217 the current design. Its name can be obtained by modifying the project name
1218 \(e.g. attaching or stripping off a substring). If no project is defined, the
1219 DIRECTORY entry is chosen."
1220 vhdl-name-doc-string)
1221 :type '(cons (cons :tag "Project" :indent 2
1222 (regexp :tag "From regexp")
1223 (string :tag "To string "))
1224 (string :tag "Directory:\n String "))
1225 :group 'vhdl-compose)
1226
1227 (defcustom vhdl-use-components-package nil
1228 "Non-nil means use a separate components package for component declarations.
1229 Otherwise, component declarations are inserted and searched for in the
1230 architecture declarative parts."
1231 :type 'boolean
1232 :group 'vhdl-compose)
1233
1234 (defcustom vhdl-compose-include-header t
1235 "Non-nil means include a header in automatically generated files."
1236 :type 'boolean
1237 :group 'vhdl-compose)
1238
1239 (defcustom vhdl-compose-create-files 'single
1240 "Specifies whether new files should be created for the new component.
1241 The component's entity and architecture are inserted:
1242 None : in current buffer
1243 Single file : in new single file
1244 Separate files: in two separate files
1245 The file names are obtained from variables `vhdl-entity-file-name' and
1246 `vhdl-architecture-file-name'."
1247 :type '(choice (const :tag "None" none)
1248 (const :tag "Single file" single)
1249 (const :tag "Separate files" separate))
1250 :group 'vhdl-compose)
1251
1252 (defcustom vhdl-compose-configuration-create-file nil
1253 "Specifies whether a new file should be created for the configuration.
1254 If non-nil, a new file is created for the configuration.
1255 The file name is obtained from variable `vhdl-configuration-file-name'."
1256 :type 'boolean
1257 :group 'vhdl-compose)
1258
1259 (defcustom vhdl-compose-configuration-hierarchical t
1260 "Specifies whether hierarchical configurations should be created.
1261 If non-nil, automatically created configurations are hierarchical and include
1262 the whole hierarchy of subcomponents. Otherwise the configuration only
1263 includes one level of subcomponents."
1264 :type 'boolean
1265 :group 'vhdl-compose)
1266
1267 (defcustom vhdl-compose-configuration-use-subconfiguration t
1268 "Specifies whether subconfigurations should be used inside configurations.
1269 If non-nil, automatically created configurations use configurations in binding
1270 indications for subcomponents, if such configurations exist. Otherwise,
1271 entities are used in binding indications for subcomponents."
1272 :type 'boolean
1273 :group 'vhdl-compose)
1274
1275
1276 (defgroup vhdl-port nil
1277 "Customizations for port translation functions."
1278 :group 'vhdl
1279 :group 'vhdl-compose)
1280
1281 (defcustom vhdl-include-port-comments nil
1282 "Non-nil means include port comments when a port is pasted."
1283 :type 'boolean
1284 :group 'vhdl-port)
1285
1286 (defcustom vhdl-include-direction-comments nil
1287 "Non-nil means include port direction in instantiations as comments."
1288 :type 'boolean
1289 :group 'vhdl-port)
1290
1291 (defcustom vhdl-include-type-comments nil
1292 "Non-nil means include generic/port type in instantiations as comments."
1293 :type 'boolean
1294 :group 'vhdl-port)
1295
1296 (defcustom vhdl-include-group-comments 'never
1297 "Specifies whether to include group comments and spacings.
1298 The comments and empty lines between groups of ports are pasted:
1299 Never : never
1300 Declarations: in entity/component/constant/signal declarations only
1301 Always : also in generic/port maps"
1302 :type '(choice (const :tag "Never" never)
1303 (const :tag "Declarations" decl)
1304 (const :tag "Always" always))
1305 :group 'vhdl-port)
1306
1307 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1308 (concat
1309 "Specifies how actual generic names are obtained from formal generic names.
1310 In a component instantiation, an actual generic name can be
1311 obtained by modifying the formal generic name (e.g. attaching or stripping
1312 off a substring)."
1313 vhdl-name-doc-string)
1314 :type '(cons (regexp :tag "From regexp")
1315 (string :tag "To string "))
1316 :group 'vhdl-port
1317 :version "24.4")
1318
1319 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1320 (concat
1321 "Specifies how actual port names are obtained from formal port names.
1322 In a component instantiation, an actual port name can be obtained by
1323 modifying the formal port name (e.g. attaching or stripping off a substring)."
1324 vhdl-name-doc-string)
1325 :type '(cons (regexp :tag "From regexp")
1326 (string :tag "To string "))
1327 :group 'vhdl-port)
1328
1329 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1330 (concat
1331 "Specifies how an instance name is obtained.
1332 The instance name can be obtained by modifying the name of the component to be
1333 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1334 by a unique number (starting with 1).
1335 If TO STRING is empty, the instance name is queried."
1336 vhdl-name-doc-string)
1337 :type '(cons (regexp :tag "From regexp")
1338 (string :tag "To string "))
1339 :group 'vhdl-port)
1340
1341
1342 (defgroup vhdl-testbench nil
1343 "Customizations for testbench generation."
1344 :group 'vhdl-port)
1345
1346 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1347 (concat
1348 "Specifies how the testbench entity name is obtained.
1349 The entity name of a testbench can be obtained by modifying the name of
1350 the component to be tested (e.g. attaching or stripping off a substring)."
1351 vhdl-name-doc-string)
1352 :type '(cons (regexp :tag "From regexp")
1353 (string :tag "To string "))
1354 :group 'vhdl-testbench)
1355
1356 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1357 (concat
1358 "Specifies how the testbench architecture name is obtained.
1359 The testbench architecture name can be obtained by modifying the name of
1360 the component to be tested (e.g. attaching or stripping off a substring).
1361 If TO STRING is empty, the architecture name is queried."
1362 vhdl-name-doc-string)
1363 :type '(cons (regexp :tag "From regexp")
1364 (string :tag "To string "))
1365 :group 'vhdl-testbench)
1366
1367 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1368 (concat
1369 "Specifies how the testbench configuration name is obtained.
1370 The configuration name of a testbench can be obtained by modifying the entity
1371 and/or architecture name (e.g. attaching or stripping off a substring). The
1372 string that is matched against the regexp is the concatenation of the entity
1373 and the architecture name separated by a space. This gives access to both
1374 names (see default setting as example)."
1375 vhdl-name-doc-string)
1376 :type '(cons (regexp :tag "From regexp")
1377 (string :tag "To string "))
1378 :group 'vhdl-testbench)
1379
1380 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1381 (concat
1382 "Specifies how a DUT instance name is obtained.
1383 The design-under-test instance name (i.e. the component instantiated in the
1384 testbench) can be obtained by modifying the component name (e.g. attaching
1385 or stripping off a substring)."
1386 vhdl-name-doc-string)
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
1390
1391 (defcustom vhdl-testbench-include-header t
1392 "Non-nil means include a header in automatically generated files."
1393 :type 'boolean
1394 :group 'vhdl-testbench)
1395
1396 (defcustom vhdl-testbench-declarations "\
1397 -- clock
1398 signal Clk : std_logic := '1';
1399 "
1400 "String or file to be inserted in the testbench declarative part.
1401 If the string specifies an existing file name, the contents of the file is
1402 inserted, otherwise the string itself is inserted in the testbench
1403 architecture before the BEGIN keyword.
1404 Type `C-j' for newlines."
1405 :type 'string
1406 :group 'vhdl-testbench)
1407
1408 (defcustom vhdl-testbench-statements "\
1409 -- clock generation
1410 Clk <= not Clk after 10 ns;
1411
1412 -- waveform generation
1413 WaveGen_Proc: process
1414 begin
1415 -- insert signal assignments here
1416
1417 wait until Clk = '1';
1418 end process WaveGen_Proc;
1419 "
1420 "String or file to be inserted in the testbench statement part.
1421 If the string specifies an existing file name, the contents of the file is
1422 inserted, otherwise the string itself is inserted in the testbench
1423 architecture before the END keyword.
1424 Type `C-j' for newlines."
1425 :type 'string
1426 :group 'vhdl-testbench)
1427
1428 (defcustom vhdl-testbench-initialize-signals nil
1429 "Non-nil means initialize signals with `0' when declared in testbench."
1430 :type 'boolean
1431 :group 'vhdl-testbench)
1432
1433 (defcustom vhdl-testbench-include-library t
1434 "Non-nil means a library/use clause for std_logic_1164 is included."
1435 :type 'boolean
1436 :group 'vhdl-testbench)
1437
1438 (defcustom vhdl-testbench-include-configuration t
1439 "Non-nil means a testbench configuration is attached at the end."
1440 :type 'boolean
1441 :group 'vhdl-testbench)
1442
1443 (defcustom vhdl-testbench-create-files 'single
1444 "Specifies whether new files should be created for the testbench.
1445 testbench entity and architecture are inserted:
1446 None : in current buffer
1447 Single file : in new single file
1448 Separate files: in two separate files
1449 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1450 and `vhdl-testbench-architecture-file-name'."
1451 :type '(choice (const :tag "None" none)
1452 (const :tag "Single file" single)
1453 (const :tag "Separate files" separate))
1454 :group 'vhdl-testbench)
1455
1456 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1457 (concat
1458 "Specifies how the testbench entity file name is obtained.
1459 The entity file name can be obtained by modifying the testbench entity name
1460 \(e.g. attaching or stripping off a substring). The file extension is
1461 automatically taken from the file name of the current buffer. Testbench
1462 files can be created in a different directory by prepending a relative or
1463 absolute path to the file name."
1464 vhdl-name-doc-string)
1465 :type '(cons (regexp :tag "From regexp")
1466 (string :tag "To string "))
1467 :group 'vhdl-testbench)
1468
1469 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1470 (concat
1471 "Specifies how the testbench architecture file name is obtained.
1472 The architecture file name can be obtained by modifying the testbench entity
1473 and/or architecture name (e.g. attaching or stripping off a substring). The
1474 string that is matched against the regexp is the concatenation of the entity
1475 and the architecture name separated by a space. This gives access to both
1476 names (see default setting as example). Testbench files can be created in
1477 a different directory by prepending a relative or absolute path to the file
1478 name."
1479 vhdl-name-doc-string)
1480 :type '(cons (regexp :tag "From regexp")
1481 (string :tag "To string "))
1482 :group 'vhdl-testbench)
1483
1484
1485 (defgroup vhdl-comment nil
1486 "Customizations for comments."
1487 :group 'vhdl)
1488
1489 (defcustom vhdl-self-insert-comments t
1490 "Non-nil means various templates automatically insert help comments."
1491 :type 'boolean
1492 :group 'vhdl-comment)
1493
1494 (defcustom vhdl-prompt-for-comments t
1495 "Non-nil means various templates prompt for user definable comments."
1496 :type 'boolean
1497 :group 'vhdl-comment)
1498
1499 (defcustom vhdl-inline-comment-column 40
1500 "Column to indent and align inline comments to.
1501 Overrides local option `comment-column'.
1502
1503 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1504 \"Activate Options\"."
1505 :type 'integer
1506 :group 'vhdl-comment)
1507
1508 (defcustom vhdl-end-comment-column 79
1509 "End of comment column.
1510 Comments that exceed this column number are wrapped.
1511
1512 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1513 \"Activate Options\"."
1514 :type 'integer
1515 :group 'vhdl-comment)
1516
1517 (defvar end-comment-column)
1518
1519
1520 (defgroup vhdl-beautify nil
1521 "Customizations for beautification."
1522 :group 'vhdl)
1523
1524 (defcustom vhdl-auto-align t
1525 "Non-nil means align some templates automatically after generation."
1526 :type 'boolean
1527 :group 'vhdl-beautify)
1528
1529 (defcustom vhdl-align-groups t
1530 "Non-nil means align groups of code lines separately.
1531 A group of code lines is a region of consecutive lines between two lines that
1532 match the regexp in option `vhdl-align-group-separate'."
1533 :type 'boolean
1534 :group 'vhdl-beautify)
1535
1536 (defcustom vhdl-align-group-separate "^\\s-*$"
1537 "Regexp for matching a line that separates groups of lines for alignment.
1538 Examples:
1539 \"^\\s-*$\": matches an empty line
1540 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1541 :type 'regexp
1542 :group 'vhdl-beautify)
1543
1544 (defcustom vhdl-align-same-indent t
1545 "Non-nil means align blocks with same indent separately.
1546 When a region or the entire buffer is aligned, the code is divided into
1547 blocks of same indent which are aligned separately (except for argument/port
1548 lists). This gives nicer alignment in most cases.
1549 Option `vhdl-align-groups' still applies within these blocks."
1550 :type 'boolean
1551 :group 'vhdl-beautify)
1552
1553 (defcustom vhdl-beautify-options '(t t t t t)
1554 "List of options for beautifying code.
1555 Allows you to disable individual features of code beautification."
1556 :type '(list (boolean :tag "Whitespace cleanup ")
1557 (boolean :tag "Single statement per line")
1558 (boolean :tag "Indentation ")
1559 (boolean :tag "Alignment ")
1560 (boolean :tag "Case fixing "))
1561 :group 'vhdl-beautify
1562 :version "24.4")
1563
1564
1565 (defgroup vhdl-highlight nil
1566 "Customizations for highlighting."
1567 :group 'vhdl)
1568
1569 (defcustom vhdl-highlight-keywords t
1570 "Non-nil means highlight VHDL keywords and other standardized words.
1571 The following faces are used:
1572 `font-lock-keyword-face' : keywords
1573 `font-lock-type-face' : standardized types
1574 `vhdl-font-lock-attribute-face': standardized attributes
1575 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1576 `vhdl-font-lock-function-face' : standardized function and package names
1577
1578 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1579 entry \"Fontify Buffer\")."
1580 :type 'boolean
1581 :set (lambda (variable value)
1582 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1583 :group 'vhdl-highlight)
1584
1585 (defcustom vhdl-highlight-names t
1586 "Non-nil means highlight declaration names and construct labels.
1587 The following faces are used:
1588 `font-lock-function-name-face' : names in declarations of units,
1589 subprograms, components, as well as labels of VHDL constructs
1590 `font-lock-type-face' : names in type/nature declarations
1591 `vhdl-font-lock-attribute-face': names in attribute declarations
1592 `font-lock-variable-name-face' : names in declarations of signals,
1593 variables, constants, subprogram parameters, generics, and ports
1594
1595 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1596 entry \"Fontify Buffer\")."
1597 :type 'boolean
1598 :set (lambda (variable value)
1599 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1600 :group 'vhdl-highlight)
1601
1602 (defcustom vhdl-highlight-special-words nil
1603 "Non-nil means highlight words with special syntax.
1604 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1605 are highlighted accordingly.
1606 Can be used for visual support of naming conventions.
1607
1608 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\")."
1610 :type 'boolean
1611 :set (lambda (variable value)
1612 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1613 :group 'vhdl-highlight)
1614
1615 (defcustom vhdl-highlight-forbidden-words nil
1616 "Non-nil means highlight forbidden words.
1617 The reserved words specified in option `vhdl-forbidden-words' or having the
1618 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1619 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1620 use them.
1621
1622 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1623 entry \"Fontify Buffer\")."
1624 :type 'boolean
1625 :set (lambda (variable value)
1626 (vhdl-custom-set variable value
1627 'vhdl-words-init 'vhdl-font-lock-init))
1628 :group 'vhdl-highlight)
1629
1630 (defcustom vhdl-highlight-verilog-keywords nil
1631 "Non-nil means highlight Verilog keywords as reserved words.
1632 Verilog keywords are highlighted in a warning color (face
1633 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1634
1635 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1636 entry \"Fontify Buffer\")."
1637 :type 'boolean
1638 :set (lambda (variable value)
1639 (vhdl-custom-set variable value
1640 'vhdl-words-init 'vhdl-font-lock-init))
1641 :group 'vhdl-highlight)
1642
1643 (defcustom vhdl-highlight-translate-off nil
1644 "Non-nil means background-highlight code excluded from translation.
1645 That is, all code between \"-- pragma translate_off\" and
1646 \"-- pragma translate_on\" is highlighted using a different background color
1647 \(face `vhdl-font-lock-translate-off-face').
1648 Note: this might slow down on-the-fly fontification (and thus editing).
1649
1650 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1651 entry \"Fontify Buffer\")."
1652 :type 'boolean
1653 :set (lambda (variable value)
1654 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1655 :group 'vhdl-highlight)
1656
1657 (defcustom vhdl-highlight-case-sensitive nil
1658 "Non-nil means consider case for highlighting.
1659 Possible trade-off:
1660 non-nil also upper-case VHDL words are highlighted, but case of words with
1661 special syntax is not considered
1662 nil only lower-case VHDL words are highlighted, but case of words with
1663 special syntax is considered
1664 Overrides local option `font-lock-keywords-case-fold-search'.
1665
1666 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1667 entry \"Fontify Buffer\")."
1668 :type 'boolean
1669 :group 'vhdl-highlight)
1670
1671 (defcustom vhdl-special-syntax-alist
1672 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1673 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1674 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1675 "List of special syntax to be highlighted.
1676 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1677 syntax (as regular expression) are highlighted in the corresponding color.
1678
1679 Name : string of words and spaces
1680 Regexp : regular expression describing word syntax
1681 (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
1682 expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
1683 if only whole words should be matched (no substrings)
1684 Color (light): foreground color for light background
1685 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1686 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1687 Color (dark) : foreground color for dark background
1688 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1689 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1690 In comments : If non-nil, words are also highlighted inside comments
1691
1692 Can be used for visual support of naming conventions, such as highlighting
1693 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1694 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1695 common substrings or name suffices.
1696 For each entry, a new face is generated with the specified colors and name
1697 \"vhdl-font-lock-\" + name + \"-face\".
1698
1699 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1700 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1701 :type '(repeat (list :tag "Face" :indent 2
1702 (string :tag "Name ")
1703 (regexp :tag "Regexp " "\\w+_")
1704 (string :tag "Color (light)")
1705 (string :tag "Color (dark) ")
1706 (boolean :tag "In comments ")))
1707 :set (lambda (variable value)
1708 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1709 :group 'vhdl-highlight)
1710
1711 (defcustom vhdl-forbidden-words '()
1712 "List of forbidden words to be highlighted.
1713 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1714 words are highlighted in a warning color to indicate not to use them.
1715
1716 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1717 entry \"Fontify Buffer\")."
1718 :type '(repeat (string :format "%v"))
1719 :set (lambda (variable value)
1720 (vhdl-custom-set variable value
1721 'vhdl-words-init 'vhdl-font-lock-init))
1722 :group 'vhdl-highlight)
1723
1724 (defcustom vhdl-forbidden-syntax ""
1725 "Syntax of forbidden words to be highlighted.
1726 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1727 syntax are highlighted in a warning color to indicate not to use them.
1728 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1729 highlights identifiers with 10 or more characters).
1730
1731 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1732 entry \"Fontify Buffer\")."
1733 :type 'regexp
1734 :set (lambda (variable value)
1735 (vhdl-custom-set variable value
1736 'vhdl-words-init 'vhdl-font-lock-init))
1737 :group 'vhdl-highlight)
1738
1739 (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
1740 "List of compiler directive keywords recognized for highlighting.
1741
1742 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1743 entry \"Fontify Buffer\")."
1744 :type '(repeat (string :format "%v"))
1745 :set (lambda (variable value)
1746 (vhdl-custom-set variable value
1747 'vhdl-words-init 'vhdl-font-lock-init))
1748 :group 'vhdl-highlight)
1749
1750
1751 (defgroup vhdl-speedbar nil
1752 "Customizations for speedbar."
1753 :group 'vhdl)
1754
1755 (defcustom vhdl-speedbar-auto-open nil
1756 "Non-nil means automatically open speedbar at startup.
1757 Alternatively, the speedbar can be opened from the VHDL menu."
1758 :type 'boolean
1759 :group 'vhdl-speedbar)
1760
1761 (defcustom vhdl-speedbar-display-mode 'files
1762 "Specifies the default displaying mode when opening speedbar.
1763 Alternatively, the displaying mode can be selected from the speedbar menu or
1764 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1765 :type '(choice (const :tag "Files" files)
1766 (const :tag "Directory hierarchy" directory)
1767 (const :tag "Project hierarchy" project))
1768 :group 'vhdl-speedbar)
1769
1770 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1771 "Limits scanning of large files and netlists.
1772 Design units: maximum file size to scan for design units
1773 Hierarchy (instances of subcomponents):
1774 File size: maximum file size to scan for instances (in bytes)
1775 Instances per arch: maximum number of instances to scan per architecture
1776
1777 \"None\" always means that there is no limit.
1778 In case of files not or incompletely scanned, a warning message and the file
1779 names are printed out.
1780 Background: scanning for instances is considerably slower than scanning for
1781 design units, especially when there are many instances. These limits should
1782 prevent the scanning of large netlists."
1783 :type '(list (choice :tag "Design units"
1784 :format "%t : %[Value Menu%] %v"
1785 (const :tag "None" nil)
1786 (integer :tag "File size"))
1787 (list :tag "Hierarchy" :indent 2
1788 (choice :tag "File size"
1789 :format "%t : %[Value Menu%] %v"
1790 (const :tag "None" nil)
1791 (integer :tag "Size "))
1792 (choice :tag "Instances per arch"
1793 (const :tag "None" nil)
1794 (integer :tag "Number "))))
1795 :group 'vhdl-speedbar)
1796
1797 (defcustom vhdl-speedbar-jump-to-unit t
1798 "Non-nil means jump to the design unit code when opened in a buffer.
1799 The buffer cursor position is left unchanged otherwise."
1800 :type 'boolean
1801 :group 'vhdl-speedbar)
1802
1803 (defcustom vhdl-speedbar-update-on-saving t
1804 "Automatically update design hierarchy when buffer is saved."
1805 :type 'boolean
1806 :group 'vhdl-speedbar)
1807
1808 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1809 "Automatically save modified hierarchy caches when exiting Emacs.
1810 Hierarchy: design hierarchy information
1811 Display: displaying information (which design units to expand)"
1812 :type '(set (const :tag "Hierarchy" hierarchy)
1813 (const :tag "Display" display))
1814 :group 'vhdl-speedbar)
1815
1816 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1817 "Name of file for saving hierarchy cache.
1818 \"\\1\" is replaced by the project name if a project is specified,
1819 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1820 different users to have cache files in the same directory). Can also have
1821 an absolute path (i.e. all caches can be stored in one global directory)."
1822 :type 'string
1823 :group 'vhdl-speedbar)
1824
1825
1826 (defgroup vhdl-menu nil
1827 "Customizations for menus."
1828 :group 'vhdl)
1829
1830 (defcustom vhdl-index-menu nil
1831 "Non-nil means add an index menu for a source file when loading.
1832 Alternatively, the speedbar can be used. Note that the index menu scans a file
1833 when it is opened, while speedbar only scans the file upon request."
1834 :type 'boolean
1835 :group 'vhdl-menu)
1836
1837 (defcustom vhdl-source-file-menu nil
1838 "Non-nil means add a menu of all source files in current directory.
1839 Alternatively, the speedbar can be used."
1840 :type 'boolean
1841 :group 'vhdl-menu)
1842
1843 (defcustom vhdl-hideshow-menu nil
1844 "Non-nil means add hideshow menu and functionality at startup.
1845 Hideshow can also be enabled from the VHDL Mode menu.
1846 Hideshow allows hiding code of various VHDL constructs.
1847
1848 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1849 \"Activate Options\"."
1850 :type 'boolean
1851 :group 'vhdl-menu)
1852
1853 (defcustom vhdl-hide-all-init nil
1854 "Non-nil means hide all design units initially after a file is loaded."
1855 :type 'boolean
1856 :group 'vhdl-menu)
1857
1858
1859 (defgroup vhdl-print nil
1860 "Customizations for printing."
1861 :group 'vhdl)
1862
1863 (defcustom vhdl-print-two-column t
1864 "Non-nil means print code in two columns and landscape format.
1865 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1866 prints VHDL files in a nice two-column landscape style.
1867
1868 NOTE: Activate the new setting by restarting Emacs.
1869 Overrides `ps-print' settings locally."
1870 :type 'boolean
1871 :group 'vhdl-print)
1872
1873 (defcustom vhdl-print-customize-faces t
1874 "Non-nil means use an optimized set of faces for PostScript printing.
1875
1876 NOTE: Activate the new setting by restarting Emacs.
1877 Overrides `ps-print' settings locally."
1878 :type 'boolean
1879 :group 'vhdl-print)
1880
1881
1882 (defgroup vhdl-misc nil
1883 "Miscellaneous customizations."
1884 :group 'vhdl)
1885
1886 (defcustom vhdl-intelligent-tab t
1887 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1888 That is, if preceding character is part of a word then complete word,
1889 else if not at beginning of line then insert tab,
1890 else if last command was a `TAB' or `RET' then dedent one step,
1891 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1892 If nil, TAB always indents current line (i.e. `TAB' is bound to
1893 `indent-according-to-mode').
1894
1895 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1896 \"Activate Options\"."
1897 :type 'boolean
1898 :group 'vhdl-misc)
1899
1900 (defcustom vhdl-indent-syntax-based t
1901 "Non-nil means indent lines of code based on their syntactic context.
1902 Otherwise, a line is indented like the previous nonblank line. This can be
1903 useful in large files where syntax-based indentation gets very slow."
1904 :type 'boolean
1905 :group 'vhdl-misc)
1906
1907 (defcustom vhdl-indent-comment-like-next-code-line t
1908 "Non-nil means comment lines are indented like the following code line.
1909 Otherwise, comment lines are indented like the preceding code line.
1910 Indenting comment lines like the following code line gives nicer indentation
1911 when comments precede the code that they refer to."
1912 :type 'boolean
1913 :version "24.3"
1914 :group 'vhdl-misc)
1915
1916 (defcustom vhdl-word-completion-case-sensitive nil
1917 "Non-nil means word completion using `TAB' is case sensitive.
1918 That is, `TAB' completes words that start with the same letters and case.
1919 Otherwise, case is ignored."
1920 :type 'boolean
1921 :group 'vhdl-misc)
1922
1923 (defcustom vhdl-word-completion-in-minibuffer t
1924 "Non-nil enables word completion in minibuffer (for template prompts).
1925
1926 NOTE: Activate the new setting by restarting Emacs."
1927 :type 'boolean
1928 :group 'vhdl-misc)
1929
1930 (defcustom vhdl-underscore-is-part-of-word nil
1931 "Non-nil means consider the underscore character `_' as part of word.
1932 An identifier containing underscores is then treated as a single word in
1933 select and move operations. All parts of an identifier separated by underscore
1934 are treated as single words otherwise."
1935 :type 'boolean
1936 :group 'vhdl-misc)
1937 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1938 'superword-mode "24.4")
1939
1940
1941 (defgroup vhdl-related nil
1942 "Related general customizations."
1943 :group 'vhdl)
1944
1945 ;; add related general customizations
1946 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1947 (if (featurep 'xemacs)
1948 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1949 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1950 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1951 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1952 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1953 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1954 (unless (featurep 'xemacs)
1955 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1956 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1957 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1958 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1959
1960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1961 ;; Hidden user variables
1962
1963 (defvar vhdl-compile-absolute-path nil
1964 "If non-nil, use absolute instead of relative path for compiled files.")
1965
1966 (defvar vhdl-comment-display-line-char ?-
1967 "Character to use in comment display line.")
1968
1969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1970 ;; Internal variables
1971
1972 (defvar vhdl-menu-max-size 20
1973 "Specifies the maximum size of a menu before splitting it into submenus.")
1974
1975 (defvar vhdl-progress-interval 1
1976 "Interval used to update progress status during long operations.
1977 If a number, percentage complete gets updated after each interval of
1978 that many seconds. To inhibit all messages, set this option to nil.")
1979
1980 (defvar vhdl-inhibit-startup-warnings-p nil
1981 "If non-nil, inhibits start up compatibility warnings.")
1982
1983 (defvar vhdl-strict-syntax-p nil
1984 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1985 If the syntactic symbol for a particular line does not match a symbol
1986 in the offsets alist, an error is generated, otherwise no error is
1987 reported and the syntactic symbol is ignored.")
1988
1989 (defvar vhdl-echo-syntactic-information-p nil
1990 "If non-nil, syntactic info is echoed when the line is indented.")
1991
1992 (defconst vhdl-offsets-alist-default
1993 '((string . -1000)
1994 (cpp-macro . -1000)
1995 (block-open . 0)
1996 (block-close . 0)
1997 (statement . 0)
1998 (statement-cont . vhdl-lineup-statement-cont)
1999 (statement-block-intro . +)
2000 (statement-case-intro . +)
2001 (case-alternative . +)
2002 (comment . vhdl-lineup-comment)
2003 (arglist-intro . +)
2004 (arglist-cont . 0)
2005 (arglist-cont-nonempty . vhdl-lineup-arglist)
2006 (arglist-close . vhdl-lineup-arglist)
2007 (entity . 0)
2008 (configuration . 0)
2009 (package . 0)
2010 (architecture . 0)
2011 (package-body . 0)
2012 (context . 0)
2013 (directive . 0)
2014 )
2015 "Default settings for offsets of syntactic elements.
2016 Do not change this constant! See the variable `vhdl-offsets-alist' for
2017 more information.")
2018
2019 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2020 "Association list of syntactic element symbols and indentation offsets.
2021 As described below, each cons cell in this list has the form:
2022
2023 (SYNTACTIC-SYMBOL . OFFSET)
2024
2025 When a line is indented, `vhdl-mode' first determines the syntactic
2026 context of the line by generating a list of symbols called syntactic
2027 elements. This list can contain more than one syntactic element and
2028 the global variable `vhdl-syntactic-context' contains the context list
2029 for the line being indented. Each element in this list is actually a
2030 cons cell of the syntactic symbol and a buffer position. This buffer
2031 position is call the relative indent point for the line. Some
2032 syntactic symbols may not have a relative indent point associated with
2033 them.
2034
2035 After the syntactic context list for a line is generated, `vhdl-mode'
2036 calculates the absolute indentation for the line by looking at each
2037 syntactic element in the list. First, it compares the syntactic
2038 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2039 finds a match, it adds the OFFSET to the column of the relative indent
2040 point. The sum of this calculation for each element in the syntactic
2041 list is the absolute offset for line being indented.
2042
2043 If the syntactic element does not match any in the `vhdl-offsets-alist',
2044 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2045 the element is ignored.
2046
2047 Actually, OFFSET can be an integer, a function, a variable, or one of
2048 the following symbols: `+', `-', `++', or `--'. These latter
2049 designate positive or negative multiples of `vhdl-basic-offset',
2050 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2051 called with a single argument containing the cons of the syntactic
2052 element symbol and the relative indent point. The function should
2053 return an integer offset.
2054
2055 Here is the current list of valid syntactic element symbols:
2056
2057 string -- inside multi-line string
2058 block-open -- statement block open
2059 block-close -- statement block close
2060 statement -- a VHDL statement
2061 statement-cont -- a continuation of a VHDL statement
2062 statement-block-intro -- the first line in a new statement block
2063 statement-case-intro -- the first line in a case alternative block
2064 case-alternative -- a case statement alternative clause
2065 comment -- a line containing only a comment
2066 arglist-intro -- the first line in an argument list
2067 arglist-cont -- subsequent argument list lines when no
2068 arguments follow on the same line as
2069 the arglist opening paren
2070 arglist-cont-nonempty -- subsequent argument list lines when at
2071 least one argument follows on the same
2072 line as the arglist opening paren
2073 arglist-close -- the solo close paren of an argument list
2074 entity -- inside an entity declaration
2075 configuration -- inside a configuration declaration
2076 package -- inside a package declaration
2077 architecture -- inside an architecture body
2078 package-body -- inside a package body
2079 context -- inside a context declaration")
2080
2081 (defvar vhdl-comment-only-line-offset 0
2082 "Extra offset for line which contains only the start of a comment.
2083 Can contain an integer or a cons cell of the form:
2084
2085 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2086
2087 Where NON-ANCHORED-OFFSET is the amount of offset given to
2088 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2089 the amount of offset to give column-zero anchored comment-only lines.
2090 Just an integer as value is equivalent to (<val> . 0)")
2091
2092 (defvar vhdl-special-indent-hook nil
2093 "Hook for user defined special indentation adjustments.
2094 This hook gets called after a line is indented by the mode.")
2095
2096 (defvar vhdl-style-alist
2097 '(("IEEE"
2098 (vhdl-basic-offset . 4)
2099 (vhdl-offsets-alist . ())))
2100 "Styles of Indentation.
2101 Elements of this alist are of the form:
2102
2103 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2104
2105 where STYLE-STRING is a short descriptive string used to select a
2106 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2107 value for that variable when using the selected style.
2108
2109 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2110 case, the VALUE is a list containing elements of the form:
2111
2112 (SYNTACTIC-SYMBOL . VALUE)
2113
2114 as described in `vhdl-offsets-alist'. These are passed directly to
2115 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2116 your style, only those that are different from the default.")
2117
2118 ;; dynamically append the default value of most variables
2119 (or (assoc "Default" vhdl-style-alist)
2120 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2121 vhdl-strict-syntax-p
2122 vhdl-echo-syntactic-information-p
2123 vhdl-basic-offset
2124 vhdl-offsets-alist
2125 vhdl-comment-only-line-offset))
2126 (default (cons "Default"
2127 (mapcar
2128 (function
2129 (lambda (var)
2130 (cons var (symbol-value var))))
2131 varlist))))
2132 (push default vhdl-style-alist)))
2133
2134 (defvar vhdl-mode-hook nil
2135 "Hook called by `vhdl-mode'.")
2136
2137
2138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2139 ;;; Required packages
2140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2141
2142 ;; mandatory
2143 (require 'compile) ; XEmacs
2144 (require 'easymenu)
2145 (require 'hippie-exp)
2146
2147 ;; optional (minimize warning messages during compile)
2148 (unless (featurep 'xemacs)
2149 (eval-when-compile
2150 (require 'font-lock)
2151 (require 'ps-print)
2152 (require 'speedbar))) ; for speedbar-with-writable
2153
2154 (defun vhdl-aput (alist-symbol key &optional value)
2155 "Insert a key-value pair into an alist.
2156 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2157 from KEY and VALUE. If the key-value pair referenced by KEY can be
2158 found in the alist, the value of KEY will be set to VALUE. If the
2159 key-value pair cannot be found in the alist, it will be inserted into
2160 the head of the alist."
2161 (let* ((alist (symbol-value alist-symbol))
2162 (elem (assoc key alist)))
2163 (if elem
2164 (setcdr elem value)
2165 (set alist-symbol (cons (cons key value) alist)))))
2166
2167 (defun vhdl-adelete (alist-symbol key)
2168 "Delete a key-value pair from the alist.
2169 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2170 is pair matching KEY."
2171 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2172 (while (equal key (caar alist))
2173 (setq alist (cdr alist))
2174 (set alist-symbol alist))
2175 (while (setq alist-cdr (cdr alist))
2176 (if (equal key (caar alist-cdr))
2177 (setcdr alist (cdr alist-cdr))
2178 (setq alist alist-cdr)))))
2179
2180 (defun vhdl-aget (alist key)
2181 "Return the value in ALIST that is associated with KEY. If KEY is
2182 not found, then nil is returned."
2183 (cdr (assoc key alist)))
2184
2185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2186 ;;; Compatibility
2187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2188
2189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190 ;; XEmacs compatibility
2191
2192 ;; active regions
2193 (defun vhdl-keep-region-active ()
2194 "Do whatever is necessary to keep the region active in XEmacs.
2195 Ignore byte-compiler warnings you might see."
2196 (and (featurep 'xemacs)
2197 (setq zmacs-region-stays t)))
2198
2199 ;; `wildcard-to-regexp' is included only in XEmacs 21
2200 (unless (fboundp 'wildcard-to-regexp)
2201 (defun wildcard-to-regexp (wildcard)
2202 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2203 (let* ((i (string-match "[*?]" wildcard))
2204 (result (substring wildcard 0 i))
2205 (len (length wildcard)))
2206 (when i
2207 (while (< i len)
2208 (let ((ch (aref wildcard i)))
2209 (setq result (concat result
2210 (cond ((eq ch ?*) "[^\000]*")
2211 ((eq ch ??) "[^\000]")
2212 (t (char-to-string ch)))))
2213 (setq i (1+ i)))))
2214 (concat "\\`" result "\\'"))))
2215
2216 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2217 ;; `regexp-opt' accelerates fontification by 10-20%
2218 (unless (fboundp 'regexp-opt)
2219 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2220 (defun regexp-opt (strings &optional paren)
2221 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2222 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2223
2224 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2225 (unless (fboundp 'match-string-no-properties)
2226 (defalias 'match-string-no-properties 'match-string))
2227
2228 ;; `subst-char-in-string' undefined (XEmacs)
2229 (unless (fboundp 'subst-char-in-string)
2230 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2231 (let ((i (length string))
2232 (newstr (if inplace string (copy-sequence string))))
2233 (while (> i 0)
2234 (setq i (1- i))
2235 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2236 newstr)))
2237
2238 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2239 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2240 (not noninteractive))
2241 (load "itimer")
2242 (when (string< itimer-version "1.09")
2243 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2244 (beep) (sit-for 5)))
2245
2246 ;; `file-expand-wildcards' undefined (XEmacs)
2247 (unless (fboundp 'file-expand-wildcards)
2248 (defun file-expand-wildcards (pattern &optional full)
2249 "Taken from Emacs's `files.el'."
2250 (let* ((nondir (file-name-nondirectory pattern))
2251 (dirpart (file-name-directory pattern))
2252 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2253 (mapcar 'file-name-as-directory
2254 (file-expand-wildcards (directory-file-name dirpart)))
2255 (list dirpart)))
2256 contents)
2257 (while dirs
2258 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2259 (file-directory-p (directory-file-name (car dirs))))
2260 (let ((this-dir-contents
2261 (delq nil
2262 (mapcar #'(lambda (name)
2263 (unless (string-match "\\`\\.\\.?\\'"
2264 (file-name-nondirectory name))
2265 name))
2266 (directory-files (or (car dirs) ".") full
2267 (wildcard-to-regexp nondir))))))
2268 (setq contents
2269 (nconc
2270 (if (and (car dirs) (not full))
2271 (mapcar (function (lambda (name) (concat (car dirs) name)))
2272 this-dir-contents)
2273 this-dir-contents)
2274 contents))))
2275 (setq dirs (cdr dirs)))
2276 contents)))
2277
2278 ;; `member-ignore-case' undefined (XEmacs)
2279 (unless (fboundp 'member-ignore-case)
2280 (defalias 'member-ignore-case 'member))
2281
2282 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2283 ;; behavior in XEmacs
2284 (defvar vhdl-last-input-event)
2285 (if (featurep 'xemacs)
2286 (defvaralias 'vhdl-last-input-event 'last-input-char)
2287 (defvaralias 'vhdl-last-input-event 'last-input-event))
2288
2289 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2290 ;;;(unless (fboundp 'help-print-return-message)
2291 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2292
2293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2294 ;; Compatibility with older VHDL Mode versions
2295
2296 (defvar vhdl-warnings nil
2297 "Warnings to tell the user during start up.")
2298
2299 (defun vhdl-run-when-idle (secs repeat function)
2300 "Wait until idle, then run FUNCTION."
2301 (if (fboundp 'start-itimer)
2302 (start-itimer "vhdl-mode" function secs repeat t)
2303 ;; explicitly activate timer (necessary when Emacs is already idle)
2304 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2305
2306 (defun vhdl-warning-when-idle (&rest args)
2307 "Wait until idle, then print out warning STRING and beep."
2308 (if noninteractive
2309 (vhdl-warning (apply 'format args) t)
2310 (unless vhdl-warnings
2311 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2312 (push (apply 'format args) vhdl-warnings)))
2313
2314 (defun vhdl-warning (string &optional nobeep)
2315 "Print out warning STRING and beep."
2316 (message "WARNING: %s" string)
2317 (unless (or nobeep noninteractive) (beep)))
2318
2319 (defun vhdl-print-warnings ()
2320 "Print out messages in variable `vhdl-warnings'."
2321 (let ((no-warnings (length vhdl-warnings)))
2322 (setq vhdl-warnings (nreverse vhdl-warnings))
2323 (while vhdl-warnings
2324 (message "WARNING: %s" (car vhdl-warnings))
2325 (setq vhdl-warnings (cdr vhdl-warnings)))
2326 (beep)
2327 (when (> no-warnings 1)
2328 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2329
2330 ;; Backward compatibility checks and fixes
2331 ;; option `vhdl-compiler' changed format
2332 (unless (stringp vhdl-compiler)
2333 (setq vhdl-compiler "ModelSim")
2334 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2335
2336 ;; option `vhdl-standard' changed format
2337 (unless (listp vhdl-standard)
2338 (setq vhdl-standard '(87 nil))
2339 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2340
2341 ;; option `vhdl-model-alist' changed format
2342 (when (= (length (car vhdl-model-alist)) 3)
2343 (let ((old-alist vhdl-model-alist)
2344 new-alist)
2345 (while old-alist
2346 (push (append (car old-alist) '("")) new-alist)
2347 (setq old-alist (cdr old-alist)))
2348 (setq vhdl-model-alist (nreverse new-alist)))
2349 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2350
2351 ;; option `vhdl-project-alist' changed format
2352 (when (= (length (car vhdl-project-alist)) 3)
2353 (let ((old-alist vhdl-project-alist)
2354 new-alist)
2355 (while old-alist
2356 (push (append (car old-alist) '("")) new-alist)
2357 (setq old-alist (cdr old-alist)))
2358 (setq vhdl-project-alist (nreverse new-alist)))
2359 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2360
2361 ;; option `vhdl-project-alist' changed format (3.31.1)
2362 (when (= (length (car vhdl-project-alist)) 4)
2363 (let ((old-alist vhdl-project-alist)
2364 new-alist elem)
2365 (while old-alist
2366 (setq elem (car old-alist))
2367 (setq new-alist
2368 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2369 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2370 new-alist))
2371 (setq old-alist (cdr old-alist)))
2372 (setq vhdl-project-alist (nreverse new-alist)))
2373 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2374
2375 ;; option `vhdl-project-alist' changed format (3.31.12)
2376 (when (= (length (car vhdl-project-alist)) 10)
2377 (let ((tmp-alist vhdl-project-alist))
2378 (while tmp-alist
2379 (setcdr (nthcdr 3 (car tmp-alist))
2380 (cons "" (nthcdr 4 (car tmp-alist))))
2381 (setq tmp-alist (cdr tmp-alist))))
2382 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2383
2384 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2385 (when (= (length (car vhdl-compiler-alist)) 7)
2386 (let ((old-alist vhdl-compiler-alist)
2387 new-alist elem)
2388 (while old-alist
2389 (setq elem (car old-alist))
2390 (setq new-alist
2391 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2392 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2393 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2394 (nth 5 elem) (nth 6 elem) nil)
2395 new-alist))
2396 (setq old-alist (cdr old-alist)))
2397 (setq vhdl-compiler-alist (nreverse new-alist)))
2398 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2399
2400 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2401 (when (= (length (car vhdl-compiler-alist)) 12)
2402 (let ((tmp-alist vhdl-compiler-alist))
2403 (while tmp-alist
2404 (setcdr (nthcdr 4 (car tmp-alist))
2405 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2406 (setq tmp-alist (cdr tmp-alist))))
2407 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2408
2409 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2410 (when (= (length (car vhdl-compiler-alist)) 13)
2411 (let ((tmp-alist vhdl-compiler-alist))
2412 (while tmp-alist
2413 (setcdr (nthcdr 3 (car tmp-alist))
2414 (cons "" (nthcdr 4 (car tmp-alist))))
2415 (setq tmp-alist (cdr tmp-alist))))
2416 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2417
2418 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2419 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2420 (let ((tmp-alist vhdl-compiler-alist))
2421 (while tmp-alist
2422 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2423 '(0 . nil))
2424 (setq tmp-alist (cdr tmp-alist))))
2425 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2426
2427 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2428 (when (equal vhdl-project "")
2429 (setq vhdl-project nil)
2430 (customize-save-variable 'vhdl-project vhdl-project))
2431
2432 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2433 (when (stringp vhdl-project-file-name)
2434 (setq vhdl-project-file-name (list vhdl-project-file-name))
2435 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2436
2437 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2438 (if (not (boundp 'speedbar-indentation-width))
2439 (defvar speedbar-indentation-width 2)
2440 ;; set default to 2 if not already customized
2441 (unless (get 'speedbar-indentation-width 'saved-value)
2442 (setq speedbar-indentation-width 2)))
2443
2444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2445 ;;; Help functions / inline substitutions / macros
2446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2447
2448 (defun vhdl-standard-p (standard)
2449 "Check if STANDARD is specified as used standard."
2450 (or (eq standard (car vhdl-standard))
2451 (memq standard (cadr vhdl-standard))))
2452
2453 (defun vhdl-project-p (&optional warning)
2454 "Return non-nil if a project is displayed, i.e. directories or files are
2455 specified."
2456 (if (assoc vhdl-project vhdl-project-alist)
2457 vhdl-project
2458 (when (and vhdl-project warning)
2459 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2460 nil))
2461
2462 (defun vhdl-resolve-env-variable (string)
2463 "Resolve environment variables in STRING."
2464 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2465 (setq string (concat (match-string 1 string)
2466 (getenv (match-string 2 string))
2467 (match-string 4 string))))
2468 string)
2469
2470 (defun vhdl-default-directory ()
2471 "Return the default directory of the current project or the directory of the
2472 current buffer if no project is defined."
2473 (if (vhdl-project-p)
2474 (expand-file-name (vhdl-resolve-env-variable
2475 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2476 default-directory))
2477
2478 (defmacro vhdl-prepare-search-1 (&rest body)
2479 "Enable case insensitive search and switch to syntax table that includes '_',
2480 then execute BODY, and finally restore the old environment. Used for
2481 consistent searching."
2482 `(let ((case-fold-search t)) ; case insensitive search
2483 ;; use extended syntax table
2484 (with-syntax-table vhdl-mode-ext-syntax-table
2485 ,@body)))
2486
2487 (defmacro vhdl-prepare-search-2 (&rest body)
2488 "Enable case insensitive search, switch to syntax table that includes '_',
2489 arrange to ignore `intangible' overlays, then execute BODY, and finally restore
2490 the old environment. Used for consistent searching."
2491 `(let ((case-fold-search t) ; case insensitive search
2492 (current-syntax-table (syntax-table))
2493 (inhibit-point-motion-hooks t))
2494 ;; use extended syntax table
2495 (set-syntax-table vhdl-mode-ext-syntax-table)
2496 ;; execute BODY safely
2497 (unwind-protect
2498 (progn ,@body)
2499 ;; restore syntax table
2500 (set-syntax-table current-syntax-table))))
2501
2502 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2503 "Visit file FILE-NAME and execute BODY."
2504 `(if (null ,file-name)
2505 (progn ,@body)
2506 (unless (file-directory-p ,file-name)
2507 (let ((source-buffer (current-buffer))
2508 (visiting-buffer (find-buffer-visiting ,file-name))
2509 file-opened)
2510 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2511 (condition-case ()
2512 (progn (set-buffer (create-file-buffer ,file-name))
2513 (setq file-opened t)
2514 (vhdl-insert-file-contents ,file-name)
2515 ;; FIXME: This modifies a global syntax-table!
2516 (modify-syntax-entry ?\- ". 12" (syntax-table))
2517 (modify-syntax-entry ?\n ">" (syntax-table))
2518 (modify-syntax-entry ?\^M ">" (syntax-table))
2519 (modify-syntax-entry ?_ "w" (syntax-table))
2520 t)
2521 (error
2522 (if ,issue-error
2523 (progn
2524 (when file-opened (kill-buffer (current-buffer)))
2525 (set-buffer source-buffer)
2526 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2527 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2528 nil))))
2529 (condition-case info
2530 (progn ,@body)
2531 (error
2532 (if ,issue-error
2533 (progn
2534 (when file-opened (kill-buffer (current-buffer)))
2535 (set-buffer source-buffer)
2536 (error (cadr info)))
2537 (vhdl-warning (cadr info))))))
2538 (when file-opened (kill-buffer (current-buffer)))
2539 (set-buffer source-buffer)))))
2540
2541 (defun vhdl-insert-file-contents (filename)
2542 "Nicked from `insert-file-contents-literally', but allow coding system
2543 conversion."
2544 (let ((format-alist nil)
2545 (after-insert-file-functions nil)
2546 (jka-compr-compression-info-list nil))
2547 (insert-file-contents filename t)))
2548
2549 (defun vhdl-sort-alist (alist)
2550 "Sort ALIST."
2551 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2552
2553 (defun vhdl-get-subdirs (directory)
2554 "Recursively get subdirectories of DIRECTORY."
2555 (let ((dir-list (list (file-name-as-directory directory)))
2556 file-list)
2557 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2558 (while file-list
2559 (when (file-directory-p (car file-list))
2560 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2561 (setq file-list (cdr file-list)))
2562 dir-list))
2563
2564 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2565 "As `aput', but delete key-value pair if VALUE is nil."
2566 (if value
2567 (vhdl-aput alist-symbol key value)
2568 (vhdl-adelete alist-symbol key)))
2569
2570 (defun vhdl-delete (elt list)
2571 "Delete by side effect the first occurrence of ELT as a member of LIST."
2572 (push nil list)
2573 (let ((list1 list))
2574 (while (and (cdr list1) (not (equal elt (cadr list1))))
2575 (setq list1 (cdr list1)))
2576 (when list
2577 (setcdr list1 (cddr list1))))
2578 (cdr list))
2579
2580 (declare-function speedbar-refresh "speedbar" (&optional arg))
2581 (declare-function speedbar-do-function-pointer "speedbar" ())
2582
2583 (defun vhdl-speedbar-refresh (&optional key)
2584 "Refresh directory or project with name KEY."
2585 (when (and (boundp 'speedbar-frame)
2586 (frame-live-p speedbar-frame))
2587 (let ((pos (point))
2588 (last-frame (selected-frame)))
2589 (if (null key)
2590 (speedbar-refresh)
2591 (select-frame speedbar-frame)
2592 (when (save-excursion
2593 (goto-char (point-min))
2594 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2595 (goto-char (match-end 1))
2596 (speedbar-do-function-pointer)
2597 (backward-char 2)
2598 (speedbar-do-function-pointer)
2599 (message "Refreshing speedbar...done"))
2600 (select-frame last-frame)))))
2601
2602 (defun vhdl-show-messages ()
2603 "Get *Messages* buffer to show recent messages."
2604 (interactive)
2605 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2606
2607 (defun vhdl-use-direct-instantiation ()
2608 "Return whether direct instantiation is used."
2609 (or (eq vhdl-use-direct-instantiation 'always)
2610 (and (eq vhdl-use-direct-instantiation 'standard)
2611 (not (vhdl-standard-p '87)))))
2612
2613 (defun vhdl-max-marker (marker1 marker2)
2614 "Return larger marker."
2615 (if (> marker1 marker2) marker1 marker2))
2616
2617 (defun vhdl-goto-marker (marker)
2618 "Goto marker in appropriate buffer."
2619 (when (markerp marker)
2620 (set-buffer (marker-buffer marker)))
2621 (goto-char marker))
2622
2623 (defun vhdl-menu-split (list title)
2624 "Split menu LIST into several submenus, if number of
2625 elements > `vhdl-menu-max-size'."
2626 (if (> (length list) vhdl-menu-max-size)
2627 (let ((remain list)
2628 (result '())
2629 (sublist '())
2630 (menuno 1)
2631 (i 0))
2632 (while remain
2633 (push (car remain) sublist)
2634 (setq remain (cdr remain))
2635 (setq i (+ i 1))
2636 (if (= i vhdl-menu-max-size)
2637 (progn
2638 (push (cons (format "%s %s" title menuno)
2639 (nreverse sublist)) result)
2640 (setq i 0)
2641 (setq menuno (+ menuno 1))
2642 (setq sublist '()))))
2643 (and sublist
2644 (push (cons (format "%s %s" title menuno)
2645 (nreverse sublist)) result))
2646 (nreverse result))
2647 list))
2648
2649
2650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2651 ;;; Bindings
2652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2653
2654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2655 ;; Key bindings
2656
2657 (defvar vhdl-template-map nil
2658 "Keymap for VHDL templates.")
2659
2660 (defun vhdl-template-map-init ()
2661 "Initialize `vhdl-template-map'."
2662 (setq vhdl-template-map (make-sparse-keymap))
2663 ;; key bindings for VHDL templates
2664 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2665 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2666 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2667 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2668 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2669 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2670 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2671 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2672 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2673 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2674 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2675 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2676 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2677 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2678 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2679 (define-key vhdl-template-map "ct" 'vhdl-template-context)
2680 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2681 (define-key vhdl-template-map "el" 'vhdl-template-else)
2682 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2683 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2684 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2685 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2686 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2687 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2688 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2689 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2690 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2691 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2692 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2693 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2694 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2695 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2696 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2697 (define-key vhdl-template-map "li" 'vhdl-template-library)
2698 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2699 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2700 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2701 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2702 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2703 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2704 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2705 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2706 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2707 (define-key vhdl-template-map "po" 'vhdl-template-port)
2708 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2709 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2710 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2711 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2712 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2713 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2714 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2715 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2716 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2717 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2718 (define-key vhdl-template-map "us" 'vhdl-template-use)
2719 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2720 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2721 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2722 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2723 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2724 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2725 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2726 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2727 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2728 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2729 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2730 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2731 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2732 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2733 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2734 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2735 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2736 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2737 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2738 (when (vhdl-standard-p 'ams)
2739 (define-key vhdl-template-map "br" 'vhdl-template-break)
2740 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2741 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2742 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2743 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2744 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2745 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2746 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2747 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2748 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2749 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2750 )
2751 (when (vhdl-standard-p 'math)
2752 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2753 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2754 ))
2755
2756 ;; initialize template map for VHDL Mode
2757 (vhdl-template-map-init)
2758
2759 (defun vhdl-function-name (prefix string &optional postfix)
2760 "Generate a Lisp function name.
2761 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2762 STRING are replaced by `-' and substrings are converted to lower case."
2763 (let ((name prefix))
2764 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2765 (setq name
2766 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2767 (setq string (substring string (match-beginning 2))))
2768 (when postfix (setq name (concat name "-" postfix)))
2769 (intern name)))
2770
2771 (defvar vhdl-model-map nil
2772 "Keymap for VHDL models.")
2773
2774 (defun vhdl-model-map-init ()
2775 "Initialize `vhdl-model-map'."
2776 (setq vhdl-model-map (make-sparse-keymap))
2777 ;; key bindings for VHDL models
2778 (let ((model-alist vhdl-model-alist) model)
2779 (while model-alist
2780 (setq model (car model-alist))
2781 (define-key vhdl-model-map (nth 2 model)
2782 (vhdl-function-name "vhdl-model" (nth 0 model)))
2783 (setq model-alist (cdr model-alist)))))
2784
2785 ;; initialize user model map for VHDL Mode
2786 (vhdl-model-map-init)
2787
2788 (defvar vhdl-mode-map nil
2789 "Keymap for VHDL Mode.")
2790
2791 (defun vhdl-mode-map-init ()
2792 "Initialize `vhdl-mode-map'."
2793 (setq vhdl-mode-map (make-sparse-keymap))
2794 ;; template key bindings
2795 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2796 ;; model key bindings
2797 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2798 ;; standard key bindings
2799 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2800 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2801 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2802 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2803 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2804 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2805 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2806 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2807 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2808 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2809 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2810 ;; mode specific key bindings
2811 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2812 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2813 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2814 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2815 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2816 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2817 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2818 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2819 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2820 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2821 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2822 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2823 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2824 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2825 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2826 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2827 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2828 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2829 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2830 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2831 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2832 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2833 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2834 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2835 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2836 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2837 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2838 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2839 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2840 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2841 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2842 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2843 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2844 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2845 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2846 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2847 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2848 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2849 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2850 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2851 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2852 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2853 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2854 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2855 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2856 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2857 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2858 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2859 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2860 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2861 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2862 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2863 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2864 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2865 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2866 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2867 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2868 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2869 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2870 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2871 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2872 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2873 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2874 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2875 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2876 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2877 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2878 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2879 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2880 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2881 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2882 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2883 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2884 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2885 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2886 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2887 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2888 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2889 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2890 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2891 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2892 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2893 ;; insert commands bindings
2894 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2895 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2896 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2897 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2898 ;; electric key bindings
2899 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2900 (when vhdl-intelligent-tab
2901 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2902 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2903 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2904 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2905 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2906 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2907 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2908 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2909 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2910 (when (vhdl-standard-p 'ams)
2911 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2912
2913 ;; initialize mode map for VHDL Mode
2914 (vhdl-mode-map-init)
2915
2916 ;; define special minibuffer keymap for enabling word completion in minibuffer
2917 ;; (useful in template generator prompts)
2918 (defvar vhdl-minibuffer-local-map
2919 (let ((map (make-sparse-keymap)))
2920 (set-keymap-parent map minibuffer-local-map)
2921 (when vhdl-word-completion-in-minibuffer
2922 (define-key map "\t" 'vhdl-minibuffer-tab))
2923 map)
2924 "Keymap for minibuffer used in VHDL Mode.")
2925
2926 ;; set up electric character functions to work with
2927 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2928 (mapc
2929 (function
2930 (lambda (sym)
2931 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2932 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2933 '(vhdl-electric-space
2934 vhdl-electric-tab
2935 vhdl-electric-return
2936 vhdl-electric-dash
2937 vhdl-electric-open-bracket
2938 vhdl-electric-close-bracket
2939 vhdl-electric-quote
2940 vhdl-electric-semicolon
2941 vhdl-electric-comma
2942 vhdl-electric-period
2943 vhdl-electric-equal))
2944
2945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2946 ;; Syntax table
2947
2948 (defvar vhdl-mode-syntax-table
2949 (let ((st (make-syntax-table)))
2950 ;; define punctuation
2951 (modify-syntax-entry ?\# "." st)
2952 (modify-syntax-entry ?\$ "." st)
2953 (modify-syntax-entry ?\% "." st)
2954 (modify-syntax-entry ?\& "." st)
2955 (modify-syntax-entry ?\' "." st)
2956 (modify-syntax-entry ?\* "." st)
2957 (modify-syntax-entry ?\+ "." st)
2958 (modify-syntax-entry ?\. "." st)
2959 ;;; (modify-syntax-entry ?\/ "." st)
2960 (modify-syntax-entry ?\: "." st)
2961 (modify-syntax-entry ?\; "." st)
2962 (modify-syntax-entry ?\< "." st)
2963 (modify-syntax-entry ?\= "." st)
2964 (modify-syntax-entry ?\> "." st)
2965 (modify-syntax-entry ?\\ "." st)
2966 (modify-syntax-entry ?\| "." st)
2967 ;; define string
2968 (modify-syntax-entry ?\" "\"" st)
2969 ;; define underscore
2970 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2971 ;; single-line comments
2972 (modify-syntax-entry ?\- ". 12b" st)
2973 ;; multi-line comments
2974 (modify-syntax-entry ?\/ ". 14b" st)
2975 (modify-syntax-entry ?* ". 23" st)
2976 (modify-syntax-entry ?\n "> b" st)
2977 (modify-syntax-entry ?\^M "> b" st)
2978 ;; define parentheses to match
2979 (modify-syntax-entry ?\( "()" st)
2980 (modify-syntax-entry ?\) ")(" st)
2981 (modify-syntax-entry ?\[ "(]" st)
2982 (modify-syntax-entry ?\] ")[" st)
2983 (modify-syntax-entry ?\{ "(}" st)
2984 (modify-syntax-entry ?\} "){" st)
2985 st)
2986 "Syntax table used in `vhdl-mode' buffers.")
2987
2988 (defvar vhdl-mode-ext-syntax-table
2989 ;; Extended syntax table including '_' (for simpler search regexps).
2990 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
2991 (modify-syntax-entry ?_ "w" st)
2992 st)
2993 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2994
2995 (defvar vhdl-syntactic-context nil
2996 "Buffer local variable containing syntactic analysis list.")
2997 (make-variable-buffer-local 'vhdl-syntactic-context)
2998
2999 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3000 ;; Abbrev hook bindings
3001
3002 (defvar vhdl-mode-abbrev-table nil
3003 "Abbrev table to use in `vhdl-mode' buffers.")
3004
3005 (defun vhdl-mode-abbrev-table-init ()
3006 "Initialize `vhdl-mode-abbrev-table'."
3007 (define-abbrev-table 'vhdl-mode-abbrev-table
3008 (append
3009 (when (memq 'vhdl vhdl-electric-keywords)
3010 ;; VHDL'02 keywords
3011 (mapcar (if (featurep 'xemacs)
3012 (lambda (x) (list (car x) "" (cdr x) 0))
3013 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3014 '(
3015 ("--" . vhdl-template-display-comment-hook)
3016 ("abs" . vhdl-template-default-hook)
3017 ("access" . vhdl-template-default-hook)
3018 ("after" . vhdl-template-default-hook)
3019 ("alias" . vhdl-template-alias-hook)
3020 ("all" . vhdl-template-default-hook)
3021 ("and" . vhdl-template-default-hook)
3022 ("arch" . vhdl-template-architecture-hook)
3023 ("architecture" . vhdl-template-architecture-hook)
3024 ("array" . vhdl-template-default-hook)
3025 ("assert" . vhdl-template-assert-hook)
3026 ("attr" . vhdl-template-attribute-hook)
3027 ("attribute" . vhdl-template-attribute-hook)
3028 ("begin" . vhdl-template-default-indent-hook)
3029 ("block" . vhdl-template-block-hook)
3030 ("body" . vhdl-template-default-hook)
3031 ("buffer" . vhdl-template-default-hook)
3032 ("bus" . vhdl-template-default-hook)
3033 ("case" . vhdl-template-case-hook)
3034 ("comp" . vhdl-template-component-hook)
3035 ("component" . vhdl-template-component-hook)
3036 ("cond" . vhdl-template-conditional-signal-asst-hook)
3037 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3038 ("conf" . vhdl-template-configuration-hook)
3039 ("configuration" . vhdl-template-configuration-hook)
3040 ("cons" . vhdl-template-constant-hook)
3041 ("constant" . vhdl-template-constant-hook)
3042 ("context" . vhdl-template-context-hook)
3043 ("disconnect" . vhdl-template-disconnect-hook)
3044 ("downto" . vhdl-template-default-hook)
3045 ("else" . vhdl-template-else-hook)
3046 ("elseif" . vhdl-template-elsif-hook)
3047 ("elsif" . vhdl-template-elsif-hook)
3048 ("end" . vhdl-template-default-indent-hook)
3049 ("entity" . vhdl-template-entity-hook)
3050 ("exit" . vhdl-template-exit-hook)
3051 ("file" . vhdl-template-file-hook)
3052 ("for" . vhdl-template-for-hook)
3053 ("func" . vhdl-template-function-hook)
3054 ("function" . vhdl-template-function-hook)
3055 ("generic" . vhdl-template-generic-hook)
3056 ("group" . vhdl-template-group-hook)
3057 ("guarded" . vhdl-template-default-hook)
3058 ("if" . vhdl-template-if-hook)
3059 ("impure" . vhdl-template-default-hook)
3060 ("in" . vhdl-template-default-hook)
3061 ("inertial" . vhdl-template-default-hook)
3062 ("inout" . vhdl-template-default-hook)
3063 ("inst" . vhdl-template-instance-hook)
3064 ("instance" . vhdl-template-instance-hook)
3065 ("is" . vhdl-template-default-hook)
3066 ("label" . vhdl-template-default-hook)
3067 ("library" . vhdl-template-library-hook)
3068 ("linkage" . vhdl-template-default-hook)
3069 ("literal" . vhdl-template-default-hook)
3070 ("loop" . vhdl-template-bare-loop-hook)
3071 ("map" . vhdl-template-map-hook)
3072 ("mod" . vhdl-template-default-hook)
3073 ("nand" . vhdl-template-default-hook)
3074 ("new" . vhdl-template-default-hook)
3075 ("next" . vhdl-template-next-hook)
3076 ("nor" . vhdl-template-default-hook)
3077 ("not" . vhdl-template-default-hook)
3078 ("null" . vhdl-template-default-hook)
3079 ("of" . vhdl-template-default-hook)
3080 ("on" . vhdl-template-default-hook)
3081 ("open" . vhdl-template-default-hook)
3082 ("or" . vhdl-template-default-hook)
3083 ("others" . vhdl-template-others-hook)
3084 ("out" . vhdl-template-default-hook)
3085 ("pack" . vhdl-template-package-hook)
3086 ("package" . vhdl-template-package-hook)
3087 ("port" . vhdl-template-port-hook)
3088 ("postponed" . vhdl-template-default-hook)
3089 ("procedure" . vhdl-template-procedure-hook)
3090 ("process" . vhdl-template-process-hook)
3091 ("pure" . vhdl-template-default-hook)
3092 ("range" . vhdl-template-default-hook)
3093 ("record" . vhdl-template-default-hook)
3094 ("register" . vhdl-template-default-hook)
3095 ("reject" . vhdl-template-default-hook)
3096 ("rem" . vhdl-template-default-hook)
3097 ("report" . vhdl-template-report-hook)
3098 ("return" . vhdl-template-return-hook)
3099 ("rol" . vhdl-template-default-hook)
3100 ("ror" . vhdl-template-default-hook)
3101 ("select" . vhdl-template-selected-signal-asst-hook)
3102 ("severity" . vhdl-template-default-hook)
3103 ("shared" . vhdl-template-default-hook)
3104 ("sig" . vhdl-template-signal-hook)
3105 ("signal" . vhdl-template-signal-hook)
3106 ("sla" . vhdl-template-default-hook)
3107 ("sll" . vhdl-template-default-hook)
3108 ("sra" . vhdl-template-default-hook)
3109 ("srl" . vhdl-template-default-hook)
3110 ("subtype" . vhdl-template-subtype-hook)
3111 ("then" . vhdl-template-default-hook)
3112 ("to" . vhdl-template-default-hook)
3113 ("transport" . vhdl-template-default-hook)
3114 ("type" . vhdl-template-type-hook)
3115 ("unaffected" . vhdl-template-default-hook)
3116 ("units" . vhdl-template-default-hook)
3117 ("until" . vhdl-template-default-hook)
3118 ("use" . vhdl-template-use-hook)
3119 ("var" . vhdl-template-variable-hook)
3120 ("variable" . vhdl-template-variable-hook)
3121 ("wait" . vhdl-template-wait-hook)
3122 ("when" . vhdl-template-when-hook)
3123 ("while" . vhdl-template-while-loop-hook)
3124 ("with" . vhdl-template-with-hook)
3125 ("xnor" . vhdl-template-default-hook)
3126 ("xor" . vhdl-template-default-hook)
3127 )))
3128 ;; VHDL-AMS keywords
3129 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3130 (mapcar (if (featurep 'xemacs)
3131 (lambda (x) (list (car x) "" (cdr x) 0))
3132 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3133 '(
3134 ("across" . vhdl-template-default-hook)
3135 ("break" . vhdl-template-break-hook)
3136 ("limit" . vhdl-template-limit-hook)
3137 ("nature" . vhdl-template-nature-hook)
3138 ("noise" . vhdl-template-default-hook)
3139 ("procedural" . vhdl-template-procedural-hook)
3140 ("quantity" . vhdl-template-quantity-hook)
3141 ("reference" . vhdl-template-default-hook)
3142 ("spectrum" . vhdl-template-default-hook)
3143 ("subnature" . vhdl-template-subnature-hook)
3144 ("terminal" . vhdl-template-terminal-hook)
3145 ("through" . vhdl-template-default-hook)
3146 ("tolerance" . vhdl-template-default-hook)
3147 )))
3148 ;; user model keywords
3149 (when (memq 'user vhdl-electric-keywords)
3150 (let (abbrev-list keyword)
3151 (dolist (elem vhdl-model-alist)
3152 (setq keyword (nth 3 elem))
3153 (unless (equal keyword "")
3154 (push (list keyword ""
3155 (vhdl-function-name
3156 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3157 abbrev-list)))
3158 abbrev-list)))))
3159
3160 ;; initialize abbrev table for VHDL Mode
3161 (vhdl-mode-abbrev-table-init)
3162
3163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3164 ;; Template completion lists
3165
3166 (defvar vhdl-template-construct-alist nil
3167 "List of built-in construct templates.")
3168
3169 (defun vhdl-template-construct-alist-init ()
3170 "Initialize `vhdl-template-construct-alist'."
3171 (setq
3172 vhdl-template-construct-alist
3173 (append
3174 '(
3175 ("alias declaration" vhdl-template-alias)
3176 ("architecture body" vhdl-template-architecture)
3177 ("assertion" vhdl-template-assert)
3178 ("attribute declaration" vhdl-template-attribute-decl)
3179 ("attribute specification" vhdl-template-attribute-spec)
3180 ("block configuration" vhdl-template-block-configuration)
3181 ("block statement" vhdl-template-block)
3182 ("case statement" vhdl-template-case-is)
3183 ("component configuration" vhdl-template-component-conf)
3184 ("component declaration" vhdl-template-component-decl)
3185 ("component instantiation statement" vhdl-template-component-inst)
3186 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3187 ("configuration declaration" vhdl-template-configuration-decl)
3188 ("configuration specification" vhdl-template-configuration-spec)
3189 ("constant declaration" vhdl-template-constant)
3190 ("context declaration" vhdl-template-context)
3191 ("disconnection specification" vhdl-template-disconnect)
3192 ("entity declaration" vhdl-template-entity)
3193 ("exit statement" vhdl-template-exit)
3194 ("file declaration" vhdl-template-file)
3195 ("generate statement" vhdl-template-generate)
3196 ("generic clause" vhdl-template-generic)
3197 ("group declaration" vhdl-template-group-decl)
3198 ("group template declaration" vhdl-template-group-template)
3199 ("if statement" vhdl-template-if-then)
3200 ("library clause" vhdl-template-library)
3201 ("loop statement" vhdl-template-loop)
3202 ("next statement" vhdl-template-next)
3203 ("package declaration" vhdl-template-package-decl)
3204 ("package body" vhdl-template-package-body)
3205 ("port clause" vhdl-template-port)
3206 ("process statement" vhdl-template-process)
3207 ("report statement" vhdl-template-report)
3208 ("return statement" vhdl-template-return)
3209 ("selected signal assignment" vhdl-template-selected-signal-asst)
3210 ("signal declaration" vhdl-template-signal)
3211 ("subprogram declaration" vhdl-template-subprogram-decl)
3212 ("subprogram body" vhdl-template-subprogram-body)
3213 ("subtype declaration" vhdl-template-subtype)
3214 ("type declaration" vhdl-template-type)
3215 ("use clause" vhdl-template-use)
3216 ("variable declaration" vhdl-template-variable)
3217 ("wait statement" vhdl-template-wait)
3218 )
3219 (when (vhdl-standard-p 'ams)
3220 '(
3221 ("break statement" vhdl-template-break)
3222 ("nature declaration" vhdl-template-nature)
3223 ("quantity declaration" vhdl-template-quantity)
3224 ("simultaneous case statement" vhdl-template-case-use)
3225 ("simultaneous if statement" vhdl-template-if-use)
3226 ("simultaneous procedural statement" vhdl-template-procedural)
3227 ("step limit specification" vhdl-template-limit)
3228 ("subnature declaration" vhdl-template-subnature)
3229 ("terminal declaration" vhdl-template-terminal)
3230 )))))
3231
3232 ;; initialize for VHDL Mode
3233 (vhdl-template-construct-alist-init)
3234
3235 (defvar vhdl-template-package-alist nil
3236 "List of built-in package templates.")
3237
3238 (defun vhdl-template-package-alist-init ()
3239 "Initialize `vhdl-template-package-alist'."
3240 (setq
3241 vhdl-template-package-alist
3242 (append
3243 '(
3244 ("numeric_bit" vhdl-template-package-numeric-bit)
3245 ("numeric_std" vhdl-template-package-numeric-std)
3246 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3247 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3248 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3249 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3250 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3251 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3252 ("textio" vhdl-template-package-textio)
3253 )
3254 (when (vhdl-standard-p 'math)
3255 '(
3256 ("math_complex" vhdl-template-package-math-complex)
3257 ("math_real" vhdl-template-package-math-real)
3258 )))))
3259
3260 ;; initialize for VHDL Mode
3261 (vhdl-template-package-alist-init)
3262
3263 (defvar vhdl-template-directive-alist
3264 '(
3265 ("translate_on" vhdl-template-directive-translate-on)
3266 ("translate_off" vhdl-template-directive-translate-off)
3267 ("synthesis_on" vhdl-template-directive-synthesis-on)
3268 ("synthesis_off" vhdl-template-directive-synthesis-off)
3269 )
3270 "List of built-in directive templates.")
3271
3272
3273 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3274 ;;; Menus
3275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3276
3277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3278 ;; VHDL menu (using `easy-menu.el')
3279
3280 (defun vhdl-customize ()
3281 "Call the customize function with `vhdl' as argument."
3282 (interactive)
3283 (customize-browse 'vhdl))
3284
3285 (defun vhdl-create-mode-menu ()
3286 "Create VHDL Mode menu."
3287 `("VHDL"
3288 ,(append
3289 '("Project"
3290 ["None" (vhdl-set-project "")
3291 :style radio :selected (null vhdl-project)]
3292 "--")
3293 ;; add menu entries for defined projects
3294 (let ((project-alist vhdl-project-alist) menu-list name)
3295 (while project-alist
3296 (setq name (caar project-alist))
3297 (setq menu-list
3298 (cons `[,name (vhdl-set-project ,name)
3299 :style radio :selected (equal ,name vhdl-project)]
3300 menu-list))
3301 (setq project-alist (cdr project-alist)))
3302 (setq menu-list
3303 (if vhdl-project-sort
3304 (sort menu-list
3305 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3306 (nreverse menu-list)))
3307 (vhdl-menu-split menu-list "Project"))
3308 '("--" "--"
3309 ["Select Project..." vhdl-set-project t]
3310 ["Set As Default Project" vhdl-set-default-project t]
3311 "--"
3312 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3313 ["Import Project..." vhdl-import-project
3314 :keys "C-c C-p C-m" :active t]
3315 ["Export Project" vhdl-export-project vhdl-project]
3316 "--"
3317 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3318 "--"
3319 ("Compile"
3320 ["Compile Buffer" vhdl-compile t]
3321 ["Stop Compilation" kill-compilation t]
3322 "--"
3323 ["Make" vhdl-make t]
3324 ["Generate Makefile" vhdl-generate-makefile t]
3325 "--"
3326 ["Next Error" next-error t]
3327 ["Previous Error" previous-error t]
3328 ["First Error" first-error t]
3329 "--"
3330 ,(append
3331 '("Compiler")
3332 ;; add menu entries for defined compilers
3333 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3334 (while comp-alist
3335 (setq name (caar comp-alist))
3336 (setq menu-list
3337 (cons `[,name (setq vhdl-compiler ,name)
3338 :style radio :selected (equal ,name vhdl-compiler)]
3339 menu-list))
3340 (setq comp-alist (cdr comp-alist)))
3341 (setq menu-list (nreverse menu-list))
3342 (vhdl-menu-split menu-list "Compiler"))
3343 '("--" "--"
3344 ["Select Compiler..." vhdl-set-compiler t]
3345 "--"
3346 ["Customize Compiler..."
3347 (customize-option 'vhdl-compiler-alist) t])))
3348 "--"
3349 ,(append
3350 '("Template"
3351 ("VHDL Construct 1"
3352 ["Alias" vhdl-template-alias t]
3353 ["Architecture" vhdl-template-architecture t]
3354 ["Assert" vhdl-template-assert t]
3355 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3356 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3357 ["Block" vhdl-template-block t]
3358 ["Case" vhdl-template-case-is t]
3359 ["Component (Decl)" vhdl-template-component-decl t]
3360 ["(Component) Instance" vhdl-template-component-inst t]
3361 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3362 ["Configuration (Block)" vhdl-template-block-configuration t]
3363 ["Configuration (Comp)" vhdl-template-component-conf t]
3364 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3365 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3366 ["Constant" vhdl-template-constant t]
3367 ["Context" vhdl-template-context t]
3368 ["Disconnect" vhdl-template-disconnect t]
3369 ["Else" vhdl-template-else t]
3370 ["Elsif" vhdl-template-elsif t]
3371 ["Entity" vhdl-template-entity t]
3372 ["Exit" vhdl-template-exit t]
3373 ["File" vhdl-template-file t]
3374 ["For (Generate)" vhdl-template-for-generate t]
3375 ["For (Loop)" vhdl-template-for-loop t]
3376 ["Function (Body)" vhdl-template-function-body t]
3377 ["Function (Decl)" vhdl-template-function-decl t]
3378 ["Generic" vhdl-template-generic t]
3379 ["Group (Decl)" vhdl-template-group-decl t]
3380 ["Group (Template)" vhdl-template-group-template t])
3381 ("VHDL Construct 2"
3382 ["If (Generate)" vhdl-template-if-generate t]
3383 ["If (Then)" vhdl-template-if-then t]
3384 ["Library" vhdl-template-library t]
3385 ["Loop" vhdl-template-bare-loop t]
3386 ["Map" vhdl-template-map t]
3387 ["Next" vhdl-template-next t]
3388 ["Others (Aggregate)" vhdl-template-others t]
3389 ["Package (Decl)" vhdl-template-package-decl t]
3390 ["Package (Body)" vhdl-template-package-body t]
3391 ["Port" vhdl-template-port t]
3392 ["Procedure (Body)" vhdl-template-procedure-body t]
3393 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3394 ["Process (Comb)" vhdl-template-process-comb t]
3395 ["Process (Seq)" vhdl-template-process-seq t]
3396 ["Report" vhdl-template-report t]
3397 ["Return" vhdl-template-return t]
3398 ["Select" vhdl-template-selected-signal-asst t]
3399 ["Signal" vhdl-template-signal t]
3400 ["Subtype" vhdl-template-subtype t]
3401 ["Type" vhdl-template-type t]
3402 ["Use" vhdl-template-use t]
3403 ["Variable" vhdl-template-variable t]
3404 ["Wait" vhdl-template-wait t]
3405 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3406 ["When" vhdl-template-when t]
3407 ["While (Loop)" vhdl-template-while-loop t]
3408 ["With" vhdl-template-with t]))
3409 (when (vhdl-standard-p 'ams)
3410 '(("VHDL-AMS Construct"
3411 ["Break" vhdl-template-break t]
3412 ["Case (Use)" vhdl-template-case-use t]
3413 ["If (Use)" vhdl-template-if-use t]
3414 ["Limit" vhdl-template-limit t]
3415 ["Nature" vhdl-template-nature t]
3416 ["Procedural" vhdl-template-procedural t]
3417 ["Quantity (Free)" vhdl-template-quantity-free t]
3418 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3419 ["Quantity (Source)" vhdl-template-quantity-source t]
3420 ["Subnature" vhdl-template-subnature t]
3421 ["Terminal" vhdl-template-terminal t])))
3422 '(["Insert Construct..." vhdl-template-insert-construct
3423 :keys "C-c C-i C-t"]
3424 "--")
3425 (list
3426 (append
3427 '("Package")
3428 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3429 ["numeric_std" vhdl-template-package-numeric-std t]
3430 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3431 ["textio" vhdl-template-package-textio t]
3432 "--"
3433 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3434 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3435 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3436 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3437 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3438 "--")
3439 (when (vhdl-standard-p 'ams)
3440 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3441 ["material_constants" vhdl-template-package-material-constants t]
3442 ["energy_systems" vhdl-template-package-energy-systems t]
3443 ["electrical_systems" vhdl-template-package-electrical-systems t]
3444 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3445 ["radiant_systems" vhdl-template-package-radiant-systems t]
3446 ["thermal_systems" vhdl-template-package-thermal-systems t]
3447 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3448 "--"))
3449 (when (vhdl-standard-p 'math)
3450 '(["math_complex" vhdl-template-package-math-complex t]
3451 ["math_real" vhdl-template-package-math-real t]
3452 "--"))
3453 '(["Insert Package..." vhdl-template-insert-package
3454 :keys "C-c C-i C-p"])))
3455 '(("Directive"
3456 ["translate_on" vhdl-template-directive-translate-on t]
3457 ["translate_off" vhdl-template-directive-translate-off t]
3458 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3459 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3460 "--"
3461 ["Insert Directive..." vhdl-template-insert-directive
3462 :keys "C-c C-i C-d"])
3463 "--"
3464 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3465 ["Insert Footer" vhdl-template-footer t]
3466 ["Insert Date" vhdl-template-insert-date t]
3467 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3468 "--"
3469 ["Query Next Prompt" vhdl-template-search-prompt t]))
3470 ,(append
3471 '("Model")
3472 ;; add menu entries for defined models
3473 (let ((model-alist vhdl-model-alist) menu-list model)
3474 (while model-alist
3475 (setq model (car model-alist))
3476 (setq menu-list
3477 (cons
3478 (vector
3479 (nth 0 model)
3480 (vhdl-function-name "vhdl-model" (nth 0 model))
3481 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3482 menu-list))
3483 (setq model-alist (cdr model-alist)))
3484 (setq menu-list (nreverse menu-list))
3485 (vhdl-menu-split menu-list "Model"))
3486 '("--" "--"
3487 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3488 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3489 ("Port"
3490 ["Copy" vhdl-port-copy t]
3491 "--"
3492 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3493 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3494 ["Paste As Instance" vhdl-port-paste-instance
3495 :keys "C-c C-p C-i" :active vhdl-port-list]
3496 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3497 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3498 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3499 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3500 "--"
3501 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3502 "--"
3503 ["Flatten" vhdl-port-flatten
3504 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3505 ["Reverse Direction" vhdl-port-reverse-direction
3506 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3507 ("Compose"
3508 ["New Component" vhdl-compose-new-component t]
3509 ["Copy Component" vhdl-port-copy t]
3510 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3511 ["Wire Components" vhdl-compose-wire-components t]
3512 "--"
3513 ["Generate Configuration" vhdl-compose-configuration t]
3514 ["Generate Components Package" vhdl-compose-components-package t])
3515 ("Subprogram"
3516 ["Copy" vhdl-subprog-copy t]
3517 "--"
3518 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3519 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3520 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3521 "--"
3522 ["Flatten" vhdl-subprog-flatten
3523 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3524 "--"
3525 ("Comment"
3526 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3527 "--"
3528 ["Insert Inline Comment" vhdl-comment-append-inline t]
3529 ["Insert Horizontal Line" vhdl-comment-display-line t]
3530 ["Insert Display Comment" vhdl-comment-display t]
3531 "--"
3532 ["Fill Comment" fill-paragraph t]
3533 ["Fill Comment Region" fill-region (mark)]
3534 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3535 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3536 ("Line"
3537 ["Kill" vhdl-line-kill t]
3538 ["Copy" vhdl-line-copy t]
3539 ["Yank" vhdl-line-yank t]
3540 ["Expand" vhdl-line-expand t]
3541 "--"
3542 ["Transpose Next" vhdl-line-transpose-next t]
3543 ["Transpose Prev" vhdl-line-transpose-previous t]
3544 ["Open" vhdl-line-open t]
3545 ["Join" vhdl-delete-indentation t]
3546 "--"
3547 ["Goto" goto-line t]
3548 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3549 ("Move"
3550 ["Forward Statement" vhdl-end-of-statement t]
3551 ["Backward Statement" vhdl-beginning-of-statement t]
3552 ["Forward Expression" vhdl-forward-sexp t]
3553 ["Backward Expression" vhdl-backward-sexp t]
3554 ["Forward Same Indent" vhdl-forward-same-indent t]
3555 ["Backward Same Indent" vhdl-backward-same-indent t]
3556 ["Forward Function" vhdl-end-of-defun t]
3557 ["Backward Function" vhdl-beginning-of-defun t]
3558 ["Mark Function" vhdl-mark-defun t])
3559 "--"
3560 ("Indent"
3561 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3562 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3563 ["Region" vhdl-indent-region (mark)]
3564 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3565 ("Align"
3566 ["Group" vhdl-align-group t]
3567 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3568 ["List" vhdl-align-list t]
3569 ["Declarations" vhdl-align-declarations t]
3570 ["Region" vhdl-align-region (mark)]
3571 ["Buffer" vhdl-align-buffer t]
3572 "--"
3573 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3574 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3575 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3576 ("Fill"
3577 ["List" vhdl-fill-list t]
3578 ["Group" vhdl-fill-group t]
3579 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3580 ["Region" vhdl-fill-region (mark)])
3581 ("Beautify"
3582 ["Region" vhdl-beautify-region (mark)]
3583 ["Buffer" vhdl-beautify-buffer t])
3584 ("Fix"
3585 ["Generic/Port Clause" vhdl-fix-clause t]
3586 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3587 "--"
3588 ["Case Region" vhdl-fix-case-region (mark)]
3589 ["Case Buffer" vhdl-fix-case-buffer t]
3590 "--"
3591 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3592 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3593 "--"
3594 ["Statement Region" vhdl-fix-statement-region (mark)]
3595 ["Statement Buffer" vhdl-fix-statement-buffer t]
3596 "--"
3597 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3598 ("Update"
3599 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3600 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3601 "--"
3602 ["Fontify Buffer" vhdl-fontify-buffer t]
3603 ["Statistics Buffer" vhdl-statistics-buffer t]
3604 ["Show Messages" vhdl-show-messages t]
3605 ["Syntactic Info" vhdl-show-syntactic-information t]
3606 "--"
3607 ["Speedbar" vhdl-speedbar t]
3608 ["Hide/Show" vhdl-hs-minor-mode t]
3609 "--"
3610 ("Documentation"
3611 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3612 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3613 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3614 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3615 ["Version" vhdl-version t]
3616 ["Bug Report..." vhdl-submit-bug-report t]
3617 "--"
3618 ("Options"
3619 ("Mode"
3620 ["Electric Mode"
3621 (progn (customize-set-variable 'vhdl-electric-mode
3622 (not vhdl-electric-mode))
3623 (vhdl-mode-line-update))
3624 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3625 ["Stutter Mode"
3626 (progn (customize-set-variable 'vhdl-stutter-mode
3627 (not vhdl-stutter-mode))
3628 (vhdl-mode-line-update))
3629 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3630 ["Indent Tabs Mode"
3631 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3632 (not vhdl-indent-tabs-mode))
3633 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3634 :style toggle :selected vhdl-indent-tabs-mode]
3635 "--"
3636 ["Customize Group..." (customize-group 'vhdl-mode) t])
3637 ("Project"
3638 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3639 ,(append
3640 '("Selected Project at Startup"
3641 ["None" (progn (customize-set-variable 'vhdl-project nil)
3642 (vhdl-set-project ""))
3643 :style radio :selected (null vhdl-project)]
3644 "--")
3645 ;; add menu entries for defined projects
3646 (let ((project-alist vhdl-project-alist) menu-list name)
3647 (while project-alist
3648 (setq name (caar project-alist))
3649 (setq menu-list
3650 (cons `[,name (progn (customize-set-variable
3651 'vhdl-project ,name)
3652 (vhdl-set-project ,name))
3653 :style radio :selected (equal ,name vhdl-project)]
3654 menu-list))
3655 (setq project-alist (cdr project-alist)))
3656 (setq menu-list (nreverse menu-list))
3657 (vhdl-menu-split menu-list "Project")))
3658 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3659 ("Auto Load Setup File"
3660 ["At Startup"
3661 (customize-set-variable 'vhdl-project-auto-load
3662 (if (memq 'startup vhdl-project-auto-load)
3663 (delq 'startup vhdl-project-auto-load)
3664 (cons 'startup vhdl-project-auto-load)))
3665 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3666 ["Sort Projects"
3667 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3668 :style toggle :selected vhdl-project-sort]
3669 "--"
3670 ["Customize Group..." (customize-group 'vhdl-project) t])
3671 ("Compiler"
3672 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3673 ,(append
3674 '("Selected Compiler at Startup")
3675 ;; add menu entries for defined compilers
3676 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3677 (while comp-alist
3678 (setq name (caar comp-alist))
3679 (setq menu-list
3680 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3681 :style radio :selected (equal ,name vhdl-compiler)]
3682 menu-list))
3683 (setq comp-alist (cdr comp-alist)))
3684 (setq menu-list (nreverse menu-list))
3685 (vhdl-menu-split menu-list "Compiler")))
3686 ["Use Local Error Regexp"
3687 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3688 (not vhdl-compile-use-local-error-regexp))
3689 :style toggle :selected vhdl-compile-use-local-error-regexp]
3690 ["Makefile Default Targets..."
3691 (customize-option 'vhdl-makefile-default-targets) t]
3692 ["Makefile Generation Hook..."
3693 (customize-option 'vhdl-makefile-generation-hook) t]
3694 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3695 "--"
3696 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3697 ("Style"
3698 ("VHDL Standard"
3699 ["VHDL'87"
3700 (progn (customize-set-variable 'vhdl-standard
3701 (list '87 (cadr vhdl-standard)))
3702 (vhdl-activate-customizations))
3703 :style radio :selected (eq '87 (car vhdl-standard))]
3704 ["VHDL'93/02"
3705 (progn (customize-set-variable 'vhdl-standard
3706 (list '93 (cadr vhdl-standard)))
3707 (vhdl-activate-customizations))
3708 :style radio :selected (eq '93 (car vhdl-standard))]
3709 ["VHDL'08"
3710 (progn (customize-set-variable 'vhdl-standard
3711 (list '08 (cadr vhdl-standard)))
3712 (vhdl-activate-customizations))
3713 :style radio :selected (eq '08 (car vhdl-standard))]
3714 "--"
3715 ["VHDL-AMS"
3716 (progn (customize-set-variable
3717 'vhdl-standard (list (car vhdl-standard)
3718 (if (memq 'ams (cadr vhdl-standard))
3719 (delq 'ams (cadr vhdl-standard))
3720 (cons 'ams (cadr vhdl-standard)))))
3721 (vhdl-activate-customizations))
3722 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3723 ["Math Packages"
3724 (progn (customize-set-variable
3725 'vhdl-standard (list (car vhdl-standard)
3726 (if (memq 'math (cadr vhdl-standard))
3727 (delq 'math (cadr vhdl-standard))
3728 (cons 'math (cadr vhdl-standard)))))
3729 (vhdl-activate-customizations))
3730 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3731 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3732 ["Upper Case Keywords"
3733 (customize-set-variable 'vhdl-upper-case-keywords
3734 (not vhdl-upper-case-keywords))
3735 :style toggle :selected vhdl-upper-case-keywords]
3736 ["Upper Case Types"
3737 (customize-set-variable 'vhdl-upper-case-types
3738 (not vhdl-upper-case-types))
3739 :style toggle :selected vhdl-upper-case-types]
3740 ["Upper Case Attributes"
3741 (customize-set-variable 'vhdl-upper-case-attributes
3742 (not vhdl-upper-case-attributes))
3743 :style toggle :selected vhdl-upper-case-attributes]
3744 ["Upper Case Enumeration Values"
3745 (customize-set-variable 'vhdl-upper-case-enum-values
3746 (not vhdl-upper-case-enum-values))
3747 :style toggle :selected vhdl-upper-case-enum-values]
3748 ["Upper Case Constants"
3749 (customize-set-variable 'vhdl-upper-case-constants
3750 (not vhdl-upper-case-constants))
3751 :style toggle :selected vhdl-upper-case-constants]
3752 ("Use Direct Instantiation"
3753 ["Never"
3754 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3755 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3756 ["Standard"
3757 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3758 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3759 ["Always"
3760 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3761 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3762 ["Include Array Index and Record Field in Sensitivity List"
3763 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3764 (not vhdl-array-index-record-field-in-sensitivity-list))
3765 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3766 "--"
3767 ["Customize Group..." (customize-group 'vhdl-style) t])
3768 ("Naming"
3769 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3770 ["Architecture File Name..."
3771 (customize-option 'vhdl-architecture-file-name) t]
3772 ["Configuration File Name..."
3773 (customize-option 'vhdl-configuration-file-name) t]
3774 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3775 ("File Name Case"
3776 ["As Is"
3777 (customize-set-variable 'vhdl-file-name-case 'identity)
3778 :style radio :selected (eq 'identity vhdl-file-name-case)]
3779 ["Lower Case"
3780 (customize-set-variable 'vhdl-file-name-case 'downcase)
3781 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3782 ["Upper Case"
3783 (customize-set-variable 'vhdl-file-name-case 'upcase)
3784 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3785 ["Capitalize"
3786 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3787 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3788 "--"
3789 ["Customize Group..." (customize-group 'vhdl-naming) t])
3790 ("Template"
3791 ("Electric Keywords"
3792 ["VHDL Keywords"
3793 (customize-set-variable 'vhdl-electric-keywords
3794 (if (memq 'vhdl vhdl-electric-keywords)
3795 (delq 'vhdl vhdl-electric-keywords)
3796 (cons 'vhdl vhdl-electric-keywords)))
3797 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3798 ["User Model Keywords"
3799 (customize-set-variable 'vhdl-electric-keywords
3800 (if (memq 'user vhdl-electric-keywords)
3801 (delq 'user vhdl-electric-keywords)
3802 (cons 'user vhdl-electric-keywords)))
3803 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3804 ("Insert Optional Labels"
3805 ["None"
3806 (customize-set-variable 'vhdl-optional-labels 'none)
3807 :style radio :selected (eq 'none vhdl-optional-labels)]
3808 ["Processes Only"
3809 (customize-set-variable 'vhdl-optional-labels 'process)
3810 :style radio :selected (eq 'process vhdl-optional-labels)]
3811 ["All Constructs"
3812 (customize-set-variable 'vhdl-optional-labels 'all)
3813 :style radio :selected (eq 'all vhdl-optional-labels)])
3814 ("Insert Empty Lines"
3815 ["None"
3816 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3817 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3818 ["Design Units Only"
3819 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3820 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3821 ["All Constructs"
3822 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3823 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3824 ["Argument List Indent"
3825 (customize-set-variable 'vhdl-argument-list-indent
3826 (not vhdl-argument-list-indent))
3827 :style toggle :selected vhdl-argument-list-indent]
3828 ["Association List with Formals"
3829 (customize-set-variable 'vhdl-association-list-with-formals
3830 (not vhdl-association-list-with-formals))
3831 :style toggle :selected vhdl-association-list-with-formals]
3832 ["Conditions in Parenthesis"
3833 (customize-set-variable 'vhdl-conditions-in-parenthesis
3834 (not vhdl-conditions-in-parenthesis))
3835 :style toggle :selected vhdl-conditions-in-parenthesis]
3836 ["Sensitivity List uses 'all'"
3837 (customize-set-variable 'vhdl-sensitivity-list-all
3838 (not vhdl-sensitivity-list-all))
3839 :style toggle :selected vhdl-sensitivity-list-all]
3840 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3841 ["One String..." (customize-option 'vhdl-one-string) t]
3842 ("File Header"
3843 ["Header String..." (customize-option 'vhdl-file-header) t]
3844 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3845 ["Company Name..." (customize-option 'vhdl-company-name) t]
3846 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3847 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3848 ["Date Format..." (customize-option 'vhdl-date-format) t]
3849 ["Modify Date Prefix String..."
3850 (customize-option 'vhdl-modify-date-prefix-string) t]
3851 ["Modify Date on Saving"
3852 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3853 (not vhdl-modify-date-on-saving))
3854 (vhdl-activate-customizations))
3855 :style toggle :selected vhdl-modify-date-on-saving])
3856 ("Sequential Process"
3857 ("Kind of Reset"
3858 ["None"
3859 (customize-set-variable 'vhdl-reset-kind 'none)
3860 :style radio :selected (eq 'none vhdl-reset-kind)]
3861 ["Synchronous"
3862 (customize-set-variable 'vhdl-reset-kind 'sync)
3863 :style radio :selected (eq 'sync vhdl-reset-kind)]
3864 ["Asynchronous"
3865 (customize-set-variable 'vhdl-reset-kind 'async)
3866 :style radio :selected (eq 'async vhdl-reset-kind)]
3867 ["Query"
3868 (customize-set-variable 'vhdl-reset-kind 'query)
3869 :style radio :selected (eq 'query vhdl-reset-kind)])
3870 ["Reset is Active High"
3871 (customize-set-variable 'vhdl-reset-active-high
3872 (not vhdl-reset-active-high))
3873 :style toggle :selected vhdl-reset-active-high]
3874 ["Use Rising Clock Edge"
3875 (customize-set-variable 'vhdl-clock-rising-edge
3876 (not vhdl-clock-rising-edge))
3877 :style toggle :selected vhdl-clock-rising-edge]
3878 ("Clock Edge Condition"
3879 ["Standard"
3880 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3881 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3882 ["Function \"rising_edge\""
3883 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3884 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3885 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3886 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3887 "--"
3888 ["Customize Group..." (customize-group 'vhdl-template) t])
3889 ("Model"
3890 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3891 ("Port"
3892 ["Include Port Comments"
3893 (customize-set-variable 'vhdl-include-port-comments
3894 (not vhdl-include-port-comments))
3895 :style toggle :selected vhdl-include-port-comments]
3896 ["Include Direction Comments"
3897 (customize-set-variable 'vhdl-include-direction-comments
3898 (not vhdl-include-direction-comments))
3899 :style toggle :selected vhdl-include-direction-comments]
3900 ["Include Type Comments"
3901 (customize-set-variable 'vhdl-include-type-comments
3902 (not vhdl-include-type-comments))
3903 :style toggle :selected vhdl-include-type-comments]
3904 ("Include Group Comments"
3905 ["Never"
3906 (customize-set-variable 'vhdl-include-group-comments 'never)
3907 :style radio :selected (eq 'never vhdl-include-group-comments)]
3908 ["Declarations"
3909 (customize-set-variable 'vhdl-include-group-comments 'decl)
3910 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3911 ["Always"
3912 (customize-set-variable 'vhdl-include-group-comments 'always)
3913 :style radio :selected (eq 'always vhdl-include-group-comments)])
3914 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3915 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3916 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3917 ("Testbench"
3918 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3919 ["Architecture Name..."
3920 (customize-option 'vhdl-testbench-architecture-name) t]
3921 ["Configuration Name..."
3922 (customize-option 'vhdl-testbench-configuration-name) t]
3923 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3924 ["Include Header"
3925 (customize-set-variable 'vhdl-testbench-include-header
3926 (not vhdl-testbench-include-header))
3927 :style toggle :selected vhdl-testbench-include-header]
3928 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3929 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3930 ["Initialize Signals"
3931 (customize-set-variable 'vhdl-testbench-initialize-signals
3932 (not vhdl-testbench-initialize-signals))
3933 :style toggle :selected vhdl-testbench-initialize-signals]
3934 ["Include Library Clause"
3935 (customize-set-variable 'vhdl-testbench-include-library
3936 (not vhdl-testbench-include-library))
3937 :style toggle :selected vhdl-testbench-include-library]
3938 ["Include Configuration"
3939 (customize-set-variable 'vhdl-testbench-include-configuration
3940 (not vhdl-testbench-include-configuration))
3941 :style toggle :selected vhdl-testbench-include-configuration]
3942 ("Create Files"
3943 ["None"
3944 (customize-set-variable 'vhdl-testbench-create-files 'none)
3945 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3946 ["Single"
3947 (customize-set-variable 'vhdl-testbench-create-files 'single)
3948 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3949 ["Separate"
3950 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3951 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3952 ["Testbench Entity File Name..."
3953 (customize-option 'vhdl-testbench-entity-file-name) t]
3954 ["Testbench Architecture File Name..."
3955 (customize-option 'vhdl-testbench-architecture-file-name) t])
3956 "--"
3957 ["Customize Group..." (customize-group 'vhdl-port) t])
3958 ("Compose"
3959 ["Architecture Name..."
3960 (customize-option 'vhdl-compose-architecture-name) t]
3961 ["Configuration Name..."
3962 (customize-option 'vhdl-compose-configuration-name) t]
3963 ["Components Package Name..."
3964 (customize-option 'vhdl-components-package-name) t]
3965 ["Use Components Package"
3966 (customize-set-variable 'vhdl-use-components-package
3967 (not vhdl-use-components-package))
3968 :style toggle :selected vhdl-use-components-package]
3969 ["Include Header"
3970 (customize-set-variable 'vhdl-compose-include-header
3971 (not vhdl-compose-include-header))
3972 :style toggle :selected vhdl-compose-include-header]
3973 ("Create Entity/Architecture Files"
3974 ["None"
3975 (customize-set-variable 'vhdl-compose-create-files 'none)
3976 :style radio :selected (eq 'none vhdl-compose-create-files)]
3977 ["Single"
3978 (customize-set-variable 'vhdl-compose-create-files 'single)
3979 :style radio :selected (eq 'single vhdl-compose-create-files)]
3980 ["Separate"
3981 (customize-set-variable 'vhdl-compose-create-files 'separate)
3982 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3983 ["Create Configuration File"
3984 (customize-set-variable 'vhdl-compose-configuration-create-file
3985 (not vhdl-compose-configuration-create-file))
3986 :style toggle :selected vhdl-compose-configuration-create-file]
3987 ["Hierarchical Configuration"
3988 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3989 (not vhdl-compose-configuration-hierarchical))
3990 :style toggle :selected vhdl-compose-configuration-hierarchical]
3991 ["Use Subconfiguration"
3992 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3993 (not vhdl-compose-configuration-use-subconfiguration))
3994 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3995 "--"
3996 ["Customize Group..." (customize-group 'vhdl-compose) t])
3997 ("Comment"
3998 ["Self Insert Comments"
3999 (customize-set-variable 'vhdl-self-insert-comments
4000 (not vhdl-self-insert-comments))
4001 :style toggle :selected vhdl-self-insert-comments]
4002 ["Prompt for Comments"
4003 (customize-set-variable 'vhdl-prompt-for-comments
4004 (not vhdl-prompt-for-comments))
4005 :style toggle :selected vhdl-prompt-for-comments]
4006 ["Inline Comment Column..."
4007 (customize-option 'vhdl-inline-comment-column) t]
4008 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4009 "--"
4010 ["Customize Group..." (customize-group 'vhdl-comment) t])
4011 ("Beautify"
4012 ["Auto Align Templates"
4013 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4014 :style toggle :selected vhdl-auto-align]
4015 ["Align Line Groups"
4016 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4017 :style toggle :selected vhdl-align-groups]
4018 ["Group Separation String..."
4019 (customize-option 'vhdl-align-group-separate) t]
4020 ["Align Lines with Same Indent"
4021 (customize-set-variable 'vhdl-align-same-indent
4022 (not vhdl-align-same-indent))
4023 :style toggle :selected vhdl-align-same-indent]
4024 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4025 "--"
4026 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4027 ("Highlight"
4028 ["Highlighting On/Off..."
4029 (customize-option
4030 (if (fboundp 'global-font-lock-mode)
4031 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4032 ["Highlight Keywords"
4033 (progn (customize-set-variable 'vhdl-highlight-keywords
4034 (not vhdl-highlight-keywords))
4035 (vhdl-fontify-buffer))
4036 :style toggle :selected vhdl-highlight-keywords]
4037 ["Highlight Names"
4038 (progn (customize-set-variable 'vhdl-highlight-names
4039 (not vhdl-highlight-names))
4040 (vhdl-fontify-buffer))
4041 :style toggle :selected vhdl-highlight-names]
4042 ["Highlight Special Words"
4043 (progn (customize-set-variable 'vhdl-highlight-special-words
4044 (not vhdl-highlight-special-words))
4045 (vhdl-fontify-buffer))
4046 :style toggle :selected vhdl-highlight-special-words]
4047 ["Highlight Forbidden Words"
4048 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4049 (not vhdl-highlight-forbidden-words))
4050 (vhdl-fontify-buffer))
4051 :style toggle :selected vhdl-highlight-forbidden-words]
4052 ["Highlight Verilog Keywords"
4053 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4054 (not vhdl-highlight-verilog-keywords))
4055 (vhdl-fontify-buffer))
4056 :style toggle :selected vhdl-highlight-verilog-keywords]
4057 ["Highlight \"translate_off\""
4058 (progn (customize-set-variable 'vhdl-highlight-translate-off
4059 (not vhdl-highlight-translate-off))
4060 (vhdl-fontify-buffer))
4061 :style toggle :selected vhdl-highlight-translate-off]
4062 ["Case Sensitive Highlighting"
4063 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4064 (not vhdl-highlight-case-sensitive))
4065 (vhdl-fontify-buffer))
4066 :style toggle :selected vhdl-highlight-case-sensitive]
4067 ["Special Syntax Definition..."
4068 (customize-option 'vhdl-special-syntax-alist) t]
4069 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4070 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4071 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4072 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4073 "--"
4074 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4075 ("Speedbar"
4076 ["Auto Open at Startup"
4077 (customize-set-variable 'vhdl-speedbar-auto-open
4078 (not vhdl-speedbar-auto-open))
4079 :style toggle :selected vhdl-speedbar-auto-open]
4080 ("Default Displaying Mode"
4081 ["Files"
4082 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4083 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4084 ["Directory Hierarchy"
4085 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4086 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4087 ["Project Hierarchy"
4088 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4089 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4090 ["Indentation Offset..."
4091 (customize-option 'speedbar-indentation-width) t]
4092 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4093 ["Jump to Unit when Opening"
4094 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4095 (not vhdl-speedbar-jump-to-unit))
4096 :style toggle :selected vhdl-speedbar-jump-to-unit]
4097 ["Update Hierarchy on File Saving"
4098 (customize-set-variable 'vhdl-speedbar-update-on-saving
4099 (not vhdl-speedbar-update-on-saving))
4100 :style toggle :selected vhdl-speedbar-update-on-saving]
4101 ("Save in Cache File"
4102 ["Hierarchy Information"
4103 (customize-set-variable 'vhdl-speedbar-save-cache
4104 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4105 (delq 'hierarchy vhdl-speedbar-save-cache)
4106 (cons 'hierarchy vhdl-speedbar-save-cache)))
4107 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4108 ["Displaying Status"
4109 (customize-set-variable 'vhdl-speedbar-save-cache
4110 (if (memq 'display vhdl-speedbar-save-cache)
4111 (delq 'display vhdl-speedbar-save-cache)
4112 (cons 'display vhdl-speedbar-save-cache)))
4113 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4114 ["Cache File Name..."
4115 (customize-option 'vhdl-speedbar-cache-file-name) t]
4116 "--"
4117 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4118 ("Menu"
4119 ["Add Index Menu when Loading File"
4120 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4121 (vhdl-index-menu-init))
4122 :style toggle :selected vhdl-index-menu]
4123 ["Add Source File Menu when Loading File"
4124 (progn (customize-set-variable 'vhdl-source-file-menu
4125 (not vhdl-source-file-menu))
4126 (vhdl-add-source-files-menu))
4127 :style toggle :selected vhdl-source-file-menu]
4128 ["Add Hideshow Menu at Startup"
4129 (progn (customize-set-variable 'vhdl-hideshow-menu
4130 (not vhdl-hideshow-menu))
4131 (vhdl-activate-customizations))
4132 :style toggle :selected vhdl-hideshow-menu]
4133 ["Hide Everything Initially"
4134 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4135 :style toggle :selected vhdl-hide-all-init]
4136 "--"
4137 ["Customize Group..." (customize-group 'vhdl-menu) t])
4138 ("Print"
4139 ["In Two Column Format"
4140 (progn (customize-set-variable 'vhdl-print-two-column
4141 (not vhdl-print-two-column))
4142 (message "Activate new setting by saving options and restarting Emacs"))
4143 :style toggle :selected vhdl-print-two-column]
4144 ["Use Customized Faces"
4145 (progn (customize-set-variable 'vhdl-print-customize-faces
4146 (not vhdl-print-customize-faces))
4147 (message "Activate new setting by saving options and restarting Emacs"))
4148 :style toggle :selected vhdl-print-customize-faces]
4149 "--"
4150 ["Customize Group..." (customize-group 'vhdl-print) t])
4151 ("Miscellaneous"
4152 ["Use Intelligent Tab"
4153 (progn (customize-set-variable 'vhdl-intelligent-tab
4154 (not vhdl-intelligent-tab))
4155 (vhdl-activate-customizations))
4156 :style toggle :selected vhdl-intelligent-tab]
4157 ["Indent Syntax-Based"
4158 (customize-set-variable 'vhdl-indent-syntax-based
4159 (not vhdl-indent-syntax-based))
4160 :style toggle :selected vhdl-indent-syntax-based]
4161 ["Indent Comments Like Next Code Line"
4162 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4163 (not vhdl-indent-comment-like-next-code-line))
4164 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4165 ["Word Completion is Case Sensitive"
4166 (customize-set-variable 'vhdl-word-completion-case-sensitive
4167 (not vhdl-word-completion-case-sensitive))
4168 :style toggle :selected vhdl-word-completion-case-sensitive]
4169 ["Word Completion in Minibuffer"
4170 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4171 (not vhdl-word-completion-in-minibuffer))
4172 (message "Activate new setting by saving options and restarting Emacs"))
4173 :style toggle :selected vhdl-word-completion-in-minibuffer]
4174 ["Underscore is Part of Word"
4175 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4176 (not vhdl-underscore-is-part-of-word))
4177 (vhdl-activate-customizations))
4178 :style toggle :selected vhdl-underscore-is-part-of-word]
4179 "--"
4180 ["Customize Group..." (customize-group 'vhdl-misc) t])
4181 ["Related..." (customize-browse 'vhdl-related) t]
4182 "--"
4183 ["Save Options" customize-save-customized t]
4184 ["Activate Options" vhdl-activate-customizations t]
4185 ["Browse Options..." vhdl-customize t])))
4186
4187 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4188 "VHDL Mode menu.")
4189
4190 (defun vhdl-update-mode-menu ()
4191 "Update VHDL Mode menu."
4192 (interactive)
4193 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4194 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4195 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4196 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4197 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4198
4199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4200 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4201
4202 (defconst vhdl-imenu-generic-expression
4203 '(
4204 ("Subprogram"
4205 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4206 4)
4207 ("Instance"
4208 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4209 1)
4210 ("Component"
4211 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4212 2)
4213 ("Procedural"
4214 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4215 1)
4216 ("Process"
4217 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4218 1)
4219 ("Block"
4220 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4221 1)
4222 ("Package"
4223 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4224 3)
4225 ("Configuration"
4226 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4227 2)
4228 ("Architecture"
4229 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4230 2)
4231 ("Entity"
4232 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4233 2)
4234 ("Context"
4235 "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4236 2)
4237 )
4238 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4239
4240 (defun vhdl-index-menu-init ()
4241 "Initialize index menu."
4242 (set (make-local-variable 'imenu-case-fold-search) t)
4243 (set (make-local-variable 'imenu-generic-expression)
4244 vhdl-imenu-generic-expression)
4245 (when (and vhdl-index-menu (fboundp 'imenu))
4246 (imenu-add-to-menubar "Index")))
4247
4248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4249 ;; Source file menu (using `easy-menu.el')
4250
4251 (defvar vhdl-sources-menu nil)
4252
4253 (defun vhdl-directory-files (directory &optional full match)
4254 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4255 message."
4256 (if (not (file-directory-p directory))
4257 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4258 (let ((dir (directory-files directory full match)))
4259 (setq dir (delete "." dir))
4260 (setq dir (delete ".." dir))
4261 dir)))
4262
4263 (defun vhdl-get-source-files (&optional full directory)
4264 "Get list of VHDL source files in DIRECTORY or current directory."
4265 (let ((mode-alist auto-mode-alist)
4266 filename-regexp)
4267 ;; create regular expressions for matching file names
4268 (setq filename-regexp "\\`[^.].*\\(")
4269 (while mode-alist
4270 (when (eq (cdar mode-alist) 'vhdl-mode)
4271 (setq filename-regexp
4272 (concat filename-regexp (caar mode-alist) "\\|")))
4273 (setq mode-alist (cdr mode-alist)))
4274 (setq filename-regexp
4275 (concat (substring filename-regexp 0
4276 (string-match "\\\\|$" filename-regexp)) "\\)"))
4277 ;; find files
4278 (vhdl-directory-files
4279 (or directory default-directory) full filename-regexp)))
4280
4281 (defun vhdl-add-source-files-menu ()
4282 "Scan directory for all VHDL source files and generate menu.
4283 The directory of the current source file is scanned."
4284 (interactive)
4285 (message "Scanning directory for source files ...")
4286 (let ((newmap (current-local-map))
4287 (file-list (vhdl-get-source-files))
4288 menu-list found)
4289 ;; Create list for menu
4290 (setq found nil)
4291 (while file-list
4292 (setq found t)
4293 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4294 menu-list)
4295 (setq file-list (cdr file-list)))
4296 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4297 (when found (push "--" menu-list))
4298 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4299 (push "Sources" menu-list)
4300 ;; Create menu
4301 (easy-menu-add menu-list)
4302 (easy-menu-define vhdl-sources-menu newmap
4303 "VHDL source files menu" menu-list))
4304 (message ""))
4305
4306
4307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4308 ;;; Mode definition
4309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4310 ;; performs all buffer local initializations
4311
4312 ;;;###autoload
4313 (define-derived-mode vhdl-mode prog-mode
4314 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4315 (vhdl-electric-mode "e")
4316 (vhdl-stutter-mode "s"))
4317 "Major mode for editing VHDL code.
4318
4319 Usage:
4320 ------
4321
4322 TEMPLATE INSERTION (electrification):
4323 After typing a VHDL keyword and entering `SPC', you are prompted for
4324 arguments while a template is generated for that VHDL construct. Typing
4325 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4326 template generation. Optional arguments are indicated by square
4327 brackets and removed if the queried string is left empty. Prompts for
4328 mandatory arguments remain in the code if the queried string is left
4329 empty. They can be queried again by `C-c C-t C-q'. Enabled
4330 electrification is indicated by `/e' in the mode line.
4331
4332 Typing `M-SPC' after a keyword inserts a space without calling the
4333 template generator. Automatic template generation (i.e.
4334 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4335 setting option `vhdl-electric-mode' (see OPTIONS).
4336
4337 Template generators can be invoked from the VHDL menu, by key
4338 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4339 the keyword (i.e. first word of menu entry not in parenthesis) and
4340 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4341 conf, comp, cons, func, inst, pack, sig, var.
4342
4343 Template styles can be customized in customization group
4344 `vhdl-template' \(see OPTIONS).
4345
4346
4347 HEADER INSERTION:
4348 A file header can be inserted by `C-c C-t C-h'. A file footer
4349 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4350 See customization group `vhdl-header'.
4351
4352
4353 STUTTERING:
4354 Double striking of some keys inserts cumbersome VHDL syntax elements.
4355 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4356 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4357 the mode line. The stuttering keys and their effects are:
4358
4359 ;; --> \" : \" [ --> ( -- --> comment
4360 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4361 .. --> \" => \" ] --> ) --- --> horizontal line
4362 ,, --> \" <= \" ]] --> ] ---- --> display comment
4363 == --> \" == \" '' --> \\\"
4364
4365
4366 WORD COMPLETION:
4367 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4368 word in the buffer that starts alike, inserts it and adjusts case.
4369 Re-typing `TAB' toggles through alternative word completions. This also
4370 works in the minibuffer (i.e. in template generator prompts).
4371
4372 Typing `TAB' after `(' looks for and inserts complete parenthesized
4373 expressions (e.g. for array index ranges). All keywords as well as
4374 standard types and subprograms of VHDL have predefined abbreviations
4375 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4376 beginning with \"std\").
4377
4378 Typing `TAB' after a non-word character indents the line if at the
4379 beginning of a line (i.e. no preceding non-blank characters), and
4380 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4381 stop.
4382
4383
4384 COMMENTS:
4385 `--' puts a single comment.
4386 `---' draws a horizontal line for separating code segments.
4387 `----' inserts a display comment, i.e. two horizontal lines
4388 with a comment in between.
4389 `--CR' comments out code on that line. Re-hitting CR comments
4390 out following lines.
4391 `C-c C-c' comments out a region if not commented out,
4392 uncomments a region if already commented out. Option
4393 `comment-style' defines where the comment characters
4394 should be placed (beginning of line, indent, etc.).
4395
4396 You are prompted for comments after object definitions (i.e. signals,
4397 variables, constants, ports) and after subprogram and process
4398 specifications if option `vhdl-prompt-for-comments' is non-nil.
4399 Comments are automatically inserted as additional labels (e.g. after
4400 begin statements) and as help comments if `vhdl-self-insert-comments' is
4401 non-nil.
4402
4403 Inline comments (i.e. comments after a piece of code on the same line)
4404 are indented at least to `vhdl-inline-comment-column'. Comments go at
4405 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4406 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4407 in a comment automatically opens a new comment line. `M-q' re-fills
4408 multi-line comments.
4409
4410
4411 INDENTATION:
4412 `TAB' indents a line if at the beginning of the line. The amount of
4413 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4414 always indents the current line (is bound to `TAB' if option
4415 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4416 the entire region.
4417
4418 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4419 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4420 indented normally (nil) or relative to the opening parenthesis (non-nil)
4421 according to option `vhdl-argument-list-indent'.
4422
4423 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4424 tabs. `\\[tabify]' and `\\[untabify]' allow to convert spaces to tabs
4425 and vice versa.
4426
4427 Syntax-based indentation can be very slow in large files. Option
4428 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4429
4430 Option `vhdl-indent-comment-like-next-code-line' controls whether
4431 comment lines are indented like the preceding or like the following code
4432 line.
4433
4434
4435 ALIGNMENT:
4436 The alignment functions align operators, keywords, and inline comments
4437 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4438 separated by blank lines, `C-c C-a C-i' a block of lines with same
4439 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4440 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4441 C-a C-d' all lines within the declarative part of a design unit. `C-c
4442 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4443 for a group of lines, and `C-c C-a M-c' for a region.
4444
4445 If option `vhdl-align-groups' is non-nil, groups of code lines
4446 separated by special lines (see option `vhdl-align-group-separate') are
4447 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4448 blocks of lines with same indent are aligned separately. Some templates
4449 are automatically aligned after generation if option `vhdl-auto-align'
4450 is non-nil.
4451
4452 Alignment tries to align inline comments at
4453 `vhdl-inline-comment-column' and tries inline comment not to exceed
4454 `vhdl-end-comment-column'.
4455
4456 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4457 symbols are surrounded by one space, and multiple spaces are eliminated.
4458
4459
4460 CODE FILLING:
4461 Code filling allows you to condense code (e.g. sensitivity lists or port
4462 maps) by removing comments and newlines and re-wrapping so that all
4463 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4464 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4465 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4466 `C-c C-f M-f' an entire region.
4467
4468
4469 CODE BEAUTIFICATION:
4470 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4471 buffer respectively. This includes indentation, alignment, and case
4472 fixing. Code beautification can also be run non-interactively using the
4473 command:
4474
4475 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4476
4477
4478 PORT TRANSLATION:
4479 Generic and port clauses from entity or component declarations can be
4480 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4481 as component instantiations and corresponding internal constants and
4482 signals, as a generic map with constants as actual generics, and as
4483 internal signal initializations (menu).
4484
4485 To include formals in component instantiations, see option
4486 `vhdl-association-list-with-formals'. To include comments in pasting,
4487 see options `vhdl-include-...-comments'.
4488
4489 A clause with several generic/port names on the same line can be
4490 flattened (`C-c C-p C-f') so that only one name per line exists. The
4491 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4492 outputs and vice versa, which can be useful in testbenches. (This
4493 reversion is done on the internal data structure and is only reflected
4494 in subsequent paste operations.)
4495
4496 Names for actual ports, instances, testbenches, and
4497 design-under-test instances can be derived from existing names according
4498 to options `vhdl-...-name'. See customization group `vhdl-port'.
4499
4500
4501 SUBPROGRAM TRANSLATION:
4502 Similar functionality exists for copying/pasting the interface of
4503 subprograms (function/procedure). A subprogram interface can be copied
4504 and then pasted as a subprogram declaration, body or call (uses
4505 association list with formals).
4506
4507
4508 TESTBENCH GENERATION:
4509 A copied port can also be pasted as a testbench. The generated
4510 testbench includes an entity, an architecture, and an optional
4511 configuration. The architecture contains the component declaration and
4512 instantiation of the DUT as well as internal constant and signal
4513 declarations. Additional user-defined templates can be inserted. The
4514 names used for entity/architecture/configuration/DUT as well as the file
4515 structure to be generated can be customized. See customization group
4516 `vhdl-testbench'.
4517
4518
4519 KEY BINDINGS:
4520 Key bindings (`C-c ...') exist for most commands (see in menu).
4521
4522
4523 VHDL MENU:
4524 All commands can be found in the VHDL menu including their key bindings.
4525
4526
4527 FILE BROWSER:
4528 The speedbar allows browsing of directories and file contents. It can
4529 be accessed from the VHDL menu and is automatically opened if option
4530 `vhdl-speedbar-auto-open' is non-nil.
4531
4532 In speedbar, open files and directories with `mouse-2' on the name and
4533 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4534
4535
4536 DESIGN HIERARCHY BROWSER:
4537 The speedbar can also be used for browsing the hierarchy of design units
4538 contained in the source files of the current directory or the specified
4539 projects (see option `vhdl-project-alist').
4540
4541 The speedbar can be switched between file, directory hierarchy and
4542 project hierarchy browsing mode in the speedbar menu or by typing `f',
4543 `h' or `H' in speedbar.
4544
4545 In speedbar, open design units with `mouse-2' on the name and browse
4546 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4547 from entities and components (in packages). Individual design units and
4548 complete designs can directly be compiled (\"Make\" menu entry).
4549
4550 The hierarchy is automatically updated upon saving a modified source
4551 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4552 hierarchy is only updated for projects that have been opened once in the
4553 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4554 options in group `vhdl-speedbar').
4555
4556 Simple design consistency checks are done during scanning, such as
4557 multiple declarations of the same unit or missing primary units that are
4558 required by secondary units.
4559
4560
4561 STRUCTURAL COMPOSITION:
4562 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4563 for a new component. Subcomponents (i.e. component declaration and
4564 instantiation) can be automatically placed from a previously read port
4565 \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4566 all subcomponents can be automatically connected using internal signals
4567 and ports (`C-c C-m C-w') following these rules:
4568 - subcomponent actual ports with same name are considered to be
4569 connected by a signal (internal signal or port)
4570 - signals that are only inputs to subcomponents are considered as
4571 inputs to this component -> input port created
4572 - signals that are only outputs from subcomponents are considered as
4573 outputs from this component -> output port created
4574 - signals that are inputs to AND outputs from subcomponents are
4575 considered as internal connections -> internal signal created
4576
4577 Purpose: With appropriate naming conventions it is possible to
4578 create higher design levels with only a few mouse clicks or key
4579 strokes. A new design level can be created by simply generating a new
4580 component, placing the required subcomponents from the hierarchy
4581 browser, and wiring everything automatically.
4582
4583 Note: Automatic wiring only works reliably on templates of new
4584 components and component instantiations that were created by VHDL mode.
4585
4586 Component declarations can be placed in a components package (option
4587 `vhdl-use-components-package') which can be automatically generated for
4588 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4589 component instantiation is also supported (option
4590 `vhdl-use-direct-instantiation').
4591
4592 Configuration declarations can automatically be generated either from
4593 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4594 the speedbar menu (for the architecture under the cursor). The
4595 configurations can optionally be hierarchical (i.e. include all
4596 component levels of a hierarchical design, option
4597 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4598 (option `vhdl-compose-configuration-use-subconfiguration'). For
4599 subcomponents in hierarchical configurations, the most-recently-analyzed
4600 (mra) architecture is selected. If another architecture is desired, it
4601 can be marked as most-recently-analyzed (speedbar menu) before
4602 generating the configuration.
4603
4604 Note: Configurations of subcomponents (i.e. hierarchical configuration
4605 declarations) are currently not considered when displaying
4606 configurations in speedbar.
4607
4608 See the options group `vhdl-compose' for all relevant user options.
4609
4610
4611 SOURCE FILE COMPILATION:
4612 The syntax of the current buffer can be analyzed by calling a VHDL
4613 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4614 option `vhdl-compiler'. The available compilers are listed in option
4615 `vhdl-compiler-alist' including all required compilation command,
4616 command options, compilation directory, and error message syntax
4617 information. New compilers can be added.
4618
4619 All the source files of an entire design can be compiled by the `make'
4620 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4621
4622
4623 MAKEFILE GENERATION:
4624 Makefiles can be generated automatically by an internal generation
4625 routine (`C-c M-k'). The library unit dependency information is
4626 obtained from the hierarchy browser. Makefile generation can be
4627 customized for each compiler in option `vhdl-compiler-alist'.
4628
4629 Makefile generation can also be run non-interactively using the
4630 command:
4631
4632 emacs -batch -l ~/.emacs -l vhdl-mode
4633 [-compiler compilername] [-project projectname]
4634 -f vhdl-generate-makefile
4635
4636 The Makefile's default target \"all\" compiles the entire design, the
4637 target \"clean\" removes it and the target \"library\" creates the
4638 library directory if not existent. These target names can be customized
4639 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4640 target for each primary library unit which allows selective compilation
4641 of this unit, its secondary units and its subhierarchy (example:
4642 compilation of a design specified by a configuration). User specific
4643 parts can be inserted into a Makefile with option
4644 `vhdl-makefile-generation-hook'.
4645
4646 Limitations:
4647 - Only library units and dependencies within the current library are
4648 considered. Makefiles for designs that span multiple libraries are
4649 not (yet) supported.
4650 - Only one-level configurations are supported (also hierarchical),
4651 but configurations that go down several levels are not.
4652 - The \"others\" keyword in configurations is not supported.
4653
4654
4655 PROJECTS:
4656 Projects can be defined in option `vhdl-project-alist' and a current
4657 project be selected using option `vhdl-project' (permanently) or from
4658 the menu or speedbar (temporarily). For each project, title and
4659 description strings (for the file headers), source files/directories
4660 (for the hierarchy browser and Makefile generation), library name, and
4661 compiler-dependent options, exceptions and compilation directory can be
4662 specified. Compilation settings overwrite the settings of option
4663 `vhdl-compiler-alist'.
4664
4665 Project setups can be exported (i.e. written to a file) and imported.
4666 Imported setups are not automatically saved in `vhdl-project-alist' but
4667 can be saved afterwards in its customization buffer. When starting
4668 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4669 vhdl-mode\") in a directory with an existing project setup file, it is
4670 automatically loaded and its project activated if option
4671 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4672 files can be specified in option `vhdl-project-file-name'. Multiple
4673 project setups can be automatically loaded from global directories.
4674 This is an alternative to specifying project setups with option
4675 `vhdl-project-alist'.
4676
4677
4678 SPECIAL MENUES:
4679 As an alternative to the speedbar, an index menu can be added (set
4680 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4681 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4682 file) for browsing the file contents (is not populated if buffer is
4683 larger than 256000). Also, a source file menu can be
4684 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4685 current directory for VHDL source files.
4686
4687
4688 VHDL STANDARDS:
4689 The VHDL standards to be used are specified in option `vhdl-standard'.
4690 Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
4691
4692
4693 KEYWORD CASE:
4694 Lower and upper case for keywords and standardized types, attributes,
4695 and enumeration values is supported. If the option
4696 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4697 lower case and are converted into upper case automatically (not for
4698 types, attributes, and enumeration values). The case of keywords,
4699 types, attributes,and enumeration values can be fixed for an entire
4700 region (menu) or buffer (`C-c C-x C-c') according to the options
4701 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4702
4703
4704 HIGHLIGHTING (fontification):
4705 Keywords and standardized types, attributes, enumeration values, and
4706 function names (controlled by option `vhdl-highlight-keywords'), as well
4707 as comments, strings, and template prompts are highlighted using
4708 different colors. Unit, subprogram, signal, variable, constant,
4709 parameter and generic/port names in declarations as well as labels are
4710 highlighted if option `vhdl-highlight-names' is non-nil.
4711
4712 Additional reserved words or words with a forbidden syntax (e.g. words
4713 that should be avoided) can be specified in option
4714 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4715 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4716 keywords are highlighted as forbidden words if option
4717 `vhdl-highlight-verilog-keywords' is non-nil.
4718
4719 Words with special syntax can be highlighted by specifying their
4720 syntax and color in option `vhdl-special-syntax-alist' and by setting
4721 option `vhdl-highlight-special-words' to non-nil. This allows you to
4722 establish some naming conventions (e.g. to distinguish different kinds
4723 of signals or other objects by using name suffices) and to support them
4724 visually.
4725
4726 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4727 to support case-sensitive highlighting. However, keywords are then only
4728 highlighted if written in lower case.
4729
4730 Code between \"translate_off\" and \"translate_on\" pragmas is
4731 highlighted using a different background color if option
4732 `vhdl-highlight-translate-off' is non-nil.
4733
4734 For documentation and customization of the used colors see
4735 customization group `vhdl-highlight-faces' (`\\[customize-group]'). For
4736 highlighting of matching parenthesis, see customization group
4737 `paren-showing'. Automatic buffer highlighting is turned on/off by
4738 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4739
4740
4741 USER MODELS:
4742 VHDL models (templates) can be specified by the user and made accessible
4743 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4744 electrification. See option `vhdl-model-alist'.
4745
4746
4747 HIDE/SHOW:
4748 The code of blocks, processes, subprograms, component declarations and
4749 instantiations, generic/port clauses, and configuration declarations can
4750 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4751 the code (see customization group `vhdl-menu'). XEmacs: limited
4752 functionality due to old `hideshow.el' package.
4753
4754
4755 CODE UPDATING:
4756 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4757 current process, `C-c C-u M-s' of all processes in the current buffer.
4758 Limitations:
4759 - Only declared local signals (ports, signals declared in
4760 architecture and blocks) are automatically inserted.
4761 - Global signals declared in packages are not automatically inserted.
4762 Insert them once manually (will be kept afterwards).
4763 - Out parameters of procedures are considered to be read.
4764 Use option `vhdl-entity-file-name' to specify the entity file name
4765 \(used to obtain the port names).
4766 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4767 specify whether to include array indices and record fields in
4768 sensitivity lists.
4769
4770
4771 CODE FIXING:
4772 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4773 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4774
4775
4776 PRINTING:
4777 PostScript printing with different faces (an optimized set of faces is
4778 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4779 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4780 PostScript printing commands. Option `vhdl-print-two-column' defines
4781 appropriate default settings for nice landscape two-column printing.
4782 The paper format can be set by option `ps-paper-type'. Do not forget to
4783 switch `ps-print-color-p' to nil for printing on black-and-white
4784 printers.
4785
4786
4787 OPTIONS:
4788 User options allow customization of VHDL Mode. All options are
4789 accessible from the \"Options\" menu entry. Simple options (switches
4790 and choices) can directly be changed, while for complex options a
4791 customization buffer is opened. Changed options can be saved for future
4792 sessions using the \"Save Options\" menu entry.
4793
4794 Options and their detailed descriptions can also be accessed by using
4795 the \"Customize\" menu entry or the command `\\[customize-option]'
4796 (`\\[customize-group]' for groups). Some customizations only take effect
4797 after some action (read the NOTE in the option documentation).
4798 Customization can also be done globally (i.e. site-wide, read the
4799 INSTALL file).
4800
4801 Not all options are described in this documentation, so go and see
4802 what other useful user options there are (`\\[vhdl-customize]' or menu)!
4803
4804
4805 FILE EXTENSIONS:
4806 As default, files with extensions \".vhd\" and \".vhdl\" are
4807 automatically recognized as VHDL source files. To add an extension
4808 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4809
4810 \(push '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist)
4811
4812
4813 HINTS:
4814 - To start Emacs with open VHDL hierarchy browser without having to load
4815 a VHDL file first, use the command:
4816
4817 emacs -l vhdl-mode -f speedbar-frame-mode
4818
4819 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4820
4821 - Some features only work on properly indented code.
4822
4823
4824 RELEASE NOTES:
4825 See also the release notes (menu) for added features in new releases.
4826
4827
4828 Maintenance:
4829 ------------
4830
4831 To submit a bug report, enter `\\[vhdl-submit-bug-report]' within VHDL Mode.
4832 Add a description of the problem and include a reproducible test case.
4833
4834 Questions and enhancement requests can be sent to <reto@gnu.org>.
4835
4836 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4837 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4838 releases. You are kindly invited to participate in beta testing. Subscribe
4839 to above mailing lists by sending an email to <reto@gnu.org>.
4840
4841 VHDL Mode is officially distributed at
4842 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4843 where the latest version can be found.
4844
4845
4846 Known problems:
4847 ---------------
4848
4849 - XEmacs: Incorrect start-up when automatically opening speedbar.
4850 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4851 - Indentation incorrect for new 'postponed' VHDL keyword.
4852 - Indentation incorrect for 'protected body' construct.
4853
4854
4855 The VHDL Mode Authors
4856 Reto Zimmermann and Rod Whitby
4857
4858 Key bindings:
4859 -------------
4860
4861 \\{vhdl-mode-map}"
4862 :abbrev-table vhdl-mode-abbrev-table
4863
4864 ;; set local variables
4865 (set (make-local-variable 'paragraph-start)
4866 "\\s-*\\(--+\\s-*$\\|$\\)")
4867 (set (make-local-variable 'paragraph-separate) paragraph-start)
4868 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4869 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4870 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4871 (set (make-local-variable 'comment-start) "--")
4872 (set (make-local-variable 'comment-end) "")
4873 (when vhdl-emacs-21
4874 (set (make-local-variable 'comment-padding) ""))
4875 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4876 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4877 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4878 (set (make-local-variable 'comment-multi-line) nil)
4879 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4880 (set (make-local-variable 'hippie-expand-verbose) nil)
4881
4882 ;; setup the comment indent variable in a Emacs version portable way
4883 ;; ignore any byte compiler warnings you might get here
4884 (when (boundp 'comment-indent-function)
4885 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4886
4887 ;; initialize font locking
4888 (set (make-local-variable 'font-lock-defaults)
4889 (list
4890 '(nil vhdl-font-lock-keywords) nil
4891 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4892 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4893 (set (make-local-variable 'syntax-propertize-function)
4894 (syntax-propertize-rules
4895 ;; Mark single quotes as having string quote syntax in
4896 ;; 'c' instances.
4897 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4898 (set (make-local-variable 'font-lock-syntactic-keywords)
4899 vhdl-font-lock-syntactic-keywords))
4900 (unless vhdl-emacs-21
4901 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4902 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4903 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4904 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4905
4906 ;; variables for source file compilation
4907 (when vhdl-compile-use-local-error-regexp
4908 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4909 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4910
4911 ;; add index menu
4912 (vhdl-index-menu-init)
4913 ;; add source file menu
4914 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4915 ;; add VHDL menu
4916 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4917 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4918 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4919 ;; initialize hideshow and add menu
4920 (vhdl-hideshow-init)
4921 (run-hooks 'menu-bar-update-hook)
4922
4923 ;; miscellaneous
4924 (vhdl-ps-print-init)
4925 (vhdl-write-file-hooks-init)
4926 (message "VHDL Mode %s.%s" vhdl-version
4927 (if noninteractive "" " See menu for documentation and release notes.")))
4928
4929 (defun vhdl-activate-customizations ()
4930 "Activate all customizations on local variables."
4931 (interactive)
4932 (vhdl-mode-map-init)
4933 (use-local-map vhdl-mode-map)
4934 (set-syntax-table vhdl-mode-syntax-table)
4935 (setq comment-column vhdl-inline-comment-column)
4936 (setq end-comment-column vhdl-end-comment-column)
4937 (vhdl-write-file-hooks-init)
4938 (vhdl-update-mode-menu)
4939 (vhdl-hideshow-init)
4940 (run-hooks 'menu-bar-update-hook))
4941
4942 (defun vhdl-write-file-hooks-init ()
4943 "Add/remove hooks when buffer is saved."
4944 (if vhdl-modify-date-on-saving
4945 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4946 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4947 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4948 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4949
4950 (defun vhdl-process-command-line-option (option)
4951 "Process command line options for VHDL Mode."
4952 (cond
4953 ;; set compiler
4954 ((equal option "-compiler")
4955 (vhdl-set-compiler (car command-line-args-left))
4956 (setq command-line-args-left (cdr command-line-args-left)))
4957 ;; set project
4958 ((equal option "-project")
4959 (vhdl-set-project (car command-line-args-left))
4960 (setq command-line-args-left (cdr command-line-args-left)))))
4961
4962 ;; make Emacs process VHDL Mode options
4963 (setq command-switch-alist
4964 (append command-switch-alist
4965 '(("-compiler" . vhdl-process-command-line-option)
4966 ("-project" . vhdl-process-command-line-option))))
4967
4968
4969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4970 ;;; Keywords and standardized words
4971 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4972
4973 (defconst vhdl-02-keywords
4974 '(
4975 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4976 "assert" "attribute"
4977 "begin" "block" "body" "buffer" "bus"
4978 "case" "component" "configuration" "constant"
4979 "disconnect" "downto"
4980 "else" "elsif" "end" "entity" "exit"
4981 "file" "for" "function"
4982 "generate" "generic" "group" "guarded"
4983 "if" "impure" "in" "inertial" "inout" "is"
4984 "label" "library" "linkage" "literal" "loop"
4985 "map" "mod"
4986 "nand" "new" "next" "nor" "not" "null"
4987 "of" "on" "open" "or" "others" "out"
4988 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4989 "range" "record" "register" "reject" "rem" "report" "return"
4990 "rol" "ror"
4991 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4992 "then" "to" "transport" "type"
4993 "unaffected" "units" "until" "use"
4994 "variable"
4995 "wait" "when" "while" "with"
4996 "xnor" "xor"
4997 )
4998 "List of VHDL'02 keywords.")
4999
5000 (defconst vhdl-08-keywords
5001 '(
5002 "context" "force" "property" "release" "sequence"
5003 )
5004 "List of VHDL'08 keywords.")
5005
5006 (defconst vhdl-ams-keywords
5007 '(
5008 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
5009 "reference" "spectrum" "subnature" "terminal" "through"
5010 "tolerance"
5011 )
5012 "List of VHDL-AMS keywords.")
5013
5014 (defconst vhdl-verilog-keywords
5015 '(
5016 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5017 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5018 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5019 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5020 "endprimitive" "endspecify" "endtable" "endtask" "event"
5021 "for" "force" "forever" "fork" "function"
5022 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5023 "macromodule" "makefile" "medium" "module"
5024 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5025 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5026 "pullup"
5027 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5028 "rtranif0" "rtranif1"
5029 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5030 "strong1" "supply" "supply0" "supply1"
5031 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5032 "triand" "trior" "trireg"
5033 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5034 )
5035 "List of Verilog keywords as candidate for additional reserved words.")
5036
5037 (defconst vhdl-02-types
5038 '(
5039 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5040 "real" "time" "natural" "positive" "string" "line" "text" "side"
5041 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5042 "std_logic" "std_logic_vector"
5043 "std_ulogic" "std_ulogic_vector"
5044 )
5045 "List of VHDL'02 standardized types.")
5046
5047 (defconst vhdl-08-types
5048 '(
5049 "boolean_vector" "integer_vector" "real_vector" "time_vector"
5050 )
5051 "List of VHDL'08 standardized types.")
5052
5053 (defconst vhdl-ams-types
5054 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5055 '(
5056 ;; package `standard'
5057 "domain_type" "real_vector"
5058 ;; package `energy_systems'
5059 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5060 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5061 "real_across_vector" "real_through_vector"
5062 ;; package `electrical_systems'
5063 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5064 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5065 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5066 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5067 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5068 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5069 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5070 "electric_flux_density_vector" "electric_field_strength_vector"
5071 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5072 "inductance_vector" "reluctance_vector" "ground"
5073 ;; package `mechanical_systems'
5074 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5075 "damping" "momentum" "angle" "torque" "angular_velocity"
5076 "angular_acceleration" "moment_inertia" "angular_momentum"
5077 "angular_stiffness" "angular_damping" "translational"
5078 "translational_vector" "translational_velocity"
5079 "translational_velocity_vector" "rotational" "rotational_vector"
5080 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5081 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5082 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5083 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5084 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5085 "angular_momentum_vector" "angular_stiffness_vector"
5086 "angular_damping_vector" "anchor" "translational_v_ref"
5087 "rotational_v_ref" "translational_v" "rotational_v"
5088 ;; package `radiant_systems'
5089 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5090 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5091 "illuminance_vector" "irradiance_vector"
5092 ;; package `thermal_systems'
5093 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5094 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5095 "heat_flow_vector" "thermal_capacitance_vector"
5096 "thermal_resistance_vector" "thermal_conductance_vector"
5097 ;; package `fluidic_systems'
5098 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5099 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5100 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5101 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5102 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5103 "density_vector" "viscosity_vector" "fresistance_vector"
5104 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5105 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5106 "cfinertance_vector"
5107 )
5108 "List of VHDL-AMS standardized types.")
5109
5110 (defconst vhdl-math-types
5111 '(
5112 "complex" "complex_polar" "positive_real" "principal_value"
5113 )
5114 "List of Math Packages standardized types.")
5115
5116 (defconst vhdl-02-attributes
5117 '(
5118 "base" "left" "right" "high" "low" "pos" "val" "succ"
5119 "pred" "leftof" "rightof" "range" "reverse_range"
5120 "length" "delayed" "stable" "quiet" "transaction"
5121 "event" "active" "last_event" "last_active" "last_value"
5122 "driving" "driving_value" "ascending" "value" "image"
5123 "simple_name" "instance_name" "path_name"
5124 "foreign"
5125 )
5126 "List of VHDL'02 standardized attributes.")
5127
5128 (defconst vhdl-08-attributes
5129 '(
5130 "instance_name" "path_name"
5131 )
5132 "List of VHDL'08 standardized attributes.")
5133
5134 (defconst vhdl-ams-attributes
5135 '(
5136 "across" "through"
5137 "reference" "contribution" "tolerance"
5138 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5139 "ramp" "slew"
5140 )
5141 "List of VHDL-AMS standardized attributes.")
5142
5143 (defconst vhdl-02-enum-values
5144 '(
5145 "true" "false"
5146 "note" "warning" "error" "failure"
5147 "read_mode" "write_mode" "append_mode"
5148 "open_ok" "status_error" "name_error" "mode_error"
5149 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5150 "right" "left"
5151 )
5152 "List of VHDL'02 standardized enumeration values.")
5153
5154 (defconst vhdl-ams-enum-values
5155 '(
5156 "quiescent_domain" "time_domain" "frequency_domain"
5157 ;; from `nature_pkg' package
5158 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5159 )
5160 "List of VHDL-AMS standardized enumeration values.")
5161
5162 (defconst vhdl-ams-constants
5163 ;; standard: IEEE Std 1076.1.1-2004
5164 '(
5165 ;; package `fundamental_constants'
5166 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5167 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5168 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5169 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5170 ;; package `material_constants'
5171 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5172 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5173 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5174 )
5175 "List of VHDL-AMS standardized constants.")
5176
5177 (defconst vhdl-math-constants
5178 ;; standard: IEEE Std 1076.2-1996
5179 '(
5180 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5181 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5182 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5183 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5184 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5185 "math_sqrt_pi"
5186 )
5187 "List of Math Packages standardized constants.")
5188
5189 (defconst vhdl-02-functions
5190 '(
5191 "now" "resolved" "rising_edge" "falling_edge"
5192 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5193 "endfile"
5194 "resize" "is_X" "std_match"
5195 "shift_left" "shift_right" "rotate_left" "rotate_right"
5196 "to_unsigned" "to_signed" "to_integer"
5197 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5198 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5199 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5200 "shl" "shr" "ext" "sxt"
5201 "deallocate"
5202 )
5203 "List of VHDL'02 standardized functions.")
5204
5205 (defconst vhdl-08-functions
5206 '(
5207 "finish" "flush" "justify" "maximum" "minimum"
5208 "resolution_limit" "rising_edge" "stop" "swrite"
5209 "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
5210 "to_octalstring" "to_ostring" "to_string"
5211 )
5212 "List of VHDL'08 standardized functions.")
5213
5214 (defconst vhdl-ams-functions
5215 '(
5216 ;; package `standard'
5217 "frequency"
5218 )
5219 "List of VHDL-AMS standardized functions.")
5220
5221 (defconst vhdl-math-functions
5222 ;; standard: IEEE Std 1076.2-1996
5223 '(
5224 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5225 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5226 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5227 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5228 "tan" "tanh" "trunc" "uniform"
5229 )
5230 "List of Math Packages standardized functions.")
5231
5232 (defconst vhdl-02-packages
5233 '(
5234 "std_logic_1164" "numeric_std" "numeric_bit"
5235 "standard" "textio"
5236 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5237 "std_logic_misc" "std_logic_textio"
5238 "ieee" "std" "work"
5239 )
5240 "List of VHDL'02 standardized packages and libraries.")
5241
5242 (defconst vhdl-08-packages
5243 '(
5244 "env" "numeric_std_signed" "numeric_std_unsigned"
5245 "ieee_bit_context" "ieee_std_context" ;; contexts
5246 )
5247 "List of VHDL'08 standardized packages and libraries.")
5248
5249 (defconst vhdl-ams-packages
5250 '(
5251 "fundamental_constants" "material_constants" "energy_systems"
5252 "electrical_systems" "mechanical_systems" "radiant_systems"
5253 "thermal_systems" "fluidic_systems"
5254 )
5255 "List of VHDL-AMS standardized packages and libraries.")
5256
5257 (defconst vhdl-math-packages
5258 '(
5259 "math_real" "math_complex"
5260 )
5261 "List of Math Packages standardized packages and libraries.")
5262
5263 (defconst vhdl-08-directives
5264 '(
5265 "author" "author_info" "begin" "begin_protected" "comment"
5266 "data_block" "data_keyname" "data_keyowner" "data_method"
5267 "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
5268 "digest_keyowner" "digest_method"
5269 "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
5270 "key_block" "key_keyname" "key_keyowner" "key_method"
5271 "runtime_license" "viewport"
5272 )
5273 "List of VHDL'08 standardized tool directives.")
5274
5275 (defvar vhdl-keywords nil
5276 "List of VHDL keywords.")
5277
5278 (defvar vhdl-types nil
5279 "List of VHDL standardized types.")
5280
5281 (defvar vhdl-attributes nil
5282 "List of VHDL standardized attributes.")
5283
5284 (defvar vhdl-enum-values nil
5285 "List of VHDL standardized enumeration values.")
5286
5287 (defvar vhdl-constants nil
5288 "List of VHDL standardized constants.")
5289
5290 (defvar vhdl-functions nil
5291 "List of VHDL standardized functions.")
5292
5293 (defvar vhdl-packages nil
5294 "List of VHDL standardized packages and libraries.")
5295
5296 (defvar vhdl-directives nil
5297 "List of VHDL standardized packages and libraries.")
5298
5299 (defvar vhdl-reserved-words nil
5300 "List of additional reserved words.")
5301
5302 (defvar vhdl-keywords-regexp nil
5303 "Regexp for VHDL keywords.")
5304
5305 (defvar vhdl-types-regexp nil
5306 "Regexp for VHDL standardized types.")
5307
5308 (defvar vhdl-attributes-regexp nil
5309 "Regexp for VHDL standardized attributes.")
5310
5311 (defvar vhdl-enum-values-regexp nil
5312 "Regexp for VHDL standardized enumeration values.")
5313
5314 (defvar vhdl-constants-regexp nil
5315 "Regexp for VHDL standardized constants.")
5316
5317 (defvar vhdl-functions-regexp nil
5318 "Regexp for VHDL standardized functions.")
5319
5320 (defvar vhdl-packages-regexp nil
5321 "Regexp for VHDL standardized packages and libraries.")
5322
5323 (defvar vhdl-reserved-words-regexp nil
5324 "Regexp for additional reserved words.")
5325
5326 (defvar vhdl-directive-keywords-regexp nil
5327 "Regexp for compiler directive keywords.")
5328
5329 (defun vhdl-upcase-list (condition list)
5330 "Upcase all elements in LIST based on CONDITION."
5331 (when condition
5332 (let ((tmp-list list))
5333 (while tmp-list
5334 (setcar tmp-list (upcase (car tmp-list)))
5335 (setq tmp-list (cdr tmp-list)))))
5336 list)
5337
5338 (defun vhdl-words-init ()
5339 "Initialize reserved words."
5340 (setq vhdl-keywords
5341 (vhdl-upcase-list
5342 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5343 (append vhdl-02-keywords
5344 (when (vhdl-standard-p '08) vhdl-08-keywords)
5345 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5346 (setq vhdl-types
5347 (vhdl-upcase-list
5348 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5349 (append vhdl-02-types
5350 (when (vhdl-standard-p '08) vhdl-08-types)
5351 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5352 (when (vhdl-standard-p 'math) vhdl-math-types))))
5353 (setq vhdl-attributes
5354 (vhdl-upcase-list
5355 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5356 (append vhdl-02-attributes
5357 (when (vhdl-standard-p '08) vhdl-08-attributes)
5358 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5359 (setq vhdl-enum-values
5360 (vhdl-upcase-list
5361 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5362 (append vhdl-02-enum-values
5363 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5364 (setq vhdl-constants
5365 (vhdl-upcase-list
5366 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5367 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5368 (when (vhdl-standard-p 'math) vhdl-math-constants)
5369 '(""))))
5370 (setq vhdl-functions
5371 (append vhdl-02-functions
5372 (when (vhdl-standard-p '08) vhdl-08-functions)
5373 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5374 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5375 (setq vhdl-packages
5376 (append vhdl-02-packages
5377 (when (vhdl-standard-p '08) vhdl-08-packages)
5378 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5379 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5380 (setq vhdl-directives
5381 (append (when (vhdl-standard-p '08) vhdl-08-directives)))
5382 (setq vhdl-reserved-words
5383 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5384 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5385 '("")))
5386 (setq vhdl-keywords-regexp
5387 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5388 (setq vhdl-types-regexp
5389 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5390 (setq vhdl-attributes-regexp
5391 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5392 (setq vhdl-enum-values-regexp
5393 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5394 (setq vhdl-constants-regexp
5395 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5396 (setq vhdl-functions-regexp
5397 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5398 (setq vhdl-packages-regexp
5399 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5400 (setq vhdl-reserved-words-regexp
5401 (concat "\\<\\("
5402 (unless (equal vhdl-forbidden-syntax "")
5403 (concat vhdl-forbidden-syntax "\\|"))
5404 (regexp-opt vhdl-reserved-words)
5405 "\\)\\>"))
5406 (setq vhdl-directive-keywords-regexp
5407 (concat "\\<\\(" (mapconcat 'regexp-quote
5408 vhdl-directive-keywords "\\|") "\\)\\>"))
5409 (vhdl-abbrev-list-init))
5410
5411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5412 ;; Words to expand
5413
5414 (defvar vhdl-abbrev-list nil
5415 "Predefined abbreviations for VHDL.")
5416
5417 (defun vhdl-abbrev-list-init ()
5418 (setq vhdl-abbrev-list
5419 (append
5420 (list vhdl-upper-case-keywords) vhdl-keywords
5421 (list vhdl-upper-case-types) vhdl-types
5422 (list vhdl-upper-case-attributes) vhdl-attributes
5423 (list vhdl-upper-case-enum-values) vhdl-enum-values
5424 (list vhdl-upper-case-constants) vhdl-constants
5425 (list nil) vhdl-functions
5426 (list nil) vhdl-packages
5427 (list nil) vhdl-directives)))
5428
5429 ;; initialize reserved words for VHDL Mode
5430 (vhdl-words-init)
5431
5432
5433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5434 ;;; Indentation
5435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5436
5437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5438 ;; Syntax analysis
5439
5440 ;; constant regular expressions for looking at various constructs
5441
5442 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5443 "Regexp describing a VHDL symbol.
5444 We cannot use just `word' syntax class since `_' cannot be in word
5445 class. Putting underscore in word class breaks forward word movement
5446 behavior that users are familiar with.")
5447
5448 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5449 "Regexp describing a case statement header key.")
5450
5451 (defconst vhdl-label-key
5452 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5453 "Regexp describing a VHDL label.")
5454
5455 ;; Macro definitions:
5456
5457 (defmacro vhdl-point (position)
5458 "Return the value of point at certain commonly referenced POSITIONs.
5459 POSITION can be one of the following symbols:
5460
5461 bol -- beginning of line
5462 eol -- end of line
5463 bod -- beginning of defun
5464 boi -- back to indentation
5465 eoi -- last whitespace on line
5466 ionl -- indentation of next line
5467 iopl -- indentation of previous line
5468 bonl -- beginning of next line
5469 bopl -- beginning of previous line
5470
5471 This function does not modify point or mark."
5472 (or (and (eq 'quote (car-safe position))
5473 (null (cddr position)))
5474 (error "ERROR: Bad buffer position requested: %s" position))
5475 (setq position (nth 1 position))
5476 `(let ((here (point)))
5477 ,@(cond
5478 ((eq position 'bol) '((beginning-of-line)))
5479 ((eq position 'eol) '((end-of-line)))
5480 ((eq position 'bod) '((save-match-data
5481 (vhdl-beginning-of-defun))))
5482 ((eq position 'boi) '((back-to-indentation)))
5483 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5484 ((eq position 'bonl) '((forward-line 1)))
5485 ((eq position 'bopl) '((forward-line -1)))
5486 ((eq position 'iopl)
5487 '((forward-line -1)
5488 (back-to-indentation)))
5489 ((eq position 'ionl)
5490 '((forward-line 1)
5491 (back-to-indentation)))
5492 (t (error "ERROR: Unknown buffer position requested: %s" position))
5493 )
5494 (prog1
5495 (point)
5496 (goto-char here))
5497 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5498 ;; doesn't hurt for v19
5499 ,@nil
5500 ))
5501
5502 (defmacro vhdl-safe (&rest body)
5503 "Safely execute BODY, return nil if an error occurred."
5504 `(condition-case nil
5505 (progn ,@body)
5506 (error nil)))
5507
5508 (defmacro vhdl-add-syntax (symbol &optional relpos)
5509 "A simple macro to append the syntax in SYMBOL to the syntax list.
5510 Try to increase performance by using this macro."
5511 `(setq vhdl-syntactic-context
5512 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5513
5514 (defmacro vhdl-has-syntax (symbol)
5515 "A simple macro to return check the syntax list.
5516 Try to increase performance by using this macro."
5517 `(assoc ,symbol vhdl-syntactic-context))
5518
5519 ;; Syntactic element offset manipulation:
5520
5521 (defun vhdl-read-offset (langelem)
5522 "Read new offset value for LANGELEM from minibuffer.
5523 Return a valid value only."
5524 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5525 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5526 (prompt "Offset: ")
5527 offset input interned)
5528 (while (not offset)
5529 (setq input (read-string prompt oldoff)
5530 offset (cond ((string-equal "+" input) '+)
5531 ((string-equal "-" input) '-)
5532 ((string-equal "++" input) '++)
5533 ((string-equal "--" input) '--)
5534 ((string-match "^-?[0-9]+$" input)
5535 (string-to-number input))
5536 ((fboundp (setq interned (intern input)))
5537 interned)
5538 ((boundp interned) interned)
5539 ;; error, but don't signal one, keep trying
5540 ;; to read an input value
5541 (t (ding)
5542 (setq prompt errmsg)
5543 nil))))
5544 offset))
5545
5546 (defun vhdl-set-offset (symbol offset &optional add-p)
5547 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5548 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5549 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5550 `vhdl-offsets-alist' if it doesn't already appear there."
5551 (interactive
5552 (let* ((langelem
5553 (intern (completing-read
5554 (concat "Syntactic symbol to change"
5555 (if current-prefix-arg " or add" "")
5556 ": ")
5557 (mapcar
5558 (function
5559 (lambda (langelem)
5560 (cons (format "%s" (car langelem)) nil)))
5561 vhdl-offsets-alist)
5562 nil (not current-prefix-arg)
5563 ;; initial contents tries to be the last element
5564 ;; on the syntactic analysis list for the current
5565 ;; line
5566 (let* ((syntax (vhdl-get-syntactic-context))
5567 (len (length syntax))
5568 (ic (format "%s" (car (nth (1- len) syntax)))))
5569 ic)
5570 )))
5571 (offset (vhdl-read-offset langelem)))
5572 (list langelem offset current-prefix-arg)))
5573 ;; sanity check offset
5574 (or (eq offset '+)
5575 (eq offset '-)
5576 (eq offset '++)
5577 (eq offset '--)
5578 (integerp offset)
5579 (fboundp offset)
5580 (boundp offset)
5581 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5582 offset))
5583 (let ((entry (assq symbol vhdl-offsets-alist)))
5584 (if entry
5585 (setcdr entry offset)
5586 (if add-p
5587 (setq vhdl-offsets-alist
5588 (cons (cons symbol offset) vhdl-offsets-alist))
5589 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5590 (vhdl-keep-region-active))
5591
5592 (defun vhdl-set-style (style &optional local)
5593 "Set `vhdl-mode' variables to use one of several different indentation styles.
5594 STYLE is a string representing the desired style and optional LOCAL is
5595 a flag which, if non-nil, means to make the style variables being
5596 changed buffer local, instead of the default, which is to set the
5597 global variables. Interactively, the flag comes from the prefix
5598 argument. The styles are chosen from the `vhdl-style-alist' variable."
5599 (interactive (list (completing-read "Use which VHDL indentation style? "
5600 vhdl-style-alist nil t)
5601 current-prefix-arg))
5602 (let ((vars (cdr (assoc style vhdl-style-alist))))
5603 (or vars
5604 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5605 ;; set all the variables
5606 (mapc
5607 (function
5608 (lambda (varentry)
5609 (let ((var (car varentry))
5610 (val (cdr varentry)))
5611 ;; special case for vhdl-offsets-alist
5612 (if (not (eq var 'vhdl-offsets-alist))
5613 (set (if local (make-local-variable var) var) val)
5614 ;; reset vhdl-offsets-alist to the default value first
5615 (set (if local (make-local-variable var) var)
5616 (copy-alist vhdl-offsets-alist-default))
5617 ;; now set the langelems that are different
5618 (mapcar
5619 (function
5620 (lambda (langentry)
5621 (let ((langelem (car langentry))
5622 (offset (cdr langentry)))
5623 (vhdl-set-offset langelem offset)
5624 )))
5625 val))
5626 )))
5627 vars))
5628 (vhdl-keep-region-active))
5629
5630 (defun vhdl-get-offset (langelem)
5631 "Get offset from LANGELEM which is a cons cell of the form:
5632 \(SYMBOL . RELPOS). The symbol is matched against
5633 vhdl-offsets-alist and the offset found there is either returned,
5634 or added to the indentation at RELPOS. If RELPOS is nil, then
5635 the offset is simply returned."
5636 (let* ((symbol (car langelem))
5637 (relpos (cdr langelem))
5638 (match (assq symbol vhdl-offsets-alist))
5639 (offset (cdr-safe match)))
5640 ;; offset can be a number, a function, a variable, or one of the
5641 ;; symbols + or -
5642 (cond
5643 ((not match)
5644 (if vhdl-strict-syntax-p
5645 (error "ERROR: Don't know how to indent a %s" symbol)
5646 (setq offset 0
5647 relpos 0)))
5648 ((eq offset '+) (setq offset vhdl-basic-offset))
5649 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5650 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5651 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5652 ((and (not (numberp offset))
5653 (fboundp offset))
5654 (setq offset (funcall offset langelem)))
5655 ((not (numberp offset))
5656 (setq offset (eval offset)))
5657 )
5658 (+ (if (and relpos
5659 (< relpos (vhdl-point 'bol)))
5660 (save-excursion
5661 (goto-char relpos)
5662 (current-column))
5663 0)
5664 offset)))
5665
5666 ;; Syntactic support functions:
5667
5668 (defun vhdl-in-comment-p (&optional pos)
5669 "Check if point is in a comment (include multi-line comments)."
5670 (let ((parse (lambda (p)
5671 (let ((c (char-after p)))
5672 (or (and c (eq (char-syntax c) ?<))
5673 (nth 4 (parse-partial-sexp
5674 (save-excursion
5675 (beginning-of-defun)
5676 (point)) p)))))))
5677 (save-excursion
5678 (goto-char (or pos (point)))
5679 (or (funcall parse (point))
5680 ;; `parse-partial-sexp's notion of comments doesn't span lines
5681 (progn
5682 (back-to-indentation)
5683 (unless (eolp)
5684 (forward-char)
5685 (funcall parse (point))))))))
5686
5687 (defun vhdl-in-string-p ()
5688 "Check if point is in a string."
5689 (eq (vhdl-in-literal) 'string))
5690
5691 (defun vhdl-in-quote-p ()
5692 "Check if point is in a quote ('x')."
5693 (or (and (> (point) (point-min))
5694 (< (1+ (point)) (point-max))
5695 (= (char-before (point)) ?\')
5696 (= (char-after (1+ (point))) ?\'))
5697 (and (> (1- (point)) (point-min))
5698 (< (point) (point-max))
5699 (= (char-before (1- (point))) ?\')
5700 (= (char-after (point)) ?\'))))
5701
5702 (defun vhdl-in-literal ()
5703 "Determine if point is in a VHDL literal."
5704 (save-excursion
5705 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5706 (cond
5707 ((nth 3 state) 'string)
5708 ((nth 4 state) 'comment)
5709 ((vhdl-beginning-of-macro) 'pound)
5710 ((vhdl-beginning-of-directive) 'directive)
5711 ;; for multi-line comments
5712 ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
5713 (t nil)))))
5714
5715 (defun vhdl-in-extended-identifier-p ()
5716 "Determine if point is inside extended identifier (delimited by ‘\\’)."
5717 (save-match-data
5718 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5719 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5720
5721 (defun vhdl-forward-comment (&optional direction)
5722 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5723 negative, skip forward otherwise."
5724 (interactive "p")
5725 (if (and direction (< direction 0))
5726 ;; skip backwards
5727 (progn
5728 (skip-chars-backward " \t\n\r\f")
5729 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5730 (goto-char (match-beginning 3))
5731 (skip-chars-backward " \t\n\r\f")))
5732 ;; skip forwards
5733 (skip-chars-forward " \t\n\r\f")
5734 (while (looking-at "--.*")
5735 (goto-char (match-end 0))
5736 (skip-chars-forward " \t\n\r\f"))))
5737
5738 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5739 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5740 (defalias 'vhdl-forward-comment 'forward-comment))
5741
5742 (defun vhdl-back-to-indentation ()
5743 "Move point to the first non-whitespace character on this line."
5744 (interactive)
5745 (beginning-of-line 1)
5746 (skip-syntax-forward " " (vhdl-point 'eol)))
5747
5748 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5749 (when (featurep 'xemacs)
5750 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5751
5752 ;; This is the best we can do in Win-Emacs.
5753 (defun vhdl-win-il (&optional lim)
5754 "Determine if point is in a VHDL literal."
5755 (save-excursion
5756 (let* ((here (point))
5757 (state nil)
5758 (match nil)
5759 (lim (or lim (vhdl-point 'bod))))
5760 (goto-char lim )
5761 (while (< (point) here)
5762 (setq match
5763 (and (re-search-forward "--\\|[\"']\\|`"
5764 here 'move)
5765 (buffer-substring (match-beginning 0) (match-end 0))))
5766 (setq state
5767 (cond
5768 ;; no match
5769 ((null match) nil)
5770 ;; looking at the opening of a VHDL style comment
5771 ((string= "--" match)
5772 (if (<= here (progn (end-of-line) (point))) 'comment))
5773 ;; looking at a directive
5774 ((string= "`" match)
5775 (if (<= here (progn (end-of-line) (point))) 'directive))
5776 ;; looking at the opening of a double quote string
5777 ((string= "\"" match)
5778 (if (not (save-restriction
5779 ;; this seems to be necessary since the
5780 ;; re-search-forward will not work without it
5781 (narrow-to-region (point) here)
5782 (re-search-forward
5783 ;; this regexp matches a double quote
5784 ;; which is preceded by an even number
5785 ;; of backslashes, including zero
5786 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5787 'string))
5788 ;; looking at the opening of a single quote string
5789 ((string= "'" match)
5790 (if (not (save-restriction
5791 ;; see comments from above
5792 (narrow-to-region (point) here)
5793 (re-search-forward
5794 ;; this matches a single quote which is
5795 ;; preceded by zero or two backslashes.
5796 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5797 here 'move)))
5798 'string))
5799 (t nil)))
5800 ) ; end-while
5801 state)))
5802
5803 (and (string-match "Win-Emacs" emacs-version)
5804 (fset 'vhdl-in-literal 'vhdl-win-il))
5805
5806 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5807 ;; defined as lexical whitespace or comments. Search no farther back
5808 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5809 ;; used for backward skipping, (point-max) is used for forward
5810 ;; skipping.
5811
5812 (defun vhdl-forward-syntactic-ws (&optional lim)
5813 "Forward skip of syntactic whitespace."
5814 (let* ((here (point-max))
5815 (hugenum (point-max)))
5816 (while (/= here (point))
5817 (setq here (point))
5818 (vhdl-forward-comment hugenum)
5819 ;; skip preprocessor directives
5820 (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
5821 (= (vhdl-point 'boi) (point)))
5822 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5823 (= (forward-line 1) 0)))
5824 (end-of-line)))
5825 (if lim (goto-char (min (point) lim)))))
5826
5827
5828 ;; This is the best we can do in Win-Emacs.
5829 (defun vhdl-win-fsws (&optional lim)
5830 "Forward skip syntactic whitespace for Win-Emacs."
5831 (let ((lim (or lim (point-max)))
5832 stop)
5833 (while (not stop)
5834 (skip-chars-forward " \t\n\r\f" lim)
5835 (cond
5836 ;; vhdl comment
5837 ((looking-at "--") (end-of-line))
5838 ;; none of the above
5839 (t (setq stop t))))))
5840
5841 (and (string-match "Win-Emacs" emacs-version)
5842 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5843
5844 (defun vhdl-beginning-of-macro (&optional lim)
5845 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5846 (let ((here (point)))
5847 (beginning-of-line)
5848 (while (eq (char-before (1- (point))) ?\\)
5849 (forward-line -1))
5850 (back-to-indentation)
5851 (if (and (<= (point) here)
5852 (eq (char-after) ?#))
5853 t
5854 (goto-char here)
5855 nil)))
5856
5857 (defun vhdl-beginning-of-directive (&optional lim)
5858 "Go to the beginning of a directive (nicked from `cc-engine')."
5859 (let ((here (point)))
5860 (beginning-of-line)
5861 (while (eq (char-before (1- (point))) ?\\)
5862 (forward-line -1))
5863 (back-to-indentation)
5864 (if (and (<= (point) here)
5865 (eq (char-after) ?`))
5866 t
5867 (goto-char here)
5868 nil)))
5869
5870 (defun vhdl-backward-syntactic-ws (&optional lim)
5871 "Backward skip over syntactic whitespace."
5872 (let* ((here (point-min))
5873 (hugenum (- (point-max))))
5874 (while (/= here (point))
5875 (setq here (point))
5876 (vhdl-forward-comment hugenum)
5877 (vhdl-beginning-of-macro))
5878 (if lim (goto-char (max (point) lim)))))
5879
5880 ;; This is the best we can do in Win-Emacs.
5881 (defun vhdl-win-bsws (&optional lim)
5882 "Backward skip syntactic whitespace for Win-Emacs."
5883 (let ((lim (or lim (vhdl-point 'bod)))
5884 stop)
5885 (while (not stop)
5886 (skip-chars-backward " \t\n\r\f" lim)
5887 (cond
5888 ;; vhdl comment
5889 ((eq (vhdl-in-literal) 'comment)
5890 (skip-chars-backward "^-" lim)
5891 (skip-chars-backward "-" lim)
5892 (while (not (or (and (= (following-char) ?-)
5893 (= (char-after (1+ (point))) ?-))
5894 (<= (point) lim)))
5895 (skip-chars-backward "^-" lim)
5896 (skip-chars-backward "-" lim)))
5897 ;; none of the above
5898 (t (setq stop t))))))
5899
5900 (and (string-match "Win-Emacs" emacs-version)
5901 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5902
5903 ;; Functions to help finding the correct indentation column:
5904
5905 (defun vhdl-first-word (point)
5906 "If the keyword at POINT is at boi, then return (current-column) at
5907 that point, else nil."
5908 (save-excursion
5909 (and (goto-char point)
5910 (eq (point) (vhdl-point 'boi))
5911 (current-column))))
5912
5913 (defun vhdl-last-word (point)
5914 "If the keyword at POINT is at eoi, then return (current-column) at
5915 that point, else nil."
5916 (save-excursion
5917 (and (goto-char point)
5918 (save-excursion (or (eq (progn (forward-sexp) (point))
5919 (vhdl-point 'eoi))
5920 (looking-at "\\s-*\\(--\\)?")))
5921 (current-column))))
5922
5923 ;; Core syntactic evaluation functions:
5924
5925 (defconst vhdl-libunit-re
5926 "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
5927
5928 (defun vhdl-libunit-p ()
5929 (and
5930 (save-excursion
5931 (forward-sexp)
5932 (skip-chars-forward " \t\n\r\f")
5933 (not (looking-at "is\\b[^_]")))
5934 (save-excursion
5935 (backward-sexp)
5936 (and (not (looking-at "use\\b[^_]"))
5937 (progn
5938 (forward-sexp)
5939 (vhdl-forward-syntactic-ws)
5940 (/= (following-char) ?:))))
5941 ))
5942
5943 (defconst vhdl-defun-re
5944 "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5945
5946 (defun vhdl-defun-p ()
5947 (save-excursion
5948 (if (looking-at "block\\|process\\|procedural")
5949 ;; "block", "process", "procedural":
5950 (save-excursion
5951 (backward-sexp)
5952 (not (looking-at "end\\s-+\\w")))
5953 ;; "architecture", "configuration", "context", "entity",
5954 ;; "package", "procedure", "function":
5955 t)))
5956
5957 (defun vhdl-corresponding-defun ()
5958 "If the word at the current position corresponds to a \"defun\"
5959 keyword, then return a string that can be used to find the
5960 corresponding \"begin\" keyword, else return nil."
5961 (save-excursion
5962 (and (looking-at vhdl-defun-re)
5963 (vhdl-defun-p)
5964 (if (looking-at "block\\|process\\|procedural")
5965 ;; "block", "process". "procedural:
5966 (buffer-substring (match-beginning 0) (match-end 0))
5967 ;; "architecture", "configuration", "context", "entity", "package",
5968 ;; "procedure", "function":
5969 "is"))))
5970
5971 (defconst vhdl-begin-fwd-re
5972 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5973 "A regular expression for searching forward that matches all known
5974 \"begin\" keywords.")
5975
5976 (defconst vhdl-begin-bwd-re
5977 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5978 "A regular expression for searching backward that matches all known
5979 \"begin\" keywords.")
5980
5981 (defun vhdl-begin-p (&optional lim)
5982 "Return t if we are looking at a real \"begin\" keyword.
5983 Assumes that the caller will make sure that we are looking at
5984 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5985 the middle of an identifier that just happens to contain a \"begin\"
5986 keyword."
5987 (cond
5988 ;; "[architecture|case|configuration|context|entity|package|
5989 ;; procedure|function] ... is":
5990 ((and (looking-at "i")
5991 (save-excursion
5992 ;; Skip backward over first sexp (needed to skip over a
5993 ;; procedure interface list, and is harmless in other
5994 ;; situations). Note that we need "return" in the
5995 ;; following search list so that we don't run into
5996 ;; semicolons in the function interface list.
5997 (backward-sexp)
5998 (let (foundp)
5999 (while (and (not foundp)
6000 (re-search-backward
6001 ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
6002 lim 'move))
6003 (if (or (= (preceding-char) ?_)
6004 (vhdl-in-literal))
6005 (backward-char)
6006 (setq foundp t))))
6007 (and (/= (following-char) ?\;)
6008 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
6009 t)
6010 ;; "begin", "then", "use":
6011 ((looking-at "be\\|t\\|use")
6012 t)
6013 ;; "else":
6014 ((and (looking-at "e")
6015 ;; make sure that the "else" isn't inside a
6016 ;; conditional signal assignment.
6017 (save-excursion
6018 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6019 (or (eq (following-char) ?\;)
6020 (eq (point) lim))))
6021 t)
6022 ;; "block", "generate", "loop", "process", "procedural",
6023 ;; "units", "record", "protected body":
6024 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
6025 (save-excursion
6026 (backward-sexp)
6027 (not (looking-at "end\\s-+\\w"))))
6028 t)
6029 ;; "component":
6030 ((and (looking-at "c")
6031 (save-excursion
6032 (backward-sexp)
6033 (not (looking-at "end\\s-+\\w")))
6034 ;; look out for the dreaded entity class in an attribute
6035 (save-excursion
6036 (vhdl-backward-syntactic-ws lim)
6037 (/= (preceding-char) ?:)))
6038 t)
6039 ;; "for" (inside configuration declaration):
6040 ((and (looking-at "f")
6041 (save-excursion
6042 (backward-sexp)
6043 (not (looking-at "end\\s-+\\w")))
6044 (vhdl-has-syntax 'configuration))
6045 t)
6046 ))
6047
6048 (defun vhdl-corresponding-mid (&optional lim)
6049 (cond
6050 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
6051 "begin")
6052 ((looking-at "then\\|use")
6053 "<else>")
6054 (t
6055 "end")))
6056
6057 (defun vhdl-corresponding-end (&optional lim)
6058 "If the word at the current position corresponds to a \"begin\"
6059 keyword, then return a vector containing enough information to find
6060 the corresponding \"end\" keyword, else return nil. The keyword to
6061 search forward for is aref 0. The column in which the keyword must
6062 appear is aref 1 or nil if any column is suitable.
6063 Assumes that the caller will make sure that we are not in the middle
6064 of an identifier that just happens to contain a \"begin\" keyword."
6065 (save-excursion
6066 (and (looking-at vhdl-begin-fwd-re)
6067 (or (not (looking-at "\\<use\\>"))
6068 (save-excursion (back-to-indentation)
6069 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6070 (/= (preceding-char) ?_)
6071 (not (vhdl-in-literal))
6072 (vhdl-begin-p lim)
6073 (cond
6074 ;; "is", "generate", "loop":
6075 ((looking-at "[igl]")
6076 (vector "end"
6077 (and (vhdl-last-word (point))
6078 (or (vhdl-first-word (point))
6079 (save-excursion
6080 (vhdl-beginning-of-statement-1 lim)
6081 (vhdl-backward-skip-label lim)
6082 (vhdl-first-word (point)))))))
6083 ;; "begin", "else", "for":
6084 ((looking-at "be\\|[ef]")
6085 (vector "end"
6086 (and (vhdl-last-word (point))
6087 (or (vhdl-first-word (point))
6088 (save-excursion
6089 (vhdl-beginning-of-statement-1 lim)
6090 (vhdl-backward-skip-label lim)
6091 (vhdl-first-word (point)))))))
6092 ;; "component", "units", "record", "protected body":
6093 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
6094 ;; The first end found will close the block
6095 (vector "end" nil))
6096 ;; "block", "process", "procedural":
6097 ((looking-at "bl\\|p")
6098 (vector "end"
6099 (or (vhdl-first-word (point))
6100 (save-excursion
6101 (vhdl-beginning-of-statement-1 lim)
6102 (vhdl-backward-skip-label lim)
6103 (vhdl-first-word (point))))))
6104 ;; "then":
6105 ((looking-at "t\\|use")
6106 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6107 (and (vhdl-last-word (point))
6108 (or (vhdl-first-word (point))
6109 (save-excursion
6110 (vhdl-beginning-of-statement-1 lim)
6111 (vhdl-backward-skip-label lim)
6112 (vhdl-first-word (point)))))))
6113 ))))
6114
6115 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6116
6117 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6118
6119 (defun vhdl-end-p (&optional lim)
6120 "Return t if we are looking at a real \"end\" keyword.
6121 Assumes that the caller will make sure that we are looking at
6122 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6123 the middle of an identifier that just happens to contain an \"end\"
6124 keyword."
6125 (or (not (looking-at "else"))
6126 ;; make sure that the "else" isn't inside a conditional signal
6127 ;; assignment.
6128 (save-excursion
6129 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6130 (or (eq (following-char) ?\;)
6131 (eq (point) lim)
6132 (vhdl-in-literal)))))
6133
6134 (defun vhdl-corresponding-begin (&optional lim)
6135 "If the word at the current position corresponds to an \"end\"
6136 keyword, then return a vector containing enough information to find
6137 the corresponding \"begin\" keyword, else return nil. The keyword to
6138 search backward for is aref 0. The column in which the keyword must
6139 appear is aref 1 or nil if any column is suitable. The supplementary
6140 keyword to search forward for is aref 2 or nil if this is not
6141 required. If aref 3 is t, then the \"begin\" keyword may be found in
6142 the middle of a statement.
6143 Assumes that the caller will make sure that we are not in the middle
6144 of an identifier that just happens to contain an \"end\" keyword."
6145 (save-excursion
6146 (let (pos)
6147 (if (and (looking-at vhdl-end-fwd-re)
6148 (not (vhdl-in-literal))
6149 (vhdl-end-p lim))
6150 (if (looking-at "el")
6151 ;; "else", "elsif":
6152 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6153 ;; "end ...":
6154 (setq pos (point))
6155 (forward-sexp)
6156 (skip-chars-forward " \t\n\r\f")
6157 (cond
6158 ;; "end if":
6159 ((looking-at "if\\b[^_]")
6160 (vector "else\\|elsif\\|if"
6161 (vhdl-first-word pos)
6162 "else\\|then\\|use" nil))
6163 ;; "end component":
6164 ((looking-at "component\\b[^_]")
6165 (vector (buffer-substring (match-beginning 1)
6166 (match-end 1))
6167 (vhdl-first-word pos)
6168 nil nil))
6169 ;; "end units", "end record", "end protected":
6170 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6171 (vector (buffer-substring (match-beginning 1)
6172 (match-end 1))
6173 (vhdl-first-word pos)
6174 nil t))
6175 ;; "end block", "end process", "end procedural":
6176 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6177 (vector "begin" (vhdl-first-word pos) nil nil))
6178 ;; "end case":
6179 ((looking-at "case\\b[^_]")
6180 (vector "case" (vhdl-first-word pos) "is" nil))
6181 ;; "end generate":
6182 ((looking-at "generate\\b[^_]")
6183 (vector "generate\\|for\\|if"
6184 (vhdl-first-word pos)
6185 "generate" nil))
6186 ;; "end loop":
6187 ((looking-at "loop\\b[^_]")
6188 (vector "loop\\|while\\|for"
6189 (vhdl-first-word pos)
6190 "loop" nil))
6191 ;; "end for" (inside configuration declaration):
6192 ((looking-at "for\\b[^_]")
6193 (vector "for" (vhdl-first-word pos) nil nil))
6194 ;; "end [id]":
6195 (t
6196 (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
6197 (vhdl-first-word pos)
6198 ;; return an alist of (statement . keyword) mappings
6199 '(
6200 ;; "begin ... end [id]":
6201 ("begin" . nil)
6202 ;; "architecture ... is ... begin ... end [id]":
6203 ("architecture" . "is")
6204 ;; "configuration ... is ... end [id]":
6205 ("configuration" . "is")
6206 ;; "context ... is ... end [id]":
6207 ("context" . "is")
6208 ;; "entity ... is ... end [id]":
6209 ("entity" . "is")
6210 ;; "package ... is ... end [id]":
6211 ("package" . "is")
6212 ;; "procedure ... is ... begin ... end [id]":
6213 ("procedure" . "is")
6214 ;; "function ... is ... begin ... end [id]":
6215 ("function" . "is")
6216 )
6217 nil))
6218 ))) ; "end ..."
6219 )))
6220
6221 (defconst vhdl-leader-re
6222 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6223
6224 (defun vhdl-end-of-leader ()
6225 (save-excursion
6226 (cond ((looking-at "block\\|process\\|procedural")
6227 (if (save-excursion
6228 (forward-sexp)
6229 (skip-chars-forward " \t\n\r\f")
6230 (= (following-char) ?\())
6231 (forward-sexp 2)
6232 (forward-sexp))
6233 (when (looking-at "[ \t\n\r\f]*is")
6234 (goto-char (match-end 0)))
6235 (point))
6236 ((looking-at "component")
6237 (forward-sexp 2)
6238 (when (looking-at "[ \t\n\r\f]*is")
6239 (goto-char (match-end 0)))
6240 (point))
6241 ((looking-at "for")
6242 (forward-sexp 2)
6243 (skip-chars-forward " \t\n\r\f")
6244 (while (looking-at "[,:(]")
6245 (forward-sexp)
6246 (skip-chars-forward " \t\n\r\f"))
6247 (point))
6248 (t nil)
6249 )))
6250
6251 (defconst vhdl-trailer-re
6252 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6253
6254 (defconst vhdl-statement-fwd-re
6255 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6256 "A regular expression for searching forward that matches all known
6257 \"statement\" keywords.")
6258
6259 (defconst vhdl-statement-bwd-re
6260 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6261 "A regular expression for searching backward that matches all known
6262 \"statement\" keywords.")
6263
6264 (defun vhdl-statement-p (&optional lim)
6265 "Return t if we are looking at a real \"statement\" keyword.
6266 Assumes that the caller will make sure that we are looking at
6267 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6268 in the middle of an identifier that just happens to contain a
6269 \"statement\" keyword."
6270 (cond
6271 ;; "for" ... "generate":
6272 ((and (looking-at "f")
6273 ;; Make sure it's the start of a parameter specification.
6274 (save-excursion
6275 (forward-sexp 2)
6276 (skip-chars-forward " \t\n\r\f")
6277 (looking-at "in\\b[^_]"))
6278 ;; Make sure it's not an "end for".
6279 (save-excursion
6280 (backward-sexp)
6281 (not (looking-at "end\\s-+\\w"))))
6282 t)
6283 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6284 ((and (looking-at "i")
6285 ;; Make sure it's not an "end if".
6286 (save-excursion
6287 (backward-sexp)
6288 (not (looking-at "end\\s-+\\w"))))
6289 t)
6290 ;; "while" ... "loop":
6291 ((looking-at "w")
6292 t)
6293 ))
6294
6295 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6296 "Regexp describing a case statement alternative key.")
6297
6298 (defun vhdl-case-alternative-p (&optional lim)
6299 "Return t if we are looking at a real case alternative.
6300 Assumes that the caller will make sure that we are looking at
6301 vhdl-case-alternative-re, and are not inside a literal, and that
6302 we are not in the middle of an identifier that just happens to
6303 contain a \"when\" keyword."
6304 (save-excursion
6305 (let (foundp)
6306 (while (and (not foundp)
6307 (re-search-backward ";\\|<=" lim 'move))
6308 (if (or (= (preceding-char) ?_)
6309 (vhdl-in-literal))
6310 (backward-char)
6311 (setq foundp t)))
6312 (or (eq (following-char) ?\;)
6313 (eq (point) lim)))
6314 ))
6315
6316 ;; Core syntactic movement functions:
6317
6318 (defconst vhdl-b-t-b-re
6319 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6320
6321 (defun vhdl-backward-to-block (&optional lim)
6322 "Move backward to the previous \"begin\" or \"end\" keyword."
6323 (let (foundp)
6324 (while (and (not foundp)
6325 (re-search-backward vhdl-b-t-b-re lim 'move))
6326 (if (or (= (preceding-char) ?_)
6327 (vhdl-in-literal))
6328 (backward-char)
6329 (cond
6330 ;; "begin" keyword:
6331 ((and (looking-at vhdl-begin-fwd-re)
6332 (or (not (looking-at "\\<use\\>"))
6333 (save-excursion (back-to-indentation)
6334 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6335 (/= (preceding-char) ?_)
6336 (vhdl-begin-p lim))
6337 (setq foundp 'begin))
6338 ;; "end" keyword:
6339 ((and (looking-at vhdl-end-fwd-re)
6340 (/= (preceding-char) ?_)
6341 (vhdl-end-p lim))
6342 (setq foundp 'end))
6343 ))
6344 )
6345 foundp
6346 ))
6347
6348 (defun vhdl-forward-sexp (&optional count lim)
6349 "Move forward across one balanced expression (sexp).
6350 With COUNT, do it that many times."
6351 (interactive "p")
6352 (let ((count (or count 1))
6353 (case-fold-search t)
6354 end-vec target)
6355 (save-excursion
6356 (while (> count 0)
6357 ;; skip whitespace
6358 (skip-chars-forward " \t\n\r\f")
6359 ;; Check for an unbalanced "end" keyword
6360 (if (and (looking-at vhdl-end-fwd-re)
6361 (/= (preceding-char) ?_)
6362 (not (vhdl-in-literal))
6363 (vhdl-end-p lim)
6364 (not (looking-at "else")))
6365 (error
6366 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6367 ;; If the current keyword is a "begin" keyword, then find the
6368 ;; corresponding "end" keyword.
6369 (if (setq end-vec (vhdl-corresponding-end lim))
6370 (let (
6371 ;; end-re is the statement keyword to search for
6372 (end-re
6373 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6374 ;; column is either the statement keyword target column
6375 ;; or nil
6376 (column (aref end-vec 1))
6377 (eol (vhdl-point 'eol))
6378 foundp literal placeholder)
6379 ;; Look for the statement keyword.
6380 (while (and (not foundp)
6381 (re-search-forward end-re nil t)
6382 (setq placeholder (match-end 1))
6383 (goto-char (match-beginning 0)))
6384 ;; If we are in a literal, or not in the right target
6385 ;; column and not on the same line as the begin, then
6386 ;; try again.
6387 (if (or (and column
6388 (/= (current-indentation) column)
6389 (> (point) eol))
6390 (= (preceding-char) ?_)
6391 (setq literal (vhdl-in-literal)))
6392 (if (eq literal 'comment)
6393 (end-of-line)
6394 (forward-char))
6395 ;; An "else" keyword corresponds to both the opening brace
6396 ;; of the following sexp and the closing brace of the
6397 ;; previous sexp.
6398 (if (not (looking-at "else"))
6399 (goto-char placeholder))
6400 (setq foundp t))
6401 )
6402 (if (not foundp)
6403 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6404 )
6405 ;; If the current keyword is not a "begin" keyword, then just
6406 ;; perform the normal forward-sexp.
6407 (forward-sexp)
6408 )
6409 (setq count (1- count))
6410 )
6411 (setq target (point)))
6412 (goto-char target)
6413 nil))
6414
6415 (defun vhdl-backward-sexp (&optional count lim)
6416 "Move backward across one balanced expression (sexp).
6417 With COUNT, do it that many times. LIM bounds any required backward
6418 searches."
6419 (interactive "p")
6420 (let ((count (or count 1))
6421 (case-fold-search t)
6422 begin-vec target)
6423 (save-excursion
6424 (while (> count 0)
6425 ;; Perform the normal backward-sexp, unless we are looking at
6426 ;; "else" - an "else" keyword corresponds to both the opening brace
6427 ;; of the following sexp and the closing brace of the previous sexp.
6428 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6429 (/= (preceding-char) ?_)
6430 (not (vhdl-in-literal)))
6431 nil
6432 (backward-sexp)
6433 (if (and (looking-at vhdl-begin-fwd-re)
6434 (or (not (looking-at "\\<use\\>"))
6435 (save-excursion
6436 (back-to-indentation)
6437 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6438 (/= (preceding-char) ?_)
6439 (not (vhdl-in-literal))
6440 (vhdl-begin-p lim))
6441 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6442 ;; If the current keyword is an "end" keyword, then find the
6443 ;; corresponding "begin" keyword.
6444 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6445 (/= (preceding-char) ?_))
6446 (let (
6447 ;; begin-re is the statement keyword to search for
6448 (begin-re
6449 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6450 ;; column is either the statement keyword target column
6451 ;; or nil
6452 (column (aref begin-vec 1))
6453 ;; internal-p controls where the statement keyword can
6454 ;; be found.
6455 (internal-p (aref begin-vec 3))
6456 (last-backward (point)) last-forward
6457 foundp literal keyword)
6458 ;; Look for the statement keyword.
6459 (while (and (not foundp)
6460 (re-search-backward begin-re lim t)
6461 (setq keyword
6462 (buffer-substring (match-beginning 1)
6463 (match-end 1))))
6464 ;; If we are in a literal or in the wrong column,
6465 ;; then try again.
6466 (if (or (and column
6467 (and (/= (current-indentation) column)
6468 ;; possibly accept current-column as
6469 ;; well as current-indentation.
6470 (or (not internal-p)
6471 (/= (current-column) column))))
6472 (= (preceding-char) ?_)
6473 (vhdl-in-literal))
6474 (backward-char)
6475 ;; If there is a supplementary keyword, then
6476 ;; search forward for it.
6477 (if (and (setq begin-re (aref begin-vec 2))
6478 (or (not (listp begin-re))
6479 ;; If begin-re is an alist, then find the
6480 ;; element corresponding to the actual
6481 ;; keyword that we found.
6482 (progn
6483 (setq begin-re
6484 (assoc keyword begin-re))
6485 (and begin-re
6486 (setq begin-re (cdr begin-re))))))
6487 (and
6488 (setq begin-re
6489 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6490 (save-excursion
6491 (setq last-forward (point))
6492 ;; Look for the supplementary keyword
6493 ;; (bounded by the backward search start
6494 ;; point).
6495 (while (and (not foundp)
6496 (re-search-forward begin-re
6497 last-backward t)
6498 (goto-char (match-beginning 1)))
6499 ;; If we are in a literal, then try again.
6500 (if (or (= (preceding-char) ?_)
6501 (setq literal
6502 (vhdl-in-literal)))
6503 (if (eq literal 'comment)
6504 (goto-char
6505 (min (vhdl-point 'eol) last-backward))
6506 (forward-char))
6507 ;; We have found the supplementary keyword.
6508 ;; Save the position of the keyword in foundp.
6509 (setq foundp (point)))
6510 )
6511 foundp)
6512 ;; If the supplementary keyword was found, then
6513 ;; move point to the supplementary keyword.
6514 (goto-char foundp))
6515 ;; If there was no supplementary keyword, then
6516 ;; point is already at the statement keyword.
6517 (setq foundp t)))
6518 ) ; end of the search for the statement keyword
6519 (if (not foundp)
6520 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6521 ))
6522 (setq count (1- count))
6523 )
6524 (setq target (point)))
6525 (goto-char target)
6526 nil))
6527
6528 (defun vhdl-backward-up-list (&optional count limit)
6529 "Move backward out of one level of blocks.
6530 With argument, do this that many times."
6531 (interactive "p")
6532 (let ((count (or count 1))
6533 target)
6534 (save-excursion
6535 (while (> count 0)
6536 (if (looking-at vhdl-defun-re)
6537 (error "ERROR: Unbalanced blocks"))
6538 (vhdl-backward-to-block limit)
6539 (setq count (1- count)))
6540 (setq target (point)))
6541 (goto-char target)))
6542
6543 (defun vhdl-end-of-defun (&optional count)
6544 "Move forward to the end of a VHDL defun."
6545 (interactive)
6546 (let ((case-fold-search t))
6547 (vhdl-beginning-of-defun)
6548 (if (not (looking-at "block\\|process\\|procedural"))
6549 (re-search-forward "\\bis\\b"))
6550 (vhdl-forward-sexp)))
6551
6552 (defun vhdl-mark-defun ()
6553 "Put mark at end of this \"defun\", point at beginning."
6554 (interactive)
6555 (let ((case-fold-search t))
6556 (push-mark)
6557 (vhdl-beginning-of-defun)
6558 (push-mark)
6559 (if (not (looking-at "block\\|process\\|procedural"))
6560 (re-search-forward "\\bis\\b"))
6561 (vhdl-forward-sexp)
6562 (exchange-point-and-mark)))
6563
6564 (defun vhdl-beginning-of-libunit ()
6565 "Move backward to the beginning of a VHDL library unit.
6566 Returns the location of the corresponding begin keyword, unless search
6567 stops due to beginning or end of buffer.
6568 Note that if point is between the \"libunit\" keyword and the
6569 corresponding \"begin\" keyword, then that libunit will not be
6570 recognized, and the search will continue backwards. If point is
6571 at the \"begin\" keyword, then the defun will be recognized. The
6572 returned point is at the first character of the \"libunit\" keyword."
6573 (let ((last-forward (point))
6574 (last-backward
6575 ;; Just in case we are actually sitting on the "begin"
6576 ;; keyword, allow for the keyword and an extra character,
6577 ;; as this will be used when looking forward for the
6578 ;; "begin" keyword.
6579 (save-excursion (forward-word 1) (1+ (point))))
6580 foundp literal placeholder)
6581 ;; Find the "libunit" keyword.
6582 (while (and (not foundp)
6583 (re-search-backward vhdl-libunit-re nil 'move))
6584 ;; If we are in a literal, or not at a real libunit, then try again.
6585 (if (or (= (preceding-char) ?_)
6586 (vhdl-in-literal)
6587 (not (vhdl-libunit-p)))
6588 (backward-char)
6589 ;; Find the corresponding "begin" keyword.
6590 (setq last-forward (point))
6591 (while (and (not foundp)
6592 (re-search-forward "\\bis\\b[^_]" last-backward t)
6593 (setq placeholder (match-beginning 0)))
6594 (if (or (= (preceding-char) ?_)
6595 (setq literal (vhdl-in-literal)))
6596 ;; It wasn't a real keyword, so keep searching.
6597 (if (eq literal 'comment)
6598 (goto-char
6599 (min (vhdl-point 'eol) last-backward))
6600 (forward-char))
6601 ;; We have found the begin keyword, loop will exit.
6602 (setq foundp placeholder)))
6603 ;; Go back to the libunit keyword
6604 (goto-char last-forward)))
6605 foundp))
6606
6607 (defun vhdl-beginning-of-defun (&optional count)
6608 "Move backward to the beginning of a VHDL defun.
6609 With argument, do it that many times.
6610 Returns the location of the corresponding begin keyword, unless search
6611 stops due to beginning or end of buffer."
6612 ;; Note that if point is between the "defun" keyword and the
6613 ;; corresponding "begin" keyword, then that defun will not be
6614 ;; recognized, and the search will continue backwards. If point is
6615 ;; at the "begin" keyword, then the defun will be recognized. The
6616 ;; returned point is at the first character of the "defun" keyword.
6617 (interactive "p")
6618 (let ((count (or count 1))
6619 (case-fold-search t)
6620 (last-forward (point))
6621 foundp)
6622 (while (> count 0)
6623 (setq foundp nil)
6624 (goto-char last-forward)
6625 (let ((last-backward
6626 ;; Just in case we are actually sitting on the "begin"
6627 ;; keyword, allow for the keyword and an extra character,
6628 ;; as this will be used when looking forward for the
6629 ;; "begin" keyword.
6630 (save-excursion (forward-word 1) (1+ (point))))
6631 begin-string literal)
6632 (while (and (not foundp)
6633 (re-search-backward vhdl-defun-re nil 'move))
6634 ;; If we are in a literal, then try again.
6635 (if (or (= (preceding-char) ?_)
6636 (vhdl-in-literal))
6637 (backward-char)
6638 (if (setq begin-string (vhdl-corresponding-defun))
6639 ;; This is a real defun keyword.
6640 ;; Find the corresponding "begin" keyword.
6641 ;; Look for the begin keyword.
6642 (progn
6643 ;; Save the search start point.
6644 (setq last-forward (point))
6645 (while (and (not foundp)
6646 (search-forward begin-string last-backward t))
6647 (if (or (= (preceding-char) ?_)
6648 (save-match-data
6649 (setq literal (vhdl-in-literal))))
6650 ;; It wasn't a real keyword, so keep searching.
6651 (if (eq literal 'comment)
6652 (goto-char
6653 (min (vhdl-point 'eol) last-backward))
6654 (forward-char))
6655 ;; We have found the begin keyword, loop will exit.
6656 (setq foundp (match-beginning 0)))
6657 )
6658 ;; Go back to the defun keyword
6659 (goto-char last-forward)) ; end search for begin keyword
6660 ))
6661 ) ; end of the search for the defun keyword
6662 )
6663 (setq count (1- count))
6664 )
6665 (vhdl-keep-region-active)
6666 foundp))
6667
6668 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6669 "Go to the beginning of the innermost VHDL statement.
6670 With prefix arg, go back N - 1 statements. If already at the
6671 beginning of a statement then go to the beginning of the preceding
6672 one. If within a string or comment, or next to a comment (only
6673 whitespace between), move by sentences instead of statements.
6674
6675 When called from a program, this function takes 3 optional args: the
6676 prefix arg, a buffer position limit which is the farthest back to
6677 search, and an argument indicating an interactive call."
6678 (interactive "p\np")
6679 (let ((count (or count 1))
6680 (case-fold-search t)
6681 (lim (or lim (point-min)))
6682 (here (point))
6683 state)
6684 (save-excursion
6685 (goto-char lim)
6686 (setq state (parse-partial-sexp (point) here nil nil)))
6687 (if (and interactive
6688 (or (nth 3 state)
6689 (nth 4 state)
6690 (looking-at (concat "[ \t]*" comment-start-skip))))
6691 (forward-sentence (- count))
6692 (while (> count 0)
6693 (vhdl-beginning-of-statement-1 lim)
6694 (setq count (1- count))))
6695 ;; its possible we've been left up-buf of lim
6696 (goto-char (max (point) lim))
6697 )
6698 (vhdl-keep-region-active))
6699
6700 (defconst vhdl-e-o-s-re
6701 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6702
6703 (defun vhdl-end-of-statement ()
6704 "Very simple implementation."
6705 (interactive)
6706 (re-search-forward vhdl-e-o-s-re))
6707
6708 (defconst vhdl-b-o-s-re
6709 (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
6710 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6711
6712 (defun vhdl-beginning-of-statement-1 (&optional lim)
6713 "Move to the start of the current statement, or the previous
6714 statement if already at the beginning of one."
6715 (let ((lim (or lim (point-min)))
6716 (here (point))
6717 (pos (point))
6718 donep)
6719 ;; go backwards one balanced expression, but be careful of
6720 ;; unbalanced paren being reached
6721 (if (not (vhdl-safe (progn (backward-sexp) t)))
6722 (progn
6723 (backward-up-list 1)
6724 (forward-char)
6725 (vhdl-forward-syntactic-ws here)
6726 (setq donep t)))
6727 (while (and (not donep)
6728 (not (bobp))
6729 ;; look backwards for a statement boundary
6730 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6731 (if (or (= (preceding-char) ?_)
6732 (vhdl-in-literal))
6733 (backward-char)
6734 (cond
6735 ;; If we are looking at an open paren, then stop after it
6736 ((eq (following-char) ?\()
6737 (forward-char)
6738 (vhdl-forward-syntactic-ws here)
6739 (setq donep t))
6740 ;; If we are looking at a close paren, then skip it
6741 ((eq (following-char) ?\))
6742 (forward-char)
6743 (setq pos (point))
6744 (backward-sexp)
6745 (if (< (point) lim)
6746 (progn (goto-char pos)
6747 (vhdl-forward-syntactic-ws here)
6748 (setq donep t))))
6749 ;; If we are looking at a semicolon, then stop
6750 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6751 (progn
6752 (forward-char)
6753 (vhdl-forward-syntactic-ws here)
6754 (setq donep t)))
6755 ;; If we are looking at a "begin", then stop
6756 ((and (looking-at vhdl-begin-fwd-re)
6757 (or (not (looking-at "\\<use\\>"))
6758 (save-excursion
6759 (back-to-indentation)
6760 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6761 (/= (preceding-char) ?_)
6762 (vhdl-begin-p nil))
6763 ;; If it's a leader "begin", then find the
6764 ;; right place
6765 (if (looking-at vhdl-leader-re)
6766 (save-excursion
6767 ;; set a default stop point at the begin
6768 (setq pos (point))
6769 ;; is the start point inside the leader area ?
6770 (goto-char (vhdl-end-of-leader))
6771 (vhdl-forward-syntactic-ws here)
6772 (if (< (point) here)
6773 ;; start point was not inside leader area
6774 ;; set stop point at word after leader
6775 (setq pos (point))))
6776 (forward-word 1)
6777 (vhdl-forward-syntactic-ws here)
6778 (setq pos (point)))
6779 (goto-char pos)
6780 (setq donep t))
6781 ;; If we are looking at a "statement", then stop
6782 ((and (looking-at vhdl-statement-fwd-re)
6783 (/= (preceding-char) ?_)
6784 (vhdl-statement-p nil))
6785 (setq donep t))
6786 ;; If we are looking at a case alternative key, then stop
6787 ((and (looking-at vhdl-case-alternative-re)
6788 (vhdl-case-alternative-p lim))
6789 (save-excursion
6790 ;; set a default stop point at the when
6791 (setq pos (point))
6792 ;; is the start point inside the case alternative key ?
6793 (looking-at vhdl-case-alternative-re)
6794 (goto-char (match-end 0))
6795 (vhdl-forward-syntactic-ws here)
6796 (if (< (point) here)
6797 ;; start point was not inside the case alternative key
6798 ;; set stop point at word after case alternative keyleader
6799 (setq pos (point))))
6800 (goto-char pos)
6801 (setq donep t))
6802 ;; Bogus find, continue
6803 (t
6804 (backward-char)))))
6805 ))
6806
6807 ;; Defuns for calculating the current syntactic state:
6808
6809 (defun vhdl-get-library-unit (bod placeholder)
6810 "If there is an enclosing library unit at BOD, with its \"begin\"
6811 keyword at PLACEHOLDER, then return the library unit type."
6812 (let ((here (vhdl-point 'bol)))
6813 (if (save-excursion
6814 (goto-char placeholder)
6815 (vhdl-safe (vhdl-forward-sexp 1 bod))
6816 (<= here (point)))
6817 (save-excursion
6818 (goto-char bod)
6819 (cond
6820 ((looking-at "e") 'entity)
6821 ((looking-at "a") 'architecture)
6822 ((looking-at "conf") 'configuration)
6823 ((looking-at "cont") 'context)
6824 ((looking-at "p")
6825 (save-excursion
6826 (goto-char bod)
6827 (forward-sexp)
6828 (vhdl-forward-syntactic-ws here)
6829 (if (looking-at "body\\b[^_]")
6830 'package-body 'package))))))
6831 ))
6832
6833 (defun vhdl-get-block-state (&optional lim)
6834 "Finds and records all the closest opens.
6835 LIM is the furthest back we need to search (it should be the
6836 previous libunit keyword)."
6837 (let ((here (point))
6838 (lim (or lim (point-min)))
6839 keyword sexp-start sexp-mid sexp-end
6840 preceding-sexp containing-sexp
6841 containing-begin containing-mid containing-paren)
6842 (save-excursion
6843 ;; Find the containing-paren, and use that as the limit
6844 (if (setq containing-paren
6845 (save-restriction
6846 (narrow-to-region lim (point))
6847 (vhdl-safe (scan-lists (point) -1 1))))
6848 (setq lim containing-paren))
6849 ;; Look backwards for "begin" and "end" keywords.
6850 (while (and (> (point) lim)
6851 (not containing-sexp))
6852 (setq keyword (vhdl-backward-to-block lim))
6853 (cond
6854 ((eq keyword 'begin)
6855 ;; Found a "begin" keyword
6856 (setq sexp-start (point))
6857 (setq sexp-mid (vhdl-corresponding-mid lim))
6858 (setq sexp-end (vhdl-safe
6859 (save-excursion
6860 (vhdl-forward-sexp 1 lim) (point))))
6861 (if (and sexp-end (<= sexp-end here))
6862 ;; we want to record this sexp, but we only want to
6863 ;; record the last-most of any of them before here
6864 (or preceding-sexp
6865 (setq preceding-sexp sexp-start))
6866 ;; we're contained in this sexp so put sexp-start on
6867 ;; front of list
6868 (setq containing-sexp sexp-start)
6869 (setq containing-mid sexp-mid)
6870 (setq containing-begin t)))
6871 ((eq keyword 'end)
6872 ;; Found an "end" keyword
6873 (forward-sexp)
6874 (setq sexp-end (point))
6875 (setq sexp-mid nil)
6876 (setq sexp-start
6877 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6878 (progn (backward-sexp) (point))))
6879 ;; we want to record this sexp, but we only want to
6880 ;; record the last-most of any of them before here
6881 (or preceding-sexp
6882 (setq preceding-sexp sexp-start)))
6883 )))
6884 ;; Check if the containing-paren should be the containing-sexp
6885 (if (and containing-paren
6886 (or (null containing-sexp)
6887 (< containing-sexp containing-paren)))
6888 (setq containing-sexp containing-paren
6889 preceding-sexp nil
6890 containing-begin nil
6891 containing-mid nil))
6892 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6893 ))
6894
6895
6896 (defconst vhdl-s-c-a-re
6897 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6898
6899 (defun vhdl-skip-case-alternative (&optional lim)
6900 "Skip forward over case/when bodies, with optional maximal
6901 limit. If no next case alternative is found, nil is returned and
6902 point is not moved."
6903 (let ((lim (or lim (point-max)))
6904 (here (point))
6905 donep foundp)
6906 (while (and (< (point) lim)
6907 (not donep))
6908 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6909 (save-match-data
6910 (not (vhdl-in-literal)))
6911 (/= (match-beginning 0) here))
6912 (progn
6913 (goto-char (match-beginning 0))
6914 (cond
6915 ((and (looking-at "case")
6916 (re-search-forward "\\bis[^_]" lim t))
6917 (backward-sexp)
6918 (vhdl-forward-sexp))
6919 (t
6920 (setq donep t
6921 foundp t))))))
6922 (if (not foundp)
6923 (goto-char here))
6924 foundp))
6925
6926 (defun vhdl-backward-skip-label (&optional lim)
6927 "Skip backward over a label, with optional maximal
6928 limit. If label is not found, nil is returned and point
6929 is not moved."
6930 (let ((lim (or lim (point-min)))
6931 placeholder)
6932 (if (save-excursion
6933 (vhdl-backward-syntactic-ws lim)
6934 (and (eq (preceding-char) ?:)
6935 (progn
6936 (backward-sexp)
6937 (setq placeholder (point))
6938 (looking-at vhdl-label-key))))
6939 (goto-char placeholder))
6940 ))
6941
6942 (defun vhdl-forward-skip-label (&optional lim)
6943 "Skip forward over a label, with optional maximal
6944 limit. If label is not found, nil is returned and point
6945 is not moved."
6946 (let ((lim (or lim (point-max))))
6947 (if (looking-at vhdl-label-key)
6948 (progn
6949 (goto-char (match-end 0))
6950 (vhdl-forward-syntactic-ws lim)))
6951 ))
6952
6953 (defun vhdl-get-syntactic-context ()
6954 "Guess the syntactic description of the current line of VHDL code."
6955 (save-excursion
6956 (save-restriction
6957 (beginning-of-line)
6958 (let* ((indent-point (point))
6959 (case-fold-search t)
6960 vec literal containing-sexp preceding-sexp
6961 containing-begin containing-mid containing-leader
6962 char-before-ip char-after-ip begin-after-ip end-after-ip
6963 placeholder lim library-unit
6964 )
6965
6966 ;; Reset the syntactic context
6967 (setq vhdl-syntactic-context nil)
6968
6969 (save-excursion
6970 ;; Move to the start of the previous library unit, and
6971 ;; record the position of the "begin" keyword.
6972 (setq placeholder (vhdl-beginning-of-libunit))
6973 ;; The position of the "libunit" keyword gives us a gross
6974 ;; limit point.
6975 (setq lim (point))
6976 )
6977
6978 ;; If there is a previous library unit, and we are enclosed by
6979 ;; it, then set the syntax accordingly.
6980 (and placeholder
6981 (setq library-unit (vhdl-get-library-unit lim placeholder))
6982 (vhdl-add-syntax library-unit lim))
6983
6984 ;; Find the surrounding state.
6985 (if (setq vec (vhdl-get-block-state lim))
6986 (progn
6987 (setq containing-sexp (aref vec 0))
6988 (setq preceding-sexp (aref vec 1))
6989 (setq containing-begin (aref vec 2))
6990 (setq containing-mid (aref vec 3))
6991 ))
6992
6993 ;; set the limit on the farthest back we need to search
6994 (setq lim (if containing-sexp
6995 (save-excursion
6996 (goto-char containing-sexp)
6997 ;; set containing-leader if required
6998 (if (looking-at vhdl-leader-re)
6999 (setq containing-leader (vhdl-end-of-leader)))
7000 (vhdl-point 'bol))
7001 (point-min)))
7002
7003 ;; cache char before and after indent point, and move point to
7004 ;; the most likely position to perform the majority of tests
7005 (goto-char indent-point)
7006 (skip-chars-forward " \t")
7007 (setq literal (vhdl-in-literal))
7008 (setq char-after-ip (following-char))
7009 (setq begin-after-ip (and
7010 (not literal)
7011 (looking-at vhdl-begin-fwd-re)
7012 (or (not (looking-at "\\<use\\>"))
7013 (save-excursion
7014 (back-to-indentation)
7015 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
7016 (vhdl-begin-p)))
7017 (setq end-after-ip (and
7018 (not literal)
7019 (looking-at vhdl-end-fwd-re)
7020 (vhdl-end-p)))
7021 (vhdl-backward-syntactic-ws lim)
7022 (setq char-before-ip (preceding-char))
7023 (goto-char indent-point)
7024 (skip-chars-forward " \t")
7025
7026 ;; now figure out syntactic qualities of the current line
7027 (cond
7028 ;; CASE 1: in a string or comment.
7029 ((memq literal '(string comment))
7030 (vhdl-add-syntax literal (vhdl-point 'bopl)))
7031 ;; CASE 2: Line is at top level.
7032 ((null containing-sexp)
7033 ;; Find the point to which indentation will be relative
7034 (save-excursion
7035 (if (null preceding-sexp)
7036 ;; CASE 2X.1
7037 ;; no preceding-sexp -> use the preceding statement
7038 (vhdl-beginning-of-statement-1 lim)
7039 ;; CASE 2X.2
7040 ;; if there is a preceding-sexp then indent relative to it
7041 (goto-char preceding-sexp)
7042 ;; if not at boi, then the block-opening keyword is
7043 ;; probably following a label, so we need a different
7044 ;; relpos
7045 (if (/= (point) (vhdl-point 'boi))
7046 ;; CASE 2X.3
7047 (vhdl-beginning-of-statement-1 lim)))
7048 ;; v-b-o-s could have left us at point-min
7049 (and (bobp)
7050 ;; CASE 2X.4
7051 (vhdl-forward-syntactic-ws indent-point))
7052 (setq placeholder (point)))
7053 (cond
7054 ;; CASE 2A : we are looking at a block-open
7055 (begin-after-ip
7056 (vhdl-add-syntax 'block-open placeholder))
7057 ;; CASE 2B: we are looking at a block-close
7058 (end-after-ip
7059 (vhdl-add-syntax 'block-close placeholder))
7060 ;; CASE 2C: we are looking at a top-level statement
7061 ((progn
7062 (vhdl-backward-syntactic-ws lim)
7063 (or (bobp)
7064 (and (= (preceding-char) ?\;)
7065 (not (vhdl-in-quote-p)))))
7066 (vhdl-add-syntax 'statement placeholder))
7067 ;; CASE 2D: we are looking at a top-level statement-cont
7068 (t
7069 (vhdl-beginning-of-statement-1 lim)
7070 ;; v-b-o-s could have left us at point-min
7071 (and (bobp)
7072 ;; CASE 2D.1
7073 (vhdl-forward-syntactic-ws indent-point))
7074 (vhdl-add-syntax 'statement-cont (point)))
7075 )) ; end CASE 2
7076 ;; CASE 3: line is inside parentheses. Most likely we are
7077 ;; either in a subprogram argument (interface) list, or a
7078 ;; continued expression containing parentheses.
7079 ((null containing-begin)
7080 (vhdl-backward-syntactic-ws containing-sexp)
7081 (cond
7082 ;; CASE 3A: we are looking at the arglist closing paren
7083 ((eq char-after-ip ?\))
7084 (goto-char containing-sexp)
7085 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
7086 ;; CASE 3B: we are looking at the first argument in an empty
7087 ;; argument list.
7088 ((eq char-before-ip ?\()
7089 (goto-char containing-sexp)
7090 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
7091 ;; CASE 3C: we are looking at an arglist continuation line,
7092 ;; but the preceding argument is on the same line as the
7093 ;; opening paren. This case includes multi-line
7094 ;; expression paren groupings.
7095 ((and (save-excursion
7096 (goto-char (1+ containing-sexp))
7097 (skip-chars-forward " \t")
7098 (not (eolp))
7099 (not (looking-at "--\\|`")))
7100 (save-excursion
7101 (vhdl-beginning-of-statement-1 containing-sexp)
7102 (skip-chars-backward " \t(")
7103 (while (and (= (preceding-char) ?\;)
7104 (not (vhdl-in-quote-p)))
7105 (vhdl-beginning-of-statement-1 containing-sexp)
7106 (skip-chars-backward " \t("))
7107 (<= (point) containing-sexp)))
7108 (goto-char containing-sexp)
7109 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7110 ;; CASE 3D: we are looking at just a normal arglist
7111 ;; continuation line
7112 (t (vhdl-beginning-of-statement-1 containing-sexp)
7113 (vhdl-forward-syntactic-ws indent-point)
7114 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7115 ))
7116 ;; CASE 4: A block mid open
7117 ((and begin-after-ip
7118 (looking-at containing-mid))
7119 (goto-char containing-sexp)
7120 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7121 (if (looking-at vhdl-trailer-re)
7122 ;; CASE 4.1
7123 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7124 (vhdl-backward-skip-label (vhdl-point 'boi))
7125 (vhdl-add-syntax 'block-open (point)))
7126 ;; CASE 5: block close brace
7127 (end-after-ip
7128 (goto-char containing-sexp)
7129 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7130 (if (looking-at vhdl-trailer-re)
7131 ;; CASE 5.1
7132 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7133 (vhdl-backward-skip-label (vhdl-point 'boi))
7134 (vhdl-add-syntax 'block-close (point)))
7135 ;; CASE 6: A continued statement
7136 ((and (/= char-before-ip ?\;)
7137 ;; check it's not a trailer begin keyword, or a begin
7138 ;; keyword immediately following a label.
7139 (not (and begin-after-ip
7140 (or (looking-at vhdl-trailer-re)
7141 (save-excursion
7142 (vhdl-backward-skip-label containing-sexp)))))
7143 ;; check it's not a statement keyword
7144 (not (and (looking-at vhdl-statement-fwd-re)
7145 (vhdl-statement-p)))
7146 ;; see if the b-o-s is before the indent point
7147 (> indent-point
7148 (save-excursion
7149 (vhdl-beginning-of-statement-1 containing-sexp)
7150 ;; If we ended up after a leader, then this will
7151 ;; move us forward to the start of the first
7152 ;; statement. Note that a containing sexp here is
7153 ;; always a keyword, not a paren, so this will
7154 ;; have no effect if we hit the containing-sexp.
7155 (vhdl-forward-syntactic-ws indent-point)
7156 (setq placeholder (point))))
7157 ;; check it's not a block-intro
7158 (/= placeholder containing-sexp)
7159 ;; check it's not a case block-intro
7160 (save-excursion
7161 (goto-char placeholder)
7162 (or (not (looking-at vhdl-case-alternative-re))
7163 (> (match-end 0) indent-point))))
7164 ;; Make placeholder skip a label, but only if it puts us
7165 ;; before the indent point at the start of a line.
7166 (let ((new placeholder))
7167 (if (and (> indent-point
7168 (save-excursion
7169 (goto-char placeholder)
7170 (vhdl-forward-skip-label indent-point)
7171 (setq new (point))))
7172 (save-excursion
7173 (goto-char new)
7174 (eq new (progn (back-to-indentation) (point)))))
7175 (setq placeholder new)))
7176 (vhdl-add-syntax 'statement-cont placeholder)
7177 (if begin-after-ip
7178 (vhdl-add-syntax 'block-open)))
7179 ;; Statement. But what kind?
7180 ;; CASE 7: A case alternative key
7181 ((and (looking-at vhdl-case-alternative-re)
7182 (vhdl-case-alternative-p containing-sexp))
7183 ;; for a case alternative key, we set relpos to the first
7184 ;; non-whitespace char on the line containing the "case"
7185 ;; keyword.
7186 (goto-char containing-sexp)
7187 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7188 (if (looking-at vhdl-trailer-re)
7189 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7190 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7191 ;; CASE 8: statement catchall
7192 (t
7193 ;; we know its a statement, but we need to find out if it is
7194 ;; the first statement in a block
7195 (if containing-leader
7196 (goto-char containing-leader)
7197 (goto-char containing-sexp)
7198 ;; Note that a containing sexp here is always a keyword,
7199 ;; not a paren, so skip over the keyword.
7200 (forward-sexp))
7201 ;; move to the start of the first statement
7202 (vhdl-forward-syntactic-ws indent-point)
7203 (setq placeholder (point))
7204 ;; we want to ignore case alternatives keys when skipping forward
7205 (let (incase-p)
7206 (while (looking-at vhdl-case-alternative-re)
7207 (setq incase-p (point))
7208 ;; we also want to skip over the body of the
7209 ;; case/when statement if that doesn't put us at
7210 ;; after the indent-point
7211 (while (vhdl-skip-case-alternative indent-point))
7212 ;; set up the match end
7213 (looking-at vhdl-case-alternative-re)
7214 (goto-char (match-end 0))
7215 ;; move to the start of the first case alternative statement
7216 (vhdl-forward-syntactic-ws indent-point)
7217 (setq placeholder (point)))
7218 (cond
7219 ;; CASE 8A: we saw a case/when statement so we must be
7220 ;; in a switch statement. find out if we are at the
7221 ;; statement just after a case alternative key
7222 ((and incase-p
7223 (= (point) indent-point))
7224 ;; relpos is the "when" keyword
7225 (vhdl-add-syntax 'statement-case-intro incase-p))
7226 ;; CASE 8B: any old statement
7227 ((< (point) indent-point)
7228 ;; relpos is the first statement of the block
7229 (vhdl-add-syntax 'statement placeholder)
7230 (if begin-after-ip
7231 (vhdl-add-syntax 'block-open)))
7232 ;; CASE 8C: first statement in a block
7233 (t
7234 (goto-char containing-sexp)
7235 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7236 (if (looking-at vhdl-trailer-re)
7237 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7238 (vhdl-backward-skip-label (vhdl-point 'boi))
7239 (vhdl-add-syntax 'statement-block-intro (point))
7240 (if begin-after-ip
7241 (vhdl-add-syntax 'block-open)))
7242 )))
7243 )
7244
7245 ;; now we need to look at any modifiers
7246 (goto-char indent-point)
7247 (skip-chars-forward " \t")
7248 (if (or (looking-at "--") (looking-at "/\\*"))
7249 (vhdl-add-syntax 'comment))
7250 (if (looking-at "`")
7251 (vhdl-add-syntax 'directive))
7252 (if (eq literal 'pound)
7253 (vhdl-add-syntax 'cpp-macro))
7254 ;; return the syntax
7255 vhdl-syntactic-context))))
7256
7257 ;; Standard indentation line-ups:
7258
7259 (defun vhdl-lineup-arglist (langelem)
7260 "Lineup the current arglist line with the arglist appearing just
7261 after the containing paren which starts the arglist."
7262 (save-excursion
7263 (let* ((containing-sexp
7264 (save-excursion
7265 ;; arglist-cont-nonempty gives relpos ==
7266 ;; to boi of containing-sexp paren. This
7267 ;; is good when offset is +, but bad
7268 ;; when it is vhdl-lineup-arglist, so we
7269 ;; have to special case a kludge here.
7270 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7271 (progn
7272 (beginning-of-line)
7273 (backward-up-list 1)
7274 (skip-chars-forward " \t" (vhdl-point 'eol)))
7275 (goto-char (cdr langelem)))
7276 (point)))
7277 (cs-curcol (save-excursion
7278 (goto-char (cdr langelem))
7279 (current-column))))
7280 (if (save-excursion
7281 (beginning-of-line)
7282 (looking-at "[ \t]*)"))
7283 (progn (goto-char (match-end 0))
7284 (backward-sexp)
7285 (forward-char)
7286 (vhdl-forward-syntactic-ws)
7287 (- (current-column) cs-curcol))
7288 (goto-char containing-sexp)
7289 (or (eolp)
7290 (let ((eol (vhdl-point 'eol))
7291 (here (progn
7292 (forward-char)
7293 (skip-chars-forward " \t")
7294 (point))))
7295 (vhdl-forward-syntactic-ws)
7296 (if (< (point) eol)
7297 (goto-char here))))
7298 (- (current-column) cs-curcol)
7299 ))))
7300
7301 (defun vhdl-lineup-arglist-intro (langelem)
7302 "Lineup an arglist-intro line to just after the open paren."
7303 (save-excursion
7304 (let ((cs-curcol (save-excursion
7305 (goto-char (cdr langelem))
7306 (current-column)))
7307 (ce-curcol (save-excursion
7308 (beginning-of-line)
7309 (backward-up-list 1)
7310 (skip-chars-forward " \t" (vhdl-point 'eol))
7311 (current-column))))
7312 (- ce-curcol cs-curcol -1))))
7313
7314 (defun vhdl-lineup-comment (langelem)
7315 "Support old behavior for comment indentation. We look at
7316 vhdl-comment-only-line-offset to decide how to indent comment
7317 only-lines."
7318 (save-excursion
7319 (back-to-indentation)
7320 ;; at or to the right of comment-column
7321 (if (>= (current-column) comment-column)
7322 (vhdl-comment-indent)
7323 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7324 (if (not (bolp))
7325 ;; inside multi-line comment
7326 (if (looking-at "\\*")
7327 1
7328 ;; otherwise
7329 (or (car-safe vhdl-comment-only-line-offset)
7330 vhdl-comment-only-line-offset))
7331 (or (cdr-safe vhdl-comment-only-line-offset)
7332 (car-safe vhdl-comment-only-line-offset)
7333 -1000 ;jam it against the left side
7334 )))))
7335
7336 (defun vhdl-lineup-statement-cont (langelem)
7337 "Line up statement-cont after the assignment operator."
7338 (save-excursion
7339 (let* ((relpos (cdr langelem))
7340 (assignp (save-excursion
7341 (goto-char (vhdl-point 'boi))
7342 (and (re-search-forward "\\(<\\|:\\|=\\)="
7343 (vhdl-point 'eol) t)
7344 (- (point) (vhdl-point 'boi)))))
7345 (curcol (progn
7346 (goto-char relpos)
7347 (current-column)))
7348 foundp)
7349 (while (and (not foundp)
7350 (< (point) (vhdl-point 'eol)))
7351 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7352 (if (vhdl-in-literal)
7353 (forward-char)
7354 (if (= (preceding-char) ?\()
7355 ;; skip over any parenthesized expressions
7356 (goto-char (min (vhdl-point 'eol)
7357 (scan-lists (point) 1 1)))
7358 ;; found an assignment operator (not at eol)
7359 (setq foundp (not (looking-at "\\s-*$"))))))
7360 (if (not foundp)
7361 ;; there's no assignment operator on the line
7362 vhdl-basic-offset
7363 ;; calculate indentation column after assign and ws, unless
7364 ;; our line contains an assignment operator
7365 (if (not assignp)
7366 (progn
7367 (forward-char)
7368 (skip-chars-forward " \t")
7369 (setq assignp 0)))
7370 (- (current-column) assignp curcol))
7371 )))
7372
7373 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7374 ;; Progress reporting
7375
7376 (defvar vhdl-progress-info nil
7377 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7378
7379 (defun vhdl-update-progress-info (string pos)
7380 "Update progress information."
7381 (when (and vhdl-progress-info (not noninteractive)
7382 (< vhdl-progress-interval
7383 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7384 (let ((delta (- (aref vhdl-progress-info 1)
7385 (aref vhdl-progress-info 0))))
7386 (message "%s... (%2d%%)" string
7387 (if (= 0 delta)
7388 100
7389 (floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
7390 delta))))
7391 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7392
7393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7394 ;; Indentation commands
7395
7396 (defun vhdl-electric-tab (&optional prefix-arg)
7397 "If preceding character is part of a word or a paren then hippie-expand,
7398 else if right of non whitespace on line then insert tab,
7399 else if last command was a tab or return then dedent one step or if a comment
7400 toggle between normal indent and inline comment indent,
7401 else indent `correctly'."
7402 (interactive "*P")
7403 (vhdl-prepare-search-2
7404 (cond
7405 ;; indent region if region is active
7406 ((and (not (featurep 'xemacs)) (use-region-p))
7407 (vhdl-indent-region (region-beginning) (region-end) nil))
7408 ;; expand word
7409 ((= (char-syntax (preceding-char)) ?w)
7410 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7411 (case-replace nil)
7412 (hippie-expand-only-buffers
7413 (or (and (boundp 'hippie-expand-only-buffers)
7414 hippie-expand-only-buffers)
7415 '(vhdl-mode))))
7416 (vhdl-expand-abbrev prefix-arg)))
7417 ;; expand parenthesis
7418 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7419 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7420 (case-replace nil))
7421 (vhdl-expand-paren prefix-arg)))
7422 ;; insert tab
7423 ((> (current-column) (current-indentation))
7424 (insert-tab))
7425 ;; toggle comment indent
7426 ((and (looking-at "--")
7427 (or (eq last-command 'vhdl-electric-tab)
7428 (eq last-command 'vhdl-electric-return)))
7429 (cond ((= (current-indentation) 0) ; no indent
7430 (indent-to 1)
7431 (indent-according-to-mode))
7432 ((< (current-indentation) comment-column) ; normal indent
7433 (indent-to comment-column)
7434 (indent-according-to-mode))
7435 (t ; inline comment indent
7436 (delete-region (line-beginning-position) (point)))))
7437 ;; dedent
7438 ((and (>= (current-indentation) vhdl-basic-offset)
7439 (or (eq last-command 'vhdl-electric-tab)
7440 (eq last-command 'vhdl-electric-return)))
7441 (backward-delete-char-untabify vhdl-basic-offset nil))
7442 ;; indent line
7443 (t (indent-according-to-mode)))
7444 (setq this-command 'vhdl-electric-tab)))
7445
7446 (defun vhdl-electric-return ()
7447 "newline-and-indent or indent-new-comment-line if in comment and preceding
7448 character is a space."
7449 (interactive)
7450 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7451 (indent-new-comment-line)
7452 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7453 (not (vhdl-in-comment-p)))
7454 (vhdl-fix-case-word -1))
7455 (newline-and-indent)))
7456
7457 (defun vhdl-indent-line ()
7458 "Indent the current line as VHDL code. Returns the amount of
7459 indentation change."
7460 (interactive)
7461 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7462 (pos (- (point-max) (point)))
7463 (is-comment nil)
7464 (indent
7465 (if syntax
7466 ;; indent syntax-based
7467 (if (and (eq (caar syntax) 'comment)
7468 (>= (vhdl-get-offset (car syntax)) comment-column))
7469 ;; special case: comments at or right of comment-column
7470 (vhdl-get-offset (car syntax))
7471 ;; align comments like following code line
7472 (when vhdl-indent-comment-like-next-code-line
7473 (save-excursion
7474 (while (eq (caar syntax) 'comment)
7475 (setq is-comment t)
7476 (beginning-of-line 2)
7477 (setq syntax (vhdl-get-syntactic-context)))))
7478 (when is-comment
7479 (push (cons 'comment nil) syntax))
7480 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7481 ;; indent like previous nonblank line
7482 (save-excursion (beginning-of-line)
7483 (re-search-backward "^[^\n]" nil t)
7484 (current-indentation))))
7485 (shift-amt (- indent (current-indentation))))
7486 (and vhdl-echo-syntactic-information-p
7487 (message "syntax: %s, indent= %d" syntax indent))
7488 (let ((has-formfeed
7489 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7490 (when (or (not (zerop shift-amt)) has-formfeed)
7491 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7492 (beginning-of-line)
7493 (when has-formfeed (insert "\f"))
7494 (indent-to indent)))
7495 (if (< (point) (vhdl-point 'boi))
7496 (back-to-indentation)
7497 ;; If initial point was within line's indentation, position after
7498 ;; the indentation. Else stay at same point in text.
7499 (when (> (- (point-max) pos) (point))
7500 (goto-char (- (point-max) pos))))
7501 (run-hooks 'vhdl-special-indent-hook)
7502 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7503 shift-amt))
7504
7505 (defun vhdl-indent-region (beg end &optional column)
7506 "Indent region as VHDL code.
7507 Adds progress reporting to `indent-region'."
7508 (interactive "r\nP")
7509 (when vhdl-progress-interval
7510 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7511 (count-lines (point-min) end) 0)))
7512 (indent-region beg end column)
7513 (when vhdl-progress-interval (message "Indenting...done"))
7514 (setq vhdl-progress-info nil))
7515
7516 (defun vhdl-indent-buffer ()
7517 "Indent whole buffer as VHDL code.
7518 Calls `indent-region' for whole buffer and adds progress reporting."
7519 (interactive)
7520 (vhdl-indent-region (point-min) (point-max)))
7521
7522 (defun vhdl-indent-group ()
7523 "Indent group of lines between empty lines."
7524 (interactive)
7525 (let ((beg (save-excursion
7526 (if (re-search-backward vhdl-align-group-separate nil t)
7527 (point-marker)
7528 (point-min-marker))))
7529 (end (save-excursion
7530 (if (re-search-forward vhdl-align-group-separate nil t)
7531 (point-marker)
7532 (point-max-marker)))))
7533 (vhdl-indent-region beg end)))
7534
7535 (defun vhdl-indent-sexp (&optional endpos)
7536 "Indent each line of the list starting just after point.
7537 If optional arg ENDPOS is given, indent each line, stopping when
7538 ENDPOS is encountered."
7539 (interactive)
7540 (save-excursion
7541 (let ((beg (point))
7542 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7543 (indent-region beg end nil))))
7544
7545 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7546 ;; Miscellaneous commands
7547
7548 (defun vhdl-show-syntactic-information ()
7549 "Show syntactic information for current line."
7550 (interactive)
7551 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7552 (vhdl-keep-region-active))
7553
7554 ;; Verification and regression functions:
7555
7556 (defun vhdl-regress-line (&optional arg)
7557 "Check syntactic information for current line."
7558 (interactive "P")
7559 (let ((expected (save-excursion
7560 (end-of-line)
7561 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7562 (forward-char 4)
7563 (read (current-buffer)))))
7564 (actual (vhdl-get-syntactic-context))
7565 (expurgated))
7566 ;; remove the library unit symbols
7567 (mapc
7568 (function
7569 (lambda (elt)
7570 (if (memq (car elt) '(entity configuration context package
7571 package-body architecture))
7572 nil
7573 (setq expurgated (append expurgated (list elt))))))
7574 actual)
7575 (if (and (not arg) expected (listp expected))
7576 (if (not (equal expected expurgated))
7577 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7578 (save-excursion
7579 (beginning-of-line)
7580 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7581 (end-of-line)
7582 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7583 (delete-region (point) (line-end-position)))
7584 (insert " -- ")
7585 (insert (format "%s" expurgated))))))
7586 (vhdl-keep-region-active))
7587
7588
7589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7590 ;;; Alignment, beautifying
7591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7592
7593 (defconst vhdl-align-alist
7594 '(
7595 ;; after some keywords
7596 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7597 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7598 ;; before ':'
7599 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7600 ;; after direction specifications
7601 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7602 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7603 ;; before "==", ":=", "=>", and "<="
7604 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7605 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7606 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7607 ;; before some keywords
7608 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7609 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7610 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7611 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7612 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7613 ;; before "=>" since "when/else ... =>" can occur
7614 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7615 )
7616 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7617 It is searched in order. If REGEXP is found anywhere in the first
7618 line of a region to be aligned, ALIGN-PATTERN will be used for that
7619 region. ALIGN-PATTERN must include the whitespace to be expanded or
7620 contracted. It may also provide regexps for the text surrounding the
7621 whitespace. SUBEXP specifies which sub-expression of
7622 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7623
7624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7625 ;; Align code
7626
7627 (defvar vhdl-align-try-all-clauses t
7628 "If REGEXP is not found on the first line of the region that clause
7629 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7630
7631 (defun vhdl-do-group (function &optional spacing)
7632 "Apply FUNCTION on group of lines between empty lines."
7633 (let
7634 ;; search for group beginning
7635 ((beg (save-excursion
7636 (if (re-search-backward vhdl-align-group-separate nil t)
7637 (progn (beginning-of-line 2) (back-to-indentation) (point))
7638 (point-min))))
7639 ;; search for group end
7640 (end (save-excursion
7641 (if (re-search-forward vhdl-align-group-separate nil t)
7642 (progn (beginning-of-line) (point))
7643 (point-max)))))
7644 ;; run FUNCTION
7645 (funcall function beg end spacing)))
7646
7647 (defun vhdl-do-list (function &optional spacing)
7648 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7649 parentheses."
7650 (let (beg end)
7651 (save-excursion
7652 ;; search for beginning of balanced group of parentheses
7653 (setq beg (vhdl-re-search-backward "[()]" nil t))
7654 (while (looking-at ")")
7655 (forward-char) (backward-sexp)
7656 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7657 ;; search for end of balanced group of parentheses
7658 (when beg
7659 (forward-list)
7660 (setq end (point))
7661 (goto-char (1+ beg))
7662 (skip-chars-forward " \t\n\r\f")
7663 (setq beg (point))))
7664 ;; run FUNCTION
7665 (if beg
7666 (funcall function beg end spacing)
7667 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7668
7669 (defun vhdl-do-same-indent (function &optional spacing)
7670 "Apply FUNCTION to block of lines with same indent."
7671 (let ((indent (current-indentation))
7672 beg end)
7673 ;; search for first line with same indent
7674 (save-excursion
7675 (while (and (not (bobp))
7676 (or (looking-at "^\\s-*\\(--.*\\)?$")
7677 (= (current-indentation) indent)))
7678 (unless (looking-at "^\\s-*$")
7679 (back-to-indentation) (setq beg (point)))
7680 (beginning-of-line -0)))
7681 ;; search for last line with same indent
7682 (save-excursion
7683 (while (and (not (eobp))
7684 (or (looking-at "^\\s-*\\(--.*\\)?$")
7685 (= (current-indentation) indent)))
7686 (if (looking-at "^\\s-*$")
7687 (beginning-of-line 2)
7688 (beginning-of-line 2)
7689 (setq end (point)))))
7690 ;; run FUNCTION
7691 (funcall function beg end spacing)))
7692
7693 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7694 "Attempt to align a range of lines based on the content of the
7695 lines. The definition of `alignment-list' determines the matching
7696 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7697 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7698 indentation is done before aligning."
7699 (interactive "r\np")
7700 (setq alignment-list (or alignment-list vhdl-align-alist))
7701 (setq spacing (or spacing 1))
7702 (save-excursion
7703 (let (bol indent)
7704 (goto-char end)
7705 (setq end (point-marker))
7706 (goto-char begin)
7707 (setq bol (setq begin (progn (beginning-of-line) (point))))
7708 (when indent
7709 (indent-region bol end nil))))
7710 (let ((copy (copy-alist alignment-list)))
7711 (vhdl-prepare-search-2
7712 (while copy
7713 (save-excursion
7714 (goto-char begin)
7715 (let (element
7716 (eol (point-at-eol)))
7717 (setq element (nth 0 copy))
7718 (when (and (or (and (listp (car element))
7719 (memq major-mode (car element)))
7720 (eq major-mode (car element)))
7721 (or vhdl-align-try-all-clauses
7722 (re-search-forward (car (cdr element)) eol t)))
7723 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7724 (car (cdr (cdr (cdr element)))) spacing))
7725 (setq copy (cdr copy))))))))
7726
7727 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7728 "Align a range of lines from BEGIN to END. The regular expression
7729 MATCH must match exactly one field: the whitespace to be
7730 contracted/expanded. The alignment column will equal the
7731 rightmost column of the widest whitespace block. SPACING is
7732 the amount of extra spaces to add to the calculated maximum required.
7733 SPACING defaults to 1 so that at least one space is inserted after
7734 the token in MATCH."
7735 (setq spacing (or spacing 1))
7736 (setq substr (or substr 1))
7737 (save-excursion
7738 (let (distance (max 0) (lines 0) bol eol width)
7739 ;; Determine the greatest whitespace distance to the alignment
7740 ;; character
7741 (goto-char begin)
7742 (setq eol (point-at-eol)
7743 bol (setq begin (progn (beginning-of-line) (point))))
7744 (while (< bol end)
7745 (save-excursion
7746 (when (and (vhdl-re-search-forward match eol t)
7747 (save-excursion
7748 (goto-char (match-beginning 0))
7749 (forward-char)
7750 (and (not (vhdl-in-literal))
7751 (not (vhdl-in-quote-p))
7752 (not (vhdl-in-extended-identifier-p))))
7753 (not (looking-at "\\s-*$")))
7754 (setq distance (- (match-beginning substr) bol))
7755 (when (> distance max)
7756 (setq max distance))))
7757 (forward-line)
7758 (setq bol (point)
7759 eol (point-at-eol))
7760 (setq lines (1+ lines)))
7761 ;; Now insert enough maxs to push each assignment operator to
7762 ;; the same column. We need to use 'lines' as a counter, since
7763 ;; the location of the mark may change
7764 (goto-char (setq bol begin))
7765 (setq eol (point-at-eol))
7766 (while (> lines 0)
7767 (when (and (vhdl-re-search-forward match eol t)
7768 (save-excursion
7769 (goto-char (match-beginning 0))
7770 (forward-char)
7771 (and (not (vhdl-in-literal))
7772 (not (vhdl-in-quote-p))
7773 (not (vhdl-in-extended-identifier-p))))
7774 (not (looking-at "\\s-*$"))
7775 (> (match-beginning 0) ; not if at boi
7776 (save-excursion (back-to-indentation) (point))))
7777 (setq width (- (match-end substr) (match-beginning substr)))
7778 (setq distance (- (match-beginning substr) bol))
7779 (goto-char (match-beginning substr))
7780 (delete-char width)
7781 (insert-char ? (+ (- max distance) spacing)))
7782 (beginning-of-line)
7783 (forward-line)
7784 (setq bol (point)
7785 eol (point-at-eol))
7786 (setq lines (1- lines))))))
7787
7788 (defun vhdl-align-region-groups (beg end &optional spacing
7789 no-message no-comments)
7790 "Align region, treat groups of lines separately."
7791 (interactive "r\nP")
7792 (save-excursion
7793 (let (orig pos)
7794 (goto-char beg)
7795 (beginning-of-line)
7796 (setq orig (point-marker))
7797 (setq beg (point))
7798 (goto-char end)
7799 (setq end (point-marker))
7800 (untabify beg end)
7801 (unless no-message
7802 (when vhdl-progress-interval
7803 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7804 (count-lines (point-min) end) 0))))
7805 (when (nth 0 vhdl-beautify-options)
7806 (vhdl-fixup-whitespace-region beg end t))
7807 (goto-char beg)
7808 (if (not vhdl-align-groups)
7809 ;; align entire region
7810 (progn (vhdl-align-region-1 beg end spacing)
7811 (unless no-comments
7812 (vhdl-align-inline-comment-region-1 beg end)))
7813 ;; align groups
7814 (while (and (< beg end)
7815 (re-search-forward vhdl-align-group-separate end t))
7816 (setq pos (point-marker))
7817 (vhdl-align-region-1 beg pos spacing)
7818 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7819 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7820 (setq beg (1+ pos))
7821 (goto-char beg))
7822 ;; align last group
7823 (when (< beg end)
7824 (vhdl-align-region-1 beg end spacing)
7825 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7826 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7827 (when vhdl-indent-tabs-mode
7828 (tabify orig end))
7829 (unless no-message
7830 (when vhdl-progress-interval (message "Aligning...done"))
7831 (setq vhdl-progress-info nil)))))
7832
7833 (defun vhdl-align-region (beg end &optional spacing)
7834 "Align region, treat blocks with same indent and argument lists separately."
7835 (interactive "r\nP")
7836 (if (not vhdl-align-same-indent)
7837 ;; align entire region
7838 (vhdl-align-region-groups beg end spacing)
7839 ;; align blocks with same indent and argument lists
7840 (save-excursion
7841 (let ((cur-beg beg)
7842 indent cur-end)
7843 (when vhdl-progress-interval
7844 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7845 (count-lines (point-min) end) 0)))
7846 (goto-char end)
7847 (setq end (point-marker))
7848 (goto-char cur-beg)
7849 (while (< (point) end)
7850 ;; is argument list opening?
7851 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7852 (point) (vhdl-point 'eol)))))
7853 ;; determine region for argument list
7854 (progn (goto-char cur-beg)
7855 (forward-sexp)
7856 (setq cur-end (point))
7857 (beginning-of-line 2))
7858 ;; determine region with same indent
7859 (setq indent (current-indentation))
7860 (setq cur-beg (point))
7861 (setq cur-end (vhdl-point 'bonl))
7862 (beginning-of-line 2)
7863 (while (and (< (point) end)
7864 (or (looking-at "^\\s-*\\(--.*\\)?$")
7865 (= (current-indentation) indent))
7866 (<= (save-excursion
7867 (nth 0 (parse-partial-sexp
7868 (point) (vhdl-point 'eol)))) 0))
7869 (unless (looking-at "^\\s-*$")
7870 (setq cur-end (vhdl-point 'bonl)))
7871 (beginning-of-line 2)))
7872 ;; align region
7873 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7874 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7875 (when vhdl-progress-interval (message "Aligning...done"))
7876 (setq vhdl-progress-info nil)))))
7877
7878 (defun vhdl-align-group (&optional spacing)
7879 "Align group of lines between empty lines."
7880 (interactive)
7881 (vhdl-do-group 'vhdl-align-region spacing))
7882
7883 (defun vhdl-align-list (&optional spacing)
7884 "Align the lines of a list surrounded by a balanced group of parentheses."
7885 (interactive)
7886 (vhdl-do-list 'vhdl-align-region-groups spacing))
7887
7888 (defun vhdl-align-same-indent (&optional spacing)
7889 "Align block of lines with same indent."
7890 (interactive)
7891 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7892
7893 (defun vhdl-align-declarations (&optional spacing)
7894 "Align the lines within the declarative part of a design unit."
7895 (interactive)
7896 (let (beg end)
7897 (vhdl-prepare-search-2
7898 (save-excursion
7899 ;; search for declarative part
7900 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
7901 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7902 (setq beg (point))
7903 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7904 (setq end (point)))))
7905 (if beg
7906 (vhdl-align-region-groups beg end spacing)
7907 (error "ERROR: Not within the declarative part of a design unit"))))
7908
7909 (defun vhdl-align-buffer ()
7910 "Align buffer."
7911 (interactive)
7912 (vhdl-align-region (point-min) (point-max)))
7913
7914 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7915 ;; Align inline comments
7916
7917 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7918 "Align inline comments in region."
7919 (save-excursion
7920 (let ((start-max comment-column)
7921 (length-max 0)
7922 comment-list start-list tmp-list start length
7923 cur-start prev-start no-code)
7924 (setq spacing (or spacing 2))
7925 (vhdl-prepare-search-2
7926 (goto-char beg)
7927 ;; search for comment start positions and lengths
7928 (while (< (point) end)
7929 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7930 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7931 (not (save-excursion (goto-char (match-beginning 2))
7932 (vhdl-in-literal))))
7933 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7934 (setq length (- (match-end 2) (match-beginning 2)))
7935 (setq start-max (max start start-max))
7936 (setq length-max (max length length-max))
7937 (push (cons start length) comment-list))
7938 (beginning-of-line 2))
7939 (setq comment-list
7940 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7941 ;; reduce start positions
7942 (setq start-list (list (caar comment-list)))
7943 (setq comment-list (cdr comment-list))
7944 (while comment-list
7945 (unless (or (= (caar comment-list) (car start-list))
7946 (<= (+ (car start-list) (cdar comment-list))
7947 end-comment-column))
7948 (push (caar comment-list) start-list))
7949 (setq comment-list (cdr comment-list)))
7950 ;; align lines as nicely as possible
7951 (goto-char beg)
7952 (while (< (point) end)
7953 (setq cur-start nil)
7954 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7955 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7956 (not (save-excursion
7957 (goto-char (match-beginning 3))
7958 (vhdl-in-literal))))
7959 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7960 (>= (- (match-end 2) (match-beginning 2))
7961 comment-column))))
7962 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7963 (setq length (- (match-end 3) (match-beginning 3)))
7964 (setq no-code (= (match-beginning 1) (match-end 1)))
7965 ;; insert minimum whitespace
7966 (goto-char (match-end 2))
7967 (delete-region (match-beginning 2) (match-end 2))
7968 (insert-char ?\ spacing)
7969 (setq tmp-list start-list)
7970 ;; insert additional whitespace to align
7971 (setq cur-start
7972 (cond
7973 ;; align comment-only line to inline comment of previous line
7974 ((and no-code prev-start
7975 (<= length (- end-comment-column prev-start)))
7976 prev-start)
7977 ;; align all comments at `start-max' if this is possible
7978 ((<= (+ start-max length-max) end-comment-column)
7979 start-max)
7980 ;; align at `comment-column' if possible
7981 ((and (<= start comment-column)
7982 (<= length (- end-comment-column comment-column)))
7983 comment-column)
7984 ;; align at left-most possible start position otherwise
7985 (t
7986 (while (and tmp-list (< (car tmp-list) start))
7987 (setq tmp-list (cdr tmp-list)))
7988 (car tmp-list))))
7989 (indent-to cur-start))
7990 (setq prev-start cur-start)
7991 (beginning-of-line 2))))))
7992
7993 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7994 "Align inline comments within a region. Groups of code lines separated by
7995 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7996 (interactive "r\nP")
7997 (save-excursion
7998 (let (orig pos)
7999 (goto-char beg)
8000 (beginning-of-line)
8001 (setq orig (point-marker))
8002 (setq beg (point))
8003 (goto-char end)
8004 (setq end (point-marker))
8005 (untabify beg end)
8006 (unless no-message (message "Aligning inline comments..."))
8007 (goto-char beg)
8008 (if (not vhdl-align-groups)
8009 ;; align entire region
8010 (vhdl-align-inline-comment-region-1 beg end spacing)
8011 ;; align groups
8012 (while (and (< beg end)
8013 (re-search-forward vhdl-align-group-separate end t))
8014 (setq pos (point-marker))
8015 (vhdl-align-inline-comment-region-1 beg pos spacing)
8016 (setq beg (1+ pos))
8017 (goto-char beg))
8018 ;; align last group
8019 (when (< beg end)
8020 (vhdl-align-inline-comment-region-1 beg end spacing)))
8021 (when vhdl-indent-tabs-mode
8022 (tabify orig end))
8023 (unless no-message (message "Aligning inline comments...done")))))
8024
8025 (defun vhdl-align-inline-comment-group (&optional spacing)
8026 "Align inline comments within a group of lines between empty lines."
8027 (interactive)
8028 (save-excursion
8029 (let ((start (point))
8030 beg end)
8031 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
8032 (point-marker) (point-max)))
8033 (goto-char start)
8034 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
8035 (point) (point-min)))
8036 (untabify beg end)
8037 (message "Aligning inline comments...")
8038 (vhdl-align-inline-comment-region-1 beg end)
8039 (when vhdl-indent-tabs-mode
8040 (tabify beg end))
8041 (message "Aligning inline comments...done"))))
8042
8043 (defun vhdl-align-inline-comment-buffer ()
8044 "Align inline comments within buffer. Groups of code lines separated by
8045 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8046 (interactive)
8047 (vhdl-align-inline-comment-region (point-min) (point-max)))
8048
8049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8050 ;; Fixup whitespace
8051
8052 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
8053 "Fixup whitespace in region. Surround operator symbols by one space,
8054 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8055 end of line, do nothing in comments and strings."
8056 (interactive "r")
8057 (unless no-message (message "Fixing up whitespace..."))
8058 (save-excursion
8059 (goto-char end)
8060 (setq end (point-marker))
8061 ;; have no space before and one space after `,' and ';'
8062 (goto-char beg)
8063 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
8064 (if (match-string 1)
8065 (goto-char (match-end 1))
8066 (replace-match "\\3 " nil nil nil 2)))
8067 ;; have no space after `('
8068 (goto-char beg)
8069 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
8070 (if (match-string 1)
8071 (goto-char (match-end 1))
8072 (replace-match "\\2")))
8073 ;; have no space before `)'
8074 (goto-char beg)
8075 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
8076 (if (match-string 1)
8077 (goto-char (match-end 1))
8078 (replace-match "\\2")))
8079 ;; surround operator symbols by one space
8080 (goto-char beg)
8081 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
8082 (if (or (match-string 1)
8083 (<= (match-beginning 0) ; not if at boi
8084 (save-excursion (back-to-indentation) (point))))
8085 (goto-char (match-end 0))
8086 (replace-match "\\3 \\4 \\5")
8087 (goto-char (match-end 2))))
8088 ;; eliminate multiple spaces and spaces at end of line
8089 (goto-char beg)
8090 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
8091 (and (looking-at "--.*") (re-search-forward "--.*" end t))
8092 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
8093 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
8094 (progn (replace-match "" nil nil) t))
8095 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
8096 (progn (replace-match ";" nil nil) t))
8097 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
8098 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
8099 (progn (replace-match " " nil nil) t))
8100 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
8101 (progn (replace-match " " nil nil) t))
8102 (and (looking-at "-") (re-search-forward "-" end t))
8103 (re-search-forward "[^ \t\"-]+" end t))))
8104 (unless no-message (message "Fixing up whitespace...done")))
8105
8106 (defun vhdl-fixup-whitespace-buffer ()
8107 "Fixup whitespace in buffer. Surround operator symbols by one space,
8108 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8109 end of line, do nothing in comments."
8110 (interactive)
8111 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8112
8113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8114 ;; Case fixing
8115
8116 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8117 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8118 depending on parameter UPPER-CASE."
8119 (let ((case-replace nil)
8120 (last-update 0))
8121 (vhdl-prepare-search-2
8122 (save-excursion
8123 (goto-char end)
8124 (setq end (point-marker))
8125 (goto-char beg)
8126 (while (re-search-forward word-regexp end t)
8127 (or (vhdl-in-literal)
8128 (if upper-case
8129 (upcase-word -1)
8130 (downcase-word -1)))
8131 (when (and count vhdl-progress-interval (not noninteractive)
8132 (< vhdl-progress-interval
8133 (- (nth 1 (current-time)) last-update)))
8134 (message "Fixing case... (%2d%s)"
8135 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8136 "%")
8137 (setq last-update (nth 1 (current-time)))))
8138 (goto-char end)))))
8139
8140 (defun vhdl-fix-case-region (beg end &optional arg)
8141 "Convert all VHDL words in region to lower or upper case, depending on
8142 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8143 (interactive "r\nP")
8144 (vhdl-fix-case-region-1
8145 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8146 (vhdl-fix-case-region-1
8147 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8148 (vhdl-fix-case-region-1
8149 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8150 (vhdl-fix-case-region-1
8151 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8152 (vhdl-fix-case-region-1
8153 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8154 (when vhdl-progress-interval (message "Fixing case...done")))
8155
8156 (defun vhdl-fix-case-buffer ()
8157 "Convert all VHDL words in buffer to lower or upper case, depending on
8158 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8159 (interactive)
8160 (vhdl-fix-case-region (point-min) (point-max)))
8161
8162 (defun vhdl-fix-case-word (&optional arg)
8163 "Convert word after cursor to upper case if necessary."
8164 (interactive "p")
8165 (save-excursion
8166 (when arg (backward-word 1))
8167 (vhdl-prepare-search-1
8168 (when (and vhdl-upper-case-keywords
8169 (looking-at vhdl-keywords-regexp))
8170 (upcase-word 1))
8171 (when (and vhdl-upper-case-types
8172 (looking-at vhdl-types-regexp))
8173 (upcase-word 1))
8174 (when (and vhdl-upper-case-attributes
8175 (looking-at vhdl-attributes-regexp))
8176 (upcase-word 1))
8177 (when (and vhdl-upper-case-enum-values
8178 (looking-at vhdl-enum-values-regexp))
8179 (upcase-word 1))
8180 (when (and vhdl-upper-case-constants
8181 (looking-at vhdl-constants-regexp))
8182 (upcase-word 1)))))
8183
8184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8185 ;; Fix statements
8186 ;; - force each statement to be on a separate line except when on same line
8187 ;; with 'end' keyword
8188
8189 (defun vhdl-fix-statement-region (beg end &optional arg)
8190 "Force statements in region on separate line except when on same line
8191 with 'end' keyword (necessary for correct indentation).
8192 Currently supported keywords: 'begin', 'if'."
8193 (interactive "r\nP")
8194 (vhdl-prepare-search-2
8195 (let (point)
8196 (save-excursion
8197 (goto-char end)
8198 (setq end (point-marker))
8199 (goto-char beg)
8200 ;; `begin' keyword
8201 (while (re-search-forward
8202 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8203 (goto-char (match-end 0))
8204 (setq point (point-marker))
8205 (when (and (match-string 1)
8206 (or (not (match-string 2))
8207 (save-excursion (goto-char (match-end 2))
8208 (vhdl-in-literal)))
8209 (not (save-excursion (goto-char (match-beginning 1))
8210 (vhdl-in-literal))))
8211 (goto-char (match-beginning 1))
8212 (insert "\n")
8213 (indent-according-to-mode))
8214 (goto-char point))
8215 (goto-char beg)
8216 ;; `for', `if' keywords
8217 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8218 (goto-char (match-end 1))
8219 (setq point (point-marker))
8220 ;; exception: in literal or preceded by `end', `wait' or label
8221 (when (and (not (save-excursion (goto-char (match-beginning 1))
8222 (vhdl-in-literal)))
8223 (save-excursion
8224 (beginning-of-line 1)
8225 (save-match-data
8226 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8227 (match-beginning 1) t)
8228 (not (string-match
8229 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8230 (match-string 1)))))))
8231 (goto-char (match-beginning 1))
8232 (insert "\n")
8233 (indent-according-to-mode))
8234 (goto-char point))))))
8235
8236 (defun vhdl-fix-statement-buffer ()
8237 "Force statements in buffer on separate line except when on same line
8238 with 'end' keyword (necessary for correct indentation)."
8239 (interactive)
8240 (vhdl-fix-statement-region (point-min) (point-max)))
8241
8242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8243 ;; Trailing spaces
8244
8245 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8246 "Remove trailing spaces in region."
8247 (interactive "r\nP")
8248 (save-excursion
8249 (goto-char end)
8250 (setq end (point-marker))
8251 (goto-char beg)
8252 (while (re-search-forward "[ \t]+$" end t)
8253 (unless (vhdl-in-literal)
8254 (replace-match "" nil nil)))))
8255
8256 (defun vhdl-remove-trailing-spaces ()
8257 "Remove trailing spaces in buffer."
8258 (interactive)
8259 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8260
8261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8262 ;; Beautify
8263
8264 (defun vhdl-beautify-region (beg end)
8265 "Beautify region by applying indentation, whitespace fixup, alignment, and
8266 case fixing to a region. Calls functions `vhdl-indent-buffer',
8267 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8268 `vhdl-fix-case-buffer'."
8269 (interactive "r")
8270 (setq end (save-excursion (goto-char end) (point-marker)))
8271 (save-excursion ; remove DOS EOL characters in UNIX file
8272 (goto-char beg)
8273 (while (search-forward "\r" nil t)
8274 (replace-match "" nil t)))
8275 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8276 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8277 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8278 (when (nth 3 vhdl-beautify-options)
8279 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8280 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8281 (when (nth 0 vhdl-beautify-options)
8282 (vhdl-remove-trailing-spaces-region beg end)
8283 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8284
8285 (defun vhdl-beautify-buffer ()
8286 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8287 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8288 buffer."
8289 (interactive)
8290 (vhdl-beautify-region (point-min) (point-max))
8291 (when noninteractive (save-buffer)))
8292
8293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8294 ;; Code filling
8295
8296 (defun vhdl-fill-region (beg end &optional arg)
8297 "Fill lines for a region of code."
8298 (interactive "r\np")
8299 (save-excursion
8300 (goto-char beg)
8301 (let ((margin (if arg (current-indentation) (current-column))))
8302 (goto-char end)
8303 (setq end (point-marker))
8304 ;; remove inline comments, newlines and whitespace
8305 (vhdl-comment-kill-region beg end)
8306 (vhdl-comment-kill-inline-region beg end)
8307 (subst-char-in-region beg (1- end) ?\n ?\ )
8308 (vhdl-fixup-whitespace-region beg end)
8309 ;; wrap and end-comment-column
8310 (goto-char beg)
8311 (while (re-search-forward "\\s-" end t)
8312 (when(> (current-column) vhdl-end-comment-column)
8313 (backward-char)
8314 (when (re-search-backward "\\s-" beg t)
8315 (replace-match "\n")
8316 (indent-to margin)))))))
8317
8318 (defun vhdl-fill-group ()
8319 "Fill group of lines between empty lines."
8320 (interactive)
8321 (vhdl-do-group 'vhdl-fill-region))
8322
8323 (defun vhdl-fill-list ()
8324 "Fill the lines of a list surrounded by a balanced group of parentheses."
8325 (interactive)
8326 (vhdl-do-list 'vhdl-fill-region))
8327
8328 (defun vhdl-fill-same-indent ()
8329 "Fill the lines of block of lines with same indent."
8330 (interactive)
8331 (vhdl-do-same-indent 'vhdl-fill-region))
8332
8333
8334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8335 ;;; Code updating/fixing
8336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8337
8338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8339 ;; Sensitivity list update
8340
8341 ;; Strategy:
8342 ;; - no sensitivity list is generated for processes with wait statements
8343 ;; - otherwise, do the following:
8344 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8345 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8346 ;; manually entered global signals)
8347 ;; 3. signals from 1. and 2. form the list of visible signals
8348 ;; 4. search for if/elsif conditions containing an event (sequential code)
8349 ;; 5. scan for strings that are within syntactical regions where signals are
8350 ;; read but not within sequential code, and that correspond to visible
8351 ;; signals
8352 ;; 6. replace sensitivity list by list of signals from 5.
8353
8354 (defun vhdl-update-sensitivity-list-process ()
8355 "Update sensitivity list of current process."
8356 (interactive)
8357 (save-excursion
8358 (vhdl-prepare-search-2
8359 (end-of-line)
8360 ;; look whether in process
8361 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8362 (equal (upcase (match-string 2)) "PROCESS")
8363 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8364 (error "ERROR: Not within a process")
8365 (message "Updating sensitivity list...")
8366 (vhdl-update-sensitivity-list)
8367 (message "Updating sensitivity list...done")))))
8368
8369 (defun vhdl-update-sensitivity-list-buffer ()
8370 "Update sensitivity list of all processes in current buffer."
8371 (interactive)
8372 (save-excursion
8373 (vhdl-prepare-search-2
8374 (goto-char (point-min))
8375 (message "Updating sensitivity lists...")
8376 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8377 (goto-char (match-beginning 0))
8378 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8379 (message "Updating sensitivity lists...done")))
8380 (when noninteractive (save-buffer)))
8381
8382 (defun vhdl-update-sensitivity-list ()
8383 "Update sensitivity list."
8384 (let ((proc-beg (point))
8385 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8386 (proc-mid (vhdl-re-search-backward
8387 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8388 seq-region-list)
8389 (cond
8390 ;; error if 'begin' keyword missing
8391 ((not (match-string 2))
8392 (error "ERROR: No 'begin' keyword found"))
8393 ;; search for wait statement (no sensitivity list allowed)
8394 ((progn (goto-char proc-mid)
8395 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8396 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8397 ;; combinational process (update sensitivity list)
8398 (t
8399 (let
8400 ;; scan for visible signals
8401 ((visible-list (vhdl-get-visible-signals))
8402 ;; define syntactic regions where signals are read
8403 (scan-regions-list
8404 '(;; right-hand side of signal/variable assignment
8405 ;; (special case: "<=" is relational operator in a condition)
8406 ((vhdl-re-search-forward "[<:]=" proc-end t)
8407 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8408 ;; if condition
8409 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8410 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8411 ;; elsif condition
8412 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8413 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8414 ;; while loop condition
8415 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8416 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8417 ;; exit/next condition
8418 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8419 (vhdl-re-search-forward ";" proc-end t))
8420 ;; assert condition
8421 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8422 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8423 ;; case expression
8424 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8425 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8426 ;; parameter list of procedure call, array index
8427 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8428 (1- (point)))
8429 (progn (backward-char) (forward-sexp)
8430 (while (looking-at "(") (forward-sexp)) (point)))))
8431 name field read-list sens-list signal-list tmp-list
8432 sens-beg sens-end beg end margin)
8433 ;; scan for signals in old sensitivity list
8434 (goto-char proc-beg)
8435 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8436 (if (not (looking-at "[ \t\n\r\f]*("))
8437 (setq sens-beg (point))
8438 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8439 (goto-char (match-end 1))
8440 (forward-sexp)
8441 (setq sens-end (1- (point)))
8442 (goto-char sens-beg)
8443 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8444 (setq sens-list
8445 (cons (downcase (match-string 0)) sens-list))
8446 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8447 (setq signal-list (append visible-list sens-list))
8448 ;; search for sequential parts
8449 (goto-char proc-mid)
8450 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8451 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8452 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8453 (goto-char end)
8454 (backward-word 1)
8455 (vhdl-forward-sexp)
8456 (push (cons end (point)) seq-region-list)
8457 (beginning-of-line)))
8458 ;; scan for signals read in process
8459 (while scan-regions-list
8460 (goto-char proc-mid)
8461 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8462 (setq end (eval (nth 1 (car scan-regions-list)))))
8463 (goto-char beg)
8464 (unless (or (vhdl-in-literal)
8465 (and seq-region-list
8466 (let ((tmp-list seq-region-list))
8467 (while (and tmp-list
8468 (< (point) (caar tmp-list)))
8469 (setq tmp-list (cdr tmp-list)))
8470 (and tmp-list (< (point) (cdar tmp-list))))))
8471 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8472 (setq name (match-string 1))
8473 ;; get array index range
8474 (when vhdl-array-index-record-field-in-sensitivity-list
8475 (setq field (match-string 2))
8476 ;; not use if it includes a variable name
8477 (save-match-data
8478 (setq tmp-list visible-list)
8479 (while (and field tmp-list)
8480 (when (string-match
8481 (concat "\\<" (car tmp-list) "\\>") field)
8482 (setq field nil))
8483 (setq tmp-list (cdr tmp-list)))))
8484 (when (and (not (match-string 6)) ; not when formal parameter
8485 (not (and (match-string 5) ; not event attribute
8486 (not (member (downcase (match-string 5))
8487 '("event" "last_event" "transaction")))))
8488 (member (downcase name) signal-list))
8489 ;; not add if name or name+field already exists
8490 (unless
8491 (or (member-ignore-case name read-list)
8492 (member-ignore-case (concat name field) read-list))
8493 (push (concat name field) read-list))
8494 (setq tmp-list read-list)
8495 ;; remove existing name+field if name is added
8496 (save-match-data
8497 (while tmp-list
8498 (when (string-match (concat "^" name field "[(.]")
8499 (car tmp-list))
8500 (setq read-list (delete (car tmp-list) read-list)))
8501 (setq tmp-list (cdr tmp-list)))))
8502 (goto-char (match-end 1)))))
8503 (setq scan-regions-list (cdr scan-regions-list)))
8504 ;; update sensitivity list
8505 (goto-char sens-beg)
8506 (if sens-end
8507 (delete-region sens-beg sens-end)
8508 (when read-list
8509 (insert " ()") (backward-char)))
8510 (setq read-list (sort read-list 'string<))
8511 (when read-list
8512 (setq margin (current-column))
8513 (insert (car read-list))
8514 (setq read-list (cdr read-list))
8515 (while read-list
8516 (insert ",")
8517 (if (<= (+ (current-column) (length (car read-list)) 2)
8518 end-comment-column)
8519 (insert " ")
8520 (insert "\n") (indent-to margin))
8521 (insert (car read-list))
8522 (setq read-list (cdr read-list)))))))))
8523
8524 (defun vhdl-get-visible-signals ()
8525 "Get all signals visible in the current block."
8526 (let (beg end signal-list entity-name file-name)
8527 (vhdl-prepare-search-2
8528 ;; get entity name
8529 (save-excursion
8530 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8531 (not (equal "END" (upcase (match-string 1))))
8532 (setq entity-name (match-string 2)))
8533 (error "ERROR: Not within an architecture")))
8534 ;; search for signals declared in entity port clause
8535 (save-excursion
8536 (goto-char (point-min))
8537 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8538 (setq file-name
8539 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8540 "." (file-name-extension (buffer-file-name)))))
8541 (vhdl-visit-file
8542 file-name t
8543 (vhdl-prepare-search-2
8544 (goto-char (point-min))
8545 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8546 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8547 (when (setq beg (vhdl-re-search-forward
8548 "\\<port[ \t\n\r\f]*("
8549 (save-excursion
8550 (re-search-forward "^end\\>" nil t)) t))
8551 (setq end (save-excursion
8552 (backward-char) (forward-sexp) (point)))
8553 (vhdl-forward-syntactic-ws)
8554 (while (< (point) end)
8555 (when (looking-at "signal[ \t\n\r\f]+")
8556 (goto-char (match-end 0)))
8557 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8558 (setq signal-list
8559 (cons (downcase (match-string 1)) signal-list))
8560 (goto-char (match-end 0))
8561 (vhdl-forward-syntactic-ws))
8562 (re-search-forward ";" end 1)
8563 (vhdl-forward-syntactic-ws)))))))
8564 ;; search for signals declared in architecture declarative part
8565 (save-excursion
8566 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8567 (not (equal "END" (upcase (match-string 1))))
8568 (setq end (re-search-forward "^begin\\>" nil t))))
8569 (error "ERROR: No architecture declarative part found")
8570 ;; scan for all declared signal and alias names
8571 (goto-char beg)
8572 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8573 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8574 (if (match-string 2)
8575 ;; scan signal name
8576 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8577 (setq signal-list
8578 (cons (downcase (match-string 1)) signal-list))
8579 (goto-char (match-end 0)))
8580 ;; scan alias name, check is alias of (declared) signal
8581 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8582 (member (downcase (match-string 2)) signal-list))
8583 (setq signal-list
8584 (cons (downcase (match-string 1)) signal-list))
8585 (goto-char (match-end 0))))
8586 (setq beg (point))))))
8587 ;; search for signals declared in surrounding block declarative parts
8588 (save-excursion
8589 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8590 (match-string 4))
8591 (goto-char (match-end 4))
8592 (vhdl-backward-sexp)
8593 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8594 beg)
8595 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8596 ;; scan for all declared signal names
8597 (goto-char beg)
8598 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8599 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8600 (if (match-string 2)
8601 ;; scan signal name
8602 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8603 (setq signal-list
8604 (cons (downcase (match-string 1)) signal-list))
8605 (goto-char (match-end 0)))
8606 ;; scan alias name, check is alias of (declared) signal
8607 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8608 (member (downcase (match-string 2)) signal-list))
8609 (setq signal-list
8610 (cons (downcase (match-string 1)) signal-list))
8611 (goto-char (match-end 0))))))
8612 (goto-char beg)))
8613 signal-list)))
8614
8615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8616 ;; Generic/port clause fixing
8617
8618 (defun vhdl-fix-clause-buffer ()
8619 "Fix all generic/port clauses in current buffer."
8620 (interactive)
8621 (save-excursion
8622 (vhdl-prepare-search-2
8623 (goto-char (point-min))
8624 (message "Fixing generic/port clauses...")
8625 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8626 (goto-char (match-end 0))
8627 (condition-case nil (vhdl-fix-clause) (error "")))
8628 (message "Fixing generic/port clauses...done"))))
8629
8630 (defun vhdl-fix-clause ()
8631 "Fix closing parenthesis within generic/port clause."
8632 (interactive)
8633 (save-excursion
8634 (vhdl-prepare-search-2
8635 (let ((pos (point))
8636 beg end)
8637 (end-of-line)
8638 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8639 (error "ERROR: Not within a generic/port clause")
8640 ;; search for end of clause
8641 (goto-char (match-end 0))
8642 (setq beg (1- (point)))
8643 (vhdl-forward-syntactic-ws)
8644 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8645 (goto-char (1- (match-end 0)))
8646 (setq end (point-marker))
8647 (forward-char)
8648 (vhdl-forward-syntactic-ws))
8649 (goto-char end)
8650 (when (> pos (point-at-eol))
8651 (error "ERROR: Not within a generic/port clause"))
8652 ;; delete closing parenthesis on separate line (not supported style)
8653 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8654 (vhdl-line-kill)
8655 (vhdl-backward-syntactic-ws)
8656 (setq end (point-marker))
8657 (insert ";"))
8658 ;; delete superfluous parentheses
8659 (while (progn (goto-char beg)
8660 (condition-case () (forward-sexp)
8661 (error (goto-char (point-max))))
8662 (< (point) end))
8663 (delete-char -1))
8664 ;; add closing parenthesis
8665 (when (> (point) end)
8666 (goto-char end)
8667 (insert ")")))))))
8668
8669
8670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8671 ;;; Electrification
8672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8673
8674 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8675 "Syntax of prompt inserted by template generators.")
8676
8677 (defvar vhdl-template-invoked-by-hook nil
8678 "Indicates whether a template has been invoked by a hook or by key or menu.
8679 Used for undoing after template abortion.")
8680
8681 ;; correct different behavior of function `unread-command-events' in XEmacs
8682 (defun vhdl-character-to-event (arg))
8683 (defalias 'vhdl-character-to-event
8684 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8685
8686 (defun vhdl-work-library ()
8687 "Return the working library name of the current project or \"work\" if no
8688 project is defined."
8689 (vhdl-resolve-env-variable
8690 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8691 vhdl-default-library)))
8692
8693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8694 ;; Enabling/disabling
8695
8696 (define-minor-mode vhdl-electric-mode
8697 "Toggle VHDL electric mode.
8698 With a prefix argument ARG, enable the mode if ARG is positive,
8699 and disable it otherwise. If called from Lisp, enable it if ARG
8700 is omitted or nil."
8701 :global t :group 'vhdl-mode)
8702
8703 (define-minor-mode vhdl-stutter-mode
8704 "Toggle VHDL stuttering mode.
8705 With a prefix argument ARG, enable the mode if ARG is positive,
8706 and disable it otherwise. If called from Lisp, enable it if ARG
8707 is omitted or nil."
8708 :global t :group 'vhdl-mode)
8709
8710 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8711 ;; Stuttering
8712
8713 (defun vhdl-electric-dash (count)
8714 "-- starts a comment, --- draws a horizontal line,
8715 ---- starts a display comment."
8716 (interactive "p")
8717 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8718 (cond
8719 ((and abbrev-start-location (= abbrev-start-location (point)))
8720 (setq abbrev-start-location nil)
8721 (goto-char last-abbrev-location)
8722 (beginning-of-line nil)
8723 (vhdl-comment-display))
8724 ((/= (preceding-char) ?-) ; standard dash (minus)
8725 (self-insert-command count))
8726 (t (self-insert-command count)
8727 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8728 (let ((next-input (read-char)))
8729 (if (= next-input ?-) ; triple dash
8730 (progn
8731 (vhdl-comment-display-line)
8732 (message
8733 "Enter '-' for display comment, else continue coding")
8734 (let ((next-input (read-char)))
8735 (if (= next-input ?-) ; four dashes
8736 (vhdl-comment-display t)
8737 (push (vhdl-character-to-event next-input)
8738 ; pushback the char
8739 unread-command-events))))
8740 (push (vhdl-character-to-event next-input) ; pushback the char
8741 unread-command-events)
8742 (vhdl-comment-insert)))))
8743 (self-insert-command count)))
8744
8745 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8746 (interactive "p")
8747 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8748 (if (= (preceding-char) ?\()
8749 (progn (delete-char -1) (insert-char ?\[ 1))
8750 (insert-char ?\( 1))
8751 (self-insert-command count)))
8752
8753 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8754 (interactive "p")
8755 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8756 (progn
8757 (if (= (preceding-char) ?\))
8758 (progn (delete-char -1) (insert-char ?\] 1))
8759 (insert-char ?\) 1))
8760 (blink-matching-open))
8761 (self-insert-command count)))
8762
8763 (defun vhdl-electric-quote (count) "'' --> \""
8764 (interactive "p")
8765 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8766 (if (= (preceding-char) vhdl-last-input-event)
8767 (progn (delete-char -1) (insert-char ?\" 1))
8768 (insert-char ?\' 1))
8769 (self-insert-command count)))
8770
8771 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8772 (interactive "p")
8773 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8774 (cond ((= (preceding-char) vhdl-last-input-event)
8775 (progn (delete-char -1)
8776 (unless (eq (preceding-char) ? ) (insert " "))
8777 (insert ": ")
8778 (setq this-command 'vhdl-electric-colon)))
8779 ((and
8780 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8781 (progn (delete-char -1) (insert "= ")))
8782 (t (insert-char ?\; 1)))
8783 (self-insert-command count)))
8784
8785 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8786 (interactive "p")
8787 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8788 (cond ((= (preceding-char) vhdl-last-input-event)
8789 (progn (delete-char -1)
8790 (unless (eq (preceding-char) ? ) (insert " "))
8791 (insert "<= ")))
8792 (t (insert-char ?\, 1)))
8793 (self-insert-command count)))
8794
8795 (defun vhdl-electric-period (count) "'..' --> ' => '"
8796 (interactive "p")
8797 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8798 (cond ((= (preceding-char) vhdl-last-input-event)
8799 (progn (delete-char -1)
8800 (unless (eq (preceding-char) ? ) (insert " "))
8801 (insert "=> ")))
8802 (t (insert-char ?\. 1)))
8803 (self-insert-command count)))
8804
8805 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8806 (interactive "p")
8807 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8808 (cond ((= (preceding-char) vhdl-last-input-event)
8809 (progn (delete-char -1)
8810 (unless (eq (preceding-char) ? ) (insert " "))
8811 (insert "== ")))
8812 (t (insert-char ?\= 1)))
8813 (self-insert-command count)))
8814
8815 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8816 ;; VHDL templates
8817
8818 (defun vhdl-template-paired-parens ()
8819 "Insert a pair of round parentheses, placing point between them."
8820 (interactive)
8821 (insert "()")
8822 (backward-char))
8823
8824 (defun vhdl-template-alias ()
8825 "Insert alias declaration."
8826 (interactive)
8827 (let ((start (point)))
8828 (vhdl-insert-keyword "ALIAS ")
8829 (when (vhdl-template-field "name" nil t start (point))
8830 (insert " : ")
8831 (unless (vhdl-template-field
8832 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8833 nil t)
8834 (delete-char -3))
8835 (vhdl-insert-keyword " IS ")
8836 (vhdl-template-field "name" ";")
8837 (vhdl-comment-insert-inline))))
8838
8839 (defun vhdl-template-architecture ()
8840 "Insert architecture."
8841 (interactive)
8842 (let ((margin (current-indentation))
8843 (start (point))
8844 arch-name)
8845 (vhdl-insert-keyword "ARCHITECTURE ")
8846 (when (setq arch-name
8847 (vhdl-template-field "name" nil t start (point)))
8848 (vhdl-insert-keyword " OF ")
8849 (if (save-excursion
8850 (vhdl-prepare-search-1
8851 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8852 (insert (match-string 1))
8853 (vhdl-template-field "entity name"))
8854 (vhdl-insert-keyword " IS\n")
8855 (vhdl-template-begin-end
8856 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8857 (memq vhdl-insert-empty-lines '(unit all))))))
8858
8859 (defun vhdl-template-array (kind &optional secondary)
8860 "Insert array type definition."
8861 (interactive)
8862 (let ((start (point)))
8863 (vhdl-insert-keyword "ARRAY (")
8864 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8865 secondary)
8866 (vhdl-insert-keyword ") OF ")
8867 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8868 (vhdl-insert-keyword ";"))))
8869
8870 (defun vhdl-template-assert ()
8871 "Insert an assertion statement."
8872 (interactive)
8873 (let ((start (point)))
8874 (vhdl-insert-keyword "ASSERT ")
8875 (when vhdl-conditions-in-parenthesis (insert "("))
8876 (when (vhdl-template-field "condition (negated)" nil t start (point))
8877 (when vhdl-conditions-in-parenthesis (insert ")"))
8878 (setq start (point))
8879 (vhdl-insert-keyword " REPORT ")
8880 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8881 (delete-region start (point)))
8882 (setq start (point))
8883 (vhdl-insert-keyword " SEVERITY ")
8884 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8885 (delete-region start (point)))
8886 (insert ";"))))
8887
8888 (defun vhdl-template-attribute ()
8889 "Insert an attribute declaration or specification."
8890 (interactive)
8891 (if (eq (vhdl-decision-query
8892 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8893 (vhdl-template-attribute-spec)
8894 (vhdl-template-attribute-decl)))
8895
8896 (defun vhdl-template-attribute-decl ()
8897 "Insert an attribute declaration."
8898 (interactive)
8899 (let ((start (point)))
8900 (vhdl-insert-keyword "ATTRIBUTE ")
8901 (when (vhdl-template-field "name" " : " t start (point))
8902 (vhdl-template-field "type" ";")
8903 (vhdl-comment-insert-inline))))
8904
8905 (defun vhdl-template-attribute-spec ()
8906 "Insert an attribute specification."
8907 (interactive)
8908 (let ((start (point)))
8909 (vhdl-insert-keyword "ATTRIBUTE ")
8910 (when (vhdl-template-field "name" nil t start (point))
8911 (vhdl-insert-keyword " OF ")
8912 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8913 (vhdl-template-field "entity class")
8914 (vhdl-insert-keyword " IS ")
8915 (vhdl-template-field "expression" ";"))))
8916
8917 (defun vhdl-template-block ()
8918 "Insert a block."
8919 (interactive)
8920 (let ((margin (current-indentation))
8921 (start (point))
8922 label)
8923 (vhdl-insert-keyword ": BLOCK ")
8924 (goto-char start)
8925 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8926 (forward-word 1)
8927 (forward-char 1)
8928 (insert "(")
8929 (if (vhdl-template-field "[guard expression]" nil t)
8930 (insert ")")
8931 (delete-char -2))
8932 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8933 (insert "\n")
8934 (vhdl-template-begin-end "BLOCK" label margin)
8935 (vhdl-comment-block))))
8936
8937 (defun vhdl-template-block-configuration ()
8938 "Insert a block configuration statement."
8939 (interactive)
8940 (let ((margin (current-indentation))
8941 (start (point)))
8942 (vhdl-insert-keyword "FOR ")
8943 (when (vhdl-template-field "block name" nil t start (point))
8944 (vhdl-insert-keyword "\n\n")
8945 (indent-to margin)
8946 (vhdl-insert-keyword "END FOR;")
8947 (end-of-line 0)
8948 (indent-to (+ margin vhdl-basic-offset)))))
8949
8950 (defun vhdl-template-break ()
8951 "Insert a break statement."
8952 (interactive)
8953 (let (position)
8954 (vhdl-insert-keyword "BREAK")
8955 (setq position (point))
8956 (insert " ")
8957 (while (or
8958 (progn (vhdl-insert-keyword "FOR ")
8959 (if (vhdl-template-field "[quantity name]" " USE " t)
8960 (progn (vhdl-template-field "quantity name" " => ") t)
8961 (delete-region (point)
8962 (progn (forward-word -1) (point)))
8963 nil))
8964 (vhdl-template-field "[quantity name]" " => " t))
8965 (vhdl-template-field "expression")
8966 (setq position (point))
8967 (insert ", "))
8968 (delete-region position (point))
8969 (unless (vhdl-sequential-statement-p)
8970 (vhdl-insert-keyword " ON ")
8971 (if (vhdl-template-field "[sensitivity list]" nil t)
8972 (setq position (point))
8973 (delete-region position (point))))
8974 (vhdl-insert-keyword " WHEN ")
8975 (when vhdl-conditions-in-parenthesis (insert "("))
8976 (if (vhdl-template-field "[condition]" nil t)
8977 (when vhdl-conditions-in-parenthesis (insert ")"))
8978 (delete-region position (point)))
8979 (insert ";")))
8980
8981 (defun vhdl-template-case (&optional kind)
8982 "Insert a case statement."
8983 (interactive)
8984 (let ((margin (current-indentation))
8985 (start (point))
8986 label)
8987 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8988 (not (vhdl-standard-p 'ams))) 'is 'use)))
8989 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8990 (vhdl-insert-keyword "CASE ")
8991 (vhdl-insert-keyword ": CASE ")
8992 (goto-char start)
8993 (setq label (vhdl-template-field "[label]" nil t))
8994 (unless label (delete-char 2))
8995 (forward-word 1)
8996 (forward-char 1))
8997 (when (vhdl-template-field "expression" nil t start (point))
8998 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8999 (indent-to margin)
9000 (vhdl-insert-keyword "END CASE")
9001 (when label (insert " " label))
9002 (insert ";")
9003 (forward-line -1)
9004 (indent-to (+ margin vhdl-basic-offset))
9005 (vhdl-insert-keyword "WHEN ")
9006 (let ((position (point)))
9007 (insert " => ;\n")
9008 (indent-to (+ margin vhdl-basic-offset))
9009 (vhdl-insert-keyword "WHEN OTHERS => null;")
9010 (goto-char position)))))
9011
9012 (defun vhdl-template-case-is ()
9013 "Insert a sequential case statement."
9014 (interactive)
9015 (vhdl-template-case 'is))
9016
9017 (defun vhdl-template-case-use ()
9018 "Insert a simultaneous case statement."
9019 (interactive)
9020 (vhdl-template-case 'use))
9021
9022 (defun vhdl-template-component ()
9023 "Insert a component declaration."
9024 (interactive)
9025 (vhdl-template-component-decl))
9026
9027 (defun vhdl-template-component-conf ()
9028 "Insert a component configuration (uses `vhdl-template-configuration-spec'
9029 since these are almost equivalent)."
9030 (interactive)
9031 (let ((margin (current-indentation))
9032 (result (vhdl-template-configuration-spec t)))
9033 (when result
9034 (insert "\n")
9035 (indent-to margin)
9036 (vhdl-insert-keyword "END FOR;")
9037 (when (eq result 'no-use)
9038 (end-of-line -0)))))
9039
9040 (defun vhdl-template-component-decl ()
9041 "Insert a component declaration."
9042 (interactive)
9043 (let ((margin (current-indentation))
9044 (start (point))
9045 name end-column)
9046 (vhdl-insert-keyword "COMPONENT ")
9047 (when (setq name (vhdl-template-field "name" nil t start (point)))
9048 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9049 (insert "\n\n")
9050 (indent-to margin)
9051 (vhdl-insert-keyword "END COMPONENT")
9052 (unless (vhdl-standard-p '87) (insert " " name))
9053 (insert ";")
9054 (setq end-column (current-column))
9055 (end-of-line -0)
9056 (indent-to (+ margin vhdl-basic-offset))
9057 (vhdl-template-generic-list t t)
9058 (insert "\n")
9059 (indent-to (+ margin vhdl-basic-offset))
9060 (vhdl-template-port-list t)
9061 (beginning-of-line 2)
9062 (forward-char end-column))))
9063
9064 (defun vhdl-template-component-inst ()
9065 "Insert a component instantiation statement."
9066 (interactive)
9067 (let ((margin (current-indentation))
9068 (start (point))
9069 unit position)
9070 (when (vhdl-template-field "instance label" nil t start (point))
9071 (insert ": ")
9072 (if (not (vhdl-use-direct-instantiation))
9073 (vhdl-template-field "component name")
9074 ;; direct instantiation
9075 (setq unit (vhdl-template-field
9076 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
9077 (setq unit (upcase (or unit "")))
9078 (cond ((equal unit "ENTITY")
9079 (let ((begin (point)))
9080 (vhdl-template-field "library name" "." t begin (point) nil
9081 (vhdl-work-library))
9082 (vhdl-template-field "entity name" "(")
9083 (if (vhdl-template-field "[architecture name]" nil t)
9084 (insert ")")
9085 (delete-char -1))))
9086 ((equal unit "CONFIGURATION")
9087 (vhdl-template-field "library name" "." nil nil nil nil
9088 (vhdl-work-library))
9089 (vhdl-template-field "configuration name"))
9090 (t (vhdl-template-field "component name"))))
9091 (insert "\n")
9092 (indent-to (+ margin vhdl-basic-offset))
9093 (setq position (point))
9094 (vhdl-insert-keyword "GENERIC ")
9095 (when (vhdl-template-map position t t)
9096 (insert "\n")
9097 (indent-to (+ margin vhdl-basic-offset)))
9098 (setq position (point))
9099 (vhdl-insert-keyword "PORT ")
9100 (unless (vhdl-template-map position t t)
9101 (delete-region (line-beginning-position) (point))
9102 (delete-char -1))
9103 (insert ";"))))
9104
9105 (defun vhdl-template-conditional-signal-asst ()
9106 "Insert a conditional signal assignment."
9107 (interactive)
9108 (when (vhdl-template-field "target signal")
9109 (insert " <= ")
9110 (let ((margin (current-column))
9111 (start (point))
9112 position)
9113 (vhdl-template-field "waveform")
9114 (setq position (point))
9115 (vhdl-insert-keyword " WHEN ")
9116 (when vhdl-conditions-in-parenthesis (insert "("))
9117 (while (and (vhdl-template-field "[condition]" nil t)
9118 (progn
9119 (when vhdl-conditions-in-parenthesis (insert ")"))
9120 (setq position (point))
9121 (vhdl-insert-keyword " ELSE")
9122 (insert "\n")
9123 (indent-to margin)
9124 (vhdl-template-field "[waveform]" nil t)))
9125 (setq position (point))
9126 (vhdl-insert-keyword " WHEN ")
9127 (when vhdl-conditions-in-parenthesis (insert "(")))
9128 (delete-region position (point))
9129 (insert ";")
9130 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9131
9132 (defun vhdl-template-configuration ()
9133 "Insert a configuration specification if within an architecture,
9134 a block or component configuration if within a configuration declaration,
9135 a configuration declaration if not within a design unit."
9136 (interactive)
9137 (vhdl-prepare-search-1
9138 (cond
9139 ((and (save-excursion ; architecture body
9140 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9141 (equal "ARCHITECTURE" (upcase (match-string 1))))
9142 (vhdl-template-configuration-spec))
9143 ((and (save-excursion ; configuration declaration
9144 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9145 (equal "CONFIGURATION" (upcase (match-string 1))))
9146 (if (eq (vhdl-decision-query
9147 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9148 (vhdl-template-component-conf)
9149 (vhdl-template-block-configuration)))
9150 (t (vhdl-template-configuration-decl))))) ; otherwise
9151
9152 (defun vhdl-template-configuration-spec (&optional optional-use)
9153 "Insert a configuration specification."
9154 (interactive)
9155 (let ((margin (current-indentation))
9156 (start (point))
9157 aspect position)
9158 (vhdl-insert-keyword "FOR ")
9159 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9160 t start (point))
9161 (vhdl-template-field "component name" "\n")
9162 (indent-to (+ margin vhdl-basic-offset))
9163 (setq start (point))
9164 (vhdl-insert-keyword "USE ")
9165 (if (and optional-use
9166 (not (setq aspect (vhdl-template-field
9167 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9168 (progn (delete-region start (point)) 'no-use)
9169 (unless optional-use
9170 (setq aspect (vhdl-template-field
9171 "ENTITY | CONFIGURATION | OPEN" " ")))
9172 (setq aspect (upcase (or aspect "")))
9173 (cond ((equal aspect "ENTITY")
9174 (vhdl-template-field "library name" "." nil nil nil nil
9175 (vhdl-work-library))
9176 (vhdl-template-field "entity name" "(")
9177 (if (vhdl-template-field "[architecture name]" nil t)
9178 (insert ")")
9179 (delete-char -1))
9180 (insert "\n")
9181 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9182 (setq position (point))
9183 (vhdl-insert-keyword "GENERIC ")
9184 (when (vhdl-template-map position t t)
9185 (insert "\n")
9186 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9187 (setq position (point))
9188 (vhdl-insert-keyword "PORT ")
9189 (unless (vhdl-template-map position t t)
9190 (delete-region (line-beginning-position) (point))
9191 (delete-char -1))
9192 (insert ";")
9193 t)
9194 ((equal aspect "CONFIGURATION")
9195 (vhdl-template-field "library name" "." nil nil nil nil
9196 (vhdl-work-library))
9197 (vhdl-template-field "configuration name" ";"))
9198 (t (delete-char -1) (insert ";") t))))))
9199
9200
9201 (defun vhdl-template-configuration-decl ()
9202 "Insert a configuration declaration."
9203 (interactive)
9204 (let ((margin (current-indentation))
9205 (start (point))
9206 entity-exists string name position)
9207 (vhdl-insert-keyword "CONFIGURATION ")
9208 (when (setq name (vhdl-template-field "name" nil t start (point)))
9209 (vhdl-insert-keyword " OF ")
9210 (save-excursion
9211 (vhdl-prepare-search-1
9212 (setq entity-exists (vhdl-re-search-backward
9213 "\\<entity \\(\\w*\\) is\\>" nil t))
9214 (setq string (match-string 1))))
9215 (if (and entity-exists (not (equal string "")))
9216 (insert string)
9217 (vhdl-template-field "entity name"))
9218 (vhdl-insert-keyword " IS\n")
9219 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9220 (indent-to (+ margin vhdl-basic-offset))
9221 (setq position (point))
9222 (insert "\n")
9223 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9224 (indent-to margin)
9225 (vhdl-insert-keyword "END ")
9226 (unless (vhdl-standard-p '87)
9227 (vhdl-insert-keyword "CONFIGURATION "))
9228 (insert name ";")
9229 (goto-char position))))
9230
9231 (defun vhdl-template-constant ()
9232 "Insert a constant declaration."
9233 (interactive)
9234 (let ((start (point))
9235 (in-arglist (vhdl-in-argument-list-p)))
9236 (vhdl-insert-keyword "CONSTANT ")
9237 (when (vhdl-template-field "name" nil t start (point))
9238 (insert " : ")
9239 (when in-arglist (vhdl-insert-keyword "IN "))
9240 (vhdl-template-field "type")
9241 (if in-arglist
9242 (progn (insert ";")
9243 (vhdl-comment-insert-inline))
9244 (let ((position (point)))
9245 (insert " := ")
9246 (unless (vhdl-template-field "[initialization]" nil t)
9247 (delete-region position (point)))
9248 (insert ";")
9249 (vhdl-comment-insert-inline))))))
9250
9251 (defun vhdl-template-context ()
9252 "Insert a context declaration."
9253 (interactive)
9254 (let ((margin (current-indentation))
9255 (start (point))
9256 entity-exists string name position)
9257 (vhdl-insert-keyword "CONTEXT ")
9258 (when (setq name (vhdl-template-field "name" nil t start (point)))
9259 (vhdl-insert-keyword " IS\n")
9260 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9261 (indent-to (+ margin vhdl-basic-offset))
9262 (setq position (point))
9263 (insert "\n")
9264 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9265 (indent-to margin)
9266 (vhdl-insert-keyword "END ")
9267 (unless (vhdl-standard-p '87)
9268 (vhdl-insert-keyword "CONTEXT "))
9269 (insert name ";")
9270 (goto-char position))))
9271
9272 (defun vhdl-template-default ()
9273 "Insert nothing."
9274 (interactive)
9275 (insert " ")
9276 (unexpand-abbrev)
9277 (backward-word 1)
9278 (vhdl-case-word 1)
9279 (forward-char 1))
9280
9281 (defun vhdl-template-default-indent ()
9282 "Insert nothing and indent."
9283 (interactive)
9284 (insert " ")
9285 (unexpand-abbrev)
9286 (backward-word 1)
9287 (vhdl-case-word 1)
9288 (forward-char 1)
9289 (indent-according-to-mode))
9290
9291 (defun vhdl-template-disconnect ()
9292 "Insert a disconnect statement."
9293 (interactive)
9294 (let ((start (point)))
9295 (vhdl-insert-keyword "DISCONNECT ")
9296 (when (vhdl-template-field "signal names | OTHERS | ALL"
9297 " : " t start (point))
9298 (vhdl-template-field "type")
9299 (vhdl-insert-keyword " AFTER ")
9300 (vhdl-template-field "time expression" ";"))))
9301
9302 (defun vhdl-template-else ()
9303 "Insert an else statement."
9304 (interactive)
9305 (let (margin)
9306 (vhdl-prepare-search-1
9307 (vhdl-insert-keyword "ELSE")
9308 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
9309 (equal "WHEN" (upcase (match-string 1))))
9310 (insert " ")
9311 (indent-according-to-mode)
9312 (setq margin (current-indentation))
9313 (insert "\n")
9314 (indent-to (+ margin vhdl-basic-offset))))))
9315
9316 (defun vhdl-template-elsif ()
9317 "Insert an elsif statement."
9318 (interactive)
9319 (let ((start (point))
9320 margin)
9321 (vhdl-insert-keyword "ELSIF ")
9322 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
9323 (when vhdl-conditions-in-parenthesis (insert "("))
9324 (when (vhdl-template-field "condition" nil t start (point))
9325 (when vhdl-conditions-in-parenthesis (insert ")"))
9326 (indent-according-to-mode)
9327 (setq margin (current-indentation))
9328 (vhdl-insert-keyword
9329 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9330 (indent-to (+ margin vhdl-basic-offset))))))
9331
9332 (defun vhdl-template-entity ()
9333 "Insert an entity."
9334 (interactive)
9335 (let ((margin (current-indentation))
9336 (start (point))
9337 name end-column)
9338 (vhdl-insert-keyword "ENTITY ")
9339 (when (setq name (vhdl-template-field "name" nil t start (point)))
9340 (vhdl-insert-keyword " IS\n\n")
9341 (indent-to margin)
9342 (vhdl-insert-keyword "END ")
9343 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9344 (insert name ";")
9345 (setq end-column (current-column))
9346 (end-of-line -0)
9347 (indent-to (+ margin vhdl-basic-offset))
9348 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9349 (indent-to (+ margin vhdl-basic-offset))
9350 (when (vhdl-template-generic-list t)
9351 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9352 (insert "\n")
9353 (indent-to (+ margin vhdl-basic-offset))
9354 (when (vhdl-template-port-list t)
9355 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9356 (beginning-of-line 2)
9357 (forward-char end-column))))
9358
9359 (defun vhdl-template-exit ()
9360 "Insert an exit statement."
9361 (interactive)
9362 (let ((start (point)))
9363 (vhdl-insert-keyword "EXIT ")
9364 (if (vhdl-template-field "[loop label]" nil t start (point))
9365 (let ((position (point)))
9366 (vhdl-insert-keyword " WHEN ")
9367 (when vhdl-conditions-in-parenthesis (insert "("))
9368 (if (vhdl-template-field "[condition]" nil t)
9369 (when vhdl-conditions-in-parenthesis (insert ")"))
9370 (delete-region position (point))))
9371 (delete-char -1))
9372 (insert ";")))
9373
9374 (defun vhdl-template-file ()
9375 "Insert a file declaration."
9376 (interactive)
9377 (let ((start (point)))
9378 (vhdl-insert-keyword "FILE ")
9379 (when (vhdl-template-field "name" nil t start (point))
9380 (insert " : ")
9381 (vhdl-template-field "type")
9382 (unless (vhdl-standard-p '87)
9383 (vhdl-insert-keyword " OPEN ")
9384 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9385 nil t)
9386 (delete-char -6)))
9387 (vhdl-insert-keyword " IS ")
9388 (when (vhdl-standard-p '87)
9389 (vhdl-template-field "[IN | OUT]" " " t))
9390 (vhdl-template-field "filename-string" nil nil nil nil t)
9391 (insert ";")
9392 (vhdl-comment-insert-inline))))
9393
9394 (defun vhdl-template-for ()
9395 "Insert a block or component configuration if within a configuration
9396 declaration, a configuration specification if within an architecture
9397 declarative part (and not within a subprogram), a for-loop if within a
9398 sequential statement part (subprogram or process), and a for-generate
9399 otherwise."
9400 (interactive)
9401 (vhdl-prepare-search-1
9402 (cond
9403 ((vhdl-sequential-statement-p) ; sequential statement
9404 (vhdl-template-for-loop))
9405 ((and (save-excursion ; configuration declaration
9406 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9407 (equal "CONFIGURATION" (upcase (match-string 1))))
9408 (if (eq (vhdl-decision-query
9409 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9410 (vhdl-template-component-conf)
9411 (vhdl-template-block-configuration)))
9412 ((and (save-excursion
9413 (re-search-backward ; architecture declarative part
9414 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9415 (equal "ARCHITECTURE" (upcase (match-string 1))))
9416 (vhdl-template-configuration-spec))
9417 (t (vhdl-template-for-generate))))) ; concurrent statement
9418
9419 (defun vhdl-template-for-generate ()
9420 "Insert a for-generate."
9421 (interactive)
9422 (let ((margin (current-indentation))
9423 (start (point))
9424 label position)
9425 (vhdl-insert-keyword ": FOR ")
9426 (setq position (point-marker))
9427 (goto-char start)
9428 (when (setq label (vhdl-template-field "label" nil t start position))
9429 (goto-char position)
9430 (vhdl-template-field "loop variable")
9431 (vhdl-insert-keyword " IN ")
9432 (vhdl-template-field "range")
9433 (vhdl-template-generate-body margin label))))
9434
9435 (defun vhdl-template-for-loop ()
9436 "Insert a for loop."
9437 (interactive)
9438 (let ((margin (current-indentation))
9439 (start (point))
9440 label index)
9441 (if (not (eq vhdl-optional-labels 'all))
9442 (vhdl-insert-keyword "FOR ")
9443 (vhdl-insert-keyword ": FOR ")
9444 (goto-char start)
9445 (setq label (vhdl-template-field "[label]" nil t))
9446 (unless label (delete-char 2))
9447 (forward-word 1)
9448 (forward-char 1))
9449 (when (setq index (vhdl-template-field "loop variable"
9450 nil t start (point)))
9451 (vhdl-insert-keyword " IN ")
9452 (vhdl-template-field "range")
9453 (vhdl-insert-keyword " LOOP\n\n")
9454 (indent-to margin)
9455 (vhdl-insert-keyword "END LOOP")
9456 (if label
9457 (insert " " label ";")
9458 (insert ";")
9459 (when vhdl-self-insert-comments (insert " -- " index)))
9460 (forward-line -1)
9461 (indent-to (+ margin vhdl-basic-offset)))))
9462
9463 (defun vhdl-template-function (&optional kind)
9464 "Insert a function declaration or body."
9465 (interactive)
9466 (let ((margin (current-indentation))
9467 (start (point))
9468 name)
9469 (vhdl-insert-keyword "FUNCTION ")
9470 (when (setq name (vhdl-template-field "name" nil t start (point)))
9471 (vhdl-template-argument-list t)
9472 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9473 (end-of-line)
9474 (insert "\n")
9475 (indent-to (+ margin vhdl-basic-offset))
9476 (vhdl-insert-keyword "RETURN ")
9477 (vhdl-template-field "type")
9478 (if (if kind (eq kind 'body)
9479 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9480 (progn (vhdl-insert-keyword " IS\n")
9481 (vhdl-template-begin-end
9482 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9483 (vhdl-comment-block))
9484 (insert ";")))))
9485
9486 (defun vhdl-template-function-decl ()
9487 "Insert a function declaration."
9488 (interactive)
9489 (vhdl-template-function 'decl))
9490
9491 (defun vhdl-template-function-body ()
9492 "Insert a function declaration."
9493 (interactive)
9494 (vhdl-template-function 'body))
9495
9496 (defun vhdl-template-generate ()
9497 "Insert a generation scheme."
9498 (interactive)
9499 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9500 (vhdl-template-if-generate)
9501 (vhdl-template-for-generate)))
9502
9503 (defun vhdl-template-generic ()
9504 "Insert generic declaration, or generic map in instantiation statements."
9505 (interactive)
9506 (let ((start (point)))
9507 (vhdl-prepare-search-1
9508 (cond
9509 ((and (save-excursion ; entity declaration
9510 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9511 (equal "ENTITY" (upcase (match-string 1))))
9512 (vhdl-template-generic-list nil))
9513 ((or (save-excursion
9514 (or (beginning-of-line)
9515 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9516 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9517 (vhdl-insert-keyword "GENERIC ")
9518 (vhdl-template-map start))
9519 (t (vhdl-template-generic-list nil t))))))
9520
9521 (defun vhdl-template-group ()
9522 "Insert group or group template declaration."
9523 (interactive)
9524 (let ((start (point)))
9525 (if (eq (vhdl-decision-query
9526 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9527 (vhdl-template-group-template)
9528 (vhdl-template-group-decl))))
9529
9530 (defun vhdl-template-group-decl ()
9531 "Insert group declaration."
9532 (interactive)
9533 (let ((start (point)))
9534 (vhdl-insert-keyword "GROUP ")
9535 (when (vhdl-template-field "name" " : " t start (point))
9536 (vhdl-template-field "template name" " (")
9537 (vhdl-template-field "constituent list" ");")
9538 (vhdl-comment-insert-inline))))
9539
9540 (defun vhdl-template-group-template ()
9541 "Insert group template declaration."
9542 (interactive)
9543 (let ((start (point)))
9544 (vhdl-insert-keyword "GROUP ")
9545 (when (vhdl-template-field "template name" nil t start (point))
9546 (vhdl-insert-keyword " IS (")
9547 (vhdl-template-field "entity class list" ");")
9548 (vhdl-comment-insert-inline))))
9549
9550 (defun vhdl-template-if ()
9551 "Insert a sequential if statement or an if-generate statement."
9552 (interactive)
9553 (if (vhdl-sequential-statement-p)
9554 (vhdl-template-if-then)
9555 (if (and (vhdl-standard-p 'ams)
9556 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9557 (vhdl-template-if-use)
9558 (vhdl-template-if-generate))))
9559
9560 (defun vhdl-template-if-generate ()
9561 "Insert an if-generate."
9562 (interactive)
9563 (let ((margin (current-indentation))
9564 (start (point))
9565 label position)
9566 (vhdl-insert-keyword ": IF ")
9567 (setq position (point-marker))
9568 (goto-char start)
9569 (when (setq label (vhdl-template-field "label" nil t start position))
9570 (goto-char position)
9571 (when vhdl-conditions-in-parenthesis (insert "("))
9572 (vhdl-template-field "condition")
9573 (when vhdl-conditions-in-parenthesis (insert ")"))
9574 (vhdl-template-generate-body margin label))))
9575
9576 (defun vhdl-template-if-then-use (kind)
9577 "Insert a sequential if statement."
9578 (interactive)
9579 (let ((margin (current-indentation))
9580 (start (point))
9581 label)
9582 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9583 (vhdl-insert-keyword "IF ")
9584 (vhdl-insert-keyword ": IF ")
9585 (goto-char start)
9586 (setq label (vhdl-template-field "[label]" nil t))
9587 (unless label (delete-char 2))
9588 (forward-word 1)
9589 (forward-char 1))
9590 (when vhdl-conditions-in-parenthesis (insert "("))
9591 (when (vhdl-template-field "condition" nil t start (point))
9592 (when vhdl-conditions-in-parenthesis (insert ")"))
9593 (vhdl-insert-keyword
9594 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9595 (indent-to margin)
9596 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9597 (when label (insert " " label))
9598 (insert ";")
9599 (forward-line -1)
9600 (indent-to (+ margin vhdl-basic-offset)))))
9601
9602 (defun vhdl-template-if-then ()
9603 "Insert a sequential if statement."
9604 (interactive)
9605 (vhdl-template-if-then-use 'then))
9606
9607 (defun vhdl-template-if-use ()
9608 "Insert a simultaneous if statement."
9609 (interactive)
9610 (vhdl-template-if-then-use 'use))
9611
9612 (defun vhdl-template-instance ()
9613 "Insert a component instantiation statement."
9614 (interactive)
9615 (vhdl-template-component-inst))
9616
9617 (defun vhdl-template-library ()
9618 "Insert a library specification."
9619 (interactive)
9620 (let ((margin (current-indentation))
9621 (start (point))
9622 name end-pos)
9623 (vhdl-insert-keyword "LIBRARY ")
9624 (when (setq name (vhdl-template-field "names" nil t start (point)))
9625 (insert ";")
9626 (unless (string-match "," name)
9627 (setq end-pos (point))
9628 (insert "\n")
9629 (indent-to margin)
9630 (vhdl-insert-keyword "USE ")
9631 (insert name)
9632 (vhdl-insert-keyword "..ALL;")
9633 (backward-char 5)
9634 (if (vhdl-template-field "package name")
9635 (forward-char 5)
9636 (delete-region end-pos (+ (point) 5)))))))
9637
9638 (defun vhdl-template-limit ()
9639 "Insert a limit."
9640 (interactive)
9641 (let ((start (point)))
9642 (vhdl-insert-keyword "LIMIT ")
9643 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9644 t start (point))
9645 (vhdl-template-field "type")
9646 (vhdl-insert-keyword " WITH ")
9647 (vhdl-template-field "real expression" ";"))))
9648
9649 (defun vhdl-template-loop ()
9650 "Insert a loop."
9651 (interactive)
9652 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9653 (cond ((eq char ?w)
9654 (vhdl-template-while-loop))
9655 ((eq char ?f)
9656 (vhdl-template-for-loop))
9657 (t (vhdl-template-bare-loop)))))
9658
9659 (defun vhdl-template-bare-loop ()
9660 "Insert a loop."
9661 (interactive)
9662 (let ((margin (current-indentation))
9663 (start (point))
9664 label)
9665 (if (not (eq vhdl-optional-labels 'all))
9666 (vhdl-insert-keyword "LOOP ")
9667 (vhdl-insert-keyword ": LOOP ")
9668 (goto-char start)
9669 (setq label (vhdl-template-field "[label]" nil t))
9670 (unless label (delete-char 2))
9671 (forward-word 1)
9672 (delete-char 1))
9673 (insert "\n\n")
9674 (indent-to margin)
9675 (vhdl-insert-keyword "END LOOP")
9676 (insert (if label (concat " " label ";") ";"))
9677 (forward-line -1)
9678 (indent-to (+ margin vhdl-basic-offset))))
9679
9680 (defun vhdl-template-map (&optional start optional secondary)
9681 "Insert a map specification with association list."
9682 (interactive)
9683 (let ((start (or start (point)))
9684 margin end-pos)
9685 (vhdl-insert-keyword "MAP (")
9686 (if (not vhdl-association-list-with-formals)
9687 (if (vhdl-template-field
9688 (concat (and optional "[") "association list" (and optional "]"))
9689 ")" (or (not secondary) optional)
9690 (and (not secondary) start) (point))
9691 t
9692 (if (and optional secondary) (delete-region start (point)))
9693 nil)
9694 (if vhdl-argument-list-indent
9695 (setq margin (current-column))
9696 (setq margin (+ (current-indentation) vhdl-basic-offset))
9697 (insert "\n")
9698 (indent-to margin))
9699 (if (vhdl-template-field
9700 (concat (and optional "[") "formal" (and optional "]"))
9701 " => " (or (not secondary) optional)
9702 (and (not secondary) start) (point))
9703 (progn
9704 (vhdl-template-field "actual" ",")
9705 (setq end-pos (point))
9706 (insert "\n")
9707 (indent-to margin)
9708 (while (vhdl-template-field "[formal]" " => " t)
9709 (vhdl-template-field "actual" ",")
9710 (setq end-pos (point))
9711 (insert "\n")
9712 (indent-to margin))
9713 (delete-region end-pos (point))
9714 (delete-char -1)
9715 (insert ")")
9716 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9717 t)
9718 (when (and optional secondary) (delete-region start (point)))
9719 nil))))
9720
9721 (defun vhdl-template-modify (&optional noerror)
9722 "Actualize modification date."
9723 (interactive)
9724 (vhdl-prepare-search-2
9725 (save-excursion
9726 (goto-char (point-min))
9727 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9728 (progn (delete-region (point) (progn (end-of-line) (point)))
9729 (vhdl-template-insert-date))
9730 (unless noerror
9731 (error "ERROR: Modification date prefix string \"%s\" not found"
9732 vhdl-modify-date-prefix-string))))))
9733
9734
9735 (defun vhdl-template-modify-noerror ()
9736 "Call `vhdl-template-modify' with NOERROR non-nil."
9737 (vhdl-template-modify t))
9738
9739 (defun vhdl-template-nature ()
9740 "Insert a nature declaration."
9741 (interactive)
9742 (let ((start (point))
9743 name mid-pos end-pos)
9744 (vhdl-insert-keyword "NATURE ")
9745 (when (setq name (vhdl-template-field "name" nil t start (point)))
9746 (vhdl-insert-keyword " IS ")
9747 (let ((definition
9748 (upcase
9749 (or (vhdl-template-field
9750 "across type | ARRAY | RECORD")
9751 ""))))
9752 (cond ((equal definition "")
9753 (insert ";"))
9754 ((equal definition "ARRAY")
9755 (delete-region (point) (progn (forward-word -1) (point)))
9756 (vhdl-template-array 'nature t))
9757 ((equal definition "RECORD")
9758 (setq mid-pos (point-marker))
9759 (delete-region (point) (progn (forward-word -1) (point)))
9760 (vhdl-template-record 'nature name t))
9761 (t
9762 (vhdl-insert-keyword " ACROSS ")
9763 (vhdl-template-field "through type")
9764 (vhdl-insert-keyword " THROUGH ")
9765 (vhdl-template-field "reference name")
9766 (vhdl-insert-keyword " REFERENCE;")))
9767 (when mid-pos
9768 (setq end-pos (point-marker))
9769 (goto-char mid-pos)
9770 (end-of-line))
9771 (vhdl-comment-insert-inline)
9772 (when end-pos (goto-char end-pos))))))
9773
9774 (defun vhdl-template-next ()
9775 "Insert a next statement."
9776 (interactive)
9777 (let ((start (point)))
9778 (vhdl-insert-keyword "NEXT ")
9779 (if (vhdl-template-field "[loop label]" nil t start (point))
9780 (let ((position (point)))
9781 (vhdl-insert-keyword " WHEN ")
9782 (when vhdl-conditions-in-parenthesis (insert "("))
9783 (if (vhdl-template-field "[condition]" nil t)
9784 (when vhdl-conditions-in-parenthesis (insert ")"))
9785 (delete-region position (point))))
9786 (delete-char -1))
9787 (insert ";")))
9788
9789 (defun vhdl-template-others ()
9790 "Insert an others aggregate."
9791 (interactive)
9792 (let ((start (point)))
9793 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9794 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9795 (vhdl-insert-keyword "OTHERS => '")
9796 (when (vhdl-template-field "value" nil t start (point))
9797 (insert "')")))
9798 (vhdl-insert-keyword "OTHERS "))))
9799
9800 (defun vhdl-template-package (&optional kind)
9801 "Insert a package specification or body."
9802 (interactive)
9803 (let ((margin (current-indentation))
9804 (start (point))
9805 name body position)
9806 (vhdl-insert-keyword "PACKAGE ")
9807 (setq body (if kind (eq kind 'body)
9808 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9809 (when body
9810 (vhdl-insert-keyword "BODY ")
9811 (when (save-excursion
9812 (vhdl-prepare-search-1
9813 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9814 (insert (setq name (match-string 1)))))
9815 (when (or name
9816 (setq name (vhdl-template-field "name" nil t start (point))))
9817 (vhdl-insert-keyword " IS\n")
9818 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9819 (indent-to (+ margin vhdl-basic-offset))
9820 (setq position (point))
9821 (insert "\n")
9822 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9823 (indent-to margin)
9824 (vhdl-insert-keyword "END ")
9825 (unless (vhdl-standard-p '87)
9826 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9827 (insert (or name "") ";")
9828 (goto-char position))))
9829
9830 (defun vhdl-template-package-decl ()
9831 "Insert a package specification."
9832 (interactive)
9833 (vhdl-template-package 'decl))
9834
9835 (defun vhdl-template-package-body ()
9836 "Insert a package body."
9837 (interactive)
9838 (vhdl-template-package 'body))
9839
9840 (defun vhdl-template-port ()
9841 "Insert a port declaration, or port map in instantiation statements."
9842 (interactive)
9843 (let ((start (point)))
9844 (vhdl-prepare-search-1
9845 (cond
9846 ((and (save-excursion ; entity declaration
9847 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9848 (equal "ENTITY" (upcase (match-string 1))))
9849 (vhdl-template-port-list nil))
9850 ((or (save-excursion
9851 (or (beginning-of-line)
9852 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9853 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9854 (vhdl-insert-keyword "PORT ")
9855 (vhdl-template-map start))
9856 (t (vhdl-template-port-list nil))))))
9857
9858 (defun vhdl-template-procedural ()
9859 "Insert a procedural."
9860 (interactive)
9861 (let ((margin (current-indentation))
9862 (start (point))
9863 (case-fold-search t)
9864 label)
9865 (vhdl-insert-keyword "PROCEDURAL ")
9866 (when (memq vhdl-optional-labels '(process all))
9867 (goto-char start)
9868 (insert ": ")
9869 (goto-char start)
9870 (setq label (vhdl-template-field "[label]" nil t))
9871 (unless label (delete-char 2))
9872 (forward-word 1)
9873 (forward-char 1))
9874 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9875 (insert "\n")
9876 (vhdl-template-begin-end "PROCEDURAL" label margin)
9877 (vhdl-comment-block)))
9878
9879 (defun vhdl-template-procedure (&optional kind)
9880 "Insert a procedure declaration or body."
9881 (interactive)
9882 (let ((margin (current-indentation))
9883 (start (point))
9884 name)
9885 (vhdl-insert-keyword "PROCEDURE ")
9886 (when (setq name (vhdl-template-field "name" nil t start (point)))
9887 (vhdl-template-argument-list)
9888 (if (if kind (eq kind 'body)
9889 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9890 (progn (vhdl-insert-keyword " IS")
9891 (when vhdl-auto-align
9892 (vhdl-align-region-groups start (point) 1))
9893 (end-of-line) (insert "\n")
9894 (vhdl-template-begin-end
9895 (unless (vhdl-standard-p '87) "PROCEDURE")
9896 name margin)
9897 (vhdl-comment-block))
9898 (insert ";")
9899 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9900 (end-of-line)))))
9901
9902 (defun vhdl-template-procedure-decl ()
9903 "Insert a procedure declaration."
9904 (interactive)
9905 (vhdl-template-procedure 'decl))
9906
9907 (defun vhdl-template-procedure-body ()
9908 "Insert a procedure body."
9909 (interactive)
9910 (vhdl-template-procedure 'body))
9911
9912 (defun vhdl-template-process (&optional kind)
9913 "Insert a process."
9914 (interactive)
9915 (let ((margin (current-indentation))
9916 (start (point))
9917 (reset-kind vhdl-reset-kind)
9918 label seq input-signals clock reset final-pos)
9919 (setq seq (if kind (eq kind 'seq)
9920 (eq (vhdl-decision-query
9921 "process" "(c)ombinational or (s)equential?" t) ?s)))
9922 (vhdl-insert-keyword "PROCESS ")
9923 (when (memq vhdl-optional-labels '(process all))
9924 (goto-char start)
9925 (insert ": ")
9926 (goto-char start)
9927 (setq label (vhdl-template-field "[label]" nil t))
9928 (unless label (delete-char 2))
9929 (forward-word 1)
9930 (forward-char 1))
9931 (insert "(")
9932 (if (not seq)
9933 (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
9934 (progn (insert "all)") (setq input-signals "all")))
9935 (setq input-signals
9936 (vhdl-template-field "[sensitivity list]" ")" t)))
9937 (setq input-signals "")
9938 (delete-char -2))
9939 (setq clock (or (and (not (equal "" vhdl-clock-name))
9940 (progn (insert vhdl-clock-name) vhdl-clock-name))
9941 (vhdl-template-field "clock name") "<clock>"))
9942 (when (eq reset-kind 'query)
9943 (setq reset-kind
9944 (if (eq (vhdl-decision-query
9945 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9946 'async
9947 'sync)))
9948 (when (eq reset-kind 'async)
9949 (insert ", ")
9950 (setq reset (or (and (not (equal "" vhdl-reset-name))
9951 (progn (insert vhdl-reset-name) vhdl-reset-name))
9952 (vhdl-template-field "reset name") "<reset>")))
9953 (insert ")"))
9954 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9955 (insert "\n")
9956 (vhdl-template-begin-end "PROCESS" label margin)
9957 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9958 (when vhdl-prompt-for-comments
9959 (setq final-pos (point-marker))
9960 (vhdl-prepare-search-2
9961 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9962 (vhdl-re-search-backward "\\<process\\>" nil t))
9963 (end-of-line -0)
9964 (if (bobp)
9965 (progn (insert "\n") (forward-line -1))
9966 (insert "\n"))
9967 (indent-to margin)
9968 (insert "-- purpose: ")
9969 (if (not (vhdl-template-field "[description]" nil t))
9970 (vhdl-line-kill-entire)
9971 (insert "\n")
9972 (indent-to margin)
9973 (insert "-- type : ")
9974 (insert (if seq "sequential" "combinational") "\n")
9975 (indent-to margin)
9976 (insert "-- inputs : ")
9977 (if (not seq)
9978 (insert input-signals)
9979 (insert clock ", ")
9980 (when reset (insert reset ", "))
9981 (unless (vhdl-template-field "[signal names]" nil t)
9982 (delete-char -2)))
9983 (insert "\n")
9984 (indent-to margin)
9985 (insert "-- outputs: ")
9986 (vhdl-template-field "[signal names]" nil t))))
9987 (goto-char final-pos))))
9988
9989 (defun vhdl-template-process-comb ()
9990 "Insert a combinational process."
9991 (interactive)
9992 (vhdl-template-process 'comb))
9993
9994 (defun vhdl-template-process-seq ()
9995 "Insert a sequential process."
9996 (interactive)
9997 (vhdl-template-process 'seq))
9998
9999 (defun vhdl-template-quantity ()
10000 "Insert a quantity declaration."
10001 (interactive)
10002 (if (vhdl-in-argument-list-p)
10003 (let ((start (point)))
10004 (vhdl-insert-keyword "QUANTITY ")
10005 (when (vhdl-template-field "names" nil t start (point))
10006 (insert " : ")
10007 (vhdl-template-field "[IN | OUT]" " " t)
10008 (vhdl-template-field "type")
10009 (insert ";")
10010 (vhdl-comment-insert-inline)))
10011 (let ((char (vhdl-decision-query
10012 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
10013 (cond ((eq char ?f) (vhdl-template-quantity-free))
10014 ((eq char ?b) (vhdl-template-quantity-branch))
10015 ((eq char ?s) (vhdl-template-quantity-source))
10016 (t (vhdl-template-undo (point) (point)))))))
10017
10018 (defun vhdl-template-quantity-free ()
10019 "Insert a free quantity declaration."
10020 (interactive)
10021 (vhdl-insert-keyword "QUANTITY ")
10022 (vhdl-template-field "names")
10023 (insert " : ")
10024 (vhdl-template-field "type")
10025 (let ((position (point)))
10026 (insert " := ")
10027 (unless (vhdl-template-field "[initialization]" nil t)
10028 (delete-region position (point)))
10029 (insert ";")
10030 (vhdl-comment-insert-inline)))
10031
10032 (defun vhdl-template-quantity-branch ()
10033 "Insert a branch quantity declaration."
10034 (interactive)
10035 (let (position)
10036 (vhdl-insert-keyword "QUANTITY ")
10037 (when (vhdl-template-field "[across names]" " " t)
10038 (vhdl-insert-keyword "ACROSS "))
10039 (when (vhdl-template-field "[through names]" " " t)
10040 (vhdl-insert-keyword "THROUGH "))
10041 (vhdl-template-field "plus terminal name")
10042 (setq position (point))
10043 (vhdl-insert-keyword " TO ")
10044 (unless (vhdl-template-field "[minus terminal name]" nil t)
10045 (delete-region position (point)))
10046 (insert ";")
10047 (vhdl-comment-insert-inline)))
10048
10049 (defun vhdl-template-quantity-source ()
10050 "Insert a source quantity declaration."
10051 (interactive)
10052 (vhdl-insert-keyword "QUANTITY ")
10053 (vhdl-template-field "names")
10054 (insert " : ")
10055 (vhdl-template-field "type" " ")
10056 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
10057 (progn (vhdl-insert-keyword "NOISE ")
10058 (vhdl-template-field "power expression"))
10059 (vhdl-insert-keyword "SPECTRUM ")
10060 (vhdl-template-field "magnitude expression" ", ")
10061 (vhdl-template-field "phase expression"))
10062 (insert ";")
10063 (vhdl-comment-insert-inline))
10064
10065 (defun vhdl-template-record (kind &optional name secondary)
10066 "Insert a record type declaration."
10067 (interactive)
10068 (let ((margin (current-indentation))
10069 (start (point))
10070 (first t))
10071 (vhdl-insert-keyword "RECORD\n")
10072 (indent-to (+ margin vhdl-basic-offset))
10073 (when (or (vhdl-template-field "element names"
10074 nil (not secondary) start (point))
10075 secondary)
10076 (while (or first (vhdl-template-field "[element names]" nil t))
10077 (insert " : ")
10078 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
10079 (vhdl-comment-insert-inline)
10080 (insert "\n")
10081 (indent-to (+ margin vhdl-basic-offset))
10082 (setq first nil))
10083 (delete-region (line-beginning-position) (point))
10084 (indent-to margin)
10085 (vhdl-insert-keyword "END RECORD")
10086 (unless (vhdl-standard-p '87) (and name (insert " " name)))
10087 (insert ";")
10088 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10089
10090 (defun vhdl-template-report ()
10091 "Insert a report statement."
10092 (interactive)
10093 (let ((start (point)))
10094 (vhdl-insert-keyword "REPORT ")
10095 (if (equal "\"\"" (vhdl-template-field
10096 "string expression" nil t start (point) t))
10097 (delete-char -2)
10098 (setq start (point))
10099 (vhdl-insert-keyword " SEVERITY ")
10100 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
10101 (delete-region start (point)))
10102 (insert ";"))))
10103
10104 (defun vhdl-template-return ()
10105 "Insert a return statement."
10106 (interactive)
10107 (let ((start (point)))
10108 (vhdl-insert-keyword "RETURN ")
10109 (unless (vhdl-template-field "[expression]" nil t start (point))
10110 (delete-char -1))
10111 (insert ";")))
10112
10113 (defun vhdl-template-selected-signal-asst ()
10114 "Insert a selected signal assignment."
10115 (interactive)
10116 (let ((margin (current-indentation))
10117 (start (point))
10118 (choices t))
10119 (let ((position (point)))
10120 (vhdl-insert-keyword " SELECT ")
10121 (goto-char position))
10122 (vhdl-insert-keyword "WITH ")
10123 (when (vhdl-template-field "selector expression"
10124 nil t start (+ (point) 7))
10125 (forward-word 1)
10126 (delete-char 1)
10127 (insert "\n")
10128 (indent-to (+ margin vhdl-basic-offset))
10129 (vhdl-template-field "target signal" " <= ")
10130 (insert "\n")
10131 (indent-to (+ margin vhdl-basic-offset))
10132 (vhdl-template-field "waveform")
10133 (vhdl-insert-keyword " WHEN ")
10134 (vhdl-template-field "choices" ",")
10135 (insert "\n")
10136 (indent-to (+ margin vhdl-basic-offset))
10137 (while (and choices (vhdl-template-field "[waveform]" nil t))
10138 (vhdl-insert-keyword " WHEN ")
10139 (if (setq choices (vhdl-template-field "[choices]" "," t))
10140 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10141 (vhdl-insert-keyword "OTHERS")))
10142 (when choices
10143 (fixup-whitespace)
10144 (delete-char -2))
10145 (insert ";")
10146 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10147
10148 (defun vhdl-template-signal ()
10149 "Insert a signal declaration."
10150 (interactive)
10151 (let ((start (point))
10152 (in-arglist (vhdl-in-argument-list-p)))
10153 (vhdl-insert-keyword "SIGNAL ")
10154 (when (vhdl-template-field "names" nil t start (point))
10155 (insert " : ")
10156 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10157 (vhdl-template-field "type")
10158 (if in-arglist
10159 (progn (insert ";")
10160 (vhdl-comment-insert-inline))
10161 (let ((position (point)))
10162 (insert " := ")
10163 (unless (vhdl-template-field "[initialization]" nil t)
10164 (delete-region position (point)))
10165 (insert ";")
10166 (vhdl-comment-insert-inline))))))
10167
10168 (defun vhdl-template-subnature ()
10169 "Insert a subnature declaration."
10170 (interactive)
10171 (let ((start (point))
10172 position)
10173 (vhdl-insert-keyword "SUBNATURE ")
10174 (when (vhdl-template-field "name" nil t start (point))
10175 (vhdl-insert-keyword " IS ")
10176 (vhdl-template-field "nature" " (")
10177 (if (vhdl-template-field "[index range]" nil t)
10178 (insert ")")
10179 (delete-char -2))
10180 (setq position (point))
10181 (vhdl-insert-keyword " TOLERANCE ")
10182 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10183 nil t nil nil t))
10184 (delete-region position (point))
10185 (vhdl-insert-keyword " ACROSS ")
10186 (vhdl-template-field "string expression" nil nil nil nil t)
10187 (vhdl-insert-keyword " THROUGH"))
10188 (insert ";")
10189 (vhdl-comment-insert-inline))))
10190
10191 (defun vhdl-template-subprogram-body ()
10192 "Insert a subprogram body."
10193 (interactive)
10194 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10195 (vhdl-template-function-body)
10196 (vhdl-template-procedure-body)))
10197
10198 (defun vhdl-template-subprogram-decl ()
10199 "Insert a subprogram declaration."
10200 (interactive)
10201 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10202 (vhdl-template-function-decl)
10203 (vhdl-template-procedure-decl)))
10204
10205 (defun vhdl-template-subtype ()
10206 "Insert a subtype declaration."
10207 (interactive)
10208 (let ((start (point)))
10209 (vhdl-insert-keyword "SUBTYPE ")
10210 (when (vhdl-template-field "name" nil t start (point))
10211 (vhdl-insert-keyword " IS ")
10212 (vhdl-template-field "type" " ")
10213 (unless
10214 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10215 (delete-char -1))
10216 (insert ";")
10217 (vhdl-comment-insert-inline))))
10218
10219 (defun vhdl-template-terminal ()
10220 "Insert a terminal declaration."
10221 (interactive)
10222 (let ((start (point)))
10223 (vhdl-insert-keyword "TERMINAL ")
10224 (when (vhdl-template-field "names" nil t start (point))
10225 (insert " : ")
10226 (vhdl-template-field "nature")
10227 (insert ";")
10228 (vhdl-comment-insert-inline))))
10229
10230 (defun vhdl-template-type ()
10231 "Insert a type declaration."
10232 (interactive)
10233 (let ((start (point))
10234 name mid-pos end-pos)
10235 (vhdl-insert-keyword "TYPE ")
10236 (when (setq name (vhdl-template-field "name" nil t start (point)))
10237 (vhdl-insert-keyword " IS ")
10238 (let ((definition
10239 (upcase
10240 (or (vhdl-template-field
10241 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10242 ""))))
10243 (cond ((equal definition "")
10244 (delete-char -4)
10245 (insert ";"))
10246 ((equal definition "ARRAY")
10247 (delete-region (point) (progn (forward-word -1) (point)))
10248 (vhdl-template-array 'type t))
10249 ((equal definition "RECORD")
10250 (setq mid-pos (point-marker))
10251 (delete-region (point) (progn (forward-word -1) (point)))
10252 (vhdl-template-record 'type name t))
10253 ((equal definition "ACCESS")
10254 (insert " ")
10255 (vhdl-template-field "type" ";"))
10256 ((equal definition "FILE")
10257 (vhdl-insert-keyword " OF ")
10258 (vhdl-template-field "type" ";"))
10259 ((equal definition "ENUM")
10260 (kill-word -1)
10261 (insert "(")
10262 (setq end-pos (point-marker))
10263 (insert ");"))
10264 (t (insert ";")))
10265 (when mid-pos
10266 (setq end-pos (point-marker))
10267 (goto-char mid-pos)
10268 (end-of-line))
10269 (vhdl-comment-insert-inline)
10270 (when end-pos (goto-char end-pos))))))
10271
10272 (defun vhdl-template-use ()
10273 "Insert a use clause."
10274 (interactive)
10275 (let ((start (point)))
10276 (vhdl-prepare-search-1
10277 (vhdl-insert-keyword "USE ")
10278 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10279 (vhdl-insert-keyword "..ALL;")
10280 (backward-char 6)
10281 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10282 (forward-char 1)
10283 (vhdl-template-field "package name")
10284 (forward-char 5))))))
10285
10286 (defun vhdl-template-variable ()
10287 "Insert a variable declaration."
10288 (interactive)
10289 (let ((start (point))
10290 (in-arglist (vhdl-in-argument-list-p)))
10291 (vhdl-prepare-search-2
10292 (if (or (save-excursion
10293 (progn (vhdl-beginning-of-block)
10294 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10295 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
10296 (vhdl-insert-keyword "VARIABLE ")
10297 (if (vhdl-standard-p '87)
10298 (error "ERROR: Not within sequential block")
10299 (vhdl-insert-keyword "SHARED VARIABLE "))))
10300 (when (vhdl-template-field "names" nil t start (point))
10301 (insert " : ")
10302 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10303 (vhdl-template-field "type")
10304 (if in-arglist
10305 (progn (insert ";")
10306 (vhdl-comment-insert-inline))
10307 (let ((position (point)))
10308 (insert " := ")
10309 (unless (vhdl-template-field "[initialization]" nil t)
10310 (delete-region position (point)))
10311 (insert ";")
10312 (vhdl-comment-insert-inline))))))
10313
10314 (defun vhdl-template-wait ()
10315 "Insert a wait statement."
10316 (interactive)
10317 (vhdl-insert-keyword "WAIT ")
10318 (unless (vhdl-template-field
10319 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10320 nil t)
10321 (delete-char -1))
10322 (insert ";"))
10323
10324 (defun vhdl-template-when ()
10325 "Indent correctly if within a case statement."
10326 (interactive)
10327 (let ((position (point))
10328 margin)
10329 (vhdl-prepare-search-2
10330 (if (and (= (current-column) (current-indentation))
10331 (vhdl-re-search-forward "\\<end\\>" nil t)
10332 (looking-at "\\s-*\\<case\\>"))
10333 (progn
10334 (setq margin (current-indentation))
10335 (goto-char position)
10336 (delete-horizontal-space)
10337 (indent-to (+ margin vhdl-basic-offset)))
10338 (goto-char position)))
10339 (vhdl-insert-keyword "WHEN ")))
10340
10341 (defun vhdl-template-while-loop ()
10342 "Insert a while loop."
10343 (interactive)
10344 (let* ((margin (current-indentation))
10345 (start (point))
10346 label)
10347 (if (not (eq vhdl-optional-labels 'all))
10348 (vhdl-insert-keyword "WHILE ")
10349 (vhdl-insert-keyword ": WHILE ")
10350 (goto-char start)
10351 (setq label (vhdl-template-field "[label]" nil t))
10352 (unless label (delete-char 2))
10353 (forward-word 1)
10354 (forward-char 1))
10355 (when vhdl-conditions-in-parenthesis (insert "("))
10356 (when (vhdl-template-field "condition" nil t start (point))
10357 (when vhdl-conditions-in-parenthesis (insert ")"))
10358 (vhdl-insert-keyword " LOOP\n\n")
10359 (indent-to margin)
10360 (vhdl-insert-keyword "END LOOP")
10361 (insert (if label (concat " " label ";") ";"))
10362 (forward-line -1)
10363 (indent-to (+ margin vhdl-basic-offset)))))
10364
10365 (defun vhdl-template-with ()
10366 "Insert a with statement (i.e. selected signal assignment)."
10367 (interactive)
10368 (vhdl-prepare-search-1
10369 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10370 (equal ";" (match-string 1)))
10371 (vhdl-template-selected-signal-asst)
10372 (vhdl-insert-keyword "WITH "))))
10373
10374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10375 ;; Special templates
10376
10377 (defun vhdl-template-clocked-wait ()
10378 "Insert a wait statement for rising/falling clock edge."
10379 (interactive)
10380 (let ((start (point))
10381 clock)
10382 (vhdl-insert-keyword "WAIT UNTIL ")
10383 (when (setq clock
10384 (or (and (not (equal "" vhdl-clock-name))
10385 (progn (insert vhdl-clock-name) vhdl-clock-name))
10386 (vhdl-template-field "clock name" nil t start (point))))
10387 (insert "'event")
10388 (vhdl-insert-keyword " AND ")
10389 (insert clock)
10390 (insert
10391 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10392 (vhdl-comment-insert-inline
10393 (concat (if vhdl-clock-rising-edge "rising" "falling")
10394 " clock edge")))))
10395
10396 (defun vhdl-template-seq-process (clock reset reset-kind)
10397 "Insert a template for the body of a sequential process."
10398 (let ((margin (current-indentation))
10399 position)
10400 (vhdl-insert-keyword "IF ")
10401 (when vhdl-conditions-in-parenthesis (insert "("))
10402 (when (eq reset-kind 'async)
10403 (insert reset " = "
10404 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10405 (when vhdl-conditions-in-parenthesis (insert ")"))
10406 (vhdl-insert-keyword " THEN")
10407 (vhdl-comment-insert-inline
10408 (concat "asynchronous reset (active "
10409 (if vhdl-reset-active-high "high" "low") ")"))
10410 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10411 (setq position (point))
10412 (insert "\n") (indent-to margin)
10413 (vhdl-insert-keyword "ELSIF ")
10414 (when vhdl-conditions-in-parenthesis (insert "(")))
10415 (if (eq vhdl-clock-edge-condition 'function)
10416 (insert (if vhdl-clock-rising-edge "rising" "falling")
10417 "_edge(" clock ")")
10418 (insert clock "'event")
10419 (vhdl-insert-keyword " AND ")
10420 (insert clock " = "
10421 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10422 (when vhdl-conditions-in-parenthesis (insert ")"))
10423 (vhdl-insert-keyword " THEN")
10424 (vhdl-comment-insert-inline
10425 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10426 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10427 (when (eq reset-kind 'sync)
10428 (vhdl-insert-keyword "IF ")
10429 (when vhdl-conditions-in-parenthesis (insert "("))
10430 (setq reset (or (and (not (equal "" vhdl-reset-name))
10431 (progn (insert vhdl-reset-name) vhdl-reset-name))
10432 (vhdl-template-field "reset name") "<reset>"))
10433 (insert " = "
10434 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10435 (when vhdl-conditions-in-parenthesis (insert ")"))
10436 (vhdl-insert-keyword " THEN")
10437 (vhdl-comment-insert-inline
10438 (concat "synchronous reset (active "
10439 (if vhdl-reset-active-high "high" "low") ")"))
10440 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10441 (setq position (point))
10442 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10443 (vhdl-insert-keyword "ELSE")
10444 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10445 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10446 (vhdl-insert-keyword "END IF;"))
10447 (when (eq reset-kind 'none)
10448 (setq position (point)))
10449 (insert "\n") (indent-to margin)
10450 (vhdl-insert-keyword "END IF;")
10451 (goto-char position)
10452 reset))
10453
10454 (defun vhdl-template-standard-package (library package)
10455 "Insert specification of a standard package. Include a library
10456 specification, if not already there."
10457 (let ((margin (current-indentation)))
10458 (unless (equal library "std")
10459 (unless (or (save-excursion
10460 (vhdl-prepare-search-1
10461 (and (not (bobp))
10462 (re-search-backward
10463 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10464 library "\\|end\\)\\>") nil t)
10465 (match-string 2))))
10466 (equal (downcase library) "work"))
10467 (vhdl-insert-keyword "LIBRARY ")
10468 (insert library ";")
10469 (when package
10470 (insert "\n")
10471 (indent-to margin))))
10472 (when package
10473 (vhdl-insert-keyword "USE ")
10474 (insert library "." package)
10475 (vhdl-insert-keyword ".ALL;"))))
10476
10477 (defun vhdl-template-package-numeric-bit ()
10478 "Insert specification of `numeric_bit' package."
10479 (interactive)
10480 (vhdl-template-standard-package "ieee" "numeric_bit"))
10481
10482 (defun vhdl-template-package-numeric-std ()
10483 "Insert specification of `numeric_std' package."
10484 (interactive)
10485 (vhdl-template-standard-package "ieee" "numeric_std"))
10486
10487 (defun vhdl-template-package-std-logic-1164 ()
10488 "Insert specification of `std_logic_1164' package."
10489 (interactive)
10490 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10491
10492 (defun vhdl-template-package-std-logic-arith ()
10493 "Insert specification of `std_logic_arith' package."
10494 (interactive)
10495 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10496
10497 (defun vhdl-template-package-std-logic-misc ()
10498 "Insert specification of `std_logic_misc' package."
10499 (interactive)
10500 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10501
10502 (defun vhdl-template-package-std-logic-signed ()
10503 "Insert specification of `std_logic_signed' package."
10504 (interactive)
10505 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10506
10507 (defun vhdl-template-package-std-logic-textio ()
10508 "Insert specification of `std_logic_textio' package."
10509 (interactive)
10510 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10511
10512 (defun vhdl-template-package-std-logic-unsigned ()
10513 "Insert specification of `std_logic_unsigned' package."
10514 (interactive)
10515 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10516
10517 (defun vhdl-template-package-textio ()
10518 "Insert specification of `textio' package."
10519 (interactive)
10520 (vhdl-template-standard-package "std" "textio"))
10521
10522 (defun vhdl-template-package-fundamental-constants ()
10523 "Insert specification of `fundamental_constants' package."
10524 (interactive)
10525 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10526
10527 (defun vhdl-template-package-material-constants ()
10528 "Insert specification of `material_constants' package."
10529 (interactive)
10530 (vhdl-template-standard-package "ieee" "material_constants"))
10531
10532 (defun vhdl-template-package-energy-systems ()
10533 "Insert specification of `energy_systems' package."
10534 (interactive)
10535 (vhdl-template-standard-package "ieee" "energy_systems"))
10536
10537 (defun vhdl-template-package-electrical-systems ()
10538 "Insert specification of `electrical_systems' package."
10539 (interactive)
10540 (vhdl-template-standard-package "ieee" "electrical_systems"))
10541
10542 (defun vhdl-template-package-mechanical-systems ()
10543 "Insert specification of `mechanical_systems' package."
10544 (interactive)
10545 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10546
10547 (defun vhdl-template-package-radiant-systems ()
10548 "Insert specification of `radiant_systems' package."
10549 (interactive)
10550 (vhdl-template-standard-package "ieee" "radiant_systems"))
10551
10552 (defun vhdl-template-package-thermal-systems ()
10553 "Insert specification of `thermal_systems' package."
10554 (interactive)
10555 (vhdl-template-standard-package "ieee" "thermal_systems"))
10556
10557 (defun vhdl-template-package-fluidic-systems ()
10558 "Insert specification of `fluidic_systems' package."
10559 (interactive)
10560 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10561
10562 (defun vhdl-template-package-math-complex ()
10563 "Insert specification of `math_complex' package."
10564 (interactive)
10565 (vhdl-template-standard-package "ieee" "math_complex"))
10566
10567 (defun vhdl-template-package-math-real ()
10568 "Insert specification of `math_real' package."
10569 (interactive)
10570 (vhdl-template-standard-package "ieee" "math_real"))
10571
10572 (defun vhdl-template-directive (directive)
10573 "Insert directive."
10574 (unless (= (current-indentation) (current-column))
10575 (delete-horizontal-space)
10576 (insert " "))
10577 (insert "-- pragma " directive))
10578
10579 (defun vhdl-template-directive-translate-on ()
10580 "Insert directive 'translate_on'."
10581 (interactive)
10582 (vhdl-template-directive "translate_on"))
10583
10584 (defun vhdl-template-directive-translate-off ()
10585 "Insert directive 'translate_off'."
10586 (interactive)
10587 (vhdl-template-directive "translate_off"))
10588
10589 (defun vhdl-template-directive-synthesis-on ()
10590 "Insert directive 'synthesis_on'."
10591 (interactive)
10592 (vhdl-template-directive "synthesis_on"))
10593
10594 (defun vhdl-template-directive-synthesis-off ()
10595 "Insert directive 'synthesis_off'."
10596 (interactive)
10597 (vhdl-template-directive "synthesis_off"))
10598
10599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10600 ;; Header and footer templates
10601
10602 (defun vhdl-template-header (&optional file-title)
10603 "Insert a VHDL file header."
10604 (interactive)
10605 (unless (equal vhdl-file-header "")
10606 (let (pos)
10607 (save-excursion
10608 (goto-char (point-min))
10609 (vhdl-insert-string-or-file vhdl-file-header)
10610 (setq pos (point-marker)))
10611 (vhdl-template-replace-header-keywords
10612 (point-min-marker) pos file-title))))
10613
10614 (defun vhdl-template-footer ()
10615 "Insert a VHDL file footer."
10616 (interactive)
10617 (unless (equal vhdl-file-footer "")
10618 (let (pos)
10619 (save-excursion
10620 (goto-char (point-max))
10621 (setq pos (point-marker))
10622 (vhdl-insert-string-or-file vhdl-file-footer)
10623 (unless (= (preceding-char) ?\n)
10624 (insert "\n")))
10625 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10626
10627 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10628 is-model)
10629 "Replace keywords in header and footer."
10630 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10631 ""))
10632 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10633 ""))
10634 pos)
10635 (vhdl-prepare-search-2
10636 (save-excursion
10637 (goto-char beg)
10638 (while (search-forward "<projectdesc>" end t)
10639 (replace-match project-desc t t))
10640 (goto-char beg)
10641 (while (search-forward "<filename>" end t)
10642 (replace-match (buffer-name) t t))
10643 (goto-char beg)
10644 (while (search-forward "<copyright>" end t)
10645 (replace-match vhdl-copyright-string t t))
10646 (goto-char beg)
10647 (while (search-forward "<author>" end t)
10648 (replace-match "" t t)
10649 (insert (user-full-name))
10650 (when user-mail-address (insert " <" user-mail-address ">")))
10651 (goto-char beg)
10652 (while (search-forward "<authorfull>" end t)
10653 (replace-match (user-full-name) t t))
10654 (goto-char beg)
10655 (while (search-forward "<login>" end t)
10656 (replace-match (user-login-name) t t))
10657 (goto-char beg)
10658 (while (search-forward "<project>" end t)
10659 (replace-match project-title t t))
10660 (goto-char beg)
10661 (while (search-forward "<company>" end t)
10662 (replace-match vhdl-company-name t t))
10663 (goto-char beg)
10664 (while (search-forward "<platform>" end t)
10665 (replace-match vhdl-platform-spec t t))
10666 (goto-char beg)
10667 (while (search-forward "<standard>" end t)
10668 (replace-match
10669 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10670 ((vhdl-standard-p '93) "'93/02")
10671 ((vhdl-standard-p '08) "'08"))
10672 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10673 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10674 (goto-char beg)
10675 ;; Replace <RCS> with $, so that RCS for the source is
10676 ;; not over-enthusiastic with replacements
10677 (while (search-forward "<RCS>" end t)
10678 (replace-match "$" nil t))
10679 (goto-char beg)
10680 (while (search-forward "<date>" end t)
10681 (replace-match "" t t)
10682 (vhdl-template-insert-date))
10683 (goto-char beg)
10684 (while (search-forward "<year>" end t)
10685 (replace-match (format-time-string "%Y" nil) t t))
10686 (goto-char beg)
10687 (when file-title
10688 (while (search-forward "<title string>" end t)
10689 (replace-match file-title t t))
10690 (goto-char beg))
10691 (let (string)
10692 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10693 (save-match-data
10694 (setq string (read-string (concat (match-string 1) ": "))))
10695 (replace-match string t t)))
10696 (goto-char beg)
10697 (when (and (not is-model) (search-forward "<cursor>" end t))
10698 (replace-match "" t t)
10699 (setq pos (point))))
10700 (when pos (goto-char pos))
10701 (unless is-model
10702 (when (or (not project-title) (equal project-title ""))
10703 (message "You can specify a project title in user option `vhdl-project-alist'"))
10704 (when (or (not project-desc) (equal project-desc ""))
10705 (message "You can specify a project description in user option `vhdl-project-alist'"))
10706 (when (equal vhdl-platform-spec "")
10707 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10708 (when (equal vhdl-company-name "")
10709 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10710
10711 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10712 ;; Comment templates and functions
10713
10714 (defun vhdl-comment-indent ()
10715 "Indent comments."
10716 (let* ((position (point))
10717 (col
10718 (progn
10719 (forward-line -1)
10720 (if (re-search-forward "--" position t)
10721 (- (current-column) 2) ; existing comment at bol stays there
10722 (goto-char position)
10723 (skip-chars-backward " \t")
10724 (max comment-column ; else indent to comment column
10725 (1+ (current-column))))))) ; except leave at least one space
10726 (goto-char position)
10727 col))
10728
10729 (defun vhdl-comment-insert ()
10730 "Start a comment at the end of the line.
10731 If on line with code, indent at least `comment-column'.
10732 If starting after end-comment-column, start a new line."
10733 (interactive)
10734 (when (> (current-column) end-comment-column) (newline-and-indent))
10735 (if (or (looking-at "\\s-*$") ; end of line
10736 (and (not unread-command-events) ; called with key binding or menu
10737 (not (end-of-line))))
10738 (let (margin)
10739 (while (= (preceding-char) ?-) (delete-char -1))
10740 (setq margin (current-column))
10741 (delete-horizontal-space)
10742 (if (bolp)
10743 (progn (indent-to margin) (insert "--"))
10744 (insert " ")
10745 (indent-to comment-column)
10746 (insert "--"))
10747 (if (not unread-command-events) (insert " ")))
10748 ;; else code following current point implies commenting out code
10749 (let (next-input code)
10750 (while (= (preceding-char) ?-) (delete-char -2))
10751 (while (= (setq next-input (read-char)) 13) ; CR
10752 (insert "--") ; or have a space after it?
10753 (forward-char -2)
10754 (forward-line 1)
10755 (message "Enter CR if commenting out a line of code.")
10756 (setq code t))
10757 (unless code
10758 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10759 (push (vhdl-character-to-event next-input) ; pushback the char
10760 unread-command-events))))
10761
10762 (defun vhdl-comment-display (&optional line-exists)
10763 "Add 2 comment lines at the current indent, making a display comment."
10764 (interactive)
10765 (let ((margin (current-indentation)))
10766 (unless line-exists (vhdl-comment-display-line))
10767 (insert "\n") (indent-to margin)
10768 (insert "\n") (indent-to margin)
10769 (vhdl-comment-display-line)
10770 (end-of-line -0)
10771 (insert "-- ")))
10772
10773 (defun vhdl-comment-display-line ()
10774 "Displays one line of dashes."
10775 (interactive)
10776 (while (= (preceding-char) ?-) (delete-char -2))
10777 (insert "--")
10778 (let* ((col (current-column))
10779 (len (- end-comment-column col)))
10780 (insert-char vhdl-comment-display-line-char len)))
10781
10782 (defun vhdl-comment-append-inline ()
10783 "Append empty inline comment to current line."
10784 (interactive)
10785 (end-of-line)
10786 (delete-horizontal-space)
10787 (insert " ")
10788 (indent-to comment-column)
10789 (insert "-- "))
10790
10791 (defun vhdl-comment-insert-inline (&optional string always-insert)
10792 "Insert inline comment."
10793 (when (or (and string (or vhdl-self-insert-comments always-insert))
10794 (and (not string) vhdl-prompt-for-comments))
10795 (let ((position (point)))
10796 (insert " ")
10797 (indent-to comment-column)
10798 (insert "-- ")
10799 (if (not (or (and string (progn (insert string) t))
10800 (vhdl-template-field "[comment]" nil t)))
10801 (delete-region position (point))
10802 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10803
10804 (defun vhdl-comment-block ()
10805 "Insert comment for code block."
10806 (when vhdl-prompt-for-comments
10807 (let ((final-pos (point-marker)))
10808 (vhdl-prepare-search-2
10809 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10810 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10811 (let (margin)
10812 (back-to-indentation)
10813 (setq margin (current-column))
10814 (end-of-line -0)
10815 (if (bobp)
10816 (progn (insert "\n") (forward-line -1))
10817 (insert "\n"))
10818 (indent-to margin)
10819 (insert "-- purpose: ")
10820 (unless (vhdl-template-field "[description]" nil t)
10821 (vhdl-line-kill-entire)))))
10822 (goto-char final-pos))))
10823
10824 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10825 "Comment out region if not commented out, uncomment otherwise."
10826 (interactive "r\nP")
10827 (save-excursion
10828 (goto-char (1- end))
10829 (end-of-line)
10830 (setq end (point-marker))
10831 (goto-char beg)
10832 (beginning-of-line)
10833 (setq beg (point))
10834 (if (looking-at (concat "\\s-*" comment-start))
10835 (comment-region beg end '(4))
10836 (comment-region beg end))))
10837
10838 (defun vhdl-comment-uncomment-line (&optional arg)
10839 "Comment out line if not commented out, uncomment otherwise."
10840 (interactive "p")
10841 (save-excursion
10842 (beginning-of-line)
10843 (let ((position (point)))
10844 (forward-line (or arg 1))
10845 (vhdl-comment-uncomment-region position (point)))))
10846
10847 (defun vhdl-comment-kill-region (beg end)
10848 "Kill comments in region."
10849 (interactive "r")
10850 (save-excursion
10851 (goto-char end)
10852 (setq end (point-marker))
10853 (goto-char beg)
10854 (beginning-of-line)
10855 (while (< (point) end)
10856 (if (looking-at "^\\(\\s-*--.*\n\\)")
10857 (progn (delete-region (match-beginning 1) (match-end 1)))
10858 (beginning-of-line 2)))))
10859
10860 (defun vhdl-comment-kill-inline-region (beg end)
10861 "Kill inline comments in region."
10862 (interactive "r")
10863 (save-excursion
10864 (goto-char end)
10865 (setq end (point-marker))
10866 (goto-char beg)
10867 (beginning-of-line)
10868 (while (< (point) end)
10869 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10870 (delete-region (match-beginning 1) (match-end 1)))
10871 (beginning-of-line 2))))
10872
10873 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10874 ;; Subtemplates
10875
10876 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10877 "Insert a begin ... end pair with optional name after the end.
10878 Point is left between them."
10879 (let (position)
10880 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10881 (indent-to margin)
10882 (vhdl-insert-keyword "BEGIN")
10883 (when (and (or construct name) vhdl-self-insert-comments)
10884 (insert " --")
10885 (when construct (insert " ") (vhdl-insert-keyword construct))
10886 (when name (insert " " name)))
10887 (insert "\n")
10888 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10889 (indent-to (+ margin vhdl-basic-offset))
10890 (setq position (point))
10891 (insert "\n")
10892 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10893 (indent-to margin)
10894 (vhdl-insert-keyword "END")
10895 (when construct (insert " ") (vhdl-insert-keyword construct))
10896 (insert (if name (concat " " name) "") ";")
10897 (goto-char position)))
10898
10899 (defun vhdl-template-argument-list (&optional is-function)
10900 "Read from user a procedure or function argument list."
10901 (insert " (")
10902 (let ((margin (current-column))
10903 (start (point))
10904 (end-pos (point))
10905 not-empty interface semicolon-pos)
10906 (unless vhdl-argument-list-indent
10907 (setq margin (+ (current-indentation) vhdl-basic-offset))
10908 (insert "\n")
10909 (indent-to margin))
10910 (setq interface (vhdl-template-field
10911 (concat "[CONSTANT | SIGNAL"
10912 (unless is-function " | VARIABLE") "]") " " t))
10913 (while (vhdl-template-field "[names]" nil t)
10914 (setq not-empty t)
10915 (insert " : ")
10916 (unless is-function
10917 (if (and interface (equal (upcase interface) "CONSTANT"))
10918 (vhdl-insert-keyword "IN ")
10919 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10920 (vhdl-template-field "type")
10921 (setq semicolon-pos (point))
10922 (insert ";")
10923 (vhdl-comment-insert-inline)
10924 (setq end-pos (point))
10925 (insert "\n")
10926 (indent-to margin)
10927 (setq interface (vhdl-template-field
10928 (concat "[CONSTANT | SIGNAL"
10929 (unless is-function " | VARIABLE") "]") " " t)))
10930 (delete-region end-pos (point))
10931 (when semicolon-pos (goto-char semicolon-pos))
10932 (if not-empty
10933 (progn (delete-char 1) (insert ")"))
10934 (delete-char -2))))
10935
10936 (defun vhdl-template-generic-list (optional &optional no-value)
10937 "Read from user a generic spec argument list."
10938 (let (margin
10939 (start (point)))
10940 (vhdl-insert-keyword "GENERIC (")
10941 (setq margin (current-column))
10942 (unless vhdl-argument-list-indent
10943 (let ((position (point)))
10944 (back-to-indentation)
10945 (setq margin (+ (current-column) vhdl-basic-offset))
10946 (goto-char position)
10947 (insert "\n")
10948 (indent-to margin)))
10949 (let ((vhdl-generics (vhdl-template-field
10950 (concat (and optional "[") "name"
10951 (and no-value "s") (and optional "]"))
10952 nil optional)))
10953 (if (not vhdl-generics)
10954 (if optional
10955 (progn (vhdl-line-kill-entire) (end-of-line -0)
10956 (unless vhdl-argument-list-indent
10957 (vhdl-line-kill-entire) (end-of-line -0)))
10958 (vhdl-template-undo start (point))
10959 nil )
10960 (insert " : ")
10961 (let (semicolon-pos end-pos)
10962 (while vhdl-generics
10963 (vhdl-template-field "type")
10964 (if no-value
10965 (progn (setq semicolon-pos (point))
10966 (insert ";"))
10967 (insert " := ")
10968 (unless (vhdl-template-field "[value]" nil t)
10969 (delete-char -4))
10970 (setq semicolon-pos (point))
10971 (insert ";"))
10972 (vhdl-comment-insert-inline)
10973 (setq end-pos (point))
10974 (insert "\n")
10975 (indent-to margin)
10976 (setq vhdl-generics (vhdl-template-field
10977 (concat "[name" (and no-value "s") "]")
10978 " : " t)))
10979 (delete-region end-pos (point))
10980 (goto-char semicolon-pos)
10981 (insert ")")
10982 (end-of-line)
10983 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10984 t)))))
10985
10986 (defun vhdl-template-port-list (optional)
10987 "Read from user a port spec argument list."
10988 (let ((start (point))
10989 margin vhdl-ports object)
10990 (vhdl-insert-keyword "PORT (")
10991 (setq margin (current-column))
10992 (unless vhdl-argument-list-indent
10993 (let ((position (point)))
10994 (back-to-indentation)
10995 (setq margin (+ (current-column) vhdl-basic-offset))
10996 (goto-char position)
10997 (insert "\n")
10998 (indent-to margin)))
10999 (when (vhdl-standard-p 'ams)
11000 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11001 " " t)))
11002 (setq vhdl-ports (vhdl-template-field
11003 (concat (and optional "[") "names" (and optional "]"))
11004 nil optional))
11005 (if (not vhdl-ports)
11006 (if optional
11007 (progn (vhdl-line-kill-entire) (end-of-line -0)
11008 (unless vhdl-argument-list-indent
11009 (vhdl-line-kill-entire) (end-of-line -0)))
11010 (vhdl-template-undo start (point))
11011 nil)
11012 (insert " : ")
11013 (let (semicolon-pos end-pos)
11014 (while vhdl-ports
11015 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
11016 (vhdl-template-field "IN | OUT | INOUT" " "))
11017 ((equal "QUANTITY" (upcase object))
11018 (vhdl-template-field "[IN | OUT]" " " t)))
11019 (vhdl-template-field
11020 (if (and object (equal "TERMINAL" (upcase object)))
11021 "nature" "type"))
11022 (setq semicolon-pos (point))
11023 (insert ";")
11024 (vhdl-comment-insert-inline)
11025 (setq end-pos (point))
11026 (insert "\n")
11027 (indent-to margin)
11028 (when (vhdl-standard-p 'ams)
11029 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11030 " " t)))
11031 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
11032 (delete-region end-pos (point))
11033 (goto-char semicolon-pos)
11034 (insert ")")
11035 (end-of-line)
11036 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
11037 t))))
11038
11039 (defun vhdl-template-generate-body (margin label)
11040 "Insert body for generate template."
11041 (vhdl-insert-keyword " GENERATE")
11042 (insert "\n\n")
11043 (indent-to margin)
11044 (vhdl-insert-keyword "END GENERATE ")
11045 (insert label ";")
11046 (end-of-line 0)
11047 (indent-to (+ margin vhdl-basic-offset)))
11048
11049 (defun vhdl-template-insert-date ()
11050 "Insert date in appropriate format."
11051 (interactive)
11052 (insert
11053 (cond
11054 ;; 'american, 'european, 'scientific kept for backward compatibility
11055 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
11056 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
11057 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
11058 (t (format-time-string vhdl-date-format nil)))))
11059
11060 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11061 ;; Help functions
11062
11063 (defun vhdl-electric-space (count)
11064 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
11065 if in comment and past end-comment-column."
11066 (interactive "p")
11067 (cond ((vhdl-in-comment-p)
11068 (self-insert-command count)
11069 (cond ((>= (current-column) (+ 2 end-comment-column))
11070 (backward-char 1)
11071 (skip-chars-backward "^ \t\n\r\f")
11072 (indent-new-comment-line)
11073 (skip-chars-forward "^ \t\n\r\f")
11074 (forward-char 1))
11075 ((>= (current-column) end-comment-column)
11076 (indent-new-comment-line))
11077 (t nil)))
11078 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
11079 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
11080 (vhdl-prepare-search-1
11081 (or (expand-abbrev) (vhdl-fix-case-word -1)))
11082 (self-insert-command count))
11083 (t (self-insert-command count))))
11084
11085 (defun vhdl-template-field (prompt &optional follow-string optional
11086 begin end is-string default)
11087 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
11088 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
11089 an empty string is inserted, return nil and call `vhdl-template-undo' for
11090 the region between BEGIN and END. IS-STRING indicates whether a string
11091 with double-quotes is to be inserted. DEFAULT specifies a default string."
11092 (let ((position (point))
11093 string)
11094 (insert "<" prompt ">")
11095 (setq string
11096 (condition-case ()
11097 (read-from-minibuffer (concat prompt ": ")
11098 (or (and is-string '("\"\"" . 2)) default)
11099 vhdl-minibuffer-local-map)
11100 (quit (if (and optional begin end)
11101 (progn (beep) "")
11102 (keyboard-quit)))))
11103 (when (or (not (equal string "")) optional)
11104 (delete-region position (point)))
11105 (when (and (equal string "") optional begin end)
11106 (vhdl-template-undo begin end)
11107 (message "Template aborted"))
11108 (unless (equal string "")
11109 (insert string)
11110 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
11111 vhdl-keywords-regexp)
11112 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
11113 vhdl-types-regexp)
11114 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
11115 (concat "'" vhdl-attributes-regexp))
11116 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
11117 vhdl-enum-values-regexp)
11118 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
11119 vhdl-constants-regexp))
11120 (when (or (not (equal string "")) (not optional))
11121 (insert (or follow-string "")))
11122 (if (equal string "") nil string)))
11123
11124 (defun vhdl-decision-query (string prompt &optional optional)
11125 "Query a decision from the user."
11126 (let ((start (point)))
11127 (when string (vhdl-insert-keyword (concat string " ")))
11128 (message "%s" (or prompt ""))
11129 (let ((char (read-char)))
11130 (delete-region start (point))
11131 (if (and optional (eq char ?\r))
11132 (progn (insert " ")
11133 (unexpand-abbrev)
11134 (throw 'abort "ERROR: Template aborted"))
11135 char))))
11136
11137 (defun vhdl-insert-keyword (keyword)
11138 "Insert KEYWORD and adjust case."
11139 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11140
11141 (defun vhdl-case-keyword (keyword)
11142 "Adjust case of KEYWORD."
11143 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11144
11145 (defun vhdl-case-word (num)
11146 "Adjust case of following NUM words."
11147 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11148
11149 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11150 "If preceding character is part of a word or a paren then hippie-expand,
11151 else insert tab (used for word completion in VHDL minibuffer)."
11152 (interactive "P")
11153 (cond
11154 ;; expand word
11155 ((= (char-syntax (preceding-char)) ?w)
11156 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11157 (case-replace nil)
11158 (hippie-expand-only-buffers
11159 (or (and (boundp 'hippie-expand-only-buffers)
11160 hippie-expand-only-buffers)
11161 '(vhdl-mode))))
11162 (vhdl-expand-abbrev prefix-arg)))
11163 ;; expand parenthesis
11164 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11165 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11166 (case-replace nil))
11167 (vhdl-expand-paren prefix-arg)))
11168 ;; insert tab
11169 (t (insert-tab))))
11170
11171 (defun vhdl-template-search-prompt ()
11172 "Search for left out template prompts and query again."
11173 (interactive)
11174 (vhdl-prepare-search-2
11175 (when (or (re-search-forward
11176 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11177 (re-search-backward
11178 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11179 (let ((string (match-string 1)))
11180 (replace-match "")
11181 (vhdl-template-field string)))))
11182
11183 (defun vhdl-template-undo (begin end)
11184 "Undo aborted template by deleting region and unexpanding the keyword."
11185 (cond (vhdl-template-invoked-by-hook
11186 (goto-char end)
11187 (insert " ")
11188 (delete-region begin end)
11189 (unexpand-abbrev))
11190 (t (delete-region begin end))))
11191
11192 (defun vhdl-insert-string-or-file (string)
11193 "Insert STRING or file contents if STRING is an existing file name."
11194 (unless (equal string "")
11195 (let ((file-name
11196 (progn (string-match "^\\([^\n]+\\)" string)
11197 (vhdl-resolve-env-variable (match-string 1 string)))))
11198 (if (file-exists-p file-name)
11199 (forward-char (cadr (insert-file-contents file-name)))
11200 (insert string)))))
11201
11202 (defun vhdl-beginning-of-block ()
11203 "Move cursor to the beginning of the enclosing block."
11204 (let (pos)
11205 (vhdl-prepare-search-2
11206 (save-excursion
11207 (beginning-of-line)
11208 ;; search backward for block beginning or end
11209 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
11210 ;; not consider subprogram declarations
11211 (or (and (match-string 5)
11212 (save-match-data
11213 (save-excursion
11214 (goto-char (match-end 5))
11215 (forward-word 1)
11216 (vhdl-forward-syntactic-ws)
11217 (when (looking-at "(")
11218 (forward-sexp))
11219 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11220 (match-string 1)))
11221 ;; not consider configuration specifications
11222 (and (match-string 6)
11223 (save-match-data
11224 (save-excursion
11225 (vhdl-end-of-block)
11226 (beginning-of-line)
11227 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11228 (match-string 2))
11229 ;; skip subblock if block end found
11230 (vhdl-beginning-of-block))))
11231 (when pos (goto-char pos))))
11232
11233 (defun vhdl-end-of-block ()
11234 "Move cursor to the end of the enclosing block."
11235 (let (pos)
11236 (vhdl-prepare-search-2
11237 (save-excursion
11238 (end-of-line)
11239 ;; search forward for block beginning or end
11240 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
11241 ;; not consider subprogram declarations
11242 (or (and (match-string 5)
11243 (save-match-data
11244 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11245 (match-string 1)))
11246 ;; not consider configuration specifications
11247 (and (match-string 6)
11248 (save-match-data
11249 (save-excursion
11250 (vhdl-end-of-block)
11251 (beginning-of-line)
11252 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11253 (not (match-string 2)))
11254 ;; skip subblock if block beginning found
11255 (vhdl-end-of-block))))
11256 (when pos (goto-char pos))))
11257
11258 (defun vhdl-sequential-statement-p ()
11259 "Check if point is within sequential statement part."
11260 (let ((start (point)))
11261 (save-excursion
11262 (vhdl-prepare-search-2
11263 ;; is sequential statement if ...
11264 (and (re-search-backward "^\\s-*begin\\>" nil t)
11265 ;; ... point is between "begin" and "end" of ...
11266 (progn (vhdl-end-of-block)
11267 (< start (point)))
11268 ;; ... a sequential block
11269 (progn (vhdl-beginning-of-block)
11270 (looking-at "^\\s-*\\(\\(\\w+[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(\\w+[ \t\n\r\f]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
11271
11272 (defun vhdl-in-argument-list-p ()
11273 "Check if within an argument list."
11274 (save-excursion
11275 (vhdl-prepare-search-2
11276 (or (string-match "arglist"
11277 (format "%s" (caar (vhdl-get-syntactic-context))))
11278 (progn (beginning-of-line)
11279 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11280
11281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11282 ;; Abbrev hooks
11283
11284 (defun vhdl-hooked-abbrev (func)
11285 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11286 but not if inside a comment or quote."
11287 (if (or (vhdl-in-literal)
11288 (save-excursion
11289 (forward-word -1)
11290 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11291 (progn
11292 (insert " ")
11293 (unexpand-abbrev)
11294 (backward-word 1)
11295 (vhdl-case-word 1)
11296 (delete-char 1))
11297 (if (not vhdl-electric-mode)
11298 (progn
11299 (insert " ")
11300 (unexpand-abbrev)
11301 (backward-word 1)
11302 (vhdl-case-word 1)
11303 (delete-char 1))
11304 (let ((invoke-char vhdl-last-input-event)
11305 (abbrev-mode -1)
11306 (vhdl-template-invoked-by-hook t))
11307 (let ((caught (catch 'abort
11308 (funcall func))))
11309 (when (stringp caught) (message "%s" caught)))
11310 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11311 ;; delete CR which is still in event queue
11312 (if (fboundp 'enqueue-eval-event)
11313 (enqueue-eval-event 'delete-char -1)
11314 (push (vhdl-character-to-event ?\177) ; push back a delete char
11315 unread-command-events))))))
11316
11317 (defun vhdl-template-alias-hook ()
11318 (vhdl-hooked-abbrev 'vhdl-template-alias))
11319 (defun vhdl-template-architecture-hook ()
11320 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11321 (defun vhdl-template-assert-hook ()
11322 (vhdl-hooked-abbrev 'vhdl-template-assert))
11323 (defun vhdl-template-attribute-hook ()
11324 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11325 (defun vhdl-template-block-hook ()
11326 (vhdl-hooked-abbrev 'vhdl-template-block))
11327 (defun vhdl-template-break-hook ()
11328 (vhdl-hooked-abbrev 'vhdl-template-break))
11329 (defun vhdl-template-case-hook ()
11330 (vhdl-hooked-abbrev 'vhdl-template-case))
11331 (defun vhdl-template-component-hook ()
11332 (vhdl-hooked-abbrev 'vhdl-template-component))
11333 (defun vhdl-template-instance-hook ()
11334 (vhdl-hooked-abbrev 'vhdl-template-instance))
11335 (defun vhdl-template-conditional-signal-asst-hook ()
11336 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11337 (defun vhdl-template-configuration-hook ()
11338 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11339 (defun vhdl-template-constant-hook ()
11340 (vhdl-hooked-abbrev 'vhdl-template-constant))
11341 (defun vhdl-template-context-hook ()
11342 (vhdl-hooked-abbrev 'vhdl-template-context))
11343 (defun vhdl-template-disconnect-hook ()
11344 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11345 (defun vhdl-template-display-comment-hook ()
11346 (vhdl-hooked-abbrev 'vhdl-comment-display))
11347 (defun vhdl-template-else-hook ()
11348 (vhdl-hooked-abbrev 'vhdl-template-else))
11349 (defun vhdl-template-elsif-hook ()
11350 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11351 (defun vhdl-template-entity-hook ()
11352 (vhdl-hooked-abbrev 'vhdl-template-entity))
11353 (defun vhdl-template-exit-hook ()
11354 (vhdl-hooked-abbrev 'vhdl-template-exit))
11355 (defun vhdl-template-file-hook ()
11356 (vhdl-hooked-abbrev 'vhdl-template-file))
11357 (defun vhdl-template-for-hook ()
11358 (vhdl-hooked-abbrev 'vhdl-template-for))
11359 (defun vhdl-template-function-hook ()
11360 (vhdl-hooked-abbrev 'vhdl-template-function))
11361 (defun vhdl-template-generic-hook ()
11362 (vhdl-hooked-abbrev 'vhdl-template-generic))
11363 (defun vhdl-template-group-hook ()
11364 (vhdl-hooked-abbrev 'vhdl-template-group))
11365 (defun vhdl-template-library-hook ()
11366 (vhdl-hooked-abbrev 'vhdl-template-library))
11367 (defun vhdl-template-limit-hook ()
11368 (vhdl-hooked-abbrev 'vhdl-template-limit))
11369 (defun vhdl-template-if-hook ()
11370 (vhdl-hooked-abbrev 'vhdl-template-if))
11371 (defun vhdl-template-bare-loop-hook ()
11372 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11373 (defun vhdl-template-map-hook ()
11374 (vhdl-hooked-abbrev 'vhdl-template-map))
11375 (defun vhdl-template-nature-hook ()
11376 (vhdl-hooked-abbrev 'vhdl-template-nature))
11377 (defun vhdl-template-next-hook ()
11378 (vhdl-hooked-abbrev 'vhdl-template-next))
11379 (defun vhdl-template-others-hook ()
11380 (vhdl-hooked-abbrev 'vhdl-template-others))
11381 (defun vhdl-template-package-hook ()
11382 (vhdl-hooked-abbrev 'vhdl-template-package))
11383 (defun vhdl-template-port-hook ()
11384 (vhdl-hooked-abbrev 'vhdl-template-port))
11385 (defun vhdl-template-procedural-hook ()
11386 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11387 (defun vhdl-template-procedure-hook ()
11388 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11389 (defun vhdl-template-process-hook ()
11390 (vhdl-hooked-abbrev 'vhdl-template-process))
11391 (defun vhdl-template-quantity-hook ()
11392 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11393 (defun vhdl-template-report-hook ()
11394 (vhdl-hooked-abbrev 'vhdl-template-report))
11395 (defun vhdl-template-return-hook ()
11396 (vhdl-hooked-abbrev 'vhdl-template-return))
11397 (defun vhdl-template-selected-signal-asst-hook ()
11398 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11399 (defun vhdl-template-signal-hook ()
11400 (vhdl-hooked-abbrev 'vhdl-template-signal))
11401 (defun vhdl-template-subnature-hook ()
11402 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11403 (defun vhdl-template-subtype-hook ()
11404 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11405 (defun vhdl-template-terminal-hook ()
11406 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11407 (defun vhdl-template-type-hook ()
11408 (vhdl-hooked-abbrev 'vhdl-template-type))
11409 (defun vhdl-template-use-hook ()
11410 (vhdl-hooked-abbrev 'vhdl-template-use))
11411 (defun vhdl-template-variable-hook ()
11412 (vhdl-hooked-abbrev 'vhdl-template-variable))
11413 (defun vhdl-template-wait-hook ()
11414 (vhdl-hooked-abbrev 'vhdl-template-wait))
11415 (defun vhdl-template-when-hook ()
11416 (vhdl-hooked-abbrev 'vhdl-template-when))
11417 (defun vhdl-template-while-loop-hook ()
11418 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11419 (defun vhdl-template-with-hook ()
11420 (vhdl-hooked-abbrev 'vhdl-template-with))
11421 (defun vhdl-template-and-hook ()
11422 (vhdl-hooked-abbrev 'vhdl-template-and))
11423 (defun vhdl-template-or-hook ()
11424 (vhdl-hooked-abbrev 'vhdl-template-or))
11425 (defun vhdl-template-nand-hook ()
11426 (vhdl-hooked-abbrev 'vhdl-template-nand))
11427 (defun vhdl-template-nor-hook ()
11428 (vhdl-hooked-abbrev 'vhdl-template-nor))
11429 (defun vhdl-template-xor-hook ()
11430 (vhdl-hooked-abbrev 'vhdl-template-xor))
11431 (defun vhdl-template-xnor-hook ()
11432 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11433 (defun vhdl-template-not-hook ()
11434 (vhdl-hooked-abbrev 'vhdl-template-not))
11435
11436 (defun vhdl-template-default-hook ()
11437 (vhdl-hooked-abbrev 'vhdl-template-default))
11438 (defun vhdl-template-default-indent-hook ()
11439 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11440
11441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11442 ;; Template insertion from completion list
11443
11444 (defun vhdl-template-insert-construct (name)
11445 "Insert the built-in construct template with NAME."
11446 (interactive
11447 (list (let ((completion-ignore-case t))
11448 (completing-read "Construct name: "
11449 vhdl-template-construct-alist nil t))))
11450 (vhdl-template-insert-fun
11451 (cadr (assoc name vhdl-template-construct-alist))))
11452
11453 (defun vhdl-template-insert-package (name)
11454 "Insert the built-in package template with NAME."
11455 (interactive
11456 (list (let ((completion-ignore-case t))
11457 (completing-read "Package name: "
11458 vhdl-template-package-alist nil t))))
11459 (vhdl-template-insert-fun
11460 (cadr (assoc name vhdl-template-package-alist))))
11461
11462 (defun vhdl-template-insert-directive (name)
11463 "Insert the built-in directive template with NAME."
11464 (interactive
11465 (list (let ((completion-ignore-case t))
11466 (completing-read "Directive name: "
11467 vhdl-template-directive-alist nil t))))
11468 (vhdl-template-insert-fun
11469 (cadr (assoc name vhdl-template-directive-alist))))
11470
11471 (defun vhdl-template-insert-fun (fun)
11472 "Call FUN to insert a built-in template."
11473 (let ((caught (catch 'abort (when fun (funcall fun)))))
11474 (when (stringp caught) (message "%s" caught))))
11475
11476
11477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11478 ;;; Models
11479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11480
11481 (defun vhdl-model-insert (model-name)
11482 "Insert the user model with name MODEL-NAME."
11483 (interactive
11484 (let ((completion-ignore-case t))
11485 (list (completing-read "Model name: " vhdl-model-alist))))
11486 (indent-according-to-mode)
11487 (let ((start (point-marker))
11488 (margin (current-indentation))
11489 model position prompt string end)
11490 (vhdl-prepare-search-2
11491 (when (setq model (assoc model-name vhdl-model-alist))
11492 ;; insert model
11493 (beginning-of-line)
11494 (delete-horizontal-space)
11495 (goto-char start)
11496 (vhdl-insert-string-or-file (nth 1 model))
11497 (setq end (point-marker))
11498 ;; indent code
11499 (goto-char start)
11500 (beginning-of-line)
11501 (while (< (point) end)
11502 (unless (looking-at "^$")
11503 (insert-char ? margin))
11504 (beginning-of-line 2))
11505 (goto-char start)
11506 ;; insert clock
11507 (unless (equal "" vhdl-clock-name)
11508 (while (re-search-forward "<clock>" end t)
11509 (replace-match vhdl-clock-name)))
11510 (goto-char start)
11511 ;; insert reset
11512 (unless (equal "" vhdl-reset-name)
11513 (while (re-search-forward "<reset>" end t)
11514 (replace-match vhdl-reset-name)))
11515 ;; replace header prompts
11516 (vhdl-template-replace-header-keywords start end nil t)
11517 (goto-char start)
11518 ;; query other prompts
11519 (while (re-search-forward
11520 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11521 (unless (equal "cursor" (match-string 1))
11522 (setq position (match-beginning 1))
11523 (setq prompt (match-string 1))
11524 (replace-match "")
11525 (setq string (vhdl-template-field prompt nil t))
11526 ;; replace occurrences of same prompt
11527 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11528 (replace-match (or string "")))
11529 (goto-char position)))
11530 (goto-char start)
11531 ;; goto final position
11532 (if (re-search-forward "<cursor>" end t)
11533 (replace-match "")
11534 (goto-char end))))))
11535
11536 (defun vhdl-model-defun ()
11537 "Define help and hook functions for user models."
11538 (let ((model-alist vhdl-model-alist)
11539 model-name model-keyword)
11540 (while model-alist
11541 ;; define functions for user models that can be invoked from menu and key
11542 ;; bindings and which themselves call `vhdl-model-insert' with the model
11543 ;; name as argument
11544 (setq model-name (nth 0 (car model-alist)))
11545 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11546 ,(concat "Insert model for \"" model-name "\".")
11547 (interactive)
11548 (vhdl-model-insert ,model-name)))
11549 ;; define hooks for user models that are invoked from keyword abbrevs
11550 (setq model-keyword (nth 3 (car model-alist)))
11551 (unless (equal model-keyword "")
11552 (eval `(defun
11553 ,(vhdl-function-name
11554 "vhdl-model" model-name "hook") ()
11555 (vhdl-hooked-abbrev
11556 ',(vhdl-function-name "vhdl-model" model-name)))))
11557 (setq model-alist (cdr model-alist)))))
11558
11559 (vhdl-model-defun)
11560
11561
11562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11563 ;;; Port translation
11564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11565
11566 (defvar vhdl-port-list nil
11567 "Variable to hold last port map parsed.")
11568 ;; structure: (parenthesized expression means list of such entries)
11569 ;; (ent-name
11570 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11571 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11572 ;; (lib-name pack-key))
11573
11574 (defun vhdl-parse-string (string &optional optional)
11575 "Check that the text following point matches the regexp in STRING."
11576 (if (looking-at string)
11577 (progn (goto-char (match-end 0))
11578 (when (vhdl-in-literal)
11579 (end-of-line))
11580 (point))
11581 (unless optional
11582 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11583 (vhdl-current-line) string)))
11584 nil))
11585
11586 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11587 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11588 (vhdl-prepare-search-1
11589 (if (string-match (car regexp-cons) string)
11590 (if adjust-case
11591 (funcall vhdl-file-name-case
11592 (replace-match (cdr regexp-cons) t nil string))
11593 (replace-match (cdr regexp-cons) t nil string))
11594 string)))
11595
11596 (defun vhdl-parse-group-comment ()
11597 "Parse comment and empty lines between groups of lines."
11598 (let ((start (point))
11599 string)
11600 (vhdl-forward-comment (point-max))
11601 (setq string (buffer-substring-no-properties start (point)))
11602 (vhdl-forward-syntactic-ws)
11603 ;; strip off leading blanks and first newline
11604 (while (string-match "^\\(\\s-+\\)" string)
11605 (setq string (concat (substring string 0 (match-beginning 1))
11606 (substring string (match-end 1)))))
11607 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11608 (substring string 1)
11609 string)))
11610
11611 (defun vhdl-paste-group-comment (string indent)
11612 "Paste comment and empty lines from STRING between groups of lines
11613 with INDENT."
11614 (let ((pos (point-marker)))
11615 (when (> indent 0)
11616 (while (string-match "^\\(--\\)" string)
11617 (setq string (concat (substring string 0 (match-beginning 1))
11618 (make-string indent ? )
11619 (substring string (match-beginning 1))))))
11620 (beginning-of-line)
11621 (insert string)
11622 (goto-char pos)))
11623
11624 (defvar vhdl-port-flattened nil
11625 "Indicates whether a port has been flattened.")
11626
11627 (defun vhdl-port-flatten (&optional as-alist)
11628 "Flatten port list so that only one generic/port exists per line.
11629 This operation is performed on an internally stored port and is only
11630 reflected in a subsequent paste operation."
11631 (interactive)
11632 (if (not vhdl-port-list)
11633 (error "ERROR: No port has been read")
11634 (message "Flattening port for next paste...")
11635 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11636 (old-vhdl-port-list (cdr vhdl-port-list))
11637 old-port-list new-port-list old-port new-port names)
11638 ;; traverse port list and flatten entries
11639 (while (cdr old-vhdl-port-list)
11640 (setq old-port-list (car old-vhdl-port-list))
11641 (setq new-port-list nil)
11642 (while old-port-list
11643 (setq old-port (car old-port-list))
11644 (setq names (car old-port))
11645 (while names
11646 (setq new-port (cons (if as-alist (car names) (list (car names)))
11647 (cdr old-port)))
11648 (setq new-port-list (append new-port-list (list new-port)))
11649 (setq names (cdr names)))
11650 (setq old-port-list (cdr old-port-list)))
11651 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11652 (setq new-vhdl-port-list (append new-vhdl-port-list
11653 (list new-port-list))))
11654 (setq vhdl-port-list
11655 (append new-vhdl-port-list (list old-vhdl-port-list))
11656 vhdl-port-flattened t)
11657 (message "Flattening port for next paste...done"))))
11658
11659 (defvar vhdl-port-reversed-direction nil
11660 "Indicates whether port directions are reversed.")
11661
11662 (defun vhdl-port-reverse-direction ()
11663 "Reverse direction for all ports (useful in testbenches).
11664 This operation is performed on an internally stored port and is only
11665 reflected in a subsequent paste operation."
11666 (interactive)
11667 (if (not vhdl-port-list)
11668 (error "ERROR: No port has been read")
11669 (message "Reversing port directions for next paste...")
11670 (let ((port-list (nth 2 vhdl-port-list))
11671 port-dir-car port-dir)
11672 ;; traverse port list and reverse directions
11673 (while port-list
11674 (setq port-dir-car (cddr (car port-list))
11675 port-dir (car port-dir-car))
11676 (setcar port-dir-car
11677 (cond ((equal port-dir "in") "out")
11678 ((equal port-dir "IN") "OUT")
11679 ((equal port-dir "out") "in")
11680 ((equal port-dir "OUT") "IN")
11681 (t port-dir)))
11682 (setq port-list (cdr port-list)))
11683 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11684 (message "Reversing port directions for next paste...done"))))
11685
11686 (defun vhdl-port-copy ()
11687 "Get generic and port information from an entity or component declaration."
11688 (interactive)
11689 (save-excursion
11690 (let (parse-error end-of-list
11691 decl-type name generic-list port-list context-clause
11692 object names direct type init comment group-comment)
11693 (vhdl-prepare-search-2
11694 (setq
11695 parse-error
11696 (catch 'parse
11697 ;; check if within entity or component declaration
11698 (end-of-line)
11699 (when (or (not (re-search-backward
11700 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11701 (equal "END" (upcase (match-string 1))))
11702 (throw 'parse "ERROR: Not within an entity or component declaration"))
11703 (setq decl-type (downcase (match-string-no-properties 1)))
11704 (forward-word 1)
11705 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11706 (setq name (match-string-no-properties 1))
11707 (message "Reading port of %s \"%s\"..." decl-type name)
11708 (vhdl-forward-syntactic-ws)
11709 ;; parse generic clause
11710 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11711 ;; parse group comment and spacing
11712 (setq group-comment (vhdl-parse-group-comment))
11713 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11714 (while (not end-of-list)
11715 ;; parse names (accept extended identifiers)
11716 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11717 (setq names (list (match-string-no-properties 1)))
11718 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11719 (setq names
11720 (append names (list (match-string-no-properties 1)))))
11721 ;; parse type
11722 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11723 (setq type (match-string-no-properties 1))
11724 (when (vhdl-in-comment-p) ; if stuck in comment
11725 (setq type (concat type (and (vhdl-parse-string ".*")
11726 (match-string-no-properties 0)))))
11727 (setq comment nil)
11728 (while (looking-at "(")
11729 (setq type
11730 (concat type
11731 (buffer-substring-no-properties
11732 (point) (progn (forward-sexp) (point)))
11733 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11734 (match-string-no-properties 1)))))
11735 ;; special case: closing parenthesis is on separate line
11736 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11737 (setq comment (substring type (match-beginning 2)))
11738 (setq type (substring type 0 (match-beginning 1))))
11739 ;; strip of trailing group-comment
11740 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11741 (setq type (substring type 0 (match-end 1)))
11742 ;; parse initialization expression
11743 (setq init nil)
11744 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11745 (vhdl-parse-string "\\([^();\n]*\\)")
11746 (setq init (match-string-no-properties 1))
11747 (while (looking-at "(")
11748 (setq init
11749 (concat init
11750 (buffer-substring-no-properties
11751 (point) (progn (forward-sexp) (point)))
11752 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11753 (match-string-no-properties 1))))))
11754 ;; special case: closing parenthesis is on separate line
11755 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11756 (setq comment (substring init (match-beginning 2)))
11757 (setq init (substring init 0 (match-beginning 1)))
11758 (vhdl-forward-syntactic-ws))
11759 (skip-chars-forward " \t")
11760 ;; parse inline comment, special case: as above, no initial.
11761 (unless comment
11762 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11763 (match-string-no-properties 1))))
11764 (vhdl-forward-syntactic-ws)
11765 (setq end-of-list (vhdl-parse-string ")" t))
11766 (vhdl-parse-string "\\s-*;\\s-*")
11767 ;; parse inline comment
11768 (unless comment
11769 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11770 (match-string-no-properties 1))))
11771 ;; save everything in list
11772 (setq generic-list (append generic-list
11773 (list (list names type init
11774 comment group-comment))))
11775 ;; parse group comment and spacing
11776 (setq group-comment (vhdl-parse-group-comment))))
11777 ;; parse port clause
11778 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11779 ;; parse group comment and spacing
11780 (setq group-comment (vhdl-parse-group-comment))
11781 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11782 (while (not end-of-list)
11783 ;; parse object
11784 (setq object
11785 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11786 (match-string-no-properties 1)))
11787 ;; parse names (accept extended identifiers)
11788 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11789 (setq names (list (match-string-no-properties 1)))
11790 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11791 (setq names (append names (list (match-string-no-properties 1)))))
11792 ;; parse direction
11793 (vhdl-parse-string ":[ \t\n\r\f]*")
11794 (setq direct
11795 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11796 (match-string-no-properties 1)))
11797 ;; parse type
11798 (vhdl-parse-string "\\([^();\n]+\\)")
11799 (setq type (match-string-no-properties 1))
11800 (when (vhdl-in-comment-p) ; if stuck in comment
11801 (setq type (concat type (and (vhdl-parse-string ".*")
11802 (match-string-no-properties 0)))))
11803 (setq comment nil)
11804 (while (looking-at "(")
11805 (setq type (concat type
11806 (buffer-substring-no-properties
11807 (point) (progn (forward-sexp) (point)))
11808 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11809 (match-string-no-properties 1)))))
11810 ;; special case: closing parenthesis is on separate line
11811 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11812 (setq comment (substring type (match-beginning 2)))
11813 (setq type (substring type 0 (match-beginning 1))))
11814 ;; strip of trailing group-comment
11815 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11816 (setq type (substring type 0 (match-end 1)))
11817 (vhdl-forward-syntactic-ws)
11818 (setq end-of-list (vhdl-parse-string ")" t))
11819 (vhdl-parse-string "\\s-*;\\s-*")
11820 ;; parse inline comment
11821 (unless comment
11822 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11823 (match-string-no-properties 1))))
11824 ;; save everything in list
11825 (setq port-list (append port-list
11826 (list (list names object direct type
11827 comment group-comment))))
11828 ;; parse group comment and spacing
11829 (setq group-comment (vhdl-parse-group-comment))))
11830 ;; parse context clause
11831 (setq context-clause (vhdl-scan-context-clause))
11832 ; ;; add surrounding package to context clause
11833 ; (when (and (equal decl-type "component")
11834 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11835 ; (setq context-clause
11836 ; (append context-clause
11837 ; (list (cons (vhdl-work-library)
11838 ; (match-string-no-properties 1))))))
11839 (message "Reading port of %s \"%s\"...done" decl-type name)
11840 nil)))
11841 ;; finish parsing
11842 (if parse-error
11843 (error parse-error)
11844 (setq vhdl-port-list (list name generic-list port-list context-clause)
11845 vhdl-port-reversed-direction nil
11846 vhdl-port-flattened nil)))))
11847
11848 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11849 "Paste a context clause."
11850 (let ((margin (current-indentation))
11851 (clause-list (nth 3 vhdl-port-list))
11852 clause)
11853 (while clause-list
11854 (setq clause (car clause-list))
11855 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11856 (downcase exclude-pack-name)))
11857 (save-excursion
11858 (re-search-backward
11859 (concat "^\\s-*use\\s-+" (car clause)
11860 "\." (cdr clause) "\\>") nil t)))
11861 (vhdl-template-standard-package (car clause) (cdr clause))
11862 (insert "\n"))
11863 (setq clause-list (cdr clause-list)))))
11864
11865 (defun vhdl-port-paste-generic (&optional no-init)
11866 "Paste a generic clause."
11867 (let ((margin (current-indentation))
11868 (generic-list (nth 1 vhdl-port-list))
11869 list-margin start names generic)
11870 ;; paste generic clause
11871 (when generic-list
11872 (setq start (point))
11873 (vhdl-insert-keyword "GENERIC (")
11874 (unless vhdl-argument-list-indent
11875 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11876 (setq list-margin (current-column))
11877 (while generic-list
11878 (setq generic (car generic-list))
11879 ;; paste group comment and spacing
11880 (when (memq vhdl-include-group-comments '(decl always))
11881 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11882 ;; paste names
11883 (setq names (nth 0 generic))
11884 (while names
11885 (insert (car names))
11886 (setq names (cdr names))
11887 (when names (insert ", ")))
11888 ;; paste type
11889 (insert " : " (nth 1 generic))
11890 ;; paste initialization
11891 (when (and (not no-init) (nth 2 generic))
11892 (insert " := " (nth 2 generic)))
11893 (unless (cdr generic-list) (insert ")"))
11894 (insert ";")
11895 ;; paste comment
11896 (when (and vhdl-include-port-comments (nth 3 generic))
11897 (vhdl-comment-insert-inline (nth 3 generic) t))
11898 (setq generic-list (cdr generic-list))
11899 (when generic-list (insert "\n") (indent-to list-margin)))
11900 ;; align generic clause
11901 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11902
11903 (defun vhdl-port-paste-port ()
11904 "Paste a port clause."
11905 (let ((margin (current-indentation))
11906 (port-list (nth 2 vhdl-port-list))
11907 list-margin start names port)
11908 ;; paste port clause
11909 (when port-list
11910 (setq start (point))
11911 (vhdl-insert-keyword "PORT (")
11912 (unless vhdl-argument-list-indent
11913 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11914 (setq list-margin (current-column))
11915 (while port-list
11916 (setq port (car port-list))
11917 ;; paste group comment and spacing
11918 (when (memq vhdl-include-group-comments '(decl always))
11919 (vhdl-paste-group-comment (nth 5 port) list-margin))
11920 ;; paste object
11921 (when (nth 1 port) (insert (nth 1 port) " "))
11922 ;; paste names
11923 (setq names (nth 0 port))
11924 (while names
11925 (insert (car names))
11926 (setq names (cdr names))
11927 (when names (insert ", ")))
11928 ;; paste direction
11929 (insert " : ")
11930 (when (nth 2 port) (insert (nth 2 port) " "))
11931 ;; paste type
11932 (insert (nth 3 port))
11933 (unless (cdr port-list) (insert ")"))
11934 (insert ";")
11935 ;; paste comment
11936 (when (and vhdl-include-port-comments (nth 4 port))
11937 (vhdl-comment-insert-inline (nth 4 port) t))
11938 (setq port-list (cdr port-list))
11939 (when port-list (insert "\n") (indent-to list-margin)))
11940 ;; align port clause
11941 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11942
11943 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11944 "Paste as an entity or component declaration."
11945 (unless no-indent (indent-according-to-mode))
11946 (let ((margin (current-indentation))
11947 (name (nth 0 vhdl-port-list)))
11948 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11949 (insert name)
11950 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11951 (vhdl-insert-keyword " IS"))
11952 ;; paste generic and port clause
11953 (when (nth 1 vhdl-port-list)
11954 (insert "\n")
11955 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11956 (insert "\n"))
11957 (indent-to (+ margin vhdl-basic-offset))
11958 (vhdl-port-paste-generic (eq kind 'component)))
11959 (when (nth 2 vhdl-port-list)
11960 (insert "\n")
11961 (when (and (memq vhdl-insert-empty-lines '(unit all))
11962 (eq kind 'entity))
11963 (insert "\n"))
11964 (indent-to (+ margin vhdl-basic-offset)))
11965 (vhdl-port-paste-port)
11966 (insert "\n")
11967 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11968 (insert "\n"))
11969 (indent-to margin)
11970 (vhdl-insert-keyword "END")
11971 (if (eq kind 'entity)
11972 (progn
11973 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11974 (insert " " name))
11975 (vhdl-insert-keyword " COMPONENT")
11976 (unless (vhdl-standard-p '87) (insert " " name)))
11977 (insert ";")))
11978
11979 (defun vhdl-port-paste-entity (&optional no-indent)
11980 "Paste as an entity declaration."
11981 (interactive)
11982 (if (not vhdl-port-list)
11983 (error "ERROR: No port read")
11984 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11985 (vhdl-port-paste-declaration 'entity no-indent)
11986 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11987
11988 (defun vhdl-port-paste-component (&optional no-indent)
11989 "Paste as a component declaration."
11990 (interactive)
11991 (if (not vhdl-port-list)
11992 (error "ERROR: No port read")
11993 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11994 (vhdl-port-paste-declaration 'component no-indent)
11995 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11996
11997 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11998 "Paste as a generic map."
11999 (interactive)
12000 (unless secondary (indent-according-to-mode))
12001 (let ((margin (current-indentation))
12002 list-margin start generic
12003 (generic-list (nth 1 vhdl-port-list)))
12004 (when generic-list
12005 (setq start (point))
12006 (vhdl-insert-keyword "GENERIC MAP (")
12007 (if (not vhdl-association-list-with-formals)
12008 ;; paste list of actual generics
12009 (while generic-list
12010 (insert (if no-constants
12011 (car (nth 0 (car generic-list)))
12012 (or (nth 2 (car generic-list)) " ")))
12013 (setq generic-list (cdr generic-list))
12014 (insert (if generic-list ", " ")"))
12015 (when (and (not generic-list) secondary
12016 (null (nth 2 vhdl-port-list)))
12017 (insert ";")))
12018 (unless vhdl-argument-list-indent
12019 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12020 (setq list-margin (current-column))
12021 (while generic-list
12022 (setq generic (car generic-list))
12023 ;; paste group comment and spacing
12024 (when (eq vhdl-include-group-comments 'always)
12025 (vhdl-paste-group-comment (nth 4 generic) list-margin))
12026 ;; paste formal and actual generic
12027 (insert (car (nth 0 generic)) " => "
12028 (if no-constants
12029 (vhdl-replace-string vhdl-actual-generic-name
12030 (car (nth 0 generic)))
12031 (or (nth 2 generic) "")))
12032 (setq generic-list (cdr generic-list))
12033 (insert (if generic-list "," ")"))
12034 (when (and (not generic-list) secondary
12035 (null (nth 2 vhdl-port-list)))
12036 (insert ";"))
12037 ;; paste comment
12038 (when (or vhdl-include-type-comments
12039 (and vhdl-include-port-comments (nth 3 generic)))
12040 (vhdl-comment-insert-inline
12041 (concat
12042 (when vhdl-include-type-comments
12043 (concat "[" (nth 1 generic) "] "))
12044 (when vhdl-include-port-comments (nth 3 generic))) t))
12045 (when generic-list (insert "\n") (indent-to list-margin)))
12046 ;; align generic map
12047 (when vhdl-auto-align
12048 (vhdl-align-region-groups start (point) 1 t))))))
12049
12050 (defun vhdl-port-paste-port-map ()
12051 "Paste as a port map."
12052 (let ((margin (current-indentation))
12053 list-margin start port
12054 (port-list (nth 2 vhdl-port-list)))
12055 (when port-list
12056 (setq start (point))
12057 (vhdl-insert-keyword "PORT MAP (")
12058 (if (not vhdl-association-list-with-formals)
12059 ;; paste list of actual ports
12060 (while port-list
12061 (insert (vhdl-replace-string vhdl-actual-port-name
12062 (car (nth 0 (car port-list)))))
12063 (setq port-list (cdr port-list))
12064 (insert (if port-list ", " ")")))
12065 (unless vhdl-argument-list-indent
12066 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12067 (setq list-margin (current-column))
12068 (while port-list
12069 (setq port (car port-list))
12070 ;; paste group comment and spacing
12071 (when (eq vhdl-include-group-comments 'always)
12072 (vhdl-paste-group-comment (nth 5 port) list-margin))
12073 ;; paste formal and actual port
12074 (insert (car (nth 0 port)) " => ")
12075 (insert (vhdl-replace-string vhdl-actual-port-name
12076 (car (nth 0 port))))
12077 (setq port-list (cdr port-list))
12078 (insert (if port-list "," ");"))
12079 ;; paste comment
12080 (when (or (and vhdl-include-direction-comments (nth 2 port))
12081 vhdl-include-type-comments
12082 (and vhdl-include-port-comments (nth 4 port)))
12083 (vhdl-comment-insert-inline
12084 (concat
12085 (cond ((and vhdl-include-direction-comments
12086 vhdl-include-type-comments)
12087 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
12088 (nth 3 port) "] "))
12089 ((and vhdl-include-direction-comments (nth 2 port))
12090 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12091 (vhdl-include-direction-comments " ")
12092 (vhdl-include-type-comments
12093 (concat "[" (nth 3 port) "] ")))
12094 (when vhdl-include-port-comments (nth 4 port))) t))
12095 (when port-list (insert "\n") (indent-to list-margin)))
12096 ;; align port clause
12097 (when vhdl-auto-align
12098 (vhdl-align-region-groups start (point) 1))))))
12099
12100 (defun vhdl-port-paste-instance (&optional name no-indent title)
12101 "Paste as an instantiation."
12102 (interactive)
12103 (if (not vhdl-port-list)
12104 (error "ERROR: No port read")
12105 (let ((orig-vhdl-port-list vhdl-port-list))
12106 ;; flatten local copy of port list (must be flat for port mapping)
12107 (vhdl-port-flatten)
12108 (unless no-indent (indent-according-to-mode))
12109 (let ((margin (current-indentation)))
12110 ;; paste instantiation
12111 (cond (name
12112 (insert name))
12113 ((equal (cdr vhdl-instance-name) "")
12114 (setq name (vhdl-template-field "instance name")))
12115 ((string-match "\%d" (cdr vhdl-instance-name))
12116 (let ((n 1))
12117 (while (save-excursion
12118 (setq name (format (vhdl-replace-string
12119 vhdl-instance-name
12120 (nth 0 vhdl-port-list)) n))
12121 (goto-char (point-min))
12122 (vhdl-re-search-forward name nil t))
12123 (setq n (1+ n)))
12124 (insert name)))
12125 (t (insert (vhdl-replace-string vhdl-instance-name
12126 (nth 0 vhdl-port-list)))))
12127 (message "Pasting port as instantiation \"%s\"..." name)
12128 (insert ": ")
12129 (when title
12130 (save-excursion
12131 (beginning-of-line)
12132 (indent-to vhdl-basic-offset)
12133 (insert "-- instance \"" name "\"\n")))
12134 (if (not (vhdl-use-direct-instantiation))
12135 (insert (nth 0 vhdl-port-list))
12136 (vhdl-insert-keyword "ENTITY ")
12137 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12138 (when (nth 1 vhdl-port-list)
12139 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12140 (vhdl-port-paste-generic-map t t))
12141 (when (nth 2 vhdl-port-list)
12142 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12143 (vhdl-port-paste-port-map))
12144 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12145 (insert ";"))
12146 (message "Pasting port as instantiation \"%s\"...done" name))
12147 (setq vhdl-port-list orig-vhdl-port-list))))
12148
12149 (defun vhdl-port-paste-constants (&optional no-indent)
12150 "Paste generics as constants."
12151 (interactive)
12152 (if (not vhdl-port-list)
12153 (error "ERROR: No port read")
12154 (let ((orig-vhdl-port-list vhdl-port-list))
12155 (message "Pasting port as constants...")
12156 ;; flatten local copy of port list (must be flat for constant initial.)
12157 (vhdl-port-flatten)
12158 (unless no-indent (indent-according-to-mode))
12159 (let ((margin (current-indentation))
12160 start generic name
12161 (generic-list (nth 1 vhdl-port-list)))
12162 (when generic-list
12163 (setq start (point))
12164 (while generic-list
12165 (setq generic (car generic-list))
12166 ;; paste group comment and spacing
12167 (when (memq vhdl-include-group-comments '(decl always))
12168 (vhdl-paste-group-comment (nth 4 generic) margin))
12169 (vhdl-insert-keyword "CONSTANT ")
12170 ;; paste generic constants
12171 (setq name (nth 0 generic))
12172 (when name
12173 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12174 ;; paste type
12175 (insert " : " (nth 1 generic))
12176 ;; paste initialization
12177 (when (nth 2 generic)
12178 (insert " := " (nth 2 generic)))
12179 (insert ";")
12180 ;; paste comment
12181 (when (and vhdl-include-port-comments (nth 3 generic))
12182 (vhdl-comment-insert-inline (nth 3 generic) t))
12183 (setq generic-list (cdr generic-list))
12184 (when generic-list (insert "\n") (indent-to margin))))
12185 ;; align signal list
12186 (when vhdl-auto-align
12187 (vhdl-align-region-groups start (point) 1))))
12188 (message "Pasting port as constants...done")
12189 (setq vhdl-port-list orig-vhdl-port-list))))
12190
12191 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12192 "Paste ports as internal signals."
12193 (interactive)
12194 (if (not vhdl-port-list)
12195 (error "ERROR: No port read")
12196 (message "Pasting port as signals...")
12197 (unless no-indent (indent-according-to-mode))
12198 (let ((margin (current-indentation))
12199 start port names type generic-list port-name constant-name pos
12200 (port-list (nth 2 vhdl-port-list)))
12201 (when port-list
12202 (setq start (point))
12203 (while port-list
12204 (setq port (car port-list))
12205 ;; paste group comment and spacing
12206 (when (memq vhdl-include-group-comments '(decl always))
12207 (vhdl-paste-group-comment (nth 5 port) margin))
12208 ;; paste object
12209 (if (nth 1 port)
12210 (insert (nth 1 port) " ")
12211 (vhdl-insert-keyword "SIGNAL "))
12212 ;; paste actual port signals
12213 (setq names (nth 0 port))
12214 (while names
12215 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12216 (setq names (cdr names))
12217 (when names (insert ", ")))
12218 ;; paste type
12219 (setq type (nth 3 port))
12220 (setq generic-list (nth 1 vhdl-port-list))
12221 (vhdl-prepare-search-1
12222 (setq pos 0)
12223 ;; replace formal by actual generics
12224 (while generic-list
12225 (setq port-name (car (nth 0 (car generic-list))))
12226 (while (string-match (concat "\\<" port-name "\\>") type pos)
12227 (setq constant-name
12228 (save-match-data (vhdl-replace-string
12229 vhdl-actual-generic-name port-name)))
12230 (setq type (replace-match constant-name t nil type))
12231 (setq pos (match-end 0)))
12232 (setq generic-list (cdr generic-list))))
12233 (insert " : " type)
12234 ;; paste initialization (inputs only)
12235 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12236 (insert " := "
12237 (cond ((string-match "integer" (nth 3 port)) "0")
12238 ((string-match "natural" (nth 3 port)) "0")
12239 ((string-match "positive" (nth 3 port)) "0")
12240 ((string-match "real" (nth 3 port)) "0.0")
12241 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12242 (t "'0'"))))
12243 (insert ";")
12244 ;; paste comment
12245 (when (or (and vhdl-include-direction-comments (nth 2 port))
12246 (and vhdl-include-port-comments (nth 4 port)))
12247 (vhdl-comment-insert-inline
12248 (concat
12249 (cond ((and vhdl-include-direction-comments (nth 2 port))
12250 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12251 (vhdl-include-direction-comments " "))
12252 (when vhdl-include-port-comments (nth 4 port))) t))
12253 (setq port-list (cdr port-list))
12254 (when port-list (insert "\n") (indent-to margin)))
12255 ;; align signal list
12256 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12257 (message "Pasting port as signals...done")))
12258
12259 (defun vhdl-port-paste-initializations (&optional no-indent)
12260 "Paste ports as signal initializations."
12261 (interactive)
12262 (if (not vhdl-port-list)
12263 (error "ERROR: No port read")
12264 (let ((orig-vhdl-port-list vhdl-port-list))
12265 (message "Pasting port as initializations...")
12266 ;; flatten local copy of port list (must be flat for signal initial.)
12267 (vhdl-port-flatten)
12268 (unless no-indent (indent-according-to-mode))
12269 (let ((margin (current-indentation))
12270 start port name
12271 (port-list (nth 2 vhdl-port-list)))
12272 (when port-list
12273 (setq start (point))
12274 (while port-list
12275 (setq port (car port-list))
12276 ;; paste actual port signal (inputs only)
12277 (when (equal "IN" (upcase (nth 2 port)))
12278 (setq name (car (nth 0 port)))
12279 (insert (vhdl-replace-string vhdl-actual-port-name name))
12280 ;; paste initialization
12281 (insert " <= "
12282 (cond ((string-match "integer" (nth 3 port)) "0")
12283 ((string-match "natural" (nth 3 port)) "0")
12284 ((string-match "positive" (nth 3 port)) "0")
12285 ((string-match "real" (nth 3 port)) "0.0")
12286 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12287 (t "'0'"))
12288 ";"))
12289 (setq port-list (cdr port-list))
12290 (when (and port-list
12291 (equal "IN" (upcase (nth 2 (car port-list)))))
12292 (insert "\n") (indent-to margin)))
12293 ;; align signal list
12294 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12295 (message "Pasting port as initializations...done")
12296 (setq vhdl-port-list orig-vhdl-port-list))))
12297
12298 (defun vhdl-port-paste-testbench ()
12299 "Paste as a bare-bones testbench."
12300 (interactive)
12301 (if (not vhdl-port-list)
12302 (error "ERROR: No port read")
12303 (let ((case-fold-search t)
12304 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12305 (nth 0 vhdl-port-list)))
12306 (source-buffer (current-buffer))
12307 arch-name config-name ent-file-name arch-file-name
12308 ent-buffer arch-buffer position)
12309 ;; open entity file
12310 (unless (eq vhdl-testbench-create-files 'none)
12311 (setq ent-file-name
12312 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12313 ent-name t)
12314 "." (file-name-extension (buffer-file-name))))
12315 (if (file-exists-p ent-file-name)
12316 (if (y-or-n-p
12317 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12318 (progn (find-file ent-file-name)
12319 (erase-buffer)
12320 (set-buffer-modified-p nil))
12321 (if (eq vhdl-testbench-create-files 'separate)
12322 (setq ent-file-name nil)
12323 (error "ERROR: Pasting port as testbench...aborted")))
12324 (find-file ent-file-name)))
12325 (unless (and (eq vhdl-testbench-create-files 'separate)
12326 (null ent-file-name))
12327 ;; paste entity header
12328 (if vhdl-testbench-include-header
12329 (progn (vhdl-template-header
12330 (concat "Testbench for design \""
12331 (nth 0 vhdl-port-list) "\""))
12332 (goto-char (point-max)))
12333 (vhdl-comment-display-line) (insert "\n\n"))
12334 ;; paste std_logic_1164 package
12335 (when vhdl-testbench-include-library
12336 (vhdl-template-package-std-logic-1164)
12337 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12338 ;; paste entity declaration
12339 (vhdl-insert-keyword "ENTITY ")
12340 (insert ent-name)
12341 (vhdl-insert-keyword " IS")
12342 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12343 (insert "\n")
12344 (vhdl-insert-keyword "END ")
12345 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12346 (insert ent-name ";")
12347 (insert "\n\n")
12348 (vhdl-comment-display-line) (insert "\n"))
12349 ;; get architecture name
12350 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12351 (read-from-minibuffer "architecture name: "
12352 nil vhdl-minibuffer-local-map)
12353 (vhdl-replace-string vhdl-testbench-architecture-name
12354 (nth 0 vhdl-port-list))))
12355 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12356 ;; open architecture file
12357 (if (not (eq vhdl-testbench-create-files 'separate))
12358 (insert "\n")
12359 (setq ent-buffer (current-buffer))
12360 (setq arch-file-name
12361 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12362 (concat ent-name " " arch-name) t)
12363 "." (file-name-extension (buffer-file-name))))
12364 (when (and (file-exists-p arch-file-name)
12365 (not (y-or-n-p (concat "File \"" arch-file-name
12366 "\" exists; overwrite? "))))
12367 (error "ERROR: Pasting port as testbench...aborted"))
12368 (find-file arch-file-name)
12369 (erase-buffer)
12370 (set-buffer-modified-p nil)
12371 ;; paste architecture header
12372 (if vhdl-testbench-include-header
12373 (progn (vhdl-template-header
12374 (concat "Testbench architecture for design \""
12375 (nth 0 vhdl-port-list) "\""))
12376 (goto-char (point-max)))
12377 (vhdl-comment-display-line) (insert "\n\n")))
12378 ;; paste architecture body
12379 (vhdl-insert-keyword "ARCHITECTURE ")
12380 (insert arch-name)
12381 (vhdl-insert-keyword " OF ")
12382 (insert ent-name)
12383 (vhdl-insert-keyword " IS")
12384 (insert "\n\n") (indent-to vhdl-basic-offset)
12385 ;; paste component declaration
12386 (unless (vhdl-use-direct-instantiation)
12387 (vhdl-port-paste-component t)
12388 (insert "\n\n") (indent-to vhdl-basic-offset))
12389 ;; paste constants
12390 (when (nth 1 vhdl-port-list)
12391 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12392 (vhdl-port-paste-constants t)
12393 (insert "\n\n") (indent-to vhdl-basic-offset))
12394 ;; paste internal signals
12395 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12396 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12397 (insert "\n")
12398 ;; paste custom declarations
12399 (unless (equal "" vhdl-testbench-declarations)
12400 (insert "\n")
12401 (setq position (point))
12402 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12403 (vhdl-indent-region position (point)))
12404 (setq position (point))
12405 (insert "\n\n")
12406 (vhdl-comment-display-line) (insert "\n")
12407 (when vhdl-testbench-include-configuration
12408 (setq config-name (vhdl-replace-string
12409 vhdl-testbench-configuration-name
12410 (concat ent-name " " arch-name)))
12411 (insert "\n")
12412 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12413 (vhdl-insert-keyword " OF ") (insert ent-name)
12414 (vhdl-insert-keyword " IS\n")
12415 (indent-to vhdl-basic-offset)
12416 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12417 (indent-to vhdl-basic-offset)
12418 (vhdl-insert-keyword "END FOR;\n")
12419 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12420 (vhdl-comment-display-line) (insert "\n"))
12421 (goto-char position)
12422 (vhdl-template-begin-end
12423 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12424 ;; paste instantiation
12425 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12426 (vhdl-port-paste-instance
12427 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12428 (insert "\n")
12429 ;; paste custom statements
12430 (unless (equal "" vhdl-testbench-statements)
12431 (insert "\n")
12432 (setq position (point))
12433 (vhdl-insert-string-or-file vhdl-testbench-statements)
12434 (vhdl-indent-region position (point)))
12435 (insert "\n")
12436 (indent-to vhdl-basic-offset)
12437 (unless (eq vhdl-testbench-create-files 'none)
12438 (setq arch-buffer (current-buffer))
12439 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12440 (set-buffer arch-buffer) (save-buffer))
12441 (message "%s"
12442 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12443 ent-name arch-name)
12444 (and ent-file-name
12445 (format "\n File created: \"%s\"" ent-file-name))
12446 (and arch-file-name
12447 (format "\n File created: \"%s\"" arch-file-name)))))))
12448
12449
12450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12451 ;;; Subprogram interface translation
12452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12453
12454 (defvar vhdl-subprog-list nil
12455 "Variable to hold last subprogram interface parsed.")
12456 ;; structure: (parenthesized expression means list of such entries)
12457 ;; (subprog-name kind
12458 ;; ((names) object direct type init comment group-comment)
12459 ;; return-type return-comment group-comment)
12460
12461 (defvar vhdl-subprog-flattened nil
12462 "Indicates whether an subprogram interface has been flattened.")
12463
12464 (defun vhdl-subprog-flatten ()
12465 "Flatten interface list so that only one parameter exists per line."
12466 (interactive)
12467 (if (not vhdl-subprog-list)
12468 (error "ERROR: No subprogram interface has been read")
12469 (message "Flattening subprogram interface...")
12470 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12471 new-subprog-list old-subprog new-subprog names)
12472 ;; traverse parameter list and flatten entries
12473 (while old-subprog-list
12474 (setq old-subprog (car old-subprog-list))
12475 (setq names (car old-subprog))
12476 (while names
12477 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12478 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12479 (setq names (cdr names)))
12480 (setq old-subprog-list (cdr old-subprog-list)))
12481 (setq vhdl-subprog-list
12482 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12483 new-subprog-list (nth 3 vhdl-subprog-list)
12484 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12485 vhdl-subprog-flattened t)
12486 (message "Flattening subprogram interface...done"))))
12487
12488 (defun vhdl-subprog-copy ()
12489 "Get interface information from a subprogram specification."
12490 (interactive)
12491 (save-excursion
12492 (let (parse-error pos end-of-list
12493 name kind param-list object names direct type init
12494 comment group-comment
12495 return-type return-comment return-group-comment)
12496 (vhdl-prepare-search-2
12497 (setq
12498 parse-error
12499 (catch 'parse
12500 ;; check if within function declaration
12501 (setq pos (point))
12502 (end-of-line)
12503 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12504 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12505 (goto-char (match-end 0))
12506 (save-excursion (backward-char)
12507 (forward-sexp)
12508 (<= pos (point))))
12509 (throw 'parse "ERROR: Not within a subprogram specification"))
12510 (setq name (match-string-no-properties 5))
12511 (setq kind (if (match-string 2) 'procedure 'function))
12512 (setq end-of-list (not (match-string 7)))
12513 (message "Reading interface of subprogram \"%s\"..." name)
12514 ;; parse parameter list
12515 (setq group-comment (vhdl-parse-group-comment))
12516 (setq end-of-list (or end-of-list
12517 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12518 (while (not end-of-list)
12519 ;; parse object
12520 (setq object
12521 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12522 (match-string-no-properties 1)))
12523 ;; parse names (accept extended identifiers)
12524 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12525 (setq names (list (match-string-no-properties 1)))
12526 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12527 (setq names (append names (list (match-string-no-properties 1)))))
12528 ;; parse direction
12529 (vhdl-parse-string ":[ \t\n\r\f]*")
12530 (setq direct
12531 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12532 (match-string-no-properties 1)))
12533 ;; parse type
12534 (vhdl-parse-string "\\([^():;\n]+\\)")
12535 (setq type (match-string-no-properties 1))
12536 (setq comment nil)
12537 (while (looking-at "(")
12538 (setq type
12539 (concat type
12540 (buffer-substring-no-properties
12541 (point) (progn (forward-sexp) (point)))
12542 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12543 (match-string-no-properties 1)))))
12544 ;; special case: closing parenthesis is on separate line
12545 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12546 (setq comment (substring type (match-beginning 2)))
12547 (setq type (substring type 0 (match-beginning 1))))
12548 ;; strip off trailing group-comment
12549 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12550 (setq type (substring type 0 (match-end 1)))
12551 ;; parse initialization expression
12552 (setq init nil)
12553 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12554 (vhdl-parse-string "\\([^();\n]*\\)")
12555 (setq init (match-string-no-properties 1))
12556 (while (looking-at "(")
12557 (setq init
12558 (concat init
12559 (buffer-substring-no-properties
12560 (point) (progn (forward-sexp) (point)))
12561 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12562 (match-string-no-properties 1))))))
12563 ;; special case: closing parenthesis is on separate line
12564 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12565 (setq comment (substring init (match-beginning 2)))
12566 (setq init (substring init 0 (match-beginning 1)))
12567 (vhdl-forward-syntactic-ws))
12568 (skip-chars-forward " \t")
12569 ;; parse inline comment, special case: as above, no initial.
12570 (unless comment
12571 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12572 (match-string-no-properties 1))))
12573 (vhdl-forward-syntactic-ws)
12574 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12575 ;; parse inline comment
12576 (unless comment
12577 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12578 (match-string-no-properties 1))))
12579 (setq return-group-comment (vhdl-parse-group-comment))
12580 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12581 ;; parse return type
12582 (when (match-string 3)
12583 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12584 (setq return-type (match-string-no-properties 1))
12585 (when (and return-type
12586 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12587 (setq return-comment (substring return-type (match-beginning 2)))
12588 (setq return-type (substring return-type 0 (match-beginning 1))))
12589 ;; strip of trailing group-comment
12590 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12591 (setq return-type (substring return-type 0 (match-end 1)))
12592 ;; parse return comment
12593 (unless return-comment
12594 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12595 (match-string-no-properties 1)))))
12596 ;; parse inline comment
12597 (unless comment
12598 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12599 (match-string-no-properties 1))))
12600 ;; save everything in list
12601 (setq param-list (append param-list
12602 (list (list names object direct type init
12603 comment group-comment))))
12604 ;; parse group comment and spacing
12605 (setq group-comment (vhdl-parse-group-comment)))
12606 (message "Reading interface of subprogram \"%s\"...done" name)
12607 nil)))
12608 ;; finish parsing
12609 (if parse-error
12610 (error parse-error)
12611 (setq vhdl-subprog-list
12612 (list name kind param-list return-type return-comment
12613 return-group-comment)
12614 vhdl-subprog-flattened nil)))))
12615
12616 (defun vhdl-subprog-paste-specification (kind)
12617 "Paste as a subprogram specification."
12618 (indent-according-to-mode)
12619 (let ((margin (current-column))
12620 (param-list (nth 2 vhdl-subprog-list))
12621 list-margin start names param)
12622 ;; paste keyword and name
12623 (vhdl-insert-keyword
12624 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12625 (insert (nth 0 vhdl-subprog-list))
12626 (if (not param-list)
12627 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12628 (setq start (point))
12629 ;; paste parameter list
12630 (insert " (")
12631 (unless vhdl-argument-list-indent
12632 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12633 (setq list-margin (current-column))
12634 (while param-list
12635 (setq param (car param-list))
12636 ;; paste group comment and spacing
12637 (when (memq vhdl-include-group-comments (list kind 'always))
12638 (vhdl-paste-group-comment (nth 6 param) list-margin))
12639 ;; paste object
12640 (when (nth 1 param) (insert (nth 1 param) " "))
12641 ;; paste names
12642 (setq names (nth 0 param))
12643 (while names
12644 (insert (car names))
12645 (setq names (cdr names))
12646 (when names (insert ", ")))
12647 ;; paste direction
12648 (insert " : ")
12649 (when (nth 2 param) (insert (nth 2 param) " "))
12650 ;; paste type
12651 (insert (nth 3 param))
12652 ;; paste initialization
12653 (when (nth 4 param) (insert " := " (nth 4 param)))
12654 ;; terminate line
12655 (if (cdr param-list)
12656 (insert ";")
12657 (insert ")")
12658 (when (null (nth 3 vhdl-subprog-list))
12659 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12660 ;; paste comment
12661 (when (and vhdl-include-port-comments (nth 5 param))
12662 (vhdl-comment-insert-inline (nth 5 param) t))
12663 (setq param-list (cdr param-list))
12664 (when param-list (insert "\n") (indent-to list-margin)))
12665 (when (nth 3 vhdl-subprog-list)
12666 (insert "\n") (indent-to list-margin)
12667 ;; paste group comment and spacing
12668 (when (memq vhdl-include-group-comments (list kind 'always))
12669 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12670 ;; paste return type
12671 (insert "return " (nth 3 vhdl-subprog-list))
12672 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12673 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12674 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12675 ;; align parameter list
12676 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12677 ;; paste body
12678 (when (eq kind 'body)
12679 (insert "\n")
12680 (vhdl-template-begin-end
12681 (unless (vhdl-standard-p '87)
12682 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12683 (nth 0 vhdl-subprog-list) margin))))
12684
12685 (defun vhdl-subprog-paste-declaration ()
12686 "Paste as a subprogram declaration."
12687 (interactive)
12688 (if (not vhdl-subprog-list)
12689 (error "ERROR: No subprogram interface read")
12690 (message "Pasting interface as subprogram declaration \"%s\"..."
12691 (car vhdl-subprog-list))
12692 ;; paste specification
12693 (vhdl-subprog-paste-specification 'decl)
12694 (message "Pasting interface as subprogram declaration \"%s\"...done"
12695 (car vhdl-subprog-list))))
12696
12697 (defun vhdl-subprog-paste-body ()
12698 "Paste as a subprogram body."
12699 (interactive)
12700 (if (not vhdl-subprog-list)
12701 (error "ERROR: No subprogram interface read")
12702 (message "Pasting interface as subprogram body \"%s\"..."
12703 (car vhdl-subprog-list))
12704 ;; paste specification and body
12705 (vhdl-subprog-paste-specification 'body)
12706 (message "Pasting interface as subprogram body \"%s\"...done"
12707 (car vhdl-subprog-list))))
12708
12709 (defun vhdl-subprog-paste-call ()
12710 "Paste as a subprogram call."
12711 (interactive)
12712 (if (not vhdl-subprog-list)
12713 (error "ERROR: No subprogram interface read")
12714 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12715 param-list margin list-margin param start)
12716 ;; flatten local copy of interface list (must be flat for parameter mapping)
12717 (vhdl-subprog-flatten)
12718 (setq param-list (nth 2 vhdl-subprog-list))
12719 (indent-according-to-mode)
12720 (setq margin (current-indentation))
12721 (message "Pasting interface as subprogram call \"%s\"..."
12722 (car vhdl-subprog-list))
12723 ;; paste name
12724 (insert (nth 0 vhdl-subprog-list))
12725 (if (not param-list)
12726 (insert ";")
12727 (setq start (point))
12728 ;; paste parameter list
12729 (insert " (")
12730 (unless vhdl-argument-list-indent
12731 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12732 (setq list-margin (current-column))
12733 (while param-list
12734 (setq param (car param-list))
12735 ;; paste group comment and spacing
12736 (when (eq vhdl-include-group-comments 'always)
12737 (vhdl-paste-group-comment (nth 6 param) list-margin))
12738 ;; paste formal port
12739 (insert (car (nth 0 param)) " => ")
12740 (setq param-list (cdr param-list))
12741 (insert (if param-list "," ");"))
12742 ;; paste comment
12743 (when (and vhdl-include-port-comments (nth 5 param))
12744 (vhdl-comment-insert-inline (nth 5 param)))
12745 (when param-list (insert "\n") (indent-to list-margin)))
12746 ;; align parameter list
12747 (when vhdl-auto-align
12748 (vhdl-align-region-groups start (point) 1)))
12749 (message "Pasting interface as subprogram call \"%s\"...done"
12750 (car vhdl-subprog-list))
12751 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12752
12753
12754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12755 ;;; Miscellaneous
12756 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12757
12758 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12759 ;; Hippie expand customization
12760
12761 (defvar vhdl-expand-upper-case nil)
12762
12763 (defun vhdl-try-expand-abbrev (old)
12764 "Try expanding abbreviations from `vhdl-abbrev-list'."
12765 (unless old
12766 (he-init-string (he-dabbrev-beg) (point))
12767 (setq he-expand-list
12768 (let ((abbrev-list vhdl-abbrev-list)
12769 (sel-abbrev-list '()))
12770 (while abbrev-list
12771 (when (or (not (stringp (car abbrev-list)))
12772 (string-match
12773 (concat "^" he-search-string) (car abbrev-list)))
12774 (setq sel-abbrev-list
12775 (cons (car abbrev-list) sel-abbrev-list)))
12776 (setq abbrev-list (cdr abbrev-list)))
12777 (nreverse sel-abbrev-list))))
12778 (while (and he-expand-list
12779 (or (not (stringp (car he-expand-list)))
12780 (he-string-member (car he-expand-list) he-tried-table t)))
12781 (unless (stringp (car he-expand-list))
12782 (setq vhdl-expand-upper-case (car he-expand-list)))
12783 (setq he-expand-list (cdr he-expand-list)))
12784 (if (null he-expand-list)
12785 (progn (when old (he-reset-string))
12786 nil)
12787 (he-substitute-string
12788 (if vhdl-expand-upper-case
12789 (upcase (car he-expand-list))
12790 (car he-expand-list))
12791 t)
12792 (setq he-expand-list (cdr he-expand-list))
12793 t))
12794
12795 (defun vhdl-he-list-beg ()
12796 "Also looks at the word before `(' in order to better match parenthesized
12797 expressions (e.g. for index ranges of types and signals)."
12798 (save-excursion
12799 (condition-case ()
12800 (progn (backward-up-list 1)
12801 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12802 (error ()))
12803 (point)))
12804
12805 ;; override `he-list-beg' from `hippie-exp'
12806 (unless (and (boundp 'viper-mode) viper-mode)
12807 (defalias 'he-list-beg 'vhdl-he-list-beg))
12808
12809 ;; function for expanding abbrevs and dabbrevs
12810 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12811 '(try-expand-dabbrev
12812 try-expand-dabbrev-all-buffers
12813 vhdl-try-expand-abbrev)))
12814
12815 ;; function for expanding parenthesis
12816 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12817 '(try-expand-list
12818 try-expand-list-all-buffers)))
12819
12820 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12821 ;; Line handling functions
12822
12823 (defun vhdl-current-line ()
12824 "Return the line number of the line containing point."
12825 (save-restriction
12826 (widen)
12827 (1+ (count-lines (point-min) (point-at-bol)))))
12828
12829 (defun vhdl-line-kill-entire (&optional arg)
12830 "Delete entire line."
12831 (interactive "p")
12832 (beginning-of-line)
12833 (kill-line (or arg 1)))
12834
12835 (defun vhdl-line-kill (&optional arg)
12836 "Kill current line."
12837 (interactive "p")
12838 (vhdl-line-kill-entire arg))
12839
12840 (defun vhdl-line-copy (&optional arg)
12841 "Copy current line."
12842 (interactive "p")
12843 (save-excursion
12844 (let ((position (point-at-bol)))
12845 (forward-line (or arg 1))
12846 (copy-region-as-kill position (point)))))
12847
12848 (defun vhdl-line-yank ()
12849 "Yank entire line."
12850 (interactive)
12851 (beginning-of-line)
12852 (yank))
12853
12854 (defun vhdl-line-expand (&optional prefix-arg)
12855 "Hippie-expand current line."
12856 (interactive "P")
12857 (require 'hippie-exp)
12858 (let ((case-fold-search t) (case-replace nil)
12859 (hippie-expand-try-functions-list
12860 '(try-expand-line try-expand-line-all-buffers)))
12861 (hippie-expand prefix-arg)))
12862
12863 (defun vhdl-line-transpose-next (&optional arg)
12864 "Interchange this line with next line."
12865 (interactive "p")
12866 (forward-line 1)
12867 (transpose-lines (or arg 1))
12868 (forward-line -1))
12869
12870 (defun vhdl-line-transpose-previous (&optional arg)
12871 "Interchange this line with previous line."
12872 (interactive "p")
12873 (forward-line 1)
12874 (transpose-lines (- 0 (or arg 0)))
12875 (forward-line -1))
12876
12877 (defun vhdl-line-open ()
12878 "Open a new line and indent."
12879 (interactive)
12880 (end-of-line -0)
12881 (newline-and-indent))
12882
12883 (defun vhdl-delete-indentation ()
12884 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12885 it works within comments too."
12886 (interactive)
12887 (let ((fill-prefix "-- "))
12888 (delete-indentation)))
12889
12890 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12891 ;; Move functions
12892
12893 (defun vhdl-forward-same-indent ()
12894 "Move forward to next line with same indent."
12895 (interactive)
12896 (let ((pos (point))
12897 (indent (current-indentation)))
12898 (beginning-of-line 2)
12899 (while (and (not (eobp))
12900 (or (looking-at "^\\s-*\\(--.*\\)?$")
12901 (> (current-indentation) indent)))
12902 (beginning-of-line 2))
12903 (if (= (current-indentation) indent)
12904 (back-to-indentation)
12905 (message "No following line with same indent found in this block")
12906 (goto-char pos)
12907 nil)))
12908
12909 (defun vhdl-backward-same-indent ()
12910 "Move backward to previous line with same indent."
12911 (interactive)
12912 (let ((pos (point))
12913 (indent (current-indentation)))
12914 (beginning-of-line -0)
12915 (while (and (not (bobp))
12916 (or (looking-at "^\\s-*\\(--.*\\)?$")
12917 (> (current-indentation) indent)))
12918 (beginning-of-line -0))
12919 (if (= (current-indentation) indent)
12920 (back-to-indentation)
12921 (message "No preceding line with same indent found in this block")
12922 (goto-char pos)
12923 nil)))
12924
12925 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12926 ;; Statistics
12927
12928 (defun vhdl-statistics-buffer ()
12929 "Get some file statistics."
12930 (interactive)
12931 (let ((no-stats 0)
12932 (no-code-lines 0)
12933 (no-empty-lines 0)
12934 (no-comm-lines 0)
12935 (no-comments 0)
12936 (no-lines (count-lines (point-min) (point-max))))
12937 (save-excursion
12938 ;; count statements
12939 (goto-char (point-min))
12940 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12941 (if (match-string 1)
12942 (goto-char (match-end 1))
12943 (setq no-stats (1+ no-stats))))
12944 ;; count code lines
12945 (goto-char (point-min))
12946 (while (not (eobp))
12947 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12948 (setq no-code-lines (1+ no-code-lines)))
12949 (beginning-of-line 2))
12950 ;; count empty lines
12951 (goto-char (point-min))
12952 (while (and (re-search-forward "^\\s-*$" nil t)
12953 (not (eq (point) (point-max))))
12954 (if (match-string 1)
12955 (goto-char (match-end 1))
12956 (setq no-empty-lines (1+ no-empty-lines))
12957 (unless (eq (point) (point-max))
12958 (forward-char))))
12959 ;; count comment-only lines
12960 (goto-char (point-min))
12961 (while (re-search-forward "^\\s-*--.*" nil t)
12962 (if (match-string 1)
12963 (goto-char (match-end 1))
12964 (setq no-comm-lines (1+ no-comm-lines))))
12965 ;; count comments
12966 (goto-char (point-min))
12967 (while (re-search-forward "--.*" nil t)
12968 (if (match-string 1)
12969 (goto-char (match-end 1))
12970 (setq no-comments (1+ no-comments)))))
12971 ;; print results
12972 (message "\n\
12973 File statistics: \"%s\"\n\
12974 -----------------------\n\
12975 # statements : %5d\n\
12976 # code lines : %5d\n\
12977 # empty lines : %5d\n\
12978 # comment lines : %5d\n\
12979 # comments : %5d\n\
12980 # total lines : %5d\n\ "
12981 (buffer-file-name) no-stats no-code-lines no-empty-lines
12982 no-comm-lines no-comments no-lines)
12983 (unless vhdl-emacs-21 (vhdl-show-messages))))
12984
12985 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12986 ;; Help functions
12987
12988 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12989 "Like `re-search-forward', but does not match within literals."
12990 (let (pos)
12991 (save-excursion
12992 (while (and (setq pos (re-search-forward regexp bound noerror count))
12993 (vhdl-in-literal))))
12994 (when pos (goto-char pos))
12995 pos))
12996
12997 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12998 "Like `re-search-backward', but does not match within literals."
12999 (let (pos)
13000 (save-excursion
13001 (while (and (setq pos (re-search-backward regexp bound noerror count))
13002 (vhdl-in-literal))))
13003 (when pos (goto-char pos))
13004 pos))
13005
13006
13007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13008 ;;; Project
13009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13010
13011 (defun vhdl-set-project (name)
13012 "Set current project to NAME."
13013 (interactive
13014 (list (let ((completion-ignore-case t))
13015 (completing-read "Project name: " vhdl-project-alist nil t))))
13016 (cond ((equal name "")
13017 (setq vhdl-project nil)
13018 (message "Current VHDL project: None"))
13019 ((assoc name vhdl-project-alist)
13020 (setq vhdl-project name)
13021 (message "Current VHDL project: \"%s\"" name))
13022 (t
13023 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
13024 (vhdl-speedbar-update-current-project))
13025
13026 (defun vhdl-set-default-project ()
13027 "Set current project as default on startup."
13028 (interactive)
13029 (customize-set-variable 'vhdl-project vhdl-project)
13030 (customize-save-customized))
13031
13032 (defun vhdl-toggle-project (name token indent)
13033 "Set current project to NAME or unset if NAME is current project."
13034 (vhdl-set-project (if (equal name vhdl-project) "" name)))
13035
13036 (defun vhdl-export-project (file-name)
13037 "Write project setup for current project."
13038 (interactive
13039 (let ((name (vhdl-resolve-env-variable
13040 (vhdl-replace-string
13041 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13042 (concat (subst-char-in-string
13043 ? ?_ (or (vhdl-project-p)
13044 (error "ERROR: No current project")))
13045 " " (user-login-name))))))
13046 (list (read-file-name
13047 "Write project file: "
13048 (when (file-name-absolute-p name) "") nil nil name))))
13049 (setq file-name (abbreviate-file-name file-name))
13050 (let ((orig-buffer (current-buffer)))
13051 (unless (file-exists-p (file-name-directory file-name))
13052 (make-directory (file-name-directory file-name) t))
13053 (if (not (file-writable-p file-name))
13054 (error "ERROR: File not writable: \"%s\"" file-name)
13055 (set-buffer (find-file-noselect file-name t t))
13056 (erase-buffer)
13057 (insert ";; -*- Emacs-Lisp -*-\n\n"
13058 ";;; " (file-name-nondirectory file-name)
13059 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
13060 ";; Project : " vhdl-project "\n"
13061 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
13062 (user-login-name) "\n\n\n"
13063 ";; project name\n"
13064 "(setq vhdl-project \"" vhdl-project "\")\n\n"
13065 ";; project setup\n"
13066 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
13067 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
13068 (insert ")\n")
13069 (save-buffer)
13070 (kill-buffer (current-buffer))
13071 (set-buffer orig-buffer))))
13072
13073 (defun vhdl-import-project (file-name &optional auto not-make-current)
13074 "Read project setup and set current project."
13075 (interactive
13076 (let ((name (vhdl-resolve-env-variable
13077 (vhdl-replace-string
13078 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13079 (concat "" " " (user-login-name))))))
13080 (list (read-file-name
13081 "Read project file: " (when (file-name-absolute-p name) "") nil t
13082 (file-name-directory name)))))
13083 (when (file-exists-p file-name)
13084 (condition-case ()
13085 (let ((current-project vhdl-project))
13086 (load-file file-name)
13087 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
13088 (vhdl-adelete 'vhdl-project-alist vhdl-project)
13089 (error ""))
13090 (if not-make-current
13091 (setq vhdl-project current-project)
13092 (setq vhdl-compiler
13093 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
13094 (vhdl-update-mode-menu)
13095 (vhdl-speedbar-refresh)
13096 (unless not-make-current
13097 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
13098 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
13099 (error (vhdl-warning
13100 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
13101
13102 (defun vhdl-duplicate-project ()
13103 "Duplicate setup of current project."
13104 (interactive)
13105 (let ((new-name (read-from-minibuffer "New project name: "))
13106 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
13107 (setq vhdl-project-alist
13108 (append vhdl-project-alist
13109 (list (cons new-name project-entry))))
13110 (vhdl-update-mode-menu)))
13111
13112 (defun vhdl-auto-load-project ()
13113 "Automatically load project setup at startup."
13114 (let ((file-name-list vhdl-project-file-name)
13115 file-list list-length)
13116 (while file-name-list
13117 (setq file-list
13118 (append file-list
13119 (file-expand-wildcards
13120 (vhdl-resolve-env-variable
13121 (vhdl-replace-string
13122 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
13123 (concat "\*" " " (user-login-name)))))))
13124 (setq list-length (or list-length (length file-list)))
13125 (setq file-name-list (cdr file-name-list)))
13126 (while file-list
13127 (vhdl-import-project (expand-file-name (car file-list)) t
13128 (not (> list-length 0)))
13129 (setq list-length (1- list-length))
13130 (setq file-list (cdr file-list)))))
13131
13132 ;; automatically load project setup when idle after startup
13133 (when (memq 'startup vhdl-project-auto-load)
13134 (if noninteractive
13135 (vhdl-auto-load-project)
13136 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13137
13138
13139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13140 ;;; Hideshow
13141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13142 ;; (using `hideshow.el')
13143
13144 (defconst vhdl-hs-start-regexp
13145 (concat
13146 "\\(^\\)\\s-*\\("
13147 ;; generic/port clause
13148 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13149 ;; component
13150 "component\\>\\|"
13151 ;; component instantiation
13152 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13153 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13154 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13155 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13156 ;; subprogram
13157 "\\(function\\|procedure\\)\\>\\|"
13158 ;; process, block
13159 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13160 ;; configuration declaration
13161 "configuration\\>"
13162 "\\)")
13163 "Regexp to match start of construct to hide.")
13164
13165 (defun vhdl-hs-forward-sexp-func (count)
13166 "Find end of construct to hide (for hideshow). Only searches forward."
13167 (let ((pos (point)))
13168 (vhdl-prepare-search-2
13169 (beginning-of-line)
13170 (cond
13171 ;; generic/port clause
13172 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13173 (goto-char (match-end 0))
13174 (backward-char)
13175 (forward-sexp))
13176 ;; component declaration
13177 ((looking-at "^\\s-*component\\>")
13178 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13179 ;; component instantiation
13180 ((looking-at
13181 (concat
13182 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13183 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13184 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13185 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13186 (goto-char (match-end 0))
13187 (backward-char)
13188 (forward-sexp)
13189 (setq pos (point))
13190 (vhdl-forward-syntactic-ws)
13191 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13192 (goto-char (match-end 0))
13193 (backward-char)
13194 (forward-sexp)
13195 (setq pos (point)))
13196 (goto-char pos))
13197 ;; subprogram declaration/body
13198 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13199 (goto-char (match-end 0))
13200 (vhdl-forward-syntactic-ws)
13201 (when (looking-at "(")
13202 (forward-sexp))
13203 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13204 (vhdl-in-literal)))
13205 ;; subprogram body
13206 (when (match-string 2)
13207 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13208 (backward-word 1)
13209 (vhdl-forward-sexp)))
13210 ;; block (recursive)
13211 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13212 (goto-char (match-end 0))
13213 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13214 (match-beginning 2))
13215 (vhdl-hs-forward-sexp-func count)))
13216 ;; process
13217 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13218 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13219 ;; configuration declaration
13220 ((looking-at "^\\s-*configuration\\>")
13221 (forward-word 4)
13222 (vhdl-forward-sexp))
13223 (t (goto-char pos))))))
13224
13225 (defun vhdl-hideshow-init ()
13226 "Initialize `hideshow'."
13227 (when vhdl-hideshow-menu
13228 (vhdl-hs-minor-mode 1)))
13229
13230 (defun vhdl-hs-minor-mode (&optional arg)
13231 "Toggle hideshow minor mode and update menu bar."
13232 (interactive "P")
13233 (require 'hideshow)
13234 ;; check for hideshow version 5.x
13235 (if (not (boundp 'hs-block-start-mdata-select))
13236 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13237 ;; initialize hideshow
13238 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13239 (setq hs-special-modes-alist
13240 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13241 'vhdl-hs-forward-sexp-func nil)
13242 hs-special-modes-alist)))
13243 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13244 (if vhdl-hide-all-init
13245 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13246 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13247 (hs-minor-mode arg)
13248 (force-mode-line-update))) ; hack to update menu bar
13249
13250
13251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13252 ;;; Font locking
13253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13254 ;; (using `font-lock.el')
13255
13256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13257 ;; Help functions
13258
13259 (defun vhdl-within-translate-off ()
13260 "Return point if within translate-off region, else nil."
13261 (and (save-excursion
13262 (re-search-backward
13263 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13264 (equal "off" (match-string 1))
13265 (point)))
13266
13267 (defun vhdl-start-translate-off (limit)
13268 "Return point before translate-off pragma if before LIMIT, else nil."
13269 (when (re-search-forward
13270 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13271 (match-beginning 0)))
13272
13273 (defun vhdl-end-translate-off (limit)
13274 "Return point after translate-on pragma if before LIMIT, else nil."
13275 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13276
13277 (defun vhdl-match-translate-off (limit)
13278 "Match a translate-off block, setting match-data and returning t, else nil."
13279 (when (< (point) limit)
13280 (let ((start (or (vhdl-within-translate-off)
13281 (vhdl-start-translate-off limit)))
13282 (case-fold-search t))
13283 (when start
13284 (let ((end (or (vhdl-end-translate-off limit) limit)))
13285 (set-match-data (list start end))
13286 (goto-char end))))))
13287
13288 (defun vhdl-font-lock-match-item (limit)
13289 "Match, and move over, any declaration item after point. Adapted from
13290 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13291 (condition-case nil
13292 (save-restriction
13293 (narrow-to-region (point-min) limit)
13294 ;; match item
13295 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13296 (save-match-data
13297 (goto-char (match-end 1))
13298 ;; move to next item
13299 (if (looking-at "\\(\\s-*,\\)")
13300 (goto-char (match-end 1))
13301 (end-of-line) t))))
13302 (error t)))
13303
13304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13305 ;; Syntax definitions
13306
13307 (defconst vhdl-font-lock-syntactic-keywords
13308 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13309 "Mark single quotes as having string quote syntax in 'c' instances.")
13310
13311 (defvar vhdl-font-lock-keywords nil
13312 "Regular expressions to highlight in VHDL Mode.")
13313
13314 (defvar vhdl-font-lock-keywords-0
13315 ;; set in `vhdl-font-lock-init' because dependent on user options
13316 "For consideration as a value of `vhdl-font-lock-keywords'.
13317 This does highlighting of template prompts and directives (pragmas).")
13318
13319 (defvar vhdl-font-lock-keywords-1 nil
13320 ;; set in `vhdl-font-lock-init' because dependent on user options
13321 "For consideration as a value of `vhdl-font-lock-keywords'.
13322 This does highlighting of keywords and standard identifiers.")
13323
13324 (defconst vhdl-font-lock-keywords-2
13325 (list
13326 ;; highlight names of units, subprograms, and components when declared
13327 (list
13328 (concat
13329 "^\\s-*\\("
13330 "architecture\\|configuration\\|context\\|entity\\|package"
13331 "\\(\\s-+body\\)?\\|"
13332 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13333 "\\)\\s-+\\(\\w+\\)")
13334 5 'font-lock-function-name-face)
13335
13336 ;; highlight entity names of architectures and configurations
13337 (list
13338 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13339 2 'font-lock-function-name-face)
13340
13341 ;; highlight labels of common constructs
13342 (list
13343 (concat
13344 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13345 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13346 "postponed\\|process\\|"
13347 (when (vhdl-standard-p 'ams) "procedural\\|")
13348 "with\\|while"
13349 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13350 1 'font-lock-function-name-face)
13351
13352 ;; highlight label and component name of component instantiations
13353 (list
13354 (concat
13355 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13356 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13357 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13358
13359 ;; highlight label and instantiated unit of component instantiations
13360 (list
13361 (concat
13362 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13363 "\\(component\\|configuration\\|entity\\)\\s-+"
13364 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13365 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13366 '(5 font-lock-function-name-face nil t)
13367 '(7 font-lock-function-name-face nil t))
13368
13369 ;; highlight names and labels at end of constructs
13370 (list
13371 (concat
13372 "^\\s-*end\\s-+\\(\\("
13373 "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
13374 "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
13375 "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
13376 (when (vhdl-standard-p 'ams) "procedural\\|")
13377 "units"
13378 "\\)\\s-+\\)?\\(\\w*\\)")
13379 5 'font-lock-function-name-face)
13380
13381 ;; highlight labels in exit and next statements
13382 (list
13383 (concat
13384 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13385 3 'font-lock-function-name-face)
13386
13387 ;; highlight entity name in attribute specifications
13388 (list
13389 (concat
13390 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13391 1 'font-lock-function-name-face)
13392
13393 ;; highlight labels in block and component specifications
13394 (list
13395 (concat
13396 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13397 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13398 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13399
13400 ;; highlight names in library clauses
13401 (list "^\\s-*library\\>"
13402 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13403
13404 ;; highlight names in use clauses
13405 (list
13406 (concat
13407 "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13408 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13409 '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
13410 '(8 font-lock-function-name-face nil t))
13411
13412 ;; highlight attribute name in attribute declarations/specifications
13413 (list
13414 (concat
13415 "^\\s-*attribute\\s-+\\(\\w+\\)")
13416 1 'vhdl-font-lock-attribute-face)
13417
13418 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13419 (list
13420 (concat
13421 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13422 5 'font-lock-type-face)
13423
13424 ;; highlight signal/variable/constant declaration names
13425 (list "\\(:[^=]\\)"
13426 '(vhdl-font-lock-match-item
13427 (progn (goto-char (match-beginning 1))
13428 (skip-syntax-backward " ")
13429 (skip-syntax-backward "w_")
13430 (skip-syntax-backward " ")
13431 (while (= (preceding-char) ?,)
13432 (backward-char 1)
13433 (skip-syntax-backward " ")
13434 (skip-syntax-backward "w_")
13435 (skip-syntax-backward " ")))
13436 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13437
13438 ;; highlight formal parameters in component instantiations and subprogram
13439 ;; calls
13440 (list "\\(=>\\)"
13441 '(vhdl-font-lock-match-item
13442 (progn (goto-char (match-beginning 1))
13443 (skip-syntax-backward " ")
13444 (while (= (preceding-char) ?\)) (backward-sexp))
13445 (skip-syntax-backward "w_")
13446 (skip-syntax-backward " ")
13447 (when (memq (preceding-char) '(?n ?N ?|))
13448 (goto-char (point-max))))
13449 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13450
13451 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13452 ;; variables
13453 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13454 '(vhdl-font-lock-match-item
13455 (progn (goto-char (match-end 1)) (match-beginning 2))
13456 nil (1 font-lock-variable-name-face)))
13457
13458 ;; highlight tool directives
13459 (list
13460 (concat
13461 "^\\s-*\\(`\\w+\\)")
13462 1 'font-lock-preprocessor-face)
13463 )
13464 "For consideration as a value of `vhdl-font-lock-keywords'.
13465 This does context sensitive highlighting of names and labels.")
13466
13467 (defvar vhdl-font-lock-keywords-3 nil
13468 ;; set in `vhdl-font-lock-init' because dependent on user options
13469 "For consideration as a value of `vhdl-font-lock-keywords'.
13470 This does highlighting of words with special syntax.")
13471
13472 (defvar vhdl-font-lock-keywords-4 nil
13473 ;; set in `vhdl-font-lock-init' because dependent on user options
13474 "For consideration as a value of `vhdl-font-lock-keywords'.
13475 This does highlighting of additional reserved words.")
13476
13477 (defconst vhdl-font-lock-keywords-5
13478 ;; background highlight translate-off regions
13479 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13480 "For consideration as a value of `vhdl-font-lock-keywords'.
13481 This does background highlighting of translate-off regions.")
13482
13483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13484 ;; Font and color definitions
13485
13486 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13487 "Face name to use for prompts.")
13488
13489 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13490 "Face name to use for standardized attributes.")
13491
13492 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13493 "Face name to use for standardized enumeration values.")
13494
13495 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13496 "Face name to use for standardized functions and packages.")
13497
13498 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13499 "Face name to use for directives.")
13500
13501 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13502 "Face name to use for additional reserved words.")
13503
13504 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13505 "Face name to use for translate-off regions.")
13506
13507 ;; face names to use for words with special syntax.
13508 (let ((syntax-alist vhdl-special-syntax-alist)
13509 name)
13510 (while syntax-alist
13511 (setq name (vhdl-function-name
13512 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13513 (eval `(defvar ,name ',name
13514 ,(concat "Face name to use for "
13515 (nth 0 (car syntax-alist)) ".")))
13516 (setq syntax-alist (cdr syntax-alist))))
13517
13518 (defgroup vhdl-highlight-faces nil
13519 "Faces for highlighting."
13520 :group 'vhdl-highlight)
13521
13522 ;; add faces used from `font-lock'
13523 (custom-add-to-group
13524 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13525 (custom-add-to-group
13526 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13527 (custom-add-to-group
13528 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13529 (custom-add-to-group
13530 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13531 (custom-add-to-group
13532 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13533 (custom-add-to-group
13534 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13535
13536 (defface vhdl-font-lock-prompt-face
13537 '((((min-colors 88) (class color) (background light))
13538 (:foreground "Red1" :bold t))
13539 (((class color) (background light)) (:foreground "Red" :bold t))
13540 (((class color) (background dark)) (:foreground "Pink" :bold t))
13541 (t (:inverse-video t)))
13542 "Font lock mode face used to highlight prompts."
13543 :group 'vhdl-highlight-faces)
13544
13545 (defface vhdl-font-lock-attribute-face
13546 '((((class color) (background light)) (:foreground "Orchid"))
13547 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13548 (t (:italic t :bold t)))
13549 "Font lock mode face used to highlight standardized attributes."
13550 :group 'vhdl-highlight-faces)
13551
13552 (defface vhdl-font-lock-enumvalue-face
13553 '((((class color) (background light)) (:foreground "SaddleBrown"))
13554 (((class color) (background dark)) (:foreground "BurlyWood"))
13555 (t (:italic t :bold t)))
13556 "Font lock mode face used to highlight standardized enumeration values."
13557 :group 'vhdl-highlight-faces)
13558
13559 (defface vhdl-font-lock-function-face
13560 '((((class color) (background light)) (:foreground "Cyan4"))
13561 (((class color) (background dark)) (:foreground "Orchid1"))
13562 (t (:italic t :bold t)))
13563 "Font lock mode face used to highlight standardized functions and packages."
13564 :group 'vhdl-highlight-faces)
13565
13566 (defface vhdl-font-lock-directive-face
13567 '((((class color) (background light)) (:foreground "CadetBlue"))
13568 (((class color) (background dark)) (:foreground "Aquamarine"))
13569 (t (:italic t :bold t)))
13570 "Font lock mode face used to highlight directives."
13571 :group 'vhdl-highlight-faces)
13572
13573 (defface vhdl-font-lock-reserved-words-face
13574 '((((class color) (background light)) (:foreground "Orange" :bold t))
13575 (((min-colors 88) (class color) (background dark))
13576 (:foreground "Yellow1" :bold t))
13577 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13578 (t ()))
13579 "Font lock mode face used to highlight additional reserved words."
13580 :group 'vhdl-highlight-faces)
13581
13582 (defface vhdl-font-lock-translate-off-face
13583 '((((class color) (background light)) (:background "LightGray"))
13584 (((class color) (background dark)) (:background "DimGray"))
13585 (t ()))
13586 "Font lock mode face used to background highlight translate-off regions."
13587 :group 'vhdl-highlight-faces)
13588
13589 ;; font lock mode faces used to highlight words with special syntax.
13590 (let ((syntax-alist vhdl-special-syntax-alist))
13591 (while syntax-alist
13592 (eval `(defface ,(vhdl-function-name
13593 "vhdl-font-lock" (caar syntax-alist) "face")
13594 '((((class color) (background light))
13595 (:foreground ,(nth 2 (car syntax-alist))))
13596 (((class color) (background dark))
13597 (:foreground ,(nth 3 (car syntax-alist))))
13598 (t ()))
13599 ,(concat "Font lock mode face used to highlight "
13600 (nth 0 (car syntax-alist)) ".")
13601 :group 'vhdl-highlight-faces))
13602 (setq syntax-alist (cdr syntax-alist))))
13603
13604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13605 ;; Font lock initialization
13606
13607 (defun vhdl-font-lock-init ()
13608 "Initialize fontification."
13609 ;; highlight template prompts and directives
13610 (setq vhdl-font-lock-keywords-0
13611 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13612 vhdl-template-prompt-syntax ">\\)")
13613 2 'vhdl-font-lock-prompt-face t)
13614 (list (concat "--\\s-*"
13615 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13616 2 'vhdl-font-lock-directive-face t)
13617 ;; highlight c-preprocessor directives
13618 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13619 '(1 font-lock-builtin-face)
13620 '(3 font-lock-variable-name-face nil t))))
13621 ;; highlight keywords and standardized types, attributes, enumeration
13622 ;; values, and subprograms
13623 (setq vhdl-font-lock-keywords-1
13624 (list
13625 (list (concat "'" vhdl-attributes-regexp)
13626 1 'vhdl-font-lock-attribute-face)
13627 (list vhdl-types-regexp 1 'font-lock-type-face)
13628 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13629 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13630 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13631 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13632 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13633 ;; highlight words with special syntax.
13634 (setq vhdl-font-lock-keywords-3
13635 (let ((syntax-alist vhdl-special-syntax-alist)
13636 keywords)
13637 (while syntax-alist
13638 (setq keywords
13639 (cons
13640 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13641 (vhdl-function-name
13642 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13643 (nth 4 (car syntax-alist)))
13644 keywords))
13645 (setq syntax-alist (cdr syntax-alist)))
13646 keywords))
13647 ;; highlight additional reserved words
13648 (setq vhdl-font-lock-keywords-4
13649 (list (list vhdl-reserved-words-regexp 1
13650 'vhdl-font-lock-reserved-words-face)))
13651 ;; highlight everything together
13652 (setq vhdl-font-lock-keywords
13653 (append
13654 vhdl-font-lock-keywords-0
13655 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13656 (when (or vhdl-highlight-forbidden-words
13657 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13658 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13659 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13660 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13661
13662 ;; initialize fontification for VHDL Mode
13663 (vhdl-font-lock-init)
13664
13665 (defun vhdl-fontify-buffer ()
13666 "Re-initialize fontification and fontify buffer."
13667 (interactive)
13668 (setq font-lock-defaults
13669 `(vhdl-font-lock-keywords
13670 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13671 beginning-of-line))
13672 (when (fboundp 'font-lock-unset-defaults)
13673 (font-lock-unset-defaults)) ; not implemented in XEmacs
13674 (font-lock-set-defaults)
13675 (font-lock-mode nil)
13676 (font-lock-mode t))
13677
13678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13679 ;; Initialization for PostScript printing
13680
13681 (defun vhdl-ps-print-settings ()
13682 "Initialize custom face and page settings for PostScript printing."
13683 ;; define custom face settings
13684 (unless (or (not vhdl-print-customize-faces)
13685 ps-print-color-p)
13686 (set (make-local-variable 'ps-bold-faces)
13687 '(font-lock-keyword-face
13688 font-lock-type-face
13689 vhdl-font-lock-attribute-face
13690 vhdl-font-lock-enumvalue-face
13691 vhdl-font-lock-directive-face))
13692 (set (make-local-variable 'ps-italic-faces)
13693 '(font-lock-comment-face
13694 font-lock-function-name-face
13695 font-lock-type-face
13696 vhdl-font-lock-attribute-face
13697 vhdl-font-lock-enumvalue-face
13698 vhdl-font-lock-directive-face))
13699 (set (make-local-variable 'ps-underlined-faces)
13700 '(font-lock-string-face))
13701 (setq ps-always-build-face-reference t))
13702 ;; define page settings, so that a line containing 79 characters (default)
13703 ;; fits into one column
13704 (when vhdl-print-two-column
13705 (set (make-local-variable 'ps-landscape-mode) t)
13706 (set (make-local-variable 'ps-number-of-columns) 2)
13707 (set (make-local-variable 'ps-font-size) 7.0)
13708 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13709 (set (make-local-variable 'ps-header-font-size) 9.0)
13710 (set (make-local-variable 'ps-header-offset) 12.0)
13711 (when (eq ps-paper-type 'letter)
13712 (set (make-local-variable 'ps-inter-column) 40.0)
13713 (set (make-local-variable 'ps-left-margin) 40.0)
13714 (set (make-local-variable 'ps-right-margin) 40.0))))
13715
13716 (defun vhdl-ps-print-init ()
13717 "Initialize PostScript printing."
13718 (if (featurep 'xemacs)
13719 (when (boundp 'ps-print-color-p)
13720 (vhdl-ps-print-settings))
13721 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13722 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13723
13724
13725 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13726 ;;; Hierarchy browser (using `speedbar.el')
13727 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13728 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13729 ;; directory by using the speedbar.
13730
13731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13732 ;; Variables
13733
13734 (defvar vhdl-entity-alist nil
13735 "Cache with entities and corresponding architectures for each
13736 project/directory.")
13737 ;; structure: (parenthesized expression means list of such entries)
13738 ;; (cache-key
13739 ;; (ent-key ent-name ent-file ent-line
13740 ;; (arch-key arch-name arch-file arch-line
13741 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13742 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13743 ;; (lib-name pack-key))
13744 ;; mra-key (lib-name pack-key))
13745
13746 (defvar vhdl-config-alist nil
13747 "Cache with configurations for each project/directory.")
13748 ;; structure: (parenthesized expression means list of such entries)
13749 ;; (cache-key
13750 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13751 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13752 ;; inst-conf-key inst-lib-key)
13753 ;; (lib-name pack-key)))
13754
13755 (defvar vhdl-package-alist nil
13756 "Cache with packages for each project/directory.")
13757 ;; structure: (parenthesized expression means list of such entries)
13758 ;; (cache-key
13759 ;; (pack-key pack-name pack-file pack-line
13760 ;; (comp-key comp-name comp-file comp-line)
13761 ;; (func-key func-name func-file func-line)
13762 ;; (lib-name pack-key)
13763 ;; pack-body-file pack-body-line
13764 ;; (func-key func-name func-body-file func-body-line)
13765 ;; (lib-name pack-key)))
13766
13767 (defvar vhdl-ent-inst-alist nil
13768 "Cache with instantiated entities for each project/directory.")
13769 ;; structure: (parenthesized expression means list of such entries)
13770 ;; (cache-key (inst-ent-key))
13771
13772 (defvar vhdl-file-alist nil
13773 "Cache with design units in each file for each project/directory.")
13774 ;; structure: (parenthesized expression means list of such entries)
13775 ;; (cache-key
13776 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13777 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13778
13779 (defvar vhdl-directory-alist nil
13780 "Cache with source directories for each project.")
13781 ;; structure: (parenthesized expression means list of such entries)
13782 ;; (cache-key (directory))
13783
13784 (defvar vhdl-speedbar-shown-unit-alist nil
13785 "Alist of design units simultaneously open in the current speedbar for each
13786 directory and project.")
13787
13788 (defvar vhdl-speedbar-shown-project-list nil
13789 "List of projects simultaneously open in the current speedbar.")
13790
13791 (defvar vhdl-updated-project-list nil
13792 "List of projects and directories with updated files.")
13793
13794 (defvar vhdl-modified-file-list nil
13795 "List of modified files to be rescanned for hierarchy updating.")
13796
13797 (defvar vhdl-speedbar-hierarchy-depth 0
13798 "Depth of instantiation hierarchy to display.")
13799
13800 (defvar vhdl-speedbar-show-projects nil
13801 "Non-nil means project hierarchy is displayed in speedbar, directory
13802 hierarchy otherwise.")
13803
13804 (defun vhdl-get-end-of-unit ()
13805 "Return position of end of current unit."
13806 (let ((pos (point)))
13807 (save-excursion
13808 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
13809 (save-excursion
13810 (goto-char (match-beginning 0))
13811 (vhdl-backward-syntactic-ws)
13812 (and (/= (preceding-char) ?\;) (not (bobp))))))
13813 (re-search-backward "^[ \t]*end\\>" pos 1)
13814 (point))))
13815
13816 (defun vhdl-match-string-downcase (num &optional string)
13817 "Like `match-string-no-properties' with down-casing."
13818 (let ((match (match-string-no-properties num string)))
13819 (and match (downcase match))))
13820
13821
13822 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13823 ;; Scan functions
13824
13825 (defun vhdl-scan-context-clause ()
13826 "Scan the context clause that precedes a design unit."
13827 (let (lib-alist)
13828 (save-excursion
13829 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
13830 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13831 (equal "USE" (upcase (match-string 1))))
13832 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13833 (push (cons (match-string-no-properties 1)
13834 (vhdl-match-string-downcase 2))
13835 lib-alist)))))
13836 lib-alist))
13837
13838 (defun vhdl-scan-directory-contents (name &optional project update num-string
13839 non-final)
13840 "Scan contents of VHDL files in directory or file pattern NAME."
13841 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13842 (let* ((dir-name (match-string 1 name))
13843 (file-pattern (match-string 2 name))
13844 (is-directory (= 0 (length file-pattern)))
13845 (file-list
13846 (if update
13847 (list name)
13848 (if is-directory
13849 (vhdl-get-source-files t dir-name)
13850 (vhdl-directory-files
13851 dir-name t (wildcard-to-regexp file-pattern)))))
13852 (key (or project dir-name))
13853 (file-exclude-regexp
13854 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13855 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13856 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13857 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13858 ent-alist conf-alist pack-alist ent-inst-list file-alist
13859 tmp-list tmp-entry no-files files-exist big-files)
13860 (when (or project update)
13861 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13862 conf-alist (vhdl-aget vhdl-config-alist key)
13863 pack-alist (vhdl-aget vhdl-package-alist key)
13864 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13865 file-alist (vhdl-aget vhdl-file-alist key)))
13866 (when (and (not is-directory) (null file-list))
13867 (message "No such file: \"%s\"" name))
13868 (setq files-exist file-list)
13869 (when file-list
13870 (setq no-files (length file-list))
13871 (message "Scanning %s %s\"%s\"..."
13872 (if is-directory "directory" "files") (or num-string "") name)
13873 ;; exclude files
13874 (unless (equal file-exclude-regexp "")
13875 (let ((case-fold-search nil)
13876 file-tmp-list)
13877 (while file-list
13878 (unless (string-match file-exclude-regexp (car file-list))
13879 (push (car file-list) file-tmp-list))
13880 (setq file-list (cdr file-list)))
13881 (setq file-list (nreverse file-tmp-list))))
13882 ;; do for all files
13883 (while file-list
13884 (unless noninteractive
13885 (message "Scanning %s %s\"%s\"... (%2d%%)"
13886 (if is-directory "directory" "files")
13887 (or num-string "") name
13888 (floor (* 100.0 (- no-files (length file-list))) no-files)))
13889 (let ((file-name (abbreviate-file-name (car file-list)))
13890 ent-list arch-list arch-ent-list conf-list
13891 pack-list pack-body-list inst-list inst-ent-list)
13892 ;; scan file
13893 (vhdl-visit-file
13894 file-name nil
13895 (vhdl-prepare-search-2
13896 (save-excursion
13897 ;; scan for design units
13898 (if (and limit-design-file-size
13899 (< limit-design-file-size (buffer-size)))
13900 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13901 (setq big-files t))
13902 ;; scan for entities
13903 (goto-char (point-min))
13904 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13905 (let* ((ent-name (match-string-no-properties 1))
13906 (ent-key (downcase ent-name))
13907 (ent-entry (vhdl-aget ent-alist ent-key))
13908 (lib-alist (vhdl-scan-context-clause)))
13909 (if (nth 1 ent-entry)
13910 (vhdl-warning-when-idle
13911 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13912 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13913 file-name (vhdl-current-line))
13914 (push ent-key ent-list)
13915 (vhdl-aput 'ent-alist ent-key
13916 (list ent-name file-name (vhdl-current-line)
13917 (nth 3 ent-entry) (nth 4 ent-entry)
13918 lib-alist)))))
13919 ;; scan for architectures
13920 (goto-char (point-min))
13921 (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13922 (let* ((arch-name (match-string-no-properties 1))
13923 (arch-key (downcase arch-name))
13924 (ent-name (match-string-no-properties 2))
13925 (ent-key (downcase ent-name))
13926 (ent-entry (vhdl-aget ent-alist ent-key))
13927 (arch-alist (nth 3 ent-entry))
13928 (arch-entry (vhdl-aget arch-alist arch-key))
13929 (lib-arch-alist (vhdl-scan-context-clause)))
13930 (if arch-entry
13931 (vhdl-warning-when-idle
13932 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13933 arch-name ent-name (nth 1 arch-entry)
13934 (nth 2 arch-entry) file-name (vhdl-current-line))
13935 (setq arch-list (cons arch-key arch-list)
13936 arch-ent-list (cons ent-key arch-ent-list))
13937 (vhdl-aput 'arch-alist arch-key
13938 (list arch-name file-name (vhdl-current-line)
13939 nil lib-arch-alist))
13940 (vhdl-aput 'ent-alist ent-key
13941 (list (or (nth 0 ent-entry) ent-name)
13942 (nth 1 ent-entry) (nth 2 ent-entry)
13943 (vhdl-sort-alist arch-alist)
13944 arch-key (nth 5 ent-entry))))))
13945 ;; scan for configurations
13946 (goto-char (point-min))
13947 (while (re-search-forward "^[ \t]*configuration[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13948 (let* ((conf-name (match-string-no-properties 1))
13949 (conf-key (downcase conf-name))
13950 (conf-entry (vhdl-aget conf-alist conf-key))
13951 (ent-name (match-string-no-properties 2))
13952 (ent-key (downcase ent-name))
13953 (lib-alist (vhdl-scan-context-clause))
13954 (conf-line (vhdl-current-line))
13955 (end-of-unit (vhdl-get-end-of-unit))
13956 arch-key comp-conf-list inst-key-list
13957 inst-comp-key inst-ent-key inst-arch-key
13958 inst-conf-key inst-lib-key)
13959 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13960 (setq arch-key (vhdl-match-string-downcase 1)))
13961 (if conf-entry
13962 (vhdl-warning-when-idle
13963 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13964 conf-name ent-name (nth 1 conf-entry)
13965 (nth 2 conf-entry) file-name conf-line)
13966 (push conf-key conf-list)
13967 ;; scan for subconfigurations and subentities
13968 (while (re-search-forward "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+" end-of-unit t)
13969 (setq inst-comp-key (vhdl-match-string-downcase 3)
13970 inst-key-list (split-string
13971 (vhdl-match-string-downcase 1)
13972 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13973 (vhdl-forward-syntactic-ws)
13974 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13975 (setq
13976 inst-lib-key (vhdl-match-string-downcase 3)
13977 inst-ent-key (and (match-string 2)
13978 (vhdl-match-string-downcase 4))
13979 inst-arch-key (and (match-string 2)
13980 (vhdl-match-string-downcase 6))
13981 inst-conf-key (and (not (match-string 2))
13982 (vhdl-match-string-downcase 4)))
13983 (while inst-key-list
13984 (setq comp-conf-list
13985 (cons (list (car inst-key-list)
13986 inst-comp-key inst-ent-key
13987 inst-arch-key inst-conf-key
13988 inst-lib-key)
13989 comp-conf-list))
13990 (setq inst-key-list (cdr inst-key-list)))))
13991 (vhdl-aput 'conf-alist conf-key
13992 (list conf-name file-name conf-line ent-key
13993 arch-key comp-conf-list lib-alist)))))
13994 ;; scan for packages
13995 (goto-char (point-min))
13996 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13997 (let* ((pack-name (match-string-no-properties 2))
13998 (pack-key (downcase pack-name))
13999 (is-body (match-string-no-properties 1))
14000 (pack-entry (vhdl-aget pack-alist pack-key))
14001 (pack-line (vhdl-current-line))
14002 (end-of-unit (vhdl-get-end-of-unit))
14003 comp-name func-name comp-alist func-alist lib-alist)
14004 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14005 (vhdl-warning-when-idle
14006 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
14007 (if is-body " body" "") pack-name
14008 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14009 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
14010 file-name (vhdl-current-line))
14011 ;; scan for context clauses
14012 (setq lib-alist (vhdl-scan-context-clause))
14013 ;; scan for component and subprogram declarations/bodies
14014 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
14015 (if (equal (upcase (match-string 1)) "COMPONENT")
14016 (setq comp-name (match-string-no-properties 2)
14017 comp-alist
14018 (cons (list (downcase comp-name) comp-name
14019 file-name (vhdl-current-line))
14020 comp-alist))
14021 (setq func-name (match-string-no-properties 2)
14022 func-alist
14023 (cons (list (downcase func-name) func-name
14024 file-name (vhdl-current-line))
14025 func-alist))))
14026 (setq func-alist (nreverse func-alist))
14027 (setq comp-alist (nreverse comp-alist))
14028 (if is-body
14029 (push pack-key pack-body-list)
14030 (push pack-key pack-list))
14031 (vhdl-aput
14032 'pack-alist pack-key
14033 (if is-body
14034 (list (or (nth 0 pack-entry) pack-name)
14035 (nth 1 pack-entry) (nth 2 pack-entry)
14036 (nth 3 pack-entry) (nth 4 pack-entry)
14037 (nth 5 pack-entry)
14038 file-name pack-line func-alist lib-alist)
14039 (list pack-name file-name pack-line
14040 comp-alist func-alist lib-alist
14041 (nth 6 pack-entry) (nth 7 pack-entry)
14042 (nth 8 pack-entry) (nth 9 pack-entry))))))))
14043 ;; scan for hierarchy
14044 (if (and limit-hier-file-size
14045 (< limit-hier-file-size (buffer-size)))
14046 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
14047 (setq big-files t))
14048 ;; scan for architectures
14049 (goto-char (point-min))
14050 (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
14051 (let* ((ent-name (match-string-no-properties 2))
14052 (ent-key (downcase ent-name))
14053 (arch-name (match-string-no-properties 1))
14054 (arch-key (downcase arch-name))
14055 (ent-entry (vhdl-aget ent-alist ent-key))
14056 (arch-alist (nth 3 ent-entry))
14057 (arch-entry (vhdl-aget arch-alist arch-key))
14058 (beg-of-unit (point))
14059 (end-of-unit (vhdl-get-end-of-unit))
14060 (inst-no 0)
14061 inst-alist inst-path)
14062 ;; scan for contained instantiations
14063 (while (and (re-search-forward
14064 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
14065 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
14066 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
14067 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
14068 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
14069 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
14070 (or (not limit-hier-inst-no)
14071 (<= (if (or (match-string 14)
14072 (match-string 16))
14073 inst-no
14074 (setq inst-no (1+ inst-no)))
14075 limit-hier-inst-no)))
14076 (cond
14077 ;; block/generate beginning found
14078 ((match-string 14)
14079 (setq inst-path
14080 (cons (match-string-no-properties 1) inst-path)))
14081 ;; block/generate end found
14082 ((match-string 16)
14083 (setq inst-path (cdr inst-path)))
14084 ;; instantiation found
14085 (t
14086 (let* ((inst-name (match-string-no-properties 1))
14087 (inst-key (downcase inst-name))
14088 (inst-comp-name
14089 (or (match-string-no-properties 3)
14090 (match-string-no-properties 6)))
14091 (inst-ent-key
14092 (or (and (match-string 8)
14093 (vhdl-match-string-downcase 11))
14094 (and inst-comp-name
14095 (downcase inst-comp-name))))
14096 (inst-arch-key (vhdl-match-string-downcase 13))
14097 (inst-conf-key
14098 (and (not (match-string 8))
14099 (vhdl-match-string-downcase 11)))
14100 (inst-lib-key (vhdl-match-string-downcase 10)))
14101 (goto-char (match-end 1))
14102 (setq inst-list (cons inst-key inst-list)
14103 inst-ent-list
14104 (cons inst-ent-key inst-ent-list))
14105 (setq inst-alist
14106 (append
14107 inst-alist
14108 (list (list inst-key inst-name file-name
14109 (vhdl-current-line) inst-comp-name
14110 inst-ent-key inst-arch-key
14111 inst-conf-key inst-lib-key
14112 (reverse inst-path)))))))))
14113 ;; scan for contained configuration specifications
14114 (goto-char beg-of-unit)
14115 (while (re-search-forward
14116 (concat "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*"
14117 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
14118 (let* ((inst-comp-name (match-string-no-properties 3))
14119 (inst-ent-key
14120 (and (match-string 6)
14121 (vhdl-match-string-downcase 9)))
14122 (inst-arch-key (vhdl-match-string-downcase 11))
14123 (inst-conf-key
14124 (and (not (match-string 6))
14125 (vhdl-match-string-downcase 9)))
14126 (inst-lib-key (vhdl-match-string-downcase 8))
14127 (inst-key-list
14128 (split-string (vhdl-match-string-downcase 1)
14129 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
14130 (tmp-inst-alist inst-alist)
14131 inst-entry)
14132 (while tmp-inst-alist
14133 (when (and (or (equal "all" (car inst-key-list))
14134 (member (nth 0 (car tmp-inst-alist))
14135 inst-key-list))
14136 (equal
14137 (downcase
14138 (or (nth 4 (car tmp-inst-alist)) ""))
14139 (downcase inst-comp-name)))
14140 (setq inst-entry (car tmp-inst-alist))
14141 (setq inst-ent-list
14142 (cons (or inst-ent-key (nth 5 inst-entry))
14143 (vhdl-delete
14144 (nth 5 inst-entry) inst-ent-list)))
14145 (setq inst-entry
14146 (list (nth 0 inst-entry) (nth 1 inst-entry)
14147 (nth 2 inst-entry) (nth 3 inst-entry)
14148 (nth 4 inst-entry)
14149 (or inst-ent-key (nth 5 inst-entry))
14150 (or inst-arch-key (nth 6 inst-entry))
14151 inst-conf-key inst-lib-key))
14152 (setcar tmp-inst-alist inst-entry))
14153 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14154 ;; save in cache
14155 (vhdl-aput 'arch-alist arch-key
14156 (list (nth 0 arch-entry) (nth 1 arch-entry)
14157 (nth 2 arch-entry) inst-alist
14158 (nth 4 arch-entry)))
14159 (vhdl-aput 'ent-alist ent-key
14160 (list (nth 0 ent-entry) (nth 1 ent-entry)
14161 (nth 2 ent-entry)
14162 (vhdl-sort-alist arch-alist)
14163 (nth 4 ent-entry) (nth 5 ent-entry)))
14164 (when (and limit-hier-inst-no
14165 (> inst-no limit-hier-inst-no))
14166 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14167 (setq big-files t))
14168 (goto-char end-of-unit))))
14169 ;; remember design units for this file
14170 (vhdl-aput 'file-alist file-name
14171 (list ent-list arch-list arch-ent-list conf-list
14172 pack-list pack-body-list
14173 inst-list inst-ent-list))
14174 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14175 (setq file-list (cdr file-list))))
14176 (when (or (and (not project) files-exist)
14177 (and project (not non-final)))
14178 ;; consistency checks:
14179 ;; check whether each architecture has a corresponding entity
14180 (setq tmp-list ent-alist)
14181 (while tmp-list
14182 (when (null (nth 2 (car tmp-list)))
14183 (setq tmp-entry (car (nth 4 (car tmp-list))))
14184 (vhdl-warning-when-idle
14185 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14186 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14187 (nth 3 tmp-entry)))
14188 (setq tmp-list (cdr tmp-list)))
14189 ;; check whether configuration has a corresponding entity/architecture
14190 (setq tmp-list conf-alist)
14191 (while tmp-list
14192 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14193 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14194 (setq tmp-entry (car tmp-list))
14195 (vhdl-warning-when-idle
14196 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14197 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14198 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14199 (setq tmp-entry (car tmp-list))
14200 (vhdl-warning-when-idle
14201 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14202 (nth 1 tmp-entry) (nth 4 tmp-entry)
14203 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14204 (setq tmp-list (cdr tmp-list)))
14205 ;; check whether each package body has a package declaration
14206 (setq tmp-list pack-alist)
14207 (while tmp-list
14208 (when (null (nth 2 (car tmp-list)))
14209 (setq tmp-entry (car tmp-list))
14210 (vhdl-warning-when-idle
14211 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14212 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14213 (setq tmp-list (cdr tmp-list)))
14214 ;; sort lists
14215 (setq ent-alist (vhdl-sort-alist ent-alist))
14216 (setq conf-alist (vhdl-sort-alist conf-alist))
14217 (setq pack-alist (vhdl-sort-alist pack-alist))
14218 ;; remember updated directory/project
14219 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14220 ;; clear directory alists
14221 (unless project
14222 (vhdl-adelete 'vhdl-entity-alist key)
14223 (vhdl-adelete 'vhdl-config-alist key)
14224 (vhdl-adelete 'vhdl-package-alist key)
14225 (vhdl-adelete 'vhdl-ent-inst-alist key)
14226 (vhdl-adelete 'vhdl-file-alist key))
14227 ;; put directory contents into cache
14228 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14229 (vhdl-aput 'vhdl-config-alist key conf-alist)
14230 (vhdl-aput 'vhdl-package-alist key pack-alist)
14231 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14232 (vhdl-aput 'vhdl-file-alist key file-alist)
14233 ;; final messages
14234 (message "Scanning %s %s\"%s\"...done"
14235 (if is-directory "directory" "files") (or num-string "") name)
14236 (unless project (message "Scanning directory...done"))
14237 (when big-files
14238 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14239 ;; save cache when scanned non-interactively
14240 (when (or (not project) (not non-final))
14241 (when (and noninteractive vhdl-speedbar-save-cache)
14242 (vhdl-save-cache key)))
14243 t))
14244
14245 (defun vhdl-scan-project-contents (project)
14246 "Scan the contents of all VHDL files found in the directories and files
14247 of PROJECT."
14248 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14249 (default-dir (vhdl-resolve-env-variable
14250 (nth 1 (vhdl-aget vhdl-project-alist project))))
14251 (file-exclude-regexp
14252 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14253 dir-list-tmp dir dir-name num-dir act-dir recursive)
14254 ;; clear project alists
14255 (vhdl-adelete 'vhdl-entity-alist project)
14256 (vhdl-adelete 'vhdl-config-alist project)
14257 (vhdl-adelete 'vhdl-package-alist project)
14258 (vhdl-adelete 'vhdl-ent-inst-alist project)
14259 (vhdl-adelete 'vhdl-file-alist project)
14260 ;; expand directory names by default-directory
14261 (message "Collecting source files...")
14262 (while dir-list
14263 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14264 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14265 (setq recursive (match-string 1 dir)
14266 dir-name (match-string 3 dir))
14267 (setq dir-list-tmp
14268 (cons (concat recursive
14269 (if (file-name-absolute-p dir-name) "" default-dir)
14270 dir-name)
14271 dir-list-tmp))
14272 (setq dir-list (cdr dir-list)))
14273 ;; resolve path wildcards
14274 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14275 ;; expand directories
14276 (while dir-list-tmp
14277 (setq dir (car dir-list-tmp))
14278 ;; get subdirectories
14279 (if (string-match "-r \\(.*[/\\]\\)" dir)
14280 (setq dir-list (append dir-list (vhdl-get-subdirs
14281 (match-string 1 dir))))
14282 (setq dir-list (append dir-list (list dir))))
14283 (setq dir-list-tmp (cdr dir-list-tmp)))
14284 ;; exclude files
14285 (unless (equal file-exclude-regexp "")
14286 (let ((case-fold-search nil))
14287 (while dir-list
14288 (unless (string-match file-exclude-regexp (car dir-list))
14289 (push (car dir-list) dir-list-tmp))
14290 (setq dir-list (cdr dir-list)))
14291 (setq dir-list (nreverse dir-list-tmp))))
14292 (message "Collecting source files...done")
14293 ;; scan for design units for each directory in DIR-LIST
14294 (setq dir-list-tmp nil
14295 num-dir (length dir-list)
14296 act-dir 1)
14297 (while dir-list
14298 (setq dir-name (abbreviate-file-name
14299 (expand-file-name (car dir-list))))
14300 (vhdl-scan-directory-contents dir-name project nil
14301 (format "(%s/%s) " act-dir num-dir)
14302 (cdr dir-list))
14303 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
14304 (setq dir-list (cdr dir-list)
14305 act-dir (1+ act-dir)))
14306 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14307 (message "Scanning project \"%s\"...done" project)))
14308
14309 (defun vhdl-update-file-contents (file-name)
14310 "Update hierarchy information by contents of current buffer."
14311 (setq file-name (abbreviate-file-name file-name))
14312 (let* ((dir-name (file-name-directory file-name))
14313 (directory-alist vhdl-directory-alist)
14314 updated)
14315 (while directory-alist
14316 (when (member dir-name (nth 1 (car directory-alist)))
14317 (let* ((vhdl-project (nth 0 (car directory-alist)))
14318 (project (vhdl-project-p))
14319 (ent-alist (vhdl-aget vhdl-entity-alist
14320 (or project dir-name)))
14321 (conf-alist (vhdl-aget vhdl-config-alist
14322 (or project dir-name)))
14323 (pack-alist (vhdl-aget vhdl-package-alist
14324 (or project dir-name)))
14325 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14326 (or project dir-name))))
14327 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14328 (file-entry (vhdl-aget file-alist file-name))
14329 (ent-list (nth 0 file-entry))
14330 (arch-list (nth 1 file-entry))
14331 (arch-ent-list (nth 2 file-entry))
14332 (conf-list (nth 3 file-entry))
14333 (pack-list (nth 4 file-entry))
14334 (pack-body-list (nth 5 file-entry))
14335 (inst-ent-list (nth 7 file-entry))
14336 (cache-key (or project dir-name))
14337 arch-alist key ent-key entry)
14338 ;; delete design units previously contained in this file:
14339 ;; entities
14340 (while ent-list
14341 (setq key (car ent-list)
14342 entry (vhdl-aget ent-alist key))
14343 (when (equal file-name (nth 1 entry))
14344 (if (nth 3 entry)
14345 (vhdl-aput 'ent-alist key
14346 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14347 (vhdl-adelete 'ent-alist key)))
14348 (setq ent-list (cdr ent-list)))
14349 ;; architectures
14350 (while arch-list
14351 (setq key (car arch-list)
14352 ent-key (car arch-ent-list)
14353 entry (vhdl-aget ent-alist ent-key)
14354 arch-alist (nth 3 entry))
14355 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14356 (vhdl-adelete 'arch-alist key)
14357 (if (or (nth 1 entry) arch-alist)
14358 (vhdl-aput 'ent-alist ent-key
14359 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14360 arch-alist (nth 4 entry) (nth 5 entry)))
14361 (vhdl-adelete 'ent-alist ent-key)))
14362 (setq arch-list (cdr arch-list)
14363 arch-ent-list (cdr arch-ent-list)))
14364 ;; configurations
14365 (while conf-list
14366 (setq key (car conf-list))
14367 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14368 (vhdl-adelete 'conf-alist key))
14369 (setq conf-list (cdr conf-list)))
14370 ;; package declarations
14371 (while pack-list
14372 (setq key (car pack-list)
14373 entry (vhdl-aget pack-alist key))
14374 (when (equal file-name (nth 1 entry))
14375 (if (nth 6 entry)
14376 (vhdl-aput 'pack-alist key
14377 (list (nth 0 entry) nil nil nil nil nil
14378 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14379 (nth 9 entry)))
14380 (vhdl-adelete 'pack-alist key)))
14381 (setq pack-list (cdr pack-list)))
14382 ;; package bodies
14383 (while pack-body-list
14384 (setq key (car pack-body-list)
14385 entry (vhdl-aget pack-alist key))
14386 (when (equal file-name (nth 6 entry))
14387 (if (nth 1 entry)
14388 (vhdl-aput 'pack-alist key
14389 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14390 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14391 nil nil nil nil))
14392 (vhdl-adelete 'pack-alist key)))
14393 (setq pack-body-list (cdr pack-body-list)))
14394 ;; instantiated entities
14395 (while inst-ent-list
14396 (setq ent-inst-list
14397 (vhdl-delete (car inst-ent-list) ent-inst-list))
14398 (setq inst-ent-list (cdr inst-ent-list)))
14399 ;; update caches
14400 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14401 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14402 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14403 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14404 ;; scan file
14405 (vhdl-scan-directory-contents file-name project t)
14406 (when (or (and vhdl-speedbar-show-projects project)
14407 (and (not vhdl-speedbar-show-projects) (not project)))
14408 (vhdl-speedbar-refresh project))
14409 (setq updated t)))
14410 (setq directory-alist (cdr directory-alist)))
14411 updated))
14412
14413 (defun vhdl-update-hierarchy ()
14414 "Update directory and hierarchy information in speedbar."
14415 (let ((file-list (reverse vhdl-modified-file-list))
14416 updated)
14417 (when (and vhdl-speedbar-update-on-saving file-list)
14418 (while file-list
14419 (setq updated
14420 (or (vhdl-update-file-contents (car file-list))
14421 updated))
14422 (setq file-list (cdr file-list)))
14423 (setq vhdl-modified-file-list nil)
14424 (vhdl-speedbar-update-current-unit)
14425 (when updated (message "Updating hierarchy...done")))))
14426
14427 ;; structure (parenthesized expression means list of such entries)
14428 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14429 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14430 ;; comp-lib-name level)
14431 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14432 conf-inst-alist level indent
14433 &optional include-top ent-hier)
14434 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14435 entity ENT-KEY."
14436 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14437 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14438 (cdar (last (nth 3 ent-entry)))))
14439 (inst-alist (nth 3 arch-entry))
14440 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14441 hier-list subcomp-list tmp-list inst-key inst-comp-name
14442 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14443 (when (= level 0) (message "Extract design hierarchy..."))
14444 (when include-top
14445 (setq level (1+ level)))
14446 (when (member ent-key ent-hier)
14447 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14448 ;; process all instances
14449 (while inst-alist
14450 (setq inst-entry (car inst-alist)
14451 inst-key (nth 0 inst-entry)
14452 inst-comp-name (nth 4 inst-entry)
14453 inst-conf-key (nth 7 inst-entry))
14454 ;; search entry in configuration's instantiations list
14455 (setq tmp-list conf-inst-alist)
14456 (while (and tmp-list
14457 (not (and (member (nth 0 (car tmp-list))
14458 (list "all" inst-key))
14459 (equal (nth 1 (car tmp-list))
14460 (downcase (or inst-comp-name ""))))))
14461 (setq tmp-list (cdr tmp-list)))
14462 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14463 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14464 (when (and inst-conf-key (not inst-conf-entry))
14465 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14466 ;; determine entity
14467 (setq inst-ent-key
14468 (or (nth 2 (car tmp-list)) ; from configuration
14469 (nth 3 inst-conf-entry) ; from subconfiguration
14470 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14471 ; from configuration spec.
14472 (nth 5 inst-entry))) ; from direct instantiation
14473 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14474 ;; determine architecture
14475 (setq inst-arch-key
14476 (or (nth 3 (car tmp-list)) ; from configuration
14477 (nth 4 inst-conf-entry) ; from subconfiguration
14478 (nth 6 inst-entry) ; from direct instantiation
14479 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14480 ; from configuration spec.
14481 (nth 4 inst-ent-entry) ; MRA
14482 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14483 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14484 ;; set library
14485 (setq inst-lib-key
14486 (or (nth 5 (car tmp-list)) ; from configuration
14487 (nth 8 inst-entry))) ; from direct instantiation
14488 ;; gather information for this instance
14489 (setq comp-entry
14490 (list (nth 1 inst-entry)
14491 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14492 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14493 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14494 (or (nth 0 inst-arch-entry) inst-arch-key)
14495 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14496 (or (nth 0 inst-conf-entry) inst-conf-key)
14497 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14498 inst-lib-key level))
14499 ;; get subcomponent hierarchy
14500 (setq subcomp-list (vhdl-get-hierarchy
14501 ent-alist conf-alist
14502 inst-ent-key inst-arch-key inst-conf-key
14503 (nth 5 inst-conf-entry)
14504 (1+ level) indent nil (cons ent-key ent-hier)))
14505 ;; add to list
14506 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14507 (setq inst-alist (cdr inst-alist)))
14508 (when include-top
14509 (setq hier-list
14510 (cons (list nil nil (nth 0 ent-entry)
14511 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14512 (nth 0 arch-entry)
14513 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14514 nil nil
14515 nil (1- level))
14516 hier-list)))
14517 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14518 hier-list))
14519
14520 (defun vhdl-get-instantiations (ent-key indent)
14521 "Get all instantiations of entity ENT-KEY."
14522 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14523 (vhdl-speedbar-line-key indent)))
14524 arch-alist inst-alist ent-inst-list
14525 ent-entry arch-entry inst-entry)
14526 (while ent-alist
14527 (setq ent-entry (car ent-alist))
14528 (setq arch-alist (nth 4 ent-entry))
14529 (while arch-alist
14530 (setq arch-entry (car arch-alist))
14531 (setq inst-alist (nth 4 arch-entry))
14532 (while inst-alist
14533 (setq inst-entry (car inst-alist))
14534 (when (equal ent-key (nth 5 inst-entry))
14535 (setq ent-inst-list
14536 (cons (list (nth 1 inst-entry)
14537 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14538 (nth 1 ent-entry)
14539 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14540 (nth 1 arch-entry)
14541 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14542 ent-inst-list)))
14543 (setq inst-alist (cdr inst-alist)))
14544 (setq arch-alist (cdr arch-alist)))
14545 (setq ent-alist (cdr ent-alist)))
14546 (nreverse ent-inst-list)))
14547
14548 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14549 ;; Caching in file
14550
14551 (defun vhdl-save-caches ()
14552 "Save all updated hierarchy caches to file."
14553 (interactive)
14554 (condition-case nil
14555 (when vhdl-speedbar-save-cache
14556 ;; update hierarchy
14557 (vhdl-update-hierarchy)
14558 (let ((project-list vhdl-updated-project-list))
14559 (message "Saving hierarchy caches...")
14560 ;; write updated project caches
14561 (while project-list
14562 (vhdl-save-cache (car project-list))
14563 (setq project-list (cdr project-list)))
14564 (message "Saving hierarchy caches...done")))
14565 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14566 (sit-for 2)))))
14567
14568 (defun vhdl-save-cache (key)
14569 "Save current hierarchy cache to file."
14570 (let* ((orig-buffer (current-buffer))
14571 (vhdl-project key)
14572 (project (vhdl-project-p))
14573 (default-directory key)
14574 (directory (abbreviate-file-name (vhdl-default-directory)))
14575 (file-name (vhdl-resolve-env-variable
14576 (vhdl-replace-string
14577 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14578 (concat
14579 (subst-char-in-string ? ?_ (or project "dir"))
14580 " " (user-login-name)))))
14581 (file-dir-name (expand-file-name file-name directory))
14582 (cache-key (or project directory))
14583 (key (if project "project" "directory")))
14584 (unless (file-exists-p (file-name-directory file-dir-name))
14585 (make-directory (file-name-directory file-dir-name) t))
14586 (if (not (file-writable-p file-dir-name))
14587 (progn (vhdl-warning (format "File not writable: \"%s\""
14588 (abbreviate-file-name file-dir-name)))
14589 (sit-for 2))
14590 (message "Saving cache: \"%s\"" file-dir-name)
14591 (set-buffer (find-file-noselect file-dir-name t t))
14592 (erase-buffer)
14593 (insert ";; -*- Emacs-Lisp -*-\n\n"
14594 ";;; " (file-name-nondirectory file-name)
14595 " - design hierarchy cache file for Emacs VHDL Mode "
14596 vhdl-version "\n")
14597 (insert "\n;; " (if project "Project " "Directory") " : ")
14598 (if project (insert project) (prin1 directory (current-buffer)))
14599 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14600 (user-login-name) "\n\n"
14601 "\n;; version number\n"
14602 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14603 "\n;; " (if project "project" "directory") " name"
14604 "\n(setq " key " ")
14605 (prin1 (or project directory) (current-buffer))
14606 (insert ")\n")
14607 (when (member 'hierarchy vhdl-speedbar-save-cache)
14608 (insert "\n;; entity and architecture cache\n"
14609 "(vhdl-aput 'vhdl-entity-alist " key " '")
14610 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14611 (insert ")\n\n;; configuration cache\n"
14612 "(vhdl-aput 'vhdl-config-alist " key " '")
14613 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14614 (insert ")\n\n;; package cache\n"
14615 "(vhdl-aput 'vhdl-package-alist " key " '")
14616 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14617 (insert ")\n\n;; instantiated entities cache\n"
14618 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14619 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14620 (insert ")\n\n;; design units per file cache\n"
14621 "(vhdl-aput 'vhdl-file-alist " key " '")
14622 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14623 (when project
14624 (insert ")\n\n;; source directories in project cache\n"
14625 "(vhdl-aput 'vhdl-directory-alist " key " '")
14626 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14627 (insert ")\n"))
14628 (when (member 'display vhdl-speedbar-save-cache)
14629 (insert "\n;; shown design units cache\n"
14630 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14631 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14632 (current-buffer))
14633 (insert ")\n"))
14634 (setq vhdl-updated-project-list
14635 (delete cache-key vhdl-updated-project-list))
14636 (save-buffer)
14637 (kill-buffer (current-buffer))
14638 (set-buffer orig-buffer))))
14639
14640 (defun vhdl-load-cache (key)
14641 "Load hierarchy cache information from file."
14642 (let* ((vhdl-project key)
14643 (default-directory key)
14644 (directory (vhdl-default-directory))
14645 (file-name (vhdl-resolve-env-variable
14646 (vhdl-replace-string
14647 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14648 (concat
14649 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14650 " " (user-login-name)))))
14651 (file-dir-name (expand-file-name file-name directory))
14652 vhdl-cache-version)
14653 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14654 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14655 (when (file-exists-p file-dir-name)
14656 (condition-case ()
14657 (progn (load-file file-dir-name)
14658 (string< (mapconcat
14659 (lambda (a) (format "%3d" (string-to-number a)))
14660 (split-string "3.33" "\\.") "")
14661 (mapconcat
14662 (lambda (a) (format "%3d" (string-to-number a)))
14663 (split-string vhdl-cache-version "\\.") "")))
14664 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14665 nil))))))
14666
14667 (defun vhdl-require-hierarchy-info ()
14668 "Make sure that hierarchy information is available. Load cache or scan files
14669 if required."
14670 (if (vhdl-project-p)
14671 (unless (or (assoc vhdl-project vhdl-file-alist)
14672 (vhdl-load-cache vhdl-project))
14673 (vhdl-scan-project-contents vhdl-project))
14674 (let ((directory (abbreviate-file-name default-directory)))
14675 (unless (or (assoc directory vhdl-file-alist)
14676 (vhdl-load-cache directory))
14677 (vhdl-scan-directory-contents directory)))))
14678
14679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14680 ;; Add hierarchy browser functionality to speedbar
14681
14682 (defvar vhdl-speedbar-mode-map nil
14683 "Keymap used when in the VHDL hierarchy browser mode.")
14684
14685 (defvar vhdl-speedbar-menu-items nil
14686 "Additional menu-items to add to speedbar frame.")
14687
14688 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14689 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14690 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14691 (declare-function speedbar-change-initial-expansion-list "speedbar"
14692 (new-default))
14693 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14694
14695 (defun vhdl-speedbar-initialize ()
14696 "Initialize speedbar."
14697 ;; general settings
14698 ;; VHDL file extensions (extracted from `auto-mode-alist')
14699 (let ((mode-alist auto-mode-alist))
14700 (while mode-alist
14701 (when (eq (cdar mode-alist) 'vhdl-mode)
14702 (speedbar-add-supported-extension (caar mode-alist)))
14703 (setq mode-alist (cdr mode-alist))))
14704 ;; hierarchy browser settings
14705 (when (boundp 'speedbar-mode-functions-list)
14706 ;; special functions
14707 (speedbar-add-mode-functions-list
14708 '("vhdl directory"
14709 (speedbar-item-info . vhdl-speedbar-item-info)
14710 (speedbar-line-directory . speedbar-files-line-path)))
14711 (speedbar-add-mode-functions-list
14712 '("vhdl project"
14713 (speedbar-item-info . vhdl-speedbar-item-info)
14714 (speedbar-line-directory . vhdl-speedbar-line-project)))
14715 ;; keymap
14716 (unless vhdl-speedbar-mode-map
14717 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14718 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14719 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14720 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14721 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14722 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14723 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14724 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14725 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14726 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14727 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14728 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14729 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14730 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14731 (let ((key 0))
14732 (while (<= key 9)
14733 (define-key vhdl-speedbar-mode-map (int-to-string key)
14734 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14735 (setq key (1+ key)))))
14736 (define-key speedbar-mode-map "h"
14737 (lambda () (interactive)
14738 (speedbar-change-initial-expansion-list "vhdl directory")))
14739 (define-key speedbar-mode-map "H"
14740 (lambda () (interactive)
14741 (speedbar-change-initial-expansion-list "vhdl project")))
14742 ;; menu
14743 (unless vhdl-speedbar-menu-items
14744 (setq
14745 vhdl-speedbar-menu-items
14746 `(["Edit" speedbar-edit-line t]
14747 ["Expand" speedbar-expand-line
14748 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14749 ["Contract" vhdl-speedbar-contract-level t]
14750 ["Expand All" vhdl-speedbar-expand-all t]
14751 ["Contract All" vhdl-speedbar-contract-all t]
14752 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14753 (while (<= key 9)
14754 (setq menu-list
14755 (cons `[,(if (= key 0) "All" (int-to-string key))
14756 (vhdl-speedbar-set-depth ,key)
14757 :style radio
14758 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14759 :keys ,(int-to-string key)]
14760 menu-list))
14761 (setq key (1+ key)))
14762 (nreverse menu-list))
14763 "--"
14764 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14765 (or (vhdl-speedbar-check-unit 'entity)
14766 (vhdl-speedbar-check-unit 'subprogram))]
14767 ["Place Component" vhdl-speedbar-place-component
14768 (vhdl-speedbar-check-unit 'entity)]
14769 ["Generate Configuration" vhdl-speedbar-configuration
14770 (vhdl-speedbar-check-unit 'architecture)]
14771 ["Select as MRA" vhdl-speedbar-select-mra
14772 (vhdl-speedbar-check-unit 'architecture)]
14773 ["Make" vhdl-speedbar-make-design
14774 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14775 ["Generate Makefile" vhdl-speedbar-generate-makefile
14776 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14777 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14778 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14779 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14780 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14781 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14782 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14783 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14784 ;; hook-ups
14785 (speedbar-add-expansion-list
14786 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14787 vhdl-speedbar-display-directory))
14788 (speedbar-add-expansion-list
14789 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14790 vhdl-speedbar-display-projects))
14791 (setq speedbar-stealthy-function-list
14792 (append
14793 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14794 ("vhdl project" vhdl-speedbar-update-current-project
14795 vhdl-speedbar-update-current-unit))
14796 speedbar-stealthy-function-list))
14797 (when (eq vhdl-speedbar-display-mode 'directory)
14798 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14799 (when (eq vhdl-speedbar-display-mode 'project)
14800 (setq speedbar-initial-expansion-list-name "vhdl project"))
14801 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14802
14803 (defun vhdl-speedbar (&optional arg)
14804 "Open/close speedbar."
14805 (interactive)
14806 (if (not (fboundp 'speedbar))
14807 (error "WARNING: Speedbar is not available or not installed")
14808 (condition-case ()
14809 (speedbar-frame-mode arg)
14810 (error (error "WARNING: An error occurred while opening speedbar")))))
14811
14812 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14813 ;; Display functions
14814
14815 (defvar vhdl-speedbar-last-selected-project nil
14816 "Name of last selected project.")
14817
14818 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14819 ;;; (defmacro speedbar-with-writable (&rest forms)
14820 ;;; "Allow the buffer to be writable and evaluate FORMS."
14821 ;;; (list 'let '((inhibit-read-only t))
14822 ;;; (cons 'progn forms)))
14823 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14824
14825 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14826 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14827 (declare-function speedbar-file-lists "speedbar" (directory))
14828
14829 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14830 "Display directory and hierarchy information in speedbar."
14831 (setq vhdl-speedbar-show-projects nil)
14832 (setq speedbar-ignored-directory-regexp
14833 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14834 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14835 (setq speedbar-last-selected-file nil)
14836 (speedbar-with-writable
14837 (condition-case nil
14838 (progn
14839 ;; insert directory path
14840 (speedbar-directory-buttons directory depth)
14841 ;; insert subdirectories
14842 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14843 ;; scan and insert hierarchy of current directory
14844 (vhdl-speedbar-insert-dir-hierarchy directory depth
14845 speedbar-power-click)
14846 ;; expand subdirectories
14847 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14848 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14849
14850 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14851 "Display projects and hierarchy information in speedbar."
14852 (setq vhdl-speedbar-show-projects t)
14853 (setq speedbar-ignored-directory-regexp ".")
14854 (setq speedbar-last-selected-file nil)
14855 (setq vhdl-speedbar-last-selected-project nil)
14856 (speedbar-with-writable
14857 (condition-case nil
14858 ;; insert projects
14859 (vhdl-speedbar-insert-projects)
14860 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14861 (setq speedbar-full-text-cache nil)) ; prevent caching
14862
14863 (declare-function speedbar-make-tag-line "speedbar"
14864 (type char func data tag tfunc tdata tface depth))
14865
14866 (defun vhdl-speedbar-insert-projects ()
14867 "Insert all projects in speedbar."
14868 (vhdl-speedbar-make-title-line "Projects:")
14869 (let ((project-alist (if vhdl-project-sort
14870 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14871 vhdl-project-alist))
14872 (vhdl-speedbar-update-current-unit nil))
14873 ;; insert projects
14874 (while project-alist
14875 (speedbar-make-tag-line
14876 'angle ?+ 'vhdl-speedbar-expand-project
14877 (caar project-alist) (caar project-alist)
14878 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14879 (setq project-alist (cdr project-alist)))
14880 (setq project-alist vhdl-project-alist)
14881 ;; expand projects
14882 (while project-alist
14883 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14884 (goto-char (point-min))
14885 (when (re-search-forward
14886 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14887 (goto-char (match-end 1))
14888 (speedbar-do-function-pointer)))
14889 (setq project-alist (cdr project-alist)))))
14890
14891 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14892 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14893 otherwise use cached data."
14894 (when (or rescan (and (not (assoc project vhdl-file-alist))
14895 (not (vhdl-load-cache project))))
14896 (vhdl-scan-project-contents project))
14897 ;; insert design hierarchy
14898 (vhdl-speedbar-insert-hierarchy
14899 (vhdl-aget vhdl-entity-alist project)
14900 (vhdl-aget vhdl-config-alist project)
14901 (vhdl-aget vhdl-package-alist project)
14902 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14903 (insert (int-to-string indent) ":\n")
14904 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14905 (put-text-property (1- (point)) (point) 'invisible nil)
14906 ;; expand design units
14907 (vhdl-speedbar-expand-units project))
14908
14909 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14910 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14911 otherwise use cached data."
14912 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14913 (not (vhdl-load-cache directory))))
14914 (vhdl-scan-directory-contents directory))
14915 ;; insert design hierarchy
14916 (vhdl-speedbar-insert-hierarchy
14917 (vhdl-aget vhdl-entity-alist directory)
14918 (vhdl-aget vhdl-config-alist directory)
14919 (vhdl-aget vhdl-package-alist directory)
14920 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14921 ;; expand design units
14922 (vhdl-speedbar-expand-units directory)
14923 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14924
14925 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14926 ent-inst-list depth)
14927 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14928 (if (not (or ent-alist conf-alist pack-alist))
14929 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14930 (let (ent-entry conf-entry pack-entry)
14931 ;; insert entities
14932 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14933 (while ent-alist
14934 (setq ent-entry (car ent-alist))
14935 (speedbar-make-tag-line
14936 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14937 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14938 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14939 'vhdl-speedbar-entity-face depth)
14940 (unless (nth 2 ent-entry)
14941 (end-of-line 0) (insert "!") (forward-char 1))
14942 (unless (member (nth 0 ent-entry) ent-inst-list)
14943 (end-of-line 0) (insert " (top)") (forward-char 1))
14944 (setq ent-alist (cdr ent-alist)))
14945 ;; insert configurations
14946 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14947 (while conf-alist
14948 (setq conf-entry (car conf-alist))
14949 (speedbar-make-tag-line
14950 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14951 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14952 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14953 'vhdl-speedbar-configuration-face depth)
14954 (setq conf-alist (cdr conf-alist)))
14955 ;; insert packages
14956 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14957 (while pack-alist
14958 (setq pack-entry (car pack-alist))
14959 (vhdl-speedbar-make-pack-line
14960 (nth 0 pack-entry) (nth 1 pack-entry)
14961 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14962 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14963 depth)
14964 (setq pack-alist (cdr pack-alist))))))
14965
14966 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14967
14968 (defun vhdl-speedbar-rescan-hierarchy ()
14969 "Rescan hierarchy for the directory or project under the cursor."
14970 (interactive)
14971 (let (key path)
14972 (cond
14973 ;; current project
14974 (vhdl-speedbar-show-projects
14975 (setq key (vhdl-speedbar-line-project))
14976 (vhdl-scan-project-contents key))
14977 ;; top-level directory
14978 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14979 (re-search-forward "[0-9]+:" nil t)
14980 (vhdl-scan-directory-contents
14981 (abbreviate-file-name (speedbar-line-directory))))
14982 ;; current directory
14983 (t (setq path (speedbar-line-directory))
14984 (string-match "^\\(.+[/\\]\\)" path)
14985 (vhdl-scan-directory-contents
14986 (abbreviate-file-name (match-string 1 path)))))
14987 (vhdl-speedbar-refresh key)))
14988
14989 (declare-function speedbar-goto-this-file "speedbar" (file))
14990
14991 (defun vhdl-speedbar-expand-dirs (directory)
14992 "Expand subdirectories in DIRECTORY according to
14993 `speedbar-shown-directories'."
14994 ;; (nicked from `speedbar-default-directory-list')
14995 (let ((sf (cdr (reverse speedbar-shown-directories)))
14996 (vhdl-speedbar-update-current-unit nil))
14997 (setq speedbar-shown-directories
14998 (list (expand-file-name default-directory)))
14999 (while sf
15000 (when (speedbar-goto-this-file (car sf))
15001 (beginning-of-line)
15002 (when (looking-at "[0-9]+:\\s-*<")
15003 (goto-char (match-end 0))
15004 (speedbar-do-function-pointer)))
15005 (setq sf (cdr sf))))
15006 (vhdl-speedbar-update-current-unit nil t))
15007
15008 (defun vhdl-speedbar-expand-units (key)
15009 "Expand design units in directory/project KEY according to
15010 `vhdl-speedbar-shown-unit-alist'."
15011 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15012 (vhdl-speedbar-update-current-unit nil)
15013 vhdl-updated-project-list)
15014 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15015 (vhdl-prepare-search-1
15016 (while unit-alist ; expand units
15017 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
15018 (beginning-of-line)
15019 (let ((arch-alist (nth 1 (car unit-alist)))
15020 position)
15021 (when (looking-at "^[0-9]+:\\s-*\\[")
15022 (goto-char (match-end 0))
15023 (setq position (point))
15024 (speedbar-do-function-pointer)
15025 (select-frame speedbar-frame)
15026 (while arch-alist ; expand architectures
15027 (goto-char position)
15028 (when (re-search-forward
15029 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
15030 (car arch-alist) "\\>\\)") nil t)
15031 (beginning-of-line)
15032 (when (looking-at "^[0-9]+:\\s-*{")
15033 (goto-char (match-end 0))
15034 (speedbar-do-function-pointer)
15035 (select-frame speedbar-frame)))
15036 (setq arch-alist (cdr arch-alist))))
15037 (setq unit-alist (cdr unit-alist))))))
15038 (vhdl-speedbar-update-current-unit nil t))
15039
15040 (declare-function speedbar-center-buffer-smartly "speedbar" ())
15041
15042 (defun vhdl-speedbar-contract-level ()
15043 "Contract current level in current directory/project."
15044 (interactive)
15045 (when (or (save-excursion
15046 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
15047 (and (save-excursion
15048 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
15049 (re-search-backward
15050 (format "^[0-%d]:\\s-*[[{<]-"
15051 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
15052 (goto-char (match-end 0))
15053 (speedbar-do-function-pointer)
15054 (speedbar-center-buffer-smartly)))
15055
15056 (defun vhdl-speedbar-contract-all ()
15057 "Contract all expanded design units in current directory/project."
15058 (interactive)
15059 (if (and vhdl-speedbar-show-projects
15060 (save-excursion (beginning-of-line) (looking-at "^0:")))
15061 (progn (setq vhdl-speedbar-shown-project-list nil)
15062 (vhdl-speedbar-refresh))
15063 (let ((key (vhdl-speedbar-line-key)))
15064 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15065 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
15066 (when (memq 'display vhdl-speedbar-save-cache)
15067 (add-to-list 'vhdl-updated-project-list key)))))
15068
15069 (defun vhdl-speedbar-expand-all ()
15070 "Expand all design units in current directory/project."
15071 (interactive)
15072 (let* ((key (vhdl-speedbar-line-key))
15073 (ent-alist (vhdl-aget vhdl-entity-alist key))
15074 (conf-alist (vhdl-aget vhdl-config-alist key))
15075 (pack-alist (vhdl-aget vhdl-package-alist key))
15076 arch-alist unit-alist subunit-alist)
15077 (add-to-list 'vhdl-speedbar-shown-project-list key)
15078 (while ent-alist
15079 (setq arch-alist (nth 4 (car ent-alist)))
15080 (setq subunit-alist nil)
15081 (while arch-alist
15082 (push (caar arch-alist) subunit-alist)
15083 (setq arch-alist (cdr arch-alist)))
15084 (push (list (caar ent-alist) subunit-alist) unit-alist)
15085 (setq ent-alist (cdr ent-alist)))
15086 (while conf-alist
15087 (push (list (caar conf-alist)) unit-alist)
15088 (setq conf-alist (cdr conf-alist)))
15089 (while pack-alist
15090 (push (list (caar pack-alist)) unit-alist)
15091 (setq pack-alist (cdr pack-alist)))
15092 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15093 (vhdl-speedbar-refresh)
15094 (when (memq 'display vhdl-speedbar-save-cache)
15095 (add-to-list 'vhdl-updated-project-list key))))
15096
15097 (declare-function speedbar-change-expand-button-char "speedbar" (char))
15098 (declare-function speedbar-delete-subblock "speedbar" (indent))
15099
15100 (defun vhdl-speedbar-expand-project (text token indent)
15101 "Expand/contract the project under the cursor."
15102 (cond
15103 ((string-match "+" text) ; expand project
15104 (speedbar-change-expand-button-char ?-)
15105 (unless (member token vhdl-speedbar-shown-project-list)
15106 (setq vhdl-speedbar-shown-project-list
15107 (cons token vhdl-speedbar-shown-project-list)))
15108 (speedbar-with-writable
15109 (save-excursion
15110 (end-of-line) (forward-char 1)
15111 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
15112 speedbar-power-click))))
15113 ((string-match "-" text) ; contract project
15114 (speedbar-change-expand-button-char ?+)
15115 (setq vhdl-speedbar-shown-project-list
15116 (delete token vhdl-speedbar-shown-project-list))
15117 (speedbar-delete-subblock indent))
15118 (t (error "Nothing to display")))
15119 (when (equal (selected-frame) speedbar-frame)
15120 (speedbar-center-buffer-smartly)))
15121
15122 (defun vhdl-speedbar-expand-entity (text token indent)
15123 "Expand/contract the entity under the cursor."
15124 (cond
15125 ((string-match "+" text) ; expand entity
15126 (let* ((key (vhdl-speedbar-line-key indent))
15127 (ent-alist (vhdl-aget vhdl-entity-alist key))
15128 (ent-entry (vhdl-aget ent-alist token))
15129 (arch-alist (nth 3 ent-entry))
15130 (inst-alist (vhdl-get-instantiations token indent))
15131 (subpack-alist (nth 5 ent-entry))
15132 (multiple-arch (> (length arch-alist) 1))
15133 arch-entry inst-entry)
15134 (if (not (or arch-alist inst-alist subpack-alist))
15135 (speedbar-change-expand-button-char ??)
15136 (speedbar-change-expand-button-char ?-)
15137 ;; add entity to `vhdl-speedbar-shown-unit-alist'
15138 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15139 (vhdl-aput 'unit-alist token nil)
15140 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15141 (speedbar-with-writable
15142 (save-excursion
15143 (end-of-line) (forward-char 1)
15144 ;; insert architectures
15145 (when arch-alist
15146 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15147 (while arch-alist
15148 (setq arch-entry (car arch-alist))
15149 (speedbar-make-tag-line
15150 'curly ?+ 'vhdl-speedbar-expand-architecture
15151 (cons token (nth 0 arch-entry))
15152 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15153 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15154 'vhdl-speedbar-architecture-face (1+ indent))
15155 (when (and multiple-arch
15156 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15157 (end-of-line 0) (insert " (mra)") (forward-char 1))
15158 (setq arch-alist (cdr arch-alist)))
15159 ;; insert instantiations
15160 (when inst-alist
15161 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15162 (while inst-alist
15163 (setq inst-entry (car inst-alist))
15164 (vhdl-speedbar-make-inst-line
15165 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15166 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15167 nil nil nil (1+ indent) 0 " in ")
15168 (setq inst-alist (cdr inst-alist)))
15169 ;; insert required packages
15170 (vhdl-speedbar-insert-subpackages
15171 subpack-alist (1+ indent) indent)))
15172 (when (memq 'display vhdl-speedbar-save-cache)
15173 (add-to-list 'vhdl-updated-project-list key))
15174 (vhdl-speedbar-update-current-unit t t))))
15175 ((string-match "-" text) ; contract entity
15176 (speedbar-change-expand-button-char ?+)
15177 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15178 (let* ((key (vhdl-speedbar-line-key indent))
15179 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15180 (vhdl-adelete 'unit-alist token)
15181 (if unit-alist
15182 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15183 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15184 (speedbar-delete-subblock indent)
15185 (when (memq 'display vhdl-speedbar-save-cache)
15186 (add-to-list 'vhdl-updated-project-list key))))
15187 (t (error "Nothing to display")))
15188 (when (equal (selected-frame) speedbar-frame)
15189 (speedbar-center-buffer-smartly)))
15190
15191 (defun vhdl-speedbar-expand-architecture (text token indent)
15192 "Expand/contract the architecture under the cursor."
15193 (cond
15194 ((string-match "+" text) ; expand architecture
15195 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15196 (ent-alist (vhdl-aget vhdl-entity-alist key))
15197 (conf-alist (vhdl-aget vhdl-config-alist key))
15198 (hier-alist (vhdl-get-hierarchy
15199 ent-alist conf-alist (car token) (cdr token) nil nil
15200 0 (1- indent)))
15201 (ent-entry (vhdl-aget ent-alist (car token)))
15202 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15203 (subpack-alist (nth 4 arch-entry))
15204 entry)
15205 (if (not (or hier-alist subpack-alist))
15206 (speedbar-change-expand-button-char ??)
15207 (speedbar-change-expand-button-char ?-)
15208 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15209 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15210 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15211 (vhdl-aput 'unit-alist (car token)
15212 (list (cons (cdr token) arch-alist)))
15213 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15214 (speedbar-with-writable
15215 (save-excursion
15216 (end-of-line) (forward-char 1)
15217 ;; insert instance hierarchy
15218 (when hier-alist
15219 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15220 (1+ indent)))
15221 (while hier-alist
15222 (setq entry (car hier-alist))
15223 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15224 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15225 (vhdl-speedbar-make-inst-line
15226 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15227 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15228 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15229 (setq hier-alist (cdr hier-alist)))
15230 ;; insert required packages
15231 (vhdl-speedbar-insert-subpackages
15232 subpack-alist (1+ indent) (1- indent))))
15233 (when (memq 'display vhdl-speedbar-save-cache)
15234 (add-to-list 'vhdl-updated-project-list key))
15235 (vhdl-speedbar-update-current-unit t t))))
15236 ((string-match "-" text) ; contract architecture
15237 (speedbar-change-expand-button-char ?+)
15238 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15239 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15240 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15241 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15242 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15243 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15244 (speedbar-delete-subblock indent)
15245 (when (memq 'display vhdl-speedbar-save-cache)
15246 (add-to-list 'vhdl-updated-project-list key))))
15247 (t (error "Nothing to display")))
15248 (when (equal (selected-frame) speedbar-frame)
15249 (speedbar-center-buffer-smartly)))
15250
15251 (defun vhdl-speedbar-expand-config (text token indent)
15252 "Expand/contract the configuration under the cursor."
15253 (cond
15254 ((string-match "+" text) ; expand configuration
15255 (let* ((key (vhdl-speedbar-line-key indent))
15256 (conf-alist (vhdl-aget vhdl-config-alist key))
15257 (conf-entry (vhdl-aget conf-alist token))
15258 (ent-alist (vhdl-aget vhdl-entity-alist key))
15259 (hier-alist (vhdl-get-hierarchy
15260 ent-alist conf-alist (nth 3 conf-entry)
15261 (nth 4 conf-entry) token (nth 5 conf-entry)
15262 0 indent t))
15263 (subpack-alist (nth 6 conf-entry))
15264 entry)
15265 (if (not (or hier-alist subpack-alist))
15266 (speedbar-change-expand-button-char ??)
15267 (speedbar-change-expand-button-char ?-)
15268 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15269 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15270 (vhdl-aput 'unit-alist token nil)
15271 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15272 (speedbar-with-writable
15273 (save-excursion
15274 (end-of-line) (forward-char 1)
15275 ;; insert instance hierarchy
15276 (when hier-alist
15277 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15278 (while hier-alist
15279 (setq entry (car hier-alist))
15280 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15281 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15282 (vhdl-speedbar-make-inst-line
15283 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15284 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15285 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15286 (setq hier-alist (cdr hier-alist)))
15287 ;; insert required packages
15288 (vhdl-speedbar-insert-subpackages
15289 subpack-alist (1+ indent) indent)))
15290 (when (memq 'display vhdl-speedbar-save-cache)
15291 (add-to-list 'vhdl-updated-project-list key))
15292 (vhdl-speedbar-update-current-unit t t))))
15293 ((string-match "-" text) ; contract configuration
15294 (speedbar-change-expand-button-char ?+)
15295 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15296 (let* ((key (vhdl-speedbar-line-key indent))
15297 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15298 (vhdl-adelete 'unit-alist token)
15299 (if unit-alist
15300 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15301 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15302 (speedbar-delete-subblock indent)
15303 (when (memq 'display vhdl-speedbar-save-cache)
15304 (add-to-list 'vhdl-updated-project-list key))))
15305 (t (error "Nothing to display")))
15306 (when (equal (selected-frame) speedbar-frame)
15307 (speedbar-center-buffer-smartly)))
15308
15309 (defun vhdl-speedbar-expand-package (text token indent)
15310 "Expand/contract the package under the cursor."
15311 (cond
15312 ((string-match "+" text) ; expand package
15313 (let* ((key (vhdl-speedbar-line-key indent))
15314 (pack-alist (vhdl-aget vhdl-package-alist key))
15315 (pack-entry (vhdl-aget pack-alist token))
15316 (comp-alist (nth 3 pack-entry))
15317 (func-alist (nth 4 pack-entry))
15318 (func-body-alist (nth 8 pack-entry))
15319 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15320 comp-entry func-entry func-body-entry)
15321 (if (not (or comp-alist func-alist subpack-alist))
15322 (speedbar-change-expand-button-char ??)
15323 (speedbar-change-expand-button-char ?-)
15324 ;; add package to `vhdl-speedbar-shown-unit-alist'
15325 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15326 (vhdl-aput 'unit-alist token nil)
15327 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15328 (speedbar-with-writable
15329 (save-excursion
15330 (end-of-line) (forward-char 1)
15331 ;; insert components
15332 (when comp-alist
15333 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15334 (while comp-alist
15335 (setq comp-entry (car comp-alist))
15336 (speedbar-make-tag-line
15337 nil nil nil
15338 (cons token (nth 0 comp-entry))
15339 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15340 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15341 'vhdl-speedbar-entity-face (1+ indent))
15342 (setq comp-alist (cdr comp-alist)))
15343 ;; insert subprograms
15344 (when func-alist
15345 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15346 (while func-alist
15347 (setq func-entry (car func-alist)
15348 func-body-entry (vhdl-aget func-body-alist
15349 (car func-entry)))
15350 (when (nth 2 func-entry)
15351 (vhdl-speedbar-make-subprogram-line
15352 (nth 1 func-entry)
15353 (cons (nth 2 func-entry) (nth 3 func-entry))
15354 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15355 (1+ indent)))
15356 (setq func-alist (cdr func-alist)))
15357 ;; insert required packages
15358 (vhdl-speedbar-insert-subpackages
15359 subpack-alist (1+ indent) indent)))
15360 (when (memq 'display vhdl-speedbar-save-cache)
15361 (add-to-list 'vhdl-updated-project-list key))
15362 (vhdl-speedbar-update-current-unit t t))))
15363 ((string-match "-" text) ; contract package
15364 (speedbar-change-expand-button-char ?+)
15365 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15366 (let* ((key (vhdl-speedbar-line-key indent))
15367 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15368 (vhdl-adelete 'unit-alist token)
15369 (if unit-alist
15370 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15371 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15372 (speedbar-delete-subblock indent)
15373 (when (memq 'display vhdl-speedbar-save-cache)
15374 (add-to-list 'vhdl-updated-project-list key))))
15375 (t (error "Nothing to display")))
15376 (when (equal (selected-frame) speedbar-frame)
15377 (speedbar-center-buffer-smartly)))
15378
15379 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15380 "Insert required packages."
15381 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15382 (vhdl-speedbar-line-key dir-indent)))
15383 pack-key lib-name pack-entry)
15384 (when subpack-alist
15385 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15386 (while subpack-alist
15387 (setq pack-key (cdar subpack-alist)
15388 lib-name (caar subpack-alist))
15389 (setq pack-entry (vhdl-aget pack-alist pack-key))
15390 (vhdl-speedbar-make-subpack-line
15391 (or (nth 0 pack-entry) pack-key) lib-name
15392 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15393 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15394 (setq subpack-alist (cdr subpack-alist)))))
15395
15396 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15397 ;; Display help functions
15398
15399 (defvar vhdl-speedbar-update-current-unit t
15400 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15401
15402 (defun vhdl-speedbar-update-current-project ()
15403 "Highlight project that is currently active."
15404 (when (and vhdl-speedbar-show-projects
15405 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15406 (and (boundp 'speedbar-frame)
15407 (frame-live-p speedbar-frame)))
15408 (let ((last-frame (selected-frame))
15409 (project-alist vhdl-project-alist)
15410 pos)
15411 (select-frame speedbar-frame)
15412 (speedbar-with-writable
15413 (save-excursion
15414 (while project-alist
15415 (goto-char (point-min))
15416 (when (re-search-forward
15417 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15418 (put-text-property (match-beginning 1) (match-end 1) 'face
15419 (if (equal (caar project-alist) vhdl-project)
15420 'speedbar-selected-face
15421 'speedbar-directory-face))
15422 (when (equal (caar project-alist) vhdl-project)
15423 (setq pos (1- (match-beginning 1)))))
15424 (setq project-alist (cdr project-alist))))
15425 (when pos (goto-char pos)))
15426 (select-frame last-frame)
15427 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15428 t)
15429
15430 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15431
15432 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15433 "Highlight all design units that are contained in the current file.
15434 NO-POSITION non-nil means do not re-position cursor."
15435 (let ((last-frame (selected-frame))
15436 (project-list vhdl-speedbar-shown-project-list)
15437 file-alist pos file-name)
15438 ;; get current file name
15439 (if (fboundp 'speedbar-select-attached-frame)
15440 (speedbar-select-attached-frame)
15441 (select-frame speedbar-attached-frame))
15442 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15443 (when (and vhdl-speedbar-update-current-unit
15444 (or always (not (equal file-name speedbar-last-selected-file))))
15445 (if vhdl-speedbar-show-projects
15446 (while project-list
15447 (setq file-alist (append file-alist
15448 (vhdl-aget vhdl-file-alist
15449 (car project-list))))
15450 (setq project-list (cdr project-list)))
15451 (setq file-alist
15452 (vhdl-aget vhdl-file-alist
15453 (abbreviate-file-name default-directory))))
15454 (select-frame speedbar-frame)
15455 (set-buffer speedbar-buffer)
15456 (speedbar-with-writable
15457 (vhdl-prepare-search-1
15458 (save-excursion
15459 ;; unhighlight last units
15460 (let* ((file-entry (vhdl-aget file-alist
15461 speedbar-last-selected-file)))
15462 (vhdl-speedbar-update-units
15463 "\\[.\\] " (nth 0 file-entry)
15464 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15465 (vhdl-speedbar-update-units
15466 "{.} " (nth 1 file-entry)
15467 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15468 (vhdl-speedbar-update-units
15469 "\\[.\\] " (nth 3 file-entry)
15470 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15471 (vhdl-speedbar-update-units
15472 "[]>] " (nth 4 file-entry)
15473 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15474 (vhdl-speedbar-update-units
15475 "\\[.\\].+(" '("body")
15476 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15477 (vhdl-speedbar-update-units
15478 "> " (nth 6 file-entry)
15479 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15480 ;; highlight current units
15481 (let* ((file-entry (vhdl-aget file-alist file-name)))
15482 (setq
15483 pos (vhdl-speedbar-update-units
15484 "\\[.\\] " (nth 0 file-entry)
15485 file-name 'vhdl-speedbar-entity-selected-face pos)
15486 pos (vhdl-speedbar-update-units
15487 "{.} " (nth 1 file-entry)
15488 file-name 'vhdl-speedbar-architecture-selected-face pos)
15489 pos (vhdl-speedbar-update-units
15490 "\\[.\\] " (nth 3 file-entry)
15491 file-name 'vhdl-speedbar-configuration-selected-face pos)
15492 pos (vhdl-speedbar-update-units
15493 "[]>] " (nth 4 file-entry)
15494 file-name 'vhdl-speedbar-package-selected-face pos)
15495 pos (vhdl-speedbar-update-units
15496 "\\[.\\].+(" '("body")
15497 file-name 'vhdl-speedbar-package-selected-face pos)
15498 pos (vhdl-speedbar-update-units
15499 "> " (nth 6 file-entry)
15500 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15501 ;; move speedbar so the first highlighted unit is visible
15502 (when (and pos (not no-position))
15503 (goto-char pos)
15504 (speedbar-center-buffer-smartly)
15505 (speedbar-position-cursor-on-line))
15506 (setq speedbar-last-selected-file file-name))
15507 (select-frame last-frame)
15508 t))
15509
15510 (defun vhdl-speedbar-update-units (text unit-list file-name face
15511 &optional pos)
15512 "Help function to highlight design units."
15513 (while unit-list
15514 (goto-char (point-min))
15515 (while (re-search-forward
15516 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15517 (when (equal file-name (car (get-text-property
15518 (match-beginning 1) 'speedbar-token)))
15519 (setq pos (or pos (point-marker)))
15520 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15521 (setq unit-list (cdr unit-list)))
15522 pos)
15523
15524 (declare-function speedbar-make-button "speedbar"
15525 (start end face mouse function &optional token))
15526
15527 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15528 ent-name ent-file-marker
15529 arch-name arch-file-marker
15530 conf-name conf-file-marker
15531 lib-name depth offset delimiter)
15532 "Insert instantiation entry."
15533 (let ((start (point))
15534 visible-start)
15535 (insert (int-to-string depth) ":")
15536 (put-text-property start (point) 'invisible t)
15537 (setq visible-start (point))
15538 (insert-char ? (* depth speedbar-indentation-width))
15539 (while (> offset 0)
15540 (insert "|")
15541 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15542 (setq offset (1- offset)))
15543 (put-text-property visible-start (point) 'invisible nil)
15544 (setq start (point))
15545 (insert ">")
15546 (speedbar-make-button start (point) nil nil nil)
15547 (setq visible-start (point))
15548 (insert " ")
15549 (setq start (point))
15550 (if (not inst-name)
15551 (insert "(top)")
15552 (insert inst-name)
15553 (speedbar-make-button
15554 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15555 'vhdl-speedbar-find-file inst-file-marker))
15556 (insert delimiter)
15557 (when ent-name
15558 (setq start (point))
15559 (insert ent-name)
15560 (speedbar-make-button
15561 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15562 'vhdl-speedbar-find-file ent-file-marker)
15563 (when arch-name
15564 (insert " (")
15565 (setq start (point))
15566 (insert arch-name)
15567 (speedbar-make-button
15568 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15569 'vhdl-speedbar-find-file arch-file-marker)
15570 (insert ")"))
15571 (when conf-name
15572 (insert " (")
15573 (setq start (point))
15574 (insert conf-name)
15575 (speedbar-make-button
15576 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15577 'vhdl-speedbar-find-file conf-file-marker)
15578 (insert ")")))
15579 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15580 (setq start (point))
15581 (insert " (" lib-name ")")
15582 (put-text-property (+ 2 start) (1- (point)) 'face
15583 'vhdl-speedbar-library-face))
15584 (insert-char ?\n 1)
15585 (put-text-property visible-start (point) 'invisible nil)))
15586
15587 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15588 body-file-marker depth)
15589 "Insert package entry."
15590 (let ((start (point))
15591 visible-start)
15592 (insert (int-to-string depth) ":")
15593 (put-text-property start (point) 'invisible t)
15594 (setq visible-start (point))
15595 (insert-char ? (* depth speedbar-indentation-width))
15596 (put-text-property visible-start (point) 'invisible nil)
15597 (setq start (point))
15598 (insert "[+]")
15599 (speedbar-make-button
15600 start (point) 'speedbar-button-face 'speedbar-highlight-face
15601 'vhdl-speedbar-expand-package pack-key)
15602 (setq visible-start (point))
15603 (insert-char ? 1 nil)
15604 (setq start (point))
15605 (insert pack-name)
15606 (speedbar-make-button
15607 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15608 'vhdl-speedbar-find-file pack-file-marker)
15609 (unless (car pack-file-marker)
15610 (insert "!"))
15611 (when (car body-file-marker)
15612 (insert " (")
15613 (setq start (point))
15614 (insert "body")
15615 (speedbar-make-button
15616 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15617 'vhdl-speedbar-find-file body-file-marker)
15618 (insert ")"))
15619 (insert-char ?\n 1)
15620 (put-text-property visible-start (point) 'invisible nil)))
15621
15622 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15623 pack-body-file-marker depth)
15624 "Insert used package entry."
15625 (let ((start (point))
15626 visible-start)
15627 (insert (int-to-string depth) ":")
15628 (put-text-property start (point) 'invisible t)
15629 (setq visible-start (point))
15630 (insert-char ? (* depth speedbar-indentation-width))
15631 (put-text-property visible-start (point) 'invisible nil)
15632 (setq start (point))
15633 (insert ">")
15634 (speedbar-make-button start (point) nil nil nil)
15635 (setq visible-start (point))
15636 (insert " ")
15637 (setq start (point))
15638 (insert pack-name)
15639 (speedbar-make-button
15640 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15641 'vhdl-speedbar-find-file pack-file-marker)
15642 (when (car pack-body-file-marker)
15643 (insert " (")
15644 (setq start (point))
15645 (insert "body")
15646 (speedbar-make-button
15647 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15648 'vhdl-speedbar-find-file pack-body-file-marker)
15649 (insert ")"))
15650 (setq start (point))
15651 (insert " (" lib-name ")")
15652 (put-text-property (+ 2 start) (1- (point)) 'face
15653 'vhdl-speedbar-library-face)
15654 (insert-char ?\n 1)
15655 (put-text-property visible-start (point) 'invisible nil)))
15656
15657 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15658 func-body-file-marker
15659 depth)
15660 "Insert subprogram entry."
15661 (let ((start (point))
15662 visible-start)
15663 (insert (int-to-string depth) ":")
15664 (put-text-property start (point) 'invisible t)
15665 (setq visible-start (point))
15666 (insert-char ? (* depth speedbar-indentation-width))
15667 (put-text-property visible-start (point) 'invisible nil)
15668 (setq start (point))
15669 (insert ">")
15670 (speedbar-make-button start (point) nil nil nil)
15671 (setq visible-start (point))
15672 (insert " ")
15673 (setq start (point))
15674 (insert func-name)
15675 (speedbar-make-button
15676 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15677 'vhdl-speedbar-find-file func-file-marker)
15678 (when (car func-body-file-marker)
15679 (insert " (")
15680 (setq start (point))
15681 (insert "body")
15682 (speedbar-make-button
15683 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15684 'vhdl-speedbar-find-file func-body-file-marker)
15685 (insert ")"))
15686 (insert-char ?\n 1)
15687 (put-text-property visible-start (point) 'invisible nil)))
15688
15689 (defun vhdl-speedbar-make-title-line (text &optional depth)
15690 "Insert design unit title entry."
15691 (let ((start (point))
15692 visible-start)
15693 (when depth
15694 (insert (int-to-string depth) ":")
15695 (put-text-property start (point) 'invisible t))
15696 (setq visible-start (point))
15697 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15698 (setq start (point))
15699 (insert text)
15700 (speedbar-make-button start (point) nil nil nil nil)
15701 (insert-char ?\n 1)
15702 (put-text-property visible-start (point) 'invisible nil)))
15703
15704 (defun vhdl-speedbar-insert-dirs (files level)
15705 "Insert subdirectories."
15706 (let ((dirs (car files)))
15707 (while dirs
15708 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15709 (car dirs) 'speedbar-dir-follow nil
15710 'speedbar-directory-face level)
15711 (setq dirs (cdr dirs)))))
15712
15713 (declare-function speedbar-reset-scanners "speedbar" ())
15714
15715 (defun vhdl-speedbar-dired (text token indent)
15716 "Speedbar click handler for directory expand button in hierarchy mode."
15717 (cond ((string-match "+" text) ; we have to expand this dir
15718 (setq speedbar-shown-directories
15719 (cons (expand-file-name
15720 (concat (speedbar-line-directory indent) token "/"))
15721 speedbar-shown-directories))
15722 (speedbar-change-expand-button-char ?-)
15723 (speedbar-reset-scanners)
15724 (speedbar-with-writable
15725 (save-excursion
15726 (end-of-line) (forward-char 1)
15727 (vhdl-speedbar-insert-dirs
15728 (speedbar-file-lists
15729 (concat (speedbar-line-directory indent) token "/"))
15730 (1+ indent))
15731 (speedbar-reset-scanners)
15732 (vhdl-speedbar-insert-dir-hierarchy
15733 (abbreviate-file-name
15734 (concat (speedbar-line-directory indent) token "/"))
15735 (1+ indent) speedbar-power-click)))
15736 (vhdl-speedbar-update-current-unit t t))
15737 ((string-match "-" text) ; we have to contract this node
15738 (speedbar-reset-scanners)
15739 (let ((oldl speedbar-shown-directories)
15740 (newl nil)
15741 (td (expand-file-name
15742 (concat (speedbar-line-directory indent) token))))
15743 (while oldl
15744 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15745 (push (car oldl) newl))
15746 (setq oldl (cdr oldl)))
15747 (setq speedbar-shown-directories (nreverse newl)))
15748 (speedbar-change-expand-button-char ?+)
15749 (speedbar-delete-subblock indent))
15750 (t (error "Nothing to display")))
15751 (when (equal (selected-frame) speedbar-frame)
15752 (speedbar-center-buffer-smartly)))
15753
15754 (declare-function speedbar-files-item-info "speedbar" ())
15755
15756 (defun vhdl-speedbar-item-info ()
15757 "Derive and display information about this line item."
15758 (save-excursion
15759 (beginning-of-line)
15760 ;; skip invisible number info
15761 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15762 (cond
15763 ;; project/directory entry
15764 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15765 (if vhdl-speedbar-show-projects
15766 (message "Project \"%s\"" (match-string-no-properties 1))
15767 (speedbar-files-item-info)))
15768 ;; design unit entry
15769 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15770 (goto-char (match-end 1))
15771 (let ((face (get-text-property (point) 'face)))
15772 (message
15773 "%s \"%s\" in \"%s\""
15774 ;; design unit kind
15775 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15776 (eq face 'vhdl-speedbar-entity-selected-face))
15777 (if (equal (match-string 2) ">") "Component" "Entity"))
15778 ((or (eq face 'vhdl-speedbar-architecture-face)
15779 (eq face 'vhdl-speedbar-architecture-selected-face))
15780 "Architecture")
15781 ((or (eq face 'vhdl-speedbar-configuration-face)
15782 (eq face 'vhdl-speedbar-configuration-selected-face))
15783 "Configuration")
15784 ((or (eq face 'vhdl-speedbar-package-face)
15785 (eq face 'vhdl-speedbar-package-selected-face))
15786 "Package")
15787 ((or (eq face 'vhdl-speedbar-instantiation-face)
15788 (eq face 'vhdl-speedbar-instantiation-selected-face))
15789 "Instantiation")
15790 ((eq face 'vhdl-speedbar-subprogram-face)
15791 "Subprogram")
15792 (t ""))
15793 ;; design unit name
15794 (buffer-substring-no-properties
15795 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15796 (match-end 1))
15797 ;; file name
15798 (file-relative-name
15799 (or (car (get-text-property (point) 'speedbar-token))
15800 "?")
15801 (vhdl-default-directory)))))
15802 (t (message "")))))
15803
15804 (declare-function speedbar-line-text "speedbar" (&optional p))
15805
15806 (defun vhdl-speedbar-line-text ()
15807 "Calls `speedbar-line-text' and removes text properties."
15808 (let ((string (speedbar-line-text)))
15809 (set-text-properties 0 (length string) nil string)
15810 string))
15811
15812 (defun vhdl-speedbar-higher-text ()
15813 "Get speedbar-line-text of higher level."
15814 (let (depth string)
15815 (save-excursion
15816 (beginning-of-line)
15817 (looking-at "^\\([0-9]+\\):")
15818 (setq depth (string-to-number (match-string 1)))
15819 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15820 (setq string (match-string 1))
15821 (set-text-properties 0 (length string) nil string)
15822 string))))
15823
15824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15825 ;; Help functions
15826
15827 (defun vhdl-speedbar-line-key (&optional indent)
15828 "Get currently displayed directory of project name."
15829 (if vhdl-speedbar-show-projects
15830 (vhdl-speedbar-line-project)
15831 (abbreviate-file-name
15832 (file-name-as-directory (speedbar-line-directory indent)))))
15833
15834 (defun vhdl-speedbar-line-project (&optional indent)
15835 "Get currently displayed project name."
15836 (and vhdl-speedbar-show-projects
15837 (save-excursion
15838 (end-of-line)
15839 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15840 (match-string-no-properties 1))))
15841
15842 (defun vhdl-add-modified-file ()
15843 "Add file to `vhdl-modified-file-list'."
15844 (when vhdl-file-alist
15845 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15846 nil)
15847
15848 (defun vhdl-resolve-paths (path-list)
15849 "Resolve path wildcards in PATH-LIST."
15850 (let (path-list-1 path-list-2 path-beg path-end dir)
15851 ;; eliminate non-existent directories
15852 (while path-list
15853 (setq dir (car path-list))
15854 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15855 (if (file-directory-p (match-string 2 dir))
15856 (push dir path-list-1)
15857 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15858 (setq path-list (cdr path-list)))
15859 ;; resolve path wildcards
15860 (while path-list-1
15861 (setq dir (car path-list-1))
15862 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15863 (progn
15864 (setq path-beg (match-string 1 dir)
15865 path-end (match-string 5 dir))
15866 (setq path-list-1
15867 (append
15868 (mapcar
15869 (function
15870 (lambda (var) (concat path-beg var path-end)))
15871 (let ((all-list (vhdl-directory-files
15872 (match-string 2 dir) t
15873 (concat "\\<" (wildcard-to-regexp
15874 (match-string 4 dir)))))
15875 dir-list)
15876 (while all-list
15877 (when (file-directory-p (car all-list))
15878 (push (car all-list) dir-list))
15879 (setq all-list (cdr all-list)))
15880 dir-list))
15881 (cdr path-list-1))))
15882 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15883 (when (file-directory-p (match-string 2 dir))
15884 (push dir path-list-2))
15885 (setq path-list-1 (cdr path-list-1))))
15886 (nreverse path-list-2)))
15887
15888 (defun vhdl-speedbar-goto-this-unit (directory unit)
15889 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15890 (let ((dest (point)))
15891 (if (and (if vhdl-speedbar-show-projects
15892 (progn (goto-char (point-min)) t)
15893 (speedbar-goto-this-file directory))
15894 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15895 (progn (speedbar-position-cursor-on-line)
15896 t)
15897 (goto-char dest)
15898 nil)))
15899
15900 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15901 (declare-function speedbar-set-timer "speedbar" (timeout))
15902 ;; speedbar loads dframe at runtime.
15903 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15904
15905 (defun vhdl-speedbar-find-file (text token indent)
15906 "When user clicks on TEXT, load file with name and position in TOKEN.
15907 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15908 is already shown in a buffer."
15909 (if (not (car token))
15910 (error "ERROR: File cannot be found")
15911 (let ((buffer (get-file-buffer (car token))))
15912 (speedbar-find-file-in-frame (car token))
15913 (when (or vhdl-speedbar-jump-to-unit buffer)
15914 (goto-char (point-min))
15915 (forward-line (1- (cdr token)))
15916 (recenter))
15917 (vhdl-speedbar-update-current-unit t t)
15918 (speedbar-set-timer dframe-update-speed)
15919 (dframe-maybee-jump-to-attached-frame))))
15920
15921 (defun vhdl-speedbar-port-copy ()
15922 "Copy the port of the entity/component or subprogram under the cursor."
15923 (interactive)
15924 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15925 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15926 (error "ERROR: No entity/component or subprogram under cursor")
15927 (beginning-of-line)
15928 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15929 (condition-case info
15930 (let ((token (get-text-property
15931 (match-beginning 3) 'speedbar-token)))
15932 (vhdl-visit-file (car token) t
15933 (progn (goto-char (point-min))
15934 (forward-line (1- (cdr token)))
15935 (end-of-line)
15936 (if is-entity
15937 (vhdl-port-copy)
15938 (vhdl-subprog-copy)))))
15939 (error (error "ERROR: %s not scanned successfully\n (%s)"
15940 (if is-entity "Port" "Interface") (cadr info))))
15941 (error "ERROR: No entity/component or subprogram on current line")))))
15942
15943 (defun vhdl-speedbar-place-component ()
15944 "Place the entity/component under the cursor as component."
15945 (interactive)
15946 (if (not (vhdl-speedbar-check-unit 'entity))
15947 (error "ERROR: No entity/component under cursor")
15948 (vhdl-speedbar-port-copy)
15949 (if (fboundp 'speedbar-select-attached-frame)
15950 (speedbar-select-attached-frame)
15951 (select-frame speedbar-attached-frame))
15952 (vhdl-compose-place-component)
15953 (select-frame speedbar-frame)))
15954
15955 (defun vhdl-speedbar-configuration ()
15956 "Generate configuration for the architecture under the cursor."
15957 (interactive)
15958 (if (not (vhdl-speedbar-check-unit 'architecture))
15959 (error "ERROR: No architecture under cursor")
15960 (let ((arch-name (vhdl-speedbar-line-text))
15961 (ent-name (vhdl-speedbar-higher-text)))
15962 (if (fboundp 'speedbar-select-attached-frame)
15963 (speedbar-select-attached-frame)
15964 (select-frame speedbar-attached-frame))
15965 (vhdl-compose-configuration ent-name arch-name))))
15966
15967 (defun vhdl-speedbar-select-mra ()
15968 "Select the architecture under the cursor as MRA."
15969 (interactive)
15970 (if (not (vhdl-speedbar-check-unit 'architecture))
15971 (error "ERROR: No architecture under cursor")
15972 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15973 (ent-key (downcase (vhdl-speedbar-higher-text)))
15974 (ent-alist (vhdl-aget
15975 vhdl-entity-alist
15976 (or (vhdl-project-p)
15977 (abbreviate-file-name default-directory))))
15978 (ent-entry (vhdl-aget ent-alist ent-key)))
15979 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15980 (speedbar-refresh))))
15981
15982 (declare-function speedbar-line-file "speedbar" (&optional p))
15983
15984 (defun vhdl-speedbar-make-design ()
15985 "Make (compile) design unit or directory/project under the cursor."
15986 (interactive)
15987 (if (not (save-excursion (beginning-of-line)
15988 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15989 (error "ERROR: No primary design unit or directory/project under cursor")
15990 (let ((is-unit (match-string 2))
15991 (unit-name (vhdl-speedbar-line-text))
15992 (vhdl-project (vhdl-speedbar-line-project))
15993 (directory (file-name-as-directory
15994 (or (speedbar-line-file) (speedbar-line-directory)))))
15995 (if (fboundp 'speedbar-select-attached-frame)
15996 (speedbar-select-attached-frame)
15997 (select-frame speedbar-attached-frame))
15998 (let ((default-directory directory))
15999 (vhdl-make (and is-unit unit-name))))))
16000
16001 (defun vhdl-speedbar-generate-makefile ()
16002 "Generate Makefile for directory/project under the cursor."
16003 (interactive)
16004 (let ((vhdl-project (vhdl-speedbar-line-project))
16005 (default-directory (file-name-as-directory
16006 (or (speedbar-line-file) (speedbar-line-directory)))))
16007 (vhdl-generate-makefile)))
16008
16009 (defun vhdl-speedbar-check-unit (design-unit)
16010 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
16011 expansion function)."
16012 (save-excursion
16013 (speedbar-position-cursor-on-line)
16014 (cond ((eq design-unit 'entity)
16015 (memq (get-text-property (match-end 0) 'face)
16016 '(vhdl-speedbar-entity-face
16017 vhdl-speedbar-entity-selected-face)))
16018 ((eq design-unit 'architecture)
16019 (memq (get-text-property (match-end 0) 'face)
16020 '(vhdl-speedbar-architecture-face
16021 vhdl-speedbar-architecture-selected-face)))
16022 ((eq design-unit 'subprogram)
16023 (eq (get-text-property (match-end 0) 'face)
16024 'vhdl-speedbar-subprogram-face))
16025 (t nil))))
16026
16027 (defun vhdl-speedbar-set-depth (depth)
16028 "Set hierarchy display depth to DEPTH and refresh speedbar."
16029 (setq vhdl-speedbar-hierarchy-depth depth)
16030 (speedbar-refresh))
16031
16032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16033 ;; Fontification
16034
16035 (defface vhdl-speedbar-entity-face
16036 '((((class color) (background light)) (:foreground "ForestGreen"))
16037 (((class color) (background dark)) (:foreground "PaleGreen")))
16038 "Face used for displaying entity names."
16039 :group 'speedbar-faces)
16040
16041 (defface vhdl-speedbar-architecture-face
16042 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
16043 (((class color) (background light)) (:foreground "Blue"))
16044
16045 (((class color) (background dark)) (:foreground "LightSkyBlue")))
16046 "Face used for displaying architecture names."
16047 :group 'speedbar-faces)
16048
16049 (defface vhdl-speedbar-configuration-face
16050 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
16051 (((class color) (background dark)) (:foreground "Salmon")))
16052 "Face used for displaying configuration names."
16053 :group 'speedbar-faces)
16054
16055 (defface vhdl-speedbar-package-face
16056 '((((class color) (background light)) (:foreground "Grey50"))
16057 (((class color) (background dark)) (:foreground "Grey80")))
16058 "Face used for displaying package names."
16059 :group 'speedbar-faces)
16060
16061 (defface vhdl-speedbar-library-face
16062 '((((class color) (background light)) (:foreground "Purple"))
16063 (((class color) (background dark)) (:foreground "Orchid1")))
16064 "Face used for displaying library names."
16065 :group 'speedbar-faces)
16066
16067 (defface vhdl-speedbar-instantiation-face
16068 '((((class color) (background light)) (:foreground "Brown"))
16069 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
16070 (((class color) (background dark)) (:foreground "Yellow")))
16071 "Face used for displaying instantiation names."
16072 :group 'speedbar-faces)
16073
16074 (defface vhdl-speedbar-subprogram-face
16075 '((((class color) (background light)) (:foreground "Orchid4"))
16076 (((class color) (background dark)) (:foreground "BurlyWood2")))
16077 "Face used for displaying subprogram names."
16078 :group 'speedbar-faces)
16079
16080 (defface vhdl-speedbar-entity-selected-face
16081 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
16082 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
16083 "Face used for displaying entity names."
16084 :group 'speedbar-faces)
16085
16086 (defface vhdl-speedbar-architecture-selected-face
16087 '((((min-colors 88) (class color) (background light)) (:foreground
16088 "Blue1" :underline t))
16089 (((class color) (background light)) (:foreground "Blue" :underline t))
16090 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
16091 "Face used for displaying architecture names."
16092 :group 'speedbar-faces)
16093
16094 (defface vhdl-speedbar-configuration-selected-face
16095 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
16096 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
16097 "Face used for displaying configuration names."
16098 :group 'speedbar-faces)
16099
16100 (defface vhdl-speedbar-package-selected-face
16101 '((((class color) (background light)) (:foreground "Grey50" :underline t))
16102 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
16103 "Face used for displaying package names."
16104 :group 'speedbar-faces)
16105
16106 (defface vhdl-speedbar-instantiation-selected-face
16107 '((((class color) (background light)) (:foreground "Brown" :underline t))
16108 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
16109 "Face used for displaying instantiation names."
16110 :group 'speedbar-faces)
16111
16112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16113 ;; Initialization
16114
16115 ;; add speedbar
16116 (when (fboundp 'speedbar)
16117 (let ((current-frame (selected-frame)))
16118 (condition-case ()
16119 (when (and vhdl-speedbar-auto-open
16120 (not (and (boundp 'speedbar-frame)
16121 (frame-live-p speedbar-frame))))
16122 (speedbar-frame-mode 1))
16123 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
16124 (select-frame current-frame)))
16125
16126 ;; initialize speedbar
16127 (if (not (boundp 'speedbar-frame))
16128 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
16129 (vhdl-speedbar-initialize)
16130 (when speedbar-frame (vhdl-speedbar-refresh)))
16131
16132
16133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16134 ;;; Structural composition
16135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16136
16137 (defun vhdl-get-components-package-name ()
16138 "Return the name of the components package."
16139 (let ((project (vhdl-project-p)))
16140 (if project
16141 (vhdl-replace-string (car vhdl-components-package-name)
16142 (subst-char-in-string ? ?_ project))
16143 (cdr vhdl-components-package-name))))
16144
16145 (defun vhdl-compose-new-component ()
16146 "Create entity and architecture for new component."
16147 (interactive)
16148 (let* ((case-fold-search t)
16149 (ent-name (read-from-minibuffer "entity name: "
16150 nil vhdl-minibuffer-local-map))
16151 (arch-name
16152 (if (equal (cdr vhdl-compose-architecture-name) "")
16153 (read-from-minibuffer "architecture name: "
16154 nil vhdl-minibuffer-local-map)
16155 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16156 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16157 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16158 ;; open entity file
16159 (unless (eq vhdl-compose-create-files 'none)
16160 (setq ent-file-name
16161 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16162 "." (file-name-extension (buffer-file-name))))
16163 (when (and (file-exists-p ent-file-name)
16164 (not (y-or-n-p (concat "File \"" ent-file-name
16165 "\" exists; overwrite? "))))
16166 (error "ERROR: Creating component...aborted"))
16167 (find-file ent-file-name)
16168 (erase-buffer)
16169 (set-buffer-modified-p nil))
16170 ;; insert header
16171 (if vhdl-compose-include-header
16172 (progn (vhdl-template-header)
16173 (setq end-pos (point))
16174 (goto-char (point-max)))
16175 (vhdl-comment-display-line) (insert "\n\n"))
16176 ;; insert library clause
16177 (vhdl-template-package-std-logic-1164)
16178 (when vhdl-use-components-package
16179 (insert "\n")
16180 (vhdl-template-standard-package (vhdl-work-library)
16181 (vhdl-get-components-package-name)))
16182 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16183 ;; insert entity declaration
16184 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16185 (vhdl-insert-keyword " IS\n")
16186 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16187 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16188 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16189 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16190 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16191 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16192 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16193 (vhdl-insert-keyword "END ")
16194 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16195 (insert ent-name ";\n\n")
16196 (vhdl-comment-display-line) (insert "\n")
16197 ;; open architecture file
16198 (if (not (eq vhdl-compose-create-files 'separate))
16199 (insert "\n")
16200 (goto-char (or end-pos (point-min)))
16201 (setq ent-buffer (current-buffer))
16202 (setq arch-file-name
16203 (concat (vhdl-replace-string vhdl-architecture-file-name
16204 (concat ent-name " " arch-name) t)
16205 "." (file-name-extension (buffer-file-name))))
16206 (when (and (file-exists-p arch-file-name)
16207 (not (y-or-n-p (concat "File \"" arch-file-name
16208 "\" exists; overwrite? "))))
16209 (error "ERROR: Creating component...aborted"))
16210 (find-file arch-file-name)
16211 (erase-buffer)
16212 (set-buffer-modified-p nil)
16213 ;; insert header
16214 (if vhdl-compose-include-header
16215 (progn (vhdl-template-header)
16216 (goto-char (point-max)))
16217 (vhdl-comment-display-line) (insert "\n\n")))
16218 ;; insert architecture body
16219 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16220 (vhdl-insert-keyword " OF ") (insert ent-name)
16221 (vhdl-insert-keyword " IS\n\n")
16222 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16223 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16224 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16225 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16226 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16227 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16228 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16229 (vhdl-insert-keyword "BEGIN")
16230 (when vhdl-self-insert-comments
16231 (insert " -- ")
16232 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16233 (insert arch-name))
16234 (insert "\n\n")
16235 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16236 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16237 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16238 (vhdl-insert-keyword "END ")
16239 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16240 (insert arch-name ";\n\n")
16241 ;; insert footer and save
16242 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16243 (vhdl-template-footer)
16244 (vhdl-comment-display-line) (insert "\n"))
16245 (goto-char (or end-pos (point-min)))
16246 (setq arch-buffer (current-buffer))
16247 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16248 (set-buffer arch-buffer) (save-buffer)
16249 (message "%s"
16250 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16251 (and ent-file-name
16252 (format "\n File created: \"%s\"" ent-file-name))
16253 (and arch-file-name
16254 (format "\n File created: \"%s\"" arch-file-name))))))
16255
16256 (defun vhdl-compose-place-component ()
16257 "Place new component by pasting current port as component declaration and
16258 component instantiation."
16259 (interactive)
16260 (if (not vhdl-port-list)
16261 (error "ERROR: No port has been read")
16262 (save-excursion
16263 (vhdl-prepare-search-2
16264 (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
16265 (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t))
16266 (error "ERROR: No architecture found"))
16267 (let* ((ent-name (match-string 1))
16268 (ent-file-name
16269 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16270 "." (file-name-extension (buffer-file-name))))
16271 (orig-buffer (current-buffer)))
16272 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16273 ;; place component declaration
16274 (unless (or vhdl-use-components-package
16275 (vhdl-use-direct-instantiation)
16276 (save-excursion
16277 (re-search-forward
16278 (concat "^\\s-*component\\s-+"
16279 (car vhdl-port-list) "\\>") nil t)))
16280 (re-search-forward "^begin\\>" nil)
16281 (beginning-of-line)
16282 (skip-chars-backward " \t\n\r\f")
16283 (insert "\n\n") (indent-to vhdl-basic-offset)
16284 (vhdl-port-paste-component t))
16285 ;; place component instantiation
16286 (re-search-forward "^end\\>" nil)
16287 (beginning-of-line)
16288 (skip-chars-backward " \t\n\r\f")
16289 (insert "\n\n") (indent-to vhdl-basic-offset)
16290 (vhdl-port-paste-instance nil t t)
16291 ;; place use clause for used packages
16292 (when (nth 3 vhdl-port-list)
16293 ;; open entity file
16294 (when (file-exists-p ent-file-name)
16295 (find-file ent-file-name))
16296 (goto-char (point-min))
16297 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16298 (error "ERROR: Entity not found: \"%s\"" ent-name))
16299 (goto-char (match-beginning 0))
16300 (if (and (save-excursion
16301 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16302 (match-string 1))
16303 (progn (goto-char (match-end 0))
16304 (beginning-of-line 2))
16305 (insert "\n")
16306 (backward-char))
16307 (vhdl-port-paste-context-clause)
16308 (switch-to-buffer orig-buffer))
16309 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16310
16311 (defun vhdl-compose-wire-components ()
16312 "Connect components."
16313 (interactive)
16314 (save-excursion
16315 (vhdl-prepare-search-2
16316 (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
16317 (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t))
16318 (error "ERROR: No architecture found"))
16319 (let* ((ent-name (match-string 1))
16320 (ent-file-name
16321 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16322 "." (file-name-extension (buffer-file-name))))
16323 (arch-decl-pos (point-marker))
16324 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16325 (arch-end-pos (re-search-forward "^end\\>" nil))
16326 (pack-name (vhdl-get-components-package-name))
16327 (pack-file-name
16328 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16329 "." (file-name-extension (buffer-file-name))))
16330 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16331 port-alist generic-alist inst-alist
16332 signal-name signal-entry signal-alist local-list written-list
16333 single-in-list multi-in-list single-out-list multi-out-list
16334 constant-name constant-entry constant-alist single-list multi-list
16335 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16336 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16337 signal-beg-pos signal-pos
16338 constant-temp-pos port-temp-pos signal-temp-pos)
16339 (message "Wiring components...")
16340 ;; process all instances
16341 (goto-char arch-stat-pos)
16342 (while (re-search-forward
16343 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16344 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16345 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16346 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16347 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\)[ \t\n\r\f]*(") arch-end-pos t)
16348 (setq inst-name (match-string-no-properties 1)
16349 comp-name (match-string-no-properties 4)
16350 comp-ent-name (match-string-no-properties 12)
16351 has-generic (or (match-string 7) (match-string 17)))
16352 ;; get port ...
16353 (if comp-name
16354 ;; ... from component declaration
16355 (vhdl-visit-file
16356 (when vhdl-use-components-package pack-file-name) t
16357 (save-excursion
16358 (goto-char (point-min))
16359 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16360 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16361 (vhdl-port-copy)))
16362 ;; ... from entity declaration (direct instantiation)
16363 (setq comp-ent-file-name
16364 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16365 "." (file-name-extension (buffer-file-name))))
16366 (vhdl-visit-file
16367 comp-ent-file-name t
16368 (save-excursion
16369 (goto-char (point-min))
16370 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16371 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16372 (vhdl-port-copy))))
16373 (vhdl-port-flatten t)
16374 (setq generic-alist (nth 1 vhdl-port-list)
16375 port-alist (nth 2 vhdl-port-list)
16376 vhdl-port-list nil)
16377 (setq constant-alist nil
16378 signal-alist nil)
16379 (when has-generic
16380 ;; process all constants in generic map
16381 (vhdl-forward-syntactic-ws)
16382 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16383 (setq constant-name (match-string-no-properties 3))
16384 (setq constant-entry
16385 (cons constant-name
16386 (if (match-string 1)
16387 (or (vhdl-aget generic-alist (match-string 2))
16388 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16389 (cdar generic-alist))))
16390 (push constant-entry constant-alist)
16391 (setq constant-name (downcase constant-name))
16392 (if (or (member constant-name single-list)
16393 (member constant-name multi-list))
16394 (progn (setq single-list (delete constant-name single-list))
16395 (add-to-list 'multi-list constant-name))
16396 (add-to-list 'single-list constant-name))
16397 (unless (match-string 1)
16398 (setq generic-alist (cdr generic-alist)))
16399 (vhdl-forward-syntactic-ws))
16400 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16401 ;; process all signals in port map
16402 (vhdl-forward-syntactic-ws)
16403 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16404 (setq signal-name (match-string-no-properties 3))
16405 (setq signal-entry
16406 (cons signal-name
16407 (if (match-string 1)
16408 (or (vhdl-aget port-alist (match-string 2))
16409 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16410 (cdar port-alist))))
16411 (push signal-entry signal-alist)
16412 (setq signal-name (downcase signal-name))
16413 (if (equal (upcase (nth 2 signal-entry)) "IN")
16414 ;; input signal
16415 (cond
16416 ((member signal-name local-list)
16417 nil)
16418 ((or (member signal-name single-out-list)
16419 (member signal-name multi-out-list))
16420 (setq single-out-list (delete signal-name single-out-list))
16421 (setq multi-out-list (delete signal-name multi-out-list))
16422 (add-to-list 'local-list signal-name))
16423 ((member signal-name single-in-list)
16424 (setq single-in-list (delete signal-name single-in-list))
16425 (add-to-list 'multi-in-list signal-name))
16426 ((not (member signal-name multi-in-list))
16427 (add-to-list 'single-in-list signal-name)))
16428 ;; output signal
16429 (cond
16430 ((member signal-name local-list)
16431 nil)
16432 ((or (member signal-name single-in-list)
16433 (member signal-name multi-in-list))
16434 (setq single-in-list (delete signal-name single-in-list))
16435 (setq multi-in-list (delete signal-name multi-in-list))
16436 (add-to-list 'local-list signal-name))
16437 ((member signal-name single-out-list)
16438 (setq single-out-list (delete signal-name single-out-list))
16439 (add-to-list 'multi-out-list signal-name))
16440 ((not (member signal-name multi-out-list))
16441 (add-to-list 'single-out-list signal-name))))
16442 (unless (match-string 1)
16443 (setq port-alist (cdr port-alist)))
16444 (vhdl-forward-syntactic-ws))
16445 (push (list inst-name (nreverse constant-alist)
16446 (nreverse signal-alist)) inst-alist))
16447 ;; prepare signal insertion
16448 (vhdl-goto-marker arch-decl-pos)
16449 (forward-line 1)
16450 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16451 (setq signal-pos (point-marker))
16452 (while (progn (vhdl-forward-syntactic-ws)
16453 (looking-at "signal\\>"))
16454 (beginning-of-line 2)
16455 (delete-region signal-pos (point)))
16456 (setq signal-beg-pos signal-pos)
16457 ;; open entity file
16458 (when (file-exists-p ent-file-name)
16459 (find-file ent-file-name))
16460 (goto-char (point-min))
16461 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16462 (error "ERROR: Entity not found: \"%s\"" ent-name))
16463 ;; prepare generic clause insertion
16464 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16465 (match-string 1))
16466 (goto-char (match-beginning 0))
16467 (indent-to vhdl-basic-offset)
16468 (insert "generic ();\n\n")
16469 (backward-char 4))
16470 (backward-char)
16471 (setq generic-pos (point-marker))
16472 (forward-sexp) (end-of-line)
16473 (delete-region generic-pos (point)) (delete-char 1)
16474 (insert "(\n")
16475 (when multi-list
16476 (insert "\n")
16477 (indent-to (* 2 vhdl-basic-offset))
16478 (insert "-- global generics\n"))
16479 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16480 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16481 ;; prepare port clause insertion
16482 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16483 (match-string 1))
16484 (goto-char (match-beginning 0))
16485 (indent-to vhdl-basic-offset)
16486 (insert "port ();\n\n")
16487 (backward-char 4))
16488 (backward-char)
16489 (setq port-in-pos (point-marker))
16490 (forward-sexp) (end-of-line)
16491 (delete-region port-in-pos (point)) (delete-char 1)
16492 (insert "(\n")
16493 (when (or multi-in-list multi-out-list)
16494 (insert "\n")
16495 (indent-to (* 2 vhdl-basic-offset))
16496 (insert "-- global ports\n"))
16497 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16498 port-out-pos (point-marker) port-inst-pos (point-marker)
16499 port-end-pos (point-marker))
16500 ;; insert generics, ports and signals
16501 (setq inst-alist (nreverse inst-alist))
16502 (while inst-alist
16503 (setq inst-name (nth 0 (car inst-alist))
16504 constant-alist (nth 1 (car inst-alist))
16505 signal-alist (nth 2 (car inst-alist))
16506 constant-temp-pos generic-inst-pos
16507 port-temp-pos port-inst-pos
16508 signal-temp-pos signal-pos)
16509 ;; generics
16510 (while constant-alist
16511 (setq constant-name (downcase (caar constant-alist))
16512 constant-entry (car constant-alist))
16513 (unless (string-match "^[0-9]+" constant-name)
16514 (cond ((member constant-name written-list)
16515 nil)
16516 ((member constant-name multi-list)
16517 (vhdl-goto-marker generic-pos)
16518 (setq generic-end-pos
16519 (vhdl-max-marker
16520 generic-end-pos
16521 (vhdl-compose-insert-generic constant-entry)))
16522 (setq generic-pos (point-marker))
16523 (add-to-list 'written-list constant-name))
16524 (t
16525 (vhdl-goto-marker
16526 (vhdl-max-marker generic-inst-pos generic-pos))
16527 (setq generic-end-pos
16528 (vhdl-compose-insert-generic constant-entry))
16529 (setq generic-inst-pos (point-marker))
16530 (add-to-list 'written-list constant-name))))
16531 (setq constant-alist (cdr constant-alist)))
16532 (when (/= constant-temp-pos generic-inst-pos)
16533 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16534 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16535 (insert "-- generics for \"" inst-name "\"\n")
16536 (vhdl-goto-marker generic-inst-pos))
16537 ;; ports and signals
16538 (while signal-alist
16539 (setq signal-name (downcase (caar signal-alist))
16540 signal-entry (car signal-alist))
16541 (cond ((member signal-name written-list)
16542 nil)
16543 ((member signal-name multi-in-list)
16544 (vhdl-goto-marker port-in-pos)
16545 (setq port-end-pos
16546 (vhdl-max-marker
16547 port-end-pos (vhdl-compose-insert-port signal-entry)))
16548 (setq port-in-pos (point-marker))
16549 (add-to-list 'written-list signal-name))
16550 ((member signal-name multi-out-list)
16551 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16552 (setq port-end-pos
16553 (vhdl-max-marker
16554 port-end-pos (vhdl-compose-insert-port signal-entry)))
16555 (setq port-out-pos (point-marker))
16556 (add-to-list 'written-list signal-name))
16557 ((or (member signal-name single-in-list)
16558 (member signal-name single-out-list))
16559 (vhdl-goto-marker
16560 (vhdl-max-marker
16561 port-inst-pos
16562 (vhdl-max-marker port-out-pos port-in-pos)))
16563 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16564 (setq port-inst-pos (point-marker))
16565 (add-to-list 'written-list signal-name))
16566 ((equal (upcase (nth 2 signal-entry)) "OUT")
16567 (vhdl-goto-marker signal-pos)
16568 (vhdl-compose-insert-signal signal-entry)
16569 (setq signal-pos (point-marker))
16570 (add-to-list 'written-list signal-name)))
16571 (setq signal-alist (cdr signal-alist)))
16572 (when (/= port-temp-pos port-inst-pos)
16573 (vhdl-goto-marker
16574 (vhdl-max-marker port-temp-pos
16575 (vhdl-max-marker port-in-pos port-out-pos)))
16576 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16577 (insert "-- ports to \"" inst-name "\"\n")
16578 (vhdl-goto-marker port-inst-pos))
16579 (when (/= signal-temp-pos signal-pos)
16580 (vhdl-goto-marker signal-temp-pos)
16581 (insert "\n") (indent-to vhdl-basic-offset)
16582 (insert "-- outputs of \"" inst-name "\"\n")
16583 (vhdl-goto-marker signal-pos))
16584 (setq inst-alist (cdr inst-alist)))
16585 ;; finalize generic/port clause
16586 (vhdl-goto-marker generic-end-pos) (backward-char)
16587 (when (= generic-beg-pos generic-end-pos)
16588 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16589 (insert ";") (backward-char))
16590 (insert ")")
16591 (vhdl-goto-marker port-end-pos) (backward-char)
16592 (when (= port-beg-pos port-end-pos)
16593 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16594 (insert ";") (backward-char))
16595 (insert ")")
16596 ;; align everything
16597 (when vhdl-auto-align
16598 (vhdl-goto-marker generic-beg-pos)
16599 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16600 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16601 (vhdl-goto-marker signal-beg-pos)
16602 (vhdl-align-region-groups signal-beg-pos signal-pos))
16603 (switch-to-buffer (marker-buffer signal-beg-pos))
16604 (message "Wiring components...done")))))
16605
16606 (defun vhdl-compose-insert-generic (entry)
16607 "Insert ENTRY as generic declaration."
16608 (let (pos)
16609 (indent-to (* 2 vhdl-basic-offset))
16610 (insert (nth 0 entry) " : " (nth 1 entry))
16611 (when (nth 2 entry)
16612 (insert " := " (nth 2 entry)))
16613 (insert ";")
16614 (setq pos (point-marker))
16615 (when (and vhdl-include-port-comments (nth 3 entry))
16616 (vhdl-comment-insert-inline (nth 3 entry) t))
16617 (insert "\n")
16618 pos))
16619
16620 (defun vhdl-compose-insert-port (entry)
16621 "Insert ENTRY as port declaration."
16622 (let (pos)
16623 (indent-to (* 2 vhdl-basic-offset))
16624 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16625 (setq pos (point-marker))
16626 (when (and vhdl-include-port-comments (nth 4 entry))
16627 (vhdl-comment-insert-inline (nth 4 entry) t))
16628 (insert "\n")
16629 pos))
16630
16631 (defun vhdl-compose-insert-signal (entry)
16632 "Insert ENTRY as signal declaration."
16633 (indent-to vhdl-basic-offset)
16634 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16635 (when (and vhdl-include-port-comments (nth 4 entry))
16636 (vhdl-comment-insert-inline (nth 4 entry) t))
16637 (insert "\n"))
16638
16639 (defun vhdl-compose-components-package ()
16640 "Generate a package containing component declarations for all entities in the
16641 current project/directory."
16642 (interactive)
16643 (vhdl-require-hierarchy-info)
16644 (let* ((project (vhdl-project-p))
16645 (pack-name (vhdl-get-components-package-name))
16646 (pack-file-name
16647 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16648 "." (file-name-extension (buffer-file-name))))
16649 (ent-alist (vhdl-aget vhdl-entity-alist
16650 (or project
16651 (abbreviate-file-name default-directory))))
16652 (lazy-lock-minimum-size 0)
16653 clause-pos component-pos)
16654 (message "Generating components package \"%s\"..." pack-name)
16655 ;; open package file
16656 (when (and (file-exists-p pack-file-name)
16657 (not (y-or-n-p (concat "File \"" pack-file-name
16658 "\" exists; overwrite? "))))
16659 (error "ERROR: Generating components package...aborted"))
16660 (find-file pack-file-name)
16661 (erase-buffer)
16662 ;; insert header
16663 (if vhdl-compose-include-header
16664 (progn (vhdl-template-header
16665 (concat "Components package (generated by Emacs VHDL Mode "
16666 vhdl-version ")"))
16667 (goto-char (point-max)))
16668 (vhdl-comment-display-line) (insert "\n\n"))
16669 ;; insert std_logic_1164 package
16670 (vhdl-template-package-std-logic-1164)
16671 (insert "\n") (setq clause-pos (point-marker))
16672 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16673 ;; insert package declaration
16674 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16675 (vhdl-insert-keyword " IS\n\n")
16676 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16677 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16678 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16679 (indent-to vhdl-basic-offset)
16680 (setq component-pos (point-marker))
16681 (insert "\n\n") (vhdl-insert-keyword "END ")
16682 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16683 (insert pack-name ";\n\n")
16684 ;; insert footer
16685 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16686 (vhdl-template-footer)
16687 (vhdl-comment-display-line) (insert "\n"))
16688 ;; insert component declarations
16689 (while ent-alist
16690 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16691 (progn (goto-char (point-min))
16692 (forward-line (1- (nth 3 (car ent-alist))))
16693 (end-of-line)
16694 (vhdl-port-copy)))
16695 (goto-char component-pos)
16696 (vhdl-port-paste-component t)
16697 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16698 (setq component-pos (point-marker))
16699 (goto-char clause-pos)
16700 (vhdl-port-paste-context-clause pack-name)
16701 (setq clause-pos (point-marker))
16702 (setq ent-alist (cdr ent-alist)))
16703 (goto-char (point-min))
16704 (save-buffer)
16705 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16706 pack-name pack-file-name)))
16707
16708 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16709 conf-alist inst-alist
16710 &optional insert-conf)
16711 "Generate block configuration for architecture."
16712 (let ((margin (current-indentation))
16713 (beg (point-at-bol))
16714 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16715 ;; insert block configuration (for architecture)
16716 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16717 (setq margin (+ margin vhdl-basic-offset))
16718 ;; process all instances
16719 (while inst-alist
16720 (setq inst-entry (car inst-alist))
16721 ;; is component?
16722 (when (nth 4 inst-entry)
16723 (setq insert-conf t)
16724 (setq inst-path (nth 9 inst-entry))
16725 ;; skip common path with previous instance
16726 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16727 (setq inst-path (cdr inst-path)
16728 inst-prev-path (cdr inst-prev-path)))
16729 ;; insert block configuration end (for previous block/generate)
16730 (while inst-prev-path
16731 (setq margin (- margin vhdl-basic-offset))
16732 (indent-to margin)
16733 (vhdl-insert-keyword "END FOR;\n")
16734 (setq inst-prev-path (cdr inst-prev-path)))
16735 ;; insert block configuration beginning (for current block/generate)
16736 (indent-to margin)
16737 (while inst-path
16738 (setq margin (+ margin vhdl-basic-offset))
16739 (vhdl-insert-keyword "FOR ")
16740 (insert (car inst-path) "\n")
16741 (indent-to margin)
16742 (setq inst-path (cdr inst-path)))
16743 ;; insert component configuration beginning
16744 (vhdl-insert-keyword "FOR ")
16745 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16746 ;; find subconfiguration
16747 (setq conf-key (nth 7 inst-entry))
16748 (setq tmp-alist conf-alist)
16749 ;; use first configuration found for instance's entity
16750 (while (and tmp-alist (null conf-key))
16751 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16752 (setq conf-key (nth 0 (car tmp-alist))))
16753 (setq tmp-alist (cdr tmp-alist)))
16754 (setq conf-entry (vhdl-aget conf-alist conf-key))
16755 ;; insert binding indication ...
16756 ;; ... with subconfiguration (if exists)
16757 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16758 (progn
16759 (indent-to (+ margin vhdl-basic-offset))
16760 (vhdl-insert-keyword "USE CONFIGURATION ")
16761 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16762 (insert ";\n"))
16763 ;; ... with entity (if exists)
16764 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16765 (when ent-entry
16766 (indent-to (+ margin vhdl-basic-offset))
16767 (vhdl-insert-keyword "USE ENTITY ")
16768 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16769 ;; insert architecture name (if architecture exists)
16770 (when (nth 3 ent-entry)
16771 (setq arch-name
16772 ;; choose architecture name a) from configuration,
16773 ;; b) from mra, or c) from first architecture
16774 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16775 (or (nth 6 inst-entry)
16776 (nth 4 ent-entry))))
16777 (nth 1 (car (nth 3 ent-entry)))))
16778 (insert "(" arch-name ")"))
16779 (insert ";\n")
16780 ;; insert block configuration (for architecture of subcomponent)
16781 (when (and vhdl-compose-configuration-hierarchical
16782 (nth 3 ent-entry))
16783 (indent-to (+ margin vhdl-basic-offset))
16784 (vhdl-compose-configuration-architecture
16785 (nth 0 ent-entry) arch-name ent-alist conf-alist
16786 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16787 ;; insert component configuration end
16788 (indent-to margin)
16789 (vhdl-insert-keyword "END FOR;\n")
16790 (setq inst-prev-path (nth 9 inst-entry)))
16791 (setq inst-alist (cdr inst-alist)))
16792 ;; insert block configuration end (for block/generate)
16793 (while inst-prev-path
16794 (setq margin (- margin vhdl-basic-offset))
16795 (indent-to margin)
16796 (vhdl-insert-keyword "END FOR;\n")
16797 (setq inst-prev-path (cdr inst-prev-path)))
16798 (indent-to (- margin vhdl-basic-offset))
16799 ;; insert block configuration end or remove beginning (for architecture)
16800 (if insert-conf
16801 (vhdl-insert-keyword "END FOR;\n")
16802 (delete-region beg (point)))))
16803
16804 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16805 "Generate configuration declaration."
16806 (interactive)
16807 (vhdl-require-hierarchy-info)
16808 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16809 (or (vhdl-project-p)
16810 (abbreviate-file-name default-directory))))
16811 (conf-alist (vhdl-aget vhdl-config-alist
16812 (or (vhdl-project-p)
16813 (abbreviate-file-name default-directory))))
16814 (from-speedbar ent-name)
16815 inst-alist conf-name conf-file-name pos)
16816 (vhdl-prepare-search-2
16817 ;; get entity and architecture name
16818 (unless ent-name
16819 (save-excursion
16820 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16821 (not (equal "END" (upcase (match-string 1))))
16822 (setq ent-name (match-string-no-properties 3))
16823 (setq arch-name (match-string-no-properties 2)))
16824 (error "ERROR: Not within an architecture"))))
16825 (setq conf-name (vhdl-replace-string
16826 vhdl-compose-configuration-name
16827 (concat ent-name " " arch-name)))
16828 (setq inst-alist
16829 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16830 (downcase arch-name)))))
16831 (message "Generating configuration \"%s\"..." conf-name)
16832 (if vhdl-compose-configuration-create-file
16833 ;; open configuration file
16834 (progn
16835 (setq conf-file-name
16836 (concat (vhdl-replace-string vhdl-configuration-file-name
16837 conf-name t)
16838 "." (file-name-extension (buffer-file-name))))
16839 (when (and (file-exists-p conf-file-name)
16840 (not (y-or-n-p (concat "File \"" conf-file-name
16841 "\" exists; overwrite? "))))
16842 (error "ERROR: Creating configuration...aborted"))
16843 (find-file conf-file-name)
16844 (erase-buffer)
16845 (set-buffer-modified-p nil)
16846 ;; insert header
16847 (if vhdl-compose-include-header
16848 (progn (vhdl-template-header
16849 (concat "Configuration declaration for design \""
16850 ent-name "(" arch-name ")\""))
16851 (goto-char (point-max)))
16852 (vhdl-comment-display-line) (insert "\n\n")))
16853 ;; goto end of architecture
16854 (unless from-speedbar
16855 (re-search-forward "^end\\>" nil)
16856 (end-of-line) (insert "\n\n")
16857 (vhdl-comment-display-line) (insert "\n\n")))
16858 ;; insert library clause
16859 (setq pos (point))
16860 (vhdl-template-standard-package (vhdl-work-library) nil)
16861 (when (/= pos (point))
16862 (insert "\n\n"))
16863 ;; insert configuration
16864 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16865 (vhdl-insert-keyword " OF ") (insert ent-name)
16866 (vhdl-insert-keyword " IS\n")
16867 (indent-to vhdl-basic-offset)
16868 ;; insert block configuration (for architecture)
16869 (vhdl-compose-configuration-architecture
16870 ent-name arch-name ent-alist conf-alist inst-alist t)
16871 (vhdl-insert-keyword "END ") (insert conf-name ";")
16872 (when conf-file-name
16873 ;; insert footer and save
16874 (insert "\n\n")
16875 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16876 (vhdl-template-footer)
16877 (vhdl-comment-display-line) (insert "\n"))
16878 (save-buffer))
16879 (message "%s"
16880 (concat (format "Generating configuration \"%s\"...done" conf-name)
16881 (and conf-file-name
16882 (format "\n File created: \"%s\"" conf-file-name))))))
16883
16884
16885 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16886 ;;; Compilation / Makefile generation
16887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16888 ;; (using `compile.el')
16889
16890 (defvar vhdl-compile-post-command ""
16891 "String appended to compile command after file name.")
16892
16893 (defun vhdl-makefile-name ()
16894 "Return the Makefile name of the current project or the current compiler if
16895 no project is defined."
16896 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16897 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16898 (vhdl-replace-string
16899 (cons "\\(.*\\)\n\\(.*\\)"
16900 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16901 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16902
16903 (defun vhdl-compile-directory ()
16904 "Return the directory where compilation/make should be run."
16905 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16906 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16907 (directory (vhdl-resolve-env-variable
16908 (if project
16909 (vhdl-replace-string
16910 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16911 (nth 6 compiler)))))
16912 (file-name-as-directory
16913 (if (file-name-absolute-p directory)
16914 directory
16915 (expand-file-name directory (vhdl-default-directory))))))
16916
16917 (defun vhdl-uniquify (in-list)
16918 "Remove duplicate elements from IN-LIST."
16919 (let (out-list)
16920 (while in-list
16921 (add-to-list 'out-list (car in-list))
16922 (setq in-list (cdr in-list)))
16923 out-list))
16924
16925 (defun vhdl-set-compiler (name)
16926 "Set current compiler to NAME."
16927 (interactive
16928 (list (let ((completion-ignore-case t))
16929 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16930 (if (assoc name vhdl-compiler-alist)
16931 (progn (setq vhdl-compiler name)
16932 (message "Current compiler: \"%s\"" vhdl-compiler))
16933 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16934
16935 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16936 ;; Compilation
16937
16938 (defun vhdl-compile-init ()
16939 "Initialize for compilation."
16940 (when (and (not vhdl-emacs-22)
16941 (or (null compilation-error-regexp-alist)
16942 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16943 compilation-error-regexp-alist))))
16944 ;; `compilation-error-regexp-alist'
16945 (let ((commands-alist vhdl-compiler-alist)
16946 regexp-alist sublist)
16947 (while commands-alist
16948 (setq sublist (nth 11 (car commands-alist)))
16949 (unless (or (equal "" (car sublist))
16950 (assoc (car sublist) regexp-alist))
16951 (push (list (nth 0 sublist)
16952 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16953 9
16954 (nth 1 sublist))
16955 (nth 2 sublist) (nth 3 sublist))
16956 regexp-alist))
16957 (setq commands-alist (cdr commands-alist)))
16958 (setq compilation-error-regexp-alist
16959 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16960 ;; `compilation-file-regexp-alist'
16961 (let ((commands-alist vhdl-compiler-alist)
16962 regexp-alist sublist)
16963 ;; matches vhdl-mode file name output
16964 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16965 (while commands-alist
16966 (setq sublist (nth 12 (car commands-alist)))
16967 (unless (or (equal "" (car sublist))
16968 (assoc (car sublist) regexp-alist))
16969 (push sublist regexp-alist))
16970 (setq commands-alist (cdr commands-alist)))
16971 (setq compilation-file-regexp-alist
16972 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16973
16974 (defvar vhdl-compile-file-name nil
16975 "Name of file to be compiled.")
16976
16977 (defun vhdl-compile-print-file-name ()
16978 "Function called within `compile' to print out file name for compilers that
16979 do not print any file names."
16980 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16981
16982 (defun vhdl-get-compile-options (project compiler file-name
16983 &optional file-options-only)
16984 "Get compiler options. Returning nil means do not compile this file."
16985 (let* ((compiler-options (nth 1 compiler))
16986 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
16987 (project-options (nth 0 project-entry))
16988 (exception-list (and file-name (nth 2 project-entry)))
16989 (work-library (vhdl-work-library))
16990 (case-fold-search nil)
16991 file-options)
16992 (while (and exception-list
16993 (not (string-match (caar exception-list) file-name)))
16994 (setq exception-list (cdr exception-list)))
16995 (if (and exception-list (not (cdar exception-list)))
16996 nil
16997 (if (and file-options-only (not exception-list))
16998 'default
16999 (setq file-options (cdar exception-list))
17000 ;; insert library name in compiler-specific options
17001 (setq compiler-options
17002 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
17003 work-library))
17004 ;; insert compiler-specific options in project-specific options
17005 (when project-options
17006 (setq project-options
17007 (vhdl-replace-string
17008 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17009 (concat work-library "\n" compiler-options))))
17010 ;; insert project-specific options in file-specific options
17011 (when file-options
17012 (setq file-options
17013 (vhdl-replace-string
17014 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
17015 (concat work-library "\n" compiler-options "\n"
17016 project-options))))
17017 ;; return options
17018 (or file-options project-options compiler-options)))))
17019
17020 (defun vhdl-get-make-options (project compiler)
17021 "Get make options."
17022 (let* ((compiler-options (nth 3 compiler))
17023 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17024 (project-options (nth 1 project-entry))
17025 (makefile-name (vhdl-makefile-name)))
17026 ;; insert Makefile name in compiler-specific options
17027 (setq compiler-options
17028 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
17029 makefile-name))
17030 ;; insert compiler-specific options in project-specific options
17031 (when project-options
17032 (setq project-options
17033 (vhdl-replace-string
17034 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17035 (concat makefile-name "\n" compiler-options))))
17036 ;; return options
17037 (or project-options compiler-options)))
17038
17039 (defun vhdl-compile ()
17040 "Compile current buffer using the VHDL compiler specified in
17041 `vhdl-compiler'."
17042 (interactive)
17043 (vhdl-compile-init)
17044 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17045 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17046 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17047 (command (nth 0 compiler))
17048 (default-directory (vhdl-compile-directory))
17049 (file-name (if vhdl-compile-absolute-path
17050 (buffer-file-name)
17051 (file-relative-name (buffer-file-name))))
17052 (options (vhdl-get-compile-options project compiler file-name))
17053 compilation-process-setup-function)
17054 (unless (file-directory-p default-directory)
17055 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17056 ;; put file name into quotes if it contains spaces
17057 (when (string-match " " file-name)
17058 (setq file-name (concat "\"" file-name "\"")))
17059 ;; print out file name if compiler does not
17060 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
17061 (buffer-file-name)
17062 (file-relative-name (buffer-file-name))))
17063 (when (and (= 0 (nth 1 (nth 10 compiler)))
17064 (= 0 (nth 1 (nth 11 compiler))))
17065 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
17066 ;; run compilation
17067 (if options
17068 (when command
17069 (compile (concat command " " options " " file-name
17070 (unless (equal vhdl-compile-post-command "")
17071 (concat " " vhdl-compile-post-command)))))
17072 (vhdl-warning "Your project settings tell me not to compile this file"))))
17073
17074 (defvar vhdl-make-target "all"
17075 "Default target for `vhdl-make' command.")
17076
17077 (defun vhdl-make (&optional target)
17078 "Call make command for compilation of all updated source files (requires
17079 `Makefile'). Optional argument TARGET allows you to compile the design
17080 specified by a target."
17081 (interactive)
17082 (setq vhdl-make-target
17083 (or target (read-from-minibuffer "Target: " vhdl-make-target
17084 vhdl-minibuffer-local-map)))
17085 (vhdl-compile-init)
17086 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17087 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17088 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17089 (command (nth 2 compiler))
17090 (options (vhdl-get-make-options project compiler))
17091 (default-directory (vhdl-compile-directory)))
17092 (unless (file-directory-p default-directory)
17093 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17094 ;; run make
17095 (compile (concat (if (equal command "") "make" command)
17096 " " options " " vhdl-make-target))))
17097
17098 ;; Emacs 22+ setup
17099 (defvar vhdl-error-regexp-emacs-alist
17100 ;; Get regexps from `vhdl-compiler-alist'
17101 (let ((compiler-alist vhdl-compiler-alist)
17102 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
17103 (while compiler-alist
17104 ;; only add regexps for currently selected compiler
17105 (when (or (not vhdl-compile-use-local-error-regexp)
17106 (equal vhdl-compiler (nth 0 (car compiler-alist))))
17107 ;; add error message regexps
17108 (setq error-regexp-alist
17109 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
17110 (nth 11 (car compiler-alist)))
17111 error-regexp-alist))
17112 ;; add filename regexps
17113 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
17114 (setq error-regexp-alist
17115 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
17116 (nth 12 (car compiler-alist)))
17117 error-regexp-alist))))
17118 (setq compiler-alist (cdr compiler-alist)))
17119 error-regexp-alist)
17120 "List of regexps for VHDL compilers. For Emacs 22+.")
17121
17122 ;; Add error regexps using compilation-mode-hook.
17123 (defun vhdl-error-regexp-add-emacs ()
17124 "Set up Emacs compile for VHDL."
17125 (interactive)
17126 (when (and (boundp 'compilation-error-regexp-alist-alist)
17127 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
17128 ;; remove all other compilers
17129 (when vhdl-compile-use-local-error-regexp
17130 (setq compilation-error-regexp-alist nil))
17131 ;; add VHDL compilers
17132 (mapcar
17133 (lambda (item)
17134 (push (car item) compilation-error-regexp-alist)
17135 (push item compilation-error-regexp-alist-alist))
17136 vhdl-error-regexp-emacs-alist)))
17137
17138 (when vhdl-emacs-22
17139 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
17140
17141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17142 ;; Makefile generation
17143
17144 (defun vhdl-generate-makefile ()
17145 "Generate `Makefile'."
17146 (interactive)
17147 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17148 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17149 (command (nth 4 compiler)))
17150 ;; generate makefile
17151 (if command
17152 (let ((default-directory (vhdl-compile-directory)))
17153 (compile (vhdl-replace-string
17154 (cons "\\(.*\\) \\(.*\\)" command)
17155 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17156 (vhdl-generate-makefile-1))))
17157
17158 (defun vhdl-get-packages (lib-alist work-library)
17159 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17160 (let (pack-list)
17161 (while lib-alist
17162 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17163 (push (cdar lib-alist) pack-list))
17164 (setq lib-alist (cdr lib-alist)))
17165 pack-list))
17166
17167 (defun vhdl-generate-makefile-1 ()
17168 "Generate Makefile for current project or directory."
17169 ;; scan hierarchy if required
17170 (if (vhdl-project-p)
17171 (unless (or (assoc vhdl-project vhdl-file-alist)
17172 (vhdl-load-cache vhdl-project))
17173 (vhdl-scan-project-contents vhdl-project))
17174 (let ((directory (abbreviate-file-name default-directory)))
17175 (unless (or (assoc directory vhdl-file-alist)
17176 (vhdl-load-cache directory))
17177 (vhdl-scan-directory-contents directory))))
17178 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17179 (project (vhdl-project-p))
17180 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17181 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17182 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17183 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17184 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17185 "\\1.vhd" "\\1_body.vhd" identity)))
17186 (mapping-exist
17187 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17188 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17189 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17190 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17191 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17192 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17193 (adjust-case (nth 5 regexp-list))
17194 (work-library (downcase (vhdl-work-library)))
17195 (compile-directory (expand-file-name (vhdl-compile-directory)
17196 default-directory))
17197 (makefile-name (vhdl-makefile-name))
17198 rule-alist arch-alist inst-alist
17199 target-list depend-list unit-list prim-list second-list subcomp-list
17200 lib-alist lib-body-alist pack-list all-pack-list
17201 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17202 conf-key conf-file-name pack-key pack-file-name
17203 ent-entry arch-entry conf-entry pack-entry inst-entry
17204 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17205 tmp-key tmp-list rule)
17206 ;; check prerequisites
17207 (unless (file-exists-p compile-directory)
17208 (make-directory compile-directory t))
17209 (unless mapping-exist
17210 (vhdl-warning
17211 (format "No unit-to-file name mapping found for compiler \"%s\".\n Directory of dummy files is created instead (to be used as dependencies).\n Please contact the VHDL Mode maintainer for full support of \"%s\""
17212 vhdl-compiler vhdl-compiler) t))
17213 (message "Generating makefile \"%s\"..." makefile-name)
17214 ;; rules for all entities
17215 (setq tmp-list ent-alist)
17216 (while ent-alist
17217 (setq ent-entry (car ent-alist)
17218 ent-key (nth 0 ent-entry))
17219 (when (nth 2 ent-entry)
17220 (setq ent-file-name (if vhdl-compile-absolute-path
17221 (nth 2 ent-entry)
17222 (file-relative-name (nth 2 ent-entry)
17223 compile-directory))
17224 arch-alist (nth 4 ent-entry)
17225 lib-alist (nth 6 ent-entry)
17226 rule (vhdl-aget rule-alist ent-file-name)
17227 target-list (nth 0 rule)
17228 depend-list (nth 1 rule)
17229 second-list nil
17230 subcomp-list nil)
17231 (setq tmp-key (vhdl-replace-string
17232 ent-regexp
17233 (funcall adjust-case
17234 (concat ent-key " " work-library))))
17235 (push (cons ent-key tmp-key) unit-list)
17236 ;; rule target for this entity
17237 (push ent-key target-list)
17238 ;; rule dependencies for all used packages
17239 (setq pack-list (vhdl-get-packages lib-alist work-library))
17240 (setq depend-list (append depend-list pack-list))
17241 (setq all-pack-list pack-list)
17242 ;; add rule
17243 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17244 ;; rules for all corresponding architectures
17245 (while arch-alist
17246 (setq arch-entry (car arch-alist)
17247 arch-key (nth 0 arch-entry)
17248 ent-arch-key (concat ent-key "-" arch-key)
17249 arch-file-name (if vhdl-compile-absolute-path
17250 (nth 2 arch-entry)
17251 (file-relative-name (nth 2 arch-entry)
17252 compile-directory))
17253 inst-alist (nth 4 arch-entry)
17254 lib-alist (nth 5 arch-entry)
17255 rule (vhdl-aget rule-alist arch-file-name)
17256 target-list (nth 0 rule)
17257 depend-list (nth 1 rule))
17258 (setq tmp-key (vhdl-replace-string
17259 arch-regexp
17260 (funcall adjust-case
17261 (concat arch-key " " ent-key " "
17262 work-library))))
17263 (setq unit-list
17264 (cons (cons ent-arch-key tmp-key) unit-list))
17265 (push ent-arch-key second-list)
17266 ;; rule target for this architecture
17267 (push ent-arch-key target-list)
17268 ;; rule dependency for corresponding entity
17269 (push ent-key depend-list)
17270 ;; rule dependencies for contained component instantiations
17271 (while inst-alist
17272 (setq inst-entry (car inst-alist))
17273 (when (or (null (nth 8 inst-entry))
17274 (equal (downcase (nth 8 inst-entry)) work-library))
17275 (setq inst-ent-key (or (nth 7 inst-entry)
17276 (nth 5 inst-entry)))
17277 (setq depend-list (cons inst-ent-key depend-list)
17278 subcomp-list (cons inst-ent-key subcomp-list)))
17279 (setq inst-alist (cdr inst-alist)))
17280 ;; rule dependencies for all used packages
17281 (setq pack-list (vhdl-get-packages lib-alist work-library))
17282 (setq depend-list (append depend-list pack-list))
17283 (setq all-pack-list (append all-pack-list pack-list))
17284 ;; add rule
17285 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17286 (setq arch-alist (cdr arch-alist)))
17287 (push (list ent-key second-list (append subcomp-list all-pack-list))
17288 prim-list))
17289 (setq ent-alist (cdr ent-alist)))
17290 (setq ent-alist tmp-list)
17291 ;; rules for all configurations
17292 (setq tmp-list conf-alist)
17293 (while conf-alist
17294 (setq conf-entry (car conf-alist)
17295 conf-key (nth 0 conf-entry)
17296 conf-file-name (if vhdl-compile-absolute-path
17297 (nth 2 conf-entry)
17298 (file-relative-name (nth 2 conf-entry)
17299 compile-directory))
17300 ent-key (nth 4 conf-entry)
17301 arch-key (nth 5 conf-entry)
17302 inst-alist (nth 6 conf-entry)
17303 lib-alist (nth 7 conf-entry)
17304 rule (vhdl-aget rule-alist conf-file-name)
17305 target-list (nth 0 rule)
17306 depend-list (nth 1 rule)
17307 subcomp-list (list ent-key))
17308 (setq tmp-key (vhdl-replace-string
17309 conf-regexp
17310 (funcall adjust-case
17311 (concat conf-key " " work-library))))
17312 (push (cons conf-key tmp-key) unit-list)
17313 ;; rule target for this configuration
17314 (push conf-key target-list)
17315 ;; rule dependency for corresponding entity and architecture
17316 (setq depend-list
17317 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17318 ;; rule dependencies for used packages
17319 (setq pack-list (vhdl-get-packages lib-alist work-library))
17320 (setq depend-list (append depend-list pack-list))
17321 ;; rule dependencies for contained component configurations
17322 (while inst-alist
17323 (setq inst-entry (car inst-alist))
17324 (setq inst-ent-key (nth 2 inst-entry)
17325 inst-conf-key (nth 4 inst-entry))
17326 (when (equal (downcase (nth 5 inst-entry)) work-library)
17327 (when inst-ent-key
17328 (setq depend-list (cons inst-ent-key depend-list)
17329 subcomp-list (cons inst-ent-key subcomp-list)))
17330 (when inst-conf-key
17331 (setq depend-list (cons inst-conf-key depend-list)
17332 subcomp-list (cons inst-conf-key subcomp-list))))
17333 (setq inst-alist (cdr inst-alist)))
17334 ;; add rule
17335 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17336 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17337 (setq conf-alist (cdr conf-alist)))
17338 (setq conf-alist tmp-list)
17339 ;; rules for all packages
17340 (setq tmp-list pack-alist)
17341 (while pack-alist
17342 (setq pack-entry (car pack-alist)
17343 pack-key (nth 0 pack-entry)
17344 pack-body-key nil)
17345 (when (nth 2 pack-entry)
17346 (setq pack-file-name (if vhdl-compile-absolute-path
17347 (nth 2 pack-entry)
17348 (file-relative-name (nth 2 pack-entry)
17349 compile-directory))
17350 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17351 rule (vhdl-aget rule-alist pack-file-name)
17352 target-list (nth 0 rule) depend-list (nth 1 rule))
17353 (setq tmp-key (vhdl-replace-string
17354 pack-regexp
17355 (funcall adjust-case
17356 (concat pack-key " " work-library))))
17357 (push (cons pack-key tmp-key) unit-list)
17358 ;; rule target for this package
17359 (push pack-key target-list)
17360 ;; rule dependencies for all used packages
17361 (setq pack-list (vhdl-get-packages lib-alist work-library))
17362 (setq depend-list (append depend-list pack-list))
17363 (setq all-pack-list pack-list)
17364 ;; add rule
17365 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17366 ;; rules for this package's body
17367 (when (nth 7 pack-entry)
17368 (setq pack-body-key (concat pack-key "-body")
17369 pack-body-file-name (if vhdl-compile-absolute-path
17370 (nth 7 pack-entry)
17371 (file-relative-name (nth 7 pack-entry)
17372 compile-directory))
17373 rule (vhdl-aget rule-alist pack-body-file-name)
17374 target-list (nth 0 rule)
17375 depend-list (nth 1 rule))
17376 (setq tmp-key (vhdl-replace-string
17377 pack-body-regexp
17378 (funcall adjust-case
17379 (concat pack-key " " work-library))))
17380 (setq unit-list
17381 (cons (cons pack-body-key tmp-key) unit-list))
17382 ;; rule target for this package's body
17383 (push pack-body-key target-list)
17384 ;; rule dependency for corresponding package declaration
17385 (push pack-key depend-list)
17386 ;; rule dependencies for all used packages
17387 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17388 (setq depend-list (append depend-list pack-list))
17389 (setq all-pack-list (append all-pack-list pack-list))
17390 ;; add rule
17391 (vhdl-aput 'rule-alist pack-body-file-name
17392 (list target-list depend-list)))
17393 (setq prim-list
17394 (cons (list pack-key (when pack-body-key (list pack-body-key))
17395 all-pack-list)
17396 prim-list)))
17397 (setq pack-alist (cdr pack-alist)))
17398 (setq pack-alist tmp-list)
17399 ;; generate Makefile
17400 (let* ((project (vhdl-aget vhdl-project-alist project))
17401 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17402 (compiler-id (nth 9 compiler))
17403 (library-directory
17404 (vhdl-resolve-env-variable
17405 (vhdl-replace-string
17406 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17407 compiler-id)))
17408 (makefile-path-name (expand-file-name
17409 makefile-name compile-directory))
17410 (orig-buffer (current-buffer))
17411 cell second-list subcomp-list options unit-key unit-name)
17412 ;; sort lists
17413 (setq unit-list (vhdl-sort-alist unit-list))
17414 (setq prim-list (vhdl-sort-alist prim-list))
17415 (setq tmp-list rule-alist)
17416 (while tmp-list ; pre-sort rule targets
17417 (setq cell (cdar tmp-list))
17418 (setcar cell (sort (car cell) 'string<))
17419 (setq tmp-list (cdr tmp-list)))
17420 (setq rule-alist ; sort by first rule target
17421 (sort rule-alist
17422 (function (lambda (a b)
17423 (string< (car (cadr a)) (car (cadr b)))))))
17424 ;; open and clear Makefile
17425 (set-buffer (find-file-noselect makefile-path-name t t))
17426 (erase-buffer)
17427 (insert "# -*- Makefile -*-\n"
17428 "### " (file-name-nondirectory makefile-name)
17429 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17430 "\n")
17431 (if project
17432 (insert "\n# Project : " (nth 0 project))
17433 (insert "\n# Directory : \"" directory "\""))
17434 (insert "\n# Platform : " vhdl-compiler
17435 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17436 (user-login-name) "\n")
17437 ;; insert compile and option variable settings
17438 (insert "\n\n# Define compilation command and options\n"
17439 "\nCOMPILE = " (nth 0 compiler)
17440 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17441 (if (equal vhdl-compile-post-command "") ""
17442 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17443 "\n")
17444 ;; insert library paths
17445 (setq library-directory
17446 (directory-file-name
17447 (if (file-name-absolute-p library-directory)
17448 library-directory
17449 (file-relative-name
17450 (expand-file-name library-directory directory)
17451 compile-directory))))
17452 (insert "\n\n# Define library paths\n"
17453 "\nLIBRARY-" work-library " = " library-directory "\n")
17454 (unless mapping-exist
17455 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17456 ")/make" "\n"))
17457 ;; insert variable definitions for all library unit files
17458 (insert "\n\n# Define library unit files\n")
17459 (setq tmp-list unit-list)
17460 (while unit-list
17461 (insert "\nUNIT-" work-library "-" (caar unit-list)
17462 " = \\\n\t$(LIBRARY-" work-library
17463 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17464 (setq unit-list (cdr unit-list)))
17465 ;; insert variable definition for list of all library unit files
17466 (insert "\n\n\n# Define list of all library unit files\n"
17467 "\nALL_UNITS =")
17468 (setq unit-list tmp-list)
17469 (while unit-list
17470 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17471 (setq unit-list (cdr unit-list)))
17472 (insert "\n")
17473 (setq unit-list tmp-list)
17474 ;; insert `make all' rule
17475 (insert "\n\n\n# Rule for compiling entire design\n"
17476 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17477 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17478 " \\\n\t\t$(ALL_UNITS)\n")
17479 ;; insert `make clean' rule
17480 (insert "\n\n# Rule for cleaning entire design\n"
17481 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17482 "\n\t-rm -f $(ALL_UNITS)\n")
17483 ;; insert `make library' rule
17484 (insert "\n\n# Rule for creating library directory\n"
17485 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17486 " \\\n\t\t$(LIBRARY-" work-library ")"
17487 (if mapping-exist ""
17488 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17489 "\n"
17490 "\n$(LIBRARY-" work-library ") :"
17491 "\n\t"
17492 (vhdl-replace-string
17493 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17494 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17495 "\n")
17496 (unless mapping-exist
17497 (insert "\n$(LIBRARY-" work-library "-make) :"
17498 "\n\t"
17499 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17500 ;; insert '.PHONY' declaration
17501 (insert "\n\n.PHONY : "
17502 (nth 0 vhdl-makefile-default-targets) " "
17503 (nth 1 vhdl-makefile-default-targets) " "
17504 (nth 2 vhdl-makefile-default-targets) "\n")
17505 ;; insert rule for each library unit
17506 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17507 (while prim-list
17508 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17509 (setq subcomp-list
17510 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17511 (setq unit-key (caar prim-list)
17512 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17513 (nth 0 (vhdl-aget conf-alist unit-key))
17514 (nth 0 (vhdl-aget pack-alist unit-key))))
17515 (insert "\n" unit-key)
17516 (unless (equal unit-key unit-name)
17517 (insert " \\\n" unit-name))
17518 (insert " :"
17519 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17520 (while subcomp-list
17521 (when (and (assoc (car subcomp-list) unit-list)
17522 (not (equal unit-key (car subcomp-list))))
17523 (insert " \\\n\t\t" (car subcomp-list)))
17524 (setq subcomp-list (cdr subcomp-list)))
17525 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17526 (while second-list
17527 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17528 (setq second-list (cdr second-list)))
17529 (insert "\n")
17530 (setq prim-list (cdr prim-list)))
17531 ;; insert rule for each library unit file
17532 (insert "\n\n# Rules for compiling single library unit files\n")
17533 (while rule-alist
17534 (setq rule (car rule-alist))
17535 ;; get compiler options for this file
17536 (setq options
17537 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17538 ;; insert rule if file is supposed to be compiled
17539 (setq target-list (nth 1 rule)
17540 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17541 ;; insert targets
17542 (setq tmp-list target-list)
17543 (while target-list
17544 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17545 (if (cdr target-list) " \\" " :"))
17546 (setq target-list (cdr target-list)))
17547 (setq target-list tmp-list)
17548 ;; insert file name as first dependency
17549 (insert " \\\n\t\t" (nth 0 rule))
17550 ;; insert dependencies (except if also target or unit does not exist)
17551 (while depend-list
17552 (when (and (not (member (car depend-list) target-list))
17553 (assoc (car depend-list) unit-list))
17554 (insert " \\\n\t\t"
17555 "$(UNIT-" work-library "-" (car depend-list) ")"))
17556 (setq depend-list (cdr depend-list)))
17557 ;; insert compile command
17558 (if options
17559 (insert "\n\t$(COMPILE) "
17560 (if (eq options 'default) "$(OPTIONS)" options) " "
17561 (nth 0 rule)
17562 (if (equal vhdl-compile-post-command "") ""
17563 " $(POST-COMPILE)") "\n")
17564 (insert "\n"))
17565 (unless (and options mapping-exist)
17566 (setq tmp-list target-list)
17567 (while target-list
17568 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17569 (setq target-list (cdr target-list)))
17570 (setq target-list tmp-list))
17571 (setq rule-alist (cdr rule-alist)))
17572
17573 (insert "\n\n### " makefile-name " ends here\n")
17574 ;; run Makefile generation hook
17575 (run-hooks 'vhdl-makefile-generation-hook)
17576 (message "Generating makefile \"%s\"...done" makefile-name)
17577 ;; save and close file
17578 (if (file-writable-p makefile-path-name)
17579 (progn (save-buffer)
17580 (kill-buffer (current-buffer))
17581 (set-buffer orig-buffer)
17582 (when (fboundp 'add-to-history)
17583 (add-to-history 'file-name-history makefile-path-name)))
17584 (vhdl-warning-when-idle
17585 (format "File not writable: \"%s\""
17586 (abbreviate-file-name makefile-path-name)))
17587 (switch-to-buffer (current-buffer))))))
17588
17589
17590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17591 ;;; Bug reports
17592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17593 ;; (using `reporter.el')
17594
17595 (defconst vhdl-mode-help-address
17596 "Reto Zimmermann <reto@gnu.org>"
17597 "Address for VHDL Mode bug reports.")
17598
17599 (defun vhdl-submit-bug-report ()
17600 "Submit via mail a bug report on VHDL Mode."
17601 (interactive)
17602 ;; load in reporter
17603 (and
17604 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17605 (let ((reporter-prompt-for-summary-p t))
17606 (reporter-submit-bug-report
17607 vhdl-mode-help-address
17608 (concat "VHDL Mode " vhdl-version)
17609 (list
17610 ;; report all important user options
17611 'vhdl-offsets-alist
17612 'vhdl-comment-only-line-offset
17613 'tab-width
17614 'vhdl-electric-mode
17615 'vhdl-stutter-mode
17616 'vhdl-indent-tabs-mode
17617 'vhdl-project-alist
17618 'vhdl-project
17619 'vhdl-project-file-name
17620 'vhdl-project-auto-load
17621 'vhdl-project-sort
17622 'vhdl-compiler-alist
17623 'vhdl-compiler
17624 'vhdl-compile-use-local-error-regexp
17625 'vhdl-makefile-default-targets
17626 'vhdl-makefile-generation-hook
17627 'vhdl-default-library
17628 'vhdl-standard
17629 'vhdl-basic-offset
17630 'vhdl-upper-case-keywords
17631 'vhdl-upper-case-types
17632 'vhdl-upper-case-attributes
17633 'vhdl-upper-case-enum-values
17634 'vhdl-upper-case-constants
17635 'vhdl-use-direct-instantiation
17636 'vhdl-array-index-record-field-in-sensitivity-list
17637 'vhdl-compose-configuration-name
17638 'vhdl-entity-file-name
17639 'vhdl-architecture-file-name
17640 'vhdl-configuration-file-name
17641 'vhdl-package-file-name
17642 'vhdl-file-name-case
17643 'vhdl-electric-keywords
17644 'vhdl-optional-labels
17645 'vhdl-insert-empty-lines
17646 'vhdl-argument-list-indent
17647 'vhdl-association-list-with-formals
17648 'vhdl-conditions-in-parenthesis
17649 'vhdl-sensitivity-list-all
17650 'vhdl-zero-string
17651 'vhdl-one-string
17652 'vhdl-file-header
17653 'vhdl-file-footer
17654 'vhdl-company-name
17655 'vhdl-copyright-string
17656 'vhdl-platform-spec
17657 'vhdl-date-format
17658 'vhdl-modify-date-prefix-string
17659 'vhdl-modify-date-on-saving
17660 'vhdl-reset-kind
17661 'vhdl-reset-active-high
17662 'vhdl-clock-rising-edge
17663 'vhdl-clock-edge-condition
17664 'vhdl-clock-name
17665 'vhdl-reset-name
17666 'vhdl-model-alist
17667 'vhdl-include-port-comments
17668 'vhdl-include-direction-comments
17669 'vhdl-include-type-comments
17670 'vhdl-include-group-comments
17671 'vhdl-actual-generic-name
17672 'vhdl-actual-port-name
17673 'vhdl-instance-name
17674 'vhdl-testbench-entity-name
17675 'vhdl-testbench-architecture-name
17676 'vhdl-testbench-configuration-name
17677 'vhdl-testbench-dut-name
17678 'vhdl-testbench-include-header
17679 'vhdl-testbench-declarations
17680 'vhdl-testbench-statements
17681 'vhdl-testbench-initialize-signals
17682 'vhdl-testbench-include-library
17683 'vhdl-testbench-include-configuration
17684 'vhdl-testbench-create-files
17685 'vhdl-testbench-entity-file-name
17686 'vhdl-testbench-architecture-file-name
17687 'vhdl-compose-create-files
17688 'vhdl-compose-configuration-create-file
17689 'vhdl-compose-configuration-hierarchical
17690 'vhdl-compose-configuration-use-subconfiguration
17691 'vhdl-compose-include-header
17692 'vhdl-compose-architecture-name
17693 'vhdl-components-package-name
17694 'vhdl-use-components-package
17695 'vhdl-self-insert-comments
17696 'vhdl-prompt-for-comments
17697 'vhdl-inline-comment-column
17698 'vhdl-end-comment-column
17699 'vhdl-auto-align
17700 'vhdl-align-groups
17701 'vhdl-align-group-separate
17702 'vhdl-align-same-indent
17703 'vhdl-highlight-keywords
17704 'vhdl-highlight-names
17705 'vhdl-highlight-special-words
17706 'vhdl-highlight-forbidden-words
17707 'vhdl-highlight-verilog-keywords
17708 'vhdl-highlight-translate-off
17709 'vhdl-highlight-case-sensitive
17710 'vhdl-special-syntax-alist
17711 'vhdl-forbidden-words
17712 'vhdl-forbidden-syntax
17713 'vhdl-directive-keywords
17714 'vhdl-speedbar-auto-open
17715 'vhdl-speedbar-display-mode
17716 'vhdl-speedbar-scan-limit
17717 'vhdl-speedbar-jump-to-unit
17718 'vhdl-speedbar-update-on-saving
17719 'vhdl-speedbar-save-cache
17720 'vhdl-speedbar-cache-file-name
17721 'vhdl-index-menu
17722 'vhdl-source-file-menu
17723 'vhdl-hideshow-menu
17724 'vhdl-hide-all-init
17725 'vhdl-print-two-column
17726 'vhdl-print-customize-faces
17727 'vhdl-intelligent-tab
17728 'vhdl-indent-syntax-based
17729 'vhdl-indent-comment-like-next-code-line
17730 'vhdl-word-completion-case-sensitive
17731 'vhdl-word-completion-in-minibuffer
17732 'vhdl-underscore-is-part-of-word
17733 'vhdl-mode-hook)
17734 (function
17735 (lambda ()
17736 (insert
17737 (if vhdl-special-indent-hook
17738 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17739 "vhdl-special-indent-hook is set to '"
17740 (format "%s" vhdl-special-indent-hook)
17741 ".\nPerhaps this is your problem?\n"
17742 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17743 "\n"))))
17744 nil
17745 "Hi Reto,"))))
17746
17747
17748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17749 ;;; Documentation
17750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17751
17752 (defconst vhdl-doc-release-notes nil
17753 "\
17754 Release Notes for VHDL Mode 3.37
17755 ================================
17756
17757 - Added support for VHDL'08:
17758 - New keywords, types, functions, attributes, operators, packages
17759 - Context declaration
17760 - Block comments
17761 - Directives
17762 - 'all' keyword in sensitivity list
17763
17764
17765 Release Notes for VHDL Mode 3.34
17766 ================================
17767
17768 - Added support for GNU Emacs 22/23/24:
17769 - Compilation error parsing fixed for new `compile.el' package.
17770
17771 - Port translation: Derive actual generic name from formal generic name.
17772
17773 - New user options:
17774 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17775
17776
17777 Release Notes for VHDL Mode 3.33
17778 ================================
17779
17780 New Features
17781 ------------
17782
17783 CONFIGURATION DECLARATION GENERATION:
17784 - Automatic generation of a configuration declaration for a design.
17785 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17786
17787
17788 Key Bindings
17789 ------------
17790
17791 For Emacs compliance the following key bindings have been changed:
17792
17793 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17794 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17795 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17796 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17797
17798
17799 User Options
17800 ------------
17801
17802 `vhdl-configuration-file-name': (new)
17803 Specify how the configuration file name is obtained.
17804 `vhdl-compose-configuration-name': (new)
17805 Specify how the configuration name is obtained.
17806 `vhdl-compose-configuration-create-file': (new)
17807 Specify whether a new file should be created for a configuration.
17808 `vhdl-compose-configuration-hierarchical': (new)
17809 Specify whether hierarchical configurations should be created.
17810 `vhdl-compose-configuration-use-subconfiguration': (new)
17811 Specify whether subconfigurations should be used inside configurations.
17812 `vhdl-makefile-default-targets': (new)
17813 Customize names of Makefile default targets.
17814 `vhdl-indent-comment-like-next-code-line': (new)
17815 Specify whether comment lines are indented like following code line.
17816 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17817 Specify whether to include array indices / record fields in sensitivity list.
17818 ")
17819
17820
17821 (defconst vhdl-doc-keywords nil
17822 "\
17823 Reserved words in VHDL
17824 ----------------------
17825
17826 VHDL'08 (IEEE Std 1076-2008):
17827 `vhdl-08-keywords' : keywords
17828 `vhdl-08-types' : standardized types
17829 `vhdl-08-attributes' : standardized attributes
17830 `vhdl-08-functions' : standardized functions
17831 `vhdl-08-packages' : standardized packages and libraries
17832
17833 VHDL'93/02 (IEEE Std 1076-1993/2002):
17834 `vhdl-02-keywords' : keywords
17835 `vhdl-02-types' : standardized types
17836 `vhdl-02-attributes' : standardized attributes
17837 `vhdl-02-enum-values' : standardized enumeration values
17838 `vhdl-02-functions' : standardized functions
17839 `vhdl-02-packages' : standardized packages and libraries
17840
17841 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17842 `vhdl-ams-keywords' : keywords
17843 `vhdl-ams-types' : standardized types
17844 `vhdl-ams-attributes' : standardized attributes
17845 `vhdl-ams-enum-values' : standardized enumeration values
17846 `vhdl-ams-constants' : standardized constants
17847 `vhdl-ams-functions' : standardized functions
17848
17849 Math Packages (IEEE Std 1076.2):
17850 `vhdl-math-types' : standardized types
17851 `vhdl-math-constants' : standardized constants
17852 `vhdl-math-functions' : standardized functions
17853 `vhdl-math-packages' : standardized packages
17854
17855 Forbidden words:
17856 `vhdl-verilog-keywords' : Verilog reserved words
17857
17858 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17859
17860
17861 (defconst vhdl-doc-coding-style nil
17862 "\
17863 For VHDL coding style and naming convention guidelines, see the following
17864 references:
17865
17866 \[1] Ben Cohen.
17867 \"VHDL Coding Styles and Methodologies\".
17868 Kluwer Academic Publishers, 1999.
17869 http://members.aol.com/vhdlcohen/vhdl/
17870
17871 \[2] Michael Keating and Pierre Bricaud.
17872 \"Reuse Methodology Manual, Second Edition\".
17873 Kluwer Academic Publishers, 1999.
17874 http://www.openmore.com/openmore/rmm2.html
17875
17876 \[3] European Space Agency.
17877 \"VHDL Modelling Guidelines\".
17878 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17879
17880 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17881 to visually support naming conventions.")
17882
17883
17884 (defun vhdl-version ()
17885 "Echo the current version of VHDL Mode in the minibuffer."
17886 (interactive)
17887 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17888 (vhdl-keep-region-active))
17889
17890 (defun vhdl-doc-variable (variable)
17891 "Display VARIABLE's documentation in *Help* buffer."
17892 (interactive)
17893 (unless (featurep 'xemacs)
17894 (help-setup-xref (list #'vhdl-doc-variable variable)
17895 (called-interactively-p 'interactive)))
17896 (with-output-to-temp-buffer
17897 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17898 (princ (documentation-property variable 'variable-documentation))
17899 (with-current-buffer standard-output
17900 (help-mode))
17901 (help-print-return-message)))
17902
17903 (defun vhdl-doc-mode ()
17904 "Display VHDL Mode documentation in *Help* buffer."
17905 (interactive)
17906 (unless (featurep 'xemacs)
17907 (help-setup-xref (list #'vhdl-doc-mode)
17908 (called-interactively-p 'interactive)))
17909 (with-output-to-temp-buffer
17910 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17911 (princ mode-name)
17912 (princ " mode:\n")
17913 (princ (documentation 'vhdl-mode))
17914 (with-current-buffer standard-output
17915 (help-mode))
17916 (help-print-return-message)))
17917
17918
17919 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17920
17921 (provide 'vhdl-mode)
17922
17923 ;;; vhdl-mode.el ends here