]> code.delx.au - gnu-emacs/blob - lisp/progmodes/vhdl-mode.el
Merge branch 'emacs-25-merge'
[gnu-emacs] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992-2015 Free Software Foundation, Inc.
4
5 ;; Authors: Reto Zimmermann <reto@gnu.org>
6 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
8 ;; Keywords: languages vhdl
9 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
10
11 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
13 ;; filed in the Emacs bug reporting system against this file, a copy
14 ;; of the bug report be sent to the maintainer's email address.
15
16 (defconst vhdl-version "3.37.1"
17 "VHDL Mode version number.")
18
19 (defconst vhdl-time-stamp "2015-01-15"
20 "VHDL Mode time stamp for last update.")
21
22 ;; This file is part of GNU Emacs.
23
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
28
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
33
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
36
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Commentary:
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
43
44 ;; - Syntax highlighting
45 ;; - Indentation
46 ;; - Template insertion (electrification)
47 ;; - Insertion of file headers
48 ;; - Insertion of user-specified models
49 ;; - Port translation / testbench generation
50 ;; - Structural composition
51 ;; - Configuration generation
52 ;; - Sensitivity list updating
53 ;; - File browser
54 ;; - Design hierarchy browser
55 ;; - Source file compilation (syntax analysis)
56 ;; - Makefile generation
57 ;; - Code hiding
58 ;; - Word/keyword completion
59 ;; - Block commenting
60 ;; - Code fixing/alignment/beautification
61 ;; - PostScript printing
62 ;; - VHDL'87/'93/'02/'08 and VHDL-AMS supported
63 ;; - Comprehensive menu
64 ;; - Fully customizable
65 ;; - Works under GNU Emacs (recommended) and XEmacs
66
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Documentation
69
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
71
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; Emacs Versions
74
75 ;; this updated version was only tested on: GNU Emacs 24.1
76
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; Installation
79
80 ;; Prerequisites: GNU Emacs 20/21/22/23/24, XEmacs 20/21.
81
82 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
83 ;; or into an arbitrary directory that is added to the load path by the
84 ;; following line in your Emacs start-up file `.emacs':
85
86 ;; (push (expand-file-name "<directory-name>") load-path)
87
88 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
89 ;; directory. Otherwise, byte-compile the source file:
90 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
91 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
92
93 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
94 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
95 ;; (not required in Emacs 20 and higher):
96
97 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
98 ;; (push '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist)
99
100 ;; More detailed installation instructions are included in the official
101 ;; VHDL Mode distribution.
102
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 ;; Acknowledgments
105
106 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
107 ;; and Steve Grout.
108
109 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
110 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
111
112 ;; Many thanks to all the users who sent me bug reports and enhancement
113 ;; requests.
114 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
115 ;; enhancement suggestions and the fruitful discussions.
116 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
117 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
118
119 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
120 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
121 ;; giving me the opportunity to develop this code.
122 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
123 ;; of the Swiss Government.
124
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126
127 ;;; Code:
128
129 ;; Emacs 21+ handling
130 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
131 "Non-nil if GNU Emacs 21, 22, ... is used.")
132 ;; Emacs 22+ handling
133 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
134 "Non-nil if GNU Emacs 22, ... is used.")
135
136 (defvar compilation-file-regexp-alist)
137 (defvar conf-alist)
138 (defvar conf-entry)
139 (defvar conf-key)
140 (defvar ent-alist)
141 (defvar itimer-version)
142 (defvar lazy-lock-defer-contextually)
143 (defvar lazy-lock-defer-on-scrolling)
144 (defvar lazy-lock-defer-on-the-fly)
145 (defvar speedbar-attached-frame)
146
147
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 ;;; Variables
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151
152 ;; help function for user options
153 (defun vhdl-custom-set (variable value &rest functions)
154 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
155 (if (fboundp 'custom-set-default)
156 (custom-set-default variable value)
157 (set-default variable value))
158 (while functions
159 (when (fboundp (car functions)) (funcall (car functions)))
160 (setq functions (cdr functions))))
161
162 (defun vhdl-widget-directory-validate (widget)
163 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
164 '/' or is empty)."
165 (let ((val (widget-value widget)))
166 (unless (string-match "^\\(\\|.*/\\)$" val)
167 (widget-put widget :error "Invalid directory entry: must end with `/'")
168 widget)))
169
170 ;; help string for user options
171 (defconst vhdl-name-doc-string "
172
173 FROM REGEXP is a regular expression matching the original name:
174 \".*\" matches the entire string
175 \"\\(...\\)\" matches a substring
176 TO STRING specifies the string to be inserted as new name:
177 \"\\&\" means substitute entire matched text
178 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
179 Examples:
180 \".*\" \"\\&\" inserts original string
181 \".*\" \"\\&_i\" attaches \"_i\" to original string
182 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
183 \".*\" \"foo\" inserts constant string \"foo\"
184 \".*\" \"\" inserts empty string")
185
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; User variables (customization options)
188
189 (defgroup vhdl nil
190 "Customizations for VHDL Mode."
191 :prefix "vhdl-"
192 :group 'languages
193 ; :version "21.2" ; comment out for XEmacs
194 )
195
196 (defgroup vhdl-mode nil
197 "Customizations for modes."
198 :group 'vhdl)
199
200 (defcustom vhdl-indent-tabs-mode nil
201 "Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
205
206
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
210
211 (defcustom vhdl-compiler-alist
212 '(
213 ;; 60: docal <= false;
214 ;; ^^^^^
215 ;; [Error] Assignment error: variable is illegal target of signal assignment
216 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
217 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
218 ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("^Compiling file \\(.+\\)" 1)
219 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
220 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
221 ;; Aldec
222 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
223 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
224 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
225 ("^.* ERROR [^:]+: \".*\" \"\\([^ \t\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
226 nil)
227 ;; Cadence Leapfrog: cv -file test.vhd
228 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
229 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
230 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
231 ("^duluth: \\*E,[0-9]+ (\\([^ \t\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
232 ("\\1/entity" "\\2/\\1" "\\1/configuration"
233 "\\1/package" "\\1/body" downcase))
234 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
235 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
236 ;; (PLL_400X_TOP) is not declared [10.3].
237 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
238 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
239 ("^ncvhdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
240 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
241 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
242 ;; ghdl vhdl
243 ;; ghdl -a bad_counter.vhdl
244 ;; bad_counter.vhdl:13:14: operator "=" is overloaded
245 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
246 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
247 ("^ghdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
248 ("\\1/entity" "\\2/\\1" "\\1/configuration"
249 "\\1/package" "\\1/body" downcase))
250 ;; IBM Compiler
251 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
252 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
253 nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
254 ("^[0-9]+ COACHDL.*: File: \\([^ \t\n]+\\), *line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
255 nil)
256 ;; Ikos Voyager: analyze test.vhd
257 ;; analyze test.vhd
258 ;; E L4/C5: this library unit is inaccessible
259 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
260 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
261 ("^E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
262 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
263 nil)
264 ;; ModelSim, Model Technology: vcom test.vhd
265 ;; ERROR: test.vhd(14): Unknown identifier: positiv
266 ;; WARNING[2]: test.vhd(85): Possible infinite loop
267 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
268 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
269 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
270 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
271 ("^\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\\[[0-9]+]\\)? \\([^ \t\n]+\\)(\\([0-9]+\\)):" 3 4 nil) ("" 0)
272 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
273 "\\1/_primary.dat" "\\1/body.dat" downcase))
274 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
275 ;; test.vhd:34: error message
276 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
277 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
278 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
279 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
280 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
281 ;; Quartus compiler
282 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
283 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
284 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
285 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
286 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
287 ("Quartus" "make" "-work \\1" "make" "-f \\1"
288 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
289 ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
290 nil)
291 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
292 ;; ERROR: test.vhd(24): near "dnd": expecting: END
293 ;; WARNING[4]: test.vhd(30): A space is required between ...
294 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
295 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
296 ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
297 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
298 "\\1/_primary.dat" "\\1/body.dat" downcase))
299 ;; Savant: scram -publish-cc test.vhd
300 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
301 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
303 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
304 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
305 "\\1_config.vhdl" "\\1_package.vhdl"
306 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
307 ;; Simili: vhdlp -work test.vhd
308 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
309 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
310 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
311 ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
312 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
313 "\\1/prim.var" "\\1/_body.var" downcase))
314 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
315 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
316 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
317 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
318 ("^ *ERROR\\[[0-9]+]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
319 nil)
320 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
321 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
322 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
323 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
324 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
325 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
326 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
327 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
328 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
329 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
330 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
331 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
332 ;; Synplify:
333 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
334 ("Synplify" "n/a" "n/a" "make" "-f \\1"
335 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
336 ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
337 nil)
338 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
339 ;; Compiling "test.vhd" line 1...
340 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
341 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
342 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
343 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
344 ("^ *Compiling \"\\(.+\\)\" " 1)
345 nil)
346 ;; VeriBest: vc vhdl test.vhd
347 ;; (no file name printed out!)
348 ;; 32: Z <= A and BitA ;
349 ;; ^^^^
350 ;; [Error] Name BITA is unknown
351 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
352 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
353 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
354 nil)
355 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
356 ;; Compiling "test.vhd" line 1...
357 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
358 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
359 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
360 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
361 ("^ *Compiling \"\\(.+\\)\" " 1)
362 nil)
363 ;; Xilinx XST:
364 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
365 ("Xilinx XST" "xflow" "" "make" "-f \\1"
366 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
367 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\\." 1 2 nil) ("" 0)
368 nil)
369 )
370 "List of available VHDL compilers and their properties.
371 Each list entry specifies the following items for a compiler:
372 Compiler:
373 Compiler name : name used in option `vhdl-compiler' to choose compiler
374 Compile command : command used for source file compilation
375 Compile options : compile options (\"\\1\" inserts library name)
376 Make command : command used for compilation using a Makefile
377 Make options : make options (\"\\1\" inserts Makefile name)
378 Generate Makefile: use built-in function or command to generate a Makefile
379 (\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
380 Library command : command to create library directory (\"\\1\" inserts
381 library directory, \"\\2\" inserts library name)
382 Compile directory: where compilation is run and the Makefile is placed
383 Library directory: directory of default library
384 Makefile name : name of Makefile (default is \"Makefile\")
385 ID string : compiler identification string (see `vhdl-project-alist')
386 Error message:
387 Regexp : regular expression to match error messages (*)
388 File subexp index: index of subexpression that matches the file name
389 Line subexp index: index of subexpression that matches the line number
390 Column subexp idx: index of subexpression that matches the column number
391 File message:
392 Regexp : regular expression to match a file name message
393 File subexp index: index of subexpression that matches the file name
394 Unit-to-file name mapping: mapping of library unit names to names of files
395 generated by the compiler (used for Makefile generation)
396 To string : string a name is mapped to (\"\\1\" inserts the unit name,
397 \"\\2\" inserts the entity name for architectures,
398 \"\\3\" inserts the library name)
399 Case adjustment : adjust case of inserted unit names
400
401 \(*) The regular expression must match the error message starting from the
402 beginning of the line (but not necessarily to the end of the line).
403
404 Compile options allows insertion of the library name (see `vhdl-project-alist')
405 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
406
407 For Makefile generation, the built-in function can be used (requires
408 specification of the unit-to-file name mapping). Alternatively, an
409 external command can be specified. Work directory allows specification of
410 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
411 used for Makefile generation). To use another library name than \"work\",
412 customize `vhdl-project-alist'. The library command is inserted in Makefiles
413 to automatically create the library directory if not existent.
414
415 Compile options, compile directory, library directory, and Makefile name are
416 overwritten by the project settings if a project is defined (see
417 `vhdl-project-alist'). Directory paths are relative to the source file
418 directory.
419
420 Some compilers do not include the file name in the error message, but print
421 out a file name message in advance. In this case, set \"File Subexp Index\"
422 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
423 If no file name at all is printed out, set both \"File Message\" entries to 0
424 \(a default file name message will be printed out instead, does not work in
425 XEmacs).
426
427 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
428 assigning its name to option `vhdl-compiler'.
429
430 Please send any missing or erroneous compiler properties to the maintainer for
431 updating.
432
433 NOTE: Activate new error and file message regexps and reflect the new setting
434 in the choice list of option `vhdl-compiler' by restarting Emacs."
435 :type '(repeat
436 (list :tag "Compiler" :indent 2
437 (string :tag "Compiler name ")
438 (string :tag "Compile command ")
439 (string :tag "Compile options " "-work \\1")
440 (string :tag "Make command " "make")
441 (string :tag "Make options " "-f \\1")
442 (choice :tag "Generate Makefile "
443 (const :tag "Built-in function" nil)
444 (string :tag "Command" "vmake \\2 > \\1"))
445 (string :tag "Library command " "mkdir \\1")
446 (directory :tag "Compile directory "
447 :validate vhdl-widget-directory-validate "./")
448 (directory :tag "Library directory "
449 :validate vhdl-widget-directory-validate "work/")
450 (file :tag "Makefile name " "Makefile")
451 (string :tag "ID string ")
452 (list :tag "Error message" :indent 4
453 (regexp :tag "Regexp ")
454 (choice :tag "File subexp "
455 (integer :tag "Index")
456 (const :tag "No file name" nil))
457 (integer :tag "Line subexp index")
458 (choice :tag "Column subexp "
459 (integer :tag "Index")
460 (const :tag "No column number" nil)))
461 (list :tag "File message" :indent 4
462 (regexp :tag "Regexp ")
463 (integer :tag "File subexp index"))
464 (choice :tag "Unit-to-file name mapping"
465 :format "%t: %[Value Menu%] %v\n"
466 (const :tag "Not defined" nil)
467 (list :tag "To string" :indent 4
468 (string :tag "Entity " "\\1.vhd")
469 (string :tag "Architecture " "\\2_\\1.vhd")
470 (string :tag "Configuration " "\\1.vhd")
471 (string :tag "Package " "\\1.vhd")
472 (string :tag "Package Body " "\\1_body.vhd")
473 (choice :tag "Case adjustment "
474 (const :tag "None" identity)
475 (const :tag "Upcase" upcase)
476 (const :tag "Downcase" downcase))))))
477 :set (lambda (variable value)
478 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
479 :version "24.4"
480 :group 'vhdl-compile)
481
482 (defcustom vhdl-compiler "GHDL"
483 "Specifies the VHDL compiler to be used for syntax analysis.
484 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
485 :type (let ((alist vhdl-compiler-alist) list)
486 (while alist
487 (push (list 'const (caar alist)) list)
488 (setq alist (cdr alist)))
489 (append '(choice) (nreverse list)))
490 :group 'vhdl-compile)
491
492 (defcustom vhdl-compile-use-local-error-regexp nil
493 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
494 In this case, only error message regexps for VHDL compilers are active if
495 compilation is started from a VHDL buffer. Otherwise, the error message
496 regexps are appended to the predefined global regexps, and all regexps are
497 active all the time. Note that by doing that, the predefined global regexps
498 might result in erroneous parsing of error messages for some VHDL compilers.
499
500 NOTE: Activate the new setting by restarting Emacs."
501 :version "25.1" ; t -> nil
502 :type 'boolean
503 :group 'vhdl-compile)
504
505 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
506 "List of default target names in Makefiles.
507 Automatically generated Makefiles include three default targets to compile
508 the entire design, clean the entire design and to create the design library.
509 This option allows you to change the names of these targets to avoid conflicts
510 with other user Makefiles."
511 :type '(list (string :tag "Compile entire design")
512 (string :tag "Clean entire design ")
513 (string :tag "Create design library"))
514 :version "24.3"
515 :group 'vhdl-compile)
516
517 (defcustom vhdl-makefile-generation-hook nil
518 "Functions to run at the end of Makefile generation.
519 Allows you to insert user specific parts into a Makefile.
520
521 Example:
522 (lambda nil
523 (re-search-backward \"^# Rule for compiling entire design\")
524 (insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
525 :type 'hook
526 :group 'vhdl-compile)
527
528 (defcustom vhdl-default-library "work"
529 "Name of default library.
530 Is overwritten by project settings if a project is active."
531 :type 'string
532 :group 'vhdl-compile)
533
534
535 (defgroup vhdl-project nil
536 "Customizations for projects."
537 :group 'vhdl)
538
539 (defcustom vhdl-project-alist
540 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
541 "~/example1/" ("src/system/" "src/components/") ""
542 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
543 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
544 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
545 ("Example 2" "Individual source files, multiple compilers in different directories"
546 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
547 nil "\\1/" "work" "\\1/work/" "Makefile" "")
548 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
549 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
550 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
551 -------------------------------------------------------------------------------
552 -- This is a multi-line project description
553 -- that can be used as a project dependent part of the file header.
554 "))
555 "List of projects and their properties.
556 Name : name used in option `vhdl-project' to choose project
557 Title : title of project (single-line string)
558 Default directory: default project directory (absolute path)
559 Sources : a) source files : path + \"/\" + file name
560 b) directory : path + \"/\"
561 c) directory tree: \"-r \" + path + \"/\"
562 Exclude regexp : matches file/directory names to be excluded as sources
563 Compile options : project-specific options for each compiler
564 Compiler name : name of compiler for which these options are valid
565 Compile options: project-specific compiler options
566 (\"\\1\" inserts library name, \"\\2\" default options)
567 Make options: project-specific make options
568 (\"\\1\" inserts Makefile name, \"\\2\" default options)
569 Exceptions : file-specific exceptions
570 File name regexp: matches file names for which exceptions are valid
571 - Options : file-specific compiler options string
572 (\"\\1\" inserts library name, \"\\2\" default options,
573 \"\\3\" project-specific options)
574 - Do not compile: do not compile this file (in Makefile)
575 Compile directory: where compilation is run and the Makefile is placed
576 (\"\\1\" inserts compiler ID string)
577 Library name : name of library (default is \"work\")
578 Library directory: path to library (\"\\1\" inserts compiler ID string)
579 Makefile name : name of Makefile
580 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
581 Description : description of project (multi-line string)
582
583 Project title and description are used to insert into the file header (see
584 option `vhdl-file-header').
585
586 The default directory must have an absolute path (use `M-TAB' for completion).
587 All other paths can be absolute or relative to the default directory. All
588 paths must end with `/'.
589
590 The design units found in the sources (files and directories) are shown in the
591 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
592 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
593 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
594 specified, the default directory is taken as source directory. Otherwise,
595 the default directory is only taken as source directory if there is a sources
596 entry with the empty string or \"./\". Exclude regexp allows you to filter
597 out specific file and directory names from the list of sources (e.g. CVS
598 directories).
599
600 Files are compiled in the compile directory. Makefiles are also placed into
601 the compile directory. Library directory specifies which directory the
602 compiler compiles into (used to generate the Makefile).
603
604 Since different compile/library directories and Makefiles may exist for
605 different compilers within one project, these paths and names allow the
606 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
607 Compile options, compile directory, library directory, and Makefile name
608 overwrite the settings of the current compiler.
609
610 File-specific compiler options (highest priority) overwrite project-specific
611 options which overwrite default options (lowest priority). Lower priority
612 options can be inserted in higher priority options. This allows you to reuse
613 default options (e.g. \"-file\") in project- or file-specific options (e.g.
614 \"-93 -file\").
615
616 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
617 by restarting Emacs."
618 :type `(repeat
619 (list :tag "Project" :indent 2
620 (string :tag "Name ")
621 (string :tag "Title ")
622 (directory :tag "Default directory"
623 :validate vhdl-widget-directory-validate
624 ,(abbreviate-file-name default-directory))
625 (repeat :tag "Sources " :indent 4
626 (directory :format " %v" "./"))
627 (regexp :tag "Exclude regexp ")
628 (repeat
629 :tag "Compile options " :indent 4
630 (list :tag "Compiler" :indent 6
631 ,(let ((alist vhdl-compiler-alist) list)
632 (while alist
633 (push (list 'const (caar alist)) list)
634 (setq alist (cdr alist)))
635 (append '(choice :tag "Compiler name")
636 (nreverse list)))
637 (string :tag "Compile options" "\\2")
638 (string :tag "Make options " "\\2")
639 (repeat
640 :tag "Exceptions " :indent 8
641 (cons :format "%v"
642 (regexp :tag "File name regexp ")
643 (choice :format "%[Value Menu%] %v"
644 (string :tag "Options" "\\3")
645 (const :tag "Do not compile" nil))))))
646 (directory :tag "Compile directory"
647 :validate vhdl-widget-directory-validate "./")
648 (string :tag "Library name " "work")
649 (directory :tag "Library directory"
650 :validate vhdl-widget-directory-validate "work/")
651 (file :tag "Makefile name " "Makefile")
652 (string :tag "Description: (type `C-j' for newline)"
653 :format "%t\n%v\n")))
654 :set (lambda (variable value)
655 (vhdl-custom-set variable value
656 'vhdl-update-mode-menu
657 'vhdl-speedbar-refresh))
658 :group 'vhdl-project)
659
660 (defcustom vhdl-project nil
661 "Specifies the default for the current project.
662 Select a project name from the ones defined in option `vhdl-project-alist'.
663 Is used to determine the project title and description to be inserted in file
664 headers and the source files/directories to be scanned in the hierarchy
665 browser. The current project can also be changed temporarily in the menu."
666 :type (let ((alist vhdl-project-alist) list)
667 (while alist
668 (push (list 'const (caar alist)) list)
669 (setq alist (cdr alist)))
670 (append '(choice (const :tag "None" nil) (const :tag "--"))
671 (nreverse list)))
672 :group 'vhdl-project)
673
674 (defcustom vhdl-project-file-name '("\\1.prj")
675 "List of file names/paths for importing/exporting project setups.
676 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
677 replaced by the user name (allows you to have user-specific project setups).
678 The first entry is used as file name to import/export individual project
679 setups. All entries are used to automatically import project setups at
680 startup (see option `vhdl-project-auto-load'). Projects loaded from the
681 first entry are automatically made current. Hint: specify local project
682 setups in first entry, global setups in following entries; loading a local
683 project setup will make it current, while loading the global setups
684 is done without changing the current project.
685 Names can also have an absolute path (i.e. project setups can be stored
686 in global directories)."
687 :type '(repeat (string :tag "File name" "\\1.prj"))
688 :group 'vhdl-project)
689
690 (defcustom vhdl-project-auto-load '(startup)
691 "Automatically load project setups from files.
692 All project setup files that match the file names specified in option
693 `vhdl-project-file-name' are automatically loaded. The project of the
694 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
695 entry is activated.
696 A project setup file can be obtained by exporting a project (see menu).
697 At startup: project setup file is loaded at Emacs startup"
698 :type '(set (const :tag "At startup" startup))
699 :group 'vhdl-project)
700
701 (defcustom vhdl-project-sort t
702 "Non-nil means projects are displayed in alphabetical order."
703 :type 'boolean
704 :group 'vhdl-project)
705
706
707 (defgroup vhdl-style nil
708 "Customizations for coding styles."
709 :group 'vhdl
710 :group 'vhdl-template
711 :group 'vhdl-port
712 :group 'vhdl-compose)
713
714 (defcustom vhdl-standard '(93 nil)
715 "VHDL standards used.
716 Basic standard:
717 VHDL'87 : IEEE Std 1076-1987
718 VHDL'93/02 : IEEE Std 1076-1993/2002
719 VHDL'08 : IEEE Std 1076-2008
720 Additional standards:
721 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
722 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
723
724 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
725 \"Activate Options\"."
726 :type '(list (choice :tag "Basic standard"
727 (const :tag "VHDL'87" 87)
728 (const :tag "VHDL'93/02" 93)
729 (const :tag "VHDL'08" 08))
730 (set :tag "Additional standards" :indent 2
731 (const :tag "VHDL-AMS" ams)
732 (const :tag "Math packages" math)))
733 :set (lambda (variable value)
734 (vhdl-custom-set variable value
735 'vhdl-template-map-init
736 'vhdl-mode-abbrev-table-init
737 'vhdl-template-construct-alist-init
738 'vhdl-template-package-alist-init
739 'vhdl-update-mode-menu
740 'vhdl-words-init 'vhdl-font-lock-init))
741 :group 'vhdl-style)
742
743 (defcustom vhdl-basic-offset 2
744 "Amount of basic offset used for indentation.
745 This value is used by + and - symbols in `vhdl-offsets-alist'."
746 :type 'integer
747 :group 'vhdl-style)
748
749 (defcustom vhdl-upper-case-keywords nil
750 "Non-nil means convert keywords to upper case.
751 This is done when typed or expanded or by the fix case functions."
752 :type 'boolean
753 :set (lambda (variable value)
754 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
755 :group 'vhdl-style)
756
757 (defcustom vhdl-upper-case-types nil
758 "Non-nil means convert standardized types to upper case.
759 This is done when expanded or by the fix case functions."
760 :type 'boolean
761 :set (lambda (variable value)
762 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
763 :group 'vhdl-style)
764
765 (defcustom vhdl-upper-case-attributes nil
766 "Non-nil means convert standardized attributes to upper case.
767 This is done when expanded or by the fix case functions."
768 :type 'boolean
769 :set (lambda (variable value)
770 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
771 :group 'vhdl-style)
772
773 (defcustom vhdl-upper-case-enum-values nil
774 "Non-nil means convert standardized enumeration values to upper case.
775 This is done when expanded or by the fix case functions."
776 :type 'boolean
777 :set (lambda (variable value)
778 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
779 :group 'vhdl-style)
780
781 (defcustom vhdl-upper-case-constants t
782 "Non-nil means convert standardized constants to upper case.
783 This is done when expanded."
784 :type 'boolean
785 :set (lambda (variable value)
786 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
787 :group 'vhdl-style)
788
789 (defcustom vhdl-use-direct-instantiation 'standard
790 "Non-nil means use VHDL'93 direct component instantiation.
791 Never : never
792 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
793 Always : always"
794 :type '(choice (const :tag "Never" never)
795 (const :tag "Standard" standard)
796 (const :tag "Always" always))
797 :group 'vhdl-style)
798
799 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
800 "Non-nil means include array indices / record fields in sensitivity list.
801 If a signal read in a process is a record field or pointed to by an array
802 index, the record field or array index is included with the record name in
803 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
804 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
805 :type 'boolean
806 :version "24.3"
807 :group 'vhdl-style)
808
809 (defgroup vhdl-naming nil
810 "Customizations for naming conventions."
811 :group 'vhdl)
812
813 (defcustom vhdl-entity-file-name '(".*" . "\\&")
814 (concat
815 "Specifies how the entity file name is obtained.
816 The entity file name can be obtained by modifying the entity name (e.g.
817 attaching or stripping off a substring). The file extension is automatically
818 taken from the file name of the current buffer."
819 vhdl-name-doc-string)
820 :type '(cons (regexp :tag "From regexp")
821 (string :tag "To string "))
822 :group 'vhdl-naming
823 :group 'vhdl-compose)
824
825 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
826 (concat
827 "Specifies how the architecture file name is obtained.
828 The architecture file name can be obtained by modifying the entity
829 and/or architecture name (e.g. attaching or stripping off a substring). The
830 file extension is automatically taken from the file name of the current
831 buffer. The string that is matched against the regexp is the concatenation
832 of the entity and the architecture name separated by a space. This gives
833 access to both names (see default setting as example)."
834 vhdl-name-doc-string)
835 :type '(cons (regexp :tag "From regexp")
836 (string :tag "To string "))
837 :group 'vhdl-naming
838 :group 'vhdl-compose)
839
840 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
841 (concat
842 "Specifies how the configuration file name is obtained.
843 The configuration file name can be obtained by modifying the configuration
844 name (e.g. attaching or stripping off a substring). The file extension is
845 automatically taken from the file name of the current buffer."
846 vhdl-name-doc-string)
847 :type '(cons (regexp :tag "From regexp")
848 (string :tag "To string "))
849 :group 'vhdl-naming
850 :group 'vhdl-compose)
851
852 (defcustom vhdl-package-file-name '(".*" . "\\&")
853 (concat
854 "Specifies how the package file name is obtained.
855 The package file name can be obtained by modifying the package name (e.g.
856 attaching or stripping off a substring). The file extension is automatically
857 taken from the file name of the current buffer. Package files can be created
858 in a different directory by prepending a relative or absolute path to the
859 file name."
860 vhdl-name-doc-string)
861 :type '(cons (regexp :tag "From regexp")
862 (string :tag "To string "))
863 :group 'vhdl-naming
864 :group 'vhdl-compose)
865
866 (defcustom vhdl-file-name-case 'identity
867 "Specifies how to change case for obtaining file names.
868 When deriving a file name from a VHDL unit name, case can be changed as
869 follows:
870 As Is: case is not changed (taken as is)
871 Lower Case: whole name is changed to lower case
872 Upper Case: whole name is changed to upper case
873 Capitalize: first letter of each word in name is capitalized"
874 :type '(choice (const :tag "As Is" identity)
875 (const :tag "Lower Case" downcase)
876 (const :tag "Upper Case" upcase)
877 (const :tag "Capitalize" capitalize))
878 :group 'vhdl-naming
879 :group 'vhdl-compose)
880
881
882 (defgroup vhdl-template nil
883 "Customizations for electrification."
884 :group 'vhdl)
885
886 (defcustom vhdl-electric-keywords '(vhdl user)
887 "Type of keywords for which electrification is enabled.
888 VHDL keywords: invoke built-in templates
889 User keywords: invoke user models (see option `vhdl-model-alist')"
890 :type '(set (const :tag "VHDL keywords" vhdl)
891 (const :tag "User model keywords" user))
892 :set (lambda (variable value)
893 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
894 :group 'vhdl-template)
895
896 (defcustom vhdl-optional-labels 'process
897 "Constructs for which labels are to be queried.
898 Template generators prompt for optional labels for:
899 None : no constructs
900 Processes only: processes only (also procedurals in VHDL-AMS)
901 All constructs: all constructs with optional labels and keyword END"
902 :type '(choice (const :tag "None" none)
903 (const :tag "Processes only" process)
904 (const :tag "All constructs" all))
905 :group 'vhdl-template)
906
907 (defcustom vhdl-insert-empty-lines 'unit
908 "Specifies whether to insert empty lines in some templates.
909 This improves readability of code. Empty lines are inserted in:
910 None : no constructs
911 Design units only: entities, architectures, configurations, packages only
912 All constructs : also all constructs with BEGIN...END parts
913
914 Replaces option `vhdl-additional-empty-lines'."
915 :type '(choice (const :tag "None" none)
916 (const :tag "Design units only" unit)
917 (const :tag "All constructs" all))
918 :group 'vhdl-template
919 :group 'vhdl-port
920 :group 'vhdl-compose)
921
922 (defcustom vhdl-argument-list-indent nil
923 "Non-nil means indent argument lists relative to opening parenthesis.
924 That is, argument, association, and port lists start on the same line as the
925 opening parenthesis and subsequent lines are indented accordingly.
926 Otherwise, lists start on a new line and are indented as normal code."
927 :type 'boolean
928 :group 'vhdl-template
929 :group 'vhdl-port
930 :group 'vhdl-compose)
931
932 (defcustom vhdl-association-list-with-formals t
933 "Non-nil means write association lists with formal parameters.
934 Templates prompt for formal and actual parameters (ports/generics).
935 When pasting component instantiations, formals are included.
936 If nil, only a list of actual parameters is entered."
937 :type 'boolean
938 :group 'vhdl-template
939 :group 'vhdl-port
940 :group 'vhdl-compose)
941
942 (defcustom vhdl-conditions-in-parenthesis nil
943 "Non-nil means place parenthesis around condition expressions."
944 :type 'boolean
945 :group 'vhdl-template)
946
947 (defcustom vhdl-sensitivity-list-all t
948 "Non-nil means use `all' keyword in sensitivity list."
949 :version "25.1"
950 :type 'boolean
951 :group 'vhdl-template)
952
953 (defcustom vhdl-zero-string "'0'"
954 "String to use for a logic zero."
955 :type 'string
956 :group 'vhdl-template)
957
958 (defcustom vhdl-one-string "'1'"
959 "String to use for a logic one."
960 :type 'string
961 :group 'vhdl-template)
962
963
964 (defgroup vhdl-header nil
965 "Customizations for file header."
966 :group 'vhdl-template
967 :group 'vhdl-compose)
968
969 (defcustom vhdl-file-header "\
970 -------------------------------------------------------------------------------
971 -- Title : <title string>
972 -- Project : <project>
973 -------------------------------------------------------------------------------
974 -- File : <filename>
975 -- Author : <author>
976 -- Company : <company>
977 -- Created : <date>
978 -- Last update: <date>
979 -- Platform : <platform>
980 -- Standard : <standard>
981 <projectdesc>-------------------------------------------------------------------------------
982 -- Description: <cursor>
983 <copyright>-------------------------------------------------------------------------------
984 -- Revisions :
985 -- Date Version Author Description
986 -- <date> 1.0 <login>\tCreated
987 -------------------------------------------------------------------------------
988
989 "
990 "String or file to insert as file header.
991 If the string specifies an existing file name, the contents of the file is
992 inserted, otherwise the string itself is inserted as file header.
993 Type `C-j' for newlines.
994 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
995 if the header needs to be version controlled.
996
997 The following keywords for template generation are supported:
998 <filename> : replaced by the name of the buffer
999 <author> : replaced by the user name and email address
1000 (`user-full-name',`mail-host-address', `user-mail-address')
1001 <authorfull> : replaced by the user full name (`user-full-name')
1002 <login> : replaced by user login name (`user-login-name')
1003 <company> : replaced by contents of option `vhdl-company-name'
1004 <date> : replaced by the current date
1005 <year> : replaced by the current year
1006 <project> : replaced by title of current project (`vhdl-project')
1007 <projectdesc> : replaced by description of current project (`vhdl-project')
1008 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1009 <platform> : replaced by contents of option `vhdl-platform-spec'
1010 <standard> : replaced by the VHDL language standard(s) used
1011 <... string> : replaced by a queried string (\"...\" is the prompt word)
1012 <title string>: replaced by file title in automatically generated files
1013 <cursor> : final cursor position
1014
1015 The (multi-line) project description <projectdesc> can be used as a project
1016 dependent part of the file header and can also contain the above keywords."
1017 :type 'string
1018 :group 'vhdl-header)
1019
1020 (defcustom vhdl-file-footer ""
1021 "String or file to insert as file footer.
1022 If the string specifies an existing file name, the contents of the file is
1023 inserted, otherwise the string itself is inserted as file footer (i.e. at
1024 the end of the file).
1025 Type `C-j' for newlines.
1026 The same keywords as in option `vhdl-file-header' can be used."
1027 :type 'string
1028 :group 'vhdl-header)
1029
1030 (defcustom vhdl-company-name ""
1031 "Name of company to insert in file header.
1032 See option `vhdl-file-header'."
1033 :type 'string
1034 :group 'vhdl-header)
1035
1036 (defcustom vhdl-copyright-string "\
1037 -------------------------------------------------------------------------------
1038 -- Copyright (c) <year> <company>
1039 "
1040 "Copyright string to insert in file header.
1041 Can be multi-line string (type `C-j' for newline) and contain other file
1042 header keywords (see option `vhdl-file-header')."
1043 :type 'string
1044 :group 'vhdl-header)
1045
1046 (defcustom vhdl-platform-spec ""
1047 "Specification of VHDL platform to insert in file header.
1048 The platform specification should contain names and versions of the
1049 simulation and synthesis tools used.
1050 See option `vhdl-file-header'."
1051 :type 'string
1052 :group 'vhdl-header)
1053
1054 (defcustom vhdl-date-format "%Y-%m-%d"
1055 "Specifies the date format to use in the header.
1056 This string is passed as argument to the command `format-time-string'.
1057 For more information on format strings, see the documentation for the
1058 `format-time-string' command (C-h f `format-time-string')."
1059 :type 'string
1060 :group 'vhdl-header)
1061
1062 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1063 "Prefix string of modification date in VHDL file header.
1064 If actualization of the modification date is called (menu,
1065 `\\[vhdl-template-modify]'), this string is searched and the rest
1066 of the line replaced by the current date."
1067 :type 'string
1068 :group 'vhdl-header)
1069
1070 (defcustom vhdl-modify-date-on-saving t
1071 "Non-nil means update the modification date when the buffer is saved.
1072 Calls function `\\[vhdl-template-modify]').
1073
1074 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1075 \"Activate Options\"."
1076 :type 'boolean
1077 :group 'vhdl-header)
1078
1079
1080 (defgroup vhdl-sequential-process nil
1081 "Customizations for sequential processes."
1082 :group 'vhdl-template)
1083
1084 (defcustom vhdl-reset-kind 'async
1085 "Specifies which kind of reset to use in sequential processes."
1086 :type '(choice (const :tag "None" none)
1087 (const :tag "Synchronous" sync)
1088 (const :tag "Asynchronous" async)
1089 (const :tag "Query" query))
1090 :group 'vhdl-sequential-process)
1091
1092 (defcustom vhdl-reset-active-high nil
1093 "Non-nil means reset in sequential processes is active high.
1094 Otherwise, reset is active low."
1095 :type 'boolean
1096 :group 'vhdl-sequential-process)
1097
1098 (defcustom vhdl-clock-rising-edge t
1099 "Non-nil means rising edge of clock triggers sequential processes.
1100 Otherwise, falling edge triggers."
1101 :type 'boolean
1102 :group 'vhdl-sequential-process)
1103
1104 (defcustom vhdl-clock-edge-condition 'standard
1105 "Syntax of the clock edge condition.
1106 Standard: \"clk\\='event and clk = \\='1\\='\"
1107 Function: \"rising_edge(clk)\""
1108 :type '(choice (const :tag "Standard" standard)
1109 (const :tag "Function" function))
1110 :group 'vhdl-sequential-process)
1111
1112 (defcustom vhdl-clock-name ""
1113 "Name of clock signal to use in templates."
1114 :type 'string
1115 :group 'vhdl-sequential-process)
1116
1117 (defcustom vhdl-reset-name ""
1118 "Name of reset signal to use in templates."
1119 :type 'string
1120 :group 'vhdl-sequential-process)
1121
1122
1123 (defgroup vhdl-model nil
1124 "Customizations for user models."
1125 :group 'vhdl)
1126
1127 (defcustom vhdl-model-alist
1128 '(("Example Model"
1129 "<label> : process (<clock>, <reset>)
1130 begin -- process <label>
1131 if <reset> = '0' then -- asynchronous reset (active low)
1132 <cursor>
1133 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1134 if <enable> = '1' then -- synchronous load
1135
1136 end if;
1137 end if;
1138 end process <label>;"
1139 "e" ""))
1140 "List of user models.
1141 VHDL models (templates) can be specified by the user in this list. They can be
1142 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1143 electrification (i.e. overriding existing or creating new keywords, see
1144 option `vhdl-electric-keywords').
1145 Name : name of model (string of words and spaces)
1146 String : string or name of file to be inserted as model (newline: `C-j')
1147 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1148 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1149 Keyword : keyword to invoke model
1150
1151 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1152 A prompt that appears several times is queried once and replaced throughout
1153 the model. Special prompts are:
1154 <clock> : name specified in `vhdl-clock-name' (if not empty)
1155 <reset> : name specified in `vhdl-reset-name' (if not empty)
1156 <cursor>: final cursor position
1157 File header prompts (see variable `vhdl-file-header') are automatically
1158 replaced, so that user models can also be used to insert different types of
1159 headers.
1160
1161 If the string specifies an existing file name, the contents of the file is
1162 inserted, otherwise the string itself is inserted.
1163 The code within the models should be correctly indented.
1164 Type `C-j' for newlines.
1165
1166 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1167 \"Activate Options\"."
1168 :type '(repeat (list :tag "Model" :indent 2
1169 (string :tag "Name ")
1170 (string :tag "String : (type `C-j' for newline)"
1171 :format "%t\n%v")
1172 (sexp :tag "Key binding" x)
1173 (string :tag "Keyword " :format "%t: %v\n")))
1174 :set (lambda (variable value)
1175 (vhdl-custom-set variable value
1176 'vhdl-model-map-init
1177 'vhdl-model-defun
1178 'vhdl-mode-abbrev-table-init
1179 'vhdl-update-mode-menu))
1180 :group 'vhdl-model)
1181
1182
1183 (defgroup vhdl-compose nil
1184 "Customizations for structural composition."
1185 :group 'vhdl)
1186
1187 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1188 (concat
1189 "Specifies how the component architecture name is obtained.
1190 The component architecture name can be obtained by modifying the entity name
1191 \(e.g. attaching or stripping off a substring).
1192 If TO STRING is empty, the architecture name is queried."
1193 vhdl-name-doc-string)
1194 :type '(cons (regexp :tag "From regexp")
1195 (string :tag "To string "))
1196 :group 'vhdl-compose)
1197
1198 (defcustom vhdl-compose-configuration-name
1199 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1200 (concat
1201 "Specifies how the configuration name is obtained.
1202 The configuration name can be obtained by modifying the entity and/or
1203 architecture name (e.g. attaching or stripping off a substring). The string
1204 that is matched against the regexp is the concatenation of the entity and the
1205 architecture name separated by a space. This gives access to both names (see
1206 default setting as example)."
1207 vhdl-name-doc-string)
1208 :type '(cons (regexp :tag "From regexp")
1209 (string :tag "To string "))
1210 :group 'vhdl-compose)
1211
1212 (defcustom vhdl-components-package-name
1213 '((".*" . "\\&_components") . "components")
1214 (concat
1215 "Specifies how the name for the components package is obtained.
1216 The components package is a package containing all component declarations for
1217 the current design. Its name can be obtained by modifying the project name
1218 \(e.g. attaching or stripping off a substring). If no project is defined, the
1219 DIRECTORY entry is chosen."
1220 vhdl-name-doc-string)
1221 :type '(cons (cons :tag "Project" :indent 2
1222 (regexp :tag "From regexp")
1223 (string :tag "To string "))
1224 (string :tag "Directory:\n String "))
1225 :group 'vhdl-compose)
1226
1227 (defcustom vhdl-use-components-package nil
1228 "Non-nil means use a separate components package for component declarations.
1229 Otherwise, component declarations are inserted and searched for in the
1230 architecture declarative parts."
1231 :type 'boolean
1232 :group 'vhdl-compose)
1233
1234 (defcustom vhdl-compose-include-header t
1235 "Non-nil means include a header in automatically generated files."
1236 :type 'boolean
1237 :group 'vhdl-compose)
1238
1239 (defcustom vhdl-compose-create-files 'single
1240 "Specifies whether new files should be created for the new component.
1241 The component's entity and architecture are inserted:
1242 None : in current buffer
1243 Single file : in new single file
1244 Separate files: in two separate files
1245 The file names are obtained from variables `vhdl-entity-file-name' and
1246 `vhdl-architecture-file-name'."
1247 :type '(choice (const :tag "None" none)
1248 (const :tag "Single file" single)
1249 (const :tag "Separate files" separate))
1250 :group 'vhdl-compose)
1251
1252 (defcustom vhdl-compose-configuration-create-file nil
1253 "Specifies whether a new file should be created for the configuration.
1254 If non-nil, a new file is created for the configuration.
1255 The file name is obtained from variable `vhdl-configuration-file-name'."
1256 :type 'boolean
1257 :group 'vhdl-compose)
1258
1259 (defcustom vhdl-compose-configuration-hierarchical t
1260 "Specifies whether hierarchical configurations should be created.
1261 If non-nil, automatically created configurations are hierarchical and include
1262 the whole hierarchy of subcomponents. Otherwise the configuration only
1263 includes one level of subcomponents."
1264 :type 'boolean
1265 :group 'vhdl-compose)
1266
1267 (defcustom vhdl-compose-configuration-use-subconfiguration t
1268 "Specifies whether subconfigurations should be used inside configurations.
1269 If non-nil, automatically created configurations use configurations in binding
1270 indications for subcomponents, if such configurations exist. Otherwise,
1271 entities are used in binding indications for subcomponents."
1272 :type 'boolean
1273 :group 'vhdl-compose)
1274
1275
1276 (defgroup vhdl-port nil
1277 "Customizations for port translation functions."
1278 :group 'vhdl
1279 :group 'vhdl-compose)
1280
1281 (defcustom vhdl-include-port-comments nil
1282 "Non-nil means include port comments when a port is pasted."
1283 :type 'boolean
1284 :group 'vhdl-port)
1285
1286 (defcustom vhdl-include-direction-comments nil
1287 "Non-nil means include port direction in instantiations as comments."
1288 :type 'boolean
1289 :group 'vhdl-port)
1290
1291 (defcustom vhdl-include-type-comments nil
1292 "Non-nil means include generic/port type in instantiations as comments."
1293 :type 'boolean
1294 :group 'vhdl-port)
1295
1296 (defcustom vhdl-include-group-comments 'never
1297 "Specifies whether to include group comments and spacings.
1298 The comments and empty lines between groups of ports are pasted:
1299 Never : never
1300 Declarations: in entity/component/constant/signal declarations only
1301 Always : also in generic/port maps"
1302 :type '(choice (const :tag "Never" never)
1303 (const :tag "Declarations" decl)
1304 (const :tag "Always" always))
1305 :group 'vhdl-port)
1306
1307 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1308 (concat
1309 "Specifies how actual generic names are obtained from formal generic names.
1310 In a component instantiation, an actual generic name can be
1311 obtained by modifying the formal generic name (e.g. attaching or stripping
1312 off a substring)."
1313 vhdl-name-doc-string)
1314 :type '(cons (regexp :tag "From regexp")
1315 (string :tag "To string "))
1316 :group 'vhdl-port
1317 :version "24.4")
1318
1319 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1320 (concat
1321 "Specifies how actual port names are obtained from formal port names.
1322 In a component instantiation, an actual port name can be obtained by
1323 modifying the formal port name (e.g. attaching or stripping off a substring)."
1324 vhdl-name-doc-string)
1325 :type '(cons (regexp :tag "From regexp")
1326 (string :tag "To string "))
1327 :group 'vhdl-port)
1328
1329 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1330 (concat
1331 "Specifies how an instance name is obtained.
1332 The instance name can be obtained by modifying the name of the component to be
1333 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1334 by a unique number (starting with 1).
1335 If TO STRING is empty, the instance name is queried."
1336 vhdl-name-doc-string)
1337 :type '(cons (regexp :tag "From regexp")
1338 (string :tag "To string "))
1339 :group 'vhdl-port)
1340
1341
1342 (defgroup vhdl-testbench nil
1343 "Customizations for testbench generation."
1344 :group 'vhdl-port)
1345
1346 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1347 (concat
1348 "Specifies how the testbench entity name is obtained.
1349 The entity name of a testbench can be obtained by modifying the name of
1350 the component to be tested (e.g. attaching or stripping off a substring)."
1351 vhdl-name-doc-string)
1352 :type '(cons (regexp :tag "From regexp")
1353 (string :tag "To string "))
1354 :group 'vhdl-testbench)
1355
1356 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1357 (concat
1358 "Specifies how the testbench architecture name is obtained.
1359 The testbench architecture name can be obtained by modifying the name of
1360 the component to be tested (e.g. attaching or stripping off a substring).
1361 If TO STRING is empty, the architecture name is queried."
1362 vhdl-name-doc-string)
1363 :type '(cons (regexp :tag "From regexp")
1364 (string :tag "To string "))
1365 :group 'vhdl-testbench)
1366
1367 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1368 (concat
1369 "Specifies how the testbench configuration name is obtained.
1370 The configuration name of a testbench can be obtained by modifying the entity
1371 and/or architecture name (e.g. attaching or stripping off a substring). The
1372 string that is matched against the regexp is the concatenation of the entity
1373 and the architecture name separated by a space. This gives access to both
1374 names (see default setting as example)."
1375 vhdl-name-doc-string)
1376 :type '(cons (regexp :tag "From regexp")
1377 (string :tag "To string "))
1378 :group 'vhdl-testbench)
1379
1380 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1381 (concat
1382 "Specifies how a DUT instance name is obtained.
1383 The design-under-test instance name (i.e. the component instantiated in the
1384 testbench) can be obtained by modifying the component name (e.g. attaching
1385 or stripping off a substring)."
1386 vhdl-name-doc-string)
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
1390
1391 (defcustom vhdl-testbench-include-header t
1392 "Non-nil means include a header in automatically generated files."
1393 :type 'boolean
1394 :group 'vhdl-testbench)
1395
1396 (defcustom vhdl-testbench-declarations "\
1397 -- clock
1398 signal Clk : std_logic := '1';
1399 "
1400 "String or file to be inserted in the testbench declarative part.
1401 If the string specifies an existing file name, the contents of the file is
1402 inserted, otherwise the string itself is inserted in the testbench
1403 architecture before the BEGIN keyword.
1404 Type `C-j' for newlines."
1405 :type 'string
1406 :group 'vhdl-testbench)
1407
1408 (defcustom vhdl-testbench-statements "\
1409 -- clock generation
1410 Clk <= not Clk after 10 ns;
1411
1412 -- waveform generation
1413 WaveGen_Proc: process
1414 begin
1415 -- insert signal assignments here
1416
1417 wait until Clk = '1';
1418 end process WaveGen_Proc;
1419 "
1420 "String or file to be inserted in the testbench statement part.
1421 If the string specifies an existing file name, the contents of the file is
1422 inserted, otherwise the string itself is inserted in the testbench
1423 architecture before the END keyword.
1424 Type `C-j' for newlines."
1425 :type 'string
1426 :group 'vhdl-testbench)
1427
1428 (defcustom vhdl-testbench-initialize-signals nil
1429 "Non-nil means initialize signals with `0' when declared in testbench."
1430 :type 'boolean
1431 :group 'vhdl-testbench)
1432
1433 (defcustom vhdl-testbench-include-library t
1434 "Non-nil means a library/use clause for std_logic_1164 is included."
1435 :type 'boolean
1436 :group 'vhdl-testbench)
1437
1438 (defcustom vhdl-testbench-include-configuration t
1439 "Non-nil means a testbench configuration is attached at the end."
1440 :type 'boolean
1441 :group 'vhdl-testbench)
1442
1443 (defcustom vhdl-testbench-create-files 'single
1444 "Specifies whether new files should be created for the testbench.
1445 testbench entity and architecture are inserted:
1446 None : in current buffer
1447 Single file : in new single file
1448 Separate files: in two separate files
1449 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1450 and `vhdl-testbench-architecture-file-name'."
1451 :type '(choice (const :tag "None" none)
1452 (const :tag "Single file" single)
1453 (const :tag "Separate files" separate))
1454 :group 'vhdl-testbench)
1455
1456 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1457 (concat
1458 "Specifies how the testbench entity file name is obtained.
1459 The entity file name can be obtained by modifying the testbench entity name
1460 \(e.g. attaching or stripping off a substring). The file extension is
1461 automatically taken from the file name of the current buffer. Testbench
1462 files can be created in a different directory by prepending a relative or
1463 absolute path to the file name."
1464 vhdl-name-doc-string)
1465 :type '(cons (regexp :tag "From regexp")
1466 (string :tag "To string "))
1467 :group 'vhdl-testbench)
1468
1469 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1470 (concat
1471 "Specifies how the testbench architecture file name is obtained.
1472 The architecture file name can be obtained by modifying the testbench entity
1473 and/or architecture name (e.g. attaching or stripping off a substring). The
1474 string that is matched against the regexp is the concatenation of the entity
1475 and the architecture name separated by a space. This gives access to both
1476 names (see default setting as example). Testbench files can be created in
1477 a different directory by prepending a relative or absolute path to the file
1478 name."
1479 vhdl-name-doc-string)
1480 :type '(cons (regexp :tag "From regexp")
1481 (string :tag "To string "))
1482 :group 'vhdl-testbench)
1483
1484
1485 (defgroup vhdl-comment nil
1486 "Customizations for comments."
1487 :group 'vhdl)
1488
1489 (defcustom vhdl-self-insert-comments t
1490 "Non-nil means various templates automatically insert help comments."
1491 :type 'boolean
1492 :group 'vhdl-comment)
1493
1494 (defcustom vhdl-prompt-for-comments t
1495 "Non-nil means various templates prompt for user definable comments."
1496 :type 'boolean
1497 :group 'vhdl-comment)
1498
1499 (defcustom vhdl-inline-comment-column 40
1500 "Column to indent and align inline comments to.
1501 Overrides local option `comment-column'.
1502
1503 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1504 \"Activate Options\"."
1505 :type 'integer
1506 :group 'vhdl-comment)
1507
1508 (defcustom vhdl-end-comment-column 79
1509 "End of comment column.
1510 Comments that exceed this column number are wrapped.
1511
1512 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1513 \"Activate Options\"."
1514 :type 'integer
1515 :group 'vhdl-comment)
1516
1517 (defvar end-comment-column)
1518
1519
1520 (defgroup vhdl-beautify nil
1521 "Customizations for beautification."
1522 :group 'vhdl)
1523
1524 (defcustom vhdl-auto-align t
1525 "Non-nil means align some templates automatically after generation."
1526 :type 'boolean
1527 :group 'vhdl-beautify)
1528
1529 (defcustom vhdl-align-groups t
1530 "Non-nil means align groups of code lines separately.
1531 A group of code lines is a region of consecutive lines between two lines that
1532 match the regexp in option `vhdl-align-group-separate'."
1533 :type 'boolean
1534 :group 'vhdl-beautify)
1535
1536 (defcustom vhdl-align-group-separate "^\\s-*$"
1537 "Regexp for matching a line that separates groups of lines for alignment.
1538 Examples:
1539 \"^\\s-*$\": matches an empty line
1540 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1541 :type 'regexp
1542 :group 'vhdl-beautify)
1543
1544 (defcustom vhdl-align-same-indent t
1545 "Non-nil means align blocks with same indent separately.
1546 When a region or the entire buffer is aligned, the code is divided into
1547 blocks of same indent which are aligned separately (except for argument/port
1548 lists). This gives nicer alignment in most cases.
1549 Option `vhdl-align-groups' still applies within these blocks."
1550 :type 'boolean
1551 :group 'vhdl-beautify)
1552
1553 (defcustom vhdl-beautify-options '(t t t t t)
1554 "List of options for beautifying code.
1555 Allows you to disable individual features of code beautification."
1556 :type '(list (boolean :tag "Whitespace cleanup ")
1557 (boolean :tag "Single statement per line")
1558 (boolean :tag "Indentation ")
1559 (boolean :tag "Alignment ")
1560 (boolean :tag "Case fixing "))
1561 :group 'vhdl-beautify
1562 :version "24.4")
1563
1564
1565 (defgroup vhdl-highlight nil
1566 "Customizations for highlighting."
1567 :group 'vhdl)
1568
1569 (defcustom vhdl-highlight-keywords t
1570 "Non-nil means highlight VHDL keywords and other standardized words.
1571 The following faces are used:
1572 `font-lock-keyword-face' : keywords
1573 `font-lock-type-face' : standardized types
1574 `vhdl-font-lock-attribute-face': standardized attributes
1575 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1576 `vhdl-font-lock-function-face' : standardized function and package names
1577
1578 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1579 entry \"Fontify Buffer\")."
1580 :type 'boolean
1581 :set (lambda (variable value)
1582 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1583 :group 'vhdl-highlight)
1584
1585 (defcustom vhdl-highlight-names t
1586 "Non-nil means highlight declaration names and construct labels.
1587 The following faces are used:
1588 `font-lock-function-name-face' : names in declarations of units,
1589 subprograms, components, as well as labels of VHDL constructs
1590 `font-lock-type-face' : names in type/nature declarations
1591 `vhdl-font-lock-attribute-face': names in attribute declarations
1592 `font-lock-variable-name-face' : names in declarations of signals,
1593 variables, constants, subprogram parameters, generics, and ports
1594
1595 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1596 entry \"Fontify Buffer\")."
1597 :type 'boolean
1598 :set (lambda (variable value)
1599 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1600 :group 'vhdl-highlight)
1601
1602 (defcustom vhdl-highlight-special-words nil
1603 "Non-nil means highlight words with special syntax.
1604 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1605 are highlighted accordingly.
1606 Can be used for visual support of naming conventions.
1607
1608 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\")."
1610 :type 'boolean
1611 :set (lambda (variable value)
1612 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1613 :group 'vhdl-highlight)
1614
1615 (defcustom vhdl-highlight-forbidden-words nil
1616 "Non-nil means highlight forbidden words.
1617 The reserved words specified in option `vhdl-forbidden-words' or having the
1618 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1619 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1620 use them.
1621
1622 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1623 entry \"Fontify Buffer\")."
1624 :type 'boolean
1625 :set (lambda (variable value)
1626 (vhdl-custom-set variable value
1627 'vhdl-words-init 'vhdl-font-lock-init))
1628 :group 'vhdl-highlight)
1629
1630 (defcustom vhdl-highlight-verilog-keywords nil
1631 "Non-nil means highlight Verilog keywords as reserved words.
1632 Verilog keywords are highlighted in a warning color (face
1633 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1634
1635 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1636 entry \"Fontify Buffer\")."
1637 :type 'boolean
1638 :set (lambda (variable value)
1639 (vhdl-custom-set variable value
1640 'vhdl-words-init 'vhdl-font-lock-init))
1641 :group 'vhdl-highlight)
1642
1643 (defcustom vhdl-highlight-translate-off nil
1644 "Non-nil means background-highlight code excluded from translation.
1645 That is, all code between \"-- pragma translate_off\" and
1646 \"-- pragma translate_on\" is highlighted using a different background color
1647 \(face `vhdl-font-lock-translate-off-face').
1648 Note: this might slow down on-the-fly fontification (and thus editing).
1649
1650 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1651 entry \"Fontify Buffer\")."
1652 :type 'boolean
1653 :set (lambda (variable value)
1654 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1655 :group 'vhdl-highlight)
1656
1657 (defcustom vhdl-highlight-case-sensitive nil
1658 "Non-nil means consider case for highlighting.
1659 Possible trade-off:
1660 non-nil also upper-case VHDL words are highlighted, but case of words with
1661 special syntax is not considered
1662 nil only lower-case VHDL words are highlighted, but case of words with
1663 special syntax is considered
1664 Overrides local option `font-lock-keywords-case-fold-search'.
1665
1666 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1667 entry \"Fontify Buffer\")."
1668 :type 'boolean
1669 :group 'vhdl-highlight)
1670
1671 (defcustom vhdl-special-syntax-alist
1672 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1673 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1674 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1675 "List of special syntax to be highlighted.
1676 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1677 syntax (as regular expression) are highlighted in the corresponding color.
1678
1679 Name : string of words and spaces
1680 Regexp : regular expression describing word syntax
1681 (e.g., `\\=\\<\\w+_c\\>' matches word with suffix `_c')
1682 expression must start with `\\=\\<' and end with `\\>'
1683 if only whole words should be matched (no substrings)
1684 Color (light): foreground color for light background
1685 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1686 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1687 Color (dark) : foreground color for dark background
1688 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1689 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1690 In comments : If non-nil, words are also highlighted inside comments
1691
1692 Can be used for visual support of naming conventions, such as highlighting
1693 different kinds of signals (e.g. `Clk50', `Rst_n') or objects (e.g.
1694 `Signal_s', `Variable_v', `Constant_c') by distinguishing them using
1695 common substrings or name suffices.
1696 For each entry, a new face is generated with the specified colors and name
1697 `vhdl-font-lock-' + name + `-face'.
1698
1699 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1700 entry `Fontify Buffer'). All other changes require restarting Emacs."
1701 :type '(repeat (list :tag "Face" :indent 2
1702 (string :tag "Name ")
1703 (regexp :tag "Regexp " "\\w+_")
1704 (string :tag "Color (light)")
1705 (string :tag "Color (dark) ")
1706 (boolean :tag "In comments ")))
1707 :set (lambda (variable value)
1708 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1709 :group 'vhdl-highlight)
1710
1711 (defcustom vhdl-forbidden-words '()
1712 "List of forbidden words to be highlighted.
1713 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1714 words are highlighted in a warning color to indicate not to use them.
1715
1716 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1717 entry \"Fontify Buffer\")."
1718 :type '(repeat (string :format "%v"))
1719 :set (lambda (variable value)
1720 (vhdl-custom-set variable value
1721 'vhdl-words-init 'vhdl-font-lock-init))
1722 :group 'vhdl-highlight)
1723
1724 (defcustom vhdl-forbidden-syntax ""
1725 "Syntax of forbidden words to be highlighted.
1726 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1727 syntax are highlighted in a warning color to indicate not to use them.
1728 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1729 highlights identifiers with 10 or more characters).
1730
1731 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1732 entry \"Fontify Buffer\")."
1733 :type 'regexp
1734 :set (lambda (variable value)
1735 (vhdl-custom-set variable value
1736 'vhdl-words-init 'vhdl-font-lock-init))
1737 :group 'vhdl-highlight)
1738
1739 (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
1740 "List of compiler directive keywords recognized for highlighting.
1741
1742 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1743 entry \"Fontify Buffer\")."
1744 :type '(repeat (string :format "%v"))
1745 :set (lambda (variable value)
1746 (vhdl-custom-set variable value
1747 'vhdl-words-init 'vhdl-font-lock-init))
1748 :group 'vhdl-highlight)
1749
1750
1751 (defgroup vhdl-speedbar nil
1752 "Customizations for speedbar."
1753 :group 'vhdl)
1754
1755 (defcustom vhdl-speedbar-auto-open nil
1756 "Non-nil means automatically open speedbar at startup.
1757 Alternatively, the speedbar can be opened from the VHDL menu."
1758 :type 'boolean
1759 :group 'vhdl-speedbar)
1760
1761 (defcustom vhdl-speedbar-display-mode 'files
1762 "Specifies the default displaying mode when opening speedbar.
1763 Alternatively, the displaying mode can be selected from the speedbar menu or
1764 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1765 :type '(choice (const :tag "Files" files)
1766 (const :tag "Directory hierarchy" directory)
1767 (const :tag "Project hierarchy" project))
1768 :group 'vhdl-speedbar)
1769
1770 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1771 "Limits scanning of large files and netlists.
1772 Design units: maximum file size to scan for design units
1773 Hierarchy (instances of subcomponents):
1774 File size: maximum file size to scan for instances (in bytes)
1775 Instances per arch: maximum number of instances to scan per architecture
1776
1777 \"None\" always means that there is no limit.
1778 In case of files not or incompletely scanned, a warning message and the file
1779 names are printed out.
1780 Background: scanning for instances is considerably slower than scanning for
1781 design units, especially when there are many instances. These limits should
1782 prevent the scanning of large netlists."
1783 :type '(list (choice :tag "Design units"
1784 :format "%t : %[Value Menu%] %v"
1785 (const :tag "None" nil)
1786 (integer :tag "File size"))
1787 (list :tag "Hierarchy" :indent 2
1788 (choice :tag "File size"
1789 :format "%t : %[Value Menu%] %v"
1790 (const :tag "None" nil)
1791 (integer :tag "Size "))
1792 (choice :tag "Instances per arch"
1793 (const :tag "None" nil)
1794 (integer :tag "Number "))))
1795 :group 'vhdl-speedbar)
1796
1797 (defcustom vhdl-speedbar-jump-to-unit t
1798 "Non-nil means jump to the design unit code when opened in a buffer.
1799 The buffer cursor position is left unchanged otherwise."
1800 :type 'boolean
1801 :group 'vhdl-speedbar)
1802
1803 (defcustom vhdl-speedbar-update-on-saving t
1804 "Automatically update design hierarchy when buffer is saved."
1805 :type 'boolean
1806 :group 'vhdl-speedbar)
1807
1808 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1809 "Automatically save modified hierarchy caches when exiting Emacs.
1810 Hierarchy: design hierarchy information
1811 Display: displaying information (which design units to expand)"
1812 :type '(set (const :tag "Hierarchy" hierarchy)
1813 (const :tag "Display" display))
1814 :group 'vhdl-speedbar)
1815
1816 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1817 "Name of file for saving hierarchy cache.
1818 \"\\1\" is replaced by the project name if a project is specified,
1819 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1820 different users to have cache files in the same directory). Can also have
1821 an absolute path (i.e. all caches can be stored in one global directory)."
1822 :type 'string
1823 :group 'vhdl-speedbar)
1824
1825
1826 (defgroup vhdl-menu nil
1827 "Customizations for menus."
1828 :group 'vhdl)
1829
1830 (defcustom vhdl-index-menu nil
1831 "Non-nil means add an index menu for a source file when loading.
1832 Alternatively, the speedbar can be used. Note that the index menu scans a file
1833 when it is opened, while speedbar only scans the file upon request."
1834 :type 'boolean
1835 :group 'vhdl-menu)
1836
1837 (defcustom vhdl-source-file-menu nil
1838 "Non-nil means add a menu of all source files in current directory.
1839 Alternatively, the speedbar can be used."
1840 :type 'boolean
1841 :group 'vhdl-menu)
1842
1843 (defcustom vhdl-hideshow-menu nil
1844 "Non-nil means add hideshow menu and functionality at startup.
1845 Hideshow can also be enabled from the VHDL Mode menu.
1846 Hideshow allows hiding code of various VHDL constructs.
1847
1848 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1849 \"Activate Options\"."
1850 :type 'boolean
1851 :group 'vhdl-menu)
1852
1853 (defcustom vhdl-hide-all-init nil
1854 "Non-nil means hide all design units initially after a file is loaded."
1855 :type 'boolean
1856 :group 'vhdl-menu)
1857
1858
1859 (defgroup vhdl-print nil
1860 "Customizations for printing."
1861 :group 'vhdl)
1862
1863 (defcustom vhdl-print-two-column t
1864 "Non-nil means print code in two columns and landscape format.
1865 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1866 prints VHDL files in a nice two-column landscape style.
1867
1868 NOTE: Activate the new setting by restarting Emacs.
1869 Overrides `ps-print' settings locally."
1870 :type 'boolean
1871 :group 'vhdl-print)
1872
1873 (defcustom vhdl-print-customize-faces t
1874 "Non-nil means use an optimized set of faces for PostScript printing.
1875
1876 NOTE: Activate the new setting by restarting Emacs.
1877 Overrides `ps-print' settings locally."
1878 :type 'boolean
1879 :group 'vhdl-print)
1880
1881
1882 (defgroup vhdl-misc nil
1883 "Miscellaneous customizations."
1884 :group 'vhdl)
1885
1886 (defcustom vhdl-intelligent-tab t
1887 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1888 That is, if preceding character is part of a word then complete word,
1889 else if not at beginning of line then insert tab,
1890 else if last command was a `TAB' or `RET' then dedent one step,
1891 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1892 If nil, TAB always indents current line (i.e. `TAB' is bound to
1893 `indent-according-to-mode').
1894
1895 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1896 \"Activate Options\"."
1897 :type 'boolean
1898 :group 'vhdl-misc)
1899
1900 (defcustom vhdl-indent-syntax-based t
1901 "Non-nil means indent lines of code based on their syntactic context.
1902 Otherwise, a line is indented like the previous nonblank line. This can be
1903 useful in large files where syntax-based indentation gets very slow."
1904 :type 'boolean
1905 :group 'vhdl-misc)
1906
1907 (defcustom vhdl-indent-comment-like-next-code-line t
1908 "Non-nil means comment lines are indented like the following code line.
1909 Otherwise, comment lines are indented like the preceding code line.
1910 Indenting comment lines like the following code line gives nicer indentation
1911 when comments precede the code that they refer to."
1912 :type 'boolean
1913 :version "24.3"
1914 :group 'vhdl-misc)
1915
1916 (defcustom vhdl-word-completion-case-sensitive nil
1917 "Non-nil means word completion using `TAB' is case sensitive.
1918 That is, `TAB' completes words that start with the same letters and case.
1919 Otherwise, case is ignored."
1920 :type 'boolean
1921 :group 'vhdl-misc)
1922
1923 (defcustom vhdl-word-completion-in-minibuffer t
1924 "Non-nil enables word completion in minibuffer (for template prompts).
1925
1926 NOTE: Activate the new setting by restarting Emacs."
1927 :type 'boolean
1928 :group 'vhdl-misc)
1929
1930 (defcustom vhdl-underscore-is-part-of-word nil
1931 "Non-nil means consider the underscore character `_' as part of word.
1932 An identifier containing underscores is then treated as a single word in
1933 select and move operations. All parts of an identifier separated by underscore
1934 are treated as single words otherwise."
1935 :type 'boolean
1936 :group 'vhdl-misc)
1937 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1938 'superword-mode "24.4")
1939
1940
1941 (defgroup vhdl-related nil
1942 "Related general customizations."
1943 :group 'vhdl)
1944
1945 ;; add related general customizations
1946 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1947 (if (featurep 'xemacs)
1948 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1949 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1950 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1951 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1952 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1953 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1954 (unless (featurep 'xemacs)
1955 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1956 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1957 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1958 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1959
1960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1961 ;; Hidden user variables
1962
1963 (defvar vhdl-compile-absolute-path nil
1964 "If non-nil, use absolute instead of relative path for compiled files.")
1965
1966 (defvar vhdl-comment-display-line-char ?-
1967 "Character to use in comment display line.")
1968
1969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1970 ;; Internal variables
1971
1972 (defvar vhdl-menu-max-size 20
1973 "Specifies the maximum size of a menu before splitting it into submenus.")
1974
1975 (defvar vhdl-progress-interval 1
1976 "Interval used to update progress status during long operations.
1977 If a number, percentage complete gets updated after each interval of
1978 that many seconds. To inhibit all messages, set this option to nil.")
1979
1980 (defvar vhdl-inhibit-startup-warnings-p nil
1981 "If non-nil, inhibits start up compatibility warnings.")
1982
1983 (defvar vhdl-strict-syntax-p nil
1984 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1985 If the syntactic symbol for a particular line does not match a symbol
1986 in the offsets alist, an error is generated, otherwise no error is
1987 reported and the syntactic symbol is ignored.")
1988
1989 (defvar vhdl-echo-syntactic-information-p nil
1990 "If non-nil, syntactic info is echoed when the line is indented.")
1991
1992 (defconst vhdl-offsets-alist-default
1993 '((string . -1000)
1994 (cpp-macro . -1000)
1995 (block-open . 0)
1996 (block-close . 0)
1997 (statement . 0)
1998 (statement-cont . vhdl-lineup-statement-cont)
1999 (statement-block-intro . +)
2000 (statement-case-intro . +)
2001 (case-alternative . +)
2002 (comment . vhdl-lineup-comment)
2003 (arglist-intro . +)
2004 (arglist-cont . 0)
2005 (arglist-cont-nonempty . vhdl-lineup-arglist)
2006 (arglist-close . vhdl-lineup-arglist)
2007 (entity . 0)
2008 (configuration . 0)
2009 (package . 0)
2010 (architecture . 0)
2011 (package-body . 0)
2012 (context . 0)
2013 (directive . 0)
2014 )
2015 "Default settings for offsets of syntactic elements.
2016 Do not change this constant! See the variable `vhdl-offsets-alist' for
2017 more information.")
2018
2019 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2020 "Association list of syntactic element symbols and indentation offsets.
2021 As described below, each cons cell in this list has the form:
2022
2023 (SYNTACTIC-SYMBOL . OFFSET)
2024
2025 When a line is indented, `vhdl-mode' first determines the syntactic
2026 context of the line by generating a list of symbols called syntactic
2027 elements. This list can contain more than one syntactic element and
2028 the global variable `vhdl-syntactic-context' contains the context list
2029 for the line being indented. Each element in this list is actually a
2030 cons cell of the syntactic symbol and a buffer position. This buffer
2031 position is call the relative indent point for the line. Some
2032 syntactic symbols may not have a relative indent point associated with
2033 them.
2034
2035 After the syntactic context list for a line is generated, `vhdl-mode'
2036 calculates the absolute indentation for the line by looking at each
2037 syntactic element in the list. First, it compares the syntactic
2038 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2039 finds a match, it adds the OFFSET to the column of the relative indent
2040 point. The sum of this calculation for each element in the syntactic
2041 list is the absolute offset for line being indented.
2042
2043 If the syntactic element does not match any in the `vhdl-offsets-alist',
2044 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2045 the element is ignored.
2046
2047 Actually, OFFSET can be an integer, a function, a variable, or one of
2048 the following symbols: `+', `-', `++', or `--'. These latter
2049 designate positive or negative multiples of `vhdl-basic-offset',
2050 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2051 called with a single argument containing the cons of the syntactic
2052 element symbol and the relative indent point. The function should
2053 return an integer offset.
2054
2055 Here is the current list of valid syntactic element symbols:
2056
2057 string -- inside multi-line string
2058 block-open -- statement block open
2059 block-close -- statement block close
2060 statement -- a VHDL statement
2061 statement-cont -- a continuation of a VHDL statement
2062 statement-block-intro -- the first line in a new statement block
2063 statement-case-intro -- the first line in a case alternative block
2064 case-alternative -- a case statement alternative clause
2065 comment -- a line containing only a comment
2066 arglist-intro -- the first line in an argument list
2067 arglist-cont -- subsequent argument list lines when no
2068 arguments follow on the same line as
2069 the arglist opening paren
2070 arglist-cont-nonempty -- subsequent argument list lines when at
2071 least one argument follows on the same
2072 line as the arglist opening paren
2073 arglist-close -- the solo close paren of an argument list
2074 entity -- inside an entity declaration
2075 configuration -- inside a configuration declaration
2076 package -- inside a package declaration
2077 architecture -- inside an architecture body
2078 package-body -- inside a package body
2079 context -- inside a context declaration")
2080
2081 (defvar vhdl-comment-only-line-offset 0
2082 "Extra offset for line which contains only the start of a comment.
2083 Can contain an integer or a cons cell of the form:
2084
2085 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2086
2087 Where NON-ANCHORED-OFFSET is the amount of offset given to
2088 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2089 the amount of offset to give column-zero anchored comment-only lines.
2090 Just an integer as value is equivalent to (<val> . 0)")
2091
2092 (defvar vhdl-special-indent-hook nil
2093 "Hook for user defined special indentation adjustments.
2094 This hook gets called after a line is indented by the mode.")
2095
2096 (defvar vhdl-style-alist
2097 '(("IEEE"
2098 (vhdl-basic-offset . 4)
2099 (vhdl-offsets-alist . ())))
2100 "Styles of Indentation.
2101 Elements of this alist are of the form:
2102
2103 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2104
2105 where STYLE-STRING is a short descriptive string used to select a
2106 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2107 value for that variable when using the selected style.
2108
2109 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2110 case, the VALUE is a list containing elements of the form:
2111
2112 (SYNTACTIC-SYMBOL . VALUE)
2113
2114 as described in `vhdl-offsets-alist'. These are passed directly to
2115 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2116 your style, only those that are different from the default.")
2117
2118 ;; dynamically append the default value of most variables
2119 (or (assoc "Default" vhdl-style-alist)
2120 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2121 vhdl-strict-syntax-p
2122 vhdl-echo-syntactic-information-p
2123 vhdl-basic-offset
2124 vhdl-offsets-alist
2125 vhdl-comment-only-line-offset))
2126 (default (cons "Default"
2127 (mapcar
2128 (function
2129 (lambda (var)
2130 (cons var (symbol-value var))))
2131 varlist))))
2132 (push default vhdl-style-alist)))
2133
2134 (defvar vhdl-mode-hook nil
2135 "Hook called by `vhdl-mode'.")
2136
2137
2138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2139 ;;; Required packages
2140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2141
2142 ;; mandatory
2143 (require 'compile) ; XEmacs
2144 (require 'easymenu)
2145 (require 'hippie-exp)
2146
2147 ;; optional (minimize warning messages during compile)
2148 (unless (featurep 'xemacs)
2149 (eval-when-compile
2150 (require 'font-lock)
2151 (require 'ps-print)
2152 (require 'speedbar))) ; for speedbar-with-writable
2153
2154 (defun vhdl-aput (alist-symbol key &optional value)
2155 "Insert a key-value pair into an alist.
2156 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2157 from KEY and VALUE. If the key-value pair referenced by KEY can be
2158 found in the alist, the value of KEY will be set to VALUE. If the
2159 key-value pair cannot be found in the alist, it will be inserted into
2160 the head of the alist."
2161 (let* ((alist (symbol-value alist-symbol))
2162 (elem (assoc key alist)))
2163 (if elem
2164 (setcdr elem value)
2165 (set alist-symbol (cons (cons key value) alist)))))
2166
2167 (defun vhdl-adelete (alist-symbol key)
2168 "Delete a key-value pair from the alist.
2169 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2170 is pair matching KEY."
2171 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2172 (while (equal key (caar alist))
2173 (setq alist (cdr alist))
2174 (set alist-symbol alist))
2175 (while (setq alist-cdr (cdr alist))
2176 (if (equal key (caar alist-cdr))
2177 (setcdr alist (cdr alist-cdr))
2178 (setq alist alist-cdr)))))
2179
2180 (defun vhdl-aget (alist key)
2181 "Return the value in ALIST that is associated with KEY. If KEY is
2182 not found, then nil is returned."
2183 (cdr (assoc key alist)))
2184
2185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2186 ;;; Compatibility
2187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2188
2189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190 ;; XEmacs compatibility
2191
2192 ;; active regions
2193 (defun vhdl-keep-region-active ()
2194 "Do whatever is necessary to keep the region active in XEmacs.
2195 Ignore byte-compiler warnings you might see."
2196 (and (featurep 'xemacs)
2197 (setq zmacs-region-stays t)))
2198
2199 ;; `wildcard-to-regexp' is included only in XEmacs 21
2200 (unless (fboundp 'wildcard-to-regexp)
2201 (defun wildcard-to-regexp (wildcard)
2202 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2203 (let* ((i (string-match "[*?]" wildcard))
2204 (result (substring wildcard 0 i))
2205 (len (length wildcard)))
2206 (when i
2207 (while (< i len)
2208 (let ((ch (aref wildcard i)))
2209 (setq result (concat result
2210 (cond ((eq ch ?*) "[^\000]*")
2211 ((eq ch ??) "[^\000]")
2212 (t (char-to-string ch)))))
2213 (setq i (1+ i)))))
2214 (concat "\\`" result "\\'"))))
2215
2216 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2217 ;; `regexp-opt' accelerates fontification by 10-20%
2218 (unless (fboundp 'regexp-opt)
2219 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2220 (defun regexp-opt (strings &optional paren)
2221 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2222 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2223
2224 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2225 (unless (fboundp 'match-string-no-properties)
2226 (defalias 'match-string-no-properties 'match-string))
2227
2228 ;; `subst-char-in-string' undefined (XEmacs)
2229 (unless (fboundp 'subst-char-in-string)
2230 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2231 (let ((i (length string))
2232 (newstr (if inplace string (copy-sequence string))))
2233 (while (> i 0)
2234 (setq i (1- i))
2235 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2236 newstr)))
2237
2238 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2239 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2240 (not noninteractive))
2241 (load "itimer")
2242 (when (string< itimer-version "1.09")
2243 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2244 (beep) (sit-for 5)))
2245
2246 ;; `file-expand-wildcards' undefined (XEmacs)
2247 (unless (fboundp 'file-expand-wildcards)
2248 (defun file-expand-wildcards (pattern &optional full)
2249 "Taken from Emacs's `files.el'."
2250 (let* ((nondir (file-name-nondirectory pattern))
2251 (dirpart (file-name-directory pattern))
2252 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2253 (mapcar 'file-name-as-directory
2254 (file-expand-wildcards (directory-file-name dirpart)))
2255 (list dirpart)))
2256 contents)
2257 (while dirs
2258 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2259 (file-directory-p (directory-file-name (car dirs))))
2260 (let ((this-dir-contents
2261 (delq nil
2262 (mapcar #'(lambda (name)
2263 (unless (string-match "\\`\\.\\.?\\'"
2264 (file-name-nondirectory name))
2265 name))
2266 (directory-files (or (car dirs) ".") full
2267 (wildcard-to-regexp nondir))))))
2268 (setq contents
2269 (nconc
2270 (if (and (car dirs) (not full))
2271 (mapcar (function (lambda (name) (concat (car dirs) name)))
2272 this-dir-contents)
2273 this-dir-contents)
2274 contents))))
2275 (setq dirs (cdr dirs)))
2276 contents)))
2277
2278 ;; `member-ignore-case' undefined (XEmacs)
2279 (unless (fboundp 'member-ignore-case)
2280 (defalias 'member-ignore-case 'member))
2281
2282 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2283 ;; behavior in XEmacs
2284 (defvar vhdl-last-input-event)
2285 (if (featurep 'xemacs)
2286 (defvaralias 'vhdl-last-input-event 'last-input-char)
2287 (defvaralias 'vhdl-last-input-event 'last-input-event))
2288
2289 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2290 ;;;(unless (fboundp 'help-print-return-message)
2291 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2292
2293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2294 ;; Compatibility with older VHDL Mode versions
2295
2296 (defvar vhdl-warnings nil
2297 "Warnings to tell the user during start up.")
2298
2299 (defun vhdl-run-when-idle (secs repeat function)
2300 "Wait until idle, then run FUNCTION."
2301 (if (fboundp 'start-itimer)
2302 (start-itimer "vhdl-mode" function secs repeat t)
2303 ;; explicitly activate timer (necessary when Emacs is already idle)
2304 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2305
2306 (defun vhdl-warning-when-idle (&rest args)
2307 "Wait until idle, then print out warning STRING and beep."
2308 (let ((message (apply #'format-message args)))
2309 (if noninteractive
2310 (vhdl-warning message t)
2311 (unless vhdl-warnings
2312 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2313 (push message vhdl-warnings))))
2314
2315 (defun vhdl-warning (string &optional nobeep)
2316 "Print out warning STRING and beep."
2317 (message "WARNING: %s" string)
2318 (unless (or nobeep noninteractive) (beep)))
2319
2320 (defun vhdl-print-warnings ()
2321 "Print out messages in variable `vhdl-warnings'."
2322 (let ((no-warnings (length vhdl-warnings)))
2323 (setq vhdl-warnings (nreverse vhdl-warnings))
2324 (while vhdl-warnings
2325 (message "WARNING: %s" (car vhdl-warnings))
2326 (setq vhdl-warnings (cdr vhdl-warnings)))
2327 (beep)
2328 (when (> no-warnings 1)
2329 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2330
2331 ;; Backward compatibility checks and fixes
2332 ;; option `vhdl-compiler' changed format
2333 (unless (stringp vhdl-compiler)
2334 (setq vhdl-compiler "ModelSim")
2335 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2336
2337 ;; option `vhdl-standard' changed format
2338 (unless (listp vhdl-standard)
2339 (setq vhdl-standard '(87 nil))
2340 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2341
2342 ;; option `vhdl-model-alist' changed format
2343 (when (= (length (car vhdl-model-alist)) 3)
2344 (let ((old-alist vhdl-model-alist)
2345 new-alist)
2346 (while old-alist
2347 (push (append (car old-alist) '("")) new-alist)
2348 (setq old-alist (cdr old-alist)))
2349 (setq vhdl-model-alist (nreverse new-alist)))
2350 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2351
2352 ;; option `vhdl-project-alist' changed format
2353 (when (= (length (car vhdl-project-alist)) 3)
2354 (let ((old-alist vhdl-project-alist)
2355 new-alist)
2356 (while old-alist
2357 (push (append (car old-alist) '("")) new-alist)
2358 (setq old-alist (cdr old-alist)))
2359 (setq vhdl-project-alist (nreverse new-alist)))
2360 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2361
2362 ;; option `vhdl-project-alist' changed format (3.31.1)
2363 (when (= (length (car vhdl-project-alist)) 4)
2364 (let ((old-alist vhdl-project-alist)
2365 new-alist elem)
2366 (while old-alist
2367 (setq elem (car old-alist))
2368 (setq new-alist
2369 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2370 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2371 new-alist))
2372 (setq old-alist (cdr old-alist)))
2373 (setq vhdl-project-alist (nreverse new-alist)))
2374 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2375
2376 ;; option `vhdl-project-alist' changed format (3.31.12)
2377 (when (= (length (car vhdl-project-alist)) 10)
2378 (let ((tmp-alist vhdl-project-alist))
2379 (while tmp-alist
2380 (setcdr (nthcdr 3 (car tmp-alist))
2381 (cons "" (nthcdr 4 (car tmp-alist))))
2382 (setq tmp-alist (cdr tmp-alist))))
2383 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2384
2385 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2386 (when (= (length (car vhdl-compiler-alist)) 7)
2387 (let ((old-alist vhdl-compiler-alist)
2388 new-alist elem)
2389 (while old-alist
2390 (setq elem (car old-alist))
2391 (setq new-alist
2392 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2393 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2394 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2395 (nth 5 elem) (nth 6 elem) nil)
2396 new-alist))
2397 (setq old-alist (cdr old-alist)))
2398 (setq vhdl-compiler-alist (nreverse new-alist)))
2399 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2400
2401 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2402 (when (= (length (car vhdl-compiler-alist)) 12)
2403 (let ((tmp-alist vhdl-compiler-alist))
2404 (while tmp-alist
2405 (setcdr (nthcdr 4 (car tmp-alist))
2406 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2407 (setq tmp-alist (cdr tmp-alist))))
2408 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2409
2410 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2411 (when (= (length (car vhdl-compiler-alist)) 13)
2412 (let ((tmp-alist vhdl-compiler-alist))
2413 (while tmp-alist
2414 (setcdr (nthcdr 3 (car tmp-alist))
2415 (cons "" (nthcdr 4 (car tmp-alist))))
2416 (setq tmp-alist (cdr tmp-alist))))
2417 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2418
2419 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2420 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2421 (let ((tmp-alist vhdl-compiler-alist))
2422 (while tmp-alist
2423 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2424 '(0 . nil))
2425 (setq tmp-alist (cdr tmp-alist))))
2426 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2427
2428 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2429 (when (equal vhdl-project "")
2430 (setq vhdl-project nil)
2431 (customize-save-variable 'vhdl-project vhdl-project))
2432
2433 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2434 (when (stringp vhdl-project-file-name)
2435 (setq vhdl-project-file-name (list vhdl-project-file-name))
2436 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2437
2438 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2439 (if (not (boundp 'speedbar-indentation-width))
2440 (defvar speedbar-indentation-width 2)
2441 ;; set default to 2 if not already customized
2442 (unless (get 'speedbar-indentation-width 'saved-value)
2443 (setq speedbar-indentation-width 2)))
2444
2445 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2446 ;;; Help functions / inline substitutions / macros
2447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2448
2449 (defun vhdl-standard-p (standard)
2450 "Check if STANDARD is specified as used standard."
2451 (or (eq standard (car vhdl-standard))
2452 (memq standard (cadr vhdl-standard))))
2453
2454 (defun vhdl-project-p (&optional warning)
2455 "Return non-nil if a project is displayed, i.e. directories or files are
2456 specified."
2457 (if (assoc vhdl-project vhdl-project-alist)
2458 vhdl-project
2459 (when (and vhdl-project warning)
2460 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2461 nil))
2462
2463 (defun vhdl-resolve-env-variable (string)
2464 "Resolve environment variables in STRING."
2465 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2466 (setq string (concat (match-string 1 string)
2467 (getenv (match-string 2 string))
2468 (match-string 4 string))))
2469 string)
2470
2471 (defun vhdl-default-directory ()
2472 "Return the default directory of the current project or the directory of the
2473 current buffer if no project is defined."
2474 (if (vhdl-project-p)
2475 (expand-file-name (vhdl-resolve-env-variable
2476 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2477 default-directory))
2478
2479 (defmacro vhdl-prepare-search-1 (&rest body)
2480 "Enable case insensitive search and switch to syntax table that includes `_',
2481 then execute BODY, and finally restore the old environment. Used for
2482 consistent searching."
2483 `(let ((case-fold-search t)) ; case insensitive search
2484 ;; use extended syntax table
2485 (with-syntax-table vhdl-mode-ext-syntax-table
2486 ,@body)))
2487
2488 (defmacro vhdl-prepare-search-2 (&rest body)
2489 "Enable case insensitive search, switch to syntax table that includes `_',
2490 arrange to ignore `intangible' overlays, then execute BODY, and finally restore
2491 the old environment. Used for consistent searching."
2492 `(let ((case-fold-search t) ; case insensitive search
2493 (current-syntax-table (syntax-table))
2494 (inhibit-point-motion-hooks t))
2495 ;; use extended syntax table
2496 (set-syntax-table vhdl-mode-ext-syntax-table)
2497 ;; execute BODY safely
2498 (unwind-protect
2499 (progn ,@body)
2500 ;; restore syntax table
2501 (set-syntax-table current-syntax-table))))
2502
2503 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2504 "Visit file FILE-NAME and execute BODY."
2505 `(if (null ,file-name)
2506 (progn ,@body)
2507 (unless (file-directory-p ,file-name)
2508 (let ((source-buffer (current-buffer))
2509 (visiting-buffer (find-buffer-visiting ,file-name))
2510 file-opened)
2511 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2512 (condition-case ()
2513 (progn (set-buffer (create-file-buffer ,file-name))
2514 (setq file-opened t)
2515 (vhdl-insert-file-contents ,file-name)
2516 ;; FIXME: This modifies a global syntax-table!
2517 (modify-syntax-entry ?\- ". 12" (syntax-table))
2518 (modify-syntax-entry ?\n ">" (syntax-table))
2519 (modify-syntax-entry ?\^M ">" (syntax-table))
2520 (modify-syntax-entry ?_ "w" (syntax-table))
2521 t)
2522 (error
2523 (if ,issue-error
2524 (progn
2525 (when file-opened (kill-buffer (current-buffer)))
2526 (set-buffer source-buffer)
2527 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2528 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2529 nil))))
2530 (condition-case info
2531 (progn ,@body)
2532 (error
2533 (if ,issue-error
2534 (progn
2535 (when file-opened (kill-buffer (current-buffer)))
2536 (set-buffer source-buffer)
2537 (error (cadr info)))
2538 (vhdl-warning (cadr info))))))
2539 (when file-opened (kill-buffer (current-buffer)))
2540 (set-buffer source-buffer)))))
2541
2542 (defun vhdl-insert-file-contents (filename)
2543 "Nicked from `insert-file-contents-literally', but allow coding system
2544 conversion."
2545 (let ((format-alist nil)
2546 (after-insert-file-functions nil)
2547 (jka-compr-compression-info-list nil))
2548 (insert-file-contents filename t)))
2549
2550 (defun vhdl-sort-alist (alist)
2551 "Sort ALIST."
2552 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2553
2554 (defun vhdl-get-subdirs (directory)
2555 "Recursively get subdirectories of DIRECTORY."
2556 (let ((dir-list (list (file-name-as-directory directory)))
2557 file-list)
2558 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2559 (while file-list
2560 (when (file-directory-p (car file-list))
2561 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2562 (setq file-list (cdr file-list)))
2563 dir-list))
2564
2565 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2566 "As `aput', but delete key-value pair if VALUE is nil."
2567 (if value
2568 (vhdl-aput alist-symbol key value)
2569 (vhdl-adelete alist-symbol key)))
2570
2571 (defun vhdl-delete (elt list)
2572 "Delete by side effect the first occurrence of ELT as a member of LIST."
2573 (push nil list)
2574 (let ((list1 list))
2575 (while (and (cdr list1) (not (equal elt (cadr list1))))
2576 (setq list1 (cdr list1)))
2577 (when list
2578 (setcdr list1 (cddr list1))))
2579 (cdr list))
2580
2581 (declare-function speedbar-refresh "speedbar" (&optional arg))
2582 (declare-function speedbar-do-function-pointer "speedbar" ())
2583
2584 (defun vhdl-speedbar-refresh (&optional key)
2585 "Refresh directory or project with name KEY."
2586 (when (and (boundp 'speedbar-frame)
2587 (frame-live-p speedbar-frame))
2588 (let ((pos (point))
2589 (last-frame (selected-frame)))
2590 (if (null key)
2591 (speedbar-refresh)
2592 (select-frame speedbar-frame)
2593 (when (save-excursion
2594 (goto-char (point-min))
2595 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2596 (goto-char (match-end 1))
2597 (speedbar-do-function-pointer)
2598 (backward-char 2)
2599 (speedbar-do-function-pointer)
2600 (message "Refreshing speedbar...done"))
2601 (select-frame last-frame)))))
2602
2603 (defun vhdl-show-messages ()
2604 "Get *Messages* buffer to show recent messages."
2605 (interactive)
2606 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2607
2608 (defun vhdl-use-direct-instantiation ()
2609 "Return whether direct instantiation is used."
2610 (or (eq vhdl-use-direct-instantiation 'always)
2611 (and (eq vhdl-use-direct-instantiation 'standard)
2612 (not (vhdl-standard-p '87)))))
2613
2614 (defun vhdl-max-marker (marker1 marker2)
2615 "Return larger marker."
2616 (if (> marker1 marker2) marker1 marker2))
2617
2618 (defun vhdl-goto-marker (marker)
2619 "Goto marker in appropriate buffer."
2620 (when (markerp marker)
2621 (set-buffer (marker-buffer marker)))
2622 (goto-char marker))
2623
2624 (defun vhdl-menu-split (list title)
2625 "Split menu LIST into several submenus, if number of
2626 elements > `vhdl-menu-max-size'."
2627 (if (> (length list) vhdl-menu-max-size)
2628 (let ((remain list)
2629 (result '())
2630 (sublist '())
2631 (menuno 1)
2632 (i 0))
2633 (while remain
2634 (push (car remain) sublist)
2635 (setq remain (cdr remain))
2636 (setq i (+ i 1))
2637 (if (= i vhdl-menu-max-size)
2638 (progn
2639 (push (cons (format "%s %s" title menuno)
2640 (nreverse sublist)) result)
2641 (setq i 0)
2642 (setq menuno (+ menuno 1))
2643 (setq sublist '()))))
2644 (and sublist
2645 (push (cons (format "%s %s" title menuno)
2646 (nreverse sublist)) result))
2647 (nreverse result))
2648 list))
2649
2650
2651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2652 ;;; Bindings
2653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2654
2655 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2656 ;; Key bindings
2657
2658 (defvar vhdl-template-map nil
2659 "Keymap for VHDL templates.")
2660
2661 (defun vhdl-template-map-init ()
2662 "Initialize `vhdl-template-map'."
2663 (setq vhdl-template-map (make-sparse-keymap))
2664 ;; key bindings for VHDL templates
2665 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2666 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2667 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2668 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2669 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2670 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2671 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2672 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2673 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2674 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2675 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2676 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2677 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2678 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2679 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2680 (define-key vhdl-template-map "ct" 'vhdl-template-context)
2681 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2682 (define-key vhdl-template-map "el" 'vhdl-template-else)
2683 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2684 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2685 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2686 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2687 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2688 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2689 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2690 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2691 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2692 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2693 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2694 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2695 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2696 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2697 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2698 (define-key vhdl-template-map "li" 'vhdl-template-library)
2699 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2700 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2701 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2702 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2703 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2704 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2705 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2706 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2707 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2708 (define-key vhdl-template-map "po" 'vhdl-template-port)
2709 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2710 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2711 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2712 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2713 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2714 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2715 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2716 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2717 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2718 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2719 (define-key vhdl-template-map "us" 'vhdl-template-use)
2720 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2721 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2722 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2723 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2724 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2725 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2726 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2727 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2728 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2729 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2730 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2731 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2732 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2733 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2734 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2735 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2736 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2737 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2738 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2739 (when (vhdl-standard-p 'ams)
2740 (define-key vhdl-template-map "br" 'vhdl-template-break)
2741 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2742 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2743 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2744 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2745 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2746 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2747 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2748 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2749 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2750 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2751 )
2752 (when (vhdl-standard-p 'math)
2753 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2754 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2755 ))
2756
2757 ;; initialize template map for VHDL Mode
2758 (vhdl-template-map-init)
2759
2760 (defun vhdl-function-name (prefix string &optional postfix)
2761 "Generate a Lisp function name.
2762 PREFIX, STRING and optional POSTFIX are concatenated by `-' and spaces in
2763 STRING are replaced by `-' and substrings are converted to lower case."
2764 (let ((name prefix))
2765 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2766 (setq name
2767 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2768 (setq string (substring string (match-beginning 2))))
2769 (when postfix (setq name (concat name "-" postfix)))
2770 (intern name)))
2771
2772 (defvar vhdl-model-map nil
2773 "Keymap for VHDL models.")
2774
2775 (defun vhdl-model-map-init ()
2776 "Initialize `vhdl-model-map'."
2777 (setq vhdl-model-map (make-sparse-keymap))
2778 ;; key bindings for VHDL models
2779 (let ((model-alist vhdl-model-alist) model)
2780 (while model-alist
2781 (setq model (car model-alist))
2782 (define-key vhdl-model-map (nth 2 model)
2783 (vhdl-function-name "vhdl-model" (nth 0 model)))
2784 (setq model-alist (cdr model-alist)))))
2785
2786 ;; initialize user model map for VHDL Mode
2787 (vhdl-model-map-init)
2788
2789 (defvar vhdl-mode-map nil
2790 "Keymap for VHDL Mode.")
2791
2792 (defun vhdl-mode-map-init ()
2793 "Initialize `vhdl-mode-map'."
2794 (setq vhdl-mode-map (make-sparse-keymap))
2795 ;; template key bindings
2796 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2797 ;; model key bindings
2798 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2799 ;; standard key bindings
2800 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2801 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2802 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2803 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2804 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2805 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2806 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2807 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2808 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2809 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2810 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2811 ;; mode specific key bindings
2812 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2813 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2814 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2815 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2816 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2817 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2818 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2819 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2820 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2821 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2822 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2823 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2824 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2825 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2826 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2827 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2828 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2829 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2830 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2831 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2832 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2833 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2834 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2835 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2836 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2837 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2838 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2839 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2840 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2841 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2842 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2843 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2844 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2845 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2846 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2847 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2848 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2849 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2850 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2851 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2852 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2853 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2854 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2855 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2856 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2857 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2858 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2859 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2860 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2861 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2862 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2863 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2864 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2865 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2866 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2867 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2868 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2869 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2870 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2871 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2872 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2873 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2874 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2875 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2876 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2877 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2878 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2879 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2880 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2881 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2882 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2883 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2884 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2885 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2886 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2887 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2888 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2889 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2890 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2891 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2892 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2893 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2894 ;; insert commands bindings
2895 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2896 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2897 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2898 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2899 ;; electric key bindings
2900 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2901 (when vhdl-intelligent-tab
2902 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2903 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2904 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2905 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2906 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2907 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2908 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2909 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2910 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2911 (when (vhdl-standard-p 'ams)
2912 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2913
2914 ;; initialize mode map for VHDL Mode
2915 (vhdl-mode-map-init)
2916
2917 ;; define special minibuffer keymap for enabling word completion in minibuffer
2918 ;; (useful in template generator prompts)
2919 (defvar vhdl-minibuffer-local-map
2920 (let ((map (make-sparse-keymap)))
2921 (set-keymap-parent map minibuffer-local-map)
2922 (when vhdl-word-completion-in-minibuffer
2923 (define-key map "\t" 'vhdl-minibuffer-tab))
2924 map)
2925 "Keymap for minibuffer used in VHDL Mode.")
2926
2927 ;; set up electric character functions to work with
2928 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2929 (mapc
2930 (function
2931 (lambda (sym)
2932 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2933 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2934 '(vhdl-electric-space
2935 vhdl-electric-tab
2936 vhdl-electric-return
2937 vhdl-electric-dash
2938 vhdl-electric-open-bracket
2939 vhdl-electric-close-bracket
2940 vhdl-electric-quote
2941 vhdl-electric-semicolon
2942 vhdl-electric-comma
2943 vhdl-electric-period
2944 vhdl-electric-equal))
2945
2946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2947 ;; Syntax table
2948
2949 (defvar vhdl-mode-syntax-table
2950 (let ((st (make-syntax-table)))
2951 ;; define punctuation
2952 (modify-syntax-entry ?\# "." st)
2953 (modify-syntax-entry ?\$ "." st)
2954 (modify-syntax-entry ?\% "." st)
2955 (modify-syntax-entry ?\& "." st)
2956 (modify-syntax-entry ?\' "." st)
2957 (modify-syntax-entry ?\* "." st)
2958 (modify-syntax-entry ?\+ "." st)
2959 (modify-syntax-entry ?\. "." st)
2960 ;;; (modify-syntax-entry ?\/ "." st)
2961 (modify-syntax-entry ?\: "." st)
2962 (modify-syntax-entry ?\; "." st)
2963 (modify-syntax-entry ?\< "." st)
2964 (modify-syntax-entry ?\= "." st)
2965 (modify-syntax-entry ?\> "." st)
2966 (modify-syntax-entry ?\\ "." st)
2967 (modify-syntax-entry ?\| "." st)
2968 ;; define string
2969 (modify-syntax-entry ?\" "\"" st)
2970 ;; define underscore
2971 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2972 ;; single-line comments
2973 (modify-syntax-entry ?\- ". 12b" st)
2974 ;; multi-line comments
2975 (modify-syntax-entry ?\/ ". 14b" st)
2976 (modify-syntax-entry ?* ". 23" st)
2977 (modify-syntax-entry ?\n "> b" st)
2978 (modify-syntax-entry ?\^M "> b" st)
2979 ;; define parentheses to match
2980 (modify-syntax-entry ?\( "()" st)
2981 (modify-syntax-entry ?\) ")(" st)
2982 (modify-syntax-entry ?\[ "(]" st)
2983 (modify-syntax-entry ?\] ")[" st)
2984 (modify-syntax-entry ?\{ "(}" st)
2985 (modify-syntax-entry ?\} "){" st)
2986 st)
2987 "Syntax table used in `vhdl-mode' buffers.")
2988
2989 (defvar vhdl-mode-ext-syntax-table
2990 ;; Extended syntax table including '_' (for simpler search regexps).
2991 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
2992 (modify-syntax-entry ?_ "w" st)
2993 st)
2994 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2995
2996 (defvar vhdl-syntactic-context nil
2997 "Buffer local variable containing syntactic analysis list.")
2998 (make-variable-buffer-local 'vhdl-syntactic-context)
2999
3000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3001 ;; Abbrev hook bindings
3002
3003 (defvar vhdl-mode-abbrev-table nil
3004 "Abbrev table to use in `vhdl-mode' buffers.")
3005
3006 (defun vhdl-mode-abbrev-table-init ()
3007 "Initialize `vhdl-mode-abbrev-table'."
3008 (define-abbrev-table 'vhdl-mode-abbrev-table
3009 (append
3010 (when (memq 'vhdl vhdl-electric-keywords)
3011 ;; VHDL'02 keywords
3012 (mapcar (if (featurep 'xemacs)
3013 (lambda (x) (list (car x) "" (cdr x) 0))
3014 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3015 '(
3016 ("--" . vhdl-template-display-comment-hook)
3017 ("abs" . vhdl-template-default-hook)
3018 ("access" . vhdl-template-default-hook)
3019 ("after" . vhdl-template-default-hook)
3020 ("alias" . vhdl-template-alias-hook)
3021 ("all" . vhdl-template-default-hook)
3022 ("and" . vhdl-template-default-hook)
3023 ("arch" . vhdl-template-architecture-hook)
3024 ("architecture" . vhdl-template-architecture-hook)
3025 ("array" . vhdl-template-default-hook)
3026 ("assert" . vhdl-template-assert-hook)
3027 ("attr" . vhdl-template-attribute-hook)
3028 ("attribute" . vhdl-template-attribute-hook)
3029 ("begin" . vhdl-template-default-indent-hook)
3030 ("block" . vhdl-template-block-hook)
3031 ("body" . vhdl-template-default-hook)
3032 ("buffer" . vhdl-template-default-hook)
3033 ("bus" . vhdl-template-default-hook)
3034 ("case" . vhdl-template-case-hook)
3035 ("comp" . vhdl-template-component-hook)
3036 ("component" . vhdl-template-component-hook)
3037 ("cond" . vhdl-template-conditional-signal-asst-hook)
3038 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3039 ("conf" . vhdl-template-configuration-hook)
3040 ("configuration" . vhdl-template-configuration-hook)
3041 ("cons" . vhdl-template-constant-hook)
3042 ("constant" . vhdl-template-constant-hook)
3043 ("context" . vhdl-template-context-hook)
3044 ("disconnect" . vhdl-template-disconnect-hook)
3045 ("downto" . vhdl-template-default-hook)
3046 ("else" . vhdl-template-else-hook)
3047 ("elseif" . vhdl-template-elsif-hook)
3048 ("elsif" . vhdl-template-elsif-hook)
3049 ("end" . vhdl-template-default-indent-hook)
3050 ("entity" . vhdl-template-entity-hook)
3051 ("exit" . vhdl-template-exit-hook)
3052 ("file" . vhdl-template-file-hook)
3053 ("for" . vhdl-template-for-hook)
3054 ("func" . vhdl-template-function-hook)
3055 ("function" . vhdl-template-function-hook)
3056 ("generic" . vhdl-template-generic-hook)
3057 ("group" . vhdl-template-group-hook)
3058 ("guarded" . vhdl-template-default-hook)
3059 ("if" . vhdl-template-if-hook)
3060 ("impure" . vhdl-template-default-hook)
3061 ("in" . vhdl-template-default-hook)
3062 ("inertial" . vhdl-template-default-hook)
3063 ("inout" . vhdl-template-default-hook)
3064 ("inst" . vhdl-template-instance-hook)
3065 ("instance" . vhdl-template-instance-hook)
3066 ("is" . vhdl-template-default-hook)
3067 ("label" . vhdl-template-default-hook)
3068 ("library" . vhdl-template-library-hook)
3069 ("linkage" . vhdl-template-default-hook)
3070 ("literal" . vhdl-template-default-hook)
3071 ("loop" . vhdl-template-bare-loop-hook)
3072 ("map" . vhdl-template-map-hook)
3073 ("mod" . vhdl-template-default-hook)
3074 ("nand" . vhdl-template-default-hook)
3075 ("new" . vhdl-template-default-hook)
3076 ("next" . vhdl-template-next-hook)
3077 ("nor" . vhdl-template-default-hook)
3078 ("not" . vhdl-template-default-hook)
3079 ("null" . vhdl-template-default-hook)
3080 ("of" . vhdl-template-default-hook)
3081 ("on" . vhdl-template-default-hook)
3082 ("open" . vhdl-template-default-hook)
3083 ("or" . vhdl-template-default-hook)
3084 ("others" . vhdl-template-others-hook)
3085 ("out" . vhdl-template-default-hook)
3086 ("pack" . vhdl-template-package-hook)
3087 ("package" . vhdl-template-package-hook)
3088 ("port" . vhdl-template-port-hook)
3089 ("postponed" . vhdl-template-default-hook)
3090 ("procedure" . vhdl-template-procedure-hook)
3091 ("process" . vhdl-template-process-hook)
3092 ("pure" . vhdl-template-default-hook)
3093 ("range" . vhdl-template-default-hook)
3094 ("record" . vhdl-template-default-hook)
3095 ("register" . vhdl-template-default-hook)
3096 ("reject" . vhdl-template-default-hook)
3097 ("rem" . vhdl-template-default-hook)
3098 ("report" . vhdl-template-report-hook)
3099 ("return" . vhdl-template-return-hook)
3100 ("rol" . vhdl-template-default-hook)
3101 ("ror" . vhdl-template-default-hook)
3102 ("select" . vhdl-template-selected-signal-asst-hook)
3103 ("severity" . vhdl-template-default-hook)
3104 ("shared" . vhdl-template-default-hook)
3105 ("sig" . vhdl-template-signal-hook)
3106 ("signal" . vhdl-template-signal-hook)
3107 ("sla" . vhdl-template-default-hook)
3108 ("sll" . vhdl-template-default-hook)
3109 ("sra" . vhdl-template-default-hook)
3110 ("srl" . vhdl-template-default-hook)
3111 ("subtype" . vhdl-template-subtype-hook)
3112 ("then" . vhdl-template-default-hook)
3113 ("to" . vhdl-template-default-hook)
3114 ("transport" . vhdl-template-default-hook)
3115 ("type" . vhdl-template-type-hook)
3116 ("unaffected" . vhdl-template-default-hook)
3117 ("units" . vhdl-template-default-hook)
3118 ("until" . vhdl-template-default-hook)
3119 ("use" . vhdl-template-use-hook)
3120 ("var" . vhdl-template-variable-hook)
3121 ("variable" . vhdl-template-variable-hook)
3122 ("wait" . vhdl-template-wait-hook)
3123 ("when" . vhdl-template-when-hook)
3124 ("while" . vhdl-template-while-loop-hook)
3125 ("with" . vhdl-template-with-hook)
3126 ("xnor" . vhdl-template-default-hook)
3127 ("xor" . vhdl-template-default-hook)
3128 )))
3129 ;; VHDL-AMS keywords
3130 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3131 (mapcar (if (featurep 'xemacs)
3132 (lambda (x) (list (car x) "" (cdr x) 0))
3133 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3134 '(
3135 ("across" . vhdl-template-default-hook)
3136 ("break" . vhdl-template-break-hook)
3137 ("limit" . vhdl-template-limit-hook)
3138 ("nature" . vhdl-template-nature-hook)
3139 ("noise" . vhdl-template-default-hook)
3140 ("procedural" . vhdl-template-procedural-hook)
3141 ("quantity" . vhdl-template-quantity-hook)
3142 ("reference" . vhdl-template-default-hook)
3143 ("spectrum" . vhdl-template-default-hook)
3144 ("subnature" . vhdl-template-subnature-hook)
3145 ("terminal" . vhdl-template-terminal-hook)
3146 ("through" . vhdl-template-default-hook)
3147 ("tolerance" . vhdl-template-default-hook)
3148 )))
3149 ;; user model keywords
3150 (when (memq 'user vhdl-electric-keywords)
3151 (let (abbrev-list keyword)
3152 (dolist (elem vhdl-model-alist)
3153 (setq keyword (nth 3 elem))
3154 (unless (equal keyword "")
3155 (push (list keyword ""
3156 (vhdl-function-name
3157 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3158 abbrev-list)))
3159 abbrev-list)))))
3160
3161 ;; initialize abbrev table for VHDL Mode
3162 (vhdl-mode-abbrev-table-init)
3163
3164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3165 ;; Template completion lists
3166
3167 (defvar vhdl-template-construct-alist nil
3168 "List of built-in construct templates.")
3169
3170 (defun vhdl-template-construct-alist-init ()
3171 "Initialize `vhdl-template-construct-alist'."
3172 (setq
3173 vhdl-template-construct-alist
3174 (append
3175 '(
3176 ("alias declaration" vhdl-template-alias)
3177 ("architecture body" vhdl-template-architecture)
3178 ("assertion" vhdl-template-assert)
3179 ("attribute declaration" vhdl-template-attribute-decl)
3180 ("attribute specification" vhdl-template-attribute-spec)
3181 ("block configuration" vhdl-template-block-configuration)
3182 ("block statement" vhdl-template-block)
3183 ("case statement" vhdl-template-case-is)
3184 ("component configuration" vhdl-template-component-conf)
3185 ("component declaration" vhdl-template-component-decl)
3186 ("component instantiation statement" vhdl-template-component-inst)
3187 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3188 ("configuration declaration" vhdl-template-configuration-decl)
3189 ("configuration specification" vhdl-template-configuration-spec)
3190 ("constant declaration" vhdl-template-constant)
3191 ("context declaration" vhdl-template-context)
3192 ("disconnection specification" vhdl-template-disconnect)
3193 ("entity declaration" vhdl-template-entity)
3194 ("exit statement" vhdl-template-exit)
3195 ("file declaration" vhdl-template-file)
3196 ("generate statement" vhdl-template-generate)
3197 ("generic clause" vhdl-template-generic)
3198 ("group declaration" vhdl-template-group-decl)
3199 ("group template declaration" vhdl-template-group-template)
3200 ("if statement" vhdl-template-if-then)
3201 ("library clause" vhdl-template-library)
3202 ("loop statement" vhdl-template-loop)
3203 ("next statement" vhdl-template-next)
3204 ("package declaration" vhdl-template-package-decl)
3205 ("package body" vhdl-template-package-body)
3206 ("port clause" vhdl-template-port)
3207 ("process statement" vhdl-template-process)
3208 ("report statement" vhdl-template-report)
3209 ("return statement" vhdl-template-return)
3210 ("selected signal assignment" vhdl-template-selected-signal-asst)
3211 ("signal declaration" vhdl-template-signal)
3212 ("subprogram declaration" vhdl-template-subprogram-decl)
3213 ("subprogram body" vhdl-template-subprogram-body)
3214 ("subtype declaration" vhdl-template-subtype)
3215 ("type declaration" vhdl-template-type)
3216 ("use clause" vhdl-template-use)
3217 ("variable declaration" vhdl-template-variable)
3218 ("wait statement" vhdl-template-wait)
3219 )
3220 (when (vhdl-standard-p 'ams)
3221 '(
3222 ("break statement" vhdl-template-break)
3223 ("nature declaration" vhdl-template-nature)
3224 ("quantity declaration" vhdl-template-quantity)
3225 ("simultaneous case statement" vhdl-template-case-use)
3226 ("simultaneous if statement" vhdl-template-if-use)
3227 ("simultaneous procedural statement" vhdl-template-procedural)
3228 ("step limit specification" vhdl-template-limit)
3229 ("subnature declaration" vhdl-template-subnature)
3230 ("terminal declaration" vhdl-template-terminal)
3231 )))))
3232
3233 ;; initialize for VHDL Mode
3234 (vhdl-template-construct-alist-init)
3235
3236 (defvar vhdl-template-package-alist nil
3237 "List of built-in package templates.")
3238
3239 (defun vhdl-template-package-alist-init ()
3240 "Initialize `vhdl-template-package-alist'."
3241 (setq
3242 vhdl-template-package-alist
3243 (append
3244 '(
3245 ("numeric_bit" vhdl-template-package-numeric-bit)
3246 ("numeric_std" vhdl-template-package-numeric-std)
3247 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3248 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3249 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3250 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3251 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3252 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3253 ("textio" vhdl-template-package-textio)
3254 )
3255 (when (vhdl-standard-p 'math)
3256 '(
3257 ("math_complex" vhdl-template-package-math-complex)
3258 ("math_real" vhdl-template-package-math-real)
3259 )))))
3260
3261 ;; initialize for VHDL Mode
3262 (vhdl-template-package-alist-init)
3263
3264 (defvar vhdl-template-directive-alist
3265 '(
3266 ("translate_on" vhdl-template-directive-translate-on)
3267 ("translate_off" vhdl-template-directive-translate-off)
3268 ("synthesis_on" vhdl-template-directive-synthesis-on)
3269 ("synthesis_off" vhdl-template-directive-synthesis-off)
3270 )
3271 "List of built-in directive templates.")
3272
3273
3274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3275 ;;; Menus
3276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3277
3278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3279 ;; VHDL menu (using `easy-menu.el')
3280
3281 (defun vhdl-customize ()
3282 "Call the customize function with `vhdl' as argument."
3283 (interactive)
3284 (customize-browse 'vhdl))
3285
3286 (defun vhdl-create-mode-menu ()
3287 "Create VHDL Mode menu."
3288 `("VHDL"
3289 ,(append
3290 '("Project"
3291 ["None" (vhdl-set-project "")
3292 :style radio :selected (null vhdl-project)]
3293 "--")
3294 ;; add menu entries for defined projects
3295 (let ((project-alist vhdl-project-alist) menu-list name)
3296 (while project-alist
3297 (setq name (caar project-alist))
3298 (setq menu-list
3299 (cons `[,name (vhdl-set-project ,name)
3300 :style radio :selected (equal ,name vhdl-project)]
3301 menu-list))
3302 (setq project-alist (cdr project-alist)))
3303 (setq menu-list
3304 (if vhdl-project-sort
3305 (sort menu-list
3306 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3307 (nreverse menu-list)))
3308 (vhdl-menu-split menu-list "Project"))
3309 '("--" "--"
3310 ["Select Project..." vhdl-set-project t]
3311 ["Set As Default Project" vhdl-set-default-project t]
3312 "--"
3313 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3314 ["Import Project..." vhdl-import-project
3315 :keys "C-c C-p C-m" :active t]
3316 ["Export Project" vhdl-export-project vhdl-project]
3317 "--"
3318 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3319 "--"
3320 ("Compile"
3321 ["Compile Buffer" vhdl-compile t]
3322 ["Stop Compilation" kill-compilation t]
3323 "--"
3324 ["Make" vhdl-make t]
3325 ["Generate Makefile" vhdl-generate-makefile t]
3326 "--"
3327 ["Next Error" next-error t]
3328 ["Previous Error" previous-error t]
3329 ["First Error" first-error t]
3330 "--"
3331 ,(append
3332 '("Compiler")
3333 ;; add menu entries for defined compilers
3334 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3335 (while comp-alist
3336 (setq name (caar comp-alist))
3337 (setq menu-list
3338 (cons `[,name (setq vhdl-compiler ,name)
3339 :style radio :selected (equal ,name vhdl-compiler)]
3340 menu-list))
3341 (setq comp-alist (cdr comp-alist)))
3342 (setq menu-list (nreverse menu-list))
3343 (vhdl-menu-split menu-list "Compiler"))
3344 '("--" "--"
3345 ["Select Compiler..." vhdl-set-compiler t]
3346 "--"
3347 ["Customize Compiler..."
3348 (customize-option 'vhdl-compiler-alist) t])))
3349 "--"
3350 ,(append
3351 '("Template"
3352 ("VHDL Construct 1"
3353 ["Alias" vhdl-template-alias t]
3354 ["Architecture" vhdl-template-architecture t]
3355 ["Assert" vhdl-template-assert t]
3356 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3357 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3358 ["Block" vhdl-template-block t]
3359 ["Case" vhdl-template-case-is t]
3360 ["Component (Decl)" vhdl-template-component-decl t]
3361 ["(Component) Instance" vhdl-template-component-inst t]
3362 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3363 ["Configuration (Block)" vhdl-template-block-configuration t]
3364 ["Configuration (Comp)" vhdl-template-component-conf t]
3365 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3366 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3367 ["Constant" vhdl-template-constant t]
3368 ["Context" vhdl-template-context t]
3369 ["Disconnect" vhdl-template-disconnect t]
3370 ["Else" vhdl-template-else t]
3371 ["Elsif" vhdl-template-elsif t]
3372 ["Entity" vhdl-template-entity t]
3373 ["Exit" vhdl-template-exit t]
3374 ["File" vhdl-template-file t]
3375 ["For (Generate)" vhdl-template-for-generate t]
3376 ["For (Loop)" vhdl-template-for-loop t]
3377 ["Function (Body)" vhdl-template-function-body t]
3378 ["Function (Decl)" vhdl-template-function-decl t]
3379 ["Generic" vhdl-template-generic t]
3380 ["Group (Decl)" vhdl-template-group-decl t]
3381 ["Group (Template)" vhdl-template-group-template t])
3382 ("VHDL Construct 2"
3383 ["If (Generate)" vhdl-template-if-generate t]
3384 ["If (Then)" vhdl-template-if-then t]
3385 ["Library" vhdl-template-library t]
3386 ["Loop" vhdl-template-bare-loop t]
3387 ["Map" vhdl-template-map t]
3388 ["Next" vhdl-template-next t]
3389 ["Others (Aggregate)" vhdl-template-others t]
3390 ["Package (Decl)" vhdl-template-package-decl t]
3391 ["Package (Body)" vhdl-template-package-body t]
3392 ["Port" vhdl-template-port t]
3393 ["Procedure (Body)" vhdl-template-procedure-body t]
3394 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3395 ["Process (Comb)" vhdl-template-process-comb t]
3396 ["Process (Seq)" vhdl-template-process-seq t]
3397 ["Report" vhdl-template-report t]
3398 ["Return" vhdl-template-return t]
3399 ["Select" vhdl-template-selected-signal-asst t]
3400 ["Signal" vhdl-template-signal t]
3401 ["Subtype" vhdl-template-subtype t]
3402 ["Type" vhdl-template-type t]
3403 ["Use" vhdl-template-use t]
3404 ["Variable" vhdl-template-variable t]
3405 ["Wait" vhdl-template-wait t]
3406 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3407 ["When" vhdl-template-when t]
3408 ["While (Loop)" vhdl-template-while-loop t]
3409 ["With" vhdl-template-with t]))
3410 (when (vhdl-standard-p 'ams)
3411 '(("VHDL-AMS Construct"
3412 ["Break" vhdl-template-break t]
3413 ["Case (Use)" vhdl-template-case-use t]
3414 ["If (Use)" vhdl-template-if-use t]
3415 ["Limit" vhdl-template-limit t]
3416 ["Nature" vhdl-template-nature t]
3417 ["Procedural" vhdl-template-procedural t]
3418 ["Quantity (Free)" vhdl-template-quantity-free t]
3419 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3420 ["Quantity (Source)" vhdl-template-quantity-source t]
3421 ["Subnature" vhdl-template-subnature t]
3422 ["Terminal" vhdl-template-terminal t])))
3423 '(["Insert Construct..." vhdl-template-insert-construct
3424 :keys "C-c C-i C-t"]
3425 "--")
3426 (list
3427 (append
3428 '("Package")
3429 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3430 ["numeric_std" vhdl-template-package-numeric-std t]
3431 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3432 ["textio" vhdl-template-package-textio t]
3433 "--"
3434 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3435 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3436 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3437 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3438 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3439 "--")
3440 (when (vhdl-standard-p 'ams)
3441 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3442 ["material_constants" vhdl-template-package-material-constants t]
3443 ["energy_systems" vhdl-template-package-energy-systems t]
3444 ["electrical_systems" vhdl-template-package-electrical-systems t]
3445 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3446 ["radiant_systems" vhdl-template-package-radiant-systems t]
3447 ["thermal_systems" vhdl-template-package-thermal-systems t]
3448 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3449 "--"))
3450 (when (vhdl-standard-p 'math)
3451 '(["math_complex" vhdl-template-package-math-complex t]
3452 ["math_real" vhdl-template-package-math-real t]
3453 "--"))
3454 '(["Insert Package..." vhdl-template-insert-package
3455 :keys "C-c C-i C-p"])))
3456 '(("Directive"
3457 ["translate_on" vhdl-template-directive-translate-on t]
3458 ["translate_off" vhdl-template-directive-translate-off t]
3459 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3460 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3461 "--"
3462 ["Insert Directive..." vhdl-template-insert-directive
3463 :keys "C-c C-i C-d"])
3464 "--"
3465 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3466 ["Insert Footer" vhdl-template-footer t]
3467 ["Insert Date" vhdl-template-insert-date t]
3468 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3469 "--"
3470 ["Query Next Prompt" vhdl-template-search-prompt t]))
3471 ,(append
3472 '("Model")
3473 ;; add menu entries for defined models
3474 (let ((model-alist vhdl-model-alist) menu-list model)
3475 (while model-alist
3476 (setq model (car model-alist))
3477 (setq menu-list
3478 (cons
3479 (vector
3480 (nth 0 model)
3481 (vhdl-function-name "vhdl-model" (nth 0 model))
3482 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3483 menu-list))
3484 (setq model-alist (cdr model-alist)))
3485 (setq menu-list (nreverse menu-list))
3486 (vhdl-menu-split menu-list "Model"))
3487 '("--" "--"
3488 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3489 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3490 ("Port"
3491 ["Copy" vhdl-port-copy t]
3492 "--"
3493 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3494 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3495 ["Paste As Instance" vhdl-port-paste-instance
3496 :keys "C-c C-p C-i" :active vhdl-port-list]
3497 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3498 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3499 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3500 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3501 "--"
3502 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3503 "--"
3504 ["Flatten" vhdl-port-flatten
3505 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3506 ["Reverse Direction" vhdl-port-reverse-direction
3507 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3508 ("Compose"
3509 ["New Component" vhdl-compose-new-component t]
3510 ["Copy Component" vhdl-port-copy t]
3511 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3512 ["Wire Components" vhdl-compose-wire-components t]
3513 "--"
3514 ["Generate Configuration" vhdl-compose-configuration t]
3515 ["Generate Components Package" vhdl-compose-components-package t])
3516 ("Subprogram"
3517 ["Copy" vhdl-subprog-copy t]
3518 "--"
3519 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3520 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3521 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3522 "--"
3523 ["Flatten" vhdl-subprog-flatten
3524 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3525 "--"
3526 ("Comment"
3527 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3528 "--"
3529 ["Insert Inline Comment" vhdl-comment-append-inline t]
3530 ["Insert Horizontal Line" vhdl-comment-display-line t]
3531 ["Insert Display Comment" vhdl-comment-display t]
3532 "--"
3533 ["Fill Comment" fill-paragraph t]
3534 ["Fill Comment Region" fill-region (mark)]
3535 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3536 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3537 ("Line"
3538 ["Kill" vhdl-line-kill t]
3539 ["Copy" vhdl-line-copy t]
3540 ["Yank" vhdl-line-yank t]
3541 ["Expand" vhdl-line-expand t]
3542 "--"
3543 ["Transpose Next" vhdl-line-transpose-next t]
3544 ["Transpose Prev" vhdl-line-transpose-previous t]
3545 ["Open" vhdl-line-open t]
3546 ["Join" vhdl-delete-indentation t]
3547 "--"
3548 ["Goto" goto-line t]
3549 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3550 ("Move"
3551 ["Forward Statement" vhdl-end-of-statement t]
3552 ["Backward Statement" vhdl-beginning-of-statement t]
3553 ["Forward Expression" vhdl-forward-sexp t]
3554 ["Backward Expression" vhdl-backward-sexp t]
3555 ["Forward Same Indent" vhdl-forward-same-indent t]
3556 ["Backward Same Indent" vhdl-backward-same-indent t]
3557 ["Forward Function" vhdl-end-of-defun t]
3558 ["Backward Function" vhdl-beginning-of-defun t]
3559 ["Mark Function" vhdl-mark-defun t])
3560 "--"
3561 ("Indent"
3562 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3563 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3564 ["Region" vhdl-indent-region (mark)]
3565 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3566 ("Align"
3567 ["Group" vhdl-align-group t]
3568 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3569 ["List" vhdl-align-list t]
3570 ["Declarations" vhdl-align-declarations t]
3571 ["Region" vhdl-align-region (mark)]
3572 ["Buffer" vhdl-align-buffer t]
3573 "--"
3574 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3575 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3576 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3577 ("Fill"
3578 ["List" vhdl-fill-list t]
3579 ["Group" vhdl-fill-group t]
3580 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3581 ["Region" vhdl-fill-region (mark)])
3582 ("Beautify"
3583 ["Region" vhdl-beautify-region (mark)]
3584 ["Buffer" vhdl-beautify-buffer t])
3585 ("Fix"
3586 ["Generic/Port Clause" vhdl-fix-clause t]
3587 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3588 "--"
3589 ["Case Region" vhdl-fix-case-region (mark)]
3590 ["Case Buffer" vhdl-fix-case-buffer t]
3591 "--"
3592 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3593 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3594 "--"
3595 ["Statement Region" vhdl-fix-statement-region (mark)]
3596 ["Statement Buffer" vhdl-fix-statement-buffer t]
3597 "--"
3598 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3599 ("Update"
3600 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3601 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3602 "--"
3603 ["Fontify Buffer" vhdl-fontify-buffer t]
3604 ["Statistics Buffer" vhdl-statistics-buffer t]
3605 ["Show Messages" vhdl-show-messages t]
3606 ["Syntactic Info" vhdl-show-syntactic-information t]
3607 "--"
3608 ["Speedbar" vhdl-speedbar t]
3609 ["Hide/Show" vhdl-hs-minor-mode t]
3610 "--"
3611 ("Documentation"
3612 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3613 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3614 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3615 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3616 ["Version" vhdl-version t]
3617 ["Bug Report..." vhdl-submit-bug-report t]
3618 "--"
3619 ("Options"
3620 ("Mode"
3621 ["Electric Mode"
3622 (progn (customize-set-variable 'vhdl-electric-mode
3623 (not vhdl-electric-mode))
3624 (vhdl-mode-line-update))
3625 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3626 ["Stutter Mode"
3627 (progn (customize-set-variable 'vhdl-stutter-mode
3628 (not vhdl-stutter-mode))
3629 (vhdl-mode-line-update))
3630 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3631 ["Indent Tabs Mode"
3632 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3633 (not vhdl-indent-tabs-mode))
3634 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3635 :style toggle :selected vhdl-indent-tabs-mode]
3636 "--"
3637 ["Customize Group..." (customize-group 'vhdl-mode) t])
3638 ("Project"
3639 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3640 ,(append
3641 '("Selected Project at Startup"
3642 ["None" (progn (customize-set-variable 'vhdl-project nil)
3643 (vhdl-set-project ""))
3644 :style radio :selected (null vhdl-project)]
3645 "--")
3646 ;; add menu entries for defined projects
3647 (let ((project-alist vhdl-project-alist) menu-list name)
3648 (while project-alist
3649 (setq name (caar project-alist))
3650 (setq menu-list
3651 (cons `[,name (progn (customize-set-variable
3652 'vhdl-project ,name)
3653 (vhdl-set-project ,name))
3654 :style radio :selected (equal ,name vhdl-project)]
3655 menu-list))
3656 (setq project-alist (cdr project-alist)))
3657 (setq menu-list (nreverse menu-list))
3658 (vhdl-menu-split menu-list "Project")))
3659 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3660 ("Auto Load Setup File"
3661 ["At Startup"
3662 (customize-set-variable 'vhdl-project-auto-load
3663 (if (memq 'startup vhdl-project-auto-load)
3664 (delq 'startup vhdl-project-auto-load)
3665 (cons 'startup vhdl-project-auto-load)))
3666 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3667 ["Sort Projects"
3668 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3669 :style toggle :selected vhdl-project-sort]
3670 "--"
3671 ["Customize Group..." (customize-group 'vhdl-project) t])
3672 ("Compiler"
3673 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3674 ,(append
3675 '("Selected Compiler at Startup")
3676 ;; add menu entries for defined compilers
3677 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3678 (while comp-alist
3679 (setq name (caar comp-alist))
3680 (setq menu-list
3681 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3682 :style radio :selected (equal ,name vhdl-compiler)]
3683 menu-list))
3684 (setq comp-alist (cdr comp-alist)))
3685 (setq menu-list (nreverse menu-list))
3686 (vhdl-menu-split menu-list "Compiler")))
3687 ["Use Local Error Regexp"
3688 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3689 (not vhdl-compile-use-local-error-regexp))
3690 :style toggle :selected vhdl-compile-use-local-error-regexp]
3691 ["Makefile Default Targets..."
3692 (customize-option 'vhdl-makefile-default-targets) t]
3693 ["Makefile Generation Hook..."
3694 (customize-option 'vhdl-makefile-generation-hook) t]
3695 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3696 "--"
3697 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3698 ("Style"
3699 ("VHDL Standard"
3700 ["VHDL'87"
3701 (progn (customize-set-variable 'vhdl-standard
3702 (list '87 (cadr vhdl-standard)))
3703 (vhdl-activate-customizations))
3704 :style radio :selected (eq '87 (car vhdl-standard))]
3705 ["VHDL'93/02"
3706 (progn (customize-set-variable 'vhdl-standard
3707 (list '93 (cadr vhdl-standard)))
3708 (vhdl-activate-customizations))
3709 :style radio :selected (eq '93 (car vhdl-standard))]
3710 ["VHDL'08"
3711 (progn (customize-set-variable 'vhdl-standard
3712 (list '08 (cadr vhdl-standard)))
3713 (vhdl-activate-customizations))
3714 :style radio :selected (eq '08 (car vhdl-standard))]
3715 "--"
3716 ["VHDL-AMS"
3717 (progn (customize-set-variable
3718 'vhdl-standard (list (car vhdl-standard)
3719 (if (memq 'ams (cadr vhdl-standard))
3720 (delq 'ams (cadr vhdl-standard))
3721 (cons 'ams (cadr vhdl-standard)))))
3722 (vhdl-activate-customizations))
3723 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3724 ["Math Packages"
3725 (progn (customize-set-variable
3726 'vhdl-standard (list (car vhdl-standard)
3727 (if (memq 'math (cadr vhdl-standard))
3728 (delq 'math (cadr vhdl-standard))
3729 (cons 'math (cadr vhdl-standard)))))
3730 (vhdl-activate-customizations))
3731 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3732 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3733 ["Upper Case Keywords"
3734 (customize-set-variable 'vhdl-upper-case-keywords
3735 (not vhdl-upper-case-keywords))
3736 :style toggle :selected vhdl-upper-case-keywords]
3737 ["Upper Case Types"
3738 (customize-set-variable 'vhdl-upper-case-types
3739 (not vhdl-upper-case-types))
3740 :style toggle :selected vhdl-upper-case-types]
3741 ["Upper Case Attributes"
3742 (customize-set-variable 'vhdl-upper-case-attributes
3743 (not vhdl-upper-case-attributes))
3744 :style toggle :selected vhdl-upper-case-attributes]
3745 ["Upper Case Enumeration Values"
3746 (customize-set-variable 'vhdl-upper-case-enum-values
3747 (not vhdl-upper-case-enum-values))
3748 :style toggle :selected vhdl-upper-case-enum-values]
3749 ["Upper Case Constants"
3750 (customize-set-variable 'vhdl-upper-case-constants
3751 (not vhdl-upper-case-constants))
3752 :style toggle :selected vhdl-upper-case-constants]
3753 ("Use Direct Instantiation"
3754 ["Never"
3755 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3756 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3757 ["Standard"
3758 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3759 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3760 ["Always"
3761 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3762 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3763 ["Include Array Index and Record Field in Sensitivity List"
3764 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3765 (not vhdl-array-index-record-field-in-sensitivity-list))
3766 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3767 "--"
3768 ["Customize Group..." (customize-group 'vhdl-style) t])
3769 ("Naming"
3770 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3771 ["Architecture File Name..."
3772 (customize-option 'vhdl-architecture-file-name) t]
3773 ["Configuration File Name..."
3774 (customize-option 'vhdl-configuration-file-name) t]
3775 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3776 ("File Name Case"
3777 ["As Is"
3778 (customize-set-variable 'vhdl-file-name-case 'identity)
3779 :style radio :selected (eq 'identity vhdl-file-name-case)]
3780 ["Lower Case"
3781 (customize-set-variable 'vhdl-file-name-case 'downcase)
3782 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3783 ["Upper Case"
3784 (customize-set-variable 'vhdl-file-name-case 'upcase)
3785 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3786 ["Capitalize"
3787 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3788 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3789 "--"
3790 ["Customize Group..." (customize-group 'vhdl-naming) t])
3791 ("Template"
3792 ("Electric Keywords"
3793 ["VHDL Keywords"
3794 (customize-set-variable 'vhdl-electric-keywords
3795 (if (memq 'vhdl vhdl-electric-keywords)
3796 (delq 'vhdl vhdl-electric-keywords)
3797 (cons 'vhdl vhdl-electric-keywords)))
3798 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3799 ["User Model Keywords"
3800 (customize-set-variable 'vhdl-electric-keywords
3801 (if (memq 'user vhdl-electric-keywords)
3802 (delq 'user vhdl-electric-keywords)
3803 (cons 'user vhdl-electric-keywords)))
3804 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3805 ("Insert Optional Labels"
3806 ["None"
3807 (customize-set-variable 'vhdl-optional-labels 'none)
3808 :style radio :selected (eq 'none vhdl-optional-labels)]
3809 ["Processes Only"
3810 (customize-set-variable 'vhdl-optional-labels 'process)
3811 :style radio :selected (eq 'process vhdl-optional-labels)]
3812 ["All Constructs"
3813 (customize-set-variable 'vhdl-optional-labels 'all)
3814 :style radio :selected (eq 'all vhdl-optional-labels)])
3815 ("Insert Empty Lines"
3816 ["None"
3817 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3818 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3819 ["Design Units Only"
3820 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3821 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3822 ["All Constructs"
3823 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3824 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3825 ["Argument List Indent"
3826 (customize-set-variable 'vhdl-argument-list-indent
3827 (not vhdl-argument-list-indent))
3828 :style toggle :selected vhdl-argument-list-indent]
3829 ["Association List with Formals"
3830 (customize-set-variable 'vhdl-association-list-with-formals
3831 (not vhdl-association-list-with-formals))
3832 :style toggle :selected vhdl-association-list-with-formals]
3833 ["Conditions in Parenthesis"
3834 (customize-set-variable 'vhdl-conditions-in-parenthesis
3835 (not vhdl-conditions-in-parenthesis))
3836 :style toggle :selected vhdl-conditions-in-parenthesis]
3837 ["Sensitivity List uses 'all'"
3838 (customize-set-variable 'vhdl-sensitivity-list-all
3839 (not vhdl-sensitivity-list-all))
3840 :style toggle :selected vhdl-sensitivity-list-all]
3841 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3842 ["One String..." (customize-option 'vhdl-one-string) t]
3843 ("File Header"
3844 ["Header String..." (customize-option 'vhdl-file-header) t]
3845 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3846 ["Company Name..." (customize-option 'vhdl-company-name) t]
3847 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3848 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3849 ["Date Format..." (customize-option 'vhdl-date-format) t]
3850 ["Modify Date Prefix String..."
3851 (customize-option 'vhdl-modify-date-prefix-string) t]
3852 ["Modify Date on Saving"
3853 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3854 (not vhdl-modify-date-on-saving))
3855 (vhdl-activate-customizations))
3856 :style toggle :selected vhdl-modify-date-on-saving])
3857 ("Sequential Process"
3858 ("Kind of Reset"
3859 ["None"
3860 (customize-set-variable 'vhdl-reset-kind 'none)
3861 :style radio :selected (eq 'none vhdl-reset-kind)]
3862 ["Synchronous"
3863 (customize-set-variable 'vhdl-reset-kind 'sync)
3864 :style radio :selected (eq 'sync vhdl-reset-kind)]
3865 ["Asynchronous"
3866 (customize-set-variable 'vhdl-reset-kind 'async)
3867 :style radio :selected (eq 'async vhdl-reset-kind)]
3868 ["Query"
3869 (customize-set-variable 'vhdl-reset-kind 'query)
3870 :style radio :selected (eq 'query vhdl-reset-kind)])
3871 ["Reset is Active High"
3872 (customize-set-variable 'vhdl-reset-active-high
3873 (not vhdl-reset-active-high))
3874 :style toggle :selected vhdl-reset-active-high]
3875 ["Use Rising Clock Edge"
3876 (customize-set-variable 'vhdl-clock-rising-edge
3877 (not vhdl-clock-rising-edge))
3878 :style toggle :selected vhdl-clock-rising-edge]
3879 ("Clock Edge Condition"
3880 ["Standard"
3881 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3882 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3883 ["Function \"rising_edge\""
3884 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3885 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3886 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3887 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3888 "--"
3889 ["Customize Group..." (customize-group 'vhdl-template) t])
3890 ("Model"
3891 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3892 ("Port"
3893 ["Include Port Comments"
3894 (customize-set-variable 'vhdl-include-port-comments
3895 (not vhdl-include-port-comments))
3896 :style toggle :selected vhdl-include-port-comments]
3897 ["Include Direction Comments"
3898 (customize-set-variable 'vhdl-include-direction-comments
3899 (not vhdl-include-direction-comments))
3900 :style toggle :selected vhdl-include-direction-comments]
3901 ["Include Type Comments"
3902 (customize-set-variable 'vhdl-include-type-comments
3903 (not vhdl-include-type-comments))
3904 :style toggle :selected vhdl-include-type-comments]
3905 ("Include Group Comments"
3906 ["Never"
3907 (customize-set-variable 'vhdl-include-group-comments 'never)
3908 :style radio :selected (eq 'never vhdl-include-group-comments)]
3909 ["Declarations"
3910 (customize-set-variable 'vhdl-include-group-comments 'decl)
3911 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3912 ["Always"
3913 (customize-set-variable 'vhdl-include-group-comments 'always)
3914 :style radio :selected (eq 'always vhdl-include-group-comments)])
3915 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3916 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3917 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3918 ("Testbench"
3919 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3920 ["Architecture Name..."
3921 (customize-option 'vhdl-testbench-architecture-name) t]
3922 ["Configuration Name..."
3923 (customize-option 'vhdl-testbench-configuration-name) t]
3924 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3925 ["Include Header"
3926 (customize-set-variable 'vhdl-testbench-include-header
3927 (not vhdl-testbench-include-header))
3928 :style toggle :selected vhdl-testbench-include-header]
3929 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3930 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3931 ["Initialize Signals"
3932 (customize-set-variable 'vhdl-testbench-initialize-signals
3933 (not vhdl-testbench-initialize-signals))
3934 :style toggle :selected vhdl-testbench-initialize-signals]
3935 ["Include Library Clause"
3936 (customize-set-variable 'vhdl-testbench-include-library
3937 (not vhdl-testbench-include-library))
3938 :style toggle :selected vhdl-testbench-include-library]
3939 ["Include Configuration"
3940 (customize-set-variable 'vhdl-testbench-include-configuration
3941 (not vhdl-testbench-include-configuration))
3942 :style toggle :selected vhdl-testbench-include-configuration]
3943 ("Create Files"
3944 ["None"
3945 (customize-set-variable 'vhdl-testbench-create-files 'none)
3946 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3947 ["Single"
3948 (customize-set-variable 'vhdl-testbench-create-files 'single)
3949 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3950 ["Separate"
3951 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3952 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3953 ["Testbench Entity File Name..."
3954 (customize-option 'vhdl-testbench-entity-file-name) t]
3955 ["Testbench Architecture File Name..."
3956 (customize-option 'vhdl-testbench-architecture-file-name) t])
3957 "--"
3958 ["Customize Group..." (customize-group 'vhdl-port) t])
3959 ("Compose"
3960 ["Architecture Name..."
3961 (customize-option 'vhdl-compose-architecture-name) t]
3962 ["Configuration Name..."
3963 (customize-option 'vhdl-compose-configuration-name) t]
3964 ["Components Package Name..."
3965 (customize-option 'vhdl-components-package-name) t]
3966 ["Use Components Package"
3967 (customize-set-variable 'vhdl-use-components-package
3968 (not vhdl-use-components-package))
3969 :style toggle :selected vhdl-use-components-package]
3970 ["Include Header"
3971 (customize-set-variable 'vhdl-compose-include-header
3972 (not vhdl-compose-include-header))
3973 :style toggle :selected vhdl-compose-include-header]
3974 ("Create Entity/Architecture Files"
3975 ["None"
3976 (customize-set-variable 'vhdl-compose-create-files 'none)
3977 :style radio :selected (eq 'none vhdl-compose-create-files)]
3978 ["Single"
3979 (customize-set-variable 'vhdl-compose-create-files 'single)
3980 :style radio :selected (eq 'single vhdl-compose-create-files)]
3981 ["Separate"
3982 (customize-set-variable 'vhdl-compose-create-files 'separate)
3983 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3984 ["Create Configuration File"
3985 (customize-set-variable 'vhdl-compose-configuration-create-file
3986 (not vhdl-compose-configuration-create-file))
3987 :style toggle :selected vhdl-compose-configuration-create-file]
3988 ["Hierarchical Configuration"
3989 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3990 (not vhdl-compose-configuration-hierarchical))
3991 :style toggle :selected vhdl-compose-configuration-hierarchical]
3992 ["Use Subconfiguration"
3993 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3994 (not vhdl-compose-configuration-use-subconfiguration))
3995 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3996 "--"
3997 ["Customize Group..." (customize-group 'vhdl-compose) t])
3998 ("Comment"
3999 ["Self Insert Comments"
4000 (customize-set-variable 'vhdl-self-insert-comments
4001 (not vhdl-self-insert-comments))
4002 :style toggle :selected vhdl-self-insert-comments]
4003 ["Prompt for Comments"
4004 (customize-set-variable 'vhdl-prompt-for-comments
4005 (not vhdl-prompt-for-comments))
4006 :style toggle :selected vhdl-prompt-for-comments]
4007 ["Inline Comment Column..."
4008 (customize-option 'vhdl-inline-comment-column) t]
4009 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4010 "--"
4011 ["Customize Group..." (customize-group 'vhdl-comment) t])
4012 ("Beautify"
4013 ["Auto Align Templates"
4014 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4015 :style toggle :selected vhdl-auto-align]
4016 ["Align Line Groups"
4017 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4018 :style toggle :selected vhdl-align-groups]
4019 ["Group Separation String..."
4020 (customize-option 'vhdl-align-group-separate) t]
4021 ["Align Lines with Same Indent"
4022 (customize-set-variable 'vhdl-align-same-indent
4023 (not vhdl-align-same-indent))
4024 :style toggle :selected vhdl-align-same-indent]
4025 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4026 "--"
4027 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4028 ("Highlight"
4029 ["Highlighting On/Off..."
4030 (customize-option
4031 (if (fboundp 'global-font-lock-mode)
4032 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4033 ["Highlight Keywords"
4034 (progn (customize-set-variable 'vhdl-highlight-keywords
4035 (not vhdl-highlight-keywords))
4036 (vhdl-fontify-buffer))
4037 :style toggle :selected vhdl-highlight-keywords]
4038 ["Highlight Names"
4039 (progn (customize-set-variable 'vhdl-highlight-names
4040 (not vhdl-highlight-names))
4041 (vhdl-fontify-buffer))
4042 :style toggle :selected vhdl-highlight-names]
4043 ["Highlight Special Words"
4044 (progn (customize-set-variable 'vhdl-highlight-special-words
4045 (not vhdl-highlight-special-words))
4046 (vhdl-fontify-buffer))
4047 :style toggle :selected vhdl-highlight-special-words]
4048 ["Highlight Forbidden Words"
4049 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4050 (not vhdl-highlight-forbidden-words))
4051 (vhdl-fontify-buffer))
4052 :style toggle :selected vhdl-highlight-forbidden-words]
4053 ["Highlight Verilog Keywords"
4054 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4055 (not vhdl-highlight-verilog-keywords))
4056 (vhdl-fontify-buffer))
4057 :style toggle :selected vhdl-highlight-verilog-keywords]
4058 ["Highlight \"translate_off\""
4059 (progn (customize-set-variable 'vhdl-highlight-translate-off
4060 (not vhdl-highlight-translate-off))
4061 (vhdl-fontify-buffer))
4062 :style toggle :selected vhdl-highlight-translate-off]
4063 ["Case Sensitive Highlighting"
4064 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4065 (not vhdl-highlight-case-sensitive))
4066 (vhdl-fontify-buffer))
4067 :style toggle :selected vhdl-highlight-case-sensitive]
4068 ["Special Syntax Definition..."
4069 (customize-option 'vhdl-special-syntax-alist) t]
4070 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4071 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4072 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4073 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4074 "--"
4075 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4076 ("Speedbar"
4077 ["Auto Open at Startup"
4078 (customize-set-variable 'vhdl-speedbar-auto-open
4079 (not vhdl-speedbar-auto-open))
4080 :style toggle :selected vhdl-speedbar-auto-open]
4081 ("Default Displaying Mode"
4082 ["Files"
4083 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4084 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4085 ["Directory Hierarchy"
4086 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4087 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4088 ["Project Hierarchy"
4089 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4090 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4091 ["Indentation Offset..."
4092 (customize-option 'speedbar-indentation-width) t]
4093 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4094 ["Jump to Unit when Opening"
4095 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4096 (not vhdl-speedbar-jump-to-unit))
4097 :style toggle :selected vhdl-speedbar-jump-to-unit]
4098 ["Update Hierarchy on File Saving"
4099 (customize-set-variable 'vhdl-speedbar-update-on-saving
4100 (not vhdl-speedbar-update-on-saving))
4101 :style toggle :selected vhdl-speedbar-update-on-saving]
4102 ("Save in Cache File"
4103 ["Hierarchy Information"
4104 (customize-set-variable 'vhdl-speedbar-save-cache
4105 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4106 (delq 'hierarchy vhdl-speedbar-save-cache)
4107 (cons 'hierarchy vhdl-speedbar-save-cache)))
4108 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4109 ["Displaying Status"
4110 (customize-set-variable 'vhdl-speedbar-save-cache
4111 (if (memq 'display vhdl-speedbar-save-cache)
4112 (delq 'display vhdl-speedbar-save-cache)
4113 (cons 'display vhdl-speedbar-save-cache)))
4114 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4115 ["Cache File Name..."
4116 (customize-option 'vhdl-speedbar-cache-file-name) t]
4117 "--"
4118 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4119 ("Menu"
4120 ["Add Index Menu when Loading File"
4121 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4122 (vhdl-index-menu-init))
4123 :style toggle :selected vhdl-index-menu]
4124 ["Add Source File Menu when Loading File"
4125 (progn (customize-set-variable 'vhdl-source-file-menu
4126 (not vhdl-source-file-menu))
4127 (vhdl-add-source-files-menu))
4128 :style toggle :selected vhdl-source-file-menu]
4129 ["Add Hideshow Menu at Startup"
4130 (progn (customize-set-variable 'vhdl-hideshow-menu
4131 (not vhdl-hideshow-menu))
4132 (vhdl-activate-customizations))
4133 :style toggle :selected vhdl-hideshow-menu]
4134 ["Hide Everything Initially"
4135 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4136 :style toggle :selected vhdl-hide-all-init]
4137 "--"
4138 ["Customize Group..." (customize-group 'vhdl-menu) t])
4139 ("Print"
4140 ["In Two Column Format"
4141 (progn (customize-set-variable 'vhdl-print-two-column
4142 (not vhdl-print-two-column))
4143 (message "Activate new setting by saving options and restarting Emacs"))
4144 :style toggle :selected vhdl-print-two-column]
4145 ["Use Customized Faces"
4146 (progn (customize-set-variable 'vhdl-print-customize-faces
4147 (not vhdl-print-customize-faces))
4148 (message "Activate new setting by saving options and restarting Emacs"))
4149 :style toggle :selected vhdl-print-customize-faces]
4150 "--"
4151 ["Customize Group..." (customize-group 'vhdl-print) t])
4152 ("Miscellaneous"
4153 ["Use Intelligent Tab"
4154 (progn (customize-set-variable 'vhdl-intelligent-tab
4155 (not vhdl-intelligent-tab))
4156 (vhdl-activate-customizations))
4157 :style toggle :selected vhdl-intelligent-tab]
4158 ["Indent Syntax-Based"
4159 (customize-set-variable 'vhdl-indent-syntax-based
4160 (not vhdl-indent-syntax-based))
4161 :style toggle :selected vhdl-indent-syntax-based]
4162 ["Indent Comments Like Next Code Line"
4163 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4164 (not vhdl-indent-comment-like-next-code-line))
4165 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4166 ["Word Completion is Case Sensitive"
4167 (customize-set-variable 'vhdl-word-completion-case-sensitive
4168 (not vhdl-word-completion-case-sensitive))
4169 :style toggle :selected vhdl-word-completion-case-sensitive]
4170 ["Word Completion in Minibuffer"
4171 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4172 (not vhdl-word-completion-in-minibuffer))
4173 (message "Activate new setting by saving options and restarting Emacs"))
4174 :style toggle :selected vhdl-word-completion-in-minibuffer]
4175 ["Underscore is Part of Word"
4176 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4177 (not vhdl-underscore-is-part-of-word))
4178 (vhdl-activate-customizations))
4179 :style toggle :selected vhdl-underscore-is-part-of-word]
4180 "--"
4181 ["Customize Group..." (customize-group 'vhdl-misc) t])
4182 ["Related..." (customize-browse 'vhdl-related) t]
4183 "--"
4184 ["Save Options" customize-save-customized t]
4185 ["Activate Options" vhdl-activate-customizations t]
4186 ["Browse Options..." vhdl-customize t])))
4187
4188 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4189 "VHDL Mode menu.")
4190
4191 (defun vhdl-update-mode-menu ()
4192 "Update VHDL Mode menu."
4193 (interactive)
4194 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4195 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4196 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4197 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4198 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4199
4200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4201 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4202
4203 (defconst vhdl-imenu-generic-expression
4204 '(
4205 ("Subprogram"
4206 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4207 4)
4208 ("Instance"
4209 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4210 1)
4211 ("Component"
4212 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4213 2)
4214 ("Procedural"
4215 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4216 1)
4217 ("Process"
4218 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4219 1)
4220 ("Block"
4221 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4222 1)
4223 ("Package"
4224 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4225 3)
4226 ("Configuration"
4227 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4228 2)
4229 ("Architecture"
4230 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4231 2)
4232 ("Entity"
4233 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4234 2)
4235 ("Context"
4236 "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4237 2)
4238 )
4239 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4240
4241 (defun vhdl-index-menu-init ()
4242 "Initialize index menu."
4243 (set (make-local-variable 'imenu-case-fold-search) t)
4244 (set (make-local-variable 'imenu-generic-expression)
4245 vhdl-imenu-generic-expression)
4246 (when (and vhdl-index-menu (fboundp 'imenu))
4247 (imenu-add-to-menubar "Index")))
4248
4249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4250 ;; Source file menu (using `easy-menu.el')
4251
4252 (defvar vhdl-sources-menu nil)
4253
4254 (defun vhdl-directory-files (directory &optional full match)
4255 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4256 message."
4257 (if (not (file-directory-p directory))
4258 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4259 (let ((dir (directory-files directory full match)))
4260 (setq dir (delete "." dir))
4261 (setq dir (delete ".." dir))
4262 dir)))
4263
4264 (defun vhdl-get-source-files (&optional full directory)
4265 "Get list of VHDL source files in DIRECTORY or current directory."
4266 (let ((mode-alist auto-mode-alist)
4267 filename-regexp)
4268 ;; create regular expressions for matching file names
4269 (setq filename-regexp "\\`[^.].*\\(")
4270 (while mode-alist
4271 (when (eq (cdar mode-alist) 'vhdl-mode)
4272 (setq filename-regexp
4273 (concat filename-regexp (caar mode-alist) "\\|")))
4274 (setq mode-alist (cdr mode-alist)))
4275 (setq filename-regexp
4276 (concat (substring filename-regexp 0
4277 (string-match "\\\\|$" filename-regexp)) "\\)"))
4278 ;; find files
4279 (vhdl-directory-files
4280 (or directory default-directory) full filename-regexp)))
4281
4282 (defun vhdl-add-source-files-menu ()
4283 "Scan directory for all VHDL source files and generate menu.
4284 The directory of the current source file is scanned."
4285 (interactive)
4286 (message "Scanning directory for source files ...")
4287 (let ((newmap (current-local-map))
4288 (file-list (vhdl-get-source-files))
4289 menu-list found)
4290 ;; Create list for menu
4291 (setq found nil)
4292 (while file-list
4293 (setq found t)
4294 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4295 menu-list)
4296 (setq file-list (cdr file-list)))
4297 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4298 (when found (push "--" menu-list))
4299 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4300 (push "Sources" menu-list)
4301 ;; Create menu
4302 (easy-menu-add menu-list)
4303 (easy-menu-define vhdl-sources-menu newmap
4304 "VHDL source files menu" menu-list))
4305 (message ""))
4306
4307
4308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4309 ;;; Mode definition
4310 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4311 ;; performs all buffer local initializations
4312
4313 ;;;###autoload
4314 (define-derived-mode vhdl-mode prog-mode
4315 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4316 (vhdl-electric-mode "e")
4317 (vhdl-stutter-mode "s"))
4318 "Major mode for editing VHDL code.
4319
4320 Usage:
4321 ------
4322
4323 TEMPLATE INSERTION (electrification):
4324 After typing a VHDL keyword and entering `SPC', you are prompted for
4325 arguments while a template is generated for that VHDL construct. Typing
4326 `RET' or `C-g' at the first (mandatory) prompt aborts the current
4327 template generation. Optional arguments are indicated by square
4328 brackets and removed if the queried string is left empty. Prompts for
4329 mandatory arguments remain in the code if the queried string is left
4330 empty. They can be queried again by `C-c C-t C-q'. Enabled
4331 electrification is indicated by `/e' in the mode line.
4332
4333 Typing `M-SPC' after a keyword inserts a space without calling the
4334 template generator. Automatic template generation (i.e.
4335 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4336 setting option `vhdl-electric-mode' (see OPTIONS).
4337
4338 Template generators can be invoked from the VHDL menu, by key
4339 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4340 the keyword (i.e. first word of menu entry not in parenthesis) and
4341 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4342 conf, comp, cons, func, inst, pack, sig, var.
4343
4344 Template styles can be customized in customization group
4345 `vhdl-template' (see OPTIONS).
4346
4347
4348 HEADER INSERTION:
4349 A file header can be inserted by `C-c C-t C-h'. A file footer
4350 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4351 See customization group `vhdl-header'.
4352
4353
4354 STUTTERING:
4355 Double striking of some keys inserts cumbersome VHDL syntax elements.
4356 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4357 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4358 the mode line. The stuttering keys and their effects are:
4359
4360 ;; --> \" : \" [ --> ( -- --> comment
4361 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4362 .. --> \" => \" ] --> ) --- --> horizontal line
4363 ,, --> \" <= \" ]] --> ] ---- --> display comment
4364 == --> \" == \" \\='\\=' --> \\\"
4365
4366
4367 WORD COMPLETION:
4368 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4369 word in the buffer that starts alike, inserts it and adjusts case.
4370 Re-typing `TAB' toggles through alternative word completions. This also
4371 works in the minibuffer (i.e. in template generator prompts).
4372
4373 Typing `TAB' after `(' looks for and inserts complete parenthesized
4374 expressions (e.g. for array index ranges). All keywords as well as
4375 standard types and subprograms of VHDL have predefined abbreviations
4376 (e.g., type \"std\" and `TAB' will toggle through all standard types
4377 beginning with \"std\").
4378
4379 Typing `TAB' after a non-word character indents the line if at the
4380 beginning of a line (i.e. no preceding non-blank characters), and
4381 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4382 stop.
4383
4384
4385 COMMENTS:
4386 `--' puts a single comment.
4387 `---' draws a horizontal line for separating code segments.
4388 `----' inserts a display comment, i.e. two horizontal lines
4389 with a comment in between.
4390 `--CR' comments out code on that line. Re-hitting CR comments
4391 out following lines.
4392 `C-c C-c' comments out a region if not commented out,
4393 uncomments a region if already commented out. Option
4394 `comment-style' defines where the comment characters
4395 should be placed (beginning of line, indent, etc.).
4396
4397 You are prompted for comments after object definitions (i.e. signals,
4398 variables, constants, ports) and after subprogram and process
4399 specifications if option `vhdl-prompt-for-comments' is non-nil.
4400 Comments are automatically inserted as additional labels (e.g. after
4401 begin statements) and as help comments if `vhdl-self-insert-comments' is
4402 non-nil.
4403
4404 Inline comments (i.e. comments after a piece of code on the same line)
4405 are indented at least to `vhdl-inline-comment-column'. Comments go at
4406 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4407 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4408 in a comment automatically opens a new comment line. `M-q' re-fills
4409 multi-line comments.
4410
4411
4412 INDENTATION:
4413 `TAB' indents a line if at the beginning of the line. The amount of
4414 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4415 always indents the current line (is bound to `TAB' if option
4416 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4417 the entire region.
4418
4419 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4420 (`M-C-\\') or the entire buffer (menu). Argument and port lists are
4421 indented normally (nil) or relative to the opening parenthesis (non-nil)
4422 according to option `vhdl-argument-list-indent'.
4423
4424 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4425 tabs. `\\[tabify]' and `\\[untabify]' allow to convert spaces to tabs
4426 and vice versa.
4427
4428 Syntax-based indentation can be very slow in large files. Option
4429 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4430
4431 Option `vhdl-indent-comment-like-next-code-line' controls whether
4432 comment lines are indented like the preceding or like the following code
4433 line.
4434
4435
4436 ALIGNMENT:
4437 The alignment functions align operators, keywords, and inline comments
4438 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4439 separated by blank lines, `C-c C-a C-i' a block of lines with same
4440 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4441 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4442 C-a C-d' all lines within the declarative part of a design unit. `C-c
4443 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4444 for a group of lines, and `C-c C-a M-c' for a region.
4445
4446 If option `vhdl-align-groups' is non-nil, groups of code lines
4447 separated by special lines (see option `vhdl-align-group-separate') are
4448 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4449 blocks of lines with same indent are aligned separately. Some templates
4450 are automatically aligned after generation if option `vhdl-auto-align'
4451 is non-nil.
4452
4453 Alignment tries to align inline comments at
4454 `vhdl-inline-comment-column' and tries inline comment not to exceed
4455 `vhdl-end-comment-column'.
4456
4457 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4458 symbols are surrounded by one space, and multiple spaces are eliminated.
4459
4460
4461 CODE FILLING:
4462 Code filling allows you to condense code (e.g. sensitivity lists or port
4463 maps) by removing comments and newlines and re-wrapping so that all
4464 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4465 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4466 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4467 `C-c C-f M-f' an entire region.
4468
4469
4470 CODE BEAUTIFICATION:
4471 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4472 buffer respectively. This includes indentation, alignment, and case
4473 fixing. Code beautification can also be run non-interactively using the
4474 command:
4475
4476 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4477
4478
4479 PORT TRANSLATION:
4480 Generic and port clauses from entity or component declarations can be
4481 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4482 as component instantiations and corresponding internal constants and
4483 signals, as a generic map with constants as actual generics, and as
4484 internal signal initializations (menu).
4485
4486 To include formals in component instantiations, see option
4487 `vhdl-association-list-with-formals'. To include comments in pasting,
4488 see options `vhdl-include-...-comments'.
4489
4490 A clause with several generic/port names on the same line can be
4491 flattened (`C-c C-p C-f') so that only one name per line exists. The
4492 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4493 outputs and vice versa, which can be useful in testbenches. (This
4494 reversion is done on the internal data structure and is only reflected
4495 in subsequent paste operations.)
4496
4497 Names for actual ports, instances, testbenches, and
4498 design-under-test instances can be derived from existing names according
4499 to options `vhdl-...-name'. See customization group `vhdl-port'.
4500
4501
4502 SUBPROGRAM TRANSLATION:
4503 Similar functionality exists for copying/pasting the interface of
4504 subprograms (function/procedure). A subprogram interface can be copied
4505 and then pasted as a subprogram declaration, body or call (uses
4506 association list with formals).
4507
4508
4509 TESTBENCH GENERATION:
4510 A copied port can also be pasted as a testbench. The generated
4511 testbench includes an entity, an architecture, and an optional
4512 configuration. The architecture contains the component declaration and
4513 instantiation of the DUT as well as internal constant and signal
4514 declarations. Additional user-defined templates can be inserted. The
4515 names used for entity/architecture/configuration/DUT as well as the file
4516 structure to be generated can be customized. See customization group
4517 `vhdl-testbench'.
4518
4519
4520 KEY BINDINGS:
4521 Key bindings (`C-c ...') exist for most commands (see in menu).
4522
4523
4524 VHDL MENU:
4525 All commands can be found in the VHDL menu including their key bindings.
4526
4527
4528 FILE BROWSER:
4529 The speedbar allows browsing of directories and file contents. It can
4530 be accessed from the VHDL menu and is automatically opened if option
4531 `vhdl-speedbar-auto-open' is non-nil.
4532
4533 In speedbar, open files and directories with `mouse-2' on the name and
4534 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4535
4536
4537 DESIGN HIERARCHY BROWSER:
4538 The speedbar can also be used for browsing the hierarchy of design units
4539 contained in the source files of the current directory or the specified
4540 projects (see option `vhdl-project-alist').
4541
4542 The speedbar can be switched between file, directory hierarchy and
4543 project hierarchy browsing mode in the speedbar menu or by typing `f',
4544 `h' or `H' in speedbar.
4545
4546 In speedbar, open design units with `mouse-2' on the name and browse
4547 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4548 from entities and components (in packages). Individual design units and
4549 complete designs can directly be compiled (\"Make\" menu entry).
4550
4551 The hierarchy is automatically updated upon saving a modified source
4552 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4553 hierarchy is only updated for projects that have been opened once in the
4554 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4555 options in group `vhdl-speedbar').
4556
4557 Simple design consistency checks are done during scanning, such as
4558 multiple declarations of the same unit or missing primary units that are
4559 required by secondary units.
4560
4561
4562 STRUCTURAL COMPOSITION:
4563 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4564 for a new component. Subcomponents (i.e. component declaration and
4565 instantiation) can be automatically placed from a previously read port
4566 (`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4567 all subcomponents can be automatically connected using internal signals
4568 and ports (`C-c C-m C-w') following these rules:
4569 - subcomponent actual ports with same name are considered to be
4570 connected by a signal (internal signal or port)
4571 - signals that are only inputs to subcomponents are considered as
4572 inputs to this component -> input port created
4573 - signals that are only outputs from subcomponents are considered as
4574 outputs from this component -> output port created
4575 - signals that are inputs to AND outputs from subcomponents are
4576 considered as internal connections -> internal signal created
4577
4578 Purpose: With appropriate naming conventions it is possible to
4579 create higher design levels with only a few mouse clicks or key
4580 strokes. A new design level can be created by simply generating a new
4581 component, placing the required subcomponents from the hierarchy
4582 browser, and wiring everything automatically.
4583
4584 Note: Automatic wiring only works reliably on templates of new
4585 components and component instantiations that were created by VHDL mode.
4586
4587 Component declarations can be placed in a components package (option
4588 `vhdl-use-components-package') which can be automatically generated for
4589 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4590 component instantiation is also supported (option
4591 `vhdl-use-direct-instantiation').
4592
4593 Configuration declarations can automatically be generated either from
4594 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4595 the speedbar menu (for the architecture under the cursor). The
4596 configurations can optionally be hierarchical (i.e. include all
4597 component levels of a hierarchical design, option
4598 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4599 (option `vhdl-compose-configuration-use-subconfiguration'). For
4600 subcomponents in hierarchical configurations, the most-recently-analyzed
4601 (mra) architecture is selected. If another architecture is desired, it
4602 can be marked as most-recently-analyzed (speedbar menu) before
4603 generating the configuration.
4604
4605 Note: Configurations of subcomponents (i.e. hierarchical configuration
4606 declarations) are currently not considered when displaying
4607 configurations in speedbar.
4608
4609 See the options group `vhdl-compose' for all relevant user options.
4610
4611
4612 SOURCE FILE COMPILATION:
4613 The syntax of the current buffer can be analyzed by calling a VHDL
4614 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4615 option `vhdl-compiler'. The available compilers are listed in option
4616 `vhdl-compiler-alist' including all required compilation command,
4617 command options, compilation directory, and error message syntax
4618 information. New compilers can be added.
4619
4620 All the source files of an entire design can be compiled by the `make'
4621 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4622
4623
4624 MAKEFILE GENERATION:
4625 Makefiles can be generated automatically by an internal generation
4626 routine (`C-c M-k'). The library unit dependency information is
4627 obtained from the hierarchy browser. Makefile generation can be
4628 customized for each compiler in option `vhdl-compiler-alist'.
4629
4630 Makefile generation can also be run non-interactively using the
4631 command:
4632
4633 emacs -batch -l ~/.emacs -l vhdl-mode
4634 [-compiler compilername] [-project projectname]
4635 -f vhdl-generate-makefile
4636
4637 The Makefile's default target \"all\" compiles the entire design, the
4638 target \"clean\" removes it and the target \"library\" creates the
4639 library directory if not existent. These target names can be customized
4640 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4641 target for each primary library unit which allows selective compilation
4642 of this unit, its secondary units and its subhierarchy (example:
4643 compilation of a design specified by a configuration). User specific
4644 parts can be inserted into a Makefile with option
4645 `vhdl-makefile-generation-hook'.
4646
4647 Limitations:
4648 - Only library units and dependencies within the current library are
4649 considered. Makefiles for designs that span multiple libraries are
4650 not (yet) supported.
4651 - Only one-level configurations are supported (also hierarchical),
4652 but configurations that go down several levels are not.
4653 - The \"others\" keyword in configurations is not supported.
4654
4655
4656 PROJECTS:
4657 Projects can be defined in option `vhdl-project-alist' and a current
4658 project be selected using option `vhdl-project' (permanently) or from
4659 the menu or speedbar (temporarily). For each project, title and
4660 description strings (for the file headers), source files/directories
4661 (for the hierarchy browser and Makefile generation), library name, and
4662 compiler-dependent options, exceptions and compilation directory can be
4663 specified. Compilation settings overwrite the settings of option
4664 `vhdl-compiler-alist'.
4665
4666 Project setups can be exported (i.e. written to a file) and imported.
4667 Imported setups are not automatically saved in `vhdl-project-alist' but
4668 can be saved afterwards in its customization buffer. When starting
4669 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4670 vhdl-mode\") in a directory with an existing project setup file, it is
4671 automatically loaded and its project activated if option
4672 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4673 files can be specified in option `vhdl-project-file-name'. Multiple
4674 project setups can be automatically loaded from global directories.
4675 This is an alternative to specifying project setups with option
4676 `vhdl-project-alist'.
4677
4678
4679 SPECIAL MENUES:
4680 As an alternative to the speedbar, an index menu can be added (set
4681 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4682 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4683 file) for browsing the file contents (is not populated if buffer is
4684 larger than 256000). Also, a source file menu can be
4685 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4686 current directory for VHDL source files.
4687
4688
4689 VHDL STANDARDS:
4690 The VHDL standards to be used are specified in option `vhdl-standard'.
4691 Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
4692
4693
4694 KEYWORD CASE:
4695 Lower and upper case for keywords and standardized types, attributes,
4696 and enumeration values is supported. If the option
4697 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4698 lower case and are converted into upper case automatically (not for
4699 types, attributes, and enumeration values). The case of keywords,
4700 types, attributes,and enumeration values can be fixed for an entire
4701 region (menu) or buffer (`C-c C-x C-c') according to the options
4702 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4703
4704
4705 HIGHLIGHTING (fontification):
4706 Keywords and standardized types, attributes, enumeration values, and
4707 function names (controlled by option `vhdl-highlight-keywords'), as well
4708 as comments, strings, and template prompts are highlighted using
4709 different colors. Unit, subprogram, signal, variable, constant,
4710 parameter and generic/port names in declarations as well as labels are
4711 highlighted if option `vhdl-highlight-names' is non-nil.
4712
4713 Additional reserved words or words with a forbidden syntax (e.g. words
4714 that should be avoided) can be specified in option
4715 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4716 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4717 keywords are highlighted as forbidden words if option
4718 `vhdl-highlight-verilog-keywords' is non-nil.
4719
4720 Words with special syntax can be highlighted by specifying their
4721 syntax and color in option `vhdl-special-syntax-alist' and by setting
4722 option `vhdl-highlight-special-words' to non-nil. This allows you to
4723 establish some naming conventions (e.g. to distinguish different kinds
4724 of signals or other objects by using name suffices) and to support them
4725 visually.
4726
4727 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4728 to support case-sensitive highlighting. However, keywords are then only
4729 highlighted if written in lower case.
4730
4731 Code between \"translate_off\" and \"translate_on\" pragmas is
4732 highlighted using a different background color if option
4733 `vhdl-highlight-translate-off' is non-nil.
4734
4735 For documentation and customization of the used colors see
4736 customization group `vhdl-highlight-faces' (`\\[customize-group]'). For
4737 highlighting of matching parenthesis, see customization group
4738 `paren-showing'. Automatic buffer highlighting is turned on/off by
4739 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4740
4741
4742 USER MODELS:
4743 VHDL models (templates) can be specified by the user and made accessible
4744 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4745 electrification. See option `vhdl-model-alist'.
4746
4747
4748 HIDE/SHOW:
4749 The code of blocks, processes, subprograms, component declarations and
4750 instantiations, generic/port clauses, and configuration declarations can
4751 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4752 the code (see customization group `vhdl-menu'). XEmacs: limited
4753 functionality due to old `hideshow.el' package.
4754
4755
4756 CODE UPDATING:
4757 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4758 current process, `C-c C-u M-s' of all processes in the current buffer.
4759 Limitations:
4760 - Only declared local signals (ports, signals declared in
4761 architecture and blocks) are automatically inserted.
4762 - Global signals declared in packages are not automatically inserted.
4763 Insert them once manually (will be kept afterwards).
4764 - Out parameters of procedures are considered to be read.
4765 Use option `vhdl-entity-file-name' to specify the entity file name
4766 (used to obtain the port names).
4767 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4768 specify whether to include array indices and record fields in
4769 sensitivity lists.
4770
4771
4772 CODE FIXING:
4773 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4774 (e.g., if the closing parenthesis is on the wrong line or is missing).
4775
4776
4777 PRINTING:
4778 PostScript printing with different faces (an optimized set of faces is
4779 used if `vhdl-print-customize-faces' is non-nil) or colors (if
4780 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4781 PostScript printing commands. Option `vhdl-print-two-column' defines
4782 appropriate default settings for nice landscape two-column printing.
4783 The paper format can be set by option `ps-paper-type'. Do not forget to
4784 switch `ps-print-color-p' to nil for printing on black-and-white
4785 printers.
4786
4787
4788 OPTIONS:
4789 User options allow customization of VHDL Mode. All options are
4790 accessible from the \"Options\" menu entry. Simple options (switches
4791 and choices) can directly be changed, while for complex options a
4792 customization buffer is opened. Changed options can be saved for future
4793 sessions using the \"Save Options\" menu entry.
4794
4795 Options and their detailed descriptions can also be accessed by using
4796 the \"Customize\" menu entry or the command `\\[customize-option]'
4797 (`\\[customize-group]' for groups). Some customizations only take effect
4798 after some action (read the NOTE in the option documentation).
4799 Customization can also be done globally (i.e. site-wide, read the
4800 INSTALL file).
4801
4802 Not all options are described in this documentation, so go and see
4803 what other useful user options there are (`\\[vhdl-customize]' or menu)!
4804
4805
4806 FILE EXTENSIONS:
4807 As default, files with extensions \".vhd\" and \".vhdl\" are
4808 automatically recognized as VHDL source files. To add an extension
4809 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4810
4811 (push \\='(\"\\\\.xxx\\\\\\='\" . vhdl-mode) auto-mode-alist)
4812
4813
4814 HINTS:
4815 - To start Emacs with open VHDL hierarchy browser without having to load
4816 a VHDL file first, use the command:
4817
4818 emacs -l vhdl-mode -f speedbar-frame-mode
4819
4820 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4821
4822 - Some features only work on properly indented code.
4823
4824
4825 RELEASE NOTES:
4826 See also the release notes (menu) for added features in new releases.
4827
4828
4829 Maintenance:
4830 ------------
4831
4832 To submit a bug report, enter `\\[vhdl-submit-bug-report]' within VHDL Mode.
4833 Add a description of the problem and include a reproducible test case.
4834
4835 Questions and enhancement requests can be sent to <reto@gnu.org>.
4836
4837 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4838 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4839 releases. You are kindly invited to participate in beta testing. Subscribe
4840 to above mailing lists by sending an email to <reto@gnu.org>.
4841
4842 VHDL Mode is officially distributed at
4843 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4844 where the latest version can be found.
4845
4846
4847 Known problems:
4848 ---------------
4849
4850 - XEmacs: Incorrect start-up when automatically opening speedbar.
4851 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4852 - Indentation incorrect for new 'postponed' VHDL keyword.
4853 - Indentation incorrect for 'protected body' construct.
4854
4855
4856 The VHDL Mode Authors
4857 Reto Zimmermann and Rod Whitby
4858
4859 Key bindings:
4860 -------------
4861
4862 \\{vhdl-mode-map}"
4863 :abbrev-table vhdl-mode-abbrev-table
4864
4865 ;; set local variables
4866 (set (make-local-variable 'paragraph-start)
4867 "\\s-*\\(--+\\s-*$\\|$\\)")
4868 (set (make-local-variable 'paragraph-separate) paragraph-start)
4869 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4870 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4871 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4872 (set (make-local-variable 'comment-start) "--")
4873 (set (make-local-variable 'comment-end) "")
4874 (when vhdl-emacs-21
4875 (set (make-local-variable 'comment-padding) ""))
4876 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4877 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4878 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4879 (set (make-local-variable 'comment-multi-line) nil)
4880 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4881 (set (make-local-variable 'hippie-expand-verbose) nil)
4882
4883 ;; setup the comment indent variable in a Emacs version portable way
4884 ;; ignore any byte compiler warnings you might get here
4885 (when (boundp 'comment-indent-function)
4886 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4887
4888 ;; initialize font locking
4889 (set (make-local-variable 'font-lock-defaults)
4890 (list
4891 '(nil vhdl-font-lock-keywords) nil
4892 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4893 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4894 (set (make-local-variable 'syntax-propertize-function)
4895 (syntax-propertize-rules
4896 ;; Mark single quotes as having string quote syntax in
4897 ;; 'c' instances.
4898 ("\\('\\).\\('\\)" (1 "\"'") (2 "\"'"))))
4899 (set (make-local-variable 'font-lock-syntactic-keywords)
4900 vhdl-font-lock-syntactic-keywords))
4901 (unless vhdl-emacs-21
4902 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4903 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4904 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4905 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4906
4907 ;; variables for source file compilation
4908 (when vhdl-compile-use-local-error-regexp
4909 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4910 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4911
4912 ;; add index menu
4913 (vhdl-index-menu-init)
4914 ;; add source file menu
4915 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4916 ;; add VHDL menu
4917 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4918 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4919 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4920 ;; initialize hideshow and add menu
4921 (vhdl-hideshow-init)
4922 (run-hooks 'menu-bar-update-hook)
4923
4924 ;; miscellaneous
4925 (vhdl-ps-print-init)
4926 (vhdl-write-file-hooks-init)
4927 (message "VHDL Mode %s.%s" vhdl-version
4928 (if noninteractive "" " See menu for documentation and release notes.")))
4929
4930 (defun vhdl-activate-customizations ()
4931 "Activate all customizations on local variables."
4932 (interactive)
4933 (vhdl-mode-map-init)
4934 (use-local-map vhdl-mode-map)
4935 (set-syntax-table vhdl-mode-syntax-table)
4936 (setq comment-column vhdl-inline-comment-column)
4937 (setq end-comment-column vhdl-end-comment-column)
4938 (vhdl-write-file-hooks-init)
4939 (vhdl-update-mode-menu)
4940 (vhdl-hideshow-init)
4941 (run-hooks 'menu-bar-update-hook))
4942
4943 (defun vhdl-write-file-hooks-init ()
4944 "Add/remove hooks when buffer is saved."
4945 (if vhdl-modify-date-on-saving
4946 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4947 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4948 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4949 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4950
4951 (defun vhdl-process-command-line-option (option)
4952 "Process command line options for VHDL Mode."
4953 (cond
4954 ;; set compiler
4955 ((equal option "-compiler")
4956 (vhdl-set-compiler (car command-line-args-left))
4957 (setq command-line-args-left (cdr command-line-args-left)))
4958 ;; set project
4959 ((equal option "-project")
4960 (vhdl-set-project (car command-line-args-left))
4961 (setq command-line-args-left (cdr command-line-args-left)))))
4962
4963 ;; make Emacs process VHDL Mode options
4964 (setq command-switch-alist
4965 (append command-switch-alist
4966 '(("-compiler" . vhdl-process-command-line-option)
4967 ("-project" . vhdl-process-command-line-option))))
4968
4969
4970 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4971 ;;; Keywords and standardized words
4972 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4973
4974 (defconst vhdl-02-keywords
4975 '(
4976 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4977 "assert" "attribute"
4978 "begin" "block" "body" "buffer" "bus"
4979 "case" "component" "configuration" "constant"
4980 "disconnect" "downto"
4981 "else" "elsif" "end" "entity" "exit"
4982 "file" "for" "function"
4983 "generate" "generic" "group" "guarded"
4984 "if" "impure" "in" "inertial" "inout" "is"
4985 "label" "library" "linkage" "literal" "loop"
4986 "map" "mod"
4987 "nand" "new" "next" "nor" "not" "null"
4988 "of" "on" "open" "or" "others" "out"
4989 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4990 "range" "record" "register" "reject" "rem" "report" "return"
4991 "rol" "ror"
4992 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4993 "then" "to" "transport" "type"
4994 "unaffected" "units" "until" "use"
4995 "variable"
4996 "wait" "when" "while" "with"
4997 "xnor" "xor"
4998 )
4999 "List of VHDL'02 keywords.")
5000
5001 (defconst vhdl-08-keywords
5002 '(
5003 "context" "force" "property" "release" "sequence"
5004 )
5005 "List of VHDL'08 keywords.")
5006
5007 (defconst vhdl-ams-keywords
5008 '(
5009 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
5010 "reference" "spectrum" "subnature" "terminal" "through"
5011 "tolerance"
5012 )
5013 "List of VHDL-AMS keywords.")
5014
5015 (defconst vhdl-verilog-keywords
5016 '(
5017 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5018 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5019 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5020 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5021 "endprimitive" "endspecify" "endtable" "endtask" "event"
5022 "for" "force" "forever" "fork" "function"
5023 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5024 "macromodule" "makefile" "medium" "module"
5025 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5026 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5027 "pullup"
5028 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5029 "rtranif0" "rtranif1"
5030 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5031 "strong1" "supply" "supply0" "supply1"
5032 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5033 "triand" "trior" "trireg"
5034 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5035 )
5036 "List of Verilog keywords as candidate for additional reserved words.")
5037
5038 (defconst vhdl-02-types
5039 '(
5040 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5041 "real" "time" "natural" "positive" "string" "line" "text" "side"
5042 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5043 "std_logic" "std_logic_vector"
5044 "std_ulogic" "std_ulogic_vector"
5045 )
5046 "List of VHDL'02 standardized types.")
5047
5048 (defconst vhdl-08-types
5049 '(
5050 "boolean_vector" "integer_vector" "real_vector" "time_vector"
5051 )
5052 "List of VHDL'08 standardized types.")
5053
5054 (defconst vhdl-ams-types
5055 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5056 '(
5057 ;; package `standard'
5058 "domain_type" "real_vector"
5059 ;; package `energy_systems'
5060 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5061 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5062 "real_across_vector" "real_through_vector"
5063 ;; package `electrical_systems'
5064 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5065 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5066 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5067 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5068 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5069 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5070 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5071 "electric_flux_density_vector" "electric_field_strength_vector"
5072 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5073 "inductance_vector" "reluctance_vector" "ground"
5074 ;; package `mechanical_systems'
5075 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5076 "damping" "momentum" "angle" "torque" "angular_velocity"
5077 "angular_acceleration" "moment_inertia" "angular_momentum"
5078 "angular_stiffness" "angular_damping" "translational"
5079 "translational_vector" "translational_velocity"
5080 "translational_velocity_vector" "rotational" "rotational_vector"
5081 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5082 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5083 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5084 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5085 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5086 "angular_momentum_vector" "angular_stiffness_vector"
5087 "angular_damping_vector" "anchor" "translational_v_ref"
5088 "rotational_v_ref" "translational_v" "rotational_v"
5089 ;; package `radiant_systems'
5090 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5091 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5092 "illuminance_vector" "irradiance_vector"
5093 ;; package `thermal_systems'
5094 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5095 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5096 "heat_flow_vector" "thermal_capacitance_vector"
5097 "thermal_resistance_vector" "thermal_conductance_vector"
5098 ;; package `fluidic_systems'
5099 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5100 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5101 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5102 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5103 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5104 "density_vector" "viscosity_vector" "fresistance_vector"
5105 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5106 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5107 "cfinertance_vector"
5108 )
5109 "List of VHDL-AMS standardized types.")
5110
5111 (defconst vhdl-math-types
5112 '(
5113 "complex" "complex_polar" "positive_real" "principal_value"
5114 )
5115 "List of Math Packages standardized types.")
5116
5117 (defconst vhdl-02-attributes
5118 '(
5119 "base" "left" "right" "high" "low" "pos" "val" "succ"
5120 "pred" "leftof" "rightof" "range" "reverse_range"
5121 "length" "delayed" "stable" "quiet" "transaction"
5122 "event" "active" "last_event" "last_active" "last_value"
5123 "driving" "driving_value" "ascending" "value" "image"
5124 "simple_name" "instance_name" "path_name"
5125 "foreign"
5126 )
5127 "List of VHDL'02 standardized attributes.")
5128
5129 (defconst vhdl-08-attributes
5130 '(
5131 "instance_name" "path_name"
5132 )
5133 "List of VHDL'08 standardized attributes.")
5134
5135 (defconst vhdl-ams-attributes
5136 '(
5137 "across" "through"
5138 "reference" "contribution" "tolerance"
5139 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5140 "ramp" "slew"
5141 )
5142 "List of VHDL-AMS standardized attributes.")
5143
5144 (defconst vhdl-02-enum-values
5145 '(
5146 "true" "false"
5147 "note" "warning" "error" "failure"
5148 "read_mode" "write_mode" "append_mode"
5149 "open_ok" "status_error" "name_error" "mode_error"
5150 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5151 "right" "left"
5152 )
5153 "List of VHDL'02 standardized enumeration values.")
5154
5155 (defconst vhdl-ams-enum-values
5156 '(
5157 "quiescent_domain" "time_domain" "frequency_domain"
5158 ;; from `nature_pkg' package
5159 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5160 )
5161 "List of VHDL-AMS standardized enumeration values.")
5162
5163 (defconst vhdl-ams-constants
5164 ;; standard: IEEE Std 1076.1.1-2004
5165 '(
5166 ;; package `fundamental_constants'
5167 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5168 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5169 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5170 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5171 ;; package `material_constants'
5172 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5173 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5174 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5175 )
5176 "List of VHDL-AMS standardized constants.")
5177
5178 (defconst vhdl-math-constants
5179 ;; standard: IEEE Std 1076.2-1996
5180 '(
5181 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5182 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5183 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5184 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5185 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5186 "math_sqrt_pi"
5187 )
5188 "List of Math Packages standardized constants.")
5189
5190 (defconst vhdl-02-functions
5191 '(
5192 "now" "resolved" "rising_edge" "falling_edge"
5193 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5194 "endfile"
5195 "resize" "is_X" "std_match"
5196 "shift_left" "shift_right" "rotate_left" "rotate_right"
5197 "to_unsigned" "to_signed" "to_integer"
5198 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5199 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5200 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5201 "shl" "shr" "ext" "sxt"
5202 "deallocate"
5203 )
5204 "List of VHDL'02 standardized functions.")
5205
5206 (defconst vhdl-08-functions
5207 '(
5208 "finish" "flush" "justify" "maximum" "minimum"
5209 "resolution_limit" "rising_edge" "stop" "swrite"
5210 "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
5211 "to_octalstring" "to_ostring" "to_string"
5212 )
5213 "List of VHDL'08 standardized functions.")
5214
5215 (defconst vhdl-ams-functions
5216 '(
5217 ;; package `standard'
5218 "frequency"
5219 )
5220 "List of VHDL-AMS standardized functions.")
5221
5222 (defconst vhdl-math-functions
5223 ;; standard: IEEE Std 1076.2-1996
5224 '(
5225 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5226 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5227 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5228 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5229 "tan" "tanh" "trunc" "uniform"
5230 )
5231 "List of Math Packages standardized functions.")
5232
5233 (defconst vhdl-02-packages
5234 '(
5235 "std_logic_1164" "numeric_std" "numeric_bit"
5236 "standard" "textio"
5237 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5238 "std_logic_misc" "std_logic_textio"
5239 "ieee" "std" "work"
5240 )
5241 "List of VHDL'02 standardized packages and libraries.")
5242
5243 (defconst vhdl-08-packages
5244 '(
5245 "env" "numeric_std_signed" "numeric_std_unsigned"
5246 "ieee_bit_context" "ieee_std_context" ;; contexts
5247 )
5248 "List of VHDL'08 standardized packages and libraries.")
5249
5250 (defconst vhdl-ams-packages
5251 '(
5252 "fundamental_constants" "material_constants" "energy_systems"
5253 "electrical_systems" "mechanical_systems" "radiant_systems"
5254 "thermal_systems" "fluidic_systems"
5255 )
5256 "List of VHDL-AMS standardized packages and libraries.")
5257
5258 (defconst vhdl-math-packages
5259 '(
5260 "math_real" "math_complex"
5261 )
5262 "List of Math Packages standardized packages and libraries.")
5263
5264 (defconst vhdl-08-directives
5265 '(
5266 "author" "author_info" "begin" "begin_protected" "comment"
5267 "data_block" "data_keyname" "data_keyowner" "data_method"
5268 "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
5269 "digest_keyowner" "digest_method"
5270 "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
5271 "key_block" "key_keyname" "key_keyowner" "key_method"
5272 "runtime_license" "viewport"
5273 )
5274 "List of VHDL'08 standardized tool directives.")
5275
5276 (defvar vhdl-keywords nil
5277 "List of VHDL keywords.")
5278
5279 (defvar vhdl-types nil
5280 "List of VHDL standardized types.")
5281
5282 (defvar vhdl-attributes nil
5283 "List of VHDL standardized attributes.")
5284
5285 (defvar vhdl-enum-values nil
5286 "List of VHDL standardized enumeration values.")
5287
5288 (defvar vhdl-constants nil
5289 "List of VHDL standardized constants.")
5290
5291 (defvar vhdl-functions nil
5292 "List of VHDL standardized functions.")
5293
5294 (defvar vhdl-packages nil
5295 "List of VHDL standardized packages and libraries.")
5296
5297 (defvar vhdl-directives nil
5298 "List of VHDL standardized packages and libraries.")
5299
5300 (defvar vhdl-reserved-words nil
5301 "List of additional reserved words.")
5302
5303 (defvar vhdl-keywords-regexp nil
5304 "Regexp for VHDL keywords.")
5305
5306 (defvar vhdl-types-regexp nil
5307 "Regexp for VHDL standardized types.")
5308
5309 (defvar vhdl-attributes-regexp nil
5310 "Regexp for VHDL standardized attributes.")
5311
5312 (defvar vhdl-enum-values-regexp nil
5313 "Regexp for VHDL standardized enumeration values.")
5314
5315 (defvar vhdl-constants-regexp nil
5316 "Regexp for VHDL standardized constants.")
5317
5318 (defvar vhdl-functions-regexp nil
5319 "Regexp for VHDL standardized functions.")
5320
5321 (defvar vhdl-packages-regexp nil
5322 "Regexp for VHDL standardized packages and libraries.")
5323
5324 (defvar vhdl-reserved-words-regexp nil
5325 "Regexp for additional reserved words.")
5326
5327 (defvar vhdl-directive-keywords-regexp nil
5328 "Regexp for compiler directive keywords.")
5329
5330 (defun vhdl-upcase-list (condition list)
5331 "Upcase all elements in LIST based on CONDITION."
5332 (when condition
5333 (let ((tmp-list list))
5334 (while tmp-list
5335 (setcar tmp-list (upcase (car tmp-list)))
5336 (setq tmp-list (cdr tmp-list)))))
5337 list)
5338
5339 (defun vhdl-words-init ()
5340 "Initialize reserved words."
5341 (setq vhdl-keywords
5342 (vhdl-upcase-list
5343 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5344 (append vhdl-02-keywords
5345 (when (vhdl-standard-p '08) vhdl-08-keywords)
5346 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5347 (setq vhdl-types
5348 (vhdl-upcase-list
5349 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5350 (append vhdl-02-types
5351 (when (vhdl-standard-p '08) vhdl-08-types)
5352 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5353 (when (vhdl-standard-p 'math) vhdl-math-types))))
5354 (setq vhdl-attributes
5355 (vhdl-upcase-list
5356 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5357 (append vhdl-02-attributes
5358 (when (vhdl-standard-p '08) vhdl-08-attributes)
5359 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5360 (setq vhdl-enum-values
5361 (vhdl-upcase-list
5362 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5363 (append vhdl-02-enum-values
5364 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5365 (setq vhdl-constants
5366 (vhdl-upcase-list
5367 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5368 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5369 (when (vhdl-standard-p 'math) vhdl-math-constants)
5370 '(""))))
5371 (setq vhdl-functions
5372 (append vhdl-02-functions
5373 (when (vhdl-standard-p '08) vhdl-08-functions)
5374 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5375 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5376 (setq vhdl-packages
5377 (append vhdl-02-packages
5378 (when (vhdl-standard-p '08) vhdl-08-packages)
5379 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5380 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5381 (setq vhdl-directives
5382 (append (when (vhdl-standard-p '08) vhdl-08-directives)))
5383 (setq vhdl-reserved-words
5384 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5385 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5386 '("")))
5387 (setq vhdl-keywords-regexp
5388 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5389 (setq vhdl-types-regexp
5390 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5391 (setq vhdl-attributes-regexp
5392 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5393 (setq vhdl-enum-values-regexp
5394 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5395 (setq vhdl-constants-regexp
5396 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5397 (setq vhdl-functions-regexp
5398 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5399 (setq vhdl-packages-regexp
5400 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5401 (setq vhdl-reserved-words-regexp
5402 (concat "\\<\\("
5403 (unless (equal vhdl-forbidden-syntax "")
5404 (concat vhdl-forbidden-syntax "\\|"))
5405 (regexp-opt vhdl-reserved-words)
5406 "\\)\\>"))
5407 (setq vhdl-directive-keywords-regexp
5408 (concat "\\<\\(" (mapconcat 'regexp-quote
5409 vhdl-directive-keywords "\\|") "\\)\\>"))
5410 (vhdl-abbrev-list-init))
5411
5412 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5413 ;; Words to expand
5414
5415 (defvar vhdl-abbrev-list nil
5416 "Predefined abbreviations for VHDL.")
5417
5418 (defun vhdl-abbrev-list-init ()
5419 (setq vhdl-abbrev-list
5420 (append
5421 (list vhdl-upper-case-keywords) vhdl-keywords
5422 (list vhdl-upper-case-types) vhdl-types
5423 (list vhdl-upper-case-attributes) vhdl-attributes
5424 (list vhdl-upper-case-enum-values) vhdl-enum-values
5425 (list vhdl-upper-case-constants) vhdl-constants
5426 (list nil) vhdl-functions
5427 (list nil) vhdl-packages
5428 (list nil) vhdl-directives)))
5429
5430 ;; initialize reserved words for VHDL Mode
5431 (vhdl-words-init)
5432
5433
5434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5435 ;;; Indentation
5436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5437
5438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5439 ;; Syntax analysis
5440
5441 ;; constant regular expressions for looking at various constructs
5442
5443 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5444 "Regexp describing a VHDL symbol.
5445 We cannot use just `word' syntax class since `_' cannot be in word
5446 class. Putting underscore in word class breaks forward word movement
5447 behavior that users are familiar with.")
5448
5449 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5450 "Regexp describing a case statement header key.")
5451
5452 (defconst vhdl-label-key
5453 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5454 "Regexp describing a VHDL label.")
5455
5456 ;; Macro definitions:
5457
5458 (defmacro vhdl-point (position)
5459 "Return the value of point at certain commonly referenced POSITIONs.
5460 POSITION can be one of the following symbols:
5461
5462 bol -- beginning of line
5463 eol -- end of line
5464 bod -- beginning of defun
5465 boi -- back to indentation
5466 eoi -- last whitespace on line
5467 ionl -- indentation of next line
5468 iopl -- indentation of previous line
5469 bonl -- beginning of next line
5470 bopl -- beginning of previous line
5471
5472 This function does not modify point or mark."
5473 (or (and (eq 'quote (car-safe position))
5474 (null (cddr position)))
5475 (error "ERROR: Bad buffer position requested: %s" position))
5476 (setq position (nth 1 position))
5477 `(let ((here (point)))
5478 ,@(cond
5479 ((eq position 'bol) '((beginning-of-line)))
5480 ((eq position 'eol) '((end-of-line)))
5481 ((eq position 'bod) '((save-match-data
5482 (vhdl-beginning-of-defun))))
5483 ((eq position 'boi) '((back-to-indentation)))
5484 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5485 ((eq position 'bonl) '((forward-line 1)))
5486 ((eq position 'bopl) '((forward-line -1)))
5487 ((eq position 'iopl)
5488 '((forward-line -1)
5489 (back-to-indentation)))
5490 ((eq position 'ionl)
5491 '((forward-line 1)
5492 (back-to-indentation)))
5493 (t (error "ERROR: Unknown buffer position requested: %s" position))
5494 )
5495 (prog1
5496 (point)
5497 (goto-char here))
5498 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5499 ;; doesn't hurt for v19
5500 ,@nil
5501 ))
5502
5503 (defmacro vhdl-safe (&rest body)
5504 "Safely execute BODY, return nil if an error occurred."
5505 `(condition-case nil
5506 (progn ,@body)
5507 (error nil)))
5508
5509 (defmacro vhdl-add-syntax (symbol &optional relpos)
5510 "A simple macro to append the syntax in SYMBOL to the syntax list.
5511 Try to increase performance by using this macro."
5512 `(setq vhdl-syntactic-context
5513 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5514
5515 (defmacro vhdl-has-syntax (symbol)
5516 "A simple macro to return check the syntax list.
5517 Try to increase performance by using this macro."
5518 `(assoc ,symbol vhdl-syntactic-context))
5519
5520 ;; Syntactic element offset manipulation:
5521
5522 (defun vhdl-read-offset (langelem)
5523 "Read new offset value for LANGELEM from minibuffer.
5524 Return a valid value only."
5525 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5526 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5527 (prompt "Offset: ")
5528 offset input interned)
5529 (while (not offset)
5530 (setq input (read-string prompt oldoff)
5531 offset (cond ((string-equal "+" input) '+)
5532 ((string-equal "-" input) '-)
5533 ((string-equal "++" input) '++)
5534 ((string-equal "--" input) '--)
5535 ((string-match "^-?[0-9]+$" input)
5536 (string-to-number input))
5537 ((fboundp (setq interned (intern input)))
5538 interned)
5539 ((boundp interned) interned)
5540 ;; error, but don't signal one, keep trying
5541 ;; to read an input value
5542 (t (ding)
5543 (setq prompt errmsg)
5544 nil))))
5545 offset))
5546
5547 (defun vhdl-set-offset (symbol offset &optional add-p)
5548 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5549 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5550 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5551 `vhdl-offsets-alist' if it doesn't already appear there."
5552 (interactive
5553 (let* ((langelem
5554 (intern (completing-read
5555 (concat "Syntactic symbol to change"
5556 (if current-prefix-arg " or add" "")
5557 ": ")
5558 (mapcar
5559 (function
5560 (lambda (langelem)
5561 (cons (format "%s" (car langelem)) nil)))
5562 vhdl-offsets-alist)
5563 nil (not current-prefix-arg)
5564 ;; initial contents tries to be the last element
5565 ;; on the syntactic analysis list for the current
5566 ;; line
5567 (let* ((syntax (vhdl-get-syntactic-context))
5568 (len (length syntax))
5569 (ic (format "%s" (car (nth (1- len) syntax)))))
5570 ic)
5571 )))
5572 (offset (vhdl-read-offset langelem)))
5573 (list langelem offset current-prefix-arg)))
5574 ;; sanity check offset
5575 (or (eq offset '+)
5576 (eq offset '-)
5577 (eq offset '++)
5578 (eq offset '--)
5579 (integerp offset)
5580 (fboundp offset)
5581 (boundp offset)
5582 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5583 offset))
5584 (let ((entry (assq symbol vhdl-offsets-alist)))
5585 (if entry
5586 (setcdr entry offset)
5587 (if add-p
5588 (setq vhdl-offsets-alist
5589 (cons (cons symbol offset) vhdl-offsets-alist))
5590 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5591 (vhdl-keep-region-active))
5592
5593 (defun vhdl-set-style (style &optional local)
5594 "Set `vhdl-mode' variables to use one of several different indentation styles.
5595 STYLE is a string representing the desired style and optional LOCAL is
5596 a flag which, if non-nil, means to make the style variables being
5597 changed buffer local, instead of the default, which is to set the
5598 global variables. Interactively, the flag comes from the prefix
5599 argument. The styles are chosen from the `vhdl-style-alist' variable."
5600 (interactive (list (completing-read "Use which VHDL indentation style? "
5601 vhdl-style-alist nil t)
5602 current-prefix-arg))
5603 (let ((vars (cdr (assoc style vhdl-style-alist))))
5604 (or vars
5605 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5606 ;; set all the variables
5607 (mapc
5608 (function
5609 (lambda (varentry)
5610 (let ((var (car varentry))
5611 (val (cdr varentry)))
5612 ;; special case for vhdl-offsets-alist
5613 (if (not (eq var 'vhdl-offsets-alist))
5614 (set (if local (make-local-variable var) var) val)
5615 ;; reset vhdl-offsets-alist to the default value first
5616 (set (if local (make-local-variable var) var)
5617 (copy-alist vhdl-offsets-alist-default))
5618 ;; now set the langelems that are different
5619 (mapcar
5620 (function
5621 (lambda (langentry)
5622 (let ((langelem (car langentry))
5623 (offset (cdr langentry)))
5624 (vhdl-set-offset langelem offset)
5625 )))
5626 val))
5627 )))
5628 vars))
5629 (vhdl-keep-region-active))
5630
5631 (defun vhdl-get-offset (langelem)
5632 "Get offset from LANGELEM which is a cons cell of the form:
5633 \(SYMBOL . RELPOS). The symbol is matched against
5634 vhdl-offsets-alist and the offset found there is either returned,
5635 or added to the indentation at RELPOS. If RELPOS is nil, then
5636 the offset is simply returned."
5637 (let* ((symbol (car langelem))
5638 (relpos (cdr langelem))
5639 (match (assq symbol vhdl-offsets-alist))
5640 (offset (cdr-safe match)))
5641 ;; offset can be a number, a function, a variable, or one of the
5642 ;; symbols + or -
5643 (cond
5644 ((not match)
5645 (if vhdl-strict-syntax-p
5646 (error "ERROR: Don't know how to indent a %s" symbol)
5647 (setq offset 0
5648 relpos 0)))
5649 ((eq offset '+) (setq offset vhdl-basic-offset))
5650 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5651 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5652 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5653 ((and (not (numberp offset))
5654 (fboundp offset))
5655 (setq offset (funcall offset langelem)))
5656 ((not (numberp offset))
5657 (setq offset (eval offset)))
5658 )
5659 (+ (if (and relpos
5660 (< relpos (vhdl-point 'bol)))
5661 (save-excursion
5662 (goto-char relpos)
5663 (current-column))
5664 0)
5665 offset)))
5666
5667 ;; Syntactic support functions:
5668
5669 (defun vhdl-in-comment-p (&optional pos)
5670 "Check if point is in a comment (include multi-line comments)."
5671 (let ((parse (lambda (p)
5672 (let ((c (char-after p)))
5673 (or (and c (eq (char-syntax c) ?<))
5674 (nth 4 (parse-partial-sexp
5675 (save-excursion
5676 (beginning-of-defun)
5677 (point)) p)))))))
5678 (save-excursion
5679 (goto-char (or pos (point)))
5680 (or (funcall parse (point))
5681 ;; `parse-partial-sexp's notion of comments doesn't span lines
5682 (progn
5683 (back-to-indentation)
5684 (unless (eolp)
5685 (forward-char)
5686 (funcall parse (point))))))))
5687
5688 (defun vhdl-in-string-p ()
5689 "Check if point is in a string."
5690 (eq (vhdl-in-literal) 'string))
5691
5692 (defun vhdl-in-quote-p ()
5693 "Check if point is in a quote ('x')."
5694 (or (and (> (point) (point-min))
5695 (< (1+ (point)) (point-max))
5696 (= (char-before (point)) ?\')
5697 (= (char-after (1+ (point))) ?\'))
5698 (and (> (1- (point)) (point-min))
5699 (< (point) (point-max))
5700 (= (char-before (1- (point))) ?\')
5701 (= (char-after (point)) ?\'))))
5702
5703 (defun vhdl-in-literal ()
5704 "Determine if point is in a VHDL literal."
5705 (save-excursion
5706 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5707 (cond
5708 ((nth 3 state) 'string)
5709 ((nth 4 state) 'comment)
5710 ((vhdl-beginning-of-macro) 'pound)
5711 ((vhdl-beginning-of-directive) 'directive)
5712 ;; for multi-line comments
5713 ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
5714 (t nil)))))
5715
5716 (defun vhdl-in-extended-identifier-p ()
5717 "Determine if point is inside extended identifier (delimited by `\\')."
5718 (save-match-data
5719 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5720 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5721
5722 (defun vhdl-forward-comment (&optional direction)
5723 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5724 negative, skip forward otherwise."
5725 (interactive "p")
5726 (if (and direction (< direction 0))
5727 ;; skip backwards
5728 (progn
5729 (skip-chars-backward " \t\n\r\f")
5730 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5731 (goto-char (match-beginning 3))
5732 (skip-chars-backward " \t\n\r\f")))
5733 ;; skip forwards
5734 (skip-chars-forward " \t\n\r\f")
5735 (while (looking-at "--.*")
5736 (goto-char (match-end 0))
5737 (skip-chars-forward " \t\n\r\f"))))
5738
5739 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5740 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5741 (defalias 'vhdl-forward-comment 'forward-comment))
5742
5743 (defun vhdl-back-to-indentation ()
5744 "Move point to the first non-whitespace character on this line."
5745 (interactive)
5746 (beginning-of-line 1)
5747 (skip-syntax-forward " " (vhdl-point 'eol)))
5748
5749 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5750 (when (featurep 'xemacs)
5751 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5752
5753 ;; This is the best we can do in Win-Emacs.
5754 (defun vhdl-win-il (&optional lim)
5755 "Determine if point is in a VHDL literal."
5756 (save-excursion
5757 (let* ((here (point))
5758 (state nil)
5759 (match nil)
5760 (lim (or lim (vhdl-point 'bod))))
5761 (goto-char lim )
5762 (while (< (point) here)
5763 (setq match
5764 (and (re-search-forward "--\\|[\"']\\|`"
5765 here 'move)
5766 (buffer-substring (match-beginning 0) (match-end 0))))
5767 (setq state
5768 (cond
5769 ;; no match
5770 ((null match) nil)
5771 ;; looking at the opening of a VHDL style comment
5772 ((string= "--" match)
5773 (if (<= here (progn (end-of-line) (point))) 'comment))
5774 ;; looking at a directive
5775 ((string= "`" match)
5776 (if (<= here (progn (end-of-line) (point))) 'directive))
5777 ;; looking at the opening of a double quote string
5778 ((string= "\"" match)
5779 (if (not (save-restriction
5780 ;; this seems to be necessary since the
5781 ;; re-search-forward will not work without it
5782 (narrow-to-region (point) here)
5783 (re-search-forward
5784 ;; this regexp matches a double quote
5785 ;; which is preceded by an even number
5786 ;; of backslashes, including zero
5787 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5788 'string))
5789 ;; looking at the opening of a single quote string
5790 ((string= "'" match)
5791 (if (not (save-restriction
5792 ;; see comments from above
5793 (narrow-to-region (point) here)
5794 (re-search-forward
5795 ;; this matches a single quote which is
5796 ;; preceded by zero or two backslashes.
5797 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5798 here 'move)))
5799 'string))
5800 (t nil)))
5801 ) ; end-while
5802 state)))
5803
5804 (and (string-match "Win-Emacs" emacs-version)
5805 (fset 'vhdl-in-literal 'vhdl-win-il))
5806
5807 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5808 ;; defined as lexical whitespace or comments. Search no farther back
5809 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5810 ;; used for backward skipping, (point-max) is used for forward
5811 ;; skipping.
5812
5813 (defun vhdl-forward-syntactic-ws (&optional lim)
5814 "Forward skip of syntactic whitespace."
5815 (let* ((here (point-max))
5816 (hugenum (point-max)))
5817 (while (/= here (point))
5818 (setq here (point))
5819 (vhdl-forward-comment hugenum)
5820 ;; skip preprocessor directives
5821 (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
5822 (= (vhdl-point 'boi) (point)))
5823 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5824 (= (forward-line 1) 0)))
5825 (end-of-line)))
5826 (if lim (goto-char (min (point) lim)))))
5827
5828
5829 ;; This is the best we can do in Win-Emacs.
5830 (defun vhdl-win-fsws (&optional lim)
5831 "Forward skip syntactic whitespace for Win-Emacs."
5832 (let ((lim (or lim (point-max)))
5833 stop)
5834 (while (not stop)
5835 (skip-chars-forward " \t\n\r\f" lim)
5836 (cond
5837 ;; vhdl comment
5838 ((looking-at "--") (end-of-line))
5839 ;; none of the above
5840 (t (setq stop t))))))
5841
5842 (and (string-match "Win-Emacs" emacs-version)
5843 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5844
5845 (defun vhdl-beginning-of-macro (&optional lim)
5846 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5847 (let ((here (point)))
5848 (beginning-of-line)
5849 (while (eq (char-before (1- (point))) ?\\)
5850 (forward-line -1))
5851 (back-to-indentation)
5852 (if (and (<= (point) here)
5853 (eq (char-after) ?#))
5854 t
5855 (goto-char here)
5856 nil)))
5857
5858 (defun vhdl-beginning-of-directive (&optional lim)
5859 "Go to the beginning of a directive (nicked from `cc-engine')."
5860 (let ((here (point)))
5861 (beginning-of-line)
5862 (while (eq (char-before (1- (point))) ?\\)
5863 (forward-line -1))
5864 (back-to-indentation)
5865 (if (and (<= (point) here)
5866 (eq (char-after) ?`))
5867 t
5868 (goto-char here)
5869 nil)))
5870
5871 (defun vhdl-backward-syntactic-ws (&optional lim)
5872 "Backward skip over syntactic whitespace."
5873 (let* ((here (point-min))
5874 (hugenum (- (point-max))))
5875 (while (/= here (point))
5876 (setq here (point))
5877 (vhdl-forward-comment hugenum)
5878 (vhdl-beginning-of-macro))
5879 (if lim (goto-char (max (point) lim)))))
5880
5881 ;; This is the best we can do in Win-Emacs.
5882 (defun vhdl-win-bsws (&optional lim)
5883 "Backward skip syntactic whitespace for Win-Emacs."
5884 (let ((lim (or lim (vhdl-point 'bod)))
5885 stop)
5886 (while (not stop)
5887 (skip-chars-backward " \t\n\r\f" lim)
5888 (cond
5889 ;; vhdl comment
5890 ((eq (vhdl-in-literal) 'comment)
5891 (skip-chars-backward "^-" lim)
5892 (skip-chars-backward "-" lim)
5893 (while (not (or (and (= (following-char) ?-)
5894 (= (char-after (1+ (point))) ?-))
5895 (<= (point) lim)))
5896 (skip-chars-backward "^-" lim)
5897 (skip-chars-backward "-" lim)))
5898 ;; none of the above
5899 (t (setq stop t))))))
5900
5901 (and (string-match "Win-Emacs" emacs-version)
5902 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5903
5904 ;; Functions to help finding the correct indentation column:
5905
5906 (defun vhdl-first-word (point)
5907 "If the keyword at POINT is at boi, then return (current-column) at
5908 that point, else nil."
5909 (save-excursion
5910 (and (goto-char point)
5911 (eq (point) (vhdl-point 'boi))
5912 (current-column))))
5913
5914 (defun vhdl-last-word (point)
5915 "If the keyword at POINT is at eoi, then return (current-column) at
5916 that point, else nil."
5917 (save-excursion
5918 (and (goto-char point)
5919 (save-excursion (or (eq (progn (forward-sexp) (point))
5920 (vhdl-point 'eoi))
5921 (looking-at "\\s-*\\(--\\)?")))
5922 (current-column))))
5923
5924 ;; Core syntactic evaluation functions:
5925
5926 (defconst vhdl-libunit-re
5927 "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
5928
5929 (defun vhdl-libunit-p ()
5930 (and
5931 (save-excursion
5932 (forward-sexp)
5933 (skip-chars-forward " \t\n\r\f")
5934 (not (looking-at "is\\b[^_]")))
5935 (save-excursion
5936 (backward-sexp)
5937 (and (not (looking-at "use\\b[^_]"))
5938 (progn
5939 (forward-sexp)
5940 (vhdl-forward-syntactic-ws)
5941 (/= (following-char) ?:))))
5942 ))
5943
5944 (defconst vhdl-defun-re
5945 "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5946
5947 (defun vhdl-defun-p ()
5948 (save-excursion
5949 (if (looking-at "block\\|process\\|procedural")
5950 ;; "block", "process", "procedural":
5951 (save-excursion
5952 (backward-sexp)
5953 (not (looking-at "end\\s-+\\w")))
5954 ;; "architecture", "configuration", "context", "entity",
5955 ;; "package", "procedure", "function":
5956 t)))
5957
5958 (defun vhdl-corresponding-defun ()
5959 "If the word at the current position corresponds to a \"defun\"
5960 keyword, then return a string that can be used to find the
5961 corresponding \"begin\" keyword, else return nil."
5962 (save-excursion
5963 (and (looking-at vhdl-defun-re)
5964 (vhdl-defun-p)
5965 (if (looking-at "block\\|process\\|procedural")
5966 ;; "block", "process". "procedural:
5967 (buffer-substring (match-beginning 0) (match-end 0))
5968 ;; "architecture", "configuration", "context", "entity", "package",
5969 ;; "procedure", "function":
5970 "is"))))
5971
5972 (defconst vhdl-begin-fwd-re
5973 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5974 "A regular expression for searching forward that matches all known
5975 \"begin\" keywords.")
5976
5977 (defconst vhdl-begin-bwd-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 backward that matches all known
5980 \"begin\" keywords.")
5981
5982 (defun vhdl-begin-p (&optional lim)
5983 "Return t if we are looking at a real \"begin\" keyword.
5984 Assumes that the caller will make sure that we are looking at
5985 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5986 the middle of an identifier that just happens to contain a \"begin\"
5987 keyword."
5988 (cond
5989 ;; "[architecture|case|configuration|context|entity|package|
5990 ;; procedure|function] ... is":
5991 ((and (looking-at "i")
5992 (save-excursion
5993 ;; Skip backward over first sexp (needed to skip over a
5994 ;; procedure interface list, and is harmless in other
5995 ;; situations). Note that we need "return" in the
5996 ;; following search list so that we don't run into
5997 ;; semicolons in the function interface list.
5998 (backward-sexp)
5999 (let (foundp)
6000 (while (and (not foundp)
6001 (re-search-backward
6002 ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
6003 lim 'move))
6004 (if (or (= (preceding-char) ?_)
6005 (vhdl-in-literal))
6006 (backward-char)
6007 (setq foundp t))))
6008 (and (/= (following-char) ?\;)
6009 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
6010 t)
6011 ;; "begin", "then", "use":
6012 ((looking-at "be\\|t\\|use")
6013 t)
6014 ;; "else":
6015 ((and (looking-at "e")
6016 ;; make sure that the "else" isn't inside a
6017 ;; conditional signal assignment.
6018 (save-excursion
6019 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6020 (or (eq (following-char) ?\;)
6021 (eq (point) lim))))
6022 t)
6023 ;; "block", "generate", "loop", "process", "procedural",
6024 ;; "units", "record", "protected body":
6025 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
6026 (save-excursion
6027 (backward-sexp)
6028 (not (looking-at "end\\s-+\\w"))))
6029 t)
6030 ;; "component":
6031 ((and (looking-at "c")
6032 (save-excursion
6033 (backward-sexp)
6034 (not (looking-at "end\\s-+\\w")))
6035 ;; look out for the dreaded entity class in an attribute
6036 (save-excursion
6037 (vhdl-backward-syntactic-ws lim)
6038 (/= (preceding-char) ?:)))
6039 t)
6040 ;; "for" (inside configuration declaration):
6041 ((and (looking-at "f")
6042 (save-excursion
6043 (backward-sexp)
6044 (not (looking-at "end\\s-+\\w")))
6045 (vhdl-has-syntax 'configuration))
6046 t)
6047 ))
6048
6049 (defun vhdl-corresponding-mid (&optional lim)
6050 (cond
6051 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
6052 "begin")
6053 ((looking-at "then\\|use")
6054 "<else>")
6055 (t
6056 "end")))
6057
6058 (defun vhdl-corresponding-end (&optional lim)
6059 "If the word at the current position corresponds to a \"begin\"
6060 keyword, then return a vector containing enough information to find
6061 the corresponding \"end\" keyword, else return nil. The keyword to
6062 search forward for is aref 0. The column in which the keyword must
6063 appear is aref 1 or nil if any column is suitable.
6064 Assumes that the caller will make sure that we are not in the middle
6065 of an identifier that just happens to contain a \"begin\" keyword."
6066 (save-excursion
6067 (and (looking-at vhdl-begin-fwd-re)
6068 (or (not (looking-at "\\<use\\>"))
6069 (save-excursion (back-to-indentation)
6070 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6071 (/= (preceding-char) ?_)
6072 (not (vhdl-in-literal))
6073 (vhdl-begin-p lim)
6074 (cond
6075 ;; "is", "generate", "loop":
6076 ((looking-at "[igl]")
6077 (vector "end"
6078 (and (vhdl-last-word (point))
6079 (or (vhdl-first-word (point))
6080 (save-excursion
6081 (vhdl-beginning-of-statement-1 lim)
6082 (vhdl-backward-skip-label lim)
6083 (vhdl-first-word (point)))))))
6084 ;; "begin", "else", "for":
6085 ((looking-at "be\\|[ef]")
6086 (vector "end"
6087 (and (vhdl-last-word (point))
6088 (or (vhdl-first-word (point))
6089 (save-excursion
6090 (vhdl-beginning-of-statement-1 lim)
6091 (vhdl-backward-skip-label lim)
6092 (vhdl-first-word (point)))))))
6093 ;; "component", "units", "record", "protected body":
6094 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
6095 ;; The first end found will close the block
6096 (vector "end" nil))
6097 ;; "block", "process", "procedural":
6098 ((looking-at "bl\\|p")
6099 (vector "end"
6100 (or (vhdl-first-word (point))
6101 (save-excursion
6102 (vhdl-beginning-of-statement-1 lim)
6103 (vhdl-backward-skip-label lim)
6104 (vhdl-first-word (point))))))
6105 ;; "then":
6106 ((looking-at "t\\|use")
6107 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6108 (and (vhdl-last-word (point))
6109 (or (vhdl-first-word (point))
6110 (save-excursion
6111 (vhdl-beginning-of-statement-1 lim)
6112 (vhdl-backward-skip-label lim)
6113 (vhdl-first-word (point)))))))
6114 ))))
6115
6116 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6117
6118 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6119
6120 (defun vhdl-end-p (&optional lim)
6121 "Return t if we are looking at a real \"end\" keyword.
6122 Assumes that the caller will make sure that we are looking at
6123 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6124 the middle of an identifier that just happens to contain an \"end\"
6125 keyword."
6126 (or (not (looking-at "else"))
6127 ;; make sure that the "else" isn't inside a conditional signal
6128 ;; assignment.
6129 (save-excursion
6130 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6131 (or (eq (following-char) ?\;)
6132 (eq (point) lim)
6133 (vhdl-in-literal)))))
6134
6135 (defun vhdl-corresponding-begin (&optional lim)
6136 "If the word at the current position corresponds to an \"end\"
6137 keyword, then return a vector containing enough information to find
6138 the corresponding \"begin\" keyword, else return nil. The keyword to
6139 search backward for is aref 0. The column in which the keyword must
6140 appear is aref 1 or nil if any column is suitable. The supplementary
6141 keyword to search forward for is aref 2 or nil if this is not
6142 required. If aref 3 is t, then the \"begin\" keyword may be found in
6143 the middle of a statement.
6144 Assumes that the caller will make sure that we are not in the middle
6145 of an identifier that just happens to contain an \"end\" keyword."
6146 (save-excursion
6147 (let (pos)
6148 (if (and (looking-at vhdl-end-fwd-re)
6149 (not (vhdl-in-literal))
6150 (vhdl-end-p lim))
6151 (if (looking-at "el")
6152 ;; "else", "elsif":
6153 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6154 ;; "end ...":
6155 (setq pos (point))
6156 (forward-sexp)
6157 (skip-chars-forward " \t\n\r\f")
6158 (cond
6159 ;; "end if":
6160 ((looking-at "if\\b[^_]")
6161 (vector "else\\|elsif\\|if"
6162 (vhdl-first-word pos)
6163 "else\\|then\\|use" nil))
6164 ;; "end component":
6165 ((looking-at "component\\b[^_]")
6166 (vector (buffer-substring (match-beginning 1)
6167 (match-end 1))
6168 (vhdl-first-word pos)
6169 nil nil))
6170 ;; "end units", "end record", "end protected":
6171 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6172 (vector (buffer-substring (match-beginning 1)
6173 (match-end 1))
6174 (vhdl-first-word pos)
6175 nil t))
6176 ;; "end block", "end process", "end procedural":
6177 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6178 (vector "begin" (vhdl-first-word pos) nil nil))
6179 ;; "end case":
6180 ((looking-at "case\\b[^_]")
6181 (vector "case" (vhdl-first-word pos) "is" nil))
6182 ;; "end generate":
6183 ((looking-at "generate\\b[^_]")
6184 (vector "generate\\|for\\|if"
6185 (vhdl-first-word pos)
6186 "generate" nil))
6187 ;; "end loop":
6188 ((looking-at "loop\\b[^_]")
6189 (vector "loop\\|while\\|for"
6190 (vhdl-first-word pos)
6191 "loop" nil))
6192 ;; "end for" (inside configuration declaration):
6193 ((looking-at "for\\b[^_]")
6194 (vector "for" (vhdl-first-word pos) nil nil))
6195 ;; "end [id]":
6196 (t
6197 (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
6198 (vhdl-first-word pos)
6199 ;; return an alist of (statement . keyword) mappings
6200 '(
6201 ;; "begin ... end [id]":
6202 ("begin" . nil)
6203 ;; "architecture ... is ... begin ... end [id]":
6204 ("architecture" . "is")
6205 ;; "configuration ... is ... end [id]":
6206 ("configuration" . "is")
6207 ;; "context ... is ... end [id]":
6208 ("context" . "is")
6209 ;; "entity ... is ... end [id]":
6210 ("entity" . "is")
6211 ;; "package ... is ... end [id]":
6212 ("package" . "is")
6213 ;; "procedure ... is ... begin ... end [id]":
6214 ("procedure" . "is")
6215 ;; "function ... is ... begin ... end [id]":
6216 ("function" . "is")
6217 )
6218 nil))
6219 ))) ; "end ..."
6220 )))
6221
6222 (defconst vhdl-leader-re
6223 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6224
6225 (defun vhdl-end-of-leader ()
6226 (save-excursion
6227 (cond ((looking-at "block\\|process\\|procedural")
6228 (if (save-excursion
6229 (forward-sexp)
6230 (skip-chars-forward " \t\n\r\f")
6231 (= (following-char) ?\())
6232 (forward-sexp 2)
6233 (forward-sexp))
6234 (when (looking-at "[ \t\n\r\f]*is")
6235 (goto-char (match-end 0)))
6236 (point))
6237 ((looking-at "component")
6238 (forward-sexp 2)
6239 (when (looking-at "[ \t\n\r\f]*is")
6240 (goto-char (match-end 0)))
6241 (point))
6242 ((looking-at "for")
6243 (forward-sexp 2)
6244 (skip-chars-forward " \t\n\r\f")
6245 (while (looking-at "[,:(]")
6246 (forward-sexp)
6247 (skip-chars-forward " \t\n\r\f"))
6248 (point))
6249 (t nil)
6250 )))
6251
6252 (defconst vhdl-trailer-re
6253 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6254
6255 (defconst vhdl-statement-fwd-re
6256 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6257 "A regular expression for searching forward that matches all known
6258 \"statement\" keywords.")
6259
6260 (defconst vhdl-statement-bwd-re
6261 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6262 "A regular expression for searching backward that matches all known
6263 \"statement\" keywords.")
6264
6265 (defun vhdl-statement-p (&optional lim)
6266 "Return t if we are looking at a real \"statement\" keyword.
6267 Assumes that the caller will make sure that we are looking at
6268 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6269 in the middle of an identifier that just happens to contain a
6270 \"statement\" keyword."
6271 (cond
6272 ;; "for" ... "generate":
6273 ((and (looking-at "f")
6274 ;; Make sure it's the start of a parameter specification.
6275 (save-excursion
6276 (forward-sexp 2)
6277 (skip-chars-forward " \t\n\r\f")
6278 (looking-at "in\\b[^_]"))
6279 ;; Make sure it's not an "end for".
6280 (save-excursion
6281 (backward-sexp)
6282 (not (looking-at "end\\s-+\\w"))))
6283 t)
6284 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6285 ((and (looking-at "i")
6286 ;; Make sure it's not an "end if".
6287 (save-excursion
6288 (backward-sexp)
6289 (not (looking-at "end\\s-+\\w"))))
6290 t)
6291 ;; "while" ... "loop":
6292 ((looking-at "w")
6293 t)
6294 ))
6295
6296 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6297 "Regexp describing a case statement alternative key.")
6298
6299 (defun vhdl-case-alternative-p (&optional lim)
6300 "Return t if we are looking at a real case alternative.
6301 Assumes that the caller will make sure that we are looking at
6302 vhdl-case-alternative-re, and are not inside a literal, and that
6303 we are not in the middle of an identifier that just happens to
6304 contain a \"when\" keyword."
6305 (save-excursion
6306 (let (foundp)
6307 (while (and (not foundp)
6308 (re-search-backward ";\\|<=" lim 'move))
6309 (if (or (= (preceding-char) ?_)
6310 (vhdl-in-literal))
6311 (backward-char)
6312 (setq foundp t)))
6313 (or (eq (following-char) ?\;)
6314 (eq (point) lim)))
6315 ))
6316
6317 ;; Core syntactic movement functions:
6318
6319 (defconst vhdl-b-t-b-re
6320 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6321
6322 (defun vhdl-backward-to-block (&optional lim)
6323 "Move backward to the previous \"begin\" or \"end\" keyword."
6324 (let (foundp)
6325 (while (and (not foundp)
6326 (re-search-backward vhdl-b-t-b-re lim 'move))
6327 (if (or (= (preceding-char) ?_)
6328 (vhdl-in-literal))
6329 (backward-char)
6330 (cond
6331 ;; "begin" keyword:
6332 ((and (looking-at vhdl-begin-fwd-re)
6333 (or (not (looking-at "\\<use\\>"))
6334 (save-excursion (back-to-indentation)
6335 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6336 (/= (preceding-char) ?_)
6337 (vhdl-begin-p lim))
6338 (setq foundp 'begin))
6339 ;; "end" keyword:
6340 ((and (looking-at vhdl-end-fwd-re)
6341 (/= (preceding-char) ?_)
6342 (vhdl-end-p lim))
6343 (setq foundp 'end))
6344 ))
6345 )
6346 foundp
6347 ))
6348
6349 (defun vhdl-forward-sexp (&optional count lim)
6350 "Move forward across one balanced expression (sexp).
6351 With COUNT, do it that many times."
6352 (interactive "p")
6353 (let ((count (or count 1))
6354 (case-fold-search t)
6355 end-vec target)
6356 (save-excursion
6357 (while (> count 0)
6358 ;; skip whitespace
6359 (skip-chars-forward " \t\n\r\f")
6360 ;; Check for an unbalanced "end" keyword
6361 (if (and (looking-at vhdl-end-fwd-re)
6362 (/= (preceding-char) ?_)
6363 (not (vhdl-in-literal))
6364 (vhdl-end-p lim)
6365 (not (looking-at "else")))
6366 (error
6367 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6368 ;; If the current keyword is a "begin" keyword, then find the
6369 ;; corresponding "end" keyword.
6370 (if (setq end-vec (vhdl-corresponding-end lim))
6371 (let (
6372 ;; end-re is the statement keyword to search for
6373 (end-re
6374 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6375 ;; column is either the statement keyword target column
6376 ;; or nil
6377 (column (aref end-vec 1))
6378 (eol (vhdl-point 'eol))
6379 foundp literal placeholder)
6380 ;; Look for the statement keyword.
6381 (while (and (not foundp)
6382 (re-search-forward end-re nil t)
6383 (setq placeholder (match-end 1))
6384 (goto-char (match-beginning 0)))
6385 ;; If we are in a literal, or not in the right target
6386 ;; column and not on the same line as the begin, then
6387 ;; try again.
6388 (if (or (and column
6389 (/= (current-indentation) column)
6390 (> (point) eol))
6391 (= (preceding-char) ?_)
6392 (setq literal (vhdl-in-literal)))
6393 (if (eq literal 'comment)
6394 (end-of-line)
6395 (forward-char))
6396 ;; An "else" keyword corresponds to both the opening brace
6397 ;; of the following sexp and the closing brace of the
6398 ;; previous sexp.
6399 (if (not (looking-at "else"))
6400 (goto-char placeholder))
6401 (setq foundp t))
6402 )
6403 (if (not foundp)
6404 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6405 )
6406 ;; If the current keyword is not a "begin" keyword, then just
6407 ;; perform the normal forward-sexp.
6408 (forward-sexp)
6409 )
6410 (setq count (1- count))
6411 )
6412 (setq target (point)))
6413 (goto-char target)
6414 nil))
6415
6416 (defun vhdl-backward-sexp (&optional count lim)
6417 "Move backward across one balanced expression (sexp).
6418 With COUNT, do it that many times. LIM bounds any required backward
6419 searches."
6420 (interactive "p")
6421 (let ((count (or count 1))
6422 (case-fold-search t)
6423 begin-vec target)
6424 (save-excursion
6425 (while (> count 0)
6426 ;; Perform the normal backward-sexp, unless we are looking at
6427 ;; "else" - an "else" keyword corresponds to both the opening brace
6428 ;; of the following sexp and the closing brace of the previous sexp.
6429 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6430 (/= (preceding-char) ?_)
6431 (not (vhdl-in-literal)))
6432 nil
6433 (backward-sexp)
6434 (if (and (looking-at vhdl-begin-fwd-re)
6435 (or (not (looking-at "\\<use\\>"))
6436 (save-excursion
6437 (back-to-indentation)
6438 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6439 (/= (preceding-char) ?_)
6440 (not (vhdl-in-literal))
6441 (vhdl-begin-p lim))
6442 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6443 ;; If the current keyword is an "end" keyword, then find the
6444 ;; corresponding "begin" keyword.
6445 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6446 (/= (preceding-char) ?_))
6447 (let (
6448 ;; begin-re is the statement keyword to search for
6449 (begin-re
6450 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6451 ;; column is either the statement keyword target column
6452 ;; or nil
6453 (column (aref begin-vec 1))
6454 ;; internal-p controls where the statement keyword can
6455 ;; be found.
6456 (internal-p (aref begin-vec 3))
6457 (last-backward (point)) last-forward
6458 foundp literal keyword)
6459 ;; Look for the statement keyword.
6460 (while (and (not foundp)
6461 (re-search-backward begin-re lim t)
6462 (setq keyword
6463 (buffer-substring (match-beginning 1)
6464 (match-end 1))))
6465 ;; If we are in a literal or in the wrong column,
6466 ;; then try again.
6467 (if (or (and column
6468 (and (/= (current-indentation) column)
6469 ;; possibly accept current-column as
6470 ;; well as current-indentation.
6471 (or (not internal-p)
6472 (/= (current-column) column))))
6473 (= (preceding-char) ?_)
6474 (vhdl-in-literal))
6475 (backward-char)
6476 ;; If there is a supplementary keyword, then
6477 ;; search forward for it.
6478 (if (and (setq begin-re (aref begin-vec 2))
6479 (or (not (listp begin-re))
6480 ;; If begin-re is an alist, then find the
6481 ;; element corresponding to the actual
6482 ;; keyword that we found.
6483 (progn
6484 (setq begin-re
6485 (assoc keyword begin-re))
6486 (and begin-re
6487 (setq begin-re (cdr begin-re))))))
6488 (and
6489 (setq begin-re
6490 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6491 (save-excursion
6492 (setq last-forward (point))
6493 ;; Look for the supplementary keyword
6494 ;; (bounded by the backward search start
6495 ;; point).
6496 (while (and (not foundp)
6497 (re-search-forward begin-re
6498 last-backward t)
6499 (goto-char (match-beginning 1)))
6500 ;; If we are in a literal, then try again.
6501 (if (or (= (preceding-char) ?_)
6502 (setq literal
6503 (vhdl-in-literal)))
6504 (if (eq literal 'comment)
6505 (goto-char
6506 (min (vhdl-point 'eol) last-backward))
6507 (forward-char))
6508 ;; We have found the supplementary keyword.
6509 ;; Save the position of the keyword in foundp.
6510 (setq foundp (point)))
6511 )
6512 foundp)
6513 ;; If the supplementary keyword was found, then
6514 ;; move point to the supplementary keyword.
6515 (goto-char foundp))
6516 ;; If there was no supplementary keyword, then
6517 ;; point is already at the statement keyword.
6518 (setq foundp t)))
6519 ) ; end of the search for the statement keyword
6520 (if (not foundp)
6521 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6522 ))
6523 (setq count (1- count))
6524 )
6525 (setq target (point)))
6526 (goto-char target)
6527 nil))
6528
6529 (defun vhdl-backward-up-list (&optional count limit)
6530 "Move backward out of one level of blocks.
6531 With argument, do this that many times."
6532 (interactive "p")
6533 (let ((count (or count 1))
6534 target)
6535 (save-excursion
6536 (while (> count 0)
6537 (if (looking-at vhdl-defun-re)
6538 (error "ERROR: Unbalanced blocks"))
6539 (vhdl-backward-to-block limit)
6540 (setq count (1- count)))
6541 (setq target (point)))
6542 (goto-char target)))
6543
6544 (defun vhdl-end-of-defun (&optional count)
6545 "Move forward to the end of a VHDL defun."
6546 (interactive)
6547 (let ((case-fold-search t))
6548 (vhdl-beginning-of-defun)
6549 (if (not (looking-at "block\\|process\\|procedural"))
6550 (re-search-forward "\\bis\\b"))
6551 (vhdl-forward-sexp)))
6552
6553 (defun vhdl-mark-defun ()
6554 "Put mark at end of this \"defun\", point at beginning."
6555 (interactive)
6556 (let ((case-fold-search t))
6557 (push-mark)
6558 (vhdl-beginning-of-defun)
6559 (push-mark)
6560 (if (not (looking-at "block\\|process\\|procedural"))
6561 (re-search-forward "\\bis\\b"))
6562 (vhdl-forward-sexp)
6563 (exchange-point-and-mark)))
6564
6565 (defun vhdl-beginning-of-libunit ()
6566 "Move backward to the beginning of a VHDL library unit.
6567 Returns the location of the corresponding begin keyword, unless search
6568 stops due to beginning or end of buffer.
6569 Note that if point is between the \"libunit\" keyword and the
6570 corresponding \"begin\" keyword, then that libunit will not be
6571 recognized, and the search will continue backwards. If point is
6572 at the \"begin\" keyword, then the defun will be recognized. The
6573 returned point is at the first character of the \"libunit\" keyword."
6574 (let ((last-forward (point))
6575 (last-backward
6576 ;; Just in case we are actually sitting on the "begin"
6577 ;; keyword, allow for the keyword and an extra character,
6578 ;; as this will be used when looking forward for the
6579 ;; "begin" keyword.
6580 (save-excursion (forward-word 1) (1+ (point))))
6581 foundp literal placeholder)
6582 ;; Find the "libunit" keyword.
6583 (while (and (not foundp)
6584 (re-search-backward vhdl-libunit-re nil 'move))
6585 ;; If we are in a literal, or not at a real libunit, then try again.
6586 (if (or (= (preceding-char) ?_)
6587 (vhdl-in-literal)
6588 (not (vhdl-libunit-p)))
6589 (backward-char)
6590 ;; Find the corresponding "begin" keyword.
6591 (setq last-forward (point))
6592 (while (and (not foundp)
6593 (re-search-forward "\\bis\\b[^_]" last-backward t)
6594 (setq placeholder (match-beginning 0)))
6595 (if (or (= (preceding-char) ?_)
6596 (setq literal (vhdl-in-literal)))
6597 ;; It wasn't a real keyword, so keep searching.
6598 (if (eq literal 'comment)
6599 (goto-char
6600 (min (vhdl-point 'eol) last-backward))
6601 (forward-char))
6602 ;; We have found the begin keyword, loop will exit.
6603 (setq foundp placeholder)))
6604 ;; Go back to the libunit keyword
6605 (goto-char last-forward)))
6606 foundp))
6607
6608 (defun vhdl-beginning-of-defun (&optional count)
6609 "Move backward to the beginning of a VHDL defun.
6610 With argument, do it that many times.
6611 Returns the location of the corresponding begin keyword, unless search
6612 stops due to beginning or end of buffer."
6613 ;; Note that if point is between the "defun" keyword and the
6614 ;; corresponding "begin" keyword, then that defun will not be
6615 ;; recognized, and the search will continue backwards. If point is
6616 ;; at the "begin" keyword, then the defun will be recognized. The
6617 ;; returned point is at the first character of the "defun" keyword.
6618 (interactive "p")
6619 (let ((count (or count 1))
6620 (case-fold-search t)
6621 (last-forward (point))
6622 foundp)
6623 (while (> count 0)
6624 (setq foundp nil)
6625 (goto-char last-forward)
6626 (let ((last-backward
6627 ;; Just in case we are actually sitting on the "begin"
6628 ;; keyword, allow for the keyword and an extra character,
6629 ;; as this will be used when looking forward for the
6630 ;; "begin" keyword.
6631 (save-excursion (forward-word 1) (1+ (point))))
6632 begin-string literal)
6633 (while (and (not foundp)
6634 (re-search-backward vhdl-defun-re nil 'move))
6635 ;; If we are in a literal, then try again.
6636 (if (or (= (preceding-char) ?_)
6637 (vhdl-in-literal))
6638 (backward-char)
6639 (if (setq begin-string (vhdl-corresponding-defun))
6640 ;; This is a real defun keyword.
6641 ;; Find the corresponding "begin" keyword.
6642 ;; Look for the begin keyword.
6643 (progn
6644 ;; Save the search start point.
6645 (setq last-forward (point))
6646 (while (and (not foundp)
6647 (search-forward begin-string last-backward t))
6648 (if (or (= (preceding-char) ?_)
6649 (save-match-data
6650 (setq literal (vhdl-in-literal))))
6651 ;; It wasn't a real keyword, so keep searching.
6652 (if (eq literal 'comment)
6653 (goto-char
6654 (min (vhdl-point 'eol) last-backward))
6655 (forward-char))
6656 ;; We have found the begin keyword, loop will exit.
6657 (setq foundp (match-beginning 0)))
6658 )
6659 ;; Go back to the defun keyword
6660 (goto-char last-forward)) ; end search for begin keyword
6661 ))
6662 ) ; end of the search for the defun keyword
6663 )
6664 (setq count (1- count))
6665 )
6666 (vhdl-keep-region-active)
6667 foundp))
6668
6669 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6670 "Go to the beginning of the innermost VHDL statement.
6671 With prefix arg, go back N - 1 statements. If already at the
6672 beginning of a statement then go to the beginning of the preceding
6673 one. If within a string or comment, or next to a comment (only
6674 whitespace between), move by sentences instead of statements.
6675
6676 When called from a program, this function takes 3 optional args: the
6677 prefix arg, a buffer position limit which is the farthest back to
6678 search, and an argument indicating an interactive call."
6679 (interactive "p\np")
6680 (let ((count (or count 1))
6681 (case-fold-search t)
6682 (lim (or lim (point-min)))
6683 (here (point))
6684 state)
6685 (save-excursion
6686 (goto-char lim)
6687 (setq state (parse-partial-sexp (point) here nil nil)))
6688 (if (and interactive
6689 (or (nth 3 state)
6690 (nth 4 state)
6691 (looking-at (concat "[ \t]*" comment-start-skip))))
6692 (forward-sentence (- count))
6693 (while (> count 0)
6694 (vhdl-beginning-of-statement-1 lim)
6695 (setq count (1- count))))
6696 ;; its possible we've been left up-buf of lim
6697 (goto-char (max (point) lim))
6698 )
6699 (vhdl-keep-region-active))
6700
6701 (defconst vhdl-e-o-s-re
6702 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6703
6704 (defun vhdl-end-of-statement ()
6705 "Very simple implementation."
6706 (interactive)
6707 (re-search-forward vhdl-e-o-s-re))
6708
6709 (defconst vhdl-b-o-s-re
6710 (concat ";[^_]\\|([^_]\\|)[^_]\\|\\bwhen\\b[^_]\\|"
6711 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6712
6713 (defun vhdl-beginning-of-statement-1 (&optional lim)
6714 "Move to the start of the current statement, or the previous
6715 statement if already at the beginning of one."
6716 (let ((lim (or lim (point-min)))
6717 (here (point))
6718 (pos (point))
6719 donep)
6720 ;; go backwards one balanced expression, but be careful of
6721 ;; unbalanced paren being reached
6722 (if (not (vhdl-safe (progn (backward-sexp) t)))
6723 (progn
6724 (backward-up-list 1)
6725 (forward-char)
6726 (vhdl-forward-syntactic-ws here)
6727 (setq donep t)))
6728 (while (and (not donep)
6729 (not (bobp))
6730 ;; look backwards for a statement boundary
6731 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6732 (if (or (= (preceding-char) ?_)
6733 (vhdl-in-literal))
6734 (backward-char)
6735 (cond
6736 ;; If we are looking at an open paren, then stop after it
6737 ((eq (following-char) ?\()
6738 (forward-char)
6739 (vhdl-forward-syntactic-ws here)
6740 (setq donep t))
6741 ;; If we are looking at a close paren, then skip it
6742 ((eq (following-char) ?\))
6743 (forward-char)
6744 (setq pos (point))
6745 (backward-sexp)
6746 (if (< (point) lim)
6747 (progn (goto-char pos)
6748 (vhdl-forward-syntactic-ws here)
6749 (setq donep t))))
6750 ;; If we are looking at a semicolon, then stop
6751 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6752 (progn
6753 (forward-char)
6754 (vhdl-forward-syntactic-ws here)
6755 (setq donep t)))
6756 ;; If we are looking at a "begin", then stop
6757 ((and (looking-at vhdl-begin-fwd-re)
6758 (or (not (looking-at "\\<use\\>"))
6759 (save-excursion
6760 (back-to-indentation)
6761 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6762 (/= (preceding-char) ?_)
6763 (vhdl-begin-p nil))
6764 ;; If it's a leader "begin", then find the
6765 ;; right place
6766 (if (looking-at vhdl-leader-re)
6767 (save-excursion
6768 ;; set a default stop point at the begin
6769 (setq pos (point))
6770 ;; is the start point inside the leader area ?
6771 (goto-char (vhdl-end-of-leader))
6772 (vhdl-forward-syntactic-ws here)
6773 (if (< (point) here)
6774 ;; start point was not inside leader area
6775 ;; set stop point at word after leader
6776 (setq pos (point))))
6777 (forward-word 1)
6778 (vhdl-forward-syntactic-ws here)
6779 (setq pos (point)))
6780 (goto-char pos)
6781 (setq donep t))
6782 ;; If we are looking at a "statement", then stop
6783 ((and (looking-at vhdl-statement-fwd-re)
6784 (/= (preceding-char) ?_)
6785 (vhdl-statement-p nil))
6786 (setq donep t))
6787 ;; If we are looking at a case alternative key, then stop
6788 ((and (looking-at vhdl-case-alternative-re)
6789 (vhdl-case-alternative-p lim))
6790 (save-excursion
6791 ;; set a default stop point at the when
6792 (setq pos (point))
6793 ;; is the start point inside the case alternative key ?
6794 (looking-at vhdl-case-alternative-re)
6795 (goto-char (match-end 0))
6796 (vhdl-forward-syntactic-ws here)
6797 (if (< (point) here)
6798 ;; start point was not inside the case alternative key
6799 ;; set stop point at word after case alternative keyleader
6800 (setq pos (point))))
6801 (goto-char pos)
6802 (setq donep t))
6803 ;; Bogus find, continue
6804 (t
6805 (backward-char)))))
6806 ))
6807
6808 ;; Defuns for calculating the current syntactic state:
6809
6810 (defun vhdl-get-library-unit (bod placeholder)
6811 "If there is an enclosing library unit at BOD, with its \"begin\"
6812 keyword at PLACEHOLDER, then return the library unit type."
6813 (let ((here (vhdl-point 'bol)))
6814 (if (save-excursion
6815 (goto-char placeholder)
6816 (vhdl-safe (vhdl-forward-sexp 1 bod))
6817 (<= here (point)))
6818 (save-excursion
6819 (goto-char bod)
6820 (cond
6821 ((looking-at "e") 'entity)
6822 ((looking-at "a") 'architecture)
6823 ((looking-at "conf") 'configuration)
6824 ((looking-at "cont") 'context)
6825 ((looking-at "p")
6826 (save-excursion
6827 (goto-char bod)
6828 (forward-sexp)
6829 (vhdl-forward-syntactic-ws here)
6830 (if (looking-at "body\\b[^_]")
6831 'package-body 'package))))))
6832 ))
6833
6834 (defun vhdl-get-block-state (&optional lim)
6835 "Finds and records all the closest opens.
6836 LIM is the furthest back we need to search (it should be the
6837 previous libunit keyword)."
6838 (let ((here (point))
6839 (lim (or lim (point-min)))
6840 keyword sexp-start sexp-mid sexp-end
6841 preceding-sexp containing-sexp
6842 containing-begin containing-mid containing-paren)
6843 (save-excursion
6844 ;; Find the containing-paren, and use that as the limit
6845 (if (setq containing-paren
6846 (save-restriction
6847 (narrow-to-region lim (point))
6848 (vhdl-safe (scan-lists (point) -1 1))))
6849 (setq lim containing-paren))
6850 ;; Look backwards for "begin" and "end" keywords.
6851 (while (and (> (point) lim)
6852 (not containing-sexp))
6853 (setq keyword (vhdl-backward-to-block lim))
6854 (cond
6855 ((eq keyword 'begin)
6856 ;; Found a "begin" keyword
6857 (setq sexp-start (point))
6858 (setq sexp-mid (vhdl-corresponding-mid lim))
6859 (setq sexp-end (vhdl-safe
6860 (save-excursion
6861 (vhdl-forward-sexp 1 lim) (point))))
6862 (if (and sexp-end (<= sexp-end here))
6863 ;; we want to record this sexp, but we only want to
6864 ;; record the last-most of any of them before here
6865 (or preceding-sexp
6866 (setq preceding-sexp sexp-start))
6867 ;; we're contained in this sexp so put sexp-start on
6868 ;; front of list
6869 (setq containing-sexp sexp-start)
6870 (setq containing-mid sexp-mid)
6871 (setq containing-begin t)))
6872 ((eq keyword 'end)
6873 ;; Found an "end" keyword
6874 (forward-sexp)
6875 (setq sexp-end (point))
6876 (setq sexp-mid nil)
6877 (setq sexp-start
6878 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6879 (progn (backward-sexp) (point))))
6880 ;; we want to record this sexp, but we only want to
6881 ;; record the last-most of any of them before here
6882 (or preceding-sexp
6883 (setq preceding-sexp sexp-start)))
6884 )))
6885 ;; Check if the containing-paren should be the containing-sexp
6886 (if (and containing-paren
6887 (or (null containing-sexp)
6888 (< containing-sexp containing-paren)))
6889 (setq containing-sexp containing-paren
6890 preceding-sexp nil
6891 containing-begin nil
6892 containing-mid nil))
6893 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6894 ))
6895
6896
6897 (defconst vhdl-s-c-a-re
6898 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6899
6900 (defun vhdl-skip-case-alternative (&optional lim)
6901 "Skip forward over case/when bodies, with optional maximal
6902 limit. If no next case alternative is found, nil is returned and
6903 point is not moved."
6904 (let ((lim (or lim (point-max)))
6905 (here (point))
6906 donep foundp)
6907 (while (and (< (point) lim)
6908 (not donep))
6909 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6910 (save-match-data
6911 (not (vhdl-in-literal)))
6912 (/= (match-beginning 0) here))
6913 (progn
6914 (goto-char (match-beginning 0))
6915 (cond
6916 ((and (looking-at "case")
6917 (re-search-forward "\\bis[^_]" lim t))
6918 (backward-sexp)
6919 (vhdl-forward-sexp))
6920 (t
6921 (setq donep t
6922 foundp t))))))
6923 (if (not foundp)
6924 (goto-char here))
6925 foundp))
6926
6927 (defun vhdl-backward-skip-label (&optional lim)
6928 "Skip backward over a label, with optional maximal
6929 limit. If label is not found, nil is returned and point
6930 is not moved."
6931 (let ((lim (or lim (point-min)))
6932 placeholder)
6933 (if (save-excursion
6934 (vhdl-backward-syntactic-ws lim)
6935 (and (eq (preceding-char) ?:)
6936 (progn
6937 (backward-sexp)
6938 (setq placeholder (point))
6939 (looking-at vhdl-label-key))))
6940 (goto-char placeholder))
6941 ))
6942
6943 (defun vhdl-forward-skip-label (&optional lim)
6944 "Skip forward over a label, with optional maximal
6945 limit. If label is not found, nil is returned and point
6946 is not moved."
6947 (let ((lim (or lim (point-max))))
6948 (if (looking-at vhdl-label-key)
6949 (progn
6950 (goto-char (match-end 0))
6951 (vhdl-forward-syntactic-ws lim)))
6952 ))
6953
6954 (defun vhdl-get-syntactic-context ()
6955 "Guess the syntactic description of the current line of VHDL code."
6956 (save-excursion
6957 (save-restriction
6958 (beginning-of-line)
6959 (let* ((indent-point (point))
6960 (case-fold-search t)
6961 vec literal containing-sexp preceding-sexp
6962 containing-begin containing-mid containing-leader
6963 char-before-ip char-after-ip begin-after-ip end-after-ip
6964 placeholder lim library-unit
6965 )
6966
6967 ;; Reset the syntactic context
6968 (setq vhdl-syntactic-context nil)
6969
6970 (save-excursion
6971 ;; Move to the start of the previous library unit, and
6972 ;; record the position of the "begin" keyword.
6973 (setq placeholder (vhdl-beginning-of-libunit))
6974 ;; The position of the "libunit" keyword gives us a gross
6975 ;; limit point.
6976 (setq lim (point))
6977 )
6978
6979 ;; If there is a previous library unit, and we are enclosed by
6980 ;; it, then set the syntax accordingly.
6981 (and placeholder
6982 (setq library-unit (vhdl-get-library-unit lim placeholder))
6983 (vhdl-add-syntax library-unit lim))
6984
6985 ;; Find the surrounding state.
6986 (if (setq vec (vhdl-get-block-state lim))
6987 (progn
6988 (setq containing-sexp (aref vec 0))
6989 (setq preceding-sexp (aref vec 1))
6990 (setq containing-begin (aref vec 2))
6991 (setq containing-mid (aref vec 3))
6992 ))
6993
6994 ;; set the limit on the farthest back we need to search
6995 (setq lim (if containing-sexp
6996 (save-excursion
6997 (goto-char containing-sexp)
6998 ;; set containing-leader if required
6999 (if (looking-at vhdl-leader-re)
7000 (setq containing-leader (vhdl-end-of-leader)))
7001 (vhdl-point 'bol))
7002 (point-min)))
7003
7004 ;; cache char before and after indent point, and move point to
7005 ;; the most likely position to perform the majority of tests
7006 (goto-char indent-point)
7007 (skip-chars-forward " \t")
7008 (setq literal (vhdl-in-literal))
7009 (setq char-after-ip (following-char))
7010 (setq begin-after-ip (and
7011 (not literal)
7012 (looking-at vhdl-begin-fwd-re)
7013 (or (not (looking-at "\\<use\\>"))
7014 (save-excursion
7015 (back-to-indentation)
7016 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
7017 (vhdl-begin-p)))
7018 (setq end-after-ip (and
7019 (not literal)
7020 (looking-at vhdl-end-fwd-re)
7021 (vhdl-end-p)))
7022 (vhdl-backward-syntactic-ws lim)
7023 (setq char-before-ip (preceding-char))
7024 (goto-char indent-point)
7025 (skip-chars-forward " \t")
7026
7027 ;; now figure out syntactic qualities of the current line
7028 (cond
7029 ;; CASE 1: in a string or comment.
7030 ((memq literal '(string comment))
7031 (vhdl-add-syntax literal (vhdl-point 'bopl)))
7032 ;; CASE 2: Line is at top level.
7033 ((null containing-sexp)
7034 ;; Find the point to which indentation will be relative
7035 (save-excursion
7036 (if (null preceding-sexp)
7037 ;; CASE 2X.1
7038 ;; no preceding-sexp -> use the preceding statement
7039 (vhdl-beginning-of-statement-1 lim)
7040 ;; CASE 2X.2
7041 ;; if there is a preceding-sexp then indent relative to it
7042 (goto-char preceding-sexp)
7043 ;; if not at boi, then the block-opening keyword is
7044 ;; probably following a label, so we need a different
7045 ;; relpos
7046 (if (/= (point) (vhdl-point 'boi))
7047 ;; CASE 2X.3
7048 (vhdl-beginning-of-statement-1 lim)))
7049 ;; v-b-o-s could have left us at point-min
7050 (and (bobp)
7051 ;; CASE 2X.4
7052 (vhdl-forward-syntactic-ws indent-point))
7053 (setq placeholder (point)))
7054 (cond
7055 ;; CASE 2A : we are looking at a block-open
7056 (begin-after-ip
7057 (vhdl-add-syntax 'block-open placeholder))
7058 ;; CASE 2B: we are looking at a block-close
7059 (end-after-ip
7060 (vhdl-add-syntax 'block-close placeholder))
7061 ;; CASE 2C: we are looking at a top-level statement
7062 ((progn
7063 (vhdl-backward-syntactic-ws lim)
7064 (or (bobp)
7065 (and (= (preceding-char) ?\;)
7066 (not (vhdl-in-quote-p)))))
7067 (vhdl-add-syntax 'statement placeholder))
7068 ;; CASE 2D: we are looking at a top-level statement-cont
7069 (t
7070 (vhdl-beginning-of-statement-1 lim)
7071 ;; v-b-o-s could have left us at point-min
7072 (and (bobp)
7073 ;; CASE 2D.1
7074 (vhdl-forward-syntactic-ws indent-point))
7075 (vhdl-add-syntax 'statement-cont (point)))
7076 )) ; end CASE 2
7077 ;; CASE 3: line is inside parentheses. Most likely we are
7078 ;; either in a subprogram argument (interface) list, or a
7079 ;; continued expression containing parentheses.
7080 ((null containing-begin)
7081 (vhdl-backward-syntactic-ws containing-sexp)
7082 (cond
7083 ;; CASE 3A: we are looking at the arglist closing paren
7084 ((eq char-after-ip ?\))
7085 (goto-char containing-sexp)
7086 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
7087 ;; CASE 3B: we are looking at the first argument in an empty
7088 ;; argument list.
7089 ((eq char-before-ip ?\()
7090 (goto-char containing-sexp)
7091 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
7092 ;; CASE 3C: we are looking at an arglist continuation line,
7093 ;; but the preceding argument is on the same line as the
7094 ;; opening paren. This case includes multi-line
7095 ;; expression paren groupings.
7096 ((and (save-excursion
7097 (goto-char (1+ containing-sexp))
7098 (skip-chars-forward " \t")
7099 (not (eolp))
7100 (not (looking-at "--\\|`")))
7101 (save-excursion
7102 (vhdl-beginning-of-statement-1 containing-sexp)
7103 (skip-chars-backward " \t(")
7104 (while (and (= (preceding-char) ?\;)
7105 (not (vhdl-in-quote-p)))
7106 (vhdl-beginning-of-statement-1 containing-sexp)
7107 (skip-chars-backward " \t("))
7108 (<= (point) containing-sexp)))
7109 (goto-char containing-sexp)
7110 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7111 ;; CASE 3D: we are looking at just a normal arglist
7112 ;; continuation line
7113 (t (vhdl-beginning-of-statement-1 containing-sexp)
7114 (vhdl-forward-syntactic-ws indent-point)
7115 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7116 ))
7117 ;; CASE 4: A block mid open
7118 ((and begin-after-ip
7119 (looking-at containing-mid))
7120 (goto-char containing-sexp)
7121 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7122 (if (looking-at vhdl-trailer-re)
7123 ;; CASE 4.1
7124 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7125 (vhdl-backward-skip-label (vhdl-point 'boi))
7126 (vhdl-add-syntax 'block-open (point)))
7127 ;; CASE 5: block close brace
7128 (end-after-ip
7129 (goto-char containing-sexp)
7130 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7131 (if (looking-at vhdl-trailer-re)
7132 ;; CASE 5.1
7133 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7134 (vhdl-backward-skip-label (vhdl-point 'boi))
7135 (vhdl-add-syntax 'block-close (point)))
7136 ;; CASE 6: A continued statement
7137 ((and (/= char-before-ip ?\;)
7138 ;; check it's not a trailer begin keyword, or a begin
7139 ;; keyword immediately following a label.
7140 (not (and begin-after-ip
7141 (or (looking-at vhdl-trailer-re)
7142 (save-excursion
7143 (vhdl-backward-skip-label containing-sexp)))))
7144 ;; check it's not a statement keyword
7145 (not (and (looking-at vhdl-statement-fwd-re)
7146 (vhdl-statement-p)))
7147 ;; see if the b-o-s is before the indent point
7148 (> indent-point
7149 (save-excursion
7150 (vhdl-beginning-of-statement-1 containing-sexp)
7151 ;; If we ended up after a leader, then this will
7152 ;; move us forward to the start of the first
7153 ;; statement. Note that a containing sexp here is
7154 ;; always a keyword, not a paren, so this will
7155 ;; have no effect if we hit the containing-sexp.
7156 (vhdl-forward-syntactic-ws indent-point)
7157 (setq placeholder (point))))
7158 ;; check it's not a block-intro
7159 (/= placeholder containing-sexp)
7160 ;; check it's not a case block-intro
7161 (save-excursion
7162 (goto-char placeholder)
7163 (or (not (looking-at vhdl-case-alternative-re))
7164 (> (match-end 0) indent-point))))
7165 ;; Make placeholder skip a label, but only if it puts us
7166 ;; before the indent point at the start of a line.
7167 (let ((new placeholder))
7168 (if (and (> indent-point
7169 (save-excursion
7170 (goto-char placeholder)
7171 (vhdl-forward-skip-label indent-point)
7172 (setq new (point))))
7173 (save-excursion
7174 (goto-char new)
7175 (eq new (progn (back-to-indentation) (point)))))
7176 (setq placeholder new)))
7177 (vhdl-add-syntax 'statement-cont placeholder)
7178 (if begin-after-ip
7179 (vhdl-add-syntax 'block-open)))
7180 ;; Statement. But what kind?
7181 ;; CASE 7: A case alternative key
7182 ((and (looking-at vhdl-case-alternative-re)
7183 (vhdl-case-alternative-p containing-sexp))
7184 ;; for a case alternative key, we set relpos to the first
7185 ;; non-whitespace char on the line containing the "case"
7186 ;; keyword.
7187 (goto-char containing-sexp)
7188 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7189 (if (looking-at vhdl-trailer-re)
7190 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7191 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7192 ;; CASE 8: statement catchall
7193 (t
7194 ;; we know its a statement, but we need to find out if it is
7195 ;; the first statement in a block
7196 (if containing-leader
7197 (goto-char containing-leader)
7198 (goto-char containing-sexp)
7199 ;; Note that a containing sexp here is always a keyword,
7200 ;; not a paren, so skip over the keyword.
7201 (forward-sexp))
7202 ;; move to the start of the first statement
7203 (vhdl-forward-syntactic-ws indent-point)
7204 (setq placeholder (point))
7205 ;; we want to ignore case alternatives keys when skipping forward
7206 (let (incase-p)
7207 (while (looking-at vhdl-case-alternative-re)
7208 (setq incase-p (point))
7209 ;; we also want to skip over the body of the
7210 ;; case/when statement if that doesn't put us at
7211 ;; after the indent-point
7212 (while (vhdl-skip-case-alternative indent-point))
7213 ;; set up the match end
7214 (looking-at vhdl-case-alternative-re)
7215 (goto-char (match-end 0))
7216 ;; move to the start of the first case alternative statement
7217 (vhdl-forward-syntactic-ws indent-point)
7218 (setq placeholder (point)))
7219 (cond
7220 ;; CASE 8A: we saw a case/when statement so we must be
7221 ;; in a switch statement. find out if we are at the
7222 ;; statement just after a case alternative key
7223 ((and incase-p
7224 (= (point) indent-point))
7225 ;; relpos is the "when" keyword
7226 (vhdl-add-syntax 'statement-case-intro incase-p))
7227 ;; CASE 8B: any old statement
7228 ((< (point) indent-point)
7229 ;; relpos is the first statement of the block
7230 (vhdl-add-syntax 'statement placeholder)
7231 (if begin-after-ip
7232 (vhdl-add-syntax 'block-open)))
7233 ;; CASE 8C: first statement in a block
7234 (t
7235 (goto-char containing-sexp)
7236 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7237 (if (looking-at vhdl-trailer-re)
7238 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7239 (vhdl-backward-skip-label (vhdl-point 'boi))
7240 (vhdl-add-syntax 'statement-block-intro (point))
7241 (if begin-after-ip
7242 (vhdl-add-syntax 'block-open)))
7243 )))
7244 )
7245
7246 ;; now we need to look at any modifiers
7247 (goto-char indent-point)
7248 (skip-chars-forward " \t")
7249 (if (or (looking-at "--") (looking-at "/\\*"))
7250 (vhdl-add-syntax 'comment))
7251 (if (looking-at "`")
7252 (vhdl-add-syntax 'directive))
7253 (if (eq literal 'pound)
7254 (vhdl-add-syntax 'cpp-macro))
7255 ;; return the syntax
7256 vhdl-syntactic-context))))
7257
7258 ;; Standard indentation line-ups:
7259
7260 (defun vhdl-lineup-arglist (langelem)
7261 "Lineup the current arglist line with the arglist appearing just
7262 after the containing paren which starts the arglist."
7263 (save-excursion
7264 (let* ((containing-sexp
7265 (save-excursion
7266 ;; arglist-cont-nonempty gives relpos ==
7267 ;; to boi of containing-sexp paren. This
7268 ;; is good when offset is +, but bad
7269 ;; when it is vhdl-lineup-arglist, so we
7270 ;; have to special case a kludge here.
7271 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7272 (progn
7273 (beginning-of-line)
7274 (backward-up-list 1)
7275 (skip-chars-forward " \t" (vhdl-point 'eol)))
7276 (goto-char (cdr langelem)))
7277 (point)))
7278 (cs-curcol (save-excursion
7279 (goto-char (cdr langelem))
7280 (current-column))))
7281 (if (save-excursion
7282 (beginning-of-line)
7283 (looking-at "[ \t]*)"))
7284 (progn (goto-char (match-end 0))
7285 (backward-sexp)
7286 (forward-char)
7287 (vhdl-forward-syntactic-ws)
7288 (- (current-column) cs-curcol))
7289 (goto-char containing-sexp)
7290 (or (eolp)
7291 (let ((eol (vhdl-point 'eol))
7292 (here (progn
7293 (forward-char)
7294 (skip-chars-forward " \t")
7295 (point))))
7296 (vhdl-forward-syntactic-ws)
7297 (if (< (point) eol)
7298 (goto-char here))))
7299 (- (current-column) cs-curcol)
7300 ))))
7301
7302 (defun vhdl-lineup-arglist-intro (langelem)
7303 "Lineup an arglist-intro line to just after the open paren."
7304 (save-excursion
7305 (let ((cs-curcol (save-excursion
7306 (goto-char (cdr langelem))
7307 (current-column)))
7308 (ce-curcol (save-excursion
7309 (beginning-of-line)
7310 (backward-up-list 1)
7311 (skip-chars-forward " \t" (vhdl-point 'eol))
7312 (current-column))))
7313 (- ce-curcol cs-curcol -1))))
7314
7315 (defun vhdl-lineup-comment (langelem)
7316 "Support old behavior for comment indentation. We look at
7317 vhdl-comment-only-line-offset to decide how to indent comment
7318 only-lines."
7319 (save-excursion
7320 (back-to-indentation)
7321 ;; at or to the right of comment-column
7322 (if (>= (current-column) comment-column)
7323 (vhdl-comment-indent)
7324 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7325 (if (not (bolp))
7326 ;; inside multi-line comment
7327 (if (looking-at "\\*")
7328 1
7329 ;; otherwise
7330 (or (car-safe vhdl-comment-only-line-offset)
7331 vhdl-comment-only-line-offset))
7332 (or (cdr-safe vhdl-comment-only-line-offset)
7333 (car-safe vhdl-comment-only-line-offset)
7334 -1000 ;jam it against the left side
7335 )))))
7336
7337 (defun vhdl-lineup-statement-cont (langelem)
7338 "Line up statement-cont after the assignment operator."
7339 (save-excursion
7340 (let* ((relpos (cdr langelem))
7341 (assignp (save-excursion
7342 (goto-char (vhdl-point 'boi))
7343 (and (re-search-forward "\\(<\\|:\\|=\\)="
7344 (vhdl-point 'eol) t)
7345 (- (point) (vhdl-point 'boi)))))
7346 (curcol (progn
7347 (goto-char relpos)
7348 (current-column)))
7349 foundp)
7350 (while (and (not foundp)
7351 (< (point) (vhdl-point 'eol)))
7352 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7353 (if (vhdl-in-literal)
7354 (forward-char)
7355 (if (= (preceding-char) ?\()
7356 ;; skip over any parenthesized expressions
7357 (goto-char (min (vhdl-point 'eol)
7358 (scan-lists (point) 1 1)))
7359 ;; found an assignment operator (not at eol)
7360 (setq foundp (not (looking-at "\\s-*$"))))))
7361 (if (not foundp)
7362 ;; there's no assignment operator on the line
7363 vhdl-basic-offset
7364 ;; calculate indentation column after assign and ws, unless
7365 ;; our line contains an assignment operator
7366 (if (not assignp)
7367 (progn
7368 (forward-char)
7369 (skip-chars-forward " \t")
7370 (setq assignp 0)))
7371 (- (current-column) assignp curcol))
7372 )))
7373
7374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7375 ;; Progress reporting
7376
7377 (defvar vhdl-progress-info nil
7378 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7379
7380 (defun vhdl-update-progress-info (string pos)
7381 "Update progress information."
7382 (when (and vhdl-progress-info (not noninteractive)
7383 (< vhdl-progress-interval
7384 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7385 (let ((delta (- (aref vhdl-progress-info 1)
7386 (aref vhdl-progress-info 0))))
7387 (message "%s... (%2d%%)" string
7388 (if (= 0 delta)
7389 100
7390 (floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
7391 delta))))
7392 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7393
7394 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7395 ;; Indentation commands
7396
7397 (defun vhdl-electric-tab (&optional prefix-arg)
7398 "If preceding character is part of a word or a paren then hippie-expand,
7399 else if right of non whitespace on line then insert tab,
7400 else if last command was a tab or return then dedent one step or if a comment
7401 toggle between normal indent and inline comment indent,
7402 else indent `correctly'."
7403 (interactive "*P")
7404 (vhdl-prepare-search-2
7405 (cond
7406 ;; indent region if region is active
7407 ((and (not (featurep 'xemacs)) (use-region-p))
7408 (vhdl-indent-region (region-beginning) (region-end) nil))
7409 ;; expand word
7410 ((= (char-syntax (preceding-char)) ?w)
7411 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7412 (case-replace nil)
7413 (hippie-expand-only-buffers
7414 (or (and (boundp 'hippie-expand-only-buffers)
7415 hippie-expand-only-buffers)
7416 '(vhdl-mode))))
7417 (vhdl-expand-abbrev prefix-arg)))
7418 ;; expand parenthesis
7419 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7420 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7421 (case-replace nil))
7422 (vhdl-expand-paren prefix-arg)))
7423 ;; insert tab
7424 ((> (current-column) (current-indentation))
7425 (insert-tab))
7426 ;; toggle comment indent
7427 ((and (looking-at "--")
7428 (or (eq last-command 'vhdl-electric-tab)
7429 (eq last-command 'vhdl-electric-return)))
7430 (cond ((= (current-indentation) 0) ; no indent
7431 (indent-to 1)
7432 (indent-according-to-mode))
7433 ((< (current-indentation) comment-column) ; normal indent
7434 (indent-to comment-column)
7435 (indent-according-to-mode))
7436 (t ; inline comment indent
7437 (delete-region (line-beginning-position) (point)))))
7438 ;; dedent
7439 ((and (>= (current-indentation) vhdl-basic-offset)
7440 (or (eq last-command 'vhdl-electric-tab)
7441 (eq last-command 'vhdl-electric-return)))
7442 (backward-delete-char-untabify vhdl-basic-offset nil))
7443 ;; indent line
7444 (t (indent-according-to-mode)))
7445 (setq this-command 'vhdl-electric-tab)))
7446
7447 (defun vhdl-electric-return ()
7448 "newline-and-indent or indent-new-comment-line if in comment and preceding
7449 character is a space."
7450 (interactive)
7451 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7452 (indent-new-comment-line)
7453 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7454 (not (vhdl-in-comment-p)))
7455 (vhdl-fix-case-word -1))
7456 (newline-and-indent)))
7457
7458 (defun vhdl-indent-line ()
7459 "Indent the current line as VHDL code. Returns the amount of
7460 indentation change."
7461 (interactive)
7462 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7463 (pos (- (point-max) (point)))
7464 (is-comment nil)
7465 (indent
7466 (if syntax
7467 ;; indent syntax-based
7468 (if (and (eq (caar syntax) 'comment)
7469 (>= (vhdl-get-offset (car syntax)) comment-column))
7470 ;; special case: comments at or right of comment-column
7471 (vhdl-get-offset (car syntax))
7472 ;; align comments like following code line
7473 (when vhdl-indent-comment-like-next-code-line
7474 (save-excursion
7475 (while (eq (caar syntax) 'comment)
7476 (setq is-comment t)
7477 (beginning-of-line 2)
7478 (setq syntax (vhdl-get-syntactic-context)))))
7479 (when is-comment
7480 (push (cons 'comment nil) syntax))
7481 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7482 ;; indent like previous nonblank line
7483 (save-excursion (beginning-of-line)
7484 (re-search-backward "^[^\n]" nil t)
7485 (current-indentation))))
7486 (shift-amt (- indent (current-indentation))))
7487 (and vhdl-echo-syntactic-information-p
7488 (message "syntax: %s, indent= %d" syntax indent))
7489 (let ((has-formfeed
7490 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7491 (when (or (not (zerop shift-amt)) has-formfeed)
7492 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7493 (beginning-of-line)
7494 (when has-formfeed (insert "\f"))
7495 (indent-to indent)))
7496 (if (< (point) (vhdl-point 'boi))
7497 (back-to-indentation)
7498 ;; If initial point was within line's indentation, position after
7499 ;; the indentation. Else stay at same point in text.
7500 (when (> (- (point-max) pos) (point))
7501 (goto-char (- (point-max) pos))))
7502 (run-hooks 'vhdl-special-indent-hook)
7503 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7504 shift-amt))
7505
7506 (defun vhdl-indent-region (beg end &optional column)
7507 "Indent region as VHDL code.
7508 Adds progress reporting to `indent-region'."
7509 (interactive "r\nP")
7510 (when vhdl-progress-interval
7511 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7512 (count-lines (point-min) end) 0)))
7513 (indent-region beg end column)
7514 (when vhdl-progress-interval (message "Indenting...done"))
7515 (setq vhdl-progress-info nil))
7516
7517 (defun vhdl-indent-buffer ()
7518 "Indent whole buffer as VHDL code.
7519 Calls `indent-region' for whole buffer and adds progress reporting."
7520 (interactive)
7521 (vhdl-indent-region (point-min) (point-max)))
7522
7523 (defun vhdl-indent-group ()
7524 "Indent group of lines between empty lines."
7525 (interactive)
7526 (let ((beg (save-excursion
7527 (if (re-search-backward vhdl-align-group-separate nil t)
7528 (point-marker)
7529 (point-min-marker))))
7530 (end (save-excursion
7531 (if (re-search-forward vhdl-align-group-separate nil t)
7532 (point-marker)
7533 (point-max-marker)))))
7534 (vhdl-indent-region beg end)))
7535
7536 (defun vhdl-indent-sexp (&optional endpos)
7537 "Indent each line of the list starting just after point.
7538 If optional arg ENDPOS is given, indent each line, stopping when
7539 ENDPOS is encountered."
7540 (interactive)
7541 (save-excursion
7542 (let ((beg (point))
7543 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7544 (indent-region beg end nil))))
7545
7546 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7547 ;; Miscellaneous commands
7548
7549 (defun vhdl-show-syntactic-information ()
7550 "Show syntactic information for current line."
7551 (interactive)
7552 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7553 (vhdl-keep-region-active))
7554
7555 ;; Verification and regression functions:
7556
7557 (defun vhdl-regress-line (&optional arg)
7558 "Check syntactic information for current line."
7559 (interactive "P")
7560 (let ((expected (save-excursion
7561 (end-of-line)
7562 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7563 (forward-char 4)
7564 (read (current-buffer)))))
7565 (actual (vhdl-get-syntactic-context))
7566 (expurgated))
7567 ;; remove the library unit symbols
7568 (mapc
7569 (function
7570 (lambda (elt)
7571 (if (memq (car elt) '(entity configuration context package
7572 package-body architecture))
7573 nil
7574 (setq expurgated (append expurgated (list elt))))))
7575 actual)
7576 (if (and (not arg) expected (listp expected))
7577 (if (not (equal expected expurgated))
7578 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7579 (save-excursion
7580 (beginning-of-line)
7581 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7582 (end-of-line)
7583 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7584 (delete-region (point) (line-end-position)))
7585 (insert " -- ")
7586 (insert (format "%s" expurgated))))))
7587 (vhdl-keep-region-active))
7588
7589
7590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7591 ;;; Alignment, beautifying
7592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7593
7594 (defconst vhdl-align-alist
7595 '(
7596 ;; after some keywords
7597 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7598 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7599 ;; before ':'
7600 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7601 ;; after direction specifications
7602 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7603 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7604 ;; before "==", ":=", "=>", and "<="
7605 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7606 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7607 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7608 ;; before some keywords
7609 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7610 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7611 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7612 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7613 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7614 ;; before "=>" since "when/else ... =>" can occur
7615 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7616 )
7617 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7618 It is searched in order. If REGEXP is found anywhere in the first
7619 line of a region to be aligned, ALIGN-PATTERN will be used for that
7620 region. ALIGN-PATTERN must include the whitespace to be expanded or
7621 contracted. It may also provide regexps for the text surrounding the
7622 whitespace. SUBEXP specifies which sub-expression of
7623 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7624
7625 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7626 ;; Align code
7627
7628 (defvar vhdl-align-try-all-clauses t
7629 "If REGEXP is not found on the first line of the region that clause
7630 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7631
7632 (defun vhdl-do-group (function &optional spacing)
7633 "Apply FUNCTION on group of lines between empty lines."
7634 (let
7635 ;; search for group beginning
7636 ((beg (save-excursion
7637 (if (re-search-backward vhdl-align-group-separate nil t)
7638 (progn (beginning-of-line 2) (back-to-indentation) (point))
7639 (point-min))))
7640 ;; search for group end
7641 (end (save-excursion
7642 (if (re-search-forward vhdl-align-group-separate nil t)
7643 (progn (beginning-of-line) (point))
7644 (point-max)))))
7645 ;; run FUNCTION
7646 (funcall function beg end spacing)))
7647
7648 (defun vhdl-do-list (function &optional spacing)
7649 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7650 parentheses."
7651 (let (beg end)
7652 (save-excursion
7653 ;; search for beginning of balanced group of parentheses
7654 (setq beg (vhdl-re-search-backward "[()]" nil t))
7655 (while (looking-at ")")
7656 (forward-char) (backward-sexp)
7657 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7658 ;; search for end of balanced group of parentheses
7659 (when beg
7660 (forward-list)
7661 (setq end (point))
7662 (goto-char (1+ beg))
7663 (skip-chars-forward " \t\n\r\f")
7664 (setq beg (point))))
7665 ;; run FUNCTION
7666 (if beg
7667 (funcall function beg end spacing)
7668 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7669
7670 (defun vhdl-do-same-indent (function &optional spacing)
7671 "Apply FUNCTION to block of lines with same indent."
7672 (let ((indent (current-indentation))
7673 beg end)
7674 ;; search for first line with same indent
7675 (save-excursion
7676 (while (and (not (bobp))
7677 (or (looking-at "^\\s-*\\(--.*\\)?$")
7678 (= (current-indentation) indent)))
7679 (unless (looking-at "^\\s-*$")
7680 (back-to-indentation) (setq beg (point)))
7681 (beginning-of-line -0)))
7682 ;; search for last line with same indent
7683 (save-excursion
7684 (while (and (not (eobp))
7685 (or (looking-at "^\\s-*\\(--.*\\)?$")
7686 (= (current-indentation) indent)))
7687 (if (looking-at "^\\s-*$")
7688 (beginning-of-line 2)
7689 (beginning-of-line 2)
7690 (setq end (point)))))
7691 ;; run FUNCTION
7692 (funcall function beg end spacing)))
7693
7694 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7695 "Attempt to align a range of lines based on the content of the
7696 lines. The definition of `alignment-list' determines the matching
7697 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7698 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7699 indentation is done before aligning."
7700 (interactive "r\np")
7701 (setq alignment-list (or alignment-list vhdl-align-alist))
7702 (setq spacing (or spacing 1))
7703 (save-excursion
7704 (let (bol indent)
7705 (goto-char end)
7706 (setq end (point-marker))
7707 (goto-char begin)
7708 (setq bol (setq begin (progn (beginning-of-line) (point))))
7709 (when indent
7710 (indent-region bol end nil))))
7711 (let ((copy (copy-alist alignment-list)))
7712 (vhdl-prepare-search-2
7713 (while copy
7714 (save-excursion
7715 (goto-char begin)
7716 (let (element
7717 (eol (point-at-eol)))
7718 (setq element (nth 0 copy))
7719 (when (and (or (and (listp (car element))
7720 (memq major-mode (car element)))
7721 (eq major-mode (car element)))
7722 (or vhdl-align-try-all-clauses
7723 (re-search-forward (car (cdr element)) eol t)))
7724 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7725 (car (cdr (cdr (cdr element)))) spacing))
7726 (setq copy (cdr copy))))))))
7727
7728 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7729 "Align a range of lines from BEGIN to END. The regular expression
7730 MATCH must match exactly one field: the whitespace to be
7731 contracted/expanded. The alignment column will equal the
7732 rightmost column of the widest whitespace block. SPACING is
7733 the amount of extra spaces to add to the calculated maximum required.
7734 SPACING defaults to 1 so that at least one space is inserted after
7735 the token in MATCH."
7736 (setq spacing (or spacing 1))
7737 (setq substr (or substr 1))
7738 (save-excursion
7739 (let (distance (max 0) (lines 0) bol eol width)
7740 ;; Determine the greatest whitespace distance to the alignment
7741 ;; character
7742 (goto-char begin)
7743 (setq eol (point-at-eol)
7744 bol (setq begin (progn (beginning-of-line) (point))))
7745 (while (< bol end)
7746 (save-excursion
7747 (when (and (vhdl-re-search-forward match eol t)
7748 (save-excursion
7749 (goto-char (match-beginning 0))
7750 (forward-char)
7751 (and (not (vhdl-in-literal))
7752 (not (vhdl-in-quote-p))
7753 (not (vhdl-in-extended-identifier-p))))
7754 (not (looking-at "\\s-*$")))
7755 (setq distance (- (match-beginning substr) bol))
7756 (when (> distance max)
7757 (setq max distance))))
7758 (forward-line)
7759 (setq bol (point)
7760 eol (point-at-eol))
7761 (setq lines (1+ lines)))
7762 ;; Now insert enough maxs to push each assignment operator to
7763 ;; the same column. We need to use 'lines' as a counter, since
7764 ;; the location of the mark may change
7765 (goto-char (setq bol begin))
7766 (setq eol (point-at-eol))
7767 (while (> lines 0)
7768 (when (and (vhdl-re-search-forward match eol t)
7769 (save-excursion
7770 (goto-char (match-beginning 0))
7771 (forward-char)
7772 (and (not (vhdl-in-literal))
7773 (not (vhdl-in-quote-p))
7774 (not (vhdl-in-extended-identifier-p))))
7775 (not (looking-at "\\s-*$"))
7776 (> (match-beginning 0) ; not if at boi
7777 (save-excursion (back-to-indentation) (point))))
7778 (setq width (- (match-end substr) (match-beginning substr)))
7779 (setq distance (- (match-beginning substr) bol))
7780 (goto-char (match-beginning substr))
7781 (delete-char width)
7782 (insert-char ? (+ (- max distance) spacing)))
7783 (beginning-of-line)
7784 (forward-line)
7785 (setq bol (point)
7786 eol (point-at-eol))
7787 (setq lines (1- lines))))))
7788
7789 (defun vhdl-align-region-groups (beg end &optional spacing
7790 no-message no-comments)
7791 "Align region, treat groups of lines separately."
7792 (interactive "r\nP")
7793 (save-excursion
7794 (let (orig pos)
7795 (goto-char beg)
7796 (beginning-of-line)
7797 (setq orig (point-marker))
7798 (setq beg (point))
7799 (goto-char end)
7800 (setq end (point-marker))
7801 (untabify beg end)
7802 (unless no-message
7803 (when vhdl-progress-interval
7804 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7805 (count-lines (point-min) end) 0))))
7806 (when (nth 0 vhdl-beautify-options)
7807 (vhdl-fixup-whitespace-region beg end t))
7808 (goto-char beg)
7809 (if (not vhdl-align-groups)
7810 ;; align entire region
7811 (progn (vhdl-align-region-1 beg end spacing)
7812 (unless no-comments
7813 (vhdl-align-inline-comment-region-1 beg end)))
7814 ;; align groups
7815 (while (and (< beg end)
7816 (re-search-forward vhdl-align-group-separate end t))
7817 (setq pos (point-marker))
7818 (vhdl-align-region-1 beg pos spacing)
7819 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7820 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7821 (setq beg (1+ pos))
7822 (goto-char beg))
7823 ;; align last group
7824 (when (< beg end)
7825 (vhdl-align-region-1 beg end spacing)
7826 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7827 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7828 (when vhdl-indent-tabs-mode
7829 (tabify orig end))
7830 (unless no-message
7831 (when vhdl-progress-interval (message "Aligning...done"))
7832 (setq vhdl-progress-info nil)))))
7833
7834 (defun vhdl-align-region (beg end &optional spacing)
7835 "Align region, treat blocks with same indent and argument lists separately."
7836 (interactive "r\nP")
7837 (if (not vhdl-align-same-indent)
7838 ;; align entire region
7839 (vhdl-align-region-groups beg end spacing)
7840 ;; align blocks with same indent and argument lists
7841 (save-excursion
7842 (let ((cur-beg beg)
7843 indent cur-end)
7844 (when vhdl-progress-interval
7845 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7846 (count-lines (point-min) end) 0)))
7847 (goto-char end)
7848 (setq end (point-marker))
7849 (goto-char cur-beg)
7850 (while (< (point) end)
7851 ;; is argument list opening?
7852 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7853 (point) (vhdl-point 'eol)))))
7854 ;; determine region for argument list
7855 (progn (goto-char cur-beg)
7856 (forward-sexp)
7857 (setq cur-end (point))
7858 (beginning-of-line 2))
7859 ;; determine region with same indent
7860 (setq indent (current-indentation))
7861 (setq cur-beg (point))
7862 (setq cur-end (vhdl-point 'bonl))
7863 (beginning-of-line 2)
7864 (while (and (< (point) end)
7865 (or (looking-at "^\\s-*\\(--.*\\)?$")
7866 (= (current-indentation) indent))
7867 (<= (save-excursion
7868 (nth 0 (parse-partial-sexp
7869 (point) (vhdl-point 'eol)))) 0))
7870 (unless (looking-at "^\\s-*$")
7871 (setq cur-end (vhdl-point 'bonl)))
7872 (beginning-of-line 2)))
7873 ;; align region
7874 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7875 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7876 (when vhdl-progress-interval (message "Aligning...done"))
7877 (setq vhdl-progress-info nil)))))
7878
7879 (defun vhdl-align-group (&optional spacing)
7880 "Align group of lines between empty lines."
7881 (interactive)
7882 (vhdl-do-group 'vhdl-align-region spacing))
7883
7884 (defun vhdl-align-list (&optional spacing)
7885 "Align the lines of a list surrounded by a balanced group of parentheses."
7886 (interactive)
7887 (vhdl-do-list 'vhdl-align-region-groups spacing))
7888
7889 (defun vhdl-align-same-indent (&optional spacing)
7890 "Align block of lines with same indent."
7891 (interactive)
7892 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7893
7894 (defun vhdl-align-declarations (&optional spacing)
7895 "Align the lines within the declarative part of a design unit."
7896 (interactive)
7897 (let (beg end)
7898 (vhdl-prepare-search-2
7899 (save-excursion
7900 ;; search for declarative part
7901 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
7902 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7903 (setq beg (point))
7904 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7905 (setq end (point)))))
7906 (if beg
7907 (vhdl-align-region-groups beg end spacing)
7908 (error "ERROR: Not within the declarative part of a design unit"))))
7909
7910 (defun vhdl-align-buffer ()
7911 "Align buffer."
7912 (interactive)
7913 (vhdl-align-region (point-min) (point-max)))
7914
7915 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7916 ;; Align inline comments
7917
7918 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7919 "Align inline comments in region."
7920 (save-excursion
7921 (let ((start-max comment-column)
7922 (length-max 0)
7923 comment-list start-list tmp-list start length
7924 cur-start prev-start no-code)
7925 (setq spacing (or spacing 2))
7926 (vhdl-prepare-search-2
7927 (goto-char beg)
7928 ;; search for comment start positions and lengths
7929 (while (< (point) end)
7930 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7931 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7932 (not (save-excursion (goto-char (match-beginning 2))
7933 (vhdl-in-literal))))
7934 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7935 (setq length (- (match-end 2) (match-beginning 2)))
7936 (setq start-max (max start start-max))
7937 (setq length-max (max length length-max))
7938 (push (cons start length) comment-list))
7939 (beginning-of-line 2))
7940 (setq comment-list
7941 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7942 ;; reduce start positions
7943 (setq start-list (list (caar comment-list)))
7944 (setq comment-list (cdr comment-list))
7945 (while comment-list
7946 (unless (or (= (caar comment-list) (car start-list))
7947 (<= (+ (car start-list) (cdar comment-list))
7948 end-comment-column))
7949 (push (caar comment-list) start-list))
7950 (setq comment-list (cdr comment-list)))
7951 ;; align lines as nicely as possible
7952 (goto-char beg)
7953 (while (< (point) end)
7954 (setq cur-start nil)
7955 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7956 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7957 (not (save-excursion
7958 (goto-char (match-beginning 3))
7959 (vhdl-in-literal))))
7960 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7961 (>= (- (match-end 2) (match-beginning 2))
7962 comment-column))))
7963 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7964 (setq length (- (match-end 3) (match-beginning 3)))
7965 (setq no-code (= (match-beginning 1) (match-end 1)))
7966 ;; insert minimum whitespace
7967 (goto-char (match-end 2))
7968 (delete-region (match-beginning 2) (match-end 2))
7969 (insert-char ?\ spacing)
7970 (setq tmp-list start-list)
7971 ;; insert additional whitespace to align
7972 (setq cur-start
7973 (cond
7974 ;; align comment-only line to inline comment of previous line
7975 ((and no-code prev-start
7976 (<= length (- end-comment-column prev-start)))
7977 prev-start)
7978 ;; align all comments at `start-max' if this is possible
7979 ((<= (+ start-max length-max) end-comment-column)
7980 start-max)
7981 ;; align at `comment-column' if possible
7982 ((and (<= start comment-column)
7983 (<= length (- end-comment-column comment-column)))
7984 comment-column)
7985 ;; align at left-most possible start position otherwise
7986 (t
7987 (while (and tmp-list (< (car tmp-list) start))
7988 (setq tmp-list (cdr tmp-list)))
7989 (car tmp-list))))
7990 (indent-to cur-start))
7991 (setq prev-start cur-start)
7992 (beginning-of-line 2))))))
7993
7994 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7995 "Align inline comments within a region. Groups of code lines separated by
7996 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7997 (interactive "r\nP")
7998 (save-excursion
7999 (let (orig pos)
8000 (goto-char beg)
8001 (beginning-of-line)
8002 (setq orig (point-marker))
8003 (setq beg (point))
8004 (goto-char end)
8005 (setq end (point-marker))
8006 (untabify beg end)
8007 (unless no-message (message "Aligning inline comments..."))
8008 (goto-char beg)
8009 (if (not vhdl-align-groups)
8010 ;; align entire region
8011 (vhdl-align-inline-comment-region-1 beg end spacing)
8012 ;; align groups
8013 (while (and (< beg end)
8014 (re-search-forward vhdl-align-group-separate end t))
8015 (setq pos (point-marker))
8016 (vhdl-align-inline-comment-region-1 beg pos spacing)
8017 (setq beg (1+ pos))
8018 (goto-char beg))
8019 ;; align last group
8020 (when (< beg end)
8021 (vhdl-align-inline-comment-region-1 beg end spacing)))
8022 (when vhdl-indent-tabs-mode
8023 (tabify orig end))
8024 (unless no-message (message "Aligning inline comments...done")))))
8025
8026 (defun vhdl-align-inline-comment-group (&optional spacing)
8027 "Align inline comments within a group of lines between empty lines."
8028 (interactive)
8029 (save-excursion
8030 (let ((start (point))
8031 beg end)
8032 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
8033 (point-marker) (point-max)))
8034 (goto-char start)
8035 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
8036 (point) (point-min)))
8037 (untabify beg end)
8038 (message "Aligning inline comments...")
8039 (vhdl-align-inline-comment-region-1 beg end)
8040 (when vhdl-indent-tabs-mode
8041 (tabify beg end))
8042 (message "Aligning inline comments...done"))))
8043
8044 (defun vhdl-align-inline-comment-buffer ()
8045 "Align inline comments within buffer. Groups of code lines separated by
8046 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8047 (interactive)
8048 (vhdl-align-inline-comment-region (point-min) (point-max)))
8049
8050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8051 ;; Fixup whitespace
8052
8053 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
8054 "Fixup whitespace in region. Surround operator symbols by one space,
8055 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8056 end of line, do nothing in comments and strings."
8057 (interactive "r")
8058 (unless no-message (message "Fixing up whitespace..."))
8059 (save-excursion
8060 (goto-char end)
8061 (setq end (point-marker))
8062 ;; have no space before and one space after `,' and ';'
8063 (goto-char beg)
8064 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
8065 (if (match-string 1)
8066 (goto-char (match-end 1))
8067 (replace-match "\\3 " nil nil nil 2)))
8068 ;; have no space after `('
8069 (goto-char beg)
8070 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
8071 (if (match-string 1)
8072 (goto-char (match-end 1))
8073 (replace-match "\\2")))
8074 ;; have no space before `)'
8075 (goto-char beg)
8076 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
8077 (if (match-string 1)
8078 (goto-char (match-end 1))
8079 (replace-match "\\2")))
8080 ;; surround operator symbols by one space
8081 (goto-char beg)
8082 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
8083 (if (or (match-string 1)
8084 (<= (match-beginning 0) ; not if at boi
8085 (save-excursion (back-to-indentation) (point))))
8086 (goto-char (match-end 0))
8087 (replace-match "\\3 \\4 \\5")
8088 (goto-char (match-end 2))))
8089 ;; eliminate multiple spaces and spaces at end of line
8090 (goto-char beg)
8091 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
8092 (and (looking-at "--.*") (re-search-forward "--.*" end t))
8093 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
8094 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
8095 (progn (replace-match "" nil nil) t))
8096 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
8097 (progn (replace-match ";" nil nil) t))
8098 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" 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 "-") (re-search-forward "-" end t))
8104 (re-search-forward "[^ \t\"-]+" end t))))
8105 (unless no-message (message "Fixing up whitespace...done")))
8106
8107 (defun vhdl-fixup-whitespace-buffer ()
8108 "Fixup whitespace in buffer. Surround operator symbols by one space,
8109 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8110 end of line, do nothing in comments."
8111 (interactive)
8112 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8113
8114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8115 ;; Case fixing
8116
8117 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8118 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8119 depending on parameter UPPER-CASE."
8120 (let ((case-replace nil)
8121 (last-update 0))
8122 (vhdl-prepare-search-2
8123 (save-excursion
8124 (goto-char end)
8125 (setq end (point-marker))
8126 (goto-char beg)
8127 (while (re-search-forward word-regexp end t)
8128 (or (vhdl-in-literal)
8129 (if upper-case
8130 (upcase-word -1)
8131 (downcase-word -1)))
8132 (when (and count vhdl-progress-interval (not noninteractive)
8133 (< vhdl-progress-interval
8134 (- (nth 1 (current-time)) last-update)))
8135 (message "Fixing case... (%2d%s)"
8136 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8137 "%")
8138 (setq last-update (nth 1 (current-time)))))
8139 (goto-char end)))))
8140
8141 (defun vhdl-fix-case-region (beg end &optional arg)
8142 "Convert all VHDL words in region to lower or upper case, depending on
8143 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8144 (interactive "r\nP")
8145 (vhdl-fix-case-region-1
8146 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8147 (vhdl-fix-case-region-1
8148 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8149 (vhdl-fix-case-region-1
8150 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8151 (vhdl-fix-case-region-1
8152 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8153 (vhdl-fix-case-region-1
8154 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8155 (when vhdl-progress-interval (message "Fixing case...done")))
8156
8157 (defun vhdl-fix-case-buffer ()
8158 "Convert all VHDL words in buffer to lower or upper case, depending on
8159 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8160 (interactive)
8161 (vhdl-fix-case-region (point-min) (point-max)))
8162
8163 (defun vhdl-fix-case-word (&optional arg)
8164 "Convert word after cursor to upper case if necessary."
8165 (interactive "p")
8166 (save-excursion
8167 (when arg (backward-word 1))
8168 (vhdl-prepare-search-1
8169 (when (and vhdl-upper-case-keywords
8170 (looking-at vhdl-keywords-regexp))
8171 (upcase-word 1))
8172 (when (and vhdl-upper-case-types
8173 (looking-at vhdl-types-regexp))
8174 (upcase-word 1))
8175 (when (and vhdl-upper-case-attributes
8176 (looking-at vhdl-attributes-regexp))
8177 (upcase-word 1))
8178 (when (and vhdl-upper-case-enum-values
8179 (looking-at vhdl-enum-values-regexp))
8180 (upcase-word 1))
8181 (when (and vhdl-upper-case-constants
8182 (looking-at vhdl-constants-regexp))
8183 (upcase-word 1)))))
8184
8185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8186 ;; Fix statements
8187 ;; - force each statement to be on a separate line except when on same line
8188 ;; with 'end' keyword
8189
8190 (defun vhdl-fix-statement-region (beg end &optional arg)
8191 "Force statements in region on separate line except when on same line
8192 with `end' keyword (necessary for correct indentation).
8193 Currently supported keywords: `begin', `if'."
8194 (interactive "r\nP")
8195 (vhdl-prepare-search-2
8196 (let (point)
8197 (save-excursion
8198 (goto-char end)
8199 (setq end (point-marker))
8200 (goto-char beg)
8201 ;; `begin' keyword
8202 (while (re-search-forward
8203 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8204 (goto-char (match-end 0))
8205 (setq point (point-marker))
8206 (when (and (match-string 1)
8207 (or (not (match-string 2))
8208 (save-excursion (goto-char (match-end 2))
8209 (vhdl-in-literal)))
8210 (not (save-excursion (goto-char (match-beginning 1))
8211 (vhdl-in-literal))))
8212 (goto-char (match-beginning 1))
8213 (insert "\n")
8214 (indent-according-to-mode))
8215 (goto-char point))
8216 (goto-char beg)
8217 ;; `for', `if' keywords
8218 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8219 (goto-char (match-end 1))
8220 (setq point (point-marker))
8221 ;; exception: in literal or preceded by `end', `wait' or label
8222 (when (and (not (save-excursion (goto-char (match-beginning 1))
8223 (vhdl-in-literal)))
8224 (save-excursion
8225 (beginning-of-line 1)
8226 (save-match-data
8227 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8228 (match-beginning 1) t)
8229 (not (string-match
8230 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8231 (match-string 1)))))))
8232 (goto-char (match-beginning 1))
8233 (insert "\n")
8234 (indent-according-to-mode))
8235 (goto-char point))))))
8236
8237 (defun vhdl-fix-statement-buffer ()
8238 "Force statements in buffer on separate line except when on same line
8239 with `end' keyword (necessary for correct indentation)."
8240 (interactive)
8241 (vhdl-fix-statement-region (point-min) (point-max)))
8242
8243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8244 ;; Trailing spaces
8245
8246 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8247 "Remove trailing spaces in region."
8248 (interactive "r\nP")
8249 (save-excursion
8250 (goto-char end)
8251 (setq end (point-marker))
8252 (goto-char beg)
8253 (while (re-search-forward "[ \t]+$" end t)
8254 (unless (vhdl-in-literal)
8255 (replace-match "" nil nil)))))
8256
8257 (defun vhdl-remove-trailing-spaces ()
8258 "Remove trailing spaces in buffer."
8259 (interactive)
8260 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8261
8262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8263 ;; Beautify
8264
8265 (defun vhdl-beautify-region (beg end)
8266 "Beautify region by applying indentation, whitespace fixup, alignment, and
8267 case fixing to a region. Calls functions `vhdl-indent-buffer',
8268 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8269 `vhdl-fix-case-buffer'."
8270 (interactive "r")
8271 (setq end (save-excursion (goto-char end) (point-marker)))
8272 (save-excursion ; remove DOS EOL characters in UNIX file
8273 (goto-char beg)
8274 (while (search-forward "\r" nil t)
8275 (replace-match "" nil t)))
8276 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8277 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8278 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8279 (when (nth 3 vhdl-beautify-options)
8280 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8281 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8282 (when (nth 0 vhdl-beautify-options)
8283 (vhdl-remove-trailing-spaces-region beg end)
8284 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8285
8286 (defun vhdl-beautify-buffer ()
8287 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8288 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8289 buffer."
8290 (interactive)
8291 (vhdl-beautify-region (point-min) (point-max))
8292 (when noninteractive (save-buffer)))
8293
8294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8295 ;; Code filling
8296
8297 (defun vhdl-fill-region (beg end &optional arg)
8298 "Fill lines for a region of code."
8299 (interactive "r\np")
8300 (save-excursion
8301 (goto-char beg)
8302 (let ((margin (if arg (current-indentation) (current-column))))
8303 (goto-char end)
8304 (setq end (point-marker))
8305 ;; remove inline comments, newlines and whitespace
8306 (vhdl-comment-kill-region beg end)
8307 (vhdl-comment-kill-inline-region beg end)
8308 (subst-char-in-region beg (1- end) ?\n ?\ )
8309 (vhdl-fixup-whitespace-region beg end)
8310 ;; wrap and end-comment-column
8311 (goto-char beg)
8312 (while (re-search-forward "\\s-" end t)
8313 (when(> (current-column) vhdl-end-comment-column)
8314 (backward-char)
8315 (when (re-search-backward "\\s-" beg t)
8316 (replace-match "\n")
8317 (indent-to margin)))))))
8318
8319 (defun vhdl-fill-group ()
8320 "Fill group of lines between empty lines."
8321 (interactive)
8322 (vhdl-do-group 'vhdl-fill-region))
8323
8324 (defun vhdl-fill-list ()
8325 "Fill the lines of a list surrounded by a balanced group of parentheses."
8326 (interactive)
8327 (vhdl-do-list 'vhdl-fill-region))
8328
8329 (defun vhdl-fill-same-indent ()
8330 "Fill the lines of block of lines with same indent."
8331 (interactive)
8332 (vhdl-do-same-indent 'vhdl-fill-region))
8333
8334
8335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8336 ;;; Code updating/fixing
8337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8338
8339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8340 ;; Sensitivity list update
8341
8342 ;; Strategy:
8343 ;; - no sensitivity list is generated for processes with wait statements
8344 ;; - otherwise, do the following:
8345 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8346 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8347 ;; manually entered global signals)
8348 ;; 3. signals from 1. and 2. form the list of visible signals
8349 ;; 4. search for if/elsif conditions containing an event (sequential code)
8350 ;; 5. scan for strings that are within syntactical regions where signals are
8351 ;; read but not within sequential code, and that correspond to visible
8352 ;; signals
8353 ;; 6. replace sensitivity list by list of signals from 5.
8354
8355 (defun vhdl-update-sensitivity-list-process ()
8356 "Update sensitivity list of current process."
8357 (interactive)
8358 (save-excursion
8359 (vhdl-prepare-search-2
8360 (end-of-line)
8361 ;; look whether in process
8362 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8363 (equal (upcase (match-string 2)) "PROCESS")
8364 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8365 (error "ERROR: Not within a process")
8366 (message "Updating sensitivity list...")
8367 (vhdl-update-sensitivity-list)
8368 (message "Updating sensitivity list...done")))))
8369
8370 (defun vhdl-update-sensitivity-list-buffer ()
8371 "Update sensitivity list of all processes in current buffer."
8372 (interactive)
8373 (save-excursion
8374 (vhdl-prepare-search-2
8375 (goto-char (point-min))
8376 (message "Updating sensitivity lists...")
8377 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8378 (goto-char (match-beginning 0))
8379 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8380 (message "Updating sensitivity lists...done")))
8381 (when noninteractive (save-buffer)))
8382
8383 (defun vhdl-update-sensitivity-list ()
8384 "Update sensitivity list."
8385 (let ((proc-beg (point))
8386 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8387 (proc-mid (vhdl-re-search-backward
8388 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8389 seq-region-list)
8390 (cond
8391 ;; error if 'begin' keyword missing
8392 ((not (match-string 2))
8393 (error "ERROR: No 'begin' keyword found"))
8394 ;; search for wait statement (no sensitivity list allowed)
8395 ((progn (goto-char proc-mid)
8396 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8397 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8398 ;; combinational process (update sensitivity list)
8399 (t
8400 (let
8401 ;; scan for visible signals
8402 ((visible-list (vhdl-get-visible-signals))
8403 ;; define syntactic regions where signals are read
8404 (scan-regions-list
8405 '(;; right-hand side of signal/variable assignment
8406 ;; (special case: "<=" is relational operator in a condition)
8407 ((vhdl-re-search-forward "[<:]=" proc-end t)
8408 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8409 ;; if condition
8410 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8411 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8412 ;; elsif condition
8413 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8414 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8415 ;; while loop condition
8416 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8417 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8418 ;; exit/next condition
8419 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8420 (vhdl-re-search-forward ";" proc-end t))
8421 ;; assert condition
8422 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8423 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8424 ;; case expression
8425 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8426 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8427 ;; parameter list of procedure call, array index
8428 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8429 (1- (point)))
8430 (progn (backward-char) (forward-sexp)
8431 (while (looking-at "(") (forward-sexp)) (point)))))
8432 name field read-list sens-list signal-list tmp-list
8433 sens-beg sens-end beg end margin)
8434 ;; scan for signals in old sensitivity list
8435 (goto-char proc-beg)
8436 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8437 (if (not (looking-at "[ \t\n\r\f]*("))
8438 (setq sens-beg (point))
8439 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8440 (goto-char (match-end 1))
8441 (forward-sexp)
8442 (setq sens-end (1- (point)))
8443 (goto-char sens-beg)
8444 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8445 (setq sens-list
8446 (cons (downcase (match-string 0)) sens-list))
8447 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8448 (setq signal-list (append visible-list sens-list))
8449 ;; search for sequential parts
8450 (goto-char proc-mid)
8451 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8452 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8453 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8454 (goto-char end)
8455 (backward-word 1)
8456 (vhdl-forward-sexp)
8457 (push (cons end (point)) seq-region-list)
8458 (beginning-of-line)))
8459 ;; scan for signals read in process
8460 (while scan-regions-list
8461 (goto-char proc-mid)
8462 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8463 (setq end (eval (nth 1 (car scan-regions-list)))))
8464 (goto-char beg)
8465 (unless (or (vhdl-in-literal)
8466 (and seq-region-list
8467 (let ((tmp-list seq-region-list))
8468 (while (and tmp-list
8469 (< (point) (caar tmp-list)))
8470 (setq tmp-list (cdr tmp-list)))
8471 (and tmp-list (< (point) (cdar tmp-list))))))
8472 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8473 (setq name (match-string 1))
8474 ;; get array index range
8475 (when vhdl-array-index-record-field-in-sensitivity-list
8476 (setq field (match-string 2))
8477 ;; not use if it includes a variable name
8478 (save-match-data
8479 (setq tmp-list visible-list)
8480 (while (and field tmp-list)
8481 (when (string-match
8482 (concat "\\<" (car tmp-list) "\\>") field)
8483 (setq field nil))
8484 (setq tmp-list (cdr tmp-list)))))
8485 (when (and (not (match-string 6)) ; not when formal parameter
8486 (not (and (match-string 5) ; not event attribute
8487 (not (member (downcase (match-string 5))
8488 '("event" "last_event" "transaction")))))
8489 (member (downcase name) signal-list))
8490 ;; not add if name or name+field already exists
8491 (unless
8492 (or (member-ignore-case name read-list)
8493 (member-ignore-case (concat name field) read-list))
8494 (push (concat name field) read-list))
8495 (setq tmp-list read-list)
8496 ;; remove existing name+field if name is added
8497 (save-match-data
8498 (while tmp-list
8499 (when (string-match (concat "^" name field "[(.]")
8500 (car tmp-list))
8501 (setq read-list (delete (car tmp-list) read-list)))
8502 (setq tmp-list (cdr tmp-list)))))
8503 (goto-char (match-end 1)))))
8504 (setq scan-regions-list (cdr scan-regions-list)))
8505 ;; update sensitivity list
8506 (goto-char sens-beg)
8507 (if sens-end
8508 (delete-region sens-beg sens-end)
8509 (when read-list
8510 (insert " ()") (backward-char)))
8511 (setq read-list (sort read-list 'string<))
8512 (when read-list
8513 (setq margin (current-column))
8514 (insert (car read-list))
8515 (setq read-list (cdr read-list))
8516 (while read-list
8517 (insert ",")
8518 (if (<= (+ (current-column) (length (car read-list)) 2)
8519 end-comment-column)
8520 (insert " ")
8521 (insert "\n") (indent-to margin))
8522 (insert (car read-list))
8523 (setq read-list (cdr read-list)))))))))
8524
8525 (defun vhdl-get-visible-signals ()
8526 "Get all signals visible in the current block."
8527 (let (beg end signal-list entity-name file-name)
8528 (vhdl-prepare-search-2
8529 ;; get entity name
8530 (save-excursion
8531 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8532 (not (equal "END" (upcase (match-string 1))))
8533 (setq entity-name (match-string 2)))
8534 (error "ERROR: Not within an architecture")))
8535 ;; search for signals declared in entity port clause
8536 (save-excursion
8537 (goto-char (point-min))
8538 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8539 (setq file-name
8540 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8541 "." (file-name-extension (buffer-file-name)))))
8542 (vhdl-visit-file
8543 file-name t
8544 (vhdl-prepare-search-2
8545 (goto-char (point-min))
8546 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8547 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8548 (when (setq beg (vhdl-re-search-forward
8549 "\\<port[ \t\n\r\f]*("
8550 (save-excursion
8551 (re-search-forward "^end\\>" nil t)) t))
8552 (setq end (save-excursion
8553 (backward-char) (forward-sexp) (point)))
8554 (vhdl-forward-syntactic-ws)
8555 (while (< (point) end)
8556 (when (looking-at "signal[ \t\n\r\f]+")
8557 (goto-char (match-end 0)))
8558 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8559 (setq signal-list
8560 (cons (downcase (match-string 1)) signal-list))
8561 (goto-char (match-end 0))
8562 (vhdl-forward-syntactic-ws))
8563 (re-search-forward ";" end 1)
8564 (vhdl-forward-syntactic-ws)))))))
8565 ;; search for signals declared in architecture declarative part
8566 (save-excursion
8567 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8568 (not (equal "END" (upcase (match-string 1))))
8569 (setq end (re-search-forward "^begin\\>" nil t))))
8570 (error "ERROR: No architecture declarative part found")
8571 ;; scan for all declared signal and alias names
8572 (goto-char beg)
8573 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8574 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8575 (if (match-string 2)
8576 ;; scan signal name
8577 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8578 (setq signal-list
8579 (cons (downcase (match-string 1)) signal-list))
8580 (goto-char (match-end 0)))
8581 ;; scan alias name, check is alias of (declared) signal
8582 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8583 (member (downcase (match-string 2)) signal-list))
8584 (setq signal-list
8585 (cons (downcase (match-string 1)) signal-list))
8586 (goto-char (match-end 0))))
8587 (setq beg (point))))))
8588 ;; search for signals declared in surrounding block declarative parts
8589 (save-excursion
8590 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8591 (match-string 4))
8592 (goto-char (match-end 4))
8593 (vhdl-backward-sexp)
8594 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8595 beg)
8596 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8597 ;; scan for all declared signal names
8598 (goto-char beg)
8599 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8600 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8601 (if (match-string 2)
8602 ;; scan signal name
8603 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8604 (setq signal-list
8605 (cons (downcase (match-string 1)) signal-list))
8606 (goto-char (match-end 0)))
8607 ;; scan alias name, check is alias of (declared) signal
8608 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8609 (member (downcase (match-string 2)) signal-list))
8610 (setq signal-list
8611 (cons (downcase (match-string 1)) signal-list))
8612 (goto-char (match-end 0))))))
8613 (goto-char beg)))
8614 signal-list)))
8615
8616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8617 ;; Generic/port clause fixing
8618
8619 (defun vhdl-fix-clause-buffer ()
8620 "Fix all generic/port clauses in current buffer."
8621 (interactive)
8622 (save-excursion
8623 (vhdl-prepare-search-2
8624 (goto-char (point-min))
8625 (message "Fixing generic/port clauses...")
8626 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8627 (goto-char (match-end 0))
8628 (condition-case nil (vhdl-fix-clause) (error "")))
8629 (message "Fixing generic/port clauses...done"))))
8630
8631 (defun vhdl-fix-clause ()
8632 "Fix closing parenthesis within generic/port clause."
8633 (interactive)
8634 (save-excursion
8635 (vhdl-prepare-search-2
8636 (let ((pos (point))
8637 beg end)
8638 (end-of-line)
8639 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8640 (error "ERROR: Not within a generic/port clause")
8641 ;; search for end of clause
8642 (goto-char (match-end 0))
8643 (setq beg (1- (point)))
8644 (vhdl-forward-syntactic-ws)
8645 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8646 (goto-char (1- (match-end 0)))
8647 (setq end (point-marker))
8648 (forward-char)
8649 (vhdl-forward-syntactic-ws))
8650 (goto-char end)
8651 (when (> pos (point-at-eol))
8652 (error "ERROR: Not within a generic/port clause"))
8653 ;; delete closing parenthesis on separate line (not supported style)
8654 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8655 (vhdl-line-kill)
8656 (vhdl-backward-syntactic-ws)
8657 (setq end (point-marker))
8658 (insert ";"))
8659 ;; delete superfluous parentheses
8660 (while (progn (goto-char beg)
8661 (condition-case () (forward-sexp)
8662 (error (goto-char (point-max))))
8663 (< (point) end))
8664 (delete-char -1))
8665 ;; add closing parenthesis
8666 (when (> (point) end)
8667 (goto-char end)
8668 (insert ")")))))))
8669
8670
8671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8672 ;;; Electrification
8673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8674
8675 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8676 "Syntax of prompt inserted by template generators.")
8677
8678 (defvar vhdl-template-invoked-by-hook nil
8679 "Indicates whether a template has been invoked by a hook or by key or menu.
8680 Used for undoing after template abortion.")
8681
8682 ;; correct different behavior of function `unread-command-events' in XEmacs
8683 (defun vhdl-character-to-event (arg))
8684 (defalias 'vhdl-character-to-event
8685 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8686
8687 (defun vhdl-work-library ()
8688 "Return the working library name of the current project or \"work\" if no
8689 project is defined."
8690 (vhdl-resolve-env-variable
8691 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8692 vhdl-default-library)))
8693
8694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8695 ;; Enabling/disabling
8696
8697 (define-minor-mode vhdl-electric-mode
8698 "Toggle VHDL electric mode.
8699 With a prefix argument ARG, enable the mode if ARG is positive,
8700 and disable it otherwise. If called from Lisp, enable it if ARG
8701 is omitted or nil."
8702 :global t :group 'vhdl-mode)
8703
8704 (define-minor-mode vhdl-stutter-mode
8705 "Toggle VHDL stuttering mode.
8706 With a prefix argument ARG, enable the mode if ARG is positive,
8707 and disable it otherwise. If called from Lisp, enable it if ARG
8708 is omitted or nil."
8709 :global t :group 'vhdl-mode)
8710
8711 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8712 ;; Stuttering
8713
8714 (defun vhdl-electric-dash (count)
8715 "-- starts a comment, --- draws a horizontal line,
8716 ---- starts a display comment."
8717 (interactive "p")
8718 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8719 (cond
8720 ((and abbrev-start-location (= abbrev-start-location (point)))
8721 (setq abbrev-start-location nil)
8722 (goto-char last-abbrev-location)
8723 (beginning-of-line nil)
8724 (vhdl-comment-display))
8725 ((/= (preceding-char) ?-) ; standard dash (minus)
8726 (self-insert-command count))
8727 (t (self-insert-command count)
8728 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8729 (let ((next-input (read-char)))
8730 (if (= next-input ?-) ; triple dash
8731 (progn
8732 (vhdl-comment-display-line)
8733 (message
8734 "Enter '-' for display comment, else continue coding")
8735 (let ((next-input (read-char)))
8736 (if (= next-input ?-) ; four dashes
8737 (vhdl-comment-display t)
8738 (push (vhdl-character-to-event next-input)
8739 ; pushback the char
8740 unread-command-events))))
8741 (push (vhdl-character-to-event next-input) ; pushback the char
8742 unread-command-events)
8743 (vhdl-comment-insert)))))
8744 (self-insert-command count)))
8745
8746 (defun vhdl-electric-open-bracket (count) "`[' --> `(', `([' --> `['"
8747 (interactive "p")
8748 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8749 (if (= (preceding-char) ?\()
8750 (progn (delete-char -1) (insert-char ?\[ 1))
8751 (insert-char ?\( 1))
8752 (self-insert-command count)))
8753
8754 (defun vhdl-electric-close-bracket (count) "`]' --> `)', `)]' --> `]'"
8755 (interactive "p")
8756 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8757 (progn
8758 (if (= (preceding-char) ?\))
8759 (progn (delete-char -1) (insert-char ?\] 1))
8760 (insert-char ?\) 1))
8761 (blink-matching-open))
8762 (self-insert-command count)))
8763
8764 (defun vhdl-electric-quote (count) "\\='\\=' --> \""
8765 (interactive "p")
8766 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8767 (if (= (preceding-char) vhdl-last-input-event)
8768 (progn (delete-char -1) (insert-char ?\" 1))
8769 (insert-char ?\' 1))
8770 (self-insert-command count)))
8771
8772 (defun vhdl-electric-semicolon (count) "`;;' --> ` : ', `: ;' --> ` := '"
8773 (interactive "p")
8774 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8775 (cond ((= (preceding-char) vhdl-last-input-event)
8776 (progn (delete-char -1)
8777 (unless (eq (preceding-char) ? ) (insert " "))
8778 (insert ": ")
8779 (setq this-command 'vhdl-electric-colon)))
8780 ((and
8781 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8782 (progn (delete-char -1) (insert "= ")))
8783 (t (insert-char ?\; 1)))
8784 (self-insert-command count)))
8785
8786 (defun vhdl-electric-comma (count) "`,,' --> ` <= '"
8787 (interactive "p")
8788 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8789 (cond ((= (preceding-char) vhdl-last-input-event)
8790 (progn (delete-char -1)
8791 (unless (eq (preceding-char) ? ) (insert " "))
8792 (insert "<= ")))
8793 (t (insert-char ?\, 1)))
8794 (self-insert-command count)))
8795
8796 (defun vhdl-electric-period (count) "`..' --> ` => '"
8797 (interactive "p")
8798 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8799 (cond ((= (preceding-char) vhdl-last-input-event)
8800 (progn (delete-char -1)
8801 (unless (eq (preceding-char) ? ) (insert " "))
8802 (insert "=> ")))
8803 (t (insert-char ?\. 1)))
8804 (self-insert-command count)))
8805
8806 (defun vhdl-electric-equal (count) "`==' --> ` == '"
8807 (interactive "p")
8808 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8809 (cond ((= (preceding-char) vhdl-last-input-event)
8810 (progn (delete-char -1)
8811 (unless (eq (preceding-char) ? ) (insert " "))
8812 (insert "== ")))
8813 (t (insert-char ?\= 1)))
8814 (self-insert-command count)))
8815
8816 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8817 ;; VHDL templates
8818
8819 (defun vhdl-template-paired-parens ()
8820 "Insert a pair of round parentheses, placing point between them."
8821 (interactive)
8822 (insert "()")
8823 (backward-char))
8824
8825 (defun vhdl-template-alias ()
8826 "Insert alias declaration."
8827 (interactive)
8828 (let ((start (point)))
8829 (vhdl-insert-keyword "ALIAS ")
8830 (when (vhdl-template-field "name" nil t start (point))
8831 (insert " : ")
8832 (unless (vhdl-template-field
8833 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8834 nil t)
8835 (delete-char -3))
8836 (vhdl-insert-keyword " IS ")
8837 (vhdl-template-field "name" ";")
8838 (vhdl-comment-insert-inline))))
8839
8840 (defun vhdl-template-architecture ()
8841 "Insert architecture."
8842 (interactive)
8843 (let ((margin (current-indentation))
8844 (start (point))
8845 arch-name)
8846 (vhdl-insert-keyword "ARCHITECTURE ")
8847 (when (setq arch-name
8848 (vhdl-template-field "name" nil t start (point)))
8849 (vhdl-insert-keyword " OF ")
8850 (if (save-excursion
8851 (vhdl-prepare-search-1
8852 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8853 (insert (match-string 1))
8854 (vhdl-template-field "entity name"))
8855 (vhdl-insert-keyword " IS\n")
8856 (vhdl-template-begin-end
8857 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8858 (memq vhdl-insert-empty-lines '(unit all))))))
8859
8860 (defun vhdl-template-array (kind &optional secondary)
8861 "Insert array type definition."
8862 (interactive)
8863 (let ((start (point)))
8864 (vhdl-insert-keyword "ARRAY (")
8865 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8866 secondary)
8867 (vhdl-insert-keyword ") OF ")
8868 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8869 (vhdl-insert-keyword ";"))))
8870
8871 (defun vhdl-template-assert ()
8872 "Insert an assertion statement."
8873 (interactive)
8874 (let ((start (point)))
8875 (vhdl-insert-keyword "ASSERT ")
8876 (when vhdl-conditions-in-parenthesis (insert "("))
8877 (when (vhdl-template-field "condition (negated)" nil t start (point))
8878 (when vhdl-conditions-in-parenthesis (insert ")"))
8879 (setq start (point))
8880 (vhdl-insert-keyword " REPORT ")
8881 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8882 (delete-region start (point)))
8883 (setq start (point))
8884 (vhdl-insert-keyword " SEVERITY ")
8885 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8886 (delete-region start (point)))
8887 (insert ";"))))
8888
8889 (defun vhdl-template-attribute ()
8890 "Insert an attribute declaration or specification."
8891 (interactive)
8892 (if (eq (vhdl-decision-query
8893 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8894 (vhdl-template-attribute-spec)
8895 (vhdl-template-attribute-decl)))
8896
8897 (defun vhdl-template-attribute-decl ()
8898 "Insert an attribute declaration."
8899 (interactive)
8900 (let ((start (point)))
8901 (vhdl-insert-keyword "ATTRIBUTE ")
8902 (when (vhdl-template-field "name" " : " t start (point))
8903 (vhdl-template-field "type" ";")
8904 (vhdl-comment-insert-inline))))
8905
8906 (defun vhdl-template-attribute-spec ()
8907 "Insert an attribute specification."
8908 (interactive)
8909 (let ((start (point)))
8910 (vhdl-insert-keyword "ATTRIBUTE ")
8911 (when (vhdl-template-field "name" nil t start (point))
8912 (vhdl-insert-keyword " OF ")
8913 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8914 (vhdl-template-field "entity class")
8915 (vhdl-insert-keyword " IS ")
8916 (vhdl-template-field "expression" ";"))))
8917
8918 (defun vhdl-template-block ()
8919 "Insert a block."
8920 (interactive)
8921 (let ((margin (current-indentation))
8922 (start (point))
8923 label)
8924 (vhdl-insert-keyword ": BLOCK ")
8925 (goto-char start)
8926 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8927 (forward-word 1)
8928 (forward-char 1)
8929 (insert "(")
8930 (if (vhdl-template-field "[guard expression]" nil t)
8931 (insert ")")
8932 (delete-char -2))
8933 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8934 (insert "\n")
8935 (vhdl-template-begin-end "BLOCK" label margin)
8936 (vhdl-comment-block))))
8937
8938 (defun vhdl-template-block-configuration ()
8939 "Insert a block configuration statement."
8940 (interactive)
8941 (let ((margin (current-indentation))
8942 (start (point)))
8943 (vhdl-insert-keyword "FOR ")
8944 (when (vhdl-template-field "block name" nil t start (point))
8945 (vhdl-insert-keyword "\n\n")
8946 (indent-to margin)
8947 (vhdl-insert-keyword "END FOR;")
8948 (end-of-line 0)
8949 (indent-to (+ margin vhdl-basic-offset)))))
8950
8951 (defun vhdl-template-break ()
8952 "Insert a break statement."
8953 (interactive)
8954 (let (position)
8955 (vhdl-insert-keyword "BREAK")
8956 (setq position (point))
8957 (insert " ")
8958 (while (or
8959 (progn (vhdl-insert-keyword "FOR ")
8960 (if (vhdl-template-field "[quantity name]" " USE " t)
8961 (progn (vhdl-template-field "quantity name" " => ") t)
8962 (delete-region (point)
8963 (progn (forward-word -1) (point)))
8964 nil))
8965 (vhdl-template-field "[quantity name]" " => " t))
8966 (vhdl-template-field "expression")
8967 (setq position (point))
8968 (insert ", "))
8969 (delete-region position (point))
8970 (unless (vhdl-sequential-statement-p)
8971 (vhdl-insert-keyword " ON ")
8972 (if (vhdl-template-field "[sensitivity list]" nil t)
8973 (setq position (point))
8974 (delete-region position (point))))
8975 (vhdl-insert-keyword " WHEN ")
8976 (when vhdl-conditions-in-parenthesis (insert "("))
8977 (if (vhdl-template-field "[condition]" nil t)
8978 (when vhdl-conditions-in-parenthesis (insert ")"))
8979 (delete-region position (point)))
8980 (insert ";")))
8981
8982 (defun vhdl-template-case (&optional kind)
8983 "Insert a case statement."
8984 (interactive)
8985 (let ((margin (current-indentation))
8986 (start (point))
8987 label)
8988 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8989 (not (vhdl-standard-p 'ams))) 'is 'use)))
8990 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8991 (vhdl-insert-keyword "CASE ")
8992 (vhdl-insert-keyword ": CASE ")
8993 (goto-char start)
8994 (setq label (vhdl-template-field "[label]" nil t))
8995 (unless label (delete-char 2))
8996 (forward-word 1)
8997 (forward-char 1))
8998 (when (vhdl-template-field "expression" nil t start (point))
8999 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
9000 (indent-to margin)
9001 (vhdl-insert-keyword "END CASE")
9002 (when label (insert " " label))
9003 (insert ";")
9004 (forward-line -1)
9005 (indent-to (+ margin vhdl-basic-offset))
9006 (vhdl-insert-keyword "WHEN ")
9007 (let ((position (point)))
9008 (insert " => ;\n")
9009 (indent-to (+ margin vhdl-basic-offset))
9010 (vhdl-insert-keyword "WHEN OTHERS => null;")
9011 (goto-char position)))))
9012
9013 (defun vhdl-template-case-is ()
9014 "Insert a sequential case statement."
9015 (interactive)
9016 (vhdl-template-case 'is))
9017
9018 (defun vhdl-template-case-use ()
9019 "Insert a simultaneous case statement."
9020 (interactive)
9021 (vhdl-template-case 'use))
9022
9023 (defun vhdl-template-component ()
9024 "Insert a component declaration."
9025 (interactive)
9026 (vhdl-template-component-decl))
9027
9028 (defun vhdl-template-component-conf ()
9029 "Insert a component configuration (uses `vhdl-template-configuration-spec'
9030 since these are almost equivalent)."
9031 (interactive)
9032 (let ((margin (current-indentation))
9033 (result (vhdl-template-configuration-spec t)))
9034 (when result
9035 (insert "\n")
9036 (indent-to margin)
9037 (vhdl-insert-keyword "END FOR;")
9038 (when (eq result 'no-use)
9039 (end-of-line -0)))))
9040
9041 (defun vhdl-template-component-decl ()
9042 "Insert a component declaration."
9043 (interactive)
9044 (let ((margin (current-indentation))
9045 (start (point))
9046 name end-column)
9047 (vhdl-insert-keyword "COMPONENT ")
9048 (when (setq name (vhdl-template-field "name" nil t start (point)))
9049 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9050 (insert "\n\n")
9051 (indent-to margin)
9052 (vhdl-insert-keyword "END COMPONENT")
9053 (unless (vhdl-standard-p '87) (insert " " name))
9054 (insert ";")
9055 (setq end-column (current-column))
9056 (end-of-line -0)
9057 (indent-to (+ margin vhdl-basic-offset))
9058 (vhdl-template-generic-list t t)
9059 (insert "\n")
9060 (indent-to (+ margin vhdl-basic-offset))
9061 (vhdl-template-port-list t)
9062 (beginning-of-line 2)
9063 (forward-char end-column))))
9064
9065 (defun vhdl-template-component-inst ()
9066 "Insert a component instantiation statement."
9067 (interactive)
9068 (let ((margin (current-indentation))
9069 (start (point))
9070 unit position)
9071 (when (vhdl-template-field "instance label" nil t start (point))
9072 (insert ": ")
9073 (if (not (vhdl-use-direct-instantiation))
9074 (vhdl-template-field "component name")
9075 ;; direct instantiation
9076 (setq unit (vhdl-template-field
9077 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
9078 (setq unit (upcase (or unit "")))
9079 (cond ((equal unit "ENTITY")
9080 (let ((begin (point)))
9081 (vhdl-template-field "library name" "." t begin (point) nil
9082 (vhdl-work-library))
9083 (vhdl-template-field "entity name" "(")
9084 (if (vhdl-template-field "[architecture name]" nil t)
9085 (insert ")")
9086 (delete-char -1))))
9087 ((equal unit "CONFIGURATION")
9088 (vhdl-template-field "library name" "." nil nil nil nil
9089 (vhdl-work-library))
9090 (vhdl-template-field "configuration name"))
9091 (t (vhdl-template-field "component name"))))
9092 (insert "\n")
9093 (indent-to (+ margin vhdl-basic-offset))
9094 (setq position (point))
9095 (vhdl-insert-keyword "GENERIC ")
9096 (when (vhdl-template-map position t t)
9097 (insert "\n")
9098 (indent-to (+ margin vhdl-basic-offset)))
9099 (setq position (point))
9100 (vhdl-insert-keyword "PORT ")
9101 (unless (vhdl-template-map position t t)
9102 (delete-region (line-beginning-position) (point))
9103 (delete-char -1))
9104 (insert ";"))))
9105
9106 (defun vhdl-template-conditional-signal-asst ()
9107 "Insert a conditional signal assignment."
9108 (interactive)
9109 (when (vhdl-template-field "target signal")
9110 (insert " <= ")
9111 (let ((margin (current-column))
9112 (start (point))
9113 position)
9114 (vhdl-template-field "waveform")
9115 (setq position (point))
9116 (vhdl-insert-keyword " WHEN ")
9117 (when vhdl-conditions-in-parenthesis (insert "("))
9118 (while (and (vhdl-template-field "[condition]" nil t)
9119 (progn
9120 (when vhdl-conditions-in-parenthesis (insert ")"))
9121 (setq position (point))
9122 (vhdl-insert-keyword " ELSE")
9123 (insert "\n")
9124 (indent-to margin)
9125 (vhdl-template-field "[waveform]" nil t)))
9126 (setq position (point))
9127 (vhdl-insert-keyword " WHEN ")
9128 (when vhdl-conditions-in-parenthesis (insert "(")))
9129 (delete-region position (point))
9130 (insert ";")
9131 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9132
9133 (defun vhdl-template-configuration ()
9134 "Insert a configuration specification if within an architecture,
9135 a block or component configuration if within a configuration declaration,
9136 a configuration declaration if not within a design unit."
9137 (interactive)
9138 (vhdl-prepare-search-1
9139 (cond
9140 ((and (save-excursion ; architecture body
9141 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9142 (equal "ARCHITECTURE" (upcase (match-string 1))))
9143 (vhdl-template-configuration-spec))
9144 ((and (save-excursion ; configuration declaration
9145 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9146 (equal "CONFIGURATION" (upcase (match-string 1))))
9147 (if (eq (vhdl-decision-query
9148 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9149 (vhdl-template-component-conf)
9150 (vhdl-template-block-configuration)))
9151 (t (vhdl-template-configuration-decl))))) ; otherwise
9152
9153 (defun vhdl-template-configuration-spec (&optional optional-use)
9154 "Insert a configuration specification."
9155 (interactive)
9156 (let ((margin (current-indentation))
9157 (start (point))
9158 aspect position)
9159 (vhdl-insert-keyword "FOR ")
9160 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9161 t start (point))
9162 (vhdl-template-field "component name" "\n")
9163 (indent-to (+ margin vhdl-basic-offset))
9164 (setq start (point))
9165 (vhdl-insert-keyword "USE ")
9166 (if (and optional-use
9167 (not (setq aspect (vhdl-template-field
9168 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9169 (progn (delete-region start (point)) 'no-use)
9170 (unless optional-use
9171 (setq aspect (vhdl-template-field
9172 "ENTITY | CONFIGURATION | OPEN" " ")))
9173 (setq aspect (upcase (or aspect "")))
9174 (cond ((equal aspect "ENTITY")
9175 (vhdl-template-field "library name" "." nil nil nil nil
9176 (vhdl-work-library))
9177 (vhdl-template-field "entity name" "(")
9178 (if (vhdl-template-field "[architecture name]" nil t)
9179 (insert ")")
9180 (delete-char -1))
9181 (insert "\n")
9182 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9183 (setq position (point))
9184 (vhdl-insert-keyword "GENERIC ")
9185 (when (vhdl-template-map position t t)
9186 (insert "\n")
9187 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9188 (setq position (point))
9189 (vhdl-insert-keyword "PORT ")
9190 (unless (vhdl-template-map position t t)
9191 (delete-region (line-beginning-position) (point))
9192 (delete-char -1))
9193 (insert ";")
9194 t)
9195 ((equal aspect "CONFIGURATION")
9196 (vhdl-template-field "library name" "." nil nil nil nil
9197 (vhdl-work-library))
9198 (vhdl-template-field "configuration name" ";"))
9199 (t (delete-char -1) (insert ";") t))))))
9200
9201
9202 (defun vhdl-template-configuration-decl ()
9203 "Insert a configuration declaration."
9204 (interactive)
9205 (let ((margin (current-indentation))
9206 (start (point))
9207 entity-exists string name position)
9208 (vhdl-insert-keyword "CONFIGURATION ")
9209 (when (setq name (vhdl-template-field "name" nil t start (point)))
9210 (vhdl-insert-keyword " OF ")
9211 (save-excursion
9212 (vhdl-prepare-search-1
9213 (setq entity-exists (vhdl-re-search-backward
9214 "\\<entity \\(\\w*\\) is\\>" nil t))
9215 (setq string (match-string 1))))
9216 (if (and entity-exists (not (equal string "")))
9217 (insert string)
9218 (vhdl-template-field "entity name"))
9219 (vhdl-insert-keyword " IS\n")
9220 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9221 (indent-to (+ margin vhdl-basic-offset))
9222 (setq position (point))
9223 (insert "\n")
9224 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9225 (indent-to margin)
9226 (vhdl-insert-keyword "END ")
9227 (unless (vhdl-standard-p '87)
9228 (vhdl-insert-keyword "CONFIGURATION "))
9229 (insert name ";")
9230 (goto-char position))))
9231
9232 (defun vhdl-template-constant ()
9233 "Insert a constant declaration."
9234 (interactive)
9235 (let ((start (point))
9236 (in-arglist (vhdl-in-argument-list-p)))
9237 (vhdl-insert-keyword "CONSTANT ")
9238 (when (vhdl-template-field "name" nil t start (point))
9239 (insert " : ")
9240 (when in-arglist (vhdl-insert-keyword "IN "))
9241 (vhdl-template-field "type")
9242 (if in-arglist
9243 (progn (insert ";")
9244 (vhdl-comment-insert-inline))
9245 (let ((position (point)))
9246 (insert " := ")
9247 (unless (vhdl-template-field "[initialization]" nil t)
9248 (delete-region position (point)))
9249 (insert ";")
9250 (vhdl-comment-insert-inline))))))
9251
9252 (defun vhdl-template-context ()
9253 "Insert a context declaration."
9254 (interactive)
9255 (let ((margin (current-indentation))
9256 (start (point))
9257 entity-exists string name position)
9258 (vhdl-insert-keyword "CONTEXT ")
9259 (when (setq name (vhdl-template-field "name" nil t start (point)))
9260 (vhdl-insert-keyword " IS\n")
9261 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9262 (indent-to (+ margin vhdl-basic-offset))
9263 (setq position (point))
9264 (insert "\n")
9265 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9266 (indent-to margin)
9267 (vhdl-insert-keyword "END ")
9268 (unless (vhdl-standard-p '87)
9269 (vhdl-insert-keyword "CONTEXT "))
9270 (insert name ";")
9271 (goto-char position))))
9272
9273 (defun vhdl-template-default ()
9274 "Insert nothing."
9275 (interactive)
9276 (insert " ")
9277 (unexpand-abbrev)
9278 (backward-word 1)
9279 (vhdl-case-word 1)
9280 (forward-char 1))
9281
9282 (defun vhdl-template-default-indent ()
9283 "Insert nothing and indent."
9284 (interactive)
9285 (insert " ")
9286 (unexpand-abbrev)
9287 (backward-word 1)
9288 (vhdl-case-word 1)
9289 (forward-char 1)
9290 (indent-according-to-mode))
9291
9292 (defun vhdl-template-disconnect ()
9293 "Insert a disconnect statement."
9294 (interactive)
9295 (let ((start (point)))
9296 (vhdl-insert-keyword "DISCONNECT ")
9297 (when (vhdl-template-field "signal names | OTHERS | ALL"
9298 " : " t start (point))
9299 (vhdl-template-field "type")
9300 (vhdl-insert-keyword " AFTER ")
9301 (vhdl-template-field "time expression" ";"))))
9302
9303 (defun vhdl-template-else ()
9304 "Insert an else statement."
9305 (interactive)
9306 (let (margin)
9307 (vhdl-prepare-search-1
9308 (vhdl-insert-keyword "ELSE")
9309 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
9310 (equal "WHEN" (upcase (match-string 1))))
9311 (insert " ")
9312 (indent-according-to-mode)
9313 (setq margin (current-indentation))
9314 (insert "\n")
9315 (indent-to (+ margin vhdl-basic-offset))))))
9316
9317 (defun vhdl-template-elsif ()
9318 "Insert an elsif statement."
9319 (interactive)
9320 (let ((start (point))
9321 margin)
9322 (vhdl-insert-keyword "ELSIF ")
9323 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
9324 (when vhdl-conditions-in-parenthesis (insert "("))
9325 (when (vhdl-template-field "condition" nil t start (point))
9326 (when vhdl-conditions-in-parenthesis (insert ")"))
9327 (indent-according-to-mode)
9328 (setq margin (current-indentation))
9329 (vhdl-insert-keyword
9330 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9331 (indent-to (+ margin vhdl-basic-offset))))))
9332
9333 (defun vhdl-template-entity ()
9334 "Insert an entity."
9335 (interactive)
9336 (let ((margin (current-indentation))
9337 (start (point))
9338 name end-column)
9339 (vhdl-insert-keyword "ENTITY ")
9340 (when (setq name (vhdl-template-field "name" nil t start (point)))
9341 (vhdl-insert-keyword " IS\n\n")
9342 (indent-to margin)
9343 (vhdl-insert-keyword "END ")
9344 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9345 (insert name ";")
9346 (setq end-column (current-column))
9347 (end-of-line -0)
9348 (indent-to (+ margin vhdl-basic-offset))
9349 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9350 (indent-to (+ margin vhdl-basic-offset))
9351 (when (vhdl-template-generic-list t)
9352 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9353 (insert "\n")
9354 (indent-to (+ margin vhdl-basic-offset))
9355 (when (vhdl-template-port-list t)
9356 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9357 (beginning-of-line 2)
9358 (forward-char end-column))))
9359
9360 (defun vhdl-template-exit ()
9361 "Insert an exit statement."
9362 (interactive)
9363 (let ((start (point)))
9364 (vhdl-insert-keyword "EXIT ")
9365 (if (vhdl-template-field "[loop label]" nil t start (point))
9366 (let ((position (point)))
9367 (vhdl-insert-keyword " WHEN ")
9368 (when vhdl-conditions-in-parenthesis (insert "("))
9369 (if (vhdl-template-field "[condition]" nil t)
9370 (when vhdl-conditions-in-parenthesis (insert ")"))
9371 (delete-region position (point))))
9372 (delete-char -1))
9373 (insert ";")))
9374
9375 (defun vhdl-template-file ()
9376 "Insert a file declaration."
9377 (interactive)
9378 (let ((start (point)))
9379 (vhdl-insert-keyword "FILE ")
9380 (when (vhdl-template-field "name" nil t start (point))
9381 (insert " : ")
9382 (vhdl-template-field "type")
9383 (unless (vhdl-standard-p '87)
9384 (vhdl-insert-keyword " OPEN ")
9385 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9386 nil t)
9387 (delete-char -6)))
9388 (vhdl-insert-keyword " IS ")
9389 (when (vhdl-standard-p '87)
9390 (vhdl-template-field "[IN | OUT]" " " t))
9391 (vhdl-template-field "filename-string" nil nil nil nil t)
9392 (insert ";")
9393 (vhdl-comment-insert-inline))))
9394
9395 (defun vhdl-template-for ()
9396 "Insert a block or component configuration if within a configuration
9397 declaration, a configuration specification if within an architecture
9398 declarative part (and not within a subprogram), a for-loop if within a
9399 sequential statement part (subprogram or process), and a for-generate
9400 otherwise."
9401 (interactive)
9402 (vhdl-prepare-search-1
9403 (cond
9404 ((vhdl-sequential-statement-p) ; sequential statement
9405 (vhdl-template-for-loop))
9406 ((and (save-excursion ; configuration declaration
9407 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9408 (equal "CONFIGURATION" (upcase (match-string 1))))
9409 (if (eq (vhdl-decision-query
9410 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9411 (vhdl-template-component-conf)
9412 (vhdl-template-block-configuration)))
9413 ((and (save-excursion
9414 (re-search-backward ; architecture declarative part
9415 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9416 (equal "ARCHITECTURE" (upcase (match-string 1))))
9417 (vhdl-template-configuration-spec))
9418 (t (vhdl-template-for-generate))))) ; concurrent statement
9419
9420 (defun vhdl-template-for-generate ()
9421 "Insert a for-generate."
9422 (interactive)
9423 (let ((margin (current-indentation))
9424 (start (point))
9425 label position)
9426 (vhdl-insert-keyword ": FOR ")
9427 (setq position (point-marker))
9428 (goto-char start)
9429 (when (setq label (vhdl-template-field "label" nil t start position))
9430 (goto-char position)
9431 (vhdl-template-field "loop variable")
9432 (vhdl-insert-keyword " IN ")
9433 (vhdl-template-field "range")
9434 (vhdl-template-generate-body margin label))))
9435
9436 (defun vhdl-template-for-loop ()
9437 "Insert a for loop."
9438 (interactive)
9439 (let ((margin (current-indentation))
9440 (start (point))
9441 label index)
9442 (if (not (eq vhdl-optional-labels 'all))
9443 (vhdl-insert-keyword "FOR ")
9444 (vhdl-insert-keyword ": FOR ")
9445 (goto-char start)
9446 (setq label (vhdl-template-field "[label]" nil t))
9447 (unless label (delete-char 2))
9448 (forward-word 1)
9449 (forward-char 1))
9450 (when (setq index (vhdl-template-field "loop variable"
9451 nil t start (point)))
9452 (vhdl-insert-keyword " IN ")
9453 (vhdl-template-field "range")
9454 (vhdl-insert-keyword " LOOP\n\n")
9455 (indent-to margin)
9456 (vhdl-insert-keyword "END LOOP")
9457 (if label
9458 (insert " " label ";")
9459 (insert ";")
9460 (when vhdl-self-insert-comments (insert " -- " index)))
9461 (forward-line -1)
9462 (indent-to (+ margin vhdl-basic-offset)))))
9463
9464 (defun vhdl-template-function (&optional kind)
9465 "Insert a function declaration or body."
9466 (interactive)
9467 (let ((margin (current-indentation))
9468 (start (point))
9469 name)
9470 (vhdl-insert-keyword "FUNCTION ")
9471 (when (setq name (vhdl-template-field "name" nil t start (point)))
9472 (vhdl-template-argument-list t)
9473 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9474 (end-of-line)
9475 (insert "\n")
9476 (indent-to (+ margin vhdl-basic-offset))
9477 (vhdl-insert-keyword "RETURN ")
9478 (vhdl-template-field "type")
9479 (if (if kind (eq kind 'body)
9480 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9481 (progn (vhdl-insert-keyword " IS\n")
9482 (vhdl-template-begin-end
9483 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9484 (vhdl-comment-block))
9485 (insert ";")))))
9486
9487 (defun vhdl-template-function-decl ()
9488 "Insert a function declaration."
9489 (interactive)
9490 (vhdl-template-function 'decl))
9491
9492 (defun vhdl-template-function-body ()
9493 "Insert a function declaration."
9494 (interactive)
9495 (vhdl-template-function 'body))
9496
9497 (defun vhdl-template-generate ()
9498 "Insert a generation scheme."
9499 (interactive)
9500 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9501 (vhdl-template-if-generate)
9502 (vhdl-template-for-generate)))
9503
9504 (defun vhdl-template-generic ()
9505 "Insert generic declaration, or generic map in instantiation statements."
9506 (interactive)
9507 (let ((start (point)))
9508 (vhdl-prepare-search-1
9509 (cond
9510 ((and (save-excursion ; entity declaration
9511 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9512 (equal "ENTITY" (upcase (match-string 1))))
9513 (vhdl-template-generic-list nil))
9514 ((or (save-excursion
9515 (or (beginning-of-line)
9516 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9517 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9518 (vhdl-insert-keyword "GENERIC ")
9519 (vhdl-template-map start))
9520 (t (vhdl-template-generic-list nil t))))))
9521
9522 (defun vhdl-template-group ()
9523 "Insert group or group template declaration."
9524 (interactive)
9525 (let ((start (point)))
9526 (if (eq (vhdl-decision-query
9527 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9528 (vhdl-template-group-template)
9529 (vhdl-template-group-decl))))
9530
9531 (defun vhdl-template-group-decl ()
9532 "Insert group declaration."
9533 (interactive)
9534 (let ((start (point)))
9535 (vhdl-insert-keyword "GROUP ")
9536 (when (vhdl-template-field "name" " : " t start (point))
9537 (vhdl-template-field "template name" " (")
9538 (vhdl-template-field "constituent list" ");")
9539 (vhdl-comment-insert-inline))))
9540
9541 (defun vhdl-template-group-template ()
9542 "Insert group template declaration."
9543 (interactive)
9544 (let ((start (point)))
9545 (vhdl-insert-keyword "GROUP ")
9546 (when (vhdl-template-field "template name" nil t start (point))
9547 (vhdl-insert-keyword " IS (")
9548 (vhdl-template-field "entity class list" ");")
9549 (vhdl-comment-insert-inline))))
9550
9551 (defun vhdl-template-if ()
9552 "Insert a sequential if statement or an if-generate statement."
9553 (interactive)
9554 (if (vhdl-sequential-statement-p)
9555 (vhdl-template-if-then)
9556 (if (and (vhdl-standard-p 'ams)
9557 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9558 (vhdl-template-if-use)
9559 (vhdl-template-if-generate))))
9560
9561 (defun vhdl-template-if-generate ()
9562 "Insert an if-generate."
9563 (interactive)
9564 (let ((margin (current-indentation))
9565 (start (point))
9566 label position)
9567 (vhdl-insert-keyword ": IF ")
9568 (setq position (point-marker))
9569 (goto-char start)
9570 (when (setq label (vhdl-template-field "label" nil t start position))
9571 (goto-char position)
9572 (when vhdl-conditions-in-parenthesis (insert "("))
9573 (vhdl-template-field "condition")
9574 (when vhdl-conditions-in-parenthesis (insert ")"))
9575 (vhdl-template-generate-body margin label))))
9576
9577 (defun vhdl-template-if-then-use (kind)
9578 "Insert a sequential if statement."
9579 (interactive)
9580 (let ((margin (current-indentation))
9581 (start (point))
9582 label)
9583 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9584 (vhdl-insert-keyword "IF ")
9585 (vhdl-insert-keyword ": IF ")
9586 (goto-char start)
9587 (setq label (vhdl-template-field "[label]" nil t))
9588 (unless label (delete-char 2))
9589 (forward-word 1)
9590 (forward-char 1))
9591 (when vhdl-conditions-in-parenthesis (insert "("))
9592 (when (vhdl-template-field "condition" nil t start (point))
9593 (when vhdl-conditions-in-parenthesis (insert ")"))
9594 (vhdl-insert-keyword
9595 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9596 (indent-to margin)
9597 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9598 (when label (insert " " label))
9599 (insert ";")
9600 (forward-line -1)
9601 (indent-to (+ margin vhdl-basic-offset)))))
9602
9603 (defun vhdl-template-if-then ()
9604 "Insert a sequential if statement."
9605 (interactive)
9606 (vhdl-template-if-then-use 'then))
9607
9608 (defun vhdl-template-if-use ()
9609 "Insert a simultaneous if statement."
9610 (interactive)
9611 (vhdl-template-if-then-use 'use))
9612
9613 (defun vhdl-template-instance ()
9614 "Insert a component instantiation statement."
9615 (interactive)
9616 (vhdl-template-component-inst))
9617
9618 (defun vhdl-template-library ()
9619 "Insert a library specification."
9620 (interactive)
9621 (let ((margin (current-indentation))
9622 (start (point))
9623 name end-pos)
9624 (vhdl-insert-keyword "LIBRARY ")
9625 (when (setq name (vhdl-template-field "names" nil t start (point)))
9626 (insert ";")
9627 (unless (string-match "," name)
9628 (setq end-pos (point))
9629 (insert "\n")
9630 (indent-to margin)
9631 (vhdl-insert-keyword "USE ")
9632 (insert name)
9633 (vhdl-insert-keyword "..ALL;")
9634 (backward-char 5)
9635 (if (vhdl-template-field "package name")
9636 (forward-char 5)
9637 (delete-region end-pos (+ (point) 5)))))))
9638
9639 (defun vhdl-template-limit ()
9640 "Insert a limit."
9641 (interactive)
9642 (let ((start (point)))
9643 (vhdl-insert-keyword "LIMIT ")
9644 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9645 t start (point))
9646 (vhdl-template-field "type")
9647 (vhdl-insert-keyword " WITH ")
9648 (vhdl-template-field "real expression" ";"))))
9649
9650 (defun vhdl-template-loop ()
9651 "Insert a loop."
9652 (interactive)
9653 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9654 (cond ((eq char ?w)
9655 (vhdl-template-while-loop))
9656 ((eq char ?f)
9657 (vhdl-template-for-loop))
9658 (t (vhdl-template-bare-loop)))))
9659
9660 (defun vhdl-template-bare-loop ()
9661 "Insert a loop."
9662 (interactive)
9663 (let ((margin (current-indentation))
9664 (start (point))
9665 label)
9666 (if (not (eq vhdl-optional-labels 'all))
9667 (vhdl-insert-keyword "LOOP ")
9668 (vhdl-insert-keyword ": LOOP ")
9669 (goto-char start)
9670 (setq label (vhdl-template-field "[label]" nil t))
9671 (unless label (delete-char 2))
9672 (forward-word 1)
9673 (delete-char 1))
9674 (insert "\n\n")
9675 (indent-to margin)
9676 (vhdl-insert-keyword "END LOOP")
9677 (insert (if label (concat " " label ";") ";"))
9678 (forward-line -1)
9679 (indent-to (+ margin vhdl-basic-offset))))
9680
9681 (defun vhdl-template-map (&optional start optional secondary)
9682 "Insert a map specification with association list."
9683 (interactive)
9684 (let ((start (or start (point)))
9685 margin end-pos)
9686 (vhdl-insert-keyword "MAP (")
9687 (if (not vhdl-association-list-with-formals)
9688 (if (vhdl-template-field
9689 (concat (and optional "[") "association list" (and optional "]"))
9690 ")" (or (not secondary) optional)
9691 (and (not secondary) start) (point))
9692 t
9693 (if (and optional secondary) (delete-region start (point)))
9694 nil)
9695 (if vhdl-argument-list-indent
9696 (setq margin (current-column))
9697 (setq margin (+ (current-indentation) vhdl-basic-offset))
9698 (insert "\n")
9699 (indent-to margin))
9700 (if (vhdl-template-field
9701 (concat (and optional "[") "formal" (and optional "]"))
9702 " => " (or (not secondary) optional)
9703 (and (not secondary) start) (point))
9704 (progn
9705 (vhdl-template-field "actual" ",")
9706 (setq end-pos (point))
9707 (insert "\n")
9708 (indent-to margin)
9709 (while (vhdl-template-field "[formal]" " => " t)
9710 (vhdl-template-field "actual" ",")
9711 (setq end-pos (point))
9712 (insert "\n")
9713 (indent-to margin))
9714 (delete-region end-pos (point))
9715 (delete-char -1)
9716 (insert ")")
9717 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9718 t)
9719 (when (and optional secondary) (delete-region start (point)))
9720 nil))))
9721
9722 (defun vhdl-template-modify (&optional noerror)
9723 "Actualize modification date."
9724 (interactive)
9725 (vhdl-prepare-search-2
9726 (save-excursion
9727 (goto-char (point-min))
9728 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9729 (progn (delete-region (point) (progn (end-of-line) (point)))
9730 (vhdl-template-insert-date))
9731 (unless noerror
9732 (error "ERROR: Modification date prefix string \"%s\" not found"
9733 vhdl-modify-date-prefix-string))))))
9734
9735
9736 (defun vhdl-template-modify-noerror ()
9737 "Call `vhdl-template-modify' with NOERROR non-nil."
9738 (vhdl-template-modify t))
9739
9740 (defun vhdl-template-nature ()
9741 "Insert a nature declaration."
9742 (interactive)
9743 (let ((start (point))
9744 name mid-pos end-pos)
9745 (vhdl-insert-keyword "NATURE ")
9746 (when (setq name (vhdl-template-field "name" nil t start (point)))
9747 (vhdl-insert-keyword " IS ")
9748 (let ((definition
9749 (upcase
9750 (or (vhdl-template-field
9751 "across type | ARRAY | RECORD")
9752 ""))))
9753 (cond ((equal definition "")
9754 (insert ";"))
9755 ((equal definition "ARRAY")
9756 (delete-region (point) (progn (forward-word -1) (point)))
9757 (vhdl-template-array 'nature t))
9758 ((equal definition "RECORD")
9759 (setq mid-pos (point-marker))
9760 (delete-region (point) (progn (forward-word -1) (point)))
9761 (vhdl-template-record 'nature name t))
9762 (t
9763 (vhdl-insert-keyword " ACROSS ")
9764 (vhdl-template-field "through type")
9765 (vhdl-insert-keyword " THROUGH ")
9766 (vhdl-template-field "reference name")
9767 (vhdl-insert-keyword " REFERENCE;")))
9768 (when mid-pos
9769 (setq end-pos (point-marker))
9770 (goto-char mid-pos)
9771 (end-of-line))
9772 (vhdl-comment-insert-inline)
9773 (when end-pos (goto-char end-pos))))))
9774
9775 (defun vhdl-template-next ()
9776 "Insert a next statement."
9777 (interactive)
9778 (let ((start (point)))
9779 (vhdl-insert-keyword "NEXT ")
9780 (if (vhdl-template-field "[loop label]" nil t start (point))
9781 (let ((position (point)))
9782 (vhdl-insert-keyword " WHEN ")
9783 (when vhdl-conditions-in-parenthesis (insert "("))
9784 (if (vhdl-template-field "[condition]" nil t)
9785 (when vhdl-conditions-in-parenthesis (insert ")"))
9786 (delete-region position (point))))
9787 (delete-char -1))
9788 (insert ";")))
9789
9790 (defun vhdl-template-others ()
9791 "Insert an others aggregate."
9792 (interactive)
9793 (let ((start (point)))
9794 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9795 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9796 (vhdl-insert-keyword "OTHERS => '")
9797 (when (vhdl-template-field "value" nil t start (point))
9798 (insert "')")))
9799 (vhdl-insert-keyword "OTHERS "))))
9800
9801 (defun vhdl-template-package (&optional kind)
9802 "Insert a package specification or body."
9803 (interactive)
9804 (let ((margin (current-indentation))
9805 (start (point))
9806 name body position)
9807 (vhdl-insert-keyword "PACKAGE ")
9808 (setq body (if kind (eq kind 'body)
9809 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9810 (when body
9811 (vhdl-insert-keyword "BODY ")
9812 (when (save-excursion
9813 (vhdl-prepare-search-1
9814 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9815 (insert (setq name (match-string 1)))))
9816 (when (or name
9817 (setq name (vhdl-template-field "name" nil t start (point))))
9818 (vhdl-insert-keyword " IS\n")
9819 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9820 (indent-to (+ margin vhdl-basic-offset))
9821 (setq position (point))
9822 (insert "\n")
9823 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9824 (indent-to margin)
9825 (vhdl-insert-keyword "END ")
9826 (unless (vhdl-standard-p '87)
9827 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9828 (insert (or name "") ";")
9829 (goto-char position))))
9830
9831 (defun vhdl-template-package-decl ()
9832 "Insert a package specification."
9833 (interactive)
9834 (vhdl-template-package 'decl))
9835
9836 (defun vhdl-template-package-body ()
9837 "Insert a package body."
9838 (interactive)
9839 (vhdl-template-package 'body))
9840
9841 (defun vhdl-template-port ()
9842 "Insert a port declaration, or port map in instantiation statements."
9843 (interactive)
9844 (let ((start (point)))
9845 (vhdl-prepare-search-1
9846 (cond
9847 ((and (save-excursion ; entity declaration
9848 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9849 (equal "ENTITY" (upcase (match-string 1))))
9850 (vhdl-template-port-list nil))
9851 ((or (save-excursion
9852 (or (beginning-of-line)
9853 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9854 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9855 (vhdl-insert-keyword "PORT ")
9856 (vhdl-template-map start))
9857 (t (vhdl-template-port-list nil))))))
9858
9859 (defun vhdl-template-procedural ()
9860 "Insert a procedural."
9861 (interactive)
9862 (let ((margin (current-indentation))
9863 (start (point))
9864 (case-fold-search t)
9865 label)
9866 (vhdl-insert-keyword "PROCEDURAL ")
9867 (when (memq vhdl-optional-labels '(process all))
9868 (goto-char start)
9869 (insert ": ")
9870 (goto-char start)
9871 (setq label (vhdl-template-field "[label]" nil t))
9872 (unless label (delete-char 2))
9873 (forward-word 1)
9874 (forward-char 1))
9875 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9876 (insert "\n")
9877 (vhdl-template-begin-end "PROCEDURAL" label margin)
9878 (vhdl-comment-block)))
9879
9880 (defun vhdl-template-procedure (&optional kind)
9881 "Insert a procedure declaration or body."
9882 (interactive)
9883 (let ((margin (current-indentation))
9884 (start (point))
9885 name)
9886 (vhdl-insert-keyword "PROCEDURE ")
9887 (when (setq name (vhdl-template-field "name" nil t start (point)))
9888 (vhdl-template-argument-list)
9889 (if (if kind (eq kind 'body)
9890 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9891 (progn (vhdl-insert-keyword " IS")
9892 (when vhdl-auto-align
9893 (vhdl-align-region-groups start (point) 1))
9894 (end-of-line) (insert "\n")
9895 (vhdl-template-begin-end
9896 (unless (vhdl-standard-p '87) "PROCEDURE")
9897 name margin)
9898 (vhdl-comment-block))
9899 (insert ";")
9900 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9901 (end-of-line)))))
9902
9903 (defun vhdl-template-procedure-decl ()
9904 "Insert a procedure declaration."
9905 (interactive)
9906 (vhdl-template-procedure 'decl))
9907
9908 (defun vhdl-template-procedure-body ()
9909 "Insert a procedure body."
9910 (interactive)
9911 (vhdl-template-procedure 'body))
9912
9913 (defun vhdl-template-process (&optional kind)
9914 "Insert a process."
9915 (interactive)
9916 (let ((margin (current-indentation))
9917 (start (point))
9918 (reset-kind vhdl-reset-kind)
9919 label seq input-signals clock reset final-pos)
9920 (setq seq (if kind (eq kind 'seq)
9921 (eq (vhdl-decision-query
9922 "process" "(c)ombinational or (s)equential?" t) ?s)))
9923 (vhdl-insert-keyword "PROCESS ")
9924 (when (memq vhdl-optional-labels '(process all))
9925 (goto-char start)
9926 (insert ": ")
9927 (goto-char start)
9928 (setq label (vhdl-template-field "[label]" nil t))
9929 (unless label (delete-char 2))
9930 (forward-word 1)
9931 (forward-char 1))
9932 (insert "(")
9933 (if (not seq)
9934 (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
9935 (progn (insert "all)") (setq input-signals "all")))
9936 (setq input-signals
9937 (vhdl-template-field "[sensitivity list]" ")" t)))
9938 (setq input-signals "")
9939 (delete-char -2))
9940 (setq clock (or (and (not (equal "" vhdl-clock-name))
9941 (progn (insert vhdl-clock-name) vhdl-clock-name))
9942 (vhdl-template-field "clock name") "<clock>"))
9943 (when (eq reset-kind 'query)
9944 (setq reset-kind
9945 (if (eq (vhdl-decision-query
9946 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9947 'async
9948 'sync)))
9949 (when (eq reset-kind 'async)
9950 (insert ", ")
9951 (setq reset (or (and (not (equal "" vhdl-reset-name))
9952 (progn (insert vhdl-reset-name) vhdl-reset-name))
9953 (vhdl-template-field "reset name") "<reset>")))
9954 (insert ")"))
9955 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9956 (insert "\n")
9957 (vhdl-template-begin-end "PROCESS" label margin)
9958 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9959 (when vhdl-prompt-for-comments
9960 (setq final-pos (point-marker))
9961 (vhdl-prepare-search-2
9962 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9963 (vhdl-re-search-backward "\\<process\\>" nil t))
9964 (end-of-line -0)
9965 (if (bobp)
9966 (progn (insert "\n") (forward-line -1))
9967 (insert "\n"))
9968 (indent-to margin)
9969 (insert "-- purpose: ")
9970 (if (not (vhdl-template-field "[description]" nil t))
9971 (vhdl-line-kill-entire)
9972 (insert "\n")
9973 (indent-to margin)
9974 (insert "-- type : ")
9975 (insert (if seq "sequential" "combinational") "\n")
9976 (indent-to margin)
9977 (insert "-- inputs : ")
9978 (if (not seq)
9979 (insert input-signals)
9980 (insert clock ", ")
9981 (when reset (insert reset ", "))
9982 (unless (vhdl-template-field "[signal names]" nil t)
9983 (delete-char -2)))
9984 (insert "\n")
9985 (indent-to margin)
9986 (insert "-- outputs: ")
9987 (vhdl-template-field "[signal names]" nil t))))
9988 (goto-char final-pos))))
9989
9990 (defun vhdl-template-process-comb ()
9991 "Insert a combinational process."
9992 (interactive)
9993 (vhdl-template-process 'comb))
9994
9995 (defun vhdl-template-process-seq ()
9996 "Insert a sequential process."
9997 (interactive)
9998 (vhdl-template-process 'seq))
9999
10000 (defun vhdl-template-quantity ()
10001 "Insert a quantity declaration."
10002 (interactive)
10003 (if (vhdl-in-argument-list-p)
10004 (let ((start (point)))
10005 (vhdl-insert-keyword "QUANTITY ")
10006 (when (vhdl-template-field "names" nil t start (point))
10007 (insert " : ")
10008 (vhdl-template-field "[IN | OUT]" " " t)
10009 (vhdl-template-field "type")
10010 (insert ";")
10011 (vhdl-comment-insert-inline)))
10012 (let ((char (vhdl-decision-query
10013 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
10014 (cond ((eq char ?f) (vhdl-template-quantity-free))
10015 ((eq char ?b) (vhdl-template-quantity-branch))
10016 ((eq char ?s) (vhdl-template-quantity-source))
10017 (t (vhdl-template-undo (point) (point)))))))
10018
10019 (defun vhdl-template-quantity-free ()
10020 "Insert a free quantity declaration."
10021 (interactive)
10022 (vhdl-insert-keyword "QUANTITY ")
10023 (vhdl-template-field "names")
10024 (insert " : ")
10025 (vhdl-template-field "type")
10026 (let ((position (point)))
10027 (insert " := ")
10028 (unless (vhdl-template-field "[initialization]" nil t)
10029 (delete-region position (point)))
10030 (insert ";")
10031 (vhdl-comment-insert-inline)))
10032
10033 (defun vhdl-template-quantity-branch ()
10034 "Insert a branch quantity declaration."
10035 (interactive)
10036 (let (position)
10037 (vhdl-insert-keyword "QUANTITY ")
10038 (when (vhdl-template-field "[across names]" " " t)
10039 (vhdl-insert-keyword "ACROSS "))
10040 (when (vhdl-template-field "[through names]" " " t)
10041 (vhdl-insert-keyword "THROUGH "))
10042 (vhdl-template-field "plus terminal name")
10043 (setq position (point))
10044 (vhdl-insert-keyword " TO ")
10045 (unless (vhdl-template-field "[minus terminal name]" nil t)
10046 (delete-region position (point)))
10047 (insert ";")
10048 (vhdl-comment-insert-inline)))
10049
10050 (defun vhdl-template-quantity-source ()
10051 "Insert a source quantity declaration."
10052 (interactive)
10053 (vhdl-insert-keyword "QUANTITY ")
10054 (vhdl-template-field "names")
10055 (insert " : ")
10056 (vhdl-template-field "type" " ")
10057 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
10058 (progn (vhdl-insert-keyword "NOISE ")
10059 (vhdl-template-field "power expression"))
10060 (vhdl-insert-keyword "SPECTRUM ")
10061 (vhdl-template-field "magnitude expression" ", ")
10062 (vhdl-template-field "phase expression"))
10063 (insert ";")
10064 (vhdl-comment-insert-inline))
10065
10066 (defun vhdl-template-record (kind &optional name secondary)
10067 "Insert a record type declaration."
10068 (interactive)
10069 (let ((margin (current-indentation))
10070 (start (point))
10071 (first t))
10072 (vhdl-insert-keyword "RECORD\n")
10073 (indent-to (+ margin vhdl-basic-offset))
10074 (when (or (vhdl-template-field "element names"
10075 nil (not secondary) start (point))
10076 secondary)
10077 (while (or first (vhdl-template-field "[element names]" nil t))
10078 (insert " : ")
10079 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
10080 (vhdl-comment-insert-inline)
10081 (insert "\n")
10082 (indent-to (+ margin vhdl-basic-offset))
10083 (setq first nil))
10084 (delete-region (line-beginning-position) (point))
10085 (indent-to margin)
10086 (vhdl-insert-keyword "END RECORD")
10087 (unless (vhdl-standard-p '87) (and name (insert " " name)))
10088 (insert ";")
10089 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10090
10091 (defun vhdl-template-report ()
10092 "Insert a report statement."
10093 (interactive)
10094 (let ((start (point)))
10095 (vhdl-insert-keyword "REPORT ")
10096 (if (equal "\"\"" (vhdl-template-field
10097 "string expression" nil t start (point) t))
10098 (delete-char -2)
10099 (setq start (point))
10100 (vhdl-insert-keyword " SEVERITY ")
10101 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
10102 (delete-region start (point)))
10103 (insert ";"))))
10104
10105 (defun vhdl-template-return ()
10106 "Insert a return statement."
10107 (interactive)
10108 (let ((start (point)))
10109 (vhdl-insert-keyword "RETURN ")
10110 (unless (vhdl-template-field "[expression]" nil t start (point))
10111 (delete-char -1))
10112 (insert ";")))
10113
10114 (defun vhdl-template-selected-signal-asst ()
10115 "Insert a selected signal assignment."
10116 (interactive)
10117 (let ((margin (current-indentation))
10118 (start (point))
10119 (choices t))
10120 (let ((position (point)))
10121 (vhdl-insert-keyword " SELECT ")
10122 (goto-char position))
10123 (vhdl-insert-keyword "WITH ")
10124 (when (vhdl-template-field "selector expression"
10125 nil t start (+ (point) 7))
10126 (forward-word 1)
10127 (delete-char 1)
10128 (insert "\n")
10129 (indent-to (+ margin vhdl-basic-offset))
10130 (vhdl-template-field "target signal" " <= ")
10131 (insert "\n")
10132 (indent-to (+ margin vhdl-basic-offset))
10133 (vhdl-template-field "waveform")
10134 (vhdl-insert-keyword " WHEN ")
10135 (vhdl-template-field "choices" ",")
10136 (insert "\n")
10137 (indent-to (+ margin vhdl-basic-offset))
10138 (while (and choices (vhdl-template-field "[waveform]" nil t))
10139 (vhdl-insert-keyword " WHEN ")
10140 (if (setq choices (vhdl-template-field "[choices]" "," t))
10141 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10142 (vhdl-insert-keyword "OTHERS")))
10143 (when choices
10144 (fixup-whitespace)
10145 (delete-char -2))
10146 (insert ";")
10147 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10148
10149 (defun vhdl-template-signal ()
10150 "Insert a signal declaration."
10151 (interactive)
10152 (let ((start (point))
10153 (in-arglist (vhdl-in-argument-list-p)))
10154 (vhdl-insert-keyword "SIGNAL ")
10155 (when (vhdl-template-field "names" nil t start (point))
10156 (insert " : ")
10157 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10158 (vhdl-template-field "type")
10159 (if in-arglist
10160 (progn (insert ";")
10161 (vhdl-comment-insert-inline))
10162 (let ((position (point)))
10163 (insert " := ")
10164 (unless (vhdl-template-field "[initialization]" nil t)
10165 (delete-region position (point)))
10166 (insert ";")
10167 (vhdl-comment-insert-inline))))))
10168
10169 (defun vhdl-template-subnature ()
10170 "Insert a subnature declaration."
10171 (interactive)
10172 (let ((start (point))
10173 position)
10174 (vhdl-insert-keyword "SUBNATURE ")
10175 (when (vhdl-template-field "name" nil t start (point))
10176 (vhdl-insert-keyword " IS ")
10177 (vhdl-template-field "nature" " (")
10178 (if (vhdl-template-field "[index range]" nil t)
10179 (insert ")")
10180 (delete-char -2))
10181 (setq position (point))
10182 (vhdl-insert-keyword " TOLERANCE ")
10183 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10184 nil t nil nil t))
10185 (delete-region position (point))
10186 (vhdl-insert-keyword " ACROSS ")
10187 (vhdl-template-field "string expression" nil nil nil nil t)
10188 (vhdl-insert-keyword " THROUGH"))
10189 (insert ";")
10190 (vhdl-comment-insert-inline))))
10191
10192 (defun vhdl-template-subprogram-body ()
10193 "Insert a subprogram body."
10194 (interactive)
10195 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10196 (vhdl-template-function-body)
10197 (vhdl-template-procedure-body)))
10198
10199 (defun vhdl-template-subprogram-decl ()
10200 "Insert a subprogram declaration."
10201 (interactive)
10202 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10203 (vhdl-template-function-decl)
10204 (vhdl-template-procedure-decl)))
10205
10206 (defun vhdl-template-subtype ()
10207 "Insert a subtype declaration."
10208 (interactive)
10209 (let ((start (point)))
10210 (vhdl-insert-keyword "SUBTYPE ")
10211 (when (vhdl-template-field "name" nil t start (point))
10212 (vhdl-insert-keyword " IS ")
10213 (vhdl-template-field "type" " ")
10214 (unless
10215 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10216 (delete-char -1))
10217 (insert ";")
10218 (vhdl-comment-insert-inline))))
10219
10220 (defun vhdl-template-terminal ()
10221 "Insert a terminal declaration."
10222 (interactive)
10223 (let ((start (point)))
10224 (vhdl-insert-keyword "TERMINAL ")
10225 (when (vhdl-template-field "names" nil t start (point))
10226 (insert " : ")
10227 (vhdl-template-field "nature")
10228 (insert ";")
10229 (vhdl-comment-insert-inline))))
10230
10231 (defun vhdl-template-type ()
10232 "Insert a type declaration."
10233 (interactive)
10234 (let ((start (point))
10235 name mid-pos end-pos)
10236 (vhdl-insert-keyword "TYPE ")
10237 (when (setq name (vhdl-template-field "name" nil t start (point)))
10238 (vhdl-insert-keyword " IS ")
10239 (let ((definition
10240 (upcase
10241 (or (vhdl-template-field
10242 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10243 ""))))
10244 (cond ((equal definition "")
10245 (delete-char -4)
10246 (insert ";"))
10247 ((equal definition "ARRAY")
10248 (delete-region (point) (progn (forward-word -1) (point)))
10249 (vhdl-template-array 'type t))
10250 ((equal definition "RECORD")
10251 (setq mid-pos (point-marker))
10252 (delete-region (point) (progn (forward-word -1) (point)))
10253 (vhdl-template-record 'type name t))
10254 ((equal definition "ACCESS")
10255 (insert " ")
10256 (vhdl-template-field "type" ";"))
10257 ((equal definition "FILE")
10258 (vhdl-insert-keyword " OF ")
10259 (vhdl-template-field "type" ";"))
10260 ((equal definition "ENUM")
10261 (kill-word -1)
10262 (insert "(")
10263 (setq end-pos (point-marker))
10264 (insert ");"))
10265 (t (insert ";")))
10266 (when mid-pos
10267 (setq end-pos (point-marker))
10268 (goto-char mid-pos)
10269 (end-of-line))
10270 (vhdl-comment-insert-inline)
10271 (when end-pos (goto-char end-pos))))))
10272
10273 (defun vhdl-template-use ()
10274 "Insert a use clause."
10275 (interactive)
10276 (let ((start (point)))
10277 (vhdl-prepare-search-1
10278 (vhdl-insert-keyword "USE ")
10279 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10280 (vhdl-insert-keyword "..ALL;")
10281 (backward-char 6)
10282 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10283 (forward-char 1)
10284 (vhdl-template-field "package name")
10285 (forward-char 5))))))
10286
10287 (defun vhdl-template-variable ()
10288 "Insert a variable declaration."
10289 (interactive)
10290 (let ((start (point))
10291 (in-arglist (vhdl-in-argument-list-p)))
10292 (vhdl-prepare-search-2
10293 (if (or (save-excursion
10294 (progn (vhdl-beginning-of-block)
10295 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10296 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
10297 (vhdl-insert-keyword "VARIABLE ")
10298 (if (vhdl-standard-p '87)
10299 (error "ERROR: Not within sequential block")
10300 (vhdl-insert-keyword "SHARED VARIABLE "))))
10301 (when (vhdl-template-field "names" nil t start (point))
10302 (insert " : ")
10303 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10304 (vhdl-template-field "type")
10305 (if in-arglist
10306 (progn (insert ";")
10307 (vhdl-comment-insert-inline))
10308 (let ((position (point)))
10309 (insert " := ")
10310 (unless (vhdl-template-field "[initialization]" nil t)
10311 (delete-region position (point)))
10312 (insert ";")
10313 (vhdl-comment-insert-inline))))))
10314
10315 (defun vhdl-template-wait ()
10316 "Insert a wait statement."
10317 (interactive)
10318 (vhdl-insert-keyword "WAIT ")
10319 (unless (vhdl-template-field
10320 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10321 nil t)
10322 (delete-char -1))
10323 (insert ";"))
10324
10325 (defun vhdl-template-when ()
10326 "Indent correctly if within a case statement."
10327 (interactive)
10328 (let ((position (point))
10329 margin)
10330 (vhdl-prepare-search-2
10331 (if (and (= (current-column) (current-indentation))
10332 (vhdl-re-search-forward "\\<end\\>" nil t)
10333 (looking-at "\\s-*\\<case\\>"))
10334 (progn
10335 (setq margin (current-indentation))
10336 (goto-char position)
10337 (delete-horizontal-space)
10338 (indent-to (+ margin vhdl-basic-offset)))
10339 (goto-char position)))
10340 (vhdl-insert-keyword "WHEN ")))
10341
10342 (defun vhdl-template-while-loop ()
10343 "Insert a while loop."
10344 (interactive)
10345 (let* ((margin (current-indentation))
10346 (start (point))
10347 label)
10348 (if (not (eq vhdl-optional-labels 'all))
10349 (vhdl-insert-keyword "WHILE ")
10350 (vhdl-insert-keyword ": WHILE ")
10351 (goto-char start)
10352 (setq label (vhdl-template-field "[label]" nil t))
10353 (unless label (delete-char 2))
10354 (forward-word 1)
10355 (forward-char 1))
10356 (when vhdl-conditions-in-parenthesis (insert "("))
10357 (when (vhdl-template-field "condition" nil t start (point))
10358 (when vhdl-conditions-in-parenthesis (insert ")"))
10359 (vhdl-insert-keyword " LOOP\n\n")
10360 (indent-to margin)
10361 (vhdl-insert-keyword "END LOOP")
10362 (insert (if label (concat " " label ";") ";"))
10363 (forward-line -1)
10364 (indent-to (+ margin vhdl-basic-offset)))))
10365
10366 (defun vhdl-template-with ()
10367 "Insert a with statement (i.e. selected signal assignment)."
10368 (interactive)
10369 (vhdl-prepare-search-1
10370 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10371 (equal ";" (match-string 1)))
10372 (vhdl-template-selected-signal-asst)
10373 (vhdl-insert-keyword "WITH "))))
10374
10375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10376 ;; Special templates
10377
10378 (defun vhdl-template-clocked-wait ()
10379 "Insert a wait statement for rising/falling clock edge."
10380 (interactive)
10381 (let ((start (point))
10382 clock)
10383 (vhdl-insert-keyword "WAIT UNTIL ")
10384 (when (setq clock
10385 (or (and (not (equal "" vhdl-clock-name))
10386 (progn (insert vhdl-clock-name) vhdl-clock-name))
10387 (vhdl-template-field "clock name" nil t start (point))))
10388 (insert "'event")
10389 (vhdl-insert-keyword " AND ")
10390 (insert clock)
10391 (insert
10392 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10393 (vhdl-comment-insert-inline
10394 (concat (if vhdl-clock-rising-edge "rising" "falling")
10395 " clock edge")))))
10396
10397 (defun vhdl-template-seq-process (clock reset reset-kind)
10398 "Insert a template for the body of a sequential process."
10399 (let ((margin (current-indentation))
10400 position)
10401 (vhdl-insert-keyword "IF ")
10402 (when vhdl-conditions-in-parenthesis (insert "("))
10403 (when (eq reset-kind 'async)
10404 (insert reset " = "
10405 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10406 (when vhdl-conditions-in-parenthesis (insert ")"))
10407 (vhdl-insert-keyword " THEN")
10408 (vhdl-comment-insert-inline
10409 (concat "asynchronous reset (active "
10410 (if vhdl-reset-active-high "high" "low") ")"))
10411 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10412 (setq position (point))
10413 (insert "\n") (indent-to margin)
10414 (vhdl-insert-keyword "ELSIF ")
10415 (when vhdl-conditions-in-parenthesis (insert "(")))
10416 (if (eq vhdl-clock-edge-condition 'function)
10417 (insert (if vhdl-clock-rising-edge "rising" "falling")
10418 "_edge(" clock ")")
10419 (insert clock "'event")
10420 (vhdl-insert-keyword " AND ")
10421 (insert clock " = "
10422 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10423 (when vhdl-conditions-in-parenthesis (insert ")"))
10424 (vhdl-insert-keyword " THEN")
10425 (vhdl-comment-insert-inline
10426 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10427 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10428 (when (eq reset-kind 'sync)
10429 (vhdl-insert-keyword "IF ")
10430 (when vhdl-conditions-in-parenthesis (insert "("))
10431 (setq reset (or (and (not (equal "" vhdl-reset-name))
10432 (progn (insert vhdl-reset-name) vhdl-reset-name))
10433 (vhdl-template-field "reset name") "<reset>"))
10434 (insert " = "
10435 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10436 (when vhdl-conditions-in-parenthesis (insert ")"))
10437 (vhdl-insert-keyword " THEN")
10438 (vhdl-comment-insert-inline
10439 (concat "synchronous reset (active "
10440 (if vhdl-reset-active-high "high" "low") ")"))
10441 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10442 (setq position (point))
10443 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10444 (vhdl-insert-keyword "ELSE")
10445 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10446 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10447 (vhdl-insert-keyword "END IF;"))
10448 (when (eq reset-kind 'none)
10449 (setq position (point)))
10450 (insert "\n") (indent-to margin)
10451 (vhdl-insert-keyword "END IF;")
10452 (goto-char position)
10453 reset))
10454
10455 (defun vhdl-template-standard-package (library package)
10456 "Insert specification of a standard package. Include a library
10457 specification, if not already there."
10458 (let ((margin (current-indentation)))
10459 (unless (equal library "std")
10460 (unless (or (save-excursion
10461 (vhdl-prepare-search-1
10462 (and (not (bobp))
10463 (re-search-backward
10464 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10465 library "\\|end\\)\\>") nil t)
10466 (match-string 2))))
10467 (equal (downcase library) "work"))
10468 (vhdl-insert-keyword "LIBRARY ")
10469 (insert library ";")
10470 (when package
10471 (insert "\n")
10472 (indent-to margin))))
10473 (when package
10474 (vhdl-insert-keyword "USE ")
10475 (insert library "." package)
10476 (vhdl-insert-keyword ".ALL;"))))
10477
10478 (defun vhdl-template-package-numeric-bit ()
10479 "Insert specification of `numeric_bit' package."
10480 (interactive)
10481 (vhdl-template-standard-package "ieee" "numeric_bit"))
10482
10483 (defun vhdl-template-package-numeric-std ()
10484 "Insert specification of `numeric_std' package."
10485 (interactive)
10486 (vhdl-template-standard-package "ieee" "numeric_std"))
10487
10488 (defun vhdl-template-package-std-logic-1164 ()
10489 "Insert specification of `std_logic_1164' package."
10490 (interactive)
10491 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10492
10493 (defun vhdl-template-package-std-logic-arith ()
10494 "Insert specification of `std_logic_arith' package."
10495 (interactive)
10496 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10497
10498 (defun vhdl-template-package-std-logic-misc ()
10499 "Insert specification of `std_logic_misc' package."
10500 (interactive)
10501 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10502
10503 (defun vhdl-template-package-std-logic-signed ()
10504 "Insert specification of `std_logic_signed' package."
10505 (interactive)
10506 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10507
10508 (defun vhdl-template-package-std-logic-textio ()
10509 "Insert specification of `std_logic_textio' package."
10510 (interactive)
10511 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10512
10513 (defun vhdl-template-package-std-logic-unsigned ()
10514 "Insert specification of `std_logic_unsigned' package."
10515 (interactive)
10516 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10517
10518 (defun vhdl-template-package-textio ()
10519 "Insert specification of `textio' package."
10520 (interactive)
10521 (vhdl-template-standard-package "std" "textio"))
10522
10523 (defun vhdl-template-package-fundamental-constants ()
10524 "Insert specification of `fundamental_constants' package."
10525 (interactive)
10526 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10527
10528 (defun vhdl-template-package-material-constants ()
10529 "Insert specification of `material_constants' package."
10530 (interactive)
10531 (vhdl-template-standard-package "ieee" "material_constants"))
10532
10533 (defun vhdl-template-package-energy-systems ()
10534 "Insert specification of `energy_systems' package."
10535 (interactive)
10536 (vhdl-template-standard-package "ieee" "energy_systems"))
10537
10538 (defun vhdl-template-package-electrical-systems ()
10539 "Insert specification of `electrical_systems' package."
10540 (interactive)
10541 (vhdl-template-standard-package "ieee" "electrical_systems"))
10542
10543 (defun vhdl-template-package-mechanical-systems ()
10544 "Insert specification of `mechanical_systems' package."
10545 (interactive)
10546 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10547
10548 (defun vhdl-template-package-radiant-systems ()
10549 "Insert specification of `radiant_systems' package."
10550 (interactive)
10551 (vhdl-template-standard-package "ieee" "radiant_systems"))
10552
10553 (defun vhdl-template-package-thermal-systems ()
10554 "Insert specification of `thermal_systems' package."
10555 (interactive)
10556 (vhdl-template-standard-package "ieee" "thermal_systems"))
10557
10558 (defun vhdl-template-package-fluidic-systems ()
10559 "Insert specification of `fluidic_systems' package."
10560 (interactive)
10561 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10562
10563 (defun vhdl-template-package-math-complex ()
10564 "Insert specification of `math_complex' package."
10565 (interactive)
10566 (vhdl-template-standard-package "ieee" "math_complex"))
10567
10568 (defun vhdl-template-package-math-real ()
10569 "Insert specification of `math_real' package."
10570 (interactive)
10571 (vhdl-template-standard-package "ieee" "math_real"))
10572
10573 (defun vhdl-template-directive (directive)
10574 "Insert directive."
10575 (unless (= (current-indentation) (current-column))
10576 (delete-horizontal-space)
10577 (insert " "))
10578 (insert "-- pragma " directive))
10579
10580 (defun vhdl-template-directive-translate-on ()
10581 "Insert directive `translate_on'."
10582 (interactive)
10583 (vhdl-template-directive "translate_on"))
10584
10585 (defun vhdl-template-directive-translate-off ()
10586 "Insert directive `translate_off'."
10587 (interactive)
10588 (vhdl-template-directive "translate_off"))
10589
10590 (defun vhdl-template-directive-synthesis-on ()
10591 "Insert directive `synthesis_on'."
10592 (interactive)
10593 (vhdl-template-directive "synthesis_on"))
10594
10595 (defun vhdl-template-directive-synthesis-off ()
10596 "Insert directive `synthesis_off'."
10597 (interactive)
10598 (vhdl-template-directive "synthesis_off"))
10599
10600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10601 ;; Header and footer templates
10602
10603 (defun vhdl-template-header (&optional file-title)
10604 "Insert a VHDL file header."
10605 (interactive)
10606 (unless (equal vhdl-file-header "")
10607 (let (pos)
10608 (save-excursion
10609 (goto-char (point-min))
10610 (vhdl-insert-string-or-file vhdl-file-header)
10611 (setq pos (point-marker)))
10612 (vhdl-template-replace-header-keywords
10613 (point-min-marker) pos file-title))))
10614
10615 (defun vhdl-template-footer ()
10616 "Insert a VHDL file footer."
10617 (interactive)
10618 (unless (equal vhdl-file-footer "")
10619 (let (pos)
10620 (save-excursion
10621 (goto-char (point-max))
10622 (setq pos (point-marker))
10623 (vhdl-insert-string-or-file vhdl-file-footer)
10624 (unless (= (preceding-char) ?\n)
10625 (insert "\n")))
10626 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10627
10628 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10629 is-model)
10630 "Replace keywords in header and footer."
10631 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10632 ""))
10633 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10634 ""))
10635 pos)
10636 (vhdl-prepare-search-2
10637 (save-excursion
10638 (goto-char beg)
10639 (while (search-forward "<projectdesc>" end t)
10640 (replace-match project-desc t t))
10641 (goto-char beg)
10642 (while (search-forward "<filename>" end t)
10643 (replace-match (buffer-name) t t))
10644 (goto-char beg)
10645 (while (search-forward "<copyright>" end t)
10646 (replace-match vhdl-copyright-string t t))
10647 (goto-char beg)
10648 (while (search-forward "<author>" end t)
10649 (replace-match "" t t)
10650 (insert (user-full-name))
10651 (when user-mail-address (insert " <" user-mail-address ">")))
10652 (goto-char beg)
10653 (while (search-forward "<authorfull>" end t)
10654 (replace-match (user-full-name) t t))
10655 (goto-char beg)
10656 (while (search-forward "<login>" end t)
10657 (replace-match (user-login-name) t t))
10658 (goto-char beg)
10659 (while (search-forward "<project>" end t)
10660 (replace-match project-title t t))
10661 (goto-char beg)
10662 (while (search-forward "<company>" end t)
10663 (replace-match vhdl-company-name t t))
10664 (goto-char beg)
10665 (while (search-forward "<platform>" end t)
10666 (replace-match vhdl-platform-spec t t))
10667 (goto-char beg)
10668 (while (search-forward "<standard>" end t)
10669 (replace-match
10670 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10671 ((vhdl-standard-p '93) "'93/02")
10672 ((vhdl-standard-p '08) "'08"))
10673 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10674 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10675 (goto-char beg)
10676 ;; Replace <RCS> with $, so that RCS for the source is
10677 ;; not over-enthusiastic with replacements
10678 (while (search-forward "<RCS>" end t)
10679 (replace-match "$" nil t))
10680 (goto-char beg)
10681 (while (search-forward "<date>" end t)
10682 (replace-match "" t t)
10683 (vhdl-template-insert-date))
10684 (goto-char beg)
10685 (while (search-forward "<year>" end t)
10686 (replace-match (format-time-string "%Y" nil) t t))
10687 (goto-char beg)
10688 (when file-title
10689 (while (search-forward "<title string>" end t)
10690 (replace-match file-title t t))
10691 (goto-char beg))
10692 (let (string)
10693 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10694 (save-match-data
10695 (setq string (read-string (concat (match-string 1) ": "))))
10696 (replace-match string t t)))
10697 (goto-char beg)
10698 (when (and (not is-model) (search-forward "<cursor>" end t))
10699 (replace-match "" t t)
10700 (setq pos (point))))
10701 (when pos (goto-char pos))
10702 (unless is-model
10703 (when (or (not project-title) (equal project-title ""))
10704 (message "You can specify a project title in user option `vhdl-project-alist'"))
10705 (when (or (not project-desc) (equal project-desc ""))
10706 (message "You can specify a project description in user option `vhdl-project-alist'"))
10707 (when (equal vhdl-platform-spec "")
10708 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10709 (when (equal vhdl-company-name "")
10710 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10711
10712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10713 ;; Comment templates and functions
10714
10715 (defun vhdl-comment-indent ()
10716 "Indent comments."
10717 (let* ((position (point))
10718 (col
10719 (progn
10720 (forward-line -1)
10721 (if (re-search-forward "--" position t)
10722 (- (current-column) 2) ; existing comment at bol stays there
10723 (goto-char position)
10724 (skip-chars-backward " \t")
10725 (max comment-column ; else indent to comment column
10726 (1+ (current-column))))))) ; except leave at least one space
10727 (goto-char position)
10728 col))
10729
10730 (defun vhdl-comment-insert ()
10731 "Start a comment at the end of the line.
10732 If on line with code, indent at least `comment-column'.
10733 If starting after end-comment-column, start a new line."
10734 (interactive)
10735 (when (> (current-column) end-comment-column) (newline-and-indent))
10736 (if (or (looking-at "\\s-*$") ; end of line
10737 (and (not unread-command-events) ; called with key binding or menu
10738 (not (end-of-line))))
10739 (let (margin)
10740 (while (= (preceding-char) ?-) (delete-char -1))
10741 (setq margin (current-column))
10742 (delete-horizontal-space)
10743 (if (bolp)
10744 (progn (indent-to margin) (insert "--"))
10745 (insert " ")
10746 (indent-to comment-column)
10747 (insert "--"))
10748 (if (not unread-command-events) (insert " ")))
10749 ;; else code following current point implies commenting out code
10750 (let (next-input code)
10751 (while (= (preceding-char) ?-) (delete-char -2))
10752 (while (= (setq next-input (read-char)) 13) ; CR
10753 (insert "--") ; or have a space after it?
10754 (forward-char -2)
10755 (forward-line 1)
10756 (message "Enter CR if commenting out a line of code.")
10757 (setq code t))
10758 (unless code
10759 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10760 (push (vhdl-character-to-event next-input) ; pushback the char
10761 unread-command-events))))
10762
10763 (defun vhdl-comment-display (&optional line-exists)
10764 "Add 2 comment lines at the current indent, making a display comment."
10765 (interactive)
10766 (let ((margin (current-indentation)))
10767 (unless line-exists (vhdl-comment-display-line))
10768 (insert "\n") (indent-to margin)
10769 (insert "\n") (indent-to margin)
10770 (vhdl-comment-display-line)
10771 (end-of-line -0)
10772 (insert "-- ")))
10773
10774 (defun vhdl-comment-display-line ()
10775 "Displays one line of dashes."
10776 (interactive)
10777 (while (= (preceding-char) ?-) (delete-char -2))
10778 (insert "--")
10779 (let* ((col (current-column))
10780 (len (- end-comment-column col)))
10781 (insert-char vhdl-comment-display-line-char len)))
10782
10783 (defun vhdl-comment-append-inline ()
10784 "Append empty inline comment to current line."
10785 (interactive)
10786 (end-of-line)
10787 (delete-horizontal-space)
10788 (insert " ")
10789 (indent-to comment-column)
10790 (insert "-- "))
10791
10792 (defun vhdl-comment-insert-inline (&optional string always-insert)
10793 "Insert inline comment."
10794 (when (or (and string (or vhdl-self-insert-comments always-insert))
10795 (and (not string) vhdl-prompt-for-comments))
10796 (let ((position (point)))
10797 (insert " ")
10798 (indent-to comment-column)
10799 (insert "-- ")
10800 (if (not (or (and string (progn (insert string) t))
10801 (vhdl-template-field "[comment]" nil t)))
10802 (delete-region position (point))
10803 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10804
10805 (defun vhdl-comment-block ()
10806 "Insert comment for code block."
10807 (when vhdl-prompt-for-comments
10808 (let ((final-pos (point-marker)))
10809 (vhdl-prepare-search-2
10810 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10811 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10812 (let (margin)
10813 (back-to-indentation)
10814 (setq margin (current-column))
10815 (end-of-line -0)
10816 (if (bobp)
10817 (progn (insert "\n") (forward-line -1))
10818 (insert "\n"))
10819 (indent-to margin)
10820 (insert "-- purpose: ")
10821 (unless (vhdl-template-field "[description]" nil t)
10822 (vhdl-line-kill-entire)))))
10823 (goto-char final-pos))))
10824
10825 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10826 "Comment out region if not commented out, uncomment otherwise."
10827 (interactive "r\nP")
10828 (save-excursion
10829 (goto-char (1- end))
10830 (end-of-line)
10831 (setq end (point-marker))
10832 (goto-char beg)
10833 (beginning-of-line)
10834 (setq beg (point))
10835 (if (looking-at (concat "\\s-*" comment-start))
10836 (comment-region beg end '(4))
10837 (comment-region beg end))))
10838
10839 (defun vhdl-comment-uncomment-line (&optional arg)
10840 "Comment out line if not commented out, uncomment otherwise."
10841 (interactive "p")
10842 (save-excursion
10843 (beginning-of-line)
10844 (let ((position (point)))
10845 (forward-line (or arg 1))
10846 (vhdl-comment-uncomment-region position (point)))))
10847
10848 (defun vhdl-comment-kill-region (beg end)
10849 "Kill comments in region."
10850 (interactive "r")
10851 (save-excursion
10852 (goto-char end)
10853 (setq end (point-marker))
10854 (goto-char beg)
10855 (beginning-of-line)
10856 (while (< (point) end)
10857 (if (looking-at "^\\(\\s-*--.*\n\\)")
10858 (progn (delete-region (match-beginning 1) (match-end 1)))
10859 (beginning-of-line 2)))))
10860
10861 (defun vhdl-comment-kill-inline-region (beg end)
10862 "Kill inline comments in region."
10863 (interactive "r")
10864 (save-excursion
10865 (goto-char end)
10866 (setq end (point-marker))
10867 (goto-char beg)
10868 (beginning-of-line)
10869 (while (< (point) end)
10870 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10871 (delete-region (match-beginning 1) (match-end 1)))
10872 (beginning-of-line 2))))
10873
10874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10875 ;; Subtemplates
10876
10877 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10878 "Insert a begin ... end pair with optional name after the end.
10879 Point is left between them."
10880 (let (position)
10881 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10882 (indent-to margin)
10883 (vhdl-insert-keyword "BEGIN")
10884 (when (and (or construct name) vhdl-self-insert-comments)
10885 (insert " --")
10886 (when construct (insert " ") (vhdl-insert-keyword construct))
10887 (when name (insert " " name)))
10888 (insert "\n")
10889 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10890 (indent-to (+ margin vhdl-basic-offset))
10891 (setq position (point))
10892 (insert "\n")
10893 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10894 (indent-to margin)
10895 (vhdl-insert-keyword "END")
10896 (when construct (insert " ") (vhdl-insert-keyword construct))
10897 (insert (if name (concat " " name) "") ";")
10898 (goto-char position)))
10899
10900 (defun vhdl-template-argument-list (&optional is-function)
10901 "Read from user a procedure or function argument list."
10902 (insert " (")
10903 (let ((margin (current-column))
10904 (start (point))
10905 (end-pos (point))
10906 not-empty interface semicolon-pos)
10907 (unless vhdl-argument-list-indent
10908 (setq margin (+ (current-indentation) vhdl-basic-offset))
10909 (insert "\n")
10910 (indent-to margin))
10911 (setq interface (vhdl-template-field
10912 (concat "[CONSTANT | SIGNAL"
10913 (unless is-function " | VARIABLE") "]") " " t))
10914 (while (vhdl-template-field "[names]" nil t)
10915 (setq not-empty t)
10916 (insert " : ")
10917 (unless is-function
10918 (if (and interface (equal (upcase interface) "CONSTANT"))
10919 (vhdl-insert-keyword "IN ")
10920 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10921 (vhdl-template-field "type")
10922 (setq semicolon-pos (point))
10923 (insert ";")
10924 (vhdl-comment-insert-inline)
10925 (setq end-pos (point))
10926 (insert "\n")
10927 (indent-to margin)
10928 (setq interface (vhdl-template-field
10929 (concat "[CONSTANT | SIGNAL"
10930 (unless is-function " | VARIABLE") "]") " " t)))
10931 (delete-region end-pos (point))
10932 (when semicolon-pos (goto-char semicolon-pos))
10933 (if not-empty
10934 (progn (delete-char 1) (insert ")"))
10935 (delete-char -2))))
10936
10937 (defun vhdl-template-generic-list (optional &optional no-value)
10938 "Read from user a generic spec argument list."
10939 (let (margin
10940 (start (point)))
10941 (vhdl-insert-keyword "GENERIC (")
10942 (setq margin (current-column))
10943 (unless vhdl-argument-list-indent
10944 (let ((position (point)))
10945 (back-to-indentation)
10946 (setq margin (+ (current-column) vhdl-basic-offset))
10947 (goto-char position)
10948 (insert "\n")
10949 (indent-to margin)))
10950 (let ((vhdl-generics (vhdl-template-field
10951 (concat (and optional "[") "name"
10952 (and no-value "s") (and optional "]"))
10953 nil optional)))
10954 (if (not vhdl-generics)
10955 (if optional
10956 (progn (vhdl-line-kill-entire) (end-of-line -0)
10957 (unless vhdl-argument-list-indent
10958 (vhdl-line-kill-entire) (end-of-line -0)))
10959 (vhdl-template-undo start (point))
10960 nil )
10961 (insert " : ")
10962 (let (semicolon-pos end-pos)
10963 (while vhdl-generics
10964 (vhdl-template-field "type")
10965 (if no-value
10966 (progn (setq semicolon-pos (point))
10967 (insert ";"))
10968 (insert " := ")
10969 (unless (vhdl-template-field "[value]" nil t)
10970 (delete-char -4))
10971 (setq semicolon-pos (point))
10972 (insert ";"))
10973 (vhdl-comment-insert-inline)
10974 (setq end-pos (point))
10975 (insert "\n")
10976 (indent-to margin)
10977 (setq vhdl-generics (vhdl-template-field
10978 (concat "[name" (and no-value "s") "]")
10979 " : " t)))
10980 (delete-region end-pos (point))
10981 (goto-char semicolon-pos)
10982 (insert ")")
10983 (end-of-line)
10984 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10985 t)))))
10986
10987 (defun vhdl-template-port-list (optional)
10988 "Read from user a port spec argument list."
10989 (let ((start (point))
10990 margin vhdl-ports object)
10991 (vhdl-insert-keyword "PORT (")
10992 (setq margin (current-column))
10993 (unless vhdl-argument-list-indent
10994 (let ((position (point)))
10995 (back-to-indentation)
10996 (setq margin (+ (current-column) vhdl-basic-offset))
10997 (goto-char position)
10998 (insert "\n")
10999 (indent-to margin)))
11000 (when (vhdl-standard-p 'ams)
11001 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11002 " " t)))
11003 (setq vhdl-ports (vhdl-template-field
11004 (concat (and optional "[") "names" (and optional "]"))
11005 nil optional))
11006 (if (not vhdl-ports)
11007 (if optional
11008 (progn (vhdl-line-kill-entire) (end-of-line -0)
11009 (unless vhdl-argument-list-indent
11010 (vhdl-line-kill-entire) (end-of-line -0)))
11011 (vhdl-template-undo start (point))
11012 nil)
11013 (insert " : ")
11014 (let (semicolon-pos end-pos)
11015 (while vhdl-ports
11016 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
11017 (vhdl-template-field "IN | OUT | INOUT" " "))
11018 ((equal "QUANTITY" (upcase object))
11019 (vhdl-template-field "[IN | OUT]" " " t)))
11020 (vhdl-template-field
11021 (if (and object (equal "TERMINAL" (upcase object)))
11022 "nature" "type"))
11023 (setq semicolon-pos (point))
11024 (insert ";")
11025 (vhdl-comment-insert-inline)
11026 (setq end-pos (point))
11027 (insert "\n")
11028 (indent-to margin)
11029 (when (vhdl-standard-p 'ams)
11030 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11031 " " t)))
11032 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
11033 (delete-region end-pos (point))
11034 (goto-char semicolon-pos)
11035 (insert ")")
11036 (end-of-line)
11037 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
11038 t))))
11039
11040 (defun vhdl-template-generate-body (margin label)
11041 "Insert body for generate template."
11042 (vhdl-insert-keyword " GENERATE")
11043 (insert "\n\n")
11044 (indent-to margin)
11045 (vhdl-insert-keyword "END GENERATE ")
11046 (insert label ";")
11047 (end-of-line 0)
11048 (indent-to (+ margin vhdl-basic-offset)))
11049
11050 (defun vhdl-template-insert-date ()
11051 "Insert date in appropriate format."
11052 (interactive)
11053 (insert
11054 (cond
11055 ;; 'american, 'european, 'scientific kept for backward compatibility
11056 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
11057 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
11058 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
11059 (t (format-time-string vhdl-date-format nil)))))
11060
11061 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11062 ;; Help functions
11063
11064 (defun vhdl-electric-space (count)
11065 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
11066 if in comment and past end-comment-column."
11067 (interactive "p")
11068 (cond ((vhdl-in-comment-p)
11069 (self-insert-command count)
11070 (cond ((>= (current-column) (+ 2 end-comment-column))
11071 (backward-char 1)
11072 (skip-chars-backward "^ \t\n\r\f")
11073 (indent-new-comment-line)
11074 (skip-chars-forward "^ \t\n\r\f")
11075 (forward-char 1))
11076 ((>= (current-column) end-comment-column)
11077 (indent-new-comment-line))
11078 (t nil)))
11079 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
11080 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
11081 (vhdl-prepare-search-1
11082 (or (expand-abbrev) (vhdl-fix-case-word -1)))
11083 (self-insert-command count))
11084 (t (self-insert-command count))))
11085
11086 (defun vhdl-template-field (prompt &optional follow-string optional
11087 begin end is-string default)
11088 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
11089 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
11090 an empty string is inserted, return nil and call `vhdl-template-undo' for
11091 the region between BEGIN and END. IS-STRING indicates whether a string
11092 with double-quotes is to be inserted. DEFAULT specifies a default string."
11093 (let ((position (point))
11094 string)
11095 (insert "<" prompt ">")
11096 (setq string
11097 (condition-case ()
11098 (read-from-minibuffer (concat prompt ": ")
11099 (or (and is-string '("\"\"" . 2)) default)
11100 vhdl-minibuffer-local-map)
11101 (quit (if (and optional begin end)
11102 (progn (beep) "")
11103 (keyboard-quit)))))
11104 (when (or (not (equal string "")) optional)
11105 (delete-region position (point)))
11106 (when (and (equal string "") optional begin end)
11107 (vhdl-template-undo begin end)
11108 (message "Template aborted"))
11109 (unless (equal string "")
11110 (insert string)
11111 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
11112 vhdl-keywords-regexp)
11113 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
11114 vhdl-types-regexp)
11115 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
11116 (concat "'" vhdl-attributes-regexp))
11117 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
11118 vhdl-enum-values-regexp)
11119 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
11120 vhdl-constants-regexp))
11121 (when (or (not (equal string "")) (not optional))
11122 (insert (or follow-string "")))
11123 (if (equal string "") nil string)))
11124
11125 (defun vhdl-decision-query (string prompt &optional optional)
11126 "Query a decision from the user."
11127 (let ((start (point)))
11128 (when string (vhdl-insert-keyword (concat string " ")))
11129 (message "%s" (or prompt ""))
11130 (let ((char (read-char)))
11131 (delete-region start (point))
11132 (if (and optional (eq char ?\r))
11133 (progn (insert " ")
11134 (unexpand-abbrev)
11135 (throw 'abort "ERROR: Template aborted"))
11136 char))))
11137
11138 (defun vhdl-insert-keyword (keyword)
11139 "Insert KEYWORD and adjust case."
11140 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11141
11142 (defun vhdl-case-keyword (keyword)
11143 "Adjust case of KEYWORD."
11144 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11145
11146 (defun vhdl-case-word (num)
11147 "Adjust case of following NUM words."
11148 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11149
11150 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11151 "If preceding character is part of a word or a paren then hippie-expand,
11152 else insert tab (used for word completion in VHDL minibuffer)."
11153 (interactive "P")
11154 (cond
11155 ;; expand word
11156 ((= (char-syntax (preceding-char)) ?w)
11157 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11158 (case-replace nil)
11159 (hippie-expand-only-buffers
11160 (or (and (boundp 'hippie-expand-only-buffers)
11161 hippie-expand-only-buffers)
11162 '(vhdl-mode))))
11163 (vhdl-expand-abbrev prefix-arg)))
11164 ;; expand parenthesis
11165 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11166 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11167 (case-replace nil))
11168 (vhdl-expand-paren prefix-arg)))
11169 ;; insert tab
11170 (t (insert-tab))))
11171
11172 (defun vhdl-template-search-prompt ()
11173 "Search for left out template prompts and query again."
11174 (interactive)
11175 (vhdl-prepare-search-2
11176 (when (or (re-search-forward
11177 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11178 (re-search-backward
11179 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11180 (let ((string (match-string 1)))
11181 (replace-match "")
11182 (vhdl-template-field string)))))
11183
11184 (defun vhdl-template-undo (begin end)
11185 "Undo aborted template by deleting region and unexpanding the keyword."
11186 (cond (vhdl-template-invoked-by-hook
11187 (goto-char end)
11188 (insert " ")
11189 (delete-region begin end)
11190 (unexpand-abbrev))
11191 (t (delete-region begin end))))
11192
11193 (defun vhdl-insert-string-or-file (string)
11194 "Insert STRING or file contents if STRING is an existing file name."
11195 (unless (equal string "")
11196 (let ((file-name
11197 (progn (string-match "^\\([^\n]+\\)" string)
11198 (vhdl-resolve-env-variable (match-string 1 string)))))
11199 (if (file-exists-p file-name)
11200 (forward-char (cadr (insert-file-contents file-name)))
11201 (insert string)))))
11202
11203 (defun vhdl-beginning-of-block ()
11204 "Move cursor to the beginning of the enclosing block."
11205 (let (pos)
11206 (vhdl-prepare-search-2
11207 (save-excursion
11208 (beginning-of-line)
11209 ;; search backward for block beginning or end
11210 (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))
11211 ;; not consider subprogram declarations
11212 (or (and (match-string 5)
11213 (save-match-data
11214 (save-excursion
11215 (goto-char (match-end 5))
11216 (forward-word 1)
11217 (vhdl-forward-syntactic-ws)
11218 (when (looking-at "(")
11219 (forward-sexp))
11220 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11221 (match-string 1)))
11222 ;; not consider configuration specifications
11223 (and (match-string 6)
11224 (save-match-data
11225 (save-excursion
11226 (vhdl-end-of-block)
11227 (beginning-of-line)
11228 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11229 (match-string 2))
11230 ;; skip subblock if block end found
11231 (vhdl-beginning-of-block))))
11232 (when pos (goto-char pos))))
11233
11234 (defun vhdl-end-of-block ()
11235 "Move cursor to the end of the enclosing block."
11236 (let (pos)
11237 (vhdl-prepare-search-2
11238 (save-excursion
11239 (end-of-line)
11240 ;; search forward for block beginning or end
11241 (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))
11242 ;; not consider subprogram declarations
11243 (or (and (match-string 5)
11244 (save-match-data
11245 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11246 (match-string 1)))
11247 ;; not consider configuration specifications
11248 (and (match-string 6)
11249 (save-match-data
11250 (save-excursion
11251 (vhdl-end-of-block)
11252 (beginning-of-line)
11253 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11254 (not (match-string 2)))
11255 ;; skip subblock if block beginning found
11256 (vhdl-end-of-block))))
11257 (when pos (goto-char pos))))
11258
11259 (defun vhdl-sequential-statement-p ()
11260 "Check if point is within sequential statement part."
11261 (let ((start (point)))
11262 (save-excursion
11263 (vhdl-prepare-search-2
11264 ;; is sequential statement if ...
11265 (and (re-search-backward "^\\s-*begin\\>" nil t)
11266 ;; ... point is between "begin" and "end" of ...
11267 (progn (vhdl-end-of-block)
11268 (< start (point)))
11269 ;; ... a sequential block
11270 (progn (vhdl-beginning-of-block)
11271 (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\\)\\)\\>")))))))
11272
11273 (defun vhdl-in-argument-list-p ()
11274 "Check if within an argument list."
11275 (save-excursion
11276 (vhdl-prepare-search-2
11277 (or (string-match "arglist"
11278 (format "%s" (caar (vhdl-get-syntactic-context))))
11279 (progn (beginning-of-line)
11280 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11281
11282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11283 ;; Abbrev hooks
11284
11285 (defun vhdl-hooked-abbrev (func)
11286 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11287 but not if inside a comment or quote."
11288 (if (or (vhdl-in-literal)
11289 (save-excursion
11290 (forward-word -1)
11291 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11292 (progn
11293 (insert " ")
11294 (unexpand-abbrev)
11295 (backward-word 1)
11296 (vhdl-case-word 1)
11297 (delete-char 1))
11298 (if (not vhdl-electric-mode)
11299 (progn
11300 (insert " ")
11301 (unexpand-abbrev)
11302 (backward-word 1)
11303 (vhdl-case-word 1)
11304 (delete-char 1))
11305 (let ((invoke-char vhdl-last-input-event)
11306 (abbrev-mode -1)
11307 (vhdl-template-invoked-by-hook t))
11308 (let ((caught (catch 'abort
11309 (funcall func))))
11310 (when (stringp caught) (message "%s" caught)))
11311 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11312 ;; delete CR which is still in event queue
11313 (if (fboundp 'enqueue-eval-event)
11314 (enqueue-eval-event 'delete-char -1)
11315 (push (vhdl-character-to-event ?\177) ; push back a delete char
11316 unread-command-events))))))
11317
11318 (defun vhdl-template-alias-hook ()
11319 (vhdl-hooked-abbrev 'vhdl-template-alias))
11320 (defun vhdl-template-architecture-hook ()
11321 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11322 (defun vhdl-template-assert-hook ()
11323 (vhdl-hooked-abbrev 'vhdl-template-assert))
11324 (defun vhdl-template-attribute-hook ()
11325 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11326 (defun vhdl-template-block-hook ()
11327 (vhdl-hooked-abbrev 'vhdl-template-block))
11328 (defun vhdl-template-break-hook ()
11329 (vhdl-hooked-abbrev 'vhdl-template-break))
11330 (defun vhdl-template-case-hook ()
11331 (vhdl-hooked-abbrev 'vhdl-template-case))
11332 (defun vhdl-template-component-hook ()
11333 (vhdl-hooked-abbrev 'vhdl-template-component))
11334 (defun vhdl-template-instance-hook ()
11335 (vhdl-hooked-abbrev 'vhdl-template-instance))
11336 (defun vhdl-template-conditional-signal-asst-hook ()
11337 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11338 (defun vhdl-template-configuration-hook ()
11339 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11340 (defun vhdl-template-constant-hook ()
11341 (vhdl-hooked-abbrev 'vhdl-template-constant))
11342 (defun vhdl-template-context-hook ()
11343 (vhdl-hooked-abbrev 'vhdl-template-context))
11344 (defun vhdl-template-disconnect-hook ()
11345 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11346 (defun vhdl-template-display-comment-hook ()
11347 (vhdl-hooked-abbrev 'vhdl-comment-display))
11348 (defun vhdl-template-else-hook ()
11349 (vhdl-hooked-abbrev 'vhdl-template-else))
11350 (defun vhdl-template-elsif-hook ()
11351 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11352 (defun vhdl-template-entity-hook ()
11353 (vhdl-hooked-abbrev 'vhdl-template-entity))
11354 (defun vhdl-template-exit-hook ()
11355 (vhdl-hooked-abbrev 'vhdl-template-exit))
11356 (defun vhdl-template-file-hook ()
11357 (vhdl-hooked-abbrev 'vhdl-template-file))
11358 (defun vhdl-template-for-hook ()
11359 (vhdl-hooked-abbrev 'vhdl-template-for))
11360 (defun vhdl-template-function-hook ()
11361 (vhdl-hooked-abbrev 'vhdl-template-function))
11362 (defun vhdl-template-generic-hook ()
11363 (vhdl-hooked-abbrev 'vhdl-template-generic))
11364 (defun vhdl-template-group-hook ()
11365 (vhdl-hooked-abbrev 'vhdl-template-group))
11366 (defun vhdl-template-library-hook ()
11367 (vhdl-hooked-abbrev 'vhdl-template-library))
11368 (defun vhdl-template-limit-hook ()
11369 (vhdl-hooked-abbrev 'vhdl-template-limit))
11370 (defun vhdl-template-if-hook ()
11371 (vhdl-hooked-abbrev 'vhdl-template-if))
11372 (defun vhdl-template-bare-loop-hook ()
11373 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11374 (defun vhdl-template-map-hook ()
11375 (vhdl-hooked-abbrev 'vhdl-template-map))
11376 (defun vhdl-template-nature-hook ()
11377 (vhdl-hooked-abbrev 'vhdl-template-nature))
11378 (defun vhdl-template-next-hook ()
11379 (vhdl-hooked-abbrev 'vhdl-template-next))
11380 (defun vhdl-template-others-hook ()
11381 (vhdl-hooked-abbrev 'vhdl-template-others))
11382 (defun vhdl-template-package-hook ()
11383 (vhdl-hooked-abbrev 'vhdl-template-package))
11384 (defun vhdl-template-port-hook ()
11385 (vhdl-hooked-abbrev 'vhdl-template-port))
11386 (defun vhdl-template-procedural-hook ()
11387 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11388 (defun vhdl-template-procedure-hook ()
11389 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11390 (defun vhdl-template-process-hook ()
11391 (vhdl-hooked-abbrev 'vhdl-template-process))
11392 (defun vhdl-template-quantity-hook ()
11393 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11394 (defun vhdl-template-report-hook ()
11395 (vhdl-hooked-abbrev 'vhdl-template-report))
11396 (defun vhdl-template-return-hook ()
11397 (vhdl-hooked-abbrev 'vhdl-template-return))
11398 (defun vhdl-template-selected-signal-asst-hook ()
11399 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11400 (defun vhdl-template-signal-hook ()
11401 (vhdl-hooked-abbrev 'vhdl-template-signal))
11402 (defun vhdl-template-subnature-hook ()
11403 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11404 (defun vhdl-template-subtype-hook ()
11405 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11406 (defun vhdl-template-terminal-hook ()
11407 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11408 (defun vhdl-template-type-hook ()
11409 (vhdl-hooked-abbrev 'vhdl-template-type))
11410 (defun vhdl-template-use-hook ()
11411 (vhdl-hooked-abbrev 'vhdl-template-use))
11412 (defun vhdl-template-variable-hook ()
11413 (vhdl-hooked-abbrev 'vhdl-template-variable))
11414 (defun vhdl-template-wait-hook ()
11415 (vhdl-hooked-abbrev 'vhdl-template-wait))
11416 (defun vhdl-template-when-hook ()
11417 (vhdl-hooked-abbrev 'vhdl-template-when))
11418 (defun vhdl-template-while-loop-hook ()
11419 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11420 (defun vhdl-template-with-hook ()
11421 (vhdl-hooked-abbrev 'vhdl-template-with))
11422 (defun vhdl-template-and-hook ()
11423 (vhdl-hooked-abbrev 'vhdl-template-and))
11424 (defun vhdl-template-or-hook ()
11425 (vhdl-hooked-abbrev 'vhdl-template-or))
11426 (defun vhdl-template-nand-hook ()
11427 (vhdl-hooked-abbrev 'vhdl-template-nand))
11428 (defun vhdl-template-nor-hook ()
11429 (vhdl-hooked-abbrev 'vhdl-template-nor))
11430 (defun vhdl-template-xor-hook ()
11431 (vhdl-hooked-abbrev 'vhdl-template-xor))
11432 (defun vhdl-template-xnor-hook ()
11433 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11434 (defun vhdl-template-not-hook ()
11435 (vhdl-hooked-abbrev 'vhdl-template-not))
11436
11437 (defun vhdl-template-default-hook ()
11438 (vhdl-hooked-abbrev 'vhdl-template-default))
11439 (defun vhdl-template-default-indent-hook ()
11440 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11441
11442 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11443 ;; Template insertion from completion list
11444
11445 (defun vhdl-template-insert-construct (name)
11446 "Insert the built-in construct template with NAME."
11447 (interactive
11448 (list (let ((completion-ignore-case t))
11449 (completing-read "Construct name: "
11450 vhdl-template-construct-alist nil t))))
11451 (vhdl-template-insert-fun
11452 (cadr (assoc name vhdl-template-construct-alist))))
11453
11454 (defun vhdl-template-insert-package (name)
11455 "Insert the built-in package template with NAME."
11456 (interactive
11457 (list (let ((completion-ignore-case t))
11458 (completing-read "Package name: "
11459 vhdl-template-package-alist nil t))))
11460 (vhdl-template-insert-fun
11461 (cadr (assoc name vhdl-template-package-alist))))
11462
11463 (defun vhdl-template-insert-directive (name)
11464 "Insert the built-in directive template with NAME."
11465 (interactive
11466 (list (let ((completion-ignore-case t))
11467 (completing-read "Directive name: "
11468 vhdl-template-directive-alist nil t))))
11469 (vhdl-template-insert-fun
11470 (cadr (assoc name vhdl-template-directive-alist))))
11471
11472 (defun vhdl-template-insert-fun (fun)
11473 "Call FUN to insert a built-in template."
11474 (let ((caught (catch 'abort (when fun (funcall fun)))))
11475 (when (stringp caught) (message "%s" caught))))
11476
11477
11478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11479 ;;; Models
11480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11481
11482 (defun vhdl-model-insert (model-name)
11483 "Insert the user model with name MODEL-NAME."
11484 (interactive
11485 (let ((completion-ignore-case t))
11486 (list (completing-read "Model name: " vhdl-model-alist))))
11487 (indent-according-to-mode)
11488 (let ((start (point-marker))
11489 (margin (current-indentation))
11490 model position prompt string end)
11491 (vhdl-prepare-search-2
11492 (when (setq model (assoc model-name vhdl-model-alist))
11493 ;; insert model
11494 (beginning-of-line)
11495 (delete-horizontal-space)
11496 (goto-char start)
11497 (vhdl-insert-string-or-file (nth 1 model))
11498 (setq end (point-marker))
11499 ;; indent code
11500 (goto-char start)
11501 (beginning-of-line)
11502 (while (< (point) end)
11503 (unless (looking-at "^$")
11504 (insert-char ? margin))
11505 (beginning-of-line 2))
11506 (goto-char start)
11507 ;; insert clock
11508 (unless (equal "" vhdl-clock-name)
11509 (while (re-search-forward "<clock>" end t)
11510 (replace-match vhdl-clock-name)))
11511 (goto-char start)
11512 ;; insert reset
11513 (unless (equal "" vhdl-reset-name)
11514 (while (re-search-forward "<reset>" end t)
11515 (replace-match vhdl-reset-name)))
11516 ;; replace header prompts
11517 (vhdl-template-replace-header-keywords start end nil t)
11518 (goto-char start)
11519 ;; query other prompts
11520 (while (re-search-forward
11521 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11522 (unless (equal "cursor" (match-string 1))
11523 (setq position (match-beginning 1))
11524 (setq prompt (match-string 1))
11525 (replace-match "")
11526 (setq string (vhdl-template-field prompt nil t))
11527 ;; replace occurrences of same prompt
11528 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11529 (replace-match (or string "")))
11530 (goto-char position)))
11531 (goto-char start)
11532 ;; goto final position
11533 (if (re-search-forward "<cursor>" end t)
11534 (replace-match "")
11535 (goto-char end))))))
11536
11537 (defun vhdl-model-defun ()
11538 "Define help and hook functions for user models."
11539 (let ((model-alist vhdl-model-alist)
11540 model-name model-keyword)
11541 (while model-alist
11542 ;; define functions for user models that can be invoked from menu and key
11543 ;; bindings and which themselves call `vhdl-model-insert' with the model
11544 ;; name as argument
11545 (setq model-name (nth 0 (car model-alist)))
11546 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11547 ,(concat "Insert model for \"" model-name "\".")
11548 (interactive)
11549 (vhdl-model-insert ,model-name)))
11550 ;; define hooks for user models that are invoked from keyword abbrevs
11551 (setq model-keyword (nth 3 (car model-alist)))
11552 (unless (equal model-keyword "")
11553 (eval `(defun
11554 ,(vhdl-function-name
11555 "vhdl-model" model-name "hook") ()
11556 (vhdl-hooked-abbrev
11557 ',(vhdl-function-name "vhdl-model" model-name)))))
11558 (setq model-alist (cdr model-alist)))))
11559
11560 (vhdl-model-defun)
11561
11562
11563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11564 ;;; Port translation
11565 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11566
11567 (defvar vhdl-port-list nil
11568 "Variable to hold last port map parsed.")
11569 ;; structure: (parenthesized expression means list of such entries)
11570 ;; (ent-name
11571 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11572 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11573 ;; (lib-name pack-key))
11574
11575 (defun vhdl-parse-string (string &optional optional)
11576 "Check that the text following point matches the regexp in STRING."
11577 (if (looking-at string)
11578 (progn (goto-char (match-end 0))
11579 (when (vhdl-in-literal)
11580 (end-of-line))
11581 (point))
11582 (unless optional
11583 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11584 (vhdl-current-line) string)))
11585 nil))
11586
11587 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11588 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11589 (vhdl-prepare-search-1
11590 (if (string-match (car regexp-cons) string)
11591 (if adjust-case
11592 (funcall vhdl-file-name-case
11593 (replace-match (cdr regexp-cons) t nil string))
11594 (replace-match (cdr regexp-cons) t nil string))
11595 string)))
11596
11597 (defun vhdl-parse-group-comment ()
11598 "Parse comment and empty lines between groups of lines."
11599 (let ((start (point))
11600 string)
11601 (vhdl-forward-comment (point-max))
11602 (setq string (buffer-substring-no-properties start (point)))
11603 (vhdl-forward-syntactic-ws)
11604 ;; strip off leading blanks and first newline
11605 (while (string-match "^\\(\\s-+\\)" string)
11606 (setq string (concat (substring string 0 (match-beginning 1))
11607 (substring string (match-end 1)))))
11608 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11609 (substring string 1)
11610 string)))
11611
11612 (defun vhdl-paste-group-comment (string indent)
11613 "Paste comment and empty lines from STRING between groups of lines
11614 with INDENT."
11615 (let ((pos (point-marker)))
11616 (when (> indent 0)
11617 (while (string-match "^\\(--\\)" string)
11618 (setq string (concat (substring string 0 (match-beginning 1))
11619 (make-string indent ? )
11620 (substring string (match-beginning 1))))))
11621 (beginning-of-line)
11622 (insert string)
11623 (goto-char pos)))
11624
11625 (defvar vhdl-port-flattened nil
11626 "Indicates whether a port has been flattened.")
11627
11628 (defun vhdl-port-flatten (&optional as-alist)
11629 "Flatten port list so that only one generic/port exists per line.
11630 This operation is performed on an internally stored port and is only
11631 reflected in a subsequent paste operation."
11632 (interactive)
11633 (if (not vhdl-port-list)
11634 (error "ERROR: No port has been read")
11635 (message "Flattening port for next paste...")
11636 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11637 (old-vhdl-port-list (cdr vhdl-port-list))
11638 old-port-list new-port-list old-port new-port names)
11639 ;; traverse port list and flatten entries
11640 (while (cdr old-vhdl-port-list)
11641 (setq old-port-list (car old-vhdl-port-list))
11642 (setq new-port-list nil)
11643 (while old-port-list
11644 (setq old-port (car old-port-list))
11645 (setq names (car old-port))
11646 (while names
11647 (setq new-port (cons (if as-alist (car names) (list (car names)))
11648 (cdr old-port)))
11649 (setq new-port-list (append new-port-list (list new-port)))
11650 (setq names (cdr names)))
11651 (setq old-port-list (cdr old-port-list)))
11652 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11653 (setq new-vhdl-port-list (append new-vhdl-port-list
11654 (list new-port-list))))
11655 (setq vhdl-port-list
11656 (append new-vhdl-port-list (list old-vhdl-port-list))
11657 vhdl-port-flattened t)
11658 (message "Flattening port for next paste...done"))))
11659
11660 (defvar vhdl-port-reversed-direction nil
11661 "Indicates whether port directions are reversed.")
11662
11663 (defun vhdl-port-reverse-direction ()
11664 "Reverse direction for all ports (useful in testbenches).
11665 This operation is performed on an internally stored port and is only
11666 reflected in a subsequent paste operation."
11667 (interactive)
11668 (if (not vhdl-port-list)
11669 (error "ERROR: No port has been read")
11670 (message "Reversing port directions for next paste...")
11671 (let ((port-list (nth 2 vhdl-port-list))
11672 port-dir-car port-dir)
11673 ;; traverse port list and reverse directions
11674 (while port-list
11675 (setq port-dir-car (cddr (car port-list))
11676 port-dir (car port-dir-car))
11677 (setcar port-dir-car
11678 (cond ((equal port-dir "in") "out")
11679 ((equal port-dir "IN") "OUT")
11680 ((equal port-dir "out") "in")
11681 ((equal port-dir "OUT") "IN")
11682 (t port-dir)))
11683 (setq port-list (cdr port-list)))
11684 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11685 (message "Reversing port directions for next paste...done"))))
11686
11687 (defun vhdl-port-copy ()
11688 "Get generic and port information from an entity or component declaration."
11689 (interactive)
11690 (save-excursion
11691 (let (parse-error end-of-list
11692 decl-type name generic-list port-list context-clause
11693 object names direct type init comment group-comment)
11694 (vhdl-prepare-search-2
11695 (setq
11696 parse-error
11697 (catch 'parse
11698 ;; check if within entity or component declaration
11699 (end-of-line)
11700 (when (or (not (re-search-backward
11701 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11702 (equal "END" (upcase (match-string 1))))
11703 (throw 'parse "ERROR: Not within an entity or component declaration"))
11704 (setq decl-type (downcase (match-string-no-properties 1)))
11705 (forward-word 1)
11706 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11707 (setq name (match-string-no-properties 1))
11708 (message "Reading port of %s \"%s\"..." decl-type name)
11709 (vhdl-forward-syntactic-ws)
11710 ;; parse generic clause
11711 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11712 ;; parse group comment and spacing
11713 (setq group-comment (vhdl-parse-group-comment))
11714 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11715 (while (not end-of-list)
11716 ;; parse names (accept extended identifiers)
11717 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11718 (setq names (list (match-string-no-properties 1)))
11719 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11720 (setq names
11721 (append names (list (match-string-no-properties 1)))))
11722 ;; parse type
11723 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11724 (setq type (match-string-no-properties 1))
11725 (when (vhdl-in-comment-p) ; if stuck in comment
11726 (setq type (concat type (and (vhdl-parse-string ".*")
11727 (match-string-no-properties 0)))))
11728 (setq comment nil)
11729 (while (looking-at "(")
11730 (setq type
11731 (concat type
11732 (buffer-substring-no-properties
11733 (point) (progn (forward-sexp) (point)))
11734 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11735 (match-string-no-properties 1)))))
11736 ;; special case: closing parenthesis is on separate line
11737 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11738 (setq comment (substring type (match-beginning 2)))
11739 (setq type (substring type 0 (match-beginning 1))))
11740 ;; strip of trailing group-comment
11741 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11742 (setq type (substring type 0 (match-end 1)))
11743 ;; parse initialization expression
11744 (setq init nil)
11745 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11746 (vhdl-parse-string "\\([^();\n]*\\)")
11747 (setq init (match-string-no-properties 1))
11748 (while (looking-at "(")
11749 (setq init
11750 (concat init
11751 (buffer-substring-no-properties
11752 (point) (progn (forward-sexp) (point)))
11753 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11754 (match-string-no-properties 1))))))
11755 ;; special case: closing parenthesis is on separate line
11756 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11757 (setq comment (substring init (match-beginning 2)))
11758 (setq init (substring init 0 (match-beginning 1)))
11759 (vhdl-forward-syntactic-ws))
11760 (skip-chars-forward " \t")
11761 ;; parse inline comment, special case: as above, no initial.
11762 (unless comment
11763 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11764 (match-string-no-properties 1))))
11765 (vhdl-forward-syntactic-ws)
11766 (setq end-of-list (vhdl-parse-string ")" t))
11767 (vhdl-parse-string "\\s-*;\\s-*")
11768 ;; parse inline comment
11769 (unless comment
11770 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11771 (match-string-no-properties 1))))
11772 ;; save everything in list
11773 (setq generic-list (append generic-list
11774 (list (list names type init
11775 comment group-comment))))
11776 ;; parse group comment and spacing
11777 (setq group-comment (vhdl-parse-group-comment))))
11778 ;; parse port clause
11779 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11780 ;; parse group comment and spacing
11781 (setq group-comment (vhdl-parse-group-comment))
11782 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11783 (while (not end-of-list)
11784 ;; parse object
11785 (setq object
11786 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11787 (match-string-no-properties 1)))
11788 ;; parse names (accept extended identifiers)
11789 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11790 (setq names (list (match-string-no-properties 1)))
11791 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11792 (setq names (append names (list (match-string-no-properties 1)))))
11793 ;; parse direction
11794 (vhdl-parse-string ":[ \t\n\r\f]*")
11795 (setq direct
11796 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11797 (match-string-no-properties 1)))
11798 ;; parse type
11799 (vhdl-parse-string "\\([^();\n]+\\)")
11800 (setq type (match-string-no-properties 1))
11801 (when (vhdl-in-comment-p) ; if stuck in comment
11802 (setq type (concat type (and (vhdl-parse-string ".*")
11803 (match-string-no-properties 0)))))
11804 (setq comment nil)
11805 (while (looking-at "(")
11806 (setq type (concat type
11807 (buffer-substring-no-properties
11808 (point) (progn (forward-sexp) (point)))
11809 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11810 (match-string-no-properties 1)))))
11811 ;; special case: closing parenthesis is on separate line
11812 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11813 (setq comment (substring type (match-beginning 2)))
11814 (setq type (substring type 0 (match-beginning 1))))
11815 ;; strip of trailing group-comment
11816 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11817 (setq type (substring type 0 (match-end 1)))
11818 (vhdl-forward-syntactic-ws)
11819 (setq end-of-list (vhdl-parse-string ")" t))
11820 (vhdl-parse-string "\\s-*;\\s-*")
11821 ;; parse inline comment
11822 (unless comment
11823 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11824 (match-string-no-properties 1))))
11825 ;; save everything in list
11826 (setq port-list (append port-list
11827 (list (list names object direct type
11828 comment group-comment))))
11829 ;; parse group comment and spacing
11830 (setq group-comment (vhdl-parse-group-comment))))
11831 ;; parse context clause
11832 (setq context-clause (vhdl-scan-context-clause))
11833 ; ;; add surrounding package to context clause
11834 ; (when (and (equal decl-type "component")
11835 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11836 ; (setq context-clause
11837 ; (append context-clause
11838 ; (list (cons (vhdl-work-library)
11839 ; (match-string-no-properties 1))))))
11840 (message "Reading port of %s \"%s\"...done" decl-type name)
11841 nil)))
11842 ;; finish parsing
11843 (if parse-error
11844 (error parse-error)
11845 (setq vhdl-port-list (list name generic-list port-list context-clause)
11846 vhdl-port-reversed-direction nil
11847 vhdl-port-flattened nil)))))
11848
11849 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11850 "Paste a context clause."
11851 (let ((margin (current-indentation))
11852 (clause-list (nth 3 vhdl-port-list))
11853 clause)
11854 (while clause-list
11855 (setq clause (car clause-list))
11856 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11857 (downcase exclude-pack-name)))
11858 (save-excursion
11859 (re-search-backward
11860 (concat "^\\s-*use\\s-+" (car clause)
11861 "." (cdr clause) "\\>") nil t)))
11862 (vhdl-template-standard-package (car clause) (cdr clause))
11863 (insert "\n"))
11864 (setq clause-list (cdr clause-list)))))
11865
11866 (defun vhdl-port-paste-generic (&optional no-init)
11867 "Paste a generic clause."
11868 (let ((margin (current-indentation))
11869 (generic-list (nth 1 vhdl-port-list))
11870 list-margin start names generic)
11871 ;; paste generic clause
11872 (when generic-list
11873 (setq start (point))
11874 (vhdl-insert-keyword "GENERIC (")
11875 (unless vhdl-argument-list-indent
11876 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11877 (setq list-margin (current-column))
11878 (while generic-list
11879 (setq generic (car generic-list))
11880 ;; paste group comment and spacing
11881 (when (memq vhdl-include-group-comments '(decl always))
11882 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11883 ;; paste names
11884 (setq names (nth 0 generic))
11885 (while names
11886 (insert (car names))
11887 (setq names (cdr names))
11888 (when names (insert ", ")))
11889 ;; paste type
11890 (insert " : " (nth 1 generic))
11891 ;; paste initialization
11892 (when (and (not no-init) (nth 2 generic))
11893 (insert " := " (nth 2 generic)))
11894 (unless (cdr generic-list) (insert ")"))
11895 (insert ";")
11896 ;; paste comment
11897 (when (and vhdl-include-port-comments (nth 3 generic))
11898 (vhdl-comment-insert-inline (nth 3 generic) t))
11899 (setq generic-list (cdr generic-list))
11900 (when generic-list (insert "\n") (indent-to list-margin)))
11901 ;; align generic clause
11902 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11903
11904 (defun vhdl-port-paste-port ()
11905 "Paste a port clause."
11906 (let ((margin (current-indentation))
11907 (port-list (nth 2 vhdl-port-list))
11908 list-margin start names port)
11909 ;; paste port clause
11910 (when port-list
11911 (setq start (point))
11912 (vhdl-insert-keyword "PORT (")
11913 (unless vhdl-argument-list-indent
11914 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11915 (setq list-margin (current-column))
11916 (while port-list
11917 (setq port (car port-list))
11918 ;; paste group comment and spacing
11919 (when (memq vhdl-include-group-comments '(decl always))
11920 (vhdl-paste-group-comment (nth 5 port) list-margin))
11921 ;; paste object
11922 (when (nth 1 port) (insert (nth 1 port) " "))
11923 ;; paste names
11924 (setq names (nth 0 port))
11925 (while names
11926 (insert (car names))
11927 (setq names (cdr names))
11928 (when names (insert ", ")))
11929 ;; paste direction
11930 (insert " : ")
11931 (when (nth 2 port) (insert (nth 2 port) " "))
11932 ;; paste type
11933 (insert (nth 3 port))
11934 (unless (cdr port-list) (insert ")"))
11935 (insert ";")
11936 ;; paste comment
11937 (when (and vhdl-include-port-comments (nth 4 port))
11938 (vhdl-comment-insert-inline (nth 4 port) t))
11939 (setq port-list (cdr port-list))
11940 (when port-list (insert "\n") (indent-to list-margin)))
11941 ;; align port clause
11942 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11943
11944 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11945 "Paste as an entity or component declaration."
11946 (unless no-indent (indent-according-to-mode))
11947 (let ((margin (current-indentation))
11948 (name (nth 0 vhdl-port-list)))
11949 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11950 (insert name)
11951 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11952 (vhdl-insert-keyword " IS"))
11953 ;; paste generic and port clause
11954 (when (nth 1 vhdl-port-list)
11955 (insert "\n")
11956 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11957 (insert "\n"))
11958 (indent-to (+ margin vhdl-basic-offset))
11959 (vhdl-port-paste-generic (eq kind 'component)))
11960 (when (nth 2 vhdl-port-list)
11961 (insert "\n")
11962 (when (and (memq vhdl-insert-empty-lines '(unit all))
11963 (eq kind 'entity))
11964 (insert "\n"))
11965 (indent-to (+ margin vhdl-basic-offset)))
11966 (vhdl-port-paste-port)
11967 (insert "\n")
11968 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11969 (insert "\n"))
11970 (indent-to margin)
11971 (vhdl-insert-keyword "END")
11972 (if (eq kind 'entity)
11973 (progn
11974 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11975 (insert " " name))
11976 (vhdl-insert-keyword " COMPONENT")
11977 (unless (vhdl-standard-p '87) (insert " " name)))
11978 (insert ";")))
11979
11980 (defun vhdl-port-paste-entity (&optional no-indent)
11981 "Paste as an entity declaration."
11982 (interactive)
11983 (if (not vhdl-port-list)
11984 (error "ERROR: No port read")
11985 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11986 (vhdl-port-paste-declaration 'entity no-indent)
11987 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11988
11989 (defun vhdl-port-paste-component (&optional no-indent)
11990 "Paste as a component declaration."
11991 (interactive)
11992 (if (not vhdl-port-list)
11993 (error "ERROR: No port read")
11994 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11995 (vhdl-port-paste-declaration 'component no-indent)
11996 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11997
11998 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11999 "Paste as a generic map."
12000 (interactive)
12001 (unless secondary (indent-according-to-mode))
12002 (let ((margin (current-indentation))
12003 list-margin start generic
12004 (generic-list (nth 1 vhdl-port-list)))
12005 (when generic-list
12006 (setq start (point))
12007 (vhdl-insert-keyword "GENERIC MAP (")
12008 (if (not vhdl-association-list-with-formals)
12009 ;; paste list of actual generics
12010 (while generic-list
12011 (insert (if no-constants
12012 (car (nth 0 (car generic-list)))
12013 (or (nth 2 (car generic-list)) " ")))
12014 (setq generic-list (cdr generic-list))
12015 (insert (if generic-list ", " ")"))
12016 (when (and (not generic-list) secondary
12017 (null (nth 2 vhdl-port-list)))
12018 (insert ";")))
12019 (unless vhdl-argument-list-indent
12020 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12021 (setq list-margin (current-column))
12022 (while generic-list
12023 (setq generic (car generic-list))
12024 ;; paste group comment and spacing
12025 (when (eq vhdl-include-group-comments 'always)
12026 (vhdl-paste-group-comment (nth 4 generic) list-margin))
12027 ;; paste formal and actual generic
12028 (insert (car (nth 0 generic)) " => "
12029 (if no-constants
12030 (vhdl-replace-string vhdl-actual-generic-name
12031 (car (nth 0 generic)))
12032 (or (nth 2 generic) "")))
12033 (setq generic-list (cdr generic-list))
12034 (insert (if generic-list "," ")"))
12035 (when (and (not generic-list) secondary
12036 (null (nth 2 vhdl-port-list)))
12037 (insert ";"))
12038 ;; paste comment
12039 (when (or vhdl-include-type-comments
12040 (and vhdl-include-port-comments (nth 3 generic)))
12041 (vhdl-comment-insert-inline
12042 (concat
12043 (when vhdl-include-type-comments
12044 (concat "[" (nth 1 generic) "] "))
12045 (when vhdl-include-port-comments (nth 3 generic))) t))
12046 (when generic-list (insert "\n") (indent-to list-margin)))
12047 ;; align generic map
12048 (when vhdl-auto-align
12049 (vhdl-align-region-groups start (point) 1 t))))))
12050
12051 (defun vhdl-port-paste-port-map ()
12052 "Paste as a port map."
12053 (let ((margin (current-indentation))
12054 list-margin start port
12055 (port-list (nth 2 vhdl-port-list)))
12056 (when port-list
12057 (setq start (point))
12058 (vhdl-insert-keyword "PORT MAP (")
12059 (if (not vhdl-association-list-with-formals)
12060 ;; paste list of actual ports
12061 (while port-list
12062 (insert (vhdl-replace-string vhdl-actual-port-name
12063 (car (nth 0 (car port-list)))))
12064 (setq port-list (cdr port-list))
12065 (insert (if port-list ", " ")")))
12066 (unless vhdl-argument-list-indent
12067 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12068 (setq list-margin (current-column))
12069 (while port-list
12070 (setq port (car port-list))
12071 ;; paste group comment and spacing
12072 (when (eq vhdl-include-group-comments 'always)
12073 (vhdl-paste-group-comment (nth 5 port) list-margin))
12074 ;; paste formal and actual port
12075 (insert (car (nth 0 port)) " => ")
12076 (insert (vhdl-replace-string vhdl-actual-port-name
12077 (car (nth 0 port))))
12078 (setq port-list (cdr port-list))
12079 (insert (if port-list "," ");"))
12080 ;; paste comment
12081 (when (or (and vhdl-include-direction-comments (nth 2 port))
12082 vhdl-include-type-comments
12083 (and vhdl-include-port-comments (nth 4 port)))
12084 (vhdl-comment-insert-inline
12085 (concat
12086 (cond ((and vhdl-include-direction-comments
12087 vhdl-include-type-comments)
12088 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
12089 (nth 3 port) "] "))
12090 ((and vhdl-include-direction-comments (nth 2 port))
12091 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12092 (vhdl-include-direction-comments " ")
12093 (vhdl-include-type-comments
12094 (concat "[" (nth 3 port) "] ")))
12095 (when vhdl-include-port-comments (nth 4 port))) t))
12096 (when port-list (insert "\n") (indent-to list-margin)))
12097 ;; align port clause
12098 (when vhdl-auto-align
12099 (vhdl-align-region-groups start (point) 1))))))
12100
12101 (defun vhdl-port-paste-instance (&optional name no-indent title)
12102 "Paste as an instantiation."
12103 (interactive)
12104 (if (not vhdl-port-list)
12105 (error "ERROR: No port read")
12106 (let ((orig-vhdl-port-list vhdl-port-list))
12107 ;; flatten local copy of port list (must be flat for port mapping)
12108 (vhdl-port-flatten)
12109 (unless no-indent (indent-according-to-mode))
12110 (let ((margin (current-indentation)))
12111 ;; paste instantiation
12112 (cond (name
12113 (insert name))
12114 ((equal (cdr vhdl-instance-name) "")
12115 (setq name (vhdl-template-field "instance name")))
12116 ((string-match "%d" (cdr vhdl-instance-name))
12117 (let ((n 1))
12118 (while (save-excursion
12119 (setq name (format (vhdl-replace-string
12120 vhdl-instance-name
12121 (nth 0 vhdl-port-list)) n))
12122 (goto-char (point-min))
12123 (vhdl-re-search-forward name nil t))
12124 (setq n (1+ n)))
12125 (insert name)))
12126 (t (insert (vhdl-replace-string vhdl-instance-name
12127 (nth 0 vhdl-port-list)))))
12128 (message "Pasting port as instantiation \"%s\"..." name)
12129 (insert ": ")
12130 (when title
12131 (save-excursion
12132 (beginning-of-line)
12133 (indent-to vhdl-basic-offset)
12134 (insert "-- instance \"" name "\"\n")))
12135 (if (not (vhdl-use-direct-instantiation))
12136 (insert (nth 0 vhdl-port-list))
12137 (vhdl-insert-keyword "ENTITY ")
12138 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12139 (when (nth 1 vhdl-port-list)
12140 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12141 (vhdl-port-paste-generic-map t t))
12142 (when (nth 2 vhdl-port-list)
12143 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12144 (vhdl-port-paste-port-map))
12145 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12146 (insert ";"))
12147 (message "Pasting port as instantiation \"%s\"...done" name))
12148 (setq vhdl-port-list orig-vhdl-port-list))))
12149
12150 (defun vhdl-port-paste-constants (&optional no-indent)
12151 "Paste generics as constants."
12152 (interactive)
12153 (if (not vhdl-port-list)
12154 (error "ERROR: No port read")
12155 (let ((orig-vhdl-port-list vhdl-port-list))
12156 (message "Pasting port as constants...")
12157 ;; flatten local copy of port list (must be flat for constant initial.)
12158 (vhdl-port-flatten)
12159 (unless no-indent (indent-according-to-mode))
12160 (let ((margin (current-indentation))
12161 start generic name
12162 (generic-list (nth 1 vhdl-port-list)))
12163 (when generic-list
12164 (setq start (point))
12165 (while generic-list
12166 (setq generic (car generic-list))
12167 ;; paste group comment and spacing
12168 (when (memq vhdl-include-group-comments '(decl always))
12169 (vhdl-paste-group-comment (nth 4 generic) margin))
12170 (vhdl-insert-keyword "CONSTANT ")
12171 ;; paste generic constants
12172 (setq name (nth 0 generic))
12173 (when name
12174 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12175 ;; paste type
12176 (insert " : " (nth 1 generic))
12177 ;; paste initialization
12178 (when (nth 2 generic)
12179 (insert " := " (nth 2 generic)))
12180 (insert ";")
12181 ;; paste comment
12182 (when (and vhdl-include-port-comments (nth 3 generic))
12183 (vhdl-comment-insert-inline (nth 3 generic) t))
12184 (setq generic-list (cdr generic-list))
12185 (when generic-list (insert "\n") (indent-to margin))))
12186 ;; align signal list
12187 (when vhdl-auto-align
12188 (vhdl-align-region-groups start (point) 1))))
12189 (message "Pasting port as constants...done")
12190 (setq vhdl-port-list orig-vhdl-port-list))))
12191
12192 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12193 "Paste ports as internal signals."
12194 (interactive)
12195 (if (not vhdl-port-list)
12196 (error "ERROR: No port read")
12197 (message "Pasting port as signals...")
12198 (unless no-indent (indent-according-to-mode))
12199 (let ((margin (current-indentation))
12200 start port names type generic-list port-name constant-name pos
12201 (port-list (nth 2 vhdl-port-list)))
12202 (when port-list
12203 (setq start (point))
12204 (while port-list
12205 (setq port (car port-list))
12206 ;; paste group comment and spacing
12207 (when (memq vhdl-include-group-comments '(decl always))
12208 (vhdl-paste-group-comment (nth 5 port) margin))
12209 ;; paste object
12210 (if (nth 1 port)
12211 (insert (nth 1 port) " ")
12212 (vhdl-insert-keyword "SIGNAL "))
12213 ;; paste actual port signals
12214 (setq names (nth 0 port))
12215 (while names
12216 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12217 (setq names (cdr names))
12218 (when names (insert ", ")))
12219 ;; paste type
12220 (setq type (nth 3 port))
12221 (setq generic-list (nth 1 vhdl-port-list))
12222 (vhdl-prepare-search-1
12223 (setq pos 0)
12224 ;; replace formal by actual generics
12225 (while generic-list
12226 (setq port-name (car (nth 0 (car generic-list))))
12227 (while (string-match (concat "\\<" port-name "\\>") type pos)
12228 (setq constant-name
12229 (save-match-data (vhdl-replace-string
12230 vhdl-actual-generic-name port-name)))
12231 (setq type (replace-match constant-name t nil type))
12232 (setq pos (match-end 0)))
12233 (setq generic-list (cdr generic-list))))
12234 (insert " : " type)
12235 ;; paste initialization (inputs only)
12236 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12237 (insert " := "
12238 (cond ((string-match "integer" (nth 3 port)) "0")
12239 ((string-match "natural" (nth 3 port)) "0")
12240 ((string-match "positive" (nth 3 port)) "0")
12241 ((string-match "real" (nth 3 port)) "0.0")
12242 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12243 (t "'0'"))))
12244 (insert ";")
12245 ;; paste comment
12246 (when (or (and vhdl-include-direction-comments (nth 2 port))
12247 (and vhdl-include-port-comments (nth 4 port)))
12248 (vhdl-comment-insert-inline
12249 (concat
12250 (cond ((and vhdl-include-direction-comments (nth 2 port))
12251 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12252 (vhdl-include-direction-comments " "))
12253 (when vhdl-include-port-comments (nth 4 port))) t))
12254 (setq port-list (cdr port-list))
12255 (when port-list (insert "\n") (indent-to margin)))
12256 ;; align signal list
12257 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12258 (message "Pasting port as signals...done")))
12259
12260 (defun vhdl-port-paste-initializations (&optional no-indent)
12261 "Paste ports as signal initializations."
12262 (interactive)
12263 (if (not vhdl-port-list)
12264 (error "ERROR: No port read")
12265 (let ((orig-vhdl-port-list vhdl-port-list))
12266 (message "Pasting port as initializations...")
12267 ;; flatten local copy of port list (must be flat for signal initial.)
12268 (vhdl-port-flatten)
12269 (unless no-indent (indent-according-to-mode))
12270 (let ((margin (current-indentation))
12271 start port name
12272 (port-list (nth 2 vhdl-port-list)))
12273 (when port-list
12274 (setq start (point))
12275 (while port-list
12276 (setq port (car port-list))
12277 ;; paste actual port signal (inputs only)
12278 (when (equal "IN" (upcase (nth 2 port)))
12279 (setq name (car (nth 0 port)))
12280 (insert (vhdl-replace-string vhdl-actual-port-name name))
12281 ;; paste initialization
12282 (insert " <= "
12283 (cond ((string-match "integer" (nth 3 port)) "0")
12284 ((string-match "natural" (nth 3 port)) "0")
12285 ((string-match "positive" (nth 3 port)) "0")
12286 ((string-match "real" (nth 3 port)) "0.0")
12287 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12288 (t "'0'"))
12289 ";"))
12290 (setq port-list (cdr port-list))
12291 (when (and port-list
12292 (equal "IN" (upcase (nth 2 (car port-list)))))
12293 (insert "\n") (indent-to margin)))
12294 ;; align signal list
12295 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12296 (message "Pasting port as initializations...done")
12297 (setq vhdl-port-list orig-vhdl-port-list))))
12298
12299 (defun vhdl-port-paste-testbench ()
12300 "Paste as a bare-bones testbench."
12301 (interactive)
12302 (if (not vhdl-port-list)
12303 (error "ERROR: No port read")
12304 (let ((case-fold-search t)
12305 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12306 (nth 0 vhdl-port-list)))
12307 (source-buffer (current-buffer))
12308 arch-name config-name ent-file-name arch-file-name
12309 ent-buffer arch-buffer position)
12310 ;; open entity file
12311 (unless (eq vhdl-testbench-create-files 'none)
12312 (setq ent-file-name
12313 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12314 ent-name t)
12315 "." (file-name-extension (buffer-file-name))))
12316 (if (file-exists-p ent-file-name)
12317 (if (y-or-n-p
12318 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12319 (progn (find-file ent-file-name)
12320 (erase-buffer)
12321 (set-buffer-modified-p nil))
12322 (if (eq vhdl-testbench-create-files 'separate)
12323 (setq ent-file-name nil)
12324 (error "ERROR: Pasting port as testbench...aborted")))
12325 (find-file ent-file-name)))
12326 (unless (and (eq vhdl-testbench-create-files 'separate)
12327 (null ent-file-name))
12328 ;; paste entity header
12329 (if vhdl-testbench-include-header
12330 (progn (vhdl-template-header
12331 (concat "Testbench for design \""
12332 (nth 0 vhdl-port-list) "\""))
12333 (goto-char (point-max)))
12334 (vhdl-comment-display-line) (insert "\n\n"))
12335 ;; paste std_logic_1164 package
12336 (when vhdl-testbench-include-library
12337 (vhdl-template-package-std-logic-1164)
12338 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12339 ;; paste entity declaration
12340 (vhdl-insert-keyword "ENTITY ")
12341 (insert ent-name)
12342 (vhdl-insert-keyword " IS")
12343 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12344 (insert "\n")
12345 (vhdl-insert-keyword "END ")
12346 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12347 (insert ent-name ";")
12348 (insert "\n\n")
12349 (vhdl-comment-display-line) (insert "\n"))
12350 ;; get architecture name
12351 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12352 (read-from-minibuffer "architecture name: "
12353 nil vhdl-minibuffer-local-map)
12354 (vhdl-replace-string vhdl-testbench-architecture-name
12355 (nth 0 vhdl-port-list))))
12356 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12357 ;; open architecture file
12358 (if (not (eq vhdl-testbench-create-files 'separate))
12359 (insert "\n")
12360 (setq ent-buffer (current-buffer))
12361 (setq arch-file-name
12362 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12363 (concat ent-name " " arch-name) t)
12364 "." (file-name-extension (buffer-file-name))))
12365 (when (and (file-exists-p arch-file-name)
12366 (not (y-or-n-p (concat "File \"" arch-file-name
12367 "\" exists; overwrite? "))))
12368 (error "ERROR: Pasting port as testbench...aborted"))
12369 (find-file arch-file-name)
12370 (erase-buffer)
12371 (set-buffer-modified-p nil)
12372 ;; paste architecture header
12373 (if vhdl-testbench-include-header
12374 (progn (vhdl-template-header
12375 (concat "Testbench architecture for design \""
12376 (nth 0 vhdl-port-list) "\""))
12377 (goto-char (point-max)))
12378 (vhdl-comment-display-line) (insert "\n\n")))
12379 ;; paste architecture body
12380 (vhdl-insert-keyword "ARCHITECTURE ")
12381 (insert arch-name)
12382 (vhdl-insert-keyword " OF ")
12383 (insert ent-name)
12384 (vhdl-insert-keyword " IS")
12385 (insert "\n\n") (indent-to vhdl-basic-offset)
12386 ;; paste component declaration
12387 (unless (vhdl-use-direct-instantiation)
12388 (vhdl-port-paste-component t)
12389 (insert "\n\n") (indent-to vhdl-basic-offset))
12390 ;; paste constants
12391 (when (nth 1 vhdl-port-list)
12392 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12393 (vhdl-port-paste-constants t)
12394 (insert "\n\n") (indent-to vhdl-basic-offset))
12395 ;; paste internal signals
12396 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12397 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12398 (insert "\n")
12399 ;; paste custom declarations
12400 (unless (equal "" vhdl-testbench-declarations)
12401 (insert "\n")
12402 (setq position (point))
12403 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12404 (vhdl-indent-region position (point)))
12405 (setq position (point))
12406 (insert "\n\n")
12407 (vhdl-comment-display-line) (insert "\n")
12408 (when vhdl-testbench-include-configuration
12409 (setq config-name (vhdl-replace-string
12410 vhdl-testbench-configuration-name
12411 (concat ent-name " " arch-name)))
12412 (insert "\n")
12413 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12414 (vhdl-insert-keyword " OF ") (insert ent-name)
12415 (vhdl-insert-keyword " IS\n")
12416 (indent-to vhdl-basic-offset)
12417 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12418 (indent-to vhdl-basic-offset)
12419 (vhdl-insert-keyword "END FOR;\n")
12420 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12421 (vhdl-comment-display-line) (insert "\n"))
12422 (goto-char position)
12423 (vhdl-template-begin-end
12424 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12425 ;; paste instantiation
12426 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12427 (vhdl-port-paste-instance
12428 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12429 (insert "\n")
12430 ;; paste custom statements
12431 (unless (equal "" vhdl-testbench-statements)
12432 (insert "\n")
12433 (setq position (point))
12434 (vhdl-insert-string-or-file vhdl-testbench-statements)
12435 (vhdl-indent-region position (point)))
12436 (insert "\n")
12437 (indent-to vhdl-basic-offset)
12438 (unless (eq vhdl-testbench-create-files 'none)
12439 (setq arch-buffer (current-buffer))
12440 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12441 (set-buffer arch-buffer) (save-buffer))
12442 (message "%s"
12443 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12444 ent-name arch-name)
12445 (and ent-file-name
12446 (format "\n File created: \"%s\"" ent-file-name))
12447 (and arch-file-name
12448 (format "\n File created: \"%s\"" arch-file-name)))))))
12449
12450
12451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12452 ;;; Subprogram interface translation
12453 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12454
12455 (defvar vhdl-subprog-list nil
12456 "Variable to hold last subprogram interface parsed.")
12457 ;; structure: (parenthesized expression means list of such entries)
12458 ;; (subprog-name kind
12459 ;; ((names) object direct type init comment group-comment)
12460 ;; return-type return-comment group-comment)
12461
12462 (defvar vhdl-subprog-flattened nil
12463 "Indicates whether an subprogram interface has been flattened.")
12464
12465 (defun vhdl-subprog-flatten ()
12466 "Flatten interface list so that only one parameter exists per line."
12467 (interactive)
12468 (if (not vhdl-subprog-list)
12469 (error "ERROR: No subprogram interface has been read")
12470 (message "Flattening subprogram interface...")
12471 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12472 new-subprog-list old-subprog new-subprog names)
12473 ;; traverse parameter list and flatten entries
12474 (while old-subprog-list
12475 (setq old-subprog (car old-subprog-list))
12476 (setq names (car old-subprog))
12477 (while names
12478 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12479 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12480 (setq names (cdr names)))
12481 (setq old-subprog-list (cdr old-subprog-list)))
12482 (setq vhdl-subprog-list
12483 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12484 new-subprog-list (nth 3 vhdl-subprog-list)
12485 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12486 vhdl-subprog-flattened t)
12487 (message "Flattening subprogram interface...done"))))
12488
12489 (defun vhdl-subprog-copy ()
12490 "Get interface information from a subprogram specification."
12491 (interactive)
12492 (save-excursion
12493 (let (parse-error pos end-of-list
12494 name kind param-list object names direct type init
12495 comment group-comment
12496 return-type return-comment return-group-comment)
12497 (vhdl-prepare-search-2
12498 (setq
12499 parse-error
12500 (catch 'parse
12501 ;; check if within function declaration
12502 (setq pos (point))
12503 (end-of-line)
12504 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12505 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12506 (goto-char (match-end 0))
12507 (save-excursion (backward-char)
12508 (forward-sexp)
12509 (<= pos (point))))
12510 (throw 'parse "ERROR: Not within a subprogram specification"))
12511 (setq name (match-string-no-properties 5))
12512 (setq kind (if (match-string 2) 'procedure 'function))
12513 (setq end-of-list (not (match-string 7)))
12514 (message "Reading interface of subprogram \"%s\"..." name)
12515 ;; parse parameter list
12516 (setq group-comment (vhdl-parse-group-comment))
12517 (setq end-of-list (or end-of-list
12518 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12519 (while (not end-of-list)
12520 ;; parse object
12521 (setq object
12522 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12523 (match-string-no-properties 1)))
12524 ;; parse names (accept extended identifiers)
12525 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12526 (setq names (list (match-string-no-properties 1)))
12527 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12528 (setq names (append names (list (match-string-no-properties 1)))))
12529 ;; parse direction
12530 (vhdl-parse-string ":[ \t\n\r\f]*")
12531 (setq direct
12532 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12533 (match-string-no-properties 1)))
12534 ;; parse type
12535 (vhdl-parse-string "\\([^():;\n]+\\)")
12536 (setq type (match-string-no-properties 1))
12537 (setq comment nil)
12538 (while (looking-at "(")
12539 (setq type
12540 (concat type
12541 (buffer-substring-no-properties
12542 (point) (progn (forward-sexp) (point)))
12543 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12544 (match-string-no-properties 1)))))
12545 ;; special case: closing parenthesis is on separate line
12546 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12547 (setq comment (substring type (match-beginning 2)))
12548 (setq type (substring type 0 (match-beginning 1))))
12549 ;; strip off trailing group-comment
12550 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12551 (setq type (substring type 0 (match-end 1)))
12552 ;; parse initialization expression
12553 (setq init nil)
12554 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12555 (vhdl-parse-string "\\([^();\n]*\\)")
12556 (setq init (match-string-no-properties 1))
12557 (while (looking-at "(")
12558 (setq init
12559 (concat init
12560 (buffer-substring-no-properties
12561 (point) (progn (forward-sexp) (point)))
12562 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12563 (match-string-no-properties 1))))))
12564 ;; special case: closing parenthesis is on separate line
12565 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12566 (setq comment (substring init (match-beginning 2)))
12567 (setq init (substring init 0 (match-beginning 1)))
12568 (vhdl-forward-syntactic-ws))
12569 (skip-chars-forward " \t")
12570 ;; parse inline comment, special case: as above, no initial.
12571 (unless comment
12572 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12573 (match-string-no-properties 1))))
12574 (vhdl-forward-syntactic-ws)
12575 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12576 ;; parse inline comment
12577 (unless comment
12578 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12579 (match-string-no-properties 1))))
12580 (setq return-group-comment (vhdl-parse-group-comment))
12581 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12582 ;; parse return type
12583 (when (match-string 3)
12584 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12585 (setq return-type (match-string-no-properties 1))
12586 (when (and return-type
12587 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12588 (setq return-comment (substring return-type (match-beginning 2)))
12589 (setq return-type (substring return-type 0 (match-beginning 1))))
12590 ;; strip of trailing group-comment
12591 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12592 (setq return-type (substring return-type 0 (match-end 1)))
12593 ;; parse return comment
12594 (unless return-comment
12595 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12596 (match-string-no-properties 1)))))
12597 ;; parse inline comment
12598 (unless comment
12599 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12600 (match-string-no-properties 1))))
12601 ;; save everything in list
12602 (setq param-list (append param-list
12603 (list (list names object direct type init
12604 comment group-comment))))
12605 ;; parse group comment and spacing
12606 (setq group-comment (vhdl-parse-group-comment)))
12607 (message "Reading interface of subprogram \"%s\"...done" name)
12608 nil)))
12609 ;; finish parsing
12610 (if parse-error
12611 (error parse-error)
12612 (setq vhdl-subprog-list
12613 (list name kind param-list return-type return-comment
12614 return-group-comment)
12615 vhdl-subprog-flattened nil)))))
12616
12617 (defun vhdl-subprog-paste-specification (kind)
12618 "Paste as a subprogram specification."
12619 (indent-according-to-mode)
12620 (let ((margin (current-column))
12621 (param-list (nth 2 vhdl-subprog-list))
12622 list-margin start names param)
12623 ;; paste keyword and name
12624 (vhdl-insert-keyword
12625 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12626 (insert (nth 0 vhdl-subprog-list))
12627 (if (not param-list)
12628 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12629 (setq start (point))
12630 ;; paste parameter list
12631 (insert " (")
12632 (unless vhdl-argument-list-indent
12633 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12634 (setq list-margin (current-column))
12635 (while param-list
12636 (setq param (car param-list))
12637 ;; paste group comment and spacing
12638 (when (memq vhdl-include-group-comments (list kind 'always))
12639 (vhdl-paste-group-comment (nth 6 param) list-margin))
12640 ;; paste object
12641 (when (nth 1 param) (insert (nth 1 param) " "))
12642 ;; paste names
12643 (setq names (nth 0 param))
12644 (while names
12645 (insert (car names))
12646 (setq names (cdr names))
12647 (when names (insert ", ")))
12648 ;; paste direction
12649 (insert " : ")
12650 (when (nth 2 param) (insert (nth 2 param) " "))
12651 ;; paste type
12652 (insert (nth 3 param))
12653 ;; paste initialization
12654 (when (nth 4 param) (insert " := " (nth 4 param)))
12655 ;; terminate line
12656 (if (cdr param-list)
12657 (insert ";")
12658 (insert ")")
12659 (when (null (nth 3 vhdl-subprog-list))
12660 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12661 ;; paste comment
12662 (when (and vhdl-include-port-comments (nth 5 param))
12663 (vhdl-comment-insert-inline (nth 5 param) t))
12664 (setq param-list (cdr param-list))
12665 (when param-list (insert "\n") (indent-to list-margin)))
12666 (when (nth 3 vhdl-subprog-list)
12667 (insert "\n") (indent-to list-margin)
12668 ;; paste group comment and spacing
12669 (when (memq vhdl-include-group-comments (list kind 'always))
12670 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12671 ;; paste return type
12672 (insert "return " (nth 3 vhdl-subprog-list))
12673 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12674 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12675 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12676 ;; align parameter list
12677 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12678 ;; paste body
12679 (when (eq kind 'body)
12680 (insert "\n")
12681 (vhdl-template-begin-end
12682 (unless (vhdl-standard-p '87)
12683 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12684 (nth 0 vhdl-subprog-list) margin))))
12685
12686 (defun vhdl-subprog-paste-declaration ()
12687 "Paste as a subprogram declaration."
12688 (interactive)
12689 (if (not vhdl-subprog-list)
12690 (error "ERROR: No subprogram interface read")
12691 (message "Pasting interface as subprogram declaration \"%s\"..."
12692 (car vhdl-subprog-list))
12693 ;; paste specification
12694 (vhdl-subprog-paste-specification 'decl)
12695 (message "Pasting interface as subprogram declaration \"%s\"...done"
12696 (car vhdl-subprog-list))))
12697
12698 (defun vhdl-subprog-paste-body ()
12699 "Paste as a subprogram body."
12700 (interactive)
12701 (if (not vhdl-subprog-list)
12702 (error "ERROR: No subprogram interface read")
12703 (message "Pasting interface as subprogram body \"%s\"..."
12704 (car vhdl-subprog-list))
12705 ;; paste specification and body
12706 (vhdl-subprog-paste-specification 'body)
12707 (message "Pasting interface as subprogram body \"%s\"...done"
12708 (car vhdl-subprog-list))))
12709
12710 (defun vhdl-subprog-paste-call ()
12711 "Paste as a subprogram call."
12712 (interactive)
12713 (if (not vhdl-subprog-list)
12714 (error "ERROR: No subprogram interface read")
12715 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12716 param-list margin list-margin param start)
12717 ;; flatten local copy of interface list (must be flat for parameter mapping)
12718 (vhdl-subprog-flatten)
12719 (setq param-list (nth 2 vhdl-subprog-list))
12720 (indent-according-to-mode)
12721 (setq margin (current-indentation))
12722 (message "Pasting interface as subprogram call \"%s\"..."
12723 (car vhdl-subprog-list))
12724 ;; paste name
12725 (insert (nth 0 vhdl-subprog-list))
12726 (if (not param-list)
12727 (insert ";")
12728 (setq start (point))
12729 ;; paste parameter list
12730 (insert " (")
12731 (unless vhdl-argument-list-indent
12732 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12733 (setq list-margin (current-column))
12734 (while param-list
12735 (setq param (car param-list))
12736 ;; paste group comment and spacing
12737 (when (eq vhdl-include-group-comments 'always)
12738 (vhdl-paste-group-comment (nth 6 param) list-margin))
12739 ;; paste formal port
12740 (insert (car (nth 0 param)) " => ")
12741 (setq param-list (cdr param-list))
12742 (insert (if param-list "," ");"))
12743 ;; paste comment
12744 (when (and vhdl-include-port-comments (nth 5 param))
12745 (vhdl-comment-insert-inline (nth 5 param)))
12746 (when param-list (insert "\n") (indent-to list-margin)))
12747 ;; align parameter list
12748 (when vhdl-auto-align
12749 (vhdl-align-region-groups start (point) 1)))
12750 (message "Pasting interface as subprogram call \"%s\"...done"
12751 (car vhdl-subprog-list))
12752 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12753
12754
12755 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12756 ;;; Miscellaneous
12757 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12758
12759 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12760 ;; Hippie expand customization
12761
12762 (defvar vhdl-expand-upper-case nil)
12763
12764 (defun vhdl-try-expand-abbrev (old)
12765 "Try expanding abbreviations from `vhdl-abbrev-list'."
12766 (unless old
12767 (he-init-string (he-dabbrev-beg) (point))
12768 (setq he-expand-list
12769 (let ((abbrev-list vhdl-abbrev-list)
12770 (sel-abbrev-list '()))
12771 (while abbrev-list
12772 (when (or (not (stringp (car abbrev-list)))
12773 (string-match
12774 (concat "^" he-search-string) (car abbrev-list)))
12775 (setq sel-abbrev-list
12776 (cons (car abbrev-list) sel-abbrev-list)))
12777 (setq abbrev-list (cdr abbrev-list)))
12778 (nreverse sel-abbrev-list))))
12779 (while (and he-expand-list
12780 (or (not (stringp (car he-expand-list)))
12781 (he-string-member (car he-expand-list) he-tried-table t)))
12782 (unless (stringp (car he-expand-list))
12783 (setq vhdl-expand-upper-case (car he-expand-list)))
12784 (setq he-expand-list (cdr he-expand-list)))
12785 (if (null he-expand-list)
12786 (progn (when old (he-reset-string))
12787 nil)
12788 (he-substitute-string
12789 (if vhdl-expand-upper-case
12790 (upcase (car he-expand-list))
12791 (car he-expand-list))
12792 t)
12793 (setq he-expand-list (cdr he-expand-list))
12794 t))
12795
12796 (defun vhdl-he-list-beg ()
12797 "Also looks at the word before `(' in order to better match parenthesized
12798 expressions (e.g. for index ranges of types and signals)."
12799 (save-excursion
12800 (condition-case ()
12801 (progn (backward-up-list 1)
12802 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12803 (error ()))
12804 (point)))
12805
12806 ;; override `he-list-beg' from `hippie-exp'
12807 (unless (and (boundp 'viper-mode) viper-mode)
12808 (defalias 'he-list-beg 'vhdl-he-list-beg))
12809
12810 ;; function for expanding abbrevs and dabbrevs
12811 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12812 '(try-expand-dabbrev
12813 try-expand-dabbrev-all-buffers
12814 vhdl-try-expand-abbrev)))
12815
12816 ;; function for expanding parenthesis
12817 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12818 '(try-expand-list
12819 try-expand-list-all-buffers)))
12820
12821 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12822 ;; Line handling functions
12823
12824 (defun vhdl-current-line ()
12825 "Return the line number of the line containing point."
12826 (save-restriction
12827 (widen)
12828 (1+ (count-lines (point-min) (point-at-bol)))))
12829
12830 (defun vhdl-line-kill-entire (&optional arg)
12831 "Delete entire line."
12832 (interactive "p")
12833 (beginning-of-line)
12834 (kill-line (or arg 1)))
12835
12836 (defun vhdl-line-kill (&optional arg)
12837 "Kill current line."
12838 (interactive "p")
12839 (vhdl-line-kill-entire arg))
12840
12841 (defun vhdl-line-copy (&optional arg)
12842 "Copy current line."
12843 (interactive "p")
12844 (save-excursion
12845 (let ((position (point-at-bol)))
12846 (forward-line (or arg 1))
12847 (copy-region-as-kill position (point)))))
12848
12849 (defun vhdl-line-yank ()
12850 "Yank entire line."
12851 (interactive)
12852 (beginning-of-line)
12853 (yank))
12854
12855 (defun vhdl-line-expand (&optional prefix-arg)
12856 "Hippie-expand current line."
12857 (interactive "P")
12858 (require 'hippie-exp)
12859 (let ((case-fold-search t) (case-replace nil)
12860 (hippie-expand-try-functions-list
12861 '(try-expand-line try-expand-line-all-buffers)))
12862 (hippie-expand prefix-arg)))
12863
12864 (defun vhdl-line-transpose-next (&optional arg)
12865 "Interchange this line with next line."
12866 (interactive "p")
12867 (forward-line 1)
12868 (transpose-lines (or arg 1))
12869 (forward-line -1))
12870
12871 (defun vhdl-line-transpose-previous (&optional arg)
12872 "Interchange this line with previous line."
12873 (interactive "p")
12874 (forward-line 1)
12875 (transpose-lines (- 0 (or arg 0)))
12876 (forward-line -1))
12877
12878 (defun vhdl-line-open ()
12879 "Open a new line and indent."
12880 (interactive)
12881 (end-of-line -0)
12882 (newline-and-indent))
12883
12884 (defun vhdl-delete-indentation ()
12885 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12886 it works within comments too."
12887 (interactive)
12888 (let ((fill-prefix "-- "))
12889 (delete-indentation)))
12890
12891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12892 ;; Move functions
12893
12894 (defun vhdl-forward-same-indent ()
12895 "Move forward to next line with same indent."
12896 (interactive)
12897 (let ((pos (point))
12898 (indent (current-indentation)))
12899 (beginning-of-line 2)
12900 (while (and (not (eobp))
12901 (or (looking-at "^\\s-*\\(--.*\\)?$")
12902 (> (current-indentation) indent)))
12903 (beginning-of-line 2))
12904 (if (= (current-indentation) indent)
12905 (back-to-indentation)
12906 (message "No following line with same indent found in this block")
12907 (goto-char pos)
12908 nil)))
12909
12910 (defun vhdl-backward-same-indent ()
12911 "Move backward to previous line with same indent."
12912 (interactive)
12913 (let ((pos (point))
12914 (indent (current-indentation)))
12915 (beginning-of-line -0)
12916 (while (and (not (bobp))
12917 (or (looking-at "^\\s-*\\(--.*\\)?$")
12918 (> (current-indentation) indent)))
12919 (beginning-of-line -0))
12920 (if (= (current-indentation) indent)
12921 (back-to-indentation)
12922 (message "No preceding line with same indent found in this block")
12923 (goto-char pos)
12924 nil)))
12925
12926 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12927 ;; Statistics
12928
12929 (defun vhdl-statistics-buffer ()
12930 "Get some file statistics."
12931 (interactive)
12932 (let ((no-stats 0)
12933 (no-code-lines 0)
12934 (no-empty-lines 0)
12935 (no-comm-lines 0)
12936 (no-comments 0)
12937 (no-lines (count-lines (point-min) (point-max))))
12938 (save-excursion
12939 ;; count statements
12940 (goto-char (point-min))
12941 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12942 (if (match-string 1)
12943 (goto-char (match-end 1))
12944 (setq no-stats (1+ no-stats))))
12945 ;; count code lines
12946 (goto-char (point-min))
12947 (while (not (eobp))
12948 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12949 (setq no-code-lines (1+ no-code-lines)))
12950 (beginning-of-line 2))
12951 ;; count empty lines
12952 (goto-char (point-min))
12953 (while (and (re-search-forward "^\\s-*$" nil t)
12954 (not (eq (point) (point-max))))
12955 (if (match-string 1)
12956 (goto-char (match-end 1))
12957 (setq no-empty-lines (1+ no-empty-lines))
12958 (unless (eq (point) (point-max))
12959 (forward-char))))
12960 ;; count comment-only lines
12961 (goto-char (point-min))
12962 (while (re-search-forward "^\\s-*--.*" nil t)
12963 (if (match-string 1)
12964 (goto-char (match-end 1))
12965 (setq no-comm-lines (1+ no-comm-lines))))
12966 ;; count comments
12967 (goto-char (point-min))
12968 (while (re-search-forward "--.*" nil t)
12969 (if (match-string 1)
12970 (goto-char (match-end 1))
12971 (setq no-comments (1+ no-comments)))))
12972 ;; print results
12973 (message "\n\
12974 File statistics: \"%s\"\n\
12975 -----------------------\n\
12976 # statements : %5d\n\
12977 # code lines : %5d\n\
12978 # empty lines : %5d\n\
12979 # comment lines : %5d\n\
12980 # comments : %5d\n\
12981 # total lines : %5d\n"
12982 (buffer-file-name) no-stats no-code-lines no-empty-lines
12983 no-comm-lines no-comments no-lines)
12984 (unless vhdl-emacs-21 (vhdl-show-messages))))
12985
12986 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12987 ;; Help functions
12988
12989 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12990 "Like `re-search-forward', but does not match within literals."
12991 (let (pos)
12992 (save-excursion
12993 (while (and (setq pos (re-search-forward regexp bound noerror count))
12994 (vhdl-in-literal))))
12995 (when pos (goto-char pos))
12996 pos))
12997
12998 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12999 "Like `re-search-backward', but does not match within literals."
13000 (let (pos)
13001 (save-excursion
13002 (while (and (setq pos (re-search-backward regexp bound noerror count))
13003 (vhdl-in-literal))))
13004 (when pos (goto-char pos))
13005 pos))
13006
13007
13008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13009 ;;; Project
13010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13011
13012 (defun vhdl-set-project (name)
13013 "Set current project to NAME."
13014 (interactive
13015 (list (let ((completion-ignore-case t))
13016 (completing-read "Project name: " vhdl-project-alist nil t))))
13017 (cond ((equal name "")
13018 (setq vhdl-project nil)
13019 (message "Current VHDL project: None"))
13020 ((assoc name vhdl-project-alist)
13021 (setq vhdl-project name)
13022 (message "Current VHDL project: \"%s\"" name))
13023 (t
13024 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
13025 (vhdl-speedbar-update-current-project))
13026
13027 (defun vhdl-set-default-project ()
13028 "Set current project as default on startup."
13029 (interactive)
13030 (customize-set-variable 'vhdl-project vhdl-project)
13031 (customize-save-customized))
13032
13033 (defun vhdl-toggle-project (name token indent)
13034 "Set current project to NAME or unset if NAME is current project."
13035 (vhdl-set-project (if (equal name vhdl-project) "" name)))
13036
13037 (defun vhdl-export-project (file-name)
13038 "Write project setup for current project."
13039 (interactive
13040 (let ((name (vhdl-resolve-env-variable
13041 (vhdl-replace-string
13042 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13043 (concat (subst-char-in-string
13044 ? ?_ (or (vhdl-project-p)
13045 (error "ERROR: No current project")))
13046 " " (user-login-name))))))
13047 (list (read-file-name
13048 "Write project file: "
13049 (when (file-name-absolute-p name) "") nil nil name))))
13050 (setq file-name (abbreviate-file-name file-name))
13051 (let ((orig-buffer (current-buffer)))
13052 (unless (file-exists-p (file-name-directory file-name))
13053 (make-directory (file-name-directory file-name) t))
13054 (if (not (file-writable-p file-name))
13055 (error "ERROR: File not writable: \"%s\"" file-name)
13056 (set-buffer (find-file-noselect file-name t t))
13057 (erase-buffer)
13058 (insert ";; -*- Emacs-Lisp -*-\n\n"
13059 ";;; " (file-name-nondirectory file-name)
13060 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
13061 ";; Project : " vhdl-project "\n"
13062 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
13063 (user-login-name) "\n\n\n"
13064 ";; project name\n"
13065 "(setq vhdl-project \"" vhdl-project "\")\n\n"
13066 ";; project setup\n"
13067 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
13068 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
13069 (insert ")\n")
13070 (save-buffer)
13071 (kill-buffer (current-buffer))
13072 (set-buffer orig-buffer))))
13073
13074 (defun vhdl-import-project (file-name &optional auto not-make-current)
13075 "Read project setup and set current project."
13076 (interactive
13077 (let ((name (vhdl-resolve-env-variable
13078 (vhdl-replace-string
13079 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13080 (concat "" " " (user-login-name))))))
13081 (list (read-file-name
13082 "Read project file: " (when (file-name-absolute-p name) "") nil t
13083 (file-name-directory name)))))
13084 (when (file-exists-p file-name)
13085 (condition-case ()
13086 (let ((current-project vhdl-project))
13087 (load-file file-name)
13088 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
13089 (vhdl-adelete 'vhdl-project-alist vhdl-project)
13090 (error ""))
13091 (if not-make-current
13092 (setq vhdl-project current-project)
13093 (setq vhdl-compiler
13094 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
13095 (vhdl-update-mode-menu)
13096 (vhdl-speedbar-refresh)
13097 (unless not-make-current
13098 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
13099 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
13100 (error (vhdl-warning
13101 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
13102
13103 (defun vhdl-duplicate-project ()
13104 "Duplicate setup of current project."
13105 (interactive)
13106 (let ((new-name (read-from-minibuffer "New project name: "))
13107 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
13108 (setq vhdl-project-alist
13109 (append vhdl-project-alist
13110 (list (cons new-name project-entry))))
13111 (vhdl-update-mode-menu)))
13112
13113 (defun vhdl-auto-load-project ()
13114 "Automatically load project setup at startup."
13115 (let ((file-name-list vhdl-project-file-name)
13116 file-list list-length)
13117 (while file-name-list
13118 (setq file-list
13119 (append file-list
13120 (file-expand-wildcards
13121 (vhdl-resolve-env-variable
13122 (vhdl-replace-string
13123 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
13124 (concat "* " (user-login-name)))))))
13125 (setq list-length (or list-length (length file-list)))
13126 (setq file-name-list (cdr file-name-list)))
13127 (while file-list
13128 (vhdl-import-project (expand-file-name (car file-list)) t
13129 (not (> list-length 0)))
13130 (setq list-length (1- list-length))
13131 (setq file-list (cdr file-list)))))
13132
13133 ;; automatically load project setup when idle after startup
13134 (when (memq 'startup vhdl-project-auto-load)
13135 (if noninteractive
13136 (vhdl-auto-load-project)
13137 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13138
13139
13140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13141 ;;; Hideshow
13142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13143 ;; (using `hideshow.el')
13144
13145 (defconst vhdl-hs-start-regexp
13146 (concat
13147 "\\(^\\)\\s-*\\("
13148 ;; generic/port clause
13149 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13150 ;; component
13151 "component\\>\\|"
13152 ;; component instantiation
13153 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13154 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13155 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13156 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13157 ;; subprogram
13158 "\\(function\\|procedure\\)\\>\\|"
13159 ;; process, block
13160 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13161 ;; configuration declaration
13162 "configuration\\>"
13163 "\\)")
13164 "Regexp to match start of construct to hide.")
13165
13166 (defun vhdl-hs-forward-sexp-func (count)
13167 "Find end of construct to hide (for hideshow). Only searches forward."
13168 (let ((pos (point)))
13169 (vhdl-prepare-search-2
13170 (beginning-of-line)
13171 (cond
13172 ;; generic/port clause
13173 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13174 (goto-char (match-end 0))
13175 (backward-char)
13176 (forward-sexp))
13177 ;; component declaration
13178 ((looking-at "^\\s-*component\\>")
13179 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13180 ;; component instantiation
13181 ((looking-at
13182 (concat
13183 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13184 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13185 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13186 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13187 (goto-char (match-end 0))
13188 (backward-char)
13189 (forward-sexp)
13190 (setq pos (point))
13191 (vhdl-forward-syntactic-ws)
13192 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13193 (goto-char (match-end 0))
13194 (backward-char)
13195 (forward-sexp)
13196 (setq pos (point)))
13197 (goto-char pos))
13198 ;; subprogram declaration/body
13199 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13200 (goto-char (match-end 0))
13201 (vhdl-forward-syntactic-ws)
13202 (when (looking-at "(")
13203 (forward-sexp))
13204 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13205 (vhdl-in-literal)))
13206 ;; subprogram body
13207 (when (match-string 2)
13208 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13209 (backward-word 1)
13210 (vhdl-forward-sexp)))
13211 ;; block (recursive)
13212 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13213 (goto-char (match-end 0))
13214 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13215 (match-beginning 2))
13216 (vhdl-hs-forward-sexp-func count)))
13217 ;; process
13218 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13219 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13220 ;; configuration declaration
13221 ((looking-at "^\\s-*configuration\\>")
13222 (forward-word 4)
13223 (vhdl-forward-sexp))
13224 (t (goto-char pos))))))
13225
13226 (defun vhdl-hideshow-init ()
13227 "Initialize `hideshow'."
13228 (when vhdl-hideshow-menu
13229 (vhdl-hs-minor-mode 1)))
13230
13231 (defun vhdl-hs-minor-mode (&optional arg)
13232 "Toggle hideshow minor mode and update menu bar."
13233 (interactive "P")
13234 (require 'hideshow)
13235 ;; check for hideshow version 5.x
13236 (if (not (boundp 'hs-block-start-mdata-select))
13237 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13238 ;; initialize hideshow
13239 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13240 (setq hs-special-modes-alist
13241 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13242 'vhdl-hs-forward-sexp-func nil)
13243 hs-special-modes-alist)))
13244 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13245 (if vhdl-hide-all-init
13246 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13247 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13248 (hs-minor-mode arg)
13249 (force-mode-line-update))) ; hack to update menu bar
13250
13251
13252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13253 ;;; Font locking
13254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13255 ;; (using `font-lock.el')
13256
13257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13258 ;; Help functions
13259
13260 (defun vhdl-within-translate-off ()
13261 "Return point if within translate-off region, else nil."
13262 (and (save-excursion
13263 (re-search-backward
13264 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13265 (equal "off" (match-string 1))
13266 (point)))
13267
13268 (defun vhdl-start-translate-off (limit)
13269 "Return point before translate-off pragma if before LIMIT, else nil."
13270 (when (re-search-forward
13271 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13272 (match-beginning 0)))
13273
13274 (defun vhdl-end-translate-off (limit)
13275 "Return point after translate-on pragma if before LIMIT, else nil."
13276 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13277
13278 (defun vhdl-match-translate-off (limit)
13279 "Match a translate-off block, setting match-data and returning t, else nil."
13280 (when (< (point) limit)
13281 (let ((start (or (vhdl-within-translate-off)
13282 (vhdl-start-translate-off limit)))
13283 (case-fold-search t))
13284 (when start
13285 (let ((end (or (vhdl-end-translate-off limit) limit)))
13286 (set-match-data (list start end))
13287 (goto-char end))))))
13288
13289 (defun vhdl-font-lock-match-item (limit)
13290 "Match, and move over, any declaration item after point. Adapted from
13291 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13292 (condition-case nil
13293 (save-restriction
13294 (narrow-to-region (point-min) limit)
13295 ;; match item
13296 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13297 (save-match-data
13298 (goto-char (match-end 1))
13299 ;; move to next item
13300 (if (looking-at "\\(\\s-*,\\)")
13301 (goto-char (match-end 1))
13302 (end-of-line) t))))
13303 (error t)))
13304
13305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13306 ;; Syntax definitions
13307
13308 (defconst vhdl-font-lock-syntactic-keywords
13309 '(("\\('\\).\\('\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13310 "Mark single quotes as having string quote syntax in `c' instances.")
13311
13312 (defvar vhdl-font-lock-keywords nil
13313 "Regular expressions to highlight in VHDL Mode.")
13314
13315 (defvar vhdl-font-lock-keywords-0
13316 ;; set in `vhdl-font-lock-init' because dependent on user options
13317 "For consideration as a value of `vhdl-font-lock-keywords'.
13318 This does highlighting of template prompts and directives (pragmas).")
13319
13320 (defvar vhdl-font-lock-keywords-1 nil
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 keywords and standard identifiers.")
13324
13325 (defconst vhdl-font-lock-keywords-2
13326 (list
13327 ;; highlight names of units, subprograms, and components when declared
13328 (list
13329 (concat
13330 "^\\s-*\\("
13331 "architecture\\|configuration\\|context\\|entity\\|package"
13332 "\\(\\s-+body\\)?\\|"
13333 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13334 "\\)\\s-+\\(\\w+\\)")
13335 5 'font-lock-function-name-face)
13336
13337 ;; highlight entity names of architectures and configurations
13338 (list
13339 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13340 2 'font-lock-function-name-face)
13341
13342 ;; highlight labels of common constructs
13343 (list
13344 (concat
13345 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13346 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13347 "postponed\\|process\\|"
13348 (when (vhdl-standard-p 'ams) "procedural\\|")
13349 "with\\|while"
13350 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13351 1 'font-lock-function-name-face)
13352
13353 ;; highlight label and component name of component instantiations
13354 (list
13355 (concat
13356 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13357 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13358 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13359
13360 ;; highlight label and instantiated unit of component instantiations
13361 (list
13362 (concat
13363 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13364 "\\(component\\|configuration\\|entity\\)\\s-+"
13365 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13366 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13367 '(5 font-lock-function-name-face nil t)
13368 '(7 font-lock-function-name-face nil t))
13369
13370 ;; highlight names and labels at end of constructs
13371 (list
13372 (concat
13373 "^\\s-*end\\s-+\\(\\("
13374 "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
13375 "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
13376 "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
13377 (when (vhdl-standard-p 'ams) "procedural\\|")
13378 "units"
13379 "\\)\\s-+\\)?\\(\\w*\\)")
13380 5 'font-lock-function-name-face)
13381
13382 ;; highlight labels in exit and next statements
13383 (list
13384 (concat
13385 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13386 3 'font-lock-function-name-face)
13387
13388 ;; highlight entity name in attribute specifications
13389 (list
13390 (concat
13391 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13392 1 'font-lock-function-name-face)
13393
13394 ;; highlight labels in block and component specifications
13395 (list
13396 (concat
13397 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13398 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13399 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13400
13401 ;; highlight names in library clauses
13402 (list "^\\s-*library\\>"
13403 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13404
13405 ;; highlight names in use clauses
13406 (list
13407 (concat
13408 "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13409 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13410 '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
13411 '(8 font-lock-function-name-face nil t))
13412
13413 ;; highlight attribute name in attribute declarations/specifications
13414 (list
13415 (concat
13416 "^\\s-*attribute\\s-+\\(\\w+\\)")
13417 1 'vhdl-font-lock-attribute-face)
13418
13419 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13420 (list
13421 (concat
13422 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13423 5 'font-lock-type-face)
13424
13425 ;; highlight signal/variable/constant declaration names
13426 (list "\\(:[^=]\\)"
13427 '(vhdl-font-lock-match-item
13428 (progn (goto-char (match-beginning 1))
13429 (skip-syntax-backward " ")
13430 (skip-syntax-backward "w_")
13431 (skip-syntax-backward " ")
13432 (while (= (preceding-char) ?,)
13433 (backward-char 1)
13434 (skip-syntax-backward " ")
13435 (skip-syntax-backward "w_")
13436 (skip-syntax-backward " ")))
13437 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13438
13439 ;; highlight formal parameters in component instantiations and subprogram
13440 ;; calls
13441 (list "\\(=>\\)"
13442 '(vhdl-font-lock-match-item
13443 (progn (goto-char (match-beginning 1))
13444 (skip-syntax-backward " ")
13445 (while (= (preceding-char) ?\)) (backward-sexp))
13446 (skip-syntax-backward "w_")
13447 (skip-syntax-backward " ")
13448 (when (memq (preceding-char) '(?n ?N ?|))
13449 (goto-char (point-max))))
13450 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13451
13452 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13453 ;; variables
13454 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13455 '(vhdl-font-lock-match-item
13456 (progn (goto-char (match-end 1)) (match-beginning 2))
13457 nil (1 font-lock-variable-name-face)))
13458
13459 ;; highlight tool directives
13460 (list
13461 (concat
13462 "^\\s-*\\(`\\w+\\)")
13463 1 'font-lock-preprocessor-face)
13464 )
13465 "For consideration as a value of `vhdl-font-lock-keywords'.
13466 This does context sensitive highlighting of names and labels.")
13467
13468 (defvar vhdl-font-lock-keywords-3 nil
13469 ;; set in `vhdl-font-lock-init' because dependent on user options
13470 "For consideration as a value of `vhdl-font-lock-keywords'.
13471 This does highlighting of words with special syntax.")
13472
13473 (defvar vhdl-font-lock-keywords-4 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 additional reserved words.")
13477
13478 (defconst vhdl-font-lock-keywords-5
13479 ;; background highlight translate-off regions
13480 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13481 "For consideration as a value of `vhdl-font-lock-keywords'.
13482 This does background highlighting of translate-off regions.")
13483
13484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13485 ;; Font and color definitions
13486
13487 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13488 "Face name to use for prompts.")
13489
13490 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13491 "Face name to use for standardized attributes.")
13492
13493 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13494 "Face name to use for standardized enumeration values.")
13495
13496 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13497 "Face name to use for standardized functions and packages.")
13498
13499 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13500 "Face name to use for directives.")
13501
13502 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13503 "Face name to use for additional reserved words.")
13504
13505 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13506 "Face name to use for translate-off regions.")
13507
13508 ;; face names to use for words with special syntax.
13509 (let ((syntax-alist vhdl-special-syntax-alist)
13510 name)
13511 (while syntax-alist
13512 (setq name (vhdl-function-name
13513 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13514 (eval `(defvar ,name ',name
13515 ,(concat "Face name to use for "
13516 (nth 0 (car syntax-alist)) ".")))
13517 (setq syntax-alist (cdr syntax-alist))))
13518
13519 (defgroup vhdl-highlight-faces nil
13520 "Faces for highlighting."
13521 :group 'vhdl-highlight)
13522
13523 ;; add faces used from `font-lock'
13524 (custom-add-to-group
13525 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13526 (custom-add-to-group
13527 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13528 (custom-add-to-group
13529 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13530 (custom-add-to-group
13531 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13532 (custom-add-to-group
13533 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13534 (custom-add-to-group
13535 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13536
13537 (defface vhdl-font-lock-prompt-face
13538 '((((min-colors 88) (class color) (background light))
13539 (:foreground "Red1" :bold t))
13540 (((class color) (background light)) (:foreground "Red" :bold t))
13541 (((class color) (background dark)) (:foreground "Pink" :bold t))
13542 (t (:inverse-video t)))
13543 "Font lock mode face used to highlight prompts."
13544 :group 'vhdl-highlight-faces)
13545
13546 (defface vhdl-font-lock-attribute-face
13547 '((((class color) (background light)) (:foreground "Orchid"))
13548 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13549 (t (:italic t :bold t)))
13550 "Font lock mode face used to highlight standardized attributes."
13551 :group 'vhdl-highlight-faces)
13552
13553 (defface vhdl-font-lock-enumvalue-face
13554 '((((class color) (background light)) (:foreground "SaddleBrown"))
13555 (((class color) (background dark)) (:foreground "BurlyWood"))
13556 (t (:italic t :bold t)))
13557 "Font lock mode face used to highlight standardized enumeration values."
13558 :group 'vhdl-highlight-faces)
13559
13560 (defface vhdl-font-lock-function-face
13561 '((((class color) (background light)) (:foreground "Cyan4"))
13562 (((class color) (background dark)) (:foreground "Orchid1"))
13563 (t (:italic t :bold t)))
13564 "Font lock mode face used to highlight standardized functions and packages."
13565 :group 'vhdl-highlight-faces)
13566
13567 (defface vhdl-font-lock-directive-face
13568 '((((class color) (background light)) (:foreground "CadetBlue"))
13569 (((class color) (background dark)) (:foreground "Aquamarine"))
13570 (t (:italic t :bold t)))
13571 "Font lock mode face used to highlight directives."
13572 :group 'vhdl-highlight-faces)
13573
13574 (defface vhdl-font-lock-reserved-words-face
13575 '((((class color) (background light)) (:foreground "Orange" :bold t))
13576 (((min-colors 88) (class color) (background dark))
13577 (:foreground "Yellow1" :bold t))
13578 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13579 (t ()))
13580 "Font lock mode face used to highlight additional reserved words."
13581 :group 'vhdl-highlight-faces)
13582
13583 (defface vhdl-font-lock-translate-off-face
13584 '((((class color) (background light)) (:background "LightGray"))
13585 (((class color) (background dark)) (:background "DimGray"))
13586 (t ()))
13587 "Font lock mode face used to background highlight translate-off regions."
13588 :group 'vhdl-highlight-faces)
13589
13590 ;; font lock mode faces used to highlight words with special syntax.
13591 (let ((syntax-alist vhdl-special-syntax-alist))
13592 (while syntax-alist
13593 (eval `(defface ,(vhdl-function-name
13594 "vhdl-font-lock" (caar syntax-alist) "face")
13595 '((((class color) (background light))
13596 (:foreground ,(nth 2 (car syntax-alist))))
13597 (((class color) (background dark))
13598 (:foreground ,(nth 3 (car syntax-alist))))
13599 (t ()))
13600 ,(concat "Font lock mode face used to highlight "
13601 (nth 0 (car syntax-alist)) ".")
13602 :group 'vhdl-highlight-faces))
13603 (setq syntax-alist (cdr syntax-alist))))
13604
13605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13606 ;; Font lock initialization
13607
13608 (defun vhdl-font-lock-init ()
13609 "Initialize fontification."
13610 ;; highlight template prompts and directives
13611 (setq vhdl-font-lock-keywords-0
13612 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13613 vhdl-template-prompt-syntax ">\\)")
13614 2 'vhdl-font-lock-prompt-face t)
13615 (list (concat "--\\s-*"
13616 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13617 2 'vhdl-font-lock-directive-face t)
13618 ;; highlight c-preprocessor directives
13619 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13620 '(1 font-lock-builtin-face)
13621 '(3 font-lock-variable-name-face nil t))))
13622 ;; highlight keywords and standardized types, attributes, enumeration
13623 ;; values, and subprograms
13624 (setq vhdl-font-lock-keywords-1
13625 (list
13626 (list (concat "'" vhdl-attributes-regexp)
13627 1 'vhdl-font-lock-attribute-face)
13628 (list vhdl-types-regexp 1 'font-lock-type-face)
13629 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13630 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13631 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13632 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13633 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13634 ;; highlight words with special syntax.
13635 (setq vhdl-font-lock-keywords-3
13636 (let ((syntax-alist vhdl-special-syntax-alist)
13637 keywords)
13638 (while syntax-alist
13639 (setq keywords
13640 (cons
13641 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13642 (vhdl-function-name
13643 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13644 (nth 4 (car syntax-alist)))
13645 keywords))
13646 (setq syntax-alist (cdr syntax-alist)))
13647 keywords))
13648 ;; highlight additional reserved words
13649 (setq vhdl-font-lock-keywords-4
13650 (list (list vhdl-reserved-words-regexp 1
13651 'vhdl-font-lock-reserved-words-face)))
13652 ;; highlight everything together
13653 (setq vhdl-font-lock-keywords
13654 (append
13655 vhdl-font-lock-keywords-0
13656 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13657 (when (or vhdl-highlight-forbidden-words
13658 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13659 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13660 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13661 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13662
13663 ;; initialize fontification for VHDL Mode
13664 (vhdl-font-lock-init)
13665
13666 (defun vhdl-fontify-buffer ()
13667 "Re-initialize fontification and fontify buffer."
13668 (interactive)
13669 (setq font-lock-defaults
13670 `(vhdl-font-lock-keywords
13671 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13672 beginning-of-line))
13673 (when (fboundp 'font-lock-unset-defaults)
13674 (font-lock-unset-defaults)) ; not implemented in XEmacs
13675 (font-lock-set-defaults)
13676 (font-lock-mode nil)
13677 (font-lock-mode t))
13678
13679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13680 ;; Initialization for PostScript printing
13681
13682 (defun vhdl-ps-print-settings ()
13683 "Initialize custom face and page settings for PostScript printing."
13684 ;; define custom face settings
13685 (unless (or (not vhdl-print-customize-faces)
13686 ps-print-color-p)
13687 (set (make-local-variable 'ps-bold-faces)
13688 '(font-lock-keyword-face
13689 font-lock-type-face
13690 vhdl-font-lock-attribute-face
13691 vhdl-font-lock-enumvalue-face
13692 vhdl-font-lock-directive-face))
13693 (set (make-local-variable 'ps-italic-faces)
13694 '(font-lock-comment-face
13695 font-lock-function-name-face
13696 font-lock-type-face
13697 vhdl-font-lock-attribute-face
13698 vhdl-font-lock-enumvalue-face
13699 vhdl-font-lock-directive-face))
13700 (set (make-local-variable 'ps-underlined-faces)
13701 '(font-lock-string-face))
13702 (setq ps-always-build-face-reference t))
13703 ;; define page settings, so that a line containing 79 characters (default)
13704 ;; fits into one column
13705 (when vhdl-print-two-column
13706 (set (make-local-variable 'ps-landscape-mode) t)
13707 (set (make-local-variable 'ps-number-of-columns) 2)
13708 (set (make-local-variable 'ps-font-size) 7.0)
13709 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13710 (set (make-local-variable 'ps-header-font-size) 9.0)
13711 (set (make-local-variable 'ps-header-offset) 12.0)
13712 (when (eq ps-paper-type 'letter)
13713 (set (make-local-variable 'ps-inter-column) 40.0)
13714 (set (make-local-variable 'ps-left-margin) 40.0)
13715 (set (make-local-variable 'ps-right-margin) 40.0))))
13716
13717 (defun vhdl-ps-print-init ()
13718 "Initialize PostScript printing."
13719 (if (featurep 'xemacs)
13720 (when (boundp 'ps-print-color-p)
13721 (vhdl-ps-print-settings))
13722 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13723 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13724
13725
13726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13727 ;;; Hierarchy browser (using `speedbar.el')
13728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13729 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13730 ;; directory by using the speedbar.
13731
13732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13733 ;; Variables
13734
13735 (defvar vhdl-entity-alist nil
13736 "Cache with entities and corresponding architectures for each
13737 project/directory.")
13738 ;; structure: (parenthesized expression means list of such entries)
13739 ;; (cache-key
13740 ;; (ent-key ent-name ent-file ent-line
13741 ;; (arch-key arch-name arch-file arch-line
13742 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13743 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13744 ;; (lib-name pack-key))
13745 ;; mra-key (lib-name pack-key))
13746
13747 (defvar vhdl-config-alist nil
13748 "Cache with configurations for each project/directory.")
13749 ;; structure: (parenthesized expression means list of such entries)
13750 ;; (cache-key
13751 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13752 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13753 ;; inst-conf-key inst-lib-key)
13754 ;; (lib-name pack-key)))
13755
13756 (defvar vhdl-package-alist nil
13757 "Cache with packages for each project/directory.")
13758 ;; structure: (parenthesized expression means list of such entries)
13759 ;; (cache-key
13760 ;; (pack-key pack-name pack-file pack-line
13761 ;; (comp-key comp-name comp-file comp-line)
13762 ;; (func-key func-name func-file func-line)
13763 ;; (lib-name pack-key)
13764 ;; pack-body-file pack-body-line
13765 ;; (func-key func-name func-body-file func-body-line)
13766 ;; (lib-name pack-key)))
13767
13768 (defvar vhdl-ent-inst-alist nil
13769 "Cache with instantiated entities for each project/directory.")
13770 ;; structure: (parenthesized expression means list of such entries)
13771 ;; (cache-key (inst-ent-key))
13772
13773 (defvar vhdl-file-alist nil
13774 "Cache with design units in each file for each project/directory.")
13775 ;; structure: (parenthesized expression means list of such entries)
13776 ;; (cache-key
13777 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13778 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13779
13780 (defvar vhdl-directory-alist nil
13781 "Cache with source directories for each project.")
13782 ;; structure: (parenthesized expression means list of such entries)
13783 ;; (cache-key (directory))
13784
13785 (defvar vhdl-speedbar-shown-unit-alist nil
13786 "Alist of design units simultaneously open in the current speedbar for each
13787 directory and project.")
13788
13789 (defvar vhdl-speedbar-shown-project-list nil
13790 "List of projects simultaneously open in the current speedbar.")
13791
13792 (defvar vhdl-updated-project-list nil
13793 "List of projects and directories with updated files.")
13794
13795 (defvar vhdl-modified-file-list nil
13796 "List of modified files to be rescanned for hierarchy updating.")
13797
13798 (defvar vhdl-speedbar-hierarchy-depth 0
13799 "Depth of instantiation hierarchy to display.")
13800
13801 (defvar vhdl-speedbar-show-projects nil
13802 "Non-nil means project hierarchy is displayed in speedbar, directory
13803 hierarchy otherwise.")
13804
13805 (defun vhdl-get-end-of-unit ()
13806 "Return position of end of current unit."
13807 (let ((pos (point)))
13808 (save-excursion
13809 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
13810 (save-excursion
13811 (goto-char (match-beginning 0))
13812 (vhdl-backward-syntactic-ws)
13813 (and (/= (preceding-char) ?\;) (not (bobp))))))
13814 (re-search-backward "^[ \t]*end\\>" pos 1)
13815 (point))))
13816
13817 (defun vhdl-match-string-downcase (num &optional string)
13818 "Like `match-string-no-properties' with down-casing."
13819 (let ((match (match-string-no-properties num string)))
13820 (and match (downcase match))))
13821
13822
13823 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13824 ;; Scan functions
13825
13826 (defun vhdl-scan-context-clause ()
13827 "Scan the context clause that precedes a design unit."
13828 (let (lib-alist)
13829 (save-excursion
13830 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
13831 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13832 (equal "USE" (upcase (match-string 1))))
13833 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13834 (push (cons (match-string-no-properties 1)
13835 (vhdl-match-string-downcase 2))
13836 lib-alist)))))
13837 lib-alist))
13838
13839 (defun vhdl-scan-directory-contents (name &optional project update num-string
13840 non-final)
13841 "Scan contents of VHDL files in directory or file pattern NAME."
13842 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13843 (let* ((dir-name (match-string 1 name))
13844 (file-pattern (match-string 2 name))
13845 (is-directory (= 0 (length file-pattern)))
13846 (file-list
13847 (if update
13848 (list name)
13849 (if is-directory
13850 (vhdl-get-source-files t dir-name)
13851 (vhdl-directory-files
13852 dir-name t (wildcard-to-regexp file-pattern)))))
13853 (key (or project dir-name))
13854 (file-exclude-regexp
13855 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13856 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13857 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13858 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13859 ent-alist conf-alist pack-alist ent-inst-list file-alist
13860 tmp-list tmp-entry no-files files-exist big-files)
13861 (when (or project update)
13862 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13863 conf-alist (vhdl-aget vhdl-config-alist key)
13864 pack-alist (vhdl-aget vhdl-package-alist key)
13865 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13866 file-alist (vhdl-aget vhdl-file-alist key)))
13867 (when (and (not is-directory) (null file-list))
13868 (message "No such file: \"%s\"" name))
13869 (setq files-exist file-list)
13870 (when file-list
13871 (setq no-files (length file-list))
13872 (message "Scanning %s %s\"%s\"..."
13873 (if is-directory "directory" "files") (or num-string "") name)
13874 ;; exclude files
13875 (unless (equal file-exclude-regexp "")
13876 (let ((case-fold-search nil)
13877 file-tmp-list)
13878 (while file-list
13879 (unless (string-match file-exclude-regexp (car file-list))
13880 (push (car file-list) file-tmp-list))
13881 (setq file-list (cdr file-list)))
13882 (setq file-list (nreverse file-tmp-list))))
13883 ;; do for all files
13884 (while file-list
13885 (unless noninteractive
13886 (message "Scanning %s %s\"%s\"... (%2d%%)"
13887 (if is-directory "directory" "files")
13888 (or num-string "") name
13889 (floor (* 100.0 (- no-files (length file-list))) no-files)))
13890 (let ((file-name (abbreviate-file-name (car file-list)))
13891 ent-list arch-list arch-ent-list conf-list
13892 pack-list pack-body-list inst-list inst-ent-list)
13893 ;; scan file
13894 (vhdl-visit-file
13895 file-name nil
13896 (vhdl-prepare-search-2
13897 (save-excursion
13898 ;; scan for design units
13899 (if (and limit-design-file-size
13900 (< limit-design-file-size (buffer-size)))
13901 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13902 (setq big-files t))
13903 ;; scan for entities
13904 (goto-char (point-min))
13905 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13906 (let* ((ent-name (match-string-no-properties 1))
13907 (ent-key (downcase ent-name))
13908 (ent-entry (vhdl-aget ent-alist ent-key))
13909 (lib-alist (vhdl-scan-context-clause)))
13910 (if (nth 1 ent-entry)
13911 (vhdl-warning-when-idle
13912 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13913 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13914 file-name (vhdl-current-line))
13915 (push ent-key ent-list)
13916 (vhdl-aput 'ent-alist ent-key
13917 (list ent-name file-name (vhdl-current-line)
13918 (nth 3 ent-entry) (nth 4 ent-entry)
13919 lib-alist)))))
13920 ;; scan for architectures
13921 (goto-char (point-min))
13922 (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)
13923 (let* ((arch-name (match-string-no-properties 1))
13924 (arch-key (downcase arch-name))
13925 (ent-name (match-string-no-properties 2))
13926 (ent-key (downcase ent-name))
13927 (ent-entry (vhdl-aget ent-alist ent-key))
13928 (arch-alist (nth 3 ent-entry))
13929 (arch-entry (vhdl-aget arch-alist arch-key))
13930 (lib-arch-alist (vhdl-scan-context-clause)))
13931 (if arch-entry
13932 (vhdl-warning-when-idle
13933 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13934 arch-name ent-name (nth 1 arch-entry)
13935 (nth 2 arch-entry) file-name (vhdl-current-line))
13936 (setq arch-list (cons arch-key arch-list)
13937 arch-ent-list (cons ent-key arch-ent-list))
13938 (vhdl-aput 'arch-alist arch-key
13939 (list arch-name file-name (vhdl-current-line)
13940 nil lib-arch-alist))
13941 (vhdl-aput 'ent-alist ent-key
13942 (list (or (nth 0 ent-entry) ent-name)
13943 (nth 1 ent-entry) (nth 2 ent-entry)
13944 (vhdl-sort-alist arch-alist)
13945 arch-key (nth 5 ent-entry))))))
13946 ;; scan for configurations
13947 (goto-char (point-min))
13948 (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)
13949 (let* ((conf-name (match-string-no-properties 1))
13950 (conf-key (downcase conf-name))
13951 (conf-entry (vhdl-aget conf-alist conf-key))
13952 (ent-name (match-string-no-properties 2))
13953 (ent-key (downcase ent-name))
13954 (lib-alist (vhdl-scan-context-clause))
13955 (conf-line (vhdl-current-line))
13956 (end-of-unit (vhdl-get-end-of-unit))
13957 arch-key comp-conf-list inst-key-list
13958 inst-comp-key inst-ent-key inst-arch-key
13959 inst-conf-key inst-lib-key)
13960 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13961 (setq arch-key (vhdl-match-string-downcase 1)))
13962 (if conf-entry
13963 (vhdl-warning-when-idle
13964 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13965 conf-name ent-name (nth 1 conf-entry)
13966 (nth 2 conf-entry) file-name conf-line)
13967 (push conf-key conf-list)
13968 ;; scan for subconfigurations and subentities
13969 (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)
13970 (setq inst-comp-key (vhdl-match-string-downcase 3)
13971 inst-key-list (split-string
13972 (vhdl-match-string-downcase 1)
13973 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13974 (vhdl-forward-syntactic-ws)
13975 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13976 (setq
13977 inst-lib-key (vhdl-match-string-downcase 3)
13978 inst-ent-key (and (match-string 2)
13979 (vhdl-match-string-downcase 4))
13980 inst-arch-key (and (match-string 2)
13981 (vhdl-match-string-downcase 6))
13982 inst-conf-key (and (not (match-string 2))
13983 (vhdl-match-string-downcase 4)))
13984 (while inst-key-list
13985 (setq comp-conf-list
13986 (cons (list (car inst-key-list)
13987 inst-comp-key inst-ent-key
13988 inst-arch-key inst-conf-key
13989 inst-lib-key)
13990 comp-conf-list))
13991 (setq inst-key-list (cdr inst-key-list)))))
13992 (vhdl-aput 'conf-alist conf-key
13993 (list conf-name file-name conf-line ent-key
13994 arch-key comp-conf-list lib-alist)))))
13995 ;; scan for packages
13996 (goto-char (point-min))
13997 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13998 (let* ((pack-name (match-string-no-properties 2))
13999 (pack-key (downcase pack-name))
14000 (is-body (match-string-no-properties 1))
14001 (pack-entry (vhdl-aget pack-alist pack-key))
14002 (pack-line (vhdl-current-line))
14003 (end-of-unit (vhdl-get-end-of-unit))
14004 comp-name func-name comp-alist func-alist lib-alist)
14005 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14006 (vhdl-warning-when-idle
14007 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
14008 (if is-body " body" "") pack-name
14009 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14010 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
14011 file-name (vhdl-current-line))
14012 ;; scan for context clauses
14013 (setq lib-alist (vhdl-scan-context-clause))
14014 ;; scan for component and subprogram declarations/bodies
14015 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
14016 (if (equal (upcase (match-string 1)) "COMPONENT")
14017 (setq comp-name (match-string-no-properties 2)
14018 comp-alist
14019 (cons (list (downcase comp-name) comp-name
14020 file-name (vhdl-current-line))
14021 comp-alist))
14022 (setq func-name (match-string-no-properties 2)
14023 func-alist
14024 (cons (list (downcase func-name) func-name
14025 file-name (vhdl-current-line))
14026 func-alist))))
14027 (setq func-alist (nreverse func-alist))
14028 (setq comp-alist (nreverse comp-alist))
14029 (if is-body
14030 (push pack-key pack-body-list)
14031 (push pack-key pack-list))
14032 (vhdl-aput
14033 'pack-alist pack-key
14034 (if is-body
14035 (list (or (nth 0 pack-entry) pack-name)
14036 (nth 1 pack-entry) (nth 2 pack-entry)
14037 (nth 3 pack-entry) (nth 4 pack-entry)
14038 (nth 5 pack-entry)
14039 file-name pack-line func-alist lib-alist)
14040 (list pack-name file-name pack-line
14041 comp-alist func-alist lib-alist
14042 (nth 6 pack-entry) (nth 7 pack-entry)
14043 (nth 8 pack-entry) (nth 9 pack-entry))))))))
14044 ;; scan for hierarchy
14045 (if (and limit-hier-file-size
14046 (< limit-hier-file-size (buffer-size)))
14047 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
14048 (setq big-files t))
14049 ;; scan for architectures
14050 (goto-char (point-min))
14051 (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)
14052 (let* ((ent-name (match-string-no-properties 2))
14053 (ent-key (downcase ent-name))
14054 (arch-name (match-string-no-properties 1))
14055 (arch-key (downcase arch-name))
14056 (ent-entry (vhdl-aget ent-alist ent-key))
14057 (arch-alist (nth 3 ent-entry))
14058 (arch-entry (vhdl-aget arch-alist arch-key))
14059 (beg-of-unit (point))
14060 (end-of-unit (vhdl-get-end-of-unit))
14061 (inst-no 0)
14062 inst-alist inst-path)
14063 ;; scan for contained instantiations
14064 (while (and (re-search-forward
14065 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
14066 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
14067 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
14068 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
14069 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
14070 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
14071 (or (not limit-hier-inst-no)
14072 (<= (if (or (match-string 14)
14073 (match-string 16))
14074 inst-no
14075 (setq inst-no (1+ inst-no)))
14076 limit-hier-inst-no)))
14077 (cond
14078 ;; block/generate beginning found
14079 ((match-string 14)
14080 (setq inst-path
14081 (cons (match-string-no-properties 1) inst-path)))
14082 ;; block/generate end found
14083 ((match-string 16)
14084 (setq inst-path (cdr inst-path)))
14085 ;; instantiation found
14086 (t
14087 (let* ((inst-name (match-string-no-properties 1))
14088 (inst-key (downcase inst-name))
14089 (inst-comp-name
14090 (or (match-string-no-properties 3)
14091 (match-string-no-properties 6)))
14092 (inst-ent-key
14093 (or (and (match-string 8)
14094 (vhdl-match-string-downcase 11))
14095 (and inst-comp-name
14096 (downcase inst-comp-name))))
14097 (inst-arch-key (vhdl-match-string-downcase 13))
14098 (inst-conf-key
14099 (and (not (match-string 8))
14100 (vhdl-match-string-downcase 11)))
14101 (inst-lib-key (vhdl-match-string-downcase 10)))
14102 (goto-char (match-end 1))
14103 (setq inst-list (cons inst-key inst-list)
14104 inst-ent-list
14105 (cons inst-ent-key inst-ent-list))
14106 (setq inst-alist
14107 (append
14108 inst-alist
14109 (list (list inst-key inst-name file-name
14110 (vhdl-current-line) inst-comp-name
14111 inst-ent-key inst-arch-key
14112 inst-conf-key inst-lib-key
14113 (reverse inst-path)))))))))
14114 ;; scan for contained configuration specifications
14115 (goto-char beg-of-unit)
14116 (while (re-search-forward
14117 (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]*\\)*"
14118 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
14119 (let* ((inst-comp-name (match-string-no-properties 3))
14120 (inst-ent-key
14121 (and (match-string 6)
14122 (vhdl-match-string-downcase 9)))
14123 (inst-arch-key (vhdl-match-string-downcase 11))
14124 (inst-conf-key
14125 (and (not (match-string 6))
14126 (vhdl-match-string-downcase 9)))
14127 (inst-lib-key (vhdl-match-string-downcase 8))
14128 (inst-key-list
14129 (split-string (vhdl-match-string-downcase 1)
14130 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
14131 (tmp-inst-alist inst-alist)
14132 inst-entry)
14133 (while tmp-inst-alist
14134 (when (and (or (equal "all" (car inst-key-list))
14135 (member (nth 0 (car tmp-inst-alist))
14136 inst-key-list))
14137 (equal
14138 (downcase
14139 (or (nth 4 (car tmp-inst-alist)) ""))
14140 (downcase inst-comp-name)))
14141 (setq inst-entry (car tmp-inst-alist))
14142 (setq inst-ent-list
14143 (cons (or inst-ent-key (nth 5 inst-entry))
14144 (vhdl-delete
14145 (nth 5 inst-entry) inst-ent-list)))
14146 (setq inst-entry
14147 (list (nth 0 inst-entry) (nth 1 inst-entry)
14148 (nth 2 inst-entry) (nth 3 inst-entry)
14149 (nth 4 inst-entry)
14150 (or inst-ent-key (nth 5 inst-entry))
14151 (or inst-arch-key (nth 6 inst-entry))
14152 inst-conf-key inst-lib-key))
14153 (setcar tmp-inst-alist inst-entry))
14154 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14155 ;; save in cache
14156 (vhdl-aput 'arch-alist arch-key
14157 (list (nth 0 arch-entry) (nth 1 arch-entry)
14158 (nth 2 arch-entry) inst-alist
14159 (nth 4 arch-entry)))
14160 (vhdl-aput 'ent-alist ent-key
14161 (list (nth 0 ent-entry) (nth 1 ent-entry)
14162 (nth 2 ent-entry)
14163 (vhdl-sort-alist arch-alist)
14164 (nth 4 ent-entry) (nth 5 ent-entry)))
14165 (when (and limit-hier-inst-no
14166 (> inst-no limit-hier-inst-no))
14167 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14168 (setq big-files t))
14169 (goto-char end-of-unit))))
14170 ;; remember design units for this file
14171 (vhdl-aput 'file-alist file-name
14172 (list ent-list arch-list arch-ent-list conf-list
14173 pack-list pack-body-list
14174 inst-list inst-ent-list))
14175 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14176 (setq file-list (cdr file-list))))
14177 (when (or (and (not project) files-exist)
14178 (and project (not non-final)))
14179 ;; consistency checks:
14180 ;; check whether each architecture has a corresponding entity
14181 (setq tmp-list ent-alist)
14182 (while tmp-list
14183 (when (null (nth 2 (car tmp-list)))
14184 (setq tmp-entry (car (nth 4 (car tmp-list))))
14185 (vhdl-warning-when-idle
14186 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14187 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14188 (nth 3 tmp-entry)))
14189 (setq tmp-list (cdr tmp-list)))
14190 ;; check whether configuration has a corresponding entity/architecture
14191 (setq tmp-list conf-alist)
14192 (while tmp-list
14193 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14194 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14195 (setq tmp-entry (car tmp-list))
14196 (vhdl-warning-when-idle
14197 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14198 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14199 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14200 (setq tmp-entry (car tmp-list))
14201 (vhdl-warning-when-idle
14202 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14203 (nth 1 tmp-entry) (nth 4 tmp-entry)
14204 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14205 (setq tmp-list (cdr tmp-list)))
14206 ;; check whether each package body has a package declaration
14207 (setq tmp-list pack-alist)
14208 (while tmp-list
14209 (when (null (nth 2 (car tmp-list)))
14210 (setq tmp-entry (car tmp-list))
14211 (vhdl-warning-when-idle
14212 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14213 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14214 (setq tmp-list (cdr tmp-list)))
14215 ;; sort lists
14216 (setq ent-alist (vhdl-sort-alist ent-alist))
14217 (setq conf-alist (vhdl-sort-alist conf-alist))
14218 (setq pack-alist (vhdl-sort-alist pack-alist))
14219 ;; remember updated directory/project
14220 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14221 ;; clear directory alists
14222 (unless project
14223 (vhdl-adelete 'vhdl-entity-alist key)
14224 (vhdl-adelete 'vhdl-config-alist key)
14225 (vhdl-adelete 'vhdl-package-alist key)
14226 (vhdl-adelete 'vhdl-ent-inst-alist key)
14227 (vhdl-adelete 'vhdl-file-alist key))
14228 ;; put directory contents into cache
14229 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14230 (vhdl-aput 'vhdl-config-alist key conf-alist)
14231 (vhdl-aput 'vhdl-package-alist key pack-alist)
14232 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14233 (vhdl-aput 'vhdl-file-alist key file-alist)
14234 ;; final messages
14235 (message "Scanning %s %s\"%s\"...done"
14236 (if is-directory "directory" "files") (or num-string "") name)
14237 (unless project (message "Scanning directory...done"))
14238 (when big-files
14239 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14240 ;; save cache when scanned non-interactively
14241 (when (or (not project) (not non-final))
14242 (when (and noninteractive vhdl-speedbar-save-cache)
14243 (vhdl-save-cache key)))
14244 t))
14245
14246 (defun vhdl-scan-project-contents (project)
14247 "Scan the contents of all VHDL files found in the directories and files
14248 of PROJECT."
14249 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14250 (default-dir (vhdl-resolve-env-variable
14251 (nth 1 (vhdl-aget vhdl-project-alist project))))
14252 (file-exclude-regexp
14253 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14254 dir-list-tmp dir dir-name num-dir act-dir recursive)
14255 ;; clear project alists
14256 (vhdl-adelete 'vhdl-entity-alist project)
14257 (vhdl-adelete 'vhdl-config-alist project)
14258 (vhdl-adelete 'vhdl-package-alist project)
14259 (vhdl-adelete 'vhdl-ent-inst-alist project)
14260 (vhdl-adelete 'vhdl-file-alist project)
14261 ;; expand directory names by default-directory
14262 (message "Collecting source files...")
14263 (while dir-list
14264 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14265 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14266 (setq recursive (match-string 1 dir)
14267 dir-name (match-string 3 dir))
14268 (setq dir-list-tmp
14269 (cons (concat recursive
14270 (if (file-name-absolute-p dir-name) "" default-dir)
14271 dir-name)
14272 dir-list-tmp))
14273 (setq dir-list (cdr dir-list)))
14274 ;; resolve path wildcards
14275 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14276 ;; expand directories
14277 (while dir-list-tmp
14278 (setq dir (car dir-list-tmp))
14279 ;; get subdirectories
14280 (if (string-match "-r \\(.*[/\\]\\)" dir)
14281 (setq dir-list (append dir-list (vhdl-get-subdirs
14282 (match-string 1 dir))))
14283 (setq dir-list (append dir-list (list dir))))
14284 (setq dir-list-tmp (cdr dir-list-tmp)))
14285 ;; exclude files
14286 (unless (equal file-exclude-regexp "")
14287 (let ((case-fold-search nil))
14288 (while dir-list
14289 (unless (string-match file-exclude-regexp (car dir-list))
14290 (push (car dir-list) dir-list-tmp))
14291 (setq dir-list (cdr dir-list)))
14292 (setq dir-list (nreverse dir-list-tmp))))
14293 (message "Collecting source files...done")
14294 ;; scan for design units for each directory in DIR-LIST
14295 (setq dir-list-tmp nil
14296 num-dir (length dir-list)
14297 act-dir 1)
14298 (while dir-list
14299 (setq dir-name (abbreviate-file-name
14300 (expand-file-name (car dir-list))))
14301 (vhdl-scan-directory-contents dir-name project nil
14302 (format "(%s/%s) " act-dir num-dir)
14303 (cdr dir-list))
14304 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
14305 (setq dir-list (cdr dir-list)
14306 act-dir (1+ act-dir)))
14307 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14308 (message "Scanning project \"%s\"...done" project)))
14309
14310 (defun vhdl-update-file-contents (file-name)
14311 "Update hierarchy information by contents of current buffer."
14312 (setq file-name (abbreviate-file-name file-name))
14313 (let* ((dir-name (file-name-directory file-name))
14314 (directory-alist vhdl-directory-alist)
14315 updated)
14316 (while directory-alist
14317 (when (member dir-name (nth 1 (car directory-alist)))
14318 (let* ((vhdl-project (nth 0 (car directory-alist)))
14319 (project (vhdl-project-p))
14320 (ent-alist (vhdl-aget vhdl-entity-alist
14321 (or project dir-name)))
14322 (conf-alist (vhdl-aget vhdl-config-alist
14323 (or project dir-name)))
14324 (pack-alist (vhdl-aget vhdl-package-alist
14325 (or project dir-name)))
14326 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14327 (or project dir-name))))
14328 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14329 (file-entry (vhdl-aget file-alist file-name))
14330 (ent-list (nth 0 file-entry))
14331 (arch-list (nth 1 file-entry))
14332 (arch-ent-list (nth 2 file-entry))
14333 (conf-list (nth 3 file-entry))
14334 (pack-list (nth 4 file-entry))
14335 (pack-body-list (nth 5 file-entry))
14336 (inst-ent-list (nth 7 file-entry))
14337 (cache-key (or project dir-name))
14338 arch-alist key ent-key entry)
14339 ;; delete design units previously contained in this file:
14340 ;; entities
14341 (while ent-list
14342 (setq key (car ent-list)
14343 entry (vhdl-aget ent-alist key))
14344 (when (equal file-name (nth 1 entry))
14345 (if (nth 3 entry)
14346 (vhdl-aput 'ent-alist key
14347 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14348 (vhdl-adelete 'ent-alist key)))
14349 (setq ent-list (cdr ent-list)))
14350 ;; architectures
14351 (while arch-list
14352 (setq key (car arch-list)
14353 ent-key (car arch-ent-list)
14354 entry (vhdl-aget ent-alist ent-key)
14355 arch-alist (nth 3 entry))
14356 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14357 (vhdl-adelete 'arch-alist key)
14358 (if (or (nth 1 entry) arch-alist)
14359 (vhdl-aput 'ent-alist ent-key
14360 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14361 arch-alist (nth 4 entry) (nth 5 entry)))
14362 (vhdl-adelete 'ent-alist ent-key)))
14363 (setq arch-list (cdr arch-list)
14364 arch-ent-list (cdr arch-ent-list)))
14365 ;; configurations
14366 (while conf-list
14367 (setq key (car conf-list))
14368 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14369 (vhdl-adelete 'conf-alist key))
14370 (setq conf-list (cdr conf-list)))
14371 ;; package declarations
14372 (while pack-list
14373 (setq key (car pack-list)
14374 entry (vhdl-aget pack-alist key))
14375 (when (equal file-name (nth 1 entry))
14376 (if (nth 6 entry)
14377 (vhdl-aput 'pack-alist key
14378 (list (nth 0 entry) nil nil nil nil nil
14379 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14380 (nth 9 entry)))
14381 (vhdl-adelete 'pack-alist key)))
14382 (setq pack-list (cdr pack-list)))
14383 ;; package bodies
14384 (while pack-body-list
14385 (setq key (car pack-body-list)
14386 entry (vhdl-aget pack-alist key))
14387 (when (equal file-name (nth 6 entry))
14388 (if (nth 1 entry)
14389 (vhdl-aput 'pack-alist key
14390 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14391 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14392 nil nil nil nil))
14393 (vhdl-adelete 'pack-alist key)))
14394 (setq pack-body-list (cdr pack-body-list)))
14395 ;; instantiated entities
14396 (while inst-ent-list
14397 (setq ent-inst-list
14398 (vhdl-delete (car inst-ent-list) ent-inst-list))
14399 (setq inst-ent-list (cdr inst-ent-list)))
14400 ;; update caches
14401 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14402 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14403 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14404 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14405 ;; scan file
14406 (vhdl-scan-directory-contents file-name project t)
14407 (when (or (and vhdl-speedbar-show-projects project)
14408 (and (not vhdl-speedbar-show-projects) (not project)))
14409 (vhdl-speedbar-refresh project))
14410 (setq updated t)))
14411 (setq directory-alist (cdr directory-alist)))
14412 updated))
14413
14414 (defun vhdl-update-hierarchy ()
14415 "Update directory and hierarchy information in speedbar."
14416 (let ((file-list (reverse vhdl-modified-file-list))
14417 updated)
14418 (when (and vhdl-speedbar-update-on-saving file-list)
14419 (while file-list
14420 (setq updated
14421 (or (vhdl-update-file-contents (car file-list))
14422 updated))
14423 (setq file-list (cdr file-list)))
14424 (setq vhdl-modified-file-list nil)
14425 (vhdl-speedbar-update-current-unit)
14426 (when updated (message "Updating hierarchy...done")))))
14427
14428 ;; structure (parenthesized expression means list of such entries)
14429 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14430 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14431 ;; comp-lib-name level)
14432 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14433 conf-inst-alist level indent
14434 &optional include-top ent-hier)
14435 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14436 entity ENT-KEY."
14437 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14438 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14439 (cdar (last (nth 3 ent-entry)))))
14440 (inst-alist (nth 3 arch-entry))
14441 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14442 hier-list subcomp-list tmp-list inst-key inst-comp-name
14443 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14444 (when (= level 0) (message "Extract design hierarchy..."))
14445 (when include-top
14446 (setq level (1+ level)))
14447 (when (member ent-key ent-hier)
14448 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14449 ;; process all instances
14450 (while inst-alist
14451 (setq inst-entry (car inst-alist)
14452 inst-key (nth 0 inst-entry)
14453 inst-comp-name (nth 4 inst-entry)
14454 inst-conf-key (nth 7 inst-entry))
14455 ;; search entry in configuration's instantiations list
14456 (setq tmp-list conf-inst-alist)
14457 (while (and tmp-list
14458 (not (and (member (nth 0 (car tmp-list))
14459 (list "all" inst-key))
14460 (equal (nth 1 (car tmp-list))
14461 (downcase (or inst-comp-name ""))))))
14462 (setq tmp-list (cdr tmp-list)))
14463 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14464 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14465 (when (and inst-conf-key (not inst-conf-entry))
14466 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14467 ;; determine entity
14468 (setq inst-ent-key
14469 (or (nth 2 (car tmp-list)) ; from configuration
14470 (nth 3 inst-conf-entry) ; from subconfiguration
14471 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14472 ; from configuration spec.
14473 (nth 5 inst-entry))) ; from direct instantiation
14474 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14475 ;; determine architecture
14476 (setq inst-arch-key
14477 (or (nth 3 (car tmp-list)) ; from configuration
14478 (nth 4 inst-conf-entry) ; from subconfiguration
14479 (nth 6 inst-entry) ; from direct instantiation
14480 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14481 ; from configuration spec.
14482 (nth 4 inst-ent-entry) ; MRA
14483 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14484 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14485 ;; set library
14486 (setq inst-lib-key
14487 (or (nth 5 (car tmp-list)) ; from configuration
14488 (nth 8 inst-entry))) ; from direct instantiation
14489 ;; gather information for this instance
14490 (setq comp-entry
14491 (list (nth 1 inst-entry)
14492 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14493 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14494 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14495 (or (nth 0 inst-arch-entry) inst-arch-key)
14496 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14497 (or (nth 0 inst-conf-entry) inst-conf-key)
14498 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14499 inst-lib-key level))
14500 ;; get subcomponent hierarchy
14501 (setq subcomp-list (vhdl-get-hierarchy
14502 ent-alist conf-alist
14503 inst-ent-key inst-arch-key inst-conf-key
14504 (nth 5 inst-conf-entry)
14505 (1+ level) indent nil (cons ent-key ent-hier)))
14506 ;; add to list
14507 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14508 (setq inst-alist (cdr inst-alist)))
14509 (when include-top
14510 (setq hier-list
14511 (cons (list nil nil (nth 0 ent-entry)
14512 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14513 (nth 0 arch-entry)
14514 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14515 nil nil
14516 nil (1- level))
14517 hier-list)))
14518 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14519 hier-list))
14520
14521 (defun vhdl-get-instantiations (ent-key indent)
14522 "Get all instantiations of entity ENT-KEY."
14523 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14524 (vhdl-speedbar-line-key indent)))
14525 arch-alist inst-alist ent-inst-list
14526 ent-entry arch-entry inst-entry)
14527 (while ent-alist
14528 (setq ent-entry (car ent-alist))
14529 (setq arch-alist (nth 4 ent-entry))
14530 (while arch-alist
14531 (setq arch-entry (car arch-alist))
14532 (setq inst-alist (nth 4 arch-entry))
14533 (while inst-alist
14534 (setq inst-entry (car inst-alist))
14535 (when (equal ent-key (nth 5 inst-entry))
14536 (setq ent-inst-list
14537 (cons (list (nth 1 inst-entry)
14538 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14539 (nth 1 ent-entry)
14540 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14541 (nth 1 arch-entry)
14542 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14543 ent-inst-list)))
14544 (setq inst-alist (cdr inst-alist)))
14545 (setq arch-alist (cdr arch-alist)))
14546 (setq ent-alist (cdr ent-alist)))
14547 (nreverse ent-inst-list)))
14548
14549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14550 ;; Caching in file
14551
14552 (defun vhdl-save-caches ()
14553 "Save all updated hierarchy caches to file."
14554 (interactive)
14555 (condition-case nil
14556 (when vhdl-speedbar-save-cache
14557 ;; update hierarchy
14558 (vhdl-update-hierarchy)
14559 (let ((project-list vhdl-updated-project-list))
14560 (message "Saving hierarchy caches...")
14561 ;; write updated project caches
14562 (while project-list
14563 (vhdl-save-cache (car project-list))
14564 (setq project-list (cdr project-list)))
14565 (message "Saving hierarchy caches...done")))
14566 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14567 (sit-for 2)))))
14568
14569 (defun vhdl-save-cache (key)
14570 "Save current hierarchy cache to file."
14571 (let* ((orig-buffer (current-buffer))
14572 (vhdl-project key)
14573 (project (vhdl-project-p))
14574 (default-directory key)
14575 (directory (abbreviate-file-name (vhdl-default-directory)))
14576 (file-name (vhdl-resolve-env-variable
14577 (vhdl-replace-string
14578 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14579 (concat
14580 (subst-char-in-string ? ?_ (or project "dir"))
14581 " " (user-login-name)))))
14582 (file-dir-name (expand-file-name file-name directory))
14583 (cache-key (or project directory))
14584 (key (if project "project" "directory")))
14585 (unless (file-exists-p (file-name-directory file-dir-name))
14586 (make-directory (file-name-directory file-dir-name) t))
14587 (if (not (file-writable-p file-dir-name))
14588 (progn (vhdl-warning (format "File not writable: \"%s\""
14589 (abbreviate-file-name file-dir-name)))
14590 (sit-for 2))
14591 (message "Saving cache: \"%s\"" file-dir-name)
14592 (set-buffer (find-file-noselect file-dir-name t t))
14593 (erase-buffer)
14594 (insert ";; -*- Emacs-Lisp -*-\n\n"
14595 ";;; " (file-name-nondirectory file-name)
14596 " - design hierarchy cache file for Emacs VHDL Mode "
14597 vhdl-version "\n")
14598 (insert "\n;; " (if project "Project " "Directory") " : ")
14599 (if project (insert project) (prin1 directory (current-buffer)))
14600 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14601 (user-login-name) "\n\n"
14602 "\n;; version number\n"
14603 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14604 "\n;; " (if project "project" "directory") " name"
14605 "\n(setq " key " ")
14606 (prin1 (or project directory) (current-buffer))
14607 (insert ")\n")
14608 (when (member 'hierarchy vhdl-speedbar-save-cache)
14609 (insert "\n;; entity and architecture cache\n"
14610 "(vhdl-aput 'vhdl-entity-alist " key " '")
14611 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14612 (insert ")\n\n;; configuration cache\n"
14613 "(vhdl-aput 'vhdl-config-alist " key " '")
14614 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14615 (insert ")\n\n;; package cache\n"
14616 "(vhdl-aput 'vhdl-package-alist " key " '")
14617 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14618 (insert ")\n\n;; instantiated entities cache\n"
14619 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14620 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14621 (insert ")\n\n;; design units per file cache\n"
14622 "(vhdl-aput 'vhdl-file-alist " key " '")
14623 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14624 (when project
14625 (insert ")\n\n;; source directories in project cache\n"
14626 "(vhdl-aput 'vhdl-directory-alist " key " '")
14627 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14628 (insert ")\n"))
14629 (when (member 'display vhdl-speedbar-save-cache)
14630 (insert "\n;; shown design units cache\n"
14631 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14632 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14633 (current-buffer))
14634 (insert ")\n"))
14635 (setq vhdl-updated-project-list
14636 (delete cache-key vhdl-updated-project-list))
14637 (save-buffer)
14638 (kill-buffer (current-buffer))
14639 (set-buffer orig-buffer))))
14640
14641 (defun vhdl-load-cache (key)
14642 "Load hierarchy cache information from file."
14643 (let* ((vhdl-project key)
14644 (default-directory key)
14645 (directory (vhdl-default-directory))
14646 (file-name (vhdl-resolve-env-variable
14647 (vhdl-replace-string
14648 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14649 (concat
14650 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14651 " " (user-login-name)))))
14652 (file-dir-name (expand-file-name file-name directory))
14653 vhdl-cache-version)
14654 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14655 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14656 (when (file-exists-p file-dir-name)
14657 (condition-case ()
14658 (progn (load-file file-dir-name)
14659 (string< (mapconcat
14660 (lambda (a) (format "%3d" (string-to-number a)))
14661 (split-string "3.33" "\\.") "")
14662 (mapconcat
14663 (lambda (a) (format "%3d" (string-to-number a)))
14664 (split-string vhdl-cache-version "\\.") "")))
14665 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14666 nil))))))
14667
14668 (defun vhdl-require-hierarchy-info ()
14669 "Make sure that hierarchy information is available. Load cache or scan files
14670 if required."
14671 (if (vhdl-project-p)
14672 (unless (or (assoc vhdl-project vhdl-file-alist)
14673 (vhdl-load-cache vhdl-project))
14674 (vhdl-scan-project-contents vhdl-project))
14675 (let ((directory (abbreviate-file-name default-directory)))
14676 (unless (or (assoc directory vhdl-file-alist)
14677 (vhdl-load-cache directory))
14678 (vhdl-scan-directory-contents directory)))))
14679
14680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14681 ;; Add hierarchy browser functionality to speedbar
14682
14683 (defvar vhdl-speedbar-mode-map nil
14684 "Keymap used when in the VHDL hierarchy browser mode.")
14685
14686 (defvar vhdl-speedbar-menu-items nil
14687 "Additional menu-items to add to speedbar frame.")
14688
14689 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14690 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14691 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14692 (declare-function speedbar-change-initial-expansion-list "speedbar"
14693 (new-default))
14694 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14695
14696 (defun vhdl-speedbar-initialize ()
14697 "Initialize speedbar."
14698 ;; general settings
14699 ;; VHDL file extensions (extracted from `auto-mode-alist')
14700 (let ((mode-alist auto-mode-alist))
14701 (while mode-alist
14702 (when (eq (cdar mode-alist) 'vhdl-mode)
14703 (speedbar-add-supported-extension (caar mode-alist)))
14704 (setq mode-alist (cdr mode-alist))))
14705 ;; hierarchy browser settings
14706 (when (boundp 'speedbar-mode-functions-list)
14707 ;; special functions
14708 (speedbar-add-mode-functions-list
14709 '("vhdl directory"
14710 (speedbar-item-info . vhdl-speedbar-item-info)
14711 (speedbar-line-directory . speedbar-files-line-path)))
14712 (speedbar-add-mode-functions-list
14713 '("vhdl project"
14714 (speedbar-item-info . vhdl-speedbar-item-info)
14715 (speedbar-line-directory . vhdl-speedbar-line-project)))
14716 ;; keymap
14717 (unless vhdl-speedbar-mode-map
14718 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14719 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14720 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14721 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14722 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14723 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14724 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14725 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14726 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14727 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14728 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14729 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14730 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14731 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14732 (let ((key 0))
14733 (while (<= key 9)
14734 (define-key vhdl-speedbar-mode-map (int-to-string key)
14735 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14736 (setq key (1+ key)))))
14737 (define-key speedbar-mode-map "h"
14738 (lambda () (interactive)
14739 (speedbar-change-initial-expansion-list "vhdl directory")))
14740 (define-key speedbar-mode-map "H"
14741 (lambda () (interactive)
14742 (speedbar-change-initial-expansion-list "vhdl project")))
14743 ;; menu
14744 (unless vhdl-speedbar-menu-items
14745 (setq
14746 vhdl-speedbar-menu-items
14747 `(["Edit" speedbar-edit-line t]
14748 ["Expand" speedbar-expand-line
14749 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14750 ["Contract" vhdl-speedbar-contract-level t]
14751 ["Expand All" vhdl-speedbar-expand-all t]
14752 ["Contract All" vhdl-speedbar-contract-all t]
14753 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14754 (while (<= key 9)
14755 (setq menu-list
14756 (cons `[,(if (= key 0) "All" (int-to-string key))
14757 (vhdl-speedbar-set-depth ,key)
14758 :style radio
14759 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14760 :keys ,(int-to-string key)]
14761 menu-list))
14762 (setq key (1+ key)))
14763 (nreverse menu-list))
14764 "--"
14765 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14766 (or (vhdl-speedbar-check-unit 'entity)
14767 (vhdl-speedbar-check-unit 'subprogram))]
14768 ["Place Component" vhdl-speedbar-place-component
14769 (vhdl-speedbar-check-unit 'entity)]
14770 ["Generate Configuration" vhdl-speedbar-configuration
14771 (vhdl-speedbar-check-unit 'architecture)]
14772 ["Select as MRA" vhdl-speedbar-select-mra
14773 (vhdl-speedbar-check-unit 'architecture)]
14774 ["Make" vhdl-speedbar-make-design
14775 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14776 ["Generate Makefile" vhdl-speedbar-generate-makefile
14777 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14778 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14779 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14780 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14781 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14782 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14783 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14784 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14785 ;; hook-ups
14786 (speedbar-add-expansion-list
14787 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14788 vhdl-speedbar-display-directory))
14789 (speedbar-add-expansion-list
14790 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14791 vhdl-speedbar-display-projects))
14792 (setq speedbar-stealthy-function-list
14793 (append
14794 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14795 ("vhdl project" vhdl-speedbar-update-current-project
14796 vhdl-speedbar-update-current-unit))
14797 speedbar-stealthy-function-list))
14798 (when (eq vhdl-speedbar-display-mode 'directory)
14799 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14800 (when (eq vhdl-speedbar-display-mode 'project)
14801 (setq speedbar-initial-expansion-list-name "vhdl project"))
14802 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14803
14804 (defun vhdl-speedbar (&optional arg)
14805 "Open/close speedbar."
14806 (interactive)
14807 (if (not (fboundp 'speedbar))
14808 (error "WARNING: Speedbar is not available or not installed")
14809 (condition-case ()
14810 (speedbar-frame-mode arg)
14811 (error (error "WARNING: An error occurred while opening speedbar")))))
14812
14813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14814 ;; Display functions
14815
14816 (defvar vhdl-speedbar-last-selected-project nil
14817 "Name of last selected project.")
14818
14819 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14820 ;;; (defmacro speedbar-with-writable (&rest forms)
14821 ;;; "Allow the buffer to be writable and evaluate FORMS."
14822 ;;; (list 'let '((inhibit-read-only t))
14823 ;;; (cons 'progn forms)))
14824 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14825
14826 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14827 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14828 (declare-function speedbar-file-lists "speedbar" (directory))
14829
14830 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14831 "Display directory and hierarchy information in speedbar."
14832 (setq vhdl-speedbar-show-projects nil)
14833 (setq speedbar-ignored-directory-regexp
14834 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14835 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14836 (setq speedbar-last-selected-file nil)
14837 (speedbar-with-writable
14838 (condition-case nil
14839 (progn
14840 ;; insert directory path
14841 (speedbar-directory-buttons directory depth)
14842 ;; insert subdirectories
14843 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14844 ;; scan and insert hierarchy of current directory
14845 (vhdl-speedbar-insert-dir-hierarchy directory depth
14846 speedbar-power-click)
14847 ;; expand subdirectories
14848 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14849 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14850
14851 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14852 "Display projects and hierarchy information in speedbar."
14853 (setq vhdl-speedbar-show-projects t)
14854 (setq speedbar-ignored-directory-regexp ".")
14855 (setq speedbar-last-selected-file nil)
14856 (setq vhdl-speedbar-last-selected-project nil)
14857 (speedbar-with-writable
14858 (condition-case nil
14859 ;; insert projects
14860 (vhdl-speedbar-insert-projects)
14861 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14862 (setq speedbar-full-text-cache nil)) ; prevent caching
14863
14864 (declare-function speedbar-make-tag-line "speedbar"
14865 (type char func data tag tfunc tdata tface depth))
14866
14867 (defun vhdl-speedbar-insert-projects ()
14868 "Insert all projects in speedbar."
14869 (vhdl-speedbar-make-title-line "Projects:")
14870 (let ((project-alist (if vhdl-project-sort
14871 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14872 vhdl-project-alist))
14873 (vhdl-speedbar-update-current-unit nil))
14874 ;; insert projects
14875 (while project-alist
14876 (speedbar-make-tag-line
14877 'angle ?+ 'vhdl-speedbar-expand-project
14878 (caar project-alist) (caar project-alist)
14879 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14880 (setq project-alist (cdr project-alist)))
14881 (setq project-alist vhdl-project-alist)
14882 ;; expand projects
14883 (while project-alist
14884 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14885 (goto-char (point-min))
14886 (when (re-search-forward
14887 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14888 (goto-char (match-end 1))
14889 (speedbar-do-function-pointer)))
14890 (setq project-alist (cdr project-alist)))))
14891
14892 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14893 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14894 otherwise use cached data."
14895 (when (or rescan (and (not (assoc project vhdl-file-alist))
14896 (not (vhdl-load-cache project))))
14897 (vhdl-scan-project-contents project))
14898 ;; insert design hierarchy
14899 (vhdl-speedbar-insert-hierarchy
14900 (vhdl-aget vhdl-entity-alist project)
14901 (vhdl-aget vhdl-config-alist project)
14902 (vhdl-aget vhdl-package-alist project)
14903 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14904 (insert (int-to-string indent) ":\n")
14905 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14906 (put-text-property (1- (point)) (point) 'invisible nil)
14907 ;; expand design units
14908 (vhdl-speedbar-expand-units project))
14909
14910 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14911 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14912 otherwise use cached data."
14913 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14914 (not (vhdl-load-cache directory))))
14915 (vhdl-scan-directory-contents directory))
14916 ;; insert design hierarchy
14917 (vhdl-speedbar-insert-hierarchy
14918 (vhdl-aget vhdl-entity-alist directory)
14919 (vhdl-aget vhdl-config-alist directory)
14920 (vhdl-aget vhdl-package-alist directory)
14921 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14922 ;; expand design units
14923 (vhdl-speedbar-expand-units directory)
14924 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14925
14926 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14927 ent-inst-list depth)
14928 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14929 (if (not (or ent-alist conf-alist pack-alist))
14930 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14931 (let (ent-entry conf-entry pack-entry)
14932 ;; insert entities
14933 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14934 (while ent-alist
14935 (setq ent-entry (car ent-alist))
14936 (speedbar-make-tag-line
14937 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14938 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14939 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14940 'vhdl-speedbar-entity-face depth)
14941 (unless (nth 2 ent-entry)
14942 (end-of-line 0) (insert "!") (forward-char 1))
14943 (unless (member (nth 0 ent-entry) ent-inst-list)
14944 (end-of-line 0) (insert " (top)") (forward-char 1))
14945 (setq ent-alist (cdr ent-alist)))
14946 ;; insert configurations
14947 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14948 (while conf-alist
14949 (setq conf-entry (car conf-alist))
14950 (speedbar-make-tag-line
14951 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14952 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14953 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14954 'vhdl-speedbar-configuration-face depth)
14955 (setq conf-alist (cdr conf-alist)))
14956 ;; insert packages
14957 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14958 (while pack-alist
14959 (setq pack-entry (car pack-alist))
14960 (vhdl-speedbar-make-pack-line
14961 (nth 0 pack-entry) (nth 1 pack-entry)
14962 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14963 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14964 depth)
14965 (setq pack-alist (cdr pack-alist))))))
14966
14967 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14968
14969 (defun vhdl-speedbar-rescan-hierarchy ()
14970 "Rescan hierarchy for the directory or project under the cursor."
14971 (interactive)
14972 (let (key path)
14973 (cond
14974 ;; current project
14975 (vhdl-speedbar-show-projects
14976 (setq key (vhdl-speedbar-line-project))
14977 (vhdl-scan-project-contents key))
14978 ;; top-level directory
14979 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14980 (re-search-forward "[0-9]+:" nil t)
14981 (vhdl-scan-directory-contents
14982 (abbreviate-file-name (speedbar-line-directory))))
14983 ;; current directory
14984 (t (setq path (speedbar-line-directory))
14985 (string-match "^\\(.+[/\\]\\)" path)
14986 (vhdl-scan-directory-contents
14987 (abbreviate-file-name (match-string 1 path)))))
14988 (vhdl-speedbar-refresh key)))
14989
14990 (declare-function speedbar-goto-this-file "speedbar" (file))
14991
14992 (defun vhdl-speedbar-expand-dirs (directory)
14993 "Expand subdirectories in DIRECTORY according to
14994 `speedbar-shown-directories'."
14995 ;; (nicked from `speedbar-default-directory-list')
14996 (let ((sf (cdr (reverse speedbar-shown-directories)))
14997 (vhdl-speedbar-update-current-unit nil))
14998 (setq speedbar-shown-directories
14999 (list (expand-file-name default-directory)))
15000 (while sf
15001 (when (speedbar-goto-this-file (car sf))
15002 (beginning-of-line)
15003 (when (looking-at "[0-9]+:\\s-*<")
15004 (goto-char (match-end 0))
15005 (speedbar-do-function-pointer)))
15006 (setq sf (cdr sf))))
15007 (vhdl-speedbar-update-current-unit nil t))
15008
15009 (defun vhdl-speedbar-expand-units (key)
15010 "Expand design units in directory/project KEY according to
15011 `vhdl-speedbar-shown-unit-alist'."
15012 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15013 (vhdl-speedbar-update-current-unit nil)
15014 vhdl-updated-project-list)
15015 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15016 (vhdl-prepare-search-1
15017 (while unit-alist ; expand units
15018 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
15019 (beginning-of-line)
15020 (let ((arch-alist (nth 1 (car unit-alist)))
15021 position)
15022 (when (looking-at "^[0-9]+:\\s-*\\[")
15023 (goto-char (match-end 0))
15024 (setq position (point))
15025 (speedbar-do-function-pointer)
15026 (select-frame speedbar-frame)
15027 (while arch-alist ; expand architectures
15028 (goto-char position)
15029 (when (re-search-forward
15030 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
15031 (car arch-alist) "\\>\\)") nil t)
15032 (beginning-of-line)
15033 (when (looking-at "^[0-9]+:\\s-*{")
15034 (goto-char (match-end 0))
15035 (speedbar-do-function-pointer)
15036 (select-frame speedbar-frame)))
15037 (setq arch-alist (cdr arch-alist))))
15038 (setq unit-alist (cdr unit-alist))))))
15039 (vhdl-speedbar-update-current-unit nil t))
15040
15041 (declare-function speedbar-center-buffer-smartly "speedbar" ())
15042
15043 (defun vhdl-speedbar-contract-level ()
15044 "Contract current level in current directory/project."
15045 (interactive)
15046 (when (or (save-excursion
15047 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
15048 (and (save-excursion
15049 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
15050 (re-search-backward
15051 (format "^[0-%d]:\\s-*[[{<]-"
15052 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
15053 (goto-char (match-end 0))
15054 (speedbar-do-function-pointer)
15055 (speedbar-center-buffer-smartly)))
15056
15057 (defun vhdl-speedbar-contract-all ()
15058 "Contract all expanded design units in current directory/project."
15059 (interactive)
15060 (if (and vhdl-speedbar-show-projects
15061 (save-excursion (beginning-of-line) (looking-at "^0:")))
15062 (progn (setq vhdl-speedbar-shown-project-list nil)
15063 (vhdl-speedbar-refresh))
15064 (let ((key (vhdl-speedbar-line-key)))
15065 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15066 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
15067 (when (memq 'display vhdl-speedbar-save-cache)
15068 (add-to-list 'vhdl-updated-project-list key)))))
15069
15070 (defun vhdl-speedbar-expand-all ()
15071 "Expand all design units in current directory/project."
15072 (interactive)
15073 (let* ((key (vhdl-speedbar-line-key))
15074 (ent-alist (vhdl-aget vhdl-entity-alist key))
15075 (conf-alist (vhdl-aget vhdl-config-alist key))
15076 (pack-alist (vhdl-aget vhdl-package-alist key))
15077 arch-alist unit-alist subunit-alist)
15078 (add-to-list 'vhdl-speedbar-shown-project-list key)
15079 (while ent-alist
15080 (setq arch-alist (nth 4 (car ent-alist)))
15081 (setq subunit-alist nil)
15082 (while arch-alist
15083 (push (caar arch-alist) subunit-alist)
15084 (setq arch-alist (cdr arch-alist)))
15085 (push (list (caar ent-alist) subunit-alist) unit-alist)
15086 (setq ent-alist (cdr ent-alist)))
15087 (while conf-alist
15088 (push (list (caar conf-alist)) unit-alist)
15089 (setq conf-alist (cdr conf-alist)))
15090 (while pack-alist
15091 (push (list (caar pack-alist)) unit-alist)
15092 (setq pack-alist (cdr pack-alist)))
15093 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15094 (vhdl-speedbar-refresh)
15095 (when (memq 'display vhdl-speedbar-save-cache)
15096 (add-to-list 'vhdl-updated-project-list key))))
15097
15098 (declare-function speedbar-change-expand-button-char "speedbar" (char))
15099 (declare-function speedbar-delete-subblock "speedbar" (indent))
15100
15101 (defun vhdl-speedbar-expand-project (text token indent)
15102 "Expand/contract the project under the cursor."
15103 (cond
15104 ((string-match "+" text) ; expand project
15105 (speedbar-change-expand-button-char ?-)
15106 (unless (member token vhdl-speedbar-shown-project-list)
15107 (setq vhdl-speedbar-shown-project-list
15108 (cons token vhdl-speedbar-shown-project-list)))
15109 (speedbar-with-writable
15110 (save-excursion
15111 (end-of-line) (forward-char 1)
15112 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
15113 speedbar-power-click))))
15114 ((string-match "-" text) ; contract project
15115 (speedbar-change-expand-button-char ?+)
15116 (setq vhdl-speedbar-shown-project-list
15117 (delete token vhdl-speedbar-shown-project-list))
15118 (speedbar-delete-subblock indent))
15119 (t (error "Nothing to display")))
15120 (when (equal (selected-frame) speedbar-frame)
15121 (speedbar-center-buffer-smartly)))
15122
15123 (defun vhdl-speedbar-expand-entity (text token indent)
15124 "Expand/contract the entity under the cursor."
15125 (cond
15126 ((string-match "+" text) ; expand entity
15127 (let* ((key (vhdl-speedbar-line-key indent))
15128 (ent-alist (vhdl-aget vhdl-entity-alist key))
15129 (ent-entry (vhdl-aget ent-alist token))
15130 (arch-alist (nth 3 ent-entry))
15131 (inst-alist (vhdl-get-instantiations token indent))
15132 (subpack-alist (nth 5 ent-entry))
15133 (multiple-arch (> (length arch-alist) 1))
15134 arch-entry inst-entry)
15135 (if (not (or arch-alist inst-alist subpack-alist))
15136 (speedbar-change-expand-button-char ??)
15137 (speedbar-change-expand-button-char ?-)
15138 ;; add entity to `vhdl-speedbar-shown-unit-alist'
15139 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15140 (vhdl-aput 'unit-alist token nil)
15141 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15142 (speedbar-with-writable
15143 (save-excursion
15144 (end-of-line) (forward-char 1)
15145 ;; insert architectures
15146 (when arch-alist
15147 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15148 (while arch-alist
15149 (setq arch-entry (car arch-alist))
15150 (speedbar-make-tag-line
15151 'curly ?+ 'vhdl-speedbar-expand-architecture
15152 (cons token (nth 0 arch-entry))
15153 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15154 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15155 'vhdl-speedbar-architecture-face (1+ indent))
15156 (when (and multiple-arch
15157 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15158 (end-of-line 0) (insert " (mra)") (forward-char 1))
15159 (setq arch-alist (cdr arch-alist)))
15160 ;; insert instantiations
15161 (when inst-alist
15162 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15163 (while inst-alist
15164 (setq inst-entry (car inst-alist))
15165 (vhdl-speedbar-make-inst-line
15166 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15167 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15168 nil nil nil (1+ indent) 0 " in ")
15169 (setq inst-alist (cdr inst-alist)))
15170 ;; insert required packages
15171 (vhdl-speedbar-insert-subpackages
15172 subpack-alist (1+ indent) indent)))
15173 (when (memq 'display vhdl-speedbar-save-cache)
15174 (add-to-list 'vhdl-updated-project-list key))
15175 (vhdl-speedbar-update-current-unit t t))))
15176 ((string-match "-" text) ; contract entity
15177 (speedbar-change-expand-button-char ?+)
15178 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15179 (let* ((key (vhdl-speedbar-line-key indent))
15180 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15181 (vhdl-adelete 'unit-alist token)
15182 (if unit-alist
15183 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15184 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15185 (speedbar-delete-subblock indent)
15186 (when (memq 'display vhdl-speedbar-save-cache)
15187 (add-to-list 'vhdl-updated-project-list key))))
15188 (t (error "Nothing to display")))
15189 (when (equal (selected-frame) speedbar-frame)
15190 (speedbar-center-buffer-smartly)))
15191
15192 (defun vhdl-speedbar-expand-architecture (text token indent)
15193 "Expand/contract the architecture under the cursor."
15194 (cond
15195 ((string-match "+" text) ; expand architecture
15196 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15197 (ent-alist (vhdl-aget vhdl-entity-alist key))
15198 (conf-alist (vhdl-aget vhdl-config-alist key))
15199 (hier-alist (vhdl-get-hierarchy
15200 ent-alist conf-alist (car token) (cdr token) nil nil
15201 0 (1- indent)))
15202 (ent-entry (vhdl-aget ent-alist (car token)))
15203 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15204 (subpack-alist (nth 4 arch-entry))
15205 entry)
15206 (if (not (or hier-alist subpack-alist))
15207 (speedbar-change-expand-button-char ??)
15208 (speedbar-change-expand-button-char ?-)
15209 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15210 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15211 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15212 (vhdl-aput 'unit-alist (car token)
15213 (list (cons (cdr token) arch-alist)))
15214 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15215 (speedbar-with-writable
15216 (save-excursion
15217 (end-of-line) (forward-char 1)
15218 ;; insert instance hierarchy
15219 (when hier-alist
15220 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15221 (1+ indent)))
15222 (while hier-alist
15223 (setq entry (car hier-alist))
15224 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15225 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15226 (vhdl-speedbar-make-inst-line
15227 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15228 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15229 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15230 (setq hier-alist (cdr hier-alist)))
15231 ;; insert required packages
15232 (vhdl-speedbar-insert-subpackages
15233 subpack-alist (1+ indent) (1- indent))))
15234 (when (memq 'display vhdl-speedbar-save-cache)
15235 (add-to-list 'vhdl-updated-project-list key))
15236 (vhdl-speedbar-update-current-unit t t))))
15237 ((string-match "-" text) ; contract architecture
15238 (speedbar-change-expand-button-char ?+)
15239 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15240 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15241 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15242 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15243 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15244 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15245 (speedbar-delete-subblock indent)
15246 (when (memq 'display vhdl-speedbar-save-cache)
15247 (add-to-list 'vhdl-updated-project-list key))))
15248 (t (error "Nothing to display")))
15249 (when (equal (selected-frame) speedbar-frame)
15250 (speedbar-center-buffer-smartly)))
15251
15252 (defun vhdl-speedbar-expand-config (text token indent)
15253 "Expand/contract the configuration under the cursor."
15254 (cond
15255 ((string-match "+" text) ; expand configuration
15256 (let* ((key (vhdl-speedbar-line-key indent))
15257 (conf-alist (vhdl-aget vhdl-config-alist key))
15258 (conf-entry (vhdl-aget conf-alist token))
15259 (ent-alist (vhdl-aget vhdl-entity-alist key))
15260 (hier-alist (vhdl-get-hierarchy
15261 ent-alist conf-alist (nth 3 conf-entry)
15262 (nth 4 conf-entry) token (nth 5 conf-entry)
15263 0 indent t))
15264 (subpack-alist (nth 6 conf-entry))
15265 entry)
15266 (if (not (or hier-alist subpack-alist))
15267 (speedbar-change-expand-button-char ??)
15268 (speedbar-change-expand-button-char ?-)
15269 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15270 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15271 (vhdl-aput 'unit-alist token nil)
15272 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15273 (speedbar-with-writable
15274 (save-excursion
15275 (end-of-line) (forward-char 1)
15276 ;; insert instance hierarchy
15277 (when hier-alist
15278 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15279 (while hier-alist
15280 (setq entry (car hier-alist))
15281 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15282 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15283 (vhdl-speedbar-make-inst-line
15284 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15285 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15286 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15287 (setq hier-alist (cdr hier-alist)))
15288 ;; insert required packages
15289 (vhdl-speedbar-insert-subpackages
15290 subpack-alist (1+ indent) indent)))
15291 (when (memq 'display vhdl-speedbar-save-cache)
15292 (add-to-list 'vhdl-updated-project-list key))
15293 (vhdl-speedbar-update-current-unit t t))))
15294 ((string-match "-" text) ; contract configuration
15295 (speedbar-change-expand-button-char ?+)
15296 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15297 (let* ((key (vhdl-speedbar-line-key indent))
15298 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15299 (vhdl-adelete 'unit-alist token)
15300 (if unit-alist
15301 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15302 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15303 (speedbar-delete-subblock indent)
15304 (when (memq 'display vhdl-speedbar-save-cache)
15305 (add-to-list 'vhdl-updated-project-list key))))
15306 (t (error "Nothing to display")))
15307 (when (equal (selected-frame) speedbar-frame)
15308 (speedbar-center-buffer-smartly)))
15309
15310 (defun vhdl-speedbar-expand-package (text token indent)
15311 "Expand/contract the package under the cursor."
15312 (cond
15313 ((string-match "+" text) ; expand package
15314 (let* ((key (vhdl-speedbar-line-key indent))
15315 (pack-alist (vhdl-aget vhdl-package-alist key))
15316 (pack-entry (vhdl-aget pack-alist token))
15317 (comp-alist (nth 3 pack-entry))
15318 (func-alist (nth 4 pack-entry))
15319 (func-body-alist (nth 8 pack-entry))
15320 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15321 comp-entry func-entry func-body-entry)
15322 (if (not (or comp-alist func-alist subpack-alist))
15323 (speedbar-change-expand-button-char ??)
15324 (speedbar-change-expand-button-char ?-)
15325 ;; add package to `vhdl-speedbar-shown-unit-alist'
15326 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15327 (vhdl-aput 'unit-alist token nil)
15328 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15329 (speedbar-with-writable
15330 (save-excursion
15331 (end-of-line) (forward-char 1)
15332 ;; insert components
15333 (when comp-alist
15334 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15335 (while comp-alist
15336 (setq comp-entry (car comp-alist))
15337 (speedbar-make-tag-line
15338 nil nil nil
15339 (cons token (nth 0 comp-entry))
15340 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15341 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15342 'vhdl-speedbar-entity-face (1+ indent))
15343 (setq comp-alist (cdr comp-alist)))
15344 ;; insert subprograms
15345 (when func-alist
15346 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15347 (while func-alist
15348 (setq func-entry (car func-alist)
15349 func-body-entry (vhdl-aget func-body-alist
15350 (car func-entry)))
15351 (when (nth 2 func-entry)
15352 (vhdl-speedbar-make-subprogram-line
15353 (nth 1 func-entry)
15354 (cons (nth 2 func-entry) (nth 3 func-entry))
15355 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15356 (1+ indent)))
15357 (setq func-alist (cdr func-alist)))
15358 ;; insert required packages
15359 (vhdl-speedbar-insert-subpackages
15360 subpack-alist (1+ indent) indent)))
15361 (when (memq 'display vhdl-speedbar-save-cache)
15362 (add-to-list 'vhdl-updated-project-list key))
15363 (vhdl-speedbar-update-current-unit t t))))
15364 ((string-match "-" text) ; contract package
15365 (speedbar-change-expand-button-char ?+)
15366 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15367 (let* ((key (vhdl-speedbar-line-key indent))
15368 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15369 (vhdl-adelete 'unit-alist token)
15370 (if unit-alist
15371 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15372 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15373 (speedbar-delete-subblock indent)
15374 (when (memq 'display vhdl-speedbar-save-cache)
15375 (add-to-list 'vhdl-updated-project-list key))))
15376 (t (error "Nothing to display")))
15377 (when (equal (selected-frame) speedbar-frame)
15378 (speedbar-center-buffer-smartly)))
15379
15380 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15381 "Insert required packages."
15382 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15383 (vhdl-speedbar-line-key dir-indent)))
15384 pack-key lib-name pack-entry)
15385 (when subpack-alist
15386 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15387 (while subpack-alist
15388 (setq pack-key (cdar subpack-alist)
15389 lib-name (caar subpack-alist))
15390 (setq pack-entry (vhdl-aget pack-alist pack-key))
15391 (vhdl-speedbar-make-subpack-line
15392 (or (nth 0 pack-entry) pack-key) lib-name
15393 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15394 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15395 (setq subpack-alist (cdr subpack-alist)))))
15396
15397 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15398 ;; Display help functions
15399
15400 (defvar vhdl-speedbar-update-current-unit t
15401 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15402
15403 (defun vhdl-speedbar-update-current-project ()
15404 "Highlight project that is currently active."
15405 (when (and vhdl-speedbar-show-projects
15406 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15407 (and (boundp 'speedbar-frame)
15408 (frame-live-p speedbar-frame)))
15409 (let ((last-frame (selected-frame))
15410 (project-alist vhdl-project-alist)
15411 pos)
15412 (select-frame speedbar-frame)
15413 (speedbar-with-writable
15414 (save-excursion
15415 (while project-alist
15416 (goto-char (point-min))
15417 (when (re-search-forward
15418 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15419 (put-text-property (match-beginning 1) (match-end 1) 'face
15420 (if (equal (caar project-alist) vhdl-project)
15421 'speedbar-selected-face
15422 'speedbar-directory-face))
15423 (when (equal (caar project-alist) vhdl-project)
15424 (setq pos (1- (match-beginning 1)))))
15425 (setq project-alist (cdr project-alist))))
15426 (when pos (goto-char pos)))
15427 (select-frame last-frame)
15428 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15429 t)
15430
15431 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15432
15433 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15434 "Highlight all design units that are contained in the current file.
15435 NO-POSITION non-nil means do not re-position cursor."
15436 (let ((last-frame (selected-frame))
15437 (project-list vhdl-speedbar-shown-project-list)
15438 file-alist pos file-name)
15439 ;; get current file name
15440 (if (fboundp 'speedbar-select-attached-frame)
15441 (speedbar-select-attached-frame)
15442 (select-frame speedbar-attached-frame))
15443 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15444 (when (and vhdl-speedbar-update-current-unit
15445 (or always (not (equal file-name speedbar-last-selected-file))))
15446 (if vhdl-speedbar-show-projects
15447 (while project-list
15448 (setq file-alist (append file-alist
15449 (vhdl-aget vhdl-file-alist
15450 (car project-list))))
15451 (setq project-list (cdr project-list)))
15452 (setq file-alist
15453 (vhdl-aget vhdl-file-alist
15454 (abbreviate-file-name default-directory))))
15455 (select-frame speedbar-frame)
15456 (set-buffer speedbar-buffer)
15457 (speedbar-with-writable
15458 (vhdl-prepare-search-1
15459 (save-excursion
15460 ;; unhighlight last units
15461 (let* ((file-entry (vhdl-aget file-alist
15462 speedbar-last-selected-file)))
15463 (vhdl-speedbar-update-units
15464 "\\[.] " (nth 0 file-entry)
15465 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15466 (vhdl-speedbar-update-units
15467 "{.} " (nth 1 file-entry)
15468 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15469 (vhdl-speedbar-update-units
15470 "\\[.] " (nth 3 file-entry)
15471 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15472 (vhdl-speedbar-update-units
15473 "[]>] " (nth 4 file-entry)
15474 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15475 (vhdl-speedbar-update-units
15476 "\\[.].+(" '("body")
15477 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15478 (vhdl-speedbar-update-units
15479 "> " (nth 6 file-entry)
15480 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15481 ;; highlight current units
15482 (let* ((file-entry (vhdl-aget file-alist file-name)))
15483 (setq
15484 pos (vhdl-speedbar-update-units
15485 "\\[.] " (nth 0 file-entry)
15486 file-name 'vhdl-speedbar-entity-selected-face pos)
15487 pos (vhdl-speedbar-update-units
15488 "{.} " (nth 1 file-entry)
15489 file-name 'vhdl-speedbar-architecture-selected-face pos)
15490 pos (vhdl-speedbar-update-units
15491 "\\[.] " (nth 3 file-entry)
15492 file-name 'vhdl-speedbar-configuration-selected-face pos)
15493 pos (vhdl-speedbar-update-units
15494 "[]>] " (nth 4 file-entry)
15495 file-name 'vhdl-speedbar-package-selected-face pos)
15496 pos (vhdl-speedbar-update-units
15497 "\\[.].+(" '("body")
15498 file-name 'vhdl-speedbar-package-selected-face pos)
15499 pos (vhdl-speedbar-update-units
15500 "> " (nth 6 file-entry)
15501 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15502 ;; move speedbar so the first highlighted unit is visible
15503 (when (and pos (not no-position))
15504 (goto-char pos)
15505 (speedbar-center-buffer-smartly)
15506 (speedbar-position-cursor-on-line))
15507 (setq speedbar-last-selected-file file-name))
15508 (select-frame last-frame)
15509 t))
15510
15511 (defun vhdl-speedbar-update-units (text unit-list file-name face
15512 &optional pos)
15513 "Help function to highlight design units."
15514 (while unit-list
15515 (goto-char (point-min))
15516 (while (re-search-forward
15517 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15518 (when (equal file-name (car (get-text-property
15519 (match-beginning 1) 'speedbar-token)))
15520 (setq pos (or pos (point-marker)))
15521 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15522 (setq unit-list (cdr unit-list)))
15523 pos)
15524
15525 (declare-function speedbar-make-button "speedbar"
15526 (start end face mouse function &optional token))
15527
15528 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15529 ent-name ent-file-marker
15530 arch-name arch-file-marker
15531 conf-name conf-file-marker
15532 lib-name depth offset delimiter)
15533 "Insert instantiation entry."
15534 (let ((start (point))
15535 visible-start)
15536 (insert (int-to-string depth) ":")
15537 (put-text-property start (point) 'invisible t)
15538 (setq visible-start (point))
15539 (insert-char ? (* depth speedbar-indentation-width))
15540 (while (> offset 0)
15541 (insert "|")
15542 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15543 (setq offset (1- offset)))
15544 (put-text-property visible-start (point) 'invisible nil)
15545 (setq start (point))
15546 (insert ">")
15547 (speedbar-make-button start (point) nil nil nil)
15548 (setq visible-start (point))
15549 (insert " ")
15550 (setq start (point))
15551 (if (not inst-name)
15552 (insert "(top)")
15553 (insert inst-name)
15554 (speedbar-make-button
15555 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15556 'vhdl-speedbar-find-file inst-file-marker))
15557 (insert delimiter)
15558 (when ent-name
15559 (setq start (point))
15560 (insert ent-name)
15561 (speedbar-make-button
15562 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15563 'vhdl-speedbar-find-file ent-file-marker)
15564 (when arch-name
15565 (insert " (")
15566 (setq start (point))
15567 (insert arch-name)
15568 (speedbar-make-button
15569 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15570 'vhdl-speedbar-find-file arch-file-marker)
15571 (insert ")"))
15572 (when conf-name
15573 (insert " (")
15574 (setq start (point))
15575 (insert conf-name)
15576 (speedbar-make-button
15577 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15578 'vhdl-speedbar-find-file conf-file-marker)
15579 (insert ")")))
15580 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15581 (setq start (point))
15582 (insert " (" lib-name ")")
15583 (put-text-property (+ 2 start) (1- (point)) 'face
15584 'vhdl-speedbar-library-face))
15585 (insert-char ?\n 1)
15586 (put-text-property visible-start (point) 'invisible nil)))
15587
15588 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15589 body-file-marker depth)
15590 "Insert package entry."
15591 (let ((start (point))
15592 visible-start)
15593 (insert (int-to-string depth) ":")
15594 (put-text-property start (point) 'invisible t)
15595 (setq visible-start (point))
15596 (insert-char ? (* depth speedbar-indentation-width))
15597 (put-text-property visible-start (point) 'invisible nil)
15598 (setq start (point))
15599 (insert "[+]")
15600 (speedbar-make-button
15601 start (point) 'speedbar-button-face 'speedbar-highlight-face
15602 'vhdl-speedbar-expand-package pack-key)
15603 (setq visible-start (point))
15604 (insert-char ? 1 nil)
15605 (setq start (point))
15606 (insert pack-name)
15607 (speedbar-make-button
15608 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15609 'vhdl-speedbar-find-file pack-file-marker)
15610 (unless (car pack-file-marker)
15611 (insert "!"))
15612 (when (car body-file-marker)
15613 (insert " (")
15614 (setq start (point))
15615 (insert "body")
15616 (speedbar-make-button
15617 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15618 'vhdl-speedbar-find-file body-file-marker)
15619 (insert ")"))
15620 (insert-char ?\n 1)
15621 (put-text-property visible-start (point) 'invisible nil)))
15622
15623 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15624 pack-body-file-marker depth)
15625 "Insert used package entry."
15626 (let ((start (point))
15627 visible-start)
15628 (insert (int-to-string depth) ":")
15629 (put-text-property start (point) 'invisible t)
15630 (setq visible-start (point))
15631 (insert-char ? (* depth speedbar-indentation-width))
15632 (put-text-property visible-start (point) 'invisible nil)
15633 (setq start (point))
15634 (insert ">")
15635 (speedbar-make-button start (point) nil nil nil)
15636 (setq visible-start (point))
15637 (insert " ")
15638 (setq start (point))
15639 (insert pack-name)
15640 (speedbar-make-button
15641 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15642 'vhdl-speedbar-find-file pack-file-marker)
15643 (when (car pack-body-file-marker)
15644 (insert " (")
15645 (setq start (point))
15646 (insert "body")
15647 (speedbar-make-button
15648 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15649 'vhdl-speedbar-find-file pack-body-file-marker)
15650 (insert ")"))
15651 (setq start (point))
15652 (insert " (" lib-name ")")
15653 (put-text-property (+ 2 start) (1- (point)) 'face
15654 'vhdl-speedbar-library-face)
15655 (insert-char ?\n 1)
15656 (put-text-property visible-start (point) 'invisible nil)))
15657
15658 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15659 func-body-file-marker
15660 depth)
15661 "Insert subprogram entry."
15662 (let ((start (point))
15663 visible-start)
15664 (insert (int-to-string depth) ":")
15665 (put-text-property start (point) 'invisible t)
15666 (setq visible-start (point))
15667 (insert-char ? (* depth speedbar-indentation-width))
15668 (put-text-property visible-start (point) 'invisible nil)
15669 (setq start (point))
15670 (insert ">")
15671 (speedbar-make-button start (point) nil nil nil)
15672 (setq visible-start (point))
15673 (insert " ")
15674 (setq start (point))
15675 (insert func-name)
15676 (speedbar-make-button
15677 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15678 'vhdl-speedbar-find-file func-file-marker)
15679 (when (car func-body-file-marker)
15680 (insert " (")
15681 (setq start (point))
15682 (insert "body")
15683 (speedbar-make-button
15684 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15685 'vhdl-speedbar-find-file func-body-file-marker)
15686 (insert ")"))
15687 (insert-char ?\n 1)
15688 (put-text-property visible-start (point) 'invisible nil)))
15689
15690 (defun vhdl-speedbar-make-title-line (text &optional depth)
15691 "Insert design unit title entry."
15692 (let ((start (point))
15693 visible-start)
15694 (when depth
15695 (insert (int-to-string depth) ":")
15696 (put-text-property start (point) 'invisible t))
15697 (setq visible-start (point))
15698 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15699 (setq start (point))
15700 (insert text)
15701 (speedbar-make-button start (point) nil nil nil nil)
15702 (insert-char ?\n 1)
15703 (put-text-property visible-start (point) 'invisible nil)))
15704
15705 (defun vhdl-speedbar-insert-dirs (files level)
15706 "Insert subdirectories."
15707 (let ((dirs (car files)))
15708 (while dirs
15709 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15710 (car dirs) 'speedbar-dir-follow nil
15711 'speedbar-directory-face level)
15712 (setq dirs (cdr dirs)))))
15713
15714 (declare-function speedbar-reset-scanners "speedbar" ())
15715
15716 (defun vhdl-speedbar-dired (text token indent)
15717 "Speedbar click handler for directory expand button in hierarchy mode."
15718 (cond ((string-match "+" text) ; we have to expand this dir
15719 (setq speedbar-shown-directories
15720 (cons (expand-file-name
15721 (concat (speedbar-line-directory indent) token "/"))
15722 speedbar-shown-directories))
15723 (speedbar-change-expand-button-char ?-)
15724 (speedbar-reset-scanners)
15725 (speedbar-with-writable
15726 (save-excursion
15727 (end-of-line) (forward-char 1)
15728 (vhdl-speedbar-insert-dirs
15729 (speedbar-file-lists
15730 (concat (speedbar-line-directory indent) token "/"))
15731 (1+ indent))
15732 (speedbar-reset-scanners)
15733 (vhdl-speedbar-insert-dir-hierarchy
15734 (abbreviate-file-name
15735 (concat (speedbar-line-directory indent) token "/"))
15736 (1+ indent) speedbar-power-click)))
15737 (vhdl-speedbar-update-current-unit t t))
15738 ((string-match "-" text) ; we have to contract this node
15739 (speedbar-reset-scanners)
15740 (let ((oldl speedbar-shown-directories)
15741 (newl nil)
15742 (td (expand-file-name
15743 (concat (speedbar-line-directory indent) token))))
15744 (while oldl
15745 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15746 (push (car oldl) newl))
15747 (setq oldl (cdr oldl)))
15748 (setq speedbar-shown-directories (nreverse newl)))
15749 (speedbar-change-expand-button-char ?+)
15750 (speedbar-delete-subblock indent))
15751 (t (error "Nothing to display")))
15752 (when (equal (selected-frame) speedbar-frame)
15753 (speedbar-center-buffer-smartly)))
15754
15755 (declare-function speedbar-files-item-info "speedbar" ())
15756
15757 (defun vhdl-speedbar-item-info ()
15758 "Derive and display information about this line item."
15759 (save-excursion
15760 (beginning-of-line)
15761 ;; skip invisible number info
15762 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15763 (cond
15764 ;; project/directory entry
15765 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15766 (if vhdl-speedbar-show-projects
15767 (message "Project \"%s\"" (match-string-no-properties 1))
15768 (speedbar-files-item-info)))
15769 ;; design unit entry
15770 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15771 (goto-char (match-end 1))
15772 (let ((face (get-text-property (point) 'face)))
15773 (message
15774 "%s \"%s\" in \"%s\""
15775 ;; design unit kind
15776 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15777 (eq face 'vhdl-speedbar-entity-selected-face))
15778 (if (equal (match-string 2) ">") "Component" "Entity"))
15779 ((or (eq face 'vhdl-speedbar-architecture-face)
15780 (eq face 'vhdl-speedbar-architecture-selected-face))
15781 "Architecture")
15782 ((or (eq face 'vhdl-speedbar-configuration-face)
15783 (eq face 'vhdl-speedbar-configuration-selected-face))
15784 "Configuration")
15785 ((or (eq face 'vhdl-speedbar-package-face)
15786 (eq face 'vhdl-speedbar-package-selected-face))
15787 "Package")
15788 ((or (eq face 'vhdl-speedbar-instantiation-face)
15789 (eq face 'vhdl-speedbar-instantiation-selected-face))
15790 "Instantiation")
15791 ((eq face 'vhdl-speedbar-subprogram-face)
15792 "Subprogram")
15793 (t ""))
15794 ;; design unit name
15795 (buffer-substring-no-properties
15796 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15797 (match-end 1))
15798 ;; file name
15799 (file-relative-name
15800 (or (car (get-text-property (point) 'speedbar-token))
15801 "?")
15802 (vhdl-default-directory)))))
15803 (t (message "")))))
15804
15805 (declare-function speedbar-line-text "speedbar" (&optional p))
15806
15807 (defun vhdl-speedbar-line-text ()
15808 "Calls `speedbar-line-text' and removes text properties."
15809 (let ((string (speedbar-line-text)))
15810 (set-text-properties 0 (length string) nil string)
15811 string))
15812
15813 (defun vhdl-speedbar-higher-text ()
15814 "Get speedbar-line-text of higher level."
15815 (let (depth string)
15816 (save-excursion
15817 (beginning-of-line)
15818 (looking-at "^\\([0-9]+\\):")
15819 (setq depth (string-to-number (match-string 1)))
15820 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15821 (setq string (match-string 1))
15822 (set-text-properties 0 (length string) nil string)
15823 string))))
15824
15825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15826 ;; Help functions
15827
15828 (defun vhdl-speedbar-line-key (&optional indent)
15829 "Get currently displayed directory of project name."
15830 (if vhdl-speedbar-show-projects
15831 (vhdl-speedbar-line-project)
15832 (abbreviate-file-name
15833 (file-name-as-directory (speedbar-line-directory indent)))))
15834
15835 (defun vhdl-speedbar-line-project (&optional indent)
15836 "Get currently displayed project name."
15837 (and vhdl-speedbar-show-projects
15838 (save-excursion
15839 (end-of-line)
15840 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15841 (match-string-no-properties 1))))
15842
15843 (defun vhdl-add-modified-file ()
15844 "Add file to `vhdl-modified-file-list'."
15845 (when vhdl-file-alist
15846 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15847 nil)
15848
15849 (defun vhdl-resolve-paths (path-list)
15850 "Resolve path wildcards in PATH-LIST."
15851 (let (path-list-1 path-list-2 path-beg path-end dir)
15852 ;; eliminate non-existent directories
15853 (while path-list
15854 (setq dir (car path-list))
15855 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15856 (if (file-directory-p (match-string 2 dir))
15857 (push dir path-list-1)
15858 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15859 (setq path-list (cdr path-list)))
15860 ;; resolve path wildcards
15861 (while path-list-1
15862 (setq dir (car path-list-1))
15863 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15864 (progn
15865 (setq path-beg (match-string 1 dir)
15866 path-end (match-string 5 dir))
15867 (setq path-list-1
15868 (append
15869 (mapcar
15870 (function
15871 (lambda (var) (concat path-beg var path-end)))
15872 (let ((all-list (vhdl-directory-files
15873 (match-string 2 dir) t
15874 (concat "\\<" (wildcard-to-regexp
15875 (match-string 4 dir)))))
15876 dir-list)
15877 (while all-list
15878 (when (file-directory-p (car all-list))
15879 (push (car all-list) dir-list))
15880 (setq all-list (cdr all-list)))
15881 dir-list))
15882 (cdr path-list-1))))
15883 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15884 (when (file-directory-p (match-string 2 dir))
15885 (push dir path-list-2))
15886 (setq path-list-1 (cdr path-list-1))))
15887 (nreverse path-list-2)))
15888
15889 (defun vhdl-speedbar-goto-this-unit (directory unit)
15890 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15891 (let ((dest (point)))
15892 (if (and (if vhdl-speedbar-show-projects
15893 (progn (goto-char (point-min)) t)
15894 (speedbar-goto-this-file directory))
15895 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15896 (progn (speedbar-position-cursor-on-line)
15897 t)
15898 (goto-char dest)
15899 nil)))
15900
15901 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15902 (declare-function speedbar-set-timer "speedbar" (timeout))
15903 ;; speedbar loads dframe at runtime.
15904 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15905
15906 (defun vhdl-speedbar-find-file (text token indent)
15907 "When user clicks on TEXT, load file with name and position in TOKEN.
15908 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15909 is already shown in a buffer."
15910 (if (not (car token))
15911 (error "ERROR: File cannot be found")
15912 (let ((buffer (get-file-buffer (car token))))
15913 (speedbar-find-file-in-frame (car token))
15914 (when (or vhdl-speedbar-jump-to-unit buffer)
15915 (goto-char (point-min))
15916 (forward-line (1- (cdr token)))
15917 (recenter))
15918 (vhdl-speedbar-update-current-unit t t)
15919 (speedbar-set-timer dframe-update-speed)
15920 (dframe-maybee-jump-to-attached-frame))))
15921
15922 (defun vhdl-speedbar-port-copy ()
15923 "Copy the port of the entity/component or subprogram under the cursor."
15924 (interactive)
15925 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15926 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15927 (error "ERROR: No entity/component or subprogram under cursor")
15928 (beginning-of-line)
15929 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15930 (condition-case info
15931 (let ((token (get-text-property
15932 (match-beginning 3) 'speedbar-token)))
15933 (vhdl-visit-file (car token) t
15934 (progn (goto-char (point-min))
15935 (forward-line (1- (cdr token)))
15936 (end-of-line)
15937 (if is-entity
15938 (vhdl-port-copy)
15939 (vhdl-subprog-copy)))))
15940 (error (error "ERROR: %s not scanned successfully\n (%s)"
15941 (if is-entity "Port" "Interface") (cadr info))))
15942 (error "ERROR: No entity/component or subprogram on current line")))))
15943
15944 (defun vhdl-speedbar-place-component ()
15945 "Place the entity/component under the cursor as component."
15946 (interactive)
15947 (if (not (vhdl-speedbar-check-unit 'entity))
15948 (error "ERROR: No entity/component under cursor")
15949 (vhdl-speedbar-port-copy)
15950 (if (fboundp 'speedbar-select-attached-frame)
15951 (speedbar-select-attached-frame)
15952 (select-frame speedbar-attached-frame))
15953 (vhdl-compose-place-component)
15954 (select-frame speedbar-frame)))
15955
15956 (defun vhdl-speedbar-configuration ()
15957 "Generate configuration for the architecture under the cursor."
15958 (interactive)
15959 (if (not (vhdl-speedbar-check-unit 'architecture))
15960 (error "ERROR: No architecture under cursor")
15961 (let ((arch-name (vhdl-speedbar-line-text))
15962 (ent-name (vhdl-speedbar-higher-text)))
15963 (if (fboundp 'speedbar-select-attached-frame)
15964 (speedbar-select-attached-frame)
15965 (select-frame speedbar-attached-frame))
15966 (vhdl-compose-configuration ent-name arch-name))))
15967
15968 (defun vhdl-speedbar-select-mra ()
15969 "Select the architecture under the cursor as MRA."
15970 (interactive)
15971 (if (not (vhdl-speedbar-check-unit 'architecture))
15972 (error "ERROR: No architecture under cursor")
15973 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15974 (ent-key (downcase (vhdl-speedbar-higher-text)))
15975 (ent-alist (vhdl-aget
15976 vhdl-entity-alist
15977 (or (vhdl-project-p)
15978 (abbreviate-file-name default-directory))))
15979 (ent-entry (vhdl-aget ent-alist ent-key)))
15980 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15981 (speedbar-refresh))))
15982
15983 (declare-function speedbar-line-file "speedbar" (&optional p))
15984
15985 (defun vhdl-speedbar-make-design ()
15986 "Make (compile) design unit or directory/project under the cursor."
15987 (interactive)
15988 (if (not (save-excursion (beginning-of-line)
15989 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15990 (error "ERROR: No primary design unit or directory/project under cursor")
15991 (let ((is-unit (match-string 2))
15992 (unit-name (vhdl-speedbar-line-text))
15993 (vhdl-project (vhdl-speedbar-line-project))
15994 (directory (file-name-as-directory
15995 (or (speedbar-line-file) (speedbar-line-directory)))))
15996 (if (fboundp 'speedbar-select-attached-frame)
15997 (speedbar-select-attached-frame)
15998 (select-frame speedbar-attached-frame))
15999 (let ((default-directory directory))
16000 (vhdl-make (and is-unit unit-name))))))
16001
16002 (defun vhdl-speedbar-generate-makefile ()
16003 "Generate Makefile for directory/project under the cursor."
16004 (interactive)
16005 (let ((vhdl-project (vhdl-speedbar-line-project))
16006 (default-directory (file-name-as-directory
16007 (or (speedbar-line-file) (speedbar-line-directory)))))
16008 (vhdl-generate-makefile)))
16009
16010 (defun vhdl-speedbar-check-unit (design-unit)
16011 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
16012 expansion function)."
16013 (save-excursion
16014 (speedbar-position-cursor-on-line)
16015 (cond ((eq design-unit 'entity)
16016 (memq (get-text-property (match-end 0) 'face)
16017 '(vhdl-speedbar-entity-face
16018 vhdl-speedbar-entity-selected-face)))
16019 ((eq design-unit 'architecture)
16020 (memq (get-text-property (match-end 0) 'face)
16021 '(vhdl-speedbar-architecture-face
16022 vhdl-speedbar-architecture-selected-face)))
16023 ((eq design-unit 'subprogram)
16024 (eq (get-text-property (match-end 0) 'face)
16025 'vhdl-speedbar-subprogram-face))
16026 (t nil))))
16027
16028 (defun vhdl-speedbar-set-depth (depth)
16029 "Set hierarchy display depth to DEPTH and refresh speedbar."
16030 (setq vhdl-speedbar-hierarchy-depth depth)
16031 (speedbar-refresh))
16032
16033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16034 ;; Fontification
16035
16036 (defface vhdl-speedbar-entity-face
16037 '((((class color) (background light)) (:foreground "ForestGreen"))
16038 (((class color) (background dark)) (:foreground "PaleGreen")))
16039 "Face used for displaying entity names."
16040 :group 'speedbar-faces)
16041
16042 (defface vhdl-speedbar-architecture-face
16043 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
16044 (((class color) (background light)) (:foreground "Blue"))
16045
16046 (((class color) (background dark)) (:foreground "LightSkyBlue")))
16047 "Face used for displaying architecture names."
16048 :group 'speedbar-faces)
16049
16050 (defface vhdl-speedbar-configuration-face
16051 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
16052 (((class color) (background dark)) (:foreground "Salmon")))
16053 "Face used for displaying configuration names."
16054 :group 'speedbar-faces)
16055
16056 (defface vhdl-speedbar-package-face
16057 '((((class color) (background light)) (:foreground "Grey50"))
16058 (((class color) (background dark)) (:foreground "Grey80")))
16059 "Face used for displaying package names."
16060 :group 'speedbar-faces)
16061
16062 (defface vhdl-speedbar-library-face
16063 '((((class color) (background light)) (:foreground "Purple"))
16064 (((class color) (background dark)) (:foreground "Orchid1")))
16065 "Face used for displaying library names."
16066 :group 'speedbar-faces)
16067
16068 (defface vhdl-speedbar-instantiation-face
16069 '((((class color) (background light)) (:foreground "Brown"))
16070 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
16071 (((class color) (background dark)) (:foreground "Yellow")))
16072 "Face used for displaying instantiation names."
16073 :group 'speedbar-faces)
16074
16075 (defface vhdl-speedbar-subprogram-face
16076 '((((class color) (background light)) (:foreground "Orchid4"))
16077 (((class color) (background dark)) (:foreground "BurlyWood2")))
16078 "Face used for displaying subprogram names."
16079 :group 'speedbar-faces)
16080
16081 (defface vhdl-speedbar-entity-selected-face
16082 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
16083 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
16084 "Face used for displaying entity names."
16085 :group 'speedbar-faces)
16086
16087 (defface vhdl-speedbar-architecture-selected-face
16088 '((((min-colors 88) (class color) (background light)) (:foreground
16089 "Blue1" :underline t))
16090 (((class color) (background light)) (:foreground "Blue" :underline t))
16091 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
16092 "Face used for displaying architecture names."
16093 :group 'speedbar-faces)
16094
16095 (defface vhdl-speedbar-configuration-selected-face
16096 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
16097 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
16098 "Face used for displaying configuration names."
16099 :group 'speedbar-faces)
16100
16101 (defface vhdl-speedbar-package-selected-face
16102 '((((class color) (background light)) (:foreground "Grey50" :underline t))
16103 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
16104 "Face used for displaying package names."
16105 :group 'speedbar-faces)
16106
16107 (defface vhdl-speedbar-instantiation-selected-face
16108 '((((class color) (background light)) (:foreground "Brown" :underline t))
16109 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
16110 "Face used for displaying instantiation names."
16111 :group 'speedbar-faces)
16112
16113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16114 ;; Initialization
16115
16116 ;; add speedbar
16117 (when (fboundp 'speedbar)
16118 (let ((current-frame (selected-frame)))
16119 (condition-case ()
16120 (when (and vhdl-speedbar-auto-open
16121 (not (and (boundp 'speedbar-frame)
16122 (frame-live-p speedbar-frame))))
16123 (speedbar-frame-mode 1))
16124 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
16125 (select-frame current-frame)))
16126
16127 ;; initialize speedbar
16128 (if (not (boundp 'speedbar-frame))
16129 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
16130 (vhdl-speedbar-initialize)
16131 (when speedbar-frame (vhdl-speedbar-refresh)))
16132
16133
16134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16135 ;;; Structural composition
16136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16137
16138 (defun vhdl-get-components-package-name ()
16139 "Return the name of the components package."
16140 (let ((project (vhdl-project-p)))
16141 (if project
16142 (vhdl-replace-string (car vhdl-components-package-name)
16143 (subst-char-in-string ? ?_ project))
16144 (cdr vhdl-components-package-name))))
16145
16146 (defun vhdl-compose-new-component ()
16147 "Create entity and architecture for new component."
16148 (interactive)
16149 (let* ((case-fold-search t)
16150 (ent-name (read-from-minibuffer "entity name: "
16151 nil vhdl-minibuffer-local-map))
16152 (arch-name
16153 (if (equal (cdr vhdl-compose-architecture-name) "")
16154 (read-from-minibuffer "architecture name: "
16155 nil vhdl-minibuffer-local-map)
16156 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16157 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16158 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16159 ;; open entity file
16160 (unless (eq vhdl-compose-create-files 'none)
16161 (setq ent-file-name
16162 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16163 "." (file-name-extension (buffer-file-name))))
16164 (when (and (file-exists-p ent-file-name)
16165 (not (y-or-n-p (concat "File \"" ent-file-name
16166 "\" exists; overwrite? "))))
16167 (error "ERROR: Creating component...aborted"))
16168 (find-file ent-file-name)
16169 (erase-buffer)
16170 (set-buffer-modified-p nil))
16171 ;; insert header
16172 (if vhdl-compose-include-header
16173 (progn (vhdl-template-header)
16174 (setq end-pos (point))
16175 (goto-char (point-max)))
16176 (vhdl-comment-display-line) (insert "\n\n"))
16177 ;; insert library clause
16178 (vhdl-template-package-std-logic-1164)
16179 (when vhdl-use-components-package
16180 (insert "\n")
16181 (vhdl-template-standard-package (vhdl-work-library)
16182 (vhdl-get-components-package-name)))
16183 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16184 ;; insert entity declaration
16185 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16186 (vhdl-insert-keyword " IS\n")
16187 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16188 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16189 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16190 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16191 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16192 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16193 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16194 (vhdl-insert-keyword "END ")
16195 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16196 (insert ent-name ";\n\n")
16197 (vhdl-comment-display-line) (insert "\n")
16198 ;; open architecture file
16199 (if (not (eq vhdl-compose-create-files 'separate))
16200 (insert "\n")
16201 (goto-char (or end-pos (point-min)))
16202 (setq ent-buffer (current-buffer))
16203 (setq arch-file-name
16204 (concat (vhdl-replace-string vhdl-architecture-file-name
16205 (concat ent-name " " arch-name) t)
16206 "." (file-name-extension (buffer-file-name))))
16207 (when (and (file-exists-p arch-file-name)
16208 (not (y-or-n-p (concat "File \"" arch-file-name
16209 "\" exists; overwrite? "))))
16210 (error "ERROR: Creating component...aborted"))
16211 (find-file arch-file-name)
16212 (erase-buffer)
16213 (set-buffer-modified-p nil)
16214 ;; insert header
16215 (if vhdl-compose-include-header
16216 (progn (vhdl-template-header)
16217 (goto-char (point-max)))
16218 (vhdl-comment-display-line) (insert "\n\n")))
16219 ;; insert architecture body
16220 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16221 (vhdl-insert-keyword " OF ") (insert ent-name)
16222 (vhdl-insert-keyword " IS\n\n")
16223 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16224 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16225 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16226 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16227 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16228 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16229 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16230 (vhdl-insert-keyword "BEGIN")
16231 (when vhdl-self-insert-comments
16232 (insert " -- ")
16233 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16234 (insert arch-name))
16235 (insert "\n\n")
16236 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16237 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16238 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16239 (vhdl-insert-keyword "END ")
16240 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16241 (insert arch-name ";\n\n")
16242 ;; insert footer and save
16243 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16244 (vhdl-template-footer)
16245 (vhdl-comment-display-line) (insert "\n"))
16246 (goto-char (or end-pos (point-min)))
16247 (setq arch-buffer (current-buffer))
16248 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16249 (set-buffer arch-buffer) (save-buffer)
16250 (message "%s"
16251 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16252 (and ent-file-name
16253 (format "\n File created: \"%s\"" ent-file-name))
16254 (and arch-file-name
16255 (format "\n File created: \"%s\"" arch-file-name))))))
16256
16257 (defun vhdl-compose-place-component ()
16258 "Place new component by pasting current port as component declaration and
16259 component instantiation."
16260 (interactive)
16261 (if (not vhdl-port-list)
16262 (error "ERROR: No port has been read")
16263 (save-excursion
16264 (vhdl-prepare-search-2
16265 (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)
16266 (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))
16267 (error "ERROR: No architecture found"))
16268 (let* ((ent-name (match-string 1))
16269 (ent-file-name
16270 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16271 "." (file-name-extension (buffer-file-name))))
16272 (orig-buffer (current-buffer)))
16273 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16274 ;; place component declaration
16275 (unless (or vhdl-use-components-package
16276 (vhdl-use-direct-instantiation)
16277 (save-excursion
16278 (re-search-forward
16279 (concat "^\\s-*component\\s-+"
16280 (car vhdl-port-list) "\\>") nil t)))
16281 (re-search-forward "^begin\\>" nil)
16282 (beginning-of-line)
16283 (skip-chars-backward " \t\n\r\f")
16284 (insert "\n\n") (indent-to vhdl-basic-offset)
16285 (vhdl-port-paste-component t))
16286 ;; place component instantiation
16287 (re-search-forward "^end\\>" nil)
16288 (beginning-of-line)
16289 (skip-chars-backward " \t\n\r\f")
16290 (insert "\n\n") (indent-to vhdl-basic-offset)
16291 (vhdl-port-paste-instance nil t t)
16292 ;; place use clause for used packages
16293 (when (nth 3 vhdl-port-list)
16294 ;; open entity file
16295 (when (file-exists-p ent-file-name)
16296 (find-file ent-file-name))
16297 (goto-char (point-min))
16298 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16299 (error "ERROR: Entity not found: \"%s\"" ent-name))
16300 (goto-char (match-beginning 0))
16301 (if (and (save-excursion
16302 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16303 (match-string 1))
16304 (progn (goto-char (match-end 0))
16305 (beginning-of-line 2))
16306 (insert "\n")
16307 (backward-char))
16308 (vhdl-port-paste-context-clause)
16309 (switch-to-buffer orig-buffer))
16310 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16311
16312 (defun vhdl-compose-wire-components ()
16313 "Connect components."
16314 (interactive)
16315 (save-excursion
16316 (vhdl-prepare-search-2
16317 (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)
16318 (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))
16319 (error "ERROR: No architecture found"))
16320 (let* ((ent-name (match-string 1))
16321 (ent-file-name
16322 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16323 "." (file-name-extension (buffer-file-name))))
16324 (arch-decl-pos (point-marker))
16325 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16326 (arch-end-pos (re-search-forward "^end\\>" nil))
16327 (pack-name (vhdl-get-components-package-name))
16328 (pack-file-name
16329 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16330 "." (file-name-extension (buffer-file-name))))
16331 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16332 port-alist generic-alist inst-alist
16333 signal-name signal-entry signal-alist local-list written-list
16334 single-in-list multi-in-list single-out-list multi-out-list
16335 constant-name constant-entry constant-alist single-list multi-list
16336 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16337 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16338 signal-beg-pos signal-pos
16339 constant-temp-pos port-temp-pos signal-temp-pos)
16340 (message "Wiring components...")
16341 ;; process all instances
16342 (goto-char arch-stat-pos)
16343 (while (re-search-forward
16344 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16345 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16346 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16347 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16348 "[ \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)
16349 (setq inst-name (match-string-no-properties 1)
16350 comp-name (match-string-no-properties 4)
16351 comp-ent-name (match-string-no-properties 12)
16352 has-generic (or (match-string 7) (match-string 17)))
16353 ;; get port ...
16354 (if comp-name
16355 ;; ... from component declaration
16356 (vhdl-visit-file
16357 (when vhdl-use-components-package pack-file-name) t
16358 (save-excursion
16359 (goto-char (point-min))
16360 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16361 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16362 (vhdl-port-copy)))
16363 ;; ... from entity declaration (direct instantiation)
16364 (setq comp-ent-file-name
16365 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16366 "." (file-name-extension (buffer-file-name))))
16367 (vhdl-visit-file
16368 comp-ent-file-name t
16369 (save-excursion
16370 (goto-char (point-min))
16371 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16372 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16373 (vhdl-port-copy))))
16374 (vhdl-port-flatten t)
16375 (setq generic-alist (nth 1 vhdl-port-list)
16376 port-alist (nth 2 vhdl-port-list)
16377 vhdl-port-list nil)
16378 (setq constant-alist nil
16379 signal-alist nil)
16380 (when has-generic
16381 ;; process all constants in generic map
16382 (vhdl-forward-syntactic-ws)
16383 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16384 (setq constant-name (match-string-no-properties 3))
16385 (setq constant-entry
16386 (cons constant-name
16387 (if (match-string 1)
16388 (or (vhdl-aget generic-alist (match-string 2))
16389 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16390 (cdar generic-alist))))
16391 (push constant-entry constant-alist)
16392 (setq constant-name (downcase constant-name))
16393 (if (or (member constant-name single-list)
16394 (member constant-name multi-list))
16395 (progn (setq single-list (delete constant-name single-list))
16396 (add-to-list 'multi-list constant-name))
16397 (add-to-list 'single-list constant-name))
16398 (unless (match-string 1)
16399 (setq generic-alist (cdr generic-alist)))
16400 (vhdl-forward-syntactic-ws))
16401 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16402 ;; process all signals in port map
16403 (vhdl-forward-syntactic-ws)
16404 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16405 (setq signal-name (match-string-no-properties 3))
16406 (setq signal-entry
16407 (cons signal-name
16408 (if (match-string 1)
16409 (or (vhdl-aget port-alist (match-string 2))
16410 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16411 (cdar port-alist))))
16412 (push signal-entry signal-alist)
16413 (setq signal-name (downcase signal-name))
16414 (if (equal (upcase (nth 2 signal-entry)) "IN")
16415 ;; input signal
16416 (cond
16417 ((member signal-name local-list)
16418 nil)
16419 ((or (member signal-name single-out-list)
16420 (member signal-name multi-out-list))
16421 (setq single-out-list (delete signal-name single-out-list))
16422 (setq multi-out-list (delete signal-name multi-out-list))
16423 (add-to-list 'local-list signal-name))
16424 ((member signal-name single-in-list)
16425 (setq single-in-list (delete signal-name single-in-list))
16426 (add-to-list 'multi-in-list signal-name))
16427 ((not (member signal-name multi-in-list))
16428 (add-to-list 'single-in-list signal-name)))
16429 ;; output signal
16430 (cond
16431 ((member signal-name local-list)
16432 nil)
16433 ((or (member signal-name single-in-list)
16434 (member signal-name multi-in-list))
16435 (setq single-in-list (delete signal-name single-in-list))
16436 (setq multi-in-list (delete signal-name multi-in-list))
16437 (add-to-list 'local-list signal-name))
16438 ((member signal-name single-out-list)
16439 (setq single-out-list (delete signal-name single-out-list))
16440 (add-to-list 'multi-out-list signal-name))
16441 ((not (member signal-name multi-out-list))
16442 (add-to-list 'single-out-list signal-name))))
16443 (unless (match-string 1)
16444 (setq port-alist (cdr port-alist)))
16445 (vhdl-forward-syntactic-ws))
16446 (push (list inst-name (nreverse constant-alist)
16447 (nreverse signal-alist)) inst-alist))
16448 ;; prepare signal insertion
16449 (vhdl-goto-marker arch-decl-pos)
16450 (forward-line 1)
16451 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16452 (setq signal-pos (point-marker))
16453 (while (progn (vhdl-forward-syntactic-ws)
16454 (looking-at "signal\\>"))
16455 (beginning-of-line 2)
16456 (delete-region signal-pos (point)))
16457 (setq signal-beg-pos signal-pos)
16458 ;; open entity file
16459 (when (file-exists-p ent-file-name)
16460 (find-file ent-file-name))
16461 (goto-char (point-min))
16462 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16463 (error "ERROR: Entity not found: \"%s\"" ent-name))
16464 ;; prepare generic clause insertion
16465 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16466 (match-string 1))
16467 (goto-char (match-beginning 0))
16468 (indent-to vhdl-basic-offset)
16469 (insert "generic ();\n\n")
16470 (backward-char 4))
16471 (backward-char)
16472 (setq generic-pos (point-marker))
16473 (forward-sexp) (end-of-line)
16474 (delete-region generic-pos (point)) (delete-char 1)
16475 (insert "(\n")
16476 (when multi-list
16477 (insert "\n")
16478 (indent-to (* 2 vhdl-basic-offset))
16479 (insert "-- global generics\n"))
16480 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16481 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16482 ;; prepare port clause insertion
16483 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16484 (match-string 1))
16485 (goto-char (match-beginning 0))
16486 (indent-to vhdl-basic-offset)
16487 (insert "port ();\n\n")
16488 (backward-char 4))
16489 (backward-char)
16490 (setq port-in-pos (point-marker))
16491 (forward-sexp) (end-of-line)
16492 (delete-region port-in-pos (point)) (delete-char 1)
16493 (insert "(\n")
16494 (when (or multi-in-list multi-out-list)
16495 (insert "\n")
16496 (indent-to (* 2 vhdl-basic-offset))
16497 (insert "-- global ports\n"))
16498 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16499 port-out-pos (point-marker) port-inst-pos (point-marker)
16500 port-end-pos (point-marker))
16501 ;; insert generics, ports and signals
16502 (setq inst-alist (nreverse inst-alist))
16503 (while inst-alist
16504 (setq inst-name (nth 0 (car inst-alist))
16505 constant-alist (nth 1 (car inst-alist))
16506 signal-alist (nth 2 (car inst-alist))
16507 constant-temp-pos generic-inst-pos
16508 port-temp-pos port-inst-pos
16509 signal-temp-pos signal-pos)
16510 ;; generics
16511 (while constant-alist
16512 (setq constant-name (downcase (caar constant-alist))
16513 constant-entry (car constant-alist))
16514 (unless (string-match "^[0-9]+" constant-name)
16515 (cond ((member constant-name written-list)
16516 nil)
16517 ((member constant-name multi-list)
16518 (vhdl-goto-marker generic-pos)
16519 (setq generic-end-pos
16520 (vhdl-max-marker
16521 generic-end-pos
16522 (vhdl-compose-insert-generic constant-entry)))
16523 (setq generic-pos (point-marker))
16524 (add-to-list 'written-list constant-name))
16525 (t
16526 (vhdl-goto-marker
16527 (vhdl-max-marker generic-inst-pos generic-pos))
16528 (setq generic-end-pos
16529 (vhdl-compose-insert-generic constant-entry))
16530 (setq generic-inst-pos (point-marker))
16531 (add-to-list 'written-list constant-name))))
16532 (setq constant-alist (cdr constant-alist)))
16533 (when (/= constant-temp-pos generic-inst-pos)
16534 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16535 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16536 (insert "-- generics for \"" inst-name "\"\n")
16537 (vhdl-goto-marker generic-inst-pos))
16538 ;; ports and signals
16539 (while signal-alist
16540 (setq signal-name (downcase (caar signal-alist))
16541 signal-entry (car signal-alist))
16542 (cond ((member signal-name written-list)
16543 nil)
16544 ((member signal-name multi-in-list)
16545 (vhdl-goto-marker port-in-pos)
16546 (setq port-end-pos
16547 (vhdl-max-marker
16548 port-end-pos (vhdl-compose-insert-port signal-entry)))
16549 (setq port-in-pos (point-marker))
16550 (add-to-list 'written-list signal-name))
16551 ((member signal-name multi-out-list)
16552 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16553 (setq port-end-pos
16554 (vhdl-max-marker
16555 port-end-pos (vhdl-compose-insert-port signal-entry)))
16556 (setq port-out-pos (point-marker))
16557 (add-to-list 'written-list signal-name))
16558 ((or (member signal-name single-in-list)
16559 (member signal-name single-out-list))
16560 (vhdl-goto-marker
16561 (vhdl-max-marker
16562 port-inst-pos
16563 (vhdl-max-marker port-out-pos port-in-pos)))
16564 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16565 (setq port-inst-pos (point-marker))
16566 (add-to-list 'written-list signal-name))
16567 ((equal (upcase (nth 2 signal-entry)) "OUT")
16568 (vhdl-goto-marker signal-pos)
16569 (vhdl-compose-insert-signal signal-entry)
16570 (setq signal-pos (point-marker))
16571 (add-to-list 'written-list signal-name)))
16572 (setq signal-alist (cdr signal-alist)))
16573 (when (/= port-temp-pos port-inst-pos)
16574 (vhdl-goto-marker
16575 (vhdl-max-marker port-temp-pos
16576 (vhdl-max-marker port-in-pos port-out-pos)))
16577 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16578 (insert "-- ports to \"" inst-name "\"\n")
16579 (vhdl-goto-marker port-inst-pos))
16580 (when (/= signal-temp-pos signal-pos)
16581 (vhdl-goto-marker signal-temp-pos)
16582 (insert "\n") (indent-to vhdl-basic-offset)
16583 (insert "-- outputs of \"" inst-name "\"\n")
16584 (vhdl-goto-marker signal-pos))
16585 (setq inst-alist (cdr inst-alist)))
16586 ;; finalize generic/port clause
16587 (vhdl-goto-marker generic-end-pos) (backward-char)
16588 (when (= generic-beg-pos generic-end-pos)
16589 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16590 (insert ";") (backward-char))
16591 (insert ")")
16592 (vhdl-goto-marker port-end-pos) (backward-char)
16593 (when (= port-beg-pos port-end-pos)
16594 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16595 (insert ";") (backward-char))
16596 (insert ")")
16597 ;; align everything
16598 (when vhdl-auto-align
16599 (vhdl-goto-marker generic-beg-pos)
16600 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16601 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16602 (vhdl-goto-marker signal-beg-pos)
16603 (vhdl-align-region-groups signal-beg-pos signal-pos))
16604 (switch-to-buffer (marker-buffer signal-beg-pos))
16605 (message "Wiring components...done")))))
16606
16607 (defun vhdl-compose-insert-generic (entry)
16608 "Insert ENTRY as generic declaration."
16609 (let (pos)
16610 (indent-to (* 2 vhdl-basic-offset))
16611 (insert (nth 0 entry) " : " (nth 1 entry))
16612 (when (nth 2 entry)
16613 (insert " := " (nth 2 entry)))
16614 (insert ";")
16615 (setq pos (point-marker))
16616 (when (and vhdl-include-port-comments (nth 3 entry))
16617 (vhdl-comment-insert-inline (nth 3 entry) t))
16618 (insert "\n")
16619 pos))
16620
16621 (defun vhdl-compose-insert-port (entry)
16622 "Insert ENTRY as port declaration."
16623 (let (pos)
16624 (indent-to (* 2 vhdl-basic-offset))
16625 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16626 (setq pos (point-marker))
16627 (when (and vhdl-include-port-comments (nth 4 entry))
16628 (vhdl-comment-insert-inline (nth 4 entry) t))
16629 (insert "\n")
16630 pos))
16631
16632 (defun vhdl-compose-insert-signal (entry)
16633 "Insert ENTRY as signal declaration."
16634 (indent-to vhdl-basic-offset)
16635 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16636 (when (and vhdl-include-port-comments (nth 4 entry))
16637 (vhdl-comment-insert-inline (nth 4 entry) t))
16638 (insert "\n"))
16639
16640 (defun vhdl-compose-components-package ()
16641 "Generate a package containing component declarations for all entities in the
16642 current project/directory."
16643 (interactive)
16644 (vhdl-require-hierarchy-info)
16645 (let* ((project (vhdl-project-p))
16646 (pack-name (vhdl-get-components-package-name))
16647 (pack-file-name
16648 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16649 "." (file-name-extension (buffer-file-name))))
16650 (ent-alist (vhdl-aget vhdl-entity-alist
16651 (or project
16652 (abbreviate-file-name default-directory))))
16653 (lazy-lock-minimum-size 0)
16654 clause-pos component-pos)
16655 (message "Generating components package \"%s\"..." pack-name)
16656 ;; open package file
16657 (when (and (file-exists-p pack-file-name)
16658 (not (y-or-n-p (concat "File \"" pack-file-name
16659 "\" exists; overwrite? "))))
16660 (error "ERROR: Generating components package...aborted"))
16661 (find-file pack-file-name)
16662 (erase-buffer)
16663 ;; insert header
16664 (if vhdl-compose-include-header
16665 (progn (vhdl-template-header
16666 (concat "Components package (generated by Emacs VHDL Mode "
16667 vhdl-version ")"))
16668 (goto-char (point-max)))
16669 (vhdl-comment-display-line) (insert "\n\n"))
16670 ;; insert std_logic_1164 package
16671 (vhdl-template-package-std-logic-1164)
16672 (insert "\n") (setq clause-pos (point-marker))
16673 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16674 ;; insert package declaration
16675 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16676 (vhdl-insert-keyword " IS\n\n")
16677 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16678 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16679 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16680 (indent-to vhdl-basic-offset)
16681 (setq component-pos (point-marker))
16682 (insert "\n\n") (vhdl-insert-keyword "END ")
16683 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16684 (insert pack-name ";\n\n")
16685 ;; insert footer
16686 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16687 (vhdl-template-footer)
16688 (vhdl-comment-display-line) (insert "\n"))
16689 ;; insert component declarations
16690 (while ent-alist
16691 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16692 (progn (goto-char (point-min))
16693 (forward-line (1- (nth 3 (car ent-alist))))
16694 (end-of-line)
16695 (vhdl-port-copy)))
16696 (goto-char component-pos)
16697 (vhdl-port-paste-component t)
16698 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16699 (setq component-pos (point-marker))
16700 (goto-char clause-pos)
16701 (vhdl-port-paste-context-clause pack-name)
16702 (setq clause-pos (point-marker))
16703 (setq ent-alist (cdr ent-alist)))
16704 (goto-char (point-min))
16705 (save-buffer)
16706 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16707 pack-name pack-file-name)))
16708
16709 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16710 conf-alist inst-alist
16711 &optional insert-conf)
16712 "Generate block configuration for architecture."
16713 (let ((margin (current-indentation))
16714 (beg (point-at-bol))
16715 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16716 ;; insert block configuration (for architecture)
16717 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16718 (setq margin (+ margin vhdl-basic-offset))
16719 ;; process all instances
16720 (while inst-alist
16721 (setq inst-entry (car inst-alist))
16722 ;; is component?
16723 (when (nth 4 inst-entry)
16724 (setq insert-conf t)
16725 (setq inst-path (nth 9 inst-entry))
16726 ;; skip common path with previous instance
16727 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16728 (setq inst-path (cdr inst-path)
16729 inst-prev-path (cdr inst-prev-path)))
16730 ;; insert block configuration end (for previous block/generate)
16731 (while inst-prev-path
16732 (setq margin (- margin vhdl-basic-offset))
16733 (indent-to margin)
16734 (vhdl-insert-keyword "END FOR;\n")
16735 (setq inst-prev-path (cdr inst-prev-path)))
16736 ;; insert block configuration beginning (for current block/generate)
16737 (indent-to margin)
16738 (while inst-path
16739 (setq margin (+ margin vhdl-basic-offset))
16740 (vhdl-insert-keyword "FOR ")
16741 (insert (car inst-path) "\n")
16742 (indent-to margin)
16743 (setq inst-path (cdr inst-path)))
16744 ;; insert component configuration beginning
16745 (vhdl-insert-keyword "FOR ")
16746 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16747 ;; find subconfiguration
16748 (setq conf-key (nth 7 inst-entry))
16749 (setq tmp-alist conf-alist)
16750 ;; use first configuration found for instance's entity
16751 (while (and tmp-alist (null conf-key))
16752 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16753 (setq conf-key (nth 0 (car tmp-alist))))
16754 (setq tmp-alist (cdr tmp-alist)))
16755 (setq conf-entry (vhdl-aget conf-alist conf-key))
16756 ;; insert binding indication ...
16757 ;; ... with subconfiguration (if exists)
16758 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16759 (progn
16760 (indent-to (+ margin vhdl-basic-offset))
16761 (vhdl-insert-keyword "USE CONFIGURATION ")
16762 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16763 (insert ";\n"))
16764 ;; ... with entity (if exists)
16765 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16766 (when ent-entry
16767 (indent-to (+ margin vhdl-basic-offset))
16768 (vhdl-insert-keyword "USE ENTITY ")
16769 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16770 ;; insert architecture name (if architecture exists)
16771 (when (nth 3 ent-entry)
16772 (setq arch-name
16773 ;; choose architecture name a) from configuration,
16774 ;; b) from mra, or c) from first architecture
16775 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16776 (or (nth 6 inst-entry)
16777 (nth 4 ent-entry))))
16778 (nth 1 (car (nth 3 ent-entry)))))
16779 (insert "(" arch-name ")"))
16780 (insert ";\n")
16781 ;; insert block configuration (for architecture of subcomponent)
16782 (when (and vhdl-compose-configuration-hierarchical
16783 (nth 3 ent-entry))
16784 (indent-to (+ margin vhdl-basic-offset))
16785 (vhdl-compose-configuration-architecture
16786 (nth 0 ent-entry) arch-name ent-alist conf-alist
16787 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16788 ;; insert component configuration end
16789 (indent-to margin)
16790 (vhdl-insert-keyword "END FOR;\n")
16791 (setq inst-prev-path (nth 9 inst-entry)))
16792 (setq inst-alist (cdr inst-alist)))
16793 ;; insert block configuration end (for block/generate)
16794 (while inst-prev-path
16795 (setq margin (- margin vhdl-basic-offset))
16796 (indent-to margin)
16797 (vhdl-insert-keyword "END FOR;\n")
16798 (setq inst-prev-path (cdr inst-prev-path)))
16799 (indent-to (- margin vhdl-basic-offset))
16800 ;; insert block configuration end or remove beginning (for architecture)
16801 (if insert-conf
16802 (vhdl-insert-keyword "END FOR;\n")
16803 (delete-region beg (point)))))
16804
16805 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16806 "Generate configuration declaration."
16807 (interactive)
16808 (vhdl-require-hierarchy-info)
16809 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16810 (or (vhdl-project-p)
16811 (abbreviate-file-name default-directory))))
16812 (conf-alist (vhdl-aget vhdl-config-alist
16813 (or (vhdl-project-p)
16814 (abbreviate-file-name default-directory))))
16815 (from-speedbar ent-name)
16816 inst-alist conf-name conf-file-name pos)
16817 (vhdl-prepare-search-2
16818 ;; get entity and architecture name
16819 (unless ent-name
16820 (save-excursion
16821 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16822 (not (equal "END" (upcase (match-string 1))))
16823 (setq ent-name (match-string-no-properties 3))
16824 (setq arch-name (match-string-no-properties 2)))
16825 (error "ERROR: Not within an architecture"))))
16826 (setq conf-name (vhdl-replace-string
16827 vhdl-compose-configuration-name
16828 (concat ent-name " " arch-name)))
16829 (setq inst-alist
16830 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16831 (downcase arch-name)))))
16832 (message "Generating configuration \"%s\"..." conf-name)
16833 (if vhdl-compose-configuration-create-file
16834 ;; open configuration file
16835 (progn
16836 (setq conf-file-name
16837 (concat (vhdl-replace-string vhdl-configuration-file-name
16838 conf-name t)
16839 "." (file-name-extension (buffer-file-name))))
16840 (when (and (file-exists-p conf-file-name)
16841 (not (y-or-n-p (concat "File \"" conf-file-name
16842 "\" exists; overwrite? "))))
16843 (error "ERROR: Creating configuration...aborted"))
16844 (find-file conf-file-name)
16845 (erase-buffer)
16846 (set-buffer-modified-p nil)
16847 ;; insert header
16848 (if vhdl-compose-include-header
16849 (progn (vhdl-template-header
16850 (concat "Configuration declaration for design \""
16851 ent-name "(" arch-name ")\""))
16852 (goto-char (point-max)))
16853 (vhdl-comment-display-line) (insert "\n\n")))
16854 ;; goto end of architecture
16855 (unless from-speedbar
16856 (re-search-forward "^end\\>" nil)
16857 (end-of-line) (insert "\n\n")
16858 (vhdl-comment-display-line) (insert "\n\n")))
16859 ;; insert library clause
16860 (setq pos (point))
16861 (vhdl-template-standard-package (vhdl-work-library) nil)
16862 (when (/= pos (point))
16863 (insert "\n\n"))
16864 ;; insert configuration
16865 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16866 (vhdl-insert-keyword " OF ") (insert ent-name)
16867 (vhdl-insert-keyword " IS\n")
16868 (indent-to vhdl-basic-offset)
16869 ;; insert block configuration (for architecture)
16870 (vhdl-compose-configuration-architecture
16871 ent-name arch-name ent-alist conf-alist inst-alist t)
16872 (vhdl-insert-keyword "END ") (insert conf-name ";")
16873 (when conf-file-name
16874 ;; insert footer and save
16875 (insert "\n\n")
16876 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16877 (vhdl-template-footer)
16878 (vhdl-comment-display-line) (insert "\n"))
16879 (save-buffer))
16880 (message "%s"
16881 (concat (format "Generating configuration \"%s\"...done" conf-name)
16882 (and conf-file-name
16883 (format "\n File created: \"%s\"" conf-file-name))))))
16884
16885
16886 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16887 ;;; Compilation / Makefile generation
16888 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16889 ;; (using `compile.el')
16890
16891 (defvar vhdl-compile-post-command ""
16892 "String appended to compile command after file name.")
16893
16894 (defun vhdl-makefile-name ()
16895 "Return the Makefile name of the current project or the current compiler if
16896 no project is defined."
16897 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16898 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16899 (vhdl-replace-string
16900 (cons "\\(.*\\)\n\\(.*\\)"
16901 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16902 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16903
16904 (defun vhdl-compile-directory ()
16905 "Return the directory where compilation/make should be run."
16906 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16907 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16908 (directory (vhdl-resolve-env-variable
16909 (if project
16910 (vhdl-replace-string
16911 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16912 (nth 6 compiler)))))
16913 (file-name-as-directory
16914 (if (file-name-absolute-p directory)
16915 directory
16916 (expand-file-name directory (vhdl-default-directory))))))
16917
16918 (defun vhdl-uniquify (in-list)
16919 "Remove duplicate elements from IN-LIST."
16920 (let (out-list)
16921 (while in-list
16922 (add-to-list 'out-list (car in-list))
16923 (setq in-list (cdr in-list)))
16924 out-list))
16925
16926 (defun vhdl-set-compiler (name)
16927 "Set current compiler to NAME."
16928 (interactive
16929 (list (let ((completion-ignore-case t))
16930 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16931 (if (assoc name vhdl-compiler-alist)
16932 (progn (setq vhdl-compiler name)
16933 (message "Current compiler: \"%s\"" vhdl-compiler))
16934 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16935
16936 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16937 ;; Compilation
16938
16939 (defun vhdl-compile-init ()
16940 "Initialize for compilation."
16941 (when (and (not vhdl-emacs-22)
16942 (or (null compilation-error-regexp-alist)
16943 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16944 compilation-error-regexp-alist))))
16945 ;; `compilation-error-regexp-alist'
16946 (let ((commands-alist vhdl-compiler-alist)
16947 regexp-alist sublist)
16948 (while commands-alist
16949 (setq sublist (nth 11 (car commands-alist)))
16950 (unless (or (equal "" (car sublist))
16951 (assoc (car sublist) regexp-alist))
16952 (push (list (nth 0 sublist)
16953 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16954 9
16955 (nth 1 sublist))
16956 (nth 2 sublist) (nth 3 sublist))
16957 regexp-alist))
16958 (setq commands-alist (cdr commands-alist)))
16959 (setq compilation-error-regexp-alist
16960 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16961 ;; `compilation-file-regexp-alist'
16962 (let ((commands-alist vhdl-compiler-alist)
16963 regexp-alist sublist)
16964 ;; matches vhdl-mode file name output
16965 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16966 (while commands-alist
16967 (setq sublist (nth 12 (car commands-alist)))
16968 (unless (or (equal "" (car sublist))
16969 (assoc (car sublist) regexp-alist))
16970 (push sublist regexp-alist))
16971 (setq commands-alist (cdr commands-alist)))
16972 (setq compilation-file-regexp-alist
16973 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16974
16975 (defvar vhdl-compile-file-name nil
16976 "Name of file to be compiled.")
16977
16978 (defun vhdl-compile-print-file-name ()
16979 "Function called within `compile' to print out file name for compilers that
16980 do not print any file names."
16981 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16982
16983 (defun vhdl-get-compile-options (project compiler file-name
16984 &optional file-options-only)
16985 "Get compiler options. Returning nil means do not compile this file."
16986 (let* ((compiler-options (nth 1 compiler))
16987 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
16988 (project-options (nth 0 project-entry))
16989 (exception-list (and file-name (nth 2 project-entry)))
16990 (work-library (vhdl-work-library))
16991 (case-fold-search nil)
16992 file-options)
16993 (while (and exception-list
16994 (not (string-match (caar exception-list) file-name)))
16995 (setq exception-list (cdr exception-list)))
16996 (if (and exception-list (not (cdar exception-list)))
16997 nil
16998 (if (and file-options-only (not exception-list))
16999 'default
17000 (setq file-options (cdar exception-list))
17001 ;; insert library name in compiler-specific options
17002 (setq compiler-options
17003 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
17004 work-library))
17005 ;; insert compiler-specific options in project-specific options
17006 (when project-options
17007 (setq project-options
17008 (vhdl-replace-string
17009 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17010 (concat work-library "\n" compiler-options))))
17011 ;; insert project-specific options in file-specific options
17012 (when file-options
17013 (setq file-options
17014 (vhdl-replace-string
17015 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
17016 (concat work-library "\n" compiler-options "\n"
17017 project-options))))
17018 ;; return options
17019 (or file-options project-options compiler-options)))))
17020
17021 (defun vhdl-get-make-options (project compiler)
17022 "Get make options."
17023 (let* ((compiler-options (nth 3 compiler))
17024 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17025 (project-options (nth 1 project-entry))
17026 (makefile-name (vhdl-makefile-name)))
17027 ;; insert Makefile name in compiler-specific options
17028 (setq compiler-options
17029 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
17030 makefile-name))
17031 ;; insert compiler-specific options in project-specific options
17032 (when project-options
17033 (setq project-options
17034 (vhdl-replace-string
17035 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17036 (concat makefile-name "\n" compiler-options))))
17037 ;; return options
17038 (or project-options compiler-options)))
17039
17040 (defun vhdl-compile ()
17041 "Compile current buffer using the VHDL compiler specified in
17042 `vhdl-compiler'."
17043 (interactive)
17044 (vhdl-compile-init)
17045 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17046 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17047 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17048 (command (nth 0 compiler))
17049 (default-directory (vhdl-compile-directory))
17050 (file-name (if vhdl-compile-absolute-path
17051 (buffer-file-name)
17052 (file-relative-name (buffer-file-name))))
17053 (options (vhdl-get-compile-options project compiler file-name))
17054 compilation-process-setup-function)
17055 (unless (file-directory-p default-directory)
17056 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17057 ;; put file name into quotes if it contains spaces
17058 (when (string-match " " file-name)
17059 (setq file-name (concat "\"" file-name "\"")))
17060 ;; print out file name if compiler does not
17061 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
17062 (buffer-file-name)
17063 (file-relative-name (buffer-file-name))))
17064 (when (and (= 0 (nth 1 (nth 10 compiler)))
17065 (= 0 (nth 1 (nth 11 compiler))))
17066 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
17067 ;; run compilation
17068 (if options
17069 (when command
17070 (compile (concat command " " options " " file-name
17071 (unless (equal vhdl-compile-post-command "")
17072 (concat " " vhdl-compile-post-command)))))
17073 (vhdl-warning "Your project settings tell me not to compile this file"))))
17074
17075 (defvar vhdl-make-target "all"
17076 "Default target for `vhdl-make' command.")
17077
17078 (defun vhdl-make (&optional target)
17079 "Call make command for compilation of all updated source files (requires
17080 `Makefile'). Optional argument TARGET allows you to compile the design
17081 specified by a target."
17082 (interactive)
17083 (setq vhdl-make-target
17084 (or target (read-from-minibuffer "Target: " vhdl-make-target
17085 vhdl-minibuffer-local-map)))
17086 (vhdl-compile-init)
17087 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17088 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17089 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17090 (command (nth 2 compiler))
17091 (options (vhdl-get-make-options project compiler))
17092 (default-directory (vhdl-compile-directory)))
17093 (unless (file-directory-p default-directory)
17094 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17095 ;; run make
17096 (compile (concat (if (equal command "") "make" command)
17097 " " options " " vhdl-make-target))))
17098
17099 ;; Emacs 22+ setup
17100 (defvar vhdl-error-regexp-emacs-alist
17101 ;; Get regexps from `vhdl-compiler-alist'
17102 (let ((compiler-alist vhdl-compiler-alist)
17103 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
17104 (while compiler-alist
17105 ;; only add regexps for currently selected compiler
17106 (when (or (not vhdl-compile-use-local-error-regexp)
17107 (equal vhdl-compiler (nth 0 (car compiler-alist))))
17108 ;; add error message regexps
17109 (setq error-regexp-alist
17110 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
17111 (nth 11 (car compiler-alist)))
17112 error-regexp-alist))
17113 ;; add filename regexps
17114 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
17115 (setq error-regexp-alist
17116 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
17117 (nth 12 (car compiler-alist)))
17118 error-regexp-alist))))
17119 (setq compiler-alist (cdr compiler-alist)))
17120 error-regexp-alist)
17121 "List of regexps for VHDL compilers. For Emacs 22+.")
17122
17123 ;; Add error regexps using compilation-mode-hook.
17124 (defun vhdl-error-regexp-add-emacs ()
17125 "Set up Emacs compile for VHDL."
17126 (interactive)
17127 (when (and (boundp 'compilation-error-regexp-alist-alist)
17128 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
17129 ;; remove all other compilers
17130 (when vhdl-compile-use-local-error-regexp
17131 (setq compilation-error-regexp-alist nil))
17132 ;; add VHDL compilers
17133 (mapcar
17134 (lambda (item)
17135 (push (car item) compilation-error-regexp-alist)
17136 (push item compilation-error-regexp-alist-alist))
17137 vhdl-error-regexp-emacs-alist)))
17138
17139 (when vhdl-emacs-22
17140 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
17141
17142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17143 ;; Makefile generation
17144
17145 (defun vhdl-generate-makefile ()
17146 "Generate `Makefile'."
17147 (interactive)
17148 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17149 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17150 (command (nth 4 compiler)))
17151 ;; generate makefile
17152 (if command
17153 (let ((default-directory (vhdl-compile-directory)))
17154 (compile (vhdl-replace-string
17155 (cons "\\(.*\\) \\(.*\\)" command)
17156 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17157 (vhdl-generate-makefile-1))))
17158
17159 (defun vhdl-get-packages (lib-alist work-library)
17160 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17161 (let (pack-list)
17162 (while lib-alist
17163 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17164 (push (cdar lib-alist) pack-list))
17165 (setq lib-alist (cdr lib-alist)))
17166 pack-list))
17167
17168 (defun vhdl-generate-makefile-1 ()
17169 "Generate Makefile for current project or directory."
17170 ;; scan hierarchy if required
17171 (if (vhdl-project-p)
17172 (unless (or (assoc vhdl-project vhdl-file-alist)
17173 (vhdl-load-cache vhdl-project))
17174 (vhdl-scan-project-contents vhdl-project))
17175 (let ((directory (abbreviate-file-name default-directory)))
17176 (unless (or (assoc directory vhdl-file-alist)
17177 (vhdl-load-cache directory))
17178 (vhdl-scan-directory-contents directory))))
17179 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17180 (project (vhdl-project-p))
17181 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17182 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17183 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17184 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17185 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17186 "\\1.vhd" "\\1_body.vhd" identity)))
17187 (mapping-exist
17188 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17189 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17190 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17191 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17192 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17193 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17194 (adjust-case (nth 5 regexp-list))
17195 (work-library (downcase (vhdl-work-library)))
17196 (compile-directory (expand-file-name (vhdl-compile-directory)
17197 default-directory))
17198 (makefile-name (vhdl-makefile-name))
17199 rule-alist arch-alist inst-alist
17200 target-list depend-list unit-list prim-list second-list subcomp-list
17201 lib-alist lib-body-alist pack-list all-pack-list
17202 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17203 conf-key conf-file-name pack-key pack-file-name
17204 ent-entry arch-entry conf-entry pack-entry inst-entry
17205 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17206 tmp-key tmp-list rule)
17207 ;; check prerequisites
17208 (unless (file-exists-p compile-directory)
17209 (make-directory compile-directory t))
17210 (unless mapping-exist
17211 (vhdl-warning
17212 (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\""
17213 vhdl-compiler vhdl-compiler) t))
17214 (message "Generating makefile \"%s\"..." makefile-name)
17215 ;; rules for all entities
17216 (setq tmp-list ent-alist)
17217 (while ent-alist
17218 (setq ent-entry (car ent-alist)
17219 ent-key (nth 0 ent-entry))
17220 (when (nth 2 ent-entry)
17221 (setq ent-file-name (if vhdl-compile-absolute-path
17222 (nth 2 ent-entry)
17223 (file-relative-name (nth 2 ent-entry)
17224 compile-directory))
17225 arch-alist (nth 4 ent-entry)
17226 lib-alist (nth 6 ent-entry)
17227 rule (vhdl-aget rule-alist ent-file-name)
17228 target-list (nth 0 rule)
17229 depend-list (nth 1 rule)
17230 second-list nil
17231 subcomp-list nil)
17232 (setq tmp-key (vhdl-replace-string
17233 ent-regexp
17234 (funcall adjust-case
17235 (concat ent-key " " work-library))))
17236 (push (cons ent-key tmp-key) unit-list)
17237 ;; rule target for this entity
17238 (push ent-key target-list)
17239 ;; rule dependencies for all used packages
17240 (setq pack-list (vhdl-get-packages lib-alist work-library))
17241 (setq depend-list (append depend-list pack-list))
17242 (setq all-pack-list pack-list)
17243 ;; add rule
17244 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17245 ;; rules for all corresponding architectures
17246 (while arch-alist
17247 (setq arch-entry (car arch-alist)
17248 arch-key (nth 0 arch-entry)
17249 ent-arch-key (concat ent-key "-" arch-key)
17250 arch-file-name (if vhdl-compile-absolute-path
17251 (nth 2 arch-entry)
17252 (file-relative-name (nth 2 arch-entry)
17253 compile-directory))
17254 inst-alist (nth 4 arch-entry)
17255 lib-alist (nth 5 arch-entry)
17256 rule (vhdl-aget rule-alist arch-file-name)
17257 target-list (nth 0 rule)
17258 depend-list (nth 1 rule))
17259 (setq tmp-key (vhdl-replace-string
17260 arch-regexp
17261 (funcall adjust-case
17262 (concat arch-key " " ent-key " "
17263 work-library))))
17264 (setq unit-list
17265 (cons (cons ent-arch-key tmp-key) unit-list))
17266 (push ent-arch-key second-list)
17267 ;; rule target for this architecture
17268 (push ent-arch-key target-list)
17269 ;; rule dependency for corresponding entity
17270 (push ent-key depend-list)
17271 ;; rule dependencies for contained component instantiations
17272 (while inst-alist
17273 (setq inst-entry (car inst-alist))
17274 (when (or (null (nth 8 inst-entry))
17275 (equal (downcase (nth 8 inst-entry)) work-library))
17276 (setq inst-ent-key (or (nth 7 inst-entry)
17277 (nth 5 inst-entry)))
17278 (setq depend-list (cons inst-ent-key depend-list)
17279 subcomp-list (cons inst-ent-key subcomp-list)))
17280 (setq inst-alist (cdr inst-alist)))
17281 ;; rule dependencies for all used packages
17282 (setq pack-list (vhdl-get-packages lib-alist work-library))
17283 (setq depend-list (append depend-list pack-list))
17284 (setq all-pack-list (append all-pack-list pack-list))
17285 ;; add rule
17286 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17287 (setq arch-alist (cdr arch-alist)))
17288 (push (list ent-key second-list (append subcomp-list all-pack-list))
17289 prim-list))
17290 (setq ent-alist (cdr ent-alist)))
17291 (setq ent-alist tmp-list)
17292 ;; rules for all configurations
17293 (setq tmp-list conf-alist)
17294 (while conf-alist
17295 (setq conf-entry (car conf-alist)
17296 conf-key (nth 0 conf-entry)
17297 conf-file-name (if vhdl-compile-absolute-path
17298 (nth 2 conf-entry)
17299 (file-relative-name (nth 2 conf-entry)
17300 compile-directory))
17301 ent-key (nth 4 conf-entry)
17302 arch-key (nth 5 conf-entry)
17303 inst-alist (nth 6 conf-entry)
17304 lib-alist (nth 7 conf-entry)
17305 rule (vhdl-aget rule-alist conf-file-name)
17306 target-list (nth 0 rule)
17307 depend-list (nth 1 rule)
17308 subcomp-list (list ent-key))
17309 (setq tmp-key (vhdl-replace-string
17310 conf-regexp
17311 (funcall adjust-case
17312 (concat conf-key " " work-library))))
17313 (push (cons conf-key tmp-key) unit-list)
17314 ;; rule target for this configuration
17315 (push conf-key target-list)
17316 ;; rule dependency for corresponding entity and architecture
17317 (setq depend-list
17318 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17319 ;; rule dependencies for used packages
17320 (setq pack-list (vhdl-get-packages lib-alist work-library))
17321 (setq depend-list (append depend-list pack-list))
17322 ;; rule dependencies for contained component configurations
17323 (while inst-alist
17324 (setq inst-entry (car inst-alist))
17325 (setq inst-ent-key (nth 2 inst-entry)
17326 inst-conf-key (nth 4 inst-entry))
17327 (when (equal (downcase (nth 5 inst-entry)) work-library)
17328 (when inst-ent-key
17329 (setq depend-list (cons inst-ent-key depend-list)
17330 subcomp-list (cons inst-ent-key subcomp-list)))
17331 (when inst-conf-key
17332 (setq depend-list (cons inst-conf-key depend-list)
17333 subcomp-list (cons inst-conf-key subcomp-list))))
17334 (setq inst-alist (cdr inst-alist)))
17335 ;; add rule
17336 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17337 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17338 (setq conf-alist (cdr conf-alist)))
17339 (setq conf-alist tmp-list)
17340 ;; rules for all packages
17341 (setq tmp-list pack-alist)
17342 (while pack-alist
17343 (setq pack-entry (car pack-alist)
17344 pack-key (nth 0 pack-entry)
17345 pack-body-key nil)
17346 (when (nth 2 pack-entry)
17347 (setq pack-file-name (if vhdl-compile-absolute-path
17348 (nth 2 pack-entry)
17349 (file-relative-name (nth 2 pack-entry)
17350 compile-directory))
17351 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17352 rule (vhdl-aget rule-alist pack-file-name)
17353 target-list (nth 0 rule) depend-list (nth 1 rule))
17354 (setq tmp-key (vhdl-replace-string
17355 pack-regexp
17356 (funcall adjust-case
17357 (concat pack-key " " work-library))))
17358 (push (cons pack-key tmp-key) unit-list)
17359 ;; rule target for this package
17360 (push pack-key target-list)
17361 ;; rule dependencies for all used packages
17362 (setq pack-list (vhdl-get-packages lib-alist work-library))
17363 (setq depend-list (append depend-list pack-list))
17364 (setq all-pack-list pack-list)
17365 ;; add rule
17366 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17367 ;; rules for this package's body
17368 (when (nth 7 pack-entry)
17369 (setq pack-body-key (concat pack-key "-body")
17370 pack-body-file-name (if vhdl-compile-absolute-path
17371 (nth 7 pack-entry)
17372 (file-relative-name (nth 7 pack-entry)
17373 compile-directory))
17374 rule (vhdl-aget rule-alist pack-body-file-name)
17375 target-list (nth 0 rule)
17376 depend-list (nth 1 rule))
17377 (setq tmp-key (vhdl-replace-string
17378 pack-body-regexp
17379 (funcall adjust-case
17380 (concat pack-key " " work-library))))
17381 (setq unit-list
17382 (cons (cons pack-body-key tmp-key) unit-list))
17383 ;; rule target for this package's body
17384 (push pack-body-key target-list)
17385 ;; rule dependency for corresponding package declaration
17386 (push pack-key depend-list)
17387 ;; rule dependencies for all used packages
17388 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17389 (setq depend-list (append depend-list pack-list))
17390 (setq all-pack-list (append all-pack-list pack-list))
17391 ;; add rule
17392 (vhdl-aput 'rule-alist pack-body-file-name
17393 (list target-list depend-list)))
17394 (setq prim-list
17395 (cons (list pack-key (when pack-body-key (list pack-body-key))
17396 all-pack-list)
17397 prim-list)))
17398 (setq pack-alist (cdr pack-alist)))
17399 (setq pack-alist tmp-list)
17400 ;; generate Makefile
17401 (let* ((project (vhdl-aget vhdl-project-alist project))
17402 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17403 (compiler-id (nth 9 compiler))
17404 (library-directory
17405 (vhdl-resolve-env-variable
17406 (vhdl-replace-string
17407 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17408 compiler-id)))
17409 (makefile-path-name (expand-file-name
17410 makefile-name compile-directory))
17411 (orig-buffer (current-buffer))
17412 cell second-list subcomp-list options unit-key unit-name)
17413 ;; sort lists
17414 (setq unit-list (vhdl-sort-alist unit-list))
17415 (setq prim-list (vhdl-sort-alist prim-list))
17416 (setq tmp-list rule-alist)
17417 (while tmp-list ; pre-sort rule targets
17418 (setq cell (cdar tmp-list))
17419 (setcar cell (sort (car cell) 'string<))
17420 (setq tmp-list (cdr tmp-list)))
17421 (setq rule-alist ; sort by first rule target
17422 (sort rule-alist
17423 (function (lambda (a b)
17424 (string< (car (cadr a)) (car (cadr b)))))))
17425 ;; open and clear Makefile
17426 (set-buffer (find-file-noselect makefile-path-name t t))
17427 (erase-buffer)
17428 (insert "# -*- Makefile -*-\n"
17429 "### " (file-name-nondirectory makefile-name)
17430 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17431 "\n")
17432 (if project
17433 (insert "\n# Project : " (nth 0 project))
17434 (insert "\n# Directory : \"" directory "\""))
17435 (insert "\n# Platform : " vhdl-compiler
17436 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17437 (user-login-name) "\n")
17438 ;; insert compile and option variable settings
17439 (insert "\n\n# Define compilation command and options\n"
17440 "\nCOMPILE = " (nth 0 compiler)
17441 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17442 (if (equal vhdl-compile-post-command "") ""
17443 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17444 "\n")
17445 ;; insert library paths
17446 (setq library-directory
17447 (directory-file-name
17448 (if (file-name-absolute-p library-directory)
17449 library-directory
17450 (file-relative-name
17451 (expand-file-name library-directory directory)
17452 compile-directory))))
17453 (insert "\n\n# Define library paths\n"
17454 "\nLIBRARY-" work-library " = " library-directory "\n")
17455 (unless mapping-exist
17456 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17457 ")/make" "\n"))
17458 ;; insert variable definitions for all library unit files
17459 (insert "\n\n# Define library unit files\n")
17460 (setq tmp-list unit-list)
17461 (while unit-list
17462 (insert "\nUNIT-" work-library "-" (caar unit-list)
17463 " = \\\n\t$(LIBRARY-" work-library
17464 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17465 (setq unit-list (cdr unit-list)))
17466 ;; insert variable definition for list of all library unit files
17467 (insert "\n\n\n# Define list of all library unit files\n"
17468 "\nALL_UNITS =")
17469 (setq unit-list tmp-list)
17470 (while unit-list
17471 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17472 (setq unit-list (cdr unit-list)))
17473 (insert "\n")
17474 (setq unit-list tmp-list)
17475 ;; insert `make all' rule
17476 (insert "\n\n\n# Rule for compiling entire design\n"
17477 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17478 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17479 " \\\n\t\t$(ALL_UNITS)\n")
17480 ;; insert `make clean' rule
17481 (insert "\n\n# Rule for cleaning entire design\n"
17482 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17483 "\n\t-rm -f $(ALL_UNITS)\n")
17484 ;; insert `make library' rule
17485 (insert "\n\n# Rule for creating library directory\n"
17486 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17487 " \\\n\t\t$(LIBRARY-" work-library ")"
17488 (if mapping-exist ""
17489 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17490 "\n"
17491 "\n$(LIBRARY-" work-library ") :"
17492 "\n\t"
17493 (vhdl-replace-string
17494 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17495 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17496 "\n")
17497 (unless mapping-exist
17498 (insert "\n$(LIBRARY-" work-library "-make) :"
17499 "\n\t"
17500 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17501 ;; insert '.PHONY' declaration
17502 (insert "\n\n.PHONY : "
17503 (nth 0 vhdl-makefile-default-targets) " "
17504 (nth 1 vhdl-makefile-default-targets) " "
17505 (nth 2 vhdl-makefile-default-targets) "\n")
17506 ;; insert rule for each library unit
17507 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17508 (while prim-list
17509 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17510 (setq subcomp-list
17511 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17512 (setq unit-key (caar prim-list)
17513 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17514 (nth 0 (vhdl-aget conf-alist unit-key))
17515 (nth 0 (vhdl-aget pack-alist unit-key))))
17516 (insert "\n" unit-key)
17517 (unless (equal unit-key unit-name)
17518 (insert " \\\n" unit-name))
17519 (insert " :"
17520 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17521 (while subcomp-list
17522 (when (and (assoc (car subcomp-list) unit-list)
17523 (not (equal unit-key (car subcomp-list))))
17524 (insert " \\\n\t\t" (car subcomp-list)))
17525 (setq subcomp-list (cdr subcomp-list)))
17526 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17527 (while second-list
17528 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17529 (setq second-list (cdr second-list)))
17530 (insert "\n")
17531 (setq prim-list (cdr prim-list)))
17532 ;; insert rule for each library unit file
17533 (insert "\n\n# Rules for compiling single library unit files\n")
17534 (while rule-alist
17535 (setq rule (car rule-alist))
17536 ;; get compiler options for this file
17537 (setq options
17538 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17539 ;; insert rule if file is supposed to be compiled
17540 (setq target-list (nth 1 rule)
17541 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17542 ;; insert targets
17543 (setq tmp-list target-list)
17544 (while target-list
17545 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17546 (if (cdr target-list) " \\" " :"))
17547 (setq target-list (cdr target-list)))
17548 (setq target-list tmp-list)
17549 ;; insert file name as first dependency
17550 (insert " \\\n\t\t" (nth 0 rule))
17551 ;; insert dependencies (except if also target or unit does not exist)
17552 (while depend-list
17553 (when (and (not (member (car depend-list) target-list))
17554 (assoc (car depend-list) unit-list))
17555 (insert " \\\n\t\t"
17556 "$(UNIT-" work-library "-" (car depend-list) ")"))
17557 (setq depend-list (cdr depend-list)))
17558 ;; insert compile command
17559 (if options
17560 (insert "\n\t$(COMPILE) "
17561 (if (eq options 'default) "$(OPTIONS)" options) " "
17562 (nth 0 rule)
17563 (if (equal vhdl-compile-post-command "") ""
17564 " $(POST-COMPILE)") "\n")
17565 (insert "\n"))
17566 (unless (and options mapping-exist)
17567 (setq tmp-list target-list)
17568 (while target-list
17569 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17570 (setq target-list (cdr target-list)))
17571 (setq target-list tmp-list))
17572 (setq rule-alist (cdr rule-alist)))
17573
17574 (insert "\n\n### " makefile-name " ends here\n")
17575 ;; run Makefile generation hook
17576 (run-hooks 'vhdl-makefile-generation-hook)
17577 (message "Generating makefile \"%s\"...done" makefile-name)
17578 ;; save and close file
17579 (if (file-writable-p makefile-path-name)
17580 (progn (save-buffer)
17581 (kill-buffer (current-buffer))
17582 (set-buffer orig-buffer)
17583 (when (fboundp 'add-to-history)
17584 (add-to-history 'file-name-history makefile-path-name)))
17585 (vhdl-warning-when-idle
17586 (format "File not writable: \"%s\""
17587 (abbreviate-file-name makefile-path-name)))
17588 (switch-to-buffer (current-buffer))))))
17589
17590
17591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17592 ;;; Bug reports
17593 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17594 ;; (using `reporter.el')
17595
17596 (defconst vhdl-mode-help-address
17597 "Reto Zimmermann <reto@gnu.org>"
17598 "Address for VHDL Mode bug reports.")
17599
17600 (defun vhdl-submit-bug-report ()
17601 "Submit via mail a bug report on VHDL Mode."
17602 (interactive)
17603 ;; load in reporter
17604 (and
17605 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17606 (let ((reporter-prompt-for-summary-p t))
17607 (reporter-submit-bug-report
17608 vhdl-mode-help-address
17609 (concat "VHDL Mode " vhdl-version)
17610 (list
17611 ;; report all important user options
17612 'vhdl-offsets-alist
17613 'vhdl-comment-only-line-offset
17614 'tab-width
17615 'vhdl-electric-mode
17616 'vhdl-stutter-mode
17617 'vhdl-indent-tabs-mode
17618 'vhdl-project-alist
17619 'vhdl-project
17620 'vhdl-project-file-name
17621 'vhdl-project-auto-load
17622 'vhdl-project-sort
17623 'vhdl-compiler-alist
17624 'vhdl-compiler
17625 'vhdl-compile-use-local-error-regexp
17626 'vhdl-makefile-default-targets
17627 'vhdl-makefile-generation-hook
17628 'vhdl-default-library
17629 'vhdl-standard
17630 'vhdl-basic-offset
17631 'vhdl-upper-case-keywords
17632 'vhdl-upper-case-types
17633 'vhdl-upper-case-attributes
17634 'vhdl-upper-case-enum-values
17635 'vhdl-upper-case-constants
17636 'vhdl-use-direct-instantiation
17637 'vhdl-array-index-record-field-in-sensitivity-list
17638 'vhdl-compose-configuration-name
17639 'vhdl-entity-file-name
17640 'vhdl-architecture-file-name
17641 'vhdl-configuration-file-name
17642 'vhdl-package-file-name
17643 'vhdl-file-name-case
17644 'vhdl-electric-keywords
17645 'vhdl-optional-labels
17646 'vhdl-insert-empty-lines
17647 'vhdl-argument-list-indent
17648 'vhdl-association-list-with-formals
17649 'vhdl-conditions-in-parenthesis
17650 'vhdl-sensitivity-list-all
17651 'vhdl-zero-string
17652 'vhdl-one-string
17653 'vhdl-file-header
17654 'vhdl-file-footer
17655 'vhdl-company-name
17656 'vhdl-copyright-string
17657 'vhdl-platform-spec
17658 'vhdl-date-format
17659 'vhdl-modify-date-prefix-string
17660 'vhdl-modify-date-on-saving
17661 'vhdl-reset-kind
17662 'vhdl-reset-active-high
17663 'vhdl-clock-rising-edge
17664 'vhdl-clock-edge-condition
17665 'vhdl-clock-name
17666 'vhdl-reset-name
17667 'vhdl-model-alist
17668 'vhdl-include-port-comments
17669 'vhdl-include-direction-comments
17670 'vhdl-include-type-comments
17671 'vhdl-include-group-comments
17672 'vhdl-actual-generic-name
17673 'vhdl-actual-port-name
17674 'vhdl-instance-name
17675 'vhdl-testbench-entity-name
17676 'vhdl-testbench-architecture-name
17677 'vhdl-testbench-configuration-name
17678 'vhdl-testbench-dut-name
17679 'vhdl-testbench-include-header
17680 'vhdl-testbench-declarations
17681 'vhdl-testbench-statements
17682 'vhdl-testbench-initialize-signals
17683 'vhdl-testbench-include-library
17684 'vhdl-testbench-include-configuration
17685 'vhdl-testbench-create-files
17686 'vhdl-testbench-entity-file-name
17687 'vhdl-testbench-architecture-file-name
17688 'vhdl-compose-create-files
17689 'vhdl-compose-configuration-create-file
17690 'vhdl-compose-configuration-hierarchical
17691 'vhdl-compose-configuration-use-subconfiguration
17692 'vhdl-compose-include-header
17693 'vhdl-compose-architecture-name
17694 'vhdl-components-package-name
17695 'vhdl-use-components-package
17696 'vhdl-self-insert-comments
17697 'vhdl-prompt-for-comments
17698 'vhdl-inline-comment-column
17699 'vhdl-end-comment-column
17700 'vhdl-auto-align
17701 'vhdl-align-groups
17702 'vhdl-align-group-separate
17703 'vhdl-align-same-indent
17704 'vhdl-highlight-keywords
17705 'vhdl-highlight-names
17706 'vhdl-highlight-special-words
17707 'vhdl-highlight-forbidden-words
17708 'vhdl-highlight-verilog-keywords
17709 'vhdl-highlight-translate-off
17710 'vhdl-highlight-case-sensitive
17711 'vhdl-special-syntax-alist
17712 'vhdl-forbidden-words
17713 'vhdl-forbidden-syntax
17714 'vhdl-directive-keywords
17715 'vhdl-speedbar-auto-open
17716 'vhdl-speedbar-display-mode
17717 'vhdl-speedbar-scan-limit
17718 'vhdl-speedbar-jump-to-unit
17719 'vhdl-speedbar-update-on-saving
17720 'vhdl-speedbar-save-cache
17721 'vhdl-speedbar-cache-file-name
17722 'vhdl-index-menu
17723 'vhdl-source-file-menu
17724 'vhdl-hideshow-menu
17725 'vhdl-hide-all-init
17726 'vhdl-print-two-column
17727 'vhdl-print-customize-faces
17728 'vhdl-intelligent-tab
17729 'vhdl-indent-syntax-based
17730 'vhdl-indent-comment-like-next-code-line
17731 'vhdl-word-completion-case-sensitive
17732 'vhdl-word-completion-in-minibuffer
17733 'vhdl-underscore-is-part-of-word
17734 'vhdl-mode-hook)
17735 (function
17736 (lambda ()
17737 (insert
17738 (if vhdl-special-indent-hook
17739 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17740 "vhdl-special-indent-hook is set to '"
17741 (format "%s" vhdl-special-indent-hook)
17742 ".\nPerhaps this is your problem?\n"
17743 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17744 "\n"))))
17745 nil
17746 "Hi Reto,"))))
17747
17748
17749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17750 ;;; Documentation
17751 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17752
17753 (defconst vhdl-doc-release-notes nil
17754 "\
17755 Release Notes for VHDL Mode 3.37
17756 ================================
17757
17758 - Added support for VHDL'08:
17759 - New keywords, types, functions, attributes, operators, packages
17760 - Context declaration
17761 - Block comments
17762 - Directives
17763 - `all' keyword in sensitivity list
17764
17765
17766 Release Notes for VHDL Mode 3.34
17767 ================================
17768
17769 - Added support for GNU Emacs 22/23/24:
17770 - Compilation error parsing fixed for new `compile.el' package.
17771
17772 - Port translation: Derive actual generic name from formal generic name.
17773
17774 - New user options:
17775 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17776
17777
17778 Release Notes for VHDL Mode 3.33
17779 ================================
17780
17781 New Features
17782 ------------
17783
17784 CONFIGURATION DECLARATION GENERATION:
17785 - Automatic generation of a configuration declaration for a design.
17786 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17787
17788
17789 Key Bindings
17790 ------------
17791
17792 For Emacs compliance the following key bindings have been changed:
17793
17794 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17795 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17796 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17797 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17798
17799
17800 User Options
17801 ------------
17802
17803 `vhdl-configuration-file-name': (new)
17804 Specify how the configuration file name is obtained.
17805 `vhdl-compose-configuration-name': (new)
17806 Specify how the configuration name is obtained.
17807 `vhdl-compose-configuration-create-file': (new)
17808 Specify whether a new file should be created for a configuration.
17809 `vhdl-compose-configuration-hierarchical': (new)
17810 Specify whether hierarchical configurations should be created.
17811 `vhdl-compose-configuration-use-subconfiguration': (new)
17812 Specify whether subconfigurations should be used inside configurations.
17813 `vhdl-makefile-default-targets': (new)
17814 Customize names of Makefile default targets.
17815 `vhdl-indent-comment-like-next-code-line': (new)
17816 Specify whether comment lines are indented like following code line.
17817 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17818 Specify whether to include array indices / record fields in sensitivity list.
17819 ")
17820
17821
17822 (defconst vhdl-doc-keywords nil
17823 "\
17824 Reserved words in VHDL
17825 ----------------------
17826
17827 VHDL'08 (IEEE Std 1076-2008):
17828 `vhdl-08-keywords' : keywords
17829 `vhdl-08-types' : standardized types
17830 `vhdl-08-attributes' : standardized attributes
17831 `vhdl-08-functions' : standardized functions
17832 `vhdl-08-packages' : standardized packages and libraries
17833
17834 VHDL'93/02 (IEEE Std 1076-1993/2002):
17835 `vhdl-02-keywords' : keywords
17836 `vhdl-02-types' : standardized types
17837 `vhdl-02-attributes' : standardized attributes
17838 `vhdl-02-enum-values' : standardized enumeration values
17839 `vhdl-02-functions' : standardized functions
17840 `vhdl-02-packages' : standardized packages and libraries
17841
17842 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17843 `vhdl-ams-keywords' : keywords
17844 `vhdl-ams-types' : standardized types
17845 `vhdl-ams-attributes' : standardized attributes
17846 `vhdl-ams-enum-values' : standardized enumeration values
17847 `vhdl-ams-constants' : standardized constants
17848 `vhdl-ams-functions' : standardized functions
17849
17850 Math Packages (IEEE Std 1076.2):
17851 `vhdl-math-types' : standardized types
17852 `vhdl-math-constants' : standardized constants
17853 `vhdl-math-functions' : standardized functions
17854 `vhdl-math-packages' : standardized packages
17855
17856 Forbidden words:
17857 `vhdl-verilog-keywords' : Verilog reserved words
17858
17859 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17860
17861
17862 (defconst vhdl-doc-coding-style nil
17863 "\
17864 For VHDL coding style and naming convention guidelines, see the following
17865 references:
17866
17867 [1] Ben Cohen.
17868 \"VHDL Coding Styles and Methodologies\".
17869 Kluwer Academic Publishers, 1999.
17870 http://members.aol.com/vhdlcohen/vhdl/
17871
17872 [2] Michael Keating and Pierre Bricaud.
17873 \"Reuse Methodology Manual, Second Edition\".
17874 Kluwer Academic Publishers, 1999.
17875 http://www.openmore.com/openmore/rmm2.html
17876
17877 [3] European Space Agency.
17878 \"VHDL Modelling Guidelines\".
17879 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17880
17881 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17882 to visually support naming conventions.")
17883
17884
17885 (defun vhdl-version ()
17886 "Echo the current version of VHDL Mode in the minibuffer."
17887 (interactive)
17888 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17889 (vhdl-keep-region-active))
17890
17891 (defun vhdl-doc-variable (variable)
17892 "Display VARIABLE's documentation in *Help* buffer."
17893 (interactive)
17894 (unless (featurep 'xemacs)
17895 (help-setup-xref (list #'vhdl-doc-variable variable)
17896 (called-interactively-p 'interactive)))
17897 (with-output-to-temp-buffer
17898 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17899 (princ (documentation-property variable 'variable-documentation))
17900 (with-current-buffer standard-output
17901 (help-mode))
17902 (help-print-return-message)))
17903
17904 (defun vhdl-doc-mode ()
17905 "Display VHDL Mode documentation in *Help* buffer."
17906 (interactive)
17907 (unless (featurep 'xemacs)
17908 (help-setup-xref (list #'vhdl-doc-mode)
17909 (called-interactively-p 'interactive)))
17910 (with-output-to-temp-buffer
17911 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17912 (princ mode-name)
17913 (princ " mode:\n")
17914 (princ (documentation 'vhdl-mode))
17915 (with-current-buffer standard-output
17916 (help-mode))
17917 (help-print-return-message)))
17918
17919
17920 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17921
17922 (provide 'vhdl-mode)
17923
17924 ;;; vhdl-mode.el ends here