]> code.delx.au - gnu-emacs/blob - lisp/progmodes/vhdl-mode.el
664642554fa8950e3724567f1c91b58e2890a8f4
[gnu-emacs] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992-2016 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 ;; ** Error: counter_rtl.vhd(18): Nonresolved signal 'hallo' has multiple sources.
270 ;; Drivers:
271 ;; counter_rtl.vhd(27):Conditional signal assignment line__27
272 ;; counter_rtl.vhd(29):Conditional signal assignment line__29
273 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
274 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
275 ("\\(ERROR:\\|WARNING\\[[0-9]+\\]:\\|\\*\\* Error:\\|\\*\\* Warning: \\[[0-9]+\\]\\| +\\) \\([^ ]+\\)(\\([0-9]+\\)):" 2 3 nil)
276 ("" 0)
277 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
278 "\\1/_primary.dat" "\\1/body.dat" downcase))
279 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
280 ;; test.vhd:34: error message
281 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
282 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
283 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
284 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
285 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
286 ;; Quartus compiler
287 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
288 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
289 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
290 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
291 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
292 ("Quartus" "make" "-work \\1" "make" "-f \\1"
293 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
294 ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
295 nil)
296 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
297 ;; ERROR: test.vhd(24): near "dnd": expecting: END
298 ;; WARNING[4]: test.vhd(30): A space is required between ...
299 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
300 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
301 ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
302 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
303 "\\1/_primary.dat" "\\1/body.dat" downcase))
304 ;; Savant: scram -publish-cc test.vhd
305 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
306 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
307 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
308 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
309 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
310 "\\1_config.vhdl" "\\1_package.vhdl"
311 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
312 ;; Simili: vhdlp -work test.vhd
313 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
314 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
316 ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
317 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
318 "\\1/prim.var" "\\1/_body.var" downcase))
319 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
320 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
321 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
322 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
323 ("^ *ERROR\\[[0-9]+]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
324 nil)
325 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
326 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
327 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
328 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
329 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
330 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
331 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
332 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
333 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
334 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
335 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
336 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
337 ;; Synplify:
338 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
339 ("Synplify" "n/a" "n/a" "make" "-f \\1"
340 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
341 ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
342 nil)
343 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
344 ;; Compiling "test.vhd" line 1...
345 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
346 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
347 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
348 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
349 ("^ *Compiling \"\\(.+\\)\" " 1)
350 nil)
351 ;; VeriBest: vc vhdl test.vhd
352 ;; (no file name printed out!)
353 ;; 32: Z <= A and BitA ;
354 ;; ^^^^
355 ;; [Error] Name BITA is unknown
356 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
357 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
358 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
359 nil)
360 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
361 ;; Compiling "test.vhd" line 1...
362 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
363 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
364 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
365 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
366 ("^ *Compiling \"\\(.+\\)\" " 1)
367 nil)
368 ;; Xilinx XST:
369 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
370 ("Xilinx XST" "xflow" "" "make" "-f \\1"
371 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
372 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\\." 1 2 nil) ("" 0)
373 nil)
374 )
375 "List of available VHDL compilers and their properties.
376 Each list entry specifies the following items for a compiler:
377 Compiler:
378 Compiler name : name used in option `vhdl-compiler' to choose compiler
379 Compile command : command used for source file compilation
380 Compile options : compile options (\"\\1\" inserts library name)
381 Make command : command used for compilation using a Makefile
382 Make options : make options (\"\\1\" inserts Makefile name)
383 Generate Makefile: use built-in function or command to generate a Makefile
384 (\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
385 Library command : command to create library directory (\"\\1\" inserts
386 library directory, \"\\2\" inserts library name)
387 Compile directory: where compilation is run and the Makefile is placed
388 Library directory: directory of default library
389 Makefile name : name of Makefile (default is \"Makefile\")
390 ID string : compiler identification string (see `vhdl-project-alist')
391 Error message:
392 Regexp : regular expression to match error messages (*)
393 File subexp index: index of subexpression that matches the file name
394 Line subexp index: index of subexpression that matches the line number
395 Column subexp idx: index of subexpression that matches the column number
396 File message:
397 Regexp : regular expression to match a file name message
398 File subexp index: index of subexpression that matches the file name
399 Unit-to-file name mapping: mapping of library unit names to names of files
400 generated by the compiler (used for Makefile generation)
401 To string : string a name is mapped to (\"\\1\" inserts the unit name,
402 \"\\2\" inserts the entity name for architectures,
403 \"\\3\" inserts the library name)
404 Case adjustment : adjust case of inserted unit names
405
406 \(*) The regular expression must match the error message starting from the
407 beginning of the line (but not necessarily to the end of the line).
408
409 Compile options allows insertion of the library name (see `vhdl-project-alist')
410 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
411
412 For Makefile generation, the built-in function can be used (requires
413 specification of the unit-to-file name mapping). Alternatively, an
414 external command can be specified. Work directory allows specification of
415 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
416 used for Makefile generation). To use another library name than \"work\",
417 customize `vhdl-project-alist'. The library command is inserted in Makefiles
418 to automatically create the library directory if not existent.
419
420 Compile options, compile directory, library directory, and Makefile name are
421 overwritten by the project settings if a project is defined (see
422 `vhdl-project-alist'). Directory paths are relative to the source file
423 directory.
424
425 Some compilers do not include the file name in the error message, but print
426 out a file name message in advance. In this case, set \"File Subexp Index\"
427 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
428 If no file name at all is printed out, set both \"File Message\" entries to 0
429 \(a default file name message will be printed out instead, does not work in
430 XEmacs).
431
432 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
433 assigning its name to option `vhdl-compiler'.
434
435 Please send any missing or erroneous compiler properties to the maintainer for
436 updating.
437
438 NOTE: Activate new error and file message regexps and reflect the new setting
439 in the choice list of option `vhdl-compiler' by restarting Emacs."
440 :type '(repeat
441 (list :tag "Compiler" :indent 2
442 (string :tag "Compiler name ")
443 (string :tag "Compile command ")
444 (string :tag "Compile options " "-work \\1")
445 (string :tag "Make command " "make")
446 (string :tag "Make options " "-f \\1")
447 (choice :tag "Generate Makefile "
448 (const :tag "Built-in function" nil)
449 (string :tag "Command" "vmake \\2 > \\1"))
450 (string :tag "Library command " "mkdir \\1")
451 (directory :tag "Compile directory "
452 :validate vhdl-widget-directory-validate "./")
453 (directory :tag "Library directory "
454 :validate vhdl-widget-directory-validate "work/")
455 (file :tag "Makefile name " "Makefile")
456 (string :tag "ID string ")
457 (list :tag "Error message" :indent 4
458 (regexp :tag "Regexp ")
459 (choice :tag "File subexp "
460 (integer :tag "Index")
461 (const :tag "No file name" nil))
462 (integer :tag "Line subexp index")
463 (choice :tag "Column subexp "
464 (integer :tag "Index")
465 (const :tag "No column number" nil)))
466 (list :tag "File message" :indent 4
467 (regexp :tag "Regexp ")
468 (integer :tag "File subexp index"))
469 (choice :tag "Unit-to-file name mapping"
470 :format "%t: %[Value Menu%] %v\n"
471 (const :tag "Not defined" nil)
472 (list :tag "To string" :indent 4
473 (string :tag "Entity " "\\1.vhd")
474 (string :tag "Architecture " "\\2_\\1.vhd")
475 (string :tag "Configuration " "\\1.vhd")
476 (string :tag "Package " "\\1.vhd")
477 (string :tag "Package Body " "\\1_body.vhd")
478 (choice :tag "Case adjustment "
479 (const :tag "None" identity)
480 (const :tag "Upcase" upcase)
481 (const :tag "Downcase" downcase))))))
482 :set (lambda (variable value)
483 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
484 :version "24.4"
485 :group 'vhdl-compile)
486
487 (defcustom vhdl-compiler "GHDL"
488 "Specifies the VHDL compiler to be used for syntax analysis.
489 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
490 :type (let ((alist vhdl-compiler-alist) list)
491 (while alist
492 (push (list 'const (caar alist)) list)
493 (setq alist (cdr alist)))
494 (append '(choice) (nreverse list)))
495 :group 'vhdl-compile)
496
497 (defcustom vhdl-compile-use-local-error-regexp nil
498 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
499 In this case, only error message regexps for VHDL compilers are active if
500 compilation is started from a VHDL buffer. Otherwise, the error message
501 regexps are appended to the predefined global regexps, and all regexps are
502 active all the time. Note that by doing that, the predefined global regexps
503 might result in erroneous parsing of error messages for some VHDL compilers.
504
505 NOTE: Activate the new setting by restarting Emacs."
506 :version "25.1" ; t -> nil
507 :type 'boolean
508 :group 'vhdl-compile)
509
510 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
511 "List of default target names in Makefiles.
512 Automatically generated Makefiles include three default targets to compile
513 the entire design, clean the entire design and to create the design library.
514 This option allows you to change the names of these targets to avoid conflicts
515 with other user Makefiles."
516 :type '(list (string :tag "Compile entire design")
517 (string :tag "Clean entire design ")
518 (string :tag "Create design library"))
519 :version "24.3"
520 :group 'vhdl-compile)
521
522 (defcustom vhdl-makefile-generation-hook nil
523 "Functions to run at the end of Makefile generation.
524 Allows you to insert user specific parts into a Makefile.
525
526 Example:
527 (lambda nil
528 (re-search-backward \"^# Rule for compiling entire design\")
529 (insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
530 :type 'hook
531 :group 'vhdl-compile)
532
533 (defcustom vhdl-default-library "work"
534 "Name of default library.
535 Is overwritten by project settings if a project is active."
536 :type 'string
537 :group 'vhdl-compile)
538
539
540 (defgroup vhdl-project nil
541 "Customizations for projects."
542 :group 'vhdl)
543
544 (defcustom vhdl-project-alist
545 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
546 "~/example1/" ("src/system/" "src/components/") ""
547 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
548 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
549 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
550 ("Example 2" "Individual source files, multiple compilers in different directories"
551 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
552 nil "\\1/" "work" "\\1/work/" "Makefile" "")
553 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
554 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
555 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
556 -------------------------------------------------------------------------------
557 -- This is a multi-line project description
558 -- that can be used as a project dependent part of the file header.
559 "))
560 "List of projects and their properties.
561 Name : name used in option `vhdl-project' to choose project
562 Title : title of project (single-line string)
563 Default directory: default project directory (absolute path)
564 Sources : a) source files : path + \"/\" + file name
565 b) directory : path + \"/\"
566 c) directory tree: \"-r \" + path + \"/\"
567 Exclude regexp : matches file/directory names to be excluded as sources
568 Compile options : project-specific options for each compiler
569 Compiler name : name of compiler for which these options are valid
570 Compile options: project-specific compiler options
571 (\"\\1\" inserts library name, \"\\2\" default options)
572 Make options: project-specific make options
573 (\"\\1\" inserts Makefile name, \"\\2\" default options)
574 Exceptions : file-specific exceptions
575 File name regexp: matches file names for which exceptions are valid
576 - Options : file-specific compiler options string
577 (\"\\1\" inserts library name, \"\\2\" default options,
578 \"\\3\" project-specific options)
579 - Do not compile: do not compile this file (in Makefile)
580 Compile directory: where compilation is run and the Makefile is placed
581 (\"\\1\" inserts compiler ID string)
582 Library name : name of library (default is \"work\")
583 Library directory: path to library (\"\\1\" inserts compiler ID string)
584 Makefile name : name of Makefile
585 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
586 Description : description of project (multi-line string)
587
588 Project title and description are used to insert into the file header (see
589 option `vhdl-file-header').
590
591 The default directory must have an absolute path (use `M-TAB' for completion).
592 All other paths can be absolute or relative to the default directory. All
593 paths must end with `/'.
594
595 The design units found in the sources (files and directories) are shown in the
596 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
597 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
598 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
599 specified, the default directory is taken as source directory. Otherwise,
600 the default directory is only taken as source directory if there is a sources
601 entry with the empty string or \"./\". Exclude regexp allows you to filter
602 out specific file and directory names from the list of sources (e.g. CVS
603 directories).
604
605 Files are compiled in the compile directory. Makefiles are also placed into
606 the compile directory. Library directory specifies which directory the
607 compiler compiles into (used to generate the Makefile).
608
609 Since different compile/library directories and Makefiles may exist for
610 different compilers within one project, these paths and names allow the
611 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
612 Compile options, compile directory, library directory, and Makefile name
613 overwrite the settings of the current compiler.
614
615 File-specific compiler options (highest priority) overwrite project-specific
616 options which overwrite default options (lowest priority). Lower priority
617 options can be inserted in higher priority options. This allows you to reuse
618 default options (e.g. \"-file\") in project- or file-specific options (e.g.
619 \"-93 -file\").
620
621 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
622 by restarting Emacs."
623 :type `(repeat
624 (list :tag "Project" :indent 2
625 (string :tag "Name ")
626 (string :tag "Title ")
627 (directory :tag "Default directory"
628 :validate vhdl-widget-directory-validate
629 ,(abbreviate-file-name default-directory))
630 (repeat :tag "Sources " :indent 4
631 (directory :format " %v" "./"))
632 (regexp :tag "Exclude regexp ")
633 (repeat
634 :tag "Compile options " :indent 4
635 (list :tag "Compiler" :indent 6
636 ,(let ((alist vhdl-compiler-alist) list)
637 (while alist
638 (push (list 'const (caar alist)) list)
639 (setq alist (cdr alist)))
640 (append '(choice :tag "Compiler name")
641 (nreverse list)))
642 (string :tag "Compile options" "\\2")
643 (string :tag "Make options " "\\2")
644 (repeat
645 :tag "Exceptions " :indent 8
646 (cons :format "%v"
647 (regexp :tag "File name regexp ")
648 (choice :format "%[Value Menu%] %v"
649 (string :tag "Options" "\\3")
650 (const :tag "Do not compile" nil))))))
651 (directory :tag "Compile directory"
652 :validate vhdl-widget-directory-validate "./")
653 (string :tag "Library name " "work")
654 (directory :tag "Library directory"
655 :validate vhdl-widget-directory-validate "work/")
656 (file :tag "Makefile name " "Makefile")
657 (string :tag "Description: (type `C-j' for newline)"
658 :format "%t\n%v\n")))
659 :set (lambda (variable value)
660 (vhdl-custom-set variable value
661 'vhdl-update-mode-menu
662 'vhdl-speedbar-refresh))
663 :group 'vhdl-project)
664
665 (defcustom vhdl-project nil
666 "Specifies the default for the current project.
667 Select a project name from the ones defined in option `vhdl-project-alist'.
668 Is used to determine the project title and description to be inserted in file
669 headers and the source files/directories to be scanned in the hierarchy
670 browser. The current project can also be changed temporarily in the menu."
671 :type (let ((alist vhdl-project-alist) list)
672 (while alist
673 (push (list 'const (caar alist)) list)
674 (setq alist (cdr alist)))
675 (append '(choice (const :tag "None" nil) (const :tag "--"))
676 (nreverse list)))
677 :group 'vhdl-project)
678
679 (defcustom vhdl-project-file-name '("\\1.prj")
680 "List of file names/paths for importing/exporting project setups.
681 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
682 replaced by the user name (allows you to have user-specific project setups).
683 The first entry is used as file name to import/export individual project
684 setups. All entries are used to automatically import project setups at
685 startup (see option `vhdl-project-auto-load'). Projects loaded from the
686 first entry are automatically made current. Hint: specify local project
687 setups in first entry, global setups in following entries; loading a local
688 project setup will make it current, while loading the global setups
689 is done without changing the current project.
690 Names can also have an absolute path (i.e. project setups can be stored
691 in global directories)."
692 :type '(repeat (string :tag "File name" "\\1.prj"))
693 :group 'vhdl-project)
694
695 (defcustom vhdl-project-auto-load '(startup)
696 "Automatically load project setups from files.
697 All project setup files that match the file names specified in option
698 `vhdl-project-file-name' are automatically loaded. The project of the
699 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
700 entry is activated.
701 A project setup file can be obtained by exporting a project (see menu).
702 At startup: project setup file is loaded at Emacs startup"
703 :type '(set (const :tag "At startup" startup))
704 :group 'vhdl-project)
705
706 (defcustom vhdl-project-sort t
707 "Non-nil means projects are displayed in alphabetical order."
708 :type 'boolean
709 :group 'vhdl-project)
710
711
712 (defgroup vhdl-style nil
713 "Customizations for coding styles."
714 :group 'vhdl
715 :group 'vhdl-template
716 :group 'vhdl-port
717 :group 'vhdl-compose)
718
719 (defcustom vhdl-standard '(93 nil)
720 "VHDL standards used.
721 Basic standard:
722 VHDL'87 : IEEE Std 1076-1987
723 VHDL'93/02 : IEEE Std 1076-1993/2002
724 VHDL'08 : IEEE Std 1076-2008
725 Additional standards:
726 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
727 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
728
729 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
730 \"Activate Options\"."
731 :type '(list (choice :tag "Basic standard"
732 (const :tag "VHDL'87" 87)
733 (const :tag "VHDL'93/02" 93)
734 (const :tag "VHDL'08" 08))
735 (set :tag "Additional standards" :indent 2
736 (const :tag "VHDL-AMS" ams)
737 (const :tag "Math packages" math)))
738 :set (lambda (variable value)
739 (vhdl-custom-set variable value
740 'vhdl-template-map-init
741 'vhdl-mode-abbrev-table-init
742 'vhdl-template-construct-alist-init
743 'vhdl-template-package-alist-init
744 'vhdl-update-mode-menu
745 'vhdl-words-init 'vhdl-font-lock-init))
746 :group 'vhdl-style)
747
748 (defcustom vhdl-basic-offset 2
749 "Amount of basic offset used for indentation.
750 This value is used by + and - symbols in `vhdl-offsets-alist'."
751 :type 'integer
752 :group 'vhdl-style)
753
754 (defcustom vhdl-upper-case-keywords nil
755 "Non-nil means convert keywords to upper case.
756 This is done when typed or expanded or by the fix case functions."
757 :type 'boolean
758 :set (lambda (variable value)
759 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
760 :group 'vhdl-style)
761
762 (defcustom vhdl-upper-case-types nil
763 "Non-nil means convert standardized types to upper case.
764 This is done when expanded or by the fix case functions."
765 :type 'boolean
766 :set (lambda (variable value)
767 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
768 :group 'vhdl-style)
769
770 (defcustom vhdl-upper-case-attributes nil
771 "Non-nil means convert standardized attributes to upper case.
772 This is done when expanded or by the fix case functions."
773 :type 'boolean
774 :set (lambda (variable value)
775 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
776 :group 'vhdl-style)
777
778 (defcustom vhdl-upper-case-enum-values nil
779 "Non-nil means convert standardized enumeration values to upper case.
780 This is done when expanded or by the fix case functions."
781 :type 'boolean
782 :set (lambda (variable value)
783 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
784 :group 'vhdl-style)
785
786 (defcustom vhdl-upper-case-constants t
787 "Non-nil means convert standardized constants to upper case.
788 This is done when expanded."
789 :type 'boolean
790 :set (lambda (variable value)
791 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
792 :group 'vhdl-style)
793
794 (defcustom vhdl-use-direct-instantiation 'standard
795 "Non-nil means use VHDL'93 direct component instantiation.
796 Never : never
797 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
798 Always : always"
799 :type '(choice (const :tag "Never" never)
800 (const :tag "Standard" standard)
801 (const :tag "Always" always))
802 :group 'vhdl-style)
803
804 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
805 "Non-nil means include array indices / record fields in sensitivity list.
806 If a signal read in a process is a record field or pointed to by an array
807 index, the record field or array index is included with the record name in
808 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
809 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
810 :type 'boolean
811 :version "24.3"
812 :group 'vhdl-style)
813
814 (defgroup vhdl-naming nil
815 "Customizations for naming conventions."
816 :group 'vhdl)
817
818 (defcustom vhdl-entity-file-name '(".*" . "\\&")
819 (concat
820 "Specifies how the entity file name is obtained.
821 The entity file name can be obtained by modifying the entity name (e.g.
822 attaching or stripping off a substring). The file extension is automatically
823 taken from the file name of the current buffer."
824 vhdl-name-doc-string)
825 :type '(cons (regexp :tag "From regexp")
826 (string :tag "To string "))
827 :group 'vhdl-naming
828 :group 'vhdl-compose)
829
830 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
831 (concat
832 "Specifies how the architecture file name is obtained.
833 The architecture file name can be obtained by modifying the entity
834 and/or architecture name (e.g. attaching or stripping off a substring). The
835 file extension is automatically taken from the file name of the current
836 buffer. The string that is matched against the regexp is the concatenation
837 of the entity and the architecture name separated by a space. This gives
838 access to both names (see default setting as example)."
839 vhdl-name-doc-string)
840 :type '(cons (regexp :tag "From regexp")
841 (string :tag "To string "))
842 :group 'vhdl-naming
843 :group 'vhdl-compose)
844
845 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
846 (concat
847 "Specifies how the configuration file name is obtained.
848 The configuration file name can be obtained by modifying the configuration
849 name (e.g. attaching or stripping off a substring). The file extension is
850 automatically taken from the file name of the current buffer."
851 vhdl-name-doc-string)
852 :type '(cons (regexp :tag "From regexp")
853 (string :tag "To string "))
854 :group 'vhdl-naming
855 :group 'vhdl-compose)
856
857 (defcustom vhdl-package-file-name '(".*" . "\\&")
858 (concat
859 "Specifies how the package file name is obtained.
860 The package file name can be obtained by modifying the package name (e.g.
861 attaching or stripping off a substring). The file extension is automatically
862 taken from the file name of the current buffer. Package files can be created
863 in a different directory by prepending a relative or absolute path to the
864 file name."
865 vhdl-name-doc-string)
866 :type '(cons (regexp :tag "From regexp")
867 (string :tag "To string "))
868 :group 'vhdl-naming
869 :group 'vhdl-compose)
870
871 (defcustom vhdl-file-name-case 'identity
872 "Specifies how to change case for obtaining file names.
873 When deriving a file name from a VHDL unit name, case can be changed as
874 follows:
875 As Is: case is not changed (taken as is)
876 Lower Case: whole name is changed to lower case
877 Upper Case: whole name is changed to upper case
878 Capitalize: first letter of each word in name is capitalized"
879 :type '(choice (const :tag "As Is" identity)
880 (const :tag "Lower Case" downcase)
881 (const :tag "Upper Case" upcase)
882 (const :tag "Capitalize" capitalize))
883 :group 'vhdl-naming
884 :group 'vhdl-compose)
885
886
887 (defgroup vhdl-template nil
888 "Customizations for electrification."
889 :group 'vhdl)
890
891 (defcustom vhdl-electric-keywords '(vhdl user)
892 "Type of keywords for which electrification is enabled.
893 VHDL keywords: invoke built-in templates
894 User keywords: invoke user models (see option `vhdl-model-alist')"
895 :type '(set (const :tag "VHDL keywords" vhdl)
896 (const :tag "User model keywords" user))
897 :set (lambda (variable value)
898 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
899 :group 'vhdl-template)
900
901 (defcustom vhdl-optional-labels 'process
902 "Constructs for which labels are to be queried.
903 Template generators prompt for optional labels for:
904 None : no constructs
905 Processes only: processes only (also procedurals in VHDL-AMS)
906 All constructs: all constructs with optional labels and keyword END"
907 :type '(choice (const :tag "None" none)
908 (const :tag "Processes only" process)
909 (const :tag "All constructs" all))
910 :group 'vhdl-template)
911
912 (defcustom vhdl-insert-empty-lines 'unit
913 "Specifies whether to insert empty lines in some templates.
914 This improves readability of code. Empty lines are inserted in:
915 None : no constructs
916 Design units only: entities, architectures, configurations, packages only
917 All constructs : also all constructs with BEGIN...END parts
918
919 Replaces option `vhdl-additional-empty-lines'."
920 :type '(choice (const :tag "None" none)
921 (const :tag "Design units only" unit)
922 (const :tag "All constructs" all))
923 :group 'vhdl-template
924 :group 'vhdl-port
925 :group 'vhdl-compose)
926
927 (defcustom vhdl-argument-list-indent nil
928 "Non-nil means indent argument lists relative to opening parenthesis.
929 That is, argument, association, and port lists start on the same line as the
930 opening parenthesis and subsequent lines are indented accordingly.
931 Otherwise, lists start on a new line and are indented as normal code."
932 :type 'boolean
933 :group 'vhdl-template
934 :group 'vhdl-port
935 :group 'vhdl-compose)
936
937 (defcustom vhdl-association-list-with-formals t
938 "Non-nil means write association lists with formal parameters.
939 Templates prompt for formal and actual parameters (ports/generics).
940 When pasting component instantiations, formals are included.
941 If nil, only a list of actual parameters is entered."
942 :type 'boolean
943 :group 'vhdl-template
944 :group 'vhdl-port
945 :group 'vhdl-compose)
946
947 (defcustom vhdl-conditions-in-parenthesis nil
948 "Non-nil means place parenthesis around condition expressions."
949 :type 'boolean
950 :group 'vhdl-template)
951
952 (defcustom vhdl-sensitivity-list-all t
953 "Non-nil means use `all' keyword in sensitivity list."
954 :version "25.1"
955 :type 'boolean
956 :group 'vhdl-template)
957
958 (defcustom vhdl-zero-string "'0'"
959 "String to use for a logic zero."
960 :type 'string
961 :group 'vhdl-template)
962
963 (defcustom vhdl-one-string "'1'"
964 "String to use for a logic one."
965 :type 'string
966 :group 'vhdl-template)
967
968
969 (defgroup vhdl-header nil
970 "Customizations for file header."
971 :group 'vhdl-template
972 :group 'vhdl-compose)
973
974 (defcustom vhdl-file-header "\
975 -------------------------------------------------------------------------------
976 -- Title : <title string>
977 -- Project : <project>
978 -------------------------------------------------------------------------------
979 -- File : <filename>
980 -- Author : <author>
981 -- Company : <company>
982 -- Created : <date>
983 -- Last update: <date>
984 -- Platform : <platform>
985 -- Standard : <standard>
986 <projectdesc>-------------------------------------------------------------------------------
987 -- Description: <cursor>
988 <copyright>-------------------------------------------------------------------------------
989 -- Revisions :
990 -- Date Version Author Description
991 -- <date> 1.0 <login>\tCreated
992 -------------------------------------------------------------------------------
993
994 "
995 "String or file to insert as file header.
996 If the string specifies an existing file name, the contents of the file is
997 inserted, otherwise the string itself is inserted as file header.
998 Type `C-j' for newlines.
999 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
1000 if the header needs to be version controlled.
1001
1002 The following keywords for template generation are supported:
1003 <filename> : replaced by the name of the buffer
1004 <author> : replaced by the user name and email address
1005 (`user-full-name',`mail-host-address', `user-mail-address')
1006 <authorfull> : replaced by the user full name (`user-full-name')
1007 <login> : replaced by user login name (`user-login-name')
1008 <company> : replaced by contents of option `vhdl-company-name'
1009 <date> : replaced by the current date
1010 <year> : replaced by the current year
1011 <project> : replaced by title of current project (`vhdl-project')
1012 <projectdesc> : replaced by description of current project (`vhdl-project')
1013 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1014 <platform> : replaced by contents of option `vhdl-platform-spec'
1015 <standard> : replaced by the VHDL language standard(s) used
1016 <... string> : replaced by a queried string (\"...\" is the prompt word)
1017 <title string>: replaced by file title in automatically generated files
1018 <cursor> : final cursor position
1019
1020 The (multi-line) project description <projectdesc> can be used as a project
1021 dependent part of the file header and can also contain the above keywords."
1022 :type 'string
1023 :group 'vhdl-header)
1024
1025 (defcustom vhdl-file-footer ""
1026 "String or file to insert as file footer.
1027 If the string specifies an existing file name, the contents of the file is
1028 inserted, otherwise the string itself is inserted as file footer (i.e. at
1029 the end of the file).
1030 Type `C-j' for newlines.
1031 The same keywords as in option `vhdl-file-header' can be used."
1032 :type 'string
1033 :group 'vhdl-header)
1034
1035 (defcustom vhdl-company-name ""
1036 "Name of company to insert in file header.
1037 See option `vhdl-file-header'."
1038 :type 'string
1039 :group 'vhdl-header)
1040
1041 (defcustom vhdl-copyright-string "\
1042 -------------------------------------------------------------------------------
1043 -- Copyright (c) <year> <company>
1044 "
1045 "Copyright string to insert in file header.
1046 Can be multi-line string (type `C-j' for newline) and contain other file
1047 header keywords (see option `vhdl-file-header')."
1048 :type 'string
1049 :group 'vhdl-header)
1050
1051 (defcustom vhdl-platform-spec ""
1052 "Specification of VHDL platform to insert in file header.
1053 The platform specification should contain names and versions of the
1054 simulation and synthesis tools used.
1055 See option `vhdl-file-header'."
1056 :type 'string
1057 :group 'vhdl-header)
1058
1059 (defcustom vhdl-date-format "%Y-%m-%d"
1060 "Specifies the date format to use in the header.
1061 This string is passed as argument to the command `format-time-string'.
1062 For more information on format strings, see the documentation for the
1063 `format-time-string' command (C-h f `format-time-string')."
1064 :type 'string
1065 :group 'vhdl-header)
1066
1067 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1068 "Prefix string of modification date in VHDL file header.
1069 If actualization of the modification date is called (menu,
1070 `\\[vhdl-template-modify]'), this string is searched and the rest
1071 of the line replaced by the current date."
1072 :type 'string
1073 :group 'vhdl-header)
1074
1075 (defcustom vhdl-modify-date-on-saving t
1076 "Non-nil means update the modification date when the buffer is saved.
1077 Calls function `\\[vhdl-template-modify]').
1078
1079 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1080 \"Activate Options\"."
1081 :type 'boolean
1082 :group 'vhdl-header)
1083
1084
1085 (defgroup vhdl-sequential-process nil
1086 "Customizations for sequential processes."
1087 :group 'vhdl-template)
1088
1089 (defcustom vhdl-reset-kind 'async
1090 "Specifies which kind of reset to use in sequential processes."
1091 :type '(choice (const :tag "None" none)
1092 (const :tag "Synchronous" sync)
1093 (const :tag "Asynchronous" async)
1094 (const :tag "Query" query))
1095 :group 'vhdl-sequential-process)
1096
1097 (defcustom vhdl-reset-active-high nil
1098 "Non-nil means reset in sequential processes is active high.
1099 Otherwise, reset is active low."
1100 :type 'boolean
1101 :group 'vhdl-sequential-process)
1102
1103 (defcustom vhdl-clock-rising-edge t
1104 "Non-nil means rising edge of clock triggers sequential processes.
1105 Otherwise, falling edge triggers."
1106 :type 'boolean
1107 :group 'vhdl-sequential-process)
1108
1109 (defcustom vhdl-clock-edge-condition 'standard
1110 "Syntax of the clock edge condition.
1111 Standard: \"clk\\='event and clk = \\='1\\='\"
1112 Function: \"rising_edge(clk)\""
1113 :type '(choice (const :tag "Standard" standard)
1114 (const :tag "Function" function))
1115 :group 'vhdl-sequential-process)
1116
1117 (defcustom vhdl-clock-name ""
1118 "Name of clock signal to use in templates."
1119 :type 'string
1120 :group 'vhdl-sequential-process)
1121
1122 (defcustom vhdl-reset-name ""
1123 "Name of reset signal to use in templates."
1124 :type 'string
1125 :group 'vhdl-sequential-process)
1126
1127
1128 (defgroup vhdl-model nil
1129 "Customizations for user models."
1130 :group 'vhdl)
1131
1132 (defcustom vhdl-model-alist
1133 '(("Example Model"
1134 "<label> : process (<clock>, <reset>)
1135 begin -- process <label>
1136 if <reset> = '0' then -- asynchronous reset (active low)
1137 <cursor>
1138 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1139 if <enable> = '1' then -- synchronous load
1140
1141 end if;
1142 end if;
1143 end process <label>;"
1144 "e" ""))
1145 "List of user models.
1146 VHDL models (templates) can be specified by the user in this list. They can be
1147 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1148 electrification (i.e. overriding existing or creating new keywords, see
1149 option `vhdl-electric-keywords').
1150 Name : name of model (string of words and spaces)
1151 String : string or name of file to be inserted as model (newline: `C-j')
1152 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1153 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1154 Keyword : keyword to invoke model
1155
1156 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1157 A prompt that appears several times is queried once and replaced throughout
1158 the model. Special prompts are:
1159 <clock> : name specified in `vhdl-clock-name' (if not empty)
1160 <reset> : name specified in `vhdl-reset-name' (if not empty)
1161 <cursor>: final cursor position
1162 File header prompts (see variable `vhdl-file-header') are automatically
1163 replaced, so that user models can also be used to insert different types of
1164 headers.
1165
1166 If the string specifies an existing file name, the contents of the file is
1167 inserted, otherwise the string itself is inserted.
1168 The code within the models should be correctly indented.
1169 Type `C-j' for newlines.
1170
1171 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1172 \"Activate Options\"."
1173 :type '(repeat (list :tag "Model" :indent 2
1174 (string :tag "Name ")
1175 (string :tag "String : (type `C-j' for newline)"
1176 :format "%t\n%v")
1177 (sexp :tag "Key binding" x)
1178 (string :tag "Keyword " :format "%t: %v\n")))
1179 :set (lambda (variable value)
1180 (vhdl-custom-set variable value
1181 'vhdl-model-map-init
1182 'vhdl-model-defun
1183 'vhdl-mode-abbrev-table-init
1184 'vhdl-update-mode-menu))
1185 :group 'vhdl-model)
1186
1187
1188 (defgroup vhdl-compose nil
1189 "Customizations for structural composition."
1190 :group 'vhdl)
1191
1192 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1193 (concat
1194 "Specifies how the component architecture name is obtained.
1195 The component architecture name can be obtained by modifying the entity name
1196 \(e.g. attaching or stripping off a substring).
1197 If TO STRING is empty, the architecture name is queried."
1198 vhdl-name-doc-string)
1199 :type '(cons (regexp :tag "From regexp")
1200 (string :tag "To string "))
1201 :group 'vhdl-compose)
1202
1203 (defcustom vhdl-compose-configuration-name
1204 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1205 (concat
1206 "Specifies how the configuration name is obtained.
1207 The configuration name can be obtained by modifying the entity and/or
1208 architecture name (e.g. attaching or stripping off a substring). The string
1209 that is matched against the regexp is the concatenation of the entity and the
1210 architecture name separated by a space. This gives access to both names (see
1211 default setting as example)."
1212 vhdl-name-doc-string)
1213 :type '(cons (regexp :tag "From regexp")
1214 (string :tag "To string "))
1215 :group 'vhdl-compose)
1216
1217 (defcustom vhdl-components-package-name
1218 '((".*" . "\\&_components") . "components")
1219 (concat
1220 "Specifies how the name for the components package is obtained.
1221 The components package is a package containing all component declarations for
1222 the current design. Its name can be obtained by modifying the project name
1223 \(e.g. attaching or stripping off a substring). If no project is defined, the
1224 DIRECTORY entry is chosen."
1225 vhdl-name-doc-string)
1226 :type '(cons (cons :tag "Project" :indent 2
1227 (regexp :tag "From regexp")
1228 (string :tag "To string "))
1229 (string :tag "Directory:\n String "))
1230 :group 'vhdl-compose)
1231
1232 (defcustom vhdl-use-components-package nil
1233 "Non-nil means use a separate components package for component declarations.
1234 Otherwise, component declarations are inserted and searched for in the
1235 architecture declarative parts."
1236 :type 'boolean
1237 :group 'vhdl-compose)
1238
1239 (defcustom vhdl-compose-include-header t
1240 "Non-nil means include a header in automatically generated files."
1241 :type 'boolean
1242 :group 'vhdl-compose)
1243
1244 (defcustom vhdl-compose-create-files 'single
1245 "Specifies whether new files should be created for the new component.
1246 The component's entity and architecture are inserted:
1247 None : in current buffer
1248 Single file : in new single file
1249 Separate files: in two separate files
1250 The file names are obtained from variables `vhdl-entity-file-name' and
1251 `vhdl-architecture-file-name'."
1252 :type '(choice (const :tag "None" none)
1253 (const :tag "Single file" single)
1254 (const :tag "Separate files" separate))
1255 :group 'vhdl-compose)
1256
1257 (defcustom vhdl-compose-configuration-create-file nil
1258 "Specifies whether a new file should be created for the configuration.
1259 If non-nil, a new file is created for the configuration.
1260 The file name is obtained from variable `vhdl-configuration-file-name'."
1261 :type 'boolean
1262 :group 'vhdl-compose)
1263
1264 (defcustom vhdl-compose-configuration-hierarchical t
1265 "Specifies whether hierarchical configurations should be created.
1266 If non-nil, automatically created configurations are hierarchical and include
1267 the whole hierarchy of subcomponents. Otherwise the configuration only
1268 includes one level of subcomponents."
1269 :type 'boolean
1270 :group 'vhdl-compose)
1271
1272 (defcustom vhdl-compose-configuration-use-subconfiguration t
1273 "Specifies whether subconfigurations should be used inside configurations.
1274 If non-nil, automatically created configurations use configurations in binding
1275 indications for subcomponents, if such configurations exist. Otherwise,
1276 entities are used in binding indications for subcomponents."
1277 :type 'boolean
1278 :group 'vhdl-compose)
1279
1280
1281 (defgroup vhdl-port nil
1282 "Customizations for port translation functions."
1283 :group 'vhdl
1284 :group 'vhdl-compose)
1285
1286 (defcustom vhdl-include-port-comments nil
1287 "Non-nil means include port comments when a port is pasted."
1288 :type 'boolean
1289 :group 'vhdl-port)
1290
1291 (defcustom vhdl-include-direction-comments nil
1292 "Non-nil means include port direction in instantiations as comments."
1293 :type 'boolean
1294 :group 'vhdl-port)
1295
1296 (defcustom vhdl-include-type-comments nil
1297 "Non-nil means include generic/port type in instantiations as comments."
1298 :type 'boolean
1299 :group 'vhdl-port)
1300
1301 (defcustom vhdl-include-group-comments 'never
1302 "Specifies whether to include group comments and spacings.
1303 The comments and empty lines between groups of ports are pasted:
1304 Never : never
1305 Declarations: in entity/component/constant/signal declarations only
1306 Always : also in generic/port maps"
1307 :type '(choice (const :tag "Never" never)
1308 (const :tag "Declarations" decl)
1309 (const :tag "Always" always))
1310 :group 'vhdl-port)
1311
1312 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1313 (concat
1314 "Specifies how actual generic names are obtained from formal generic names.
1315 In a component instantiation, an actual generic name can be
1316 obtained by modifying the formal generic name (e.g. attaching or stripping
1317 off a substring)."
1318 vhdl-name-doc-string)
1319 :type '(cons (regexp :tag "From regexp")
1320 (string :tag "To string "))
1321 :group 'vhdl-port
1322 :version "24.4")
1323
1324 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1325 (concat
1326 "Specifies how actual port names are obtained from formal port names.
1327 In a component instantiation, an actual port name can be obtained by
1328 modifying the formal port name (e.g. attaching or stripping off a substring)."
1329 vhdl-name-doc-string)
1330 :type '(cons (regexp :tag "From regexp")
1331 (string :tag "To string "))
1332 :group 'vhdl-port)
1333
1334 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1335 (concat
1336 "Specifies how an instance name is obtained.
1337 The instance name can be obtained by modifying the name of the component to be
1338 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1339 by a unique number (starting with 1).
1340 If TO STRING is empty, the instance name is queried."
1341 vhdl-name-doc-string)
1342 :type '(cons (regexp :tag "From regexp")
1343 (string :tag "To string "))
1344 :group 'vhdl-port)
1345
1346
1347 (defgroup vhdl-testbench nil
1348 "Customizations for testbench generation."
1349 :group 'vhdl-port)
1350
1351 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1352 (concat
1353 "Specifies how the testbench entity name is obtained.
1354 The entity name of a testbench can be obtained by modifying the name of
1355 the component to be tested (e.g. attaching or stripping off a substring)."
1356 vhdl-name-doc-string)
1357 :type '(cons (regexp :tag "From regexp")
1358 (string :tag "To string "))
1359 :group 'vhdl-testbench)
1360
1361 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1362 (concat
1363 "Specifies how the testbench architecture name is obtained.
1364 The testbench architecture name can be obtained by modifying the name of
1365 the component to be tested (e.g. attaching or stripping off a substring).
1366 If TO STRING is empty, the architecture name is queried."
1367 vhdl-name-doc-string)
1368 :type '(cons (regexp :tag "From regexp")
1369 (string :tag "To string "))
1370 :group 'vhdl-testbench)
1371
1372 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1373 (concat
1374 "Specifies how the testbench configuration name is obtained.
1375 The configuration name of a testbench can be obtained by modifying the entity
1376 and/or architecture name (e.g. attaching or stripping off a substring). The
1377 string that is matched against the regexp is the concatenation of the entity
1378 and the architecture name separated by a space. This gives access to both
1379 names (see default setting as example)."
1380 vhdl-name-doc-string)
1381 :type '(cons (regexp :tag "From regexp")
1382 (string :tag "To string "))
1383 :group 'vhdl-testbench)
1384
1385 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1386 (concat
1387 "Specifies how a DUT instance name is obtained.
1388 The design-under-test instance name (i.e. the component instantiated in the
1389 testbench) can be obtained by modifying the component name (e.g. attaching
1390 or stripping off a substring)."
1391 vhdl-name-doc-string)
1392 :type '(cons (regexp :tag "From regexp")
1393 (string :tag "To string "))
1394 :group 'vhdl-testbench)
1395
1396 (defcustom vhdl-testbench-include-header t
1397 "Non-nil means include a header in automatically generated files."
1398 :type 'boolean
1399 :group 'vhdl-testbench)
1400
1401 (defcustom vhdl-testbench-declarations "\
1402 -- clock
1403 signal Clk : std_logic := '1';
1404 "
1405 "String or file to be inserted in the testbench declarative part.
1406 If the string specifies an existing file name, the contents of the file is
1407 inserted, otherwise the string itself is inserted in the testbench
1408 architecture before the BEGIN keyword.
1409 Type `C-j' for newlines."
1410 :type 'string
1411 :group 'vhdl-testbench)
1412
1413 (defcustom vhdl-testbench-statements "\
1414 -- clock generation
1415 Clk <= not Clk after 10 ns;
1416
1417 -- waveform generation
1418 WaveGen_Proc: process
1419 begin
1420 -- insert signal assignments here
1421
1422 wait until Clk = '1';
1423 end process WaveGen_Proc;
1424 "
1425 "String or file to be inserted in the testbench statement part.
1426 If the string specifies an existing file name, the contents of the file is
1427 inserted, otherwise the string itself is inserted in the testbench
1428 architecture before the END keyword.
1429 Type `C-j' for newlines."
1430 :type 'string
1431 :group 'vhdl-testbench)
1432
1433 (defcustom vhdl-testbench-initialize-signals nil
1434 "Non-nil means initialize signals with `0' when declared in testbench."
1435 :type 'boolean
1436 :group 'vhdl-testbench)
1437
1438 (defcustom vhdl-testbench-include-library t
1439 "Non-nil means a library/use clause for std_logic_1164 is included."
1440 :type 'boolean
1441 :group 'vhdl-testbench)
1442
1443 (defcustom vhdl-testbench-include-configuration t
1444 "Non-nil means a testbench configuration is attached at the end."
1445 :type 'boolean
1446 :group 'vhdl-testbench)
1447
1448 (defcustom vhdl-testbench-create-files 'single
1449 "Specifies whether new files should be created for the testbench.
1450 testbench entity and architecture are inserted:
1451 None : in current buffer
1452 Single file : in new single file
1453 Separate files: in two separate files
1454 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1455 and `vhdl-testbench-architecture-file-name'."
1456 :type '(choice (const :tag "None" none)
1457 (const :tag "Single file" single)
1458 (const :tag "Separate files" separate))
1459 :group 'vhdl-testbench)
1460
1461 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1462 (concat
1463 "Specifies how the testbench entity file name is obtained.
1464 The entity file name can be obtained by modifying the testbench entity name
1465 \(e.g. attaching or stripping off a substring). The file extension is
1466 automatically taken from the file name of the current buffer. Testbench
1467 files can be created in a different directory by prepending a relative or
1468 absolute path to the file name."
1469 vhdl-name-doc-string)
1470 :type '(cons (regexp :tag "From regexp")
1471 (string :tag "To string "))
1472 :group 'vhdl-testbench)
1473
1474 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1475 (concat
1476 "Specifies how the testbench architecture file name is obtained.
1477 The architecture file name can be obtained by modifying the testbench entity
1478 and/or architecture name (e.g. attaching or stripping off a substring). The
1479 string that is matched against the regexp is the concatenation of the entity
1480 and the architecture name separated by a space. This gives access to both
1481 names (see default setting as example). Testbench files can be created in
1482 a different directory by prepending a relative or absolute path to the file
1483 name."
1484 vhdl-name-doc-string)
1485 :type '(cons (regexp :tag "From regexp")
1486 (string :tag "To string "))
1487 :group 'vhdl-testbench)
1488
1489
1490 (defgroup vhdl-comment nil
1491 "Customizations for comments."
1492 :group 'vhdl)
1493
1494 (defcustom vhdl-self-insert-comments t
1495 "Non-nil means various templates automatically insert help comments."
1496 :type 'boolean
1497 :group 'vhdl-comment)
1498
1499 (defcustom vhdl-prompt-for-comments t
1500 "Non-nil means various templates prompt for user definable comments."
1501 :type 'boolean
1502 :group 'vhdl-comment)
1503
1504 (defcustom vhdl-inline-comment-column 40
1505 "Column to indent and align inline comments to.
1506 Overrides local option `comment-column'.
1507
1508 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1509 \"Activate Options\"."
1510 :type 'integer
1511 :group 'vhdl-comment)
1512
1513 (defcustom vhdl-end-comment-column 79
1514 "End of comment column.
1515 Comments that exceed this column number are wrapped.
1516
1517 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1518 \"Activate Options\"."
1519 :type 'integer
1520 :group 'vhdl-comment)
1521
1522 (defvar end-comment-column)
1523
1524
1525 (defgroup vhdl-beautify nil
1526 "Customizations for beautification."
1527 :group 'vhdl)
1528
1529 (defcustom vhdl-auto-align t
1530 "Non-nil means align some templates automatically after generation."
1531 :type 'boolean
1532 :group 'vhdl-beautify)
1533
1534 (defcustom vhdl-align-groups t
1535 "Non-nil means align groups of code lines separately.
1536 A group of code lines is a region of consecutive lines between two lines that
1537 match the regexp in option `vhdl-align-group-separate'."
1538 :type 'boolean
1539 :group 'vhdl-beautify)
1540
1541 (defcustom vhdl-align-group-separate "^\\s-*$"
1542 "Regexp for matching a line that separates groups of lines for alignment.
1543 Examples:
1544 \"^\\s-*$\": matches an empty line
1545 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1546 :type 'regexp
1547 :group 'vhdl-beautify)
1548
1549 (defcustom vhdl-align-same-indent t
1550 "Non-nil means align blocks with same indent separately.
1551 When a region or the entire buffer is aligned, the code is divided into
1552 blocks of same indent which are aligned separately (except for argument/port
1553 lists). This gives nicer alignment in most cases.
1554 Option `vhdl-align-groups' still applies within these blocks."
1555 :type 'boolean
1556 :group 'vhdl-beautify)
1557
1558 (defcustom vhdl-beautify-options '(t t t t t)
1559 "List of options for beautifying code.
1560 Allows you to disable individual features of code beautification."
1561 :type '(list (boolean :tag "Whitespace cleanup ")
1562 (boolean :tag "Single statement per line")
1563 (boolean :tag "Indentation ")
1564 (boolean :tag "Alignment ")
1565 (boolean :tag "Case fixing "))
1566 :group 'vhdl-beautify
1567 :version "24.4")
1568
1569
1570 (defgroup vhdl-highlight nil
1571 "Customizations for highlighting."
1572 :group 'vhdl)
1573
1574 (defcustom vhdl-highlight-keywords t
1575 "Non-nil means highlight VHDL keywords and other standardized words.
1576 The following faces are used:
1577 `font-lock-keyword-face' : keywords
1578 `font-lock-type-face' : standardized types
1579 `vhdl-font-lock-attribute-face': standardized attributes
1580 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1581 `vhdl-font-lock-function-face' : standardized function and package names
1582
1583 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1584 entry \"Fontify Buffer\")."
1585 :type 'boolean
1586 :set (lambda (variable value)
1587 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1588 :group 'vhdl-highlight)
1589
1590 (defcustom vhdl-highlight-names t
1591 "Non-nil means highlight declaration names and construct labels.
1592 The following faces are used:
1593 `font-lock-function-name-face' : names in declarations of units,
1594 subprograms, components, as well as labels of VHDL constructs
1595 `font-lock-type-face' : names in type/nature declarations
1596 `vhdl-font-lock-attribute-face': names in attribute declarations
1597 `font-lock-variable-name-face' : names in declarations of signals,
1598 variables, constants, subprogram parameters, generics, and ports
1599
1600 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1601 entry \"Fontify Buffer\")."
1602 :type 'boolean
1603 :set (lambda (variable value)
1604 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1605 :group 'vhdl-highlight)
1606
1607 (defcustom vhdl-highlight-special-words nil
1608 "Non-nil means highlight words with special syntax.
1609 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1610 are highlighted accordingly.
1611 Can be used for visual support of naming conventions.
1612
1613 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1614 entry \"Fontify Buffer\")."
1615 :type 'boolean
1616 :set (lambda (variable value)
1617 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1618 :group 'vhdl-highlight)
1619
1620 (defcustom vhdl-highlight-forbidden-words nil
1621 "Non-nil means highlight forbidden words.
1622 The reserved words specified in option `vhdl-forbidden-words' or having the
1623 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1624 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1625 use them.
1626
1627 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1628 entry \"Fontify Buffer\")."
1629 :type 'boolean
1630 :set (lambda (variable value)
1631 (vhdl-custom-set variable value
1632 'vhdl-words-init 'vhdl-font-lock-init))
1633 :group 'vhdl-highlight)
1634
1635 (defcustom vhdl-highlight-verilog-keywords nil
1636 "Non-nil means highlight Verilog keywords as reserved words.
1637 Verilog keywords are highlighted in a warning color (face
1638 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1639
1640 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1641 entry \"Fontify Buffer\")."
1642 :type 'boolean
1643 :set (lambda (variable value)
1644 (vhdl-custom-set variable value
1645 'vhdl-words-init 'vhdl-font-lock-init))
1646 :group 'vhdl-highlight)
1647
1648 (defcustom vhdl-highlight-translate-off nil
1649 "Non-nil means background-highlight code excluded from translation.
1650 That is, all code between \"-- pragma translate_off\" and
1651 \"-- pragma translate_on\" is highlighted using a different background color
1652 \(face `vhdl-font-lock-translate-off-face').
1653 Note: this might slow down on-the-fly fontification (and thus editing).
1654
1655 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1656 entry \"Fontify Buffer\")."
1657 :type 'boolean
1658 :set (lambda (variable value)
1659 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1660 :group 'vhdl-highlight)
1661
1662 (defcustom vhdl-highlight-case-sensitive nil
1663 "Non-nil means consider case for highlighting.
1664 Possible trade-off:
1665 non-nil also upper-case VHDL words are highlighted, but case of words with
1666 special syntax is not considered
1667 nil only lower-case VHDL words are highlighted, but case of words with
1668 special syntax is considered
1669 Overrides local option `font-lock-keywords-case-fold-search'.
1670
1671 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1672 entry \"Fontify Buffer\")."
1673 :type 'boolean
1674 :group 'vhdl-highlight)
1675
1676 (defcustom vhdl-special-syntax-alist
1677 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1678 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1679 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1680 "List of special syntax to be highlighted.
1681 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1682 syntax (as regular expression) are highlighted in the corresponding color.
1683
1684 Name : string of words and spaces
1685 Regexp : regular expression describing word syntax
1686 (e.g., `\\=\\<\\w+_c\\>' matches word with suffix `_c')
1687 expression must start with `\\=\\<' and end with `\\>'
1688 if only whole words should be matched (no substrings)
1689 Color (light): foreground color for light background
1690 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1691 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1692 Color (dark) : foreground color for dark background
1693 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1694 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1695 In comments : If non-nil, words are also highlighted inside comments
1696
1697 Can be used for visual support of naming conventions, such as highlighting
1698 different kinds of signals (e.g. `Clk50', `Rst_n') or objects (e.g.
1699 `Signal_s', `Variable_v', `Constant_c') by distinguishing them using
1700 common substrings or name suffices.
1701 For each entry, a new face is generated with the specified colors and name
1702 `vhdl-font-lock-' + name + `-face'.
1703
1704 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1705 entry `Fontify Buffer'). All other changes require restarting Emacs."
1706 :type '(repeat (list :tag "Face" :indent 2
1707 (string :tag "Name ")
1708 (regexp :tag "Regexp " "\\w+_")
1709 (string :tag "Color (light)")
1710 (string :tag "Color (dark) ")
1711 (boolean :tag "In comments ")))
1712 :set (lambda (variable value)
1713 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1714 :group 'vhdl-highlight)
1715
1716 (defcustom vhdl-forbidden-words '()
1717 "List of forbidden words to be highlighted.
1718 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1719 words are highlighted in a warning color to indicate not to use them.
1720
1721 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1722 entry \"Fontify Buffer\")."
1723 :type '(repeat (string :format "%v"))
1724 :set (lambda (variable value)
1725 (vhdl-custom-set variable value
1726 'vhdl-words-init 'vhdl-font-lock-init))
1727 :group 'vhdl-highlight)
1728
1729 (defcustom vhdl-forbidden-syntax ""
1730 "Syntax of forbidden words to be highlighted.
1731 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1732 syntax are highlighted in a warning color to indicate not to use them.
1733 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1734 highlights identifiers with 10 or more characters).
1735
1736 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1737 entry \"Fontify Buffer\")."
1738 :type 'regexp
1739 :set (lambda (variable value)
1740 (vhdl-custom-set variable value
1741 'vhdl-words-init 'vhdl-font-lock-init))
1742 :group 'vhdl-highlight)
1743
1744 (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
1745 "List of compiler directive keywords recognized for highlighting.
1746
1747 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1748 entry \"Fontify Buffer\")."
1749 :type '(repeat (string :format "%v"))
1750 :set (lambda (variable value)
1751 (vhdl-custom-set variable value
1752 'vhdl-words-init 'vhdl-font-lock-init))
1753 :group 'vhdl-highlight)
1754
1755
1756 (defgroup vhdl-speedbar nil
1757 "Customizations for speedbar."
1758 :group 'vhdl)
1759
1760 (defcustom vhdl-speedbar-auto-open nil
1761 "Non-nil means automatically open speedbar at startup.
1762 Alternatively, the speedbar can be opened from the VHDL menu."
1763 :type 'boolean
1764 :group 'vhdl-speedbar)
1765
1766 (defcustom vhdl-speedbar-display-mode 'files
1767 "Specifies the default displaying mode when opening speedbar.
1768 Alternatively, the displaying mode can be selected from the speedbar menu or
1769 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1770 :type '(choice (const :tag "Files" files)
1771 (const :tag "Directory hierarchy" directory)
1772 (const :tag "Project hierarchy" project))
1773 :group 'vhdl-speedbar)
1774
1775 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1776 "Limits scanning of large files and netlists.
1777 Design units: maximum file size to scan for design units
1778 Hierarchy (instances of subcomponents):
1779 File size: maximum file size to scan for instances (in bytes)
1780 Instances per arch: maximum number of instances to scan per architecture
1781
1782 \"None\" always means that there is no limit.
1783 In case of files not or incompletely scanned, a warning message and the file
1784 names are printed out.
1785 Background: scanning for instances is considerably slower than scanning for
1786 design units, especially when there are many instances. These limits should
1787 prevent the scanning of large netlists."
1788 :type '(list (choice :tag "Design units"
1789 :format "%t : %[Value Menu%] %v"
1790 (const :tag "None" nil)
1791 (integer :tag "File size"))
1792 (list :tag "Hierarchy" :indent 2
1793 (choice :tag "File size"
1794 :format "%t : %[Value Menu%] %v"
1795 (const :tag "None" nil)
1796 (integer :tag "Size "))
1797 (choice :tag "Instances per arch"
1798 (const :tag "None" nil)
1799 (integer :tag "Number "))))
1800 :group 'vhdl-speedbar)
1801
1802 (defcustom vhdl-speedbar-jump-to-unit t
1803 "Non-nil means jump to the design unit code when opened in a buffer.
1804 The buffer cursor position is left unchanged otherwise."
1805 :type 'boolean
1806 :group 'vhdl-speedbar)
1807
1808 (defcustom vhdl-speedbar-update-on-saving t
1809 "Automatically update design hierarchy when buffer is saved."
1810 :type 'boolean
1811 :group 'vhdl-speedbar)
1812
1813 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1814 "Automatically save modified hierarchy caches when exiting Emacs.
1815 Hierarchy: design hierarchy information
1816 Display: displaying information (which design units to expand)"
1817 :type '(set (const :tag "Hierarchy" hierarchy)
1818 (const :tag "Display" display))
1819 :group 'vhdl-speedbar)
1820
1821 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1822 "Name of file for saving hierarchy cache.
1823 \"\\1\" is replaced by the project name if a project is specified,
1824 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1825 different users to have cache files in the same directory). Can also have
1826 an absolute path (i.e. all caches can be stored in one global directory)."
1827 :type 'string
1828 :group 'vhdl-speedbar)
1829
1830
1831 (defgroup vhdl-menu nil
1832 "Customizations for menus."
1833 :group 'vhdl)
1834
1835 (defcustom vhdl-index-menu nil
1836 "Non-nil means add an index menu for a source file when loading.
1837 Alternatively, the speedbar can be used. Note that the index menu scans a file
1838 when it is opened, while speedbar only scans the file upon request."
1839 :type 'boolean
1840 :group 'vhdl-menu)
1841
1842 (defcustom vhdl-source-file-menu nil
1843 "Non-nil means add a menu of all source files in current directory.
1844 Alternatively, the speedbar can be used."
1845 :type 'boolean
1846 :group 'vhdl-menu)
1847
1848 (defcustom vhdl-hideshow-menu nil
1849 "Non-nil means add hideshow menu and functionality at startup.
1850 Hideshow can also be enabled from the VHDL Mode menu.
1851 Hideshow allows hiding code of various VHDL constructs.
1852
1853 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1854 \"Activate Options\"."
1855 :type 'boolean
1856 :group 'vhdl-menu)
1857
1858 (defcustom vhdl-hide-all-init nil
1859 "Non-nil means hide all design units initially after a file is loaded."
1860 :type 'boolean
1861 :group 'vhdl-menu)
1862
1863
1864 (defgroup vhdl-print nil
1865 "Customizations for printing."
1866 :group 'vhdl)
1867
1868 (defcustom vhdl-print-two-column t
1869 "Non-nil means print code in two columns and landscape format.
1870 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1871 prints VHDL files in a nice two-column landscape style.
1872
1873 NOTE: Activate the new setting by restarting Emacs.
1874 Overrides `ps-print' settings locally."
1875 :type 'boolean
1876 :group 'vhdl-print)
1877
1878 (defcustom vhdl-print-customize-faces t
1879 "Non-nil means use an optimized set of faces for PostScript printing.
1880
1881 NOTE: Activate the new setting by restarting Emacs.
1882 Overrides `ps-print' settings locally."
1883 :type 'boolean
1884 :group 'vhdl-print)
1885
1886
1887 (defgroup vhdl-misc nil
1888 "Miscellaneous customizations."
1889 :group 'vhdl)
1890
1891 (defcustom vhdl-intelligent-tab t
1892 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1893 That is, if preceding character is part of a word then complete word,
1894 else if not at beginning of line then insert tab,
1895 else if last command was a `TAB' or `RET' then dedent one step,
1896 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1897 If nil, TAB always indents current line (i.e. `TAB' is bound to
1898 `indent-according-to-mode').
1899
1900 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1901 \"Activate Options\"."
1902 :type 'boolean
1903 :group 'vhdl-misc)
1904
1905 (defcustom vhdl-indent-syntax-based t
1906 "Non-nil means indent lines of code based on their syntactic context.
1907 Otherwise, a line is indented like the previous nonblank line. This can be
1908 useful in large files where syntax-based indentation gets very slow."
1909 :type 'boolean
1910 :group 'vhdl-misc)
1911
1912 (defcustom vhdl-indent-comment-like-next-code-line t
1913 "Non-nil means comment lines are indented like the following code line.
1914 Otherwise, comment lines are indented like the preceding code line.
1915 Indenting comment lines like the following code line gives nicer indentation
1916 when comments precede the code that they refer to."
1917 :type 'boolean
1918 :version "24.3"
1919 :group 'vhdl-misc)
1920
1921 (defcustom vhdl-word-completion-case-sensitive nil
1922 "Non-nil means word completion using `TAB' is case sensitive.
1923 That is, `TAB' completes words that start with the same letters and case.
1924 Otherwise, case is ignored."
1925 :type 'boolean
1926 :group 'vhdl-misc)
1927
1928 (defcustom vhdl-word-completion-in-minibuffer t
1929 "Non-nil enables word completion in minibuffer (for template prompts).
1930
1931 NOTE: Activate the new setting by restarting Emacs."
1932 :type 'boolean
1933 :group 'vhdl-misc)
1934
1935 (defcustom vhdl-underscore-is-part-of-word nil
1936 "Non-nil means consider the underscore character `_' as part of word.
1937 An identifier containing underscores is then treated as a single word in
1938 select and move operations. All parts of an identifier separated by underscore
1939 are treated as single words otherwise."
1940 :type 'boolean
1941 :group 'vhdl-misc)
1942 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1943 'superword-mode "24.4")
1944
1945
1946 (defgroup vhdl-related nil
1947 "Related general customizations."
1948 :group 'vhdl)
1949
1950 ;; add related general customizations
1951 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1952 (if (featurep 'xemacs)
1953 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1954 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1955 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1956 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1957 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1958 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1959 (unless (featurep 'xemacs)
1960 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1961 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1962 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1963 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1964
1965 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1966 ;; Hidden user variables
1967
1968 (defvar vhdl-compile-absolute-path nil
1969 "If non-nil, use absolute instead of relative path for compiled files.")
1970
1971 (defvar vhdl-comment-display-line-char ?-
1972 "Character to use in comment display line.")
1973
1974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1975 ;; Internal variables
1976
1977 (defvar vhdl-menu-max-size 20
1978 "Specifies the maximum size of a menu before splitting it into submenus.")
1979
1980 (defvar vhdl-progress-interval 1
1981 "Interval used to update progress status during long operations.
1982 If a number, percentage complete gets updated after each interval of
1983 that many seconds. To inhibit all messages, set this option to nil.")
1984
1985 (defvar vhdl-inhibit-startup-warnings-p nil
1986 "If non-nil, inhibits start up compatibility warnings.")
1987
1988 (defvar vhdl-strict-syntax-p nil
1989 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1990 If the syntactic symbol for a particular line does not match a symbol
1991 in the offsets alist, an error is generated, otherwise no error is
1992 reported and the syntactic symbol is ignored.")
1993
1994 (defvar vhdl-echo-syntactic-information-p nil
1995 "If non-nil, syntactic info is echoed when the line is indented.")
1996
1997 (defconst vhdl-offsets-alist-default
1998 '((string . -1000)
1999 (cpp-macro . -1000)
2000 (block-open . 0)
2001 (block-close . 0)
2002 (statement . 0)
2003 (statement-cont . vhdl-lineup-statement-cont)
2004 (statement-block-intro . +)
2005 (statement-case-intro . +)
2006 (case-alternative . +)
2007 (comment . vhdl-lineup-comment)
2008 (arglist-intro . +)
2009 (arglist-cont . 0)
2010 (arglist-cont-nonempty . vhdl-lineup-arglist)
2011 (arglist-close . vhdl-lineup-arglist)
2012 (entity . 0)
2013 (configuration . 0)
2014 (package . 0)
2015 (architecture . 0)
2016 (package-body . 0)
2017 (context . 0)
2018 (directive . 0)
2019 )
2020 "Default settings for offsets of syntactic elements.
2021 Do not change this constant! See the variable `vhdl-offsets-alist' for
2022 more information.")
2023
2024 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2025 "Association list of syntactic element symbols and indentation offsets.
2026 As described below, each cons cell in this list has the form:
2027
2028 (SYNTACTIC-SYMBOL . OFFSET)
2029
2030 When a line is indented, `vhdl-mode' first determines the syntactic
2031 context of the line by generating a list of symbols called syntactic
2032 elements. This list can contain more than one syntactic element and
2033 the global variable `vhdl-syntactic-context' contains the context list
2034 for the line being indented. Each element in this list is actually a
2035 cons cell of the syntactic symbol and a buffer position. This buffer
2036 position is call the relative indent point for the line. Some
2037 syntactic symbols may not have a relative indent point associated with
2038 them.
2039
2040 After the syntactic context list for a line is generated, `vhdl-mode'
2041 calculates the absolute indentation for the line by looking at each
2042 syntactic element in the list. First, it compares the syntactic
2043 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2044 finds a match, it adds the OFFSET to the column of the relative indent
2045 point. The sum of this calculation for each element in the syntactic
2046 list is the absolute offset for line being indented.
2047
2048 If the syntactic element does not match any in the `vhdl-offsets-alist',
2049 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2050 the element is ignored.
2051
2052 Actually, OFFSET can be an integer, a function, a variable, or one of
2053 the following symbols: `+', `-', `++', or `--'. These latter
2054 designate positive or negative multiples of `vhdl-basic-offset',
2055 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2056 called with a single argument containing the cons of the syntactic
2057 element symbol and the relative indent point. The function should
2058 return an integer offset.
2059
2060 Here is the current list of valid syntactic element symbols:
2061
2062 string -- inside multi-line string
2063 block-open -- statement block open
2064 block-close -- statement block close
2065 statement -- a VHDL statement
2066 statement-cont -- a continuation of a VHDL statement
2067 statement-block-intro -- the first line in a new statement block
2068 statement-case-intro -- the first line in a case alternative block
2069 case-alternative -- a case statement alternative clause
2070 comment -- a line containing only a comment
2071 arglist-intro -- the first line in an argument list
2072 arglist-cont -- subsequent argument list lines when no
2073 arguments follow on the same line as
2074 the arglist opening paren
2075 arglist-cont-nonempty -- subsequent argument list lines when at
2076 least one argument follows on the same
2077 line as the arglist opening paren
2078 arglist-close -- the solo close paren of an argument list
2079 entity -- inside an entity declaration
2080 configuration -- inside a configuration declaration
2081 package -- inside a package declaration
2082 architecture -- inside an architecture body
2083 package-body -- inside a package body
2084 context -- inside a context declaration")
2085
2086 (defvar vhdl-comment-only-line-offset 0
2087 "Extra offset for line which contains only the start of a comment.
2088 Can contain an integer or a cons cell of the form:
2089
2090 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2091
2092 Where NON-ANCHORED-OFFSET is the amount of offset given to
2093 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2094 the amount of offset to give column-zero anchored comment-only lines.
2095 Just an integer as value is equivalent to (<val> . 0)")
2096
2097 (defvar vhdl-special-indent-hook nil
2098 "Hook for user defined special indentation adjustments.
2099 This hook gets called after a line is indented by the mode.")
2100
2101 (defvar vhdl-style-alist
2102 '(("IEEE"
2103 (vhdl-basic-offset . 4)
2104 (vhdl-offsets-alist . ())))
2105 "Styles of Indentation.
2106 Elements of this alist are of the form:
2107
2108 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2109
2110 where STYLE-STRING is a short descriptive string used to select a
2111 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2112 value for that variable when using the selected style.
2113
2114 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2115 case, the VALUE is a list containing elements of the form:
2116
2117 (SYNTACTIC-SYMBOL . VALUE)
2118
2119 as described in `vhdl-offsets-alist'. These are passed directly to
2120 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2121 your style, only those that are different from the default.")
2122
2123 ;; dynamically append the default value of most variables
2124 (or (assoc "Default" vhdl-style-alist)
2125 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2126 vhdl-strict-syntax-p
2127 vhdl-echo-syntactic-information-p
2128 vhdl-basic-offset
2129 vhdl-offsets-alist
2130 vhdl-comment-only-line-offset))
2131 (default (cons "Default"
2132 (mapcar
2133 (function
2134 (lambda (var)
2135 (cons var (symbol-value var))))
2136 varlist))))
2137 (push default vhdl-style-alist)))
2138
2139 (defvar vhdl-mode-hook nil
2140 "Hook called by `vhdl-mode'.")
2141
2142
2143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2144 ;;; Required packages
2145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2146
2147 ;; mandatory
2148 (require 'compile) ; XEmacs
2149 (require 'easymenu)
2150 (require 'hippie-exp)
2151
2152 ;; optional (minimize warning messages during compile)
2153 (unless (featurep 'xemacs)
2154 (eval-when-compile
2155 (require 'font-lock)
2156 (require 'ps-print)
2157 (require 'speedbar))) ; for speedbar-with-writable
2158
2159 (defun vhdl-aput (alist-symbol key &optional value)
2160 "Insert a key-value pair into an alist.
2161 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2162 from KEY and VALUE. If the key-value pair referenced by KEY can be
2163 found in the alist, the value of KEY will be set to VALUE. If the
2164 key-value pair cannot be found in the alist, it will be inserted into
2165 the head of the alist."
2166 (let* ((alist (symbol-value alist-symbol))
2167 (elem (assoc key alist)))
2168 (if elem
2169 (setcdr elem value)
2170 (set alist-symbol (cons (cons key value) alist)))))
2171
2172 (defun vhdl-adelete (alist-symbol key)
2173 "Delete a key-value pair from the alist.
2174 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2175 is pair matching KEY."
2176 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2177 (while (equal key (caar alist))
2178 (setq alist (cdr alist))
2179 (set alist-symbol alist))
2180 (while (setq alist-cdr (cdr alist))
2181 (if (equal key (caar alist-cdr))
2182 (setcdr alist (cdr alist-cdr))
2183 (setq alist alist-cdr)))))
2184
2185 (defun vhdl-aget (alist key)
2186 "Return the value in ALIST that is associated with KEY. If KEY is
2187 not found, then nil is returned."
2188 (cdr (assoc key alist)))
2189
2190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2191 ;;; Compatibility
2192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2193
2194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2195 ;; XEmacs compatibility
2196
2197 ;; active regions
2198 (defun vhdl-keep-region-active ()
2199 "Do whatever is necessary to keep the region active in XEmacs.
2200 Ignore byte-compiler warnings you might see."
2201 (and (featurep 'xemacs)
2202 (setq zmacs-region-stays t)))
2203
2204 ;; `wildcard-to-regexp' is included only in XEmacs 21
2205 (unless (fboundp 'wildcard-to-regexp)
2206 (defun wildcard-to-regexp (wildcard)
2207 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2208 (let* ((i (string-match "[*?]" wildcard))
2209 (result (substring wildcard 0 i))
2210 (len (length wildcard)))
2211 (when i
2212 (while (< i len)
2213 (let ((ch (aref wildcard i)))
2214 (setq result (concat result
2215 (cond ((eq ch ?*) "[^\000]*")
2216 ((eq ch ??) "[^\000]")
2217 (t (char-to-string ch)))))
2218 (setq i (1+ i)))))
2219 (concat "\\`" result "\\'"))))
2220
2221 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2222 ;; `regexp-opt' accelerates fontification by 10-20%
2223 (unless (fboundp 'regexp-opt)
2224 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2225 (defun regexp-opt (strings &optional paren)
2226 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2227 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2228
2229 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2230 (unless (fboundp 'match-string-no-properties)
2231 (defalias 'match-string-no-properties 'match-string))
2232
2233 ;; `subst-char-in-string' undefined (XEmacs)
2234 (unless (fboundp 'subst-char-in-string)
2235 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2236 (let ((i (length string))
2237 (newstr (if inplace string (copy-sequence string))))
2238 (while (> i 0)
2239 (setq i (1- i))
2240 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2241 newstr)))
2242
2243 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2244 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2245 (not noninteractive))
2246 (load "itimer")
2247 (when (string< itimer-version "1.09")
2248 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2249 (beep) (sit-for 5)))
2250
2251 ;; `file-expand-wildcards' undefined (XEmacs)
2252 (unless (fboundp 'file-expand-wildcards)
2253 (defun file-expand-wildcards (pattern &optional full)
2254 "Taken from Emacs's `files.el'."
2255 (let* ((nondir (file-name-nondirectory pattern))
2256 (dirpart (file-name-directory pattern))
2257 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2258 (mapcar 'file-name-as-directory
2259 (file-expand-wildcards (directory-file-name dirpart)))
2260 (list dirpart)))
2261 contents)
2262 (while dirs
2263 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2264 (file-directory-p (directory-file-name (car dirs))))
2265 (let ((this-dir-contents
2266 (delq nil
2267 (mapcar #'(lambda (name)
2268 (unless (string-match "\\`\\.\\.?\\'"
2269 (file-name-nondirectory name))
2270 name))
2271 (directory-files (or (car dirs) ".") full
2272 (wildcard-to-regexp nondir))))))
2273 (setq contents
2274 (nconc
2275 (if (and (car dirs) (not full))
2276 (mapcar (function (lambda (name) (concat (car dirs) name)))
2277 this-dir-contents)
2278 this-dir-contents)
2279 contents))))
2280 (setq dirs (cdr dirs)))
2281 contents)))
2282
2283 ;; `member-ignore-case' undefined (XEmacs)
2284 (unless (fboundp 'member-ignore-case)
2285 (defalias 'member-ignore-case 'member))
2286
2287 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2288 ;; behavior in XEmacs
2289 (defvar vhdl-last-input-event)
2290 (if (featurep 'xemacs)
2291 (defvaralias 'vhdl-last-input-event 'last-input-char)
2292 (defvaralias 'vhdl-last-input-event 'last-input-event))
2293
2294 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2295 ;;;(unless (fboundp 'help-print-return-message)
2296 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2297
2298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2299 ;; Compatibility with older VHDL Mode versions
2300
2301 (defvar vhdl-warnings nil
2302 "Warnings to tell the user during start up.")
2303
2304 (defun vhdl-run-when-idle (secs repeat function)
2305 "Wait until idle, then run FUNCTION."
2306 (if (fboundp 'start-itimer)
2307 (start-itimer "vhdl-mode" function secs repeat t)
2308 ;; explicitly activate timer (necessary when Emacs is already idle)
2309 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2310
2311 (defun vhdl-warning-when-idle (&rest args)
2312 "Wait until idle, then print out warning STRING and beep."
2313 (let ((message (apply #'format-message args)))
2314 (if noninteractive
2315 (vhdl-warning message t)
2316 (unless vhdl-warnings
2317 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2318 (push message vhdl-warnings))))
2319
2320 (defun vhdl-warning (string &optional nobeep)
2321 "Print out warning STRING and beep."
2322 (message "WARNING: %s" string)
2323 (unless (or nobeep noninteractive) (beep)))
2324
2325 (defun vhdl-print-warnings ()
2326 "Print out messages in variable `vhdl-warnings'."
2327 (let ((no-warnings (length vhdl-warnings)))
2328 (setq vhdl-warnings (nreverse vhdl-warnings))
2329 (while vhdl-warnings
2330 (message "WARNING: %s" (car vhdl-warnings))
2331 (setq vhdl-warnings (cdr vhdl-warnings)))
2332 (beep)
2333 (when (> no-warnings 1)
2334 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2335
2336 ;; Backward compatibility checks and fixes
2337 ;; option `vhdl-compiler' changed format
2338 (unless (stringp vhdl-compiler)
2339 (setq vhdl-compiler "ModelSim")
2340 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2341
2342 ;; option `vhdl-standard' changed format
2343 (unless (listp vhdl-standard)
2344 (setq vhdl-standard '(87 nil))
2345 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2346
2347 ;; option `vhdl-model-alist' changed format
2348 (when (= (length (car vhdl-model-alist)) 3)
2349 (let ((old-alist vhdl-model-alist)
2350 new-alist)
2351 (while old-alist
2352 (push (append (car old-alist) '("")) new-alist)
2353 (setq old-alist (cdr old-alist)))
2354 (setq vhdl-model-alist (nreverse new-alist)))
2355 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2356
2357 ;; option `vhdl-project-alist' changed format
2358 (when (= (length (car vhdl-project-alist)) 3)
2359 (let ((old-alist vhdl-project-alist)
2360 new-alist)
2361 (while old-alist
2362 (push (append (car old-alist) '("")) new-alist)
2363 (setq old-alist (cdr old-alist)))
2364 (setq vhdl-project-alist (nreverse new-alist)))
2365 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2366
2367 ;; option `vhdl-project-alist' changed format (3.31.1)
2368 (when (= (length (car vhdl-project-alist)) 4)
2369 (let ((old-alist vhdl-project-alist)
2370 new-alist elem)
2371 (while old-alist
2372 (setq elem (car old-alist))
2373 (setq new-alist
2374 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2375 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2376 new-alist))
2377 (setq old-alist (cdr old-alist)))
2378 (setq vhdl-project-alist (nreverse new-alist)))
2379 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2380
2381 ;; option `vhdl-project-alist' changed format (3.31.12)
2382 (when (= (length (car vhdl-project-alist)) 10)
2383 (let ((tmp-alist vhdl-project-alist))
2384 (while tmp-alist
2385 (setcdr (nthcdr 3 (car tmp-alist))
2386 (cons "" (nthcdr 4 (car tmp-alist))))
2387 (setq tmp-alist (cdr tmp-alist))))
2388 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2389
2390 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2391 (when (= (length (car vhdl-compiler-alist)) 7)
2392 (let ((old-alist vhdl-compiler-alist)
2393 new-alist elem)
2394 (while old-alist
2395 (setq elem (car old-alist))
2396 (setq new-alist
2397 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2398 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2399 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2400 (nth 5 elem) (nth 6 elem) nil)
2401 new-alist))
2402 (setq old-alist (cdr old-alist)))
2403 (setq vhdl-compiler-alist (nreverse new-alist)))
2404 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2405
2406 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2407 (when (= (length (car vhdl-compiler-alist)) 12)
2408 (let ((tmp-alist vhdl-compiler-alist))
2409 (while tmp-alist
2410 (setcdr (nthcdr 4 (car tmp-alist))
2411 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2412 (setq tmp-alist (cdr tmp-alist))))
2413 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2414
2415 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2416 (when (= (length (car vhdl-compiler-alist)) 13)
2417 (let ((tmp-alist vhdl-compiler-alist))
2418 (while tmp-alist
2419 (setcdr (nthcdr 3 (car tmp-alist))
2420 (cons "" (nthcdr 4 (car tmp-alist))))
2421 (setq tmp-alist (cdr tmp-alist))))
2422 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2423
2424 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2425 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2426 (let ((tmp-alist vhdl-compiler-alist))
2427 (while tmp-alist
2428 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2429 '(0 . nil))
2430 (setq tmp-alist (cdr tmp-alist))))
2431 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2432
2433 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2434 (when (equal vhdl-project "")
2435 (setq vhdl-project nil)
2436 (customize-save-variable 'vhdl-project vhdl-project))
2437
2438 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2439 (when (stringp vhdl-project-file-name)
2440 (setq vhdl-project-file-name (list vhdl-project-file-name))
2441 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2442
2443 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2444 (if (not (boundp 'speedbar-indentation-width))
2445 (defvar speedbar-indentation-width 2)
2446 ;; set default to 2 if not already customized
2447 (unless (get 'speedbar-indentation-width 'saved-value)
2448 (setq speedbar-indentation-width 2)))
2449
2450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2451 ;;; Help functions / inline substitutions / macros
2452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2453
2454 (defun vhdl-standard-p (standard)
2455 "Check if STANDARD is specified as used standard."
2456 (or (eq standard (car vhdl-standard))
2457 (memq standard (cadr vhdl-standard))))
2458
2459 (defun vhdl-project-p (&optional warning)
2460 "Return non-nil if a project is displayed, i.e. directories or files are
2461 specified."
2462 (if (assoc vhdl-project vhdl-project-alist)
2463 vhdl-project
2464 (when (and vhdl-project warning)
2465 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2466 nil))
2467
2468 (defun vhdl-resolve-env-variable (string)
2469 "Resolve environment variables in STRING."
2470 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2471 (setq string (concat (match-string 1 string)
2472 (getenv (match-string 2 string))
2473 (match-string 4 string))))
2474 string)
2475
2476 (defun vhdl-default-directory ()
2477 "Return the default directory of the current project or the directory of the
2478 current buffer if no project is defined."
2479 (if (vhdl-project-p)
2480 (expand-file-name (vhdl-resolve-env-variable
2481 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2482 default-directory))
2483
2484 (defmacro vhdl-prepare-search-1 (&rest body)
2485 "Enable case insensitive search and switch to syntax table that includes `_',
2486 then execute BODY, and finally restore the old environment. Used for
2487 consistent searching."
2488 `(let ((case-fold-search t)) ; case insensitive search
2489 ;; use extended syntax table
2490 (with-syntax-table vhdl-mode-ext-syntax-table
2491 ,@body)))
2492
2493 (defmacro vhdl-prepare-search-2 (&rest body)
2494 "Enable case insensitive search, switch to syntax table that includes `_',
2495 arrange to ignore `intangible' overlays, then execute BODY, and finally restore
2496 the old environment. Used for consistent searching."
2497 `(let ((case-fold-search t) ; case insensitive search
2498 (current-syntax-table (syntax-table))
2499 (inhibit-point-motion-hooks t))
2500 ;; use extended syntax table
2501 (set-syntax-table vhdl-mode-ext-syntax-table)
2502 ;; execute BODY safely
2503 (unwind-protect
2504 (progn ,@body)
2505 ;; restore syntax table
2506 (set-syntax-table current-syntax-table))))
2507
2508 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2509 "Visit file FILE-NAME and execute BODY."
2510 `(if (null ,file-name)
2511 (progn ,@body)
2512 (unless (file-directory-p ,file-name)
2513 (let ((source-buffer (current-buffer))
2514 (visiting-buffer (find-buffer-visiting ,file-name))
2515 file-opened)
2516 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2517 (condition-case ()
2518 (progn (set-buffer (create-file-buffer ,file-name))
2519 (setq file-opened t)
2520 (vhdl-insert-file-contents ,file-name)
2521 ;; FIXME: This modifies a global syntax-table!
2522 (modify-syntax-entry ?\- ". 12" (syntax-table))
2523 (modify-syntax-entry ?\n ">" (syntax-table))
2524 (modify-syntax-entry ?\^M ">" (syntax-table))
2525 (modify-syntax-entry ?_ "w" (syntax-table))
2526 t)
2527 (error
2528 (if ,issue-error
2529 (progn
2530 (when file-opened (kill-buffer (current-buffer)))
2531 (set-buffer source-buffer)
2532 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2533 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2534 nil))))
2535 (condition-case info
2536 (progn ,@body)
2537 (error
2538 (if ,issue-error
2539 (progn
2540 (when file-opened (kill-buffer (current-buffer)))
2541 (set-buffer source-buffer)
2542 (error (cadr info)))
2543 (vhdl-warning (cadr info))))))
2544 (when file-opened (kill-buffer (current-buffer)))
2545 (set-buffer source-buffer)))))
2546
2547 (defun vhdl-insert-file-contents (filename)
2548 "Nicked from `insert-file-contents-literally', but allow coding system
2549 conversion."
2550 (let ((format-alist nil)
2551 (after-insert-file-functions nil)
2552 (jka-compr-compression-info-list nil))
2553 (insert-file-contents filename t)))
2554
2555 (defun vhdl-sort-alist (alist)
2556 "Sort ALIST."
2557 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2558
2559 (defun vhdl-get-subdirs (directory)
2560 "Recursively get subdirectories of DIRECTORY."
2561 (let ((dir-list (list (file-name-as-directory directory)))
2562 file-list)
2563 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2564 (while file-list
2565 (when (file-directory-p (car file-list))
2566 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2567 (setq file-list (cdr file-list)))
2568 dir-list))
2569
2570 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2571 "As `aput', but delete key-value pair if VALUE is nil."
2572 (if value
2573 (vhdl-aput alist-symbol key value)
2574 (vhdl-adelete alist-symbol key)))
2575
2576 (defun vhdl-delete (elt list)
2577 "Delete by side effect the first occurrence of ELT as a member of LIST."
2578 (push nil list)
2579 (let ((list1 list))
2580 (while (and (cdr list1) (not (equal elt (cadr list1))))
2581 (setq list1 (cdr list1)))
2582 (when list
2583 (setcdr list1 (cddr list1))))
2584 (cdr list))
2585
2586 (declare-function speedbar-refresh "speedbar" (&optional arg))
2587 (declare-function speedbar-do-function-pointer "speedbar" ())
2588
2589 (defun vhdl-speedbar-refresh (&optional key)
2590 "Refresh directory or project with name KEY."
2591 (when (and (boundp 'speedbar-frame)
2592 (frame-live-p speedbar-frame))
2593 (let ((pos (point))
2594 (last-frame (selected-frame)))
2595 (if (null key)
2596 (speedbar-refresh)
2597 (select-frame speedbar-frame)
2598 (when (save-excursion
2599 (goto-char (point-min))
2600 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2601 (goto-char (match-end 1))
2602 (speedbar-do-function-pointer)
2603 (backward-char 2)
2604 (speedbar-do-function-pointer)
2605 (message "Refreshing speedbar...done"))
2606 (select-frame last-frame)))))
2607
2608 (defun vhdl-show-messages ()
2609 "Get *Messages* buffer to show recent messages."
2610 (interactive)
2611 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2612
2613 (defun vhdl-use-direct-instantiation ()
2614 "Return whether direct instantiation is used."
2615 (or (eq vhdl-use-direct-instantiation 'always)
2616 (and (eq vhdl-use-direct-instantiation 'standard)
2617 (not (vhdl-standard-p '87)))))
2618
2619 (defun vhdl-max-marker (marker1 marker2)
2620 "Return larger marker."
2621 (if (> marker1 marker2) marker1 marker2))
2622
2623 (defun vhdl-goto-marker (marker)
2624 "Goto marker in appropriate buffer."
2625 (when (markerp marker)
2626 (set-buffer (marker-buffer marker)))
2627 (goto-char marker))
2628
2629 (defun vhdl-menu-split (list title)
2630 "Split menu LIST into several submenus, if number of
2631 elements > `vhdl-menu-max-size'."
2632 (if (> (length list) vhdl-menu-max-size)
2633 (let ((remain list)
2634 (result '())
2635 (sublist '())
2636 (menuno 1)
2637 (i 0))
2638 (while remain
2639 (push (car remain) sublist)
2640 (setq remain (cdr remain))
2641 (setq i (+ i 1))
2642 (if (= i vhdl-menu-max-size)
2643 (progn
2644 (push (cons (format "%s %s" title menuno)
2645 (nreverse sublist)) result)
2646 (setq i 0)
2647 (setq menuno (+ menuno 1))
2648 (setq sublist '()))))
2649 (and sublist
2650 (push (cons (format "%s %s" title menuno)
2651 (nreverse sublist)) result))
2652 (nreverse result))
2653 list))
2654
2655
2656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2657 ;;; Bindings
2658 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2659
2660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2661 ;; Key bindings
2662
2663 (defvar vhdl-template-map nil
2664 "Keymap for VHDL templates.")
2665
2666 (defun vhdl-template-map-init ()
2667 "Initialize `vhdl-template-map'."
2668 (setq vhdl-template-map (make-sparse-keymap))
2669 ;; key bindings for VHDL templates
2670 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2671 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2672 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2673 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2674 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2675 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2676 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2677 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2678 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2679 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2680 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2681 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2682 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2683 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2684 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2685 (define-key vhdl-template-map "ct" 'vhdl-template-context)
2686 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2687 (define-key vhdl-template-map "el" 'vhdl-template-else)
2688 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2689 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2690 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2691 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2692 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2693 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2694 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2695 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2696 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2697 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2698 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2699 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2700 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2701 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2702 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2703 (define-key vhdl-template-map "li" 'vhdl-template-library)
2704 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2705 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2706 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2707 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2708 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2709 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2710 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2711 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2712 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2713 (define-key vhdl-template-map "po" 'vhdl-template-port)
2714 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2715 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2716 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2717 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2718 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2719 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2720 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2721 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2722 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2723 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2724 (define-key vhdl-template-map "us" 'vhdl-template-use)
2725 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2726 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2727 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2728 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2729 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2730 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2731 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2732 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2733 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2734 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2735 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2736 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2737 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2738 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2739 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2740 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2741 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2742 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2743 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2744 (when (vhdl-standard-p 'ams)
2745 (define-key vhdl-template-map "br" 'vhdl-template-break)
2746 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2747 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2748 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2749 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2750 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2751 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2752 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2753 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2754 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2755 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2756 )
2757 (when (vhdl-standard-p 'math)
2758 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2759 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2760 ))
2761
2762 ;; initialize template map for VHDL Mode
2763 (vhdl-template-map-init)
2764
2765 (defun vhdl-function-name (prefix string &optional postfix)
2766 "Generate a Lisp function name.
2767 PREFIX, STRING and optional POSTFIX are concatenated by `-' and spaces in
2768 STRING are replaced by `-' and substrings are converted to lower case."
2769 (let ((name prefix))
2770 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2771 (setq name
2772 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2773 (setq string (substring string (match-beginning 2))))
2774 (when postfix (setq name (concat name "-" postfix)))
2775 (intern name)))
2776
2777 (defvar vhdl-model-map nil
2778 "Keymap for VHDL models.")
2779
2780 (defun vhdl-model-map-init ()
2781 "Initialize `vhdl-model-map'."
2782 (setq vhdl-model-map (make-sparse-keymap))
2783 ;; key bindings for VHDL models
2784 (let ((model-alist vhdl-model-alist) model)
2785 (while model-alist
2786 (setq model (car model-alist))
2787 (define-key vhdl-model-map (nth 2 model)
2788 (vhdl-function-name "vhdl-model" (nth 0 model)))
2789 (setq model-alist (cdr model-alist)))))
2790
2791 ;; initialize user model map for VHDL Mode
2792 (vhdl-model-map-init)
2793
2794 (defvar vhdl-mode-map nil
2795 "Keymap for VHDL Mode.")
2796
2797 (defun vhdl-mode-map-init ()
2798 "Initialize `vhdl-mode-map'."
2799 (setq vhdl-mode-map (make-sparse-keymap))
2800 ;; template key bindings
2801 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2802 ;; model key bindings
2803 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2804 ;; standard key bindings
2805 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2806 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2807 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2808 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2809 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2810 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2811 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2812 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2813 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2814 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2815 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2816 ;; mode specific key bindings
2817 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2818 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2819 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2820 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2821 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2822 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2823 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2824 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2825 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2826 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2827 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2828 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2829 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2830 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2831 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2832 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2833 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2834 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2835 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2836 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2837 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2838 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2839 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2840 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2841 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2842 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2843 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2844 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2845 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2846 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2847 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2848 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2849 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2850 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2851 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2852 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2853 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2854 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2855 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2856 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2857 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2858 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2859 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2860 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2861 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2862 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2863 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2864 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2865 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2866 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2867 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2868 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2869 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2870 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2871 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2872 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2873 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2874 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2875 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2876 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2877 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2878 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2879 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2880 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2881 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2882 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2883 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2884 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2885 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2886 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2887 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2888 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2889 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2890 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2891 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2892 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2893 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2894 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2895 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2896 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2897 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2898 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2899 ;; insert commands bindings
2900 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2901 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2902 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2903 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2904 ;; electric key bindings
2905 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2906 (when vhdl-intelligent-tab
2907 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2908 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2909 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2910 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2911 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2912 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2913 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2914 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2915 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2916 (when (vhdl-standard-p 'ams)
2917 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2918
2919 ;; initialize mode map for VHDL Mode
2920 (vhdl-mode-map-init)
2921
2922 ;; define special minibuffer keymap for enabling word completion in minibuffer
2923 ;; (useful in template generator prompts)
2924 (defvar vhdl-minibuffer-local-map
2925 (let ((map (make-sparse-keymap)))
2926 (set-keymap-parent map minibuffer-local-map)
2927 (when vhdl-word-completion-in-minibuffer
2928 (define-key map "\t" 'vhdl-minibuffer-tab))
2929 map)
2930 "Keymap for minibuffer used in VHDL Mode.")
2931
2932 ;; set up electric character functions to work with
2933 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2934 (mapc
2935 (function
2936 (lambda (sym)
2937 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2938 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2939 '(vhdl-electric-space
2940 vhdl-electric-tab
2941 vhdl-electric-return
2942 vhdl-electric-dash
2943 vhdl-electric-open-bracket
2944 vhdl-electric-close-bracket
2945 vhdl-electric-quote
2946 vhdl-electric-semicolon
2947 vhdl-electric-comma
2948 vhdl-electric-period
2949 vhdl-electric-equal))
2950
2951 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2952 ;; Syntax table
2953
2954 (defvar vhdl-mode-syntax-table
2955 (let ((st (make-syntax-table)))
2956 ;; define punctuation
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 (modify-syntax-entry ?\; "." st)
2968 (modify-syntax-entry ?\< "." st)
2969 (modify-syntax-entry ?\= "." st)
2970 (modify-syntax-entry ?\> "." st)
2971 (modify-syntax-entry ?\\ "." st)
2972 (modify-syntax-entry ?\| "." st)
2973 ;; define string
2974 (modify-syntax-entry ?\" "\"" st)
2975 ;; define underscore
2976 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2977 ;; single-line comments
2978 (modify-syntax-entry ?\- ". 12b" st)
2979 ;; multi-line comments
2980 (modify-syntax-entry ?\/ ". 14b" st)
2981 (modify-syntax-entry ?* ". 23" st)
2982 (modify-syntax-entry ?\n "> b" st)
2983 (modify-syntax-entry ?\^M "> b" st)
2984 ;; define parentheses to match
2985 (modify-syntax-entry ?\( "()" st)
2986 (modify-syntax-entry ?\) ")(" st)
2987 (modify-syntax-entry ?\[ "(]" st)
2988 (modify-syntax-entry ?\] ")[" st)
2989 (modify-syntax-entry ?\{ "(}" st)
2990 (modify-syntax-entry ?\} "){" st)
2991 st)
2992 "Syntax table used in `vhdl-mode' buffers.")
2993
2994 (defvar vhdl-mode-ext-syntax-table
2995 ;; Extended syntax table including '_' (for simpler search regexps).
2996 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
2997 (modify-syntax-entry ?_ "w" st)
2998 st)
2999 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
3000
3001 (defvar vhdl-syntactic-context nil
3002 "Buffer local variable containing syntactic analysis list.")
3003 (make-variable-buffer-local 'vhdl-syntactic-context)
3004
3005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3006 ;; Abbrev hook bindings
3007
3008 (defvar vhdl-mode-abbrev-table nil
3009 "Abbrev table to use in `vhdl-mode' buffers.")
3010
3011 (defun vhdl-mode-abbrev-table-init ()
3012 "Initialize `vhdl-mode-abbrev-table'."
3013 (define-abbrev-table 'vhdl-mode-abbrev-table
3014 (append
3015 (when (memq 'vhdl vhdl-electric-keywords)
3016 ;; VHDL'02 keywords
3017 (mapcar (if (featurep 'xemacs)
3018 (lambda (x) (list (car x) "" (cdr x) 0))
3019 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3020 '(
3021 ("--" . vhdl-template-display-comment-hook)
3022 ("abs" . vhdl-template-default-hook)
3023 ("access" . vhdl-template-default-hook)
3024 ("after" . vhdl-template-default-hook)
3025 ("alias" . vhdl-template-alias-hook)
3026 ("all" . vhdl-template-default-hook)
3027 ("and" . vhdl-template-default-hook)
3028 ("arch" . vhdl-template-architecture-hook)
3029 ("architecture" . vhdl-template-architecture-hook)
3030 ("array" . vhdl-template-default-hook)
3031 ("assert" . vhdl-template-assert-hook)
3032 ("attr" . vhdl-template-attribute-hook)
3033 ("attribute" . vhdl-template-attribute-hook)
3034 ("begin" . vhdl-template-default-indent-hook)
3035 ("block" . vhdl-template-block-hook)
3036 ("body" . vhdl-template-default-hook)
3037 ("buffer" . vhdl-template-default-hook)
3038 ("bus" . vhdl-template-default-hook)
3039 ("case" . vhdl-template-case-hook)
3040 ("comp" . vhdl-template-component-hook)
3041 ("component" . vhdl-template-component-hook)
3042 ("cond" . vhdl-template-conditional-signal-asst-hook)
3043 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3044 ("conf" . vhdl-template-configuration-hook)
3045 ("configuration" . vhdl-template-configuration-hook)
3046 ("cons" . vhdl-template-constant-hook)
3047 ("constant" . vhdl-template-constant-hook)
3048 ("context" . vhdl-template-context-hook)
3049 ("disconnect" . vhdl-template-disconnect-hook)
3050 ("downto" . vhdl-template-default-hook)
3051 ("else" . vhdl-template-else-hook)
3052 ("elseif" . vhdl-template-elsif-hook)
3053 ("elsif" . vhdl-template-elsif-hook)
3054 ("end" . vhdl-template-default-indent-hook)
3055 ("entity" . vhdl-template-entity-hook)
3056 ("exit" . vhdl-template-exit-hook)
3057 ("file" . vhdl-template-file-hook)
3058 ("for" . vhdl-template-for-hook)
3059 ("func" . vhdl-template-function-hook)
3060 ("function" . vhdl-template-function-hook)
3061 ("generic" . vhdl-template-generic-hook)
3062 ("group" . vhdl-template-group-hook)
3063 ("guarded" . vhdl-template-default-hook)
3064 ("if" . vhdl-template-if-hook)
3065 ("impure" . vhdl-template-default-hook)
3066 ("in" . vhdl-template-default-hook)
3067 ("inertial" . vhdl-template-default-hook)
3068 ("inout" . vhdl-template-default-hook)
3069 ("inst" . vhdl-template-instance-hook)
3070 ("instance" . vhdl-template-instance-hook)
3071 ("is" . vhdl-template-default-hook)
3072 ("label" . vhdl-template-default-hook)
3073 ("library" . vhdl-template-library-hook)
3074 ("linkage" . vhdl-template-default-hook)
3075 ("literal" . vhdl-template-default-hook)
3076 ("loop" . vhdl-template-bare-loop-hook)
3077 ("map" . vhdl-template-map-hook)
3078 ("mod" . vhdl-template-default-hook)
3079 ("nand" . vhdl-template-default-hook)
3080 ("new" . vhdl-template-default-hook)
3081 ("next" . vhdl-template-next-hook)
3082 ("nor" . vhdl-template-default-hook)
3083 ("not" . vhdl-template-default-hook)
3084 ("null" . vhdl-template-default-hook)
3085 ("of" . vhdl-template-default-hook)
3086 ("on" . vhdl-template-default-hook)
3087 ("open" . vhdl-template-default-hook)
3088 ("or" . vhdl-template-default-hook)
3089 ("others" . vhdl-template-others-hook)
3090 ("out" . vhdl-template-default-hook)
3091 ("pack" . vhdl-template-package-hook)
3092 ("package" . vhdl-template-package-hook)
3093 ("port" . vhdl-template-port-hook)
3094 ("postponed" . vhdl-template-default-hook)
3095 ("procedure" . vhdl-template-procedure-hook)
3096 ("process" . vhdl-template-process-hook)
3097 ("pure" . vhdl-template-default-hook)
3098 ("range" . vhdl-template-default-hook)
3099 ("record" . vhdl-template-default-hook)
3100 ("register" . vhdl-template-default-hook)
3101 ("reject" . vhdl-template-default-hook)
3102 ("rem" . vhdl-template-default-hook)
3103 ("report" . vhdl-template-report-hook)
3104 ("return" . vhdl-template-return-hook)
3105 ("rol" . vhdl-template-default-hook)
3106 ("ror" . vhdl-template-default-hook)
3107 ("select" . vhdl-template-selected-signal-asst-hook)
3108 ("severity" . vhdl-template-default-hook)
3109 ("shared" . vhdl-template-default-hook)
3110 ("sig" . vhdl-template-signal-hook)
3111 ("signal" . vhdl-template-signal-hook)
3112 ("sla" . vhdl-template-default-hook)
3113 ("sll" . vhdl-template-default-hook)
3114 ("sra" . vhdl-template-default-hook)
3115 ("srl" . vhdl-template-default-hook)
3116 ("subtype" . vhdl-template-subtype-hook)
3117 ("then" . vhdl-template-default-hook)
3118 ("to" . vhdl-template-default-hook)
3119 ("transport" . vhdl-template-default-hook)
3120 ("type" . vhdl-template-type-hook)
3121 ("unaffected" . vhdl-template-default-hook)
3122 ("units" . vhdl-template-default-hook)
3123 ("until" . vhdl-template-default-hook)
3124 ("use" . vhdl-template-use-hook)
3125 ("var" . vhdl-template-variable-hook)
3126 ("variable" . vhdl-template-variable-hook)
3127 ("wait" . vhdl-template-wait-hook)
3128 ("when" . vhdl-template-when-hook)
3129 ("while" . vhdl-template-while-loop-hook)
3130 ("with" . vhdl-template-with-hook)
3131 ("xnor" . vhdl-template-default-hook)
3132 ("xor" . vhdl-template-default-hook)
3133 )))
3134 ;; VHDL-AMS keywords
3135 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3136 (mapcar (if (featurep 'xemacs)
3137 (lambda (x) (list (car x) "" (cdr x) 0))
3138 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3139 '(
3140 ("across" . vhdl-template-default-hook)
3141 ("break" . vhdl-template-break-hook)
3142 ("limit" . vhdl-template-limit-hook)
3143 ("nature" . vhdl-template-nature-hook)
3144 ("noise" . vhdl-template-default-hook)
3145 ("procedural" . vhdl-template-procedural-hook)
3146 ("quantity" . vhdl-template-quantity-hook)
3147 ("reference" . vhdl-template-default-hook)
3148 ("spectrum" . vhdl-template-default-hook)
3149 ("subnature" . vhdl-template-subnature-hook)
3150 ("terminal" . vhdl-template-terminal-hook)
3151 ("through" . vhdl-template-default-hook)
3152 ("tolerance" . vhdl-template-default-hook)
3153 )))
3154 ;; user model keywords
3155 (when (memq 'user vhdl-electric-keywords)
3156 (let (abbrev-list keyword)
3157 (dolist (elem vhdl-model-alist)
3158 (setq keyword (nth 3 elem))
3159 (unless (equal keyword "")
3160 (push (list keyword ""
3161 (vhdl-function-name
3162 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3163 abbrev-list)))
3164 abbrev-list)))))
3165
3166 ;; initialize abbrev table for VHDL Mode
3167 (vhdl-mode-abbrev-table-init)
3168
3169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3170 ;; Template completion lists
3171
3172 (defvar vhdl-template-construct-alist nil
3173 "List of built-in construct templates.")
3174
3175 (defun vhdl-template-construct-alist-init ()
3176 "Initialize `vhdl-template-construct-alist'."
3177 (setq
3178 vhdl-template-construct-alist
3179 (append
3180 '(
3181 ("alias declaration" vhdl-template-alias)
3182 ("architecture body" vhdl-template-architecture)
3183 ("assertion" vhdl-template-assert)
3184 ("attribute declaration" vhdl-template-attribute-decl)
3185 ("attribute specification" vhdl-template-attribute-spec)
3186 ("block configuration" vhdl-template-block-configuration)
3187 ("block statement" vhdl-template-block)
3188 ("case statement" vhdl-template-case-is)
3189 ("component configuration" vhdl-template-component-conf)
3190 ("component declaration" vhdl-template-component-decl)
3191 ("component instantiation statement" vhdl-template-component-inst)
3192 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3193 ("configuration declaration" vhdl-template-configuration-decl)
3194 ("configuration specification" vhdl-template-configuration-spec)
3195 ("constant declaration" vhdl-template-constant)
3196 ("context declaration" vhdl-template-context)
3197 ("disconnection specification" vhdl-template-disconnect)
3198 ("entity declaration" vhdl-template-entity)
3199 ("exit statement" vhdl-template-exit)
3200 ("file declaration" vhdl-template-file)
3201 ("generate statement" vhdl-template-generate)
3202 ("generic clause" vhdl-template-generic)
3203 ("group declaration" vhdl-template-group-decl)
3204 ("group template declaration" vhdl-template-group-template)
3205 ("if statement" vhdl-template-if-then)
3206 ("library clause" vhdl-template-library)
3207 ("loop statement" vhdl-template-loop)
3208 ("next statement" vhdl-template-next)
3209 ("package declaration" vhdl-template-package-decl)
3210 ("package body" vhdl-template-package-body)
3211 ("port clause" vhdl-template-port)
3212 ("process statement" vhdl-template-process)
3213 ("report statement" vhdl-template-report)
3214 ("return statement" vhdl-template-return)
3215 ("selected signal assignment" vhdl-template-selected-signal-asst)
3216 ("signal declaration" vhdl-template-signal)
3217 ("subprogram declaration" vhdl-template-subprogram-decl)
3218 ("subprogram body" vhdl-template-subprogram-body)
3219 ("subtype declaration" vhdl-template-subtype)
3220 ("type declaration" vhdl-template-type)
3221 ("use clause" vhdl-template-use)
3222 ("variable declaration" vhdl-template-variable)
3223 ("wait statement" vhdl-template-wait)
3224 )
3225 (when (vhdl-standard-p 'ams)
3226 '(
3227 ("break statement" vhdl-template-break)
3228 ("nature declaration" vhdl-template-nature)
3229 ("quantity declaration" vhdl-template-quantity)
3230 ("simultaneous case statement" vhdl-template-case-use)
3231 ("simultaneous if statement" vhdl-template-if-use)
3232 ("simultaneous procedural statement" vhdl-template-procedural)
3233 ("step limit specification" vhdl-template-limit)
3234 ("subnature declaration" vhdl-template-subnature)
3235 ("terminal declaration" vhdl-template-terminal)
3236 )))))
3237
3238 ;; initialize for VHDL Mode
3239 (vhdl-template-construct-alist-init)
3240
3241 (defvar vhdl-template-package-alist nil
3242 "List of built-in package templates.")
3243
3244 (defun vhdl-template-package-alist-init ()
3245 "Initialize `vhdl-template-package-alist'."
3246 (setq
3247 vhdl-template-package-alist
3248 (append
3249 '(
3250 ("numeric_bit" vhdl-template-package-numeric-bit)
3251 ("numeric_std" vhdl-template-package-numeric-std)
3252 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3253 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3254 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3255 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3256 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3257 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3258 ("textio" vhdl-template-package-textio)
3259 )
3260 (when (vhdl-standard-p 'math)
3261 '(
3262 ("math_complex" vhdl-template-package-math-complex)
3263 ("math_real" vhdl-template-package-math-real)
3264 )))))
3265
3266 ;; initialize for VHDL Mode
3267 (vhdl-template-package-alist-init)
3268
3269 (defvar vhdl-template-directive-alist
3270 '(
3271 ("translate_on" vhdl-template-directive-translate-on)
3272 ("translate_off" vhdl-template-directive-translate-off)
3273 ("synthesis_on" vhdl-template-directive-synthesis-on)
3274 ("synthesis_off" vhdl-template-directive-synthesis-off)
3275 )
3276 "List of built-in directive templates.")
3277
3278
3279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3280 ;;; Menus
3281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3282
3283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3284 ;; VHDL menu (using `easy-menu.el')
3285
3286 (defun vhdl-customize ()
3287 "Call the customize function with `vhdl' as argument."
3288 (interactive)
3289 (customize-browse 'vhdl))
3290
3291 (defun vhdl-create-mode-menu ()
3292 "Create VHDL Mode menu."
3293 `("VHDL"
3294 ,(append
3295 '("Project"
3296 ["None" (vhdl-set-project "")
3297 :style radio :selected (null vhdl-project)]
3298 "--")
3299 ;; add menu entries for defined projects
3300 (let ((project-alist vhdl-project-alist) menu-list name)
3301 (while project-alist
3302 (setq name (caar project-alist))
3303 (setq menu-list
3304 (cons `[,name (vhdl-set-project ,name)
3305 :style radio :selected (equal ,name vhdl-project)]
3306 menu-list))
3307 (setq project-alist (cdr project-alist)))
3308 (setq menu-list
3309 (if vhdl-project-sort
3310 (sort menu-list
3311 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3312 (nreverse menu-list)))
3313 (vhdl-menu-split menu-list "Project"))
3314 '("--" "--"
3315 ["Select Project..." vhdl-set-project t]
3316 ["Set As Default Project" vhdl-set-default-project t]
3317 "--"
3318 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3319 ["Import Project..." vhdl-import-project
3320 :keys "C-c C-p C-m" :active t]
3321 ["Export Project" vhdl-export-project vhdl-project]
3322 "--"
3323 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3324 "--"
3325 ("Compile"
3326 ["Compile Buffer" vhdl-compile t]
3327 ["Stop Compilation" kill-compilation t]
3328 "--"
3329 ["Make" vhdl-make t]
3330 ["Generate Makefile" vhdl-generate-makefile t]
3331 "--"
3332 ["Next Error" next-error t]
3333 ["Previous Error" previous-error t]
3334 ["First Error" first-error t]
3335 "--"
3336 ,(append
3337 '("Compiler")
3338 ;; add menu entries for defined compilers
3339 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3340 (while comp-alist
3341 (setq name (caar comp-alist))
3342 (setq menu-list
3343 (cons `[,name (setq vhdl-compiler ,name)
3344 :style radio :selected (equal ,name vhdl-compiler)]
3345 menu-list))
3346 (setq comp-alist (cdr comp-alist)))
3347 (setq menu-list (nreverse menu-list))
3348 (vhdl-menu-split menu-list "Compiler"))
3349 '("--" "--"
3350 ["Select Compiler..." vhdl-set-compiler t]
3351 "--"
3352 ["Customize Compiler..."
3353 (customize-option 'vhdl-compiler-alist) t])))
3354 "--"
3355 ,(append
3356 '("Template"
3357 ("VHDL Construct 1"
3358 ["Alias" vhdl-template-alias t]
3359 ["Architecture" vhdl-template-architecture t]
3360 ["Assert" vhdl-template-assert t]
3361 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3362 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3363 ["Block" vhdl-template-block t]
3364 ["Case" vhdl-template-case-is t]
3365 ["Component (Decl)" vhdl-template-component-decl t]
3366 ["(Component) Instance" vhdl-template-component-inst t]
3367 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3368 ["Configuration (Block)" vhdl-template-block-configuration t]
3369 ["Configuration (Comp)" vhdl-template-component-conf t]
3370 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3371 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3372 ["Constant" vhdl-template-constant t]
3373 ["Context" vhdl-template-context t]
3374 ["Disconnect" vhdl-template-disconnect t]
3375 ["Else" vhdl-template-else t]
3376 ["Elsif" vhdl-template-elsif t]
3377 ["Entity" vhdl-template-entity t]
3378 ["Exit" vhdl-template-exit t]
3379 ["File" vhdl-template-file t]
3380 ["For (Generate)" vhdl-template-for-generate t]
3381 ["For (Loop)" vhdl-template-for-loop t]
3382 ["Function (Body)" vhdl-template-function-body t]
3383 ["Function (Decl)" vhdl-template-function-decl t]
3384 ["Generic" vhdl-template-generic t]
3385 ["Group (Decl)" vhdl-template-group-decl t]
3386 ["Group (Template)" vhdl-template-group-template t])
3387 ("VHDL Construct 2"
3388 ["If (Generate)" vhdl-template-if-generate t]
3389 ["If (Then)" vhdl-template-if-then t]
3390 ["Library" vhdl-template-library t]
3391 ["Loop" vhdl-template-bare-loop t]
3392 ["Map" vhdl-template-map t]
3393 ["Next" vhdl-template-next t]
3394 ["Others (Aggregate)" vhdl-template-others t]
3395 ["Package (Decl)" vhdl-template-package-decl t]
3396 ["Package (Body)" vhdl-template-package-body t]
3397 ["Port" vhdl-template-port t]
3398 ["Procedure (Body)" vhdl-template-procedure-body t]
3399 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3400 ["Process (Comb)" vhdl-template-process-comb t]
3401 ["Process (Seq)" vhdl-template-process-seq t]
3402 ["Report" vhdl-template-report t]
3403 ["Return" vhdl-template-return t]
3404 ["Select" vhdl-template-selected-signal-asst t]
3405 ["Signal" vhdl-template-signal t]
3406 ["Subtype" vhdl-template-subtype t]
3407 ["Type" vhdl-template-type t]
3408 ["Use" vhdl-template-use t]
3409 ["Variable" vhdl-template-variable t]
3410 ["Wait" vhdl-template-wait t]
3411 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3412 ["When" vhdl-template-when t]
3413 ["While (Loop)" vhdl-template-while-loop t]
3414 ["With" vhdl-template-with t]))
3415 (when (vhdl-standard-p 'ams)
3416 '(("VHDL-AMS Construct"
3417 ["Break" vhdl-template-break t]
3418 ["Case (Use)" vhdl-template-case-use t]
3419 ["If (Use)" vhdl-template-if-use t]
3420 ["Limit" vhdl-template-limit t]
3421 ["Nature" vhdl-template-nature t]
3422 ["Procedural" vhdl-template-procedural t]
3423 ["Quantity (Free)" vhdl-template-quantity-free t]
3424 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3425 ["Quantity (Source)" vhdl-template-quantity-source t]
3426 ["Subnature" vhdl-template-subnature t]
3427 ["Terminal" vhdl-template-terminal t])))
3428 '(["Insert Construct..." vhdl-template-insert-construct
3429 :keys "C-c C-i C-t"]
3430 "--")
3431 (list
3432 (append
3433 '("Package")
3434 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3435 ["numeric_std" vhdl-template-package-numeric-std t]
3436 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3437 ["textio" vhdl-template-package-textio t]
3438 "--"
3439 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3440 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3441 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3442 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3443 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3444 "--")
3445 (when (vhdl-standard-p 'ams)
3446 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3447 ["material_constants" vhdl-template-package-material-constants t]
3448 ["energy_systems" vhdl-template-package-energy-systems t]
3449 ["electrical_systems" vhdl-template-package-electrical-systems t]
3450 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3451 ["radiant_systems" vhdl-template-package-radiant-systems t]
3452 ["thermal_systems" vhdl-template-package-thermal-systems t]
3453 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3454 "--"))
3455 (when (vhdl-standard-p 'math)
3456 '(["math_complex" vhdl-template-package-math-complex t]
3457 ["math_real" vhdl-template-package-math-real t]
3458 "--"))
3459 '(["Insert Package..." vhdl-template-insert-package
3460 :keys "C-c C-i C-p"])))
3461 '(("Directive"
3462 ["translate_on" vhdl-template-directive-translate-on t]
3463 ["translate_off" vhdl-template-directive-translate-off t]
3464 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3465 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3466 "--"
3467 ["Insert Directive..." vhdl-template-insert-directive
3468 :keys "C-c C-i C-d"])
3469 "--"
3470 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3471 ["Insert Footer" vhdl-template-footer t]
3472 ["Insert Date" vhdl-template-insert-date t]
3473 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3474 "--"
3475 ["Query Next Prompt" vhdl-template-search-prompt t]))
3476 ,(append
3477 '("Model")
3478 ;; add menu entries for defined models
3479 (let ((model-alist vhdl-model-alist) menu-list model)
3480 (while model-alist
3481 (setq model (car model-alist))
3482 (setq menu-list
3483 (cons
3484 (vector
3485 (nth 0 model)
3486 (vhdl-function-name "vhdl-model" (nth 0 model))
3487 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3488 menu-list))
3489 (setq model-alist (cdr model-alist)))
3490 (setq menu-list (nreverse menu-list))
3491 (vhdl-menu-split menu-list "Model"))
3492 '("--" "--"
3493 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3494 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3495 ("Port"
3496 ["Copy" vhdl-port-copy t]
3497 "--"
3498 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3499 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3500 ["Paste As Instance" vhdl-port-paste-instance
3501 :keys "C-c C-p C-i" :active vhdl-port-list]
3502 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3503 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3504 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3505 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3506 "--"
3507 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3508 "--"
3509 ["Flatten" vhdl-port-flatten
3510 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3511 ["Reverse Direction" vhdl-port-reverse-direction
3512 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3513 ("Compose"
3514 ["New Component" vhdl-compose-new-component t]
3515 ["Copy Component" vhdl-port-copy t]
3516 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3517 ["Wire Components" vhdl-compose-wire-components t]
3518 "--"
3519 ["Generate Configuration" vhdl-compose-configuration t]
3520 ["Generate Components Package" vhdl-compose-components-package t])
3521 ("Subprogram"
3522 ["Copy" vhdl-subprog-copy t]
3523 "--"
3524 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3525 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3526 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3527 "--"
3528 ["Flatten" vhdl-subprog-flatten
3529 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3530 "--"
3531 ("Comment"
3532 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3533 "--"
3534 ["Insert Inline Comment" vhdl-comment-append-inline t]
3535 ["Insert Horizontal Line" vhdl-comment-display-line t]
3536 ["Insert Display Comment" vhdl-comment-display t]
3537 "--"
3538 ["Fill Comment" fill-paragraph t]
3539 ["Fill Comment Region" fill-region (mark)]
3540 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3541 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3542 ("Line"
3543 ["Kill" vhdl-line-kill t]
3544 ["Copy" vhdl-line-copy t]
3545 ["Yank" vhdl-line-yank t]
3546 ["Expand" vhdl-line-expand t]
3547 "--"
3548 ["Transpose Next" vhdl-line-transpose-next t]
3549 ["Transpose Prev" vhdl-line-transpose-previous t]
3550 ["Open" vhdl-line-open t]
3551 ["Join" vhdl-delete-indentation t]
3552 "--"
3553 ["Goto" goto-line t]
3554 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3555 ("Move"
3556 ["Forward Statement" vhdl-end-of-statement t]
3557 ["Backward Statement" vhdl-beginning-of-statement t]
3558 ["Forward Expression" vhdl-forward-sexp t]
3559 ["Backward Expression" vhdl-backward-sexp t]
3560 ["Forward Same Indent" vhdl-forward-same-indent t]
3561 ["Backward Same Indent" vhdl-backward-same-indent t]
3562 ["Forward Function" vhdl-end-of-defun t]
3563 ["Backward Function" vhdl-beginning-of-defun t]
3564 ["Mark Function" vhdl-mark-defun t])
3565 "--"
3566 ("Indent"
3567 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3568 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3569 ["Region" vhdl-indent-region (mark)]
3570 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3571 ("Align"
3572 ["Group" vhdl-align-group t]
3573 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3574 ["List" vhdl-align-list t]
3575 ["Declarations" vhdl-align-declarations t]
3576 ["Region" vhdl-align-region (mark)]
3577 ["Buffer" vhdl-align-buffer t]
3578 "--"
3579 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3580 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3581 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3582 ("Fill"
3583 ["List" vhdl-fill-list t]
3584 ["Group" vhdl-fill-group t]
3585 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3586 ["Region" vhdl-fill-region (mark)])
3587 ("Beautify"
3588 ["Region" vhdl-beautify-region (mark)]
3589 ["Buffer" vhdl-beautify-buffer t])
3590 ("Fix"
3591 ["Generic/Port Clause" vhdl-fix-clause t]
3592 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3593 "--"
3594 ["Case Region" vhdl-fix-case-region (mark)]
3595 ["Case Buffer" vhdl-fix-case-buffer t]
3596 "--"
3597 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3598 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3599 "--"
3600 ["Statement Region" vhdl-fix-statement-region (mark)]
3601 ["Statement Buffer" vhdl-fix-statement-buffer t]
3602 "--"
3603 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3604 ("Update"
3605 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3606 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3607 "--"
3608 ["Fontify Buffer" vhdl-fontify-buffer t]
3609 ["Statistics Buffer" vhdl-statistics-buffer t]
3610 ["Show Messages" vhdl-show-messages t]
3611 ["Syntactic Info" vhdl-show-syntactic-information t]
3612 "--"
3613 ["Speedbar" vhdl-speedbar t]
3614 ["Hide/Show" vhdl-hs-minor-mode t]
3615 "--"
3616 ("Documentation"
3617 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3618 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3619 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3620 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3621 ["Version" vhdl-version t]
3622 ["Bug Report..." vhdl-submit-bug-report t]
3623 "--"
3624 ("Options"
3625 ("Mode"
3626 ["Electric Mode"
3627 (progn (customize-set-variable 'vhdl-electric-mode
3628 (not vhdl-electric-mode))
3629 (vhdl-mode-line-update))
3630 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3631 ["Stutter Mode"
3632 (progn (customize-set-variable 'vhdl-stutter-mode
3633 (not vhdl-stutter-mode))
3634 (vhdl-mode-line-update))
3635 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3636 ["Indent Tabs Mode"
3637 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3638 (not vhdl-indent-tabs-mode))
3639 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3640 :style toggle :selected vhdl-indent-tabs-mode]
3641 "--"
3642 ["Customize Group..." (customize-group 'vhdl-mode) t])
3643 ("Project"
3644 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3645 ,(append
3646 '("Selected Project at Startup"
3647 ["None" (progn (customize-set-variable 'vhdl-project nil)
3648 (vhdl-set-project ""))
3649 :style radio :selected (null vhdl-project)]
3650 "--")
3651 ;; add menu entries for defined projects
3652 (let ((project-alist vhdl-project-alist) menu-list name)
3653 (while project-alist
3654 (setq name (caar project-alist))
3655 (setq menu-list
3656 (cons `[,name (progn (customize-set-variable
3657 'vhdl-project ,name)
3658 (vhdl-set-project ,name))
3659 :style radio :selected (equal ,name vhdl-project)]
3660 menu-list))
3661 (setq project-alist (cdr project-alist)))
3662 (setq menu-list (nreverse menu-list))
3663 (vhdl-menu-split menu-list "Project")))
3664 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3665 ("Auto Load Setup File"
3666 ["At Startup"
3667 (customize-set-variable 'vhdl-project-auto-load
3668 (if (memq 'startup vhdl-project-auto-load)
3669 (delq 'startup vhdl-project-auto-load)
3670 (cons 'startup vhdl-project-auto-load)))
3671 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3672 ["Sort Projects"
3673 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3674 :style toggle :selected vhdl-project-sort]
3675 "--"
3676 ["Customize Group..." (customize-group 'vhdl-project) t])
3677 ("Compiler"
3678 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3679 ,(append
3680 '("Selected Compiler at Startup")
3681 ;; add menu entries for defined compilers
3682 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3683 (while comp-alist
3684 (setq name (caar comp-alist))
3685 (setq menu-list
3686 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3687 :style radio :selected (equal ,name vhdl-compiler)]
3688 menu-list))
3689 (setq comp-alist (cdr comp-alist)))
3690 (setq menu-list (nreverse menu-list))
3691 (vhdl-menu-split menu-list "Compiler")))
3692 ["Use Local Error Regexp"
3693 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3694 (not vhdl-compile-use-local-error-regexp))
3695 :style toggle :selected vhdl-compile-use-local-error-regexp]
3696 ["Makefile Default Targets..."
3697 (customize-option 'vhdl-makefile-default-targets) t]
3698 ["Makefile Generation Hook..."
3699 (customize-option 'vhdl-makefile-generation-hook) t]
3700 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3701 "--"
3702 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3703 ("Style"
3704 ("VHDL Standard"
3705 ["VHDL'87"
3706 (progn (customize-set-variable 'vhdl-standard
3707 (list '87 (cadr vhdl-standard)))
3708 (vhdl-activate-customizations))
3709 :style radio :selected (eq '87 (car vhdl-standard))]
3710 ["VHDL'93/02"
3711 (progn (customize-set-variable 'vhdl-standard
3712 (list '93 (cadr vhdl-standard)))
3713 (vhdl-activate-customizations))
3714 :style radio :selected (eq '93 (car vhdl-standard))]
3715 ["VHDL'08"
3716 (progn (customize-set-variable 'vhdl-standard
3717 (list '08 (cadr vhdl-standard)))
3718 (vhdl-activate-customizations))
3719 :style radio :selected (eq '08 (car vhdl-standard))]
3720 "--"
3721 ["VHDL-AMS"
3722 (progn (customize-set-variable
3723 'vhdl-standard (list (car vhdl-standard)
3724 (if (memq 'ams (cadr vhdl-standard))
3725 (delq 'ams (cadr vhdl-standard))
3726 (cons 'ams (cadr vhdl-standard)))))
3727 (vhdl-activate-customizations))
3728 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3729 ["Math Packages"
3730 (progn (customize-set-variable
3731 'vhdl-standard (list (car vhdl-standard)
3732 (if (memq 'math (cadr vhdl-standard))
3733 (delq 'math (cadr vhdl-standard))
3734 (cons 'math (cadr vhdl-standard)))))
3735 (vhdl-activate-customizations))
3736 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3737 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3738 ["Upper Case Keywords"
3739 (customize-set-variable 'vhdl-upper-case-keywords
3740 (not vhdl-upper-case-keywords))
3741 :style toggle :selected vhdl-upper-case-keywords]
3742 ["Upper Case Types"
3743 (customize-set-variable 'vhdl-upper-case-types
3744 (not vhdl-upper-case-types))
3745 :style toggle :selected vhdl-upper-case-types]
3746 ["Upper Case Attributes"
3747 (customize-set-variable 'vhdl-upper-case-attributes
3748 (not vhdl-upper-case-attributes))
3749 :style toggle :selected vhdl-upper-case-attributes]
3750 ["Upper Case Enumeration Values"
3751 (customize-set-variable 'vhdl-upper-case-enum-values
3752 (not vhdl-upper-case-enum-values))
3753 :style toggle :selected vhdl-upper-case-enum-values]
3754 ["Upper Case Constants"
3755 (customize-set-variable 'vhdl-upper-case-constants
3756 (not vhdl-upper-case-constants))
3757 :style toggle :selected vhdl-upper-case-constants]
3758 ("Use Direct Instantiation"
3759 ["Never"
3760 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3761 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3762 ["Standard"
3763 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3764 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3765 ["Always"
3766 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3767 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3768 ["Include Array Index and Record Field in Sensitivity List"
3769 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3770 (not vhdl-array-index-record-field-in-sensitivity-list))
3771 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3772 "--"
3773 ["Customize Group..." (customize-group 'vhdl-style) t])
3774 ("Naming"
3775 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3776 ["Architecture File Name..."
3777 (customize-option 'vhdl-architecture-file-name) t]
3778 ["Configuration File Name..."
3779 (customize-option 'vhdl-configuration-file-name) t]
3780 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3781 ("File Name Case"
3782 ["As Is"
3783 (customize-set-variable 'vhdl-file-name-case 'identity)
3784 :style radio :selected (eq 'identity vhdl-file-name-case)]
3785 ["Lower Case"
3786 (customize-set-variable 'vhdl-file-name-case 'downcase)
3787 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3788 ["Upper Case"
3789 (customize-set-variable 'vhdl-file-name-case 'upcase)
3790 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3791 ["Capitalize"
3792 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3793 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3794 "--"
3795 ["Customize Group..." (customize-group 'vhdl-naming) t])
3796 ("Template"
3797 ("Electric Keywords"
3798 ["VHDL Keywords"
3799 (customize-set-variable 'vhdl-electric-keywords
3800 (if (memq 'vhdl vhdl-electric-keywords)
3801 (delq 'vhdl vhdl-electric-keywords)
3802 (cons 'vhdl vhdl-electric-keywords)))
3803 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3804 ["User Model Keywords"
3805 (customize-set-variable 'vhdl-electric-keywords
3806 (if (memq 'user vhdl-electric-keywords)
3807 (delq 'user vhdl-electric-keywords)
3808 (cons 'user vhdl-electric-keywords)))
3809 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3810 ("Insert Optional Labels"
3811 ["None"
3812 (customize-set-variable 'vhdl-optional-labels 'none)
3813 :style radio :selected (eq 'none vhdl-optional-labels)]
3814 ["Processes Only"
3815 (customize-set-variable 'vhdl-optional-labels 'process)
3816 :style radio :selected (eq 'process vhdl-optional-labels)]
3817 ["All Constructs"
3818 (customize-set-variable 'vhdl-optional-labels 'all)
3819 :style radio :selected (eq 'all vhdl-optional-labels)])
3820 ("Insert Empty Lines"
3821 ["None"
3822 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3823 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3824 ["Design Units Only"
3825 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3826 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3827 ["All Constructs"
3828 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3829 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3830 ["Argument List Indent"
3831 (customize-set-variable 'vhdl-argument-list-indent
3832 (not vhdl-argument-list-indent))
3833 :style toggle :selected vhdl-argument-list-indent]
3834 ["Association List with Formals"
3835 (customize-set-variable 'vhdl-association-list-with-formals
3836 (not vhdl-association-list-with-formals))
3837 :style toggle :selected vhdl-association-list-with-formals]
3838 ["Conditions in Parenthesis"
3839 (customize-set-variable 'vhdl-conditions-in-parenthesis
3840 (not vhdl-conditions-in-parenthesis))
3841 :style toggle :selected vhdl-conditions-in-parenthesis]
3842 ["Sensitivity List uses 'all'"
3843 (customize-set-variable 'vhdl-sensitivity-list-all
3844 (not vhdl-sensitivity-list-all))
3845 :style toggle :selected vhdl-sensitivity-list-all]
3846 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3847 ["One String..." (customize-option 'vhdl-one-string) t]
3848 ("File Header"
3849 ["Header String..." (customize-option 'vhdl-file-header) t]
3850 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3851 ["Company Name..." (customize-option 'vhdl-company-name) t]
3852 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3853 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3854 ["Date Format..." (customize-option 'vhdl-date-format) t]
3855 ["Modify Date Prefix String..."
3856 (customize-option 'vhdl-modify-date-prefix-string) t]
3857 ["Modify Date on Saving"
3858 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3859 (not vhdl-modify-date-on-saving))
3860 (vhdl-activate-customizations))
3861 :style toggle :selected vhdl-modify-date-on-saving])
3862 ("Sequential Process"
3863 ("Kind of Reset"
3864 ["None"
3865 (customize-set-variable 'vhdl-reset-kind 'none)
3866 :style radio :selected (eq 'none vhdl-reset-kind)]
3867 ["Synchronous"
3868 (customize-set-variable 'vhdl-reset-kind 'sync)
3869 :style radio :selected (eq 'sync vhdl-reset-kind)]
3870 ["Asynchronous"
3871 (customize-set-variable 'vhdl-reset-kind 'async)
3872 :style radio :selected (eq 'async vhdl-reset-kind)]
3873 ["Query"
3874 (customize-set-variable 'vhdl-reset-kind 'query)
3875 :style radio :selected (eq 'query vhdl-reset-kind)])
3876 ["Reset is Active High"
3877 (customize-set-variable 'vhdl-reset-active-high
3878 (not vhdl-reset-active-high))
3879 :style toggle :selected vhdl-reset-active-high]
3880 ["Use Rising Clock Edge"
3881 (customize-set-variable 'vhdl-clock-rising-edge
3882 (not vhdl-clock-rising-edge))
3883 :style toggle :selected vhdl-clock-rising-edge]
3884 ("Clock Edge Condition"
3885 ["Standard"
3886 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3887 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3888 ["Function \"rising_edge\""
3889 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3890 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3891 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3892 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3893 "--"
3894 ["Customize Group..." (customize-group 'vhdl-template) t])
3895 ("Model"
3896 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3897 ("Port"
3898 ["Include Port Comments"
3899 (customize-set-variable 'vhdl-include-port-comments
3900 (not vhdl-include-port-comments))
3901 :style toggle :selected vhdl-include-port-comments]
3902 ["Include Direction Comments"
3903 (customize-set-variable 'vhdl-include-direction-comments
3904 (not vhdl-include-direction-comments))
3905 :style toggle :selected vhdl-include-direction-comments]
3906 ["Include Type Comments"
3907 (customize-set-variable 'vhdl-include-type-comments
3908 (not vhdl-include-type-comments))
3909 :style toggle :selected vhdl-include-type-comments]
3910 ("Include Group Comments"
3911 ["Never"
3912 (customize-set-variable 'vhdl-include-group-comments 'never)
3913 :style radio :selected (eq 'never vhdl-include-group-comments)]
3914 ["Declarations"
3915 (customize-set-variable 'vhdl-include-group-comments 'decl)
3916 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3917 ["Always"
3918 (customize-set-variable 'vhdl-include-group-comments 'always)
3919 :style radio :selected (eq 'always vhdl-include-group-comments)])
3920 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3921 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3922 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3923 ("Testbench"
3924 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3925 ["Architecture Name..."
3926 (customize-option 'vhdl-testbench-architecture-name) t]
3927 ["Configuration Name..."
3928 (customize-option 'vhdl-testbench-configuration-name) t]
3929 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3930 ["Include Header"
3931 (customize-set-variable 'vhdl-testbench-include-header
3932 (not vhdl-testbench-include-header))
3933 :style toggle :selected vhdl-testbench-include-header]
3934 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3935 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3936 ["Initialize Signals"
3937 (customize-set-variable 'vhdl-testbench-initialize-signals
3938 (not vhdl-testbench-initialize-signals))
3939 :style toggle :selected vhdl-testbench-initialize-signals]
3940 ["Include Library Clause"
3941 (customize-set-variable 'vhdl-testbench-include-library
3942 (not vhdl-testbench-include-library))
3943 :style toggle :selected vhdl-testbench-include-library]
3944 ["Include Configuration"
3945 (customize-set-variable 'vhdl-testbench-include-configuration
3946 (not vhdl-testbench-include-configuration))
3947 :style toggle :selected vhdl-testbench-include-configuration]
3948 ("Create Files"
3949 ["None"
3950 (customize-set-variable 'vhdl-testbench-create-files 'none)
3951 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3952 ["Single"
3953 (customize-set-variable 'vhdl-testbench-create-files 'single)
3954 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3955 ["Separate"
3956 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3957 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3958 ["Testbench Entity File Name..."
3959 (customize-option 'vhdl-testbench-entity-file-name) t]
3960 ["Testbench Architecture File Name..."
3961 (customize-option 'vhdl-testbench-architecture-file-name) t])
3962 "--"
3963 ["Customize Group..." (customize-group 'vhdl-port) t])
3964 ("Compose"
3965 ["Architecture Name..."
3966 (customize-option 'vhdl-compose-architecture-name) t]
3967 ["Configuration Name..."
3968 (customize-option 'vhdl-compose-configuration-name) t]
3969 ["Components Package Name..."
3970 (customize-option 'vhdl-components-package-name) t]
3971 ["Use Components Package"
3972 (customize-set-variable 'vhdl-use-components-package
3973 (not vhdl-use-components-package))
3974 :style toggle :selected vhdl-use-components-package]
3975 ["Include Header"
3976 (customize-set-variable 'vhdl-compose-include-header
3977 (not vhdl-compose-include-header))
3978 :style toggle :selected vhdl-compose-include-header]
3979 ("Create Entity/Architecture Files"
3980 ["None"
3981 (customize-set-variable 'vhdl-compose-create-files 'none)
3982 :style radio :selected (eq 'none vhdl-compose-create-files)]
3983 ["Single"
3984 (customize-set-variable 'vhdl-compose-create-files 'single)
3985 :style radio :selected (eq 'single vhdl-compose-create-files)]
3986 ["Separate"
3987 (customize-set-variable 'vhdl-compose-create-files 'separate)
3988 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3989 ["Create Configuration File"
3990 (customize-set-variable 'vhdl-compose-configuration-create-file
3991 (not vhdl-compose-configuration-create-file))
3992 :style toggle :selected vhdl-compose-configuration-create-file]
3993 ["Hierarchical Configuration"
3994 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3995 (not vhdl-compose-configuration-hierarchical))
3996 :style toggle :selected vhdl-compose-configuration-hierarchical]
3997 ["Use Subconfiguration"
3998 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3999 (not vhdl-compose-configuration-use-subconfiguration))
4000 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
4001 "--"
4002 ["Customize Group..." (customize-group 'vhdl-compose) t])
4003 ("Comment"
4004 ["Self Insert Comments"
4005 (customize-set-variable 'vhdl-self-insert-comments
4006 (not vhdl-self-insert-comments))
4007 :style toggle :selected vhdl-self-insert-comments]
4008 ["Prompt for Comments"
4009 (customize-set-variable 'vhdl-prompt-for-comments
4010 (not vhdl-prompt-for-comments))
4011 :style toggle :selected vhdl-prompt-for-comments]
4012 ["Inline Comment Column..."
4013 (customize-option 'vhdl-inline-comment-column) t]
4014 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4015 "--"
4016 ["Customize Group..." (customize-group 'vhdl-comment) t])
4017 ("Beautify"
4018 ["Auto Align Templates"
4019 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4020 :style toggle :selected vhdl-auto-align]
4021 ["Align Line Groups"
4022 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4023 :style toggle :selected vhdl-align-groups]
4024 ["Group Separation String..."
4025 (customize-option 'vhdl-align-group-separate) t]
4026 ["Align Lines with Same Indent"
4027 (customize-set-variable 'vhdl-align-same-indent
4028 (not vhdl-align-same-indent))
4029 :style toggle :selected vhdl-align-same-indent]
4030 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4031 "--"
4032 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4033 ("Highlight"
4034 ["Highlighting On/Off..."
4035 (customize-option
4036 (if (fboundp 'global-font-lock-mode)
4037 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4038 ["Highlight Keywords"
4039 (progn (customize-set-variable 'vhdl-highlight-keywords
4040 (not vhdl-highlight-keywords))
4041 (vhdl-fontify-buffer))
4042 :style toggle :selected vhdl-highlight-keywords]
4043 ["Highlight Names"
4044 (progn (customize-set-variable 'vhdl-highlight-names
4045 (not vhdl-highlight-names))
4046 (vhdl-fontify-buffer))
4047 :style toggle :selected vhdl-highlight-names]
4048 ["Highlight Special Words"
4049 (progn (customize-set-variable 'vhdl-highlight-special-words
4050 (not vhdl-highlight-special-words))
4051 (vhdl-fontify-buffer))
4052 :style toggle :selected vhdl-highlight-special-words]
4053 ["Highlight Forbidden Words"
4054 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4055 (not vhdl-highlight-forbidden-words))
4056 (vhdl-fontify-buffer))
4057 :style toggle :selected vhdl-highlight-forbidden-words]
4058 ["Highlight Verilog Keywords"
4059 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4060 (not vhdl-highlight-verilog-keywords))
4061 (vhdl-fontify-buffer))
4062 :style toggle :selected vhdl-highlight-verilog-keywords]
4063 ["Highlight \"translate_off\""
4064 (progn (customize-set-variable 'vhdl-highlight-translate-off
4065 (not vhdl-highlight-translate-off))
4066 (vhdl-fontify-buffer))
4067 :style toggle :selected vhdl-highlight-translate-off]
4068 ["Case Sensitive Highlighting"
4069 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4070 (not vhdl-highlight-case-sensitive))
4071 (vhdl-fontify-buffer))
4072 :style toggle :selected vhdl-highlight-case-sensitive]
4073 ["Special Syntax Definition..."
4074 (customize-option 'vhdl-special-syntax-alist) t]
4075 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4076 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4077 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4078 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4079 "--"
4080 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4081 ("Speedbar"
4082 ["Auto Open at Startup"
4083 (customize-set-variable 'vhdl-speedbar-auto-open
4084 (not vhdl-speedbar-auto-open))
4085 :style toggle :selected vhdl-speedbar-auto-open]
4086 ("Default Displaying Mode"
4087 ["Files"
4088 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4089 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4090 ["Directory Hierarchy"
4091 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4092 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4093 ["Project Hierarchy"
4094 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4095 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4096 ["Indentation Offset..."
4097 (customize-option 'speedbar-indentation-width) t]
4098 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4099 ["Jump to Unit when Opening"
4100 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4101 (not vhdl-speedbar-jump-to-unit))
4102 :style toggle :selected vhdl-speedbar-jump-to-unit]
4103 ["Update Hierarchy on File Saving"
4104 (customize-set-variable 'vhdl-speedbar-update-on-saving
4105 (not vhdl-speedbar-update-on-saving))
4106 :style toggle :selected vhdl-speedbar-update-on-saving]
4107 ("Save in Cache File"
4108 ["Hierarchy Information"
4109 (customize-set-variable 'vhdl-speedbar-save-cache
4110 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4111 (delq 'hierarchy vhdl-speedbar-save-cache)
4112 (cons 'hierarchy vhdl-speedbar-save-cache)))
4113 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4114 ["Displaying Status"
4115 (customize-set-variable 'vhdl-speedbar-save-cache
4116 (if (memq 'display vhdl-speedbar-save-cache)
4117 (delq 'display vhdl-speedbar-save-cache)
4118 (cons 'display vhdl-speedbar-save-cache)))
4119 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4120 ["Cache File Name..."
4121 (customize-option 'vhdl-speedbar-cache-file-name) t]
4122 "--"
4123 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4124 ("Menu"
4125 ["Add Index Menu when Loading File"
4126 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4127 (vhdl-index-menu-init))
4128 :style toggle :selected vhdl-index-menu]
4129 ["Add Source File Menu when Loading File"
4130 (progn (customize-set-variable 'vhdl-source-file-menu
4131 (not vhdl-source-file-menu))
4132 (vhdl-add-source-files-menu))
4133 :style toggle :selected vhdl-source-file-menu]
4134 ["Add Hideshow Menu at Startup"
4135 (progn (customize-set-variable 'vhdl-hideshow-menu
4136 (not vhdl-hideshow-menu))
4137 (vhdl-activate-customizations))
4138 :style toggle :selected vhdl-hideshow-menu]
4139 ["Hide Everything Initially"
4140 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4141 :style toggle :selected vhdl-hide-all-init]
4142 "--"
4143 ["Customize Group..." (customize-group 'vhdl-menu) t])
4144 ("Print"
4145 ["In Two Column Format"
4146 (progn (customize-set-variable 'vhdl-print-two-column
4147 (not vhdl-print-two-column))
4148 (message "Activate new setting by saving options and restarting Emacs"))
4149 :style toggle :selected vhdl-print-two-column]
4150 ["Use Customized Faces"
4151 (progn (customize-set-variable 'vhdl-print-customize-faces
4152 (not vhdl-print-customize-faces))
4153 (message "Activate new setting by saving options and restarting Emacs"))
4154 :style toggle :selected vhdl-print-customize-faces]
4155 "--"
4156 ["Customize Group..." (customize-group 'vhdl-print) t])
4157 ("Miscellaneous"
4158 ["Use Intelligent Tab"
4159 (progn (customize-set-variable 'vhdl-intelligent-tab
4160 (not vhdl-intelligent-tab))
4161 (vhdl-activate-customizations))
4162 :style toggle :selected vhdl-intelligent-tab]
4163 ["Indent Syntax-Based"
4164 (customize-set-variable 'vhdl-indent-syntax-based
4165 (not vhdl-indent-syntax-based))
4166 :style toggle :selected vhdl-indent-syntax-based]
4167 ["Indent Comments Like Next Code Line"
4168 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4169 (not vhdl-indent-comment-like-next-code-line))
4170 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4171 ["Word Completion is Case Sensitive"
4172 (customize-set-variable 'vhdl-word-completion-case-sensitive
4173 (not vhdl-word-completion-case-sensitive))
4174 :style toggle :selected vhdl-word-completion-case-sensitive]
4175 ["Word Completion in Minibuffer"
4176 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4177 (not vhdl-word-completion-in-minibuffer))
4178 (message "Activate new setting by saving options and restarting Emacs"))
4179 :style toggle :selected vhdl-word-completion-in-minibuffer]
4180 ["Underscore is Part of Word"
4181 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4182 (not vhdl-underscore-is-part-of-word))
4183 (vhdl-activate-customizations))
4184 :style toggle :selected vhdl-underscore-is-part-of-word]
4185 "--"
4186 ["Customize Group..." (customize-group 'vhdl-misc) t])
4187 ["Related..." (customize-browse 'vhdl-related) t]
4188 "--"
4189 ["Save Options" customize-save-customized t]
4190 ["Activate Options" vhdl-activate-customizations t]
4191 ["Browse Options..." vhdl-customize t])))
4192
4193 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4194 "VHDL Mode menu.")
4195
4196 (defun vhdl-update-mode-menu ()
4197 "Update VHDL Mode menu."
4198 (interactive)
4199 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4200 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4201 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4202 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4203 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4204
4205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4206 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4207
4208 (defconst vhdl-imenu-generic-expression
4209 '(
4210 ("Subprogram"
4211 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4212 4)
4213 ("Instance"
4214 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4215 1)
4216 ("Component"
4217 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4218 2)
4219 ("Procedural"
4220 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4221 1)
4222 ("Process"
4223 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4224 1)
4225 ("Block"
4226 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4227 1)
4228 ("Package"
4229 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4230 3)
4231 ("Configuration"
4232 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4233 2)
4234 ("Architecture"
4235 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4236 2)
4237 ("Entity"
4238 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4239 2)
4240 ("Context"
4241 "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4242 2)
4243 )
4244 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4245
4246 (defun vhdl-index-menu-init ()
4247 "Initialize index menu."
4248 (set (make-local-variable 'imenu-case-fold-search) t)
4249 (set (make-local-variable 'imenu-generic-expression)
4250 vhdl-imenu-generic-expression)
4251 (when (and vhdl-index-menu (fboundp 'imenu))
4252 (imenu-add-to-menubar "Index")))
4253
4254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4255 ;; Source file menu (using `easy-menu.el')
4256
4257 (defvar vhdl-sources-menu nil)
4258
4259 (defun vhdl-directory-files (directory &optional full match)
4260 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4261 message."
4262 (if (not (file-directory-p directory))
4263 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4264 (let ((dir (directory-files directory full match)))
4265 (setq dir (delete "." dir))
4266 (setq dir (delete ".." dir))
4267 dir)))
4268
4269 (defun vhdl-get-source-files (&optional full directory)
4270 "Get list of VHDL source files in DIRECTORY or current directory."
4271 (let ((mode-alist auto-mode-alist)
4272 filename-regexp)
4273 ;; create regular expressions for matching file names
4274 (setq filename-regexp "\\`[^.].*\\(")
4275 (while mode-alist
4276 (when (eq (cdar mode-alist) 'vhdl-mode)
4277 (setq filename-regexp
4278 (concat filename-regexp (caar mode-alist) "\\|")))
4279 (setq mode-alist (cdr mode-alist)))
4280 (setq filename-regexp
4281 (concat (substring filename-regexp 0
4282 (string-match "\\\\|$" filename-regexp)) "\\)"))
4283 ;; find files
4284 (vhdl-directory-files
4285 (or directory default-directory) full filename-regexp)))
4286
4287 (defun vhdl-add-source-files-menu ()
4288 "Scan directory for all VHDL source files and generate menu.
4289 The directory of the current source file is scanned."
4290 (interactive)
4291 (message "Scanning directory for source files ...")
4292 (let ((newmap (current-local-map))
4293 (file-list (vhdl-get-source-files))
4294 menu-list found)
4295 ;; Create list for menu
4296 (setq found nil)
4297 (while file-list
4298 (setq found t)
4299 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4300 menu-list)
4301 (setq file-list (cdr file-list)))
4302 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4303 (when found (push "--" menu-list))
4304 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4305 (push "Sources" menu-list)
4306 ;; Create menu
4307 (easy-menu-add menu-list)
4308 (easy-menu-define vhdl-sources-menu newmap
4309 "VHDL source files menu" menu-list))
4310 (message ""))
4311
4312
4313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4314 ;;; Mode definition
4315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4316 ;; performs all buffer local initializations
4317
4318 ;;;###autoload
4319 (define-derived-mode vhdl-mode prog-mode
4320 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4321 (vhdl-electric-mode "e")
4322 (vhdl-stutter-mode "s"))
4323 "Major mode for editing VHDL code.
4324
4325 Usage:
4326 ------
4327
4328 TEMPLATE INSERTION (electrification):
4329 After typing a VHDL keyword and entering `SPC', you are prompted for
4330 arguments while a template is generated for that VHDL construct. Typing
4331 `RET' or `C-g' at the first (mandatory) prompt aborts the current
4332 template generation. Optional arguments are indicated by square
4333 brackets and removed if the queried string is left empty. Prompts for
4334 mandatory arguments remain in the code if the queried string is left
4335 empty. They can be queried again by `C-c C-t C-q'. Enabled
4336 electrification is indicated by `/e' in the mode line.
4337
4338 Typing `M-SPC' after a keyword inserts a space without calling the
4339 template generator. Automatic template generation (i.e.
4340 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4341 setting option `vhdl-electric-mode' (see OPTIONS).
4342
4343 Template generators can be invoked from the VHDL menu, by key
4344 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4345 the keyword (i.e. first word of menu entry not in parenthesis) and
4346 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4347 conf, comp, cons, func, inst, pack, sig, var.
4348
4349 Template styles can be customized in customization group
4350 `vhdl-template' (see OPTIONS).
4351
4352
4353 HEADER INSERTION:
4354 A file header can be inserted by `C-c C-t C-h'. A file footer
4355 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4356 See customization group `vhdl-header'.
4357
4358
4359 STUTTERING:
4360 Double striking of some keys inserts cumbersome VHDL syntax elements.
4361 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4362 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4363 the mode line. The stuttering keys and their effects are:
4364
4365 ;; --> \" : \" [ --> ( -- --> comment
4366 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4367 .. --> \" => \" ] --> ) --- --> horizontal line
4368 ,, --> \" <= \" ]] --> ] ---- --> display comment
4369 == --> \" == \" \\='\\=' --> \\\"
4370
4371
4372 WORD COMPLETION:
4373 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4374 word in the buffer that starts alike, inserts it and adjusts case.
4375 Re-typing `TAB' toggles through alternative word completions. This also
4376 works in the minibuffer (i.e. in template generator prompts).
4377
4378 Typing `TAB' after `(' looks for and inserts complete parenthesized
4379 expressions (e.g. for array index ranges). All keywords as well as
4380 standard types and subprograms of VHDL have predefined abbreviations
4381 (e.g., type \"std\" and `TAB' will toggle through all standard types
4382 beginning with \"std\").
4383
4384 Typing `TAB' after a non-word character indents the line if at the
4385 beginning of a line (i.e. no preceding non-blank characters), and
4386 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4387 stop.
4388
4389
4390 COMMENTS:
4391 `--' puts a single comment.
4392 `---' draws a horizontal line for separating code segments.
4393 `----' inserts a display comment, i.e. two horizontal lines
4394 with a comment in between.
4395 `--CR' comments out code on that line. Re-hitting CR comments
4396 out following lines.
4397 `C-c C-c' comments out a region if not commented out,
4398 uncomments a region if already commented out. Option
4399 `comment-style' defines where the comment characters
4400 should be placed (beginning of line, indent, etc.).
4401
4402 You are prompted for comments after object definitions (i.e. signals,
4403 variables, constants, ports) and after subprogram and process
4404 specifications if option `vhdl-prompt-for-comments' is non-nil.
4405 Comments are automatically inserted as additional labels (e.g. after
4406 begin statements) and as help comments if `vhdl-self-insert-comments' is
4407 non-nil.
4408
4409 Inline comments (i.e. comments after a piece of code on the same line)
4410 are indented at least to `vhdl-inline-comment-column'. Comments go at
4411 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4412 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4413 in a comment automatically opens a new comment line. `M-q' re-fills
4414 multi-line comments.
4415
4416
4417 INDENTATION:
4418 `TAB' indents a line if at the beginning of the line. The amount of
4419 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4420 always indents the current line (is bound to `TAB' if option
4421 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4422 the entire region.
4423
4424 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4425 (`M-C-\\') or the entire buffer (menu). Argument and port lists are
4426 indented normally (nil) or relative to the opening parenthesis (non-nil)
4427 according to option `vhdl-argument-list-indent'.
4428
4429 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4430 tabs. `\\[tabify]' and `\\[untabify]' allow the conversion of spaces to
4431 tabs and vice versa.
4432
4433 Syntax-based indentation can be very slow in large files. Option
4434 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4435
4436 Option `vhdl-indent-comment-like-next-code-line' controls whether
4437 comment lines are indented like the preceding or like the following code
4438 line.
4439
4440
4441 ALIGNMENT:
4442 The alignment functions align operators, keywords, and inline comments
4443 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4444 separated by blank lines, `C-c C-a C-i' a block of lines with same
4445 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4446 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4447 C-a C-d' all lines within the declarative part of a design unit. `C-c
4448 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4449 for a group of lines, and `C-c C-a M-c' for a region.
4450
4451 If option `vhdl-align-groups' is non-nil, groups of code lines
4452 separated by special lines (see option `vhdl-align-group-separate') are
4453 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4454 blocks of lines with same indent are aligned separately. Some templates
4455 are automatically aligned after generation if option `vhdl-auto-align'
4456 is non-nil.
4457
4458 Alignment tries to align inline comments at
4459 `vhdl-inline-comment-column' and tries inline comment not to exceed
4460 `vhdl-end-comment-column'.
4461
4462 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4463 symbols are surrounded by one space, and multiple spaces are eliminated.
4464
4465
4466 CODE FILLING:
4467 Code filling allows you to condense code (e.g. sensitivity lists or port
4468 maps) by removing comments and newlines and re-wrapping so that all
4469 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4470 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4471 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4472 `C-c C-f M-f' an entire region.
4473
4474
4475 CODE BEAUTIFICATION:
4476 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4477 buffer respectively. This includes indentation, alignment, and case
4478 fixing. Code beautification can also be run non-interactively using the
4479 command:
4480
4481 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4482
4483
4484 PORT TRANSLATION:
4485 Generic and port clauses from entity or component declarations can be
4486 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4487 as component instantiations and corresponding internal constants and
4488 signals, as a generic map with constants as actual generics, and as
4489 internal signal initializations (menu).
4490
4491 To include formals in component instantiations, see option
4492 `vhdl-association-list-with-formals'. To include comments in pasting,
4493 see options `vhdl-include-...-comments'.
4494
4495 A clause with several generic/port names on the same line can be
4496 flattened (`C-c C-p C-f') so that only one name per line exists. The
4497 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4498 outputs and vice versa, which can be useful in testbenches. (This
4499 reversion is done on the internal data structure and is only reflected
4500 in subsequent paste operations.)
4501
4502 Names for actual ports, instances, testbenches, and
4503 design-under-test instances can be derived from existing names according
4504 to options `vhdl-...-name'. See customization group `vhdl-port'.
4505
4506
4507 SUBPROGRAM TRANSLATION:
4508 Similar functionality exists for copying/pasting the interface of
4509 subprograms (function/procedure). A subprogram interface can be copied
4510 and then pasted as a subprogram declaration, body or call (uses
4511 association list with formals).
4512
4513
4514 TESTBENCH GENERATION:
4515 A copied port can also be pasted as a testbench. The generated
4516 testbench includes an entity, an architecture, and an optional
4517 configuration. The architecture contains the component declaration and
4518 instantiation of the DUT as well as internal constant and signal
4519 declarations. Additional user-defined templates can be inserted. The
4520 names used for entity/architecture/configuration/DUT as well as the file
4521 structure to be generated can be customized. See customization group
4522 `vhdl-testbench'.
4523
4524
4525 KEY BINDINGS:
4526 Key bindings (`C-c ...') exist for most commands (see in menu).
4527
4528
4529 VHDL MENU:
4530 All commands can be found in the VHDL menu including their key bindings.
4531
4532
4533 FILE BROWSER:
4534 The speedbar allows browsing of directories and file contents. It can
4535 be accessed from the VHDL menu and is automatically opened if option
4536 `vhdl-speedbar-auto-open' is non-nil.
4537
4538 In speedbar, open files and directories with `mouse-2' on the name and
4539 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4540
4541
4542 DESIGN HIERARCHY BROWSER:
4543 The speedbar can also be used for browsing the hierarchy of design units
4544 contained in the source files of the current directory or the specified
4545 projects (see option `vhdl-project-alist').
4546
4547 The speedbar can be switched between file, directory hierarchy and
4548 project hierarchy browsing mode in the speedbar menu or by typing `f',
4549 `h' or `H' in speedbar.
4550
4551 In speedbar, open design units with `mouse-2' on the name and browse
4552 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4553 from entities and components (in packages). Individual design units and
4554 complete designs can directly be compiled (\"Make\" menu entry).
4555
4556 The hierarchy is automatically updated upon saving a modified source
4557 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4558 hierarchy is only updated for projects that have been opened once in the
4559 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4560 options in group `vhdl-speedbar').
4561
4562 Simple design consistency checks are done during scanning, such as
4563 multiple declarations of the same unit or missing primary units that are
4564 required by secondary units.
4565
4566
4567 STRUCTURAL COMPOSITION:
4568 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4569 for a new component. Subcomponents (i.e. component declaration and
4570 instantiation) can be automatically placed from a previously read port
4571 (`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4572 all subcomponents can be automatically connected using internal signals
4573 and ports (`C-c C-m C-w') following these rules:
4574 - subcomponent actual ports with same name are considered to be
4575 connected by a signal (internal signal or port)
4576 - signals that are only inputs to subcomponents are considered as
4577 inputs to this component -> input port created
4578 - signals that are only outputs from subcomponents are considered as
4579 outputs from this component -> output port created
4580 - signals that are inputs to AND outputs from subcomponents are
4581 considered as internal connections -> internal signal created
4582
4583 Purpose: With appropriate naming conventions it is possible to
4584 create higher design levels with only a few mouse clicks or key
4585 strokes. A new design level can be created by simply generating a new
4586 component, placing the required subcomponents from the hierarchy
4587 browser, and wiring everything automatically.
4588
4589 Note: Automatic wiring only works reliably on templates of new
4590 components and component instantiations that were created by VHDL mode.
4591
4592 Component declarations can be placed in a components package (option
4593 `vhdl-use-components-package') which can be automatically generated for
4594 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4595 component instantiation is also supported (option
4596 `vhdl-use-direct-instantiation').
4597
4598 Configuration declarations can automatically be generated either from
4599 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4600 the speedbar menu (for the architecture under the cursor). The
4601 configurations can optionally be hierarchical (i.e. include all
4602 component levels of a hierarchical design, option
4603 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4604 (option `vhdl-compose-configuration-use-subconfiguration'). For
4605 subcomponents in hierarchical configurations, the most-recently-analyzed
4606 (mra) architecture is selected. If another architecture is desired, it
4607 can be marked as most-recently-analyzed (speedbar menu) before
4608 generating the configuration.
4609
4610 Note: Configurations of subcomponents (i.e. hierarchical configuration
4611 declarations) are currently not considered when displaying
4612 configurations in speedbar.
4613
4614 See the options group `vhdl-compose' for all relevant user options.
4615
4616
4617 SOURCE FILE COMPILATION:
4618 The syntax of the current buffer can be analyzed by calling a VHDL
4619 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4620 option `vhdl-compiler'. The available compilers are listed in option
4621 `vhdl-compiler-alist' including all required compilation command,
4622 command options, compilation directory, and error message syntax
4623 information. New compilers can be added.
4624
4625 All the source files of an entire design can be compiled by the `make'
4626 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4627
4628
4629 MAKEFILE GENERATION:
4630 Makefiles can be generated automatically by an internal generation
4631 routine (`C-c M-k'). The library unit dependency information is
4632 obtained from the hierarchy browser. Makefile generation can be
4633 customized for each compiler in option `vhdl-compiler-alist'.
4634
4635 Makefile generation can also be run non-interactively using the
4636 command:
4637
4638 emacs -batch -l ~/.emacs -l vhdl-mode
4639 [-compiler compilername] [-project projectname]
4640 -f vhdl-generate-makefile
4641
4642 The Makefile's default target \"all\" compiles the entire design, the
4643 target \"clean\" removes it and the target \"library\" creates the
4644 library directory if not existent. These target names can be customized
4645 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4646 target for each primary library unit which allows selective compilation
4647 of this unit, its secondary units and its subhierarchy (example:
4648 compilation of a design specified by a configuration). User specific
4649 parts can be inserted into a Makefile with option
4650 `vhdl-makefile-generation-hook'.
4651
4652 Limitations:
4653 - Only library units and dependencies within the current library are
4654 considered. Makefiles for designs that span multiple libraries are
4655 not (yet) supported.
4656 - Only one-level configurations are supported (also hierarchical),
4657 but configurations that go down several levels are not.
4658 - The \"others\" keyword in configurations is not supported.
4659
4660
4661 PROJECTS:
4662 Projects can be defined in option `vhdl-project-alist' and a current
4663 project be selected using option `vhdl-project' (permanently) or from
4664 the menu or speedbar (temporarily). For each project, title and
4665 description strings (for the file headers), source files/directories
4666 (for the hierarchy browser and Makefile generation), library name, and
4667 compiler-dependent options, exceptions and compilation directory can be
4668 specified. Compilation settings overwrite the settings of option
4669 `vhdl-compiler-alist'.
4670
4671 Project setups can be exported (i.e. written to a file) and imported.
4672 Imported setups are not automatically saved in `vhdl-project-alist' but
4673 can be saved afterwards in its customization buffer. When starting
4674 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4675 vhdl-mode\") in a directory with an existing project setup file, it is
4676 automatically loaded and its project activated if option
4677 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4678 files can be specified in option `vhdl-project-file-name'. Multiple
4679 project setups can be automatically loaded from global directories.
4680 This is an alternative to specifying project setups with option
4681 `vhdl-project-alist'.
4682
4683
4684 SPECIAL MENUES:
4685 As an alternative to the speedbar, an index menu can be added (set
4686 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4687 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4688 file) for browsing the file contents (is not populated if buffer is
4689 larger than 256000). Also, a source file menu can be
4690 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4691 current directory for VHDL source files.
4692
4693
4694 VHDL STANDARDS:
4695 The VHDL standards to be used are specified in option `vhdl-standard'.
4696 Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
4697
4698
4699 KEYWORD CASE:
4700 Lower and upper case for keywords and standardized types, attributes,
4701 and enumeration values is supported. If the option
4702 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4703 lower case and are converted into upper case automatically (not for
4704 types, attributes, and enumeration values). The case of keywords,
4705 types, attributes,and enumeration values can be fixed for an entire
4706 region (menu) or buffer (`C-c C-x C-c') according to the options
4707 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4708
4709
4710 HIGHLIGHTING (fontification):
4711 Keywords and standardized types, attributes, enumeration values, and
4712 function names (controlled by option `vhdl-highlight-keywords'), as well
4713 as comments, strings, and template prompts are highlighted using
4714 different colors. Unit, subprogram, signal, variable, constant,
4715 parameter and generic/port names in declarations as well as labels are
4716 highlighted if option `vhdl-highlight-names' is non-nil.
4717
4718 Additional reserved words or words with a forbidden syntax (e.g. words
4719 that should be avoided) can be specified in option
4720 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4721 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4722 keywords are highlighted as forbidden words if option
4723 `vhdl-highlight-verilog-keywords' is non-nil.
4724
4725 Words with special syntax can be highlighted by specifying their
4726 syntax and color in option `vhdl-special-syntax-alist' and by setting
4727 option `vhdl-highlight-special-words' to non-nil. This allows you to
4728 establish some naming conventions (e.g. to distinguish different kinds
4729 of signals or other objects by using name suffices) and to support them
4730 visually.
4731
4732 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4733 to support case-sensitive highlighting. However, keywords are then only
4734 highlighted if written in lower case.
4735
4736 Code between \"translate_off\" and \"translate_on\" pragmas is
4737 highlighted using a different background color if option
4738 `vhdl-highlight-translate-off' is non-nil.
4739
4740 For documentation and customization of the used colors see
4741 customization group `vhdl-highlight-faces' (`\\[customize-group]'). For
4742 highlighting of matching parenthesis, see customization group
4743 `paren-showing'. Automatic buffer highlighting is turned on/off by
4744 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4745
4746
4747 USER MODELS:
4748 VHDL models (templates) can be specified by the user and made accessible
4749 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4750 electrification. See option `vhdl-model-alist'.
4751
4752
4753 HIDE/SHOW:
4754 The code of blocks, processes, subprograms, component declarations and
4755 instantiations, generic/port clauses, and configuration declarations can
4756 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4757 the code (see customization group `vhdl-menu'). XEmacs: limited
4758 functionality due to old `hideshow.el' package.
4759
4760
4761 CODE UPDATING:
4762 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4763 current process, `C-c C-u M-s' of all processes in the current buffer.
4764 Limitations:
4765 - Only declared local signals (ports, signals declared in
4766 architecture and blocks) are automatically inserted.
4767 - Global signals declared in packages are not automatically inserted.
4768 Insert them once manually (will be kept afterwards).
4769 - Out parameters of procedures are considered to be read.
4770 Use option `vhdl-entity-file-name' to specify the entity file name
4771 (used to obtain the port names).
4772 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4773 specify whether to include array indices and record fields in
4774 sensitivity lists.
4775
4776
4777 CODE FIXING:
4778 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4779 (e.g., if the closing parenthesis is on the wrong line or is missing).
4780
4781
4782 PRINTING:
4783 PostScript printing with different faces (an optimized set of faces is
4784 used if `vhdl-print-customize-faces' is non-nil) or colors (if
4785 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4786 PostScript printing commands. Option `vhdl-print-two-column' defines
4787 appropriate default settings for nice landscape two-column printing.
4788 The paper format can be set by option `ps-paper-type'. Do not forget to
4789 switch `ps-print-color-p' to nil for printing on black-and-white
4790 printers.
4791
4792
4793 OPTIONS:
4794 User options allow customization of VHDL Mode. All options are
4795 accessible from the \"Options\" menu entry. Simple options (switches
4796 and choices) can directly be changed, while for complex options a
4797 customization buffer is opened. Changed options can be saved for future
4798 sessions using the \"Save Options\" menu entry.
4799
4800 Options and their detailed descriptions can also be accessed by using
4801 the \"Customize\" menu entry or the command `\\[customize-option]'
4802 (`\\[customize-group]' for groups). Some customizations only take effect
4803 after some action (read the NOTE in the option documentation).
4804 Customization can also be done globally (i.e. site-wide, read the
4805 INSTALL file).
4806
4807 Not all options are described in this documentation, so go and see
4808 what other useful user options there are (`\\[vhdl-customize]' or menu)!
4809
4810
4811 FILE EXTENSIONS:
4812 As default, files with extensions \".vhd\" and \".vhdl\" are
4813 automatically recognized as VHDL source files. To add an extension
4814 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4815
4816 (push \\='(\"\\\\.xxx\\\\\\='\" . vhdl-mode) auto-mode-alist)
4817
4818
4819 HINTS:
4820 - To start Emacs with open VHDL hierarchy browser without having to load
4821 a VHDL file first, use the command:
4822
4823 emacs -l vhdl-mode -f speedbar-frame-mode
4824
4825 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4826
4827 - Some features only work on properly indented code.
4828
4829
4830 RELEASE NOTES:
4831 See also the release notes (menu) for added features in new releases.
4832
4833
4834 Maintenance:
4835 ------------
4836
4837 To submit a bug report, enter `\\[vhdl-submit-bug-report]' within VHDL Mode.
4838 Add a description of the problem and include a reproducible test case.
4839
4840 Questions and enhancement requests can be sent to <reto@gnu.org>.
4841
4842 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4843 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4844 releases. You are kindly invited to participate in beta testing. Subscribe
4845 to above mailing lists by sending an email to <reto@gnu.org>.
4846
4847 VHDL Mode is officially distributed at
4848 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4849 where the latest version can be found.
4850
4851
4852 Known problems:
4853 ---------------
4854
4855 - XEmacs: Incorrect start-up when automatically opening speedbar.
4856 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4857 - Indentation incorrect for new 'postponed' VHDL keyword.
4858 - Indentation incorrect for 'protected body' construct.
4859
4860
4861 The VHDL Mode Authors
4862 Reto Zimmermann and Rod Whitby
4863
4864 Key bindings:
4865 -------------
4866
4867 \\{vhdl-mode-map}"
4868 :abbrev-table vhdl-mode-abbrev-table
4869
4870 ;; set local variables
4871 (set (make-local-variable 'paragraph-start)
4872 "\\s-*\\(--+\\s-*$\\|$\\)")
4873 (set (make-local-variable 'paragraph-separate) paragraph-start)
4874 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4875 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4876 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4877 (set (make-local-variable 'comment-start) "--")
4878 (set (make-local-variable 'comment-end) "")
4879 (when vhdl-emacs-21
4880 (set (make-local-variable 'comment-padding) ""))
4881 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4882 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4883 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4884 (set (make-local-variable 'comment-multi-line) nil)
4885 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4886 (set (make-local-variable 'hippie-expand-verbose) nil)
4887
4888 ;; setup the comment indent variable in a Emacs version portable way
4889 ;; ignore any byte compiler warnings you might get here
4890 (when (boundp 'comment-indent-function)
4891 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4892
4893 ;; initialize font locking
4894 (set (make-local-variable 'font-lock-defaults)
4895 (list
4896 '(nil vhdl-font-lock-keywords) nil
4897 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4898 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4899 (set (make-local-variable 'syntax-propertize-function)
4900 (syntax-propertize-rules
4901 ;; Mark single quotes as having string quote syntax in
4902 ;; 'c' instances.
4903 ("\\('\\).\\('\\)" (1 "\"'") (2 "\"'"))))
4904 (set (make-local-variable 'font-lock-syntactic-keywords)
4905 vhdl-font-lock-syntactic-keywords))
4906 (unless vhdl-emacs-21
4907 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4908 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4909 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4910 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4911
4912 ;; variables for source file compilation
4913 (when vhdl-compile-use-local-error-regexp
4914 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4915 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4916
4917 ;; add index menu
4918 (vhdl-index-menu-init)
4919 ;; add source file menu
4920 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4921 ;; add VHDL menu
4922 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4923 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4924 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4925 ;; initialize hideshow and add menu
4926 (vhdl-hideshow-init)
4927 (run-hooks 'menu-bar-update-hook)
4928
4929 ;; miscellaneous
4930 (vhdl-ps-print-init)
4931 (vhdl-write-file-hooks-init)
4932 (message "VHDL Mode %s.%s" vhdl-version
4933 (if noninteractive "" " See menu for documentation and release notes.")))
4934
4935 (defun vhdl-activate-customizations ()
4936 "Activate all customizations on local variables."
4937 (interactive)
4938 (vhdl-mode-map-init)
4939 (use-local-map vhdl-mode-map)
4940 (set-syntax-table vhdl-mode-syntax-table)
4941 (setq comment-column vhdl-inline-comment-column)
4942 (setq end-comment-column vhdl-end-comment-column)
4943 (vhdl-write-file-hooks-init)
4944 (vhdl-update-mode-menu)
4945 (vhdl-hideshow-init)
4946 (run-hooks 'menu-bar-update-hook))
4947
4948 (defun vhdl-write-file-hooks-init ()
4949 "Add/remove hooks when buffer is saved."
4950 (if vhdl-modify-date-on-saving
4951 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4952 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4953 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4954 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4955
4956 (defun vhdl-process-command-line-option (option)
4957 "Process command line options for VHDL Mode."
4958 (cond
4959 ;; set compiler
4960 ((equal option "-compiler")
4961 (vhdl-set-compiler (car command-line-args-left))
4962 (setq command-line-args-left (cdr command-line-args-left)))
4963 ;; set project
4964 ((equal option "-project")
4965 (vhdl-set-project (car command-line-args-left))
4966 (setq command-line-args-left (cdr command-line-args-left)))))
4967
4968 ;; make Emacs process VHDL Mode options
4969 (setq command-switch-alist
4970 (append command-switch-alist
4971 '(("-compiler" . vhdl-process-command-line-option)
4972 ("-project" . vhdl-process-command-line-option))))
4973
4974
4975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4976 ;;; Keywords and standardized words
4977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4978
4979 (defconst vhdl-02-keywords
4980 '(
4981 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4982 "assert" "attribute"
4983 "begin" "block" "body" "buffer" "bus"
4984 "case" "component" "configuration" "constant"
4985 "disconnect" "downto"
4986 "else" "elsif" "end" "entity" "exit"
4987 "file" "for" "function"
4988 "generate" "generic" "group" "guarded"
4989 "if" "impure" "in" "inertial" "inout" "is"
4990 "label" "library" "linkage" "literal" "loop"
4991 "map" "mod"
4992 "nand" "new" "next" "nor" "not" "null"
4993 "of" "on" "open" "or" "others" "out"
4994 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4995 "range" "record" "register" "reject" "rem" "report" "return"
4996 "rol" "ror"
4997 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4998 "then" "to" "transport" "type"
4999 "unaffected" "units" "until" "use"
5000 "variable"
5001 "wait" "when" "while" "with"
5002 "xnor" "xor"
5003 )
5004 "List of VHDL'02 keywords.")
5005
5006 (defconst vhdl-08-keywords
5007 '(
5008 "context" "force" "property" "release" "sequence"
5009 )
5010 "List of VHDL'08 keywords.")
5011
5012 (defconst vhdl-ams-keywords
5013 '(
5014 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
5015 "reference" "spectrum" "subnature" "terminal" "through"
5016 "tolerance"
5017 )
5018 "List of VHDL-AMS keywords.")
5019
5020 (defconst vhdl-verilog-keywords
5021 '(
5022 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5023 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5024 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5025 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5026 "endprimitive" "endspecify" "endtable" "endtask" "event"
5027 "for" "force" "forever" "fork" "function"
5028 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5029 "macromodule" "makefile" "medium" "module"
5030 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5031 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5032 "pullup"
5033 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5034 "rtranif0" "rtranif1"
5035 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5036 "strong1" "supply" "supply0" "supply1"
5037 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5038 "triand" "trior" "trireg"
5039 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5040 )
5041 "List of Verilog keywords as candidate for additional reserved words.")
5042
5043 (defconst vhdl-02-types
5044 '(
5045 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5046 "real" "time" "natural" "positive" "string" "line" "text" "side"
5047 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5048 "std_logic" "std_logic_vector"
5049 "std_ulogic" "std_ulogic_vector"
5050 )
5051 "List of VHDL'02 standardized types.")
5052
5053 (defconst vhdl-08-types
5054 '(
5055 "boolean_vector" "integer_vector" "real_vector" "time_vector"
5056 )
5057 "List of VHDL'08 standardized types.")
5058
5059 (defconst vhdl-ams-types
5060 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5061 '(
5062 ;; package `standard'
5063 "domain_type" "real_vector"
5064 ;; package `energy_systems'
5065 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5066 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5067 "real_across_vector" "real_through_vector"
5068 ;; package `electrical_systems'
5069 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5070 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5071 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5072 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5073 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5074 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5075 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5076 "electric_flux_density_vector" "electric_field_strength_vector"
5077 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5078 "inductance_vector" "reluctance_vector" "ground"
5079 ;; package `mechanical_systems'
5080 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5081 "damping" "momentum" "angle" "torque" "angular_velocity"
5082 "angular_acceleration" "moment_inertia" "angular_momentum"
5083 "angular_stiffness" "angular_damping" "translational"
5084 "translational_vector" "translational_velocity"
5085 "translational_velocity_vector" "rotational" "rotational_vector"
5086 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5087 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5088 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5089 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5090 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5091 "angular_momentum_vector" "angular_stiffness_vector"
5092 "angular_damping_vector" "anchor" "translational_v_ref"
5093 "rotational_v_ref" "translational_v" "rotational_v"
5094 ;; package `radiant_systems'
5095 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5096 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5097 "illuminance_vector" "irradiance_vector"
5098 ;; package `thermal_systems'
5099 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5100 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5101 "heat_flow_vector" "thermal_capacitance_vector"
5102 "thermal_resistance_vector" "thermal_conductance_vector"
5103 ;; package `fluidic_systems'
5104 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5105 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5106 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5107 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5108 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5109 "density_vector" "viscosity_vector" "fresistance_vector"
5110 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5111 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5112 "cfinertance_vector"
5113 )
5114 "List of VHDL-AMS standardized types.")
5115
5116 (defconst vhdl-math-types
5117 '(
5118 "complex" "complex_polar" "positive_real" "principal_value"
5119 )
5120 "List of Math Packages standardized types.")
5121
5122 (defconst vhdl-02-attributes
5123 '(
5124 "base" "left" "right" "high" "low" "pos" "val" "succ"
5125 "pred" "leftof" "rightof" "range" "reverse_range"
5126 "length" "delayed" "stable" "quiet" "transaction"
5127 "event" "active" "last_event" "last_active" "last_value"
5128 "driving" "driving_value" "ascending" "value" "image"
5129 "simple_name" "instance_name" "path_name"
5130 "foreign"
5131 )
5132 "List of VHDL'02 standardized attributes.")
5133
5134 (defconst vhdl-08-attributes
5135 '(
5136 "instance_name" "path_name"
5137 )
5138 "List of VHDL'08 standardized attributes.")
5139
5140 (defconst vhdl-ams-attributes
5141 '(
5142 "across" "through"
5143 "reference" "contribution" "tolerance"
5144 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5145 "ramp" "slew"
5146 )
5147 "List of VHDL-AMS standardized attributes.")
5148
5149 (defconst vhdl-02-enum-values
5150 '(
5151 "true" "false"
5152 "note" "warning" "error" "failure"
5153 "read_mode" "write_mode" "append_mode"
5154 "open_ok" "status_error" "name_error" "mode_error"
5155 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5156 "right" "left"
5157 )
5158 "List of VHDL'02 standardized enumeration values.")
5159
5160 (defconst vhdl-ams-enum-values
5161 '(
5162 "quiescent_domain" "time_domain" "frequency_domain"
5163 ;; from `nature_pkg' package
5164 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5165 )
5166 "List of VHDL-AMS standardized enumeration values.")
5167
5168 (defconst vhdl-ams-constants
5169 ;; standard: IEEE Std 1076.1.1-2004
5170 '(
5171 ;; package `fundamental_constants'
5172 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5173 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5174 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5175 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5176 ;; package `material_constants'
5177 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5178 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5179 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5180 )
5181 "List of VHDL-AMS standardized constants.")
5182
5183 (defconst vhdl-math-constants
5184 ;; standard: IEEE Std 1076.2-1996
5185 '(
5186 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5187 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5188 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5189 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5190 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5191 "math_sqrt_pi"
5192 )
5193 "List of Math Packages standardized constants.")
5194
5195 (defconst vhdl-02-functions
5196 '(
5197 "now" "resolved" "rising_edge" "falling_edge"
5198 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5199 "endfile"
5200 "resize" "is_X" "std_match"
5201 "shift_left" "shift_right" "rotate_left" "rotate_right"
5202 "to_unsigned" "to_signed" "to_integer"
5203 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5204 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5205 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5206 "shl" "shr" "ext" "sxt"
5207 "deallocate"
5208 )
5209 "List of VHDL'02 standardized functions.")
5210
5211 (defconst vhdl-08-functions
5212 '(
5213 "finish" "flush" "justify" "maximum" "minimum"
5214 "resolution_limit" "rising_edge" "stop" "swrite"
5215 "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
5216 "to_octalstring" "to_ostring" "to_string"
5217 )
5218 "List of VHDL'08 standardized functions.")
5219
5220 (defconst vhdl-ams-functions
5221 '(
5222 ;; package `standard'
5223 "frequency"
5224 )
5225 "List of VHDL-AMS standardized functions.")
5226
5227 (defconst vhdl-math-functions
5228 ;; standard: IEEE Std 1076.2-1996
5229 '(
5230 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5231 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5232 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5233 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5234 "tan" "tanh" "trunc" "uniform"
5235 )
5236 "List of Math Packages standardized functions.")
5237
5238 (defconst vhdl-02-packages
5239 '(
5240 "std_logic_1164" "numeric_std" "numeric_bit"
5241 "standard" "textio"
5242 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5243 "std_logic_misc" "std_logic_textio"
5244 "ieee" "std" "work"
5245 )
5246 "List of VHDL'02 standardized packages and libraries.")
5247
5248 (defconst vhdl-08-packages
5249 '(
5250 "env" "numeric_std_signed" "numeric_std_unsigned"
5251 "ieee_bit_context" "ieee_std_context" ;; contexts
5252 )
5253 "List of VHDL'08 standardized packages and libraries.")
5254
5255 (defconst vhdl-ams-packages
5256 '(
5257 "fundamental_constants" "material_constants" "energy_systems"
5258 "electrical_systems" "mechanical_systems" "radiant_systems"
5259 "thermal_systems" "fluidic_systems"
5260 )
5261 "List of VHDL-AMS standardized packages and libraries.")
5262
5263 (defconst vhdl-math-packages
5264 '(
5265 "math_real" "math_complex"
5266 )
5267 "List of Math Packages standardized packages and libraries.")
5268
5269 (defconst vhdl-08-directives
5270 '(
5271 "author" "author_info" "begin" "begin_protected" "comment"
5272 "data_block" "data_keyname" "data_keyowner" "data_method"
5273 "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
5274 "digest_keyowner" "digest_method"
5275 "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
5276 "key_block" "key_keyname" "key_keyowner" "key_method"
5277 "runtime_license" "viewport"
5278 )
5279 "List of VHDL'08 standardized tool directives.")
5280
5281 (defvar vhdl-keywords nil
5282 "List of VHDL keywords.")
5283
5284 (defvar vhdl-types nil
5285 "List of VHDL standardized types.")
5286
5287 (defvar vhdl-attributes nil
5288 "List of VHDL standardized attributes.")
5289
5290 (defvar vhdl-enum-values nil
5291 "List of VHDL standardized enumeration values.")
5292
5293 (defvar vhdl-constants nil
5294 "List of VHDL standardized constants.")
5295
5296 (defvar vhdl-functions nil
5297 "List of VHDL standardized functions.")
5298
5299 (defvar vhdl-packages nil
5300 "List of VHDL standardized packages and libraries.")
5301
5302 (defvar vhdl-directives nil
5303 "List of VHDL standardized packages and libraries.")
5304
5305 (defvar vhdl-reserved-words nil
5306 "List of additional reserved words.")
5307
5308 (defvar vhdl-keywords-regexp nil
5309 "Regexp for VHDL keywords.")
5310
5311 (defvar vhdl-types-regexp nil
5312 "Regexp for VHDL standardized types.")
5313
5314 (defvar vhdl-attributes-regexp nil
5315 "Regexp for VHDL standardized attributes.")
5316
5317 (defvar vhdl-enum-values-regexp nil
5318 "Regexp for VHDL standardized enumeration values.")
5319
5320 (defvar vhdl-constants-regexp nil
5321 "Regexp for VHDL standardized constants.")
5322
5323 (defvar vhdl-functions-regexp nil
5324 "Regexp for VHDL standardized functions.")
5325
5326 (defvar vhdl-packages-regexp nil
5327 "Regexp for VHDL standardized packages and libraries.")
5328
5329 (defvar vhdl-reserved-words-regexp nil
5330 "Regexp for additional reserved words.")
5331
5332 (defvar vhdl-directive-keywords-regexp nil
5333 "Regexp for compiler directive keywords.")
5334
5335 (defun vhdl-upcase-list (condition list)
5336 "Upcase all elements in LIST based on CONDITION."
5337 (when condition
5338 (let ((tmp-list list))
5339 (while tmp-list
5340 (setcar tmp-list (upcase (car tmp-list)))
5341 (setq tmp-list (cdr tmp-list)))))
5342 list)
5343
5344 (defun vhdl-words-init ()
5345 "Initialize reserved words."
5346 (setq vhdl-keywords
5347 (vhdl-upcase-list
5348 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5349 (append vhdl-02-keywords
5350 (when (vhdl-standard-p '08) vhdl-08-keywords)
5351 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5352 (setq vhdl-types
5353 (vhdl-upcase-list
5354 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5355 (append vhdl-02-types
5356 (when (vhdl-standard-p '08) vhdl-08-types)
5357 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5358 (when (vhdl-standard-p 'math) vhdl-math-types))))
5359 (setq vhdl-attributes
5360 (vhdl-upcase-list
5361 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5362 (append vhdl-02-attributes
5363 (when (vhdl-standard-p '08) vhdl-08-attributes)
5364 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5365 (setq vhdl-enum-values
5366 (vhdl-upcase-list
5367 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5368 (append vhdl-02-enum-values
5369 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5370 (setq vhdl-constants
5371 (vhdl-upcase-list
5372 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5373 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5374 (when (vhdl-standard-p 'math) vhdl-math-constants)
5375 '(""))))
5376 (setq vhdl-functions
5377 (append vhdl-02-functions
5378 (when (vhdl-standard-p '08) vhdl-08-functions)
5379 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5380 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5381 (setq vhdl-packages
5382 (append vhdl-02-packages
5383 (when (vhdl-standard-p '08) vhdl-08-packages)
5384 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5385 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5386 (setq vhdl-directives
5387 (append (when (vhdl-standard-p '08) vhdl-08-directives)))
5388 (setq vhdl-reserved-words
5389 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5390 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5391 '("")))
5392 (setq vhdl-keywords-regexp
5393 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5394 (setq vhdl-types-regexp
5395 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5396 (setq vhdl-attributes-regexp
5397 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5398 (setq vhdl-enum-values-regexp
5399 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5400 (setq vhdl-constants-regexp
5401 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5402 (setq vhdl-functions-regexp
5403 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5404 (setq vhdl-packages-regexp
5405 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5406 (setq vhdl-reserved-words-regexp
5407 (concat "\\<\\("
5408 (unless (equal vhdl-forbidden-syntax "")
5409 (concat vhdl-forbidden-syntax "\\|"))
5410 (regexp-opt vhdl-reserved-words)
5411 "\\)\\>"))
5412 (setq vhdl-directive-keywords-regexp
5413 (concat "\\<\\(" (mapconcat 'regexp-quote
5414 vhdl-directive-keywords "\\|") "\\)\\>"))
5415 (vhdl-abbrev-list-init))
5416
5417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5418 ;; Words to expand
5419
5420 (defvar vhdl-abbrev-list nil
5421 "Predefined abbreviations for VHDL.")
5422
5423 (defun vhdl-abbrev-list-init ()
5424 (setq vhdl-abbrev-list
5425 (append
5426 (list vhdl-upper-case-keywords) vhdl-keywords
5427 (list vhdl-upper-case-types) vhdl-types
5428 (list vhdl-upper-case-attributes) vhdl-attributes
5429 (list vhdl-upper-case-enum-values) vhdl-enum-values
5430 (list vhdl-upper-case-constants) vhdl-constants
5431 (list nil) vhdl-functions
5432 (list nil) vhdl-packages
5433 (list nil) vhdl-directives)))
5434
5435 ;; initialize reserved words for VHDL Mode
5436 (vhdl-words-init)
5437
5438
5439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5440 ;;; Indentation
5441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5442
5443 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5444 ;; Syntax analysis
5445
5446 ;; constant regular expressions for looking at various constructs
5447
5448 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5449 "Regexp describing a VHDL symbol.
5450 We cannot use just `word' syntax class since `_' cannot be in word
5451 class. Putting underscore in word class breaks forward word movement
5452 behavior that users are familiar with.")
5453
5454 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5455 "Regexp describing a case statement header key.")
5456
5457 (defconst vhdl-label-key
5458 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5459 "Regexp describing a VHDL label.")
5460
5461 ;; Macro definitions:
5462
5463 (defmacro vhdl-point (position)
5464 "Return the value of point at certain commonly referenced POSITIONs.
5465 POSITION can be one of the following symbols:
5466
5467 bol -- beginning of line
5468 eol -- end of line
5469 bod -- beginning of defun
5470 boi -- back to indentation
5471 eoi -- last whitespace on line
5472 ionl -- indentation of next line
5473 iopl -- indentation of previous line
5474 bonl -- beginning of next line
5475 bopl -- beginning of previous line
5476
5477 This function does not modify point or mark."
5478 (or (and (eq 'quote (car-safe position))
5479 (null (cddr position)))
5480 (error "ERROR: Bad buffer position requested: %s" position))
5481 (setq position (nth 1 position))
5482 `(let ((here (point)))
5483 ,@(cond
5484 ((eq position 'bol) '((beginning-of-line)))
5485 ((eq position 'eol) '((end-of-line)))
5486 ((eq position 'bod) '((save-match-data
5487 (vhdl-beginning-of-defun))))
5488 ((eq position 'boi) '((back-to-indentation)))
5489 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5490 ((eq position 'bonl) '((forward-line 1)))
5491 ((eq position 'bopl) '((forward-line -1)))
5492 ((eq position 'iopl)
5493 '((forward-line -1)
5494 (back-to-indentation)))
5495 ((eq position 'ionl)
5496 '((forward-line 1)
5497 (back-to-indentation)))
5498 (t (error "ERROR: Unknown buffer position requested: %s" position))
5499 )
5500 (prog1
5501 (point)
5502 (goto-char here))
5503 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5504 ;; doesn't hurt for v19
5505 ,@nil
5506 ))
5507
5508 (defmacro vhdl-safe (&rest body)
5509 "Safely execute BODY, return nil if an error occurred."
5510 `(condition-case nil
5511 (progn ,@body)
5512 (error nil)))
5513
5514 (defmacro vhdl-add-syntax (symbol &optional relpos)
5515 "A simple macro to append the syntax in SYMBOL to the syntax list.
5516 Try to increase performance by using this macro."
5517 `(setq vhdl-syntactic-context
5518 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5519
5520 (defmacro vhdl-has-syntax (symbol)
5521 "A simple macro to return check the syntax list.
5522 Try to increase performance by using this macro."
5523 `(assoc ,symbol vhdl-syntactic-context))
5524
5525 ;; Syntactic element offset manipulation:
5526
5527 (defun vhdl-read-offset (langelem)
5528 "Read new offset value for LANGELEM from minibuffer.
5529 Return a valid value only."
5530 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5531 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5532 (prompt "Offset: ")
5533 offset input interned)
5534 (while (not offset)
5535 (setq input (read-string prompt oldoff)
5536 offset (cond ((string-equal "+" input) '+)
5537 ((string-equal "-" input) '-)
5538 ((string-equal "++" input) '++)
5539 ((string-equal "--" input) '--)
5540 ((string-match "^-?[0-9]+$" input)
5541 (string-to-number input))
5542 ((fboundp (setq interned (intern input)))
5543 interned)
5544 ((boundp interned) interned)
5545 ;; error, but don't signal one, keep trying
5546 ;; to read an input value
5547 (t (ding)
5548 (setq prompt errmsg)
5549 nil))))
5550 offset))
5551
5552 (defun vhdl-set-offset (symbol offset &optional add-p)
5553 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5554 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5555 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5556 `vhdl-offsets-alist' if it doesn't already appear there."
5557 (interactive
5558 (let* ((langelem
5559 (intern (completing-read
5560 (concat "Syntactic symbol to change"
5561 (if current-prefix-arg " or add" "")
5562 ": ")
5563 (mapcar
5564 (function
5565 (lambda (langelem)
5566 (cons (format "%s" (car langelem)) nil)))
5567 vhdl-offsets-alist)
5568 nil (not current-prefix-arg)
5569 ;; initial contents tries to be the last element
5570 ;; on the syntactic analysis list for the current
5571 ;; line
5572 (let* ((syntax (vhdl-get-syntactic-context))
5573 (len (length syntax))
5574 (ic (format "%s" (car (nth (1- len) syntax)))))
5575 ic)
5576 )))
5577 (offset (vhdl-read-offset langelem)))
5578 (list langelem offset current-prefix-arg)))
5579 ;; sanity check offset
5580 (or (eq offset '+)
5581 (eq offset '-)
5582 (eq offset '++)
5583 (eq offset '--)
5584 (integerp offset)
5585 (fboundp offset)
5586 (boundp offset)
5587 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5588 offset))
5589 (let ((entry (assq symbol vhdl-offsets-alist)))
5590 (if entry
5591 (setcdr entry offset)
5592 (if add-p
5593 (setq vhdl-offsets-alist
5594 (cons (cons symbol offset) vhdl-offsets-alist))
5595 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5596 (vhdl-keep-region-active))
5597
5598 (defun vhdl-set-style (style &optional local)
5599 "Set `vhdl-mode' variables to use one of several different indentation styles.
5600 STYLE is a string representing the desired style and optional LOCAL is
5601 a flag which, if non-nil, means to make the style variables being
5602 changed buffer local, instead of the default, which is to set the
5603 global variables. Interactively, the flag comes from the prefix
5604 argument. The styles are chosen from the `vhdl-style-alist' variable."
5605 (interactive (list (completing-read "Use which VHDL indentation style? "
5606 vhdl-style-alist nil t)
5607 current-prefix-arg))
5608 (let ((vars (cdr (assoc style vhdl-style-alist))))
5609 (or vars
5610 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5611 ;; set all the variables
5612 (mapc
5613 (function
5614 (lambda (varentry)
5615 (let ((var (car varentry))
5616 (val (cdr varentry)))
5617 ;; special case for vhdl-offsets-alist
5618 (if (not (eq var 'vhdl-offsets-alist))
5619 (set (if local (make-local-variable var) var) val)
5620 ;; reset vhdl-offsets-alist to the default value first
5621 (set (if local (make-local-variable var) var)
5622 (copy-alist vhdl-offsets-alist-default))
5623 ;; now set the langelems that are different
5624 (mapcar
5625 (function
5626 (lambda (langentry)
5627 (let ((langelem (car langentry))
5628 (offset (cdr langentry)))
5629 (vhdl-set-offset langelem offset)
5630 )))
5631 val))
5632 )))
5633 vars))
5634 (vhdl-keep-region-active))
5635
5636 (defun vhdl-get-offset (langelem)
5637 "Get offset from LANGELEM which is a cons cell of the form:
5638 \(SYMBOL . RELPOS). The symbol is matched against
5639 vhdl-offsets-alist and the offset found there is either returned,
5640 or added to the indentation at RELPOS. If RELPOS is nil, then
5641 the offset is simply returned."
5642 (let* ((symbol (car langelem))
5643 (relpos (cdr langelem))
5644 (match (assq symbol vhdl-offsets-alist))
5645 (offset (cdr-safe match)))
5646 ;; offset can be a number, a function, a variable, or one of the
5647 ;; symbols + or -
5648 (cond
5649 ((not match)
5650 (if vhdl-strict-syntax-p
5651 (error "ERROR: Don't know how to indent a %s" symbol)
5652 (setq offset 0
5653 relpos 0)))
5654 ((eq offset '+) (setq offset vhdl-basic-offset))
5655 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5656 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5657 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5658 ((and (not (numberp offset))
5659 (fboundp offset))
5660 (setq offset (funcall offset langelem)))
5661 ((not (numberp offset))
5662 (setq offset (eval offset)))
5663 )
5664 (+ (if (and relpos
5665 (< relpos (vhdl-point 'bol)))
5666 (save-excursion
5667 (goto-char relpos)
5668 (current-column))
5669 0)
5670 offset)))
5671
5672 ;; Syntactic support functions:
5673
5674 (defun vhdl-in-comment-p (&optional pos)
5675 "Check if point is in a comment (include multi-line comments)."
5676 (let ((parse (lambda (p)
5677 (let ((c (char-after p)))
5678 (or (and c (eq (char-syntax c) ?<))
5679 (nth 4 (parse-partial-sexp
5680 (save-excursion
5681 (beginning-of-defun)
5682 (point)) p)))))))
5683 (save-excursion
5684 (goto-char (or pos (point)))
5685 (or (funcall parse (point))
5686 ;; `parse-partial-sexp's notion of comments doesn't span lines
5687 (progn
5688 (back-to-indentation)
5689 (unless (eolp)
5690 (forward-char)
5691 (funcall parse (point))))))))
5692
5693 (defun vhdl-in-string-p ()
5694 "Check if point is in a string."
5695 (eq (vhdl-in-literal) 'string))
5696
5697 (defun vhdl-in-quote-p ()
5698 "Check if point is in a quote ('x')."
5699 (or (and (> (point) (point-min))
5700 (< (1+ (point)) (point-max))
5701 (= (char-before (point)) ?\')
5702 (= (char-after (1+ (point))) ?\'))
5703 (and (> (1- (point)) (point-min))
5704 (< (point) (point-max))
5705 (= (char-before (1- (point))) ?\')
5706 (= (char-after (point)) ?\'))))
5707
5708 (defun vhdl-in-literal ()
5709 "Determine if point is in a VHDL literal."
5710 (save-excursion
5711 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5712 (cond
5713 ((nth 3 state) 'string)
5714 ((nth 4 state) 'comment)
5715 ((vhdl-beginning-of-macro) 'pound)
5716 ((vhdl-beginning-of-directive) 'directive)
5717 ;; for multi-line comments
5718 ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
5719 (t nil)))))
5720
5721 (defun vhdl-in-extended-identifier-p ()
5722 "Determine if point is inside extended identifier (delimited by `\\')."
5723 (save-match-data
5724 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5725 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5726
5727 (defun vhdl-forward-comment (&optional direction)
5728 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5729 negative, skip forward otherwise."
5730 (interactive "p")
5731 (if (and direction (< direction 0))
5732 ;; skip backwards
5733 (progn
5734 (skip-chars-backward " \t\n\r\f")
5735 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5736 (goto-char (match-beginning 3))
5737 (skip-chars-backward " \t\n\r\f")))
5738 ;; skip forwards
5739 (skip-chars-forward " \t\n\r\f")
5740 (while (looking-at "--.*")
5741 (goto-char (match-end 0))
5742 (skip-chars-forward " \t\n\r\f"))))
5743
5744 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5745 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5746 (defalias 'vhdl-forward-comment 'forward-comment))
5747
5748 (defun vhdl-back-to-indentation ()
5749 "Move point to the first non-whitespace character on this line."
5750 (interactive)
5751 (beginning-of-line 1)
5752 (skip-syntax-forward " " (vhdl-point 'eol)))
5753
5754 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5755 (when (featurep 'xemacs)
5756 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5757
5758 ;; This is the best we can do in Win-Emacs.
5759 (defun vhdl-win-il (&optional lim)
5760 "Determine if point is in a VHDL literal."
5761 (save-excursion
5762 (let* ((here (point))
5763 (state nil)
5764 (match nil)
5765 (lim (or lim (vhdl-point 'bod))))
5766 (goto-char lim )
5767 (while (< (point) here)
5768 (setq match
5769 (and (re-search-forward "--\\|[\"']\\|`"
5770 here 'move)
5771 (buffer-substring (match-beginning 0) (match-end 0))))
5772 (setq state
5773 (cond
5774 ;; no match
5775 ((null match) nil)
5776 ;; looking at the opening of a VHDL style comment
5777 ((string= "--" match)
5778 (if (<= here (progn (end-of-line) (point))) 'comment))
5779 ;; looking at a directive
5780 ((string= "`" match)
5781 (if (<= here (progn (end-of-line) (point))) 'directive))
5782 ;; looking at the opening of a double quote string
5783 ((string= "\"" match)
5784 (if (not (save-restriction
5785 ;; this seems to be necessary since the
5786 ;; re-search-forward will not work without it
5787 (narrow-to-region (point) here)
5788 (re-search-forward
5789 ;; this regexp matches a double quote
5790 ;; which is preceded by an even number
5791 ;; of backslashes, including zero
5792 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5793 'string))
5794 ;; looking at the opening of a single quote string
5795 ((string= "'" match)
5796 (if (not (save-restriction
5797 ;; see comments from above
5798 (narrow-to-region (point) here)
5799 (re-search-forward
5800 ;; this matches a single quote which is
5801 ;; preceded by zero or two backslashes.
5802 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5803 here 'move)))
5804 'string))
5805 (t nil)))
5806 ) ; end-while
5807 state)))
5808
5809 (and (string-match "Win-Emacs" emacs-version)
5810 (fset 'vhdl-in-literal 'vhdl-win-il))
5811
5812 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5813 ;; defined as lexical whitespace or comments. Search no farther back
5814 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5815 ;; used for backward skipping, (point-max) is used for forward
5816 ;; skipping.
5817
5818 (defun vhdl-forward-syntactic-ws (&optional lim)
5819 "Forward skip of syntactic whitespace."
5820 (let* ((here (point-max))
5821 (hugenum (point-max)))
5822 (while (/= here (point))
5823 (setq here (point))
5824 (vhdl-forward-comment hugenum)
5825 ;; skip preprocessor directives
5826 (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
5827 (= (vhdl-point 'boi) (point)))
5828 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5829 (= (forward-line 1) 0)))
5830 (end-of-line)))
5831 (if lim (goto-char (min (point) lim)))))
5832
5833
5834 ;; This is the best we can do in Win-Emacs.
5835 (defun vhdl-win-fsws (&optional lim)
5836 "Forward skip syntactic whitespace for Win-Emacs."
5837 (let ((lim (or lim (point-max)))
5838 stop)
5839 (while (not stop)
5840 (skip-chars-forward " \t\n\r\f" lim)
5841 (cond
5842 ;; vhdl comment
5843 ((looking-at "--") (end-of-line))
5844 ;; none of the above
5845 (t (setq stop t))))))
5846
5847 (and (string-match "Win-Emacs" emacs-version)
5848 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5849
5850 (defun vhdl-beginning-of-macro (&optional lim)
5851 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5852 (let ((here (point)))
5853 (beginning-of-line)
5854 (while (eq (char-before (1- (point))) ?\\)
5855 (forward-line -1))
5856 (back-to-indentation)
5857 (if (and (<= (point) here)
5858 (eq (char-after) ?#))
5859 t
5860 (goto-char here)
5861 nil)))
5862
5863 (defun vhdl-beginning-of-directive (&optional lim)
5864 "Go to the beginning of a directive (nicked from `cc-engine')."
5865 (let ((here (point)))
5866 (beginning-of-line)
5867 (while (eq (char-before (1- (point))) ?\\)
5868 (forward-line -1))
5869 (back-to-indentation)
5870 (if (and (<= (point) here)
5871 (eq (char-after) ?`))
5872 t
5873 (goto-char here)
5874 nil)))
5875
5876 (defun vhdl-backward-syntactic-ws (&optional lim)
5877 "Backward skip over syntactic whitespace."
5878 (let* ((here (point-min))
5879 (hugenum (- (point-max))))
5880 (while (/= here (point))
5881 (setq here (point))
5882 (vhdl-forward-comment hugenum)
5883 (vhdl-beginning-of-macro))
5884 (if lim (goto-char (max (point) lim)))))
5885
5886 ;; This is the best we can do in Win-Emacs.
5887 (defun vhdl-win-bsws (&optional lim)
5888 "Backward skip syntactic whitespace for Win-Emacs."
5889 (let ((lim (or lim (vhdl-point 'bod)))
5890 stop)
5891 (while (not stop)
5892 (skip-chars-backward " \t\n\r\f" lim)
5893 (cond
5894 ;; vhdl comment
5895 ((eq (vhdl-in-literal) 'comment)
5896 (skip-chars-backward "^-" lim)
5897 (skip-chars-backward "-" lim)
5898 (while (not (or (and (= (following-char) ?-)
5899 (= (char-after (1+ (point))) ?-))
5900 (<= (point) lim)))
5901 (skip-chars-backward "^-" lim)
5902 (skip-chars-backward "-" lim)))
5903 ;; none of the above
5904 (t (setq stop t))))))
5905
5906 (and (string-match "Win-Emacs" emacs-version)
5907 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5908
5909 ;; Functions to help finding the correct indentation column:
5910
5911 (defun vhdl-first-word (point)
5912 "If the keyword at POINT is at boi, then return (current-column) at
5913 that point, else nil."
5914 (save-excursion
5915 (and (goto-char point)
5916 (eq (point) (vhdl-point 'boi))
5917 (current-column))))
5918
5919 (defun vhdl-last-word (point)
5920 "If the keyword at POINT is at eoi, then return (current-column) at
5921 that point, else nil."
5922 (save-excursion
5923 (and (goto-char point)
5924 (save-excursion (or (eq (progn (forward-sexp) (point))
5925 (vhdl-point 'eoi))
5926 (looking-at "\\s-*\\(--\\)?")))
5927 (current-column))))
5928
5929 ;; Core syntactic evaluation functions:
5930
5931 (defconst vhdl-libunit-re
5932 "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
5933
5934 (defun vhdl-libunit-p ()
5935 (and
5936 (save-excursion
5937 (forward-sexp)
5938 (skip-chars-forward " \t\n\r\f")
5939 (not (looking-at "is\\b[^_]")))
5940 (save-excursion
5941 (backward-sexp)
5942 (and (not (looking-at "use\\b[^_]"))
5943 (progn
5944 (forward-sexp)
5945 (vhdl-forward-syntactic-ws)
5946 (/= (following-char) ?:))))
5947 ))
5948
5949 (defconst vhdl-defun-re
5950 "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5951
5952 (defun vhdl-defun-p ()
5953 (save-excursion
5954 (if (looking-at "block\\|process\\|procedural")
5955 ;; "block", "process", "procedural":
5956 (save-excursion
5957 (backward-sexp)
5958 (not (looking-at "end\\s-+\\w")))
5959 ;; "architecture", "configuration", "context", "entity",
5960 ;; "package", "procedure", "function":
5961 t)))
5962
5963 (defun vhdl-corresponding-defun ()
5964 "If the word at the current position corresponds to a \"defun\"
5965 keyword, then return a string that can be used to find the
5966 corresponding \"begin\" keyword, else return nil."
5967 (save-excursion
5968 (and (looking-at vhdl-defun-re)
5969 (vhdl-defun-p)
5970 (if (looking-at "block\\|process\\|procedural")
5971 ;; "block", "process". "procedural:
5972 (buffer-substring (match-beginning 0) (match-end 0))
5973 ;; "architecture", "configuration", "context", "entity", "package",
5974 ;; "procedure", "function":
5975 "is"))))
5976
5977 (defconst vhdl-begin-fwd-re
5978 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5979 "A regular expression for searching forward that matches all known
5980 \"begin\" keywords.")
5981
5982 (defconst vhdl-begin-bwd-re
5983 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5984 "A regular expression for searching backward that matches all known
5985 \"begin\" keywords.")
5986
5987 (defun vhdl-begin-p (&optional lim)
5988 "Return t if we are looking at a real \"begin\" keyword.
5989 Assumes that the caller will make sure that we are looking at
5990 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5991 the middle of an identifier that just happens to contain a \"begin\"
5992 keyword."
5993 (cond
5994 ;; "[architecture|case|configuration|context|entity|package|
5995 ;; procedure|function] ... is":
5996 ((and (looking-at "i")
5997 (save-excursion
5998 ;; Skip backward over first sexp (needed to skip over a
5999 ;; procedure interface list, and is harmless in other
6000 ;; situations). Note that we need "return" in the
6001 ;; following search list so that we don't run into
6002 ;; semicolons in the function interface list.
6003 (backward-sexp)
6004 (let (foundp)
6005 (while (and (not foundp)
6006 (re-search-backward
6007 ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
6008 lim 'move))
6009 (if (or (= (preceding-char) ?_)
6010 (vhdl-in-literal))
6011 (backward-char)
6012 (setq foundp t))))
6013 (and (/= (following-char) ?\;)
6014 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
6015 t)
6016 ;; "begin", "then", "use":
6017 ((looking-at "be\\|t\\|use")
6018 t)
6019 ;; "else":
6020 ((and (looking-at "e")
6021 ;; make sure that the "else" isn't inside a
6022 ;; conditional signal assignment.
6023 (save-excursion
6024 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6025 (or (eq (following-char) ?\;)
6026 (eq (point) lim))))
6027 t)
6028 ;; "block", "generate", "loop", "process", "procedural",
6029 ;; "units", "record", "protected body":
6030 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
6031 (save-excursion
6032 (backward-sexp)
6033 (not (looking-at "end\\s-+\\w"))))
6034 t)
6035 ;; "component":
6036 ((and (looking-at "c")
6037 (save-excursion
6038 (backward-sexp)
6039 (not (looking-at "end\\s-+\\w")))
6040 ;; look out for the dreaded entity class in an attribute
6041 (save-excursion
6042 (vhdl-backward-syntactic-ws lim)
6043 (/= (preceding-char) ?:)))
6044 t)
6045 ;; "for" (inside configuration declaration):
6046 ((and (looking-at "f")
6047 (save-excursion
6048 (backward-sexp)
6049 (not (looking-at "end\\s-+\\w")))
6050 (vhdl-has-syntax 'configuration))
6051 t)
6052 ))
6053
6054 (defun vhdl-corresponding-mid (&optional lim)
6055 (cond
6056 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
6057 "begin")
6058 ((looking-at "then\\|use")
6059 "<else>")
6060 (t
6061 "end")))
6062
6063 (defun vhdl-corresponding-end (&optional lim)
6064 "If the word at the current position corresponds to a \"begin\"
6065 keyword, then return a vector containing enough information to find
6066 the corresponding \"end\" keyword, else return nil. The keyword to
6067 search forward for is aref 0. The column in which the keyword must
6068 appear is aref 1 or nil if any column is suitable.
6069 Assumes that the caller will make sure that we are not in the middle
6070 of an identifier that just happens to contain a \"begin\" keyword."
6071 (save-excursion
6072 (and (looking-at vhdl-begin-fwd-re)
6073 (or (not (looking-at "\\<use\\>"))
6074 (save-excursion (back-to-indentation)
6075 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6076 (/= (preceding-char) ?_)
6077 (not (vhdl-in-literal))
6078 (vhdl-begin-p lim)
6079 (cond
6080 ;; "is", "generate", "loop":
6081 ((looking-at "[igl]")
6082 (vector "end"
6083 (and (vhdl-last-word (point))
6084 (or (vhdl-first-word (point))
6085 (save-excursion
6086 (vhdl-beginning-of-statement-1 lim)
6087 (vhdl-backward-skip-label lim)
6088 (vhdl-first-word (point)))))))
6089 ;; "begin", "else", "for":
6090 ((looking-at "be\\|[ef]")
6091 (vector "end"
6092 (and (vhdl-last-word (point))
6093 (or (vhdl-first-word (point))
6094 (save-excursion
6095 (vhdl-beginning-of-statement-1 lim)
6096 (vhdl-backward-skip-label lim)
6097 (vhdl-first-word (point)))))))
6098 ;; "component", "units", "record", "protected body":
6099 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
6100 ;; The first end found will close the block
6101 (vector "end" nil))
6102 ;; "block", "process", "procedural":
6103 ((looking-at "bl\\|p")
6104 (vector "end"
6105 (or (vhdl-first-word (point))
6106 (save-excursion
6107 (vhdl-beginning-of-statement-1 lim)
6108 (vhdl-backward-skip-label lim)
6109 (vhdl-first-word (point))))))
6110 ;; "then":
6111 ((looking-at "t\\|use")
6112 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6113 (and (vhdl-last-word (point))
6114 (or (vhdl-first-word (point))
6115 (save-excursion
6116 (vhdl-beginning-of-statement-1 lim)
6117 (vhdl-backward-skip-label lim)
6118 (vhdl-first-word (point)))))))
6119 ))))
6120
6121 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6122
6123 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6124
6125 (defun vhdl-end-p (&optional lim)
6126 "Return t if we are looking at a real \"end\" keyword.
6127 Assumes that the caller will make sure that we are looking at
6128 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6129 the middle of an identifier that just happens to contain an \"end\"
6130 keyword."
6131 (or (not (looking-at "else"))
6132 ;; make sure that the "else" isn't inside a conditional signal
6133 ;; assignment.
6134 (save-excursion
6135 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6136 (or (eq (following-char) ?\;)
6137 (eq (point) lim)
6138 (vhdl-in-literal)))))
6139
6140 (defun vhdl-corresponding-begin (&optional lim)
6141 "If the word at the current position corresponds to an \"end\"
6142 keyword, then return a vector containing enough information to find
6143 the corresponding \"begin\" keyword, else return nil. The keyword to
6144 search backward for is aref 0. The column in which the keyword must
6145 appear is aref 1 or nil if any column is suitable. The supplementary
6146 keyword to search forward for is aref 2 or nil if this is not
6147 required. If aref 3 is t, then the \"begin\" keyword may be found in
6148 the middle of a statement.
6149 Assumes that the caller will make sure that we are not in the middle
6150 of an identifier that just happens to contain an \"end\" keyword."
6151 (save-excursion
6152 (let (pos)
6153 (if (and (looking-at vhdl-end-fwd-re)
6154 (not (vhdl-in-literal))
6155 (vhdl-end-p lim))
6156 (if (looking-at "el")
6157 ;; "else", "elsif":
6158 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6159 ;; "end ...":
6160 (setq pos (point))
6161 (forward-sexp)
6162 (skip-chars-forward " \t\n\r\f")
6163 (cond
6164 ;; "end if":
6165 ((looking-at "if\\b[^_]")
6166 (vector "else\\|elsif\\|if"
6167 (vhdl-first-word pos)
6168 "else\\|then\\|use" nil))
6169 ;; "end component":
6170 ((looking-at "component\\b[^_]")
6171 (vector (buffer-substring (match-beginning 1)
6172 (match-end 1))
6173 (vhdl-first-word pos)
6174 nil nil))
6175 ;; "end units", "end record", "end protected":
6176 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6177 (vector (buffer-substring (match-beginning 1)
6178 (match-end 1))
6179 (vhdl-first-word pos)
6180 nil t))
6181 ;; "end block", "end process", "end procedural":
6182 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6183 (vector "begin" (vhdl-first-word pos) nil nil))
6184 ;; "end case":
6185 ((looking-at "case\\b[^_]")
6186 (vector "case" (vhdl-first-word pos) "is" nil))
6187 ;; "end generate":
6188 ((looking-at "generate\\b[^_]")
6189 (vector "generate\\|for\\|if"
6190 (vhdl-first-word pos)
6191 "generate" nil))
6192 ;; "end loop":
6193 ((looking-at "loop\\b[^_]")
6194 (vector "loop\\|while\\|for"
6195 (vhdl-first-word pos)
6196 "loop" nil))
6197 ;; "end for" (inside configuration declaration):
6198 ((looking-at "for\\b[^_]")
6199 (vector "for" (vhdl-first-word pos) nil nil))
6200 ;; "end [id]":
6201 (t
6202 (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
6203 (vhdl-first-word pos)
6204 ;; return an alist of (statement . keyword) mappings
6205 '(
6206 ;; "begin ... end [id]":
6207 ("begin" . nil)
6208 ;; "architecture ... is ... begin ... end [id]":
6209 ("architecture" . "is")
6210 ;; "configuration ... is ... end [id]":
6211 ("configuration" . "is")
6212 ;; "context ... is ... end [id]":
6213 ("context" . "is")
6214 ;; "entity ... is ... end [id]":
6215 ("entity" . "is")
6216 ;; "package ... is ... end [id]":
6217 ("package" . "is")
6218 ;; "procedure ... is ... begin ... end [id]":
6219 ("procedure" . "is")
6220 ;; "function ... is ... begin ... end [id]":
6221 ("function" . "is")
6222 )
6223 nil))
6224 ))) ; "end ..."
6225 )))
6226
6227 (defconst vhdl-leader-re
6228 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6229
6230 (defun vhdl-end-of-leader ()
6231 (save-excursion
6232 (cond ((looking-at "block\\|process\\|procedural")
6233 (if (save-excursion
6234 (forward-sexp)
6235 (skip-chars-forward " \t\n\r\f")
6236 (= (following-char) ?\())
6237 (forward-sexp 2)
6238 (forward-sexp))
6239 (when (looking-at "[ \t\n\r\f]*is")
6240 (goto-char (match-end 0)))
6241 (point))
6242 ((looking-at "component")
6243 (forward-sexp 2)
6244 (when (looking-at "[ \t\n\r\f]*is")
6245 (goto-char (match-end 0)))
6246 (point))
6247 ((looking-at "for")
6248 (forward-sexp 2)
6249 (skip-chars-forward " \t\n\r\f")
6250 (while (looking-at "[,:(]")
6251 (forward-sexp)
6252 (skip-chars-forward " \t\n\r\f"))
6253 (point))
6254 (t nil)
6255 )))
6256
6257 (defconst vhdl-trailer-re
6258 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6259
6260 (defconst vhdl-statement-fwd-re
6261 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6262 "A regular expression for searching forward that matches all known
6263 \"statement\" keywords.")
6264
6265 (defconst vhdl-statement-bwd-re
6266 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6267 "A regular expression for searching backward that matches all known
6268 \"statement\" keywords.")
6269
6270 (defun vhdl-statement-p (&optional lim)
6271 "Return t if we are looking at a real \"statement\" keyword.
6272 Assumes that the caller will make sure that we are looking at
6273 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6274 in the middle of an identifier that just happens to contain a
6275 \"statement\" keyword."
6276 (cond
6277 ;; "for" ... "generate":
6278 ((and (looking-at "f")
6279 ;; Make sure it's the start of a parameter specification.
6280 (save-excursion
6281 (forward-sexp 2)
6282 (skip-chars-forward " \t\n\r\f")
6283 (looking-at "in\\b[^_]"))
6284 ;; Make sure it's not an "end for".
6285 (save-excursion
6286 (backward-sexp)
6287 (not (looking-at "end\\s-+\\w"))))
6288 t)
6289 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6290 ((and (looking-at "i")
6291 ;; Make sure it's not an "end if".
6292 (save-excursion
6293 (backward-sexp)
6294 (not (looking-at "end\\s-+\\w"))))
6295 t)
6296 ;; "while" ... "loop":
6297 ((looking-at "w")
6298 t)
6299 ))
6300
6301 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6302 "Regexp describing a case statement alternative key.")
6303
6304 (defun vhdl-case-alternative-p (&optional lim)
6305 "Return t if we are looking at a real case alternative.
6306 Assumes that the caller will make sure that we are looking at
6307 vhdl-case-alternative-re, and are not inside a literal, and that
6308 we are not in the middle of an identifier that just happens to
6309 contain a \"when\" keyword."
6310 (save-excursion
6311 (let (foundp)
6312 (while (and (not foundp)
6313 (re-search-backward ";\\|<=" lim 'move))
6314 (if (or (= (preceding-char) ?_)
6315 (vhdl-in-literal))
6316 (backward-char)
6317 (setq foundp t)))
6318 (or (eq (following-char) ?\;)
6319 (eq (point) lim)))
6320 ))
6321
6322 ;; Core syntactic movement functions:
6323
6324 (defconst vhdl-b-t-b-re
6325 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6326
6327 (defun vhdl-backward-to-block (&optional lim)
6328 "Move backward to the previous \"begin\" or \"end\" keyword."
6329 (let (foundp)
6330 (while (and (not foundp)
6331 (re-search-backward vhdl-b-t-b-re lim 'move))
6332 (if (or (= (preceding-char) ?_)
6333 (vhdl-in-literal))
6334 (backward-char)
6335 (cond
6336 ;; "begin" keyword:
6337 ((and (looking-at vhdl-begin-fwd-re)
6338 (or (not (looking-at "\\<use\\>"))
6339 (save-excursion (back-to-indentation)
6340 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6341 (/= (preceding-char) ?_)
6342 (vhdl-begin-p lim))
6343 (setq foundp 'begin))
6344 ;; "end" keyword:
6345 ((and (looking-at vhdl-end-fwd-re)
6346 (/= (preceding-char) ?_)
6347 (vhdl-end-p lim))
6348 (setq foundp 'end))
6349 ))
6350 )
6351 foundp
6352 ))
6353
6354 (defun vhdl-forward-sexp (&optional count lim)
6355 "Move forward across one balanced expression (sexp).
6356 With COUNT, do it that many times."
6357 (interactive "p")
6358 (let ((count (or count 1))
6359 (case-fold-search t)
6360 end-vec target)
6361 (save-excursion
6362 (while (> count 0)
6363 ;; skip whitespace
6364 (skip-chars-forward " \t\n\r\f")
6365 ;; Check for an unbalanced "end" keyword
6366 (if (and (looking-at vhdl-end-fwd-re)
6367 (/= (preceding-char) ?_)
6368 (not (vhdl-in-literal))
6369 (vhdl-end-p lim)
6370 (not (looking-at "else")))
6371 (error
6372 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6373 ;; If the current keyword is a "begin" keyword, then find the
6374 ;; corresponding "end" keyword.
6375 (if (setq end-vec (vhdl-corresponding-end lim))
6376 (let (
6377 ;; end-re is the statement keyword to search for
6378 (end-re
6379 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6380 ;; column is either the statement keyword target column
6381 ;; or nil
6382 (column (aref end-vec 1))
6383 (eol (vhdl-point 'eol))
6384 foundp literal placeholder)
6385 ;; Look for the statement keyword.
6386 (while (and (not foundp)
6387 (re-search-forward end-re nil t)
6388 (setq placeholder (match-end 1))
6389 (goto-char (match-beginning 0)))
6390 ;; If we are in a literal, or not in the right target
6391 ;; column and not on the same line as the begin, then
6392 ;; try again.
6393 (if (or (and column
6394 (/= (current-indentation) column)
6395 (> (point) eol))
6396 (= (preceding-char) ?_)
6397 (setq literal (vhdl-in-literal)))
6398 (if (eq literal 'comment)
6399 (end-of-line)
6400 (forward-char))
6401 ;; An "else" keyword corresponds to both the opening brace
6402 ;; of the following sexp and the closing brace of the
6403 ;; previous sexp.
6404 (if (not (looking-at "else"))
6405 (goto-char placeholder))
6406 (setq foundp t))
6407 )
6408 (if (not foundp)
6409 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6410 )
6411 ;; If the current keyword is not a "begin" keyword, then just
6412 ;; perform the normal forward-sexp.
6413 (forward-sexp)
6414 )
6415 (setq count (1- count))
6416 )
6417 (setq target (point)))
6418 (goto-char target)
6419 nil))
6420
6421 (defun vhdl-backward-sexp (&optional count lim)
6422 "Move backward across one balanced expression (sexp).
6423 With COUNT, do it that many times. LIM bounds any required backward
6424 searches."
6425 (interactive "p")
6426 (let ((count (or count 1))
6427 (case-fold-search t)
6428 begin-vec target)
6429 (save-excursion
6430 (while (> count 0)
6431 ;; Perform the normal backward-sexp, unless we are looking at
6432 ;; "else" - an "else" keyword corresponds to both the opening brace
6433 ;; of the following sexp and the closing brace of the previous sexp.
6434 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6435 (/= (preceding-char) ?_)
6436 (not (vhdl-in-literal)))
6437 nil
6438 (backward-sexp)
6439 (if (and (looking-at vhdl-begin-fwd-re)
6440 (or (not (looking-at "\\<use\\>"))
6441 (save-excursion
6442 (back-to-indentation)
6443 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6444 (/= (preceding-char) ?_)
6445 (not (vhdl-in-literal))
6446 (vhdl-begin-p lim))
6447 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6448 ;; If the current keyword is an "end" keyword, then find the
6449 ;; corresponding "begin" keyword.
6450 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6451 (/= (preceding-char) ?_))
6452 (let (
6453 ;; begin-re is the statement keyword to search for
6454 (begin-re
6455 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6456 ;; column is either the statement keyword target column
6457 ;; or nil
6458 (column (aref begin-vec 1))
6459 ;; internal-p controls where the statement keyword can
6460 ;; be found.
6461 (internal-p (aref begin-vec 3))
6462 (last-backward (point)) last-forward
6463 foundp literal keyword)
6464 ;; Look for the statement keyword.
6465 (while (and (not foundp)
6466 (re-search-backward begin-re lim t)
6467 (setq keyword
6468 (buffer-substring (match-beginning 1)
6469 (match-end 1))))
6470 ;; If we are in a literal or in the wrong column,
6471 ;; then try again.
6472 (if (or (and column
6473 (and (/= (current-indentation) column)
6474 ;; possibly accept current-column as
6475 ;; well as current-indentation.
6476 (or (not internal-p)
6477 (/= (current-column) column))))
6478 (= (preceding-char) ?_)
6479 (vhdl-in-literal))
6480 (backward-char)
6481 ;; If there is a supplementary keyword, then
6482 ;; search forward for it.
6483 (if (and (setq begin-re (aref begin-vec 2))
6484 (or (not (listp begin-re))
6485 ;; If begin-re is an alist, then find the
6486 ;; element corresponding to the actual
6487 ;; keyword that we found.
6488 (progn
6489 (setq begin-re
6490 (assoc keyword begin-re))
6491 (and begin-re
6492 (setq begin-re (cdr begin-re))))))
6493 (and
6494 (setq begin-re
6495 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6496 (save-excursion
6497 (setq last-forward (point))
6498 ;; Look for the supplementary keyword
6499 ;; (bounded by the backward search start
6500 ;; point).
6501 (while (and (not foundp)
6502 (re-search-forward begin-re
6503 last-backward t)
6504 (goto-char (match-beginning 1)))
6505 ;; If we are in a literal, then try again.
6506 (if (or (= (preceding-char) ?_)
6507 (setq literal
6508 (vhdl-in-literal)))
6509 (if (eq literal 'comment)
6510 (goto-char
6511 (min (vhdl-point 'eol) last-backward))
6512 (forward-char))
6513 ;; We have found the supplementary keyword.
6514 ;; Save the position of the keyword in foundp.
6515 (setq foundp (point)))
6516 )
6517 foundp)
6518 ;; If the supplementary keyword was found, then
6519 ;; move point to the supplementary keyword.
6520 (goto-char foundp))
6521 ;; If there was no supplementary keyword, then
6522 ;; point is already at the statement keyword.
6523 (setq foundp t)))
6524 ) ; end of the search for the statement keyword
6525 (if (not foundp)
6526 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6527 ))
6528 (setq count (1- count))
6529 )
6530 (setq target (point)))
6531 (goto-char target)
6532 nil))
6533
6534 (defun vhdl-backward-up-list (&optional count limit)
6535 "Move backward out of one level of blocks.
6536 With argument, do this that many times."
6537 (interactive "p")
6538 (let ((count (or count 1))
6539 target)
6540 (save-excursion
6541 (while (> count 0)
6542 (if (looking-at vhdl-defun-re)
6543 (error "ERROR: Unbalanced blocks"))
6544 (vhdl-backward-to-block limit)
6545 (setq count (1- count)))
6546 (setq target (point)))
6547 (goto-char target)))
6548
6549 (defun vhdl-end-of-defun (&optional count)
6550 "Move forward to the end of a VHDL defun."
6551 (interactive)
6552 (let ((case-fold-search t))
6553 (vhdl-beginning-of-defun)
6554 (if (not (looking-at "block\\|process\\|procedural"))
6555 (re-search-forward "\\bis\\b"))
6556 (vhdl-forward-sexp)))
6557
6558 (defun vhdl-mark-defun ()
6559 "Put mark at end of this \"defun\", point at beginning."
6560 (interactive)
6561 (let ((case-fold-search t))
6562 (push-mark)
6563 (vhdl-beginning-of-defun)
6564 (push-mark)
6565 (if (not (looking-at "block\\|process\\|procedural"))
6566 (re-search-forward "\\bis\\b"))
6567 (vhdl-forward-sexp)
6568 (exchange-point-and-mark)))
6569
6570 (defun vhdl-beginning-of-libunit ()
6571 "Move backward to the beginning of a VHDL library unit.
6572 Returns the location of the corresponding begin keyword, unless search
6573 stops due to beginning or end of buffer.
6574 Note that if point is between the \"libunit\" keyword and the
6575 corresponding \"begin\" keyword, then that libunit will not be
6576 recognized, and the search will continue backwards. If point is
6577 at the \"begin\" keyword, then the defun will be recognized. The
6578 returned point is at the first character of the \"libunit\" keyword."
6579 (let ((last-forward (point))
6580 (last-backward
6581 ;; Just in case we are actually sitting on the "begin"
6582 ;; keyword, allow for the keyword and an extra character,
6583 ;; as this will be used when looking forward for the
6584 ;; "begin" keyword.
6585 (save-excursion (forward-word 1) (1+ (point))))
6586 foundp literal placeholder)
6587 ;; Find the "libunit" keyword.
6588 (while (and (not foundp)
6589 (re-search-backward vhdl-libunit-re nil 'move))
6590 ;; If we are in a literal, or not at a real libunit, then try again.
6591 (if (or (= (preceding-char) ?_)
6592 (vhdl-in-literal)
6593 (not (vhdl-libunit-p)))
6594 (backward-char)
6595 ;; Find the corresponding "begin" keyword.
6596 (setq last-forward (point))
6597 (while (and (not foundp)
6598 (re-search-forward "\\bis\\b[^_]" last-backward t)
6599 (setq placeholder (match-beginning 0)))
6600 (if (or (= (preceding-char) ?_)
6601 (setq literal (vhdl-in-literal)))
6602 ;; It wasn't a real keyword, so keep searching.
6603 (if (eq literal 'comment)
6604 (goto-char
6605 (min (vhdl-point 'eol) last-backward))
6606 (forward-char))
6607 ;; We have found the begin keyword, loop will exit.
6608 (setq foundp placeholder)))
6609 ;; Go back to the libunit keyword
6610 (goto-char last-forward)))
6611 foundp))
6612
6613 (defun vhdl-beginning-of-defun (&optional count)
6614 "Move backward to the beginning of a VHDL defun.
6615 With argument, do it that many times.
6616 Returns the location of the corresponding begin keyword, unless search
6617 stops due to beginning or end of buffer."
6618 ;; Note that if point is between the "defun" keyword and the
6619 ;; corresponding "begin" keyword, then that defun will not be
6620 ;; recognized, and the search will continue backwards. If point is
6621 ;; at the "begin" keyword, then the defun will be recognized. The
6622 ;; returned point is at the first character of the "defun" keyword.
6623 (interactive "p")
6624 (let ((count (or count 1))
6625 (case-fold-search t)
6626 (last-forward (point))
6627 foundp)
6628 (while (> count 0)
6629 (setq foundp nil)
6630 (goto-char last-forward)
6631 (let ((last-backward
6632 ;; Just in case we are actually sitting on the "begin"
6633 ;; keyword, allow for the keyword and an extra character,
6634 ;; as this will be used when looking forward for the
6635 ;; "begin" keyword.
6636 (save-excursion (forward-word 1) (1+ (point))))
6637 begin-string literal)
6638 (while (and (not foundp)
6639 (re-search-backward vhdl-defun-re nil 'move))
6640 ;; If we are in a literal, then try again.
6641 (if (or (= (preceding-char) ?_)
6642 (vhdl-in-literal))
6643 (backward-char)
6644 (if (setq begin-string (vhdl-corresponding-defun))
6645 ;; This is a real defun keyword.
6646 ;; Find the corresponding "begin" keyword.
6647 ;; Look for the begin keyword.
6648 (progn
6649 ;; Save the search start point.
6650 (setq last-forward (point))
6651 (while (and (not foundp)
6652 (search-forward begin-string last-backward t))
6653 (if (or (= (preceding-char) ?_)
6654 (save-match-data
6655 (setq literal (vhdl-in-literal))))
6656 ;; It wasn't a real keyword, so keep searching.
6657 (if (eq literal 'comment)
6658 (goto-char
6659 (min (vhdl-point 'eol) last-backward))
6660 (forward-char))
6661 ;; We have found the begin keyword, loop will exit.
6662 (setq foundp (match-beginning 0)))
6663 )
6664 ;; Go back to the defun keyword
6665 (goto-char last-forward)) ; end search for begin keyword
6666 ))
6667 ) ; end of the search for the defun keyword
6668 )
6669 (setq count (1- count))
6670 )
6671 (vhdl-keep-region-active)
6672 foundp))
6673
6674 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6675 "Go to the beginning of the innermost VHDL statement.
6676 With prefix arg, go back N - 1 statements. If already at the
6677 beginning of a statement then go to the beginning of the preceding
6678 one. If within a string or comment, or next to a comment (only
6679 whitespace between), move by sentences instead of statements.
6680
6681 When called from a program, this function takes 3 optional args: the
6682 prefix arg, a buffer position limit which is the farthest back to
6683 search, and an argument indicating an interactive call."
6684 (interactive "p\np")
6685 (let ((count (or count 1))
6686 (case-fold-search t)
6687 (lim (or lim (point-min)))
6688 (here (point))
6689 state)
6690 (save-excursion
6691 (goto-char lim)
6692 (setq state (parse-partial-sexp (point) here nil nil)))
6693 (if (and interactive
6694 (or (nth 3 state)
6695 (nth 4 state)
6696 (looking-at (concat "[ \t]*" comment-start-skip))))
6697 (forward-sentence (- count))
6698 (while (> count 0)
6699 (vhdl-beginning-of-statement-1 lim)
6700 (setq count (1- count))))
6701 ;; its possible we've been left up-buf of lim
6702 (goto-char (max (point) lim))
6703 )
6704 (vhdl-keep-region-active))
6705
6706 (defconst vhdl-e-o-s-re
6707 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6708
6709 (defun vhdl-end-of-statement ()
6710 "Very simple implementation."
6711 (interactive)
6712 (re-search-forward vhdl-e-o-s-re))
6713
6714 (defconst vhdl-b-o-s-re
6715 (concat ";[^_]\\|([^_]\\|)[^_]\\|\\bwhen\\b[^_]\\|"
6716 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6717
6718 (defun vhdl-beginning-of-statement-1 (&optional lim)
6719 "Move to the start of the current statement, or the previous
6720 statement if already at the beginning of one."
6721 (let ((lim (or lim (point-min)))
6722 (here (point))
6723 (pos (point))
6724 donep)
6725 ;; go backwards one balanced expression, but be careful of
6726 ;; unbalanced paren being reached
6727 (if (not (vhdl-safe (progn (backward-sexp) t)))
6728 (progn
6729 (backward-up-list 1)
6730 (forward-char)
6731 (vhdl-forward-syntactic-ws here)
6732 (setq donep t)))
6733 (while (and (not donep)
6734 (not (bobp))
6735 ;; look backwards for a statement boundary
6736 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6737 (if (or (= (preceding-char) ?_)
6738 (vhdl-in-literal))
6739 (backward-char)
6740 (cond
6741 ;; If we are looking at an open paren, then stop after it
6742 ((eq (following-char) ?\()
6743 (forward-char)
6744 (vhdl-forward-syntactic-ws here)
6745 (setq donep t))
6746 ;; If we are looking at a close paren, then skip it
6747 ((eq (following-char) ?\))
6748 (forward-char)
6749 (setq pos (point))
6750 (backward-sexp)
6751 (if (< (point) lim)
6752 (progn (goto-char pos)
6753 (vhdl-forward-syntactic-ws here)
6754 (setq donep t))))
6755 ;; If we are looking at a semicolon, then stop
6756 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6757 (progn
6758 (forward-char)
6759 (vhdl-forward-syntactic-ws here)
6760 (setq donep t)))
6761 ;; If we are looking at a "begin", then stop
6762 ((and (looking-at vhdl-begin-fwd-re)
6763 (or (not (looking-at "\\<use\\>"))
6764 (save-excursion
6765 (back-to-indentation)
6766 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6767 (/= (preceding-char) ?_)
6768 (vhdl-begin-p nil))
6769 ;; If it's a leader "begin", then find the
6770 ;; right place
6771 (if (looking-at vhdl-leader-re)
6772 (save-excursion
6773 ;; set a default stop point at the begin
6774 (setq pos (point))
6775 ;; is the start point inside the leader area ?
6776 (goto-char (vhdl-end-of-leader))
6777 (vhdl-forward-syntactic-ws here)
6778 (if (< (point) here)
6779 ;; start point was not inside leader area
6780 ;; set stop point at word after leader
6781 (setq pos (point))))
6782 (forward-word 1)
6783 (vhdl-forward-syntactic-ws here)
6784 (setq pos (point)))
6785 (goto-char pos)
6786 (setq donep t))
6787 ;; If we are looking at a "statement", then stop
6788 ((and (looking-at vhdl-statement-fwd-re)
6789 (/= (preceding-char) ?_)
6790 (vhdl-statement-p nil))
6791 (setq donep t))
6792 ;; If we are looking at a case alternative key, then stop
6793 ((and (looking-at vhdl-case-alternative-re)
6794 (vhdl-case-alternative-p lim))
6795 (save-excursion
6796 ;; set a default stop point at the when
6797 (setq pos (point))
6798 ;; is the start point inside the case alternative key ?
6799 (looking-at vhdl-case-alternative-re)
6800 (goto-char (match-end 0))
6801 (vhdl-forward-syntactic-ws here)
6802 (if (< (point) here)
6803 ;; start point was not inside the case alternative key
6804 ;; set stop point at word after case alternative keyleader
6805 (setq pos (point))))
6806 (goto-char pos)
6807 (setq donep t))
6808 ;; Bogus find, continue
6809 (t
6810 (backward-char)))))
6811 ))
6812
6813 ;; Defuns for calculating the current syntactic state:
6814
6815 (defun vhdl-get-library-unit (bod placeholder)
6816 "If there is an enclosing library unit at BOD, with its \"begin\"
6817 keyword at PLACEHOLDER, then return the library unit type."
6818 (let ((here (vhdl-point 'bol)))
6819 (if (save-excursion
6820 (goto-char placeholder)
6821 (vhdl-safe (vhdl-forward-sexp 1 bod))
6822 (<= here (point)))
6823 (save-excursion
6824 (goto-char bod)
6825 (cond
6826 ((looking-at "e") 'entity)
6827 ((looking-at "a") 'architecture)
6828 ((looking-at "conf") 'configuration)
6829 ((looking-at "cont") 'context)
6830 ((looking-at "p")
6831 (save-excursion
6832 (goto-char bod)
6833 (forward-sexp)
6834 (vhdl-forward-syntactic-ws here)
6835 (if (looking-at "body\\b[^_]")
6836 'package-body 'package))))))
6837 ))
6838
6839 (defun vhdl-get-block-state (&optional lim)
6840 "Finds and records all the closest opens.
6841 LIM is the furthest back we need to search (it should be the
6842 previous libunit keyword)."
6843 (let ((here (point))
6844 (lim (or lim (point-min)))
6845 keyword sexp-start sexp-mid sexp-end
6846 preceding-sexp containing-sexp
6847 containing-begin containing-mid containing-paren)
6848 (save-excursion
6849 ;; Find the containing-paren, and use that as the limit
6850 (if (setq containing-paren
6851 (save-restriction
6852 (narrow-to-region lim (point))
6853 (vhdl-safe (scan-lists (point) -1 1))))
6854 (setq lim containing-paren))
6855 ;; Look backwards for "begin" and "end" keywords.
6856 (while (and (> (point) lim)
6857 (not containing-sexp))
6858 (setq keyword (vhdl-backward-to-block lim))
6859 (cond
6860 ((eq keyword 'begin)
6861 ;; Found a "begin" keyword
6862 (setq sexp-start (point))
6863 (setq sexp-mid (vhdl-corresponding-mid lim))
6864 (setq sexp-end (vhdl-safe
6865 (save-excursion
6866 (vhdl-forward-sexp 1 lim) (point))))
6867 (if (and sexp-end (<= sexp-end here))
6868 ;; we want to record this sexp, but we only want to
6869 ;; record the last-most of any of them before here
6870 (or preceding-sexp
6871 (setq preceding-sexp sexp-start))
6872 ;; we're contained in this sexp so put sexp-start on
6873 ;; front of list
6874 (setq containing-sexp sexp-start)
6875 (setq containing-mid sexp-mid)
6876 (setq containing-begin t)))
6877 ((eq keyword 'end)
6878 ;; Found an "end" keyword
6879 (forward-sexp)
6880 (setq sexp-end (point))
6881 (setq sexp-mid nil)
6882 (setq sexp-start
6883 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6884 (progn (backward-sexp) (point))))
6885 ;; we want to record this sexp, but we only want to
6886 ;; record the last-most of any of them before here
6887 (or preceding-sexp
6888 (setq preceding-sexp sexp-start)))
6889 )))
6890 ;; Check if the containing-paren should be the containing-sexp
6891 (if (and containing-paren
6892 (or (null containing-sexp)
6893 (< containing-sexp containing-paren)))
6894 (setq containing-sexp containing-paren
6895 preceding-sexp nil
6896 containing-begin nil
6897 containing-mid nil))
6898 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6899 ))
6900
6901
6902 (defconst vhdl-s-c-a-re
6903 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6904
6905 (defun vhdl-skip-case-alternative (&optional lim)
6906 "Skip forward over case/when bodies, with optional maximal
6907 limit. If no next case alternative is found, nil is returned and
6908 point is not moved."
6909 (let ((lim (or lim (point-max)))
6910 (here (point))
6911 donep foundp)
6912 (while (and (< (point) lim)
6913 (not donep))
6914 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6915 (save-match-data
6916 (not (vhdl-in-literal)))
6917 (/= (match-beginning 0) here))
6918 (progn
6919 (goto-char (match-beginning 0))
6920 (cond
6921 ((and (looking-at "case")
6922 (re-search-forward "\\bis[^_]" lim t))
6923 (backward-sexp)
6924 (vhdl-forward-sexp))
6925 (t
6926 (setq donep t
6927 foundp t))))))
6928 (if (not foundp)
6929 (goto-char here))
6930 foundp))
6931
6932 (defun vhdl-backward-skip-label (&optional lim)
6933 "Skip backward over a label, with optional maximal
6934 limit. If label is not found, nil is returned and point
6935 is not moved."
6936 (let ((lim (or lim (point-min)))
6937 placeholder)
6938 (if (save-excursion
6939 (vhdl-backward-syntactic-ws lim)
6940 (and (eq (preceding-char) ?:)
6941 (progn
6942 (backward-sexp)
6943 (setq placeholder (point))
6944 (looking-at vhdl-label-key))))
6945 (goto-char placeholder))
6946 ))
6947
6948 (defun vhdl-forward-skip-label (&optional lim)
6949 "Skip forward over a label, with optional maximal
6950 limit. If label is not found, nil is returned and point
6951 is not moved."
6952 (let ((lim (or lim (point-max))))
6953 (if (looking-at vhdl-label-key)
6954 (progn
6955 (goto-char (match-end 0))
6956 (vhdl-forward-syntactic-ws lim)))
6957 ))
6958
6959 (defun vhdl-get-syntactic-context ()
6960 "Guess the syntactic description of the current line of VHDL code."
6961 (save-excursion
6962 (save-restriction
6963 (beginning-of-line)
6964 (let* ((indent-point (point))
6965 (case-fold-search t)
6966 vec literal containing-sexp preceding-sexp
6967 containing-begin containing-mid containing-leader
6968 char-before-ip char-after-ip begin-after-ip end-after-ip
6969 placeholder lim library-unit
6970 )
6971
6972 ;; Reset the syntactic context
6973 (setq vhdl-syntactic-context nil)
6974
6975 (save-excursion
6976 ;; Move to the start of the previous library unit, and
6977 ;; record the position of the "begin" keyword.
6978 (setq placeholder (vhdl-beginning-of-libunit))
6979 ;; The position of the "libunit" keyword gives us a gross
6980 ;; limit point.
6981 (setq lim (point))
6982 )
6983
6984 ;; If there is a previous library unit, and we are enclosed by
6985 ;; it, then set the syntax accordingly.
6986 (and placeholder
6987 (setq library-unit (vhdl-get-library-unit lim placeholder))
6988 (vhdl-add-syntax library-unit lim))
6989
6990 ;; Find the surrounding state.
6991 (if (setq vec (vhdl-get-block-state lim))
6992 (progn
6993 (setq containing-sexp (aref vec 0))
6994 (setq preceding-sexp (aref vec 1))
6995 (setq containing-begin (aref vec 2))
6996 (setq containing-mid (aref vec 3))
6997 ))
6998
6999 ;; set the limit on the farthest back we need to search
7000 (setq lim (if containing-sexp
7001 (save-excursion
7002 (goto-char containing-sexp)
7003 ;; set containing-leader if required
7004 (if (looking-at vhdl-leader-re)
7005 (setq containing-leader (vhdl-end-of-leader)))
7006 (vhdl-point 'bol))
7007 (point-min)))
7008
7009 ;; cache char before and after indent point, and move point to
7010 ;; the most likely position to perform the majority of tests
7011 (goto-char indent-point)
7012 (skip-chars-forward " \t")
7013 (setq literal (vhdl-in-literal))
7014 (setq char-after-ip (following-char))
7015 (setq begin-after-ip (and
7016 (not literal)
7017 (looking-at vhdl-begin-fwd-re)
7018 (or (not (looking-at "\\<use\\>"))
7019 (save-excursion
7020 (back-to-indentation)
7021 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
7022 (vhdl-begin-p)))
7023 (setq end-after-ip (and
7024 (not literal)
7025 (looking-at vhdl-end-fwd-re)
7026 (vhdl-end-p)))
7027 (vhdl-backward-syntactic-ws lim)
7028 (setq char-before-ip (preceding-char))
7029 (goto-char indent-point)
7030 (skip-chars-forward " \t")
7031
7032 ;; now figure out syntactic qualities of the current line
7033 (cond
7034 ;; CASE 1: in a string or comment.
7035 ((memq literal '(string comment))
7036 (vhdl-add-syntax literal (vhdl-point 'bopl)))
7037 ;; CASE 2: Line is at top level.
7038 ((null containing-sexp)
7039 ;; Find the point to which indentation will be relative
7040 (save-excursion
7041 (if (null preceding-sexp)
7042 ;; CASE 2X.1
7043 ;; no preceding-sexp -> use the preceding statement
7044 (vhdl-beginning-of-statement-1 lim)
7045 ;; CASE 2X.2
7046 ;; if there is a preceding-sexp then indent relative to it
7047 (goto-char preceding-sexp)
7048 ;; if not at boi, then the block-opening keyword is
7049 ;; probably following a label, so we need a different
7050 ;; relpos
7051 (if (/= (point) (vhdl-point 'boi))
7052 ;; CASE 2X.3
7053 (vhdl-beginning-of-statement-1 lim)))
7054 ;; v-b-o-s could have left us at point-min
7055 (and (bobp)
7056 ;; CASE 2X.4
7057 (vhdl-forward-syntactic-ws indent-point))
7058 (setq placeholder (point)))
7059 (cond
7060 ;; CASE 2A : we are looking at a block-open
7061 (begin-after-ip
7062 (vhdl-add-syntax 'block-open placeholder))
7063 ;; CASE 2B: we are looking at a block-close
7064 (end-after-ip
7065 (vhdl-add-syntax 'block-close placeholder))
7066 ;; CASE 2C: we are looking at a top-level statement
7067 ((progn
7068 (vhdl-backward-syntactic-ws lim)
7069 (or (bobp)
7070 (and (= (preceding-char) ?\;)
7071 (not (vhdl-in-quote-p)))))
7072 (vhdl-add-syntax 'statement placeholder))
7073 ;; CASE 2D: we are looking at a top-level statement-cont
7074 (t
7075 (vhdl-beginning-of-statement-1 lim)
7076 ;; v-b-o-s could have left us at point-min
7077 (and (bobp)
7078 ;; CASE 2D.1
7079 (vhdl-forward-syntactic-ws indent-point))
7080 (vhdl-add-syntax 'statement-cont (point)))
7081 )) ; end CASE 2
7082 ;; CASE 3: line is inside parentheses. Most likely we are
7083 ;; either in a subprogram argument (interface) list, or a
7084 ;; continued expression containing parentheses.
7085 ((null containing-begin)
7086 (vhdl-backward-syntactic-ws containing-sexp)
7087 (cond
7088 ;; CASE 3A: we are looking at the arglist closing paren
7089 ((eq char-after-ip ?\))
7090 (goto-char containing-sexp)
7091 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
7092 ;; CASE 3B: we are looking at the first argument in an empty
7093 ;; argument list.
7094 ((eq char-before-ip ?\()
7095 (goto-char containing-sexp)
7096 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
7097 ;; CASE 3C: we are looking at an arglist continuation line,
7098 ;; but the preceding argument is on the same line as the
7099 ;; opening paren. This case includes multi-line
7100 ;; expression paren groupings.
7101 ((and (save-excursion
7102 (goto-char (1+ containing-sexp))
7103 (skip-chars-forward " \t")
7104 (not (eolp))
7105 (not (looking-at "--\\|`")))
7106 (save-excursion
7107 (vhdl-beginning-of-statement-1 containing-sexp)
7108 (skip-chars-backward " \t(")
7109 (while (and (= (preceding-char) ?\;)
7110 (not (vhdl-in-quote-p)))
7111 (vhdl-beginning-of-statement-1 containing-sexp)
7112 (skip-chars-backward " \t("))
7113 (<= (point) containing-sexp)))
7114 (goto-char containing-sexp)
7115 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7116 ;; CASE 3D: we are looking at just a normal arglist
7117 ;; continuation line
7118 (t (vhdl-beginning-of-statement-1 containing-sexp)
7119 (vhdl-forward-syntactic-ws indent-point)
7120 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7121 ))
7122 ;; CASE 4: A block mid open
7123 ((and begin-after-ip
7124 (looking-at containing-mid))
7125 (goto-char containing-sexp)
7126 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7127 (if (looking-at vhdl-trailer-re)
7128 ;; CASE 4.1
7129 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7130 (vhdl-backward-skip-label (vhdl-point 'boi))
7131 (vhdl-add-syntax 'block-open (point)))
7132 ;; CASE 5: block close brace
7133 (end-after-ip
7134 (goto-char containing-sexp)
7135 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7136 (if (looking-at vhdl-trailer-re)
7137 ;; CASE 5.1
7138 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7139 (vhdl-backward-skip-label (vhdl-point 'boi))
7140 (vhdl-add-syntax 'block-close (point)))
7141 ;; CASE 6: A continued statement
7142 ((and (/= char-before-ip ?\;)
7143 ;; check it's not a trailer begin keyword, or a begin
7144 ;; keyword immediately following a label.
7145 (not (and begin-after-ip
7146 (or (looking-at vhdl-trailer-re)
7147 (save-excursion
7148 (vhdl-backward-skip-label containing-sexp)))))
7149 ;; check it's not a statement keyword
7150 (not (and (looking-at vhdl-statement-fwd-re)
7151 (vhdl-statement-p)))
7152 ;; see if the b-o-s is before the indent point
7153 (> indent-point
7154 (save-excursion
7155 (vhdl-beginning-of-statement-1 containing-sexp)
7156 ;; If we ended up after a leader, then this will
7157 ;; move us forward to the start of the first
7158 ;; statement. Note that a containing sexp here is
7159 ;; always a keyword, not a paren, so this will
7160 ;; have no effect if we hit the containing-sexp.
7161 (vhdl-forward-syntactic-ws indent-point)
7162 (setq placeholder (point))))
7163 ;; check it's not a block-intro
7164 (/= placeholder containing-sexp)
7165 ;; check it's not a case block-intro
7166 (save-excursion
7167 (goto-char placeholder)
7168 (or (not (looking-at vhdl-case-alternative-re))
7169 (> (match-end 0) indent-point))))
7170 ;; Make placeholder skip a label, but only if it puts us
7171 ;; before the indent point at the start of a line.
7172 (let ((new placeholder))
7173 (if (and (> indent-point
7174 (save-excursion
7175 (goto-char placeholder)
7176 (vhdl-forward-skip-label indent-point)
7177 (setq new (point))))
7178 (save-excursion
7179 (goto-char new)
7180 (eq new (progn (back-to-indentation) (point)))))
7181 (setq placeholder new)))
7182 (vhdl-add-syntax 'statement-cont placeholder)
7183 (if begin-after-ip
7184 (vhdl-add-syntax 'block-open)))
7185 ;; Statement. But what kind?
7186 ;; CASE 7: A case alternative key
7187 ((and (looking-at vhdl-case-alternative-re)
7188 (vhdl-case-alternative-p containing-sexp))
7189 ;; for a case alternative key, we set relpos to the first
7190 ;; non-whitespace char on the line containing the "case"
7191 ;; keyword.
7192 (goto-char containing-sexp)
7193 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7194 (if (looking-at vhdl-trailer-re)
7195 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7196 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7197 ;; CASE 8: statement catchall
7198 (t
7199 ;; we know its a statement, but we need to find out if it is
7200 ;; the first statement in a block
7201 (if containing-leader
7202 (goto-char containing-leader)
7203 (goto-char containing-sexp)
7204 ;; Note that a containing sexp here is always a keyword,
7205 ;; not a paren, so skip over the keyword.
7206 (forward-sexp))
7207 ;; move to the start of the first statement
7208 (vhdl-forward-syntactic-ws indent-point)
7209 (setq placeholder (point))
7210 ;; we want to ignore case alternatives keys when skipping forward
7211 (let (incase-p)
7212 (while (looking-at vhdl-case-alternative-re)
7213 (setq incase-p (point))
7214 ;; we also want to skip over the body of the
7215 ;; case/when statement if that doesn't put us at
7216 ;; after the indent-point
7217 (while (vhdl-skip-case-alternative indent-point))
7218 ;; set up the match end
7219 (looking-at vhdl-case-alternative-re)
7220 (goto-char (match-end 0))
7221 ;; move to the start of the first case alternative statement
7222 (vhdl-forward-syntactic-ws indent-point)
7223 (setq placeholder (point)))
7224 (cond
7225 ;; CASE 8A: we saw a case/when statement so we must be
7226 ;; in a switch statement. find out if we are at the
7227 ;; statement just after a case alternative key
7228 ((and incase-p
7229 (= (point) indent-point))
7230 ;; relpos is the "when" keyword
7231 (vhdl-add-syntax 'statement-case-intro incase-p))
7232 ;; CASE 8B: any old statement
7233 ((< (point) indent-point)
7234 ;; relpos is the first statement of the block
7235 (vhdl-add-syntax 'statement placeholder)
7236 (if begin-after-ip
7237 (vhdl-add-syntax 'block-open)))
7238 ;; CASE 8C: first statement in a block
7239 (t
7240 (goto-char containing-sexp)
7241 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7242 (if (looking-at vhdl-trailer-re)
7243 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7244 (vhdl-backward-skip-label (vhdl-point 'boi))
7245 (vhdl-add-syntax 'statement-block-intro (point))
7246 (if begin-after-ip
7247 (vhdl-add-syntax 'block-open)))
7248 )))
7249 )
7250
7251 ;; now we need to look at any modifiers
7252 (goto-char indent-point)
7253 (skip-chars-forward " \t")
7254 (if (or (looking-at "--") (looking-at "/\\*"))
7255 (vhdl-add-syntax 'comment))
7256 (if (looking-at "`")
7257 (vhdl-add-syntax 'directive))
7258 (if (eq literal 'pound)
7259 (vhdl-add-syntax 'cpp-macro))
7260 ;; return the syntax
7261 vhdl-syntactic-context))))
7262
7263 ;; Standard indentation line-ups:
7264
7265 (defun vhdl-lineup-arglist (langelem)
7266 "Lineup the current arglist line with the arglist appearing just
7267 after the containing paren which starts the arglist."
7268 (save-excursion
7269 (let* ((containing-sexp
7270 (save-excursion
7271 ;; arglist-cont-nonempty gives relpos ==
7272 ;; to boi of containing-sexp paren. This
7273 ;; is good when offset is +, but bad
7274 ;; when it is vhdl-lineup-arglist, so we
7275 ;; have to special case a kludge here.
7276 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7277 (progn
7278 (beginning-of-line)
7279 (backward-up-list 1)
7280 (skip-chars-forward " \t" (vhdl-point 'eol)))
7281 (goto-char (cdr langelem)))
7282 (point)))
7283 (cs-curcol (save-excursion
7284 (goto-char (cdr langelem))
7285 (current-column))))
7286 (if (save-excursion
7287 (beginning-of-line)
7288 (looking-at "[ \t]*)"))
7289 (progn (goto-char (match-end 0))
7290 (backward-sexp)
7291 (forward-char)
7292 (vhdl-forward-syntactic-ws)
7293 (- (current-column) cs-curcol))
7294 (goto-char containing-sexp)
7295 (or (eolp)
7296 (let ((eol (vhdl-point 'eol))
7297 (here (progn
7298 (forward-char)
7299 (skip-chars-forward " \t")
7300 (point))))
7301 (vhdl-forward-syntactic-ws)
7302 (if (< (point) eol)
7303 (goto-char here))))
7304 (- (current-column) cs-curcol)
7305 ))))
7306
7307 (defun vhdl-lineup-arglist-intro (langelem)
7308 "Lineup an arglist-intro line to just after the open paren."
7309 (save-excursion
7310 (let ((cs-curcol (save-excursion
7311 (goto-char (cdr langelem))
7312 (current-column)))
7313 (ce-curcol (save-excursion
7314 (beginning-of-line)
7315 (backward-up-list 1)
7316 (skip-chars-forward " \t" (vhdl-point 'eol))
7317 (current-column))))
7318 (- ce-curcol cs-curcol -1))))
7319
7320 (defun vhdl-lineup-comment (langelem)
7321 "Support old behavior for comment indentation. We look at
7322 vhdl-comment-only-line-offset to decide how to indent comment
7323 only-lines."
7324 (save-excursion
7325 (back-to-indentation)
7326 ;; at or to the right of comment-column
7327 (if (>= (current-column) comment-column)
7328 (vhdl-comment-indent)
7329 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7330 (if (not (bolp))
7331 ;; inside multi-line comment
7332 (if (looking-at "\\*")
7333 1
7334 ;; otherwise
7335 (or (car-safe vhdl-comment-only-line-offset)
7336 vhdl-comment-only-line-offset))
7337 (or (cdr-safe vhdl-comment-only-line-offset)
7338 (car-safe vhdl-comment-only-line-offset)
7339 -1000 ;jam it against the left side
7340 )))))
7341
7342 (defun vhdl-lineup-statement-cont (langelem)
7343 "Line up statement-cont after the assignment operator."
7344 (save-excursion
7345 (let* ((relpos (cdr langelem))
7346 (assignp (save-excursion
7347 (goto-char (vhdl-point 'boi))
7348 (and (re-search-forward "\\(<\\|:\\|=\\)="
7349 (vhdl-point 'eol) t)
7350 (- (point) (vhdl-point 'boi)))))
7351 (curcol (progn
7352 (goto-char relpos)
7353 (current-column)))
7354 foundp)
7355 (while (and (not foundp)
7356 (< (point) (vhdl-point 'eol)))
7357 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7358 (if (vhdl-in-literal)
7359 (forward-char)
7360 (if (= (preceding-char) ?\()
7361 ;; skip over any parenthesized expressions
7362 (goto-char (min (vhdl-point 'eol)
7363 (scan-lists (point) 1 1)))
7364 ;; found an assignment operator (not at eol)
7365 (setq foundp (not (looking-at "\\s-*$"))))))
7366 (if (not foundp)
7367 ;; there's no assignment operator on the line
7368 vhdl-basic-offset
7369 ;; calculate indentation column after assign and ws, unless
7370 ;; our line contains an assignment operator
7371 (if (not assignp)
7372 (progn
7373 (forward-char)
7374 (skip-chars-forward " \t")
7375 (setq assignp 0)))
7376 (- (current-column) assignp curcol))
7377 )))
7378
7379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7380 ;; Progress reporting
7381
7382 (defvar vhdl-progress-info nil
7383 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7384
7385 (defun vhdl-update-progress-info (string pos)
7386 "Update progress information."
7387 (when (and vhdl-progress-info (not noninteractive)
7388 (< vhdl-progress-interval
7389 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7390 (let ((delta (- (aref vhdl-progress-info 1)
7391 (aref vhdl-progress-info 0))))
7392 (message "%s... (%2d%%)" string
7393 (if (= 0 delta)
7394 100
7395 (floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
7396 delta))))
7397 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7398
7399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7400 ;; Indentation commands
7401
7402 (defun vhdl-electric-tab (&optional prefix-arg)
7403 "If preceding character is part of a word or a paren then hippie-expand,
7404 else if right of non whitespace on line then insert tab,
7405 else if last command was a tab or return then dedent one step or if a comment
7406 toggle between normal indent and inline comment indent,
7407 else indent `correctly'."
7408 (interactive "*P")
7409 (vhdl-prepare-search-2
7410 (cond
7411 ;; indent region if region is active
7412 ((and (not (featurep 'xemacs)) (use-region-p))
7413 (vhdl-indent-region (region-beginning) (region-end) nil))
7414 ;; expand word
7415 ((= (char-syntax (preceding-char)) ?w)
7416 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7417 (case-replace nil)
7418 (hippie-expand-only-buffers
7419 (or (and (boundp 'hippie-expand-only-buffers)
7420 hippie-expand-only-buffers)
7421 '(vhdl-mode))))
7422 (vhdl-expand-abbrev prefix-arg)))
7423 ;; expand parenthesis
7424 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7425 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7426 (case-replace nil))
7427 (vhdl-expand-paren prefix-arg)))
7428 ;; insert tab
7429 ((> (current-column) (current-indentation))
7430 (insert-tab))
7431 ;; toggle comment indent
7432 ((and (looking-at "--")
7433 (or (eq last-command 'vhdl-electric-tab)
7434 (eq last-command 'vhdl-electric-return)))
7435 (cond ((= (current-indentation) 0) ; no indent
7436 (indent-to 1)
7437 (indent-according-to-mode))
7438 ((< (current-indentation) comment-column) ; normal indent
7439 (indent-to comment-column)
7440 (indent-according-to-mode))
7441 (t ; inline comment indent
7442 (delete-region (line-beginning-position) (point)))))
7443 ;; dedent
7444 ((and (>= (current-indentation) vhdl-basic-offset)
7445 (or (eq last-command 'vhdl-electric-tab)
7446 (eq last-command 'vhdl-electric-return)))
7447 (backward-delete-char-untabify vhdl-basic-offset nil))
7448 ;; indent line
7449 (t (indent-according-to-mode)))
7450 (setq this-command 'vhdl-electric-tab)))
7451
7452 (defun vhdl-electric-return ()
7453 "newline-and-indent or indent-new-comment-line if in comment and preceding
7454 character is a space."
7455 (interactive)
7456 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7457 (indent-new-comment-line)
7458 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7459 (not (vhdl-in-comment-p)))
7460 (vhdl-fix-case-word -1))
7461 (newline-and-indent)))
7462
7463 (defun vhdl-indent-line ()
7464 "Indent the current line as VHDL code. Returns the amount of
7465 indentation change."
7466 (interactive)
7467 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7468 (pos (- (point-max) (point)))
7469 (is-comment nil)
7470 (indent
7471 (if syntax
7472 ;; indent syntax-based
7473 (if (and (eq (caar syntax) 'comment)
7474 (>= (vhdl-get-offset (car syntax)) comment-column))
7475 ;; special case: comments at or right of comment-column
7476 (vhdl-get-offset (car syntax))
7477 ;; align comments like following code line
7478 (when vhdl-indent-comment-like-next-code-line
7479 (save-excursion
7480 (while (eq (caar syntax) 'comment)
7481 (setq is-comment t)
7482 (beginning-of-line 2)
7483 (setq syntax (vhdl-get-syntactic-context)))))
7484 (when is-comment
7485 (push (cons 'comment nil) syntax))
7486 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7487 ;; indent like previous nonblank line
7488 (save-excursion (beginning-of-line)
7489 (re-search-backward "^[^\n]" nil t)
7490 (current-indentation))))
7491 (shift-amt (- indent (current-indentation))))
7492 (and vhdl-echo-syntactic-information-p
7493 (message "syntax: %s, indent= %d" syntax indent))
7494 (let ((has-formfeed
7495 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7496 (when (or (not (zerop shift-amt)) has-formfeed)
7497 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7498 (beginning-of-line)
7499 (when has-formfeed (insert "\f"))
7500 (indent-to indent)))
7501 (if (< (point) (vhdl-point 'boi))
7502 (back-to-indentation)
7503 ;; If initial point was within line's indentation, position after
7504 ;; the indentation. Else stay at same point in text.
7505 (when (> (- (point-max) pos) (point))
7506 (goto-char (- (point-max) pos))))
7507 (run-hooks 'vhdl-special-indent-hook)
7508 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7509 shift-amt))
7510
7511 (defun vhdl-indent-region (beg end &optional column)
7512 "Indent region as VHDL code.
7513 Adds progress reporting to `indent-region'."
7514 (interactive "r\nP")
7515 (when vhdl-progress-interval
7516 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7517 (count-lines (point-min) end) 0)))
7518 (indent-region beg end column)
7519 (when vhdl-progress-interval (message "Indenting...done"))
7520 (setq vhdl-progress-info nil))
7521
7522 (defun vhdl-indent-buffer ()
7523 "Indent whole buffer as VHDL code.
7524 Calls `indent-region' for whole buffer and adds progress reporting."
7525 (interactive)
7526 (vhdl-indent-region (point-min) (point-max)))
7527
7528 (defun vhdl-indent-group ()
7529 "Indent group of lines between empty lines."
7530 (interactive)
7531 (let ((beg (save-excursion
7532 (if (re-search-backward vhdl-align-group-separate nil t)
7533 (point-marker)
7534 (point-min-marker))))
7535 (end (save-excursion
7536 (if (re-search-forward vhdl-align-group-separate nil t)
7537 (point-marker)
7538 (point-max-marker)))))
7539 (vhdl-indent-region beg end)))
7540
7541 (defun vhdl-indent-sexp (&optional endpos)
7542 "Indent each line of the list starting just after point.
7543 If optional arg ENDPOS is given, indent each line, stopping when
7544 ENDPOS is encountered."
7545 (interactive)
7546 (save-excursion
7547 (let ((beg (point))
7548 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7549 (indent-region beg end nil))))
7550
7551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7552 ;; Miscellaneous commands
7553
7554 (defun vhdl-show-syntactic-information ()
7555 "Show syntactic information for current line."
7556 (interactive)
7557 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7558 (vhdl-keep-region-active))
7559
7560 ;; Verification and regression functions:
7561
7562 (defun vhdl-regress-line (&optional arg)
7563 "Check syntactic information for current line."
7564 (interactive "P")
7565 (let ((expected (save-excursion
7566 (end-of-line)
7567 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7568 (forward-char 4)
7569 (read (current-buffer)))))
7570 (actual (vhdl-get-syntactic-context))
7571 (expurgated))
7572 ;; remove the library unit symbols
7573 (mapc
7574 (function
7575 (lambda (elt)
7576 (if (memq (car elt) '(entity configuration context package
7577 package-body architecture))
7578 nil
7579 (setq expurgated (append expurgated (list elt))))))
7580 actual)
7581 (if (and (not arg) expected (listp expected))
7582 (if (not (equal expected expurgated))
7583 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7584 (save-excursion
7585 (beginning-of-line)
7586 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7587 (end-of-line)
7588 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7589 (delete-region (point) (line-end-position)))
7590 (insert " -- ")
7591 (insert (format "%s" expurgated))))))
7592 (vhdl-keep-region-active))
7593
7594
7595 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7596 ;;; Alignment, beautifying
7597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7598
7599 (defconst vhdl-align-alist
7600 '(
7601 ;; after some keywords
7602 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7603 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7604 ;; before ':'
7605 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7606 ;; after direction specifications
7607 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7608 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7609 ;; before "==", ":=", "=>", and "<="
7610 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7611 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7612 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7613 ;; before some keywords
7614 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7615 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7616 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7617 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7618 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7619 ;; before "=>" since "when/else ... =>" can occur
7620 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7621 )
7622 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7623 It is searched in order. If REGEXP is found anywhere in the first
7624 line of a region to be aligned, ALIGN-PATTERN will be used for that
7625 region. ALIGN-PATTERN must include the whitespace to be expanded or
7626 contracted. It may also provide regexps for the text surrounding the
7627 whitespace. SUBEXP specifies which sub-expression of
7628 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7629
7630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7631 ;; Align code
7632
7633 (defvar vhdl-align-try-all-clauses t
7634 "If REGEXP is not found on the first line of the region that clause
7635 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7636
7637 (defun vhdl-do-group (function &optional spacing)
7638 "Apply FUNCTION on group of lines between empty lines."
7639 (let
7640 ;; search for group beginning
7641 ((beg (save-excursion
7642 (if (re-search-backward vhdl-align-group-separate nil t)
7643 (progn (beginning-of-line 2) (back-to-indentation) (point))
7644 (point-min))))
7645 ;; search for group end
7646 (end (save-excursion
7647 (if (re-search-forward vhdl-align-group-separate nil t)
7648 (progn (beginning-of-line) (point))
7649 (point-max)))))
7650 ;; run FUNCTION
7651 (funcall function beg end spacing)))
7652
7653 (defun vhdl-do-list (function &optional spacing)
7654 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7655 parentheses."
7656 (let (beg end)
7657 (save-excursion
7658 ;; search for beginning of balanced group of parentheses
7659 (setq beg (vhdl-re-search-backward "[()]" nil t))
7660 (while (looking-at ")")
7661 (forward-char) (backward-sexp)
7662 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7663 ;; search for end of balanced group of parentheses
7664 (when beg
7665 (forward-list)
7666 (setq end (point))
7667 (goto-char (1+ beg))
7668 (skip-chars-forward " \t\n\r\f")
7669 (setq beg (point))))
7670 ;; run FUNCTION
7671 (if beg
7672 (funcall function beg end spacing)
7673 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7674
7675 (defun vhdl-do-same-indent (function &optional spacing)
7676 "Apply FUNCTION to block of lines with same indent."
7677 (let ((indent (current-indentation))
7678 beg end)
7679 ;; search for first line with same indent
7680 (save-excursion
7681 (while (and (not (bobp))
7682 (or (looking-at "^\\s-*\\(--.*\\)?$")
7683 (= (current-indentation) indent)))
7684 (unless (looking-at "^\\s-*$")
7685 (back-to-indentation) (setq beg (point)))
7686 (beginning-of-line -0)))
7687 ;; search for last line with same indent
7688 (save-excursion
7689 (while (and (not (eobp))
7690 (or (looking-at "^\\s-*\\(--.*\\)?$")
7691 (= (current-indentation) indent)))
7692 (if (looking-at "^\\s-*$")
7693 (beginning-of-line 2)
7694 (beginning-of-line 2)
7695 (setq end (point)))))
7696 ;; run FUNCTION
7697 (funcall function beg end spacing)))
7698
7699 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7700 "Attempt to align a range of lines based on the content of the
7701 lines. The definition of `alignment-list' determines the matching
7702 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7703 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7704 indentation is done before aligning."
7705 (interactive "r\np")
7706 (setq alignment-list (or alignment-list vhdl-align-alist))
7707 (setq spacing (or spacing 1))
7708 (save-excursion
7709 (let (bol indent)
7710 (goto-char end)
7711 (setq end (point-marker))
7712 (goto-char begin)
7713 (setq bol (setq begin (progn (beginning-of-line) (point))))
7714 (when indent
7715 (indent-region bol end nil))))
7716 (let ((copy (copy-alist alignment-list)))
7717 (vhdl-prepare-search-2
7718 (while copy
7719 (save-excursion
7720 (goto-char begin)
7721 (let (element
7722 (eol (point-at-eol)))
7723 (setq element (nth 0 copy))
7724 (when (and (or (and (listp (car element))
7725 (memq major-mode (car element)))
7726 (eq major-mode (car element)))
7727 (or vhdl-align-try-all-clauses
7728 (re-search-forward (car (cdr element)) eol t)))
7729 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7730 (car (cdr (cdr (cdr element)))) spacing))
7731 (setq copy (cdr copy))))))))
7732
7733 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7734 "Align a range of lines from BEGIN to END. The regular expression
7735 MATCH must match exactly one field: the whitespace to be
7736 contracted/expanded. The alignment column will equal the
7737 rightmost column of the widest whitespace block. SPACING is
7738 the amount of extra spaces to add to the calculated maximum required.
7739 SPACING defaults to 1 so that at least one space is inserted after
7740 the token in MATCH."
7741 (setq spacing (or spacing 1))
7742 (setq substr (or substr 1))
7743 (save-excursion
7744 (let (distance (max 0) (lines 0) bol eol width)
7745 ;; Determine the greatest whitespace distance to the alignment
7746 ;; character
7747 (goto-char begin)
7748 (setq eol (point-at-eol)
7749 bol (setq begin (progn (beginning-of-line) (point))))
7750 (while (< bol end)
7751 (save-excursion
7752 (when (and (vhdl-re-search-forward match eol t)
7753 (save-excursion
7754 (goto-char (match-beginning 0))
7755 (forward-char)
7756 (and (not (vhdl-in-literal))
7757 (not (vhdl-in-quote-p))
7758 (not (vhdl-in-extended-identifier-p))))
7759 (not (looking-at "\\s-*$")))
7760 (setq distance (- (match-beginning substr) bol))
7761 (when (> distance max)
7762 (setq max distance))))
7763 (forward-line)
7764 (setq bol (point)
7765 eol (point-at-eol))
7766 (setq lines (1+ lines)))
7767 ;; Now insert enough maxs to push each assignment operator to
7768 ;; the same column. We need to use 'lines' as a counter, since
7769 ;; the location of the mark may change
7770 (goto-char (setq bol begin))
7771 (setq eol (point-at-eol))
7772 (while (> lines 0)
7773 (when (and (vhdl-re-search-forward match eol t)
7774 (save-excursion
7775 (goto-char (match-beginning 0))
7776 (forward-char)
7777 (and (not (vhdl-in-literal))
7778 (not (vhdl-in-quote-p))
7779 (not (vhdl-in-extended-identifier-p))))
7780 (not (looking-at "\\s-*$"))
7781 (> (match-beginning 0) ; not if at boi
7782 (save-excursion (back-to-indentation) (point))))
7783 (setq width (- (match-end substr) (match-beginning substr)))
7784 (setq distance (- (match-beginning substr) bol))
7785 (goto-char (match-beginning substr))
7786 (delete-char width)
7787 (insert-char ? (+ (- max distance) spacing)))
7788 (beginning-of-line)
7789 (forward-line)
7790 (setq bol (point)
7791 eol (point-at-eol))
7792 (setq lines (1- lines))))))
7793
7794 (defun vhdl-align-region-groups (beg end &optional spacing
7795 no-message no-comments)
7796 "Align region, treat groups of lines separately."
7797 (interactive "r\nP")
7798 (save-excursion
7799 (let (orig pos)
7800 (goto-char beg)
7801 (beginning-of-line)
7802 (setq orig (point-marker))
7803 (setq beg (point))
7804 (goto-char end)
7805 (setq end (point-marker))
7806 (untabify beg end)
7807 (unless no-message
7808 (when vhdl-progress-interval
7809 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7810 (count-lines (point-min) end) 0))))
7811 (when (nth 0 vhdl-beautify-options)
7812 (vhdl-fixup-whitespace-region beg end t))
7813 (goto-char beg)
7814 (if (not vhdl-align-groups)
7815 ;; align entire region
7816 (progn (vhdl-align-region-1 beg end spacing)
7817 (unless no-comments
7818 (vhdl-align-inline-comment-region-1 beg end)))
7819 ;; align groups
7820 (while (and (< beg end)
7821 (re-search-forward vhdl-align-group-separate end t))
7822 (setq pos (point-marker))
7823 (vhdl-align-region-1 beg pos spacing)
7824 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7825 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7826 (setq beg (1+ pos))
7827 (goto-char beg))
7828 ;; align last group
7829 (when (< beg end)
7830 (vhdl-align-region-1 beg end spacing)
7831 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7832 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7833 (when vhdl-indent-tabs-mode
7834 (tabify orig end))
7835 (unless no-message
7836 (when vhdl-progress-interval (message "Aligning...done"))
7837 (setq vhdl-progress-info nil)))))
7838
7839 (defun vhdl-align-region (beg end &optional spacing)
7840 "Align region, treat blocks with same indent and argument lists separately."
7841 (interactive "r\nP")
7842 (if (not vhdl-align-same-indent)
7843 ;; align entire region
7844 (vhdl-align-region-groups beg end spacing)
7845 ;; align blocks with same indent and argument lists
7846 (save-excursion
7847 (let ((cur-beg beg)
7848 indent cur-end)
7849 (when vhdl-progress-interval
7850 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7851 (count-lines (point-min) end) 0)))
7852 (goto-char end)
7853 (setq end (point-marker))
7854 (goto-char cur-beg)
7855 (while (< (point) end)
7856 ;; is argument list opening?
7857 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7858 (point) (vhdl-point 'eol)))))
7859 ;; determine region for argument list
7860 (progn (goto-char cur-beg)
7861 (forward-sexp)
7862 (setq cur-end (point))
7863 (beginning-of-line 2))
7864 ;; determine region with same indent
7865 (setq indent (current-indentation))
7866 (setq cur-beg (point))
7867 (setq cur-end (vhdl-point 'bonl))
7868 (beginning-of-line 2)
7869 (while (and (< (point) end)
7870 (or (looking-at "^\\s-*\\(--.*\\)?$")
7871 (= (current-indentation) indent))
7872 (<= (save-excursion
7873 (nth 0 (parse-partial-sexp
7874 (point) (vhdl-point 'eol)))) 0))
7875 (unless (looking-at "^\\s-*$")
7876 (setq cur-end (vhdl-point 'bonl)))
7877 (beginning-of-line 2)))
7878 ;; align region
7879 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7880 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7881 (when vhdl-progress-interval (message "Aligning...done"))
7882 (setq vhdl-progress-info nil)))))
7883
7884 (defun vhdl-align-group (&optional spacing)
7885 "Align group of lines between empty lines."
7886 (interactive)
7887 (vhdl-do-group 'vhdl-align-region spacing))
7888
7889 (defun vhdl-align-list (&optional spacing)
7890 "Align the lines of a list surrounded by a balanced group of parentheses."
7891 (interactive)
7892 (vhdl-do-list 'vhdl-align-region-groups spacing))
7893
7894 (defun vhdl-align-same-indent (&optional spacing)
7895 "Align block of lines with same indent."
7896 (interactive)
7897 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7898
7899 (defun vhdl-align-declarations (&optional spacing)
7900 "Align the lines within the declarative part of a design unit."
7901 (interactive)
7902 (let (beg end)
7903 (vhdl-prepare-search-2
7904 (save-excursion
7905 ;; search for declarative part
7906 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
7907 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7908 (setq beg (point))
7909 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7910 (setq end (point)))))
7911 (if beg
7912 (vhdl-align-region-groups beg end spacing)
7913 (error "ERROR: Not within the declarative part of a design unit"))))
7914
7915 (defun vhdl-align-buffer ()
7916 "Align buffer."
7917 (interactive)
7918 (vhdl-align-region (point-min) (point-max)))
7919
7920 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7921 ;; Align inline comments
7922
7923 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7924 "Align inline comments in region."
7925 (save-excursion
7926 (let ((start-max comment-column)
7927 (length-max 0)
7928 comment-list start-list tmp-list start length
7929 cur-start prev-start no-code)
7930 (setq spacing (or spacing 2))
7931 (vhdl-prepare-search-2
7932 (goto-char beg)
7933 ;; search for comment start positions and lengths
7934 (while (< (point) end)
7935 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7936 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7937 (not (save-excursion (goto-char (match-beginning 2))
7938 (vhdl-in-literal))))
7939 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7940 (setq length (- (match-end 2) (match-beginning 2)))
7941 (setq start-max (max start start-max))
7942 (setq length-max (max length length-max))
7943 (push (cons start length) comment-list))
7944 (beginning-of-line 2))
7945 (setq comment-list
7946 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7947 ;; reduce start positions
7948 (setq start-list (list (caar comment-list)))
7949 (setq comment-list (cdr comment-list))
7950 (while comment-list
7951 (unless (or (= (caar comment-list) (car start-list))
7952 (<= (+ (car start-list) (cdar comment-list))
7953 end-comment-column))
7954 (push (caar comment-list) start-list))
7955 (setq comment-list (cdr comment-list)))
7956 ;; align lines as nicely as possible
7957 (goto-char beg)
7958 (while (< (point) end)
7959 (setq cur-start nil)
7960 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7961 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7962 (not (save-excursion
7963 (goto-char (match-beginning 3))
7964 (vhdl-in-literal))))
7965 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7966 (>= (- (match-end 2) (match-beginning 2))
7967 comment-column))))
7968 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7969 (setq length (- (match-end 3) (match-beginning 3)))
7970 (setq no-code (= (match-beginning 1) (match-end 1)))
7971 ;; insert minimum whitespace
7972 (goto-char (match-end 2))
7973 (delete-region (match-beginning 2) (match-end 2))
7974 (insert-char ?\ spacing)
7975 (setq tmp-list start-list)
7976 ;; insert additional whitespace to align
7977 (setq cur-start
7978 (cond
7979 ;; align comment-only line to inline comment of previous line
7980 ((and no-code prev-start
7981 (<= length (- end-comment-column prev-start)))
7982 prev-start)
7983 ;; align all comments at `start-max' if this is possible
7984 ((<= (+ start-max length-max) end-comment-column)
7985 start-max)
7986 ;; align at `comment-column' if possible
7987 ((and (<= start comment-column)
7988 (<= length (- end-comment-column comment-column)))
7989 comment-column)
7990 ;; align at left-most possible start position otherwise
7991 (t
7992 (while (and tmp-list (< (car tmp-list) start))
7993 (setq tmp-list (cdr tmp-list)))
7994 (car tmp-list))))
7995 (indent-to cur-start))
7996 (setq prev-start cur-start)
7997 (beginning-of-line 2))))))
7998
7999 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
8000 "Align inline comments within a region. Groups of code lines separated by
8001 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8002 (interactive "r\nP")
8003 (save-excursion
8004 (let (orig pos)
8005 (goto-char beg)
8006 (beginning-of-line)
8007 (setq orig (point-marker))
8008 (setq beg (point))
8009 (goto-char end)
8010 (setq end (point-marker))
8011 (untabify beg end)
8012 (unless no-message (message "Aligning inline comments..."))
8013 (goto-char beg)
8014 (if (not vhdl-align-groups)
8015 ;; align entire region
8016 (vhdl-align-inline-comment-region-1 beg end spacing)
8017 ;; align groups
8018 (while (and (< beg end)
8019 (re-search-forward vhdl-align-group-separate end t))
8020 (setq pos (point-marker))
8021 (vhdl-align-inline-comment-region-1 beg pos spacing)
8022 (setq beg (1+ pos))
8023 (goto-char beg))
8024 ;; align last group
8025 (when (< beg end)
8026 (vhdl-align-inline-comment-region-1 beg end spacing)))
8027 (when vhdl-indent-tabs-mode
8028 (tabify orig end))
8029 (unless no-message (message "Aligning inline comments...done")))))
8030
8031 (defun vhdl-align-inline-comment-group (&optional spacing)
8032 "Align inline comments within a group of lines between empty lines."
8033 (interactive)
8034 (save-excursion
8035 (let ((start (point))
8036 beg end)
8037 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
8038 (point-marker) (point-max)))
8039 (goto-char start)
8040 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
8041 (point) (point-min)))
8042 (untabify beg end)
8043 (message "Aligning inline comments...")
8044 (vhdl-align-inline-comment-region-1 beg end)
8045 (when vhdl-indent-tabs-mode
8046 (tabify beg end))
8047 (message "Aligning inline comments...done"))))
8048
8049 (defun vhdl-align-inline-comment-buffer ()
8050 "Align inline comments within buffer. Groups of code lines separated by
8051 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8052 (interactive)
8053 (vhdl-align-inline-comment-region (point-min) (point-max)))
8054
8055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8056 ;; Fixup whitespace
8057
8058 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
8059 "Fixup whitespace in region. Surround operator symbols by one space,
8060 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8061 end of line, do nothing in comments and strings."
8062 (interactive "r")
8063 (unless no-message (message "Fixing up whitespace..."))
8064 (save-excursion
8065 (goto-char end)
8066 (setq end (point-marker))
8067 ;; have no space before and one space after `,' and ';'
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 "\\3 " nil nil nil 2)))
8073 ;; have no space after `('
8074 (goto-char beg)
8075 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
8076 (if (match-string 1)
8077 (goto-char (match-end 1))
8078 (replace-match "\\2")))
8079 ;; have no space before `)'
8080 (goto-char beg)
8081 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
8082 (if (match-string 1)
8083 (goto-char (match-end 1))
8084 (replace-match "\\2")))
8085 ;; surround operator symbols by one space
8086 (goto-char beg)
8087 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
8088 (if (or (match-string 1)
8089 (<= (match-beginning 0) ; not if at boi
8090 (save-excursion (back-to-indentation) (point))))
8091 (goto-char (match-end 0))
8092 (replace-match "\\3 \\4 \\5")
8093 (goto-char (match-end 2))))
8094 ;; eliminate multiple spaces and spaces at end of line
8095 (goto-char beg)
8096 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
8097 (and (looking-at "--.*") (re-search-forward "--.*" end t))
8098 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
8099 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
8100 (progn (replace-match "" nil nil) t))
8101 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
8102 (progn (replace-match ";" nil nil) t))
8103 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
8104 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
8105 (progn (replace-match " " nil nil) t))
8106 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
8107 (progn (replace-match " " nil nil) t))
8108 (and (looking-at "-") (re-search-forward "-" end t))
8109 (re-search-forward "[^ \t\"-]+" end t))))
8110 (unless no-message (message "Fixing up whitespace...done")))
8111
8112 (defun vhdl-fixup-whitespace-buffer ()
8113 "Fixup whitespace in buffer. Surround operator symbols by one space,
8114 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8115 end of line, do nothing in comments."
8116 (interactive)
8117 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8118
8119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8120 ;; Case fixing
8121
8122 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8123 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8124 depending on parameter UPPER-CASE."
8125 (let ((case-replace nil)
8126 (last-update 0))
8127 (vhdl-prepare-search-2
8128 (save-excursion
8129 (goto-char end)
8130 (setq end (point-marker))
8131 (goto-char beg)
8132 (while (re-search-forward word-regexp end t)
8133 (or (vhdl-in-literal)
8134 (if upper-case
8135 (upcase-word -1)
8136 (downcase-word -1)))
8137 (when (and count vhdl-progress-interval (not noninteractive)
8138 (< vhdl-progress-interval
8139 (- (nth 1 (current-time)) last-update)))
8140 (message "Fixing case... (%2d%s)"
8141 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8142 "%")
8143 (setq last-update (nth 1 (current-time)))))
8144 (goto-char end)))))
8145
8146 (defun vhdl-fix-case-region (beg end &optional arg)
8147 "Convert all VHDL words in region to lower or upper case, depending on
8148 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8149 (interactive "r\nP")
8150 (vhdl-fix-case-region-1
8151 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8152 (vhdl-fix-case-region-1
8153 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8154 (vhdl-fix-case-region-1
8155 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8156 (vhdl-fix-case-region-1
8157 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8158 (vhdl-fix-case-region-1
8159 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8160 (when vhdl-progress-interval (message "Fixing case...done")))
8161
8162 (defun vhdl-fix-case-buffer ()
8163 "Convert all VHDL words in buffer to lower or upper case, depending on
8164 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8165 (interactive)
8166 (vhdl-fix-case-region (point-min) (point-max)))
8167
8168 (defun vhdl-fix-case-word (&optional arg)
8169 "Convert word after cursor to upper case if necessary."
8170 (interactive "p")
8171 (save-excursion
8172 (when arg (backward-word 1))
8173 (vhdl-prepare-search-1
8174 (when (and vhdl-upper-case-keywords
8175 (looking-at vhdl-keywords-regexp))
8176 (upcase-word 1))
8177 (when (and vhdl-upper-case-types
8178 (looking-at vhdl-types-regexp))
8179 (upcase-word 1))
8180 (when (and vhdl-upper-case-attributes
8181 (looking-at vhdl-attributes-regexp))
8182 (upcase-word 1))
8183 (when (and vhdl-upper-case-enum-values
8184 (looking-at vhdl-enum-values-regexp))
8185 (upcase-word 1))
8186 (when (and vhdl-upper-case-constants
8187 (looking-at vhdl-constants-regexp))
8188 (upcase-word 1)))))
8189
8190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8191 ;; Fix statements
8192 ;; - force each statement to be on a separate line except when on same line
8193 ;; with 'end' keyword
8194
8195 (defun vhdl-fix-statement-region (beg end &optional arg)
8196 "Force statements in region on separate line except when on same line
8197 with `end' keyword (necessary for correct indentation).
8198 Currently supported keywords: `begin', `if'."
8199 (interactive "r\nP")
8200 (vhdl-prepare-search-2
8201 (let (point)
8202 (save-excursion
8203 (goto-char end)
8204 (setq end (point-marker))
8205 (goto-char beg)
8206 ;; `begin' keyword
8207 (while (re-search-forward
8208 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8209 (goto-char (match-end 0))
8210 (setq point (point-marker))
8211 (when (and (match-string 1)
8212 (or (not (match-string 2))
8213 (save-excursion (goto-char (match-end 2))
8214 (vhdl-in-literal)))
8215 (not (save-excursion (goto-char (match-beginning 1))
8216 (vhdl-in-literal))))
8217 (goto-char (match-beginning 1))
8218 (insert "\n")
8219 (indent-according-to-mode))
8220 (goto-char point))
8221 (goto-char beg)
8222 ;; `for', `if' keywords
8223 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8224 (goto-char (match-end 1))
8225 (setq point (point-marker))
8226 ;; exception: in literal or preceded by `end', `wait' or label
8227 (when (and (not (save-excursion (goto-char (match-beginning 1))
8228 (vhdl-in-literal)))
8229 (save-excursion
8230 (beginning-of-line 1)
8231 (save-match-data
8232 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8233 (match-beginning 1) t)
8234 (not (string-match
8235 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8236 (match-string 1)))))))
8237 (goto-char (match-beginning 1))
8238 (insert "\n")
8239 (indent-according-to-mode))
8240 (goto-char point))))))
8241
8242 (defun vhdl-fix-statement-buffer ()
8243 "Force statements in buffer on separate line except when on same line
8244 with `end' keyword (necessary for correct indentation)."
8245 (interactive)
8246 (vhdl-fix-statement-region (point-min) (point-max)))
8247
8248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8249 ;; Trailing spaces
8250
8251 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8252 "Remove trailing spaces in region."
8253 (interactive "r\nP")
8254 (save-excursion
8255 (goto-char end)
8256 (setq end (point-marker))
8257 (goto-char beg)
8258 (while (re-search-forward "[ \t]+$" end t)
8259 (unless (vhdl-in-literal)
8260 (replace-match "" nil nil)))))
8261
8262 (defun vhdl-remove-trailing-spaces ()
8263 "Remove trailing spaces in buffer."
8264 (interactive)
8265 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8266
8267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8268 ;; Beautify
8269
8270 (defun vhdl-beautify-region (beg end)
8271 "Beautify region by applying indentation, whitespace fixup, alignment, and
8272 case fixing to a region. Calls functions `vhdl-indent-buffer',
8273 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8274 `vhdl-fix-case-buffer'."
8275 (interactive "r")
8276 (setq end (save-excursion (goto-char end) (point-marker)))
8277 (save-excursion ; remove DOS EOL characters in UNIX file
8278 (goto-char beg)
8279 (while (search-forward "\r" nil t)
8280 (replace-match "" nil t)))
8281 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8282 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8283 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8284 (when (nth 3 vhdl-beautify-options)
8285 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8286 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8287 (when (nth 0 vhdl-beautify-options)
8288 (vhdl-remove-trailing-spaces-region beg end)
8289 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8290
8291 (defun vhdl-beautify-buffer ()
8292 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8293 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8294 buffer."
8295 (interactive)
8296 (vhdl-beautify-region (point-min) (point-max))
8297 (when noninteractive (save-buffer)))
8298
8299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8300 ;; Code filling
8301
8302 (defun vhdl-fill-region (beg end &optional arg)
8303 "Fill lines for a region of code."
8304 (interactive "r\np")
8305 (save-excursion
8306 (goto-char beg)
8307 (let ((margin (if arg (current-indentation) (current-column))))
8308 (goto-char end)
8309 (setq end (point-marker))
8310 ;; remove inline comments, newlines and whitespace
8311 (vhdl-comment-kill-region beg end)
8312 (vhdl-comment-kill-inline-region beg end)
8313 (subst-char-in-region beg (1- end) ?\n ?\ )
8314 (vhdl-fixup-whitespace-region beg end)
8315 ;; wrap and end-comment-column
8316 (goto-char beg)
8317 (while (re-search-forward "\\s-" end t)
8318 (when(> (current-column) vhdl-end-comment-column)
8319 (backward-char)
8320 (when (re-search-backward "\\s-" beg t)
8321 (replace-match "\n")
8322 (indent-to margin)))))))
8323
8324 (defun vhdl-fill-group ()
8325 "Fill group of lines between empty lines."
8326 (interactive)
8327 (vhdl-do-group 'vhdl-fill-region))
8328
8329 (defun vhdl-fill-list ()
8330 "Fill the lines of a list surrounded by a balanced group of parentheses."
8331 (interactive)
8332 (vhdl-do-list 'vhdl-fill-region))
8333
8334 (defun vhdl-fill-same-indent ()
8335 "Fill the lines of block of lines with same indent."
8336 (interactive)
8337 (vhdl-do-same-indent 'vhdl-fill-region))
8338
8339
8340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8341 ;;; Code updating/fixing
8342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8343
8344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8345 ;; Sensitivity list update
8346
8347 ;; Strategy:
8348 ;; - no sensitivity list is generated for processes with wait statements
8349 ;; - otherwise, do the following:
8350 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8351 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8352 ;; manually entered global signals)
8353 ;; 3. signals from 1. and 2. form the list of visible signals
8354 ;; 4. search for if/elsif conditions containing an event (sequential code)
8355 ;; 5. scan for strings that are within syntactical regions where signals are
8356 ;; read but not within sequential code, and that correspond to visible
8357 ;; signals
8358 ;; 6. replace sensitivity list by list of signals from 5.
8359
8360 (defun vhdl-update-sensitivity-list-process ()
8361 "Update sensitivity list of current process."
8362 (interactive)
8363 (save-excursion
8364 (vhdl-prepare-search-2
8365 (end-of-line)
8366 ;; look whether in process
8367 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8368 (equal (upcase (match-string 2)) "PROCESS")
8369 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8370 (error "ERROR: Not within a process")
8371 (message "Updating sensitivity list...")
8372 (vhdl-update-sensitivity-list)
8373 (message "Updating sensitivity list...done")))))
8374
8375 (defun vhdl-update-sensitivity-list-buffer ()
8376 "Update sensitivity list of all processes in current buffer."
8377 (interactive)
8378 (save-excursion
8379 (vhdl-prepare-search-2
8380 (goto-char (point-min))
8381 (message "Updating sensitivity lists...")
8382 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8383 (goto-char (match-beginning 0))
8384 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8385 (message "Updating sensitivity lists...done")))
8386 (when noninteractive (save-buffer)))
8387
8388 (defun vhdl-update-sensitivity-list ()
8389 "Update sensitivity list."
8390 (let ((proc-beg (point))
8391 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8392 (proc-mid (vhdl-re-search-backward
8393 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8394 seq-region-list)
8395 (cond
8396 ;; error if 'begin' keyword missing
8397 ((not (match-string 2))
8398 (error "ERROR: No 'begin' keyword found"))
8399 ;; search for wait statement (no sensitivity list allowed)
8400 ((progn (goto-char proc-mid)
8401 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8402 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8403 ;; combinational process (update sensitivity list)
8404 (t
8405 (let
8406 ;; scan for visible signals
8407 ((visible-list (vhdl-get-visible-signals))
8408 ;; define syntactic regions where signals are read
8409 (scan-regions-list
8410 '(;; right-hand side of signal/variable assignment
8411 ;; (special case: "<=" is relational operator in a condition)
8412 ((vhdl-re-search-forward "[<:]=" proc-end t)
8413 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8414 ;; if condition
8415 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8416 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8417 ;; elsif condition
8418 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8419 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8420 ;; while loop condition
8421 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8422 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8423 ;; exit/next condition
8424 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8425 (vhdl-re-search-forward ";" proc-end t))
8426 ;; assert condition
8427 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8428 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8429 ;; case expression
8430 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8431 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8432 ;; parameter list of procedure call, array index
8433 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8434 (1- (point)))
8435 (progn (backward-char) (forward-sexp)
8436 (while (looking-at "(") (forward-sexp)) (point)))))
8437 name field read-list sens-list signal-list tmp-list
8438 sens-beg sens-end beg end margin)
8439 ;; scan for signals in old sensitivity list
8440 (goto-char proc-beg)
8441 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8442 (if (not (looking-at "[ \t\n\r\f]*("))
8443 (setq sens-beg (point))
8444 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8445 (goto-char (match-end 1))
8446 (forward-sexp)
8447 (setq sens-end (1- (point)))
8448 (goto-char sens-beg)
8449 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8450 (setq sens-list
8451 (cons (downcase (match-string 0)) sens-list))
8452 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8453 (setq signal-list (append visible-list sens-list))
8454 ;; search for sequential parts
8455 (goto-char proc-mid)
8456 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8457 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8458 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8459 (goto-char end)
8460 (backward-word 1)
8461 (vhdl-forward-sexp)
8462 (push (cons end (point)) seq-region-list)
8463 (beginning-of-line)))
8464 ;; scan for signals read in process
8465 (while scan-regions-list
8466 (goto-char proc-mid)
8467 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8468 (setq end (eval (nth 1 (car scan-regions-list)))))
8469 (goto-char beg)
8470 (unless (or (vhdl-in-literal)
8471 (and seq-region-list
8472 (let ((tmp-list seq-region-list))
8473 (while (and tmp-list
8474 (< (point) (caar tmp-list)))
8475 (setq tmp-list (cdr tmp-list)))
8476 (and tmp-list (< (point) (cdar tmp-list))))))
8477 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8478 (setq name (match-string 1))
8479 ;; get array index range
8480 (when vhdl-array-index-record-field-in-sensitivity-list
8481 (setq field (match-string 2))
8482 ;; not use if it includes a variable name
8483 (save-match-data
8484 (setq tmp-list visible-list)
8485 (while (and field tmp-list)
8486 (when (string-match
8487 (concat "\\<" (car tmp-list) "\\>") field)
8488 (setq field nil))
8489 (setq tmp-list (cdr tmp-list)))))
8490 (when (and (not (match-string 6)) ; not when formal parameter
8491 (not (and (match-string 5) ; not event attribute
8492 (not (member (downcase (match-string 5))
8493 '("event" "last_event" "transaction")))))
8494 (member (downcase name) signal-list))
8495 ;; not add if name or name+field already exists
8496 (unless
8497 (or (member-ignore-case name read-list)
8498 (member-ignore-case (concat name field) read-list))
8499 (push (concat name field) read-list))
8500 (setq tmp-list read-list)
8501 ;; remove existing name+field if name is added
8502 (save-match-data
8503 (while tmp-list
8504 (when (string-match (concat "^" name field "[(.]")
8505 (car tmp-list))
8506 (setq read-list (delete (car tmp-list) read-list)))
8507 (setq tmp-list (cdr tmp-list)))))
8508 (goto-char (match-end 1)))))
8509 (setq scan-regions-list (cdr scan-regions-list)))
8510 ;; update sensitivity list
8511 (goto-char sens-beg)
8512 (if sens-end
8513 (delete-region sens-beg sens-end)
8514 (when read-list
8515 (insert " ()") (backward-char)))
8516 (setq read-list (sort read-list 'string<))
8517 (when read-list
8518 (setq margin (current-column))
8519 (insert (car read-list))
8520 (setq read-list (cdr read-list))
8521 (while read-list
8522 (insert ",")
8523 (if (<= (+ (current-column) (length (car read-list)) 2)
8524 end-comment-column)
8525 (insert " ")
8526 (insert "\n") (indent-to margin))
8527 (insert (car read-list))
8528 (setq read-list (cdr read-list)))))))))
8529
8530 (defun vhdl-get-visible-signals ()
8531 "Get all signals visible in the current block."
8532 (let (beg end signal-list entity-name file-name)
8533 (vhdl-prepare-search-2
8534 ;; get entity name
8535 (save-excursion
8536 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8537 (not (equal "END" (upcase (match-string 1))))
8538 (setq entity-name (match-string 2)))
8539 (error "ERROR: Not within an architecture")))
8540 ;; search for signals declared in entity port clause
8541 (save-excursion
8542 (goto-char (point-min))
8543 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8544 (setq file-name
8545 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8546 "." (file-name-extension (buffer-file-name)))))
8547 (vhdl-visit-file
8548 file-name t
8549 (vhdl-prepare-search-2
8550 (goto-char (point-min))
8551 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8552 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8553 (when (setq beg (vhdl-re-search-forward
8554 "\\<port[ \t\n\r\f]*("
8555 (save-excursion
8556 (re-search-forward "^end\\>" nil t)) t))
8557 (setq end (save-excursion
8558 (backward-char) (forward-sexp) (point)))
8559 (vhdl-forward-syntactic-ws)
8560 (while (< (point) end)
8561 (when (looking-at "signal[ \t\n\r\f]+")
8562 (goto-char (match-end 0)))
8563 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8564 (setq signal-list
8565 (cons (downcase (match-string 1)) signal-list))
8566 (goto-char (match-end 0))
8567 (vhdl-forward-syntactic-ws))
8568 (re-search-forward ";" end 1)
8569 (vhdl-forward-syntactic-ws)))))))
8570 ;; search for signals declared in architecture declarative part
8571 (save-excursion
8572 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8573 (not (equal "END" (upcase (match-string 1))))
8574 (setq end (re-search-forward "^begin\\>" nil t))))
8575 (error "ERROR: No architecture declarative part found")
8576 ;; scan for all declared signal and alias names
8577 (goto-char beg)
8578 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8579 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8580 (if (match-string 2)
8581 ;; scan signal name
8582 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8583 (setq signal-list
8584 (cons (downcase (match-string 1)) signal-list))
8585 (goto-char (match-end 0)))
8586 ;; scan alias name, check is alias of (declared) signal
8587 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8588 (member (downcase (match-string 2)) signal-list))
8589 (setq signal-list
8590 (cons (downcase (match-string 1)) signal-list))
8591 (goto-char (match-end 0))))
8592 (setq beg (point))))))
8593 ;; search for signals declared in surrounding block declarative parts
8594 (save-excursion
8595 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8596 (match-string 4))
8597 (goto-char (match-end 4))
8598 (vhdl-backward-sexp)
8599 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8600 beg)
8601 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8602 ;; scan for all declared signal names
8603 (goto-char beg)
8604 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8605 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8606 (if (match-string 2)
8607 ;; scan signal name
8608 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8609 (setq signal-list
8610 (cons (downcase (match-string 1)) signal-list))
8611 (goto-char (match-end 0)))
8612 ;; scan alias name, check is alias of (declared) signal
8613 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8614 (member (downcase (match-string 2)) signal-list))
8615 (setq signal-list
8616 (cons (downcase (match-string 1)) signal-list))
8617 (goto-char (match-end 0))))))
8618 (goto-char beg)))
8619 signal-list)))
8620
8621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8622 ;; Generic/port clause fixing
8623
8624 (defun vhdl-fix-clause-buffer ()
8625 "Fix all generic/port clauses in current buffer."
8626 (interactive)
8627 (save-excursion
8628 (vhdl-prepare-search-2
8629 (goto-char (point-min))
8630 (message "Fixing generic/port clauses...")
8631 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8632 (goto-char (match-end 0))
8633 (condition-case nil (vhdl-fix-clause) (error "")))
8634 (message "Fixing generic/port clauses...done"))))
8635
8636 (defun vhdl-fix-clause ()
8637 "Fix closing parenthesis within generic/port clause."
8638 (interactive)
8639 (save-excursion
8640 (vhdl-prepare-search-2
8641 (let ((pos (point))
8642 beg end)
8643 (end-of-line)
8644 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8645 (error "ERROR: Not within a generic/port clause")
8646 ;; search for end of clause
8647 (goto-char (match-end 0))
8648 (setq beg (1- (point)))
8649 (vhdl-forward-syntactic-ws)
8650 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8651 (goto-char (1- (match-end 0)))
8652 (setq end (point-marker))
8653 (forward-char)
8654 (vhdl-forward-syntactic-ws))
8655 (goto-char end)
8656 (when (> pos (point-at-eol))
8657 (error "ERROR: Not within a generic/port clause"))
8658 ;; delete closing parenthesis on separate line (not supported style)
8659 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8660 (vhdl-line-kill)
8661 (vhdl-backward-syntactic-ws)
8662 (setq end (point-marker))
8663 (insert ";"))
8664 ;; delete superfluous parentheses
8665 (while (progn (goto-char beg)
8666 (condition-case () (forward-sexp)
8667 (error (goto-char (point-max))))
8668 (< (point) end))
8669 (delete-char -1))
8670 ;; add closing parenthesis
8671 (when (> (point) end)
8672 (goto-char end)
8673 (insert ")")))))))
8674
8675
8676 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8677 ;;; Electrification
8678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8679
8680 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8681 "Syntax of prompt inserted by template generators.")
8682
8683 (defvar vhdl-template-invoked-by-hook nil
8684 "Indicates whether a template has been invoked by a hook or by key or menu.
8685 Used for undoing after template abortion.")
8686
8687 ;; correct different behavior of function `unread-command-events' in XEmacs
8688 (defun vhdl-character-to-event (arg))
8689 (defalias 'vhdl-character-to-event
8690 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8691
8692 (defun vhdl-work-library ()
8693 "Return the working library name of the current project or \"work\" if no
8694 project is defined."
8695 (vhdl-resolve-env-variable
8696 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8697 vhdl-default-library)))
8698
8699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8700 ;; Enabling/disabling
8701
8702 (define-minor-mode vhdl-electric-mode
8703 "Toggle VHDL electric mode.
8704 With a prefix argument ARG, enable the mode if ARG is positive,
8705 and disable it otherwise. If called from Lisp, enable it if ARG
8706 is omitted or nil."
8707 :global t :group 'vhdl-mode)
8708
8709 (define-minor-mode vhdl-stutter-mode
8710 "Toggle VHDL stuttering mode.
8711 With a prefix argument ARG, enable the mode if ARG is positive,
8712 and disable it otherwise. If called from Lisp, enable it if ARG
8713 is omitted or nil."
8714 :global t :group 'vhdl-mode)
8715
8716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8717 ;; Stuttering
8718
8719 (defun vhdl-electric-dash (count)
8720 "-- starts a comment, --- draws a horizontal line,
8721 ---- starts a display comment."
8722 (interactive "p")
8723 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8724 (cond
8725 ((and abbrev-start-location (= abbrev-start-location (point)))
8726 (setq abbrev-start-location nil)
8727 (goto-char last-abbrev-location)
8728 (beginning-of-line nil)
8729 (vhdl-comment-display))
8730 ((/= (preceding-char) ?-) ; standard dash (minus)
8731 (self-insert-command count))
8732 (t (self-insert-command count)
8733 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8734 (let ((next-input (read-char)))
8735 (if (= next-input ?-) ; triple dash
8736 (progn
8737 (vhdl-comment-display-line)
8738 (message
8739 "Enter '-' for display comment, else continue coding")
8740 (let ((next-input (read-char)))
8741 (if (= next-input ?-) ; four dashes
8742 (vhdl-comment-display t)
8743 (push (vhdl-character-to-event next-input)
8744 ; pushback the char
8745 unread-command-events))))
8746 (push (vhdl-character-to-event next-input) ; pushback the char
8747 unread-command-events)
8748 (vhdl-comment-insert)))))
8749 (self-insert-command count)))
8750
8751 (defun vhdl-electric-open-bracket (count) "`[' --> `(', `([' --> `['"
8752 (interactive "p")
8753 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8754 (if (= (preceding-char) ?\()
8755 (progn (delete-char -1) (insert-char ?\[ 1))
8756 (insert-char ?\( 1))
8757 (self-insert-command count)))
8758
8759 (defun vhdl-electric-close-bracket (count) "`]' --> `)', `)]' --> `]'"
8760 (interactive "p")
8761 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8762 (progn
8763 (if (= (preceding-char) ?\))
8764 (progn (delete-char -1) (insert-char ?\] 1))
8765 (insert-char ?\) 1))
8766 (blink-matching-open))
8767 (self-insert-command count)))
8768
8769 (defun vhdl-electric-quote (count) "\\='\\=' --> \""
8770 (interactive "p")
8771 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8772 (if (= (preceding-char) vhdl-last-input-event)
8773 (progn (delete-char -1) (insert-char ?\" 1))
8774 (insert-char ?\' 1))
8775 (self-insert-command count)))
8776
8777 (defun vhdl-electric-semicolon (count) "`;;' --> ` : ', `: ;' --> ` := '"
8778 (interactive "p")
8779 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8780 (cond ((= (preceding-char) vhdl-last-input-event)
8781 (progn (delete-char -1)
8782 (unless (eq (preceding-char) ? ) (insert " "))
8783 (insert ": ")
8784 (setq this-command 'vhdl-electric-colon)))
8785 ((and
8786 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8787 (progn (delete-char -1) (insert "= ")))
8788 (t (insert-char ?\; 1)))
8789 (self-insert-command count)))
8790
8791 (defun vhdl-electric-comma (count) "`,,' --> ` <= '"
8792 (interactive "p")
8793 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8794 (cond ((= (preceding-char) vhdl-last-input-event)
8795 (progn (delete-char -1)
8796 (unless (eq (preceding-char) ? ) (insert " "))
8797 (insert "<= ")))
8798 (t (insert-char ?\, 1)))
8799 (self-insert-command count)))
8800
8801 (defun vhdl-electric-period (count) "`..' --> ` => '"
8802 (interactive "p")
8803 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8804 (cond ((= (preceding-char) vhdl-last-input-event)
8805 (progn (delete-char -1)
8806 (unless (eq (preceding-char) ? ) (insert " "))
8807 (insert "=> ")))
8808 (t (insert-char ?\. 1)))
8809 (self-insert-command count)))
8810
8811 (defun vhdl-electric-equal (count) "`==' --> ` == '"
8812 (interactive "p")
8813 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8814 (cond ((= (preceding-char) vhdl-last-input-event)
8815 (progn (delete-char -1)
8816 (unless (eq (preceding-char) ? ) (insert " "))
8817 (insert "== ")))
8818 (t (insert-char ?\= 1)))
8819 (self-insert-command count)))
8820
8821 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8822 ;; VHDL templates
8823
8824 (defun vhdl-template-paired-parens ()
8825 "Insert a pair of round parentheses, placing point between them."
8826 (interactive)
8827 (insert "()")
8828 (backward-char))
8829
8830 (defun vhdl-template-alias ()
8831 "Insert alias declaration."
8832 (interactive)
8833 (let ((start (point)))
8834 (vhdl-insert-keyword "ALIAS ")
8835 (when (vhdl-template-field "name" nil t start (point))
8836 (insert " : ")
8837 (unless (vhdl-template-field
8838 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8839 nil t)
8840 (delete-char -3))
8841 (vhdl-insert-keyword " IS ")
8842 (vhdl-template-field "name" ";")
8843 (vhdl-comment-insert-inline))))
8844
8845 (defun vhdl-template-architecture ()
8846 "Insert architecture."
8847 (interactive)
8848 (let ((margin (current-indentation))
8849 (start (point))
8850 arch-name)
8851 (vhdl-insert-keyword "ARCHITECTURE ")
8852 (when (setq arch-name
8853 (vhdl-template-field "name" nil t start (point)))
8854 (vhdl-insert-keyword " OF ")
8855 (if (save-excursion
8856 (vhdl-prepare-search-1
8857 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8858 (insert (match-string 1))
8859 (vhdl-template-field "entity name"))
8860 (vhdl-insert-keyword " IS\n")
8861 (vhdl-template-begin-end
8862 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8863 (memq vhdl-insert-empty-lines '(unit all))))))
8864
8865 (defun vhdl-template-array (kind &optional secondary)
8866 "Insert array type definition."
8867 (interactive)
8868 (let ((start (point)))
8869 (vhdl-insert-keyword "ARRAY (")
8870 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8871 secondary)
8872 (vhdl-insert-keyword ") OF ")
8873 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8874 (vhdl-insert-keyword ";"))))
8875
8876 (defun vhdl-template-assert ()
8877 "Insert an assertion statement."
8878 (interactive)
8879 (let ((start (point)))
8880 (vhdl-insert-keyword "ASSERT ")
8881 (when vhdl-conditions-in-parenthesis (insert "("))
8882 (when (vhdl-template-field "condition (negated)" nil t start (point))
8883 (when vhdl-conditions-in-parenthesis (insert ")"))
8884 (setq start (point))
8885 (vhdl-insert-keyword " REPORT ")
8886 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8887 (delete-region start (point)))
8888 (setq start (point))
8889 (vhdl-insert-keyword " SEVERITY ")
8890 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8891 (delete-region start (point)))
8892 (insert ";"))))
8893
8894 (defun vhdl-template-attribute ()
8895 "Insert an attribute declaration or specification."
8896 (interactive)
8897 (if (eq (vhdl-decision-query
8898 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8899 (vhdl-template-attribute-spec)
8900 (vhdl-template-attribute-decl)))
8901
8902 (defun vhdl-template-attribute-decl ()
8903 "Insert an attribute declaration."
8904 (interactive)
8905 (let ((start (point)))
8906 (vhdl-insert-keyword "ATTRIBUTE ")
8907 (when (vhdl-template-field "name" " : " t start (point))
8908 (vhdl-template-field "type" ";")
8909 (vhdl-comment-insert-inline))))
8910
8911 (defun vhdl-template-attribute-spec ()
8912 "Insert an attribute specification."
8913 (interactive)
8914 (let ((start (point)))
8915 (vhdl-insert-keyword "ATTRIBUTE ")
8916 (when (vhdl-template-field "name" nil t start (point))
8917 (vhdl-insert-keyword " OF ")
8918 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8919 (vhdl-template-field "entity class")
8920 (vhdl-insert-keyword " IS ")
8921 (vhdl-template-field "expression" ";"))))
8922
8923 (defun vhdl-template-block ()
8924 "Insert a block."
8925 (interactive)
8926 (let ((margin (current-indentation))
8927 (start (point))
8928 label)
8929 (vhdl-insert-keyword ": BLOCK ")
8930 (goto-char start)
8931 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8932 (forward-word 1)
8933 (forward-char 1)
8934 (insert "(")
8935 (if (vhdl-template-field "[guard expression]" nil t)
8936 (insert ")")
8937 (delete-char -2))
8938 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8939 (insert "\n")
8940 (vhdl-template-begin-end "BLOCK" label margin)
8941 (vhdl-comment-block))))
8942
8943 (defun vhdl-template-block-configuration ()
8944 "Insert a block configuration statement."
8945 (interactive)
8946 (let ((margin (current-indentation))
8947 (start (point)))
8948 (vhdl-insert-keyword "FOR ")
8949 (when (vhdl-template-field "block name" nil t start (point))
8950 (vhdl-insert-keyword "\n\n")
8951 (indent-to margin)
8952 (vhdl-insert-keyword "END FOR;")
8953 (end-of-line 0)
8954 (indent-to (+ margin vhdl-basic-offset)))))
8955
8956 (defun vhdl-template-break ()
8957 "Insert a break statement."
8958 (interactive)
8959 (let (position)
8960 (vhdl-insert-keyword "BREAK")
8961 (setq position (point))
8962 (insert " ")
8963 (while (or
8964 (progn (vhdl-insert-keyword "FOR ")
8965 (if (vhdl-template-field "[quantity name]" " USE " t)
8966 (progn (vhdl-template-field "quantity name" " => ") t)
8967 (delete-region (point)
8968 (progn (forward-word -1) (point)))
8969 nil))
8970 (vhdl-template-field "[quantity name]" " => " t))
8971 (vhdl-template-field "expression")
8972 (setq position (point))
8973 (insert ", "))
8974 (delete-region position (point))
8975 (unless (vhdl-sequential-statement-p)
8976 (vhdl-insert-keyword " ON ")
8977 (if (vhdl-template-field "[sensitivity list]" nil t)
8978 (setq position (point))
8979 (delete-region position (point))))
8980 (vhdl-insert-keyword " WHEN ")
8981 (when vhdl-conditions-in-parenthesis (insert "("))
8982 (if (vhdl-template-field "[condition]" nil t)
8983 (when vhdl-conditions-in-parenthesis (insert ")"))
8984 (delete-region position (point)))
8985 (insert ";")))
8986
8987 (defun vhdl-template-case (&optional kind)
8988 "Insert a case statement."
8989 (interactive)
8990 (let ((margin (current-indentation))
8991 (start (point))
8992 label)
8993 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8994 (not (vhdl-standard-p 'ams))) 'is 'use)))
8995 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8996 (vhdl-insert-keyword "CASE ")
8997 (vhdl-insert-keyword ": CASE ")
8998 (goto-char start)
8999 (setq label (vhdl-template-field "[label]" nil t))
9000 (unless label (delete-char 2))
9001 (forward-word 1)
9002 (forward-char 1))
9003 (when (vhdl-template-field "expression" nil t start (point))
9004 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
9005 (indent-to margin)
9006 (vhdl-insert-keyword "END CASE")
9007 (when label (insert " " label))
9008 (insert ";")
9009 (forward-line -1)
9010 (indent-to (+ margin vhdl-basic-offset))
9011 (vhdl-insert-keyword "WHEN ")
9012 (let ((position (point)))
9013 (insert " => ;\n")
9014 (indent-to (+ margin vhdl-basic-offset))
9015 (vhdl-insert-keyword "WHEN OTHERS => null;")
9016 (goto-char position)))))
9017
9018 (defun vhdl-template-case-is ()
9019 "Insert a sequential case statement."
9020 (interactive)
9021 (vhdl-template-case 'is))
9022
9023 (defun vhdl-template-case-use ()
9024 "Insert a simultaneous case statement."
9025 (interactive)
9026 (vhdl-template-case 'use))
9027
9028 (defun vhdl-template-component ()
9029 "Insert a component declaration."
9030 (interactive)
9031 (vhdl-template-component-decl))
9032
9033 (defun vhdl-template-component-conf ()
9034 "Insert a component configuration (uses `vhdl-template-configuration-spec'
9035 since these are almost equivalent)."
9036 (interactive)
9037 (let ((margin (current-indentation))
9038 (result (vhdl-template-configuration-spec t)))
9039 (when result
9040 (insert "\n")
9041 (indent-to margin)
9042 (vhdl-insert-keyword "END FOR;")
9043 (when (eq result 'no-use)
9044 (end-of-line -0)))))
9045
9046 (defun vhdl-template-component-decl ()
9047 "Insert a component declaration."
9048 (interactive)
9049 (let ((margin (current-indentation))
9050 (start (point))
9051 name end-column)
9052 (vhdl-insert-keyword "COMPONENT ")
9053 (when (setq name (vhdl-template-field "name" nil t start (point)))
9054 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9055 (insert "\n\n")
9056 (indent-to margin)
9057 (vhdl-insert-keyword "END COMPONENT")
9058 (unless (vhdl-standard-p '87) (insert " " name))
9059 (insert ";")
9060 (setq end-column (current-column))
9061 (end-of-line -0)
9062 (indent-to (+ margin vhdl-basic-offset))
9063 (vhdl-template-generic-list t t)
9064 (insert "\n")
9065 (indent-to (+ margin vhdl-basic-offset))
9066 (vhdl-template-port-list t)
9067 (beginning-of-line 2)
9068 (forward-char end-column))))
9069
9070 (defun vhdl-template-component-inst ()
9071 "Insert a component instantiation statement."
9072 (interactive)
9073 (let ((margin (current-indentation))
9074 (start (point))
9075 unit position)
9076 (when (vhdl-template-field "instance label" nil t start (point))
9077 (insert ": ")
9078 (if (not (vhdl-use-direct-instantiation))
9079 (vhdl-template-field "component name")
9080 ;; direct instantiation
9081 (setq unit (vhdl-template-field
9082 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
9083 (setq unit (upcase (or unit "")))
9084 (cond ((equal unit "ENTITY")
9085 (let ((begin (point)))
9086 (vhdl-template-field "library name" "." t begin (point) nil
9087 (vhdl-work-library))
9088 (vhdl-template-field "entity name" "(")
9089 (if (vhdl-template-field "[architecture name]" nil t)
9090 (insert ")")
9091 (delete-char -1))))
9092 ((equal unit "CONFIGURATION")
9093 (vhdl-template-field "library name" "." nil nil nil nil
9094 (vhdl-work-library))
9095 (vhdl-template-field "configuration name"))
9096 (t (vhdl-template-field "component name"))))
9097 (insert "\n")
9098 (indent-to (+ margin vhdl-basic-offset))
9099 (setq position (point))
9100 (vhdl-insert-keyword "GENERIC ")
9101 (when (vhdl-template-map position t t)
9102 (insert "\n")
9103 (indent-to (+ margin vhdl-basic-offset)))
9104 (setq position (point))
9105 (vhdl-insert-keyword "PORT ")
9106 (unless (vhdl-template-map position t t)
9107 (delete-region (line-beginning-position) (point))
9108 (delete-char -1))
9109 (insert ";"))))
9110
9111 (defun vhdl-template-conditional-signal-asst ()
9112 "Insert a conditional signal assignment."
9113 (interactive)
9114 (when (vhdl-template-field "target signal")
9115 (insert " <= ")
9116 (let ((margin (current-column))
9117 (start (point))
9118 position)
9119 (vhdl-template-field "waveform")
9120 (setq position (point))
9121 (vhdl-insert-keyword " WHEN ")
9122 (when vhdl-conditions-in-parenthesis (insert "("))
9123 (while (and (vhdl-template-field "[condition]" nil t)
9124 (progn
9125 (when vhdl-conditions-in-parenthesis (insert ")"))
9126 (setq position (point))
9127 (vhdl-insert-keyword " ELSE")
9128 (insert "\n")
9129 (indent-to margin)
9130 (vhdl-template-field "[waveform]" nil t)))
9131 (setq position (point))
9132 (vhdl-insert-keyword " WHEN ")
9133 (when vhdl-conditions-in-parenthesis (insert "(")))
9134 (delete-region position (point))
9135 (insert ";")
9136 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9137
9138 (defun vhdl-template-configuration ()
9139 "Insert a configuration specification if within an architecture,
9140 a block or component configuration if within a configuration declaration,
9141 a configuration declaration if not within a design unit."
9142 (interactive)
9143 (vhdl-prepare-search-1
9144 (cond
9145 ((and (save-excursion ; architecture body
9146 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9147 (equal "ARCHITECTURE" (upcase (match-string 1))))
9148 (vhdl-template-configuration-spec))
9149 ((and (save-excursion ; configuration declaration
9150 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9151 (equal "CONFIGURATION" (upcase (match-string 1))))
9152 (if (eq (vhdl-decision-query
9153 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9154 (vhdl-template-component-conf)
9155 (vhdl-template-block-configuration)))
9156 (t (vhdl-template-configuration-decl))))) ; otherwise
9157
9158 (defun vhdl-template-configuration-spec (&optional optional-use)
9159 "Insert a configuration specification."
9160 (interactive)
9161 (let ((margin (current-indentation))
9162 (start (point))
9163 aspect position)
9164 (vhdl-insert-keyword "FOR ")
9165 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9166 t start (point))
9167 (vhdl-template-field "component name" "\n")
9168 (indent-to (+ margin vhdl-basic-offset))
9169 (setq start (point))
9170 (vhdl-insert-keyword "USE ")
9171 (if (and optional-use
9172 (not (setq aspect (vhdl-template-field
9173 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9174 (progn (delete-region start (point)) 'no-use)
9175 (unless optional-use
9176 (setq aspect (vhdl-template-field
9177 "ENTITY | CONFIGURATION | OPEN" " ")))
9178 (setq aspect (upcase (or aspect "")))
9179 (cond ((equal aspect "ENTITY")
9180 (vhdl-template-field "library name" "." nil nil nil nil
9181 (vhdl-work-library))
9182 (vhdl-template-field "entity name" "(")
9183 (if (vhdl-template-field "[architecture name]" nil t)
9184 (insert ")")
9185 (delete-char -1))
9186 (insert "\n")
9187 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9188 (setq position (point))
9189 (vhdl-insert-keyword "GENERIC ")
9190 (when (vhdl-template-map position t t)
9191 (insert "\n")
9192 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9193 (setq position (point))
9194 (vhdl-insert-keyword "PORT ")
9195 (unless (vhdl-template-map position t t)
9196 (delete-region (line-beginning-position) (point))
9197 (delete-char -1))
9198 (insert ";")
9199 t)
9200 ((equal aspect "CONFIGURATION")
9201 (vhdl-template-field "library name" "." nil nil nil nil
9202 (vhdl-work-library))
9203 (vhdl-template-field "configuration name" ";"))
9204 (t (delete-char -1) (insert ";") t))))))
9205
9206
9207 (defun vhdl-template-configuration-decl ()
9208 "Insert a configuration declaration."
9209 (interactive)
9210 (let ((margin (current-indentation))
9211 (start (point))
9212 entity-exists string name position)
9213 (vhdl-insert-keyword "CONFIGURATION ")
9214 (when (setq name (vhdl-template-field "name" nil t start (point)))
9215 (vhdl-insert-keyword " OF ")
9216 (save-excursion
9217 (vhdl-prepare-search-1
9218 (setq entity-exists (vhdl-re-search-backward
9219 "\\<entity \\(\\w*\\) is\\>" nil t))
9220 (setq string (match-string 1))))
9221 (if (and entity-exists (not (equal string "")))
9222 (insert string)
9223 (vhdl-template-field "entity name"))
9224 (vhdl-insert-keyword " IS\n")
9225 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9226 (indent-to (+ margin vhdl-basic-offset))
9227 (setq position (point))
9228 (insert "\n")
9229 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9230 (indent-to margin)
9231 (vhdl-insert-keyword "END ")
9232 (unless (vhdl-standard-p '87)
9233 (vhdl-insert-keyword "CONFIGURATION "))
9234 (insert name ";")
9235 (goto-char position))))
9236
9237 (defun vhdl-template-constant ()
9238 "Insert a constant declaration."
9239 (interactive)
9240 (let ((start (point))
9241 (in-arglist (vhdl-in-argument-list-p)))
9242 (vhdl-insert-keyword "CONSTANT ")
9243 (when (vhdl-template-field "name" nil t start (point))
9244 (insert " : ")
9245 (when in-arglist (vhdl-insert-keyword "IN "))
9246 (vhdl-template-field "type")
9247 (if in-arglist
9248 (progn (insert ";")
9249 (vhdl-comment-insert-inline))
9250 (let ((position (point)))
9251 (insert " := ")
9252 (unless (vhdl-template-field "[initialization]" nil t)
9253 (delete-region position (point)))
9254 (insert ";")
9255 (vhdl-comment-insert-inline))))))
9256
9257 (defun vhdl-template-context ()
9258 "Insert a context declaration."
9259 (interactive)
9260 (let ((margin (current-indentation))
9261 (start (point))
9262 entity-exists string name position)
9263 (vhdl-insert-keyword "CONTEXT ")
9264 (when (setq name (vhdl-template-field "name" nil t start (point)))
9265 (vhdl-insert-keyword " IS\n")
9266 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9267 (indent-to (+ margin vhdl-basic-offset))
9268 (setq position (point))
9269 (insert "\n")
9270 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9271 (indent-to margin)
9272 (vhdl-insert-keyword "END ")
9273 (unless (vhdl-standard-p '87)
9274 (vhdl-insert-keyword "CONTEXT "))
9275 (insert name ";")
9276 (goto-char position))))
9277
9278 (defun vhdl-template-default ()
9279 "Insert nothing."
9280 (interactive)
9281 (insert " ")
9282 (unexpand-abbrev)
9283 (backward-word 1)
9284 (vhdl-case-word 1)
9285 (forward-char 1))
9286
9287 (defun vhdl-template-default-indent ()
9288 "Insert nothing and indent."
9289 (interactive)
9290 (insert " ")
9291 (unexpand-abbrev)
9292 (backward-word 1)
9293 (vhdl-case-word 1)
9294 (forward-char 1)
9295 (indent-according-to-mode))
9296
9297 (defun vhdl-template-disconnect ()
9298 "Insert a disconnect statement."
9299 (interactive)
9300 (let ((start (point)))
9301 (vhdl-insert-keyword "DISCONNECT ")
9302 (when (vhdl-template-field "signal names | OTHERS | ALL"
9303 " : " t start (point))
9304 (vhdl-template-field "type")
9305 (vhdl-insert-keyword " AFTER ")
9306 (vhdl-template-field "time expression" ";"))))
9307
9308 (defun vhdl-template-else ()
9309 "Insert an else statement."
9310 (interactive)
9311 (let (margin)
9312 (vhdl-prepare-search-1
9313 (vhdl-insert-keyword "ELSE")
9314 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
9315 (equal "WHEN" (upcase (match-string 1))))
9316 (insert " ")
9317 (indent-according-to-mode)
9318 (setq margin (current-indentation))
9319 (insert "\n")
9320 (indent-to (+ margin vhdl-basic-offset))))))
9321
9322 (defun vhdl-template-elsif ()
9323 "Insert an elsif statement."
9324 (interactive)
9325 (let ((start (point))
9326 margin)
9327 (vhdl-insert-keyword "ELSIF ")
9328 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
9329 (when vhdl-conditions-in-parenthesis (insert "("))
9330 (when (vhdl-template-field "condition" nil t start (point))
9331 (when vhdl-conditions-in-parenthesis (insert ")"))
9332 (indent-according-to-mode)
9333 (setq margin (current-indentation))
9334 (vhdl-insert-keyword
9335 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9336 (indent-to (+ margin vhdl-basic-offset))))))
9337
9338 (defun vhdl-template-entity ()
9339 "Insert an entity."
9340 (interactive)
9341 (let ((margin (current-indentation))
9342 (start (point))
9343 name end-column)
9344 (vhdl-insert-keyword "ENTITY ")
9345 (when (setq name (vhdl-template-field "name" nil t start (point)))
9346 (vhdl-insert-keyword " IS\n\n")
9347 (indent-to margin)
9348 (vhdl-insert-keyword "END ")
9349 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9350 (insert name ";")
9351 (setq end-column (current-column))
9352 (end-of-line -0)
9353 (indent-to (+ margin vhdl-basic-offset))
9354 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9355 (indent-to (+ margin vhdl-basic-offset))
9356 (when (vhdl-template-generic-list t)
9357 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9358 (insert "\n")
9359 (indent-to (+ margin vhdl-basic-offset))
9360 (when (vhdl-template-port-list t)
9361 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9362 (beginning-of-line 2)
9363 (forward-char end-column))))
9364
9365 (defun vhdl-template-exit ()
9366 "Insert an exit statement."
9367 (interactive)
9368 (let ((start (point)))
9369 (vhdl-insert-keyword "EXIT ")
9370 (if (vhdl-template-field "[loop label]" nil t start (point))
9371 (let ((position (point)))
9372 (vhdl-insert-keyword " WHEN ")
9373 (when vhdl-conditions-in-parenthesis (insert "("))
9374 (if (vhdl-template-field "[condition]" nil t)
9375 (when vhdl-conditions-in-parenthesis (insert ")"))
9376 (delete-region position (point))))
9377 (delete-char -1))
9378 (insert ";")))
9379
9380 (defun vhdl-template-file ()
9381 "Insert a file declaration."
9382 (interactive)
9383 (let ((start (point)))
9384 (vhdl-insert-keyword "FILE ")
9385 (when (vhdl-template-field "name" nil t start (point))
9386 (insert " : ")
9387 (vhdl-template-field "type")
9388 (unless (vhdl-standard-p '87)
9389 (vhdl-insert-keyword " OPEN ")
9390 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9391 nil t)
9392 (delete-char -6)))
9393 (vhdl-insert-keyword " IS ")
9394 (when (vhdl-standard-p '87)
9395 (vhdl-template-field "[IN | OUT]" " " t))
9396 (vhdl-template-field "filename-string" nil nil nil nil t)
9397 (insert ";")
9398 (vhdl-comment-insert-inline))))
9399
9400 (defun vhdl-template-for ()
9401 "Insert a block or component configuration if within a configuration
9402 declaration, a configuration specification if within an architecture
9403 declarative part (and not within a subprogram), a for-loop if within a
9404 sequential statement part (subprogram or process), and a for-generate
9405 otherwise."
9406 (interactive)
9407 (vhdl-prepare-search-1
9408 (cond
9409 ((vhdl-sequential-statement-p) ; sequential statement
9410 (vhdl-template-for-loop))
9411 ((and (save-excursion ; configuration declaration
9412 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9413 (equal "CONFIGURATION" (upcase (match-string 1))))
9414 (if (eq (vhdl-decision-query
9415 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9416 (vhdl-template-component-conf)
9417 (vhdl-template-block-configuration)))
9418 ((and (save-excursion
9419 (re-search-backward ; architecture declarative part
9420 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9421 (equal "ARCHITECTURE" (upcase (match-string 1))))
9422 (vhdl-template-configuration-spec))
9423 (t (vhdl-template-for-generate))))) ; concurrent statement
9424
9425 (defun vhdl-template-for-generate ()
9426 "Insert a for-generate."
9427 (interactive)
9428 (let ((margin (current-indentation))
9429 (start (point))
9430 label position)
9431 (vhdl-insert-keyword ": FOR ")
9432 (setq position (point-marker))
9433 (goto-char start)
9434 (when (setq label (vhdl-template-field "label" nil t start position))
9435 (goto-char position)
9436 (vhdl-template-field "loop variable")
9437 (vhdl-insert-keyword " IN ")
9438 (vhdl-template-field "range")
9439 (vhdl-template-generate-body margin label))))
9440
9441 (defun vhdl-template-for-loop ()
9442 "Insert a for loop."
9443 (interactive)
9444 (let ((margin (current-indentation))
9445 (start (point))
9446 label index)
9447 (if (not (eq vhdl-optional-labels 'all))
9448 (vhdl-insert-keyword "FOR ")
9449 (vhdl-insert-keyword ": FOR ")
9450 (goto-char start)
9451 (setq label (vhdl-template-field "[label]" nil t))
9452 (unless label (delete-char 2))
9453 (forward-word 1)
9454 (forward-char 1))
9455 (when (setq index (vhdl-template-field "loop variable"
9456 nil t start (point)))
9457 (vhdl-insert-keyword " IN ")
9458 (vhdl-template-field "range")
9459 (vhdl-insert-keyword " LOOP\n\n")
9460 (indent-to margin)
9461 (vhdl-insert-keyword "END LOOP")
9462 (if label
9463 (insert " " label ";")
9464 (insert ";")
9465 (when vhdl-self-insert-comments (insert " -- " index)))
9466 (forward-line -1)
9467 (indent-to (+ margin vhdl-basic-offset)))))
9468
9469 (defun vhdl-template-function (&optional kind)
9470 "Insert a function declaration or body."
9471 (interactive)
9472 (let ((margin (current-indentation))
9473 (start (point))
9474 name)
9475 (vhdl-insert-keyword "FUNCTION ")
9476 (when (setq name (vhdl-template-field "name" nil t start (point)))
9477 (vhdl-template-argument-list t)
9478 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9479 (end-of-line)
9480 (insert "\n")
9481 (indent-to (+ margin vhdl-basic-offset))
9482 (vhdl-insert-keyword "RETURN ")
9483 (vhdl-template-field "type")
9484 (if (if kind (eq kind 'body)
9485 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9486 (progn (vhdl-insert-keyword " IS\n")
9487 (vhdl-template-begin-end
9488 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9489 (vhdl-comment-block))
9490 (insert ";")))))
9491
9492 (defun vhdl-template-function-decl ()
9493 "Insert a function declaration."
9494 (interactive)
9495 (vhdl-template-function 'decl))
9496
9497 (defun vhdl-template-function-body ()
9498 "Insert a function declaration."
9499 (interactive)
9500 (vhdl-template-function 'body))
9501
9502 (defun vhdl-template-generate ()
9503 "Insert a generation scheme."
9504 (interactive)
9505 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9506 (vhdl-template-if-generate)
9507 (vhdl-template-for-generate)))
9508
9509 (defun vhdl-template-generic ()
9510 "Insert generic declaration, or generic map in instantiation statements."
9511 (interactive)
9512 (let ((start (point)))
9513 (vhdl-prepare-search-1
9514 (cond
9515 ((and (save-excursion ; entity declaration
9516 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9517 (equal "ENTITY" (upcase (match-string 1))))
9518 (vhdl-template-generic-list nil))
9519 ((or (save-excursion
9520 (or (beginning-of-line)
9521 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9522 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9523 (vhdl-insert-keyword "GENERIC ")
9524 (vhdl-template-map start))
9525 (t (vhdl-template-generic-list nil t))))))
9526
9527 (defun vhdl-template-group ()
9528 "Insert group or group template declaration."
9529 (interactive)
9530 (let ((start (point)))
9531 (if (eq (vhdl-decision-query
9532 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9533 (vhdl-template-group-template)
9534 (vhdl-template-group-decl))))
9535
9536 (defun vhdl-template-group-decl ()
9537 "Insert group declaration."
9538 (interactive)
9539 (let ((start (point)))
9540 (vhdl-insert-keyword "GROUP ")
9541 (when (vhdl-template-field "name" " : " t start (point))
9542 (vhdl-template-field "template name" " (")
9543 (vhdl-template-field "constituent list" ");")
9544 (vhdl-comment-insert-inline))))
9545
9546 (defun vhdl-template-group-template ()
9547 "Insert group template declaration."
9548 (interactive)
9549 (let ((start (point)))
9550 (vhdl-insert-keyword "GROUP ")
9551 (when (vhdl-template-field "template name" nil t start (point))
9552 (vhdl-insert-keyword " IS (")
9553 (vhdl-template-field "entity class list" ");")
9554 (vhdl-comment-insert-inline))))
9555
9556 (defun vhdl-template-if ()
9557 "Insert a sequential if statement or an if-generate statement."
9558 (interactive)
9559 (if (vhdl-sequential-statement-p)
9560 (vhdl-template-if-then)
9561 (if (and (vhdl-standard-p 'ams)
9562 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9563 (vhdl-template-if-use)
9564 (vhdl-template-if-generate))))
9565
9566 (defun vhdl-template-if-generate ()
9567 "Insert an if-generate."
9568 (interactive)
9569 (let ((margin (current-indentation))
9570 (start (point))
9571 label position)
9572 (vhdl-insert-keyword ": IF ")
9573 (setq position (point-marker))
9574 (goto-char start)
9575 (when (setq label (vhdl-template-field "label" nil t start position))
9576 (goto-char position)
9577 (when vhdl-conditions-in-parenthesis (insert "("))
9578 (vhdl-template-field "condition")
9579 (when vhdl-conditions-in-parenthesis (insert ")"))
9580 (vhdl-template-generate-body margin label))))
9581
9582 (defun vhdl-template-if-then-use (kind)
9583 "Insert a sequential if statement."
9584 (interactive)
9585 (let ((margin (current-indentation))
9586 (start (point))
9587 label)
9588 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9589 (vhdl-insert-keyword "IF ")
9590 (vhdl-insert-keyword ": IF ")
9591 (goto-char start)
9592 (setq label (vhdl-template-field "[label]" nil t))
9593 (unless label (delete-char 2))
9594 (forward-word 1)
9595 (forward-char 1))
9596 (when vhdl-conditions-in-parenthesis (insert "("))
9597 (when (vhdl-template-field "condition" nil t start (point))
9598 (when vhdl-conditions-in-parenthesis (insert ")"))
9599 (vhdl-insert-keyword
9600 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9601 (indent-to margin)
9602 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9603 (when label (insert " " label))
9604 (insert ";")
9605 (forward-line -1)
9606 (indent-to (+ margin vhdl-basic-offset)))))
9607
9608 (defun vhdl-template-if-then ()
9609 "Insert a sequential if statement."
9610 (interactive)
9611 (vhdl-template-if-then-use 'then))
9612
9613 (defun vhdl-template-if-use ()
9614 "Insert a simultaneous if statement."
9615 (interactive)
9616 (vhdl-template-if-then-use 'use))
9617
9618 (defun vhdl-template-instance ()
9619 "Insert a component instantiation statement."
9620 (interactive)
9621 (vhdl-template-component-inst))
9622
9623 (defun vhdl-template-library ()
9624 "Insert a library specification."
9625 (interactive)
9626 (let ((margin (current-indentation))
9627 (start (point))
9628 name end-pos)
9629 (vhdl-insert-keyword "LIBRARY ")
9630 (when (setq name (vhdl-template-field "names" nil t start (point)))
9631 (insert ";")
9632 (unless (string-match "," name)
9633 (setq end-pos (point))
9634 (insert "\n")
9635 (indent-to margin)
9636 (vhdl-insert-keyword "USE ")
9637 (insert name)
9638 (vhdl-insert-keyword "..ALL;")
9639 (backward-char 5)
9640 (if (vhdl-template-field "package name")
9641 (forward-char 5)
9642 (delete-region end-pos (+ (point) 5)))))))
9643
9644 (defun vhdl-template-limit ()
9645 "Insert a limit."
9646 (interactive)
9647 (let ((start (point)))
9648 (vhdl-insert-keyword "LIMIT ")
9649 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9650 t start (point))
9651 (vhdl-template-field "type")
9652 (vhdl-insert-keyword " WITH ")
9653 (vhdl-template-field "real expression" ";"))))
9654
9655 (defun vhdl-template-loop ()
9656 "Insert a loop."
9657 (interactive)
9658 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9659 (cond ((eq char ?w)
9660 (vhdl-template-while-loop))
9661 ((eq char ?f)
9662 (vhdl-template-for-loop))
9663 (t (vhdl-template-bare-loop)))))
9664
9665 (defun vhdl-template-bare-loop ()
9666 "Insert a loop."
9667 (interactive)
9668 (let ((margin (current-indentation))
9669 (start (point))
9670 label)
9671 (if (not (eq vhdl-optional-labels 'all))
9672 (vhdl-insert-keyword "LOOP ")
9673 (vhdl-insert-keyword ": LOOP ")
9674 (goto-char start)
9675 (setq label (vhdl-template-field "[label]" nil t))
9676 (unless label (delete-char 2))
9677 (forward-word 1)
9678 (delete-char 1))
9679 (insert "\n\n")
9680 (indent-to margin)
9681 (vhdl-insert-keyword "END LOOP")
9682 (insert (if label (concat " " label ";") ";"))
9683 (forward-line -1)
9684 (indent-to (+ margin vhdl-basic-offset))))
9685
9686 (defun vhdl-template-map (&optional start optional secondary)
9687 "Insert a map specification with association list."
9688 (interactive)
9689 (let ((start (or start (point)))
9690 margin end-pos)
9691 (vhdl-insert-keyword "MAP (")
9692 (if (not vhdl-association-list-with-formals)
9693 (if (vhdl-template-field
9694 (concat (and optional "[") "association list" (and optional "]"))
9695 ")" (or (not secondary) optional)
9696 (and (not secondary) start) (point))
9697 t
9698 (if (and optional secondary) (delete-region start (point)))
9699 nil)
9700 (if vhdl-argument-list-indent
9701 (setq margin (current-column))
9702 (setq margin (+ (current-indentation) vhdl-basic-offset))
9703 (insert "\n")
9704 (indent-to margin))
9705 (if (vhdl-template-field
9706 (concat (and optional "[") "formal" (and optional "]"))
9707 " => " (or (not secondary) optional)
9708 (and (not secondary) start) (point))
9709 (progn
9710 (vhdl-template-field "actual" ",")
9711 (setq end-pos (point))
9712 (insert "\n")
9713 (indent-to margin)
9714 (while (vhdl-template-field "[formal]" " => " t)
9715 (vhdl-template-field "actual" ",")
9716 (setq end-pos (point))
9717 (insert "\n")
9718 (indent-to margin))
9719 (delete-region end-pos (point))
9720 (delete-char -1)
9721 (insert ")")
9722 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9723 t)
9724 (when (and optional secondary) (delete-region start (point)))
9725 nil))))
9726
9727 (defun vhdl-template-modify (&optional noerror)
9728 "Actualize modification date."
9729 (interactive)
9730 (vhdl-prepare-search-2
9731 (save-excursion
9732 (goto-char (point-min))
9733 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9734 (progn (delete-region (point) (progn (end-of-line) (point)))
9735 (vhdl-template-insert-date))
9736 (unless noerror
9737 (error "ERROR: Modification date prefix string \"%s\" not found"
9738 vhdl-modify-date-prefix-string))))))
9739
9740
9741 (defun vhdl-template-modify-noerror ()
9742 "Call `vhdl-template-modify' with NOERROR non-nil."
9743 (vhdl-template-modify t))
9744
9745 (defun vhdl-template-nature ()
9746 "Insert a nature declaration."
9747 (interactive)
9748 (let ((start (point))
9749 name mid-pos end-pos)
9750 (vhdl-insert-keyword "NATURE ")
9751 (when (setq name (vhdl-template-field "name" nil t start (point)))
9752 (vhdl-insert-keyword " IS ")
9753 (let ((definition
9754 (upcase
9755 (or (vhdl-template-field
9756 "across type | ARRAY | RECORD")
9757 ""))))
9758 (cond ((equal definition "")
9759 (insert ";"))
9760 ((equal definition "ARRAY")
9761 (delete-region (point) (progn (forward-word -1) (point)))
9762 (vhdl-template-array 'nature t))
9763 ((equal definition "RECORD")
9764 (setq mid-pos (point-marker))
9765 (delete-region (point) (progn (forward-word -1) (point)))
9766 (vhdl-template-record 'nature name t))
9767 (t
9768 (vhdl-insert-keyword " ACROSS ")
9769 (vhdl-template-field "through type")
9770 (vhdl-insert-keyword " THROUGH ")
9771 (vhdl-template-field "reference name")
9772 (vhdl-insert-keyword " REFERENCE;")))
9773 (when mid-pos
9774 (setq end-pos (point-marker))
9775 (goto-char mid-pos)
9776 (end-of-line))
9777 (vhdl-comment-insert-inline)
9778 (when end-pos (goto-char end-pos))))))
9779
9780 (defun vhdl-template-next ()
9781 "Insert a next statement."
9782 (interactive)
9783 (let ((start (point)))
9784 (vhdl-insert-keyword "NEXT ")
9785 (if (vhdl-template-field "[loop label]" nil t start (point))
9786 (let ((position (point)))
9787 (vhdl-insert-keyword " WHEN ")
9788 (when vhdl-conditions-in-parenthesis (insert "("))
9789 (if (vhdl-template-field "[condition]" nil t)
9790 (when vhdl-conditions-in-parenthesis (insert ")"))
9791 (delete-region position (point))))
9792 (delete-char -1))
9793 (insert ";")))
9794
9795 (defun vhdl-template-others ()
9796 "Insert an others aggregate."
9797 (interactive)
9798 (let ((start (point)))
9799 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9800 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9801 (vhdl-insert-keyword "OTHERS => '")
9802 (when (vhdl-template-field "value" nil t start (point))
9803 (insert "')")))
9804 (vhdl-insert-keyword "OTHERS "))))
9805
9806 (defun vhdl-template-package (&optional kind)
9807 "Insert a package specification or body."
9808 (interactive)
9809 (let ((margin (current-indentation))
9810 (start (point))
9811 name body position)
9812 (vhdl-insert-keyword "PACKAGE ")
9813 (setq body (if kind (eq kind 'body)
9814 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9815 (when body
9816 (vhdl-insert-keyword "BODY ")
9817 (when (save-excursion
9818 (vhdl-prepare-search-1
9819 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9820 (insert (setq name (match-string 1)))))
9821 (when (or name
9822 (setq name (vhdl-template-field "name" nil t start (point))))
9823 (vhdl-insert-keyword " IS\n")
9824 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9825 (indent-to (+ margin vhdl-basic-offset))
9826 (setq position (point))
9827 (insert "\n")
9828 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9829 (indent-to margin)
9830 (vhdl-insert-keyword "END ")
9831 (unless (vhdl-standard-p '87)
9832 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9833 (insert (or name "") ";")
9834 (goto-char position))))
9835
9836 (defun vhdl-template-package-decl ()
9837 "Insert a package specification."
9838 (interactive)
9839 (vhdl-template-package 'decl))
9840
9841 (defun vhdl-template-package-body ()
9842 "Insert a package body."
9843 (interactive)
9844 (vhdl-template-package 'body))
9845
9846 (defun vhdl-template-port ()
9847 "Insert a port declaration, or port map in instantiation statements."
9848 (interactive)
9849 (let ((start (point)))
9850 (vhdl-prepare-search-1
9851 (cond
9852 ((and (save-excursion ; entity declaration
9853 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9854 (equal "ENTITY" (upcase (match-string 1))))
9855 (vhdl-template-port-list nil))
9856 ((or (save-excursion
9857 (or (beginning-of-line)
9858 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9859 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9860 (vhdl-insert-keyword "PORT ")
9861 (vhdl-template-map start))
9862 (t (vhdl-template-port-list nil))))))
9863
9864 (defun vhdl-template-procedural ()
9865 "Insert a procedural."
9866 (interactive)
9867 (let ((margin (current-indentation))
9868 (start (point))
9869 (case-fold-search t)
9870 label)
9871 (vhdl-insert-keyword "PROCEDURAL ")
9872 (when (memq vhdl-optional-labels '(process all))
9873 (goto-char start)
9874 (insert ": ")
9875 (goto-char start)
9876 (setq label (vhdl-template-field "[label]" nil t))
9877 (unless label (delete-char 2))
9878 (forward-word 1)
9879 (forward-char 1))
9880 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9881 (insert "\n")
9882 (vhdl-template-begin-end "PROCEDURAL" label margin)
9883 (vhdl-comment-block)))
9884
9885 (defun vhdl-template-procedure (&optional kind)
9886 "Insert a procedure declaration or body."
9887 (interactive)
9888 (let ((margin (current-indentation))
9889 (start (point))
9890 name)
9891 (vhdl-insert-keyword "PROCEDURE ")
9892 (when (setq name (vhdl-template-field "name" nil t start (point)))
9893 (vhdl-template-argument-list)
9894 (if (if kind (eq kind 'body)
9895 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9896 (progn (vhdl-insert-keyword " IS")
9897 (when vhdl-auto-align
9898 (vhdl-align-region-groups start (point) 1))
9899 (end-of-line) (insert "\n")
9900 (vhdl-template-begin-end
9901 (unless (vhdl-standard-p '87) "PROCEDURE")
9902 name margin)
9903 (vhdl-comment-block))
9904 (insert ";")
9905 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9906 (end-of-line)))))
9907
9908 (defun vhdl-template-procedure-decl ()
9909 "Insert a procedure declaration."
9910 (interactive)
9911 (vhdl-template-procedure 'decl))
9912
9913 (defun vhdl-template-procedure-body ()
9914 "Insert a procedure body."
9915 (interactive)
9916 (vhdl-template-procedure 'body))
9917
9918 (defun vhdl-template-process (&optional kind)
9919 "Insert a process."
9920 (interactive)
9921 (let ((margin (current-indentation))
9922 (start (point))
9923 (reset-kind vhdl-reset-kind)
9924 label seq input-signals clock reset final-pos)
9925 (setq seq (if kind (eq kind 'seq)
9926 (eq (vhdl-decision-query
9927 "process" "(c)ombinational or (s)equential?" t) ?s)))
9928 (vhdl-insert-keyword "PROCESS ")
9929 (when (memq vhdl-optional-labels '(process all))
9930 (goto-char start)
9931 (insert ": ")
9932 (goto-char start)
9933 (setq label (vhdl-template-field "[label]" nil t))
9934 (unless label (delete-char 2))
9935 (forward-word 1)
9936 (forward-char 1))
9937 (insert "(")
9938 (if (not seq)
9939 (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
9940 (progn (insert "all)") (setq input-signals "all")))
9941 (setq input-signals
9942 (vhdl-template-field "[sensitivity list]" ")" t)))
9943 (setq input-signals "")
9944 (delete-char -2))
9945 (setq clock (or (and (not (equal "" vhdl-clock-name))
9946 (progn (insert vhdl-clock-name) vhdl-clock-name))
9947 (vhdl-template-field "clock name") "<clock>"))
9948 (when (eq reset-kind 'query)
9949 (setq reset-kind
9950 (if (eq (vhdl-decision-query
9951 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9952 'async
9953 'sync)))
9954 (when (eq reset-kind 'async)
9955 (insert ", ")
9956 (setq reset (or (and (not (equal "" vhdl-reset-name))
9957 (progn (insert vhdl-reset-name) vhdl-reset-name))
9958 (vhdl-template-field "reset name") "<reset>")))
9959 (insert ")"))
9960 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9961 (insert "\n")
9962 (vhdl-template-begin-end "PROCESS" label margin)
9963 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9964 (when vhdl-prompt-for-comments
9965 (setq final-pos (point-marker))
9966 (vhdl-prepare-search-2
9967 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9968 (vhdl-re-search-backward "\\<process\\>" nil t))
9969 (end-of-line -0)
9970 (if (bobp)
9971 (progn (insert "\n") (forward-line -1))
9972 (insert "\n"))
9973 (indent-to margin)
9974 (insert "-- purpose: ")
9975 (if (not (vhdl-template-field "[description]" nil t))
9976 (vhdl-line-kill-entire)
9977 (insert "\n")
9978 (indent-to margin)
9979 (insert "-- type : ")
9980 (insert (if seq "sequential" "combinational") "\n")
9981 (indent-to margin)
9982 (insert "-- inputs : ")
9983 (if (not seq)
9984 (insert input-signals)
9985 (insert clock ", ")
9986 (when reset (insert reset ", "))
9987 (unless (vhdl-template-field "[signal names]" nil t)
9988 (delete-char -2)))
9989 (insert "\n")
9990 (indent-to margin)
9991 (insert "-- outputs: ")
9992 (vhdl-template-field "[signal names]" nil t))))
9993 (goto-char final-pos))))
9994
9995 (defun vhdl-template-process-comb ()
9996 "Insert a combinational process."
9997 (interactive)
9998 (vhdl-template-process 'comb))
9999
10000 (defun vhdl-template-process-seq ()
10001 "Insert a sequential process."
10002 (interactive)
10003 (vhdl-template-process 'seq))
10004
10005 (defun vhdl-template-quantity ()
10006 "Insert a quantity declaration."
10007 (interactive)
10008 (if (vhdl-in-argument-list-p)
10009 (let ((start (point)))
10010 (vhdl-insert-keyword "QUANTITY ")
10011 (when (vhdl-template-field "names" nil t start (point))
10012 (insert " : ")
10013 (vhdl-template-field "[IN | OUT]" " " t)
10014 (vhdl-template-field "type")
10015 (insert ";")
10016 (vhdl-comment-insert-inline)))
10017 (let ((char (vhdl-decision-query
10018 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
10019 (cond ((eq char ?f) (vhdl-template-quantity-free))
10020 ((eq char ?b) (vhdl-template-quantity-branch))
10021 ((eq char ?s) (vhdl-template-quantity-source))
10022 (t (vhdl-template-undo (point) (point)))))))
10023
10024 (defun vhdl-template-quantity-free ()
10025 "Insert a free quantity declaration."
10026 (interactive)
10027 (vhdl-insert-keyword "QUANTITY ")
10028 (vhdl-template-field "names")
10029 (insert " : ")
10030 (vhdl-template-field "type")
10031 (let ((position (point)))
10032 (insert " := ")
10033 (unless (vhdl-template-field "[initialization]" nil t)
10034 (delete-region position (point)))
10035 (insert ";")
10036 (vhdl-comment-insert-inline)))
10037
10038 (defun vhdl-template-quantity-branch ()
10039 "Insert a branch quantity declaration."
10040 (interactive)
10041 (let (position)
10042 (vhdl-insert-keyword "QUANTITY ")
10043 (when (vhdl-template-field "[across names]" " " t)
10044 (vhdl-insert-keyword "ACROSS "))
10045 (when (vhdl-template-field "[through names]" " " t)
10046 (vhdl-insert-keyword "THROUGH "))
10047 (vhdl-template-field "plus terminal name")
10048 (setq position (point))
10049 (vhdl-insert-keyword " TO ")
10050 (unless (vhdl-template-field "[minus terminal name]" nil t)
10051 (delete-region position (point)))
10052 (insert ";")
10053 (vhdl-comment-insert-inline)))
10054
10055 (defun vhdl-template-quantity-source ()
10056 "Insert a source quantity declaration."
10057 (interactive)
10058 (vhdl-insert-keyword "QUANTITY ")
10059 (vhdl-template-field "names")
10060 (insert " : ")
10061 (vhdl-template-field "type" " ")
10062 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
10063 (progn (vhdl-insert-keyword "NOISE ")
10064 (vhdl-template-field "power expression"))
10065 (vhdl-insert-keyword "SPECTRUM ")
10066 (vhdl-template-field "magnitude expression" ", ")
10067 (vhdl-template-field "phase expression"))
10068 (insert ";")
10069 (vhdl-comment-insert-inline))
10070
10071 (defun vhdl-template-record (kind &optional name secondary)
10072 "Insert a record type declaration."
10073 (interactive)
10074 (let ((margin (current-indentation))
10075 (start (point))
10076 (first t))
10077 (vhdl-insert-keyword "RECORD\n")
10078 (indent-to (+ margin vhdl-basic-offset))
10079 (when (or (vhdl-template-field "element names"
10080 nil (not secondary) start (point))
10081 secondary)
10082 (while (or first (vhdl-template-field "[element names]" nil t))
10083 (insert " : ")
10084 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
10085 (vhdl-comment-insert-inline)
10086 (insert "\n")
10087 (indent-to (+ margin vhdl-basic-offset))
10088 (setq first nil))
10089 (delete-region (line-beginning-position) (point))
10090 (indent-to margin)
10091 (vhdl-insert-keyword "END RECORD")
10092 (unless (vhdl-standard-p '87) (and name (insert " " name)))
10093 (insert ";")
10094 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10095
10096 (defun vhdl-template-report ()
10097 "Insert a report statement."
10098 (interactive)
10099 (let ((start (point)))
10100 (vhdl-insert-keyword "REPORT ")
10101 (if (equal "\"\"" (vhdl-template-field
10102 "string expression" nil t start (point) t))
10103 (delete-char -2)
10104 (setq start (point))
10105 (vhdl-insert-keyword " SEVERITY ")
10106 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
10107 (delete-region start (point)))
10108 (insert ";"))))
10109
10110 (defun vhdl-template-return ()
10111 "Insert a return statement."
10112 (interactive)
10113 (let ((start (point)))
10114 (vhdl-insert-keyword "RETURN ")
10115 (unless (vhdl-template-field "[expression]" nil t start (point))
10116 (delete-char -1))
10117 (insert ";")))
10118
10119 (defun vhdl-template-selected-signal-asst ()
10120 "Insert a selected signal assignment."
10121 (interactive)
10122 (let ((margin (current-indentation))
10123 (start (point))
10124 (choices t))
10125 (let ((position (point)))
10126 (vhdl-insert-keyword " SELECT ")
10127 (goto-char position))
10128 (vhdl-insert-keyword "WITH ")
10129 (when (vhdl-template-field "selector expression"
10130 nil t start (+ (point) 7))
10131 (forward-word 1)
10132 (delete-char 1)
10133 (insert "\n")
10134 (indent-to (+ margin vhdl-basic-offset))
10135 (vhdl-template-field "target signal" " <= ")
10136 (insert "\n")
10137 (indent-to (+ margin vhdl-basic-offset))
10138 (vhdl-template-field "waveform")
10139 (vhdl-insert-keyword " WHEN ")
10140 (vhdl-template-field "choices" ",")
10141 (insert "\n")
10142 (indent-to (+ margin vhdl-basic-offset))
10143 (while (and choices (vhdl-template-field "[waveform]" nil t))
10144 (vhdl-insert-keyword " WHEN ")
10145 (if (setq choices (vhdl-template-field "[choices]" "," t))
10146 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10147 (vhdl-insert-keyword "OTHERS")))
10148 (when choices
10149 (fixup-whitespace)
10150 (delete-char -2))
10151 (insert ";")
10152 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10153
10154 (defun vhdl-template-signal ()
10155 "Insert a signal declaration."
10156 (interactive)
10157 (let ((start (point))
10158 (in-arglist (vhdl-in-argument-list-p)))
10159 (vhdl-insert-keyword "SIGNAL ")
10160 (when (vhdl-template-field "names" nil t start (point))
10161 (insert " : ")
10162 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10163 (vhdl-template-field "type")
10164 (if in-arglist
10165 (progn (insert ";")
10166 (vhdl-comment-insert-inline))
10167 (let ((position (point)))
10168 (insert " := ")
10169 (unless (vhdl-template-field "[initialization]" nil t)
10170 (delete-region position (point)))
10171 (insert ";")
10172 (vhdl-comment-insert-inline))))))
10173
10174 (defun vhdl-template-subnature ()
10175 "Insert a subnature declaration."
10176 (interactive)
10177 (let ((start (point))
10178 position)
10179 (vhdl-insert-keyword "SUBNATURE ")
10180 (when (vhdl-template-field "name" nil t start (point))
10181 (vhdl-insert-keyword " IS ")
10182 (vhdl-template-field "nature" " (")
10183 (if (vhdl-template-field "[index range]" nil t)
10184 (insert ")")
10185 (delete-char -2))
10186 (setq position (point))
10187 (vhdl-insert-keyword " TOLERANCE ")
10188 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10189 nil t nil nil t))
10190 (delete-region position (point))
10191 (vhdl-insert-keyword " ACROSS ")
10192 (vhdl-template-field "string expression" nil nil nil nil t)
10193 (vhdl-insert-keyword " THROUGH"))
10194 (insert ";")
10195 (vhdl-comment-insert-inline))))
10196
10197 (defun vhdl-template-subprogram-body ()
10198 "Insert a subprogram body."
10199 (interactive)
10200 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10201 (vhdl-template-function-body)
10202 (vhdl-template-procedure-body)))
10203
10204 (defun vhdl-template-subprogram-decl ()
10205 "Insert a subprogram declaration."
10206 (interactive)
10207 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10208 (vhdl-template-function-decl)
10209 (vhdl-template-procedure-decl)))
10210
10211 (defun vhdl-template-subtype ()
10212 "Insert a subtype declaration."
10213 (interactive)
10214 (let ((start (point)))
10215 (vhdl-insert-keyword "SUBTYPE ")
10216 (when (vhdl-template-field "name" nil t start (point))
10217 (vhdl-insert-keyword " IS ")
10218 (vhdl-template-field "type" " ")
10219 (unless
10220 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10221 (delete-char -1))
10222 (insert ";")
10223 (vhdl-comment-insert-inline))))
10224
10225 (defun vhdl-template-terminal ()
10226 "Insert a terminal declaration."
10227 (interactive)
10228 (let ((start (point)))
10229 (vhdl-insert-keyword "TERMINAL ")
10230 (when (vhdl-template-field "names" nil t start (point))
10231 (insert " : ")
10232 (vhdl-template-field "nature")
10233 (insert ";")
10234 (vhdl-comment-insert-inline))))
10235
10236 (defun vhdl-template-type ()
10237 "Insert a type declaration."
10238 (interactive)
10239 (let ((start (point))
10240 name mid-pos end-pos)
10241 (vhdl-insert-keyword "TYPE ")
10242 (when (setq name (vhdl-template-field "name" nil t start (point)))
10243 (vhdl-insert-keyword " IS ")
10244 (let ((definition
10245 (upcase
10246 (or (vhdl-template-field
10247 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10248 ""))))
10249 (cond ((equal definition "")
10250 (delete-char -4)
10251 (insert ";"))
10252 ((equal definition "ARRAY")
10253 (delete-region (point) (progn (forward-word -1) (point)))
10254 (vhdl-template-array 'type t))
10255 ((equal definition "RECORD")
10256 (setq mid-pos (point-marker))
10257 (delete-region (point) (progn (forward-word -1) (point)))
10258 (vhdl-template-record 'type name t))
10259 ((equal definition "ACCESS")
10260 (insert " ")
10261 (vhdl-template-field "type" ";"))
10262 ((equal definition "FILE")
10263 (vhdl-insert-keyword " OF ")
10264 (vhdl-template-field "type" ";"))
10265 ((equal definition "ENUM")
10266 (kill-word -1)
10267 (insert "(")
10268 (setq end-pos (point-marker))
10269 (insert ");"))
10270 (t (insert ";")))
10271 (when mid-pos
10272 (setq end-pos (point-marker))
10273 (goto-char mid-pos)
10274 (end-of-line))
10275 (vhdl-comment-insert-inline)
10276 (when end-pos (goto-char end-pos))))))
10277
10278 (defun vhdl-template-use ()
10279 "Insert a use clause."
10280 (interactive)
10281 (let ((start (point)))
10282 (vhdl-prepare-search-1
10283 (vhdl-insert-keyword "USE ")
10284 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10285 (vhdl-insert-keyword "..ALL;")
10286 (backward-char 6)
10287 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10288 (forward-char 1)
10289 (vhdl-template-field "package name")
10290 (forward-char 5))))))
10291
10292 (defun vhdl-template-variable ()
10293 "Insert a variable declaration."
10294 (interactive)
10295 (let ((start (point))
10296 (in-arglist (vhdl-in-argument-list-p)))
10297 (vhdl-prepare-search-2
10298 (if (or (save-excursion
10299 (progn (vhdl-beginning-of-block)
10300 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10301 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
10302 (vhdl-insert-keyword "VARIABLE ")
10303 (if (vhdl-standard-p '87)
10304 (error "ERROR: Not within sequential block")
10305 (vhdl-insert-keyword "SHARED VARIABLE "))))
10306 (when (vhdl-template-field "names" nil t start (point))
10307 (insert " : ")
10308 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10309 (vhdl-template-field "type")
10310 (if in-arglist
10311 (progn (insert ";")
10312 (vhdl-comment-insert-inline))
10313 (let ((position (point)))
10314 (insert " := ")
10315 (unless (vhdl-template-field "[initialization]" nil t)
10316 (delete-region position (point)))
10317 (insert ";")
10318 (vhdl-comment-insert-inline))))))
10319
10320 (defun vhdl-template-wait ()
10321 "Insert a wait statement."
10322 (interactive)
10323 (vhdl-insert-keyword "WAIT ")
10324 (unless (vhdl-template-field
10325 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10326 nil t)
10327 (delete-char -1))
10328 (insert ";"))
10329
10330 (defun vhdl-template-when ()
10331 "Indent correctly if within a case statement."
10332 (interactive)
10333 (let ((position (point))
10334 margin)
10335 (vhdl-prepare-search-2
10336 (if (and (= (current-column) (current-indentation))
10337 (vhdl-re-search-forward "\\<end\\>" nil t)
10338 (looking-at "\\s-*\\<case\\>"))
10339 (progn
10340 (setq margin (current-indentation))
10341 (goto-char position)
10342 (delete-horizontal-space)
10343 (indent-to (+ margin vhdl-basic-offset)))
10344 (goto-char position)))
10345 (vhdl-insert-keyword "WHEN ")))
10346
10347 (defun vhdl-template-while-loop ()
10348 "Insert a while loop."
10349 (interactive)
10350 (let* ((margin (current-indentation))
10351 (start (point))
10352 label)
10353 (if (not (eq vhdl-optional-labels 'all))
10354 (vhdl-insert-keyword "WHILE ")
10355 (vhdl-insert-keyword ": WHILE ")
10356 (goto-char start)
10357 (setq label (vhdl-template-field "[label]" nil t))
10358 (unless label (delete-char 2))
10359 (forward-word 1)
10360 (forward-char 1))
10361 (when vhdl-conditions-in-parenthesis (insert "("))
10362 (when (vhdl-template-field "condition" nil t start (point))
10363 (when vhdl-conditions-in-parenthesis (insert ")"))
10364 (vhdl-insert-keyword " LOOP\n\n")
10365 (indent-to margin)
10366 (vhdl-insert-keyword "END LOOP")
10367 (insert (if label (concat " " label ";") ";"))
10368 (forward-line -1)
10369 (indent-to (+ margin vhdl-basic-offset)))))
10370
10371 (defun vhdl-template-with ()
10372 "Insert a with statement (i.e. selected signal assignment)."
10373 (interactive)
10374 (vhdl-prepare-search-1
10375 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10376 (equal ";" (match-string 1)))
10377 (vhdl-template-selected-signal-asst)
10378 (vhdl-insert-keyword "WITH "))))
10379
10380 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10381 ;; Special templates
10382
10383 (defun vhdl-template-clocked-wait ()
10384 "Insert a wait statement for rising/falling clock edge."
10385 (interactive)
10386 (let ((start (point))
10387 clock)
10388 (vhdl-insert-keyword "WAIT UNTIL ")
10389 (when (setq clock
10390 (or (and (not (equal "" vhdl-clock-name))
10391 (progn (insert vhdl-clock-name) vhdl-clock-name))
10392 (vhdl-template-field "clock name" nil t start (point))))
10393 (insert "'event")
10394 (vhdl-insert-keyword " AND ")
10395 (insert clock)
10396 (insert
10397 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10398 (vhdl-comment-insert-inline
10399 (concat (if vhdl-clock-rising-edge "rising" "falling")
10400 " clock edge")))))
10401
10402 (defun vhdl-template-seq-process (clock reset reset-kind)
10403 "Insert a template for the body of a sequential process."
10404 (let ((margin (current-indentation))
10405 position)
10406 (vhdl-insert-keyword "IF ")
10407 (when vhdl-conditions-in-parenthesis (insert "("))
10408 (when (eq reset-kind 'async)
10409 (insert reset " = "
10410 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10411 (when vhdl-conditions-in-parenthesis (insert ")"))
10412 (vhdl-insert-keyword " THEN")
10413 (vhdl-comment-insert-inline
10414 (concat "asynchronous reset (active "
10415 (if vhdl-reset-active-high "high" "low") ")"))
10416 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10417 (setq position (point))
10418 (insert "\n") (indent-to margin)
10419 (vhdl-insert-keyword "ELSIF ")
10420 (when vhdl-conditions-in-parenthesis (insert "(")))
10421 (if (eq vhdl-clock-edge-condition 'function)
10422 (insert (if vhdl-clock-rising-edge "rising" "falling")
10423 "_edge(" clock ")")
10424 (insert clock "'event")
10425 (vhdl-insert-keyword " AND ")
10426 (insert clock " = "
10427 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10428 (when vhdl-conditions-in-parenthesis (insert ")"))
10429 (vhdl-insert-keyword " THEN")
10430 (vhdl-comment-insert-inline
10431 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10432 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10433 (when (eq reset-kind 'sync)
10434 (vhdl-insert-keyword "IF ")
10435 (when vhdl-conditions-in-parenthesis (insert "("))
10436 (setq reset (or (and (not (equal "" vhdl-reset-name))
10437 (progn (insert vhdl-reset-name) vhdl-reset-name))
10438 (vhdl-template-field "reset name") "<reset>"))
10439 (insert " = "
10440 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10441 (when vhdl-conditions-in-parenthesis (insert ")"))
10442 (vhdl-insert-keyword " THEN")
10443 (vhdl-comment-insert-inline
10444 (concat "synchronous reset (active "
10445 (if vhdl-reset-active-high "high" "low") ")"))
10446 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10447 (setq position (point))
10448 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10449 (vhdl-insert-keyword "ELSE")
10450 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10451 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10452 (vhdl-insert-keyword "END IF;"))
10453 (when (eq reset-kind 'none)
10454 (setq position (point)))
10455 (insert "\n") (indent-to margin)
10456 (vhdl-insert-keyword "END IF;")
10457 (goto-char position)
10458 reset))
10459
10460 (defun vhdl-template-standard-package (library package)
10461 "Insert specification of a standard package. Include a library
10462 specification, if not already there."
10463 (let ((margin (current-indentation)))
10464 (unless (equal library "std")
10465 (unless (or (save-excursion
10466 (vhdl-prepare-search-1
10467 (and (not (bobp))
10468 (re-search-backward
10469 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10470 library "\\|end\\)\\>") nil t)
10471 (match-string 2))))
10472 (equal (downcase library) "work"))
10473 (vhdl-insert-keyword "LIBRARY ")
10474 (insert library ";")
10475 (when package
10476 (insert "\n")
10477 (indent-to margin))))
10478 (when package
10479 (vhdl-insert-keyword "USE ")
10480 (insert library "." package)
10481 (vhdl-insert-keyword ".ALL;"))))
10482
10483 (defun vhdl-template-package-numeric-bit ()
10484 "Insert specification of `numeric_bit' package."
10485 (interactive)
10486 (vhdl-template-standard-package "ieee" "numeric_bit"))
10487
10488 (defun vhdl-template-package-numeric-std ()
10489 "Insert specification of `numeric_std' package."
10490 (interactive)
10491 (vhdl-template-standard-package "ieee" "numeric_std"))
10492
10493 (defun vhdl-template-package-std-logic-1164 ()
10494 "Insert specification of `std_logic_1164' package."
10495 (interactive)
10496 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10497
10498 (defun vhdl-template-package-std-logic-arith ()
10499 "Insert specification of `std_logic_arith' package."
10500 (interactive)
10501 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10502
10503 (defun vhdl-template-package-std-logic-misc ()
10504 "Insert specification of `std_logic_misc' package."
10505 (interactive)
10506 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10507
10508 (defun vhdl-template-package-std-logic-signed ()
10509 "Insert specification of `std_logic_signed' package."
10510 (interactive)
10511 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10512
10513 (defun vhdl-template-package-std-logic-textio ()
10514 "Insert specification of `std_logic_textio' package."
10515 (interactive)
10516 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10517
10518 (defun vhdl-template-package-std-logic-unsigned ()
10519 "Insert specification of `std_logic_unsigned' package."
10520 (interactive)
10521 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10522
10523 (defun vhdl-template-package-textio ()
10524 "Insert specification of `textio' package."
10525 (interactive)
10526 (vhdl-template-standard-package "std" "textio"))
10527
10528 (defun vhdl-template-package-fundamental-constants ()
10529 "Insert specification of `fundamental_constants' package."
10530 (interactive)
10531 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10532
10533 (defun vhdl-template-package-material-constants ()
10534 "Insert specification of `material_constants' package."
10535 (interactive)
10536 (vhdl-template-standard-package "ieee" "material_constants"))
10537
10538 (defun vhdl-template-package-energy-systems ()
10539 "Insert specification of `energy_systems' package."
10540 (interactive)
10541 (vhdl-template-standard-package "ieee" "energy_systems"))
10542
10543 (defun vhdl-template-package-electrical-systems ()
10544 "Insert specification of `electrical_systems' package."
10545 (interactive)
10546 (vhdl-template-standard-package "ieee" "electrical_systems"))
10547
10548 (defun vhdl-template-package-mechanical-systems ()
10549 "Insert specification of `mechanical_systems' package."
10550 (interactive)
10551 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10552
10553 (defun vhdl-template-package-radiant-systems ()
10554 "Insert specification of `radiant_systems' package."
10555 (interactive)
10556 (vhdl-template-standard-package "ieee" "radiant_systems"))
10557
10558 (defun vhdl-template-package-thermal-systems ()
10559 "Insert specification of `thermal_systems' package."
10560 (interactive)
10561 (vhdl-template-standard-package "ieee" "thermal_systems"))
10562
10563 (defun vhdl-template-package-fluidic-systems ()
10564 "Insert specification of `fluidic_systems' package."
10565 (interactive)
10566 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10567
10568 (defun vhdl-template-package-math-complex ()
10569 "Insert specification of `math_complex' package."
10570 (interactive)
10571 (vhdl-template-standard-package "ieee" "math_complex"))
10572
10573 (defun vhdl-template-package-math-real ()
10574 "Insert specification of `math_real' package."
10575 (interactive)
10576 (vhdl-template-standard-package "ieee" "math_real"))
10577
10578 (defun vhdl-template-directive (directive)
10579 "Insert directive."
10580 (unless (= (current-indentation) (current-column))
10581 (delete-horizontal-space)
10582 (insert " "))
10583 (insert "-- pragma " directive))
10584
10585 (defun vhdl-template-directive-translate-on ()
10586 "Insert directive `translate_on'."
10587 (interactive)
10588 (vhdl-template-directive "translate_on"))
10589
10590 (defun vhdl-template-directive-translate-off ()
10591 "Insert directive `translate_off'."
10592 (interactive)
10593 (vhdl-template-directive "translate_off"))
10594
10595 (defun vhdl-template-directive-synthesis-on ()
10596 "Insert directive `synthesis_on'."
10597 (interactive)
10598 (vhdl-template-directive "synthesis_on"))
10599
10600 (defun vhdl-template-directive-synthesis-off ()
10601 "Insert directive `synthesis_off'."
10602 (interactive)
10603 (vhdl-template-directive "synthesis_off"))
10604
10605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10606 ;; Header and footer templates
10607
10608 (defun vhdl-template-header (&optional file-title)
10609 "Insert a VHDL file header."
10610 (interactive)
10611 (unless (equal vhdl-file-header "")
10612 (let (pos)
10613 (save-excursion
10614 (goto-char (point-min))
10615 (vhdl-insert-string-or-file vhdl-file-header)
10616 (setq pos (point-marker)))
10617 (vhdl-template-replace-header-keywords
10618 (point-min-marker) pos file-title))))
10619
10620 (defun vhdl-template-footer ()
10621 "Insert a VHDL file footer."
10622 (interactive)
10623 (unless (equal vhdl-file-footer "")
10624 (let (pos)
10625 (save-excursion
10626 (goto-char (point-max))
10627 (setq pos (point-marker))
10628 (vhdl-insert-string-or-file vhdl-file-footer)
10629 (unless (= (preceding-char) ?\n)
10630 (insert "\n")))
10631 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10632
10633 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10634 is-model)
10635 "Replace keywords in header and footer."
10636 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10637 ""))
10638 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10639 ""))
10640 pos)
10641 (vhdl-prepare-search-2
10642 (save-excursion
10643 (goto-char beg)
10644 (while (search-forward "<projectdesc>" end t)
10645 (replace-match project-desc t t))
10646 (goto-char beg)
10647 (while (search-forward "<filename>" end t)
10648 (replace-match (buffer-name) t t))
10649 (goto-char beg)
10650 (while (search-forward "<copyright>" end t)
10651 (replace-match vhdl-copyright-string t t))
10652 (goto-char beg)
10653 (while (search-forward "<author>" end t)
10654 (replace-match "" t t)
10655 (insert (user-full-name))
10656 (when user-mail-address (insert " <" user-mail-address ">")))
10657 (goto-char beg)
10658 (while (search-forward "<authorfull>" end t)
10659 (replace-match (user-full-name) t t))
10660 (goto-char beg)
10661 (while (search-forward "<login>" end t)
10662 (replace-match (user-login-name) t t))
10663 (goto-char beg)
10664 (while (search-forward "<project>" end t)
10665 (replace-match project-title t t))
10666 (goto-char beg)
10667 (while (search-forward "<company>" end t)
10668 (replace-match vhdl-company-name t t))
10669 (goto-char beg)
10670 (while (search-forward "<platform>" end t)
10671 (replace-match vhdl-platform-spec t t))
10672 (goto-char beg)
10673 (while (search-forward "<standard>" end t)
10674 (replace-match
10675 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10676 ((vhdl-standard-p '93) "'93/02")
10677 ((vhdl-standard-p '08) "'08"))
10678 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10679 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10680 (goto-char beg)
10681 ;; Replace <RCS> with $, so that RCS for the source is
10682 ;; not over-enthusiastic with replacements
10683 (while (search-forward "<RCS>" end t)
10684 (replace-match "$" nil t))
10685 (goto-char beg)
10686 (while (search-forward "<date>" end t)
10687 (replace-match "" t t)
10688 (vhdl-template-insert-date))
10689 (goto-char beg)
10690 (while (search-forward "<year>" end t)
10691 (replace-match (format-time-string "%Y" nil) t t))
10692 (goto-char beg)
10693 (when file-title
10694 (while (search-forward "<title string>" end t)
10695 (replace-match file-title t t))
10696 (goto-char beg))
10697 (let (string)
10698 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10699 (save-match-data
10700 (setq string (read-string (concat (match-string 1) ": "))))
10701 (replace-match string t t)))
10702 (goto-char beg)
10703 (when (and (not is-model) (search-forward "<cursor>" end t))
10704 (replace-match "" t t)
10705 (setq pos (point))))
10706 (when pos (goto-char pos))
10707 (unless is-model
10708 (when (or (not project-title) (equal project-title ""))
10709 (message "You can specify a project title in user option `vhdl-project-alist'"))
10710 (when (or (not project-desc) (equal project-desc ""))
10711 (message "You can specify a project description in user option `vhdl-project-alist'"))
10712 (when (equal vhdl-platform-spec "")
10713 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10714 (when (equal vhdl-company-name "")
10715 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10716
10717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10718 ;; Comment templates and functions
10719
10720 (defun vhdl-comment-indent ()
10721 "Indent comments."
10722 (let* ((position (point))
10723 (col
10724 (progn
10725 (forward-line -1)
10726 (if (re-search-forward "--" position t)
10727 (- (current-column) 2) ; existing comment at bol stays there
10728 (goto-char position)
10729 (skip-chars-backward " \t")
10730 (max comment-column ; else indent to comment column
10731 (1+ (current-column))))))) ; except leave at least one space
10732 (goto-char position)
10733 col))
10734
10735 (defun vhdl-comment-insert ()
10736 "Start a comment at the end of the line.
10737 If on line with code, indent at least `comment-column'.
10738 If starting after end-comment-column, start a new line."
10739 (interactive)
10740 (when (> (current-column) end-comment-column) (newline-and-indent))
10741 (if (or (looking-at "\\s-*$") ; end of line
10742 (and (not unread-command-events) ; called with key binding or menu
10743 (not (end-of-line))))
10744 (let (margin)
10745 (while (= (preceding-char) ?-) (delete-char -1))
10746 (setq margin (current-column))
10747 (delete-horizontal-space)
10748 (if (bolp)
10749 (progn (indent-to margin) (insert "--"))
10750 (insert " ")
10751 (indent-to comment-column)
10752 (insert "--"))
10753 (if (not unread-command-events) (insert " ")))
10754 ;; else code following current point implies commenting out code
10755 (let (next-input code)
10756 (while (= (preceding-char) ?-) (delete-char -2))
10757 (while (= (setq next-input (read-char)) 13) ; CR
10758 (insert "--") ; or have a space after it?
10759 (forward-char -2)
10760 (forward-line 1)
10761 (message "Enter CR if commenting out a line of code.")
10762 (setq code t))
10763 (unless code
10764 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10765 (push (vhdl-character-to-event next-input) ; pushback the char
10766 unread-command-events))))
10767
10768 (defun vhdl-comment-display (&optional line-exists)
10769 "Add 2 comment lines at the current indent, making a display comment."
10770 (interactive)
10771 (let ((margin (current-indentation)))
10772 (unless line-exists (vhdl-comment-display-line))
10773 (insert "\n") (indent-to margin)
10774 (insert "\n") (indent-to margin)
10775 (vhdl-comment-display-line)
10776 (end-of-line -0)
10777 (insert "-- ")))
10778
10779 (defun vhdl-comment-display-line ()
10780 "Displays one line of dashes."
10781 (interactive)
10782 (while (= (preceding-char) ?-) (delete-char -2))
10783 (insert "--")
10784 (let* ((col (current-column))
10785 (len (- end-comment-column col)))
10786 (insert-char vhdl-comment-display-line-char len)))
10787
10788 (defun vhdl-comment-append-inline ()
10789 "Append empty inline comment to current line."
10790 (interactive)
10791 (end-of-line)
10792 (delete-horizontal-space)
10793 (insert " ")
10794 (indent-to comment-column)
10795 (insert "-- "))
10796
10797 (defun vhdl-comment-insert-inline (&optional string always-insert)
10798 "Insert inline comment."
10799 (when (or (and string (or vhdl-self-insert-comments always-insert))
10800 (and (not string) vhdl-prompt-for-comments))
10801 (let ((position (point)))
10802 (insert " ")
10803 (indent-to comment-column)
10804 (insert "-- ")
10805 (if (not (or (and string (progn (insert string) t))
10806 (vhdl-template-field "[comment]" nil t)))
10807 (delete-region position (point))
10808 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10809
10810 (defun vhdl-comment-block ()
10811 "Insert comment for code block."
10812 (when vhdl-prompt-for-comments
10813 (let ((final-pos (point-marker)))
10814 (vhdl-prepare-search-2
10815 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10816 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10817 (let (margin)
10818 (back-to-indentation)
10819 (setq margin (current-column))
10820 (end-of-line -0)
10821 (if (bobp)
10822 (progn (insert "\n") (forward-line -1))
10823 (insert "\n"))
10824 (indent-to margin)
10825 (insert "-- purpose: ")
10826 (unless (vhdl-template-field "[description]" nil t)
10827 (vhdl-line-kill-entire)))))
10828 (goto-char final-pos))))
10829
10830 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10831 "Comment out region if not commented out, uncomment otherwise."
10832 (interactive "r\nP")
10833 (save-excursion
10834 (goto-char (1- end))
10835 (end-of-line)
10836 (setq end (point-marker))
10837 (goto-char beg)
10838 (beginning-of-line)
10839 (setq beg (point))
10840 (if (looking-at (concat "\\s-*" comment-start))
10841 (comment-region beg end '(4))
10842 (comment-region beg end))))
10843
10844 (defun vhdl-comment-uncomment-line (&optional arg)
10845 "Comment out line if not commented out, uncomment otherwise."
10846 (interactive "p")
10847 (save-excursion
10848 (beginning-of-line)
10849 (let ((position (point)))
10850 (forward-line (or arg 1))
10851 (vhdl-comment-uncomment-region position (point)))))
10852
10853 (defun vhdl-comment-kill-region (beg end)
10854 "Kill comments in region."
10855 (interactive "r")
10856 (save-excursion
10857 (goto-char end)
10858 (setq end (point-marker))
10859 (goto-char beg)
10860 (beginning-of-line)
10861 (while (< (point) end)
10862 (if (looking-at "^\\(\\s-*--.*\n\\)")
10863 (progn (delete-region (match-beginning 1) (match-end 1)))
10864 (beginning-of-line 2)))))
10865
10866 (defun vhdl-comment-kill-inline-region (beg end)
10867 "Kill inline comments in region."
10868 (interactive "r")
10869 (save-excursion
10870 (goto-char end)
10871 (setq end (point-marker))
10872 (goto-char beg)
10873 (beginning-of-line)
10874 (while (< (point) end)
10875 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10876 (delete-region (match-beginning 1) (match-end 1)))
10877 (beginning-of-line 2))))
10878
10879 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10880 ;; Subtemplates
10881
10882 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10883 "Insert a begin ... end pair with optional name after the end.
10884 Point is left between them."
10885 (let (position)
10886 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10887 (indent-to margin)
10888 (vhdl-insert-keyword "BEGIN")
10889 (when (and (or construct name) vhdl-self-insert-comments)
10890 (insert " --")
10891 (when construct (insert " ") (vhdl-insert-keyword construct))
10892 (when name (insert " " name)))
10893 (insert "\n")
10894 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10895 (indent-to (+ margin vhdl-basic-offset))
10896 (setq position (point))
10897 (insert "\n")
10898 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10899 (indent-to margin)
10900 (vhdl-insert-keyword "END")
10901 (when construct (insert " ") (vhdl-insert-keyword construct))
10902 (insert (if name (concat " " name) "") ";")
10903 (goto-char position)))
10904
10905 (defun vhdl-template-argument-list (&optional is-function)
10906 "Read from user a procedure or function argument list."
10907 (insert " (")
10908 (let ((margin (current-column))
10909 (start (point))
10910 (end-pos (point))
10911 not-empty interface semicolon-pos)
10912 (unless vhdl-argument-list-indent
10913 (setq margin (+ (current-indentation) vhdl-basic-offset))
10914 (insert "\n")
10915 (indent-to margin))
10916 (setq interface (vhdl-template-field
10917 (concat "[CONSTANT | SIGNAL"
10918 (unless is-function " | VARIABLE") "]") " " t))
10919 (while (vhdl-template-field "[names]" nil t)
10920 (setq not-empty t)
10921 (insert " : ")
10922 (unless is-function
10923 (if (and interface (equal (upcase interface) "CONSTANT"))
10924 (vhdl-insert-keyword "IN ")
10925 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10926 (vhdl-template-field "type")
10927 (setq semicolon-pos (point))
10928 (insert ";")
10929 (vhdl-comment-insert-inline)
10930 (setq end-pos (point))
10931 (insert "\n")
10932 (indent-to margin)
10933 (setq interface (vhdl-template-field
10934 (concat "[CONSTANT | SIGNAL"
10935 (unless is-function " | VARIABLE") "]") " " t)))
10936 (delete-region end-pos (point))
10937 (when semicolon-pos (goto-char semicolon-pos))
10938 (if not-empty
10939 (progn (delete-char 1) (insert ")"))
10940 (delete-char -2))))
10941
10942 (defun vhdl-template-generic-list (optional &optional no-value)
10943 "Read from user a generic spec argument list."
10944 (let (margin
10945 (start (point)))
10946 (vhdl-insert-keyword "GENERIC (")
10947 (setq margin (current-column))
10948 (unless vhdl-argument-list-indent
10949 (let ((position (point)))
10950 (back-to-indentation)
10951 (setq margin (+ (current-column) vhdl-basic-offset))
10952 (goto-char position)
10953 (insert "\n")
10954 (indent-to margin)))
10955 (let ((vhdl-generics (vhdl-template-field
10956 (concat (and optional "[") "name"
10957 (and no-value "s") (and optional "]"))
10958 nil optional)))
10959 (if (not vhdl-generics)
10960 (if optional
10961 (progn (vhdl-line-kill-entire) (end-of-line -0)
10962 (unless vhdl-argument-list-indent
10963 (vhdl-line-kill-entire) (end-of-line -0)))
10964 (vhdl-template-undo start (point))
10965 nil )
10966 (insert " : ")
10967 (let (semicolon-pos end-pos)
10968 (while vhdl-generics
10969 (vhdl-template-field "type")
10970 (if no-value
10971 (progn (setq semicolon-pos (point))
10972 (insert ";"))
10973 (insert " := ")
10974 (unless (vhdl-template-field "[value]" nil t)
10975 (delete-char -4))
10976 (setq semicolon-pos (point))
10977 (insert ";"))
10978 (vhdl-comment-insert-inline)
10979 (setq end-pos (point))
10980 (insert "\n")
10981 (indent-to margin)
10982 (setq vhdl-generics (vhdl-template-field
10983 (concat "[name" (and no-value "s") "]")
10984 " : " t)))
10985 (delete-region end-pos (point))
10986 (goto-char semicolon-pos)
10987 (insert ")")
10988 (end-of-line)
10989 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10990 t)))))
10991
10992 (defun vhdl-template-port-list (optional)
10993 "Read from user a port spec argument list."
10994 (let ((start (point))
10995 margin vhdl-ports object)
10996 (vhdl-insert-keyword "PORT (")
10997 (setq margin (current-column))
10998 (unless vhdl-argument-list-indent
10999 (let ((position (point)))
11000 (back-to-indentation)
11001 (setq margin (+ (current-column) vhdl-basic-offset))
11002 (goto-char position)
11003 (insert "\n")
11004 (indent-to margin)))
11005 (when (vhdl-standard-p 'ams)
11006 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11007 " " t)))
11008 (setq vhdl-ports (vhdl-template-field
11009 (concat (and optional "[") "names" (and optional "]"))
11010 nil optional))
11011 (if (not vhdl-ports)
11012 (if optional
11013 (progn (vhdl-line-kill-entire) (end-of-line -0)
11014 (unless vhdl-argument-list-indent
11015 (vhdl-line-kill-entire) (end-of-line -0)))
11016 (vhdl-template-undo start (point))
11017 nil)
11018 (insert " : ")
11019 (let (semicolon-pos end-pos)
11020 (while vhdl-ports
11021 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
11022 (vhdl-template-field "IN | OUT | INOUT" " "))
11023 ((equal "QUANTITY" (upcase object))
11024 (vhdl-template-field "[IN | OUT]" " " t)))
11025 (vhdl-template-field
11026 (if (and object (equal "TERMINAL" (upcase object)))
11027 "nature" "type"))
11028 (setq semicolon-pos (point))
11029 (insert ";")
11030 (vhdl-comment-insert-inline)
11031 (setq end-pos (point))
11032 (insert "\n")
11033 (indent-to margin)
11034 (when (vhdl-standard-p 'ams)
11035 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11036 " " t)))
11037 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
11038 (delete-region end-pos (point))
11039 (goto-char semicolon-pos)
11040 (insert ")")
11041 (end-of-line)
11042 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
11043 t))))
11044
11045 (defun vhdl-template-generate-body (margin label)
11046 "Insert body for generate template."
11047 (vhdl-insert-keyword " GENERATE")
11048 (insert "\n\n")
11049 (indent-to margin)
11050 (vhdl-insert-keyword "END GENERATE ")
11051 (insert label ";")
11052 (end-of-line 0)
11053 (indent-to (+ margin vhdl-basic-offset)))
11054
11055 (defun vhdl-template-insert-date ()
11056 "Insert date in appropriate format."
11057 (interactive)
11058 (insert
11059 (cond
11060 ;; 'american, 'european, 'scientific kept for backward compatibility
11061 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
11062 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
11063 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
11064 (t (format-time-string vhdl-date-format nil)))))
11065
11066 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11067 ;; Help functions
11068
11069 (defun vhdl-electric-space (count)
11070 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
11071 if in comment and past end-comment-column."
11072 (interactive "p")
11073 (cond ((vhdl-in-comment-p)
11074 (self-insert-command count)
11075 (cond ((>= (current-column) (+ 2 end-comment-column))
11076 (backward-char 1)
11077 (skip-chars-backward "^ \t\n\r\f")
11078 (indent-new-comment-line)
11079 (skip-chars-forward "^ \t\n\r\f")
11080 (forward-char 1))
11081 ((>= (current-column) end-comment-column)
11082 (indent-new-comment-line))
11083 (t nil)))
11084 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
11085 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
11086 (vhdl-prepare-search-1
11087 (or (expand-abbrev) (vhdl-fix-case-word -1)))
11088 (self-insert-command count))
11089 (t (self-insert-command count))))
11090
11091 (defun vhdl-template-field (prompt &optional follow-string optional
11092 begin end is-string default)
11093 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
11094 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
11095 an empty string is inserted, return nil and call `vhdl-template-undo' for
11096 the region between BEGIN and END. IS-STRING indicates whether a string
11097 with double-quotes is to be inserted. DEFAULT specifies a default string."
11098 (let ((position (point))
11099 string)
11100 (insert "<" prompt ">")
11101 (setq string
11102 (condition-case ()
11103 (read-from-minibuffer (concat prompt ": ")
11104 (or (and is-string '("\"\"" . 2)) default)
11105 vhdl-minibuffer-local-map)
11106 (quit (if (and optional begin end)
11107 (progn (beep) "")
11108 (keyboard-quit)))))
11109 (when (or (not (equal string "")) optional)
11110 (delete-region position (point)))
11111 (when (and (equal string "") optional begin end)
11112 (vhdl-template-undo begin end)
11113 (message "Template aborted"))
11114 (unless (equal string "")
11115 (insert string)
11116 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
11117 vhdl-keywords-regexp)
11118 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
11119 vhdl-types-regexp)
11120 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
11121 (concat "'" vhdl-attributes-regexp))
11122 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
11123 vhdl-enum-values-regexp)
11124 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
11125 vhdl-constants-regexp))
11126 (when (or (not (equal string "")) (not optional))
11127 (insert (or follow-string "")))
11128 (if (equal string "") nil string)))
11129
11130 (defun vhdl-decision-query (string prompt &optional optional)
11131 "Query a decision from the user."
11132 (let ((start (point)))
11133 (when string (vhdl-insert-keyword (concat string " ")))
11134 (message "%s" (or prompt ""))
11135 (let ((char (read-char)))
11136 (delete-region start (point))
11137 (if (and optional (eq char ?\r))
11138 (progn (insert " ")
11139 (unexpand-abbrev)
11140 (throw 'abort "ERROR: Template aborted"))
11141 char))))
11142
11143 (defun vhdl-insert-keyword (keyword)
11144 "Insert KEYWORD and adjust case."
11145 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11146
11147 (defun vhdl-case-keyword (keyword)
11148 "Adjust case of KEYWORD."
11149 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11150
11151 (defun vhdl-case-word (num)
11152 "Adjust case of following NUM words."
11153 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11154
11155 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11156 "If preceding character is part of a word or a paren then hippie-expand,
11157 else insert tab (used for word completion in VHDL minibuffer)."
11158 (interactive "P")
11159 (cond
11160 ;; expand word
11161 ((= (char-syntax (preceding-char)) ?w)
11162 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11163 (case-replace nil)
11164 (hippie-expand-only-buffers
11165 (or (and (boundp 'hippie-expand-only-buffers)
11166 hippie-expand-only-buffers)
11167 '(vhdl-mode))))
11168 (vhdl-expand-abbrev prefix-arg)))
11169 ;; expand parenthesis
11170 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11171 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11172 (case-replace nil))
11173 (vhdl-expand-paren prefix-arg)))
11174 ;; insert tab
11175 (t (insert-tab))))
11176
11177 (defun vhdl-template-search-prompt ()
11178 "Search for left out template prompts and query again."
11179 (interactive)
11180 (vhdl-prepare-search-2
11181 (when (or (re-search-forward
11182 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11183 (re-search-backward
11184 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11185 (let ((string (match-string 1)))
11186 (replace-match "")
11187 (vhdl-template-field string)))))
11188
11189 (defun vhdl-template-undo (begin end)
11190 "Undo aborted template by deleting region and unexpanding the keyword."
11191 (cond (vhdl-template-invoked-by-hook
11192 (goto-char end)
11193 (insert " ")
11194 (delete-region begin end)
11195 (unexpand-abbrev))
11196 (t (delete-region begin end))))
11197
11198 (defun vhdl-insert-string-or-file (string)
11199 "Insert STRING or file contents if STRING is an existing file name."
11200 (unless (equal string "")
11201 (let ((file-name
11202 (progn (string-match "^\\([^\n]+\\)" string)
11203 (vhdl-resolve-env-variable (match-string 1 string)))))
11204 (if (file-exists-p file-name)
11205 (forward-char (cadr (insert-file-contents file-name)))
11206 (insert string)))))
11207
11208 (defun vhdl-beginning-of-block ()
11209 "Move cursor to the beginning of the enclosing block."
11210 (let (pos)
11211 (vhdl-prepare-search-2
11212 (save-excursion
11213 (beginning-of-line)
11214 ;; search backward for block beginning or end
11215 (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))
11216 ;; not consider subprogram declarations
11217 (or (and (match-string 5)
11218 (save-match-data
11219 (save-excursion
11220 (goto-char (match-end 5))
11221 (forward-word 1)
11222 (vhdl-forward-syntactic-ws)
11223 (when (looking-at "(")
11224 (forward-sexp))
11225 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11226 (match-string 1)))
11227 ;; not consider configuration specifications
11228 (and (match-string 6)
11229 (save-match-data
11230 (save-excursion
11231 (vhdl-end-of-block)
11232 (beginning-of-line)
11233 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11234 (match-string 2))
11235 ;; skip subblock if block end found
11236 (vhdl-beginning-of-block))))
11237 (when pos (goto-char pos))))
11238
11239 (defun vhdl-end-of-block ()
11240 "Move cursor to the end of the enclosing block."
11241 (let (pos)
11242 (vhdl-prepare-search-2
11243 (save-excursion
11244 (end-of-line)
11245 ;; search forward for block beginning or end
11246 (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))
11247 ;; not consider subprogram declarations
11248 (or (and (match-string 5)
11249 (save-match-data
11250 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11251 (match-string 1)))
11252 ;; not consider configuration specifications
11253 (and (match-string 6)
11254 (save-match-data
11255 (save-excursion
11256 (vhdl-end-of-block)
11257 (beginning-of-line)
11258 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11259 (not (match-string 2)))
11260 ;; skip subblock if block beginning found
11261 (vhdl-end-of-block))))
11262 (when pos (goto-char pos))))
11263
11264 (defun vhdl-sequential-statement-p ()
11265 "Check if point is within sequential statement part."
11266 (let ((start (point)))
11267 (save-excursion
11268 (vhdl-prepare-search-2
11269 ;; is sequential statement if ...
11270 (and (re-search-backward "^\\s-*begin\\>" nil t)
11271 ;; ... point is between "begin" and "end" of ...
11272 (progn (vhdl-end-of-block)
11273 (< start (point)))
11274 ;; ... a sequential block
11275 (progn (vhdl-beginning-of-block)
11276 (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\\)\\)\\>")))))))
11277
11278 (defun vhdl-in-argument-list-p ()
11279 "Check if within an argument list."
11280 (save-excursion
11281 (vhdl-prepare-search-2
11282 (or (string-match "arglist"
11283 (format "%s" (caar (vhdl-get-syntactic-context))))
11284 (progn (beginning-of-line)
11285 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11286
11287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11288 ;; Abbrev hooks
11289
11290 (defun vhdl-hooked-abbrev (func)
11291 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11292 but not if inside a comment or quote."
11293 (if (or (vhdl-in-literal)
11294 (save-excursion
11295 (forward-word -1)
11296 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11297 (progn
11298 (insert " ")
11299 (unexpand-abbrev)
11300 (backward-word 1)
11301 (vhdl-case-word 1)
11302 (delete-char 1))
11303 (if (not vhdl-electric-mode)
11304 (progn
11305 (insert " ")
11306 (unexpand-abbrev)
11307 (backward-word 1)
11308 (vhdl-case-word 1)
11309 (delete-char 1))
11310 (let ((invoke-char vhdl-last-input-event)
11311 (abbrev-mode -1)
11312 (vhdl-template-invoked-by-hook t))
11313 (let ((caught (catch 'abort
11314 (funcall func))))
11315 (when (stringp caught) (message "%s" caught)))
11316 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11317 ;; delete CR which is still in event queue
11318 (if (fboundp 'enqueue-eval-event)
11319 (enqueue-eval-event 'delete-char -1)
11320 (push (vhdl-character-to-event ?\177) ; push back a delete char
11321 unread-command-events))))))
11322
11323 (defun vhdl-template-alias-hook ()
11324 (vhdl-hooked-abbrev 'vhdl-template-alias))
11325 (defun vhdl-template-architecture-hook ()
11326 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11327 (defun vhdl-template-assert-hook ()
11328 (vhdl-hooked-abbrev 'vhdl-template-assert))
11329 (defun vhdl-template-attribute-hook ()
11330 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11331 (defun vhdl-template-block-hook ()
11332 (vhdl-hooked-abbrev 'vhdl-template-block))
11333 (defun vhdl-template-break-hook ()
11334 (vhdl-hooked-abbrev 'vhdl-template-break))
11335 (defun vhdl-template-case-hook ()
11336 (vhdl-hooked-abbrev 'vhdl-template-case))
11337 (defun vhdl-template-component-hook ()
11338 (vhdl-hooked-abbrev 'vhdl-template-component))
11339 (defun vhdl-template-instance-hook ()
11340 (vhdl-hooked-abbrev 'vhdl-template-instance))
11341 (defun vhdl-template-conditional-signal-asst-hook ()
11342 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11343 (defun vhdl-template-configuration-hook ()
11344 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11345 (defun vhdl-template-constant-hook ()
11346 (vhdl-hooked-abbrev 'vhdl-template-constant))
11347 (defun vhdl-template-context-hook ()
11348 (vhdl-hooked-abbrev 'vhdl-template-context))
11349 (defun vhdl-template-disconnect-hook ()
11350 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11351 (defun vhdl-template-display-comment-hook ()
11352 (vhdl-hooked-abbrev 'vhdl-comment-display))
11353 (defun vhdl-template-else-hook ()
11354 (vhdl-hooked-abbrev 'vhdl-template-else))
11355 (defun vhdl-template-elsif-hook ()
11356 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11357 (defun vhdl-template-entity-hook ()
11358 (vhdl-hooked-abbrev 'vhdl-template-entity))
11359 (defun vhdl-template-exit-hook ()
11360 (vhdl-hooked-abbrev 'vhdl-template-exit))
11361 (defun vhdl-template-file-hook ()
11362 (vhdl-hooked-abbrev 'vhdl-template-file))
11363 (defun vhdl-template-for-hook ()
11364 (vhdl-hooked-abbrev 'vhdl-template-for))
11365 (defun vhdl-template-function-hook ()
11366 (vhdl-hooked-abbrev 'vhdl-template-function))
11367 (defun vhdl-template-generic-hook ()
11368 (vhdl-hooked-abbrev 'vhdl-template-generic))
11369 (defun vhdl-template-group-hook ()
11370 (vhdl-hooked-abbrev 'vhdl-template-group))
11371 (defun vhdl-template-library-hook ()
11372 (vhdl-hooked-abbrev 'vhdl-template-library))
11373 (defun vhdl-template-limit-hook ()
11374 (vhdl-hooked-abbrev 'vhdl-template-limit))
11375 (defun vhdl-template-if-hook ()
11376 (vhdl-hooked-abbrev 'vhdl-template-if))
11377 (defun vhdl-template-bare-loop-hook ()
11378 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11379 (defun vhdl-template-map-hook ()
11380 (vhdl-hooked-abbrev 'vhdl-template-map))
11381 (defun vhdl-template-nature-hook ()
11382 (vhdl-hooked-abbrev 'vhdl-template-nature))
11383 (defun vhdl-template-next-hook ()
11384 (vhdl-hooked-abbrev 'vhdl-template-next))
11385 (defun vhdl-template-others-hook ()
11386 (vhdl-hooked-abbrev 'vhdl-template-others))
11387 (defun vhdl-template-package-hook ()
11388 (vhdl-hooked-abbrev 'vhdl-template-package))
11389 (defun vhdl-template-port-hook ()
11390 (vhdl-hooked-abbrev 'vhdl-template-port))
11391 (defun vhdl-template-procedural-hook ()
11392 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11393 (defun vhdl-template-procedure-hook ()
11394 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11395 (defun vhdl-template-process-hook ()
11396 (vhdl-hooked-abbrev 'vhdl-template-process))
11397 (defun vhdl-template-quantity-hook ()
11398 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11399 (defun vhdl-template-report-hook ()
11400 (vhdl-hooked-abbrev 'vhdl-template-report))
11401 (defun vhdl-template-return-hook ()
11402 (vhdl-hooked-abbrev 'vhdl-template-return))
11403 (defun vhdl-template-selected-signal-asst-hook ()
11404 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11405 (defun vhdl-template-signal-hook ()
11406 (vhdl-hooked-abbrev 'vhdl-template-signal))
11407 (defun vhdl-template-subnature-hook ()
11408 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11409 (defun vhdl-template-subtype-hook ()
11410 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11411 (defun vhdl-template-terminal-hook ()
11412 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11413 (defun vhdl-template-type-hook ()
11414 (vhdl-hooked-abbrev 'vhdl-template-type))
11415 (defun vhdl-template-use-hook ()
11416 (vhdl-hooked-abbrev 'vhdl-template-use))
11417 (defun vhdl-template-variable-hook ()
11418 (vhdl-hooked-abbrev 'vhdl-template-variable))
11419 (defun vhdl-template-wait-hook ()
11420 (vhdl-hooked-abbrev 'vhdl-template-wait))
11421 (defun vhdl-template-when-hook ()
11422 (vhdl-hooked-abbrev 'vhdl-template-when))
11423 (defun vhdl-template-while-loop-hook ()
11424 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11425 (defun vhdl-template-with-hook ()
11426 (vhdl-hooked-abbrev 'vhdl-template-with))
11427 (defun vhdl-template-and-hook ()
11428 (vhdl-hooked-abbrev 'vhdl-template-and))
11429 (defun vhdl-template-or-hook ()
11430 (vhdl-hooked-abbrev 'vhdl-template-or))
11431 (defun vhdl-template-nand-hook ()
11432 (vhdl-hooked-abbrev 'vhdl-template-nand))
11433 (defun vhdl-template-nor-hook ()
11434 (vhdl-hooked-abbrev 'vhdl-template-nor))
11435 (defun vhdl-template-xor-hook ()
11436 (vhdl-hooked-abbrev 'vhdl-template-xor))
11437 (defun vhdl-template-xnor-hook ()
11438 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11439 (defun vhdl-template-not-hook ()
11440 (vhdl-hooked-abbrev 'vhdl-template-not))
11441
11442 (defun vhdl-template-default-hook ()
11443 (vhdl-hooked-abbrev 'vhdl-template-default))
11444 (defun vhdl-template-default-indent-hook ()
11445 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11446
11447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11448 ;; Template insertion from completion list
11449
11450 (defun vhdl-template-insert-construct (name)
11451 "Insert the built-in construct template with NAME."
11452 (interactive
11453 (list (let ((completion-ignore-case t))
11454 (completing-read "Construct name: "
11455 vhdl-template-construct-alist nil t))))
11456 (vhdl-template-insert-fun
11457 (cadr (assoc name vhdl-template-construct-alist))))
11458
11459 (defun vhdl-template-insert-package (name)
11460 "Insert the built-in package template with NAME."
11461 (interactive
11462 (list (let ((completion-ignore-case t))
11463 (completing-read "Package name: "
11464 vhdl-template-package-alist nil t))))
11465 (vhdl-template-insert-fun
11466 (cadr (assoc name vhdl-template-package-alist))))
11467
11468 (defun vhdl-template-insert-directive (name)
11469 "Insert the built-in directive template with NAME."
11470 (interactive
11471 (list (let ((completion-ignore-case t))
11472 (completing-read "Directive name: "
11473 vhdl-template-directive-alist nil t))))
11474 (vhdl-template-insert-fun
11475 (cadr (assoc name vhdl-template-directive-alist))))
11476
11477 (defun vhdl-template-insert-fun (fun)
11478 "Call FUN to insert a built-in template."
11479 (let ((caught (catch 'abort (when fun (funcall fun)))))
11480 (when (stringp caught) (message "%s" caught))))
11481
11482
11483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11484 ;;; Models
11485 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11486
11487 (defun vhdl-model-insert (model-name)
11488 "Insert the user model with name MODEL-NAME."
11489 (interactive
11490 (let ((completion-ignore-case t))
11491 (list (completing-read "Model name: " vhdl-model-alist))))
11492 (indent-according-to-mode)
11493 (let ((start (point-marker))
11494 (margin (current-indentation))
11495 model position prompt string end)
11496 (vhdl-prepare-search-2
11497 (when (setq model (assoc model-name vhdl-model-alist))
11498 ;; insert model
11499 (beginning-of-line)
11500 (delete-horizontal-space)
11501 (goto-char start)
11502 (vhdl-insert-string-or-file (nth 1 model))
11503 (setq end (point-marker))
11504 ;; indent code
11505 (goto-char start)
11506 (beginning-of-line)
11507 (while (< (point) end)
11508 (unless (looking-at "^$")
11509 (insert-char ? margin))
11510 (beginning-of-line 2))
11511 (goto-char start)
11512 ;; insert clock
11513 (unless (equal "" vhdl-clock-name)
11514 (while (re-search-forward "<clock>" end t)
11515 (replace-match vhdl-clock-name)))
11516 (goto-char start)
11517 ;; insert reset
11518 (unless (equal "" vhdl-reset-name)
11519 (while (re-search-forward "<reset>" end t)
11520 (replace-match vhdl-reset-name)))
11521 ;; replace header prompts
11522 (vhdl-template-replace-header-keywords start end nil t)
11523 (goto-char start)
11524 ;; query other prompts
11525 (while (re-search-forward
11526 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11527 (unless (equal "cursor" (match-string 1))
11528 (setq position (match-beginning 1))
11529 (setq prompt (match-string 1))
11530 (replace-match "")
11531 (setq string (vhdl-template-field prompt nil t))
11532 ;; replace occurrences of same prompt
11533 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11534 (replace-match (or string "")))
11535 (goto-char position)))
11536 (goto-char start)
11537 ;; goto final position
11538 (if (re-search-forward "<cursor>" end t)
11539 (replace-match "")
11540 (goto-char end))))))
11541
11542 (defun vhdl-model-defun ()
11543 "Define help and hook functions for user models."
11544 (let ((model-alist vhdl-model-alist)
11545 model-name model-keyword)
11546 (while model-alist
11547 ;; define functions for user models that can be invoked from menu and key
11548 ;; bindings and which themselves call `vhdl-model-insert' with the model
11549 ;; name as argument
11550 (setq model-name (nth 0 (car model-alist)))
11551 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11552 ,(concat "Insert model for \"" model-name "\".")
11553 (interactive)
11554 (vhdl-model-insert ,model-name)))
11555 ;; define hooks for user models that are invoked from keyword abbrevs
11556 (setq model-keyword (nth 3 (car model-alist)))
11557 (unless (equal model-keyword "")
11558 (eval `(defun
11559 ,(vhdl-function-name
11560 "vhdl-model" model-name "hook") ()
11561 (vhdl-hooked-abbrev
11562 ',(vhdl-function-name "vhdl-model" model-name)))))
11563 (setq model-alist (cdr model-alist)))))
11564
11565 (vhdl-model-defun)
11566
11567
11568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11569 ;;; Port translation
11570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11571
11572 (defvar vhdl-port-list nil
11573 "Variable to hold last port map parsed.")
11574 ;; structure: (parenthesized expression means list of such entries)
11575 ;; (ent-name
11576 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11577 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11578 ;; (lib-name pack-key))
11579
11580 (defun vhdl-parse-string (string &optional optional)
11581 "Check that the text following point matches the regexp in STRING."
11582 (if (looking-at string)
11583 (progn (goto-char (match-end 0))
11584 (when (vhdl-in-literal)
11585 (end-of-line))
11586 (point))
11587 (unless optional
11588 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11589 (vhdl-current-line) string)))
11590 nil))
11591
11592 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11593 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11594 (vhdl-prepare-search-1
11595 (if (string-match (car regexp-cons) string)
11596 (if adjust-case
11597 (funcall vhdl-file-name-case
11598 (replace-match (cdr regexp-cons) t nil string))
11599 (replace-match (cdr regexp-cons) t nil string))
11600 string)))
11601
11602 (defun vhdl-parse-group-comment ()
11603 "Parse comment and empty lines between groups of lines."
11604 (let ((start (point))
11605 string)
11606 (vhdl-forward-comment (point-max))
11607 (setq string (buffer-substring-no-properties start (point)))
11608 (vhdl-forward-syntactic-ws)
11609 ;; strip off leading blanks and first newline
11610 (while (string-match "^\\(\\s-+\\)" string)
11611 (setq string (concat (substring string 0 (match-beginning 1))
11612 (substring string (match-end 1)))))
11613 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11614 (substring string 1)
11615 string)))
11616
11617 (defun vhdl-paste-group-comment (string indent)
11618 "Paste comment and empty lines from STRING between groups of lines
11619 with INDENT."
11620 (let ((pos (point-marker)))
11621 (when (> indent 0)
11622 (while (string-match "^\\(--\\)" string)
11623 (setq string (concat (substring string 0 (match-beginning 1))
11624 (make-string indent ? )
11625 (substring string (match-beginning 1))))))
11626 (beginning-of-line)
11627 (insert string)
11628 (goto-char pos)))
11629
11630 (defvar vhdl-port-flattened nil
11631 "Indicates whether a port has been flattened.")
11632
11633 (defun vhdl-port-flatten (&optional as-alist)
11634 "Flatten port list so that only one generic/port exists per line.
11635 This operation is performed on an internally stored port and is only
11636 reflected in a subsequent paste operation."
11637 (interactive)
11638 (if (not vhdl-port-list)
11639 (error "ERROR: No port has been read")
11640 (message "Flattening port for next paste...")
11641 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11642 (old-vhdl-port-list (cdr vhdl-port-list))
11643 old-port-list new-port-list old-port new-port names)
11644 ;; traverse port list and flatten entries
11645 (while (cdr old-vhdl-port-list)
11646 (setq old-port-list (car old-vhdl-port-list))
11647 (setq new-port-list nil)
11648 (while old-port-list
11649 (setq old-port (car old-port-list))
11650 (setq names (car old-port))
11651 (while names
11652 (setq new-port (cons (if as-alist (car names) (list (car names)))
11653 (cdr old-port)))
11654 (setq new-port-list (append new-port-list (list new-port)))
11655 (setq names (cdr names)))
11656 (setq old-port-list (cdr old-port-list)))
11657 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11658 (setq new-vhdl-port-list (append new-vhdl-port-list
11659 (list new-port-list))))
11660 (setq vhdl-port-list
11661 (append new-vhdl-port-list (list old-vhdl-port-list))
11662 vhdl-port-flattened t)
11663 (message "Flattening port for next paste...done"))))
11664
11665 (defvar vhdl-port-reversed-direction nil
11666 "Indicates whether port directions are reversed.")
11667
11668 (defun vhdl-port-reverse-direction ()
11669 "Reverse direction for all ports (useful in testbenches).
11670 This operation is performed on an internally stored port and is only
11671 reflected in a subsequent paste operation."
11672 (interactive)
11673 (if (not vhdl-port-list)
11674 (error "ERROR: No port has been read")
11675 (message "Reversing port directions for next paste...")
11676 (let ((port-list (nth 2 vhdl-port-list))
11677 port-dir-car port-dir)
11678 ;; traverse port list and reverse directions
11679 (while port-list
11680 (setq port-dir-car (cddr (car port-list))
11681 port-dir (car port-dir-car))
11682 (setcar port-dir-car
11683 (cond ((equal port-dir "in") "out")
11684 ((equal port-dir "IN") "OUT")
11685 ((equal port-dir "out") "in")
11686 ((equal port-dir "OUT") "IN")
11687 (t port-dir)))
11688 (setq port-list (cdr port-list)))
11689 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11690 (message "Reversing port directions for next paste...done"))))
11691
11692 (defun vhdl-port-copy ()
11693 "Get generic and port information from an entity or component declaration."
11694 (interactive)
11695 (save-excursion
11696 (let (parse-error end-of-list
11697 decl-type name generic-list port-list context-clause
11698 object names direct type init comment group-comment)
11699 (vhdl-prepare-search-2
11700 (setq
11701 parse-error
11702 (catch 'parse
11703 ;; check if within entity or component declaration
11704 (end-of-line)
11705 (when (or (not (re-search-backward
11706 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11707 (equal "END" (upcase (match-string 1))))
11708 (throw 'parse "ERROR: Not within an entity or component declaration"))
11709 (setq decl-type (downcase (match-string-no-properties 1)))
11710 (forward-word 1)
11711 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11712 (setq name (match-string-no-properties 1))
11713 (message "Reading port of %s \"%s\"..." decl-type name)
11714 (vhdl-forward-syntactic-ws)
11715 ;; parse generic clause
11716 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11717 ;; parse group comment and spacing
11718 (setq group-comment (vhdl-parse-group-comment))
11719 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11720 (while (not end-of-list)
11721 ;; parse names (accept extended identifiers)
11722 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11723 (setq names (list (match-string-no-properties 1)))
11724 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11725 (setq names
11726 (append names (list (match-string-no-properties 1)))))
11727 ;; parse type
11728 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11729 (setq type (match-string-no-properties 1))
11730 (when (vhdl-in-comment-p) ; if stuck in comment
11731 (setq type (concat type (and (vhdl-parse-string ".*")
11732 (match-string-no-properties 0)))))
11733 (setq comment nil)
11734 (while (looking-at "(")
11735 (setq type
11736 (concat type
11737 (buffer-substring-no-properties
11738 (point) (progn (forward-sexp) (point)))
11739 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11740 (match-string-no-properties 1)))))
11741 ;; special case: closing parenthesis is on separate line
11742 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11743 (setq comment (substring type (match-beginning 2)))
11744 (setq type (substring type 0 (match-beginning 1))))
11745 ;; strip of trailing group-comment
11746 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11747 (setq type (substring type 0 (match-end 1)))
11748 ;; parse initialization expression
11749 (setq init nil)
11750 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11751 (vhdl-parse-string "\\([^();\n]*\\)")
11752 (setq init (match-string-no-properties 1))
11753 (while (looking-at "(")
11754 (setq init
11755 (concat init
11756 (buffer-substring-no-properties
11757 (point) (progn (forward-sexp) (point)))
11758 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11759 (match-string-no-properties 1))))))
11760 ;; special case: closing parenthesis is on separate line
11761 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11762 (setq comment (substring init (match-beginning 2)))
11763 (setq init (substring init 0 (match-beginning 1)))
11764 (vhdl-forward-syntactic-ws))
11765 (skip-chars-forward " \t")
11766 ;; parse inline comment, special case: as above, no initial.
11767 (unless comment
11768 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11769 (match-string-no-properties 1))))
11770 (vhdl-forward-syntactic-ws)
11771 (setq end-of-list (vhdl-parse-string ")" t))
11772 (vhdl-parse-string "\\s-*;\\s-*")
11773 ;; parse inline comment
11774 (unless comment
11775 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11776 (match-string-no-properties 1))))
11777 ;; save everything in list
11778 (setq generic-list (append generic-list
11779 (list (list names type init
11780 comment group-comment))))
11781 ;; parse group comment and spacing
11782 (setq group-comment (vhdl-parse-group-comment))))
11783 ;; parse port clause
11784 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11785 ;; parse group comment and spacing
11786 (setq group-comment (vhdl-parse-group-comment))
11787 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11788 (while (not end-of-list)
11789 ;; parse object
11790 (setq object
11791 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11792 (match-string-no-properties 1)))
11793 ;; parse names (accept extended identifiers)
11794 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11795 (setq names (list (match-string-no-properties 1)))
11796 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11797 (setq names (append names (list (match-string-no-properties 1)))))
11798 ;; parse direction
11799 (vhdl-parse-string ":[ \t\n\r\f]*")
11800 (setq direct
11801 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11802 (match-string-no-properties 1)))
11803 ;; parse type
11804 (vhdl-parse-string "\\([^();\n]+\\)")
11805 (setq type (match-string-no-properties 1))
11806 (when (vhdl-in-comment-p) ; if stuck in comment
11807 (setq type (concat type (and (vhdl-parse-string ".*")
11808 (match-string-no-properties 0)))))
11809 (setq comment nil)
11810 (while (looking-at "(")
11811 (setq type (concat type
11812 (buffer-substring-no-properties
11813 (point) (progn (forward-sexp) (point)))
11814 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11815 (match-string-no-properties 1)))))
11816 ;; special case: closing parenthesis is on separate line
11817 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11818 (setq comment (substring type (match-beginning 2)))
11819 (setq type (substring type 0 (match-beginning 1))))
11820 ;; strip of trailing group-comment
11821 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11822 (setq type (substring type 0 (match-end 1)))
11823 (vhdl-forward-syntactic-ws)
11824 (setq end-of-list (vhdl-parse-string ")" t))
11825 (vhdl-parse-string "\\s-*;\\s-*")
11826 ;; parse inline comment
11827 (unless comment
11828 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11829 (match-string-no-properties 1))))
11830 ;; save everything in list
11831 (setq port-list (append port-list
11832 (list (list names object direct type
11833 comment group-comment))))
11834 ;; parse group comment and spacing
11835 (setq group-comment (vhdl-parse-group-comment))))
11836 ;; parse context clause
11837 (setq context-clause (vhdl-scan-context-clause))
11838 ; ;; add surrounding package to context clause
11839 ; (when (and (equal decl-type "component")
11840 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11841 ; (setq context-clause
11842 ; (append context-clause
11843 ; (list (cons (vhdl-work-library)
11844 ; (match-string-no-properties 1))))))
11845 (message "Reading port of %s \"%s\"...done" decl-type name)
11846 nil)))
11847 ;; finish parsing
11848 (if parse-error
11849 (error parse-error)
11850 (setq vhdl-port-list (list name generic-list port-list context-clause)
11851 vhdl-port-reversed-direction nil
11852 vhdl-port-flattened nil)))))
11853
11854 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11855 "Paste a context clause."
11856 (let ((margin (current-indentation))
11857 (clause-list (nth 3 vhdl-port-list))
11858 clause)
11859 (while clause-list
11860 (setq clause (car clause-list))
11861 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11862 (downcase exclude-pack-name)))
11863 (save-excursion
11864 (re-search-backward
11865 (concat "^\\s-*use\\s-+" (car clause)
11866 "." (cdr clause) "\\>") nil t)))
11867 (vhdl-template-standard-package (car clause) (cdr clause))
11868 (insert "\n"))
11869 (setq clause-list (cdr clause-list)))))
11870
11871 (defun vhdl-port-paste-generic (&optional no-init)
11872 "Paste a generic clause."
11873 (let ((margin (current-indentation))
11874 (generic-list (nth 1 vhdl-port-list))
11875 list-margin start names generic)
11876 ;; paste generic clause
11877 (when generic-list
11878 (setq start (point))
11879 (vhdl-insert-keyword "GENERIC (")
11880 (unless vhdl-argument-list-indent
11881 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11882 (setq list-margin (current-column))
11883 (while generic-list
11884 (setq generic (car generic-list))
11885 ;; paste group comment and spacing
11886 (when (memq vhdl-include-group-comments '(decl always))
11887 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11888 ;; paste names
11889 (setq names (nth 0 generic))
11890 (while names
11891 (insert (car names))
11892 (setq names (cdr names))
11893 (when names (insert ", ")))
11894 ;; paste type
11895 (insert " : " (nth 1 generic))
11896 ;; paste initialization
11897 (when (and (not no-init) (nth 2 generic))
11898 (insert " := " (nth 2 generic)))
11899 (unless (cdr generic-list) (insert ")"))
11900 (insert ";")
11901 ;; paste comment
11902 (when (and vhdl-include-port-comments (nth 3 generic))
11903 (vhdl-comment-insert-inline (nth 3 generic) t))
11904 (setq generic-list (cdr generic-list))
11905 (when generic-list (insert "\n") (indent-to list-margin)))
11906 ;; align generic clause
11907 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11908
11909 (defun vhdl-port-paste-port ()
11910 "Paste a port clause."
11911 (let ((margin (current-indentation))
11912 (port-list (nth 2 vhdl-port-list))
11913 list-margin start names port)
11914 ;; paste port clause
11915 (when port-list
11916 (setq start (point))
11917 (vhdl-insert-keyword "PORT (")
11918 (unless vhdl-argument-list-indent
11919 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11920 (setq list-margin (current-column))
11921 (while port-list
11922 (setq port (car port-list))
11923 ;; paste group comment and spacing
11924 (when (memq vhdl-include-group-comments '(decl always))
11925 (vhdl-paste-group-comment (nth 5 port) list-margin))
11926 ;; paste object
11927 (when (nth 1 port) (insert (nth 1 port) " "))
11928 ;; paste names
11929 (setq names (nth 0 port))
11930 (while names
11931 (insert (car names))
11932 (setq names (cdr names))
11933 (when names (insert ", ")))
11934 ;; paste direction
11935 (insert " : ")
11936 (when (nth 2 port) (insert (nth 2 port) " "))
11937 ;; paste type
11938 (insert (nth 3 port))
11939 (unless (cdr port-list) (insert ")"))
11940 (insert ";")
11941 ;; paste comment
11942 (when (and vhdl-include-port-comments (nth 4 port))
11943 (vhdl-comment-insert-inline (nth 4 port) t))
11944 (setq port-list (cdr port-list))
11945 (when port-list (insert "\n") (indent-to list-margin)))
11946 ;; align port clause
11947 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11948
11949 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11950 "Paste as an entity or component declaration."
11951 (unless no-indent (indent-according-to-mode))
11952 (let ((margin (current-indentation))
11953 (name (nth 0 vhdl-port-list)))
11954 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11955 (insert name)
11956 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11957 (vhdl-insert-keyword " IS"))
11958 ;; paste generic and port clause
11959 (when (nth 1 vhdl-port-list)
11960 (insert "\n")
11961 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11962 (insert "\n"))
11963 (indent-to (+ margin vhdl-basic-offset))
11964 (vhdl-port-paste-generic (eq kind 'component)))
11965 (when (nth 2 vhdl-port-list)
11966 (insert "\n")
11967 (when (and (memq vhdl-insert-empty-lines '(unit all))
11968 (eq kind 'entity))
11969 (insert "\n"))
11970 (indent-to (+ margin vhdl-basic-offset)))
11971 (vhdl-port-paste-port)
11972 (insert "\n")
11973 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11974 (insert "\n"))
11975 (indent-to margin)
11976 (vhdl-insert-keyword "END")
11977 (if (eq kind 'entity)
11978 (progn
11979 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11980 (insert " " name))
11981 (vhdl-insert-keyword " COMPONENT")
11982 (unless (vhdl-standard-p '87) (insert " " name)))
11983 (insert ";")))
11984
11985 (defun vhdl-port-paste-entity (&optional no-indent)
11986 "Paste as an entity declaration."
11987 (interactive)
11988 (if (not vhdl-port-list)
11989 (error "ERROR: No port read")
11990 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11991 (vhdl-port-paste-declaration 'entity no-indent)
11992 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11993
11994 (defun vhdl-port-paste-component (&optional no-indent)
11995 "Paste as a component declaration."
11996 (interactive)
11997 (if (not vhdl-port-list)
11998 (error "ERROR: No port read")
11999 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
12000 (vhdl-port-paste-declaration 'component no-indent)
12001 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
12002
12003 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
12004 "Paste as a generic map."
12005 (interactive)
12006 (unless secondary (indent-according-to-mode))
12007 (let ((margin (current-indentation))
12008 list-margin start generic
12009 (generic-list (nth 1 vhdl-port-list)))
12010 (when generic-list
12011 (setq start (point))
12012 (vhdl-insert-keyword "GENERIC MAP (")
12013 (if (not vhdl-association-list-with-formals)
12014 ;; paste list of actual generics
12015 (while generic-list
12016 (insert (if no-constants
12017 (car (nth 0 (car generic-list)))
12018 (or (nth 2 (car generic-list)) " ")))
12019 (setq generic-list (cdr generic-list))
12020 (insert (if generic-list ", " ")"))
12021 (when (and (not generic-list) secondary
12022 (null (nth 2 vhdl-port-list)))
12023 (insert ";")))
12024 (unless vhdl-argument-list-indent
12025 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12026 (setq list-margin (current-column))
12027 (while generic-list
12028 (setq generic (car generic-list))
12029 ;; paste group comment and spacing
12030 (when (eq vhdl-include-group-comments 'always)
12031 (vhdl-paste-group-comment (nth 4 generic) list-margin))
12032 ;; paste formal and actual generic
12033 (insert (car (nth 0 generic)) " => "
12034 (if no-constants
12035 (vhdl-replace-string vhdl-actual-generic-name
12036 (car (nth 0 generic)))
12037 (or (nth 2 generic) "")))
12038 (setq generic-list (cdr generic-list))
12039 (insert (if generic-list "," ")"))
12040 (when (and (not generic-list) secondary
12041 (null (nth 2 vhdl-port-list)))
12042 (insert ";"))
12043 ;; paste comment
12044 (when (or vhdl-include-type-comments
12045 (and vhdl-include-port-comments (nth 3 generic)))
12046 (vhdl-comment-insert-inline
12047 (concat
12048 (when vhdl-include-type-comments
12049 (concat "[" (nth 1 generic) "] "))
12050 (when vhdl-include-port-comments (nth 3 generic))) t))
12051 (when generic-list (insert "\n") (indent-to list-margin)))
12052 ;; align generic map
12053 (when vhdl-auto-align
12054 (vhdl-align-region-groups start (point) 1 t))))))
12055
12056 (defun vhdl-port-paste-port-map ()
12057 "Paste as a port map."
12058 (let ((margin (current-indentation))
12059 list-margin start port
12060 (port-list (nth 2 vhdl-port-list)))
12061 (when port-list
12062 (setq start (point))
12063 (vhdl-insert-keyword "PORT MAP (")
12064 (if (not vhdl-association-list-with-formals)
12065 ;; paste list of actual ports
12066 (while port-list
12067 (insert (vhdl-replace-string vhdl-actual-port-name
12068 (car (nth 0 (car port-list)))))
12069 (setq port-list (cdr port-list))
12070 (insert (if port-list ", " ")")))
12071 (unless vhdl-argument-list-indent
12072 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12073 (setq list-margin (current-column))
12074 (while port-list
12075 (setq port (car port-list))
12076 ;; paste group comment and spacing
12077 (when (eq vhdl-include-group-comments 'always)
12078 (vhdl-paste-group-comment (nth 5 port) list-margin))
12079 ;; paste formal and actual port
12080 (insert (car (nth 0 port)) " => ")
12081 (insert (vhdl-replace-string vhdl-actual-port-name
12082 (car (nth 0 port))))
12083 (setq port-list (cdr port-list))
12084 (insert (if port-list "," ");"))
12085 ;; paste comment
12086 (when (or (and vhdl-include-direction-comments (nth 2 port))
12087 vhdl-include-type-comments
12088 (and vhdl-include-port-comments (nth 4 port)))
12089 (vhdl-comment-insert-inline
12090 (concat
12091 (cond ((and vhdl-include-direction-comments
12092 vhdl-include-type-comments)
12093 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
12094 (nth 3 port) "] "))
12095 ((and vhdl-include-direction-comments (nth 2 port))
12096 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12097 (vhdl-include-direction-comments " ")
12098 (vhdl-include-type-comments
12099 (concat "[" (nth 3 port) "] ")))
12100 (when vhdl-include-port-comments (nth 4 port))) t))
12101 (when port-list (insert "\n") (indent-to list-margin)))
12102 ;; align port clause
12103 (when vhdl-auto-align
12104 (vhdl-align-region-groups start (point) 1))))))
12105
12106 (defun vhdl-port-paste-instance (&optional name no-indent title)
12107 "Paste as an instantiation."
12108 (interactive)
12109 (if (not vhdl-port-list)
12110 (error "ERROR: No port read")
12111 (let ((orig-vhdl-port-list vhdl-port-list))
12112 ;; flatten local copy of port list (must be flat for port mapping)
12113 (vhdl-port-flatten)
12114 (unless no-indent (indent-according-to-mode))
12115 (let ((margin (current-indentation)))
12116 ;; paste instantiation
12117 (cond (name
12118 (insert name))
12119 ((equal (cdr vhdl-instance-name) "")
12120 (setq name (vhdl-template-field "instance name")))
12121 ((string-match "%d" (cdr vhdl-instance-name))
12122 (let ((n 1))
12123 (while (save-excursion
12124 (setq name (format (vhdl-replace-string
12125 vhdl-instance-name
12126 (nth 0 vhdl-port-list)) n))
12127 (goto-char (point-min))
12128 (vhdl-re-search-forward name nil t))
12129 (setq n (1+ n)))
12130 (insert name)))
12131 (t (insert (vhdl-replace-string vhdl-instance-name
12132 (nth 0 vhdl-port-list)))))
12133 (message "Pasting port as instantiation \"%s\"..." name)
12134 (insert ": ")
12135 (when title
12136 (save-excursion
12137 (beginning-of-line)
12138 (indent-to vhdl-basic-offset)
12139 (insert "-- instance \"" name "\"\n")))
12140 (if (not (vhdl-use-direct-instantiation))
12141 (insert (nth 0 vhdl-port-list))
12142 (vhdl-insert-keyword "ENTITY ")
12143 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12144 (when (nth 1 vhdl-port-list)
12145 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12146 (vhdl-port-paste-generic-map t t))
12147 (when (nth 2 vhdl-port-list)
12148 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12149 (vhdl-port-paste-port-map))
12150 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12151 (insert ";"))
12152 (message "Pasting port as instantiation \"%s\"...done" name))
12153 (setq vhdl-port-list orig-vhdl-port-list))))
12154
12155 (defun vhdl-port-paste-constants (&optional no-indent)
12156 "Paste generics as constants."
12157 (interactive)
12158 (if (not vhdl-port-list)
12159 (error "ERROR: No port read")
12160 (let ((orig-vhdl-port-list vhdl-port-list))
12161 (message "Pasting port as constants...")
12162 ;; flatten local copy of port list (must be flat for constant initial.)
12163 (vhdl-port-flatten)
12164 (unless no-indent (indent-according-to-mode))
12165 (let ((margin (current-indentation))
12166 start generic name
12167 (generic-list (nth 1 vhdl-port-list)))
12168 (when generic-list
12169 (setq start (point))
12170 (while generic-list
12171 (setq generic (car generic-list))
12172 ;; paste group comment and spacing
12173 (when (memq vhdl-include-group-comments '(decl always))
12174 (vhdl-paste-group-comment (nth 4 generic) margin))
12175 (vhdl-insert-keyword "CONSTANT ")
12176 ;; paste generic constants
12177 (setq name (nth 0 generic))
12178 (when name
12179 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12180 ;; paste type
12181 (insert " : " (nth 1 generic))
12182 ;; paste initialization
12183 (when (nth 2 generic)
12184 (insert " := " (nth 2 generic)))
12185 (insert ";")
12186 ;; paste comment
12187 (when (and vhdl-include-port-comments (nth 3 generic))
12188 (vhdl-comment-insert-inline (nth 3 generic) t))
12189 (setq generic-list (cdr generic-list))
12190 (when generic-list (insert "\n") (indent-to margin))))
12191 ;; align signal list
12192 (when vhdl-auto-align
12193 (vhdl-align-region-groups start (point) 1))))
12194 (message "Pasting port as constants...done")
12195 (setq vhdl-port-list orig-vhdl-port-list))))
12196
12197 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12198 "Paste ports as internal signals."
12199 (interactive)
12200 (if (not vhdl-port-list)
12201 (error "ERROR: No port read")
12202 (message "Pasting port as signals...")
12203 (unless no-indent (indent-according-to-mode))
12204 (let ((margin (current-indentation))
12205 start port names type generic-list port-name constant-name pos
12206 (port-list (nth 2 vhdl-port-list)))
12207 (when port-list
12208 (setq start (point))
12209 (while port-list
12210 (setq port (car port-list))
12211 ;; paste group comment and spacing
12212 (when (memq vhdl-include-group-comments '(decl always))
12213 (vhdl-paste-group-comment (nth 5 port) margin))
12214 ;; paste object
12215 (if (nth 1 port)
12216 (insert (nth 1 port) " ")
12217 (vhdl-insert-keyword "SIGNAL "))
12218 ;; paste actual port signals
12219 (setq names (nth 0 port))
12220 (while names
12221 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12222 (setq names (cdr names))
12223 (when names (insert ", ")))
12224 ;; paste type
12225 (setq type (nth 3 port))
12226 (setq generic-list (nth 1 vhdl-port-list))
12227 (vhdl-prepare-search-1
12228 (setq pos 0)
12229 ;; replace formal by actual generics
12230 (while generic-list
12231 (setq port-name (car (nth 0 (car generic-list))))
12232 (while (string-match (concat "\\<" port-name "\\>") type pos)
12233 (setq constant-name
12234 (save-match-data (vhdl-replace-string
12235 vhdl-actual-generic-name port-name)))
12236 (setq type (replace-match constant-name t nil type))
12237 (setq pos (match-end 0)))
12238 (setq generic-list (cdr generic-list))))
12239 (insert " : " type)
12240 ;; paste initialization (inputs only)
12241 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12242 (insert " := "
12243 (cond ((string-match "integer" (nth 3 port)) "0")
12244 ((string-match "natural" (nth 3 port)) "0")
12245 ((string-match "positive" (nth 3 port)) "0")
12246 ((string-match "real" (nth 3 port)) "0.0")
12247 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12248 (t "'0'"))))
12249 (insert ";")
12250 ;; paste comment
12251 (when (or (and vhdl-include-direction-comments (nth 2 port))
12252 (and vhdl-include-port-comments (nth 4 port)))
12253 (vhdl-comment-insert-inline
12254 (concat
12255 (cond ((and vhdl-include-direction-comments (nth 2 port))
12256 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12257 (vhdl-include-direction-comments " "))
12258 (when vhdl-include-port-comments (nth 4 port))) t))
12259 (setq port-list (cdr port-list))
12260 (when port-list (insert "\n") (indent-to margin)))
12261 ;; align signal list
12262 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12263 (message "Pasting port as signals...done")))
12264
12265 (defun vhdl-port-paste-initializations (&optional no-indent)
12266 "Paste ports as signal initializations."
12267 (interactive)
12268 (if (not vhdl-port-list)
12269 (error "ERROR: No port read")
12270 (let ((orig-vhdl-port-list vhdl-port-list))
12271 (message "Pasting port as initializations...")
12272 ;; flatten local copy of port list (must be flat for signal initial.)
12273 (vhdl-port-flatten)
12274 (unless no-indent (indent-according-to-mode))
12275 (let ((margin (current-indentation))
12276 start port name
12277 (port-list (nth 2 vhdl-port-list)))
12278 (when port-list
12279 (setq start (point))
12280 (while port-list
12281 (setq port (car port-list))
12282 ;; paste actual port signal (inputs only)
12283 (when (equal "IN" (upcase (nth 2 port)))
12284 (setq name (car (nth 0 port)))
12285 (insert (vhdl-replace-string vhdl-actual-port-name name))
12286 ;; paste initialization
12287 (insert " <= "
12288 (cond ((string-match "integer" (nth 3 port)) "0")
12289 ((string-match "natural" (nth 3 port)) "0")
12290 ((string-match "positive" (nth 3 port)) "0")
12291 ((string-match "real" (nth 3 port)) "0.0")
12292 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12293 (t "'0'"))
12294 ";"))
12295 (setq port-list (cdr port-list))
12296 (when (and port-list
12297 (equal "IN" (upcase (nth 2 (car port-list)))))
12298 (insert "\n") (indent-to margin)))
12299 ;; align signal list
12300 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12301 (message "Pasting port as initializations...done")
12302 (setq vhdl-port-list orig-vhdl-port-list))))
12303
12304 (defun vhdl-port-paste-testbench ()
12305 "Paste as a bare-bones testbench."
12306 (interactive)
12307 (if (not vhdl-port-list)
12308 (error "ERROR: No port read")
12309 (let ((case-fold-search t)
12310 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12311 (nth 0 vhdl-port-list)))
12312 (source-buffer (current-buffer))
12313 arch-name config-name ent-file-name arch-file-name
12314 ent-buffer arch-buffer position)
12315 ;; open entity file
12316 (unless (eq vhdl-testbench-create-files 'none)
12317 (setq ent-file-name
12318 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12319 ent-name t)
12320 "." (file-name-extension (buffer-file-name))))
12321 (if (file-exists-p ent-file-name)
12322 (if (y-or-n-p
12323 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12324 (progn (find-file ent-file-name)
12325 (erase-buffer)
12326 (set-buffer-modified-p nil))
12327 (if (eq vhdl-testbench-create-files 'separate)
12328 (setq ent-file-name nil)
12329 (error "ERROR: Pasting port as testbench...aborted")))
12330 (find-file ent-file-name)))
12331 (unless (and (eq vhdl-testbench-create-files 'separate)
12332 (null ent-file-name))
12333 ;; paste entity header
12334 (if vhdl-testbench-include-header
12335 (progn (vhdl-template-header
12336 (concat "Testbench for design \""
12337 (nth 0 vhdl-port-list) "\""))
12338 (goto-char (point-max)))
12339 (vhdl-comment-display-line) (insert "\n\n"))
12340 ;; paste std_logic_1164 package
12341 (when vhdl-testbench-include-library
12342 (vhdl-template-package-std-logic-1164)
12343 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12344 ;; paste entity declaration
12345 (vhdl-insert-keyword "ENTITY ")
12346 (insert ent-name)
12347 (vhdl-insert-keyword " IS")
12348 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12349 (insert "\n")
12350 (vhdl-insert-keyword "END ")
12351 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12352 (insert ent-name ";")
12353 (insert "\n\n")
12354 (vhdl-comment-display-line) (insert "\n"))
12355 ;; get architecture name
12356 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12357 (read-from-minibuffer "architecture name: "
12358 nil vhdl-minibuffer-local-map)
12359 (vhdl-replace-string vhdl-testbench-architecture-name
12360 (nth 0 vhdl-port-list))))
12361 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12362 ;; open architecture file
12363 (if (not (eq vhdl-testbench-create-files 'separate))
12364 (insert "\n")
12365 (setq ent-buffer (current-buffer))
12366 (setq arch-file-name
12367 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12368 (concat ent-name " " arch-name) t)
12369 "." (file-name-extension (buffer-file-name))))
12370 (when (and (file-exists-p arch-file-name)
12371 (not (y-or-n-p (concat "File \"" arch-file-name
12372 "\" exists; overwrite? "))))
12373 (error "ERROR: Pasting port as testbench...aborted"))
12374 (find-file arch-file-name)
12375 (erase-buffer)
12376 (set-buffer-modified-p nil)
12377 ;; paste architecture header
12378 (if vhdl-testbench-include-header
12379 (progn (vhdl-template-header
12380 (concat "Testbench architecture for design \""
12381 (nth 0 vhdl-port-list) "\""))
12382 (goto-char (point-max)))
12383 (vhdl-comment-display-line) (insert "\n\n")))
12384 ;; paste architecture body
12385 (vhdl-insert-keyword "ARCHITECTURE ")
12386 (insert arch-name)
12387 (vhdl-insert-keyword " OF ")
12388 (insert ent-name)
12389 (vhdl-insert-keyword " IS")
12390 (insert "\n\n") (indent-to vhdl-basic-offset)
12391 ;; paste component declaration
12392 (unless (vhdl-use-direct-instantiation)
12393 (vhdl-port-paste-component t)
12394 (insert "\n\n") (indent-to vhdl-basic-offset))
12395 ;; paste constants
12396 (when (nth 1 vhdl-port-list)
12397 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12398 (vhdl-port-paste-constants t)
12399 (insert "\n\n") (indent-to vhdl-basic-offset))
12400 ;; paste internal signals
12401 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12402 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12403 (insert "\n")
12404 ;; paste custom declarations
12405 (unless (equal "" vhdl-testbench-declarations)
12406 (insert "\n")
12407 (setq position (point))
12408 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12409 (vhdl-indent-region position (point)))
12410 (setq position (point))
12411 (insert "\n\n")
12412 (vhdl-comment-display-line) (insert "\n")
12413 (when vhdl-testbench-include-configuration
12414 (setq config-name (vhdl-replace-string
12415 vhdl-testbench-configuration-name
12416 (concat ent-name " " arch-name)))
12417 (insert "\n")
12418 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12419 (vhdl-insert-keyword " OF ") (insert ent-name)
12420 (vhdl-insert-keyword " IS\n")
12421 (indent-to vhdl-basic-offset)
12422 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12423 (indent-to vhdl-basic-offset)
12424 (vhdl-insert-keyword "END FOR;\n")
12425 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12426 (vhdl-comment-display-line) (insert "\n"))
12427 (goto-char position)
12428 (vhdl-template-begin-end
12429 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12430 ;; paste instantiation
12431 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12432 (vhdl-port-paste-instance
12433 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12434 (insert "\n")
12435 ;; paste custom statements
12436 (unless (equal "" vhdl-testbench-statements)
12437 (insert "\n")
12438 (setq position (point))
12439 (vhdl-insert-string-or-file vhdl-testbench-statements)
12440 (vhdl-indent-region position (point)))
12441 (insert "\n")
12442 (indent-to vhdl-basic-offset)
12443 (unless (eq vhdl-testbench-create-files 'none)
12444 (setq arch-buffer (current-buffer))
12445 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12446 (set-buffer arch-buffer) (save-buffer))
12447 (message "%s"
12448 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12449 ent-name arch-name)
12450 (and ent-file-name
12451 (format "\n File created: \"%s\"" ent-file-name))
12452 (and arch-file-name
12453 (format "\n File created: \"%s\"" arch-file-name)))))))
12454
12455
12456 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12457 ;;; Subprogram interface translation
12458 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12459
12460 (defvar vhdl-subprog-list nil
12461 "Variable to hold last subprogram interface parsed.")
12462 ;; structure: (parenthesized expression means list of such entries)
12463 ;; (subprog-name kind
12464 ;; ((names) object direct type init comment group-comment)
12465 ;; return-type return-comment group-comment)
12466
12467 (defvar vhdl-subprog-flattened nil
12468 "Indicates whether an subprogram interface has been flattened.")
12469
12470 (defun vhdl-subprog-flatten ()
12471 "Flatten interface list so that only one parameter exists per line."
12472 (interactive)
12473 (if (not vhdl-subprog-list)
12474 (error "ERROR: No subprogram interface has been read")
12475 (message "Flattening subprogram interface...")
12476 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12477 new-subprog-list old-subprog new-subprog names)
12478 ;; traverse parameter list and flatten entries
12479 (while old-subprog-list
12480 (setq old-subprog (car old-subprog-list))
12481 (setq names (car old-subprog))
12482 (while names
12483 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12484 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12485 (setq names (cdr names)))
12486 (setq old-subprog-list (cdr old-subprog-list)))
12487 (setq vhdl-subprog-list
12488 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12489 new-subprog-list (nth 3 vhdl-subprog-list)
12490 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12491 vhdl-subprog-flattened t)
12492 (message "Flattening subprogram interface...done"))))
12493
12494 (defun vhdl-subprog-copy ()
12495 "Get interface information from a subprogram specification."
12496 (interactive)
12497 (save-excursion
12498 (let (parse-error pos end-of-list
12499 name kind param-list object names direct type init
12500 comment group-comment
12501 return-type return-comment return-group-comment)
12502 (vhdl-prepare-search-2
12503 (setq
12504 parse-error
12505 (catch 'parse
12506 ;; check if within function declaration
12507 (setq pos (point))
12508 (end-of-line)
12509 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12510 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12511 (goto-char (match-end 0))
12512 (save-excursion (backward-char)
12513 (forward-sexp)
12514 (<= pos (point))))
12515 (throw 'parse "ERROR: Not within a subprogram specification"))
12516 (setq name (match-string-no-properties 5))
12517 (setq kind (if (match-string 2) 'procedure 'function))
12518 (setq end-of-list (not (match-string 7)))
12519 (message "Reading interface of subprogram \"%s\"..." name)
12520 ;; parse parameter list
12521 (setq group-comment (vhdl-parse-group-comment))
12522 (setq end-of-list (or end-of-list
12523 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12524 (while (not end-of-list)
12525 ;; parse object
12526 (setq object
12527 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12528 (match-string-no-properties 1)))
12529 ;; parse names (accept extended identifiers)
12530 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12531 (setq names (list (match-string-no-properties 1)))
12532 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12533 (setq names (append names (list (match-string-no-properties 1)))))
12534 ;; parse direction
12535 (vhdl-parse-string ":[ \t\n\r\f]*")
12536 (setq direct
12537 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12538 (match-string-no-properties 1)))
12539 ;; parse type
12540 (vhdl-parse-string "\\([^():;\n]+\\)")
12541 (setq type (match-string-no-properties 1))
12542 (setq comment nil)
12543 (while (looking-at "(")
12544 (setq type
12545 (concat type
12546 (buffer-substring-no-properties
12547 (point) (progn (forward-sexp) (point)))
12548 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12549 (match-string-no-properties 1)))))
12550 ;; special case: closing parenthesis is on separate line
12551 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12552 (setq comment (substring type (match-beginning 2)))
12553 (setq type (substring type 0 (match-beginning 1))))
12554 ;; strip off trailing group-comment
12555 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12556 (setq type (substring type 0 (match-end 1)))
12557 ;; parse initialization expression
12558 (setq init nil)
12559 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12560 (vhdl-parse-string "\\([^();\n]*\\)")
12561 (setq init (match-string-no-properties 1))
12562 (while (looking-at "(")
12563 (setq init
12564 (concat init
12565 (buffer-substring-no-properties
12566 (point) (progn (forward-sexp) (point)))
12567 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12568 (match-string-no-properties 1))))))
12569 ;; special case: closing parenthesis is on separate line
12570 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12571 (setq comment (substring init (match-beginning 2)))
12572 (setq init (substring init 0 (match-beginning 1)))
12573 (vhdl-forward-syntactic-ws))
12574 (skip-chars-forward " \t")
12575 ;; parse inline comment, special case: as above, no initial.
12576 (unless comment
12577 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12578 (match-string-no-properties 1))))
12579 (vhdl-forward-syntactic-ws)
12580 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12581 ;; parse inline comment
12582 (unless comment
12583 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12584 (match-string-no-properties 1))))
12585 (setq return-group-comment (vhdl-parse-group-comment))
12586 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12587 ;; parse return type
12588 (when (match-string 3)
12589 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12590 (setq return-type (match-string-no-properties 1))
12591 (when (and return-type
12592 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12593 (setq return-comment (substring return-type (match-beginning 2)))
12594 (setq return-type (substring return-type 0 (match-beginning 1))))
12595 ;; strip of trailing group-comment
12596 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12597 (setq return-type (substring return-type 0 (match-end 1)))
12598 ;; parse return comment
12599 (unless return-comment
12600 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12601 (match-string-no-properties 1)))))
12602 ;; parse inline comment
12603 (unless comment
12604 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12605 (match-string-no-properties 1))))
12606 ;; save everything in list
12607 (setq param-list (append param-list
12608 (list (list names object direct type init
12609 comment group-comment))))
12610 ;; parse group comment and spacing
12611 (setq group-comment (vhdl-parse-group-comment)))
12612 (message "Reading interface of subprogram \"%s\"...done" name)
12613 nil)))
12614 ;; finish parsing
12615 (if parse-error
12616 (error parse-error)
12617 (setq vhdl-subprog-list
12618 (list name kind param-list return-type return-comment
12619 return-group-comment)
12620 vhdl-subprog-flattened nil)))))
12621
12622 (defun vhdl-subprog-paste-specification (kind)
12623 "Paste as a subprogram specification."
12624 (indent-according-to-mode)
12625 (let ((margin (current-column))
12626 (param-list (nth 2 vhdl-subprog-list))
12627 list-margin start names param)
12628 ;; paste keyword and name
12629 (vhdl-insert-keyword
12630 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12631 (insert (nth 0 vhdl-subprog-list))
12632 (if (not param-list)
12633 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12634 (setq start (point))
12635 ;; paste parameter list
12636 (insert " (")
12637 (unless vhdl-argument-list-indent
12638 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12639 (setq list-margin (current-column))
12640 (while param-list
12641 (setq param (car param-list))
12642 ;; paste group comment and spacing
12643 (when (memq vhdl-include-group-comments (list kind 'always))
12644 (vhdl-paste-group-comment (nth 6 param) list-margin))
12645 ;; paste object
12646 (when (nth 1 param) (insert (nth 1 param) " "))
12647 ;; paste names
12648 (setq names (nth 0 param))
12649 (while names
12650 (insert (car names))
12651 (setq names (cdr names))
12652 (when names (insert ", ")))
12653 ;; paste direction
12654 (insert " : ")
12655 (when (nth 2 param) (insert (nth 2 param) " "))
12656 ;; paste type
12657 (insert (nth 3 param))
12658 ;; paste initialization
12659 (when (nth 4 param) (insert " := " (nth 4 param)))
12660 ;; terminate line
12661 (if (cdr param-list)
12662 (insert ";")
12663 (insert ")")
12664 (when (null (nth 3 vhdl-subprog-list))
12665 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12666 ;; paste comment
12667 (when (and vhdl-include-port-comments (nth 5 param))
12668 (vhdl-comment-insert-inline (nth 5 param) t))
12669 (setq param-list (cdr param-list))
12670 (when param-list (insert "\n") (indent-to list-margin)))
12671 (when (nth 3 vhdl-subprog-list)
12672 (insert "\n") (indent-to list-margin)
12673 ;; paste group comment and spacing
12674 (when (memq vhdl-include-group-comments (list kind 'always))
12675 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12676 ;; paste return type
12677 (insert "return " (nth 3 vhdl-subprog-list))
12678 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12679 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12680 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12681 ;; align parameter list
12682 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12683 ;; paste body
12684 (when (eq kind 'body)
12685 (insert "\n")
12686 (vhdl-template-begin-end
12687 (unless (vhdl-standard-p '87)
12688 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12689 (nth 0 vhdl-subprog-list) margin))))
12690
12691 (defun vhdl-subprog-paste-declaration ()
12692 "Paste as a subprogram declaration."
12693 (interactive)
12694 (if (not vhdl-subprog-list)
12695 (error "ERROR: No subprogram interface read")
12696 (message "Pasting interface as subprogram declaration \"%s\"..."
12697 (car vhdl-subprog-list))
12698 ;; paste specification
12699 (vhdl-subprog-paste-specification 'decl)
12700 (message "Pasting interface as subprogram declaration \"%s\"...done"
12701 (car vhdl-subprog-list))))
12702
12703 (defun vhdl-subprog-paste-body ()
12704 "Paste as a subprogram body."
12705 (interactive)
12706 (if (not vhdl-subprog-list)
12707 (error "ERROR: No subprogram interface read")
12708 (message "Pasting interface as subprogram body \"%s\"..."
12709 (car vhdl-subprog-list))
12710 ;; paste specification and body
12711 (vhdl-subprog-paste-specification 'body)
12712 (message "Pasting interface as subprogram body \"%s\"...done"
12713 (car vhdl-subprog-list))))
12714
12715 (defun vhdl-subprog-paste-call ()
12716 "Paste as a subprogram call."
12717 (interactive)
12718 (if (not vhdl-subprog-list)
12719 (error "ERROR: No subprogram interface read")
12720 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12721 param-list margin list-margin param start)
12722 ;; flatten local copy of interface list (must be flat for parameter mapping)
12723 (vhdl-subprog-flatten)
12724 (setq param-list (nth 2 vhdl-subprog-list))
12725 (indent-according-to-mode)
12726 (setq margin (current-indentation))
12727 (message "Pasting interface as subprogram call \"%s\"..."
12728 (car vhdl-subprog-list))
12729 ;; paste name
12730 (insert (nth 0 vhdl-subprog-list))
12731 (if (not param-list)
12732 (insert ";")
12733 (setq start (point))
12734 ;; paste parameter list
12735 (insert " (")
12736 (unless vhdl-argument-list-indent
12737 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12738 (setq list-margin (current-column))
12739 (while param-list
12740 (setq param (car param-list))
12741 ;; paste group comment and spacing
12742 (when (eq vhdl-include-group-comments 'always)
12743 (vhdl-paste-group-comment (nth 6 param) list-margin))
12744 ;; paste formal port
12745 (insert (car (nth 0 param)) " => ")
12746 (setq param-list (cdr param-list))
12747 (insert (if param-list "," ");"))
12748 ;; paste comment
12749 (when (and vhdl-include-port-comments (nth 5 param))
12750 (vhdl-comment-insert-inline (nth 5 param)))
12751 (when param-list (insert "\n") (indent-to list-margin)))
12752 ;; align parameter list
12753 (when vhdl-auto-align
12754 (vhdl-align-region-groups start (point) 1)))
12755 (message "Pasting interface as subprogram call \"%s\"...done"
12756 (car vhdl-subprog-list))
12757 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12758
12759
12760 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12761 ;;; Miscellaneous
12762 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12763
12764 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12765 ;; Hippie expand customization
12766
12767 (defvar vhdl-expand-upper-case nil)
12768
12769 (defun vhdl-try-expand-abbrev (old)
12770 "Try expanding abbreviations from `vhdl-abbrev-list'."
12771 (unless old
12772 (he-init-string (he-dabbrev-beg) (point))
12773 (setq he-expand-list
12774 (let ((abbrev-list vhdl-abbrev-list)
12775 (sel-abbrev-list '()))
12776 (while abbrev-list
12777 (when (or (not (stringp (car abbrev-list)))
12778 (string-match
12779 (concat "^" he-search-string) (car abbrev-list)))
12780 (setq sel-abbrev-list
12781 (cons (car abbrev-list) sel-abbrev-list)))
12782 (setq abbrev-list (cdr abbrev-list)))
12783 (nreverse sel-abbrev-list))))
12784 (while (and he-expand-list
12785 (or (not (stringp (car he-expand-list)))
12786 (he-string-member (car he-expand-list) he-tried-table t)))
12787 (unless (stringp (car he-expand-list))
12788 (setq vhdl-expand-upper-case (car he-expand-list)))
12789 (setq he-expand-list (cdr he-expand-list)))
12790 (if (null he-expand-list)
12791 (progn (when old (he-reset-string))
12792 nil)
12793 (he-substitute-string
12794 (if vhdl-expand-upper-case
12795 (upcase (car he-expand-list))
12796 (car he-expand-list))
12797 t)
12798 (setq he-expand-list (cdr he-expand-list))
12799 t))
12800
12801 (defun vhdl-he-list-beg ()
12802 "Also looks at the word before `(' in order to better match parenthesized
12803 expressions (e.g. for index ranges of types and signals)."
12804 (save-excursion
12805 (condition-case ()
12806 (progn (backward-up-list 1)
12807 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12808 (error ()))
12809 (point)))
12810
12811 ;; override `he-list-beg' from `hippie-exp'
12812 (unless (and (boundp 'viper-mode) viper-mode)
12813 (defalias 'he-list-beg 'vhdl-he-list-beg))
12814
12815 ;; function for expanding abbrevs and dabbrevs
12816 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12817 '(try-expand-dabbrev
12818 try-expand-dabbrev-all-buffers
12819 vhdl-try-expand-abbrev)))
12820
12821 ;; function for expanding parenthesis
12822 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12823 '(try-expand-list
12824 try-expand-list-all-buffers)))
12825
12826 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12827 ;; Line handling functions
12828
12829 (defun vhdl-current-line ()
12830 "Return the line number of the line containing point."
12831 (save-restriction
12832 (widen)
12833 (1+ (count-lines (point-min) (point-at-bol)))))
12834
12835 (defun vhdl-line-kill-entire (&optional arg)
12836 "Delete entire line."
12837 (interactive "p")
12838 (beginning-of-line)
12839 (kill-line (or arg 1)))
12840
12841 (defun vhdl-line-kill (&optional arg)
12842 "Kill current line."
12843 (interactive "p")
12844 (vhdl-line-kill-entire arg))
12845
12846 (defun vhdl-line-copy (&optional arg)
12847 "Copy current line."
12848 (interactive "p")
12849 (save-excursion
12850 (let ((position (point-at-bol)))
12851 (forward-line (or arg 1))
12852 (copy-region-as-kill position (point)))))
12853
12854 (defun vhdl-line-yank ()
12855 "Yank entire line."
12856 (interactive)
12857 (beginning-of-line)
12858 (yank))
12859
12860 (defun vhdl-line-expand (&optional prefix-arg)
12861 "Hippie-expand current line."
12862 (interactive "P")
12863 (require 'hippie-exp)
12864 (let ((case-fold-search t) (case-replace nil)
12865 (hippie-expand-try-functions-list
12866 '(try-expand-line try-expand-line-all-buffers)))
12867 (hippie-expand prefix-arg)))
12868
12869 (defun vhdl-line-transpose-next (&optional arg)
12870 "Interchange this line with next line."
12871 (interactive "p")
12872 (forward-line 1)
12873 (transpose-lines (or arg 1))
12874 (forward-line -1))
12875
12876 (defun vhdl-line-transpose-previous (&optional arg)
12877 "Interchange this line with previous line."
12878 (interactive "p")
12879 (forward-line 1)
12880 (transpose-lines (- 0 (or arg 0)))
12881 (forward-line -1))
12882
12883 (defun vhdl-line-open ()
12884 "Open a new line and indent."
12885 (interactive)
12886 (end-of-line -0)
12887 (newline-and-indent))
12888
12889 (defun vhdl-delete-indentation ()
12890 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12891 it works within comments too."
12892 (interactive)
12893 (let ((fill-prefix "-- "))
12894 (delete-indentation)))
12895
12896 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12897 ;; Move functions
12898
12899 (defun vhdl-forward-same-indent ()
12900 "Move forward to next line with same indent."
12901 (interactive)
12902 (let ((pos (point))
12903 (indent (current-indentation)))
12904 (beginning-of-line 2)
12905 (while (and (not (eobp))
12906 (or (looking-at "^\\s-*\\(--.*\\)?$")
12907 (> (current-indentation) indent)))
12908 (beginning-of-line 2))
12909 (if (= (current-indentation) indent)
12910 (back-to-indentation)
12911 (message "No following line with same indent found in this block")
12912 (goto-char pos)
12913 nil)))
12914
12915 (defun vhdl-backward-same-indent ()
12916 "Move backward to previous line with same indent."
12917 (interactive)
12918 (let ((pos (point))
12919 (indent (current-indentation)))
12920 (beginning-of-line -0)
12921 (while (and (not (bobp))
12922 (or (looking-at "^\\s-*\\(--.*\\)?$")
12923 (> (current-indentation) indent)))
12924 (beginning-of-line -0))
12925 (if (= (current-indentation) indent)
12926 (back-to-indentation)
12927 (message "No preceding line with same indent found in this block")
12928 (goto-char pos)
12929 nil)))
12930
12931 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12932 ;; Statistics
12933
12934 (defun vhdl-statistics-buffer ()
12935 "Get some file statistics."
12936 (interactive)
12937 (let ((no-stats 0)
12938 (no-code-lines 0)
12939 (no-empty-lines 0)
12940 (no-comm-lines 0)
12941 (no-comments 0)
12942 (no-lines (count-lines (point-min) (point-max))))
12943 (save-excursion
12944 ;; count statements
12945 (goto-char (point-min))
12946 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12947 (if (match-string 1)
12948 (goto-char (match-end 1))
12949 (setq no-stats (1+ no-stats))))
12950 ;; count code lines
12951 (goto-char (point-min))
12952 (while (not (eobp))
12953 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12954 (setq no-code-lines (1+ no-code-lines)))
12955 (beginning-of-line 2))
12956 ;; count empty lines
12957 (goto-char (point-min))
12958 (while (and (re-search-forward "^\\s-*$" nil t)
12959 (not (eq (point) (point-max))))
12960 (if (match-string 1)
12961 (goto-char (match-end 1))
12962 (setq no-empty-lines (1+ no-empty-lines))
12963 (unless (eq (point) (point-max))
12964 (forward-char))))
12965 ;; count comment-only lines
12966 (goto-char (point-min))
12967 (while (re-search-forward "^\\s-*--.*" nil t)
12968 (if (match-string 1)
12969 (goto-char (match-end 1))
12970 (setq no-comm-lines (1+ no-comm-lines))))
12971 ;; count comments
12972 (goto-char (point-min))
12973 (while (re-search-forward "--.*" nil t)
12974 (if (match-string 1)
12975 (goto-char (match-end 1))
12976 (setq no-comments (1+ no-comments)))))
12977 ;; print results
12978 (message "\n\
12979 File statistics: \"%s\"\n\
12980 -----------------------\n\
12981 # statements : %5d\n\
12982 # code lines : %5d\n\
12983 # empty lines : %5d\n\
12984 # comment lines : %5d\n\
12985 # comments : %5d\n\
12986 # total lines : %5d\n"
12987 (buffer-file-name) no-stats no-code-lines no-empty-lines
12988 no-comm-lines no-comments no-lines)
12989 (unless vhdl-emacs-21 (vhdl-show-messages))))
12990
12991 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12992 ;; Help functions
12993
12994 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12995 "Like `re-search-forward', but does not match within literals."
12996 (let (pos)
12997 (save-excursion
12998 (while (and (setq pos (re-search-forward regexp bound noerror count))
12999 (vhdl-in-literal))))
13000 (when pos (goto-char pos))
13001 pos))
13002
13003 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
13004 "Like `re-search-backward', but does not match within literals."
13005 (let (pos)
13006 (save-excursion
13007 (while (and (setq pos (re-search-backward regexp bound noerror count))
13008 (vhdl-in-literal))))
13009 (when pos (goto-char pos))
13010 pos))
13011
13012
13013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13014 ;;; Project
13015 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13016
13017 (defun vhdl-set-project (name)
13018 "Set current project to NAME."
13019 (interactive
13020 (list (let ((completion-ignore-case t))
13021 (completing-read "Project name: " vhdl-project-alist nil t))))
13022 (cond ((equal name "")
13023 (setq vhdl-project nil)
13024 (message "Current VHDL project: None"))
13025 ((assoc name vhdl-project-alist)
13026 (setq vhdl-project name)
13027 (message "Current VHDL project: \"%s\"" name))
13028 (t
13029 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
13030 (vhdl-speedbar-update-current-project))
13031
13032 (defun vhdl-set-default-project ()
13033 "Set current project as default on startup."
13034 (interactive)
13035 (customize-set-variable 'vhdl-project vhdl-project)
13036 (customize-save-customized))
13037
13038 (defun vhdl-toggle-project (name token indent)
13039 "Set current project to NAME or unset if NAME is current project."
13040 (vhdl-set-project (if (equal name vhdl-project) "" name)))
13041
13042 (defun vhdl-export-project (file-name)
13043 "Write project setup for current project."
13044 (interactive
13045 (let ((name (vhdl-resolve-env-variable
13046 (vhdl-replace-string
13047 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13048 (concat (subst-char-in-string
13049 ? ?_ (or (vhdl-project-p)
13050 (error "ERROR: No current project")))
13051 " " (user-login-name))))))
13052 (list (read-file-name
13053 "Write project file: "
13054 (when (file-name-absolute-p name) "") nil nil name))))
13055 (setq file-name (abbreviate-file-name file-name))
13056 (let ((orig-buffer (current-buffer)))
13057 (unless (file-exists-p (file-name-directory file-name))
13058 (make-directory (file-name-directory file-name) t))
13059 (if (not (file-writable-p file-name))
13060 (error "ERROR: File not writable: \"%s\"" file-name)
13061 (set-buffer (find-file-noselect file-name t t))
13062 (erase-buffer)
13063 (insert ";; -*- Emacs-Lisp -*-\n\n"
13064 ";;; " (file-name-nondirectory file-name)
13065 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
13066 ";; Project : " vhdl-project "\n"
13067 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
13068 (user-login-name) "\n\n\n"
13069 ";; project name\n"
13070 "(setq vhdl-project \"" vhdl-project "\")\n\n"
13071 ";; project setup\n"
13072 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
13073 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
13074 (insert ")\n")
13075 (save-buffer)
13076 (kill-buffer (current-buffer))
13077 (set-buffer orig-buffer))))
13078
13079 (defun vhdl-import-project (file-name &optional auto not-make-current)
13080 "Read project setup and set current project."
13081 (interactive
13082 (let ((name (vhdl-resolve-env-variable
13083 (vhdl-replace-string
13084 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13085 (concat "" " " (user-login-name))))))
13086 (list (read-file-name
13087 "Read project file: " (when (file-name-absolute-p name) "") nil t
13088 (file-name-directory name)))))
13089 (when (file-exists-p file-name)
13090 (condition-case ()
13091 (let ((current-project vhdl-project))
13092 (load-file file-name)
13093 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
13094 (vhdl-adelete 'vhdl-project-alist vhdl-project)
13095 (error ""))
13096 (if not-make-current
13097 (setq vhdl-project current-project)
13098 (setq vhdl-compiler
13099 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
13100 (vhdl-update-mode-menu)
13101 (vhdl-speedbar-refresh)
13102 (unless not-make-current
13103 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
13104 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
13105 (error (vhdl-warning
13106 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
13107
13108 (defun vhdl-duplicate-project ()
13109 "Duplicate setup of current project."
13110 (interactive)
13111 (let ((new-name (read-from-minibuffer "New project name: "))
13112 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
13113 (setq vhdl-project-alist
13114 (append vhdl-project-alist
13115 (list (cons new-name project-entry))))
13116 (vhdl-update-mode-menu)))
13117
13118 (defun vhdl-auto-load-project ()
13119 "Automatically load project setup at startup."
13120 (let ((file-name-list vhdl-project-file-name)
13121 file-list list-length)
13122 (while file-name-list
13123 (setq file-list
13124 (append file-list
13125 (file-expand-wildcards
13126 (vhdl-resolve-env-variable
13127 (vhdl-replace-string
13128 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
13129 (concat "* " (user-login-name)))))))
13130 (setq list-length (or list-length (length file-list)))
13131 (setq file-name-list (cdr file-name-list)))
13132 (while file-list
13133 (vhdl-import-project (expand-file-name (car file-list)) t
13134 (not (> list-length 0)))
13135 (setq list-length (1- list-length))
13136 (setq file-list (cdr file-list)))))
13137
13138 ;; automatically load project setup when idle after startup
13139 (when (memq 'startup vhdl-project-auto-load)
13140 (if noninteractive
13141 (vhdl-auto-load-project)
13142 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13143
13144
13145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13146 ;;; Hideshow
13147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13148 ;; (using `hideshow.el')
13149
13150 (defconst vhdl-hs-start-regexp
13151 (concat
13152 "\\(^\\)\\s-*\\("
13153 ;; generic/port clause
13154 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13155 ;; component
13156 "component\\>\\|"
13157 ;; component instantiation
13158 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13159 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13160 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13161 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13162 ;; subprogram
13163 "\\(function\\|procedure\\)\\>\\|"
13164 ;; process, block
13165 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13166 ;; configuration declaration
13167 "configuration\\>"
13168 "\\)")
13169 "Regexp to match start of construct to hide.")
13170
13171 (defun vhdl-hs-forward-sexp-func (count)
13172 "Find end of construct to hide (for hideshow). Only searches forward."
13173 (let ((pos (point)))
13174 (vhdl-prepare-search-2
13175 (beginning-of-line)
13176 (cond
13177 ;; generic/port clause
13178 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13179 (goto-char (match-end 0))
13180 (backward-char)
13181 (forward-sexp))
13182 ;; component declaration
13183 ((looking-at "^\\s-*component\\>")
13184 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13185 ;; component instantiation
13186 ((looking-at
13187 (concat
13188 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13189 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13190 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13191 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13192 (goto-char (match-end 0))
13193 (backward-char)
13194 (forward-sexp)
13195 (setq pos (point))
13196 (vhdl-forward-syntactic-ws)
13197 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13198 (goto-char (match-end 0))
13199 (backward-char)
13200 (forward-sexp)
13201 (setq pos (point)))
13202 (goto-char pos))
13203 ;; subprogram declaration/body
13204 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13205 (goto-char (match-end 0))
13206 (vhdl-forward-syntactic-ws)
13207 (when (looking-at "(")
13208 (forward-sexp))
13209 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13210 (vhdl-in-literal)))
13211 ;; subprogram body
13212 (when (match-string 2)
13213 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13214 (backward-word 1)
13215 (vhdl-forward-sexp)))
13216 ;; block (recursive)
13217 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13218 (goto-char (match-end 0))
13219 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13220 (match-beginning 2))
13221 (vhdl-hs-forward-sexp-func count)))
13222 ;; process
13223 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13224 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13225 ;; configuration declaration
13226 ((looking-at "^\\s-*configuration\\>")
13227 (forward-word 4)
13228 (vhdl-forward-sexp))
13229 (t (goto-char pos))))))
13230
13231 (defun vhdl-hideshow-init ()
13232 "Initialize `hideshow'."
13233 (when vhdl-hideshow-menu
13234 (vhdl-hs-minor-mode 1)))
13235
13236 (defun vhdl-hs-minor-mode (&optional arg)
13237 "Toggle hideshow minor mode and update menu bar."
13238 (interactive "P")
13239 (require 'hideshow)
13240 ;; check for hideshow version 5.x
13241 (if (not (boundp 'hs-block-start-mdata-select))
13242 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13243 ;; initialize hideshow
13244 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13245 (setq hs-special-modes-alist
13246 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13247 'vhdl-hs-forward-sexp-func nil)
13248 hs-special-modes-alist)))
13249 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13250 (if vhdl-hide-all-init
13251 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13252 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13253 (hs-minor-mode arg)
13254 (force-mode-line-update))) ; hack to update menu bar
13255
13256
13257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13258 ;;; Font locking
13259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13260 ;; (using `font-lock.el')
13261
13262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13263 ;; Help functions
13264
13265 (defun vhdl-within-translate-off ()
13266 "Return point if within translate-off region, else nil."
13267 (and (save-excursion
13268 (re-search-backward
13269 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13270 (equal "off" (match-string 1))
13271 (point)))
13272
13273 (defun vhdl-start-translate-off (limit)
13274 "Return point before translate-off pragma if before LIMIT, else nil."
13275 (when (re-search-forward
13276 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13277 (match-beginning 0)))
13278
13279 (defun vhdl-end-translate-off (limit)
13280 "Return point after translate-on pragma if before LIMIT, else nil."
13281 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13282
13283 (defun vhdl-match-translate-off (limit)
13284 "Match a translate-off block, setting match-data and returning t, else nil."
13285 (when (< (point) limit)
13286 (let ((start (or (vhdl-within-translate-off)
13287 (vhdl-start-translate-off limit)))
13288 (case-fold-search t))
13289 (when start
13290 (let ((end (or (vhdl-end-translate-off limit) limit)))
13291 (set-match-data (list start end))
13292 (goto-char end))))))
13293
13294 (defun vhdl-font-lock-match-item (limit)
13295 "Match, and move over, any declaration item after point. Adapted from
13296 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13297 (condition-case nil
13298 (save-restriction
13299 (narrow-to-region (point-min) limit)
13300 ;; match item
13301 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13302 (save-match-data
13303 (goto-char (match-end 1))
13304 ;; move to next item
13305 (if (looking-at "\\(\\s-*,\\)")
13306 (goto-char (match-end 1))
13307 (end-of-line) t))))
13308 (error t)))
13309
13310 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13311 ;; Syntax definitions
13312
13313 (defconst vhdl-font-lock-syntactic-keywords
13314 '(("\\('\\).\\('\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13315 "Mark single quotes as having string quote syntax in `c' instances.")
13316
13317 (defvar vhdl-font-lock-keywords nil
13318 "Regular expressions to highlight in VHDL Mode.")
13319
13320 (defvar vhdl-font-lock-keywords-0
13321 ;; set in `vhdl-font-lock-init' because dependent on user options
13322 "For consideration as a value of `vhdl-font-lock-keywords'.
13323 This does highlighting of template prompts and directives (pragmas).")
13324
13325 (defvar vhdl-font-lock-keywords-1 nil
13326 ;; set in `vhdl-font-lock-init' because dependent on user options
13327 "For consideration as a value of `vhdl-font-lock-keywords'.
13328 This does highlighting of keywords and standard identifiers.")
13329
13330 (defconst vhdl-font-lock-keywords-2
13331 (list
13332 ;; highlight names of units, subprograms, and components when declared
13333 (list
13334 (concat
13335 "^\\s-*\\("
13336 "architecture\\|configuration\\|context\\|entity\\|package"
13337 "\\(\\s-+body\\)?\\|"
13338 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13339 "\\)\\s-+\\(\\w+\\)")
13340 5 'font-lock-function-name-face)
13341
13342 ;; highlight entity names of architectures and configurations
13343 (list
13344 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13345 2 'font-lock-function-name-face)
13346
13347 ;; highlight labels of common constructs
13348 (list
13349 (concat
13350 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13351 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13352 "postponed\\|process\\|"
13353 (when (vhdl-standard-p 'ams) "procedural\\|")
13354 "with\\|while"
13355 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13356 1 'font-lock-function-name-face)
13357
13358 ;; highlight label and component name of component instantiations
13359 (list
13360 (concat
13361 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13362 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13363 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13364
13365 ;; highlight label and instantiated unit of component instantiations
13366 (list
13367 (concat
13368 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13369 "\\(component\\|configuration\\|entity\\)\\s-+"
13370 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13371 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13372 '(5 font-lock-function-name-face nil t)
13373 '(7 font-lock-function-name-face nil t))
13374
13375 ;; highlight names and labels at end of constructs
13376 (list
13377 (concat
13378 "^\\s-*end\\s-+\\(\\("
13379 "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
13380 "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
13381 "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
13382 (when (vhdl-standard-p 'ams) "procedural\\|")
13383 "units"
13384 "\\)\\s-+\\)?\\(\\w*\\)")
13385 5 'font-lock-function-name-face)
13386
13387 ;; highlight labels in exit and next statements
13388 (list
13389 (concat
13390 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13391 3 'font-lock-function-name-face)
13392
13393 ;; highlight entity name in attribute specifications
13394 (list
13395 (concat
13396 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13397 1 'font-lock-function-name-face)
13398
13399 ;; highlight labels in block and component specifications
13400 (list
13401 (concat
13402 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13403 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13404 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13405
13406 ;; highlight names in library clauses
13407 (list "^\\s-*library\\>"
13408 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13409
13410 ;; highlight names in use clauses
13411 (list
13412 (concat
13413 "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13414 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13415 '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
13416 '(8 font-lock-function-name-face nil t))
13417
13418 ;; highlight attribute name in attribute declarations/specifications
13419 (list
13420 (concat
13421 "^\\s-*attribute\\s-+\\(\\w+\\)")
13422 1 'vhdl-font-lock-attribute-face)
13423
13424 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13425 (list
13426 (concat
13427 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13428 5 'font-lock-type-face)
13429
13430 ;; highlight signal/variable/constant declaration names
13431 (list "\\(:[^=]\\)"
13432 '(vhdl-font-lock-match-item
13433 (progn (goto-char (match-beginning 1))
13434 (skip-syntax-backward " ")
13435 (skip-syntax-backward "w_")
13436 (skip-syntax-backward " ")
13437 (while (= (preceding-char) ?,)
13438 (backward-char 1)
13439 (skip-syntax-backward " ")
13440 (skip-syntax-backward "w_")
13441 (skip-syntax-backward " ")))
13442 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13443
13444 ;; highlight formal parameters in component instantiations and subprogram
13445 ;; calls
13446 (list "\\(=>\\)"
13447 '(vhdl-font-lock-match-item
13448 (progn (goto-char (match-beginning 1))
13449 (skip-syntax-backward " ")
13450 (while (= (preceding-char) ?\)) (backward-sexp))
13451 (skip-syntax-backward "w_")
13452 (skip-syntax-backward " ")
13453 (when (memq (preceding-char) '(?n ?N ?|))
13454 (goto-char (point-max))))
13455 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13456
13457 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13458 ;; variables
13459 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13460 '(vhdl-font-lock-match-item
13461 (progn (goto-char (match-end 1)) (match-beginning 2))
13462 nil (1 font-lock-variable-name-face)))
13463
13464 ;; highlight tool directives
13465 (list
13466 (concat
13467 "^\\s-*\\(`\\w+\\)")
13468 1 'font-lock-preprocessor-face)
13469 )
13470 "For consideration as a value of `vhdl-font-lock-keywords'.
13471 This does context sensitive highlighting of names and labels.")
13472
13473 (defvar vhdl-font-lock-keywords-3 nil
13474 ;; set in `vhdl-font-lock-init' because dependent on user options
13475 "For consideration as a value of `vhdl-font-lock-keywords'.
13476 This does highlighting of words with special syntax.")
13477
13478 (defvar vhdl-font-lock-keywords-4 nil
13479 ;; set in `vhdl-font-lock-init' because dependent on user options
13480 "For consideration as a value of `vhdl-font-lock-keywords'.
13481 This does highlighting of additional reserved words.")
13482
13483 (defconst vhdl-font-lock-keywords-5
13484 ;; background highlight translate-off regions
13485 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13486 "For consideration as a value of `vhdl-font-lock-keywords'.
13487 This does background highlighting of translate-off regions.")
13488
13489 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13490 ;; Font and color definitions
13491
13492 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13493 "Face name to use for prompts.")
13494
13495 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13496 "Face name to use for standardized attributes.")
13497
13498 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13499 "Face name to use for standardized enumeration values.")
13500
13501 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13502 "Face name to use for standardized functions and packages.")
13503
13504 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13505 "Face name to use for directives.")
13506
13507 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13508 "Face name to use for additional reserved words.")
13509
13510 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13511 "Face name to use for translate-off regions.")
13512
13513 ;; face names to use for words with special syntax.
13514 (let ((syntax-alist vhdl-special-syntax-alist)
13515 name)
13516 (while syntax-alist
13517 (setq name (vhdl-function-name
13518 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13519 (eval `(defvar ,name ',name
13520 ,(concat "Face name to use for "
13521 (nth 0 (car syntax-alist)) ".")))
13522 (setq syntax-alist (cdr syntax-alist))))
13523
13524 (defgroup vhdl-highlight-faces nil
13525 "Faces for highlighting."
13526 :group 'vhdl-highlight)
13527
13528 ;; add faces used from `font-lock'
13529 (custom-add-to-group
13530 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13531 (custom-add-to-group
13532 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13533 (custom-add-to-group
13534 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13535 (custom-add-to-group
13536 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13537 (custom-add-to-group
13538 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13539 (custom-add-to-group
13540 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13541
13542 (defface vhdl-font-lock-prompt-face
13543 '((((min-colors 88) (class color) (background light))
13544 (:foreground "Red1" :bold t))
13545 (((class color) (background light)) (:foreground "Red" :bold t))
13546 (((class color) (background dark)) (:foreground "Pink" :bold t))
13547 (t (:inverse-video t)))
13548 "Font lock mode face used to highlight prompts."
13549 :group 'vhdl-highlight-faces)
13550
13551 (defface vhdl-font-lock-attribute-face
13552 '((((class color) (background light)) (:foreground "Orchid"))
13553 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13554 (t (:italic t :bold t)))
13555 "Font lock mode face used to highlight standardized attributes."
13556 :group 'vhdl-highlight-faces)
13557
13558 (defface vhdl-font-lock-enumvalue-face
13559 '((((class color) (background light)) (:foreground "SaddleBrown"))
13560 (((class color) (background dark)) (:foreground "BurlyWood"))
13561 (t (:italic t :bold t)))
13562 "Font lock mode face used to highlight standardized enumeration values."
13563 :group 'vhdl-highlight-faces)
13564
13565 (defface vhdl-font-lock-function-face
13566 '((((class color) (background light)) (:foreground "Cyan4"))
13567 (((class color) (background dark)) (:foreground "Orchid1"))
13568 (t (:italic t :bold t)))
13569 "Font lock mode face used to highlight standardized functions and packages."
13570 :group 'vhdl-highlight-faces)
13571
13572 (defface vhdl-font-lock-directive-face
13573 '((((class color) (background light)) (:foreground "CadetBlue"))
13574 (((class color) (background dark)) (:foreground "Aquamarine"))
13575 (t (:italic t :bold t)))
13576 "Font lock mode face used to highlight directives."
13577 :group 'vhdl-highlight-faces)
13578
13579 (defface vhdl-font-lock-reserved-words-face
13580 '((((class color) (background light)) (:foreground "Orange" :bold t))
13581 (((min-colors 88) (class color) (background dark))
13582 (:foreground "Yellow1" :bold t))
13583 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13584 (t ()))
13585 "Font lock mode face used to highlight additional reserved words."
13586 :group 'vhdl-highlight-faces)
13587
13588 (defface vhdl-font-lock-translate-off-face
13589 '((((class color) (background light)) (:background "LightGray"))
13590 (((class color) (background dark)) (:background "DimGray"))
13591 (t ()))
13592 "Font lock mode face used to background highlight translate-off regions."
13593 :group 'vhdl-highlight-faces)
13594
13595 ;; font lock mode faces used to highlight words with special syntax.
13596 (let ((syntax-alist vhdl-special-syntax-alist))
13597 (while syntax-alist
13598 (eval `(defface ,(vhdl-function-name
13599 "vhdl-font-lock" (caar syntax-alist) "face")
13600 '((((class color) (background light))
13601 (:foreground ,(nth 2 (car syntax-alist))))
13602 (((class color) (background dark))
13603 (:foreground ,(nth 3 (car syntax-alist))))
13604 (t ()))
13605 ,(concat "Font lock mode face used to highlight "
13606 (nth 0 (car syntax-alist)) ".")
13607 :group 'vhdl-highlight-faces))
13608 (setq syntax-alist (cdr syntax-alist))))
13609
13610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13611 ;; Font lock initialization
13612
13613 (defun vhdl-font-lock-init ()
13614 "Initialize fontification."
13615 ;; highlight template prompts and directives
13616 (setq vhdl-font-lock-keywords-0
13617 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13618 vhdl-template-prompt-syntax ">\\)")
13619 2 'vhdl-font-lock-prompt-face t)
13620 (list (concat "--\\s-*"
13621 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13622 2 'vhdl-font-lock-directive-face t)
13623 ;; highlight c-preprocessor directives
13624 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13625 '(1 font-lock-builtin-face)
13626 '(3 font-lock-variable-name-face nil t))))
13627 ;; highlight keywords and standardized types, attributes, enumeration
13628 ;; values, and subprograms
13629 (setq vhdl-font-lock-keywords-1
13630 (list
13631 (list (concat "'" vhdl-attributes-regexp)
13632 1 'vhdl-font-lock-attribute-face)
13633 (list vhdl-types-regexp 1 'font-lock-type-face)
13634 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13635 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13636 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13637 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13638 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13639 ;; highlight words with special syntax.
13640 (setq vhdl-font-lock-keywords-3
13641 (let ((syntax-alist vhdl-special-syntax-alist)
13642 keywords)
13643 (while syntax-alist
13644 (setq keywords
13645 (cons
13646 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13647 (vhdl-function-name
13648 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13649 (nth 4 (car syntax-alist)))
13650 keywords))
13651 (setq syntax-alist (cdr syntax-alist)))
13652 keywords))
13653 ;; highlight additional reserved words
13654 (setq vhdl-font-lock-keywords-4
13655 (list (list vhdl-reserved-words-regexp 1
13656 'vhdl-font-lock-reserved-words-face)))
13657 ;; highlight everything together
13658 (setq vhdl-font-lock-keywords
13659 (append
13660 vhdl-font-lock-keywords-0
13661 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13662 (when (or vhdl-highlight-forbidden-words
13663 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13664 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13665 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13666 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13667
13668 ;; initialize fontification for VHDL Mode
13669 (vhdl-font-lock-init)
13670
13671 (defun vhdl-fontify-buffer ()
13672 "Re-initialize fontification and fontify buffer."
13673 (interactive)
13674 (setq font-lock-defaults
13675 `(vhdl-font-lock-keywords
13676 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13677 beginning-of-line))
13678 (when (fboundp 'font-lock-unset-defaults)
13679 (font-lock-unset-defaults)) ; not implemented in XEmacs
13680 (font-lock-set-defaults)
13681 (font-lock-mode nil)
13682 (font-lock-mode t))
13683
13684 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13685 ;; Initialization for PostScript printing
13686
13687 (defun vhdl-ps-print-settings ()
13688 "Initialize custom face and page settings for PostScript printing."
13689 ;; define custom face settings
13690 (unless (or (not vhdl-print-customize-faces)
13691 ps-print-color-p)
13692 (set (make-local-variable 'ps-bold-faces)
13693 '(font-lock-keyword-face
13694 font-lock-type-face
13695 vhdl-font-lock-attribute-face
13696 vhdl-font-lock-enumvalue-face
13697 vhdl-font-lock-directive-face))
13698 (set (make-local-variable 'ps-italic-faces)
13699 '(font-lock-comment-face
13700 font-lock-function-name-face
13701 font-lock-type-face
13702 vhdl-font-lock-attribute-face
13703 vhdl-font-lock-enumvalue-face
13704 vhdl-font-lock-directive-face))
13705 (set (make-local-variable 'ps-underlined-faces)
13706 '(font-lock-string-face))
13707 (setq ps-always-build-face-reference t))
13708 ;; define page settings, so that a line containing 79 characters (default)
13709 ;; fits into one column
13710 (when vhdl-print-two-column
13711 (set (make-local-variable 'ps-landscape-mode) t)
13712 (set (make-local-variable 'ps-number-of-columns) 2)
13713 (set (make-local-variable 'ps-font-size) 7.0)
13714 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13715 (set (make-local-variable 'ps-header-font-size) 9.0)
13716 (set (make-local-variable 'ps-header-offset) 12.0)
13717 (when (eq ps-paper-type 'letter)
13718 (set (make-local-variable 'ps-inter-column) 40.0)
13719 (set (make-local-variable 'ps-left-margin) 40.0)
13720 (set (make-local-variable 'ps-right-margin) 40.0))))
13721
13722 (defun vhdl-ps-print-init ()
13723 "Initialize PostScript printing."
13724 (if (featurep 'xemacs)
13725 (when (boundp 'ps-print-color-p)
13726 (vhdl-ps-print-settings))
13727 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13728 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13729
13730
13731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13732 ;;; Hierarchy browser (using `speedbar.el')
13733 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13734 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13735 ;; directory by using the speedbar.
13736
13737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13738 ;; Variables
13739
13740 (defvar vhdl-entity-alist nil
13741 "Cache with entities and corresponding architectures for each
13742 project/directory.")
13743 ;; structure: (parenthesized expression means list of such entries)
13744 ;; (cache-key
13745 ;; (ent-key ent-name ent-file ent-line
13746 ;; (arch-key arch-name arch-file arch-line
13747 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13748 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13749 ;; (lib-name pack-key))
13750 ;; mra-key (lib-name pack-key))
13751
13752 (defvar vhdl-config-alist nil
13753 "Cache with configurations for each project/directory.")
13754 ;; structure: (parenthesized expression means list of such entries)
13755 ;; (cache-key
13756 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13757 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13758 ;; inst-conf-key inst-lib-key)
13759 ;; (lib-name pack-key)))
13760
13761 (defvar vhdl-package-alist nil
13762 "Cache with packages for each project/directory.")
13763 ;; structure: (parenthesized expression means list of such entries)
13764 ;; (cache-key
13765 ;; (pack-key pack-name pack-file pack-line
13766 ;; (comp-key comp-name comp-file comp-line)
13767 ;; (func-key func-name func-file func-line)
13768 ;; (lib-name pack-key)
13769 ;; pack-body-file pack-body-line
13770 ;; (func-key func-name func-body-file func-body-line)
13771 ;; (lib-name pack-key)))
13772
13773 (defvar vhdl-ent-inst-alist nil
13774 "Cache with instantiated entities for each project/directory.")
13775 ;; structure: (parenthesized expression means list of such entries)
13776 ;; (cache-key (inst-ent-key))
13777
13778 (defvar vhdl-file-alist nil
13779 "Cache with design units in each file for each project/directory.")
13780 ;; structure: (parenthesized expression means list of such entries)
13781 ;; (cache-key
13782 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13783 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13784
13785 (defvar vhdl-directory-alist nil
13786 "Cache with source directories for each project.")
13787 ;; structure: (parenthesized expression means list of such entries)
13788 ;; (cache-key (directory))
13789
13790 (defvar vhdl-speedbar-shown-unit-alist nil
13791 "Alist of design units simultaneously open in the current speedbar for each
13792 directory and project.")
13793
13794 (defvar vhdl-speedbar-shown-project-list nil
13795 "List of projects simultaneously open in the current speedbar.")
13796
13797 (defvar vhdl-updated-project-list nil
13798 "List of projects and directories with updated files.")
13799
13800 (defvar vhdl-modified-file-list nil
13801 "List of modified files to be rescanned for hierarchy updating.")
13802
13803 (defvar vhdl-speedbar-hierarchy-depth 0
13804 "Depth of instantiation hierarchy to display.")
13805
13806 (defvar vhdl-speedbar-show-projects nil
13807 "Non-nil means project hierarchy is displayed in speedbar, directory
13808 hierarchy otherwise.")
13809
13810 (defun vhdl-get-end-of-unit ()
13811 "Return position of end of current unit."
13812 (let ((pos (point)))
13813 (save-excursion
13814 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
13815 (save-excursion
13816 (goto-char (match-beginning 0))
13817 (vhdl-backward-syntactic-ws)
13818 (and (/= (preceding-char) ?\;) (not (bobp))))))
13819 (re-search-backward "^[ \t]*end\\>" pos 1)
13820 (point))))
13821
13822 (defun vhdl-match-string-downcase (num &optional string)
13823 "Like `match-string-no-properties' with down-casing."
13824 (let ((match (match-string-no-properties num string)))
13825 (and match (downcase match))))
13826
13827
13828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13829 ;; Scan functions
13830
13831 (defun vhdl-scan-context-clause ()
13832 "Scan the context clause that precedes a design unit."
13833 (let (lib-alist)
13834 (save-excursion
13835 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
13836 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13837 (equal "USE" (upcase (match-string 1))))
13838 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13839 (push (cons (match-string-no-properties 1)
13840 (vhdl-match-string-downcase 2))
13841 lib-alist)))))
13842 lib-alist))
13843
13844 (defun vhdl-scan-directory-contents (name &optional project update num-string
13845 non-final)
13846 "Scan contents of VHDL files in directory or file pattern NAME."
13847 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13848 (let* ((dir-name (match-string 1 name))
13849 (file-pattern (match-string 2 name))
13850 (is-directory (= 0 (length file-pattern)))
13851 (file-list
13852 (if update
13853 (list name)
13854 (if is-directory
13855 (vhdl-get-source-files t dir-name)
13856 (vhdl-directory-files
13857 dir-name t (wildcard-to-regexp file-pattern)))))
13858 (key (or project dir-name))
13859 (file-exclude-regexp
13860 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13861 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13862 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13863 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13864 ent-alist conf-alist pack-alist ent-inst-list file-alist
13865 tmp-list tmp-entry no-files files-exist big-files)
13866 (when (or project update)
13867 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13868 conf-alist (vhdl-aget vhdl-config-alist key)
13869 pack-alist (vhdl-aget vhdl-package-alist key)
13870 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13871 file-alist (vhdl-aget vhdl-file-alist key)))
13872 (when (and (not is-directory) (null file-list))
13873 (message "No such file: \"%s\"" name))
13874 (setq files-exist file-list)
13875 (when file-list
13876 (setq no-files (length file-list))
13877 (message "Scanning %s %s\"%s\"..."
13878 (if is-directory "directory" "files") (or num-string "") name)
13879 ;; exclude files
13880 (unless (equal file-exclude-regexp "")
13881 (let ((case-fold-search nil)
13882 file-tmp-list)
13883 (while file-list
13884 (unless (string-match file-exclude-regexp (car file-list))
13885 (push (car file-list) file-tmp-list))
13886 (setq file-list (cdr file-list)))
13887 (setq file-list (nreverse file-tmp-list))))
13888 ;; do for all files
13889 (while file-list
13890 (unless noninteractive
13891 (message "Scanning %s %s\"%s\"... (%2d%%)"
13892 (if is-directory "directory" "files")
13893 (or num-string "") name
13894 (floor (* 100.0 (- no-files (length file-list))) no-files)))
13895 (let ((file-name (abbreviate-file-name (car file-list)))
13896 ent-list arch-list arch-ent-list conf-list
13897 pack-list pack-body-list inst-list inst-ent-list)
13898 ;; scan file
13899 (vhdl-visit-file
13900 file-name nil
13901 (vhdl-prepare-search-2
13902 (save-excursion
13903 ;; scan for design units
13904 (if (and limit-design-file-size
13905 (< limit-design-file-size (buffer-size)))
13906 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13907 (setq big-files t))
13908 ;; scan for entities
13909 (goto-char (point-min))
13910 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13911 (let* ((ent-name (match-string-no-properties 1))
13912 (ent-key (downcase ent-name))
13913 (ent-entry (vhdl-aget ent-alist ent-key))
13914 (lib-alist (vhdl-scan-context-clause)))
13915 (if (nth 1 ent-entry)
13916 (vhdl-warning-when-idle
13917 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13918 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13919 file-name (vhdl-current-line))
13920 (push ent-key ent-list)
13921 (vhdl-aput 'ent-alist ent-key
13922 (list ent-name file-name (vhdl-current-line)
13923 (nth 3 ent-entry) (nth 4 ent-entry)
13924 lib-alist)))))
13925 ;; scan for architectures
13926 (goto-char (point-min))
13927 (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)
13928 (let* ((arch-name (match-string-no-properties 1))
13929 (arch-key (downcase arch-name))
13930 (ent-name (match-string-no-properties 2))
13931 (ent-key (downcase ent-name))
13932 (ent-entry (vhdl-aget ent-alist ent-key))
13933 (arch-alist (nth 3 ent-entry))
13934 (arch-entry (vhdl-aget arch-alist arch-key))
13935 (lib-arch-alist (vhdl-scan-context-clause)))
13936 (if arch-entry
13937 (vhdl-warning-when-idle
13938 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13939 arch-name ent-name (nth 1 arch-entry)
13940 (nth 2 arch-entry) file-name (vhdl-current-line))
13941 (setq arch-list (cons arch-key arch-list)
13942 arch-ent-list (cons ent-key arch-ent-list))
13943 (vhdl-aput 'arch-alist arch-key
13944 (list arch-name file-name (vhdl-current-line)
13945 nil lib-arch-alist))
13946 (vhdl-aput 'ent-alist ent-key
13947 (list (or (nth 0 ent-entry) ent-name)
13948 (nth 1 ent-entry) (nth 2 ent-entry)
13949 (vhdl-sort-alist arch-alist)
13950 arch-key (nth 5 ent-entry))))))
13951 ;; scan for configurations
13952 (goto-char (point-min))
13953 (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)
13954 (let* ((conf-name (match-string-no-properties 1))
13955 (conf-key (downcase conf-name))
13956 (conf-entry (vhdl-aget conf-alist conf-key))
13957 (ent-name (match-string-no-properties 2))
13958 (ent-key (downcase ent-name))
13959 (lib-alist (vhdl-scan-context-clause))
13960 (conf-line (vhdl-current-line))
13961 (end-of-unit (vhdl-get-end-of-unit))
13962 arch-key comp-conf-list inst-key-list
13963 inst-comp-key inst-ent-key inst-arch-key
13964 inst-conf-key inst-lib-key)
13965 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13966 (setq arch-key (vhdl-match-string-downcase 1)))
13967 (if conf-entry
13968 (vhdl-warning-when-idle
13969 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13970 conf-name ent-name (nth 1 conf-entry)
13971 (nth 2 conf-entry) file-name conf-line)
13972 (push conf-key conf-list)
13973 ;; scan for subconfigurations and subentities
13974 (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)
13975 (setq inst-comp-key (vhdl-match-string-downcase 3)
13976 inst-key-list (split-string
13977 (vhdl-match-string-downcase 1)
13978 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13979 (vhdl-forward-syntactic-ws)
13980 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13981 (setq
13982 inst-lib-key (vhdl-match-string-downcase 3)
13983 inst-ent-key (and (match-string 2)
13984 (vhdl-match-string-downcase 4))
13985 inst-arch-key (and (match-string 2)
13986 (vhdl-match-string-downcase 6))
13987 inst-conf-key (and (not (match-string 2))
13988 (vhdl-match-string-downcase 4)))
13989 (while inst-key-list
13990 (setq comp-conf-list
13991 (cons (list (car inst-key-list)
13992 inst-comp-key inst-ent-key
13993 inst-arch-key inst-conf-key
13994 inst-lib-key)
13995 comp-conf-list))
13996 (setq inst-key-list (cdr inst-key-list)))))
13997 (vhdl-aput 'conf-alist conf-key
13998 (list conf-name file-name conf-line ent-key
13999 arch-key comp-conf-list lib-alist)))))
14000 ;; scan for packages
14001 (goto-char (point-min))
14002 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
14003 (let* ((pack-name (match-string-no-properties 2))
14004 (pack-key (downcase pack-name))
14005 (is-body (match-string-no-properties 1))
14006 (pack-entry (vhdl-aget pack-alist pack-key))
14007 (pack-line (vhdl-current-line))
14008 (end-of-unit (vhdl-get-end-of-unit))
14009 comp-name func-name comp-alist func-alist lib-alist)
14010 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14011 (vhdl-warning-when-idle
14012 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
14013 (if is-body " body" "") pack-name
14014 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14015 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
14016 file-name (vhdl-current-line))
14017 ;; scan for context clauses
14018 (setq lib-alist (vhdl-scan-context-clause))
14019 ;; scan for component and subprogram declarations/bodies
14020 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
14021 (if (equal (upcase (match-string 1)) "COMPONENT")
14022 (setq comp-name (match-string-no-properties 2)
14023 comp-alist
14024 (cons (list (downcase comp-name) comp-name
14025 file-name (vhdl-current-line))
14026 comp-alist))
14027 (setq func-name (match-string-no-properties 2)
14028 func-alist
14029 (cons (list (downcase func-name) func-name
14030 file-name (vhdl-current-line))
14031 func-alist))))
14032 (setq func-alist (nreverse func-alist))
14033 (setq comp-alist (nreverse comp-alist))
14034 (if is-body
14035 (push pack-key pack-body-list)
14036 (push pack-key pack-list))
14037 (vhdl-aput
14038 'pack-alist pack-key
14039 (if is-body
14040 (list (or (nth 0 pack-entry) pack-name)
14041 (nth 1 pack-entry) (nth 2 pack-entry)
14042 (nth 3 pack-entry) (nth 4 pack-entry)
14043 (nth 5 pack-entry)
14044 file-name pack-line func-alist lib-alist)
14045 (list pack-name file-name pack-line
14046 comp-alist func-alist lib-alist
14047 (nth 6 pack-entry) (nth 7 pack-entry)
14048 (nth 8 pack-entry) (nth 9 pack-entry))))))))
14049 ;; scan for hierarchy
14050 (if (and limit-hier-file-size
14051 (< limit-hier-file-size (buffer-size)))
14052 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
14053 (setq big-files t))
14054 ;; scan for architectures
14055 (goto-char (point-min))
14056 (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)
14057 (let* ((ent-name (match-string-no-properties 2))
14058 (ent-key (downcase ent-name))
14059 (arch-name (match-string-no-properties 1))
14060 (arch-key (downcase arch-name))
14061 (ent-entry (vhdl-aget ent-alist ent-key))
14062 (arch-alist (nth 3 ent-entry))
14063 (arch-entry (vhdl-aget arch-alist arch-key))
14064 (beg-of-unit (point))
14065 (end-of-unit (vhdl-get-end-of-unit))
14066 (inst-no 0)
14067 inst-alist inst-path)
14068 ;; scan for contained instantiations
14069 (while (and (re-search-forward
14070 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
14071 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
14072 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
14073 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
14074 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
14075 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
14076 (or (not limit-hier-inst-no)
14077 (<= (if (or (match-string 14)
14078 (match-string 16))
14079 inst-no
14080 (setq inst-no (1+ inst-no)))
14081 limit-hier-inst-no)))
14082 (cond
14083 ;; block/generate beginning found
14084 ((match-string 14)
14085 (setq inst-path
14086 (cons (match-string-no-properties 1) inst-path)))
14087 ;; block/generate end found
14088 ((match-string 16)
14089 (setq inst-path (cdr inst-path)))
14090 ;; instantiation found
14091 (t
14092 (let* ((inst-name (match-string-no-properties 1))
14093 (inst-key (downcase inst-name))
14094 (inst-comp-name
14095 (or (match-string-no-properties 3)
14096 (match-string-no-properties 6)))
14097 (inst-ent-key
14098 (or (and (match-string 8)
14099 (vhdl-match-string-downcase 11))
14100 (and inst-comp-name
14101 (downcase inst-comp-name))))
14102 (inst-arch-key (vhdl-match-string-downcase 13))
14103 (inst-conf-key
14104 (and (not (match-string 8))
14105 (vhdl-match-string-downcase 11)))
14106 (inst-lib-key (vhdl-match-string-downcase 10)))
14107 (goto-char (match-end 1))
14108 (setq inst-list (cons inst-key inst-list)
14109 inst-ent-list
14110 (cons inst-ent-key inst-ent-list))
14111 (setq inst-alist
14112 (append
14113 inst-alist
14114 (list (list inst-key inst-name file-name
14115 (vhdl-current-line) inst-comp-name
14116 inst-ent-key inst-arch-key
14117 inst-conf-key inst-lib-key
14118 (reverse inst-path)))))))))
14119 ;; scan for contained configuration specifications
14120 (goto-char beg-of-unit)
14121 (while (re-search-forward
14122 (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]*\\)*"
14123 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
14124 (let* ((inst-comp-name (match-string-no-properties 3))
14125 (inst-ent-key
14126 (and (match-string 6)
14127 (vhdl-match-string-downcase 9)))
14128 (inst-arch-key (vhdl-match-string-downcase 11))
14129 (inst-conf-key
14130 (and (not (match-string 6))
14131 (vhdl-match-string-downcase 9)))
14132 (inst-lib-key (vhdl-match-string-downcase 8))
14133 (inst-key-list
14134 (split-string (vhdl-match-string-downcase 1)
14135 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
14136 (tmp-inst-alist inst-alist)
14137 inst-entry)
14138 (while tmp-inst-alist
14139 (when (and (or (equal "all" (car inst-key-list))
14140 (member (nth 0 (car tmp-inst-alist))
14141 inst-key-list))
14142 (equal
14143 (downcase
14144 (or (nth 4 (car tmp-inst-alist)) ""))
14145 (downcase inst-comp-name)))
14146 (setq inst-entry (car tmp-inst-alist))
14147 (setq inst-ent-list
14148 (cons (or inst-ent-key (nth 5 inst-entry))
14149 (vhdl-delete
14150 (nth 5 inst-entry) inst-ent-list)))
14151 (setq inst-entry
14152 (list (nth 0 inst-entry) (nth 1 inst-entry)
14153 (nth 2 inst-entry) (nth 3 inst-entry)
14154 (nth 4 inst-entry)
14155 (or inst-ent-key (nth 5 inst-entry))
14156 (or inst-arch-key (nth 6 inst-entry))
14157 inst-conf-key inst-lib-key))
14158 (setcar tmp-inst-alist inst-entry))
14159 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14160 ;; save in cache
14161 (vhdl-aput 'arch-alist arch-key
14162 (list (nth 0 arch-entry) (nth 1 arch-entry)
14163 (nth 2 arch-entry) inst-alist
14164 (nth 4 arch-entry)))
14165 (vhdl-aput 'ent-alist ent-key
14166 (list (nth 0 ent-entry) (nth 1 ent-entry)
14167 (nth 2 ent-entry)
14168 (vhdl-sort-alist arch-alist)
14169 (nth 4 ent-entry) (nth 5 ent-entry)))
14170 (when (and limit-hier-inst-no
14171 (> inst-no limit-hier-inst-no))
14172 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14173 (setq big-files t))
14174 (goto-char end-of-unit))))
14175 ;; remember design units for this file
14176 (vhdl-aput 'file-alist file-name
14177 (list ent-list arch-list arch-ent-list conf-list
14178 pack-list pack-body-list
14179 inst-list inst-ent-list))
14180 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14181 (setq file-list (cdr file-list))))
14182 (when (or (and (not project) files-exist)
14183 (and project (not non-final)))
14184 ;; consistency checks:
14185 ;; check whether each architecture has a corresponding entity
14186 (setq tmp-list ent-alist)
14187 (while tmp-list
14188 (when (null (nth 2 (car tmp-list)))
14189 (setq tmp-entry (car (nth 4 (car tmp-list))))
14190 (vhdl-warning-when-idle
14191 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14192 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14193 (nth 3 tmp-entry)))
14194 (setq tmp-list (cdr tmp-list)))
14195 ;; check whether configuration has a corresponding entity/architecture
14196 (setq tmp-list conf-alist)
14197 (while tmp-list
14198 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14199 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14200 (setq tmp-entry (car tmp-list))
14201 (vhdl-warning-when-idle
14202 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14203 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14204 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14205 (setq tmp-entry (car tmp-list))
14206 (vhdl-warning-when-idle
14207 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14208 (nth 1 tmp-entry) (nth 4 tmp-entry)
14209 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14210 (setq tmp-list (cdr tmp-list)))
14211 ;; check whether each package body has a package declaration
14212 (setq tmp-list pack-alist)
14213 (while tmp-list
14214 (when (null (nth 2 (car tmp-list)))
14215 (setq tmp-entry (car tmp-list))
14216 (vhdl-warning-when-idle
14217 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14218 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14219 (setq tmp-list (cdr tmp-list)))
14220 ;; sort lists
14221 (setq ent-alist (vhdl-sort-alist ent-alist))
14222 (setq conf-alist (vhdl-sort-alist conf-alist))
14223 (setq pack-alist (vhdl-sort-alist pack-alist))
14224 ;; remember updated directory/project
14225 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14226 ;; clear directory alists
14227 (unless project
14228 (vhdl-adelete 'vhdl-entity-alist key)
14229 (vhdl-adelete 'vhdl-config-alist key)
14230 (vhdl-adelete 'vhdl-package-alist key)
14231 (vhdl-adelete 'vhdl-ent-inst-alist key)
14232 (vhdl-adelete 'vhdl-file-alist key))
14233 ;; put directory contents into cache
14234 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14235 (vhdl-aput 'vhdl-config-alist key conf-alist)
14236 (vhdl-aput 'vhdl-package-alist key pack-alist)
14237 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14238 (vhdl-aput 'vhdl-file-alist key file-alist)
14239 ;; final messages
14240 (message "Scanning %s %s\"%s\"...done"
14241 (if is-directory "directory" "files") (or num-string "") name)
14242 (unless project (message "Scanning directory...done"))
14243 (when big-files
14244 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14245 ;; save cache when scanned non-interactively
14246 (when (or (not project) (not non-final))
14247 (when (and noninteractive vhdl-speedbar-save-cache)
14248 (vhdl-save-cache key)))
14249 t))
14250
14251 (defun vhdl-scan-project-contents (project)
14252 "Scan the contents of all VHDL files found in the directories and files
14253 of PROJECT."
14254 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14255 (default-dir (vhdl-resolve-env-variable
14256 (nth 1 (vhdl-aget vhdl-project-alist project))))
14257 (file-exclude-regexp
14258 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14259 dir-list-tmp dir dir-name num-dir act-dir recursive)
14260 ;; clear project alists
14261 (vhdl-adelete 'vhdl-entity-alist project)
14262 (vhdl-adelete 'vhdl-config-alist project)
14263 (vhdl-adelete 'vhdl-package-alist project)
14264 (vhdl-adelete 'vhdl-ent-inst-alist project)
14265 (vhdl-adelete 'vhdl-file-alist project)
14266 ;; expand directory names by default-directory
14267 (message "Collecting source files...")
14268 (while dir-list
14269 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14270 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14271 (setq recursive (match-string 1 dir)
14272 dir-name (match-string 3 dir))
14273 (setq dir-list-tmp
14274 (cons (concat recursive
14275 (if (file-name-absolute-p dir-name) "" default-dir)
14276 dir-name)
14277 dir-list-tmp))
14278 (setq dir-list (cdr dir-list)))
14279 ;; resolve path wildcards
14280 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14281 ;; expand directories
14282 (while dir-list-tmp
14283 (setq dir (car dir-list-tmp))
14284 ;; get subdirectories
14285 (if (string-match "-r \\(.*[/\\]\\)" dir)
14286 (setq dir-list (append dir-list (vhdl-get-subdirs
14287 (match-string 1 dir))))
14288 (setq dir-list (append dir-list (list dir))))
14289 (setq dir-list-tmp (cdr dir-list-tmp)))
14290 ;; exclude files
14291 (unless (equal file-exclude-regexp "")
14292 (let ((case-fold-search nil))
14293 (while dir-list
14294 (unless (string-match file-exclude-regexp (car dir-list))
14295 (push (car dir-list) dir-list-tmp))
14296 (setq dir-list (cdr dir-list)))
14297 (setq dir-list (nreverse dir-list-tmp))))
14298 (message "Collecting source files...done")
14299 ;; scan for design units for each directory in DIR-LIST
14300 (setq dir-list-tmp nil
14301 num-dir (length dir-list)
14302 act-dir 1)
14303 (while dir-list
14304 (setq dir-name (abbreviate-file-name
14305 (expand-file-name (car dir-list))))
14306 (vhdl-scan-directory-contents dir-name project nil
14307 (format "(%s/%s) " act-dir num-dir)
14308 (cdr dir-list))
14309 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
14310 (setq dir-list (cdr dir-list)
14311 act-dir (1+ act-dir)))
14312 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14313 (message "Scanning project \"%s\"...done" project)))
14314
14315 (defun vhdl-update-file-contents (file-name)
14316 "Update hierarchy information by contents of current buffer."
14317 (setq file-name (abbreviate-file-name file-name))
14318 (let* ((dir-name (file-name-directory file-name))
14319 (directory-alist vhdl-directory-alist)
14320 updated)
14321 (while directory-alist
14322 (when (member dir-name (nth 1 (car directory-alist)))
14323 (let* ((vhdl-project (nth 0 (car directory-alist)))
14324 (project (vhdl-project-p))
14325 (ent-alist (vhdl-aget vhdl-entity-alist
14326 (or project dir-name)))
14327 (conf-alist (vhdl-aget vhdl-config-alist
14328 (or project dir-name)))
14329 (pack-alist (vhdl-aget vhdl-package-alist
14330 (or project dir-name)))
14331 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14332 (or project dir-name))))
14333 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14334 (file-entry (vhdl-aget file-alist file-name))
14335 (ent-list (nth 0 file-entry))
14336 (arch-list (nth 1 file-entry))
14337 (arch-ent-list (nth 2 file-entry))
14338 (conf-list (nth 3 file-entry))
14339 (pack-list (nth 4 file-entry))
14340 (pack-body-list (nth 5 file-entry))
14341 (inst-ent-list (nth 7 file-entry))
14342 (cache-key (or project dir-name))
14343 arch-alist key ent-key entry)
14344 ;; delete design units previously contained in this file:
14345 ;; entities
14346 (while ent-list
14347 (setq key (car ent-list)
14348 entry (vhdl-aget ent-alist key))
14349 (when (equal file-name (nth 1 entry))
14350 (if (nth 3 entry)
14351 (vhdl-aput 'ent-alist key
14352 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14353 (vhdl-adelete 'ent-alist key)))
14354 (setq ent-list (cdr ent-list)))
14355 ;; architectures
14356 (while arch-list
14357 (setq key (car arch-list)
14358 ent-key (car arch-ent-list)
14359 entry (vhdl-aget ent-alist ent-key)
14360 arch-alist (nth 3 entry))
14361 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14362 (vhdl-adelete 'arch-alist key)
14363 (if (or (nth 1 entry) arch-alist)
14364 (vhdl-aput 'ent-alist ent-key
14365 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14366 arch-alist (nth 4 entry) (nth 5 entry)))
14367 (vhdl-adelete 'ent-alist ent-key)))
14368 (setq arch-list (cdr arch-list)
14369 arch-ent-list (cdr arch-ent-list)))
14370 ;; configurations
14371 (while conf-list
14372 (setq key (car conf-list))
14373 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14374 (vhdl-adelete 'conf-alist key))
14375 (setq conf-list (cdr conf-list)))
14376 ;; package declarations
14377 (while pack-list
14378 (setq key (car pack-list)
14379 entry (vhdl-aget pack-alist key))
14380 (when (equal file-name (nth 1 entry))
14381 (if (nth 6 entry)
14382 (vhdl-aput 'pack-alist key
14383 (list (nth 0 entry) nil nil nil nil nil
14384 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14385 (nth 9 entry)))
14386 (vhdl-adelete 'pack-alist key)))
14387 (setq pack-list (cdr pack-list)))
14388 ;; package bodies
14389 (while pack-body-list
14390 (setq key (car pack-body-list)
14391 entry (vhdl-aget pack-alist key))
14392 (when (equal file-name (nth 6 entry))
14393 (if (nth 1 entry)
14394 (vhdl-aput 'pack-alist key
14395 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14396 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14397 nil nil nil nil))
14398 (vhdl-adelete 'pack-alist key)))
14399 (setq pack-body-list (cdr pack-body-list)))
14400 ;; instantiated entities
14401 (while inst-ent-list
14402 (setq ent-inst-list
14403 (vhdl-delete (car inst-ent-list) ent-inst-list))
14404 (setq inst-ent-list (cdr inst-ent-list)))
14405 ;; update caches
14406 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14407 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14408 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14409 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14410 ;; scan file
14411 (vhdl-scan-directory-contents file-name project t)
14412 (when (or (and vhdl-speedbar-show-projects project)
14413 (and (not vhdl-speedbar-show-projects) (not project)))
14414 (vhdl-speedbar-refresh project))
14415 (setq updated t)))
14416 (setq directory-alist (cdr directory-alist)))
14417 updated))
14418
14419 (defun vhdl-update-hierarchy ()
14420 "Update directory and hierarchy information in speedbar."
14421 (let ((file-list (reverse vhdl-modified-file-list))
14422 updated)
14423 (when (and vhdl-speedbar-update-on-saving file-list)
14424 (while file-list
14425 (setq updated
14426 (or (vhdl-update-file-contents (car file-list))
14427 updated))
14428 (setq file-list (cdr file-list)))
14429 (setq vhdl-modified-file-list nil)
14430 (vhdl-speedbar-update-current-unit)
14431 (when updated (message "Updating hierarchy...done")))))
14432
14433 ;; structure (parenthesized expression means list of such entries)
14434 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14435 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14436 ;; comp-lib-name level)
14437 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14438 conf-inst-alist level indent
14439 &optional include-top ent-hier)
14440 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14441 entity ENT-KEY."
14442 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14443 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14444 (cdar (last (nth 3 ent-entry)))))
14445 (inst-alist (nth 3 arch-entry))
14446 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14447 hier-list subcomp-list tmp-list inst-key inst-comp-name
14448 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14449 (when (= level 0) (message "Extract design hierarchy..."))
14450 (when include-top
14451 (setq level (1+ level)))
14452 (when (member ent-key ent-hier)
14453 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14454 ;; process all instances
14455 (while inst-alist
14456 (setq inst-entry (car inst-alist)
14457 inst-key (nth 0 inst-entry)
14458 inst-comp-name (nth 4 inst-entry)
14459 inst-conf-key (nth 7 inst-entry))
14460 ;; search entry in configuration's instantiations list
14461 (setq tmp-list conf-inst-alist)
14462 (while (and tmp-list
14463 (not (and (member (nth 0 (car tmp-list))
14464 (list "all" inst-key))
14465 (equal (nth 1 (car tmp-list))
14466 (downcase (or inst-comp-name ""))))))
14467 (setq tmp-list (cdr tmp-list)))
14468 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14469 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14470 (when (and inst-conf-key (not inst-conf-entry))
14471 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14472 ;; determine entity
14473 (setq inst-ent-key
14474 (or (nth 2 (car tmp-list)) ; from configuration
14475 (nth 3 inst-conf-entry) ; from subconfiguration
14476 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14477 ; from configuration spec.
14478 (nth 5 inst-entry))) ; from direct instantiation
14479 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14480 ;; determine architecture
14481 (setq inst-arch-key
14482 (or (nth 3 (car tmp-list)) ; from configuration
14483 (nth 4 inst-conf-entry) ; from subconfiguration
14484 (nth 6 inst-entry) ; from direct instantiation
14485 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14486 ; from configuration spec.
14487 (nth 4 inst-ent-entry) ; MRA
14488 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14489 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14490 ;; set library
14491 (setq inst-lib-key
14492 (or (nth 5 (car tmp-list)) ; from configuration
14493 (nth 8 inst-entry))) ; from direct instantiation
14494 ;; gather information for this instance
14495 (setq comp-entry
14496 (list (nth 1 inst-entry)
14497 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14498 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14499 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14500 (or (nth 0 inst-arch-entry) inst-arch-key)
14501 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14502 (or (nth 0 inst-conf-entry) inst-conf-key)
14503 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14504 inst-lib-key level))
14505 ;; get subcomponent hierarchy
14506 (setq subcomp-list (vhdl-get-hierarchy
14507 ent-alist conf-alist
14508 inst-ent-key inst-arch-key inst-conf-key
14509 (nth 5 inst-conf-entry)
14510 (1+ level) indent nil (cons ent-key ent-hier)))
14511 ;; add to list
14512 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14513 (setq inst-alist (cdr inst-alist)))
14514 (when include-top
14515 (setq hier-list
14516 (cons (list nil nil (nth 0 ent-entry)
14517 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14518 (nth 0 arch-entry)
14519 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14520 nil nil
14521 nil (1- level))
14522 hier-list)))
14523 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14524 hier-list))
14525
14526 (defun vhdl-get-instantiations (ent-key indent)
14527 "Get all instantiations of entity ENT-KEY."
14528 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14529 (vhdl-speedbar-line-key indent)))
14530 arch-alist inst-alist ent-inst-list
14531 ent-entry arch-entry inst-entry)
14532 (while ent-alist
14533 (setq ent-entry (car ent-alist))
14534 (setq arch-alist (nth 4 ent-entry))
14535 (while arch-alist
14536 (setq arch-entry (car arch-alist))
14537 (setq inst-alist (nth 4 arch-entry))
14538 (while inst-alist
14539 (setq inst-entry (car inst-alist))
14540 (when (equal ent-key (nth 5 inst-entry))
14541 (setq ent-inst-list
14542 (cons (list (nth 1 inst-entry)
14543 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14544 (nth 1 ent-entry)
14545 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14546 (nth 1 arch-entry)
14547 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14548 ent-inst-list)))
14549 (setq inst-alist (cdr inst-alist)))
14550 (setq arch-alist (cdr arch-alist)))
14551 (setq ent-alist (cdr ent-alist)))
14552 (nreverse ent-inst-list)))
14553
14554 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14555 ;; Caching in file
14556
14557 (defun vhdl-save-caches ()
14558 "Save all updated hierarchy caches to file."
14559 (interactive)
14560 (condition-case nil
14561 (when vhdl-speedbar-save-cache
14562 ;; update hierarchy
14563 (vhdl-update-hierarchy)
14564 (let ((project-list vhdl-updated-project-list))
14565 (message "Saving hierarchy caches...")
14566 ;; write updated project caches
14567 (while project-list
14568 (vhdl-save-cache (car project-list))
14569 (setq project-list (cdr project-list)))
14570 (message "Saving hierarchy caches...done")))
14571 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14572 (sit-for 2)))))
14573
14574 (defun vhdl-save-cache (key)
14575 "Save current hierarchy cache to file."
14576 (let* ((orig-buffer (current-buffer))
14577 (vhdl-project key)
14578 (project (vhdl-project-p))
14579 (default-directory key)
14580 (directory (abbreviate-file-name (vhdl-default-directory)))
14581 (file-name (vhdl-resolve-env-variable
14582 (vhdl-replace-string
14583 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14584 (concat
14585 (subst-char-in-string ? ?_ (or project "dir"))
14586 " " (user-login-name)))))
14587 (file-dir-name (expand-file-name file-name directory))
14588 (cache-key (or project directory))
14589 (key (if project "project" "directory")))
14590 (unless (file-exists-p (file-name-directory file-dir-name))
14591 (make-directory (file-name-directory file-dir-name) t))
14592 (if (not (file-writable-p file-dir-name))
14593 (progn (vhdl-warning (format "File not writable: \"%s\""
14594 (abbreviate-file-name file-dir-name)))
14595 (sit-for 2))
14596 (message "Saving cache: \"%s\"" file-dir-name)
14597 (set-buffer (find-file-noselect file-dir-name t t))
14598 (erase-buffer)
14599 (insert ";; -*- Emacs-Lisp -*-\n\n"
14600 ";;; " (file-name-nondirectory file-name)
14601 " - design hierarchy cache file for Emacs VHDL Mode "
14602 vhdl-version "\n")
14603 (insert "\n;; " (if project "Project " "Directory") " : ")
14604 (if project (insert project) (prin1 directory (current-buffer)))
14605 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14606 (user-login-name) "\n\n"
14607 "\n;; version number\n"
14608 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14609 "\n;; " (if project "project" "directory") " name"
14610 "\n(setq " key " ")
14611 (prin1 (or project directory) (current-buffer))
14612 (insert ")\n")
14613 (when (member 'hierarchy vhdl-speedbar-save-cache)
14614 (insert "\n;; entity and architecture cache\n"
14615 "(vhdl-aput 'vhdl-entity-alist " key " '")
14616 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14617 (insert ")\n\n;; configuration cache\n"
14618 "(vhdl-aput 'vhdl-config-alist " key " '")
14619 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14620 (insert ")\n\n;; package cache\n"
14621 "(vhdl-aput 'vhdl-package-alist " key " '")
14622 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14623 (insert ")\n\n;; instantiated entities cache\n"
14624 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14625 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14626 (insert ")\n\n;; design units per file cache\n"
14627 "(vhdl-aput 'vhdl-file-alist " key " '")
14628 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14629 (when project
14630 (insert ")\n\n;; source directories in project cache\n"
14631 "(vhdl-aput 'vhdl-directory-alist " key " '")
14632 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14633 (insert ")\n"))
14634 (when (member 'display vhdl-speedbar-save-cache)
14635 (insert "\n;; shown design units cache\n"
14636 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14637 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14638 (current-buffer))
14639 (insert ")\n"))
14640 (setq vhdl-updated-project-list
14641 (delete cache-key vhdl-updated-project-list))
14642 (save-buffer)
14643 (kill-buffer (current-buffer))
14644 (set-buffer orig-buffer))))
14645
14646 (defun vhdl-load-cache (key)
14647 "Load hierarchy cache information from file."
14648 (let* ((vhdl-project key)
14649 (default-directory key)
14650 (directory (vhdl-default-directory))
14651 (file-name (vhdl-resolve-env-variable
14652 (vhdl-replace-string
14653 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14654 (concat
14655 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14656 " " (user-login-name)))))
14657 (file-dir-name (expand-file-name file-name directory))
14658 vhdl-cache-version)
14659 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14660 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14661 (when (file-exists-p file-dir-name)
14662 (condition-case ()
14663 (progn (load-file file-dir-name)
14664 (string< (mapconcat
14665 (lambda (a) (format "%3d" (string-to-number a)))
14666 (split-string "3.33" "\\.") "")
14667 (mapconcat
14668 (lambda (a) (format "%3d" (string-to-number a)))
14669 (split-string vhdl-cache-version "\\.") "")))
14670 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14671 nil))))))
14672
14673 (defun vhdl-require-hierarchy-info ()
14674 "Make sure that hierarchy information is available. Load cache or scan files
14675 if required."
14676 (if (vhdl-project-p)
14677 (unless (or (assoc vhdl-project vhdl-file-alist)
14678 (vhdl-load-cache vhdl-project))
14679 (vhdl-scan-project-contents vhdl-project))
14680 (let ((directory (abbreviate-file-name default-directory)))
14681 (unless (or (assoc directory vhdl-file-alist)
14682 (vhdl-load-cache directory))
14683 (vhdl-scan-directory-contents directory)))))
14684
14685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14686 ;; Add hierarchy browser functionality to speedbar
14687
14688 (defvar vhdl-speedbar-mode-map nil
14689 "Keymap used when in the VHDL hierarchy browser mode.")
14690
14691 (defvar vhdl-speedbar-menu-items nil
14692 "Additional menu-items to add to speedbar frame.")
14693
14694 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14695 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14696 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14697 (declare-function speedbar-change-initial-expansion-list "speedbar"
14698 (new-default))
14699 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14700
14701 (defun vhdl-speedbar-initialize ()
14702 "Initialize speedbar."
14703 ;; general settings
14704 ;; VHDL file extensions (extracted from `auto-mode-alist')
14705 (let ((mode-alist auto-mode-alist))
14706 (while mode-alist
14707 (when (eq (cdar mode-alist) 'vhdl-mode)
14708 (speedbar-add-supported-extension (caar mode-alist)))
14709 (setq mode-alist (cdr mode-alist))))
14710 ;; hierarchy browser settings
14711 (when (boundp 'speedbar-mode-functions-list)
14712 ;; special functions
14713 (speedbar-add-mode-functions-list
14714 '("vhdl directory"
14715 (speedbar-item-info . vhdl-speedbar-item-info)
14716 (speedbar-line-directory . speedbar-files-line-path)))
14717 (speedbar-add-mode-functions-list
14718 '("vhdl project"
14719 (speedbar-item-info . vhdl-speedbar-item-info)
14720 (speedbar-line-directory . vhdl-speedbar-line-project)))
14721 ;; keymap
14722 (unless vhdl-speedbar-mode-map
14723 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14724 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14725 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14726 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14727 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14728 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14729 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14730 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14731 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14732 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14733 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14734 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14735 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14736 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14737 (let ((key 0))
14738 (while (<= key 9)
14739 (define-key vhdl-speedbar-mode-map (int-to-string key)
14740 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14741 (setq key (1+ key)))))
14742 (define-key speedbar-mode-map "h"
14743 (lambda () (interactive)
14744 (speedbar-change-initial-expansion-list "vhdl directory")))
14745 (define-key speedbar-mode-map "H"
14746 (lambda () (interactive)
14747 (speedbar-change-initial-expansion-list "vhdl project")))
14748 ;; menu
14749 (unless vhdl-speedbar-menu-items
14750 (setq
14751 vhdl-speedbar-menu-items
14752 `(["Edit" speedbar-edit-line t]
14753 ["Expand" speedbar-expand-line
14754 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14755 ["Contract" vhdl-speedbar-contract-level t]
14756 ["Expand All" vhdl-speedbar-expand-all t]
14757 ["Contract All" vhdl-speedbar-contract-all t]
14758 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14759 (while (<= key 9)
14760 (setq menu-list
14761 (cons `[,(if (= key 0) "All" (int-to-string key))
14762 (vhdl-speedbar-set-depth ,key)
14763 :style radio
14764 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14765 :keys ,(int-to-string key)]
14766 menu-list))
14767 (setq key (1+ key)))
14768 (nreverse menu-list))
14769 "--"
14770 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14771 (or (vhdl-speedbar-check-unit 'entity)
14772 (vhdl-speedbar-check-unit 'subprogram))]
14773 ["Place Component" vhdl-speedbar-place-component
14774 (vhdl-speedbar-check-unit 'entity)]
14775 ["Generate Configuration" vhdl-speedbar-configuration
14776 (vhdl-speedbar-check-unit 'architecture)]
14777 ["Select as MRA" vhdl-speedbar-select-mra
14778 (vhdl-speedbar-check-unit 'architecture)]
14779 ["Make" vhdl-speedbar-make-design
14780 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14781 ["Generate Makefile" vhdl-speedbar-generate-makefile
14782 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14783 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14784 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14785 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14786 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14787 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14788 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14789 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14790 ;; hook-ups
14791 (speedbar-add-expansion-list
14792 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14793 vhdl-speedbar-display-directory))
14794 (speedbar-add-expansion-list
14795 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14796 vhdl-speedbar-display-projects))
14797 (setq speedbar-stealthy-function-list
14798 (append
14799 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14800 ("vhdl project" vhdl-speedbar-update-current-project
14801 vhdl-speedbar-update-current-unit))
14802 speedbar-stealthy-function-list))
14803 (when (eq vhdl-speedbar-display-mode 'directory)
14804 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14805 (when (eq vhdl-speedbar-display-mode 'project)
14806 (setq speedbar-initial-expansion-list-name "vhdl project"))
14807 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14808
14809 (defun vhdl-speedbar (&optional arg)
14810 "Open/close speedbar."
14811 (interactive)
14812 (if (not (fboundp 'speedbar))
14813 (error "WARNING: Speedbar is not available or not installed")
14814 (condition-case ()
14815 (speedbar-frame-mode arg)
14816 (error (error "WARNING: An error occurred while opening speedbar")))))
14817
14818 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14819 ;; Display functions
14820
14821 (defvar vhdl-speedbar-last-selected-project nil
14822 "Name of last selected project.")
14823
14824 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14825 ;;; (defmacro speedbar-with-writable (&rest forms)
14826 ;;; "Allow the buffer to be writable and evaluate FORMS."
14827 ;;; (list 'let '((inhibit-read-only t))
14828 ;;; (cons 'progn forms)))
14829 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14830
14831 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14832 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14833 (declare-function speedbar-file-lists "speedbar" (directory))
14834
14835 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14836 "Display directory and hierarchy information in speedbar."
14837 (setq vhdl-speedbar-show-projects nil)
14838 (setq speedbar-ignored-directory-regexp
14839 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14840 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14841 (setq speedbar-last-selected-file nil)
14842 (speedbar-with-writable
14843 (condition-case nil
14844 (progn
14845 ;; insert directory path
14846 (speedbar-directory-buttons directory depth)
14847 ;; insert subdirectories
14848 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14849 ;; scan and insert hierarchy of current directory
14850 (vhdl-speedbar-insert-dir-hierarchy directory depth
14851 speedbar-power-click)
14852 ;; expand subdirectories
14853 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14854 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14855
14856 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14857 "Display projects and hierarchy information in speedbar."
14858 (setq vhdl-speedbar-show-projects t)
14859 (setq speedbar-ignored-directory-regexp ".")
14860 (setq speedbar-last-selected-file nil)
14861 (setq vhdl-speedbar-last-selected-project nil)
14862 (speedbar-with-writable
14863 (condition-case nil
14864 ;; insert projects
14865 (vhdl-speedbar-insert-projects)
14866 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14867 (setq speedbar-full-text-cache nil)) ; prevent caching
14868
14869 (declare-function speedbar-make-tag-line "speedbar"
14870 (type char func data tag tfunc tdata tface depth))
14871
14872 (defun vhdl-speedbar-insert-projects ()
14873 "Insert all projects in speedbar."
14874 (vhdl-speedbar-make-title-line "Projects:")
14875 (let ((project-alist (if vhdl-project-sort
14876 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14877 vhdl-project-alist))
14878 (vhdl-speedbar-update-current-unit nil))
14879 ;; insert projects
14880 (while project-alist
14881 (speedbar-make-tag-line
14882 'angle ?+ 'vhdl-speedbar-expand-project
14883 (caar project-alist) (caar project-alist)
14884 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14885 (setq project-alist (cdr project-alist)))
14886 (setq project-alist vhdl-project-alist)
14887 ;; expand projects
14888 (while project-alist
14889 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14890 (goto-char (point-min))
14891 (when (re-search-forward
14892 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14893 (goto-char (match-end 1))
14894 (speedbar-do-function-pointer)))
14895 (setq project-alist (cdr project-alist)))))
14896
14897 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14898 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14899 otherwise use cached data."
14900 (when (or rescan (and (not (assoc project vhdl-file-alist))
14901 (not (vhdl-load-cache project))))
14902 (vhdl-scan-project-contents project))
14903 ;; insert design hierarchy
14904 (vhdl-speedbar-insert-hierarchy
14905 (vhdl-aget vhdl-entity-alist project)
14906 (vhdl-aget vhdl-config-alist project)
14907 (vhdl-aget vhdl-package-alist project)
14908 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14909 (insert (int-to-string indent) ":\n")
14910 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14911 (put-text-property (1- (point)) (point) 'invisible nil)
14912 ;; expand design units
14913 (vhdl-speedbar-expand-units project))
14914
14915 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14916 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14917 otherwise use cached data."
14918 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14919 (not (vhdl-load-cache directory))))
14920 (vhdl-scan-directory-contents directory))
14921 ;; insert design hierarchy
14922 (vhdl-speedbar-insert-hierarchy
14923 (vhdl-aget vhdl-entity-alist directory)
14924 (vhdl-aget vhdl-config-alist directory)
14925 (vhdl-aget vhdl-package-alist directory)
14926 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14927 ;; expand design units
14928 (vhdl-speedbar-expand-units directory)
14929 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14930
14931 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14932 ent-inst-list depth)
14933 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14934 (if (not (or ent-alist conf-alist pack-alist))
14935 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14936 (let (ent-entry conf-entry pack-entry)
14937 ;; insert entities
14938 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14939 (while ent-alist
14940 (setq ent-entry (car ent-alist))
14941 (speedbar-make-tag-line
14942 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14943 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14944 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14945 'vhdl-speedbar-entity-face depth)
14946 (unless (nth 2 ent-entry)
14947 (end-of-line 0) (insert "!") (forward-char 1))
14948 (unless (member (nth 0 ent-entry) ent-inst-list)
14949 (end-of-line 0) (insert " (top)") (forward-char 1))
14950 (setq ent-alist (cdr ent-alist)))
14951 ;; insert configurations
14952 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14953 (while conf-alist
14954 (setq conf-entry (car conf-alist))
14955 (speedbar-make-tag-line
14956 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14957 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14958 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14959 'vhdl-speedbar-configuration-face depth)
14960 (setq conf-alist (cdr conf-alist)))
14961 ;; insert packages
14962 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14963 (while pack-alist
14964 (setq pack-entry (car pack-alist))
14965 (vhdl-speedbar-make-pack-line
14966 (nth 0 pack-entry) (nth 1 pack-entry)
14967 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14968 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14969 depth)
14970 (setq pack-alist (cdr pack-alist))))))
14971
14972 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14973
14974 (defun vhdl-speedbar-rescan-hierarchy ()
14975 "Rescan hierarchy for the directory or project under the cursor."
14976 (interactive)
14977 (let (key path)
14978 (cond
14979 ;; current project
14980 (vhdl-speedbar-show-projects
14981 (setq key (vhdl-speedbar-line-project))
14982 (vhdl-scan-project-contents key))
14983 ;; top-level directory
14984 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14985 (re-search-forward "[0-9]+:" nil t)
14986 (vhdl-scan-directory-contents
14987 (abbreviate-file-name (speedbar-line-directory))))
14988 ;; current directory
14989 (t (setq path (speedbar-line-directory))
14990 (string-match "^\\(.+[/\\]\\)" path)
14991 (vhdl-scan-directory-contents
14992 (abbreviate-file-name (match-string 1 path)))))
14993 (vhdl-speedbar-refresh key)))
14994
14995 (declare-function speedbar-goto-this-file "speedbar" (file))
14996
14997 (defun vhdl-speedbar-expand-dirs (directory)
14998 "Expand subdirectories in DIRECTORY according to
14999 `speedbar-shown-directories'."
15000 ;; (nicked from `speedbar-default-directory-list')
15001 (let ((sf (cdr (reverse speedbar-shown-directories)))
15002 (vhdl-speedbar-update-current-unit nil))
15003 (setq speedbar-shown-directories
15004 (list (expand-file-name default-directory)))
15005 (while sf
15006 (when (speedbar-goto-this-file (car sf))
15007 (beginning-of-line)
15008 (when (looking-at "[0-9]+:\\s-*<")
15009 (goto-char (match-end 0))
15010 (speedbar-do-function-pointer)))
15011 (setq sf (cdr sf))))
15012 (vhdl-speedbar-update-current-unit nil t))
15013
15014 (defun vhdl-speedbar-expand-units (key)
15015 "Expand design units in directory/project KEY according to
15016 `vhdl-speedbar-shown-unit-alist'."
15017 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15018 (vhdl-speedbar-update-current-unit nil)
15019 vhdl-updated-project-list)
15020 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15021 (vhdl-prepare-search-1
15022 (while unit-alist ; expand units
15023 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
15024 (beginning-of-line)
15025 (let ((arch-alist (nth 1 (car unit-alist)))
15026 position)
15027 (when (looking-at "^[0-9]+:\\s-*\\[")
15028 (goto-char (match-end 0))
15029 (setq position (point))
15030 (speedbar-do-function-pointer)
15031 (select-frame speedbar-frame)
15032 (while arch-alist ; expand architectures
15033 (goto-char position)
15034 (when (re-search-forward
15035 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
15036 (car arch-alist) "\\>\\)") nil t)
15037 (beginning-of-line)
15038 (when (looking-at "^[0-9]+:\\s-*{")
15039 (goto-char (match-end 0))
15040 (speedbar-do-function-pointer)
15041 (select-frame speedbar-frame)))
15042 (setq arch-alist (cdr arch-alist))))
15043 (setq unit-alist (cdr unit-alist))))))
15044 (vhdl-speedbar-update-current-unit nil t))
15045
15046 (declare-function speedbar-center-buffer-smartly "speedbar" ())
15047
15048 (defun vhdl-speedbar-contract-level ()
15049 "Contract current level in current directory/project."
15050 (interactive)
15051 (when (or (save-excursion
15052 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
15053 (and (save-excursion
15054 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
15055 (re-search-backward
15056 (format "^[0-%d]:\\s-*[[{<]-"
15057 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
15058 (goto-char (match-end 0))
15059 (speedbar-do-function-pointer)
15060 (speedbar-center-buffer-smartly)))
15061
15062 (defun vhdl-speedbar-contract-all ()
15063 "Contract all expanded design units in current directory/project."
15064 (interactive)
15065 (if (and vhdl-speedbar-show-projects
15066 (save-excursion (beginning-of-line) (looking-at "^0:")))
15067 (progn (setq vhdl-speedbar-shown-project-list nil)
15068 (vhdl-speedbar-refresh))
15069 (let ((key (vhdl-speedbar-line-key)))
15070 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15071 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
15072 (when (memq 'display vhdl-speedbar-save-cache)
15073 (add-to-list 'vhdl-updated-project-list key)))))
15074
15075 (defun vhdl-speedbar-expand-all ()
15076 "Expand all design units in current directory/project."
15077 (interactive)
15078 (let* ((key (vhdl-speedbar-line-key))
15079 (ent-alist (vhdl-aget vhdl-entity-alist key))
15080 (conf-alist (vhdl-aget vhdl-config-alist key))
15081 (pack-alist (vhdl-aget vhdl-package-alist key))
15082 arch-alist unit-alist subunit-alist)
15083 (add-to-list 'vhdl-speedbar-shown-project-list key)
15084 (while ent-alist
15085 (setq arch-alist (nth 4 (car ent-alist)))
15086 (setq subunit-alist nil)
15087 (while arch-alist
15088 (push (caar arch-alist) subunit-alist)
15089 (setq arch-alist (cdr arch-alist)))
15090 (push (list (caar ent-alist) subunit-alist) unit-alist)
15091 (setq ent-alist (cdr ent-alist)))
15092 (while conf-alist
15093 (push (list (caar conf-alist)) unit-alist)
15094 (setq conf-alist (cdr conf-alist)))
15095 (while pack-alist
15096 (push (list (caar pack-alist)) unit-alist)
15097 (setq pack-alist (cdr pack-alist)))
15098 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15099 (vhdl-speedbar-refresh)
15100 (when (memq 'display vhdl-speedbar-save-cache)
15101 (add-to-list 'vhdl-updated-project-list key))))
15102
15103 (declare-function speedbar-change-expand-button-char "speedbar" (char))
15104 (declare-function speedbar-delete-subblock "speedbar" (indent))
15105
15106 (defun vhdl-speedbar-expand-project (text token indent)
15107 "Expand/contract the project under the cursor."
15108 (cond
15109 ((string-match "+" text) ; expand project
15110 (speedbar-change-expand-button-char ?-)
15111 (unless (member token vhdl-speedbar-shown-project-list)
15112 (setq vhdl-speedbar-shown-project-list
15113 (cons token vhdl-speedbar-shown-project-list)))
15114 (speedbar-with-writable
15115 (save-excursion
15116 (end-of-line) (forward-char 1)
15117 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
15118 speedbar-power-click))))
15119 ((string-match "-" text) ; contract project
15120 (speedbar-change-expand-button-char ?+)
15121 (setq vhdl-speedbar-shown-project-list
15122 (delete token vhdl-speedbar-shown-project-list))
15123 (speedbar-delete-subblock indent))
15124 (t (error "Nothing to display")))
15125 (when (equal (selected-frame) speedbar-frame)
15126 (speedbar-center-buffer-smartly)))
15127
15128 (defun vhdl-speedbar-expand-entity (text token indent)
15129 "Expand/contract the entity under the cursor."
15130 (cond
15131 ((string-match "+" text) ; expand entity
15132 (let* ((key (vhdl-speedbar-line-key indent))
15133 (ent-alist (vhdl-aget vhdl-entity-alist key))
15134 (ent-entry (vhdl-aget ent-alist token))
15135 (arch-alist (nth 3 ent-entry))
15136 (inst-alist (vhdl-get-instantiations token indent))
15137 (subpack-alist (nth 5 ent-entry))
15138 (multiple-arch (> (length arch-alist) 1))
15139 arch-entry inst-entry)
15140 (if (not (or arch-alist inst-alist subpack-alist))
15141 (speedbar-change-expand-button-char ??)
15142 (speedbar-change-expand-button-char ?-)
15143 ;; add entity to `vhdl-speedbar-shown-unit-alist'
15144 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15145 (vhdl-aput 'unit-alist token nil)
15146 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15147 (speedbar-with-writable
15148 (save-excursion
15149 (end-of-line) (forward-char 1)
15150 ;; insert architectures
15151 (when arch-alist
15152 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15153 (while arch-alist
15154 (setq arch-entry (car arch-alist))
15155 (speedbar-make-tag-line
15156 'curly ?+ 'vhdl-speedbar-expand-architecture
15157 (cons token (nth 0 arch-entry))
15158 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15159 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15160 'vhdl-speedbar-architecture-face (1+ indent))
15161 (when (and multiple-arch
15162 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15163 (end-of-line 0) (insert " (mra)") (forward-char 1))
15164 (setq arch-alist (cdr arch-alist)))
15165 ;; insert instantiations
15166 (when inst-alist
15167 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15168 (while inst-alist
15169 (setq inst-entry (car inst-alist))
15170 (vhdl-speedbar-make-inst-line
15171 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15172 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15173 nil nil nil (1+ indent) 0 " in ")
15174 (setq inst-alist (cdr inst-alist)))
15175 ;; insert required packages
15176 (vhdl-speedbar-insert-subpackages
15177 subpack-alist (1+ indent) indent)))
15178 (when (memq 'display vhdl-speedbar-save-cache)
15179 (add-to-list 'vhdl-updated-project-list key))
15180 (vhdl-speedbar-update-current-unit t t))))
15181 ((string-match "-" text) ; contract entity
15182 (speedbar-change-expand-button-char ?+)
15183 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15184 (let* ((key (vhdl-speedbar-line-key indent))
15185 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15186 (vhdl-adelete 'unit-alist token)
15187 (if unit-alist
15188 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15189 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15190 (speedbar-delete-subblock indent)
15191 (when (memq 'display vhdl-speedbar-save-cache)
15192 (add-to-list 'vhdl-updated-project-list key))))
15193 (t (error "Nothing to display")))
15194 (when (equal (selected-frame) speedbar-frame)
15195 (speedbar-center-buffer-smartly)))
15196
15197 (defun vhdl-speedbar-expand-architecture (text token indent)
15198 "Expand/contract the architecture under the cursor."
15199 (cond
15200 ((string-match "+" text) ; expand architecture
15201 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15202 (ent-alist (vhdl-aget vhdl-entity-alist key))
15203 (conf-alist (vhdl-aget vhdl-config-alist key))
15204 (hier-alist (vhdl-get-hierarchy
15205 ent-alist conf-alist (car token) (cdr token) nil nil
15206 0 (1- indent)))
15207 (ent-entry (vhdl-aget ent-alist (car token)))
15208 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15209 (subpack-alist (nth 4 arch-entry))
15210 entry)
15211 (if (not (or hier-alist subpack-alist))
15212 (speedbar-change-expand-button-char ??)
15213 (speedbar-change-expand-button-char ?-)
15214 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15215 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15216 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15217 (vhdl-aput 'unit-alist (car token)
15218 (list (cons (cdr token) arch-alist)))
15219 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15220 (speedbar-with-writable
15221 (save-excursion
15222 (end-of-line) (forward-char 1)
15223 ;; insert instance hierarchy
15224 (when hier-alist
15225 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15226 (1+ indent)))
15227 (while hier-alist
15228 (setq entry (car hier-alist))
15229 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15230 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15231 (vhdl-speedbar-make-inst-line
15232 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15233 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15234 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15235 (setq hier-alist (cdr hier-alist)))
15236 ;; insert required packages
15237 (vhdl-speedbar-insert-subpackages
15238 subpack-alist (1+ indent) (1- indent))))
15239 (when (memq 'display vhdl-speedbar-save-cache)
15240 (add-to-list 'vhdl-updated-project-list key))
15241 (vhdl-speedbar-update-current-unit t t))))
15242 ((string-match "-" text) ; contract architecture
15243 (speedbar-change-expand-button-char ?+)
15244 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15245 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15246 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15247 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15248 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15249 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15250 (speedbar-delete-subblock indent)
15251 (when (memq 'display vhdl-speedbar-save-cache)
15252 (add-to-list 'vhdl-updated-project-list key))))
15253 (t (error "Nothing to display")))
15254 (when (equal (selected-frame) speedbar-frame)
15255 (speedbar-center-buffer-smartly)))
15256
15257 (defun vhdl-speedbar-expand-config (text token indent)
15258 "Expand/contract the configuration under the cursor."
15259 (cond
15260 ((string-match "+" text) ; expand configuration
15261 (let* ((key (vhdl-speedbar-line-key indent))
15262 (conf-alist (vhdl-aget vhdl-config-alist key))
15263 (conf-entry (vhdl-aget conf-alist token))
15264 (ent-alist (vhdl-aget vhdl-entity-alist key))
15265 (hier-alist (vhdl-get-hierarchy
15266 ent-alist conf-alist (nth 3 conf-entry)
15267 (nth 4 conf-entry) token (nth 5 conf-entry)
15268 0 indent t))
15269 (subpack-alist (nth 6 conf-entry))
15270 entry)
15271 (if (not (or hier-alist subpack-alist))
15272 (speedbar-change-expand-button-char ??)
15273 (speedbar-change-expand-button-char ?-)
15274 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15275 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15276 (vhdl-aput 'unit-alist token nil)
15277 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15278 (speedbar-with-writable
15279 (save-excursion
15280 (end-of-line) (forward-char 1)
15281 ;; insert instance hierarchy
15282 (when hier-alist
15283 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15284 (while hier-alist
15285 (setq entry (car hier-alist))
15286 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15287 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15288 (vhdl-speedbar-make-inst-line
15289 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15290 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15291 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15292 (setq hier-alist (cdr hier-alist)))
15293 ;; insert required packages
15294 (vhdl-speedbar-insert-subpackages
15295 subpack-alist (1+ indent) indent)))
15296 (when (memq 'display vhdl-speedbar-save-cache)
15297 (add-to-list 'vhdl-updated-project-list key))
15298 (vhdl-speedbar-update-current-unit t t))))
15299 ((string-match "-" text) ; contract configuration
15300 (speedbar-change-expand-button-char ?+)
15301 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15302 (let* ((key (vhdl-speedbar-line-key indent))
15303 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15304 (vhdl-adelete 'unit-alist token)
15305 (if unit-alist
15306 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15307 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15308 (speedbar-delete-subblock indent)
15309 (when (memq 'display vhdl-speedbar-save-cache)
15310 (add-to-list 'vhdl-updated-project-list key))))
15311 (t (error "Nothing to display")))
15312 (when (equal (selected-frame) speedbar-frame)
15313 (speedbar-center-buffer-smartly)))
15314
15315 (defun vhdl-speedbar-expand-package (text token indent)
15316 "Expand/contract the package under the cursor."
15317 (cond
15318 ((string-match "+" text) ; expand package
15319 (let* ((key (vhdl-speedbar-line-key indent))
15320 (pack-alist (vhdl-aget vhdl-package-alist key))
15321 (pack-entry (vhdl-aget pack-alist token))
15322 (comp-alist (nth 3 pack-entry))
15323 (func-alist (nth 4 pack-entry))
15324 (func-body-alist (nth 8 pack-entry))
15325 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15326 comp-entry func-entry func-body-entry)
15327 (if (not (or comp-alist func-alist subpack-alist))
15328 (speedbar-change-expand-button-char ??)
15329 (speedbar-change-expand-button-char ?-)
15330 ;; add package to `vhdl-speedbar-shown-unit-alist'
15331 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15332 (vhdl-aput 'unit-alist token nil)
15333 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15334 (speedbar-with-writable
15335 (save-excursion
15336 (end-of-line) (forward-char 1)
15337 ;; insert components
15338 (when comp-alist
15339 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15340 (while comp-alist
15341 (setq comp-entry (car comp-alist))
15342 (speedbar-make-tag-line
15343 nil nil nil
15344 (cons token (nth 0 comp-entry))
15345 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15346 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15347 'vhdl-speedbar-entity-face (1+ indent))
15348 (setq comp-alist (cdr comp-alist)))
15349 ;; insert subprograms
15350 (when func-alist
15351 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15352 (while func-alist
15353 (setq func-entry (car func-alist)
15354 func-body-entry (vhdl-aget func-body-alist
15355 (car func-entry)))
15356 (when (nth 2 func-entry)
15357 (vhdl-speedbar-make-subprogram-line
15358 (nth 1 func-entry)
15359 (cons (nth 2 func-entry) (nth 3 func-entry))
15360 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15361 (1+ indent)))
15362 (setq func-alist (cdr func-alist)))
15363 ;; insert required packages
15364 (vhdl-speedbar-insert-subpackages
15365 subpack-alist (1+ indent) indent)))
15366 (when (memq 'display vhdl-speedbar-save-cache)
15367 (add-to-list 'vhdl-updated-project-list key))
15368 (vhdl-speedbar-update-current-unit t t))))
15369 ((string-match "-" text) ; contract package
15370 (speedbar-change-expand-button-char ?+)
15371 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15372 (let* ((key (vhdl-speedbar-line-key indent))
15373 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15374 (vhdl-adelete 'unit-alist token)
15375 (if unit-alist
15376 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15377 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15378 (speedbar-delete-subblock indent)
15379 (when (memq 'display vhdl-speedbar-save-cache)
15380 (add-to-list 'vhdl-updated-project-list key))))
15381 (t (error "Nothing to display")))
15382 (when (equal (selected-frame) speedbar-frame)
15383 (speedbar-center-buffer-smartly)))
15384
15385 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15386 "Insert required packages."
15387 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15388 (vhdl-speedbar-line-key dir-indent)))
15389 pack-key lib-name pack-entry)
15390 (when subpack-alist
15391 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15392 (while subpack-alist
15393 (setq pack-key (cdar subpack-alist)
15394 lib-name (caar subpack-alist))
15395 (setq pack-entry (vhdl-aget pack-alist pack-key))
15396 (vhdl-speedbar-make-subpack-line
15397 (or (nth 0 pack-entry) pack-key) lib-name
15398 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15399 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15400 (setq subpack-alist (cdr subpack-alist)))))
15401
15402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15403 ;; Display help functions
15404
15405 (defvar vhdl-speedbar-update-current-unit t
15406 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15407
15408 (defun vhdl-speedbar-update-current-project ()
15409 "Highlight project that is currently active."
15410 (when (and vhdl-speedbar-show-projects
15411 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15412 (and (boundp 'speedbar-frame)
15413 (frame-live-p speedbar-frame)))
15414 (let ((last-frame (selected-frame))
15415 (project-alist vhdl-project-alist)
15416 pos)
15417 (select-frame speedbar-frame)
15418 (speedbar-with-writable
15419 (save-excursion
15420 (while project-alist
15421 (goto-char (point-min))
15422 (when (re-search-forward
15423 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15424 (put-text-property (match-beginning 1) (match-end 1) 'face
15425 (if (equal (caar project-alist) vhdl-project)
15426 'speedbar-selected-face
15427 'speedbar-directory-face))
15428 (when (equal (caar project-alist) vhdl-project)
15429 (setq pos (1- (match-beginning 1)))))
15430 (setq project-alist (cdr project-alist))))
15431 (when pos (goto-char pos)))
15432 (select-frame last-frame)
15433 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15434 t)
15435
15436 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15437
15438 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15439 "Highlight all design units that are contained in the current file.
15440 NO-POSITION non-nil means do not re-position cursor."
15441 (let ((last-frame (selected-frame))
15442 (project-list vhdl-speedbar-shown-project-list)
15443 file-alist pos file-name)
15444 ;; get current file name
15445 (if (fboundp 'speedbar-select-attached-frame)
15446 (speedbar-select-attached-frame)
15447 (select-frame speedbar-attached-frame))
15448 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15449 (when (and vhdl-speedbar-update-current-unit
15450 (or always (not (equal file-name speedbar-last-selected-file))))
15451 (if vhdl-speedbar-show-projects
15452 (while project-list
15453 (setq file-alist (append file-alist
15454 (vhdl-aget vhdl-file-alist
15455 (car project-list))))
15456 (setq project-list (cdr project-list)))
15457 (setq file-alist
15458 (vhdl-aget vhdl-file-alist
15459 (abbreviate-file-name default-directory))))
15460 (select-frame speedbar-frame)
15461 (set-buffer speedbar-buffer)
15462 (speedbar-with-writable
15463 (vhdl-prepare-search-1
15464 (save-excursion
15465 ;; unhighlight last units
15466 (let* ((file-entry (vhdl-aget file-alist
15467 speedbar-last-selected-file)))
15468 (vhdl-speedbar-update-units
15469 "\\[.] " (nth 0 file-entry)
15470 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15471 (vhdl-speedbar-update-units
15472 "{.} " (nth 1 file-entry)
15473 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15474 (vhdl-speedbar-update-units
15475 "\\[.] " (nth 3 file-entry)
15476 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15477 (vhdl-speedbar-update-units
15478 "[]>] " (nth 4 file-entry)
15479 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15480 (vhdl-speedbar-update-units
15481 "\\[.].+(" '("body")
15482 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15483 (vhdl-speedbar-update-units
15484 "> " (nth 6 file-entry)
15485 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15486 ;; highlight current units
15487 (let* ((file-entry (vhdl-aget file-alist file-name)))
15488 (setq
15489 pos (vhdl-speedbar-update-units
15490 "\\[.] " (nth 0 file-entry)
15491 file-name 'vhdl-speedbar-entity-selected-face pos)
15492 pos (vhdl-speedbar-update-units
15493 "{.} " (nth 1 file-entry)
15494 file-name 'vhdl-speedbar-architecture-selected-face pos)
15495 pos (vhdl-speedbar-update-units
15496 "\\[.] " (nth 3 file-entry)
15497 file-name 'vhdl-speedbar-configuration-selected-face pos)
15498 pos (vhdl-speedbar-update-units
15499 "[]>] " (nth 4 file-entry)
15500 file-name 'vhdl-speedbar-package-selected-face pos)
15501 pos (vhdl-speedbar-update-units
15502 "\\[.].+(" '("body")
15503 file-name 'vhdl-speedbar-package-selected-face pos)
15504 pos (vhdl-speedbar-update-units
15505 "> " (nth 6 file-entry)
15506 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15507 ;; move speedbar so the first highlighted unit is visible
15508 (when (and pos (not no-position))
15509 (goto-char pos)
15510 (speedbar-center-buffer-smartly)
15511 (speedbar-position-cursor-on-line))
15512 (setq speedbar-last-selected-file file-name))
15513 (select-frame last-frame)
15514 t))
15515
15516 (defun vhdl-speedbar-update-units (text unit-list file-name face
15517 &optional pos)
15518 "Help function to highlight design units."
15519 (while unit-list
15520 (goto-char (point-min))
15521 (while (re-search-forward
15522 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15523 (when (equal file-name (car (get-text-property
15524 (match-beginning 1) 'speedbar-token)))
15525 (setq pos (or pos (point-marker)))
15526 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15527 (setq unit-list (cdr unit-list)))
15528 pos)
15529
15530 (declare-function speedbar-make-button "speedbar"
15531 (start end face mouse function &optional token))
15532
15533 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15534 ent-name ent-file-marker
15535 arch-name arch-file-marker
15536 conf-name conf-file-marker
15537 lib-name depth offset delimiter)
15538 "Insert instantiation entry."
15539 (let ((start (point))
15540 visible-start)
15541 (insert (int-to-string depth) ":")
15542 (put-text-property start (point) 'invisible t)
15543 (setq visible-start (point))
15544 (insert-char ? (* depth speedbar-indentation-width))
15545 (while (> offset 0)
15546 (insert "|")
15547 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15548 (setq offset (1- offset)))
15549 (put-text-property visible-start (point) 'invisible nil)
15550 (setq start (point))
15551 (insert ">")
15552 (speedbar-make-button start (point) nil nil nil)
15553 (setq visible-start (point))
15554 (insert " ")
15555 (setq start (point))
15556 (if (not inst-name)
15557 (insert "(top)")
15558 (insert inst-name)
15559 (speedbar-make-button
15560 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15561 'vhdl-speedbar-find-file inst-file-marker))
15562 (insert delimiter)
15563 (when ent-name
15564 (setq start (point))
15565 (insert ent-name)
15566 (speedbar-make-button
15567 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15568 'vhdl-speedbar-find-file ent-file-marker)
15569 (when arch-name
15570 (insert " (")
15571 (setq start (point))
15572 (insert arch-name)
15573 (speedbar-make-button
15574 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15575 'vhdl-speedbar-find-file arch-file-marker)
15576 (insert ")"))
15577 (when conf-name
15578 (insert " (")
15579 (setq start (point))
15580 (insert conf-name)
15581 (speedbar-make-button
15582 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15583 'vhdl-speedbar-find-file conf-file-marker)
15584 (insert ")")))
15585 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15586 (setq start (point))
15587 (insert " (" lib-name ")")
15588 (put-text-property (+ 2 start) (1- (point)) 'face
15589 'vhdl-speedbar-library-face))
15590 (insert-char ?\n 1)
15591 (put-text-property visible-start (point) 'invisible nil)))
15592
15593 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15594 body-file-marker depth)
15595 "Insert package entry."
15596 (let ((start (point))
15597 visible-start)
15598 (insert (int-to-string depth) ":")
15599 (put-text-property start (point) 'invisible t)
15600 (setq visible-start (point))
15601 (insert-char ? (* depth speedbar-indentation-width))
15602 (put-text-property visible-start (point) 'invisible nil)
15603 (setq start (point))
15604 (insert "[+]")
15605 (speedbar-make-button
15606 start (point) 'speedbar-button-face 'speedbar-highlight-face
15607 'vhdl-speedbar-expand-package pack-key)
15608 (setq visible-start (point))
15609 (insert-char ? 1 nil)
15610 (setq start (point))
15611 (insert pack-name)
15612 (speedbar-make-button
15613 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15614 'vhdl-speedbar-find-file pack-file-marker)
15615 (unless (car pack-file-marker)
15616 (insert "!"))
15617 (when (car body-file-marker)
15618 (insert " (")
15619 (setq start (point))
15620 (insert "body")
15621 (speedbar-make-button
15622 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15623 'vhdl-speedbar-find-file body-file-marker)
15624 (insert ")"))
15625 (insert-char ?\n 1)
15626 (put-text-property visible-start (point) 'invisible nil)))
15627
15628 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15629 pack-body-file-marker depth)
15630 "Insert used package entry."
15631 (let ((start (point))
15632 visible-start)
15633 (insert (int-to-string depth) ":")
15634 (put-text-property start (point) 'invisible t)
15635 (setq visible-start (point))
15636 (insert-char ? (* depth speedbar-indentation-width))
15637 (put-text-property visible-start (point) 'invisible nil)
15638 (setq start (point))
15639 (insert ">")
15640 (speedbar-make-button start (point) nil nil nil)
15641 (setq visible-start (point))
15642 (insert " ")
15643 (setq start (point))
15644 (insert pack-name)
15645 (speedbar-make-button
15646 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15647 'vhdl-speedbar-find-file pack-file-marker)
15648 (when (car pack-body-file-marker)
15649 (insert " (")
15650 (setq start (point))
15651 (insert "body")
15652 (speedbar-make-button
15653 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15654 'vhdl-speedbar-find-file pack-body-file-marker)
15655 (insert ")"))
15656 (setq start (point))
15657 (insert " (" lib-name ")")
15658 (put-text-property (+ 2 start) (1- (point)) 'face
15659 'vhdl-speedbar-library-face)
15660 (insert-char ?\n 1)
15661 (put-text-property visible-start (point) 'invisible nil)))
15662
15663 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15664 func-body-file-marker
15665 depth)
15666 "Insert subprogram entry."
15667 (let ((start (point))
15668 visible-start)
15669 (insert (int-to-string depth) ":")
15670 (put-text-property start (point) 'invisible t)
15671 (setq visible-start (point))
15672 (insert-char ? (* depth speedbar-indentation-width))
15673 (put-text-property visible-start (point) 'invisible nil)
15674 (setq start (point))
15675 (insert ">")
15676 (speedbar-make-button start (point) nil nil nil)
15677 (setq visible-start (point))
15678 (insert " ")
15679 (setq start (point))
15680 (insert func-name)
15681 (speedbar-make-button
15682 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15683 'vhdl-speedbar-find-file func-file-marker)
15684 (when (car func-body-file-marker)
15685 (insert " (")
15686 (setq start (point))
15687 (insert "body")
15688 (speedbar-make-button
15689 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15690 'vhdl-speedbar-find-file func-body-file-marker)
15691 (insert ")"))
15692 (insert-char ?\n 1)
15693 (put-text-property visible-start (point) 'invisible nil)))
15694
15695 (defun vhdl-speedbar-make-title-line (text &optional depth)
15696 "Insert design unit title entry."
15697 (let ((start (point))
15698 visible-start)
15699 (when depth
15700 (insert (int-to-string depth) ":")
15701 (put-text-property start (point) 'invisible t))
15702 (setq visible-start (point))
15703 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15704 (setq start (point))
15705 (insert text)
15706 (speedbar-make-button start (point) nil nil nil nil)
15707 (insert-char ?\n 1)
15708 (put-text-property visible-start (point) 'invisible nil)))
15709
15710 (defun vhdl-speedbar-insert-dirs (files level)
15711 "Insert subdirectories."
15712 (let ((dirs (car files)))
15713 (while dirs
15714 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15715 (car dirs) 'speedbar-dir-follow nil
15716 'speedbar-directory-face level)
15717 (setq dirs (cdr dirs)))))
15718
15719 (declare-function speedbar-reset-scanners "speedbar" ())
15720
15721 (defun vhdl-speedbar-dired (text token indent)
15722 "Speedbar click handler for directory expand button in hierarchy mode."
15723 (cond ((string-match "+" text) ; we have to expand this dir
15724 (setq speedbar-shown-directories
15725 (cons (expand-file-name
15726 (concat (speedbar-line-directory indent) token "/"))
15727 speedbar-shown-directories))
15728 (speedbar-change-expand-button-char ?-)
15729 (speedbar-reset-scanners)
15730 (speedbar-with-writable
15731 (save-excursion
15732 (end-of-line) (forward-char 1)
15733 (vhdl-speedbar-insert-dirs
15734 (speedbar-file-lists
15735 (concat (speedbar-line-directory indent) token "/"))
15736 (1+ indent))
15737 (speedbar-reset-scanners)
15738 (vhdl-speedbar-insert-dir-hierarchy
15739 (abbreviate-file-name
15740 (concat (speedbar-line-directory indent) token "/"))
15741 (1+ indent) speedbar-power-click)))
15742 (vhdl-speedbar-update-current-unit t t))
15743 ((string-match "-" text) ; we have to contract this node
15744 (speedbar-reset-scanners)
15745 (let ((oldl speedbar-shown-directories)
15746 (newl nil)
15747 (td (expand-file-name
15748 (concat (speedbar-line-directory indent) token))))
15749 (while oldl
15750 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15751 (push (car oldl) newl))
15752 (setq oldl (cdr oldl)))
15753 (setq speedbar-shown-directories (nreverse newl)))
15754 (speedbar-change-expand-button-char ?+)
15755 (speedbar-delete-subblock indent))
15756 (t (error "Nothing to display")))
15757 (when (equal (selected-frame) speedbar-frame)
15758 (speedbar-center-buffer-smartly)))
15759
15760 (declare-function speedbar-files-item-info "speedbar" ())
15761
15762 (defun vhdl-speedbar-item-info ()
15763 "Derive and display information about this line item."
15764 (save-excursion
15765 (beginning-of-line)
15766 ;; skip invisible number info
15767 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15768 (cond
15769 ;; project/directory entry
15770 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15771 (if vhdl-speedbar-show-projects
15772 (message "Project \"%s\"" (match-string-no-properties 1))
15773 (speedbar-files-item-info)))
15774 ;; design unit entry
15775 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15776 (goto-char (match-end 1))
15777 (let ((face (get-text-property (point) 'face)))
15778 (message
15779 "%s \"%s\" in \"%s\""
15780 ;; design unit kind
15781 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15782 (eq face 'vhdl-speedbar-entity-selected-face))
15783 (if (equal (match-string 2) ">") "Component" "Entity"))
15784 ((or (eq face 'vhdl-speedbar-architecture-face)
15785 (eq face 'vhdl-speedbar-architecture-selected-face))
15786 "Architecture")
15787 ((or (eq face 'vhdl-speedbar-configuration-face)
15788 (eq face 'vhdl-speedbar-configuration-selected-face))
15789 "Configuration")
15790 ((or (eq face 'vhdl-speedbar-package-face)
15791 (eq face 'vhdl-speedbar-package-selected-face))
15792 "Package")
15793 ((or (eq face 'vhdl-speedbar-instantiation-face)
15794 (eq face 'vhdl-speedbar-instantiation-selected-face))
15795 "Instantiation")
15796 ((eq face 'vhdl-speedbar-subprogram-face)
15797 "Subprogram")
15798 (t ""))
15799 ;; design unit name
15800 (buffer-substring-no-properties
15801 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15802 (match-end 1))
15803 ;; file name
15804 (file-relative-name
15805 (or (car (get-text-property (point) 'speedbar-token))
15806 "?")
15807 (vhdl-default-directory)))))
15808 (t (message "")))))
15809
15810 (declare-function speedbar-line-text "speedbar" (&optional p))
15811
15812 (defun vhdl-speedbar-line-text ()
15813 "Calls `speedbar-line-text' and removes text properties."
15814 (let ((string (speedbar-line-text)))
15815 (set-text-properties 0 (length string) nil string)
15816 string))
15817
15818 (defun vhdl-speedbar-higher-text ()
15819 "Get speedbar-line-text of higher level."
15820 (let (depth string)
15821 (save-excursion
15822 (beginning-of-line)
15823 (looking-at "^\\([0-9]+\\):")
15824 (setq depth (string-to-number (match-string 1)))
15825 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15826 (setq string (match-string 1))
15827 (set-text-properties 0 (length string) nil string)
15828 string))))
15829
15830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15831 ;; Help functions
15832
15833 (defun vhdl-speedbar-line-key (&optional indent)
15834 "Get currently displayed directory of project name."
15835 (if vhdl-speedbar-show-projects
15836 (vhdl-speedbar-line-project)
15837 (abbreviate-file-name
15838 (file-name-as-directory (speedbar-line-directory indent)))))
15839
15840 (defun vhdl-speedbar-line-project (&optional indent)
15841 "Get currently displayed project name."
15842 (and vhdl-speedbar-show-projects
15843 (save-excursion
15844 (end-of-line)
15845 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15846 (match-string-no-properties 1))))
15847
15848 (defun vhdl-add-modified-file ()
15849 "Add file to `vhdl-modified-file-list'."
15850 (when vhdl-file-alist
15851 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15852 nil)
15853
15854 (defun vhdl-resolve-paths (path-list)
15855 "Resolve path wildcards in PATH-LIST."
15856 (let (path-list-1 path-list-2 path-beg path-end dir)
15857 ;; eliminate non-existent directories
15858 (while path-list
15859 (setq dir (car path-list))
15860 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15861 (if (file-directory-p (match-string 2 dir))
15862 (push dir path-list-1)
15863 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15864 (setq path-list (cdr path-list)))
15865 ;; resolve path wildcards
15866 (while path-list-1
15867 (setq dir (car path-list-1))
15868 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15869 (progn
15870 (setq path-beg (match-string 1 dir)
15871 path-end (match-string 5 dir))
15872 (setq path-list-1
15873 (append
15874 (mapcar
15875 (function
15876 (lambda (var) (concat path-beg var path-end)))
15877 (let ((all-list (vhdl-directory-files
15878 (match-string 2 dir) t
15879 (concat "\\<" (wildcard-to-regexp
15880 (match-string 4 dir)))))
15881 dir-list)
15882 (while all-list
15883 (when (file-directory-p (car all-list))
15884 (push (car all-list) dir-list))
15885 (setq all-list (cdr all-list)))
15886 dir-list))
15887 (cdr path-list-1))))
15888 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15889 (when (file-directory-p (match-string 2 dir))
15890 (push dir path-list-2))
15891 (setq path-list-1 (cdr path-list-1))))
15892 (nreverse path-list-2)))
15893
15894 (defun vhdl-speedbar-goto-this-unit (directory unit)
15895 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15896 (let ((dest (point)))
15897 (if (and (if vhdl-speedbar-show-projects
15898 (progn (goto-char (point-min)) t)
15899 (speedbar-goto-this-file directory))
15900 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15901 (progn (speedbar-position-cursor-on-line)
15902 t)
15903 (goto-char dest)
15904 nil)))
15905
15906 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15907 (declare-function speedbar-set-timer "speedbar" (timeout))
15908 ;; speedbar loads dframe at runtime.
15909 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15910
15911 (defun vhdl-speedbar-find-file (text token indent)
15912 "When user clicks on TEXT, load file with name and position in TOKEN.
15913 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15914 is already shown in a buffer."
15915 (if (not (car token))
15916 (error "ERROR: File cannot be found")
15917 (let ((buffer (get-file-buffer (car token))))
15918 (speedbar-find-file-in-frame (car token))
15919 (when (or vhdl-speedbar-jump-to-unit buffer)
15920 (goto-char (point-min))
15921 (forward-line (1- (cdr token)))
15922 (recenter))
15923 (vhdl-speedbar-update-current-unit t t)
15924 (speedbar-set-timer dframe-update-speed)
15925 (dframe-maybee-jump-to-attached-frame))))
15926
15927 (defun vhdl-speedbar-port-copy ()
15928 "Copy the port of the entity/component or subprogram under the cursor."
15929 (interactive)
15930 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15931 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15932 (error "ERROR: No entity/component or subprogram under cursor")
15933 (beginning-of-line)
15934 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15935 (condition-case info
15936 (let ((token (get-text-property
15937 (match-beginning 3) 'speedbar-token)))
15938 (vhdl-visit-file (car token) t
15939 (progn (goto-char (point-min))
15940 (forward-line (1- (cdr token)))
15941 (end-of-line)
15942 (if is-entity
15943 (vhdl-port-copy)
15944 (vhdl-subprog-copy)))))
15945 (error (error "ERROR: %s not scanned successfully\n (%s)"
15946 (if is-entity "Port" "Interface") (cadr info))))
15947 (error "ERROR: No entity/component or subprogram on current line")))))
15948
15949 (defun vhdl-speedbar-place-component ()
15950 "Place the entity/component under the cursor as component."
15951 (interactive)
15952 (if (not (vhdl-speedbar-check-unit 'entity))
15953 (error "ERROR: No entity/component under cursor")
15954 (vhdl-speedbar-port-copy)
15955 (if (fboundp 'speedbar-select-attached-frame)
15956 (speedbar-select-attached-frame)
15957 (select-frame speedbar-attached-frame))
15958 (vhdl-compose-place-component)
15959 (select-frame speedbar-frame)))
15960
15961 (defun vhdl-speedbar-configuration ()
15962 "Generate configuration for the architecture under the cursor."
15963 (interactive)
15964 (if (not (vhdl-speedbar-check-unit 'architecture))
15965 (error "ERROR: No architecture under cursor")
15966 (let ((arch-name (vhdl-speedbar-line-text))
15967 (ent-name (vhdl-speedbar-higher-text)))
15968 (if (fboundp 'speedbar-select-attached-frame)
15969 (speedbar-select-attached-frame)
15970 (select-frame speedbar-attached-frame))
15971 (vhdl-compose-configuration ent-name arch-name))))
15972
15973 (defun vhdl-speedbar-select-mra ()
15974 "Select the architecture under the cursor as MRA."
15975 (interactive)
15976 (if (not (vhdl-speedbar-check-unit 'architecture))
15977 (error "ERROR: No architecture under cursor")
15978 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15979 (ent-key (downcase (vhdl-speedbar-higher-text)))
15980 (ent-alist (vhdl-aget
15981 vhdl-entity-alist
15982 (or (vhdl-project-p)
15983 (abbreviate-file-name default-directory))))
15984 (ent-entry (vhdl-aget ent-alist ent-key)))
15985 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15986 (speedbar-refresh))))
15987
15988 (declare-function speedbar-line-file "speedbar" (&optional p))
15989
15990 (defun vhdl-speedbar-make-design ()
15991 "Make (compile) design unit or directory/project under the cursor."
15992 (interactive)
15993 (if (not (save-excursion (beginning-of-line)
15994 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15995 (error "ERROR: No primary design unit or directory/project under cursor")
15996 (let ((is-unit (match-string 2))
15997 (unit-name (vhdl-speedbar-line-text))
15998 (vhdl-project (vhdl-speedbar-line-project))
15999 (directory (file-name-as-directory
16000 (or (speedbar-line-file) (speedbar-line-directory)))))
16001 (if (fboundp 'speedbar-select-attached-frame)
16002 (speedbar-select-attached-frame)
16003 (select-frame speedbar-attached-frame))
16004 (let ((default-directory directory))
16005 (vhdl-make (and is-unit unit-name))))))
16006
16007 (defun vhdl-speedbar-generate-makefile ()
16008 "Generate Makefile for directory/project under the cursor."
16009 (interactive)
16010 (let ((vhdl-project (vhdl-speedbar-line-project))
16011 (default-directory (file-name-as-directory
16012 (or (speedbar-line-file) (speedbar-line-directory)))))
16013 (vhdl-generate-makefile)))
16014
16015 (defun vhdl-speedbar-check-unit (design-unit)
16016 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
16017 expansion function)."
16018 (save-excursion
16019 (speedbar-position-cursor-on-line)
16020 (cond ((eq design-unit 'entity)
16021 (memq (get-text-property (match-end 0) 'face)
16022 '(vhdl-speedbar-entity-face
16023 vhdl-speedbar-entity-selected-face)))
16024 ((eq design-unit 'architecture)
16025 (memq (get-text-property (match-end 0) 'face)
16026 '(vhdl-speedbar-architecture-face
16027 vhdl-speedbar-architecture-selected-face)))
16028 ((eq design-unit 'subprogram)
16029 (eq (get-text-property (match-end 0) 'face)
16030 'vhdl-speedbar-subprogram-face))
16031 (t nil))))
16032
16033 (defun vhdl-speedbar-set-depth (depth)
16034 "Set hierarchy display depth to DEPTH and refresh speedbar."
16035 (setq vhdl-speedbar-hierarchy-depth depth)
16036 (speedbar-refresh))
16037
16038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16039 ;; Fontification
16040
16041 (defface vhdl-speedbar-entity-face
16042 '((((class color) (background light)) (:foreground "ForestGreen"))
16043 (((class color) (background dark)) (:foreground "PaleGreen")))
16044 "Face used for displaying entity names."
16045 :group 'speedbar-faces)
16046
16047 (defface vhdl-speedbar-architecture-face
16048 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
16049 (((class color) (background light)) (:foreground "Blue"))
16050
16051 (((class color) (background dark)) (:foreground "LightSkyBlue")))
16052 "Face used for displaying architecture names."
16053 :group 'speedbar-faces)
16054
16055 (defface vhdl-speedbar-configuration-face
16056 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
16057 (((class color) (background dark)) (:foreground "Salmon")))
16058 "Face used for displaying configuration names."
16059 :group 'speedbar-faces)
16060
16061 (defface vhdl-speedbar-package-face
16062 '((((class color) (background light)) (:foreground "Grey50"))
16063 (((class color) (background dark)) (:foreground "Grey80")))
16064 "Face used for displaying package names."
16065 :group 'speedbar-faces)
16066
16067 (defface vhdl-speedbar-library-face
16068 '((((class color) (background light)) (:foreground "Purple"))
16069 (((class color) (background dark)) (:foreground "Orchid1")))
16070 "Face used for displaying library names."
16071 :group 'speedbar-faces)
16072
16073 (defface vhdl-speedbar-instantiation-face
16074 '((((class color) (background light)) (:foreground "Brown"))
16075 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
16076 (((class color) (background dark)) (:foreground "Yellow")))
16077 "Face used for displaying instantiation names."
16078 :group 'speedbar-faces)
16079
16080 (defface vhdl-speedbar-subprogram-face
16081 '((((class color) (background light)) (:foreground "Orchid4"))
16082 (((class color) (background dark)) (:foreground "BurlyWood2")))
16083 "Face used for displaying subprogram names."
16084 :group 'speedbar-faces)
16085
16086 (defface vhdl-speedbar-entity-selected-face
16087 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
16088 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
16089 "Face used for displaying entity names."
16090 :group 'speedbar-faces)
16091
16092 (defface vhdl-speedbar-architecture-selected-face
16093 '((((min-colors 88) (class color) (background light)) (:foreground
16094 "Blue1" :underline t))
16095 (((class color) (background light)) (:foreground "Blue" :underline t))
16096 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
16097 "Face used for displaying architecture names."
16098 :group 'speedbar-faces)
16099
16100 (defface vhdl-speedbar-configuration-selected-face
16101 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
16102 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
16103 "Face used for displaying configuration names."
16104 :group 'speedbar-faces)
16105
16106 (defface vhdl-speedbar-package-selected-face
16107 '((((class color) (background light)) (:foreground "Grey50" :underline t))
16108 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
16109 "Face used for displaying package names."
16110 :group 'speedbar-faces)
16111
16112 (defface vhdl-speedbar-instantiation-selected-face
16113 '((((class color) (background light)) (:foreground "Brown" :underline t))
16114 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
16115 "Face used for displaying instantiation names."
16116 :group 'speedbar-faces)
16117
16118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16119 ;; Initialization
16120
16121 ;; add speedbar
16122 (when (fboundp 'speedbar)
16123 (let ((current-frame (selected-frame)))
16124 (condition-case ()
16125 (when (and vhdl-speedbar-auto-open
16126 (not (and (boundp 'speedbar-frame)
16127 (frame-live-p speedbar-frame))))
16128 (speedbar-frame-mode 1))
16129 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
16130 (select-frame current-frame)))
16131
16132 ;; initialize speedbar
16133 (if (not (boundp 'speedbar-frame))
16134 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
16135 (vhdl-speedbar-initialize)
16136 (when speedbar-frame (vhdl-speedbar-refresh)))
16137
16138
16139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16140 ;;; Structural composition
16141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16142
16143 (defun vhdl-get-components-package-name ()
16144 "Return the name of the components package."
16145 (let ((project (vhdl-project-p)))
16146 (if project
16147 (vhdl-replace-string (car vhdl-components-package-name)
16148 (subst-char-in-string ? ?_ project))
16149 (cdr vhdl-components-package-name))))
16150
16151 (defun vhdl-compose-new-component ()
16152 "Create entity and architecture for new component."
16153 (interactive)
16154 (let* ((case-fold-search t)
16155 (ent-name (read-from-minibuffer "entity name: "
16156 nil vhdl-minibuffer-local-map))
16157 (arch-name
16158 (if (equal (cdr vhdl-compose-architecture-name) "")
16159 (read-from-minibuffer "architecture name: "
16160 nil vhdl-minibuffer-local-map)
16161 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16162 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16163 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16164 ;; open entity file
16165 (unless (eq vhdl-compose-create-files 'none)
16166 (setq ent-file-name
16167 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16168 "." (file-name-extension (buffer-file-name))))
16169 (when (and (file-exists-p ent-file-name)
16170 (not (y-or-n-p (concat "File \"" ent-file-name
16171 "\" exists; overwrite? "))))
16172 (error "ERROR: Creating component...aborted"))
16173 (find-file ent-file-name)
16174 (erase-buffer)
16175 (set-buffer-modified-p nil))
16176 ;; insert header
16177 (if vhdl-compose-include-header
16178 (progn (vhdl-template-header)
16179 (setq end-pos (point))
16180 (goto-char (point-max)))
16181 (vhdl-comment-display-line) (insert "\n\n"))
16182 ;; insert library clause
16183 (vhdl-template-package-std-logic-1164)
16184 (when vhdl-use-components-package
16185 (insert "\n")
16186 (vhdl-template-standard-package (vhdl-work-library)
16187 (vhdl-get-components-package-name)))
16188 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16189 ;; insert entity declaration
16190 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16191 (vhdl-insert-keyword " IS\n")
16192 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16193 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16194 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16195 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16196 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16197 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16198 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16199 (vhdl-insert-keyword "END ")
16200 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16201 (insert ent-name ";\n\n")
16202 (vhdl-comment-display-line) (insert "\n")
16203 ;; open architecture file
16204 (if (not (eq vhdl-compose-create-files 'separate))
16205 (insert "\n")
16206 (goto-char (or end-pos (point-min)))
16207 (setq ent-buffer (current-buffer))
16208 (setq arch-file-name
16209 (concat (vhdl-replace-string vhdl-architecture-file-name
16210 (concat ent-name " " arch-name) t)
16211 "." (file-name-extension (buffer-file-name))))
16212 (when (and (file-exists-p arch-file-name)
16213 (not (y-or-n-p (concat "File \"" arch-file-name
16214 "\" exists; overwrite? "))))
16215 (error "ERROR: Creating component...aborted"))
16216 (find-file arch-file-name)
16217 (erase-buffer)
16218 (set-buffer-modified-p nil)
16219 ;; insert header
16220 (if vhdl-compose-include-header
16221 (progn (vhdl-template-header)
16222 (goto-char (point-max)))
16223 (vhdl-comment-display-line) (insert "\n\n")))
16224 ;; insert architecture body
16225 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16226 (vhdl-insert-keyword " OF ") (insert ent-name)
16227 (vhdl-insert-keyword " IS\n\n")
16228 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16229 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16230 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16231 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16232 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16233 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16234 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16235 (vhdl-insert-keyword "BEGIN")
16236 (when vhdl-self-insert-comments
16237 (insert " -- ")
16238 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16239 (insert arch-name))
16240 (insert "\n\n")
16241 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16242 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16243 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16244 (vhdl-insert-keyword "END ")
16245 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16246 (insert arch-name ";\n\n")
16247 ;; insert footer and save
16248 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16249 (vhdl-template-footer)
16250 (vhdl-comment-display-line) (insert "\n"))
16251 (goto-char (or end-pos (point-min)))
16252 (setq arch-buffer (current-buffer))
16253 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16254 (set-buffer arch-buffer) (save-buffer)
16255 (message "%s"
16256 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16257 (and ent-file-name
16258 (format "\n File created: \"%s\"" ent-file-name))
16259 (and arch-file-name
16260 (format "\n File created: \"%s\"" arch-file-name))))))
16261
16262 (defun vhdl-compose-place-component ()
16263 "Place new component by pasting current port as component declaration and
16264 component instantiation."
16265 (interactive)
16266 (if (not vhdl-port-list)
16267 (error "ERROR: No port has been read")
16268 (save-excursion
16269 (vhdl-prepare-search-2
16270 (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)
16271 (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))
16272 (error "ERROR: No architecture found"))
16273 (let* ((ent-name (match-string 1))
16274 (ent-file-name
16275 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16276 "." (file-name-extension (buffer-file-name))))
16277 (orig-buffer (current-buffer)))
16278 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16279 ;; place component declaration
16280 (unless (or vhdl-use-components-package
16281 (vhdl-use-direct-instantiation)
16282 (save-excursion
16283 (re-search-forward
16284 (concat "^\\s-*component\\s-+"
16285 (car vhdl-port-list) "\\>") nil t)))
16286 (re-search-forward "^begin\\>" 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-component t))
16291 ;; place component instantiation
16292 (re-search-forward "^end\\>" nil)
16293 (beginning-of-line)
16294 (skip-chars-backward " \t\n\r\f")
16295 (insert "\n\n") (indent-to vhdl-basic-offset)
16296 (vhdl-port-paste-instance nil t t)
16297 ;; place use clause for used packages
16298 (when (nth 3 vhdl-port-list)
16299 ;; open entity file
16300 (when (file-exists-p ent-file-name)
16301 (find-file ent-file-name))
16302 (goto-char (point-min))
16303 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16304 (error "ERROR: Entity not found: \"%s\"" ent-name))
16305 (goto-char (match-beginning 0))
16306 (if (and (save-excursion
16307 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16308 (match-string 1))
16309 (progn (goto-char (match-end 0))
16310 (beginning-of-line 2))
16311 (insert "\n")
16312 (backward-char))
16313 (vhdl-port-paste-context-clause)
16314 (switch-to-buffer orig-buffer))
16315 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16316
16317 (defun vhdl-compose-wire-components ()
16318 "Connect components."
16319 (interactive)
16320 (save-excursion
16321 (vhdl-prepare-search-2
16322 (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)
16323 (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))
16324 (error "ERROR: No architecture found"))
16325 (let* ((ent-name (match-string 1))
16326 (ent-file-name
16327 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16328 "." (file-name-extension (buffer-file-name))))
16329 (arch-decl-pos (point-marker))
16330 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16331 (arch-end-pos (re-search-forward "^end\\>" nil))
16332 (pack-name (vhdl-get-components-package-name))
16333 (pack-file-name
16334 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16335 "." (file-name-extension (buffer-file-name))))
16336 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16337 port-alist generic-alist inst-alist
16338 signal-name signal-entry signal-alist local-list written-list
16339 single-in-list multi-in-list single-out-list multi-out-list
16340 constant-name constant-entry constant-alist single-list multi-list
16341 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16342 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16343 signal-beg-pos signal-pos
16344 constant-temp-pos port-temp-pos signal-temp-pos)
16345 (message "Wiring components...")
16346 ;; process all instances
16347 (goto-char arch-stat-pos)
16348 (while (re-search-forward
16349 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16350 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16351 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16352 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16353 "[ \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)
16354 (setq inst-name (match-string-no-properties 1)
16355 comp-name (match-string-no-properties 4)
16356 comp-ent-name (match-string-no-properties 12)
16357 has-generic (or (match-string 7) (match-string 17)))
16358 ;; get port ...
16359 (if comp-name
16360 ;; ... from component declaration
16361 (vhdl-visit-file
16362 (when vhdl-use-components-package pack-file-name) t
16363 (save-excursion
16364 (goto-char (point-min))
16365 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16366 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16367 (vhdl-port-copy)))
16368 ;; ... from entity declaration (direct instantiation)
16369 (setq comp-ent-file-name
16370 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16371 "." (file-name-extension (buffer-file-name))))
16372 (vhdl-visit-file
16373 comp-ent-file-name t
16374 (save-excursion
16375 (goto-char (point-min))
16376 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16377 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16378 (vhdl-port-copy))))
16379 (vhdl-port-flatten t)
16380 (setq generic-alist (nth 1 vhdl-port-list)
16381 port-alist (nth 2 vhdl-port-list)
16382 vhdl-port-list nil)
16383 (setq constant-alist nil
16384 signal-alist nil)
16385 (when has-generic
16386 ;; process all constants in generic map
16387 (vhdl-forward-syntactic-ws)
16388 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16389 (setq constant-name (match-string-no-properties 3))
16390 (setq constant-entry
16391 (cons constant-name
16392 (if (match-string 1)
16393 (or (vhdl-aget generic-alist (match-string 2))
16394 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16395 (cdar generic-alist))))
16396 (push constant-entry constant-alist)
16397 (setq constant-name (downcase constant-name))
16398 (if (or (member constant-name single-list)
16399 (member constant-name multi-list))
16400 (progn (setq single-list (delete constant-name single-list))
16401 (add-to-list 'multi-list constant-name))
16402 (add-to-list 'single-list constant-name))
16403 (unless (match-string 1)
16404 (setq generic-alist (cdr generic-alist)))
16405 (vhdl-forward-syntactic-ws))
16406 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16407 ;; process all signals in port map
16408 (vhdl-forward-syntactic-ws)
16409 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16410 (setq signal-name (match-string-no-properties 3))
16411 (setq signal-entry
16412 (cons signal-name
16413 (if (match-string 1)
16414 (or (vhdl-aget port-alist (match-string 2))
16415 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16416 (cdar port-alist))))
16417 (push signal-entry signal-alist)
16418 (setq signal-name (downcase signal-name))
16419 (if (equal (upcase (nth 2 signal-entry)) "IN")
16420 ;; input signal
16421 (cond
16422 ((member signal-name local-list)
16423 nil)
16424 ((or (member signal-name single-out-list)
16425 (member signal-name multi-out-list))
16426 (setq single-out-list (delete signal-name single-out-list))
16427 (setq multi-out-list (delete signal-name multi-out-list))
16428 (add-to-list 'local-list signal-name))
16429 ((member signal-name single-in-list)
16430 (setq single-in-list (delete signal-name single-in-list))
16431 (add-to-list 'multi-in-list signal-name))
16432 ((not (member signal-name multi-in-list))
16433 (add-to-list 'single-in-list signal-name)))
16434 ;; output signal
16435 (cond
16436 ((member signal-name local-list)
16437 nil)
16438 ((or (member signal-name single-in-list)
16439 (member signal-name multi-in-list))
16440 (setq single-in-list (delete signal-name single-in-list))
16441 (setq multi-in-list (delete signal-name multi-in-list))
16442 (add-to-list 'local-list signal-name))
16443 ((member signal-name single-out-list)
16444 (setq single-out-list (delete signal-name single-out-list))
16445 (add-to-list 'multi-out-list signal-name))
16446 ((not (member signal-name multi-out-list))
16447 (add-to-list 'single-out-list signal-name))))
16448 (unless (match-string 1)
16449 (setq port-alist (cdr port-alist)))
16450 (vhdl-forward-syntactic-ws))
16451 (push (list inst-name (nreverse constant-alist)
16452 (nreverse signal-alist)) inst-alist))
16453 ;; prepare signal insertion
16454 (vhdl-goto-marker arch-decl-pos)
16455 (forward-line 1)
16456 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16457 (setq signal-pos (point-marker))
16458 (while (progn (vhdl-forward-syntactic-ws)
16459 (looking-at "signal\\>"))
16460 (beginning-of-line 2)
16461 (delete-region signal-pos (point)))
16462 (setq signal-beg-pos signal-pos)
16463 ;; open entity file
16464 (when (file-exists-p ent-file-name)
16465 (find-file ent-file-name))
16466 (goto-char (point-min))
16467 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16468 (error "ERROR: Entity not found: \"%s\"" ent-name))
16469 ;; prepare generic clause insertion
16470 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16471 (match-string 1))
16472 (goto-char (match-beginning 0))
16473 (indent-to vhdl-basic-offset)
16474 (insert "generic ();\n\n")
16475 (backward-char 4))
16476 (backward-char)
16477 (setq generic-pos (point-marker))
16478 (forward-sexp) (end-of-line)
16479 (delete-region generic-pos (point)) (delete-char 1)
16480 (insert "(\n")
16481 (when multi-list
16482 (insert "\n")
16483 (indent-to (* 2 vhdl-basic-offset))
16484 (insert "-- global generics\n"))
16485 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16486 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16487 ;; prepare port clause insertion
16488 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16489 (match-string 1))
16490 (goto-char (match-beginning 0))
16491 (indent-to vhdl-basic-offset)
16492 (insert "port ();\n\n")
16493 (backward-char 4))
16494 (backward-char)
16495 (setq port-in-pos (point-marker))
16496 (forward-sexp) (end-of-line)
16497 (delete-region port-in-pos (point)) (delete-char 1)
16498 (insert "(\n")
16499 (when (or multi-in-list multi-out-list)
16500 (insert "\n")
16501 (indent-to (* 2 vhdl-basic-offset))
16502 (insert "-- global ports\n"))
16503 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16504 port-out-pos (point-marker) port-inst-pos (point-marker)
16505 port-end-pos (point-marker))
16506 ;; insert generics, ports and signals
16507 (setq inst-alist (nreverse inst-alist))
16508 (while inst-alist
16509 (setq inst-name (nth 0 (car inst-alist))
16510 constant-alist (nth 1 (car inst-alist))
16511 signal-alist (nth 2 (car inst-alist))
16512 constant-temp-pos generic-inst-pos
16513 port-temp-pos port-inst-pos
16514 signal-temp-pos signal-pos)
16515 ;; generics
16516 (while constant-alist
16517 (setq constant-name (downcase (caar constant-alist))
16518 constant-entry (car constant-alist))
16519 (unless (string-match "^[0-9]+" constant-name)
16520 (cond ((member constant-name written-list)
16521 nil)
16522 ((member constant-name multi-list)
16523 (vhdl-goto-marker generic-pos)
16524 (setq generic-end-pos
16525 (vhdl-max-marker
16526 generic-end-pos
16527 (vhdl-compose-insert-generic constant-entry)))
16528 (setq generic-pos (point-marker))
16529 (add-to-list 'written-list constant-name))
16530 (t
16531 (vhdl-goto-marker
16532 (vhdl-max-marker generic-inst-pos generic-pos))
16533 (setq generic-end-pos
16534 (vhdl-compose-insert-generic constant-entry))
16535 (setq generic-inst-pos (point-marker))
16536 (add-to-list 'written-list constant-name))))
16537 (setq constant-alist (cdr constant-alist)))
16538 (when (/= constant-temp-pos generic-inst-pos)
16539 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16540 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16541 (insert "-- generics for \"" inst-name "\"\n")
16542 (vhdl-goto-marker generic-inst-pos))
16543 ;; ports and signals
16544 (while signal-alist
16545 (setq signal-name (downcase (caar signal-alist))
16546 signal-entry (car signal-alist))
16547 (cond ((member signal-name written-list)
16548 nil)
16549 ((member signal-name multi-in-list)
16550 (vhdl-goto-marker port-in-pos)
16551 (setq port-end-pos
16552 (vhdl-max-marker
16553 port-end-pos (vhdl-compose-insert-port signal-entry)))
16554 (setq port-in-pos (point-marker))
16555 (add-to-list 'written-list signal-name))
16556 ((member signal-name multi-out-list)
16557 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16558 (setq port-end-pos
16559 (vhdl-max-marker
16560 port-end-pos (vhdl-compose-insert-port signal-entry)))
16561 (setq port-out-pos (point-marker))
16562 (add-to-list 'written-list signal-name))
16563 ((or (member signal-name single-in-list)
16564 (member signal-name single-out-list))
16565 (vhdl-goto-marker
16566 (vhdl-max-marker
16567 port-inst-pos
16568 (vhdl-max-marker port-out-pos port-in-pos)))
16569 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16570 (setq port-inst-pos (point-marker))
16571 (add-to-list 'written-list signal-name))
16572 ((equal (upcase (nth 2 signal-entry)) "OUT")
16573 (vhdl-goto-marker signal-pos)
16574 (vhdl-compose-insert-signal signal-entry)
16575 (setq signal-pos (point-marker))
16576 (add-to-list 'written-list signal-name)))
16577 (setq signal-alist (cdr signal-alist)))
16578 (when (/= port-temp-pos port-inst-pos)
16579 (vhdl-goto-marker
16580 (vhdl-max-marker port-temp-pos
16581 (vhdl-max-marker port-in-pos port-out-pos)))
16582 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16583 (insert "-- ports to \"" inst-name "\"\n")
16584 (vhdl-goto-marker port-inst-pos))
16585 (when (/= signal-temp-pos signal-pos)
16586 (vhdl-goto-marker signal-temp-pos)
16587 (insert "\n") (indent-to vhdl-basic-offset)
16588 (insert "-- outputs of \"" inst-name "\"\n")
16589 (vhdl-goto-marker signal-pos))
16590 (setq inst-alist (cdr inst-alist)))
16591 ;; finalize generic/port clause
16592 (vhdl-goto-marker generic-end-pos) (backward-char)
16593 (when (= generic-beg-pos generic-end-pos)
16594 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16595 (insert ";") (backward-char))
16596 (insert ")")
16597 (vhdl-goto-marker port-end-pos) (backward-char)
16598 (when (= port-beg-pos port-end-pos)
16599 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16600 (insert ";") (backward-char))
16601 (insert ")")
16602 ;; align everything
16603 (when vhdl-auto-align
16604 (vhdl-goto-marker generic-beg-pos)
16605 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16606 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16607 (vhdl-goto-marker signal-beg-pos)
16608 (vhdl-align-region-groups signal-beg-pos signal-pos))
16609 (switch-to-buffer (marker-buffer signal-beg-pos))
16610 (message "Wiring components...done")))))
16611
16612 (defun vhdl-compose-insert-generic (entry)
16613 "Insert ENTRY as generic declaration."
16614 (let (pos)
16615 (indent-to (* 2 vhdl-basic-offset))
16616 (insert (nth 0 entry) " : " (nth 1 entry))
16617 (when (nth 2 entry)
16618 (insert " := " (nth 2 entry)))
16619 (insert ";")
16620 (setq pos (point-marker))
16621 (when (and vhdl-include-port-comments (nth 3 entry))
16622 (vhdl-comment-insert-inline (nth 3 entry) t))
16623 (insert "\n")
16624 pos))
16625
16626 (defun vhdl-compose-insert-port (entry)
16627 "Insert ENTRY as port declaration."
16628 (let (pos)
16629 (indent-to (* 2 vhdl-basic-offset))
16630 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16631 (setq pos (point-marker))
16632 (when (and vhdl-include-port-comments (nth 4 entry))
16633 (vhdl-comment-insert-inline (nth 4 entry) t))
16634 (insert "\n")
16635 pos))
16636
16637 (defun vhdl-compose-insert-signal (entry)
16638 "Insert ENTRY as signal declaration."
16639 (indent-to vhdl-basic-offset)
16640 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16641 (when (and vhdl-include-port-comments (nth 4 entry))
16642 (vhdl-comment-insert-inline (nth 4 entry) t))
16643 (insert "\n"))
16644
16645 (defun vhdl-compose-components-package ()
16646 "Generate a package containing component declarations for all entities in the
16647 current project/directory."
16648 (interactive)
16649 (vhdl-require-hierarchy-info)
16650 (let* ((project (vhdl-project-p))
16651 (pack-name (vhdl-get-components-package-name))
16652 (pack-file-name
16653 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16654 "." (file-name-extension (buffer-file-name))))
16655 (ent-alist (vhdl-aget vhdl-entity-alist
16656 (or project
16657 (abbreviate-file-name default-directory))))
16658 (lazy-lock-minimum-size 0)
16659 clause-pos component-pos)
16660 (message "Generating components package \"%s\"..." pack-name)
16661 ;; open package file
16662 (when (and (file-exists-p pack-file-name)
16663 (not (y-or-n-p (concat "File \"" pack-file-name
16664 "\" exists; overwrite? "))))
16665 (error "ERROR: Generating components package...aborted"))
16666 (find-file pack-file-name)
16667 (erase-buffer)
16668 ;; insert header
16669 (if vhdl-compose-include-header
16670 (progn (vhdl-template-header
16671 (concat "Components package (generated by Emacs VHDL Mode "
16672 vhdl-version ")"))
16673 (goto-char (point-max)))
16674 (vhdl-comment-display-line) (insert "\n\n"))
16675 ;; insert std_logic_1164 package
16676 (vhdl-template-package-std-logic-1164)
16677 (insert "\n") (setq clause-pos (point-marker))
16678 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16679 ;; insert package declaration
16680 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16681 (vhdl-insert-keyword " IS\n\n")
16682 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16683 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16684 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16685 (indent-to vhdl-basic-offset)
16686 (setq component-pos (point-marker))
16687 (insert "\n\n") (vhdl-insert-keyword "END ")
16688 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16689 (insert pack-name ";\n\n")
16690 ;; insert footer
16691 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16692 (vhdl-template-footer)
16693 (vhdl-comment-display-line) (insert "\n"))
16694 ;; insert component declarations
16695 (while ent-alist
16696 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16697 (progn (goto-char (point-min))
16698 (forward-line (1- (nth 3 (car ent-alist))))
16699 (end-of-line)
16700 (vhdl-port-copy)))
16701 (goto-char component-pos)
16702 (vhdl-port-paste-component t)
16703 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16704 (setq component-pos (point-marker))
16705 (goto-char clause-pos)
16706 (vhdl-port-paste-context-clause pack-name)
16707 (setq clause-pos (point-marker))
16708 (setq ent-alist (cdr ent-alist)))
16709 (goto-char (point-min))
16710 (save-buffer)
16711 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16712 pack-name pack-file-name)))
16713
16714 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16715 conf-alist inst-alist
16716 &optional insert-conf)
16717 "Generate block configuration for architecture."
16718 (let ((margin (current-indentation))
16719 (beg (point-at-bol))
16720 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16721 ;; insert block configuration (for architecture)
16722 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16723 (setq margin (+ margin vhdl-basic-offset))
16724 ;; process all instances
16725 (while inst-alist
16726 (setq inst-entry (car inst-alist))
16727 ;; is component?
16728 (when (nth 4 inst-entry)
16729 (setq insert-conf t)
16730 (setq inst-path (nth 9 inst-entry))
16731 ;; skip common path with previous instance
16732 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16733 (setq inst-path (cdr inst-path)
16734 inst-prev-path (cdr inst-prev-path)))
16735 ;; insert block configuration end (for previous block/generate)
16736 (while inst-prev-path
16737 (setq margin (- margin vhdl-basic-offset))
16738 (indent-to margin)
16739 (vhdl-insert-keyword "END FOR;\n")
16740 (setq inst-prev-path (cdr inst-prev-path)))
16741 ;; insert block configuration beginning (for current block/generate)
16742 (indent-to margin)
16743 (while inst-path
16744 (setq margin (+ margin vhdl-basic-offset))
16745 (vhdl-insert-keyword "FOR ")
16746 (insert (car inst-path) "\n")
16747 (indent-to margin)
16748 (setq inst-path (cdr inst-path)))
16749 ;; insert component configuration beginning
16750 (vhdl-insert-keyword "FOR ")
16751 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16752 ;; find subconfiguration
16753 (setq conf-key (nth 7 inst-entry))
16754 (setq tmp-alist conf-alist)
16755 ;; use first configuration found for instance's entity
16756 (while (and tmp-alist (null conf-key))
16757 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16758 (setq conf-key (nth 0 (car tmp-alist))))
16759 (setq tmp-alist (cdr tmp-alist)))
16760 (setq conf-entry (vhdl-aget conf-alist conf-key))
16761 ;; insert binding indication ...
16762 ;; ... with subconfiguration (if exists)
16763 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16764 (progn
16765 (indent-to (+ margin vhdl-basic-offset))
16766 (vhdl-insert-keyword "USE CONFIGURATION ")
16767 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16768 (insert ";\n"))
16769 ;; ... with entity (if exists)
16770 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16771 (when ent-entry
16772 (indent-to (+ margin vhdl-basic-offset))
16773 (vhdl-insert-keyword "USE ENTITY ")
16774 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16775 ;; insert architecture name (if architecture exists)
16776 (when (nth 3 ent-entry)
16777 (setq arch-name
16778 ;; choose architecture name a) from configuration,
16779 ;; b) from mra, or c) from first architecture
16780 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16781 (or (nth 6 inst-entry)
16782 (nth 4 ent-entry))))
16783 (nth 1 (car (nth 3 ent-entry)))))
16784 (insert "(" arch-name ")"))
16785 (insert ";\n")
16786 ;; insert block configuration (for architecture of subcomponent)
16787 (when (and vhdl-compose-configuration-hierarchical
16788 (nth 3 ent-entry))
16789 (indent-to (+ margin vhdl-basic-offset))
16790 (vhdl-compose-configuration-architecture
16791 (nth 0 ent-entry) arch-name ent-alist conf-alist
16792 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16793 ;; insert component configuration end
16794 (indent-to margin)
16795 (vhdl-insert-keyword "END FOR;\n")
16796 (setq inst-prev-path (nth 9 inst-entry)))
16797 (setq inst-alist (cdr inst-alist)))
16798 ;; insert block configuration end (for block/generate)
16799 (while inst-prev-path
16800 (setq margin (- margin vhdl-basic-offset))
16801 (indent-to margin)
16802 (vhdl-insert-keyword "END FOR;\n")
16803 (setq inst-prev-path (cdr inst-prev-path)))
16804 (indent-to (- margin vhdl-basic-offset))
16805 ;; insert block configuration end or remove beginning (for architecture)
16806 (if insert-conf
16807 (vhdl-insert-keyword "END FOR;\n")
16808 (delete-region beg (point)))))
16809
16810 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16811 "Generate configuration declaration."
16812 (interactive)
16813 (vhdl-require-hierarchy-info)
16814 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16815 (or (vhdl-project-p)
16816 (abbreviate-file-name default-directory))))
16817 (conf-alist (vhdl-aget vhdl-config-alist
16818 (or (vhdl-project-p)
16819 (abbreviate-file-name default-directory))))
16820 (from-speedbar ent-name)
16821 inst-alist conf-name conf-file-name pos)
16822 (vhdl-prepare-search-2
16823 ;; get entity and architecture name
16824 (unless ent-name
16825 (save-excursion
16826 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16827 (not (equal "END" (upcase (match-string 1))))
16828 (setq ent-name (match-string-no-properties 3))
16829 (setq arch-name (match-string-no-properties 2)))
16830 (error "ERROR: Not within an architecture"))))
16831 (setq conf-name (vhdl-replace-string
16832 vhdl-compose-configuration-name
16833 (concat ent-name " " arch-name)))
16834 (setq inst-alist
16835 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16836 (downcase arch-name)))))
16837 (message "Generating configuration \"%s\"..." conf-name)
16838 (if vhdl-compose-configuration-create-file
16839 ;; open configuration file
16840 (progn
16841 (setq conf-file-name
16842 (concat (vhdl-replace-string vhdl-configuration-file-name
16843 conf-name t)
16844 "." (file-name-extension (buffer-file-name))))
16845 (when (and (file-exists-p conf-file-name)
16846 (not (y-or-n-p (concat "File \"" conf-file-name
16847 "\" exists; overwrite? "))))
16848 (error "ERROR: Creating configuration...aborted"))
16849 (find-file conf-file-name)
16850 (erase-buffer)
16851 (set-buffer-modified-p nil)
16852 ;; insert header
16853 (if vhdl-compose-include-header
16854 (progn (vhdl-template-header
16855 (concat "Configuration declaration for design \""
16856 ent-name "(" arch-name ")\""))
16857 (goto-char (point-max)))
16858 (vhdl-comment-display-line) (insert "\n\n")))
16859 ;; goto end of architecture
16860 (unless from-speedbar
16861 (re-search-forward "^end\\>" nil)
16862 (end-of-line) (insert "\n\n")
16863 (vhdl-comment-display-line) (insert "\n\n")))
16864 ;; insert library clause
16865 (setq pos (point))
16866 (vhdl-template-standard-package (vhdl-work-library) nil)
16867 (when (/= pos (point))
16868 (insert "\n\n"))
16869 ;; insert configuration
16870 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16871 (vhdl-insert-keyword " OF ") (insert ent-name)
16872 (vhdl-insert-keyword " IS\n")
16873 (indent-to vhdl-basic-offset)
16874 ;; insert block configuration (for architecture)
16875 (vhdl-compose-configuration-architecture
16876 ent-name arch-name ent-alist conf-alist inst-alist t)
16877 (vhdl-insert-keyword "END ") (insert conf-name ";")
16878 (when conf-file-name
16879 ;; insert footer and save
16880 (insert "\n\n")
16881 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16882 (vhdl-template-footer)
16883 (vhdl-comment-display-line) (insert "\n"))
16884 (save-buffer))
16885 (message "%s"
16886 (concat (format "Generating configuration \"%s\"...done" conf-name)
16887 (and conf-file-name
16888 (format "\n File created: \"%s\"" conf-file-name))))))
16889
16890
16891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16892 ;;; Compilation / Makefile generation
16893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16894 ;; (using `compile.el')
16895
16896 (defvar vhdl-compile-post-command ""
16897 "String appended to compile command after file name.")
16898
16899 (defun vhdl-makefile-name ()
16900 "Return the Makefile name of the current project or the current compiler if
16901 no project is defined."
16902 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16903 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16904 (vhdl-replace-string
16905 (cons "\\(.*\\)\n\\(.*\\)"
16906 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16907 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16908
16909 (defun vhdl-compile-directory ()
16910 "Return the directory where compilation/make should be run."
16911 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16912 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16913 (directory (vhdl-resolve-env-variable
16914 (if project
16915 (vhdl-replace-string
16916 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16917 (nth 6 compiler)))))
16918 (file-name-as-directory
16919 (if (file-name-absolute-p directory)
16920 directory
16921 (expand-file-name directory (vhdl-default-directory))))))
16922
16923 (defun vhdl-uniquify (in-list)
16924 "Remove duplicate elements from IN-LIST."
16925 (let (out-list)
16926 (while in-list
16927 (add-to-list 'out-list (car in-list))
16928 (setq in-list (cdr in-list)))
16929 out-list))
16930
16931 (defun vhdl-set-compiler (name)
16932 "Set current compiler to NAME."
16933 (interactive
16934 (list (let ((completion-ignore-case t))
16935 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16936 (if (assoc name vhdl-compiler-alist)
16937 (progn (setq vhdl-compiler name)
16938 (message "Current compiler: \"%s\"" vhdl-compiler))
16939 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16940
16941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16942 ;; Compilation
16943
16944 (defun vhdl-compile-init ()
16945 "Initialize for compilation."
16946 (when (and (not vhdl-emacs-22)
16947 (or (null compilation-error-regexp-alist)
16948 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16949 compilation-error-regexp-alist))))
16950 ;; `compilation-error-regexp-alist'
16951 (let ((commands-alist vhdl-compiler-alist)
16952 regexp-alist sublist)
16953 (while commands-alist
16954 (setq sublist (nth 11 (car commands-alist)))
16955 (unless (or (equal "" (car sublist))
16956 (assoc (car sublist) regexp-alist))
16957 (push (list (nth 0 sublist)
16958 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16959 9
16960 (nth 1 sublist))
16961 (nth 2 sublist) (nth 3 sublist))
16962 regexp-alist))
16963 (setq commands-alist (cdr commands-alist)))
16964 (setq compilation-error-regexp-alist
16965 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16966 ;; `compilation-file-regexp-alist'
16967 (let ((commands-alist vhdl-compiler-alist)
16968 regexp-alist sublist)
16969 ;; matches vhdl-mode file name output
16970 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16971 (while commands-alist
16972 (setq sublist (nth 12 (car commands-alist)))
16973 (unless (or (equal "" (car sublist))
16974 (assoc (car sublist) regexp-alist))
16975 (push sublist regexp-alist))
16976 (setq commands-alist (cdr commands-alist)))
16977 (setq compilation-file-regexp-alist
16978 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16979
16980 (defvar vhdl-compile-file-name nil
16981 "Name of file to be compiled.")
16982
16983 (defun vhdl-compile-print-file-name ()
16984 "Function called within `compile' to print out file name for compilers that
16985 do not print any file names."
16986 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16987
16988 (defun vhdl-get-compile-options (project compiler file-name
16989 &optional file-options-only)
16990 "Get compiler options. Returning nil means do not compile this file."
16991 (let* ((compiler-options (nth 1 compiler))
16992 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
16993 (project-options (nth 0 project-entry))
16994 (exception-list (and file-name (nth 2 project-entry)))
16995 (work-library (vhdl-work-library))
16996 (case-fold-search nil)
16997 file-options)
16998 (while (and exception-list
16999 (not (string-match (caar exception-list) file-name)))
17000 (setq exception-list (cdr exception-list)))
17001 (if (and exception-list (not (cdar exception-list)))
17002 nil
17003 (if (and file-options-only (not exception-list))
17004 'default
17005 (setq file-options (cdar exception-list))
17006 ;; insert library name in compiler-specific options
17007 (setq compiler-options
17008 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
17009 work-library))
17010 ;; insert compiler-specific options in project-specific options
17011 (when project-options
17012 (setq project-options
17013 (vhdl-replace-string
17014 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17015 (concat work-library "\n" compiler-options))))
17016 ;; insert project-specific options in file-specific options
17017 (when file-options
17018 (setq file-options
17019 (vhdl-replace-string
17020 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
17021 (concat work-library "\n" compiler-options "\n"
17022 project-options))))
17023 ;; return options
17024 (or file-options project-options compiler-options)))))
17025
17026 (defun vhdl-get-make-options (project compiler)
17027 "Get make options."
17028 (let* ((compiler-options (nth 3 compiler))
17029 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17030 (project-options (nth 1 project-entry))
17031 (makefile-name (vhdl-makefile-name)))
17032 ;; insert Makefile name in compiler-specific options
17033 (setq compiler-options
17034 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
17035 makefile-name))
17036 ;; insert compiler-specific options in project-specific options
17037 (when project-options
17038 (setq project-options
17039 (vhdl-replace-string
17040 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17041 (concat makefile-name "\n" compiler-options))))
17042 ;; return options
17043 (or project-options compiler-options)))
17044
17045 (defun vhdl-compile ()
17046 "Compile current buffer using the VHDL compiler specified in
17047 `vhdl-compiler'."
17048 (interactive)
17049 (vhdl-compile-init)
17050 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17051 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17052 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17053 (command (nth 0 compiler))
17054 (default-directory (vhdl-compile-directory))
17055 (file-name (if vhdl-compile-absolute-path
17056 (buffer-file-name)
17057 (file-relative-name (buffer-file-name))))
17058 (options (vhdl-get-compile-options project compiler file-name))
17059 compilation-process-setup-function)
17060 (unless (file-directory-p default-directory)
17061 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17062 ;; put file name into quotes if it contains spaces
17063 (when (string-match " " file-name)
17064 (setq file-name (concat "\"" file-name "\"")))
17065 ;; print out file name if compiler does not
17066 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
17067 (buffer-file-name)
17068 (file-relative-name (buffer-file-name))))
17069 (when (and (= 0 (nth 1 (nth 10 compiler)))
17070 (= 0 (nth 1 (nth 11 compiler))))
17071 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
17072 ;; run compilation
17073 (if options
17074 (when command
17075 (compile (concat command " " options " " file-name
17076 (unless (equal vhdl-compile-post-command "")
17077 (concat " " vhdl-compile-post-command)))))
17078 (vhdl-warning "Your project settings tell me not to compile this file"))))
17079
17080 (defvar vhdl-make-target "all"
17081 "Default target for `vhdl-make' command.")
17082
17083 (defun vhdl-make (&optional target)
17084 "Call make command for compilation of all updated source files (requires
17085 `Makefile'). Optional argument TARGET allows you to compile the design
17086 specified by a target."
17087 (interactive)
17088 (setq vhdl-make-target
17089 (or target (read-from-minibuffer "Target: " vhdl-make-target
17090 vhdl-minibuffer-local-map)))
17091 (vhdl-compile-init)
17092 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17093 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17094 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17095 (command (nth 2 compiler))
17096 (options (vhdl-get-make-options project compiler))
17097 (default-directory (vhdl-compile-directory)))
17098 (unless (file-directory-p default-directory)
17099 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17100 ;; run make
17101 (compile (concat (if (equal command "") "make" command)
17102 " " options " " vhdl-make-target))))
17103
17104 ;; Emacs 22+ setup
17105 (defvar vhdl-error-regexp-emacs-alist
17106 ;; Get regexps from `vhdl-compiler-alist'
17107 (let ((compiler-alist vhdl-compiler-alist)
17108 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
17109 (while compiler-alist
17110 ;; only add regexps for currently selected compiler
17111 (when (or (not vhdl-compile-use-local-error-regexp)
17112 (equal vhdl-compiler (nth 0 (car compiler-alist))))
17113 ;; add error message regexps
17114 (setq error-regexp-alist
17115 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
17116 (nth 11 (car compiler-alist)))
17117 error-regexp-alist))
17118 ;; add filename regexps
17119 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
17120 (setq error-regexp-alist
17121 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
17122 (nth 12 (car compiler-alist)))
17123 error-regexp-alist))))
17124 (setq compiler-alist (cdr compiler-alist)))
17125 error-regexp-alist)
17126 "List of regexps for VHDL compilers. For Emacs 22+.")
17127
17128 ;; Add error regexps using compilation-mode-hook.
17129 (defun vhdl-error-regexp-add-emacs ()
17130 "Set up Emacs compile for VHDL."
17131 (interactive)
17132 (when (and (boundp 'compilation-error-regexp-alist-alist)
17133 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
17134 ;; remove all other compilers
17135 (when vhdl-compile-use-local-error-regexp
17136 (setq compilation-error-regexp-alist nil))
17137 ;; add VHDL compilers
17138 (mapcar
17139 (lambda (item)
17140 (push (car item) compilation-error-regexp-alist)
17141 (push item compilation-error-regexp-alist-alist))
17142 vhdl-error-regexp-emacs-alist)))
17143
17144 (when vhdl-emacs-22
17145 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
17146
17147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17148 ;; Makefile generation
17149
17150 (defun vhdl-generate-makefile ()
17151 "Generate `Makefile'."
17152 (interactive)
17153 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17154 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17155 (command (nth 4 compiler)))
17156 ;; generate makefile
17157 (if command
17158 (let ((default-directory (vhdl-compile-directory)))
17159 (compile (vhdl-replace-string
17160 (cons "\\(.*\\) \\(.*\\)" command)
17161 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17162 (vhdl-generate-makefile-1))))
17163
17164 (defun vhdl-get-packages (lib-alist work-library)
17165 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17166 (let (pack-list)
17167 (while lib-alist
17168 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17169 (push (cdar lib-alist) pack-list))
17170 (setq lib-alist (cdr lib-alist)))
17171 pack-list))
17172
17173 (defun vhdl-generate-makefile-1 ()
17174 "Generate Makefile for current project or directory."
17175 ;; scan hierarchy if required
17176 (if (vhdl-project-p)
17177 (unless (or (assoc vhdl-project vhdl-file-alist)
17178 (vhdl-load-cache vhdl-project))
17179 (vhdl-scan-project-contents vhdl-project))
17180 (let ((directory (abbreviate-file-name default-directory)))
17181 (unless (or (assoc directory vhdl-file-alist)
17182 (vhdl-load-cache directory))
17183 (vhdl-scan-directory-contents directory))))
17184 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17185 (project (vhdl-project-p))
17186 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17187 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17188 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17189 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17190 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17191 "\\1.vhd" "\\1_body.vhd" identity)))
17192 (mapping-exist
17193 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17194 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17195 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17196 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17197 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17198 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17199 (adjust-case (nth 5 regexp-list))
17200 (work-library (downcase (vhdl-work-library)))
17201 (compile-directory (expand-file-name (vhdl-compile-directory)
17202 default-directory))
17203 (makefile-name (vhdl-makefile-name))
17204 rule-alist arch-alist inst-alist
17205 target-list depend-list unit-list prim-list second-list subcomp-list
17206 lib-alist lib-body-alist pack-list all-pack-list
17207 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17208 conf-key conf-file-name pack-key pack-file-name
17209 ent-entry arch-entry conf-entry pack-entry inst-entry
17210 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17211 tmp-key tmp-list rule)
17212 ;; check prerequisites
17213 (unless (file-exists-p compile-directory)
17214 (make-directory compile-directory t))
17215 (unless mapping-exist
17216 (vhdl-warning
17217 (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\""
17218 vhdl-compiler vhdl-compiler) t))
17219 (message "Generating makefile \"%s\"..." makefile-name)
17220 ;; rules for all entities
17221 (setq tmp-list ent-alist)
17222 (while ent-alist
17223 (setq ent-entry (car ent-alist)
17224 ent-key (nth 0 ent-entry))
17225 (when (nth 2 ent-entry)
17226 (setq ent-file-name (if vhdl-compile-absolute-path
17227 (nth 2 ent-entry)
17228 (file-relative-name (nth 2 ent-entry)
17229 compile-directory))
17230 arch-alist (nth 4 ent-entry)
17231 lib-alist (nth 6 ent-entry)
17232 rule (vhdl-aget rule-alist ent-file-name)
17233 target-list (nth 0 rule)
17234 depend-list (nth 1 rule)
17235 second-list nil
17236 subcomp-list nil)
17237 (setq tmp-key (vhdl-replace-string
17238 ent-regexp
17239 (funcall adjust-case
17240 (concat ent-key " " work-library))))
17241 (push (cons ent-key tmp-key) unit-list)
17242 ;; rule target for this entity
17243 (push ent-key target-list)
17244 ;; rule dependencies for all used packages
17245 (setq pack-list (vhdl-get-packages lib-alist work-library))
17246 (setq depend-list (append depend-list pack-list))
17247 (setq all-pack-list pack-list)
17248 ;; add rule
17249 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17250 ;; rules for all corresponding architectures
17251 (while arch-alist
17252 (setq arch-entry (car arch-alist)
17253 arch-key (nth 0 arch-entry)
17254 ent-arch-key (concat ent-key "-" arch-key)
17255 arch-file-name (if vhdl-compile-absolute-path
17256 (nth 2 arch-entry)
17257 (file-relative-name (nth 2 arch-entry)
17258 compile-directory))
17259 inst-alist (nth 4 arch-entry)
17260 lib-alist (nth 5 arch-entry)
17261 rule (vhdl-aget rule-alist arch-file-name)
17262 target-list (nth 0 rule)
17263 depend-list (nth 1 rule))
17264 (setq tmp-key (vhdl-replace-string
17265 arch-regexp
17266 (funcall adjust-case
17267 (concat arch-key " " ent-key " "
17268 work-library))))
17269 (setq unit-list
17270 (cons (cons ent-arch-key tmp-key) unit-list))
17271 (push ent-arch-key second-list)
17272 ;; rule target for this architecture
17273 (push ent-arch-key target-list)
17274 ;; rule dependency for corresponding entity
17275 (push ent-key depend-list)
17276 ;; rule dependencies for contained component instantiations
17277 (while inst-alist
17278 (setq inst-entry (car inst-alist))
17279 (when (or (null (nth 8 inst-entry))
17280 (equal (downcase (nth 8 inst-entry)) work-library))
17281 (setq inst-ent-key (or (nth 7 inst-entry)
17282 (nth 5 inst-entry)))
17283 (setq depend-list (cons inst-ent-key depend-list)
17284 subcomp-list (cons inst-ent-key subcomp-list)))
17285 (setq inst-alist (cdr inst-alist)))
17286 ;; rule dependencies for all used packages
17287 (setq pack-list (vhdl-get-packages lib-alist work-library))
17288 (setq depend-list (append depend-list pack-list))
17289 (setq all-pack-list (append all-pack-list pack-list))
17290 ;; add rule
17291 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17292 (setq arch-alist (cdr arch-alist)))
17293 (push (list ent-key second-list (append subcomp-list all-pack-list))
17294 prim-list))
17295 (setq ent-alist (cdr ent-alist)))
17296 (setq ent-alist tmp-list)
17297 ;; rules for all configurations
17298 (setq tmp-list conf-alist)
17299 (while conf-alist
17300 (setq conf-entry (car conf-alist)
17301 conf-key (nth 0 conf-entry)
17302 conf-file-name (if vhdl-compile-absolute-path
17303 (nth 2 conf-entry)
17304 (file-relative-name (nth 2 conf-entry)
17305 compile-directory))
17306 ent-key (nth 4 conf-entry)
17307 arch-key (nth 5 conf-entry)
17308 inst-alist (nth 6 conf-entry)
17309 lib-alist (nth 7 conf-entry)
17310 rule (vhdl-aget rule-alist conf-file-name)
17311 target-list (nth 0 rule)
17312 depend-list (nth 1 rule)
17313 subcomp-list (list ent-key))
17314 (setq tmp-key (vhdl-replace-string
17315 conf-regexp
17316 (funcall adjust-case
17317 (concat conf-key " " work-library))))
17318 (push (cons conf-key tmp-key) unit-list)
17319 ;; rule target for this configuration
17320 (push conf-key target-list)
17321 ;; rule dependency for corresponding entity and architecture
17322 (setq depend-list
17323 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17324 ;; rule dependencies for used packages
17325 (setq pack-list (vhdl-get-packages lib-alist work-library))
17326 (setq depend-list (append depend-list pack-list))
17327 ;; rule dependencies for contained component configurations
17328 (while inst-alist
17329 (setq inst-entry (car inst-alist))
17330 (setq inst-ent-key (nth 2 inst-entry)
17331 inst-conf-key (nth 4 inst-entry))
17332 (when (equal (downcase (nth 5 inst-entry)) work-library)
17333 (when inst-ent-key
17334 (setq depend-list (cons inst-ent-key depend-list)
17335 subcomp-list (cons inst-ent-key subcomp-list)))
17336 (when inst-conf-key
17337 (setq depend-list (cons inst-conf-key depend-list)
17338 subcomp-list (cons inst-conf-key subcomp-list))))
17339 (setq inst-alist (cdr inst-alist)))
17340 ;; add rule
17341 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17342 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17343 (setq conf-alist (cdr conf-alist)))
17344 (setq conf-alist tmp-list)
17345 ;; rules for all packages
17346 (setq tmp-list pack-alist)
17347 (while pack-alist
17348 (setq pack-entry (car pack-alist)
17349 pack-key (nth 0 pack-entry)
17350 pack-body-key nil)
17351 (when (nth 2 pack-entry)
17352 (setq pack-file-name (if vhdl-compile-absolute-path
17353 (nth 2 pack-entry)
17354 (file-relative-name (nth 2 pack-entry)
17355 compile-directory))
17356 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17357 rule (vhdl-aget rule-alist pack-file-name)
17358 target-list (nth 0 rule) depend-list (nth 1 rule))
17359 (setq tmp-key (vhdl-replace-string
17360 pack-regexp
17361 (funcall adjust-case
17362 (concat pack-key " " work-library))))
17363 (push (cons pack-key tmp-key) unit-list)
17364 ;; rule target for this package
17365 (push pack-key target-list)
17366 ;; rule dependencies for all used packages
17367 (setq pack-list (vhdl-get-packages lib-alist work-library))
17368 (setq depend-list (append depend-list pack-list))
17369 (setq all-pack-list pack-list)
17370 ;; add rule
17371 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17372 ;; rules for this package's body
17373 (when (nth 7 pack-entry)
17374 (setq pack-body-key (concat pack-key "-body")
17375 pack-body-file-name (if vhdl-compile-absolute-path
17376 (nth 7 pack-entry)
17377 (file-relative-name (nth 7 pack-entry)
17378 compile-directory))
17379 rule (vhdl-aget rule-alist pack-body-file-name)
17380 target-list (nth 0 rule)
17381 depend-list (nth 1 rule))
17382 (setq tmp-key (vhdl-replace-string
17383 pack-body-regexp
17384 (funcall adjust-case
17385 (concat pack-key " " work-library))))
17386 (setq unit-list
17387 (cons (cons pack-body-key tmp-key) unit-list))
17388 ;; rule target for this package's body
17389 (push pack-body-key target-list)
17390 ;; rule dependency for corresponding package declaration
17391 (push pack-key depend-list)
17392 ;; rule dependencies for all used packages
17393 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17394 (setq depend-list (append depend-list pack-list))
17395 (setq all-pack-list (append all-pack-list pack-list))
17396 ;; add rule
17397 (vhdl-aput 'rule-alist pack-body-file-name
17398 (list target-list depend-list)))
17399 (setq prim-list
17400 (cons (list pack-key (when pack-body-key (list pack-body-key))
17401 all-pack-list)
17402 prim-list)))
17403 (setq pack-alist (cdr pack-alist)))
17404 (setq pack-alist tmp-list)
17405 ;; generate Makefile
17406 (let* ((project (vhdl-aget vhdl-project-alist project))
17407 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17408 (compiler-id (nth 9 compiler))
17409 (library-directory
17410 (vhdl-resolve-env-variable
17411 (vhdl-replace-string
17412 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17413 compiler-id)))
17414 (makefile-path-name (expand-file-name
17415 makefile-name compile-directory))
17416 (orig-buffer (current-buffer))
17417 cell second-list subcomp-list options unit-key unit-name)
17418 ;; sort lists
17419 (setq unit-list (vhdl-sort-alist unit-list))
17420 (setq prim-list (vhdl-sort-alist prim-list))
17421 (setq tmp-list rule-alist)
17422 (while tmp-list ; pre-sort rule targets
17423 (setq cell (cdar tmp-list))
17424 (setcar cell (sort (car cell) 'string<))
17425 (setq tmp-list (cdr tmp-list)))
17426 (setq rule-alist ; sort by first rule target
17427 (sort rule-alist
17428 (function (lambda (a b)
17429 (string< (car (cadr a)) (car (cadr b)))))))
17430 ;; open and clear Makefile
17431 (set-buffer (find-file-noselect makefile-path-name t t))
17432 (erase-buffer)
17433 (insert "# -*- Makefile -*-\n"
17434 "### " (file-name-nondirectory makefile-name)
17435 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17436 "\n")
17437 (if project
17438 (insert "\n# Project : " (nth 0 project))
17439 (insert "\n# Directory : \"" directory "\""))
17440 (insert "\n# Platform : " vhdl-compiler
17441 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17442 (user-login-name) "\n")
17443 ;; insert compile and option variable settings
17444 (insert "\n\n# Define compilation command and options\n"
17445 "\nCOMPILE = " (nth 0 compiler)
17446 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17447 (if (equal vhdl-compile-post-command "") ""
17448 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17449 "\n")
17450 ;; insert library paths
17451 (setq library-directory
17452 (directory-file-name
17453 (if (file-name-absolute-p library-directory)
17454 library-directory
17455 (file-relative-name
17456 (expand-file-name library-directory directory)
17457 compile-directory))))
17458 (insert "\n\n# Define library paths\n"
17459 "\nLIBRARY-" work-library " = " library-directory "\n")
17460 (unless mapping-exist
17461 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17462 ")/make" "\n"))
17463 ;; insert variable definitions for all library unit files
17464 (insert "\n\n# Define library unit files\n")
17465 (setq tmp-list unit-list)
17466 (while unit-list
17467 (insert "\nUNIT-" work-library "-" (caar unit-list)
17468 " = \\\n\t$(LIBRARY-" work-library
17469 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17470 (setq unit-list (cdr unit-list)))
17471 ;; insert variable definition for list of all library unit files
17472 (insert "\n\n\n# Define list of all library unit files\n"
17473 "\nALL_UNITS =")
17474 (setq unit-list tmp-list)
17475 (while unit-list
17476 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17477 (setq unit-list (cdr unit-list)))
17478 (insert "\n")
17479 (setq unit-list tmp-list)
17480 ;; insert `make all' rule
17481 (insert "\n\n\n# Rule for compiling entire design\n"
17482 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17483 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17484 " \\\n\t\t$(ALL_UNITS)\n")
17485 ;; insert `make clean' rule
17486 (insert "\n\n# Rule for cleaning entire design\n"
17487 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17488 "\n\t-rm -f $(ALL_UNITS)\n")
17489 ;; insert `make library' rule
17490 (insert "\n\n# Rule for creating library directory\n"
17491 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17492 " \\\n\t\t$(LIBRARY-" work-library ")"
17493 (if mapping-exist ""
17494 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17495 "\n"
17496 "\n$(LIBRARY-" work-library ") :"
17497 "\n\t"
17498 (vhdl-replace-string
17499 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17500 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17501 "\n")
17502 (unless mapping-exist
17503 (insert "\n$(LIBRARY-" work-library "-make) :"
17504 "\n\t"
17505 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17506 ;; insert '.PHONY' declaration
17507 (insert "\n\n.PHONY : "
17508 (nth 0 vhdl-makefile-default-targets) " "
17509 (nth 1 vhdl-makefile-default-targets) " "
17510 (nth 2 vhdl-makefile-default-targets) "\n")
17511 ;; insert rule for each library unit
17512 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17513 (while prim-list
17514 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17515 (setq subcomp-list
17516 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17517 (setq unit-key (caar prim-list)
17518 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17519 (nth 0 (vhdl-aget conf-alist unit-key))
17520 (nth 0 (vhdl-aget pack-alist unit-key))))
17521 (insert "\n" unit-key)
17522 (unless (equal unit-key unit-name)
17523 (insert " \\\n" unit-name))
17524 (insert " :"
17525 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17526 (while subcomp-list
17527 (when (and (assoc (car subcomp-list) unit-list)
17528 (not (equal unit-key (car subcomp-list))))
17529 (insert " \\\n\t\t" (car subcomp-list)))
17530 (setq subcomp-list (cdr subcomp-list)))
17531 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17532 (while second-list
17533 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17534 (setq second-list (cdr second-list)))
17535 (insert "\n")
17536 (setq prim-list (cdr prim-list)))
17537 ;; insert rule for each library unit file
17538 (insert "\n\n# Rules for compiling single library unit files\n")
17539 (while rule-alist
17540 (setq rule (car rule-alist))
17541 ;; get compiler options for this file
17542 (setq options
17543 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17544 ;; insert rule if file is supposed to be compiled
17545 (setq target-list (nth 1 rule)
17546 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17547 ;; insert targets
17548 (setq tmp-list target-list)
17549 (while target-list
17550 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17551 (if (cdr target-list) " \\" " :"))
17552 (setq target-list (cdr target-list)))
17553 (setq target-list tmp-list)
17554 ;; insert file name as first dependency
17555 (insert " \\\n\t\t" (nth 0 rule))
17556 ;; insert dependencies (except if also target or unit does not exist)
17557 (while depend-list
17558 (when (and (not (member (car depend-list) target-list))
17559 (assoc (car depend-list) unit-list))
17560 (insert " \\\n\t\t"
17561 "$(UNIT-" work-library "-" (car depend-list) ")"))
17562 (setq depend-list (cdr depend-list)))
17563 ;; insert compile command
17564 (if options
17565 (insert "\n\t$(COMPILE) "
17566 (if (eq options 'default) "$(OPTIONS)" options) " "
17567 (nth 0 rule)
17568 (if (equal vhdl-compile-post-command "") ""
17569 " $(POST-COMPILE)") "\n")
17570 (insert "\n"))
17571 (unless (and options mapping-exist)
17572 (setq tmp-list target-list)
17573 (while target-list
17574 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17575 (setq target-list (cdr target-list)))
17576 (setq target-list tmp-list))
17577 (setq rule-alist (cdr rule-alist)))
17578
17579 (insert "\n\n### " makefile-name " ends here\n")
17580 ;; run Makefile generation hook
17581 (run-hooks 'vhdl-makefile-generation-hook)
17582 (message "Generating makefile \"%s\"...done" makefile-name)
17583 ;; save and close file
17584 (if (file-writable-p makefile-path-name)
17585 (progn (save-buffer)
17586 (kill-buffer (current-buffer))
17587 (set-buffer orig-buffer)
17588 (when (fboundp 'add-to-history)
17589 (add-to-history 'file-name-history makefile-path-name)))
17590 (vhdl-warning-when-idle
17591 (format "File not writable: \"%s\""
17592 (abbreviate-file-name makefile-path-name)))
17593 (switch-to-buffer (current-buffer))))))
17594
17595
17596 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17597 ;;; Bug reports
17598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17599 ;; (using `reporter.el')
17600
17601 (defconst vhdl-mode-help-address
17602 "Reto Zimmermann <reto@gnu.org>"
17603 "Address for VHDL Mode bug reports.")
17604
17605 (defun vhdl-submit-bug-report ()
17606 "Submit via mail a bug report on VHDL Mode."
17607 (interactive)
17608 ;; load in reporter
17609 (and
17610 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17611 (let ((reporter-prompt-for-summary-p t))
17612 (reporter-submit-bug-report
17613 vhdl-mode-help-address
17614 (concat "VHDL Mode " vhdl-version)
17615 (list
17616 ;; report all important user options
17617 'vhdl-offsets-alist
17618 'vhdl-comment-only-line-offset
17619 'tab-width
17620 'vhdl-electric-mode
17621 'vhdl-stutter-mode
17622 'vhdl-indent-tabs-mode
17623 'vhdl-project-alist
17624 'vhdl-project
17625 'vhdl-project-file-name
17626 'vhdl-project-auto-load
17627 'vhdl-project-sort
17628 'vhdl-compiler-alist
17629 'vhdl-compiler
17630 'vhdl-compile-use-local-error-regexp
17631 'vhdl-makefile-default-targets
17632 'vhdl-makefile-generation-hook
17633 'vhdl-default-library
17634 'vhdl-standard
17635 'vhdl-basic-offset
17636 'vhdl-upper-case-keywords
17637 'vhdl-upper-case-types
17638 'vhdl-upper-case-attributes
17639 'vhdl-upper-case-enum-values
17640 'vhdl-upper-case-constants
17641 'vhdl-use-direct-instantiation
17642 'vhdl-array-index-record-field-in-sensitivity-list
17643 'vhdl-compose-configuration-name
17644 'vhdl-entity-file-name
17645 'vhdl-architecture-file-name
17646 'vhdl-configuration-file-name
17647 'vhdl-package-file-name
17648 'vhdl-file-name-case
17649 'vhdl-electric-keywords
17650 'vhdl-optional-labels
17651 'vhdl-insert-empty-lines
17652 'vhdl-argument-list-indent
17653 'vhdl-association-list-with-formals
17654 'vhdl-conditions-in-parenthesis
17655 'vhdl-sensitivity-list-all
17656 'vhdl-zero-string
17657 'vhdl-one-string
17658 'vhdl-file-header
17659 'vhdl-file-footer
17660 'vhdl-company-name
17661 'vhdl-copyright-string
17662 'vhdl-platform-spec
17663 'vhdl-date-format
17664 'vhdl-modify-date-prefix-string
17665 'vhdl-modify-date-on-saving
17666 'vhdl-reset-kind
17667 'vhdl-reset-active-high
17668 'vhdl-clock-rising-edge
17669 'vhdl-clock-edge-condition
17670 'vhdl-clock-name
17671 'vhdl-reset-name
17672 'vhdl-model-alist
17673 'vhdl-include-port-comments
17674 'vhdl-include-direction-comments
17675 'vhdl-include-type-comments
17676 'vhdl-include-group-comments
17677 'vhdl-actual-generic-name
17678 'vhdl-actual-port-name
17679 'vhdl-instance-name
17680 'vhdl-testbench-entity-name
17681 'vhdl-testbench-architecture-name
17682 'vhdl-testbench-configuration-name
17683 'vhdl-testbench-dut-name
17684 'vhdl-testbench-include-header
17685 'vhdl-testbench-declarations
17686 'vhdl-testbench-statements
17687 'vhdl-testbench-initialize-signals
17688 'vhdl-testbench-include-library
17689 'vhdl-testbench-include-configuration
17690 'vhdl-testbench-create-files
17691 'vhdl-testbench-entity-file-name
17692 'vhdl-testbench-architecture-file-name
17693 'vhdl-compose-create-files
17694 'vhdl-compose-configuration-create-file
17695 'vhdl-compose-configuration-hierarchical
17696 'vhdl-compose-configuration-use-subconfiguration
17697 'vhdl-compose-include-header
17698 'vhdl-compose-architecture-name
17699 'vhdl-components-package-name
17700 'vhdl-use-components-package
17701 'vhdl-self-insert-comments
17702 'vhdl-prompt-for-comments
17703 'vhdl-inline-comment-column
17704 'vhdl-end-comment-column
17705 'vhdl-auto-align
17706 'vhdl-align-groups
17707 'vhdl-align-group-separate
17708 'vhdl-align-same-indent
17709 'vhdl-highlight-keywords
17710 'vhdl-highlight-names
17711 'vhdl-highlight-special-words
17712 'vhdl-highlight-forbidden-words
17713 'vhdl-highlight-verilog-keywords
17714 'vhdl-highlight-translate-off
17715 'vhdl-highlight-case-sensitive
17716 'vhdl-special-syntax-alist
17717 'vhdl-forbidden-words
17718 'vhdl-forbidden-syntax
17719 'vhdl-directive-keywords
17720 'vhdl-speedbar-auto-open
17721 'vhdl-speedbar-display-mode
17722 'vhdl-speedbar-scan-limit
17723 'vhdl-speedbar-jump-to-unit
17724 'vhdl-speedbar-update-on-saving
17725 'vhdl-speedbar-save-cache
17726 'vhdl-speedbar-cache-file-name
17727 'vhdl-index-menu
17728 'vhdl-source-file-menu
17729 'vhdl-hideshow-menu
17730 'vhdl-hide-all-init
17731 'vhdl-print-two-column
17732 'vhdl-print-customize-faces
17733 'vhdl-intelligent-tab
17734 'vhdl-indent-syntax-based
17735 'vhdl-indent-comment-like-next-code-line
17736 'vhdl-word-completion-case-sensitive
17737 'vhdl-word-completion-in-minibuffer
17738 'vhdl-underscore-is-part-of-word
17739 'vhdl-mode-hook)
17740 (function
17741 (lambda ()
17742 (insert
17743 (if vhdl-special-indent-hook
17744 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17745 "vhdl-special-indent-hook is set to '"
17746 (format "%s" vhdl-special-indent-hook)
17747 ".\nPerhaps this is your problem?\n"
17748 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17749 "\n"))))
17750 nil
17751 "Hi Reto,"))))
17752
17753
17754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17755 ;;; Documentation
17756 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17757
17758 (defconst vhdl-doc-release-notes nil
17759 "\
17760 Release Notes for VHDL Mode 3.37
17761 ================================
17762
17763 - Added support for VHDL'08:
17764 - New keywords, types, functions, attributes, operators, packages
17765 - Context declaration
17766 - Block comments
17767 - Directives
17768 - `all' keyword in sensitivity list
17769
17770
17771 Release Notes for VHDL Mode 3.34
17772 ================================
17773
17774 - Added support for GNU Emacs 22/23/24:
17775 - Compilation error parsing fixed for new `compile.el' package.
17776
17777 - Port translation: Derive actual generic name from formal generic name.
17778
17779 - New user options:
17780 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17781
17782
17783 Release Notes for VHDL Mode 3.33
17784 ================================
17785
17786 New Features
17787 ------------
17788
17789 CONFIGURATION DECLARATION GENERATION:
17790 - Automatic generation of a configuration declaration for a design.
17791 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17792
17793
17794 Key Bindings
17795 ------------
17796
17797 For Emacs compliance the following key bindings have been changed:
17798
17799 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17800 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17801 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17802 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17803
17804
17805 User Options
17806 ------------
17807
17808 `vhdl-configuration-file-name': (new)
17809 Specify how the configuration file name is obtained.
17810 `vhdl-compose-configuration-name': (new)
17811 Specify how the configuration name is obtained.
17812 `vhdl-compose-configuration-create-file': (new)
17813 Specify whether a new file should be created for a configuration.
17814 `vhdl-compose-configuration-hierarchical': (new)
17815 Specify whether hierarchical configurations should be created.
17816 `vhdl-compose-configuration-use-subconfiguration': (new)
17817 Specify whether subconfigurations should be used inside configurations.
17818 `vhdl-makefile-default-targets': (new)
17819 Customize names of Makefile default targets.
17820 `vhdl-indent-comment-like-next-code-line': (new)
17821 Specify whether comment lines are indented like following code line.
17822 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17823 Specify whether to include array indices / record fields in sensitivity list.
17824 ")
17825
17826
17827 (defconst vhdl-doc-keywords nil
17828 "\
17829 Reserved words in VHDL
17830 ----------------------
17831
17832 VHDL'08 (IEEE Std 1076-2008):
17833 `vhdl-08-keywords' : keywords
17834 `vhdl-08-types' : standardized types
17835 `vhdl-08-attributes' : standardized attributes
17836 `vhdl-08-functions' : standardized functions
17837 `vhdl-08-packages' : standardized packages and libraries
17838
17839 VHDL'93/02 (IEEE Std 1076-1993/2002):
17840 `vhdl-02-keywords' : keywords
17841 `vhdl-02-types' : standardized types
17842 `vhdl-02-attributes' : standardized attributes
17843 `vhdl-02-enum-values' : standardized enumeration values
17844 `vhdl-02-functions' : standardized functions
17845 `vhdl-02-packages' : standardized packages and libraries
17846
17847 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17848 `vhdl-ams-keywords' : keywords
17849 `vhdl-ams-types' : standardized types
17850 `vhdl-ams-attributes' : standardized attributes
17851 `vhdl-ams-enum-values' : standardized enumeration values
17852 `vhdl-ams-constants' : standardized constants
17853 `vhdl-ams-functions' : standardized functions
17854
17855 Math Packages (IEEE Std 1076.2):
17856 `vhdl-math-types' : standardized types
17857 `vhdl-math-constants' : standardized constants
17858 `vhdl-math-functions' : standardized functions
17859 `vhdl-math-packages' : standardized packages
17860
17861 Forbidden words:
17862 `vhdl-verilog-keywords' : Verilog reserved words
17863
17864 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17865
17866
17867 (defconst vhdl-doc-coding-style nil
17868 "\
17869 For VHDL coding style and naming convention guidelines, see the following
17870 references:
17871
17872 [1] Ben Cohen.
17873 \"VHDL Coding Styles and Methodologies\".
17874 Kluwer Academic Publishers, 1999.
17875 http://members.aol.com/vhdlcohen/vhdl/
17876
17877 [2] Michael Keating and Pierre Bricaud.
17878 \"Reuse Methodology Manual, Second Edition\".
17879 Kluwer Academic Publishers, 1999.
17880 http://www.openmore.com/openmore/rmm2.html
17881
17882 [3] European Space Agency.
17883 \"VHDL Modelling Guidelines\".
17884 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17885
17886 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17887 to visually support naming conventions.")
17888
17889
17890 (defun vhdl-version ()
17891 "Echo the current version of VHDL Mode in the minibuffer."
17892 (interactive)
17893 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17894 (vhdl-keep-region-active))
17895
17896 (defun vhdl-doc-variable (variable)
17897 "Display VARIABLE's documentation in *Help* buffer."
17898 (interactive)
17899 (unless (featurep 'xemacs)
17900 (help-setup-xref (list #'vhdl-doc-variable variable)
17901 (called-interactively-p 'interactive)))
17902 (with-output-to-temp-buffer
17903 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17904 (princ (documentation-property variable 'variable-documentation))
17905 (with-current-buffer standard-output
17906 (help-mode))
17907 (help-print-return-message)))
17908
17909 (defun vhdl-doc-mode ()
17910 "Display VHDL Mode documentation in *Help* buffer."
17911 (interactive)
17912 (unless (featurep 'xemacs)
17913 (help-setup-xref (list #'vhdl-doc-mode)
17914 (called-interactively-p 'interactive)))
17915 (with-output-to-temp-buffer
17916 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17917 (princ mode-name)
17918 (princ " mode:\n")
17919 (princ (documentation 'vhdl-mode))
17920 (with-current-buffer standard-output
17921 (help-mode))
17922 (help-print-return-message)))
17923
17924
17925 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17926
17927 (provide 'vhdl-mode)
17928
17929 ;;; vhdl-mode.el ends here