Fix a comment whitespace typo.
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob06ffd54d2df0add9397fc2d30b32dc954dfae082
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2017 Free Software Foundation, Inc.
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
11 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
13 ;; filed in the Emacs bug reporting system against this file, a copy
14 ;; of the bug report be sent to the maintainer's email address.
16 (defconst vhdl-version "3.38.1"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2015-03-12"
20 "VHDL Mode time stamp for last update.")
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Commentary:
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
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
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Documentation
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; Emacs Versions
75 ;; this updated version was only tested on: GNU Emacs 24.1
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; Installation
80 ;; Prerequisites: GNU Emacs 20/21/22/23/24, XEmacs 20/21.
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':
86 ;; (push (expand-file-name "<directory-name>") load-path)
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
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):
97 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
98 ;; (push '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist)
100 ;; More detailed installation instructions are included in the official
101 ;; VHDL Mode distribution.
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 ;; Acknowledgments
106 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
107 ;; and Steve Grout.
109 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
110 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
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.
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.
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;;; Code:
129 (eval-when-compile (require 'cl))
130 (eval-and-compile
131 ;; Before Emacs-24.4, `pushnew' expands to runtime calls to `cl-adjoin'
132 ;; even for relatively simple cases such as used here. We only test <25
133 ;; because it's easier and sufficient.
134 (when (or (featurep 'xemacs) (< emacs-major-version 25))
135 (require 'cl)))
137 ;; Emacs 21+ handling
138 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
139 "Non-nil if GNU Emacs 21, 22, ... is used.")
140 ;; Emacs 22+ handling
141 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
142 "Non-nil if GNU Emacs 22, ... is used.")
144 (defvar compilation-file-regexp-alist)
145 (defvar conf-alist)
146 (defvar conf-entry)
147 (defvar conf-key)
148 (defvar ent-alist)
149 (defvar itimer-version)
150 (defvar lazy-lock-defer-contextually)
151 (defvar lazy-lock-defer-on-scrolling)
152 (defvar lazy-lock-defer-on-the-fly)
153 (defvar speedbar-attached-frame)
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 ;;; Variables
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
160 ;; help function for user options
161 (defun vhdl-custom-set (variable value &rest functions)
162 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
163 (if (fboundp 'custom-set-default)
164 (custom-set-default variable value)
165 (set-default variable value))
166 (while functions
167 (when (fboundp (car functions)) (funcall (car functions)))
168 (setq functions (cdr functions))))
170 (defun vhdl-widget-directory-validate (widget)
171 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
172 '/' or is empty)."
173 (let ((val (widget-value widget)))
174 (unless (string-match "^\\(\\|.*/\\)$" val)
175 (widget-put widget :error "Invalid directory entry: must end with `/'")
176 widget)))
178 ;; help string for user options
179 (defconst vhdl-name-doc-string "
181 FROM REGEXP is a regular expression matching the original name:
182 \".*\" matches the entire string
183 \"\\(...\\)\" matches a substring
184 TO STRING specifies the string to be inserted as new name:
185 \"\\&\" means substitute entire matched text
186 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
187 Examples:
188 \".*\" \"\\&\" inserts original string
189 \".*\" \"\\&_i\" attaches \"_i\" to original string
190 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
191 \".*\" \"foo\" inserts constant string \"foo\"
192 \".*\" \"\" inserts empty string")
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;; User variables (customization options)
197 (defgroup vhdl nil
198 "Customizations for VHDL Mode."
199 :prefix "vhdl-"
200 :group 'languages
201 ; :version "21.2" ; comment out for XEmacs
204 (defgroup vhdl-mode nil
205 "Customizations for modes."
206 :group 'vhdl)
208 (defcustom vhdl-indent-tabs-mode nil
209 "Non-nil means indentation can insert tabs.
210 Overrides local variable `indent-tabs-mode'."
211 :type 'boolean
212 :group 'vhdl-mode)
215 (defgroup vhdl-compile nil
216 "Customizations for compilation."
217 :group 'vhdl)
219 (defcustom vhdl-compiler-alist
221 ;; 60: docal <= false;
222 ;; ^^^^^
223 ;; [Error] Assignment error: variable is illegal target of signal assignment
224 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
225 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
226 ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("^Compiling file \\(.+\\)" 1)
227 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
228 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
229 ;; Aldec
230 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
231 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
232 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
233 ("^.* ERROR [^:]+: \".*\" \"\\([^ \t\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
234 nil)
235 ;; Cadence Leapfrog: cv -file test.vhd
236 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
237 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
238 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
239 ("^duluth: \\*E,[0-9]+ (\\([^ \t\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
240 ("\\1/entity" "\\2/\\1" "\\1/configuration"
241 "\\1/package" "\\1/body" downcase))
242 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
243 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
244 ;; (PLL_400X_TOP) is not declared [10.3].
245 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
246 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
247 ("^ncvhdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
248 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
249 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
250 ;; ghdl vhdl
251 ;; ghdl -a bad_counter.vhdl
252 ;; bad_counter.vhdl:13:14: operator "=" is overloaded
253 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
254 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
255 ("^ghdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
256 ("\\1/entity" "\\2/\\1" "\\1/configuration"
257 "\\1/package" "\\1/body" downcase))
258 ;; IBM Compiler
259 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
260 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
261 nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
262 ("^[0-9]+ COACHDL.*: File: \\([^ \t\n]+\\), *line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
263 nil)
264 ;; Ikos Voyager: analyze test.vhd
265 ;; analyze test.vhd
266 ;; E L4/C5: this library unit is inaccessible
267 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
268 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
269 ("^E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
270 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
271 nil)
272 ;; ModelSim, Model Technology: vcom test.vhd
273 ;; ERROR: test.vhd(14): Unknown identifier: positiv
274 ;; WARNING[2]: test.vhd(85): Possible infinite loop
275 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
276 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
277 ;; ** Error: counter_rtl.vhd(18): Nonresolved signal 'hallo' has multiple sources.
278 ;; Drivers:
279 ;; counter_rtl.vhd(27):Conditional signal assignment line__27
280 ;; counter_rtl.vhd(29):Conditional signal assignment line__29
281 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
282 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
283 ("\\(ERROR:\\|WARNING\\[[0-9]+\\]:\\|\\*\\* Error:\\|\\*\\* Warning: \\[[0-9]+\\]\\| +\\) \\([^ ]+\\)(\\([0-9]+\\)):" 2 3 nil)
284 ("" 0)
285 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
286 "\\1/_primary.dat" "\\1/body.dat" downcase))
287 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
288 ;; test.vhd:34: error message
289 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
290 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
291 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
292 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
293 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
294 ;; Quartus compiler
295 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
296 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
297 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
298 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
299 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
300 ("Quartus" "make" "-work \\1" "make" "-f \\1"
301 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
302 ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
303 nil)
304 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
305 ;; ERROR: test.vhd(24): near "dnd": expecting: END
306 ;; WARNING[4]: test.vhd(30): A space is required between ...
307 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
308 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
309 ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
310 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
311 "\\1/_primary.dat" "\\1/body.dat" downcase))
312 ;; Savant: scram -publish-cc test.vhd
313 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
314 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
316 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
317 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
318 "\\1_config.vhdl" "\\1_package.vhdl"
319 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
320 ;; Simili: vhdlp -work test.vhd
321 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
322 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
323 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
324 ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
325 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
326 "\\1/prim.var" "\\1/_body.var" downcase))
327 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
328 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
329 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
330 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
331 ("^ *ERROR\\[[0-9]+]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
332 nil)
333 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
334 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
335 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
336 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
337 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
338 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
339 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
340 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
341 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
342 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
343 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
344 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
345 ;; Synplify:
346 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
347 ("Synplify" "n/a" "n/a" "make" "-f \\1"
348 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
349 ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
350 nil)
351 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
352 ;; Compiling "test.vhd" line 1...
353 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
354 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
355 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
356 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
357 ("^ *Compiling \"\\(.+\\)\" " 1)
358 nil)
359 ;; VeriBest: vc vhdl test.vhd
360 ;; (no file name printed out!)
361 ;; 32: Z <= A and BitA ;
362 ;; ^^^^
363 ;; [Error] Name BITA is unknown
364 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
365 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
366 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
367 nil)
368 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
369 ;; Compiling "test.vhd" line 1...
370 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
371 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
372 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
373 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
374 ("^ *Compiling \"\\(.+\\)\" " 1)
375 nil)
376 ;; Xilinx XST:
377 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
378 ("Xilinx XST" "xflow" "" "make" "-f \\1"
379 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
380 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\\." 1 2 nil) ("" 0)
381 nil)
383 "List of available VHDL compilers and their properties.
384 Each list entry specifies the following items for a compiler:
385 Compiler:
386 Compiler name : name used in option `vhdl-compiler' to choose compiler
387 Compile command : command used for source file compilation
388 Compile options : compile options (\"\\1\" inserts library name)
389 Make command : command used for compilation using a Makefile
390 Make options : make options (\"\\1\" inserts Makefile name)
391 Generate Makefile: use built-in function or command to generate a Makefile
392 (\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
393 Library command : command to create library directory (\"\\1\" inserts
394 library directory, \"\\2\" inserts library name)
395 Compile directory: where compilation is run and the Makefile is placed
396 Library directory: directory of default library
397 Makefile name : name of Makefile (default is \"Makefile\")
398 ID string : compiler identification string (see `vhdl-project-alist')
399 Error message:
400 Regexp : regular expression to match error messages (*)
401 File subexp index: index of subexpression that matches the file name
402 Line subexp index: index of subexpression that matches the line number
403 Column subexp idx: index of subexpression that matches the column number
404 File message:
405 Regexp : regular expression to match a file name message
406 File subexp index: index of subexpression that matches the file name
407 Unit-to-file name mapping: mapping of library unit names to names of files
408 generated by the compiler (used for Makefile generation)
409 To string : string a name is mapped to (\"\\1\" inserts the unit name,
410 \"\\2\" inserts the entity name for architectures,
411 \"\\3\" inserts the library name)
412 Case adjustment : adjust case of inserted unit names
414 \(*) The regular expression must match the error message starting from the
415 beginning of the line (but not necessarily to the end of the line).
417 Compile options allows insertion of the library name (see `vhdl-project-alist')
418 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
420 For Makefile generation, the built-in function can be used (requires
421 specification of the unit-to-file name mapping). Alternatively, an
422 external command can be specified. Work directory allows specification of
423 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
424 used for Makefile generation). To use another library name than \"work\",
425 customize `vhdl-project-alist'. The library command is inserted in Makefiles
426 to automatically create the library directory if not existent.
428 Compile options, compile directory, library directory, and Makefile name are
429 overwritten by the project settings if a project is defined (see
430 `vhdl-project-alist'). Directory paths are relative to the source file
431 directory.
433 Some compilers do not include the file name in the error message, but print
434 out a file name message in advance. In this case, set \"File Subexp Index\"
435 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
436 If no file name at all is printed out, set both \"File Message\" entries to 0
437 \(a default file name message will be printed out instead, does not work in
438 XEmacs).
440 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
441 assigning its name to option `vhdl-compiler'.
443 Please send any missing or erroneous compiler properties to the maintainer for
444 updating.
446 NOTE: Activate new error and file message regexps and reflect the new setting
447 in the choice list of option `vhdl-compiler' by restarting Emacs."
448 :type '(repeat
449 (list :tag "Compiler" :indent 2
450 (string :tag "Compiler name ")
451 (string :tag "Compile command ")
452 (string :tag "Compile options " "-work \\1")
453 (string :tag "Make command " "make")
454 (string :tag "Make options " "-f \\1")
455 (choice :tag "Generate Makefile "
456 (const :tag "Built-in function" nil)
457 (string :tag "Command" "vmake \\2 > \\1"))
458 (string :tag "Library command " "mkdir \\1")
459 (directory :tag "Compile directory "
460 :validate vhdl-widget-directory-validate "./")
461 (directory :tag "Library directory "
462 :validate vhdl-widget-directory-validate "work/")
463 (file :tag "Makefile name " "Makefile")
464 (string :tag "ID string ")
465 (list :tag "Error message" :indent 4
466 (regexp :tag "Regexp ")
467 (choice :tag "File subexp "
468 (integer :tag "Index")
469 (const :tag "No file name" nil))
470 (integer :tag "Line subexp index")
471 (choice :tag "Column subexp "
472 (integer :tag "Index")
473 (const :tag "No column number" nil)))
474 (list :tag "File message" :indent 4
475 (regexp :tag "Regexp ")
476 (integer :tag "File subexp index"))
477 (choice :tag "Unit-to-file name mapping"
478 :format "%t: %[Value Menu%] %v\n"
479 (const :tag "Not defined" nil)
480 (list :tag "To string" :indent 4
481 (string :tag "Entity " "\\1.vhd")
482 (string :tag "Architecture " "\\2_\\1.vhd")
483 (string :tag "Configuration " "\\1.vhd")
484 (string :tag "Package " "\\1.vhd")
485 (string :tag "Package Body " "\\1_body.vhd")
486 (choice :tag "Case adjustment "
487 (const :tag "None" identity)
488 (const :tag "Upcase" upcase)
489 (const :tag "Downcase" downcase))))))
490 :set (lambda (variable value)
491 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
492 :version "24.4"
493 :group 'vhdl-compile)
495 (defcustom vhdl-compiler "GHDL"
496 "Specifies the VHDL compiler to be used for syntax analysis.
497 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
498 :type (let ((alist vhdl-compiler-alist) list)
499 (while alist
500 (push (list 'const (caar alist)) list)
501 (setq alist (cdr alist)))
502 (append '(choice) (nreverse list)))
503 :group 'vhdl-compile)
505 (defcustom vhdl-compile-use-local-error-regexp nil
506 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
507 In this case, only error message regexps for VHDL compilers are active if
508 compilation is started from a VHDL buffer. Otherwise, the error message
509 regexps are appended to the predefined global regexps, and all regexps are
510 active all the time. Note that by doing that, the predefined global regexps
511 might result in erroneous parsing of error messages for some VHDL compilers.
513 NOTE: Activate the new setting by restarting Emacs."
514 :version "25.1" ; t -> nil
515 :type 'boolean
516 :group 'vhdl-compile)
518 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
519 "List of default target names in Makefiles.
520 Automatically generated Makefiles include three default targets to compile
521 the entire design, clean the entire design and to create the design library.
522 This option allows you to change the names of these targets to avoid conflicts
523 with other user Makefiles."
524 :type '(list (string :tag "Compile entire design")
525 (string :tag "Clean entire design ")
526 (string :tag "Create design library"))
527 :version "24.3"
528 :group 'vhdl-compile)
530 (defcustom vhdl-makefile-generation-hook nil
531 "Functions to run at the end of Makefile generation.
532 Allows you to insert user specific parts into a Makefile.
534 Example:
535 (lambda nil
536 (re-search-backward \"^# Rule for compiling entire design\")
537 (insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
538 :type 'hook
539 :group 'vhdl-compile)
541 (defcustom vhdl-default-library "work"
542 "Name of default library.
543 Is overwritten by project settings if a project is active."
544 :type 'string
545 :group 'vhdl-compile)
548 (defgroup vhdl-project nil
549 "Customizations for projects."
550 :group 'vhdl)
552 (defcustom vhdl-project-alist
553 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
554 "~/example1/" ("src/system/" "src/components/") ""
555 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
556 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
557 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
558 ("Example 2" "Individual source files, multiple compilers in different directories"
559 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
560 nil "\\1/" "work" "\\1/work/" "Makefile" "")
561 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
562 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
563 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
564 -------------------------------------------------------------------------------
565 -- This is a multi-line project description
566 -- that can be used as a project dependent part of the file header.
568 "List of projects and their properties.
569 Name : name used in option `vhdl-project' to choose project
570 Title : title of project (single-line string)
571 Default directory: default project directory (absolute path)
572 Sources : a) source files : path + \"/\" + file name
573 b) directory : path + \"/\"
574 c) directory tree: \"-r \" + path + \"/\"
575 Exclude regexp : matches file/directory names to be excluded as sources
576 Compile options : project-specific options for each compiler
577 Compiler name : name of compiler for which these options are valid
578 Compile options: project-specific compiler options
579 (\"\\1\" inserts library name, \"\\2\" default options)
580 Make options: project-specific make options
581 (\"\\1\" inserts Makefile name, \"\\2\" default options)
582 Exceptions : file-specific exceptions
583 File name regexp: matches file names for which exceptions are valid
584 - Options : file-specific compiler options string
585 (\"\\1\" inserts library name, \"\\2\" default options,
586 \"\\3\" project-specific options)
587 - Do not compile: do not compile this file (in Makefile)
588 Compile directory: where compilation is run and the Makefile is placed
589 (\"\\1\" inserts compiler ID string)
590 Library name : name of library (default is \"work\")
591 Library directory: path to library (\"\\1\" inserts compiler ID string)
592 Makefile name : name of Makefile
593 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
594 Description : description of project (multi-line string)
596 Project title and description are used to insert into the file header (see
597 option `vhdl-file-header').
599 The default directory must have an absolute path (use `M-TAB' for completion).
600 All other paths can be absolute or relative to the default directory. All
601 paths must end with `/'.
603 The design units found in the sources (files and directories) are shown in the
604 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
605 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
606 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
607 specified, the default directory is taken as source directory. Otherwise,
608 the default directory is only taken as source directory if there is a sources
609 entry with the empty string or \"./\". Exclude regexp allows you to filter
610 out specific file and directory names from the list of sources (e.g. CVS
611 directories).
613 Files are compiled in the compile directory. Makefiles are also placed into
614 the compile directory. Library directory specifies which directory the
615 compiler compiles into (used to generate the Makefile).
617 Since different compile/library directories and Makefiles may exist for
618 different compilers within one project, these paths and names allow the
619 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
620 Compile options, compile directory, library directory, and Makefile name
621 overwrite the settings of the current compiler.
623 File-specific compiler options (highest priority) overwrite project-specific
624 options which overwrite default options (lowest priority). Lower priority
625 options can be inserted in higher priority options. This allows you to reuse
626 default options (e.g. \"-file\") in project- or file-specific options (e.g.
627 \"-93 -file\").
629 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
630 by restarting Emacs."
631 :type `(repeat
632 (list :tag "Project" :indent 2
633 (string :tag "Name ")
634 (string :tag "Title ")
635 (directory :tag "Default directory"
636 :validate vhdl-widget-directory-validate
637 ,(abbreviate-file-name default-directory))
638 (repeat :tag "Sources " :indent 4
639 (directory :format " %v" "./"))
640 (regexp :tag "Exclude regexp ")
641 (repeat
642 :tag "Compile options " :indent 4
643 (list :tag "Compiler" :indent 6
644 ,(let ((alist vhdl-compiler-alist) list)
645 (while alist
646 (push (list 'const (caar alist)) list)
647 (setq alist (cdr alist)))
648 (append '(choice :tag "Compiler name")
649 (nreverse list)))
650 (string :tag "Compile options" "\\2")
651 (string :tag "Make options " "\\2")
652 (repeat
653 :tag "Exceptions " :indent 8
654 (cons :format "%v"
655 (regexp :tag "File name regexp ")
656 (choice :format "%[Value Menu%] %v"
657 (string :tag "Options" "\\3")
658 (const :tag "Do not compile" nil))))))
659 (directory :tag "Compile directory"
660 :validate vhdl-widget-directory-validate "./")
661 (string :tag "Library name " "work")
662 (directory :tag "Library directory"
663 :validate vhdl-widget-directory-validate "work/")
664 (file :tag "Makefile name " "Makefile")
665 (string :tag "Description: (type `C-j' for newline)"
666 :format "%t\n%v\n")))
667 :set (lambda (variable value)
668 (vhdl-custom-set variable value
669 'vhdl-update-mode-menu
670 'vhdl-speedbar-refresh))
671 :group 'vhdl-project)
673 (defcustom vhdl-project nil
674 "Specifies the default for the current project.
675 Select a project name from the ones defined in option `vhdl-project-alist'.
676 Is used to determine the project title and description to be inserted in file
677 headers and the source files/directories to be scanned in the hierarchy
678 browser. The current project can also be changed temporarily in the menu."
679 :type (let ((alist vhdl-project-alist) list)
680 (while alist
681 (push (list 'const (caar alist)) list)
682 (setq alist (cdr alist)))
683 (append '(choice (const :tag "None" nil) (const :tag "--"))
684 (nreverse list)))
685 :group 'vhdl-project)
687 (defcustom vhdl-project-file-name '("\\1.prj")
688 "List of file names/paths for importing/exporting project setups.
689 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
690 replaced by the user name (allows you to have user-specific project setups).
691 The first entry is used as file name to import/export individual project
692 setups. All entries are used to automatically import project setups at
693 startup (see option `vhdl-project-auto-load'). Projects loaded from the
694 first entry are automatically made current. Hint: specify local project
695 setups in first entry, global setups in following entries; loading a local
696 project setup will make it current, while loading the global setups
697 is done without changing the current project.
698 Names can also have an absolute path (i.e. project setups can be stored
699 in global directories)."
700 :type '(repeat (string :tag "File name" "\\1.prj"))
701 :group 'vhdl-project)
703 (defcustom vhdl-project-auto-load '(startup)
704 "Automatically load project setups from files.
705 All project setup files that match the file names specified in option
706 `vhdl-project-file-name' are automatically loaded. The project of the
707 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
708 entry is activated.
709 A project setup file can be obtained by exporting a project (see menu).
710 At startup: project setup file is loaded at Emacs startup"
711 :type '(set (const :tag "At startup" startup))
712 :group 'vhdl-project)
714 (defcustom vhdl-project-sort t
715 "Non-nil means projects are displayed in alphabetical order."
716 :type 'boolean
717 :group 'vhdl-project)
720 (defgroup vhdl-style nil
721 "Customizations for coding styles."
722 :group 'vhdl
723 :group 'vhdl-template
724 :group 'vhdl-port
725 :group 'vhdl-compose)
727 (defcustom vhdl-standard '(93 nil)
728 "VHDL standards used.
729 Basic standard:
730 VHDL'87 : IEEE Std 1076-1987
731 VHDL'93/02 : IEEE Std 1076-1993/2002
732 VHDL'08 : IEEE Std 1076-2008
733 Additional standards:
734 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
735 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
737 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
738 \"Activate Options\"."
739 :type '(list (choice :tag "Basic standard"
740 (const :tag "VHDL'87" 87)
741 (const :tag "VHDL'93/02" 93)
742 (const :tag "VHDL'08" 08))
743 (set :tag "Additional standards" :indent 2
744 (const :tag "VHDL-AMS" ams)
745 (const :tag "Math packages" math)))
746 :set (lambda (variable value)
747 (vhdl-custom-set variable value
748 'vhdl-template-map-init
749 'vhdl-mode-abbrev-table-init
750 'vhdl-template-construct-alist-init
751 'vhdl-template-package-alist-init
752 'vhdl-update-mode-menu
753 'vhdl-words-init 'vhdl-font-lock-init))
754 :group 'vhdl-style)
756 (defcustom vhdl-basic-offset 2
757 "Amount of basic offset used for indentation.
758 This value is used by + and - symbols in `vhdl-offsets-alist'."
759 :type 'integer
760 :group 'vhdl-style)
762 (defcustom vhdl-upper-case-keywords nil
763 "Non-nil means convert keywords to upper case.
764 This is done when typed or expanded or by the fix case functions."
765 :type 'boolean
766 :set (lambda (variable value)
767 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
768 :group 'vhdl-style)
770 (defcustom vhdl-upper-case-types nil
771 "Non-nil means convert standardized types to upper case.
772 This is done when expanded or by the fix case functions."
773 :type 'boolean
774 :set (lambda (variable value)
775 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
776 :group 'vhdl-style)
778 (defcustom vhdl-upper-case-attributes nil
779 "Non-nil means convert standardized attributes to upper case.
780 This is done when expanded or by the fix case functions."
781 :type 'boolean
782 :set (lambda (variable value)
783 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
784 :group 'vhdl-style)
786 (defcustom vhdl-upper-case-enum-values nil
787 "Non-nil means convert standardized enumeration values to upper case.
788 This is done when expanded or by the fix case functions."
789 :type 'boolean
790 :set (lambda (variable value)
791 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
792 :group 'vhdl-style)
794 (defcustom vhdl-upper-case-constants t
795 "Non-nil means convert standardized constants to upper case.
796 This is done when expanded."
797 :type 'boolean
798 :set (lambda (variable value)
799 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
800 :group 'vhdl-style)
802 (defcustom vhdl-use-direct-instantiation 'standard
803 "Non-nil means use VHDL'93 direct component instantiation.
804 Never : never
805 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
806 Always : always"
807 :type '(choice (const :tag "Never" never)
808 (const :tag "Standard" standard)
809 (const :tag "Always" always))
810 :group 'vhdl-style)
812 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
813 "Non-nil means include array indices / record fields in sensitivity list.
814 If a signal read in a process is a record field or pointed to by an array
815 index, the record field or array index is included with the record name in
816 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
817 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
818 :type 'boolean
819 :version "24.3"
820 :group 'vhdl-style)
822 (defgroup vhdl-naming nil
823 "Customizations for naming conventions."
824 :group 'vhdl)
826 (defcustom vhdl-entity-file-name '(".*" . "\\&")
827 (concat
828 "Specifies how the entity file name is obtained.
829 The entity file name can be obtained by modifying the entity name (e.g.
830 attaching or stripping off a substring). The file extension is automatically
831 taken from the file name of the current buffer."
832 vhdl-name-doc-string)
833 :type '(cons (regexp :tag "From regexp")
834 (string :tag "To string "))
835 :group 'vhdl-naming
836 :group 'vhdl-compose)
838 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
839 (concat
840 "Specifies how the architecture file name is obtained.
841 The architecture file name can be obtained by modifying the entity
842 and/or architecture name (e.g. attaching or stripping off a substring). The
843 file extension is automatically taken from the file name of the current
844 buffer. The string that is matched against the regexp is the concatenation
845 of the entity and the architecture name separated by a space. This gives
846 access to both names (see default setting as example)."
847 vhdl-name-doc-string)
848 :type '(cons (regexp :tag "From regexp")
849 (string :tag "To string "))
850 :group 'vhdl-naming
851 :group 'vhdl-compose)
853 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
854 (concat
855 "Specifies how the configuration file name is obtained.
856 The configuration file name can be obtained by modifying the configuration
857 name (e.g. attaching or stripping off a substring). The file extension is
858 automatically taken from the file name of the current buffer."
859 vhdl-name-doc-string)
860 :type '(cons (regexp :tag "From regexp")
861 (string :tag "To string "))
862 :group 'vhdl-naming
863 :group 'vhdl-compose)
865 (defcustom vhdl-package-file-name '(".*" . "\\&")
866 (concat
867 "Specifies how the package file name is obtained.
868 The package file name can be obtained by modifying the package name (e.g.
869 attaching or stripping off a substring). The file extension is automatically
870 taken from the file name of the current buffer. Package files can be created
871 in a different directory by prepending a relative or absolute path to the
872 file name."
873 vhdl-name-doc-string)
874 :type '(cons (regexp :tag "From regexp")
875 (string :tag "To string "))
876 :group 'vhdl-naming
877 :group 'vhdl-compose)
879 (defcustom vhdl-file-name-case 'identity
880 "Specifies how to change case for obtaining file names.
881 When deriving a file name from a VHDL unit name, case can be changed as
882 follows:
883 As Is: case is not changed (taken as is)
884 Lower Case: whole name is changed to lower case
885 Upper Case: whole name is changed to upper case
886 Capitalize: first letter of each word in name is capitalized"
887 :type '(choice (const :tag "As Is" identity)
888 (const :tag "Lower Case" downcase)
889 (const :tag "Upper Case" upcase)
890 (const :tag "Capitalize" capitalize))
891 :group 'vhdl-naming
892 :group 'vhdl-compose)
895 (defgroup vhdl-template nil
896 "Customizations for electrification."
897 :group 'vhdl)
899 (defcustom vhdl-electric-keywords '(vhdl user)
900 "Type of keywords for which electrification is enabled.
901 VHDL keywords: invoke built-in templates
902 User keywords: invoke user models (see option `vhdl-model-alist')"
903 :type '(set (const :tag "VHDL keywords" vhdl)
904 (const :tag "User model keywords" user))
905 :set (lambda (variable value)
906 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
907 :group 'vhdl-template)
909 (defcustom vhdl-optional-labels 'process
910 "Constructs for which labels are to be queried.
911 Template generators prompt for optional labels for:
912 None : no constructs
913 Processes only: processes only (also procedurals in VHDL-AMS)
914 All constructs: all constructs with optional labels and keyword END"
915 :type '(choice (const :tag "None" none)
916 (const :tag "Processes only" process)
917 (const :tag "All constructs" all))
918 :group 'vhdl-template)
920 (defcustom vhdl-insert-empty-lines 'unit
921 "Specifies whether to insert empty lines in some templates.
922 This improves readability of code. Empty lines are inserted in:
923 None : no constructs
924 Design units only: entities, architectures, configurations, packages only
925 All constructs : also all constructs with BEGIN...END parts
927 Replaces option `vhdl-additional-empty-lines'."
928 :type '(choice (const :tag "None" none)
929 (const :tag "Design units only" unit)
930 (const :tag "All constructs" all))
931 :group 'vhdl-template
932 :group 'vhdl-port
933 :group 'vhdl-compose)
935 (defcustom vhdl-argument-list-indent nil
936 "Non-nil means indent argument lists relative to opening parenthesis.
937 That is, argument, association, and port lists start on the same line as the
938 opening parenthesis and subsequent lines are indented accordingly.
939 Otherwise, lists start on a new line and are indented as normal code."
940 :type 'boolean
941 :group 'vhdl-template
942 :group 'vhdl-port
943 :group 'vhdl-compose)
945 (defcustom vhdl-association-list-with-formals t
946 "Non-nil means write association lists with formal parameters.
947 Templates prompt for formal and actual parameters (ports/generics).
948 When pasting component instantiations, formals are included.
949 If nil, only a list of actual parameters is entered."
950 :type 'boolean
951 :group 'vhdl-template
952 :group 'vhdl-port
953 :group 'vhdl-compose)
955 (defcustom vhdl-conditions-in-parenthesis nil
956 "Non-nil means place parenthesis around condition expressions."
957 :type 'boolean
958 :group 'vhdl-template)
960 (defcustom vhdl-sensitivity-list-all t
961 "Non-nil means use `all' keyword in sensitivity list."
962 :version "25.1"
963 :type 'boolean
964 :group 'vhdl-template)
966 (defcustom vhdl-zero-string "'0'"
967 "String to use for a logic zero."
968 :type 'string
969 :group 'vhdl-template)
971 (defcustom vhdl-one-string "'1'"
972 "String to use for a logic one."
973 :type 'string
974 :group 'vhdl-template)
977 (defgroup vhdl-header nil
978 "Customizations for file header."
979 :group 'vhdl-template
980 :group 'vhdl-compose)
982 (defcustom vhdl-file-header "\
983 -------------------------------------------------------------------------------
984 -- Title : <title string>
985 -- Project : <project>
986 -------------------------------------------------------------------------------
987 -- File : <filename>
988 -- Author : <author>
989 -- Company : <company>
990 -- Created : <date>
991 -- Last update: <date>
992 -- Platform : <platform>
993 -- Standard : <standard>
994 <projectdesc>-------------------------------------------------------------------------------
995 -- Description: <cursor>
996 <copyright>-------------------------------------------------------------------------------
997 -- Revisions :
998 -- Date Version Author Description
999 -- <date> 1.0 <login>\tCreated
1000 -------------------------------------------------------------------------------
1003 "String or file to insert as file header.
1004 If the string specifies an existing file name, the contents of the file is
1005 inserted, otherwise the string itself is inserted as file header.
1006 Type `C-j' for newlines.
1007 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
1008 if the header needs to be version controlled.
1010 The following keywords for template generation are supported:
1011 <filename> : replaced by the name of the buffer
1012 <author> : replaced by the user name and email address
1013 (`user-full-name', `user-mail-address')
1014 <authorfull> : replaced by the user full name (`user-full-name')
1015 <login> : replaced by user login name (`user-login-name')
1016 <company> : replaced by contents of option `vhdl-company-name'
1017 <date> : replaced by the current date
1018 <year> : replaced by the current year
1019 <project> : replaced by title of current project (`vhdl-project')
1020 <projectdesc> : replaced by description of current project (`vhdl-project')
1021 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1022 <platform> : replaced by contents of option `vhdl-platform-spec'
1023 <standard> : replaced by the VHDL language standard(s) used
1024 <... string> : replaced by a queried string (\"...\" is the prompt word)
1025 <title string>: replaced by file title in automatically generated files
1026 <cursor> : final cursor position
1028 The (multi-line) project description <projectdesc> can be used as a project
1029 dependent part of the file header and can also contain the above keywords."
1030 :type 'string
1031 :group 'vhdl-header)
1033 (defcustom vhdl-file-footer ""
1034 "String or file to insert as file footer.
1035 If the string specifies an existing file name, the contents of the file is
1036 inserted, otherwise the string itself is inserted as file footer (i.e. at
1037 the end of the file).
1038 Type `C-j' for newlines.
1039 The same keywords as in option `vhdl-file-header' can be used."
1040 :type 'string
1041 :group 'vhdl-header)
1043 (defcustom vhdl-company-name ""
1044 "Name of company to insert in file header.
1045 See option `vhdl-file-header'."
1046 :type 'string
1047 :group 'vhdl-header)
1049 (defcustom vhdl-copyright-string "\
1050 -------------------------------------------------------------------------------
1051 -- Copyright (c) <year> <company>
1053 "Copyright string to insert in file header.
1054 Can be multi-line string (type `C-j' for newline) and contain other file
1055 header keywords (see option `vhdl-file-header')."
1056 :type 'string
1057 :group 'vhdl-header)
1059 (defcustom vhdl-platform-spec ""
1060 "Specification of VHDL platform to insert in file header.
1061 The platform specification should contain names and versions of the
1062 simulation and synthesis tools used.
1063 See option `vhdl-file-header'."
1064 :type 'string
1065 :group 'vhdl-header)
1067 (defcustom vhdl-date-format "%Y-%m-%d"
1068 "Specifies the date format to use in the header.
1069 This string is passed as argument to the command `format-time-string'.
1070 For more information on format strings, see the documentation for the
1071 `format-time-string' command (C-h f `format-time-string')."
1072 :type 'string
1073 :group 'vhdl-header)
1075 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1076 "Prefix string of modification date in VHDL file header.
1077 If actualization of the modification date is called (menu,
1078 `\\[vhdl-template-modify]'), this string is searched and the rest
1079 of the line replaced by the current date."
1080 :type 'string
1081 :group 'vhdl-header)
1083 (defcustom vhdl-modify-date-on-saving t
1084 "Non-nil means update the modification date when the buffer is saved.
1085 Calls function `\\[vhdl-template-modify]').
1087 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1088 \"Activate Options\"."
1089 :type 'boolean
1090 :group 'vhdl-header)
1093 (defgroup vhdl-sequential-process nil
1094 "Customizations for sequential processes."
1095 :group 'vhdl-template)
1097 (defcustom vhdl-reset-kind 'async
1098 "Specifies which kind of reset to use in sequential processes."
1099 :type '(choice (const :tag "None" none)
1100 (const :tag "Synchronous" sync)
1101 (const :tag "Asynchronous" async)
1102 (const :tag "Query" query))
1103 :group 'vhdl-sequential-process)
1105 (defcustom vhdl-reset-active-high nil
1106 "Non-nil means reset in sequential processes is active high.
1107 Otherwise, reset is active low."
1108 :type 'boolean
1109 :group 'vhdl-sequential-process)
1111 (defcustom vhdl-clock-rising-edge t
1112 "Non-nil means rising edge of clock triggers sequential processes.
1113 Otherwise, falling edge triggers."
1114 :type 'boolean
1115 :group 'vhdl-sequential-process)
1117 (defcustom vhdl-clock-edge-condition 'standard
1118 "Syntax of the clock edge condition.
1119 Standard: \"clk\\='event and clk = \\='1\\='\"
1120 Function: \"rising_edge(clk)\""
1121 :type '(choice (const :tag "Standard" standard)
1122 (const :tag "Function" function))
1123 :group 'vhdl-sequential-process)
1125 (defcustom vhdl-clock-name ""
1126 "Name of clock signal to use in templates."
1127 :type 'string
1128 :group 'vhdl-sequential-process)
1130 (defcustom vhdl-reset-name ""
1131 "Name of reset signal to use in templates."
1132 :type 'string
1133 :group 'vhdl-sequential-process)
1136 (defgroup vhdl-model nil
1137 "Customizations for user models."
1138 :group 'vhdl)
1140 (defcustom vhdl-model-alist
1141 '(("Example Model"
1142 "<label> : process (<clock>, <reset>)
1143 begin -- process <label>
1144 if <reset> = '0' then -- asynchronous reset (active low)
1145 <cursor>
1146 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1147 if <enable> = '1' then -- synchronous load
1149 end if;
1150 end if;
1151 end process <label>;"
1152 "e" ""))
1153 "List of user models.
1154 VHDL models (templates) can be specified by the user in this list. They can be
1155 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1156 electrification (i.e. overriding existing or creating new keywords, see
1157 option `vhdl-electric-keywords').
1158 Name : name of model (string of words and spaces)
1159 String : string or name of file to be inserted as model (newline: `C-j')
1160 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1161 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1162 Keyword : keyword to invoke model
1164 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1165 A prompt that appears several times is queried once and replaced throughout
1166 the model. Special prompts are:
1167 <clock> : name specified in `vhdl-clock-name' (if not empty)
1168 <reset> : name specified in `vhdl-reset-name' (if not empty)
1169 <cursor>: final cursor position
1170 File header prompts (see variable `vhdl-file-header') are automatically
1171 replaced, so that user models can also be used to insert different types of
1172 headers.
1174 If the string specifies an existing file name, the contents of the file is
1175 inserted, otherwise the string itself is inserted.
1176 The code within the models should be correctly indented.
1177 Type `C-j' for newlines.
1179 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1180 \"Activate Options\"."
1181 :type '(repeat (list :tag "Model" :indent 2
1182 (string :tag "Name ")
1183 (string :tag "String : (type `C-j' for newline)"
1184 :format "%t\n%v")
1185 (sexp :tag "Key binding" x)
1186 (string :tag "Keyword " :format "%t: %v\n")))
1187 :set (lambda (variable value)
1188 (vhdl-custom-set variable value
1189 'vhdl-model-map-init
1190 'vhdl-model-defun
1191 'vhdl-mode-abbrev-table-init
1192 'vhdl-update-mode-menu))
1193 :group 'vhdl-model)
1196 (defgroup vhdl-compose nil
1197 "Customizations for structural composition."
1198 :group 'vhdl)
1200 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1201 (concat
1202 "Specifies how the component architecture name is obtained.
1203 The component architecture name can be obtained by modifying the entity name
1204 \(e.g. attaching or stripping off a substring).
1205 If TO STRING is empty, the architecture name is queried."
1206 vhdl-name-doc-string)
1207 :type '(cons (regexp :tag "From regexp")
1208 (string :tag "To string "))
1209 :group 'vhdl-compose)
1211 (defcustom vhdl-compose-configuration-name
1212 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1213 (concat
1214 "Specifies how the configuration name is obtained.
1215 The configuration name can be obtained by modifying the entity and/or
1216 architecture name (e.g. attaching or stripping off a substring). The string
1217 that is matched against the regexp is the concatenation of the entity and the
1218 architecture name separated by a space. This gives access to both names (see
1219 default setting as example)."
1220 vhdl-name-doc-string)
1221 :type '(cons (regexp :tag "From regexp")
1222 (string :tag "To string "))
1223 :group 'vhdl-compose)
1225 (defcustom vhdl-components-package-name
1226 '((".*" . "\\&_components") . "components")
1227 (concat
1228 "Specifies how the name for the components package is obtained.
1229 The components package is a package containing all component declarations for
1230 the current design. Its name can be obtained by modifying the project name
1231 \(e.g. attaching or stripping off a substring). If no project is defined, the
1232 DIRECTORY entry is chosen."
1233 vhdl-name-doc-string)
1234 :type '(cons (cons :tag "Project" :indent 2
1235 (regexp :tag "From regexp")
1236 (string :tag "To string "))
1237 (string :tag "Directory:\n String "))
1238 :group 'vhdl-compose)
1240 (defcustom vhdl-use-components-package nil
1241 "Non-nil means use a separate components package for component declarations.
1242 Otherwise, component declarations are inserted and searched for in the
1243 architecture declarative parts."
1244 :type 'boolean
1245 :group 'vhdl-compose)
1247 (defcustom vhdl-compose-include-header t
1248 "Non-nil means include a header in automatically generated files."
1249 :type 'boolean
1250 :group 'vhdl-compose)
1252 (defcustom vhdl-compose-create-files 'single
1253 "Specifies whether new files should be created for the new component.
1254 The component's entity and architecture are inserted:
1255 None : in current buffer
1256 Single file : in new single file
1257 Separate files: in two separate files
1258 The file names are obtained from variables `vhdl-entity-file-name' and
1259 `vhdl-architecture-file-name'."
1260 :type '(choice (const :tag "None" none)
1261 (const :tag "Single file" single)
1262 (const :tag "Separate files" separate))
1263 :group 'vhdl-compose)
1265 (defcustom vhdl-compose-configuration-create-file nil
1266 "Specifies whether a new file should be created for the configuration.
1267 If non-nil, a new file is created for the configuration.
1268 The file name is obtained from variable `vhdl-configuration-file-name'."
1269 :type 'boolean
1270 :group 'vhdl-compose)
1272 (defcustom vhdl-compose-configuration-hierarchical t
1273 "Specifies whether hierarchical configurations should be created.
1274 If non-nil, automatically created configurations are hierarchical and include
1275 the whole hierarchy of subcomponents. Otherwise the configuration only
1276 includes one level of subcomponents."
1277 :type 'boolean
1278 :group 'vhdl-compose)
1280 (defcustom vhdl-compose-configuration-use-subconfiguration t
1281 "Specifies whether subconfigurations should be used inside configurations.
1282 If non-nil, automatically created configurations use configurations in binding
1283 indications for subcomponents, if such configurations exist. Otherwise,
1284 entities are used in binding indications for subcomponents."
1285 :type 'boolean
1286 :group 'vhdl-compose)
1289 (defgroup vhdl-port nil
1290 "Customizations for port translation functions."
1291 :group 'vhdl
1292 :group 'vhdl-compose)
1294 (defcustom vhdl-include-port-comments nil
1295 "Non-nil means include port comments when a port is pasted."
1296 :type 'boolean
1297 :group 'vhdl-port)
1299 (defcustom vhdl-include-direction-comments nil
1300 "Non-nil means include port direction in instantiations as comments."
1301 :type 'boolean
1302 :group 'vhdl-port)
1304 (defcustom vhdl-include-type-comments nil
1305 "Non-nil means include generic/port type in instantiations as comments."
1306 :type 'boolean
1307 :group 'vhdl-port)
1309 (defcustom vhdl-include-group-comments 'never
1310 "Specifies whether to include group comments and spacings.
1311 The comments and empty lines between groups of ports are pasted:
1312 Never : never
1313 Declarations: in entity/component/constant/signal declarations only
1314 Always : also in generic/port maps"
1315 :type '(choice (const :tag "Never" never)
1316 (const :tag "Declarations" decl)
1317 (const :tag "Always" always))
1318 :group 'vhdl-port)
1320 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1321 (concat
1322 "Specifies how actual generic names are obtained from formal generic names.
1323 In a component instantiation, an actual generic name can be
1324 obtained by modifying the formal generic name (e.g. attaching or stripping
1325 off a substring)."
1326 vhdl-name-doc-string)
1327 :type '(cons (regexp :tag "From regexp")
1328 (string :tag "To string "))
1329 :group 'vhdl-port
1330 :version "24.4")
1332 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1333 (concat
1334 "Specifies how actual port names are obtained from formal port names.
1335 In a component instantiation, an actual port name can be obtained by
1336 modifying the formal port name (e.g. attaching or stripping off a substring)."
1337 vhdl-name-doc-string)
1338 :type '(cons (regexp :tag "From regexp")
1339 (string :tag "To string "))
1340 :group 'vhdl-port)
1342 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1343 (concat
1344 "Specifies how an instance name is obtained.
1345 The instance name can be obtained by modifying the name of the component to be
1346 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1347 by a unique number (starting with 1).
1348 If TO STRING is empty, the instance name is queried."
1349 vhdl-name-doc-string)
1350 :type '(cons (regexp :tag "From regexp")
1351 (string :tag "To string "))
1352 :group 'vhdl-port)
1355 (defgroup vhdl-testbench nil
1356 "Customizations for testbench generation."
1357 :group 'vhdl-port)
1359 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1360 (concat
1361 "Specifies how the testbench entity name is obtained.
1362 The entity name of a testbench can be obtained by modifying the name of
1363 the component to be tested (e.g. attaching or stripping off a substring)."
1364 vhdl-name-doc-string)
1365 :type '(cons (regexp :tag "From regexp")
1366 (string :tag "To string "))
1367 :group 'vhdl-testbench)
1369 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1370 (concat
1371 "Specifies how the testbench architecture name is obtained.
1372 The testbench architecture name can be obtained by modifying the name of
1373 the component to be tested (e.g. attaching or stripping off a substring).
1374 If TO STRING is empty, the architecture name is queried."
1375 vhdl-name-doc-string)
1376 :type '(cons (regexp :tag "From regexp")
1377 (string :tag "To string "))
1378 :group 'vhdl-testbench)
1380 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1381 (concat
1382 "Specifies how the testbench configuration name is obtained.
1383 The configuration name of a testbench can be obtained by modifying the entity
1384 and/or architecture name (e.g. attaching or stripping off a substring). The
1385 string that is matched against the regexp is the concatenation of the entity
1386 and the architecture name separated by a space. This gives access to both
1387 names (see default setting as example)."
1388 vhdl-name-doc-string)
1389 :type '(cons (regexp :tag "From regexp")
1390 (string :tag "To string "))
1391 :group 'vhdl-testbench)
1393 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1394 (concat
1395 "Specifies how a DUT instance name is obtained.
1396 The design-under-test instance name (i.e. the component instantiated in the
1397 testbench) can be obtained by modifying the component name (e.g. attaching
1398 or stripping off a substring)."
1399 vhdl-name-doc-string)
1400 :type '(cons (regexp :tag "From regexp")
1401 (string :tag "To string "))
1402 :group 'vhdl-testbench)
1404 (defcustom vhdl-testbench-include-header t
1405 "Non-nil means include a header in automatically generated files."
1406 :type 'boolean
1407 :group 'vhdl-testbench)
1409 (defcustom vhdl-testbench-declarations "\
1410 -- clock
1411 signal Clk : std_logic := '1';
1413 "String or file to be inserted in the testbench declarative part.
1414 If the string specifies an existing file name, the contents of the file is
1415 inserted, otherwise the string itself is inserted in the testbench
1416 architecture before the BEGIN keyword.
1417 Type `C-j' for newlines."
1418 :type 'string
1419 :group 'vhdl-testbench)
1421 (defcustom vhdl-testbench-statements "\
1422 -- clock generation
1423 Clk <= not Clk after 10 ns;
1425 -- waveform generation
1426 WaveGen_Proc: process
1427 begin
1428 -- insert signal assignments here
1430 wait until Clk = '1';
1431 end process WaveGen_Proc;
1433 "String or file to be inserted in the testbench statement part.
1434 If the string specifies an existing file name, the contents of the file is
1435 inserted, otherwise the string itself is inserted in the testbench
1436 architecture before the END keyword.
1437 Type `C-j' for newlines."
1438 :type 'string
1439 :group 'vhdl-testbench)
1441 (defcustom vhdl-testbench-initialize-signals nil
1442 "Non-nil means initialize signals with `0' when declared in testbench."
1443 :type 'boolean
1444 :group 'vhdl-testbench)
1446 (defcustom vhdl-testbench-include-library t
1447 "Non-nil means a library/use clause for std_logic_1164 is included."
1448 :type 'boolean
1449 :group 'vhdl-testbench)
1451 (defcustom vhdl-testbench-include-configuration t
1452 "Non-nil means a testbench configuration is attached at the end."
1453 :type 'boolean
1454 :group 'vhdl-testbench)
1456 (defcustom vhdl-testbench-create-files 'single
1457 "Specifies whether new files should be created for the testbench.
1458 testbench entity and architecture are inserted:
1459 None : in current buffer
1460 Single file : in new single file
1461 Separate files: in two separate files
1462 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1463 and `vhdl-testbench-architecture-file-name'."
1464 :type '(choice (const :tag "None" none)
1465 (const :tag "Single file" single)
1466 (const :tag "Separate files" separate))
1467 :group 'vhdl-testbench)
1469 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1470 (concat
1471 "Specifies how the testbench entity file name is obtained.
1472 The entity file name can be obtained by modifying the testbench entity name
1473 \(e.g. attaching or stripping off a substring). The file extension is
1474 automatically taken from the file name of the current buffer. Testbench
1475 files can be created in a different directory by prepending a relative or
1476 absolute path to the file name."
1477 vhdl-name-doc-string)
1478 :type '(cons (regexp :tag "From regexp")
1479 (string :tag "To string "))
1480 :group 'vhdl-testbench)
1482 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1483 (concat
1484 "Specifies how the testbench architecture file name is obtained.
1485 The architecture file name can be obtained by modifying the testbench entity
1486 and/or architecture name (e.g. attaching or stripping off a substring). The
1487 string that is matched against the regexp is the concatenation of the entity
1488 and the architecture name separated by a space. This gives access to both
1489 names (see default setting as example). Testbench files can be created in
1490 a different directory by prepending a relative or absolute path to the file
1491 name."
1492 vhdl-name-doc-string)
1493 :type '(cons (regexp :tag "From regexp")
1494 (string :tag "To string "))
1495 :group 'vhdl-testbench)
1498 (defgroup vhdl-comment nil
1499 "Customizations for comments."
1500 :group 'vhdl)
1502 (defcustom vhdl-self-insert-comments t
1503 "Non-nil means various templates automatically insert help comments."
1504 :type 'boolean
1505 :group 'vhdl-comment)
1507 (defcustom vhdl-prompt-for-comments t
1508 "Non-nil means various templates prompt for user definable comments."
1509 :type 'boolean
1510 :group 'vhdl-comment)
1512 (defcustom vhdl-inline-comment-column 40
1513 "Column to indent and align inline comments to.
1514 Overrides local option `comment-column'.
1516 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1517 \"Activate Options\"."
1518 :type 'integer
1519 :group 'vhdl-comment)
1521 (defcustom vhdl-end-comment-column 79
1522 "End of comment column.
1523 Comments that exceed this column number are wrapped.
1525 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1526 \"Activate Options\"."
1527 :type 'integer
1528 :group 'vhdl-comment)
1530 (defvar end-comment-column)
1533 (defgroup vhdl-beautify nil
1534 "Customizations for beautification."
1535 :group 'vhdl)
1537 (defcustom vhdl-auto-align t
1538 "Non-nil means align some templates automatically after generation."
1539 :type 'boolean
1540 :group 'vhdl-beautify)
1542 (defcustom vhdl-align-groups t
1543 "Non-nil means align groups of code lines separately.
1544 A group of code lines is a region of consecutive lines between two lines that
1545 match the regexp in option `vhdl-align-group-separate'."
1546 :type 'boolean
1547 :group 'vhdl-beautify)
1549 (defcustom vhdl-align-group-separate "^\\s-*$"
1550 "Regexp for matching a line that separates groups of lines for alignment.
1551 Examples:
1552 \"^\\s-*$\": matches an empty line
1553 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1554 :type 'regexp
1555 :group 'vhdl-beautify)
1557 (defcustom vhdl-align-same-indent t
1558 "Non-nil means align blocks with same indent separately.
1559 When a region or the entire buffer is aligned, the code is divided into
1560 blocks of same indent which are aligned separately (except for argument/port
1561 lists). This gives nicer alignment in most cases.
1562 Option `vhdl-align-groups' still applies within these blocks."
1563 :type 'boolean
1564 :group 'vhdl-beautify)
1566 (defcustom vhdl-beautify-options '(t t t t t)
1567 "List of options for beautifying code.
1568 Allows you to disable individual features of code beautification."
1569 :type '(list (boolean :tag "Whitespace cleanup ")
1570 (boolean :tag "Single statement per line")
1571 (boolean :tag "Indentation ")
1572 (boolean :tag "Alignment ")
1573 (boolean :tag "Case fixing "))
1574 :group 'vhdl-beautify
1575 :version "24.4")
1578 (defgroup vhdl-highlight nil
1579 "Customizations for highlighting."
1580 :group 'vhdl)
1582 (defcustom vhdl-highlight-keywords t
1583 "Non-nil means highlight VHDL keywords and other standardized words.
1584 The following faces are used:
1585 `font-lock-keyword-face' : keywords
1586 `font-lock-type-face' : standardized types
1587 `vhdl-font-lock-attribute-face': standardized attributes
1588 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1589 `vhdl-font-lock-function-face' : standardized function and package names
1591 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1592 entry \"Fontify Buffer\")."
1593 :type 'boolean
1594 :set (lambda (variable value)
1595 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1596 :group 'vhdl-highlight)
1598 (defcustom vhdl-highlight-names t
1599 "Non-nil means highlight declaration names and construct labels.
1600 The following faces are used:
1601 `font-lock-function-name-face' : names in declarations of units,
1602 subprograms, components, as well as labels of VHDL constructs
1603 `font-lock-type-face' : names in type/nature declarations
1604 `vhdl-font-lock-attribute-face': names in attribute declarations
1605 `font-lock-variable-name-face' : names in declarations of signals,
1606 variables, constants, subprogram parameters, generics, and ports
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)
1615 (defcustom vhdl-highlight-special-words nil
1616 "Non-nil means highlight words with special syntax.
1617 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1618 are highlighted accordingly.
1619 Can be used for visual support of naming conventions.
1621 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1622 entry \"Fontify Buffer\")."
1623 :type 'boolean
1624 :set (lambda (variable value)
1625 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1626 :group 'vhdl-highlight)
1628 (defcustom vhdl-highlight-forbidden-words nil
1629 "Non-nil means highlight forbidden words.
1630 The reserved words specified in option `vhdl-forbidden-words' or having the
1631 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1632 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1633 use them.
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)
1643 (defcustom vhdl-highlight-verilog-keywords nil
1644 "Non-nil means highlight Verilog keywords as reserved words.
1645 Verilog keywords are highlighted in a warning color (face
1646 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1648 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1649 entry \"Fontify Buffer\")."
1650 :type 'boolean
1651 :set (lambda (variable value)
1652 (vhdl-custom-set variable value
1653 'vhdl-words-init 'vhdl-font-lock-init))
1654 :group 'vhdl-highlight)
1656 (defcustom vhdl-highlight-translate-off nil
1657 "Non-nil means background-highlight code excluded from translation.
1658 That is, all code between \"-- pragma translate_off\" and
1659 \"-- pragma translate_on\" is highlighted using a different background color
1660 \(face `vhdl-font-lock-translate-off-face').
1661 Note: this might slow down on-the-fly fontification (and thus editing).
1663 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1664 entry \"Fontify Buffer\")."
1665 :type 'boolean
1666 :set (lambda (variable value)
1667 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1668 :group 'vhdl-highlight)
1670 (defcustom vhdl-highlight-case-sensitive nil
1671 "Non-nil means consider case for highlighting.
1672 Possible trade-off:
1673 non-nil also upper-case VHDL words are highlighted, but case of words with
1674 special syntax is not considered
1675 nil only lower-case VHDL words are highlighted, but case of words with
1676 special syntax is considered
1677 Overrides local option `font-lock-keywords-case-fold-search'.
1679 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1680 entry \"Fontify Buffer\")."
1681 :type 'boolean
1682 :group 'vhdl-highlight)
1684 (defcustom vhdl-special-syntax-alist
1685 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1686 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1687 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1688 "List of special syntax to be highlighted.
1689 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1690 syntax (as regular expression) are highlighted in the corresponding color.
1692 Name : string of words and spaces
1693 Regexp : regular expression describing word syntax
1694 (e.g., `\\=\\<\\w+_c\\>' matches word with suffix `_c')
1695 expression must start with `\\=\\<' and end with `\\>'
1696 if only whole words should be matched (no substrings)
1697 Color (light): foreground color for light background
1698 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1699 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1700 Color (dark) : foreground color for dark background
1701 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1702 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1703 In comments : If non-nil, words are also highlighted inside comments
1705 Can be used for visual support of naming conventions, such as highlighting
1706 different kinds of signals (e.g. `Clk50', `Rst_n') or objects (e.g.
1707 `Signal_s', `Variable_v', `Constant_c') by distinguishing them using
1708 common substrings or name suffices.
1709 For each entry, a new face is generated with the specified colors and name
1710 `vhdl-font-lock-' + name + `-face'.
1712 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1713 entry `Fontify Buffer'). All other changes require restarting Emacs."
1714 :type '(repeat (list :tag "Face" :indent 2
1715 (string :tag "Name ")
1716 (regexp :tag "Regexp " "\\w+_")
1717 (string :tag "Color (light)")
1718 (string :tag "Color (dark) ")
1719 (boolean :tag "In comments ")))
1720 :set (lambda (variable value)
1721 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1722 :group 'vhdl-highlight)
1724 (defcustom vhdl-forbidden-words '()
1725 "List of forbidden words to be highlighted.
1726 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1727 words are highlighted in a warning color to indicate not to use them.
1729 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1730 entry \"Fontify Buffer\")."
1731 :type '(repeat (string :format "%v"))
1732 :set (lambda (variable value)
1733 (vhdl-custom-set variable value
1734 'vhdl-words-init 'vhdl-font-lock-init))
1735 :group 'vhdl-highlight)
1737 (defcustom vhdl-forbidden-syntax ""
1738 "Syntax of forbidden words to be highlighted.
1739 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1740 syntax are highlighted in a warning color to indicate not to use them.
1741 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1742 highlights identifiers with 10 or more characters).
1744 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1745 entry \"Fontify Buffer\")."
1746 :type 'regexp
1747 :set (lambda (variable value)
1748 (vhdl-custom-set variable value
1749 'vhdl-words-init 'vhdl-font-lock-init))
1750 :group 'vhdl-highlight)
1752 (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
1753 "List of compiler directive keywords recognized for highlighting.
1755 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1756 entry \"Fontify Buffer\")."
1757 :type '(repeat (string :format "%v"))
1758 :set (lambda (variable value)
1759 (vhdl-custom-set variable value
1760 'vhdl-words-init 'vhdl-font-lock-init))
1761 :group 'vhdl-highlight)
1764 (defgroup vhdl-speedbar nil
1765 "Customizations for speedbar."
1766 :group 'vhdl)
1768 (defcustom vhdl-speedbar-auto-open nil
1769 "Non-nil means automatically open speedbar at startup.
1770 Alternatively, the speedbar can be opened from the VHDL menu."
1771 :type 'boolean
1772 :group 'vhdl-speedbar)
1774 (defcustom vhdl-speedbar-display-mode 'files
1775 "Specifies the default displaying mode when opening speedbar.
1776 Alternatively, the displaying mode can be selected from the speedbar menu or
1777 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1778 :type '(choice (const :tag "Files" files)
1779 (const :tag "Directory hierarchy" directory)
1780 (const :tag "Project hierarchy" project))
1781 :group 'vhdl-speedbar)
1783 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1784 "Limits scanning of large files and netlists.
1785 Design units: maximum file size to scan for design units
1786 Hierarchy (instances of subcomponents):
1787 File size: maximum file size to scan for instances (in bytes)
1788 Instances per arch: maximum number of instances to scan per architecture
1790 \"None\" always means that there is no limit.
1791 In case of files not or incompletely scanned, a warning message and the file
1792 names are printed out.
1793 Background: scanning for instances is considerably slower than scanning for
1794 design units, especially when there are many instances. These limits should
1795 prevent the scanning of large netlists."
1796 :type '(list (choice :tag "Design units"
1797 :format "%t : %[Value Menu%] %v"
1798 (const :tag "None" nil)
1799 (integer :tag "File size"))
1800 (list :tag "Hierarchy" :indent 2
1801 (choice :tag "File size"
1802 :format "%t : %[Value Menu%] %v"
1803 (const :tag "None" nil)
1804 (integer :tag "Size "))
1805 (choice :tag "Instances per arch"
1806 (const :tag "None" nil)
1807 (integer :tag "Number "))))
1808 :group 'vhdl-speedbar)
1810 (defcustom vhdl-speedbar-jump-to-unit t
1811 "Non-nil means jump to the design unit code when opened in a buffer.
1812 The buffer cursor position is left unchanged otherwise."
1813 :type 'boolean
1814 :group 'vhdl-speedbar)
1816 (defcustom vhdl-speedbar-update-on-saving t
1817 "Automatically update design hierarchy when buffer is saved."
1818 :type 'boolean
1819 :group 'vhdl-speedbar)
1821 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1822 "Automatically save modified hierarchy caches when exiting Emacs.
1823 Hierarchy: design hierarchy information
1824 Display: displaying information (which design units to expand)"
1825 :type '(set (const :tag "Hierarchy" hierarchy)
1826 (const :tag "Display" display))
1827 :group 'vhdl-speedbar)
1829 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1830 "Name of file for saving hierarchy cache.
1831 \"\\1\" is replaced by the project name if a project is specified,
1832 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1833 different users to have cache files in the same directory). Can also have
1834 an absolute path (i.e. all caches can be stored in one global directory)."
1835 :type 'string
1836 :group 'vhdl-speedbar)
1839 (defgroup vhdl-menu nil
1840 "Customizations for menus."
1841 :group 'vhdl)
1843 (defcustom vhdl-index-menu nil
1844 "Non-nil means add an index menu for a source file when loading.
1845 Alternatively, the speedbar can be used. Note that the index menu scans a file
1846 when it is opened, while speedbar only scans the file upon request."
1847 :type 'boolean
1848 :group 'vhdl-menu)
1850 (defcustom vhdl-source-file-menu nil
1851 "Non-nil means add a menu of all source files in current directory.
1852 Alternatively, the speedbar can be used."
1853 :type 'boolean
1854 :group 'vhdl-menu)
1856 (defcustom vhdl-hideshow-menu nil
1857 "Non-nil means add hideshow menu and functionality at startup.
1858 Hideshow can also be enabled from the VHDL Mode menu.
1859 Hideshow allows hiding code of various VHDL constructs.
1861 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1862 \"Activate Options\"."
1863 :type 'boolean
1864 :group 'vhdl-menu)
1866 (defcustom vhdl-hide-all-init nil
1867 "Non-nil means hide all design units initially after a file is loaded."
1868 :type 'boolean
1869 :group 'vhdl-menu)
1872 (defgroup vhdl-print nil
1873 "Customizations for printing."
1874 :group 'vhdl)
1876 (defcustom vhdl-print-two-column t
1877 "Non-nil means print code in two columns and landscape format.
1878 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1879 prints VHDL files in a nice two-column landscape style.
1881 NOTE: Activate the new setting by restarting Emacs.
1882 Overrides `ps-print' settings locally."
1883 :type 'boolean
1884 :group 'vhdl-print)
1886 (defcustom vhdl-print-customize-faces t
1887 "Non-nil means use an optimized set of faces for PostScript printing.
1889 NOTE: Activate the new setting by restarting Emacs.
1890 Overrides `ps-print' settings locally."
1891 :type 'boolean
1892 :group 'vhdl-print)
1895 (defgroup vhdl-misc nil
1896 "Miscellaneous customizations."
1897 :group 'vhdl)
1899 (defcustom vhdl-intelligent-tab t
1900 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1901 That is, if preceding character is part of a word then complete word,
1902 else if not at beginning of line then insert tab,
1903 else if last command was a `TAB' or `RET' then dedent one step,
1904 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1905 If nil, TAB always indents current line (i.e. `TAB' is bound to
1906 `indent-according-to-mode').
1908 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1909 \"Activate Options\"."
1910 :type 'boolean
1911 :group 'vhdl-misc)
1913 (defcustom vhdl-indent-syntax-based t
1914 "Non-nil means indent lines of code based on their syntactic context.
1915 Otherwise, a line is indented like the previous nonblank line. This can be
1916 useful in large files where syntax-based indentation gets very slow."
1917 :type 'boolean
1918 :group 'vhdl-misc)
1920 (defcustom vhdl-indent-comment-like-next-code-line t
1921 "Non-nil means comment lines are indented like the following code line.
1922 Otherwise, comment lines are indented like the preceding code line.
1923 Indenting comment lines like the following code line gives nicer indentation
1924 when comments precede the code that they refer to."
1925 :type 'boolean
1926 :version "24.3"
1927 :group 'vhdl-misc)
1929 (defcustom vhdl-word-completion-case-sensitive nil
1930 "Non-nil means word completion using `TAB' is case sensitive.
1931 That is, `TAB' completes words that start with the same letters and case.
1932 Otherwise, case is ignored."
1933 :type 'boolean
1934 :group 'vhdl-misc)
1936 (defcustom vhdl-word-completion-in-minibuffer t
1937 "Non-nil enables word completion in minibuffer (for template prompts).
1939 NOTE: Activate the new setting by restarting Emacs."
1940 :type 'boolean
1941 :group 'vhdl-misc)
1943 (defcustom vhdl-underscore-is-part-of-word nil
1944 "Non-nil means consider the underscore character `_' as part of word.
1945 An identifier containing underscores is then treated as a single word in
1946 select and move operations. All parts of an identifier separated by underscore
1947 are treated as single words otherwise."
1948 :type 'boolean
1949 :group 'vhdl-misc)
1950 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1951 'superword-mode "24.4")
1954 (defgroup vhdl-related nil
1955 "Related general customizations."
1956 :group 'vhdl)
1958 ;; add related general customizations
1959 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1960 (if (featurep 'xemacs)
1961 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1962 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1963 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1964 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1965 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1966 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1967 (unless (featurep 'xemacs)
1968 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1969 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1970 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1972 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1973 ;; Hidden user variables
1975 (defvar vhdl-compile-absolute-path nil
1976 "If non-nil, use absolute instead of relative path for compiled files.")
1978 (defvar vhdl-comment-display-line-char ?-
1979 "Character to use in comment display line.")
1981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1982 ;; Internal variables
1984 (defvar vhdl-menu-max-size 20
1985 "Specifies the maximum size of a menu before splitting it into submenus.")
1987 (defvar vhdl-progress-interval 1
1988 "Interval used to update progress status during long operations.
1989 If a number, percentage complete gets updated after each interval of
1990 that many seconds. To inhibit all messages, set this option to nil.")
1992 (defvar vhdl-inhibit-startup-warnings-p nil
1993 "If non-nil, inhibits start up compatibility warnings.")
1995 (defvar vhdl-strict-syntax-p nil
1996 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1997 If the syntactic symbol for a particular line does not match a symbol
1998 in the offsets alist, an error is generated, otherwise no error is
1999 reported and the syntactic symbol is ignored.")
2001 (defvar vhdl-echo-syntactic-information-p nil
2002 "If non-nil, syntactic info is echoed when the line is indented.")
2004 (defconst vhdl-offsets-alist-default
2005 '((string . -1000)
2006 (cpp-macro . -1000)
2007 (block-open . 0)
2008 (block-close . 0)
2009 (statement . 0)
2010 (statement-cont . vhdl-lineup-statement-cont)
2011 (statement-block-intro . +)
2012 (statement-case-intro . +)
2013 (case-alternative . +)
2014 (comment . vhdl-lineup-comment)
2015 (arglist-intro . +)
2016 (arglist-cont . 0)
2017 (arglist-cont-nonempty . vhdl-lineup-arglist)
2018 (arglist-close . vhdl-lineup-arglist)
2019 (entity . 0)
2020 (configuration . 0)
2021 (package . 0)
2022 (architecture . 0)
2023 (package-body . 0)
2024 (context . 0)
2025 (directive . 0)
2027 "Default settings for offsets of syntactic elements.
2028 Do not change this constant! See the variable `vhdl-offsets-alist' for
2029 more information.")
2031 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2032 "Association list of syntactic element symbols and indentation offsets.
2033 As described below, each cons cell in this list has the form:
2035 (SYNTACTIC-SYMBOL . OFFSET)
2037 When a line is indented, `vhdl-mode' first determines the syntactic
2038 context of the line by generating a list of symbols called syntactic
2039 elements. This list can contain more than one syntactic element and
2040 the global variable `vhdl-syntactic-context' contains the context list
2041 for the line being indented. Each element in this list is actually a
2042 cons cell of the syntactic symbol and a buffer position. This buffer
2043 position is call the relative indent point for the line. Some
2044 syntactic symbols may not have a relative indent point associated with
2045 them.
2047 After the syntactic context list for a line is generated, `vhdl-mode'
2048 calculates the absolute indentation for the line by looking at each
2049 syntactic element in the list. First, it compares the syntactic
2050 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2051 finds a match, it adds the OFFSET to the column of the relative indent
2052 point. The sum of this calculation for each element in the syntactic
2053 list is the absolute offset for line being indented.
2055 If the syntactic element does not match any in the `vhdl-offsets-alist',
2056 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2057 the element is ignored.
2059 Actually, OFFSET can be an integer, a function, a variable, or one of
2060 the following symbols: `+', `-', `++', or `--'. These latter
2061 designate positive or negative multiples of `vhdl-basic-offset',
2062 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2063 called with a single argument containing the cons of the syntactic
2064 element symbol and the relative indent point. The function should
2065 return an integer offset.
2067 Here is the current list of valid syntactic element symbols:
2069 string -- inside multi-line string
2070 block-open -- statement block open
2071 block-close -- statement block close
2072 statement -- a VHDL statement
2073 statement-cont -- a continuation of a VHDL statement
2074 statement-block-intro -- the first line in a new statement block
2075 statement-case-intro -- the first line in a case alternative block
2076 case-alternative -- a case statement alternative clause
2077 comment -- a line containing only a comment
2078 arglist-intro -- the first line in an argument list
2079 arglist-cont -- subsequent argument list lines when no
2080 arguments follow on the same line as
2081 the arglist opening paren
2082 arglist-cont-nonempty -- subsequent argument list lines when at
2083 least one argument follows on the same
2084 line as the arglist opening paren
2085 arglist-close -- the solo close paren of an argument list
2086 entity -- inside an entity declaration
2087 configuration -- inside a configuration declaration
2088 package -- inside a package declaration
2089 architecture -- inside an architecture body
2090 package-body -- inside a package body
2091 context -- inside a context declaration")
2093 (defvar vhdl-comment-only-line-offset 0
2094 "Extra offset for line which contains only the start of a comment.
2095 Can contain an integer or a cons cell of the form:
2097 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2099 Where NON-ANCHORED-OFFSET is the amount of offset given to
2100 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2101 the amount of offset to give column-zero anchored comment-only lines.
2102 Just an integer as value is equivalent to (<val> . 0)")
2104 (defvar vhdl-special-indent-hook nil
2105 "Hook for user defined special indentation adjustments.
2106 This hook gets called after a line is indented by the mode.")
2108 (defvar vhdl-style-alist
2109 '(("IEEE"
2110 (vhdl-basic-offset . 4)
2111 (vhdl-offsets-alist . ())))
2112 "Styles of Indentation.
2113 Elements of this alist are of the form:
2115 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2117 where STYLE-STRING is a short descriptive string used to select a
2118 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2119 value for that variable when using the selected style.
2121 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2122 case, the VALUE is a list containing elements of the form:
2124 (SYNTACTIC-SYMBOL . VALUE)
2126 as described in `vhdl-offsets-alist'. These are passed directly to
2127 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2128 your style, only those that are different from the default.")
2130 ;; dynamically append the default value of most variables
2131 (or (assoc "Default" vhdl-style-alist)
2132 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2133 vhdl-strict-syntax-p
2134 vhdl-echo-syntactic-information-p
2135 vhdl-basic-offset
2136 vhdl-offsets-alist
2137 vhdl-comment-only-line-offset))
2138 (default (cons "Default"
2139 (mapcar
2140 (function
2141 (lambda (var)
2142 (cons var (symbol-value var))))
2143 varlist))))
2144 (push default vhdl-style-alist)))
2146 (defvar vhdl-mode-hook nil
2147 "Hook called by `vhdl-mode'.")
2150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2151 ;;; Required packages
2152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2154 ;; mandatory
2155 (require 'compile) ; XEmacs
2156 (require 'easymenu)
2157 (require 'hippie-exp)
2159 ;; optional (minimize warning messages during compile)
2160 (unless (featurep 'xemacs)
2161 (eval-when-compile
2162 (require 'font-lock)
2163 (require 'ps-print)
2164 (require 'speedbar))) ; for speedbar-with-writable
2166 (defun vhdl-aput (alist-symbol key &optional value)
2167 "Insert a key-value pair into an alist.
2168 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2169 from KEY and VALUE. If the key-value pair referenced by KEY can be
2170 found in the alist, the value of KEY will be set to VALUE. If the
2171 key-value pair cannot be found in the alist, it will be inserted into
2172 the head of the alist."
2173 (let* ((alist (symbol-value alist-symbol))
2174 (elem (assoc key alist)))
2175 (if elem
2176 (setcdr elem value)
2177 (set alist-symbol (cons (cons key value) alist)))))
2179 (defun vhdl-adelete (alist-symbol key)
2180 "Delete a key-value pair from the alist.
2181 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2182 is pair matching KEY."
2183 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2184 (while (equal key (caar alist))
2185 (setq alist (cdr alist))
2186 (set alist-symbol alist))
2187 (while (setq alist-cdr (cdr alist))
2188 (if (equal key (caar alist-cdr))
2189 (setcdr alist (cdr alist-cdr))
2190 (setq alist alist-cdr)))))
2192 (defun vhdl-aget (alist key)
2193 "Return the value in ALIST that is associated with KEY. If KEY is
2194 not found, then nil is returned."
2195 (cdr (assoc key alist)))
2197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2198 ;;; Compatibility
2199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2202 ;; XEmacs compatibility
2204 ;; active regions
2205 (defun vhdl-keep-region-active ()
2206 "Do whatever is necessary to keep the region active in XEmacs.
2207 Ignore byte-compiler warnings you might see."
2208 (and (featurep 'xemacs)
2209 (setq zmacs-region-stays t)))
2211 ;; `wildcard-to-regexp' is included only in XEmacs 21
2212 (unless (fboundp 'wildcard-to-regexp)
2213 (defun wildcard-to-regexp (wildcard)
2214 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2215 (let* ((i (string-match "[*?]" wildcard))
2216 (result (substring wildcard 0 i))
2217 (len (length wildcard)))
2218 (when i
2219 (while (< i len)
2220 (let ((ch (aref wildcard i)))
2221 (setq result (concat result
2222 (cond ((eq ch ?*) "[^\000]*")
2223 ((eq ch ??) "[^\000]")
2224 (t (char-to-string ch)))))
2225 (setq i (1+ i)))))
2226 (concat "\\`" result "\\'"))))
2228 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2229 ;; `regexp-opt' accelerates fontification by 10-20%
2230 (unless (fboundp 'regexp-opt)
2231 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2232 (defun regexp-opt (strings &optional paren)
2233 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2234 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2236 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2237 (unless (fboundp 'match-string-no-properties)
2238 (defalias 'match-string-no-properties 'match-string))
2240 ;; `subst-char-in-string' undefined (XEmacs)
2241 (unless (fboundp 'subst-char-in-string)
2242 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2243 (let ((i (length string))
2244 (newstr (if inplace string (copy-sequence string))))
2245 (while (> i 0)
2246 (setq i (1- i))
2247 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2248 newstr)))
2250 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2251 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2252 (not noninteractive))
2253 (load "itimer")
2254 (when (string< itimer-version "1.09")
2255 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2256 (beep) (sit-for 5)))
2258 ;; `file-expand-wildcards' undefined (XEmacs)
2259 (unless (fboundp 'file-expand-wildcards)
2260 (defun file-expand-wildcards (pattern &optional full)
2261 "Taken from Emacs's `files.el'."
2262 (let* ((nondir (file-name-nondirectory pattern))
2263 (dirpart (file-name-directory pattern))
2264 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2265 (mapcar 'file-name-as-directory
2266 (file-expand-wildcards (directory-file-name dirpart)))
2267 (list dirpart)))
2268 contents)
2269 (while dirs
2270 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2271 (file-directory-p (directory-file-name (car dirs))))
2272 (let ((this-dir-contents
2273 (delq nil
2274 (mapcar #'(lambda (name)
2275 (unless (string-match "\\`\\.\\.?\\'"
2276 (file-name-nondirectory name))
2277 name))
2278 (directory-files (or (car dirs) ".") full
2279 (wildcard-to-regexp nondir))))))
2280 (setq contents
2281 (nconc
2282 (if (and (car dirs) (not full))
2283 (mapcar (function (lambda (name) (concat (car dirs) name)))
2284 this-dir-contents)
2285 this-dir-contents)
2286 contents))))
2287 (setq dirs (cdr dirs)))
2288 contents)))
2290 ;; `member-ignore-case' undefined (XEmacs)
2291 (unless (fboundp 'member-ignore-case)
2292 (defalias 'member-ignore-case 'member))
2294 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2295 ;; behavior in XEmacs
2296 (defvar vhdl-last-input-event)
2297 (if (featurep 'xemacs)
2298 (defvaralias 'vhdl-last-input-event 'last-input-char)
2299 (defvaralias 'vhdl-last-input-event 'last-input-event))
2301 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2302 ;;;(unless (fboundp 'help-print-return-message)
2303 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2306 ;; Compatibility with older VHDL Mode versions
2308 (defvar vhdl-warnings nil
2309 "Warnings to tell the user during start up.")
2311 (defun vhdl-run-when-idle (secs repeat function)
2312 "Wait until idle, then run FUNCTION."
2313 (if (fboundp 'start-itimer)
2314 (start-itimer "vhdl-mode" function secs repeat t)
2315 ;; explicitly activate timer (necessary when Emacs is already idle)
2316 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2318 (defun vhdl-warning-when-idle (&rest args)
2319 "Wait until idle, then print out warning STRING and beep."
2320 (let ((message (apply #'format-message args)))
2321 (if noninteractive
2322 (vhdl-warning message t)
2323 (unless vhdl-warnings
2324 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2325 (push message vhdl-warnings))))
2327 (defun vhdl-warning (string &optional nobeep)
2328 "Print out warning STRING and beep."
2329 (message "WARNING: %s" string)
2330 (unless (or nobeep noninteractive) (beep)))
2332 (defun vhdl-print-warnings ()
2333 "Print out messages in variable `vhdl-warnings'."
2334 (let ((no-warnings (length vhdl-warnings)))
2335 (setq vhdl-warnings (nreverse vhdl-warnings))
2336 (while vhdl-warnings
2337 (message "WARNING: %s" (car vhdl-warnings))
2338 (setq vhdl-warnings (cdr vhdl-warnings)))
2339 (beep)
2340 (when (> no-warnings 1)
2341 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2343 ;; Backward compatibility checks and fixes
2344 ;; option `vhdl-compiler' changed format
2345 (unless (stringp vhdl-compiler)
2346 (setq vhdl-compiler "ModelSim")
2347 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2349 ;; option `vhdl-standard' changed format
2350 (unless (listp vhdl-standard)
2351 (setq vhdl-standard '(87 nil))
2352 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2354 ;; option `vhdl-model-alist' changed format
2355 (when (= (length (car vhdl-model-alist)) 3)
2356 (let ((old-alist vhdl-model-alist)
2357 new-alist)
2358 (while old-alist
2359 (push (append (car old-alist) '("")) new-alist)
2360 (setq old-alist (cdr old-alist)))
2361 (setq vhdl-model-alist (nreverse new-alist)))
2362 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2364 ;; option `vhdl-project-alist' changed format
2365 (when (= (length (car vhdl-project-alist)) 3)
2366 (let ((old-alist vhdl-project-alist)
2367 new-alist)
2368 (while old-alist
2369 (push (append (car old-alist) '("")) new-alist)
2370 (setq old-alist (cdr old-alist)))
2371 (setq vhdl-project-alist (nreverse new-alist)))
2372 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2374 ;; option `vhdl-project-alist' changed format (3.31.1)
2375 (when (= (length (car vhdl-project-alist)) 4)
2376 (let ((old-alist vhdl-project-alist)
2377 new-alist elem)
2378 (while old-alist
2379 (setq elem (car old-alist))
2380 (setq new-alist
2381 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2382 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2383 new-alist))
2384 (setq old-alist (cdr old-alist)))
2385 (setq vhdl-project-alist (nreverse new-alist)))
2386 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2388 ;; option `vhdl-project-alist' changed format (3.31.12)
2389 (when (= (length (car vhdl-project-alist)) 10)
2390 (let ((tmp-alist vhdl-project-alist))
2391 (while tmp-alist
2392 (setcdr (nthcdr 3 (car tmp-alist))
2393 (cons "" (nthcdr 4 (car tmp-alist))))
2394 (setq tmp-alist (cdr tmp-alist))))
2395 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2397 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2398 (when (= (length (car vhdl-compiler-alist)) 7)
2399 (let ((old-alist vhdl-compiler-alist)
2400 new-alist elem)
2401 (while old-alist
2402 (setq elem (car old-alist))
2403 (setq new-alist
2404 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2405 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2406 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2407 (nth 5 elem) (nth 6 elem) nil)
2408 new-alist))
2409 (setq old-alist (cdr old-alist)))
2410 (setq vhdl-compiler-alist (nreverse new-alist)))
2411 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2413 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2414 (when (= (length (car vhdl-compiler-alist)) 12)
2415 (let ((tmp-alist vhdl-compiler-alist))
2416 (while tmp-alist
2417 (setcdr (nthcdr 4 (car tmp-alist))
2418 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2419 (setq tmp-alist (cdr tmp-alist))))
2420 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2422 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2423 (when (= (length (car vhdl-compiler-alist)) 13)
2424 (let ((tmp-alist vhdl-compiler-alist))
2425 (while tmp-alist
2426 (setcdr (nthcdr 3 (car tmp-alist))
2427 (cons "" (nthcdr 4 (car tmp-alist))))
2428 (setq tmp-alist (cdr tmp-alist))))
2429 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2431 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2432 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2433 (let ((tmp-alist vhdl-compiler-alist))
2434 (while tmp-alist
2435 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2436 '(0 . nil))
2437 (setq tmp-alist (cdr tmp-alist))))
2438 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2440 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2441 (when (equal vhdl-project "")
2442 (setq vhdl-project nil)
2443 (customize-save-variable 'vhdl-project vhdl-project))
2445 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2446 (when (stringp vhdl-project-file-name)
2447 (setq vhdl-project-file-name (list vhdl-project-file-name))
2448 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2450 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2451 (if (not (boundp 'speedbar-indentation-width))
2452 (defvar speedbar-indentation-width 2)
2453 ;; set default to 2 if not already customized
2454 (unless (get 'speedbar-indentation-width 'saved-value)
2455 (setq speedbar-indentation-width 2)))
2457 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2458 ;;; Help functions / inline substitutions / macros
2459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2461 (defun vhdl-standard-p (standard)
2462 "Check if STANDARD is specified as used standard."
2463 (or (eq standard (car vhdl-standard))
2464 (memq standard (cadr vhdl-standard))))
2466 (defun vhdl-project-p (&optional warning)
2467 "Return non-nil if a project is displayed, i.e. directories or files are
2468 specified."
2469 (if (assoc vhdl-project vhdl-project-alist)
2470 vhdl-project
2471 (when (and vhdl-project warning)
2472 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2473 nil))
2475 (defun vhdl-resolve-env-variable (string)
2476 "Resolve environment variables in STRING."
2477 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2478 (setq string (concat (match-string 1 string)
2479 (getenv (match-string 2 string))
2480 (match-string 4 string))))
2481 string)
2483 (defun vhdl-default-directory ()
2484 "Return the default directory of the current project or the directory of the
2485 current buffer if no project is defined."
2486 (if (vhdl-project-p)
2487 (expand-file-name (vhdl-resolve-env-variable
2488 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2489 default-directory))
2491 (defmacro vhdl-prepare-search-1 (&rest body)
2492 "Enable case insensitive search and switch to syntax table that includes `_',
2493 then execute BODY, and finally restore the old environment. Used for
2494 consistent searching."
2495 `(let ((case-fold-search t)) ; case insensitive search
2496 ;; use extended syntax table
2497 (with-syntax-table vhdl-mode-ext-syntax-table
2498 ,@body)))
2500 (defmacro vhdl-prepare-search-2 (&rest body)
2501 "Enable case insensitive search, switch to syntax table that includes `_',
2502 arrange to ignore `intangible' overlays, then execute BODY, and finally restore
2503 the old environment. Used for consistent searching."
2504 `(let ((case-fold-search t) ; case insensitive search
2505 (current-syntax-table (syntax-table))
2506 (inhibit-point-motion-hooks t))
2507 ;; use extended syntax table
2508 (set-syntax-table vhdl-mode-ext-syntax-table)
2509 ;; execute BODY safely
2510 (unwind-protect
2511 (progn ,@body)
2512 ;; restore syntax table
2513 (set-syntax-table current-syntax-table))))
2515 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2516 "Visit file FILE-NAME and execute BODY."
2517 `(if (null ,file-name)
2518 (progn ,@body)
2519 (unless (file-directory-p ,file-name)
2520 (let ((source-buffer (current-buffer))
2521 (visiting-buffer (find-buffer-visiting ,file-name))
2522 file-opened)
2523 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2524 (condition-case ()
2525 (progn (set-buffer (create-file-buffer ,file-name))
2526 (setq file-opened t)
2527 (vhdl-insert-file-contents ,file-name)
2528 ;; FIXME: This modifies a global syntax-table!
2529 (modify-syntax-entry ?\- ". 12" (syntax-table))
2530 (modify-syntax-entry ?\n ">" (syntax-table))
2531 (modify-syntax-entry ?\^M ">" (syntax-table))
2532 (modify-syntax-entry ?_ "w" (syntax-table))
2534 (error
2535 (if ,issue-error
2536 (progn
2537 (when file-opened (kill-buffer (current-buffer)))
2538 (set-buffer source-buffer)
2539 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2540 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2541 nil))))
2542 (condition-case info
2543 (progn ,@body)
2544 (error
2545 (if ,issue-error
2546 (progn
2547 (when file-opened (kill-buffer (current-buffer)))
2548 (set-buffer source-buffer)
2549 (error (cadr info)))
2550 (vhdl-warning (cadr info))))))
2551 (when file-opened (kill-buffer (current-buffer)))
2552 (set-buffer source-buffer)))))
2554 (defun vhdl-insert-file-contents (filename)
2555 "Nicked from `insert-file-contents-literally', but allow coding system
2556 conversion."
2557 (let ((format-alist nil)
2558 (after-insert-file-functions nil)
2559 (jka-compr-compression-info-list nil))
2560 (insert-file-contents filename t)))
2562 (defun vhdl-sort-alist (alist)
2563 "Sort ALIST."
2564 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2566 (defun vhdl-get-subdirs (directory)
2567 "Recursively get subdirectories of DIRECTORY."
2568 (let ((dir-list (list (file-name-as-directory directory)))
2569 file-list)
2570 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2571 (while file-list
2572 (when (file-directory-p (car file-list))
2573 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2574 (setq file-list (cdr file-list)))
2575 dir-list))
2577 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2578 "As `aput', but delete key-value pair if VALUE is nil."
2579 (if value
2580 (vhdl-aput alist-symbol key value)
2581 (vhdl-adelete alist-symbol key)))
2583 (defun vhdl-delete (elt list)
2584 "Delete by side effect the first occurrence of ELT as a member of LIST."
2585 (push nil list)
2586 (let ((list1 list))
2587 (while (and (cdr list1) (not (equal elt (cadr list1))))
2588 (setq list1 (cdr list1)))
2589 (when list
2590 (setcdr list1 (cddr list1))))
2591 (cdr list))
2593 (declare-function speedbar-refresh "speedbar" (&optional arg))
2594 (declare-function speedbar-do-function-pointer "speedbar" ())
2596 (defun vhdl-speedbar-refresh (&optional key)
2597 "Refresh directory or project with name KEY."
2598 (when (and (boundp 'speedbar-frame)
2599 (frame-live-p speedbar-frame))
2600 (let ((pos (point))
2601 (last-frame (selected-frame)))
2602 (if (null key)
2603 (speedbar-refresh)
2604 (select-frame speedbar-frame)
2605 (when (save-excursion
2606 (goto-char (point-min))
2607 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2608 (goto-char (match-end 1))
2609 (speedbar-do-function-pointer)
2610 (backward-char 2)
2611 (speedbar-do-function-pointer)
2612 (message "Refreshing speedbar...done"))
2613 (select-frame last-frame)))))
2615 (defun vhdl-show-messages ()
2616 "Get *Messages* buffer to show recent messages."
2617 (interactive)
2618 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2620 (defun vhdl-use-direct-instantiation ()
2621 "Return whether direct instantiation is used."
2622 (or (eq vhdl-use-direct-instantiation 'always)
2623 (and (eq vhdl-use-direct-instantiation 'standard)
2624 (not (vhdl-standard-p '87)))))
2626 (defun vhdl-max-marker (marker1 marker2)
2627 "Return larger marker."
2628 (if (> marker1 marker2) marker1 marker2))
2630 (defun vhdl-goto-marker (marker)
2631 "Goto marker in appropriate buffer."
2632 (when (markerp marker)
2633 (set-buffer (marker-buffer marker)))
2634 (goto-char marker))
2636 (defun vhdl-menu-split (list title)
2637 "Split menu LIST into several submenus, if number of
2638 elements > `vhdl-menu-max-size'."
2639 (if (> (length list) vhdl-menu-max-size)
2640 (let ((remain list)
2641 (result '())
2642 (sublist '())
2643 (menuno 1)
2644 (i 0))
2645 (while remain
2646 (push (car remain) sublist)
2647 (setq remain (cdr remain))
2648 (setq i (+ i 1))
2649 (if (= i vhdl-menu-max-size)
2650 (progn
2651 (push (cons (format "%s %s" title menuno)
2652 (nreverse sublist)) result)
2653 (setq i 0)
2654 (setq menuno (+ menuno 1))
2655 (setq sublist '()))))
2656 (and sublist
2657 (push (cons (format "%s %s" title menuno)
2658 (nreverse sublist)) result))
2659 (nreverse result))
2660 list))
2663 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2664 ;;; Bindings
2665 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2667 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2668 ;; Key bindings
2670 (defvar vhdl-template-map nil
2671 "Keymap for VHDL templates.")
2673 (defun vhdl-template-map-init ()
2674 "Initialize `vhdl-template-map'."
2675 (setq vhdl-template-map (make-sparse-keymap))
2676 ;; key bindings for VHDL templates
2677 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2678 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2679 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2680 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2681 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2682 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2683 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2684 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2685 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2686 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2687 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2688 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2689 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2690 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2691 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2692 (define-key vhdl-template-map "ct" 'vhdl-template-context)
2693 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2694 (define-key vhdl-template-map "el" 'vhdl-template-else)
2695 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2696 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2697 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2698 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2699 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2700 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2701 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2702 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2703 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2704 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2705 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2706 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2707 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2708 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2709 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2710 (define-key vhdl-template-map "li" 'vhdl-template-library)
2711 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2712 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2713 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2714 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2715 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2716 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2717 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2718 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2719 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2720 (define-key vhdl-template-map "po" 'vhdl-template-port)
2721 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2722 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2723 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2724 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2725 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2726 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2727 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2728 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2729 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2730 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2731 (define-key vhdl-template-map "us" 'vhdl-template-use)
2732 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2733 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2734 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2735 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2736 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2737 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2738 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2739 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2740 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2741 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2742 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2743 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2744 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2745 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2746 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2747 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2748 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2749 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2750 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2751 (when (vhdl-standard-p 'ams)
2752 (define-key vhdl-template-map "br" 'vhdl-template-break)
2753 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2754 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2755 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2756 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2757 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2758 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2759 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2760 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2761 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2762 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2764 (when (vhdl-standard-p 'math)
2765 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2766 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2769 ;; initialize template map for VHDL Mode
2770 (vhdl-template-map-init)
2772 (defun vhdl-function-name (prefix string &optional postfix)
2773 "Generate a Lisp function name.
2774 PREFIX, STRING and optional POSTFIX are concatenated by `-' and spaces in
2775 STRING are replaced by `-' and substrings are converted to lower case."
2776 (let ((name prefix))
2777 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2778 (setq name
2779 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2780 (setq string (substring string (match-beginning 2))))
2781 (when postfix (setq name (concat name "-" postfix)))
2782 (intern name)))
2784 (defvar vhdl-model-map nil
2785 "Keymap for VHDL models.")
2787 (defun vhdl-model-map-init ()
2788 "Initialize `vhdl-model-map'."
2789 (setq vhdl-model-map (make-sparse-keymap))
2790 ;; key bindings for VHDL models
2791 (let ((model-alist vhdl-model-alist) model)
2792 (while model-alist
2793 (setq model (car model-alist))
2794 (define-key vhdl-model-map (nth 2 model)
2795 (vhdl-function-name "vhdl-model" (nth 0 model)))
2796 (setq model-alist (cdr model-alist)))))
2798 ;; initialize user model map for VHDL Mode
2799 (vhdl-model-map-init)
2801 (defvar vhdl-mode-map nil
2802 "Keymap for VHDL Mode.")
2804 (defun vhdl-mode-map-init ()
2805 "Initialize `vhdl-mode-map'."
2806 (setq vhdl-mode-map (make-sparse-keymap))
2807 ;; template key bindings
2808 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2809 ;; model key bindings
2810 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2811 ;; standard key bindings
2812 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2813 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2814 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2815 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2816 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2817 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2818 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2819 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2820 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2821 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2822 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2823 ;; mode specific key bindings
2824 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2825 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2826 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2827 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2828 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2829 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2830 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2831 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2832 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2833 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2834 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2835 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2836 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2837 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2838 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2839 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2840 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2841 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2842 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2843 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2844 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2845 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2846 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2847 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2848 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2849 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2850 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2851 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2852 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2853 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2854 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2855 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2856 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2857 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2858 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2859 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2860 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2861 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2862 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2863 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2864 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2865 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2866 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2867 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2868 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2869 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2870 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2871 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2872 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2873 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2874 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2875 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2876 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2877 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2878 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2879 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2880 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2881 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2882 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2883 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2884 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2885 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2886 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2887 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2888 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2889 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2890 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2891 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2892 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2893 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2894 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2895 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2896 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2897 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2898 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2899 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2900 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2901 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2902 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2903 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2904 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2905 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2906 ;; insert commands bindings
2907 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2908 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2909 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2910 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2911 ;; electric key bindings
2912 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2913 (when vhdl-intelligent-tab
2914 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2915 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2916 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2917 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2918 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2919 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2920 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2921 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2922 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2923 (when (vhdl-standard-p 'ams)
2924 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2926 ;; initialize mode map for VHDL Mode
2927 (vhdl-mode-map-init)
2929 ;; define special minibuffer keymap for enabling word completion in minibuffer
2930 ;; (useful in template generator prompts)
2931 (defvar vhdl-minibuffer-local-map
2932 (let ((map (make-sparse-keymap)))
2933 (set-keymap-parent map minibuffer-local-map)
2934 (when vhdl-word-completion-in-minibuffer
2935 (define-key map "\t" 'vhdl-minibuffer-tab))
2936 map)
2937 "Keymap for minibuffer used in VHDL Mode.")
2939 ;; set up electric character functions to work with
2940 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2941 (mapc
2942 (function
2943 (lambda (sym)
2944 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2945 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2946 '(vhdl-electric-space
2947 vhdl-electric-tab
2948 vhdl-electric-return
2949 vhdl-electric-dash
2950 vhdl-electric-open-bracket
2951 vhdl-electric-close-bracket
2952 vhdl-electric-quote
2953 vhdl-electric-semicolon
2954 vhdl-electric-comma
2955 vhdl-electric-period
2956 vhdl-electric-equal))
2958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2959 ;; Syntax table
2961 (defvar vhdl-mode-syntax-table
2962 (let ((st (make-syntax-table)))
2963 ;; define punctuation
2964 (modify-syntax-entry ?\# "." st)
2965 (modify-syntax-entry ?\$ "." st)
2966 (modify-syntax-entry ?\% "." st)
2967 (modify-syntax-entry ?\& "." st)
2968 (modify-syntax-entry ?\' "." st)
2969 (modify-syntax-entry ?\* "." st)
2970 (modify-syntax-entry ?\+ "." st)
2971 (modify-syntax-entry ?\. "." st)
2972 ;;; (modify-syntax-entry ?\/ "." st)
2973 (modify-syntax-entry ?\: "." st)
2974 (modify-syntax-entry ?\; "." st)
2975 (modify-syntax-entry ?\< "." st)
2976 (modify-syntax-entry ?\= "." st)
2977 (modify-syntax-entry ?\> "." st)
2978 (modify-syntax-entry ?\\ "." st)
2979 (modify-syntax-entry ?\| "." st)
2980 ;; define string
2981 (modify-syntax-entry ?\" "\"" st)
2982 ;; define underscore
2983 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2984 ;; single-line comments
2985 (modify-syntax-entry ?\- ". 12b" st)
2986 ;; multi-line comments
2987 (modify-syntax-entry ?\/ ". 14b" st)
2988 (modify-syntax-entry ?* ". 23" st)
2989 (modify-syntax-entry ?\n "> b" st)
2990 (modify-syntax-entry ?\^M "> b" st)
2991 ;; define parentheses to match
2992 (modify-syntax-entry ?\( "()" st)
2993 (modify-syntax-entry ?\) ")(" st)
2994 (modify-syntax-entry ?\[ "(]" st)
2995 (modify-syntax-entry ?\] ")[" st)
2996 (modify-syntax-entry ?\{ "(}" st)
2997 (modify-syntax-entry ?\} "){" st)
2999 "Syntax table used in `vhdl-mode' buffers.")
3001 (defvar vhdl-mode-ext-syntax-table
3002 ;; Extended syntax table including '_' (for simpler search regexps).
3003 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
3004 (modify-syntax-entry ?_ "w" st)
3006 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
3008 (defvar vhdl-syntactic-context nil
3009 "Buffer local variable containing syntactic analysis list.")
3010 (make-variable-buffer-local 'vhdl-syntactic-context)
3012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3013 ;; Abbrev hook bindings
3015 (defvar vhdl-mode-abbrev-table nil
3016 "Abbrev table to use in `vhdl-mode' buffers.")
3018 (defun vhdl-mode-abbrev-table-init ()
3019 "Initialize `vhdl-mode-abbrev-table'."
3020 (define-abbrev-table 'vhdl-mode-abbrev-table
3021 (append
3022 (when (memq 'vhdl vhdl-electric-keywords)
3023 ;; VHDL'02 keywords
3024 (mapcar (if (featurep 'xemacs)
3025 (lambda (x) (list (car x) "" (cdr x) 0))
3026 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3028 ("--" . vhdl-template-display-comment-hook)
3029 ("abs" . vhdl-template-default-hook)
3030 ("access" . vhdl-template-default-hook)
3031 ("after" . vhdl-template-default-hook)
3032 ("alias" . vhdl-template-alias-hook)
3033 ("all" . vhdl-template-default-hook)
3034 ("and" . vhdl-template-default-hook)
3035 ("arch" . vhdl-template-architecture-hook)
3036 ("architecture" . vhdl-template-architecture-hook)
3037 ("array" . vhdl-template-default-hook)
3038 ("assert" . vhdl-template-assert-hook)
3039 ("attr" . vhdl-template-attribute-hook)
3040 ("attribute" . vhdl-template-attribute-hook)
3041 ("begin" . vhdl-template-default-indent-hook)
3042 ("block" . vhdl-template-block-hook)
3043 ("body" . vhdl-template-default-hook)
3044 ("buffer" . vhdl-template-default-hook)
3045 ("bus" . vhdl-template-default-hook)
3046 ("case" . vhdl-template-case-hook)
3047 ("comp" . vhdl-template-component-hook)
3048 ("component" . vhdl-template-component-hook)
3049 ("cond" . vhdl-template-conditional-signal-asst-hook)
3050 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3051 ("conf" . vhdl-template-configuration-hook)
3052 ("configuration" . vhdl-template-configuration-hook)
3053 ("cons" . vhdl-template-constant-hook)
3054 ("constant" . vhdl-template-constant-hook)
3055 ("context" . vhdl-template-context-hook)
3056 ("disconnect" . vhdl-template-disconnect-hook)
3057 ("downto" . vhdl-template-default-hook)
3058 ("else" . vhdl-template-else-hook)
3059 ("elseif" . vhdl-template-elsif-hook)
3060 ("elsif" . vhdl-template-elsif-hook)
3061 ("end" . vhdl-template-default-indent-hook)
3062 ("entity" . vhdl-template-entity-hook)
3063 ("exit" . vhdl-template-exit-hook)
3064 ("file" . vhdl-template-file-hook)
3065 ("for" . vhdl-template-for-hook)
3066 ("func" . vhdl-template-function-hook)
3067 ("function" . vhdl-template-function-hook)
3068 ("generic" . vhdl-template-generic-hook)
3069 ("group" . vhdl-template-group-hook)
3070 ("guarded" . vhdl-template-default-hook)
3071 ("if" . vhdl-template-if-hook)
3072 ("impure" . vhdl-template-default-hook)
3073 ("in" . vhdl-template-default-hook)
3074 ("inertial" . vhdl-template-default-hook)
3075 ("inout" . vhdl-template-default-hook)
3076 ("inst" . vhdl-template-instance-hook)
3077 ("instance" . vhdl-template-instance-hook)
3078 ("is" . vhdl-template-default-hook)
3079 ("label" . vhdl-template-default-hook)
3080 ("library" . vhdl-template-library-hook)
3081 ("linkage" . vhdl-template-default-hook)
3082 ("literal" . vhdl-template-default-hook)
3083 ("loop" . vhdl-template-bare-loop-hook)
3084 ("map" . vhdl-template-map-hook)
3085 ("mod" . vhdl-template-default-hook)
3086 ("nand" . vhdl-template-default-hook)
3087 ("new" . vhdl-template-default-hook)
3088 ("next" . vhdl-template-next-hook)
3089 ("nor" . vhdl-template-default-hook)
3090 ("not" . vhdl-template-default-hook)
3091 ("null" . vhdl-template-default-hook)
3092 ("of" . vhdl-template-default-hook)
3093 ("on" . vhdl-template-default-hook)
3094 ("open" . vhdl-template-default-hook)
3095 ("or" . vhdl-template-default-hook)
3096 ("others" . vhdl-template-others-hook)
3097 ("out" . vhdl-template-default-hook)
3098 ("pack" . vhdl-template-package-hook)
3099 ("package" . vhdl-template-package-hook)
3100 ("port" . vhdl-template-port-hook)
3101 ("postponed" . vhdl-template-default-hook)
3102 ("procedure" . vhdl-template-procedure-hook)
3103 ("process" . vhdl-template-process-hook)
3104 ("pure" . vhdl-template-default-hook)
3105 ("range" . vhdl-template-default-hook)
3106 ("record" . vhdl-template-default-hook)
3107 ("register" . vhdl-template-default-hook)
3108 ("reject" . vhdl-template-default-hook)
3109 ("rem" . vhdl-template-default-hook)
3110 ("report" . vhdl-template-report-hook)
3111 ("return" . vhdl-template-return-hook)
3112 ("rol" . vhdl-template-default-hook)
3113 ("ror" . vhdl-template-default-hook)
3114 ("select" . vhdl-template-selected-signal-asst-hook)
3115 ("severity" . vhdl-template-default-hook)
3116 ("shared" . vhdl-template-default-hook)
3117 ("sig" . vhdl-template-signal-hook)
3118 ("signal" . vhdl-template-signal-hook)
3119 ("sla" . vhdl-template-default-hook)
3120 ("sll" . vhdl-template-default-hook)
3121 ("sra" . vhdl-template-default-hook)
3122 ("srl" . vhdl-template-default-hook)
3123 ("subtype" . vhdl-template-subtype-hook)
3124 ("then" . vhdl-template-default-hook)
3125 ("to" . vhdl-template-default-hook)
3126 ("transport" . vhdl-template-default-hook)
3127 ("type" . vhdl-template-type-hook)
3128 ("unaffected" . vhdl-template-default-hook)
3129 ("units" . vhdl-template-default-hook)
3130 ("until" . vhdl-template-default-hook)
3131 ("use" . vhdl-template-use-hook)
3132 ("var" . vhdl-template-variable-hook)
3133 ("variable" . vhdl-template-variable-hook)
3134 ("wait" . vhdl-template-wait-hook)
3135 ("when" . vhdl-template-when-hook)
3136 ("while" . vhdl-template-while-loop-hook)
3137 ("with" . vhdl-template-with-hook)
3138 ("xnor" . vhdl-template-default-hook)
3139 ("xor" . vhdl-template-default-hook)
3141 ;; VHDL-AMS keywords
3142 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3143 (mapcar (if (featurep 'xemacs)
3144 (lambda (x) (list (car x) "" (cdr x) 0))
3145 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3147 ("across" . vhdl-template-default-hook)
3148 ("break" . vhdl-template-break-hook)
3149 ("limit" . vhdl-template-limit-hook)
3150 ("nature" . vhdl-template-nature-hook)
3151 ("noise" . vhdl-template-default-hook)
3152 ("procedural" . vhdl-template-procedural-hook)
3153 ("quantity" . vhdl-template-quantity-hook)
3154 ("reference" . vhdl-template-default-hook)
3155 ("spectrum" . vhdl-template-default-hook)
3156 ("subnature" . vhdl-template-subnature-hook)
3157 ("terminal" . vhdl-template-terminal-hook)
3158 ("through" . vhdl-template-default-hook)
3159 ("tolerance" . vhdl-template-default-hook)
3161 ;; user model keywords
3162 (when (memq 'user vhdl-electric-keywords)
3163 (let (abbrev-list keyword)
3164 (dolist (elem vhdl-model-alist)
3165 (setq keyword (nth 3 elem))
3166 (unless (equal keyword "")
3167 (push (list keyword ""
3168 (vhdl-function-name
3169 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3170 abbrev-list)))
3171 abbrev-list)))))
3173 ;; initialize abbrev table for VHDL Mode
3174 (vhdl-mode-abbrev-table-init)
3176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3177 ;; Template completion lists
3179 (defvar vhdl-template-construct-alist nil
3180 "List of built-in construct templates.")
3182 (defun vhdl-template-construct-alist-init ()
3183 "Initialize `vhdl-template-construct-alist'."
3184 (setq
3185 vhdl-template-construct-alist
3186 (append
3188 ("alias declaration" vhdl-template-alias)
3189 ("architecture body" vhdl-template-architecture)
3190 ("assertion" vhdl-template-assert)
3191 ("attribute declaration" vhdl-template-attribute-decl)
3192 ("attribute specification" vhdl-template-attribute-spec)
3193 ("block configuration" vhdl-template-block-configuration)
3194 ("block statement" vhdl-template-block)
3195 ("case statement" vhdl-template-case-is)
3196 ("component configuration" vhdl-template-component-conf)
3197 ("component declaration" vhdl-template-component-decl)
3198 ("component instantiation statement" vhdl-template-component-inst)
3199 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3200 ("configuration declaration" vhdl-template-configuration-decl)
3201 ("configuration specification" vhdl-template-configuration-spec)
3202 ("constant declaration" vhdl-template-constant)
3203 ("context declaration" vhdl-template-context)
3204 ("disconnection specification" vhdl-template-disconnect)
3205 ("entity declaration" vhdl-template-entity)
3206 ("exit statement" vhdl-template-exit)
3207 ("file declaration" vhdl-template-file)
3208 ("generate statement" vhdl-template-generate)
3209 ("generic clause" vhdl-template-generic)
3210 ("group declaration" vhdl-template-group-decl)
3211 ("group template declaration" vhdl-template-group-template)
3212 ("if statement" vhdl-template-if-then)
3213 ("library clause" vhdl-template-library)
3214 ("loop statement" vhdl-template-loop)
3215 ("next statement" vhdl-template-next)
3216 ("package declaration" vhdl-template-package-decl)
3217 ("package body" vhdl-template-package-body)
3218 ("port clause" vhdl-template-port)
3219 ("process statement" vhdl-template-process)
3220 ("report statement" vhdl-template-report)
3221 ("return statement" vhdl-template-return)
3222 ("selected signal assignment" vhdl-template-selected-signal-asst)
3223 ("signal declaration" vhdl-template-signal)
3224 ("subprogram declaration" vhdl-template-subprogram-decl)
3225 ("subprogram body" vhdl-template-subprogram-body)
3226 ("subtype declaration" vhdl-template-subtype)
3227 ("type declaration" vhdl-template-type)
3228 ("use clause" vhdl-template-use)
3229 ("variable declaration" vhdl-template-variable)
3230 ("wait statement" vhdl-template-wait)
3232 (when (vhdl-standard-p 'ams)
3234 ("break statement" vhdl-template-break)
3235 ("nature declaration" vhdl-template-nature)
3236 ("quantity declaration" vhdl-template-quantity)
3237 ("simultaneous case statement" vhdl-template-case-use)
3238 ("simultaneous if statement" vhdl-template-if-use)
3239 ("simultaneous procedural statement" vhdl-template-procedural)
3240 ("step limit specification" vhdl-template-limit)
3241 ("subnature declaration" vhdl-template-subnature)
3242 ("terminal declaration" vhdl-template-terminal)
3243 )))))
3245 ;; initialize for VHDL Mode
3246 (vhdl-template-construct-alist-init)
3248 (defvar vhdl-template-package-alist nil
3249 "List of built-in package templates.")
3251 (defun vhdl-template-package-alist-init ()
3252 "Initialize `vhdl-template-package-alist'."
3253 (setq
3254 vhdl-template-package-alist
3255 (append
3257 ("numeric_bit" vhdl-template-package-numeric-bit)
3258 ("numeric_std" vhdl-template-package-numeric-std)
3259 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3260 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3261 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3262 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3263 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3264 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3265 ("textio" vhdl-template-package-textio)
3267 (when (vhdl-standard-p 'math)
3269 ("math_complex" vhdl-template-package-math-complex)
3270 ("math_real" vhdl-template-package-math-real)
3271 )))))
3273 ;; initialize for VHDL Mode
3274 (vhdl-template-package-alist-init)
3276 (defvar vhdl-template-directive-alist
3278 ("translate_on" vhdl-template-directive-translate-on)
3279 ("translate_off" vhdl-template-directive-translate-off)
3280 ("synthesis_on" vhdl-template-directive-synthesis-on)
3281 ("synthesis_off" vhdl-template-directive-synthesis-off)
3283 "List of built-in directive templates.")
3286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3287 ;;; Menus
3288 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3291 ;; VHDL menu (using `easy-menu.el')
3293 (defun vhdl-customize ()
3294 "Call the customize function with `vhdl' as argument."
3295 (interactive)
3296 (customize-browse 'vhdl))
3298 (defun vhdl-create-mode-menu ()
3299 "Create VHDL Mode menu."
3300 `("VHDL"
3301 ,(append
3302 '("Project"
3303 ["None" (vhdl-set-project "")
3304 :style radio :selected (null vhdl-project)]
3305 "--")
3306 ;; add menu entries for defined projects
3307 (let ((project-alist vhdl-project-alist) menu-list name)
3308 (while project-alist
3309 (setq name (caar project-alist))
3310 (setq menu-list
3311 (cons `[,name (vhdl-set-project ,name)
3312 :style radio :selected (equal ,name vhdl-project)]
3313 menu-list))
3314 (setq project-alist (cdr project-alist)))
3315 (setq menu-list
3316 (if vhdl-project-sort
3317 (sort menu-list
3318 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3319 (nreverse menu-list)))
3320 (vhdl-menu-split menu-list "Project"))
3321 '("--" "--"
3322 ["Select Project..." vhdl-set-project t]
3323 ["Set As Default Project" vhdl-set-default-project t]
3324 "--"
3325 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3326 ["Import Project..." vhdl-import-project
3327 :keys "C-c C-p C-m" :active t]
3328 ["Export Project" vhdl-export-project vhdl-project]
3329 "--"
3330 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3331 "--"
3332 ("Compile"
3333 ["Compile Buffer" vhdl-compile t]
3334 ["Stop Compilation" kill-compilation t]
3335 "--"
3336 ["Make" vhdl-make t]
3337 ["Generate Makefile" vhdl-generate-makefile t]
3338 "--"
3339 ["Next Error" next-error t]
3340 ["Previous Error" previous-error t]
3341 ["First Error" first-error t]
3342 "--"
3343 ,(append
3344 '("Compiler")
3345 ;; add menu entries for defined compilers
3346 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3347 (while comp-alist
3348 (setq name (caar comp-alist))
3349 (setq menu-list
3350 (cons `[,name (setq vhdl-compiler ,name)
3351 :style radio :selected (equal ,name vhdl-compiler)]
3352 menu-list))
3353 (setq comp-alist (cdr comp-alist)))
3354 (setq menu-list (nreverse menu-list))
3355 (vhdl-menu-split menu-list "Compiler"))
3356 '("--" "--"
3357 ["Select Compiler..." vhdl-set-compiler t]
3358 "--"
3359 ["Customize Compiler..."
3360 (customize-option 'vhdl-compiler-alist) t])))
3361 "--"
3362 ,(append
3363 '("Template"
3364 ("VHDL Construct 1"
3365 ["Alias" vhdl-template-alias t]
3366 ["Architecture" vhdl-template-architecture t]
3367 ["Assert" vhdl-template-assert t]
3368 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3369 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3370 ["Block" vhdl-template-block t]
3371 ["Case" vhdl-template-case-is t]
3372 ["Component (Decl)" vhdl-template-component-decl t]
3373 ["(Component) Instance" vhdl-template-component-inst t]
3374 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3375 ["Configuration (Block)" vhdl-template-block-configuration t]
3376 ["Configuration (Comp)" vhdl-template-component-conf t]
3377 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3378 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3379 ["Constant" vhdl-template-constant t]
3380 ["Context" vhdl-template-context t]
3381 ["Disconnect" vhdl-template-disconnect t]
3382 ["Else" vhdl-template-else t]
3383 ["Elsif" vhdl-template-elsif t]
3384 ["Entity" vhdl-template-entity t]
3385 ["Exit" vhdl-template-exit t]
3386 ["File" vhdl-template-file t]
3387 ["For (Generate)" vhdl-template-for-generate t]
3388 ["For (Loop)" vhdl-template-for-loop t]
3389 ["Function (Body)" vhdl-template-function-body t]
3390 ["Function (Decl)" vhdl-template-function-decl t]
3391 ["Generic" vhdl-template-generic t]
3392 ["Group (Decl)" vhdl-template-group-decl t]
3393 ["Group (Template)" vhdl-template-group-template t])
3394 ("VHDL Construct 2"
3395 ["If (Generate)" vhdl-template-if-generate t]
3396 ["If (Then)" vhdl-template-if-then t]
3397 ["Library" vhdl-template-library t]
3398 ["Loop" vhdl-template-bare-loop t]
3399 ["Map" vhdl-template-map t]
3400 ["Next" vhdl-template-next t]
3401 ["Others (Aggregate)" vhdl-template-others t]
3402 ["Package (Decl)" vhdl-template-package-decl t]
3403 ["Package (Body)" vhdl-template-package-body t]
3404 ["Port" vhdl-template-port t]
3405 ["Procedure (Body)" vhdl-template-procedure-body t]
3406 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3407 ["Process (Comb)" vhdl-template-process-comb t]
3408 ["Process (Seq)" vhdl-template-process-seq t]
3409 ["Report" vhdl-template-report t]
3410 ["Return" vhdl-template-return t]
3411 ["Select" vhdl-template-selected-signal-asst t]
3412 ["Signal" vhdl-template-signal t]
3413 ["Subtype" vhdl-template-subtype t]
3414 ["Type" vhdl-template-type t]
3415 ["Use" vhdl-template-use t]
3416 ["Variable" vhdl-template-variable t]
3417 ["Wait" vhdl-template-wait t]
3418 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3419 ["When" vhdl-template-when t]
3420 ["While (Loop)" vhdl-template-while-loop t]
3421 ["With" vhdl-template-with t]))
3422 (when (vhdl-standard-p 'ams)
3423 '(("VHDL-AMS Construct"
3424 ["Break" vhdl-template-break t]
3425 ["Case (Use)" vhdl-template-case-use t]
3426 ["If (Use)" vhdl-template-if-use t]
3427 ["Limit" vhdl-template-limit t]
3428 ["Nature" vhdl-template-nature t]
3429 ["Procedural" vhdl-template-procedural t]
3430 ["Quantity (Free)" vhdl-template-quantity-free t]
3431 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3432 ["Quantity (Source)" vhdl-template-quantity-source t]
3433 ["Subnature" vhdl-template-subnature t]
3434 ["Terminal" vhdl-template-terminal t])))
3435 '(["Insert Construct..." vhdl-template-insert-construct
3436 :keys "C-c C-i C-t"]
3437 "--")
3438 (list
3439 (append
3440 '("Package")
3441 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3442 ["numeric_std" vhdl-template-package-numeric-std t]
3443 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3444 ["textio" vhdl-template-package-textio t]
3445 "--"
3446 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3447 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3448 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3449 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3450 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3451 "--")
3452 (when (vhdl-standard-p 'ams)
3453 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3454 ["material_constants" vhdl-template-package-material-constants t]
3455 ["energy_systems" vhdl-template-package-energy-systems t]
3456 ["electrical_systems" vhdl-template-package-electrical-systems t]
3457 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3458 ["radiant_systems" vhdl-template-package-radiant-systems t]
3459 ["thermal_systems" vhdl-template-package-thermal-systems t]
3460 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3461 "--"))
3462 (when (vhdl-standard-p 'math)
3463 '(["math_complex" vhdl-template-package-math-complex t]
3464 ["math_real" vhdl-template-package-math-real t]
3465 "--"))
3466 '(["Insert Package..." vhdl-template-insert-package
3467 :keys "C-c C-i C-p"])))
3468 '(("Directive"
3469 ["translate_on" vhdl-template-directive-translate-on t]
3470 ["translate_off" vhdl-template-directive-translate-off t]
3471 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3472 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3473 "--"
3474 ["Insert Directive..." vhdl-template-insert-directive
3475 :keys "C-c C-i C-d"])
3476 "--"
3477 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3478 ["Insert Footer" vhdl-template-footer t]
3479 ["Insert Date" vhdl-template-insert-date t]
3480 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3481 "--"
3482 ["Query Next Prompt" vhdl-template-search-prompt t]))
3483 ,(append
3484 '("Model")
3485 ;; add menu entries for defined models
3486 (let ((model-alist vhdl-model-alist) menu-list model)
3487 (while model-alist
3488 (setq model (car model-alist))
3489 (setq menu-list
3490 (cons
3491 (vector
3492 (nth 0 model)
3493 (vhdl-function-name "vhdl-model" (nth 0 model))
3494 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3495 menu-list))
3496 (setq model-alist (cdr model-alist)))
3497 (setq menu-list (nreverse menu-list))
3498 (vhdl-menu-split menu-list "Model"))
3499 '("--" "--"
3500 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3501 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3502 ("Port"
3503 ["Copy" vhdl-port-copy t]
3504 "--"
3505 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3506 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3507 ["Paste As Instance" vhdl-port-paste-instance
3508 :keys "C-c C-p C-i" :active vhdl-port-list]
3509 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3510 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3511 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3512 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3513 "--"
3514 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3515 "--"
3516 ["Flatten" vhdl-port-flatten
3517 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3518 ["Reverse Direction" vhdl-port-reverse-direction
3519 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3520 ("Compose"
3521 ["New Component" vhdl-compose-new-component t]
3522 ["Copy Component" vhdl-port-copy t]
3523 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3524 ["Wire Components" vhdl-compose-wire-components t]
3525 "--"
3526 ["Generate Configuration" vhdl-compose-configuration t]
3527 ["Generate Components Package" vhdl-compose-components-package t])
3528 ("Subprogram"
3529 ["Copy" vhdl-subprog-copy t]
3530 "--"
3531 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3532 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3533 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3534 "--"
3535 ["Flatten" vhdl-subprog-flatten
3536 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3537 "--"
3538 ("Comment"
3539 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3540 "--"
3541 ["Insert Inline Comment" vhdl-comment-append-inline t]
3542 ["Insert Horizontal Line" vhdl-comment-display-line t]
3543 ["Insert Display Comment" vhdl-comment-display t]
3544 "--"
3545 ["Fill Comment" fill-paragraph t]
3546 ["Fill Comment Region" fill-region (mark)]
3547 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3548 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3549 ("Line"
3550 ["Kill" vhdl-line-kill t]
3551 ["Copy" vhdl-line-copy t]
3552 ["Yank" vhdl-line-yank t]
3553 ["Expand" vhdl-line-expand t]
3554 "--"
3555 ["Transpose Next" vhdl-line-transpose-next t]
3556 ["Transpose Prev" vhdl-line-transpose-previous t]
3557 ["Open" vhdl-line-open t]
3558 ["Join" vhdl-delete-indentation t]
3559 "--"
3560 ["Goto" goto-line t]
3561 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3562 ("Move"
3563 ["Forward Statement" vhdl-end-of-statement t]
3564 ["Backward Statement" vhdl-beginning-of-statement t]
3565 ["Forward Expression" vhdl-forward-sexp t]
3566 ["Backward Expression" vhdl-backward-sexp t]
3567 ["Forward Same Indent" vhdl-forward-same-indent t]
3568 ["Backward Same Indent" vhdl-backward-same-indent t]
3569 ["Forward Function" vhdl-end-of-defun t]
3570 ["Backward Function" vhdl-beginning-of-defun t]
3571 ["Mark Function" vhdl-mark-defun t])
3572 "--"
3573 ("Indent"
3574 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3575 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3576 ["Region" vhdl-indent-region (mark)]
3577 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3578 ("Align"
3579 ["Group" vhdl-align-group t]
3580 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3581 ["List" vhdl-align-list t]
3582 ["Declarations" vhdl-align-declarations t]
3583 ["Region" vhdl-align-region (mark)]
3584 ["Buffer" vhdl-align-buffer t]
3585 "--"
3586 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3587 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3588 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3589 ("Fill"
3590 ["List" vhdl-fill-list t]
3591 ["Group" vhdl-fill-group t]
3592 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3593 ["Region" vhdl-fill-region (mark)])
3594 ("Beautify"
3595 ["Region" vhdl-beautify-region (mark)]
3596 ["Buffer" vhdl-beautify-buffer t])
3597 ("Fix"
3598 ["Generic/Port Clause" vhdl-fix-clause t]
3599 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3600 "--"
3601 ["Case Region" vhdl-fix-case-region (mark)]
3602 ["Case Buffer" vhdl-fix-case-buffer t]
3603 "--"
3604 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3605 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3606 "--"
3607 ["Statement Region" vhdl-fix-statement-region (mark)]
3608 ["Statement Buffer" vhdl-fix-statement-buffer t]
3609 "--"
3610 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3611 ("Update"
3612 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3613 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3614 "--"
3615 ["Fontify Buffer" vhdl-fontify-buffer t]
3616 ["Statistics Buffer" vhdl-statistics-buffer t]
3617 ["Show Messages" vhdl-show-messages t]
3618 ["Syntactic Info" vhdl-show-syntactic-information t]
3619 "--"
3620 ["Speedbar" vhdl-speedbar t]
3621 ["Hide/Show" vhdl-hs-minor-mode t]
3622 "--"
3623 ("Documentation"
3624 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3625 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3626 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3627 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3628 ["Version" vhdl-version t]
3629 ["Bug Report..." vhdl-submit-bug-report t]
3630 "--"
3631 ("Options"
3632 ("Mode"
3633 ["Electric Mode"
3634 (progn (customize-set-variable 'vhdl-electric-mode
3635 (not vhdl-electric-mode))
3636 (vhdl-mode-line-update))
3637 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3638 ["Stutter Mode"
3639 (progn (customize-set-variable 'vhdl-stutter-mode
3640 (not vhdl-stutter-mode))
3641 (vhdl-mode-line-update))
3642 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3643 ["Indent Tabs Mode"
3644 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3645 (not vhdl-indent-tabs-mode))
3646 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3647 :style toggle :selected vhdl-indent-tabs-mode]
3648 "--"
3649 ["Customize Group..." (customize-group 'vhdl-mode) t])
3650 ("Project"
3651 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3652 ,(append
3653 '("Selected Project at Startup"
3654 ["None" (progn (customize-set-variable 'vhdl-project nil)
3655 (vhdl-set-project ""))
3656 :style radio :selected (null vhdl-project)]
3657 "--")
3658 ;; add menu entries for defined projects
3659 (let ((project-alist vhdl-project-alist) menu-list name)
3660 (while project-alist
3661 (setq name (caar project-alist))
3662 (setq menu-list
3663 (cons `[,name (progn (customize-set-variable
3664 'vhdl-project ,name)
3665 (vhdl-set-project ,name))
3666 :style radio :selected (equal ,name vhdl-project)]
3667 menu-list))
3668 (setq project-alist (cdr project-alist)))
3669 (setq menu-list (nreverse menu-list))
3670 (vhdl-menu-split menu-list "Project")))
3671 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3672 ("Auto Load Setup File"
3673 ["At Startup"
3674 (customize-set-variable 'vhdl-project-auto-load
3675 (if (memq 'startup vhdl-project-auto-load)
3676 (delq 'startup vhdl-project-auto-load)
3677 (cons 'startup vhdl-project-auto-load)))
3678 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3679 ["Sort Projects"
3680 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3681 :style toggle :selected vhdl-project-sort]
3682 "--"
3683 ["Customize Group..." (customize-group 'vhdl-project) t])
3684 ("Compiler"
3685 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3686 ,(append
3687 '("Selected Compiler at Startup")
3688 ;; add menu entries for defined compilers
3689 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3690 (while comp-alist
3691 (setq name (caar comp-alist))
3692 (setq menu-list
3693 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3694 :style radio :selected (equal ,name vhdl-compiler)]
3695 menu-list))
3696 (setq comp-alist (cdr comp-alist)))
3697 (setq menu-list (nreverse menu-list))
3698 (vhdl-menu-split menu-list "Compiler")))
3699 ["Use Local Error Regexp"
3700 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3701 (not vhdl-compile-use-local-error-regexp))
3702 :style toggle :selected vhdl-compile-use-local-error-regexp]
3703 ["Makefile Default Targets..."
3704 (customize-option 'vhdl-makefile-default-targets) t]
3705 ["Makefile Generation Hook..."
3706 (customize-option 'vhdl-makefile-generation-hook) t]
3707 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3708 "--"
3709 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3710 ("Style"
3711 ("VHDL Standard"
3712 ["VHDL'87"
3713 (progn (customize-set-variable 'vhdl-standard
3714 (list '87 (cadr vhdl-standard)))
3715 (vhdl-activate-customizations))
3716 :style radio :selected (eq '87 (car vhdl-standard))]
3717 ["VHDL'93/02"
3718 (progn (customize-set-variable 'vhdl-standard
3719 (list '93 (cadr vhdl-standard)))
3720 (vhdl-activate-customizations))
3721 :style radio :selected (eq '93 (car vhdl-standard))]
3722 ["VHDL'08"
3723 (progn (customize-set-variable 'vhdl-standard
3724 (list '08 (cadr vhdl-standard)))
3725 (vhdl-activate-customizations))
3726 :style radio :selected (eq '08 (car vhdl-standard))]
3727 "--"
3728 ["VHDL-AMS"
3729 (progn (customize-set-variable
3730 'vhdl-standard (list (car vhdl-standard)
3731 (if (memq 'ams (cadr vhdl-standard))
3732 (delq 'ams (cadr vhdl-standard))
3733 (cons 'ams (cadr vhdl-standard)))))
3734 (vhdl-activate-customizations))
3735 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3736 ["Math Packages"
3737 (progn (customize-set-variable
3738 'vhdl-standard (list (car vhdl-standard)
3739 (if (memq 'math (cadr vhdl-standard))
3740 (delq 'math (cadr vhdl-standard))
3741 (cons 'math (cadr vhdl-standard)))))
3742 (vhdl-activate-customizations))
3743 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3744 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3745 ["Upper Case Keywords"
3746 (customize-set-variable 'vhdl-upper-case-keywords
3747 (not vhdl-upper-case-keywords))
3748 :style toggle :selected vhdl-upper-case-keywords]
3749 ["Upper Case Types"
3750 (customize-set-variable 'vhdl-upper-case-types
3751 (not vhdl-upper-case-types))
3752 :style toggle :selected vhdl-upper-case-types]
3753 ["Upper Case Attributes"
3754 (customize-set-variable 'vhdl-upper-case-attributes
3755 (not vhdl-upper-case-attributes))
3756 :style toggle :selected vhdl-upper-case-attributes]
3757 ["Upper Case Enumeration Values"
3758 (customize-set-variable 'vhdl-upper-case-enum-values
3759 (not vhdl-upper-case-enum-values))
3760 :style toggle :selected vhdl-upper-case-enum-values]
3761 ["Upper Case Constants"
3762 (customize-set-variable 'vhdl-upper-case-constants
3763 (not vhdl-upper-case-constants))
3764 :style toggle :selected vhdl-upper-case-constants]
3765 ("Use Direct Instantiation"
3766 ["Never"
3767 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3768 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3769 ["Standard"
3770 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3771 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3772 ["Always"
3773 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3774 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3775 ["Include Array Index and Record Field in Sensitivity List"
3776 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3777 (not vhdl-array-index-record-field-in-sensitivity-list))
3778 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3779 "--"
3780 ["Customize Group..." (customize-group 'vhdl-style) t])
3781 ("Naming"
3782 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3783 ["Architecture File Name..."
3784 (customize-option 'vhdl-architecture-file-name) t]
3785 ["Configuration File Name..."
3786 (customize-option 'vhdl-configuration-file-name) t]
3787 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3788 ("File Name Case"
3789 ["As Is"
3790 (customize-set-variable 'vhdl-file-name-case 'identity)
3791 :style radio :selected (eq 'identity vhdl-file-name-case)]
3792 ["Lower Case"
3793 (customize-set-variable 'vhdl-file-name-case 'downcase)
3794 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3795 ["Upper Case"
3796 (customize-set-variable 'vhdl-file-name-case 'upcase)
3797 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3798 ["Capitalize"
3799 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3800 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3801 "--"
3802 ["Customize Group..." (customize-group 'vhdl-naming) t])
3803 ("Template"
3804 ("Electric Keywords"
3805 ["VHDL Keywords"
3806 (customize-set-variable 'vhdl-electric-keywords
3807 (if (memq 'vhdl vhdl-electric-keywords)
3808 (delq 'vhdl vhdl-electric-keywords)
3809 (cons 'vhdl vhdl-electric-keywords)))
3810 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3811 ["User Model Keywords"
3812 (customize-set-variable 'vhdl-electric-keywords
3813 (if (memq 'user vhdl-electric-keywords)
3814 (delq 'user vhdl-electric-keywords)
3815 (cons 'user vhdl-electric-keywords)))
3816 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3817 ("Insert Optional Labels"
3818 ["None"
3819 (customize-set-variable 'vhdl-optional-labels 'none)
3820 :style radio :selected (eq 'none vhdl-optional-labels)]
3821 ["Processes Only"
3822 (customize-set-variable 'vhdl-optional-labels 'process)
3823 :style radio :selected (eq 'process vhdl-optional-labels)]
3824 ["All Constructs"
3825 (customize-set-variable 'vhdl-optional-labels 'all)
3826 :style radio :selected (eq 'all vhdl-optional-labels)])
3827 ("Insert Empty Lines"
3828 ["None"
3829 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3830 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3831 ["Design Units Only"
3832 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3833 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3834 ["All Constructs"
3835 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3836 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3837 ["Argument List Indent"
3838 (customize-set-variable 'vhdl-argument-list-indent
3839 (not vhdl-argument-list-indent))
3840 :style toggle :selected vhdl-argument-list-indent]
3841 ["Association List with Formals"
3842 (customize-set-variable 'vhdl-association-list-with-formals
3843 (not vhdl-association-list-with-formals))
3844 :style toggle :selected vhdl-association-list-with-formals]
3845 ["Conditions in Parenthesis"
3846 (customize-set-variable 'vhdl-conditions-in-parenthesis
3847 (not vhdl-conditions-in-parenthesis))
3848 :style toggle :selected vhdl-conditions-in-parenthesis]
3849 ["Sensitivity List uses 'all'"
3850 (customize-set-variable 'vhdl-sensitivity-list-all
3851 (not vhdl-sensitivity-list-all))
3852 :style toggle :selected vhdl-sensitivity-list-all]
3853 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3854 ["One String..." (customize-option 'vhdl-one-string) t]
3855 ("File Header"
3856 ["Header String..." (customize-option 'vhdl-file-header) t]
3857 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3858 ["Company Name..." (customize-option 'vhdl-company-name) t]
3859 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3860 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3861 ["Date Format..." (customize-option 'vhdl-date-format) t]
3862 ["Modify Date Prefix String..."
3863 (customize-option 'vhdl-modify-date-prefix-string) t]
3864 ["Modify Date on Saving"
3865 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3866 (not vhdl-modify-date-on-saving))
3867 (vhdl-activate-customizations))
3868 :style toggle :selected vhdl-modify-date-on-saving])
3869 ("Sequential Process"
3870 ("Kind of Reset"
3871 ["None"
3872 (customize-set-variable 'vhdl-reset-kind 'none)
3873 :style radio :selected (eq 'none vhdl-reset-kind)]
3874 ["Synchronous"
3875 (customize-set-variable 'vhdl-reset-kind 'sync)
3876 :style radio :selected (eq 'sync vhdl-reset-kind)]
3877 ["Asynchronous"
3878 (customize-set-variable 'vhdl-reset-kind 'async)
3879 :style radio :selected (eq 'async vhdl-reset-kind)]
3880 ["Query"
3881 (customize-set-variable 'vhdl-reset-kind 'query)
3882 :style radio :selected (eq 'query vhdl-reset-kind)])
3883 ["Reset is Active High"
3884 (customize-set-variable 'vhdl-reset-active-high
3885 (not vhdl-reset-active-high))
3886 :style toggle :selected vhdl-reset-active-high]
3887 ["Use Rising Clock Edge"
3888 (customize-set-variable 'vhdl-clock-rising-edge
3889 (not vhdl-clock-rising-edge))
3890 :style toggle :selected vhdl-clock-rising-edge]
3891 ("Clock Edge Condition"
3892 ["Standard"
3893 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3894 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3895 ["Function \"rising_edge\""
3896 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3897 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3898 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3899 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3900 "--"
3901 ["Customize Group..." (customize-group 'vhdl-template) t])
3902 ("Model"
3903 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3904 ("Port"
3905 ["Include Port Comments"
3906 (customize-set-variable 'vhdl-include-port-comments
3907 (not vhdl-include-port-comments))
3908 :style toggle :selected vhdl-include-port-comments]
3909 ["Include Direction Comments"
3910 (customize-set-variable 'vhdl-include-direction-comments
3911 (not vhdl-include-direction-comments))
3912 :style toggle :selected vhdl-include-direction-comments]
3913 ["Include Type Comments"
3914 (customize-set-variable 'vhdl-include-type-comments
3915 (not vhdl-include-type-comments))
3916 :style toggle :selected vhdl-include-type-comments]
3917 ("Include Group Comments"
3918 ["Never"
3919 (customize-set-variable 'vhdl-include-group-comments 'never)
3920 :style radio :selected (eq 'never vhdl-include-group-comments)]
3921 ["Declarations"
3922 (customize-set-variable 'vhdl-include-group-comments 'decl)
3923 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3924 ["Always"
3925 (customize-set-variable 'vhdl-include-group-comments 'always)
3926 :style radio :selected (eq 'always vhdl-include-group-comments)])
3927 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3928 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3929 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3930 ("Testbench"
3931 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3932 ["Architecture Name..."
3933 (customize-option 'vhdl-testbench-architecture-name) t]
3934 ["Configuration Name..."
3935 (customize-option 'vhdl-testbench-configuration-name) t]
3936 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3937 ["Include Header"
3938 (customize-set-variable 'vhdl-testbench-include-header
3939 (not vhdl-testbench-include-header))
3940 :style toggle :selected vhdl-testbench-include-header]
3941 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3942 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3943 ["Initialize Signals"
3944 (customize-set-variable 'vhdl-testbench-initialize-signals
3945 (not vhdl-testbench-initialize-signals))
3946 :style toggle :selected vhdl-testbench-initialize-signals]
3947 ["Include Library Clause"
3948 (customize-set-variable 'vhdl-testbench-include-library
3949 (not vhdl-testbench-include-library))
3950 :style toggle :selected vhdl-testbench-include-library]
3951 ["Include Configuration"
3952 (customize-set-variable 'vhdl-testbench-include-configuration
3953 (not vhdl-testbench-include-configuration))
3954 :style toggle :selected vhdl-testbench-include-configuration]
3955 ("Create Files"
3956 ["None"
3957 (customize-set-variable 'vhdl-testbench-create-files 'none)
3958 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3959 ["Single"
3960 (customize-set-variable 'vhdl-testbench-create-files 'single)
3961 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3962 ["Separate"
3963 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3964 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3965 ["Testbench Entity File Name..."
3966 (customize-option 'vhdl-testbench-entity-file-name) t]
3967 ["Testbench Architecture File Name..."
3968 (customize-option 'vhdl-testbench-architecture-file-name) t])
3969 "--"
3970 ["Customize Group..." (customize-group 'vhdl-port) t])
3971 ("Compose"
3972 ["Architecture Name..."
3973 (customize-option 'vhdl-compose-architecture-name) t]
3974 ["Configuration Name..."
3975 (customize-option 'vhdl-compose-configuration-name) t]
3976 ["Components Package Name..."
3977 (customize-option 'vhdl-components-package-name) t]
3978 ["Use Components Package"
3979 (customize-set-variable 'vhdl-use-components-package
3980 (not vhdl-use-components-package))
3981 :style toggle :selected vhdl-use-components-package]
3982 ["Include Header"
3983 (customize-set-variable 'vhdl-compose-include-header
3984 (not vhdl-compose-include-header))
3985 :style toggle :selected vhdl-compose-include-header]
3986 ("Create Entity/Architecture Files"
3987 ["None"
3988 (customize-set-variable 'vhdl-compose-create-files 'none)
3989 :style radio :selected (eq 'none vhdl-compose-create-files)]
3990 ["Single"
3991 (customize-set-variable 'vhdl-compose-create-files 'single)
3992 :style radio :selected (eq 'single vhdl-compose-create-files)]
3993 ["Separate"
3994 (customize-set-variable 'vhdl-compose-create-files 'separate)
3995 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3996 ["Create Configuration File"
3997 (customize-set-variable 'vhdl-compose-configuration-create-file
3998 (not vhdl-compose-configuration-create-file))
3999 :style toggle :selected vhdl-compose-configuration-create-file]
4000 ["Hierarchical Configuration"
4001 (customize-set-variable 'vhdl-compose-configuration-hierarchical
4002 (not vhdl-compose-configuration-hierarchical))
4003 :style toggle :selected vhdl-compose-configuration-hierarchical]
4004 ["Use Subconfiguration"
4005 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
4006 (not vhdl-compose-configuration-use-subconfiguration))
4007 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
4008 "--"
4009 ["Customize Group..." (customize-group 'vhdl-compose) t])
4010 ("Comment"
4011 ["Self Insert Comments"
4012 (customize-set-variable 'vhdl-self-insert-comments
4013 (not vhdl-self-insert-comments))
4014 :style toggle :selected vhdl-self-insert-comments]
4015 ["Prompt for Comments"
4016 (customize-set-variable 'vhdl-prompt-for-comments
4017 (not vhdl-prompt-for-comments))
4018 :style toggle :selected vhdl-prompt-for-comments]
4019 ["Inline Comment Column..."
4020 (customize-option 'vhdl-inline-comment-column) t]
4021 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4022 "--"
4023 ["Customize Group..." (customize-group 'vhdl-comment) t])
4024 ("Beautify"
4025 ["Auto Align Templates"
4026 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4027 :style toggle :selected vhdl-auto-align]
4028 ["Align Line Groups"
4029 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4030 :style toggle :selected vhdl-align-groups]
4031 ["Group Separation String..."
4032 (customize-option 'vhdl-align-group-separate) t]
4033 ["Align Lines with Same Indent"
4034 (customize-set-variable 'vhdl-align-same-indent
4035 (not vhdl-align-same-indent))
4036 :style toggle :selected vhdl-align-same-indent]
4037 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4038 "--"
4039 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4040 ("Highlight"
4041 ["Highlighting On/Off..."
4042 (customize-option
4043 (if (fboundp 'global-font-lock-mode)
4044 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4045 ["Highlight Keywords"
4046 (progn (customize-set-variable 'vhdl-highlight-keywords
4047 (not vhdl-highlight-keywords))
4048 (vhdl-fontify-buffer))
4049 :style toggle :selected vhdl-highlight-keywords]
4050 ["Highlight Names"
4051 (progn (customize-set-variable 'vhdl-highlight-names
4052 (not vhdl-highlight-names))
4053 (vhdl-fontify-buffer))
4054 :style toggle :selected vhdl-highlight-names]
4055 ["Highlight Special Words"
4056 (progn (customize-set-variable 'vhdl-highlight-special-words
4057 (not vhdl-highlight-special-words))
4058 (vhdl-fontify-buffer))
4059 :style toggle :selected vhdl-highlight-special-words]
4060 ["Highlight Forbidden Words"
4061 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4062 (not vhdl-highlight-forbidden-words))
4063 (vhdl-fontify-buffer))
4064 :style toggle :selected vhdl-highlight-forbidden-words]
4065 ["Highlight Verilog Keywords"
4066 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4067 (not vhdl-highlight-verilog-keywords))
4068 (vhdl-fontify-buffer))
4069 :style toggle :selected vhdl-highlight-verilog-keywords]
4070 ["Highlight \"translate_off\""
4071 (progn (customize-set-variable 'vhdl-highlight-translate-off
4072 (not vhdl-highlight-translate-off))
4073 (vhdl-fontify-buffer))
4074 :style toggle :selected vhdl-highlight-translate-off]
4075 ["Case Sensitive Highlighting"
4076 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4077 (not vhdl-highlight-case-sensitive))
4078 (vhdl-fontify-buffer))
4079 :style toggle :selected vhdl-highlight-case-sensitive]
4080 ["Special Syntax Definition..."
4081 (customize-option 'vhdl-special-syntax-alist) t]
4082 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4083 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4084 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4085 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4086 "--"
4087 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4088 ("Speedbar"
4089 ["Auto Open at Startup"
4090 (customize-set-variable 'vhdl-speedbar-auto-open
4091 (not vhdl-speedbar-auto-open))
4092 :style toggle :selected vhdl-speedbar-auto-open]
4093 ("Default Displaying Mode"
4094 ["Files"
4095 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4096 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4097 ["Directory Hierarchy"
4098 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4099 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4100 ["Project Hierarchy"
4101 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4102 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4103 ["Indentation Offset..."
4104 (customize-option 'speedbar-indentation-width) t]
4105 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4106 ["Jump to Unit when Opening"
4107 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4108 (not vhdl-speedbar-jump-to-unit))
4109 :style toggle :selected vhdl-speedbar-jump-to-unit]
4110 ["Update Hierarchy on File Saving"
4111 (customize-set-variable 'vhdl-speedbar-update-on-saving
4112 (not vhdl-speedbar-update-on-saving))
4113 :style toggle :selected vhdl-speedbar-update-on-saving]
4114 ("Save in Cache File"
4115 ["Hierarchy Information"
4116 (customize-set-variable 'vhdl-speedbar-save-cache
4117 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4118 (delq 'hierarchy vhdl-speedbar-save-cache)
4119 (cons 'hierarchy vhdl-speedbar-save-cache)))
4120 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4121 ["Displaying Status"
4122 (customize-set-variable 'vhdl-speedbar-save-cache
4123 (if (memq 'display vhdl-speedbar-save-cache)
4124 (delq 'display vhdl-speedbar-save-cache)
4125 (cons 'display vhdl-speedbar-save-cache)))
4126 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4127 ["Cache File Name..."
4128 (customize-option 'vhdl-speedbar-cache-file-name) t]
4129 "--"
4130 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4131 ("Menu"
4132 ["Add Index Menu when Loading File"
4133 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4134 (vhdl-index-menu-init))
4135 :style toggle :selected vhdl-index-menu]
4136 ["Add Source File Menu when Loading File"
4137 (progn (customize-set-variable 'vhdl-source-file-menu
4138 (not vhdl-source-file-menu))
4139 (vhdl-add-source-files-menu))
4140 :style toggle :selected vhdl-source-file-menu]
4141 ["Add Hideshow Menu at Startup"
4142 (progn (customize-set-variable 'vhdl-hideshow-menu
4143 (not vhdl-hideshow-menu))
4144 (vhdl-activate-customizations))
4145 :style toggle :selected vhdl-hideshow-menu]
4146 ["Hide Everything Initially"
4147 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4148 :style toggle :selected vhdl-hide-all-init]
4149 "--"
4150 ["Customize Group..." (customize-group 'vhdl-menu) t])
4151 ("Print"
4152 ["In Two Column Format"
4153 (progn (customize-set-variable 'vhdl-print-two-column
4154 (not vhdl-print-two-column))
4155 (message "Activate new setting by saving options and restarting Emacs"))
4156 :style toggle :selected vhdl-print-two-column]
4157 ["Use Customized Faces"
4158 (progn (customize-set-variable 'vhdl-print-customize-faces
4159 (not vhdl-print-customize-faces))
4160 (message "Activate new setting by saving options and restarting Emacs"))
4161 :style toggle :selected vhdl-print-customize-faces]
4162 "--"
4163 ["Customize Group..." (customize-group 'vhdl-print) t])
4164 ("Miscellaneous"
4165 ["Use Intelligent Tab"
4166 (progn (customize-set-variable 'vhdl-intelligent-tab
4167 (not vhdl-intelligent-tab))
4168 (vhdl-activate-customizations))
4169 :style toggle :selected vhdl-intelligent-tab]
4170 ["Indent Syntax-Based"
4171 (customize-set-variable 'vhdl-indent-syntax-based
4172 (not vhdl-indent-syntax-based))
4173 :style toggle :selected vhdl-indent-syntax-based]
4174 ["Indent Comments Like Next Code Line"
4175 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4176 (not vhdl-indent-comment-like-next-code-line))
4177 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4178 ["Word Completion is Case Sensitive"
4179 (customize-set-variable 'vhdl-word-completion-case-sensitive
4180 (not vhdl-word-completion-case-sensitive))
4181 :style toggle :selected vhdl-word-completion-case-sensitive]
4182 ["Word Completion in Minibuffer"
4183 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4184 (not vhdl-word-completion-in-minibuffer))
4185 (message "Activate new setting by saving options and restarting Emacs"))
4186 :style toggle :selected vhdl-word-completion-in-minibuffer]
4187 ["Underscore is Part of Word"
4188 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4189 (not vhdl-underscore-is-part-of-word))
4190 (vhdl-activate-customizations))
4191 :style toggle :selected vhdl-underscore-is-part-of-word]
4192 "--"
4193 ["Customize Group..." (customize-group 'vhdl-misc) t])
4194 ["Related..." (customize-browse 'vhdl-related) t]
4195 "--"
4196 ["Save Options" customize-save-customized t]
4197 ["Activate Options" vhdl-activate-customizations t]
4198 ["Browse Options..." vhdl-customize t])))
4200 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4201 "VHDL Mode menu.")
4203 (defun vhdl-update-mode-menu ()
4204 "Update VHDL Mode menu."
4205 (interactive)
4206 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4207 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4208 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4209 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4210 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4213 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4215 (defconst vhdl-imenu-generic-expression
4217 ("Subprogram"
4218 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4220 ("Instance"
4221 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4223 ("Component"
4224 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4226 ("Procedural"
4227 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4229 ("Process"
4230 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4232 ("Block"
4233 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4235 ("Package"
4236 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4238 ("Configuration"
4239 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4241 ("Architecture"
4242 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4244 ("Entity"
4245 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4247 ("Context"
4248 "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4251 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4253 (defun vhdl-index-menu-init ()
4254 "Initialize index menu."
4255 (set (make-local-variable 'imenu-case-fold-search) t)
4256 (set (make-local-variable 'imenu-generic-expression)
4257 vhdl-imenu-generic-expression)
4258 (when (and vhdl-index-menu (fboundp 'imenu))
4259 (imenu-add-to-menubar "Index")))
4261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4262 ;; Source file menu (using `easy-menu.el')
4264 (defvar vhdl-sources-menu nil)
4266 (defun vhdl-directory-files (directory &optional full match)
4267 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4268 message."
4269 (if (not (file-directory-p directory))
4270 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4271 (let ((dir (directory-files directory full match)))
4272 (setq dir (delete "." dir))
4273 (setq dir (delete ".." dir))
4274 dir)))
4276 (defun vhdl-get-source-files (&optional full directory)
4277 "Get list of VHDL source files in DIRECTORY or current directory."
4278 (let ((mode-alist auto-mode-alist)
4279 filename-regexp)
4280 ;; create regular expressions for matching file names
4281 (setq filename-regexp "\\`[^.].*\\(")
4282 (while mode-alist
4283 (when (eq (cdar mode-alist) 'vhdl-mode)
4284 (setq filename-regexp
4285 (concat filename-regexp (caar mode-alist) "\\|")))
4286 (setq mode-alist (cdr mode-alist)))
4287 (setq filename-regexp
4288 (concat (substring filename-regexp 0
4289 (string-match "\\\\|$" filename-regexp)) "\\)"))
4290 ;; find files
4291 (vhdl-directory-files
4292 (or directory default-directory) full filename-regexp)))
4294 (defun vhdl-add-source-files-menu ()
4295 "Scan directory for all VHDL source files and generate menu.
4296 The directory of the current source file is scanned."
4297 (interactive)
4298 (message "Scanning directory for source files ...")
4299 (let ((newmap (current-local-map))
4300 (file-list (vhdl-get-source-files))
4301 menu-list found)
4302 ;; Create list for menu
4303 (setq found nil)
4304 (while file-list
4305 (setq found t)
4306 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4307 menu-list)
4308 (setq file-list (cdr file-list)))
4309 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4310 (when found (push "--" menu-list))
4311 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4312 (push "Sources" menu-list)
4313 ;; Create menu
4314 (easy-menu-add menu-list)
4315 (easy-menu-define vhdl-sources-menu newmap
4316 "VHDL source files menu" menu-list))
4317 (message ""))
4320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4321 ;;; Mode definition
4322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4323 ;; performs all buffer local initializations
4325 ;;;###autoload
4326 (define-derived-mode vhdl-mode prog-mode
4327 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4328 (vhdl-electric-mode "e")
4329 (vhdl-stutter-mode "s"))
4330 "Major mode for editing VHDL code.
4332 Usage:
4333 ------
4335 TEMPLATE INSERTION (electrification):
4336 After typing a VHDL keyword and entering `SPC', you are prompted for
4337 arguments while a template is generated for that VHDL construct. Typing
4338 `RET' or `C-g' at the first (mandatory) prompt aborts the current
4339 template generation. Optional arguments are indicated by square
4340 brackets and removed if the queried string is left empty. Prompts for
4341 mandatory arguments remain in the code if the queried string is left
4342 empty. They can be queried again by `C-c C-t C-q'. Enabled
4343 electrification is indicated by `/e' in the mode line.
4345 Typing `M-SPC' after a keyword inserts a space without calling the
4346 template generator. Automatic template generation (i.e.
4347 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4348 setting option `vhdl-electric-mode' (see OPTIONS).
4350 Template generators can be invoked from the VHDL menu, by key
4351 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4352 the keyword (i.e. first word of menu entry not in parenthesis) and
4353 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4354 conf, comp, cons, func, inst, pack, sig, var.
4356 Template styles can be customized in customization group
4357 `vhdl-template' (see OPTIONS).
4360 HEADER INSERTION:
4361 A file header can be inserted by `C-c C-t C-h'. A file footer
4362 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4363 See customization group `vhdl-header'.
4366 STUTTERING:
4367 Double striking of some keys inserts cumbersome VHDL syntax elements.
4368 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4369 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4370 the mode line. The stuttering keys and their effects are:
4372 ;; --> \" : \" [ --> ( -- --> comment
4373 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4374 .. --> \" => \" ] --> ) --- --> horizontal line
4375 ,, --> \" <= \" ]] --> ] ---- --> display comment
4376 == --> \" == \" \\='\\=' --> \\\"
4379 WORD COMPLETION:
4380 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4381 word in the buffer that starts alike, inserts it and adjusts case.
4382 Re-typing `TAB' toggles through alternative word completions. This also
4383 works in the minibuffer (i.e. in template generator prompts).
4385 Typing `TAB' after `(' looks for and inserts complete parenthesized
4386 expressions (e.g. for array index ranges). All keywords as well as
4387 standard types and subprograms of VHDL have predefined abbreviations
4388 (e.g., type \"std\" and `TAB' will toggle through all standard types
4389 beginning with \"std\").
4391 Typing `TAB' after a non-word character indents the line if at the
4392 beginning of a line (i.e. no preceding non-blank characters), and
4393 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4394 stop.
4397 COMMENTS:
4398 `--' puts a single comment.
4399 `---' draws a horizontal line for separating code segments.
4400 `----' inserts a display comment, i.e. two horizontal lines
4401 with a comment in between.
4402 `--CR' comments out code on that line. Re-hitting CR comments
4403 out following lines.
4404 `C-c C-c' comments out a region if not commented out,
4405 uncomments a region if already commented out. Option
4406 `comment-style' defines where the comment characters
4407 should be placed (beginning of line, indent, etc.).
4409 You are prompted for comments after object definitions (i.e. signals,
4410 variables, constants, ports) and after subprogram and process
4411 specifications if option `vhdl-prompt-for-comments' is non-nil.
4412 Comments are automatically inserted as additional labels (e.g. after
4413 begin statements) and as help comments if `vhdl-self-insert-comments' is
4414 non-nil.
4416 Inline comments (i.e. comments after a piece of code on the same line)
4417 are indented at least to `vhdl-inline-comment-column'. Comments go at
4418 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4419 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4420 in a comment automatically opens a new comment line. `M-q' re-fills
4421 multi-line comments.
4424 INDENTATION:
4425 `TAB' indents a line if at the beginning of the line. The amount of
4426 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4427 always indents the current line (is bound to `TAB' if option
4428 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4429 the entire region.
4431 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4432 (`M-C-\\') or the entire buffer (menu). Argument and port lists are
4433 indented normally (nil) or relative to the opening parenthesis (non-nil)
4434 according to option `vhdl-argument-list-indent'.
4436 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4437 tabs. `\\[tabify]' and `\\[untabify]' allow the conversion of spaces to
4438 tabs and vice versa.
4440 Syntax-based indentation can be very slow in large files. Option
4441 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4443 Option `vhdl-indent-comment-like-next-code-line' controls whether
4444 comment lines are indented like the preceding or like the following code
4445 line.
4448 ALIGNMENT:
4449 The alignment functions align operators, keywords, and inline comments
4450 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4451 separated by blank lines, `C-c C-a C-i' a block of lines with same
4452 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4453 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4454 C-a C-d' all lines within the declarative part of a design unit. `C-c
4455 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4456 for a group of lines, and `C-c C-a M-c' for a region.
4458 If option `vhdl-align-groups' is non-nil, groups of code lines
4459 separated by special lines (see option `vhdl-align-group-separate') are
4460 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4461 blocks of lines with same indent are aligned separately. Some templates
4462 are automatically aligned after generation if option `vhdl-auto-align'
4463 is non-nil.
4465 Alignment tries to align inline comments at
4466 `vhdl-inline-comment-column' and tries inline comment not to exceed
4467 `vhdl-end-comment-column'.
4469 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4470 symbols are surrounded by one space, and multiple spaces are eliminated.
4473 CODE FILLING:
4474 Code filling allows you to condense code (e.g. sensitivity lists or port
4475 maps) by removing comments and newlines and re-wrapping so that all
4476 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4477 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4478 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4479 `C-c C-f M-f' an entire region.
4482 CODE BEAUTIFICATION:
4483 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4484 buffer respectively. This includes indentation, alignment, and case
4485 fixing. Code beautification can also be run non-interactively using the
4486 command:
4488 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4491 PORT TRANSLATION:
4492 Generic and port clauses from entity or component declarations can be
4493 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4494 as component instantiations and corresponding internal constants and
4495 signals, as a generic map with constants as actual generics, and as
4496 internal signal initializations (menu).
4498 To include formals in component instantiations, see option
4499 `vhdl-association-list-with-formals'. To include comments in pasting,
4500 see options `vhdl-include-...-comments'.
4502 A clause with several generic/port names on the same line can be
4503 flattened (`C-c C-p C-f') so that only one name per line exists. The
4504 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4505 outputs and vice versa, which can be useful in testbenches. (This
4506 reversion is done on the internal data structure and is only reflected
4507 in subsequent paste operations.)
4509 Names for actual ports, instances, testbenches, and
4510 design-under-test instances can be derived from existing names according
4511 to options `vhdl-...-name'. See customization group `vhdl-port'.
4514 SUBPROGRAM TRANSLATION:
4515 Similar functionality exists for copying/pasting the interface of
4516 subprograms (function/procedure). A subprogram interface can be copied
4517 and then pasted as a subprogram declaration, body or call (uses
4518 association list with formals).
4521 TESTBENCH GENERATION:
4522 A copied port can also be pasted as a testbench. The generated
4523 testbench includes an entity, an architecture, and an optional
4524 configuration. The architecture contains the component declaration and
4525 instantiation of the DUT as well as internal constant and signal
4526 declarations. Additional user-defined templates can be inserted. The
4527 names used for entity/architecture/configuration/DUT as well as the file
4528 structure to be generated can be customized. See customization group
4529 `vhdl-testbench'.
4532 KEY BINDINGS:
4533 Key bindings (`C-c ...') exist for most commands (see in menu).
4536 VHDL MENU:
4537 All commands can be found in the VHDL menu including their key bindings.
4540 FILE BROWSER:
4541 The speedbar allows browsing of directories and file contents. It can
4542 be accessed from the VHDL menu and is automatically opened if option
4543 `vhdl-speedbar-auto-open' is non-nil.
4545 In speedbar, open files and directories with `mouse-2' on the name and
4546 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4549 DESIGN HIERARCHY BROWSER:
4550 The speedbar can also be used for browsing the hierarchy of design units
4551 contained in the source files of the current directory or the specified
4552 projects (see option `vhdl-project-alist').
4554 The speedbar can be switched between file, directory hierarchy and
4555 project hierarchy browsing mode in the speedbar menu or by typing `f',
4556 `h' or `H' in speedbar.
4558 In speedbar, open design units with `mouse-2' on the name and browse
4559 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4560 from entities and components (in packages). Individual design units and
4561 complete designs can directly be compiled (\"Make\" menu entry).
4563 The hierarchy is automatically updated upon saving a modified source
4564 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4565 hierarchy is only updated for projects that have been opened once in the
4566 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4567 options in group `vhdl-speedbar').
4569 Simple design consistency checks are done during scanning, such as
4570 multiple declarations of the same unit or missing primary units that are
4571 required by secondary units.
4574 STRUCTURAL COMPOSITION:
4575 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4576 for a new component. Subcomponents (i.e. component declaration and
4577 instantiation) can be automatically placed from a previously read port
4578 (`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4579 all subcomponents can be automatically connected using internal signals
4580 and ports (`C-c C-m C-w') following these rules:
4581 - subcomponent actual ports with same name are considered to be
4582 connected by a signal (internal signal or port)
4583 - signals that are only inputs to subcomponents are considered as
4584 inputs to this component -> input port created
4585 - signals that are only outputs from subcomponents are considered as
4586 outputs from this component -> output port created
4587 - signals that are inputs to AND outputs from subcomponents are
4588 considered as internal connections -> internal signal created
4590 Purpose: With appropriate naming conventions it is possible to
4591 create higher design levels with only a few mouse clicks or key
4592 strokes. A new design level can be created by simply generating a new
4593 component, placing the required subcomponents from the hierarchy
4594 browser, and wiring everything automatically.
4596 Note: Automatic wiring only works reliably on templates of new
4597 components and component instantiations that were created by VHDL mode.
4599 Component declarations can be placed in a components package (option
4600 `vhdl-use-components-package') which can be automatically generated for
4601 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4602 component instantiation is also supported (option
4603 `vhdl-use-direct-instantiation').
4605 Configuration declarations can automatically be generated either from
4606 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4607 the speedbar menu (for the architecture under the cursor). The
4608 configurations can optionally be hierarchical (i.e. include all
4609 component levels of a hierarchical design, option
4610 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4611 (option `vhdl-compose-configuration-use-subconfiguration'). For
4612 subcomponents in hierarchical configurations, the most-recently-analyzed
4613 (mra) architecture is selected. If another architecture is desired, it
4614 can be marked as most-recently-analyzed (speedbar menu) before
4615 generating the configuration.
4617 Note: Configurations of subcomponents (i.e. hierarchical configuration
4618 declarations) are currently not considered when displaying
4619 configurations in speedbar.
4621 See the options group `vhdl-compose' for all relevant user options.
4624 SOURCE FILE COMPILATION:
4625 The syntax of the current buffer can be analyzed by calling a VHDL
4626 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4627 option `vhdl-compiler'. The available compilers are listed in option
4628 `vhdl-compiler-alist' including all required compilation command,
4629 command options, compilation directory, and error message syntax
4630 information. New compilers can be added.
4632 All the source files of an entire design can be compiled by the `make'
4633 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4636 MAKEFILE GENERATION:
4637 Makefiles can be generated automatically by an internal generation
4638 routine (`C-c M-k'). The library unit dependency information is
4639 obtained from the hierarchy browser. Makefile generation can be
4640 customized for each compiler in option `vhdl-compiler-alist'.
4642 Makefile generation can also be run non-interactively using the
4643 command:
4645 emacs -batch -l ~/.emacs -l vhdl-mode
4646 [-compiler compilername] [-project projectname]
4647 -f vhdl-generate-makefile
4649 The Makefile's default target \"all\" compiles the entire design, the
4650 target \"clean\" removes it and the target \"library\" creates the
4651 library directory if not existent. These target names can be customized
4652 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4653 target for each primary library unit which allows selective compilation
4654 of this unit, its secondary units and its subhierarchy (example:
4655 compilation of a design specified by a configuration). User specific
4656 parts can be inserted into a Makefile with option
4657 `vhdl-makefile-generation-hook'.
4659 Limitations:
4660 - Only library units and dependencies within the current library are
4661 considered. Makefiles for designs that span multiple libraries are
4662 not (yet) supported.
4663 - Only one-level configurations are supported (also hierarchical),
4664 but configurations that go down several levels are not.
4665 - The \"others\" keyword in configurations is not supported.
4668 PROJECTS:
4669 Projects can be defined in option `vhdl-project-alist' and a current
4670 project be selected using option `vhdl-project' (permanently) or from
4671 the menu or speedbar (temporarily). For each project, title and
4672 description strings (for the file headers), source files/directories
4673 (for the hierarchy browser and Makefile generation), library name, and
4674 compiler-dependent options, exceptions and compilation directory can be
4675 specified. Compilation settings overwrite the settings of option
4676 `vhdl-compiler-alist'.
4678 Project setups can be exported (i.e. written to a file) and imported.
4679 Imported setups are not automatically saved in `vhdl-project-alist' but
4680 can be saved afterwards in its customization buffer. When starting
4681 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4682 vhdl-mode\") in a directory with an existing project setup file, it is
4683 automatically loaded and its project activated if option
4684 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4685 files can be specified in option `vhdl-project-file-name'. Multiple
4686 project setups can be automatically loaded from global directories.
4687 This is an alternative to specifying project setups with option
4688 `vhdl-project-alist'.
4691 SPECIAL MENUES:
4692 As an alternative to the speedbar, an index menu can be added (set
4693 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4694 (e.g. add \"(global-set-key [S-down-mouse-3] \\='imenu)\" to your start-up
4695 file) for browsing the file contents (is not populated if buffer is
4696 larger than 256000). Also, a source file menu can be
4697 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4698 current directory for VHDL source files.
4701 VHDL STANDARDS:
4702 The VHDL standards to be used are specified in option `vhdl-standard'.
4703 Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
4706 KEYWORD CASE:
4707 Lower and upper case for keywords and standardized types, attributes,
4708 and enumeration values is supported. If the option
4709 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4710 lower case and are converted into upper case automatically (not for
4711 types, attributes, and enumeration values). The case of keywords,
4712 types, attributes,and enumeration values can be fixed for an entire
4713 region (menu) or buffer (`C-c C-x C-c') according to the options
4714 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4717 HIGHLIGHTING (fontification):
4718 Keywords and standardized types, attributes, enumeration values, and
4719 function names (controlled by option `vhdl-highlight-keywords'), as well
4720 as comments, strings, and template prompts are highlighted using
4721 different colors. Unit, subprogram, signal, variable, constant,
4722 parameter and generic/port names in declarations as well as labels are
4723 highlighted if option `vhdl-highlight-names' is non-nil.
4725 Additional reserved words or words with a forbidden syntax (e.g. words
4726 that should be avoided) can be specified in option
4727 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4728 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4729 keywords are highlighted as forbidden words if option
4730 `vhdl-highlight-verilog-keywords' is non-nil.
4732 Words with special syntax can be highlighted by specifying their
4733 syntax and color in option `vhdl-special-syntax-alist' and by setting
4734 option `vhdl-highlight-special-words' to non-nil. This allows you to
4735 establish some naming conventions (e.g. to distinguish different kinds
4736 of signals or other objects by using name suffices) and to support them
4737 visually.
4739 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4740 to support case-sensitive highlighting. However, keywords are then only
4741 highlighted if written in lower case.
4743 Code between \"translate_off\" and \"translate_on\" pragmas is
4744 highlighted using a different background color if option
4745 `vhdl-highlight-translate-off' is non-nil.
4747 For documentation and customization of the used colors see
4748 customization group `vhdl-highlight-faces' (`\\[customize-group]'). For
4749 highlighting of matching parenthesis, see customization group
4750 `paren-showing'. Automatic buffer highlighting is turned on/off by
4751 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4754 USER MODELS:
4755 VHDL models (templates) can be specified by the user and made accessible
4756 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4757 electrification. See option `vhdl-model-alist'.
4760 HIDE/SHOW:
4761 The code of blocks, processes, subprograms, component declarations and
4762 instantiations, generic/port clauses, and configuration declarations can
4763 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4764 the code (see customization group `vhdl-menu'). XEmacs: limited
4765 functionality due to old `hideshow.el' package.
4768 CODE UPDATING:
4769 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4770 current process, `C-c C-u M-s' of all processes in the current buffer.
4771 Limitations:
4772 - Only declared local signals (ports, signals declared in
4773 architecture and blocks) are automatically inserted.
4774 - Global signals declared in packages are not automatically inserted.
4775 Insert them once manually (will be kept afterwards).
4776 - Out parameters of procedures are considered to be read.
4777 Use option `vhdl-entity-file-name' to specify the entity file name
4778 (used to obtain the port names).
4779 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4780 specify whether to include array indices and record fields in
4781 sensitivity lists.
4784 CODE FIXING:
4785 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4786 (e.g., if the closing parenthesis is on the wrong line or is missing).
4789 PRINTING:
4790 PostScript printing with different faces (an optimized set of faces is
4791 used if `vhdl-print-customize-faces' is non-nil) or colors (if
4792 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4793 PostScript printing commands. Option `vhdl-print-two-column' defines
4794 appropriate default settings for nice landscape two-column printing.
4795 The paper format can be set by option `ps-paper-type'. Do not forget to
4796 switch `ps-print-color-p' to nil for printing on black-and-white
4797 printers.
4800 OPTIONS:
4801 User options allow customization of VHDL Mode. All options are
4802 accessible from the \"Options\" menu entry. Simple options (switches
4803 and choices) can directly be changed, while for complex options a
4804 customization buffer is opened. Changed options can be saved for future
4805 sessions using the \"Save Options\" menu entry.
4807 Options and their detailed descriptions can also be accessed by using
4808 the \"Customize\" menu entry or the command `\\[customize-option]'
4809 (`\\[customize-group]' for groups). Some customizations only take effect
4810 after some action (read the NOTE in the option documentation).
4811 Customization can also be done globally (i.e. site-wide, read the
4812 INSTALL file).
4814 Not all options are described in this documentation, so go and see
4815 what other useful user options there are (`\\[vhdl-customize]' or menu)!
4818 FILE EXTENSIONS:
4819 As default, files with extensions \".vhd\" and \".vhdl\" are
4820 automatically recognized as VHDL source files. To add an extension
4821 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4823 (push \\='(\"\\\\.xxx\\\\\\='\" . vhdl-mode) auto-mode-alist)
4826 HINTS:
4827 - To start Emacs with open VHDL hierarchy browser without having to load
4828 a VHDL file first, use the command:
4830 emacs -l vhdl-mode -f speedbar-frame-mode
4832 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4834 - Some features only work on properly indented code.
4837 RELEASE NOTES:
4838 See also the release notes (menu) for added features in new releases.
4841 Maintenance:
4842 ------------
4844 To submit a bug report, enter `\\[vhdl-submit-bug-report]' within VHDL Mode.
4845 Add a description of the problem and include a reproducible test case.
4847 Questions and enhancement requests can be sent to <reto@gnu.org>.
4849 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4850 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4851 releases. You are kindly invited to participate in beta testing. Subscribe
4852 to above mailing lists by sending an email to <reto@gnu.org>.
4854 VHDL Mode is officially distributed at
4855 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4856 where the latest version can be found.
4859 Known problems:
4860 ---------------
4862 - XEmacs: Incorrect start-up when automatically opening speedbar.
4863 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4864 - Indentation incorrect for new 'postponed' VHDL keyword.
4865 - Indentation incorrect for 'protected body' construct.
4868 The VHDL Mode Authors
4869 Reto Zimmermann and Rod Whitby
4871 Key bindings:
4872 -------------
4874 \\{vhdl-mode-map}"
4875 :abbrev-table vhdl-mode-abbrev-table
4877 ;; set local variables
4878 (set (make-local-variable 'paragraph-start)
4879 "\\s-*\\(--+\\s-*$\\|$\\)")
4880 (set (make-local-variable 'paragraph-separate) paragraph-start)
4881 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4882 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4883 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4884 (set (make-local-variable 'comment-start) "--")
4885 (set (make-local-variable 'comment-end) "")
4886 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4887 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4888 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4889 (set (make-local-variable 'comment-multi-line) nil)
4890 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4891 (set (make-local-variable 'hippie-expand-verbose) nil)
4893 ;; setup the comment indent variable in a Emacs version portable way
4894 ;; ignore any byte compiler warnings you might get here
4895 (when (boundp 'comment-indent-function)
4896 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4898 ;; initialize font locking
4899 (set (make-local-variable 'font-lock-defaults)
4900 (list
4901 '(nil vhdl-font-lock-keywords) nil
4902 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4903 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4904 (set (make-local-variable 'syntax-propertize-function)
4905 (syntax-propertize-rules
4906 ;; Mark single quotes as having string quote syntax in
4907 ;; 'c' instances.
4908 ("\\('\\).\\('\\)" (1 "\"'") (2 "\"'"))))
4909 (set (make-local-variable 'font-lock-syntactic-keywords)
4910 vhdl-font-lock-syntactic-keywords))
4911 (unless vhdl-emacs-21
4912 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4913 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4914 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4915 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4917 ;; variables for source file compilation
4918 (when vhdl-compile-use-local-error-regexp
4919 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4920 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4922 ;; add index menu
4923 (vhdl-index-menu-init)
4924 ;; add source file menu
4925 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4926 ;; add VHDL menu
4927 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4928 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4929 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4930 ;; initialize hideshow and add menu
4931 (vhdl-hideshow-init)
4932 (run-hooks 'menu-bar-update-hook)
4934 ;; miscellaneous
4935 (vhdl-ps-print-init)
4936 (vhdl-write-file-hooks-init)
4937 (message "VHDL Mode %s.%s" vhdl-version
4938 (if noninteractive "" " See menu for documentation and release notes.")))
4940 (defun vhdl-activate-customizations ()
4941 "Activate all customizations on local variables."
4942 (interactive)
4943 (vhdl-mode-map-init)
4944 (use-local-map vhdl-mode-map)
4945 (set-syntax-table vhdl-mode-syntax-table)
4946 (setq comment-column vhdl-inline-comment-column)
4947 (setq end-comment-column vhdl-end-comment-column)
4948 (vhdl-write-file-hooks-init)
4949 (vhdl-update-mode-menu)
4950 (vhdl-hideshow-init)
4951 (run-hooks 'menu-bar-update-hook))
4953 (defun vhdl-write-file-hooks-init ()
4954 "Add/remove hooks when buffer is saved."
4955 (if vhdl-modify-date-on-saving
4956 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4957 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4958 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4959 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4961 (defun vhdl-process-command-line-option (option)
4962 "Process command line options for VHDL Mode."
4963 (cond
4964 ;; set compiler
4965 ((equal option "-compiler")
4966 (vhdl-set-compiler (car command-line-args-left))
4967 (setq command-line-args-left (cdr command-line-args-left)))
4968 ;; set project
4969 ((equal option "-project")
4970 (vhdl-set-project (car command-line-args-left))
4971 (setq command-line-args-left (cdr command-line-args-left)))))
4973 ;; make Emacs process VHDL Mode options
4974 (setq command-switch-alist
4975 (append command-switch-alist
4976 '(("-compiler" . vhdl-process-command-line-option)
4977 ("-project" . vhdl-process-command-line-option))))
4980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4981 ;;; Keywords and standardized words
4982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4984 (defconst vhdl-02-keywords
4986 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4987 "assert" "attribute"
4988 "begin" "block" "body" "buffer" "bus"
4989 "case" "component" "configuration" "constant"
4990 "disconnect" "downto"
4991 "else" "elsif" "end" "entity" "exit"
4992 "file" "for" "function"
4993 "generate" "generic" "group" "guarded"
4994 "if" "impure" "in" "inertial" "inout" "is"
4995 "label" "library" "linkage" "literal" "loop"
4996 "map" "mod"
4997 "nand" "new" "next" "nor" "not" "null"
4998 "of" "on" "open" "or" "others" "out"
4999 "package" "port" "postponed" "procedure" "process" "protected" "pure"
5000 "range" "record" "register" "reject" "rem" "report" "return"
5001 "rol" "ror"
5002 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
5003 "then" "to" "transport" "type"
5004 "unaffected" "units" "until" "use"
5005 "variable"
5006 "wait" "when" "while" "with"
5007 "xnor" "xor"
5009 "List of VHDL'02 keywords.")
5011 (defconst vhdl-08-keywords
5013 "context" "force" "property" "release" "sequence"
5015 "List of VHDL'08 keywords.")
5017 (defconst vhdl-ams-keywords
5019 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
5020 "reference" "spectrum" "subnature" "terminal" "through"
5021 "tolerance"
5023 "List of VHDL-AMS keywords.")
5025 (defconst vhdl-verilog-keywords
5027 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5028 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5029 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5030 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5031 "endprimitive" "endspecify" "endtable" "endtask" "event"
5032 "for" "force" "forever" "fork" "function"
5033 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5034 "macromodule" "makefile" "medium" "module"
5035 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5036 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5037 "pullup"
5038 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5039 "rtranif0" "rtranif1"
5040 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5041 "strong1" "supply" "supply0" "supply1"
5042 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5043 "triand" "trior" "trireg"
5044 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5046 "List of Verilog keywords as candidate for additional reserved words.")
5048 (defconst vhdl-02-types
5050 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5051 "real" "time" "natural" "positive" "string" "line" "text" "side"
5052 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5053 "std_logic" "std_logic_vector"
5054 "std_ulogic" "std_ulogic_vector"
5056 "List of VHDL'02 standardized types.")
5058 (defconst vhdl-08-types
5060 "boolean_vector" "integer_vector" "real_vector" "time_vector"
5062 "List of VHDL'08 standardized types.")
5064 (defconst vhdl-ams-types
5065 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5067 ;; package `standard'
5068 "domain_type" "real_vector"
5069 ;; package `energy_systems'
5070 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5071 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5072 "real_across_vector" "real_through_vector"
5073 ;; package `electrical_systems'
5074 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5075 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5076 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5077 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5078 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5079 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5080 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5081 "electric_flux_density_vector" "electric_field_strength_vector"
5082 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5083 "inductance_vector" "reluctance_vector" "ground"
5084 ;; package `mechanical_systems'
5085 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5086 "damping" "momentum" "angle" "torque" "angular_velocity"
5087 "angular_acceleration" "moment_inertia" "angular_momentum"
5088 "angular_stiffness" "angular_damping" "translational"
5089 "translational_vector" "translational_velocity"
5090 "translational_velocity_vector" "rotational" "rotational_vector"
5091 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5092 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5093 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5094 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5095 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5096 "angular_momentum_vector" "angular_stiffness_vector"
5097 "angular_damping_vector" "anchor" "translational_v_ref"
5098 "rotational_v_ref" "translational_v" "rotational_v"
5099 ;; package `radiant_systems'
5100 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5101 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5102 "illuminance_vector" "irradiance_vector"
5103 ;; package `thermal_systems'
5104 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5105 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5106 "heat_flow_vector" "thermal_capacitance_vector"
5107 "thermal_resistance_vector" "thermal_conductance_vector"
5108 ;; package `fluidic_systems'
5109 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5110 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5111 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5112 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5113 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5114 "density_vector" "viscosity_vector" "fresistance_vector"
5115 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5116 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5117 "cfinertance_vector"
5119 "List of VHDL-AMS standardized types.")
5121 (defconst vhdl-math-types
5123 "complex" "complex_polar" "positive_real" "principal_value"
5125 "List of Math Packages standardized types.")
5127 (defconst vhdl-02-attributes
5129 "base" "left" "right" "high" "low" "pos" "val" "succ"
5130 "pred" "leftof" "rightof" "range" "reverse_range"
5131 "length" "delayed" "stable" "quiet" "transaction"
5132 "event" "active" "last_event" "last_active" "last_value"
5133 "driving" "driving_value" "ascending" "value" "image"
5134 "simple_name" "instance_name" "path_name"
5135 "foreign"
5137 "List of VHDL'02 standardized attributes.")
5139 (defconst vhdl-08-attributes
5141 "instance_name" "path_name"
5143 "List of VHDL'08 standardized attributes.")
5145 (defconst vhdl-ams-attributes
5147 "across" "through"
5148 "reference" "contribution" "tolerance"
5149 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5150 "ramp" "slew"
5152 "List of VHDL-AMS standardized attributes.")
5154 (defconst vhdl-02-enum-values
5156 "true" "false"
5157 "note" "warning" "error" "failure"
5158 "read_mode" "write_mode" "append_mode"
5159 "open_ok" "status_error" "name_error" "mode_error"
5160 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5161 "right" "left"
5163 "List of VHDL'02 standardized enumeration values.")
5165 (defconst vhdl-ams-enum-values
5167 "quiescent_domain" "time_domain" "frequency_domain"
5168 ;; from `nature_pkg' package
5169 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5171 "List of VHDL-AMS standardized enumeration values.")
5173 (defconst vhdl-ams-constants
5174 ;; standard: IEEE Std 1076.1.1-2004
5176 ;; package `fundamental_constants'
5177 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5178 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5179 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5180 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5181 ;; package `material_constants'
5182 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5183 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5184 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5186 "List of VHDL-AMS standardized constants.")
5188 (defconst vhdl-math-constants
5189 ;; standard: IEEE Std 1076.2-1996
5191 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5192 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5193 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5194 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5195 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5196 "math_sqrt_pi"
5198 "List of Math Packages standardized constants.")
5200 (defconst vhdl-02-functions
5202 "now" "resolved" "rising_edge" "falling_edge"
5203 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5204 "endfile"
5205 "resize" "is_X" "std_match"
5206 "shift_left" "shift_right" "rotate_left" "rotate_right"
5207 "to_unsigned" "to_signed" "to_integer"
5208 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5209 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5210 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5211 "shl" "shr" "ext" "sxt"
5212 "deallocate"
5214 "List of VHDL'02 standardized functions.")
5216 (defconst vhdl-08-functions
5218 "finish" "flush" "justify" "maximum" "minimum"
5219 "resolution_limit" "rising_edge" "stop" "swrite"
5220 "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
5221 "to_octalstring" "to_ostring" "to_string"
5223 "List of VHDL'08 standardized functions.")
5225 (defconst vhdl-ams-functions
5227 ;; package `standard'
5228 "frequency"
5230 "List of VHDL-AMS standardized functions.")
5232 (defconst vhdl-math-functions
5233 ;; standard: IEEE Std 1076.2-1996
5235 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5236 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5237 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5238 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5239 "tan" "tanh" "trunc" "uniform"
5241 "List of Math Packages standardized functions.")
5243 (defconst vhdl-02-packages
5245 "std_logic_1164" "numeric_std" "numeric_bit"
5246 "standard" "textio"
5247 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5248 "std_logic_misc" "std_logic_textio"
5249 "ieee" "std" "work"
5251 "List of VHDL'02 standardized packages and libraries.")
5253 (defconst vhdl-08-packages
5255 "env" "numeric_std_signed" "numeric_std_unsigned"
5256 "ieee_bit_context" "ieee_std_context" ;; contexts
5258 "List of VHDL'08 standardized packages and libraries.")
5260 (defconst vhdl-ams-packages
5262 "fundamental_constants" "material_constants" "energy_systems"
5263 "electrical_systems" "mechanical_systems" "radiant_systems"
5264 "thermal_systems" "fluidic_systems"
5266 "List of VHDL-AMS standardized packages and libraries.")
5268 (defconst vhdl-math-packages
5270 "math_real" "math_complex"
5272 "List of Math Packages standardized packages and libraries.")
5274 (defconst vhdl-08-directives
5276 "author" "author_info" "begin" "begin_protected" "comment"
5277 "data_block" "data_keyname" "data_keyowner" "data_method"
5278 "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
5279 "digest_keyowner" "digest_method"
5280 "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
5281 "key_block" "key_keyname" "key_keyowner" "key_method"
5282 "runtime_license" "viewport"
5284 "List of VHDL'08 standardized tool directives.")
5286 (defvar vhdl-keywords nil
5287 "List of VHDL keywords.")
5289 (defvar vhdl-types nil
5290 "List of VHDL standardized types.")
5292 (defvar vhdl-attributes nil
5293 "List of VHDL standardized attributes.")
5295 (defvar vhdl-enum-values nil
5296 "List of VHDL standardized enumeration values.")
5298 (defvar vhdl-constants nil
5299 "List of VHDL standardized constants.")
5301 (defvar vhdl-functions nil
5302 "List of VHDL standardized functions.")
5304 (defvar vhdl-packages nil
5305 "List of VHDL standardized packages and libraries.")
5307 (defvar vhdl-directives nil
5308 "List of VHDL standardized packages and libraries.")
5310 (defvar vhdl-reserved-words nil
5311 "List of additional reserved words.")
5313 (defvar vhdl-keywords-regexp nil
5314 "Regexp for VHDL keywords.")
5316 (defvar vhdl-types-regexp nil
5317 "Regexp for VHDL standardized types.")
5319 (defvar vhdl-attributes-regexp nil
5320 "Regexp for VHDL standardized attributes.")
5322 (defvar vhdl-enum-values-regexp nil
5323 "Regexp for VHDL standardized enumeration values.")
5325 (defvar vhdl-constants-regexp nil
5326 "Regexp for VHDL standardized constants.")
5328 (defvar vhdl-functions-regexp nil
5329 "Regexp for VHDL standardized functions.")
5331 (defvar vhdl-packages-regexp nil
5332 "Regexp for VHDL standardized packages and libraries.")
5334 (defvar vhdl-reserved-words-regexp nil
5335 "Regexp for additional reserved words.")
5337 (defvar vhdl-directive-keywords-regexp nil
5338 "Regexp for compiler directive keywords.")
5340 (defun vhdl-upcase-list (condition list)
5341 "Upcase all elements in LIST based on CONDITION."
5342 (when condition
5343 (let ((tmp-list list))
5344 (while tmp-list
5345 (setcar tmp-list (upcase (car tmp-list)))
5346 (setq tmp-list (cdr tmp-list)))))
5347 list)
5349 (defun vhdl-words-init ()
5350 "Initialize reserved words."
5351 (setq vhdl-keywords
5352 (vhdl-upcase-list
5353 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5354 (append vhdl-02-keywords
5355 (when (vhdl-standard-p '08) vhdl-08-keywords)
5356 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5357 (setq vhdl-types
5358 (vhdl-upcase-list
5359 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5360 (append vhdl-02-types
5361 (when (vhdl-standard-p '08) vhdl-08-types)
5362 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5363 (when (vhdl-standard-p 'math) vhdl-math-types))))
5364 (setq vhdl-attributes
5365 (vhdl-upcase-list
5366 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5367 (append vhdl-02-attributes
5368 (when (vhdl-standard-p '08) vhdl-08-attributes)
5369 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5370 (setq vhdl-enum-values
5371 (vhdl-upcase-list
5372 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5373 (append vhdl-02-enum-values
5374 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5375 (setq vhdl-constants
5376 (vhdl-upcase-list
5377 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5378 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5379 (when (vhdl-standard-p 'math) vhdl-math-constants)
5380 '(""))))
5381 (setq vhdl-functions
5382 (append vhdl-02-functions
5383 (when (vhdl-standard-p '08) vhdl-08-functions)
5384 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5385 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5386 (setq vhdl-packages
5387 (append vhdl-02-packages
5388 (when (vhdl-standard-p '08) vhdl-08-packages)
5389 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5390 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5391 (setq vhdl-directives
5392 (append (when (vhdl-standard-p '08) vhdl-08-directives)))
5393 (setq vhdl-reserved-words
5394 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5395 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5396 '("")))
5397 (setq vhdl-keywords-regexp
5398 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5399 (setq vhdl-types-regexp
5400 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5401 (setq vhdl-attributes-regexp
5402 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5403 (setq vhdl-enum-values-regexp
5404 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5405 (setq vhdl-constants-regexp
5406 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5407 (setq vhdl-functions-regexp
5408 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5409 (setq vhdl-packages-regexp
5410 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5411 (setq vhdl-reserved-words-regexp
5412 (concat "\\<\\("
5413 (unless (equal vhdl-forbidden-syntax "")
5414 (concat vhdl-forbidden-syntax "\\|"))
5415 (regexp-opt vhdl-reserved-words)
5416 "\\)\\>"))
5417 (setq vhdl-directive-keywords-regexp
5418 (concat "\\<\\(" (mapconcat 'regexp-quote
5419 vhdl-directive-keywords "\\|") "\\)\\>"))
5420 (vhdl-abbrev-list-init))
5422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5423 ;; Words to expand
5425 (defvar vhdl-abbrev-list nil
5426 "Predefined abbreviations for VHDL.")
5428 (defun vhdl-abbrev-list-init ()
5429 (setq vhdl-abbrev-list
5430 (append
5431 (list vhdl-upper-case-keywords) vhdl-keywords
5432 (list vhdl-upper-case-types) vhdl-types
5433 (list vhdl-upper-case-attributes) vhdl-attributes
5434 (list vhdl-upper-case-enum-values) vhdl-enum-values
5435 (list vhdl-upper-case-constants) vhdl-constants
5436 (list nil) vhdl-functions
5437 (list nil) vhdl-packages
5438 (list nil) vhdl-directives)))
5440 ;; initialize reserved words for VHDL Mode
5441 (vhdl-words-init)
5444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5445 ;;; Indentation
5446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5449 ;; Syntax analysis
5451 ;; constant regular expressions for looking at various constructs
5453 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5454 "Regexp describing a VHDL symbol.
5455 We cannot use just `word' syntax class since `_' cannot be in word
5456 class. Putting underscore in word class breaks forward word movement
5457 behavior that users are familiar with.")
5459 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5460 "Regexp describing a case statement header key.")
5462 (defconst vhdl-label-key
5463 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5464 "Regexp describing a VHDL label.")
5466 ;; Macro definitions:
5468 (defmacro vhdl-point (position)
5469 "Return the value of point at certain commonly referenced POSITIONs.
5470 POSITION can be one of the following symbols:
5472 bol -- beginning of line
5473 eol -- end of line
5474 bod -- beginning of defun
5475 boi -- back to indentation
5476 eoi -- last whitespace on line
5477 ionl -- indentation of next line
5478 iopl -- indentation of previous line
5479 bonl -- beginning of next line
5480 bopl -- beginning of previous line
5482 This function does not modify point or mark."
5483 (or (and (eq 'quote (car-safe position))
5484 (null (cddr position)))
5485 (error "ERROR: Bad buffer position requested: %s" position))
5486 (setq position (nth 1 position))
5487 `(let ((here (point)))
5488 ,@(cond
5489 ((eq position 'bol) '((beginning-of-line)))
5490 ((eq position 'eol) '((end-of-line)))
5491 ((eq position 'bod) '((save-match-data
5492 (vhdl-beginning-of-defun))))
5493 ((eq position 'boi) '((back-to-indentation)))
5494 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5495 ((eq position 'bonl) '((forward-line 1)))
5496 ((eq position 'bopl) '((forward-line -1)))
5497 ((eq position 'iopl)
5498 '((forward-line -1)
5499 (back-to-indentation)))
5500 ((eq position 'ionl)
5501 '((forward-line 1)
5502 (back-to-indentation)))
5503 (t (error "ERROR: Unknown buffer position requested: %s" position))
5505 (prog1
5506 (point)
5507 (goto-char here))
5508 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5509 ;; doesn't hurt for v19
5510 ,@nil
5513 (defmacro vhdl-safe (&rest body)
5514 "Safely execute BODY, return nil if an error occurred."
5515 `(condition-case nil
5516 (progn ,@body)
5517 (error nil)))
5519 (defmacro vhdl-add-syntax (symbol &optional relpos)
5520 "A simple macro to append the syntax in SYMBOL to the syntax list.
5521 Try to increase performance by using this macro."
5522 `(setq vhdl-syntactic-context
5523 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5525 (defmacro vhdl-has-syntax (symbol)
5526 "A simple macro to return check the syntax list.
5527 Try to increase performance by using this macro."
5528 `(assoc ,symbol vhdl-syntactic-context))
5530 ;; Syntactic element offset manipulation:
5532 (defun vhdl-read-offset (langelem)
5533 "Read new offset value for LANGELEM from minibuffer.
5534 Return a valid value only."
5535 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5536 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5537 (prompt "Offset: ")
5538 offset input interned)
5539 (while (not offset)
5540 (setq input (read-string prompt oldoff)
5541 offset (cond ((string-equal "+" input) '+)
5542 ((string-equal "-" input) '-)
5543 ((string-equal "++" input) '++)
5544 ((string-equal "--" input) '--)
5545 ((string-match "^-?[0-9]+$" input)
5546 (string-to-number input))
5547 ((fboundp (setq interned (intern input)))
5548 interned)
5549 ((boundp interned) interned)
5550 ;; error, but don't signal one, keep trying
5551 ;; to read an input value
5552 (t (ding)
5553 (setq prompt errmsg)
5554 nil))))
5555 offset))
5557 (defun vhdl-set-offset (symbol offset &optional add-p)
5558 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5559 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5560 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5561 `vhdl-offsets-alist' if it doesn't already appear there."
5562 (interactive
5563 (let* ((langelem
5564 (intern (completing-read
5565 (concat "Syntactic symbol to change"
5566 (if current-prefix-arg " or add" "")
5567 ": ")
5568 (mapcar
5569 (function
5570 (lambda (langelem)
5571 (cons (format "%s" (car langelem)) nil)))
5572 vhdl-offsets-alist)
5573 nil (not current-prefix-arg)
5574 ;; initial contents tries to be the last element
5575 ;; on the syntactic analysis list for the current
5576 ;; line
5577 (let* ((syntax (vhdl-get-syntactic-context))
5578 (len (length syntax))
5579 (ic (format "%s" (car (nth (1- len) syntax)))))
5582 (offset (vhdl-read-offset langelem)))
5583 (list langelem offset current-prefix-arg)))
5584 ;; sanity check offset
5585 (or (eq offset '+)
5586 (eq offset '-)
5587 (eq offset '++)
5588 (eq offset '--)
5589 (integerp offset)
5590 (fboundp offset)
5591 (boundp offset)
5592 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5593 offset))
5594 (let ((entry (assq symbol vhdl-offsets-alist)))
5595 (if entry
5596 (setcdr entry offset)
5597 (if add-p
5598 (setq vhdl-offsets-alist
5599 (cons (cons symbol offset) vhdl-offsets-alist))
5600 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5601 (vhdl-keep-region-active))
5603 (defun vhdl-set-style (style &optional local)
5604 "Set `vhdl-mode' variables to use one of several different indentation styles.
5605 STYLE is a string representing the desired style and optional LOCAL is
5606 a flag which, if non-nil, means to make the style variables being
5607 changed buffer local, instead of the default, which is to set the
5608 global variables. Interactively, the flag comes from the prefix
5609 argument. The styles are chosen from the `vhdl-style-alist' variable."
5610 (interactive (list (completing-read "Use which VHDL indentation style? "
5611 vhdl-style-alist nil t)
5612 current-prefix-arg))
5613 (let ((vars (cdr (assoc style vhdl-style-alist))))
5614 (or vars
5615 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5616 ;; set all the variables
5617 (mapc
5618 (function
5619 (lambda (varentry)
5620 (let ((var (car varentry))
5621 (val (cdr varentry)))
5622 ;; special case for vhdl-offsets-alist
5623 (if (not (eq var 'vhdl-offsets-alist))
5624 (set (if local (make-local-variable var) var) val)
5625 ;; reset vhdl-offsets-alist to the default value first
5626 (set (if local (make-local-variable var) var)
5627 (copy-alist vhdl-offsets-alist-default))
5628 ;; now set the langelems that are different
5629 (mapcar
5630 (function
5631 (lambda (langentry)
5632 (let ((langelem (car langentry))
5633 (offset (cdr langentry)))
5634 (vhdl-set-offset langelem offset)
5636 val))
5638 vars))
5639 (vhdl-keep-region-active))
5641 (defun vhdl-get-offset (langelem)
5642 "Get offset from LANGELEM which is a cons cell of the form:
5643 \(SYMBOL . RELPOS). The symbol is matched against
5644 vhdl-offsets-alist and the offset found there is either returned,
5645 or added to the indentation at RELPOS. If RELPOS is nil, then
5646 the offset is simply returned."
5647 (let* ((symbol (car langelem))
5648 (relpos (cdr langelem))
5649 (match (assq symbol vhdl-offsets-alist))
5650 (offset (cdr-safe match)))
5651 ;; offset can be a number, a function, a variable, or one of the
5652 ;; symbols + or -
5653 (cond
5654 ((not match)
5655 (if vhdl-strict-syntax-p
5656 (error "ERROR: Don't know how to indent a %s" symbol)
5657 (setq offset 0
5658 relpos 0)))
5659 ((eq offset '+) (setq offset vhdl-basic-offset))
5660 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5661 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5662 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5663 ((and (not (numberp offset))
5664 (fboundp offset))
5665 (setq offset (funcall offset langelem)))
5666 ((not (numberp offset))
5667 (setq offset (eval offset)))
5669 (+ (if (and relpos
5670 (< relpos (vhdl-point 'bol)))
5671 (save-excursion
5672 (goto-char relpos)
5673 (current-column))
5675 offset)))
5677 ;; Syntactic support functions:
5679 (defun vhdl-in-comment-p (&optional pos)
5680 "Check if point is in a comment (include multi-line comments)."
5681 (let ((parse (lambda (p)
5682 (let ((c (char-after p)))
5683 (or (and c (eq (char-syntax c) ?<))
5684 (nth 4 (parse-partial-sexp
5685 (save-excursion
5686 (beginning-of-defun)
5687 (point)) p)))))))
5688 (save-excursion
5689 (goto-char (or pos (point)))
5690 (or (funcall parse (point))
5691 ;; `parse-partial-sexp's notion of comments doesn't span lines
5692 (progn
5693 (back-to-indentation)
5694 (unless (eolp)
5695 (forward-char)
5696 (funcall parse (point))))))))
5698 (defun vhdl-in-string-p ()
5699 "Check if point is in a string."
5700 (eq (vhdl-in-literal) 'string))
5702 (defun vhdl-in-quote-p ()
5703 "Check if point is in a quote ('x')."
5704 (or (and (> (point) (point-min))
5705 (< (1+ (point)) (point-max))
5706 (= (char-before (point)) ?\')
5707 (= (char-after (1+ (point))) ?\'))
5708 (and (> (1- (point)) (point-min))
5709 (< (point) (point-max))
5710 (= (char-before (1- (point))) ?\')
5711 (= (char-after (point)) ?\'))))
5713 (defun vhdl-in-literal ()
5714 "Determine if point is in a VHDL literal."
5715 (save-excursion
5716 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5717 (cond
5718 ((nth 3 state) 'string)
5719 ((nth 4 state) 'comment)
5720 ((vhdl-beginning-of-macro) 'pound)
5721 ((vhdl-beginning-of-directive) 'directive)
5722 ;; for multi-line comments
5723 ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
5724 (t nil)))))
5726 (defun vhdl-in-extended-identifier-p ()
5727 "Determine if point is inside extended identifier (delimited by `\\')."
5728 (save-match-data
5729 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5730 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5732 (defun vhdl-forward-comment (&optional direction)
5733 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5734 negative, skip forward otherwise."
5735 (interactive "p")
5736 (if (and direction (< direction 0))
5737 ;; skip backwards
5738 (progn
5739 (skip-chars-backward " \t\n\r\f")
5740 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5741 (goto-char (match-beginning 3))
5742 (skip-chars-backward " \t\n\r\f")))
5743 ;; skip forwards
5744 (skip-chars-forward " \t\n\r\f")
5745 (while (looking-at "--.*")
5746 (goto-char (match-end 0))
5747 (skip-chars-forward " \t\n\r\f"))))
5749 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5750 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5751 (defalias 'vhdl-forward-comment 'forward-comment))
5753 (defun vhdl-back-to-indentation ()
5754 "Move point to the first non-whitespace character on this line."
5755 (interactive)
5756 (beginning-of-line 1)
5757 (skip-syntax-forward " " (vhdl-point 'eol)))
5759 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5760 (when (featurep 'xemacs)
5761 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5763 ;; This is the best we can do in Win-Emacs.
5764 (defun vhdl-win-il (&optional lim)
5765 "Determine if point is in a VHDL literal."
5766 (save-excursion
5767 (let* ((here (point))
5768 (state nil)
5769 (match nil)
5770 (lim (or lim (vhdl-point 'bod))))
5771 (goto-char lim )
5772 (while (< (point) here)
5773 (setq match
5774 (and (re-search-forward "--\\|[\"']\\|`"
5775 here 'move)
5776 (buffer-substring (match-beginning 0) (match-end 0))))
5777 (setq state
5778 (cond
5779 ;; no match
5780 ((null match) nil)
5781 ;; looking at the opening of a VHDL style comment
5782 ((string= "--" match)
5783 (if (<= here (progn (end-of-line) (point))) 'comment))
5784 ;; looking at a directive
5785 ((string= "`" match)
5786 (if (<= here (progn (end-of-line) (point))) 'directive))
5787 ;; looking at the opening of a double quote string
5788 ((string= "\"" match)
5789 (if (not (save-restriction
5790 ;; this seems to be necessary since the
5791 ;; re-search-forward will not work without it
5792 (narrow-to-region (point) here)
5793 (re-search-forward
5794 ;; this regexp matches a double quote
5795 ;; which is preceded by an even number
5796 ;; of backslashes, including zero
5797 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5798 'string))
5799 ;; looking at the opening of a single quote string
5800 ((string= "'" match)
5801 (if (not (save-restriction
5802 ;; see comments from above
5803 (narrow-to-region (point) here)
5804 (re-search-forward
5805 ;; this matches a single quote which is
5806 ;; preceded by zero or two backslashes.
5807 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5808 here 'move)))
5809 'string))
5810 (t nil)))
5811 ) ; end-while
5812 state)))
5814 (and (string-match "Win-Emacs" emacs-version)
5815 (fset 'vhdl-in-literal 'vhdl-win-il))
5817 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5818 ;; defined as lexical whitespace or comments. Search no farther back
5819 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5820 ;; used for backward skipping, (point-max) is used for forward
5821 ;; skipping.
5823 (defun vhdl-forward-syntactic-ws (&optional lim)
5824 "Forward skip of syntactic whitespace."
5825 (let* ((here (point-max))
5826 (hugenum (point-max)))
5827 (while (/= here (point))
5828 (setq here (point))
5829 (vhdl-forward-comment hugenum)
5830 ;; skip preprocessor directives
5831 (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
5832 (= (vhdl-point 'boi) (point)))
5833 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5834 (= (forward-line 1) 0)))
5835 (end-of-line)))
5836 (if lim (goto-char (min (point) lim)))))
5839 ;; This is the best we can do in Win-Emacs.
5840 (defun vhdl-win-fsws (&optional lim)
5841 "Forward skip syntactic whitespace for Win-Emacs."
5842 (let ((lim (or lim (point-max)))
5843 stop)
5844 (while (not stop)
5845 (skip-chars-forward " \t\n\r\f" lim)
5846 (cond
5847 ;; vhdl comment
5848 ((looking-at "--") (end-of-line))
5849 ;; none of the above
5850 (t (setq stop t))))))
5852 (and (string-match "Win-Emacs" emacs-version)
5853 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5855 (defun vhdl-beginning-of-macro (&optional lim)
5856 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5857 (let ((here (point)))
5858 (beginning-of-line)
5859 (while (eq (char-before (1- (point))) ?\\)
5860 (forward-line -1))
5861 (back-to-indentation)
5862 (if (and (<= (point) here)
5863 (eq (char-after) ?#))
5865 (goto-char here)
5866 nil)))
5868 (defun vhdl-beginning-of-directive (&optional lim)
5869 "Go to the beginning of a directive (nicked from `cc-engine')."
5870 (let ((here (point)))
5871 (beginning-of-line)
5872 (while (eq (char-before (1- (point))) ?\\)
5873 (forward-line -1))
5874 (back-to-indentation)
5875 (if (and (<= (point) here)
5876 (eq (char-after) ?`))
5878 (goto-char here)
5879 nil)))
5881 (defun vhdl-backward-syntactic-ws (&optional lim)
5882 "Backward skip over syntactic whitespace."
5883 (let* ((here (point-min))
5884 (hugenum (- (point-max))))
5885 (while (/= here (point))
5886 (setq here (point))
5887 (vhdl-forward-comment hugenum)
5888 (vhdl-beginning-of-macro))
5889 (if lim (goto-char (max (point) lim)))))
5891 ;; This is the best we can do in Win-Emacs.
5892 (defun vhdl-win-bsws (&optional lim)
5893 "Backward skip syntactic whitespace for Win-Emacs."
5894 (let ((lim (or lim (vhdl-point 'bod)))
5895 stop)
5896 (while (not stop)
5897 (skip-chars-backward " \t\n\r\f" lim)
5898 (cond
5899 ;; vhdl comment
5900 ((eq (vhdl-in-literal) 'comment)
5901 (skip-chars-backward "^-" lim)
5902 (skip-chars-backward "-" lim)
5903 (while (not (or (and (= (following-char) ?-)
5904 (= (char-after (1+ (point))) ?-))
5905 (<= (point) lim)))
5906 (skip-chars-backward "^-" lim)
5907 (skip-chars-backward "-" lim)))
5908 ;; none of the above
5909 (t (setq stop t))))))
5911 (and (string-match "Win-Emacs" emacs-version)
5912 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5914 ;; Functions to help finding the correct indentation column:
5916 (defun vhdl-first-word (point)
5917 "If the keyword at POINT is at boi, then return (current-column) at
5918 that point, else nil."
5919 (save-excursion
5920 (and (goto-char point)
5921 (eq (point) (vhdl-point 'boi))
5922 (current-column))))
5924 (defun vhdl-last-word (point)
5925 "If the keyword at POINT is at eoi, then return (current-column) at
5926 that point, else nil."
5927 (save-excursion
5928 (and (goto-char point)
5929 (save-excursion (or (eq (progn (forward-sexp) (point))
5930 (vhdl-point 'eoi))
5931 (looking-at "\\s-*\\(--\\)?")))
5932 (current-column))))
5934 ;; Core syntactic evaluation functions:
5936 (defconst vhdl-libunit-re
5937 "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
5939 (defun vhdl-libunit-p ()
5940 (and
5941 (save-excursion
5942 (forward-sexp)
5943 (skip-chars-forward " \t\n\r\f")
5944 (not (looking-at "is\\b[^_]")))
5945 (save-excursion
5946 (backward-sexp)
5947 (and (not (looking-at "use\\b[^_]"))
5948 (progn
5949 (forward-sexp)
5950 (vhdl-forward-syntactic-ws)
5951 (/= (following-char) ?:))))
5954 (defconst vhdl-defun-re
5955 "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5957 (defun vhdl-defun-p ()
5958 (save-excursion
5959 (if (looking-at "block\\|process\\|procedural")
5960 ;; "block", "process", "procedural":
5961 (save-excursion
5962 (backward-sexp)
5963 (not (looking-at "end\\s-+\\w")))
5964 ;; "architecture", "configuration", "context", "entity",
5965 ;; "package", "procedure", "function":
5966 t)))
5968 (defun vhdl-corresponding-defun ()
5969 "If the word at the current position corresponds to a \"defun\"
5970 keyword, then return a string that can be used to find the
5971 corresponding \"begin\" keyword, else return nil."
5972 (save-excursion
5973 (and (looking-at vhdl-defun-re)
5974 (vhdl-defun-p)
5975 (if (looking-at "block\\|process\\|procedural")
5976 ;; "block", "process". "procedural:
5977 (buffer-substring (match-beginning 0) (match-end 0))
5978 ;; "architecture", "configuration", "context", "entity", "package",
5979 ;; "procedure", "function":
5980 "is"))))
5982 (defconst vhdl-begin-fwd-re
5983 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5984 "A regular expression for searching forward that matches all known
5985 \"begin\" keywords.")
5987 (defconst vhdl-begin-bwd-re
5988 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5989 "A regular expression for searching backward that matches all known
5990 \"begin\" keywords.")
5992 (defun vhdl-begin-p (&optional lim)
5993 "Return t if we are looking at a real \"begin\" keyword.
5994 Assumes that the caller will make sure that we are looking at
5995 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5996 the middle of an identifier that just happens to contain a \"begin\"
5997 keyword."
5998 (cond
5999 ;; "[architecture|case|configuration|context|entity|package|
6000 ;; procedure|function] ... is":
6001 ((and (looking-at "i")
6002 (save-excursion
6003 ;; Skip backward over first sexp (needed to skip over a
6004 ;; procedure interface list, and is harmless in other
6005 ;; situations). Note that we need "return" in the
6006 ;; following search list so that we don't run into
6007 ;; semicolons in the function interface list.
6008 (backward-sexp)
6009 (skip-chars-forward "(")
6010 (let (foundp)
6011 (while (and (not foundp)
6012 (re-search-backward
6013 ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
6014 lim 'move))
6015 (if (or (= (preceding-char) ?_)
6016 (vhdl-in-literal))
6017 (backward-char)
6018 (setq foundp t))))
6019 (and (/= (following-char) ?\;)
6020 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
6022 ;; "begin", "then", "use":
6023 ((looking-at "be\\|t\\|use")
6025 ;; "else":
6026 ((and (looking-at "e")
6027 ;; make sure that the "else" isn't inside a
6028 ;; conditional signal assignment.
6029 (save-excursion
6030 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6031 (or (eq (following-char) ?\;)
6032 (eq (point) lim))))
6034 ;; "block", "generate", "loop", "process", "procedural",
6035 ;; "units", "record", "protected body":
6036 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
6037 (save-excursion
6038 (backward-sexp)
6039 (not (looking-at "end\\s-+\\w"))))
6041 ;; "component":
6042 ((and (looking-at "c")
6043 (save-excursion
6044 (backward-sexp)
6045 (not (looking-at "end\\s-+\\w")))
6046 ;; look out for the dreaded entity class in an attribute
6047 (save-excursion
6048 (vhdl-backward-syntactic-ws lim)
6049 (/= (preceding-char) ?:)))
6051 ;; "for" (inside configuration declaration):
6052 ((and (looking-at "f")
6053 (save-excursion
6054 (backward-sexp)
6055 (not (looking-at "end\\s-+\\w")))
6056 (vhdl-has-syntax 'configuration))
6060 (defun vhdl-corresponding-mid (&optional lim)
6061 (cond
6062 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
6063 "begin")
6064 ((looking-at "then\\|use")
6065 "<else>")
6067 "end")))
6069 (defun vhdl-corresponding-end (&optional lim)
6070 "If the word at the current position corresponds to a \"begin\"
6071 keyword, then return a vector containing enough information to find
6072 the corresponding \"end\" keyword, else return nil. The keyword to
6073 search forward for is aref 0. The column in which the keyword must
6074 appear is aref 1 or nil if any column is suitable.
6075 Assumes that the caller will make sure that we are not in the middle
6076 of an identifier that just happens to contain a \"begin\" keyword."
6077 (save-excursion
6078 (and (looking-at vhdl-begin-fwd-re)
6079 (or (not (looking-at "\\<use\\>"))
6080 (save-excursion (back-to-indentation)
6081 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6082 (/= (preceding-char) ?_)
6083 (not (vhdl-in-literal))
6084 (vhdl-begin-p lim)
6085 (cond
6086 ;; "is", "generate", "loop":
6087 ((looking-at "[igl]")
6088 (vector "end"
6089 (and (vhdl-last-word (point))
6090 (or (vhdl-first-word (point))
6091 (save-excursion
6092 (vhdl-beginning-of-statement-1 lim)
6093 (vhdl-backward-skip-label lim)
6094 (vhdl-first-word (point)))))))
6095 ;; "begin", "else", "for":
6096 ((looking-at "be\\|[ef]")
6097 (vector "end"
6098 (and (vhdl-last-word (point))
6099 (or (vhdl-first-word (point))
6100 (save-excursion
6101 (vhdl-beginning-of-statement-1 lim)
6102 (vhdl-backward-skip-label lim)
6103 (vhdl-first-word (point)))))))
6104 ;; "component", "units", "record", "protected body":
6105 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
6106 ;; The first end found will close the block
6107 (vector "end" nil))
6108 ;; "block", "process", "procedural":
6109 ((looking-at "bl\\|p")
6110 (vector "end"
6111 (or (vhdl-first-word (point))
6112 (save-excursion
6113 (vhdl-beginning-of-statement-1 lim)
6114 (vhdl-backward-skip-label lim)
6115 (vhdl-first-word (point))))))
6116 ;; "then":
6117 ((looking-at "t\\|use")
6118 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6119 (and (vhdl-last-word (point))
6120 (or (vhdl-first-word (point))
6121 (save-excursion
6122 (vhdl-beginning-of-statement-1 lim)
6123 (vhdl-backward-skip-label lim)
6124 (vhdl-first-word (point)))))))
6125 ))))
6127 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6129 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6131 (defun vhdl-end-p (&optional lim)
6132 "Return t if we are looking at a real \"end\" keyword.
6133 Assumes that the caller will make sure that we are looking at
6134 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6135 the middle of an identifier that just happens to contain an \"end\"
6136 keyword."
6137 (or (not (looking-at "else"))
6138 ;; make sure that the "else" isn't inside a conditional signal
6139 ;; assignment.
6140 (save-excursion
6141 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6142 (or (eq (following-char) ?\;)
6143 (eq (point) lim)
6144 (vhdl-in-literal)))))
6146 (defun vhdl-corresponding-begin (&optional lim)
6147 "If the word at the current position corresponds to an \"end\"
6148 keyword, then return a vector containing enough information to find
6149 the corresponding \"begin\" keyword, else return nil. The keyword to
6150 search backward for is aref 0. The column in which the keyword must
6151 appear is aref 1 or nil if any column is suitable. The supplementary
6152 keyword to search forward for is aref 2 or nil if this is not
6153 required. If aref 3 is t, then the \"begin\" keyword may be found in
6154 the middle of a statement.
6155 Assumes that the caller will make sure that we are not in the middle
6156 of an identifier that just happens to contain an \"end\" keyword."
6157 (save-excursion
6158 (let (pos)
6159 (if (and (looking-at vhdl-end-fwd-re)
6160 (not (vhdl-in-literal))
6161 (vhdl-end-p lim))
6162 (if (looking-at "el")
6163 ;; "else", "elsif":
6164 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6165 ;; "end ...":
6166 (setq pos (point))
6167 (forward-sexp)
6168 (skip-chars-forward " \t\n\r\f")
6169 (cond
6170 ;; "end if":
6171 ((looking-at "if\\b[^_]")
6172 (vector "else\\|elsif\\|if"
6173 (vhdl-first-word pos)
6174 "else\\|then\\|use" nil))
6175 ;; "end component":
6176 ((looking-at "component\\b[^_]")
6177 (vector (buffer-substring (match-beginning 1)
6178 (match-end 1))
6179 (vhdl-first-word pos)
6180 nil nil))
6181 ;; "end units", "end record", "end protected":
6182 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6183 (vector (buffer-substring (match-beginning 1)
6184 (match-end 1))
6185 (vhdl-first-word pos)
6186 nil t))
6187 ;; "end block", "end process", "end procedural":
6188 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6189 (vector "begin" (vhdl-first-word pos) nil nil))
6190 ;; "end case":
6191 ((looking-at "case\\b[^_]")
6192 (vector "case" (vhdl-first-word pos) "is" nil))
6193 ;; "end generate":
6194 ((looking-at "generate\\b[^_]")
6195 (vector "generate\\|for\\|if"
6196 (vhdl-first-word pos)
6197 "generate" nil))
6198 ;; "end loop":
6199 ((looking-at "loop\\b[^_]")
6200 (vector "loop\\|while\\|for"
6201 (vhdl-first-word pos)
6202 "loop" nil))
6203 ;; "end for" (inside configuration declaration):
6204 ((looking-at "for\\b[^_]")
6205 (vector "for" (vhdl-first-word pos) nil nil))
6206 ;; "end [id]":
6208 (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
6209 (vhdl-first-word pos)
6210 ;; return an alist of (statement . keyword) mappings
6212 ;; "begin ... end [id]":
6213 ("begin" . nil)
6214 ;; "architecture ... is ... begin ... end [id]":
6215 ("architecture" . "is")
6216 ;; "configuration ... is ... end [id]":
6217 ("configuration" . "is")
6218 ;; "context ... is ... end [id]":
6219 ("context" . "is")
6220 ;; "entity ... is ... end [id]":
6221 ("entity" . "is")
6222 ;; "package ... is ... end [id]":
6223 ("package" . "is")
6224 ;; "procedure ... is ... begin ... end [id]":
6225 ("procedure" . "is")
6226 ;; "function ... is ... begin ... end [id]":
6227 ("function" . "is")
6229 nil))
6230 ))) ; "end ..."
6233 (defconst vhdl-leader-re
6234 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6236 (defun vhdl-end-of-leader ()
6237 (save-excursion
6238 (cond ((looking-at "block\\|process\\|procedural")
6239 (if (save-excursion
6240 (forward-sexp)
6241 (skip-chars-forward " \t\n\r\f")
6242 (= (following-char) ?\())
6243 (forward-sexp 2)
6244 (forward-sexp))
6245 (when (looking-at "[ \t\n\r\f]*is")
6246 (goto-char (match-end 0)))
6247 (point))
6248 ((looking-at "component")
6249 (forward-sexp 2)
6250 (when (looking-at "[ \t\n\r\f]*is")
6251 (goto-char (match-end 0)))
6252 (point))
6253 ((looking-at "for")
6254 (forward-sexp 2)
6255 (skip-chars-forward " \t\n\r\f")
6256 (while (looking-at "[,:(]")
6257 (forward-sexp)
6258 (skip-chars-forward " \t\n\r\f"))
6259 (point))
6260 (t nil)
6263 (defconst vhdl-trailer-re
6264 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6266 (defconst vhdl-statement-fwd-re
6267 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6268 "A regular expression for searching forward that matches all known
6269 \"statement\" keywords.")
6271 (defconst vhdl-statement-bwd-re
6272 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6273 "A regular expression for searching backward that matches all known
6274 \"statement\" keywords.")
6276 (defun vhdl-statement-p (&optional lim)
6277 "Return t if we are looking at a real \"statement\" keyword.
6278 Assumes that the caller will make sure that we are looking at
6279 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6280 in the middle of an identifier that just happens to contain a
6281 \"statement\" keyword."
6282 (cond
6283 ;; "for" ... "generate":
6284 ((and (looking-at "f")
6285 ;; Make sure it's the start of a parameter specification.
6286 (save-excursion
6287 (forward-sexp 2)
6288 (skip-chars-forward " \t\n\r\f")
6289 (looking-at "in\\b[^_]"))
6290 ;; Make sure it's not an "end for".
6291 (save-excursion
6292 (backward-sexp)
6293 (not (looking-at "end\\s-+\\w"))))
6295 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6296 ((and (looking-at "i")
6297 ;; Make sure it's not an "end if".
6298 (save-excursion
6299 (backward-sexp)
6300 (not (looking-at "end\\s-+\\w"))))
6302 ;; "while" ... "loop":
6303 ((looking-at "w")
6307 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6308 "Regexp describing a case statement alternative key.")
6310 (defun vhdl-case-alternative-p (&optional lim)
6311 "Return t if we are looking at a real case alternative.
6312 Assumes that the caller will make sure that we are looking at
6313 vhdl-case-alternative-re, and are not inside a literal, and that
6314 we are not in the middle of an identifier that just happens to
6315 contain a \"when\" keyword."
6316 (save-excursion
6317 (let (foundp)
6318 (while (and (not foundp)
6319 (re-search-backward ";\\|<=" lim 'move))
6320 (if (or (= (preceding-char) ?_)
6321 (vhdl-in-literal))
6322 (backward-char)
6323 (setq foundp t)))
6324 (or (eq (following-char) ?\;)
6325 (eq (point) lim)))
6328 ;; Core syntactic movement functions:
6330 (defconst vhdl-b-t-b-re
6331 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6333 (defun vhdl-backward-to-block (&optional lim)
6334 "Move backward to the previous \"begin\" or \"end\" keyword."
6335 (let (foundp)
6336 (while (and (not foundp)
6337 (re-search-backward vhdl-b-t-b-re lim 'move))
6338 (if (or (= (preceding-char) ?_)
6339 (vhdl-in-literal))
6340 (backward-char)
6341 (cond
6342 ;; "begin" keyword:
6343 ((and (looking-at vhdl-begin-fwd-re)
6344 (or (not (looking-at "\\<use\\>"))
6345 (save-excursion (back-to-indentation)
6346 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6347 (/= (preceding-char) ?_)
6348 (vhdl-begin-p lim))
6349 (setq foundp 'begin))
6350 ;; "end" keyword:
6351 ((and (looking-at vhdl-end-fwd-re)
6352 (/= (preceding-char) ?_)
6353 (vhdl-end-p lim))
6354 (setq foundp 'end))
6357 foundp
6360 (defun vhdl-forward-sexp (&optional count lim)
6361 "Move forward across one balanced expression (sexp).
6362 With COUNT, do it that many times."
6363 (interactive "p")
6364 (let ((count (or count 1))
6365 (case-fold-search t)
6366 end-vec target)
6367 (save-excursion
6368 (while (> count 0)
6369 ;; skip whitespace
6370 (skip-chars-forward " \t\n\r\f")
6371 ;; Check for an unbalanced "end" keyword
6372 (if (and (looking-at vhdl-end-fwd-re)
6373 (/= (preceding-char) ?_)
6374 (not (vhdl-in-literal))
6375 (vhdl-end-p lim)
6376 (not (looking-at "else")))
6377 (error
6378 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6379 ;; If the current keyword is a "begin" keyword, then find the
6380 ;; corresponding "end" keyword.
6381 (if (setq end-vec (vhdl-corresponding-end lim))
6382 (let (
6383 ;; end-re is the statement keyword to search for
6384 (end-re
6385 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6386 ;; column is either the statement keyword target column
6387 ;; or nil
6388 (column (aref end-vec 1))
6389 (eol (vhdl-point 'eol))
6390 foundp literal placeholder)
6391 ;; Look for the statement keyword.
6392 (while (and (not foundp)
6393 (re-search-forward end-re nil t)
6394 (setq placeholder (match-end 1))
6395 (goto-char (match-beginning 0)))
6396 ;; If we are in a literal, or not in the right target
6397 ;; column and not on the same line as the begin, then
6398 ;; try again.
6399 (if (or (and column
6400 (/= (current-indentation) column)
6401 (> (point) eol))
6402 (= (preceding-char) ?_)
6403 (setq literal (vhdl-in-literal)))
6404 (if (eq literal 'comment)
6405 (end-of-line)
6406 (forward-char))
6407 ;; An "else" keyword corresponds to both the opening brace
6408 ;; of the following sexp and the closing brace of the
6409 ;; previous sexp.
6410 (if (not (looking-at "else"))
6411 (goto-char placeholder))
6412 (setq foundp t))
6414 (if (not foundp)
6415 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6417 ;; If the current keyword is not a "begin" keyword, then just
6418 ;; perform the normal forward-sexp.
6419 (forward-sexp)
6421 (setq count (1- count))
6423 (setq target (point)))
6424 (goto-char target)
6425 nil))
6427 (defun vhdl-backward-sexp (&optional count lim)
6428 "Move backward across one balanced expression (sexp).
6429 With COUNT, do it that many times. LIM bounds any required backward
6430 searches."
6431 (interactive "p")
6432 (let ((count (or count 1))
6433 (case-fold-search t)
6434 begin-vec target)
6435 (save-excursion
6436 (while (> count 0)
6437 ;; Perform the normal backward-sexp, unless we are looking at
6438 ;; "else" - an "else" keyword corresponds to both the opening brace
6439 ;; of the following sexp and the closing brace of the previous sexp.
6440 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6441 (/= (preceding-char) ?_)
6442 (not (vhdl-in-literal)))
6444 (backward-sexp)
6445 (if (and (looking-at vhdl-begin-fwd-re)
6446 (or (not (looking-at "\\<use\\>"))
6447 (save-excursion
6448 (back-to-indentation)
6449 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6450 (/= (preceding-char) ?_)
6451 (not (vhdl-in-literal))
6452 (vhdl-begin-p lim))
6453 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6454 ;; If the current keyword is an "end" keyword, then find the
6455 ;; corresponding "begin" keyword.
6456 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6457 (/= (preceding-char) ?_))
6458 (let (
6459 ;; begin-re is the statement keyword to search for
6460 (begin-re
6461 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6462 ;; column is either the statement keyword target column
6463 ;; or nil
6464 (column (aref begin-vec 1))
6465 ;; internal-p controls where the statement keyword can
6466 ;; be found.
6467 (internal-p (aref begin-vec 3))
6468 (last-backward (point)) last-forward
6469 foundp literal keyword)
6470 ;; Look for the statement keyword.
6471 (while (and (not foundp)
6472 (re-search-backward begin-re lim t)
6473 (setq keyword
6474 (buffer-substring (match-beginning 1)
6475 (match-end 1))))
6476 ;; If we are in a literal or in the wrong column,
6477 ;; then try again.
6478 (if (or (and column
6479 (and (/= (current-indentation) column)
6480 ;; possibly accept current-column as
6481 ;; well as current-indentation.
6482 (or (not internal-p)
6483 (/= (current-column) column))))
6484 (= (preceding-char) ?_)
6485 (vhdl-in-literal))
6486 (backward-char)
6487 ;; If there is a supplementary keyword, then
6488 ;; search forward for it.
6489 (if (and (setq begin-re (aref begin-vec 2))
6490 (or (not (listp begin-re))
6491 ;; If begin-re is an alist, then find the
6492 ;; element corresponding to the actual
6493 ;; keyword that we found.
6494 (progn
6495 (setq begin-re
6496 (assoc keyword begin-re))
6497 (and begin-re
6498 (setq begin-re (cdr begin-re))))))
6499 (and
6500 (setq begin-re
6501 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6502 (save-excursion
6503 (setq last-forward (point))
6504 ;; Look for the supplementary keyword
6505 ;; (bounded by the backward search start
6506 ;; point).
6507 (while (and (not foundp)
6508 (re-search-forward begin-re
6509 last-backward t)
6510 (goto-char (match-beginning 1)))
6511 ;; If we are in a literal, then try again.
6512 (if (or (= (preceding-char) ?_)
6513 (setq literal
6514 (vhdl-in-literal)))
6515 (if (eq literal 'comment)
6516 (goto-char
6517 (min (vhdl-point 'eol) last-backward))
6518 (forward-char))
6519 ;; We have found the supplementary keyword.
6520 ;; Save the position of the keyword in foundp.
6521 (setq foundp (point)))
6523 foundp)
6524 ;; If the supplementary keyword was found, then
6525 ;; move point to the supplementary keyword.
6526 (goto-char foundp))
6527 ;; If there was no supplementary keyword, then
6528 ;; point is already at the statement keyword.
6529 (setq foundp t)))
6530 ) ; end of the search for the statement keyword
6531 (if (not foundp)
6532 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6534 (setq count (1- count))
6536 (setq target (point)))
6537 (goto-char target)
6538 nil))
6540 (defun vhdl-backward-up-list (&optional count limit)
6541 "Move backward out of one level of blocks.
6542 With argument, do this that many times."
6543 (interactive "p")
6544 (let ((count (or count 1))
6545 target)
6546 (save-excursion
6547 (while (> count 0)
6548 (if (looking-at vhdl-defun-re)
6549 (error "ERROR: Unbalanced blocks"))
6550 (vhdl-backward-to-block limit)
6551 (setq count (1- count)))
6552 (setq target (point)))
6553 (goto-char target)))
6555 (defun vhdl-end-of-defun (&optional count)
6556 "Move forward to the end of a VHDL defun."
6557 (interactive)
6558 (let ((case-fold-search t))
6559 (vhdl-beginning-of-defun)
6560 (if (not (looking-at "block\\|process\\|procedural"))
6561 (re-search-forward "\\bis\\b"))
6562 (vhdl-forward-sexp)))
6564 (defun vhdl-mark-defun ()
6565 "Put mark at end of this \"defun\", point at beginning."
6566 (interactive)
6567 (let ((case-fold-search t))
6568 (push-mark)
6569 (vhdl-beginning-of-defun)
6570 (push-mark)
6571 (if (not (looking-at "block\\|process\\|procedural"))
6572 (re-search-forward "\\bis\\b"))
6573 (vhdl-forward-sexp)
6574 (exchange-point-and-mark)))
6576 (defun vhdl-beginning-of-libunit ()
6577 "Move backward to the beginning of a VHDL library unit.
6578 Returns the location of the corresponding begin keyword, unless search
6579 stops due to beginning or end of buffer.
6580 Note that if point is between the \"libunit\" keyword and the
6581 corresponding \"begin\" keyword, then that libunit will not be
6582 recognized, and the search will continue backwards. If point is
6583 at the \"begin\" keyword, then the defun will be recognized. The
6584 returned point is at the first character of the \"libunit\" keyword."
6585 (let ((last-forward (point))
6586 (last-backward
6587 ;; Just in case we are actually sitting on the "begin"
6588 ;; keyword, allow for the keyword and an extra character,
6589 ;; as this will be used when looking forward for the
6590 ;; "begin" keyword.
6591 (save-excursion (forward-word-strictly 1) (1+ (point))))
6592 foundp literal placeholder)
6593 ;; Find the "libunit" keyword.
6594 (while (and (not foundp)
6595 (re-search-backward vhdl-libunit-re nil 'move))
6596 ;; If we are in a literal, or not at a real libunit, then try again.
6597 (if (or (= (preceding-char) ?_)
6598 (vhdl-in-literal)
6599 (not (vhdl-libunit-p)))
6600 (backward-char)
6601 ;; Find the corresponding "begin" keyword.
6602 (setq last-forward (point))
6603 (while (and (not foundp)
6604 (re-search-forward "\\bis\\b[^_]" last-backward t)
6605 (setq placeholder (match-beginning 0)))
6606 (if (or (= (preceding-char) ?_)
6607 (setq literal (vhdl-in-literal)))
6608 ;; It wasn't a real keyword, so keep searching.
6609 (if (eq literal 'comment)
6610 (goto-char
6611 (min (vhdl-point 'eol) last-backward))
6612 (forward-char))
6613 ;; We have found the begin keyword, loop will exit.
6614 (setq foundp placeholder)))
6615 ;; Go back to the libunit keyword
6616 (goto-char last-forward)))
6617 foundp))
6619 (defun vhdl-beginning-of-defun (&optional count)
6620 "Move backward to the beginning of a VHDL defun.
6621 With argument, do it that many times.
6622 Returns the location of the corresponding begin keyword, unless search
6623 stops due to beginning or end of buffer."
6624 ;; Note that if point is between the "defun" keyword and the
6625 ;; corresponding "begin" keyword, then that defun will not be
6626 ;; recognized, and the search will continue backwards. If point is
6627 ;; at the "begin" keyword, then the defun will be recognized. The
6628 ;; returned point is at the first character of the "defun" keyword.
6629 (interactive "p")
6630 (let ((count (or count 1))
6631 (case-fold-search t)
6632 (last-forward (point))
6633 foundp)
6634 (while (> count 0)
6635 (setq foundp nil)
6636 (goto-char last-forward)
6637 (let ((last-backward
6638 ;; Just in case we are actually sitting on the "begin"
6639 ;; keyword, allow for the keyword and an extra character,
6640 ;; as this will be used when looking forward for the
6641 ;; "begin" keyword.
6642 (save-excursion (forward-word-strictly 1) (1+ (point))))
6643 begin-string literal)
6644 (while (and (not foundp)
6645 (re-search-backward vhdl-defun-re nil 'move))
6646 ;; If we are in a literal, then try again.
6647 (if (or (= (preceding-char) ?_)
6648 (vhdl-in-literal))
6649 (backward-char)
6650 (if (setq begin-string (vhdl-corresponding-defun))
6651 ;; This is a real defun keyword.
6652 ;; Find the corresponding "begin" keyword.
6653 ;; Look for the begin keyword.
6654 (progn
6655 ;; Save the search start point.
6656 (setq last-forward (point))
6657 (while (and (not foundp)
6658 (search-forward begin-string last-backward t))
6659 (if (or (= (preceding-char) ?_)
6660 (save-match-data
6661 (setq literal (vhdl-in-literal))))
6662 ;; It wasn't a real keyword, so keep searching.
6663 (if (eq literal 'comment)
6664 (goto-char
6665 (min (vhdl-point 'eol) last-backward))
6666 (forward-char))
6667 ;; We have found the begin keyword, loop will exit.
6668 (setq foundp (match-beginning 0)))
6670 ;; Go back to the defun keyword
6671 (goto-char last-forward)) ; end search for begin keyword
6673 ) ; end of the search for the defun keyword
6675 (setq count (1- count))
6677 (vhdl-keep-region-active)
6678 foundp))
6680 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6681 "Go to the beginning of the innermost VHDL statement.
6682 With prefix arg, go back N - 1 statements. If already at the
6683 beginning of a statement then go to the beginning of the preceding
6684 one. If within a string or comment, or next to a comment (only
6685 whitespace between), move by sentences instead of statements.
6687 When called from a program, this function takes 3 optional args: the
6688 prefix arg, a buffer position limit which is the farthest back to
6689 search, and an argument indicating an interactive call."
6690 (interactive "p\np")
6691 (let ((count (or count 1))
6692 (case-fold-search t)
6693 (lim (or lim (point-min)))
6694 (here (point))
6695 state)
6696 (save-excursion
6697 (goto-char lim)
6698 (setq state (parse-partial-sexp (point) here nil nil)))
6699 (if (and interactive
6700 (or (nth 3 state)
6701 (nth 4 state)
6702 (looking-at (concat "[ \t]*" comment-start-skip))))
6703 (forward-sentence (- count))
6704 (while (> count 0)
6705 (vhdl-beginning-of-statement-1 lim)
6706 (setq count (1- count))))
6707 ;; its possible we've been left up-buf of lim
6708 (goto-char (max (point) lim))
6710 (vhdl-keep-region-active))
6712 (defconst vhdl-e-o-s-re
6713 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6715 (defun vhdl-end-of-statement ()
6716 "Very simple implementation."
6717 (interactive)
6718 (re-search-forward vhdl-e-o-s-re))
6720 (defconst vhdl-b-o-s-re
6721 (concat ";[^_]\\|([^_]\\|)[^_]\\|\\bwhen\\b[^_]\\|"
6722 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6724 (defun vhdl-beginning-of-statement-1 (&optional lim)
6725 "Move to the start of the current statement, or the previous
6726 statement if already at the beginning of one."
6727 (let ((lim (or lim (point-min)))
6728 (here (point))
6729 (pos (point))
6730 donep)
6731 ;; go backwards one balanced expression, but be careful of
6732 ;; unbalanced paren being reached
6733 (if (not (vhdl-safe (progn (backward-sexp) t)))
6734 (progn
6735 (backward-up-list 1)
6736 (forward-char)
6737 (vhdl-forward-syntactic-ws here)
6738 (setq donep t)))
6739 (while (and (not donep)
6740 (not (bobp))
6741 ;; look backwards for a statement boundary
6742 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6743 (if (or (= (preceding-char) ?_)
6744 (vhdl-in-literal))
6745 (backward-char)
6746 (cond
6747 ;; If we are looking at an open paren, then stop after it
6748 ((eq (following-char) ?\()
6749 (forward-char)
6750 (vhdl-forward-syntactic-ws here)
6751 (setq donep t))
6752 ;; If we are looking at a close paren, then skip it
6753 ((eq (following-char) ?\))
6754 (forward-char)
6755 (setq pos (point))
6756 (backward-sexp)
6757 (if (< (point) lim)
6758 (progn (goto-char pos)
6759 (vhdl-forward-syntactic-ws here)
6760 (setq donep t))))
6761 ;; If we are looking at a semicolon, then stop
6762 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6763 (progn
6764 (forward-char)
6765 (vhdl-forward-syntactic-ws here)
6766 (setq donep t)))
6767 ;; If we are looking at a "begin", then stop
6768 ((and (looking-at vhdl-begin-fwd-re)
6769 (or (not (looking-at "\\<use\\>"))
6770 (save-excursion
6771 (back-to-indentation)
6772 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6773 (/= (preceding-char) ?_)
6774 (vhdl-begin-p nil))
6775 ;; If it's a leader "begin", then find the
6776 ;; right place
6777 (if (looking-at vhdl-leader-re)
6778 (save-excursion
6779 ;; set a default stop point at the begin
6780 (setq pos (point))
6781 ;; is the start point inside the leader area ?
6782 (goto-char (vhdl-end-of-leader))
6783 (vhdl-forward-syntactic-ws here)
6784 (if (< (point) here)
6785 ;; start point was not inside leader area
6786 ;; set stop point at word after leader
6787 (setq pos (point))))
6788 (unless (looking-at "\\<else\\s-+generate\\>")
6789 (forward-word-strictly 1))
6790 (vhdl-forward-syntactic-ws here)
6791 (setq pos (point)))
6792 (goto-char pos)
6793 (setq donep t))
6794 ;; If we are looking at a "statement", then stop
6795 ((and (looking-at vhdl-statement-fwd-re)
6796 (/= (preceding-char) ?_)
6797 (vhdl-statement-p nil))
6798 (setq donep t))
6799 ;; If we are looking at a case alternative key, then stop
6800 ((and (looking-at vhdl-case-alternative-re)
6801 (vhdl-case-alternative-p lim))
6802 (save-excursion
6803 ;; set a default stop point at the when
6804 (setq pos (point))
6805 ;; is the start point inside the case alternative key ?
6806 (looking-at vhdl-case-alternative-re)
6807 (goto-char (match-end 0))
6808 (vhdl-forward-syntactic-ws here)
6809 (if (< (point) here)
6810 ;; start point was not inside the case alternative key
6811 ;; set stop point at word after case alternative keyleader
6812 (setq pos (point))))
6813 (goto-char pos)
6814 (setq donep t))
6815 ;; Bogus find, continue
6817 (backward-char)))))
6820 ;; Defuns for calculating the current syntactic state:
6822 (defun vhdl-get-library-unit (bod placeholder)
6823 "If there is an enclosing library unit at BOD, with its \"begin\"
6824 keyword at PLACEHOLDER, then return the library unit type."
6825 (let ((here (vhdl-point 'bol)))
6826 (if (save-excursion
6827 (goto-char placeholder)
6828 (vhdl-safe (vhdl-forward-sexp 1 bod))
6829 (<= here (point)))
6830 (save-excursion
6831 (goto-char bod)
6832 (cond
6833 ((looking-at "e") 'entity)
6834 ((looking-at "a") 'architecture)
6835 ((looking-at "conf") 'configuration)
6836 ((looking-at "cont") 'context)
6837 ((looking-at "p")
6838 (save-excursion
6839 (goto-char bod)
6840 (forward-sexp)
6841 (vhdl-forward-syntactic-ws here)
6842 (if (looking-at "body\\b[^_]")
6843 'package-body 'package))))))
6846 (defun vhdl-get-block-state (&optional lim)
6847 "Finds and records all the closest opens.
6848 LIM is the furthest back we need to search (it should be the
6849 previous libunit keyword)."
6850 (let ((here (point))
6851 (lim (or lim (point-min)))
6852 keyword sexp-start sexp-mid sexp-end
6853 preceding-sexp containing-sexp
6854 containing-begin containing-mid containing-paren)
6855 (save-excursion
6856 ;; Find the containing-paren, and use that as the limit
6857 (if (setq containing-paren
6858 (save-restriction
6859 (narrow-to-region lim (point))
6860 (vhdl-safe (scan-lists (point) -1 1))))
6861 (setq lim containing-paren))
6862 ;; Look backwards for "begin" and "end" keywords.
6863 (while (and (> (point) lim)
6864 (not containing-sexp))
6865 (setq keyword (vhdl-backward-to-block lim))
6866 (cond
6867 ((eq keyword 'begin)
6868 ;; Found a "begin" keyword
6869 (setq sexp-start (point))
6870 (setq sexp-mid (vhdl-corresponding-mid lim))
6871 (setq sexp-end (vhdl-safe
6872 (save-excursion
6873 (vhdl-forward-sexp 1 lim) (point))))
6874 (if (and sexp-end (<= sexp-end here))
6875 ;; we want to record this sexp, but we only want to
6876 ;; record the last-most of any of them before here
6877 (or preceding-sexp
6878 (setq preceding-sexp sexp-start))
6879 ;; we're contained in this sexp so put sexp-start on
6880 ;; front of list
6881 (setq containing-sexp sexp-start)
6882 (setq containing-mid sexp-mid)
6883 (setq containing-begin t)))
6884 ((eq keyword 'end)
6885 ;; Found an "end" keyword
6886 (forward-sexp)
6887 (setq sexp-end (point))
6888 (setq sexp-mid nil)
6889 (setq sexp-start
6890 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6891 (progn (backward-sexp) (point))))
6892 ;; we want to record this sexp, but we only want to
6893 ;; record the last-most of any of them before here
6894 (or preceding-sexp
6895 (setq preceding-sexp sexp-start)))
6897 ;; Check if the containing-paren should be the containing-sexp
6898 (if (and containing-paren
6899 (or (null containing-sexp)
6900 (< containing-sexp containing-paren)))
6901 (setq containing-sexp containing-paren
6902 preceding-sexp nil
6903 containing-begin nil
6904 containing-mid nil))
6905 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6909 (defconst vhdl-s-c-a-re
6910 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6912 (defun vhdl-skip-case-alternative (&optional lim)
6913 "Skip forward over case/when bodies, with optional maximal
6914 limit. If no next case alternative is found, nil is returned and
6915 point is not moved."
6916 (let ((lim (or lim (point-max)))
6917 (here (point))
6918 donep foundp)
6919 (while (and (< (point) lim)
6920 (not donep))
6921 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6922 (save-match-data
6923 (not (vhdl-in-literal)))
6924 (/= (match-beginning 0) here))
6925 (progn
6926 (goto-char (match-beginning 0))
6927 (cond
6928 ((and (looking-at "case")
6929 (re-search-forward "\\bis[^_]" lim t))
6930 (backward-sexp)
6931 (vhdl-forward-sexp))
6933 (setq donep t
6934 foundp t))))))
6935 (if (not foundp)
6936 (goto-char here))
6937 foundp))
6939 (defun vhdl-backward-skip-label (&optional lim)
6940 "Skip backward over a label, with optional maximal
6941 limit. If label is not found, nil is returned and point
6942 is not moved."
6943 (let ((lim (or lim (point-min)))
6944 placeholder)
6945 (if (save-excursion
6946 (vhdl-backward-syntactic-ws lim)
6947 (and (eq (preceding-char) ?:)
6948 (progn
6949 (backward-sexp)
6950 (setq placeholder (point))
6951 (looking-at vhdl-label-key))))
6952 (goto-char placeholder))
6955 (defun vhdl-forward-skip-label (&optional lim)
6956 "Skip forward over a label, with optional maximal
6957 limit. If label is not found, nil is returned and point
6958 is not moved."
6959 (let ((lim (or lim (point-max))))
6960 (if (looking-at vhdl-label-key)
6961 (progn
6962 (goto-char (match-end 0))
6963 (vhdl-forward-syntactic-ws lim)))
6966 (defun vhdl-get-syntactic-context ()
6967 "Guess the syntactic description of the current line of VHDL code."
6968 (save-excursion
6969 (save-restriction
6970 (beginning-of-line)
6971 (let* ((indent-point (point))
6972 (case-fold-search t)
6973 vec literal containing-sexp preceding-sexp
6974 containing-begin containing-mid containing-leader
6975 char-before-ip char-after-ip begin-after-ip end-after-ip
6976 placeholder lim library-unit
6979 ;; Reset the syntactic context
6980 (setq vhdl-syntactic-context nil)
6982 (save-excursion
6983 ;; Move to the start of the previous library unit, and
6984 ;; record the position of the "begin" keyword.
6985 (setq placeholder (vhdl-beginning-of-libunit))
6986 ;; The position of the "libunit" keyword gives us a gross
6987 ;; limit point.
6988 (setq lim (point))
6991 ;; If there is a previous library unit, and we are enclosed by
6992 ;; it, then set the syntax accordingly.
6993 (and placeholder
6994 (setq library-unit (vhdl-get-library-unit lim placeholder))
6995 (vhdl-add-syntax library-unit lim))
6997 ;; Find the surrounding state.
6998 (if (setq vec (vhdl-get-block-state lim))
6999 (progn
7000 (setq containing-sexp (aref vec 0))
7001 (setq preceding-sexp (aref vec 1))
7002 (setq containing-begin (aref vec 2))
7003 (setq containing-mid (aref vec 3))
7006 ;; set the limit on the farthest back we need to search
7007 (setq lim (if containing-sexp
7008 (save-excursion
7009 (goto-char containing-sexp)
7010 ;; set containing-leader if required
7011 (if (looking-at vhdl-leader-re)
7012 (setq containing-leader (vhdl-end-of-leader)))
7013 (vhdl-point 'bol))
7014 (point-min)))
7016 ;; cache char before and after indent point, and move point to
7017 ;; the most likely position to perform the majority of tests
7018 (goto-char indent-point)
7019 (skip-chars-forward " \t")
7020 (setq literal (vhdl-in-literal))
7021 (setq char-after-ip (following-char))
7022 (setq begin-after-ip (and
7023 (not literal)
7024 (looking-at vhdl-begin-fwd-re)
7025 (or (not (looking-at "\\<use\\>"))
7026 (save-excursion
7027 (back-to-indentation)
7028 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
7029 (vhdl-begin-p)))
7030 (setq end-after-ip (and
7031 (not literal)
7032 (looking-at vhdl-end-fwd-re)
7033 (vhdl-end-p)))
7034 (vhdl-backward-syntactic-ws lim)
7035 (setq char-before-ip (preceding-char))
7036 (goto-char indent-point)
7037 (skip-chars-forward " \t")
7039 ;; now figure out syntactic qualities of the current line
7040 (cond
7041 ;; CASE 1: in a string or comment.
7042 ((memq literal '(string comment))
7043 (vhdl-add-syntax literal (vhdl-point 'bopl)))
7044 ;; CASE 2: Line is at top level.
7045 ((null containing-sexp)
7046 ;; Find the point to which indentation will be relative
7047 (save-excursion
7048 (if (null preceding-sexp)
7049 ;; CASE 2X.1
7050 ;; no preceding-sexp -> use the preceding statement
7051 (vhdl-beginning-of-statement-1 lim)
7052 ;; CASE 2X.2
7053 ;; if there is a preceding-sexp then indent relative to it
7054 (goto-char preceding-sexp)
7055 ;; if not at boi, then the block-opening keyword is
7056 ;; probably following a label, so we need a different
7057 ;; relpos
7058 (if (/= (point) (vhdl-point 'boi))
7059 ;; CASE 2X.3
7060 (vhdl-beginning-of-statement-1 lim)))
7061 ;; v-b-o-s could have left us at point-min
7062 (and (bobp)
7063 ;; CASE 2X.4
7064 (vhdl-forward-syntactic-ws indent-point))
7065 (setq placeholder (point)))
7066 (cond
7067 ;; CASE 2A : we are looking at a block-open
7068 (begin-after-ip
7069 (vhdl-add-syntax 'block-open placeholder))
7070 ;; CASE 2B: we are looking at a block-close
7071 (end-after-ip
7072 (vhdl-add-syntax 'block-close placeholder))
7073 ;; CASE 2C: we are looking at a top-level statement
7074 ((progn
7075 (vhdl-backward-syntactic-ws lim)
7076 (or (bobp)
7077 (and (= (preceding-char) ?\;)
7078 (not (vhdl-in-quote-p)))))
7079 (vhdl-add-syntax 'statement placeholder))
7080 ;; CASE 2D: we are looking at a top-level statement-cont
7082 (vhdl-beginning-of-statement-1 lim)
7083 ;; v-b-o-s could have left us at point-min
7084 (and (bobp)
7085 ;; CASE 2D.1
7086 (vhdl-forward-syntactic-ws indent-point))
7087 (vhdl-add-syntax 'statement-cont (point)))
7088 )) ; end CASE 2
7089 ;; CASE 3: line is inside parentheses. Most likely we are
7090 ;; either in a subprogram argument (interface) list, or a
7091 ;; continued expression containing parentheses.
7092 ((null containing-begin)
7093 (vhdl-backward-syntactic-ws containing-sexp)
7094 (cond
7095 ;; CASE 3A: we are looking at the arglist closing paren
7096 ((eq char-after-ip ?\))
7097 (goto-char containing-sexp)
7098 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
7099 ;; CASE 3B: we are looking at the first argument in an empty
7100 ;; argument list.
7101 ((eq char-before-ip ?\()
7102 (goto-char containing-sexp)
7103 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
7104 ;; CASE 3C: we are looking at an arglist continuation line,
7105 ;; but the preceding argument is on the same line as the
7106 ;; opening paren. This case includes multi-line
7107 ;; expression paren groupings.
7108 ((and (save-excursion
7109 (goto-char (1+ containing-sexp))
7110 (skip-chars-forward " \t")
7111 (not (eolp))
7112 (not (looking-at "--\\|`")))
7113 (save-excursion
7114 (vhdl-beginning-of-statement-1 containing-sexp)
7115 (skip-chars-backward " \t(")
7116 (while (and (= (preceding-char) ?\;)
7117 (not (vhdl-in-quote-p)))
7118 (vhdl-beginning-of-statement-1 containing-sexp)
7119 (skip-chars-backward " \t("))
7120 (<= (point) containing-sexp)))
7121 (goto-char containing-sexp)
7122 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7123 ;; CASE 3D: we are looking at just a normal arglist
7124 ;; continuation line
7125 (t (vhdl-beginning-of-statement-1 containing-sexp)
7126 (vhdl-forward-syntactic-ws indent-point)
7127 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7129 ;; CASE 4: A block mid open
7130 ((and begin-after-ip
7131 (looking-at containing-mid))
7132 (goto-char containing-sexp)
7133 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7134 (if (looking-at vhdl-trailer-re)
7135 ;; CASE 4.1
7136 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7137 (vhdl-backward-skip-label (vhdl-point 'boi))
7138 (vhdl-add-syntax 'block-open (point)))
7139 ;; CASE 5: block close brace
7140 (end-after-ip
7141 (goto-char containing-sexp)
7142 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7143 (if (looking-at vhdl-trailer-re)
7144 ;; CASE 5.1
7145 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7146 (vhdl-backward-skip-label (vhdl-point 'boi))
7147 (vhdl-add-syntax 'block-close (point)))
7148 ;; CASE 6: A continued statement
7149 ((and (/= char-before-ip ?\;)
7150 ;; check it's not a trailer begin keyword, or a begin
7151 ;; keyword immediately following a label.
7152 (not (and begin-after-ip
7153 (or (looking-at vhdl-trailer-re)
7154 (save-excursion
7155 (vhdl-backward-skip-label containing-sexp)))))
7156 ;; check it's not a statement keyword
7157 (not (and (looking-at vhdl-statement-fwd-re)
7158 (vhdl-statement-p)))
7159 ;; see if the b-o-s is before the indent point
7160 (> indent-point
7161 (save-excursion
7162 (vhdl-beginning-of-statement-1 containing-sexp)
7163 ;; If we ended up after a leader, then this will
7164 ;; move us forward to the start of the first
7165 ;; statement. Note that a containing sexp here is
7166 ;; always a keyword, not a paren, so this will
7167 ;; have no effect if we hit the containing-sexp.
7168 (vhdl-forward-syntactic-ws indent-point)
7169 (setq placeholder (point))))
7170 ;; check it's not a block-intro
7171 (/= placeholder containing-sexp)
7172 ;; check it's not a case block-intro
7173 (save-excursion
7174 (goto-char placeholder)
7175 (or (not (looking-at vhdl-case-alternative-re))
7176 (> (match-end 0) indent-point))))
7177 ;; Make placeholder skip a label, but only if it puts us
7178 ;; before the indent point at the start of a line.
7179 (let ((new placeholder))
7180 (if (and (> indent-point
7181 (save-excursion
7182 (goto-char placeholder)
7183 (vhdl-forward-skip-label indent-point)
7184 (setq new (point))))
7185 (save-excursion
7186 (goto-char new)
7187 (eq new (progn (back-to-indentation) (point)))))
7188 (setq placeholder new)))
7189 (vhdl-add-syntax 'statement-cont placeholder)
7190 (if begin-after-ip
7191 (vhdl-add-syntax 'block-open)))
7192 ;; Statement. But what kind?
7193 ;; CASE 7: A case alternative key
7194 ((and (looking-at vhdl-case-alternative-re)
7195 (vhdl-case-alternative-p containing-sexp))
7196 ;; for a case alternative key, we set relpos to the first
7197 ;; non-whitespace char on the line containing the "case"
7198 ;; keyword.
7199 (goto-char containing-sexp)
7200 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7201 (if (looking-at vhdl-trailer-re)
7202 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7203 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7204 ;; CASE 8: statement catchall
7206 ;; we know its a statement, but we need to find out if it is
7207 ;; the first statement in a block
7208 (if containing-leader
7209 (goto-char containing-leader)
7210 (goto-char containing-sexp)
7211 ;; Note that a containing sexp here is always a keyword,
7212 ;; not a paren, so skip over the keyword.
7213 (forward-sexp))
7214 ;; move to the start of the first statement
7215 (vhdl-forward-syntactic-ws indent-point)
7216 (setq placeholder (point))
7217 ;; we want to ignore case alternatives keys when skipping forward
7218 (let (incase-p)
7219 (while (looking-at vhdl-case-alternative-re)
7220 (setq incase-p (point))
7221 ;; we also want to skip over the body of the
7222 ;; case/when statement if that doesn't put us at
7223 ;; after the indent-point
7224 (while (vhdl-skip-case-alternative indent-point))
7225 ;; set up the match end
7226 (looking-at vhdl-case-alternative-re)
7227 (goto-char (match-end 0))
7228 ;; move to the start of the first case alternative statement
7229 (vhdl-forward-syntactic-ws indent-point)
7230 (setq placeholder (point)))
7231 (cond
7232 ;; CASE 8A: we saw a case/when statement so we must be
7233 ;; in a switch statement. find out if we are at the
7234 ;; statement just after a case alternative key
7235 ((and incase-p
7236 (= (point) indent-point))
7237 ;; relpos is the "when" keyword
7238 (vhdl-add-syntax 'statement-case-intro incase-p))
7239 ;; CASE 8B: any old statement
7240 ((< (point) indent-point)
7241 ;; relpos is the first statement of the block
7242 (vhdl-add-syntax 'statement placeholder)
7243 (if begin-after-ip
7244 (vhdl-add-syntax 'block-open)))
7245 ;; CASE 8C: first statement in a block
7247 (goto-char containing-sexp)
7248 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7249 (if (looking-at vhdl-trailer-re)
7250 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7251 (vhdl-backward-skip-label (vhdl-point 'boi))
7252 (vhdl-add-syntax 'statement-block-intro (point))
7253 (if begin-after-ip
7254 (vhdl-add-syntax 'block-open)))
7258 ;; now we need to look at any modifiers
7259 (goto-char indent-point)
7260 (skip-chars-forward " \t")
7261 (if (or (looking-at "--") (looking-at "/\\*"))
7262 (vhdl-add-syntax 'comment))
7263 (if (looking-at "`")
7264 (vhdl-add-syntax 'directive))
7265 (if (eq literal 'pound)
7266 (vhdl-add-syntax 'cpp-macro))
7267 ;; return the syntax
7268 vhdl-syntactic-context))))
7270 ;; Standard indentation line-ups:
7272 (defun vhdl-lineup-arglist (langelem)
7273 "Lineup the current arglist line with the arglist appearing just
7274 after the containing paren which starts the arglist."
7275 (save-excursion
7276 (let* ((containing-sexp
7277 (save-excursion
7278 ;; arglist-cont-nonempty gives relpos ==
7279 ;; to boi of containing-sexp paren. This
7280 ;; is good when offset is +, but bad
7281 ;; when it is vhdl-lineup-arglist, so we
7282 ;; have to special case a kludge here.
7283 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7284 (progn
7285 (beginning-of-line)
7286 (backward-up-list 1)
7287 (skip-chars-forward " \t" (vhdl-point 'eol)))
7288 (goto-char (cdr langelem)))
7289 (point)))
7290 (cs-curcol (save-excursion
7291 (goto-char (cdr langelem))
7292 (current-column))))
7293 (if (save-excursion
7294 (beginning-of-line)
7295 (looking-at "[ \t]*)"))
7296 (progn (goto-char (match-end 0))
7297 (backward-sexp)
7298 (forward-char)
7299 (vhdl-forward-syntactic-ws)
7300 (- (current-column) cs-curcol))
7301 (goto-char containing-sexp)
7302 (or (eolp)
7303 (let ((eol (vhdl-point 'eol))
7304 (here (progn
7305 (forward-char)
7306 (skip-chars-forward " \t")
7307 (point))))
7308 (vhdl-forward-syntactic-ws)
7309 (if (< (point) eol)
7310 (goto-char here))))
7311 (- (current-column) cs-curcol)
7312 ))))
7314 (defun vhdl-lineup-arglist-intro (langelem)
7315 "Lineup an arglist-intro line to just after the open paren."
7316 (save-excursion
7317 (let ((cs-curcol (save-excursion
7318 (goto-char (cdr langelem))
7319 (current-column)))
7320 (ce-curcol (save-excursion
7321 (beginning-of-line)
7322 (backward-up-list 1)
7323 (skip-chars-forward " \t" (vhdl-point 'eol))
7324 (current-column))))
7325 (- ce-curcol cs-curcol -1))))
7327 (defun vhdl-lineup-comment (langelem)
7328 "Support old behavior for comment indentation. We look at
7329 vhdl-comment-only-line-offset to decide how to indent comment
7330 only-lines."
7331 (save-excursion
7332 (back-to-indentation)
7333 ;; at or to the right of comment-column
7334 (if (>= (current-column) comment-column)
7335 (vhdl-comment-indent)
7336 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7337 (if (not (bolp))
7338 ;; inside multi-line comment
7339 (if (looking-at "\\*")
7341 ;; otherwise
7342 (or (car-safe vhdl-comment-only-line-offset)
7343 vhdl-comment-only-line-offset))
7344 (or (cdr-safe vhdl-comment-only-line-offset)
7345 (car-safe vhdl-comment-only-line-offset)
7346 -1000 ;jam it against the left side
7347 )))))
7349 (defun vhdl-lineup-statement-cont (langelem)
7350 "Line up statement-cont after the assignment operator."
7351 (save-excursion
7352 (let* ((relpos (cdr langelem))
7353 (assignp (save-excursion
7354 (goto-char (vhdl-point 'boi))
7355 (and (re-search-forward "\\(<\\|:\\|=\\)="
7356 (vhdl-point 'eol) t)
7357 (- (point) (vhdl-point 'boi)))))
7358 (curcol (progn
7359 (goto-char relpos)
7360 (current-column)))
7361 foundp)
7362 (while (and (not foundp)
7363 (< (point) (vhdl-point 'eol)))
7364 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7365 (if (vhdl-in-literal)
7366 (forward-char)
7367 (if (= (preceding-char) ?\()
7368 ;; skip over any parenthesized expressions
7369 (goto-char (min (vhdl-point 'eol)
7370 (scan-lists (point) 1 1)))
7371 ;; found an assignment operator (not at eol)
7372 (setq foundp (not (looking-at "\\s-*$"))))))
7373 (if (not foundp)
7374 ;; there's no assignment operator on the line
7375 vhdl-basic-offset
7376 ;; calculate indentation column after assign and ws, unless
7377 ;; our line contains an assignment operator
7378 (if (not assignp)
7379 (progn
7380 (forward-char)
7381 (skip-chars-forward " \t")
7382 (setq assignp 0)))
7383 (- (current-column) assignp curcol))
7386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7387 ;; Progress reporting
7389 (defvar vhdl-progress-info nil
7390 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7392 (defun vhdl-update-progress-info (string pos)
7393 "Update progress information."
7394 (when (and vhdl-progress-info (not noninteractive)
7395 (< vhdl-progress-interval
7396 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7397 (let ((delta (- (aref vhdl-progress-info 1)
7398 (aref vhdl-progress-info 0))))
7399 (message "%s... (%2d%%)" string
7400 (if (= 0 delta)
7402 (floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
7403 delta))))
7404 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7406 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7407 ;; Indentation commands
7409 (defun vhdl-electric-tab (&optional prefix-arg)
7410 "If preceding character is part of a word or a paren then hippie-expand,
7411 else if right of non whitespace on line then insert tab,
7412 else if last command was a tab or return then dedent one step or if a comment
7413 toggle between normal indent and inline comment indent,
7414 else indent `correctly'."
7415 (interactive "*P")
7416 (vhdl-prepare-search-2
7417 (cond
7418 ;; indent region if region is active
7419 ((and (not (featurep 'xemacs)) (use-region-p))
7420 (vhdl-indent-region (region-beginning) (region-end) nil))
7421 ;; expand word
7422 ((= (char-syntax (preceding-char)) ?w)
7423 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7424 (case-replace nil)
7425 (hippie-expand-only-buffers
7426 (or (and (boundp 'hippie-expand-only-buffers)
7427 hippie-expand-only-buffers)
7428 '(vhdl-mode))))
7429 (vhdl-expand-abbrev prefix-arg)))
7430 ;; expand parenthesis
7431 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7432 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7433 (case-replace nil))
7434 (vhdl-expand-paren prefix-arg)))
7435 ;; insert tab
7436 ((> (current-column) (current-indentation))
7437 (insert-tab))
7438 ;; toggle comment indent
7439 ((and (looking-at "--")
7440 (or (eq last-command 'vhdl-electric-tab)
7441 (eq last-command 'vhdl-electric-return)))
7442 (cond ((= (current-indentation) 0) ; no indent
7443 (indent-to 1)
7444 (indent-according-to-mode))
7445 ((< (current-indentation) comment-column) ; normal indent
7446 (indent-to comment-column)
7447 (indent-according-to-mode))
7448 (t ; inline comment indent
7449 (delete-region (line-beginning-position) (point)))))
7450 ;; dedent
7451 ((and (>= (current-indentation) vhdl-basic-offset)
7452 (or (eq last-command 'vhdl-electric-tab)
7453 (eq last-command 'vhdl-electric-return)))
7454 (backward-delete-char-untabify vhdl-basic-offset nil))
7455 ;; indent line
7456 (t (indent-according-to-mode)))
7457 (setq this-command 'vhdl-electric-tab)))
7459 (defun vhdl-electric-return ()
7460 "newline-and-indent or indent-new-comment-line if in comment and preceding
7461 character is a space."
7462 (interactive)
7463 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7464 (indent-new-comment-line)
7465 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7466 (not (vhdl-in-comment-p)))
7467 (vhdl-fix-case-word -1))
7468 (newline-and-indent)))
7470 (defun vhdl-indent-line ()
7471 "Indent the current line as VHDL code. Returns the amount of
7472 indentation change."
7473 (interactive)
7474 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7475 (pos (- (point-max) (point)))
7476 (is-comment nil)
7477 (indent
7478 (if syntax
7479 ;; indent syntax-based
7480 (if (and (eq (caar syntax) 'comment)
7481 (>= (vhdl-get-offset (car syntax)) comment-column))
7482 ;; special case: comments at or right of comment-column
7483 (vhdl-get-offset (car syntax))
7484 ;; align comments like following code line
7485 (when vhdl-indent-comment-like-next-code-line
7486 (save-excursion
7487 (while (eq (caar syntax) 'comment)
7488 (setq is-comment t)
7489 (beginning-of-line 2)
7490 (setq syntax (vhdl-get-syntactic-context)))))
7491 (when is-comment
7492 (push (cons 'comment nil) syntax))
7493 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7494 ;; indent like previous nonblank line
7495 (save-excursion (beginning-of-line)
7496 (re-search-backward "^[^\n]" nil t)
7497 (current-indentation))))
7498 (shift-amt (- indent (current-indentation))))
7499 (and vhdl-echo-syntactic-information-p
7500 (message "syntax: %s, indent= %d" syntax indent))
7501 (let ((has-formfeed
7502 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7503 (when (or (not (zerop shift-amt)) has-formfeed)
7504 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7505 (beginning-of-line)
7506 (when has-formfeed (insert "\f"))
7507 (indent-to indent)))
7508 (if (< (point) (vhdl-point 'boi))
7509 (back-to-indentation)
7510 ;; If initial point was within line's indentation, position after
7511 ;; the indentation. Else stay at same point in text.
7512 (when (> (- (point-max) pos) (point))
7513 (goto-char (- (point-max) pos))))
7514 (run-hooks 'vhdl-special-indent-hook)
7515 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7516 shift-amt))
7518 (defun vhdl-indent-region (beg end &optional column)
7519 "Indent region as VHDL code.
7520 Adds progress reporting to `indent-region'."
7521 (interactive "r\nP")
7522 (when vhdl-progress-interval
7523 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7524 (count-lines (point-min) end) 0)))
7525 (indent-region beg end column)
7526 (when vhdl-progress-interval (message "Indenting...done"))
7527 (setq vhdl-progress-info nil))
7529 (defun vhdl-indent-buffer ()
7530 "Indent whole buffer as VHDL code.
7531 Calls `indent-region' for whole buffer and adds progress reporting."
7532 (interactive)
7533 (vhdl-indent-region (point-min) (point-max)))
7535 (defun vhdl-indent-group ()
7536 "Indent group of lines between empty lines."
7537 (interactive)
7538 (let ((beg (save-excursion
7539 (if (re-search-backward vhdl-align-group-separate nil t)
7540 (point-marker)
7541 (point-min-marker))))
7542 (end (save-excursion
7543 (if (re-search-forward vhdl-align-group-separate nil t)
7544 (point-marker)
7545 (point-max-marker)))))
7546 (vhdl-indent-region beg end)))
7548 (defun vhdl-indent-sexp (&optional endpos)
7549 "Indent each line of the list starting just after point.
7550 If optional arg ENDPOS is given, indent each line, stopping when
7551 ENDPOS is encountered."
7552 (interactive)
7553 (save-excursion
7554 (let ((beg (point))
7555 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7556 (indent-region beg end nil))))
7558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7559 ;; Miscellaneous commands
7561 (defun vhdl-show-syntactic-information ()
7562 "Show syntactic information for current line."
7563 (interactive)
7564 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7565 (vhdl-keep-region-active))
7567 ;; Verification and regression functions:
7569 (defun vhdl-regress-line (&optional arg)
7570 "Check syntactic information for current line."
7571 (interactive "P")
7572 (let ((expected (save-excursion
7573 (end-of-line)
7574 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7575 (forward-char 4)
7576 (read (current-buffer)))))
7577 (actual (vhdl-get-syntactic-context))
7578 (expurgated))
7579 ;; remove the library unit symbols
7580 (mapc
7581 (function
7582 (lambda (elt)
7583 (if (memq (car elt) '(entity configuration context package
7584 package-body architecture))
7586 (setq expurgated (append expurgated (list elt))))))
7587 actual)
7588 (if (and (not arg) expected (listp expected))
7589 (if (not (equal expected expurgated))
7590 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7591 (save-excursion
7592 (beginning-of-line)
7593 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7594 (end-of-line)
7595 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7596 (delete-region (point) (line-end-position)))
7597 (insert " -- ")
7598 (insert (format "%s" expurgated))))))
7599 (vhdl-keep-region-active))
7602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7603 ;;; Alignment, beautifying
7604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7606 (defconst vhdl-align-alist
7608 ;; after some keywords
7609 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7610 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7611 ;; before ':'
7612 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7613 ;; after direction specifications
7614 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7615 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7616 ;; before "==", ":=", "=>", and "<="
7617 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7618 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7619 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7620 ;; before some keywords
7621 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7622 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7623 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7624 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7625 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7626 ;; before "=>" since "when/else ... =>" can occur
7627 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7629 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7630 It is searched in order. If REGEXP is found anywhere in the first
7631 line of a region to be aligned, ALIGN-PATTERN will be used for that
7632 region. ALIGN-PATTERN must include the whitespace to be expanded or
7633 contracted. It may also provide regexps for the text surrounding the
7634 whitespace. SUBEXP specifies which sub-expression of
7635 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7638 ;; Align code
7640 (defvar vhdl-align-try-all-clauses t
7641 "If REGEXP is not found on the first line of the region that clause
7642 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7644 (defun vhdl-do-group (function &optional spacing)
7645 "Apply FUNCTION on group of lines between empty lines."
7646 (let
7647 ;; search for group beginning
7648 ((beg (save-excursion
7649 (if (re-search-backward vhdl-align-group-separate nil t)
7650 (progn (beginning-of-line 2) (back-to-indentation) (point))
7651 (point-min))))
7652 ;; search for group end
7653 (end (save-excursion
7654 (if (re-search-forward vhdl-align-group-separate nil t)
7655 (progn (beginning-of-line) (point))
7656 (point-max)))))
7657 ;; run FUNCTION
7658 (funcall function beg end spacing)))
7660 (defun vhdl-do-list (function &optional spacing)
7661 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7662 parentheses."
7663 (let (beg end)
7664 (save-excursion
7665 ;; search for beginning of balanced group of parentheses
7666 (setq beg (vhdl-re-search-backward "[()]" nil t))
7667 (while (looking-at ")")
7668 (forward-char) (backward-sexp)
7669 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7670 ;; search for end of balanced group of parentheses
7671 (when beg
7672 (forward-list)
7673 (setq end (point))
7674 (goto-char (1+ beg))
7675 (skip-chars-forward " \t\n\r\f")
7676 (setq beg (point))))
7677 ;; run FUNCTION
7678 (if beg
7679 (funcall function beg end spacing)
7680 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7682 (defun vhdl-do-same-indent (function &optional spacing)
7683 "Apply FUNCTION to block of lines with same indent."
7684 (let ((indent (current-indentation))
7685 beg end)
7686 ;; search for first line with same indent
7687 (save-excursion
7688 (while (and (not (bobp))
7689 (or (looking-at "^\\s-*\\(--.*\\)?$")
7690 (= (current-indentation) indent)))
7691 (unless (looking-at "^\\s-*$")
7692 (back-to-indentation) (setq beg (point)))
7693 (beginning-of-line -0)))
7694 ;; search for last line with same indent
7695 (save-excursion
7696 (while (and (not (eobp))
7697 (or (looking-at "^\\s-*\\(--.*\\)?$")
7698 (= (current-indentation) indent)))
7699 (if (looking-at "^\\s-*$")
7700 (beginning-of-line 2)
7701 (beginning-of-line 2)
7702 (setq end (point)))))
7703 ;; run FUNCTION
7704 (funcall function beg end spacing)))
7706 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7707 "Attempt to align a range of lines based on the content of the
7708 lines. The definition of `alignment-list' determines the matching
7709 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7710 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7711 indentation is done before aligning."
7712 (interactive "r\np")
7713 (setq alignment-list (or alignment-list vhdl-align-alist))
7714 (setq spacing (or spacing 1))
7715 (save-excursion
7716 (let (bol indent)
7717 (goto-char end)
7718 (setq end (point-marker))
7719 (goto-char begin)
7720 (setq bol (setq begin (progn (beginning-of-line) (point))))
7721 (when indent
7722 (indent-region bol end nil))))
7723 (let ((copy (copy-alist alignment-list)))
7724 (vhdl-prepare-search-2
7725 (while copy
7726 (save-excursion
7727 (goto-char begin)
7728 (let (element
7729 (eol (point-at-eol)))
7730 (setq element (nth 0 copy))
7731 (when (and (or (and (listp (car element))
7732 (memq major-mode (car element)))
7733 (eq major-mode (car element)))
7734 (or vhdl-align-try-all-clauses
7735 (re-search-forward (car (cdr element)) eol t)))
7736 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7737 (car (cdr (cdr (cdr element)))) spacing))
7738 (setq copy (cdr copy))))))))
7740 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7741 "Align a range of lines from BEGIN to END. The regular expression
7742 MATCH must match exactly one field: the whitespace to be
7743 contracted/expanded. The alignment column will equal the
7744 rightmost column of the widest whitespace block. SPACING is
7745 the amount of extra spaces to add to the calculated maximum required.
7746 SPACING defaults to 1 so that at least one space is inserted after
7747 the token in MATCH."
7748 (setq spacing (or spacing 1))
7749 (setq substr (or substr 1))
7750 (save-excursion
7751 (let (distance (max 0) (lines 0) bol eol width)
7752 ;; Determine the greatest whitespace distance to the alignment
7753 ;; character
7754 (goto-char begin)
7755 (setq eol (point-at-eol)
7756 bol (setq begin (progn (beginning-of-line) (point))))
7757 (while (< bol end)
7758 (save-excursion
7759 (when (and (vhdl-re-search-forward match eol t)
7760 (save-excursion
7761 (goto-char (match-beginning 0))
7762 (forward-char)
7763 (and (not (vhdl-in-literal))
7764 (not (vhdl-in-quote-p))
7765 (not (vhdl-in-extended-identifier-p))))
7766 (not (looking-at "\\s-*$")))
7767 (setq distance (- (match-beginning substr) bol))
7768 (when (> distance max)
7769 (setq max distance))))
7770 (forward-line)
7771 (setq bol (point)
7772 eol (point-at-eol))
7773 (setq lines (1+ lines)))
7774 ;; Now insert enough maxs to push each assignment operator to
7775 ;; the same column. We need to use 'lines' as a counter, since
7776 ;; the location of the mark may change
7777 (goto-char (setq bol begin))
7778 (setq eol (point-at-eol))
7779 (while (> lines 0)
7780 (when (and (vhdl-re-search-forward match eol t)
7781 (save-excursion
7782 (goto-char (match-beginning 0))
7783 (forward-char)
7784 (and (not (vhdl-in-literal))
7785 (not (vhdl-in-quote-p))
7786 (not (vhdl-in-extended-identifier-p))))
7787 (not (looking-at "\\s-*$"))
7788 (> (match-beginning 0) ; not if at boi
7789 (save-excursion (back-to-indentation) (point))))
7790 (setq width (- (match-end substr) (match-beginning substr)))
7791 (setq distance (- (match-beginning substr) bol))
7792 (goto-char (match-beginning substr))
7793 (delete-char width)
7794 (insert-char ? (+ (- max distance) spacing)))
7795 (beginning-of-line)
7796 (forward-line)
7797 (setq bol (point)
7798 eol (point-at-eol))
7799 (setq lines (1- lines))))))
7801 (defun vhdl-align-region-groups (beg end &optional spacing
7802 no-message no-comments)
7803 "Align region, treat groups of lines separately."
7804 (interactive "r\nP")
7805 (save-excursion
7806 (let (orig pos)
7807 (goto-char beg)
7808 (beginning-of-line)
7809 (setq orig (point-marker))
7810 (setq beg (point))
7811 (goto-char end)
7812 (setq end (point-marker))
7813 (untabify beg end)
7814 (unless no-message
7815 (when vhdl-progress-interval
7816 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7817 (count-lines (point-min) end) 0))))
7818 (when (nth 0 vhdl-beautify-options)
7819 (vhdl-fixup-whitespace-region beg end t))
7820 (goto-char beg)
7821 (if (not vhdl-align-groups)
7822 ;; align entire region
7823 (progn (vhdl-align-region-1 beg end spacing)
7824 (unless no-comments
7825 (vhdl-align-inline-comment-region-1 beg end)))
7826 ;; align groups
7827 (while (and (< beg end)
7828 (re-search-forward vhdl-align-group-separate end t))
7829 (setq pos (point-marker))
7830 (vhdl-align-region-1 beg pos spacing)
7831 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7832 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7833 (setq beg (1+ pos))
7834 (goto-char beg))
7835 ;; align last group
7836 (when (< beg end)
7837 (vhdl-align-region-1 beg end spacing)
7838 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7839 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7840 (when vhdl-indent-tabs-mode
7841 (tabify orig end))
7842 (unless no-message
7843 (when vhdl-progress-interval (message "Aligning...done"))
7844 (setq vhdl-progress-info nil)))))
7846 (defun vhdl-align-region (beg end &optional spacing)
7847 "Align region, treat blocks with same indent and argument lists separately."
7848 (interactive "r\nP")
7849 (if (not vhdl-align-same-indent)
7850 ;; align entire region
7851 (vhdl-align-region-groups beg end spacing)
7852 ;; align blocks with same indent and argument lists
7853 (save-excursion
7854 (let ((cur-beg beg)
7855 indent cur-end)
7856 (when vhdl-progress-interval
7857 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7858 (count-lines (point-min) end) 0)))
7859 (goto-char end)
7860 (setq end (point-marker))
7861 (goto-char cur-beg)
7862 (while (< (point) end)
7863 ;; is argument list opening?
7864 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7865 (point) (vhdl-point 'eol)))))
7866 ;; determine region for argument list
7867 (progn (goto-char cur-beg)
7868 (forward-sexp)
7869 (setq cur-end (point))
7870 (beginning-of-line 2))
7871 ;; determine region with same indent
7872 (setq indent (current-indentation))
7873 (setq cur-beg (point))
7874 (setq cur-end (vhdl-point 'bonl))
7875 (beginning-of-line 2)
7876 (while (and (< (point) end)
7877 (or (looking-at "^\\s-*\\(--.*\\)?$")
7878 (= (current-indentation) indent))
7879 (<= (save-excursion
7880 (nth 0 (parse-partial-sexp
7881 (point) (vhdl-point 'eol)))) 0))
7882 (unless (looking-at "^\\s-*$")
7883 (setq cur-end (vhdl-point 'bonl)))
7884 (beginning-of-line 2)))
7885 ;; align region
7886 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7887 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7888 (when vhdl-progress-interval (message "Aligning...done"))
7889 (setq vhdl-progress-info nil)))))
7891 (defun vhdl-align-group (&optional spacing)
7892 "Align group of lines between empty lines."
7893 (interactive)
7894 (vhdl-do-group 'vhdl-align-region spacing))
7896 (defun vhdl-align-list (&optional spacing)
7897 "Align the lines of a list surrounded by a balanced group of parentheses."
7898 (interactive)
7899 (vhdl-do-list 'vhdl-align-region-groups spacing))
7901 (defun vhdl-align-same-indent (&optional spacing)
7902 "Align block of lines with same indent."
7903 (interactive)
7904 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7906 (defun vhdl-align-declarations (&optional spacing)
7907 "Align the lines within the declarative part of a design unit."
7908 (interactive)
7909 (let (beg end)
7910 (vhdl-prepare-search-2
7911 (save-excursion
7912 ;; search for declarative part
7913 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
7914 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7915 (setq beg (point))
7916 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7917 (setq end (point)))))
7918 (if beg
7919 (vhdl-align-region-groups beg end spacing)
7920 (error "ERROR: Not within the declarative part of a design unit"))))
7922 (defun vhdl-align-buffer ()
7923 "Align buffer."
7924 (interactive)
7925 (vhdl-align-region (point-min) (point-max)))
7927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7928 ;; Align inline comments
7930 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7931 "Align inline comments in region."
7932 (save-excursion
7933 (let ((start-max comment-column)
7934 (length-max 0)
7935 comment-list start-list tmp-list start length
7936 cur-start prev-start no-code)
7937 (setq spacing (or spacing 2))
7938 (vhdl-prepare-search-2
7939 (goto-char beg)
7940 ;; search for comment start positions and lengths
7941 (while (< (point) end)
7942 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7943 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7944 (not (save-excursion (goto-char (match-beginning 2))
7945 (vhdl-in-literal))))
7946 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7947 (setq length (- (match-end 2) (match-beginning 2)))
7948 (setq start-max (max start start-max))
7949 (setq length-max (max length length-max))
7950 (push (cons start length) comment-list))
7951 (beginning-of-line 2))
7952 (setq comment-list
7953 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7954 ;; reduce start positions
7955 (setq start-list (list (caar comment-list)))
7956 (setq comment-list (cdr comment-list))
7957 (while comment-list
7958 (unless (or (= (caar comment-list) (car start-list))
7959 (<= (+ (car start-list) (cdar comment-list))
7960 end-comment-column))
7961 (push (caar comment-list) start-list))
7962 (setq comment-list (cdr comment-list)))
7963 ;; align lines as nicely as possible
7964 (goto-char beg)
7965 (while (< (point) end)
7966 (setq cur-start nil)
7967 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7968 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7969 (not (save-excursion
7970 (goto-char (match-beginning 3))
7971 (vhdl-in-literal))))
7972 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7973 (>= (- (match-end 2) (match-beginning 2))
7974 comment-column))))
7975 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7976 (setq length (- (match-end 3) (match-beginning 3)))
7977 (setq no-code (= (match-beginning 1) (match-end 1)))
7978 ;; insert minimum whitespace
7979 (goto-char (match-end 2))
7980 (delete-region (match-beginning 2) (match-end 2))
7981 (insert-char ?\ spacing)
7982 (setq tmp-list start-list)
7983 ;; insert additional whitespace to align
7984 (setq cur-start
7985 (cond
7986 ;; align comment-only line to inline comment of previous line
7987 ((and no-code prev-start
7988 (<= length (- end-comment-column prev-start)))
7989 prev-start)
7990 ;; align all comments at `start-max' if this is possible
7991 ((<= (+ start-max length-max) end-comment-column)
7992 start-max)
7993 ;; align at `comment-column' if possible
7994 ((and (<= start comment-column)
7995 (<= length (- end-comment-column comment-column)))
7996 comment-column)
7997 ;; align at left-most possible start position otherwise
7999 (while (and tmp-list (< (car tmp-list) start))
8000 (setq tmp-list (cdr tmp-list)))
8001 (car tmp-list))))
8002 (indent-to cur-start))
8003 (setq prev-start cur-start)
8004 (beginning-of-line 2))))))
8006 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
8007 "Align inline comments within a region. Groups of code lines separated by
8008 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8009 (interactive "r\nP")
8010 (save-excursion
8011 (let (orig pos)
8012 (goto-char beg)
8013 (beginning-of-line)
8014 (setq orig (point-marker))
8015 (setq beg (point))
8016 (goto-char end)
8017 (setq end (point-marker))
8018 (untabify beg end)
8019 (unless no-message (message "Aligning inline comments..."))
8020 (goto-char beg)
8021 (if (not vhdl-align-groups)
8022 ;; align entire region
8023 (vhdl-align-inline-comment-region-1 beg end spacing)
8024 ;; align groups
8025 (while (and (< beg end)
8026 (re-search-forward vhdl-align-group-separate end t))
8027 (setq pos (point-marker))
8028 (vhdl-align-inline-comment-region-1 beg pos spacing)
8029 (setq beg (1+ pos))
8030 (goto-char beg))
8031 ;; align last group
8032 (when (< beg end)
8033 (vhdl-align-inline-comment-region-1 beg end spacing)))
8034 (when vhdl-indent-tabs-mode
8035 (tabify orig end))
8036 (unless no-message (message "Aligning inline comments...done")))))
8038 (defun vhdl-align-inline-comment-group (&optional spacing)
8039 "Align inline comments within a group of lines between empty lines."
8040 (interactive)
8041 (save-excursion
8042 (let ((start (point))
8043 beg end)
8044 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
8045 (point-marker) (point-max)))
8046 (goto-char start)
8047 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
8048 (point) (point-min)))
8049 (untabify beg end)
8050 (message "Aligning inline comments...")
8051 (vhdl-align-inline-comment-region-1 beg end)
8052 (when vhdl-indent-tabs-mode
8053 (tabify beg end))
8054 (message "Aligning inline comments...done"))))
8056 (defun vhdl-align-inline-comment-buffer ()
8057 "Align inline comments within buffer. Groups of code lines separated by
8058 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8059 (interactive)
8060 (vhdl-align-inline-comment-region (point-min) (point-max)))
8062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8063 ;; Fixup whitespace
8065 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
8066 "Fixup whitespace in region. Surround operator symbols by one space,
8067 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8068 end of line, do nothing in comments and strings."
8069 (interactive "r")
8070 (unless no-message (message "Fixing up whitespace..."))
8071 (save-excursion
8072 (goto-char end)
8073 (setq end (point-marker))
8074 ;; have no space before and one space after `,' and ';'
8075 (goto-char beg)
8076 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
8077 (if (match-string 1)
8078 (goto-char (match-end 1))
8079 (replace-match "\\3 " nil nil nil 2)))
8080 ;; have no space after `('
8081 (goto-char beg)
8082 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
8083 (if (match-string 1)
8084 (goto-char (match-end 1))
8085 (replace-match "\\2")))
8086 ;; have no space before `)'
8087 (goto-char beg)
8088 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
8089 (if (match-string 1)
8090 (goto-char (match-end 1))
8091 (replace-match "\\2")))
8092 ;; surround operator symbols by one space
8093 (goto-char beg)
8094 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
8095 (if (or (match-string 1)
8096 (<= (match-beginning 0) ; not if at boi
8097 (save-excursion (back-to-indentation) (point))))
8098 (goto-char (match-end 0))
8099 (replace-match "\\3 \\4 \\5")
8100 (goto-char (match-end 2))))
8101 ;; eliminate multiple spaces and spaces at end of line
8102 (goto-char beg)
8103 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
8104 (and (looking-at "--.*") (re-search-forward "--.*" end t))
8105 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
8106 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
8107 (progn (replace-match "" nil nil) t))
8108 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
8109 (progn (replace-match ";" nil nil) t))
8110 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
8111 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
8112 (progn (replace-match " " nil nil) t))
8113 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
8114 (progn (replace-match " " nil nil) t))
8115 (and (looking-at "-") (re-search-forward "-" end t))
8116 (re-search-forward "[^ \t\"-]+" end t))))
8117 (unless no-message (message "Fixing up whitespace...done")))
8119 (defun vhdl-fixup-whitespace-buffer ()
8120 "Fixup whitespace in buffer. Surround operator symbols by one space,
8121 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8122 end of line, do nothing in comments."
8123 (interactive)
8124 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8127 ;; Case fixing
8129 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8130 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8131 depending on parameter UPPER-CASE."
8132 (let ((case-replace nil)
8133 (last-update 0))
8134 (vhdl-prepare-search-2
8135 (save-excursion
8136 (goto-char end)
8137 (setq end (point-marker))
8138 (goto-char beg)
8139 (while (re-search-forward word-regexp end t)
8140 (or (vhdl-in-literal)
8141 (if upper-case
8142 (upcase-word -1)
8143 (downcase-word -1)))
8144 (when (and count vhdl-progress-interval (not noninteractive)
8145 (< vhdl-progress-interval
8146 (- (nth 1 (current-time)) last-update)))
8147 (message "Fixing case... (%2d%s)"
8148 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8149 "%")
8150 (setq last-update (nth 1 (current-time)))))
8151 (goto-char end)))))
8153 (defun vhdl-fix-case-region (beg end &optional arg)
8154 "Convert all VHDL words in region to lower or upper case, depending on
8155 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8156 (interactive "r\nP")
8157 (vhdl-fix-case-region-1
8158 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8159 (vhdl-fix-case-region-1
8160 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8161 (vhdl-fix-case-region-1
8162 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8163 (vhdl-fix-case-region-1
8164 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8165 (vhdl-fix-case-region-1
8166 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8167 (when vhdl-progress-interval (message "Fixing case...done")))
8169 (defun vhdl-fix-case-buffer ()
8170 "Convert all VHDL words in buffer to lower or upper case, depending on
8171 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8172 (interactive)
8173 (vhdl-fix-case-region (point-min) (point-max)))
8175 (defun vhdl-fix-case-word (&optional arg)
8176 "Convert word after cursor to upper case if necessary."
8177 (interactive "p")
8178 (save-excursion
8179 (when arg (backward-word 1))
8180 (vhdl-prepare-search-1
8181 (when (and vhdl-upper-case-keywords
8182 (looking-at vhdl-keywords-regexp))
8183 (upcase-word 1))
8184 (when (and vhdl-upper-case-types
8185 (looking-at vhdl-types-regexp))
8186 (upcase-word 1))
8187 (when (and vhdl-upper-case-attributes
8188 (looking-at vhdl-attributes-regexp))
8189 (upcase-word 1))
8190 (when (and vhdl-upper-case-enum-values
8191 (looking-at vhdl-enum-values-regexp))
8192 (upcase-word 1))
8193 (when (and vhdl-upper-case-constants
8194 (looking-at vhdl-constants-regexp))
8195 (upcase-word 1)))))
8197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8198 ;; Fix statements
8199 ;; - force each statement to be on a separate line except when on same line
8200 ;; with 'end' keyword
8202 (defun vhdl-fix-statement-region (beg end &optional arg)
8203 "Force statements in region on separate line except when on same line
8204 with `end' keyword (necessary for correct indentation).
8205 Currently supported keywords: `begin', `if'."
8206 (interactive "r\nP")
8207 (vhdl-prepare-search-2
8208 (let (point)
8209 (save-excursion
8210 (goto-char end)
8211 (setq end (point-marker))
8212 (goto-char beg)
8213 ;; `begin' keyword
8214 (while (re-search-forward
8215 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8216 (goto-char (match-end 0))
8217 (setq point (point-marker))
8218 (when (and (match-string 1)
8219 (or (not (match-string 2))
8220 (save-excursion (goto-char (match-end 2))
8221 (vhdl-in-literal)))
8222 (not (save-excursion (goto-char (match-beginning 1))
8223 (vhdl-in-literal))))
8224 (goto-char (match-beginning 1))
8225 (insert "\n")
8226 (indent-according-to-mode))
8227 (goto-char point))
8228 (goto-char beg)
8229 ;; `for', `if' keywords
8230 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8231 (goto-char (match-end 1))
8232 (setq point (point-marker))
8233 ;; exception: in literal or preceded by `end', `wait' or label
8234 (when (and (not (save-excursion (goto-char (match-beginning 1))
8235 (vhdl-in-literal)))
8236 (save-excursion
8237 (beginning-of-line 1)
8238 (save-match-data
8239 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8240 (match-beginning 1) t)
8241 (not (string-match
8242 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8243 (match-string 1)))))))
8244 (goto-char (match-beginning 1))
8245 (insert "\n")
8246 (indent-according-to-mode))
8247 (goto-char point))))))
8249 (defun vhdl-fix-statement-buffer ()
8250 "Force statements in buffer on separate line except when on same line
8251 with `end' keyword (necessary for correct indentation)."
8252 (interactive)
8253 (vhdl-fix-statement-region (point-min) (point-max)))
8255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8256 ;; Trailing spaces
8258 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8259 "Remove trailing spaces in region."
8260 (interactive "r\nP")
8261 (save-excursion
8262 (goto-char end)
8263 (setq end (point-marker))
8264 (goto-char beg)
8265 (while (re-search-forward "[ \t]+$" end t)
8266 (unless (vhdl-in-literal)
8267 (replace-match "" nil nil)))))
8269 (defun vhdl-remove-trailing-spaces ()
8270 "Remove trailing spaces in buffer."
8271 (interactive)
8272 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8275 ;; Beautify
8277 (defun vhdl-beautify-region (beg end)
8278 "Beautify region by applying indentation, whitespace fixup, alignment, and
8279 case fixing to a region. Calls functions `vhdl-indent-buffer',
8280 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8281 `vhdl-fix-case-buffer'."
8282 (interactive "r")
8283 (setq end (save-excursion (goto-char end) (point-marker)))
8284 (save-excursion ; remove DOS EOL characters in UNIX file
8285 (goto-char beg)
8286 (while (search-forward "\r" nil t)
8287 (replace-match "" nil t)))
8288 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8289 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8290 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8291 (when (nth 3 vhdl-beautify-options)
8292 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8293 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8294 (when (nth 0 vhdl-beautify-options)
8295 (vhdl-remove-trailing-spaces-region beg end)
8296 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8298 (defun vhdl-beautify-buffer ()
8299 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8300 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8301 buffer."
8302 (interactive)
8303 (vhdl-beautify-region (point-min) (point-max))
8304 (when noninteractive (save-buffer)))
8306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8307 ;; Code filling
8309 (defun vhdl-fill-region (beg end &optional arg)
8310 "Fill lines for a region of code."
8311 (interactive "r\np")
8312 (save-excursion
8313 (goto-char beg)
8314 (let ((margin (if arg (current-indentation) (current-column))))
8315 (goto-char end)
8316 (setq end (point-marker))
8317 ;; remove inline comments, newlines and whitespace
8318 (vhdl-comment-kill-region beg end)
8319 (vhdl-comment-kill-inline-region beg end)
8320 (subst-char-in-region beg (1- end) ?\n ?\ )
8321 (vhdl-fixup-whitespace-region beg end)
8322 ;; wrap and end-comment-column
8323 (goto-char beg)
8324 (while (re-search-forward "\\s-" end t)
8325 (when(> (current-column) vhdl-end-comment-column)
8326 (backward-char)
8327 (when (re-search-backward "\\s-" beg t)
8328 (replace-match "\n")
8329 (indent-to margin)))))))
8331 (defun vhdl-fill-group ()
8332 "Fill group of lines between empty lines."
8333 (interactive)
8334 (vhdl-do-group 'vhdl-fill-region))
8336 (defun vhdl-fill-list ()
8337 "Fill the lines of a list surrounded by a balanced group of parentheses."
8338 (interactive)
8339 (vhdl-do-list 'vhdl-fill-region))
8341 (defun vhdl-fill-same-indent ()
8342 "Fill the lines of block of lines with same indent."
8343 (interactive)
8344 (vhdl-do-same-indent 'vhdl-fill-region))
8347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8348 ;;; Code updating/fixing
8349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8352 ;; Sensitivity list update
8354 ;; Strategy:
8355 ;; - no sensitivity list is generated for processes with wait statements
8356 ;; - otherwise, do the following:
8357 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8358 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8359 ;; manually entered global signals)
8360 ;; 3. signals from 1. and 2. form the list of visible signals
8361 ;; 4. search for if/elsif conditions containing an event (sequential code)
8362 ;; 5. scan for strings that are within syntactical regions where signals are
8363 ;; read but not within sequential code, and that correspond to visible
8364 ;; signals
8365 ;; 6. replace sensitivity list by list of signals from 5.
8367 (defun vhdl-update-sensitivity-list-process ()
8368 "Update sensitivity list of current process."
8369 (interactive)
8370 (save-excursion
8371 (vhdl-prepare-search-2
8372 (end-of-line)
8373 ;; look whether in process
8374 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8375 (equal (upcase (match-string 2)) "PROCESS")
8376 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8377 (error "ERROR: Not within a process")
8378 (message "Updating sensitivity list...")
8379 (vhdl-update-sensitivity-list)
8380 (message "Updating sensitivity list...done")))))
8382 (defun vhdl-update-sensitivity-list-buffer ()
8383 "Update sensitivity list of all processes in current buffer."
8384 (interactive)
8385 (save-excursion
8386 (vhdl-prepare-search-2
8387 (goto-char (point-min))
8388 (message "Updating sensitivity lists...")
8389 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8390 (goto-char (match-beginning 0))
8391 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8392 (message "Updating sensitivity lists...done")))
8393 (when noninteractive (save-buffer)))
8395 (defun vhdl-update-sensitivity-list ()
8396 "Update sensitivity list."
8397 (let ((proc-beg (point))
8398 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8399 (proc-mid (vhdl-re-search-backward
8400 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8401 seq-region-list)
8402 (cond
8403 ;; error if 'begin' keyword missing
8404 ((not (match-string 2))
8405 (error "ERROR: No 'begin' keyword found"))
8406 ;; search for wait statement (no sensitivity list allowed)
8407 ((progn (goto-char proc-mid)
8408 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8409 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8410 ;; combinational process (update sensitivity list)
8412 (let
8413 ;; scan for visible signals
8414 ((visible-list (vhdl-get-visible-signals))
8415 ;; define syntactic regions where signals are read
8416 (scan-regions-list
8417 '(;; right-hand side of signal/variable assignment
8418 ;; (special case: "<=" is relational operator in a condition)
8419 ((vhdl-re-search-forward "[<:]=" proc-end t)
8420 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8421 ;; if condition
8422 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8423 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8424 ;; elsif condition
8425 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8426 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8427 ;; while loop condition
8428 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8429 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8430 ;; exit/next condition
8431 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8432 (vhdl-re-search-forward ";" proc-end t))
8433 ;; assert condition
8434 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8435 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8436 ;; case expression
8437 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8438 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8439 ;; parameter list of procedure call, array index
8440 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8441 (1- (point)))
8442 (progn (backward-char) (forward-sexp)
8443 (while (looking-at "(") (forward-sexp)) (point)))))
8444 name field read-list sens-list signal-list tmp-list
8445 sens-beg sens-end beg end margin)
8446 ;; scan for signals in old sensitivity list
8447 (goto-char proc-beg)
8448 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8449 (if (not (looking-at "[ \t\n\r\f]*("))
8450 (setq sens-beg (point))
8451 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8452 (goto-char (match-end 1))
8453 (forward-sexp)
8454 (setq sens-end (1- (point)))
8455 (goto-char sens-beg)
8456 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8457 (setq sens-list
8458 (cons (downcase (match-string 0)) sens-list))
8459 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8460 (setq signal-list (append visible-list sens-list))
8461 ;; search for sequential parts
8462 (goto-char proc-mid)
8463 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8464 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8465 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8466 (goto-char end)
8467 (backward-word-strictly 1)
8468 (vhdl-forward-sexp)
8469 (push (cons end (point)) seq-region-list)
8470 (beginning-of-line)))
8471 ;; scan for signals read in process
8472 (while scan-regions-list
8473 (goto-char proc-mid)
8474 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8475 (setq end (eval (nth 1 (car scan-regions-list)))))
8476 (goto-char beg)
8477 (unless (or (vhdl-in-literal)
8478 (and seq-region-list
8479 (let ((tmp-list seq-region-list))
8480 (while (and tmp-list
8481 (< (point) (caar tmp-list)))
8482 (setq tmp-list (cdr tmp-list)))
8483 (and tmp-list (< (point) (cdar tmp-list))))))
8484 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8485 (setq name (match-string 1))
8486 ;; get array index range
8487 (when vhdl-array-index-record-field-in-sensitivity-list
8488 (setq field (match-string 2))
8489 ;; not use if it includes a variable name
8490 (save-match-data
8491 (setq tmp-list visible-list)
8492 (while (and field tmp-list)
8493 (when (string-match
8494 (concat "\\<" (car tmp-list) "\\>") field)
8495 (setq field nil))
8496 (setq tmp-list (cdr tmp-list)))))
8497 (when (and (not (match-string 6)) ; not when formal parameter
8498 (not (and (match-string 5) ; not event attribute
8499 (not (member (downcase (match-string 5))
8500 '("event" "last_event" "transaction")))))
8501 (member (downcase name) signal-list))
8502 ;; not add if name or name+field already exists
8503 (unless
8504 (or (member-ignore-case name read-list)
8505 (member-ignore-case (concat name field) read-list))
8506 (push (concat name field) read-list))
8507 (setq tmp-list read-list)
8508 ;; remove existing name+field if name is added
8509 (save-match-data
8510 (while tmp-list
8511 (when (string-match (concat "^" name field "[(.]")
8512 (car tmp-list))
8513 (setq read-list (delete (car tmp-list) read-list)))
8514 (setq tmp-list (cdr tmp-list)))))
8515 (goto-char (match-end 1)))))
8516 (setq scan-regions-list (cdr scan-regions-list)))
8517 ;; update sensitivity list
8518 (goto-char sens-beg)
8519 (if sens-end
8520 (delete-region sens-beg sens-end)
8521 (when read-list
8522 (insert " ()") (backward-char)))
8523 (setq read-list (sort read-list 'string<))
8524 (when read-list
8525 (setq margin (current-column))
8526 (insert (car read-list))
8527 (setq read-list (cdr read-list))
8528 (while read-list
8529 (insert ",")
8530 (if (<= (+ (current-column) (length (car read-list)) 2)
8531 end-comment-column)
8532 (insert " ")
8533 (insert "\n") (indent-to margin))
8534 (insert (car read-list))
8535 (setq read-list (cdr read-list)))))))))
8537 (defun vhdl-get-visible-signals ()
8538 "Get all signals visible in the current block."
8539 (let (beg end signal-list entity-name file-name)
8540 (vhdl-prepare-search-2
8541 ;; get entity name
8542 (save-excursion
8543 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8544 (not (equal "END" (upcase (match-string 1))))
8545 (setq entity-name (match-string 2)))
8546 (error "ERROR: Not within an architecture")))
8547 ;; search for signals declared in entity port clause
8548 (save-excursion
8549 (goto-char (point-min))
8550 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8551 (setq file-name
8552 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8553 "." (file-name-extension (buffer-file-name)))))
8554 (vhdl-visit-file
8555 file-name t
8556 (vhdl-prepare-search-2
8557 (goto-char (point-min))
8558 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8559 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8560 (when (setq beg (vhdl-re-search-forward
8561 "\\<port[ \t\n\r\f]*("
8562 (save-excursion
8563 (re-search-forward "^end\\>" nil t)) t))
8564 (setq end (save-excursion
8565 (backward-char) (forward-sexp) (point)))
8566 (vhdl-forward-syntactic-ws)
8567 (while (< (point) end)
8568 (when (looking-at "signal[ \t\n\r\f]+")
8569 (goto-char (match-end 0)))
8570 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8571 (setq signal-list
8572 (cons (downcase (match-string 1)) signal-list))
8573 (goto-char (match-end 0))
8574 (vhdl-forward-syntactic-ws))
8575 (re-search-forward ";" end 1)
8576 (vhdl-forward-syntactic-ws)))))))
8577 ;; search for signals declared in architecture declarative part
8578 (save-excursion
8579 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8580 (not (equal "END" (upcase (match-string 1))))
8581 (setq end (re-search-forward "^begin\\>" nil t))))
8582 (error "ERROR: No architecture declarative part found")
8583 ;; scan for all declared signal and alias names
8584 (goto-char beg)
8585 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8586 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8587 (if (match-string 2)
8588 ;; scan signal name
8589 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8590 (setq signal-list
8591 (cons (downcase (match-string 1)) signal-list))
8592 (goto-char (match-end 0)))
8593 ;; scan alias name, check is alias of (declared) signal
8594 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8595 (member (downcase (match-string 2)) signal-list))
8596 (setq signal-list
8597 (cons (downcase (match-string 1)) signal-list))
8598 (goto-char (match-end 0))))
8599 (setq beg (point))))))
8600 ;; search for signals declared in surrounding block declarative parts
8601 (save-excursion
8602 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8603 (match-string 4))
8604 (goto-char (match-end 4))
8605 (vhdl-backward-sexp)
8606 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8607 beg)
8608 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8609 ;; scan for all declared signal names
8610 (goto-char beg)
8611 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8612 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8613 (if (match-string 2)
8614 ;; scan signal name
8615 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8616 (setq signal-list
8617 (cons (downcase (match-string 1)) signal-list))
8618 (goto-char (match-end 0)))
8619 ;; scan alias name, check is alias of (declared) signal
8620 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8621 (member (downcase (match-string 2)) signal-list))
8622 (setq signal-list
8623 (cons (downcase (match-string 1)) signal-list))
8624 (goto-char (match-end 0))))))
8625 (goto-char beg)))
8626 signal-list)))
8628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8629 ;; Generic/port clause fixing
8631 (defun vhdl-fix-clause-buffer ()
8632 "Fix all generic/port clauses in current buffer."
8633 (interactive)
8634 (save-excursion
8635 (vhdl-prepare-search-2
8636 (goto-char (point-min))
8637 (message "Fixing generic/port clauses...")
8638 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8639 (goto-char (match-end 0))
8640 (condition-case nil (vhdl-fix-clause) (error "")))
8641 (message "Fixing generic/port clauses...done"))))
8643 (defun vhdl-fix-clause ()
8644 "Fix closing parenthesis within generic/port clause."
8645 (interactive)
8646 (save-excursion
8647 (vhdl-prepare-search-2
8648 (let ((pos (point))
8649 beg end)
8650 (end-of-line)
8651 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8652 (error "ERROR: Not within a generic/port clause")
8653 ;; search for end of clause
8654 (goto-char (match-end 0))
8655 (setq beg (1- (point)))
8656 (vhdl-forward-syntactic-ws)
8657 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8658 (goto-char (1- (match-end 0)))
8659 (setq end (point-marker))
8660 (forward-char)
8661 (vhdl-forward-syntactic-ws))
8662 (goto-char end)
8663 (when (> pos (point-at-eol))
8664 (error "ERROR: Not within a generic/port clause"))
8665 ;; delete closing parenthesis on separate line (not supported style)
8666 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8667 (vhdl-line-kill)
8668 (vhdl-backward-syntactic-ws)
8669 (setq end (point-marker))
8670 (insert ";"))
8671 ;; delete superfluous parentheses
8672 (while (progn (goto-char beg)
8673 (condition-case () (forward-sexp)
8674 (error (goto-char (point-max))))
8675 (< (point) end))
8676 (delete-char -1))
8677 ;; add closing parenthesis
8678 (when (> (point) end)
8679 (goto-char end)
8680 (insert ")")))))))
8683 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8684 ;;; Electrification
8685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8687 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8688 "Syntax of prompt inserted by template generators.")
8690 (defvar vhdl-template-invoked-by-hook nil
8691 "Indicates whether a template has been invoked by a hook or by key or menu.
8692 Used for undoing after template abortion.")
8694 ;; correct different behavior of function `unread-command-events' in XEmacs
8695 (defun vhdl-character-to-event (arg))
8696 (defalias 'vhdl-character-to-event
8697 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8699 (defun vhdl-work-library ()
8700 "Return the working library name of the current project or \"work\" if no
8701 project is defined."
8702 (vhdl-resolve-env-variable
8703 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8704 vhdl-default-library)))
8706 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8707 ;; Enabling/disabling
8709 (define-minor-mode vhdl-electric-mode
8710 "Toggle VHDL electric mode.
8711 With a prefix argument ARG, enable the mode if ARG is positive,
8712 and disable it otherwise. If called from Lisp, enable it if ARG
8713 is omitted or nil."
8714 :global t :group 'vhdl-mode)
8716 (define-minor-mode vhdl-stutter-mode
8717 "Toggle VHDL stuttering mode.
8718 With a prefix argument ARG, enable the mode if ARG is positive,
8719 and disable it otherwise. If called from Lisp, enable it if ARG
8720 is omitted or nil."
8721 :global t :group 'vhdl-mode)
8723 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8724 ;; Stuttering
8726 (defun vhdl-electric-dash (count)
8727 "-- starts a comment, --- draws a horizontal line,
8728 ---- starts a display comment."
8729 (interactive "p")
8730 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8731 (cond
8732 ((and abbrev-start-location (= abbrev-start-location (point)))
8733 (setq abbrev-start-location nil)
8734 (goto-char last-abbrev-location)
8735 (beginning-of-line nil)
8736 (vhdl-comment-display))
8737 ((/= (preceding-char) ?-) ; standard dash (minus)
8738 (self-insert-command count))
8739 (t (self-insert-command count)
8740 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8741 (let ((next-input (read-char)))
8742 (if (= next-input ?-) ; triple dash
8743 (progn
8744 (vhdl-comment-display-line)
8745 (message
8746 "Enter '-' for display comment, else continue coding")
8747 (let ((next-input (read-char)))
8748 (if (= next-input ?-) ; four dashes
8749 (vhdl-comment-display t)
8750 (push (vhdl-character-to-event next-input)
8751 ; pushback the char
8752 unread-command-events))))
8753 (push (vhdl-character-to-event next-input) ; pushback the char
8754 unread-command-events)
8755 (vhdl-comment-insert)))))
8756 (self-insert-command count)))
8758 (defun vhdl-electric-open-bracket (count) "`[' --> `(', `([' --> `['"
8759 (interactive "p")
8760 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8761 (if (= (preceding-char) ?\()
8762 (progn (delete-char -1) (insert-char ?\[ 1))
8763 (insert-char ?\( 1))
8764 (self-insert-command count)))
8766 (defun vhdl-electric-close-bracket (count) "`]' --> `)', `)]' --> `]'"
8767 (interactive "p")
8768 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8769 (progn
8770 (if (= (preceding-char) ?\))
8771 (progn (delete-char -1) (insert-char ?\] 1))
8772 (insert-char ?\) 1))
8773 (blink-matching-open))
8774 (self-insert-command count)))
8776 (defun vhdl-electric-quote (count) "\\='\\=' --> \""
8777 (interactive "p")
8778 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8779 (if (= (preceding-char) vhdl-last-input-event)
8780 (progn (delete-char -1) (insert-char ?\" 1))
8781 (insert-char ?\' 1))
8782 (self-insert-command count)))
8784 (defun vhdl-electric-semicolon (count) "`;;' --> ` : ', `: ;' --> ` := '"
8785 (interactive "p")
8786 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8787 (cond ((= (preceding-char) vhdl-last-input-event)
8788 (progn (delete-char -1)
8789 (unless (eq (preceding-char) ? ) (insert " "))
8790 (insert ": ")
8791 (setq this-command 'vhdl-electric-colon)))
8792 ((and
8793 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8794 (progn (delete-char -1) (insert "= ")))
8795 (t (insert-char ?\; 1)))
8796 (self-insert-command count)))
8798 (defun vhdl-electric-comma (count) "`,,' --> ` <= '"
8799 (interactive "p")
8800 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8801 (cond ((= (preceding-char) vhdl-last-input-event)
8802 (progn (delete-char -1)
8803 (unless (eq (preceding-char) ? ) (insert " "))
8804 (insert "<= ")))
8805 (t (insert-char ?\, 1)))
8806 (self-insert-command count)))
8808 (defun vhdl-electric-period (count) "`..' --> ` => '"
8809 (interactive "p")
8810 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8811 (cond ((= (preceding-char) vhdl-last-input-event)
8812 (progn (delete-char -1)
8813 (unless (eq (preceding-char) ? ) (insert " "))
8814 (insert "=> ")))
8815 (t (insert-char ?\. 1)))
8816 (self-insert-command count)))
8818 (defun vhdl-electric-equal (count) "`==' --> ` == '"
8819 (interactive "p")
8820 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8821 (cond ((= (preceding-char) vhdl-last-input-event)
8822 (progn (delete-char -1)
8823 (unless (eq (preceding-char) ? ) (insert " "))
8824 (insert "== ")))
8825 (t (insert-char ?\= 1)))
8826 (self-insert-command count)))
8828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8829 ;; VHDL templates
8831 (defun vhdl-template-paired-parens ()
8832 "Insert a pair of round parentheses, placing point between them."
8833 (interactive)
8834 (insert "()")
8835 (backward-char))
8837 (defun vhdl-template-alias ()
8838 "Insert alias declaration."
8839 (interactive)
8840 (let ((start (point)))
8841 (vhdl-insert-keyword "ALIAS ")
8842 (when (vhdl-template-field "name" nil t start (point))
8843 (insert " : ")
8844 (unless (vhdl-template-field
8845 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8846 nil t)
8847 (delete-char -3))
8848 (vhdl-insert-keyword " IS ")
8849 (vhdl-template-field "name" ";")
8850 (vhdl-comment-insert-inline))))
8852 (defun vhdl-template-architecture ()
8853 "Insert architecture."
8854 (interactive)
8855 (let ((margin (current-indentation))
8856 (start (point))
8857 arch-name)
8858 (vhdl-insert-keyword "ARCHITECTURE ")
8859 (when (setq arch-name
8860 (vhdl-template-field "name" nil t start (point)))
8861 (vhdl-insert-keyword " OF ")
8862 (if (save-excursion
8863 (vhdl-prepare-search-1
8864 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8865 (insert (match-string 1))
8866 (vhdl-template-field "entity name"))
8867 (vhdl-insert-keyword " IS\n")
8868 (vhdl-template-begin-end
8869 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8870 (memq vhdl-insert-empty-lines '(unit all))))))
8872 (defun vhdl-template-array (kind &optional secondary)
8873 "Insert array type definition."
8874 (interactive)
8875 (let ((start (point)))
8876 (vhdl-insert-keyword "ARRAY (")
8877 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8878 secondary)
8879 (vhdl-insert-keyword ") OF ")
8880 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8881 (vhdl-insert-keyword ";"))))
8883 (defun vhdl-template-assert ()
8884 "Insert an assertion statement."
8885 (interactive)
8886 (let ((start (point)))
8887 (vhdl-insert-keyword "ASSERT ")
8888 (when vhdl-conditions-in-parenthesis (insert "("))
8889 (when (vhdl-template-field "condition (negated)" nil t start (point))
8890 (when vhdl-conditions-in-parenthesis (insert ")"))
8891 (setq start (point))
8892 (vhdl-insert-keyword " REPORT ")
8893 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8894 (delete-region start (point)))
8895 (setq start (point))
8896 (vhdl-insert-keyword " SEVERITY ")
8897 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8898 (delete-region start (point)))
8899 (insert ";"))))
8901 (defun vhdl-template-attribute ()
8902 "Insert an attribute declaration or specification."
8903 (interactive)
8904 (if (eq (vhdl-decision-query
8905 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8906 (vhdl-template-attribute-spec)
8907 (vhdl-template-attribute-decl)))
8909 (defun vhdl-template-attribute-decl ()
8910 "Insert an attribute declaration."
8911 (interactive)
8912 (let ((start (point)))
8913 (vhdl-insert-keyword "ATTRIBUTE ")
8914 (when (vhdl-template-field "name" " : " t start (point))
8915 (vhdl-template-field "type" ";")
8916 (vhdl-comment-insert-inline))))
8918 (defun vhdl-template-attribute-spec ()
8919 "Insert an attribute specification."
8920 (interactive)
8921 (let ((start (point)))
8922 (vhdl-insert-keyword "ATTRIBUTE ")
8923 (when (vhdl-template-field "name" nil t start (point))
8924 (vhdl-insert-keyword " OF ")
8925 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8926 (vhdl-template-field "entity class")
8927 (vhdl-insert-keyword " IS ")
8928 (vhdl-template-field "expression" ";"))))
8930 (defun vhdl-template-block ()
8931 "Insert a block."
8932 (interactive)
8933 (let ((margin (current-indentation))
8934 (start (point))
8935 label)
8936 (vhdl-insert-keyword ": BLOCK ")
8937 (goto-char start)
8938 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8939 (forward-word-strictly 1)
8940 (forward-char 1)
8941 (insert "(")
8942 (if (vhdl-template-field "[guard expression]" nil t)
8943 (insert ")")
8944 (delete-char -2))
8945 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8946 (insert "\n")
8947 (vhdl-template-begin-end "BLOCK" label margin)
8948 (vhdl-comment-block))))
8950 (defun vhdl-template-block-configuration ()
8951 "Insert a block configuration statement."
8952 (interactive)
8953 (let ((margin (current-indentation))
8954 (start (point)))
8955 (vhdl-insert-keyword "FOR ")
8956 (when (vhdl-template-field "block name" nil t start (point))
8957 (vhdl-insert-keyword "\n\n")
8958 (indent-to margin)
8959 (vhdl-insert-keyword "END FOR;")
8960 (end-of-line 0)
8961 (indent-to (+ margin vhdl-basic-offset)))))
8963 (defun vhdl-template-break ()
8964 "Insert a break statement."
8965 (interactive)
8966 (let (position)
8967 (vhdl-insert-keyword "BREAK")
8968 (setq position (point))
8969 (insert " ")
8970 (while (or
8971 (progn (vhdl-insert-keyword "FOR ")
8972 (if (vhdl-template-field "[quantity name]" " USE " t)
8973 (progn (vhdl-template-field "quantity name" " => ") t)
8974 (delete-region (point)
8975 (progn (forward-word-strictly -1) (point)))
8976 nil))
8977 (vhdl-template-field "[quantity name]" " => " t))
8978 (vhdl-template-field "expression")
8979 (setq position (point))
8980 (insert ", "))
8981 (delete-region position (point))
8982 (unless (vhdl-sequential-statement-p)
8983 (vhdl-insert-keyword " ON ")
8984 (if (vhdl-template-field "[sensitivity list]" nil t)
8985 (setq position (point))
8986 (delete-region position (point))))
8987 (vhdl-insert-keyword " WHEN ")
8988 (when vhdl-conditions-in-parenthesis (insert "("))
8989 (if (vhdl-template-field "[condition]" nil t)
8990 (when vhdl-conditions-in-parenthesis (insert ")"))
8991 (delete-region position (point)))
8992 (insert ";")))
8994 (defun vhdl-template-case (&optional kind)
8995 "Insert a case statement."
8996 (interactive)
8997 (let ((margin (current-indentation))
8998 (start (point))
8999 label)
9000 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
9001 (not (vhdl-standard-p 'ams))) 'is 'use)))
9002 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9003 (vhdl-insert-keyword "CASE ")
9004 (vhdl-insert-keyword ": CASE ")
9005 (goto-char start)
9006 (setq label (vhdl-template-field "[label]" nil t))
9007 (unless label (delete-char 2))
9008 (forward-word-strictly 1)
9009 (forward-char 1))
9010 (when (vhdl-template-field "expression" nil t start (point))
9011 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
9012 (indent-to margin)
9013 (vhdl-insert-keyword "END CASE")
9014 (when label (insert " " label))
9015 (insert ";")
9016 (forward-line -1)
9017 (indent-to (+ margin vhdl-basic-offset))
9018 (vhdl-insert-keyword "WHEN ")
9019 (let ((position (point)))
9020 (insert " => ;\n")
9021 (indent-to (+ margin vhdl-basic-offset))
9022 (vhdl-insert-keyword "WHEN OTHERS => null;")
9023 (goto-char position)))))
9025 (defun vhdl-template-case-is ()
9026 "Insert a sequential case statement."
9027 (interactive)
9028 (vhdl-template-case 'is))
9030 (defun vhdl-template-case-use ()
9031 "Insert a simultaneous case statement."
9032 (interactive)
9033 (vhdl-template-case 'use))
9035 (defun vhdl-template-component ()
9036 "Insert a component declaration."
9037 (interactive)
9038 (vhdl-template-component-decl))
9040 (defun vhdl-template-component-conf ()
9041 "Insert a component configuration (uses `vhdl-template-configuration-spec'
9042 since these are almost equivalent)."
9043 (interactive)
9044 (let ((margin (current-indentation))
9045 (result (vhdl-template-configuration-spec t)))
9046 (when result
9047 (insert "\n")
9048 (indent-to margin)
9049 (vhdl-insert-keyword "END FOR;")
9050 (when (eq result 'no-use)
9051 (end-of-line -0)))))
9053 (defun vhdl-template-component-decl ()
9054 "Insert a component declaration."
9055 (interactive)
9056 (let ((margin (current-indentation))
9057 (start (point))
9058 name end-column)
9059 (vhdl-insert-keyword "COMPONENT ")
9060 (when (setq name (vhdl-template-field "name" nil t start (point)))
9061 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9062 (insert "\n\n")
9063 (indent-to margin)
9064 (vhdl-insert-keyword "END COMPONENT")
9065 (unless (vhdl-standard-p '87) (insert " " name))
9066 (insert ";")
9067 (setq end-column (current-column))
9068 (end-of-line -0)
9069 (indent-to (+ margin vhdl-basic-offset))
9070 (vhdl-template-generic-list t t)
9071 (insert "\n")
9072 (indent-to (+ margin vhdl-basic-offset))
9073 (vhdl-template-port-list t)
9074 (beginning-of-line 2)
9075 (forward-char end-column))))
9077 (defun vhdl-template-component-inst ()
9078 "Insert a component instantiation statement."
9079 (interactive)
9080 (let ((margin (current-indentation))
9081 (start (point))
9082 unit position)
9083 (when (vhdl-template-field "instance label" nil t start (point))
9084 (insert ": ")
9085 (if (not (vhdl-use-direct-instantiation))
9086 (vhdl-template-field "component name")
9087 ;; direct instantiation
9088 (setq unit (vhdl-template-field
9089 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
9090 (setq unit (upcase (or unit "")))
9091 (cond ((equal unit "ENTITY")
9092 (let ((begin (point)))
9093 (vhdl-template-field "library name" "." t begin (point) nil
9094 (vhdl-work-library))
9095 (vhdl-template-field "entity name" "(")
9096 (if (vhdl-template-field "[architecture name]" nil t)
9097 (insert ")")
9098 (delete-char -1))))
9099 ((equal unit "CONFIGURATION")
9100 (vhdl-template-field "library name" "." nil nil nil nil
9101 (vhdl-work-library))
9102 (vhdl-template-field "configuration name"))
9103 (t (vhdl-template-field "component name"))))
9104 (insert "\n")
9105 (indent-to (+ margin vhdl-basic-offset))
9106 (setq position (point))
9107 (vhdl-insert-keyword "GENERIC ")
9108 (when (vhdl-template-map position t t)
9109 (insert "\n")
9110 (indent-to (+ margin vhdl-basic-offset)))
9111 (setq position (point))
9112 (vhdl-insert-keyword "PORT ")
9113 (unless (vhdl-template-map position t t)
9114 (delete-region (line-beginning-position) (point))
9115 (delete-char -1))
9116 (insert ";"))))
9118 (defun vhdl-template-conditional-signal-asst ()
9119 "Insert a conditional signal assignment."
9120 (interactive)
9121 (when (vhdl-template-field "target signal")
9122 (insert " <= ")
9123 (let ((margin (current-column))
9124 (start (point))
9125 position)
9126 (vhdl-template-field "waveform")
9127 (setq position (point))
9128 (vhdl-insert-keyword " WHEN ")
9129 (when vhdl-conditions-in-parenthesis (insert "("))
9130 (while (and (vhdl-template-field "[condition]" nil t)
9131 (progn
9132 (when vhdl-conditions-in-parenthesis (insert ")"))
9133 (setq position (point))
9134 (vhdl-insert-keyword " ELSE")
9135 (insert "\n")
9136 (indent-to margin)
9137 (vhdl-template-field "[waveform]" nil t)))
9138 (setq position (point))
9139 (vhdl-insert-keyword " WHEN ")
9140 (when vhdl-conditions-in-parenthesis (insert "(")))
9141 (delete-region position (point))
9142 (insert ";")
9143 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9145 (defun vhdl-template-configuration ()
9146 "Insert a configuration specification if within an architecture,
9147 a block or component configuration if within a configuration declaration,
9148 a configuration declaration if not within a design unit."
9149 (interactive)
9150 (vhdl-prepare-search-1
9151 (cond
9152 ((and (save-excursion ; architecture body
9153 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9154 (equal "ARCHITECTURE" (upcase (match-string 1))))
9155 (vhdl-template-configuration-spec))
9156 ((and (save-excursion ; configuration declaration
9157 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9158 (equal "CONFIGURATION" (upcase (match-string 1))))
9159 (if (eq (vhdl-decision-query
9160 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9161 (vhdl-template-component-conf)
9162 (vhdl-template-block-configuration)))
9163 (t (vhdl-template-configuration-decl))))) ; otherwise
9165 (defun vhdl-template-configuration-spec (&optional optional-use)
9166 "Insert a configuration specification."
9167 (interactive)
9168 (let ((margin (current-indentation))
9169 (start (point))
9170 aspect position)
9171 (vhdl-insert-keyword "FOR ")
9172 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9173 t start (point))
9174 (vhdl-template-field "component name" "\n")
9175 (indent-to (+ margin vhdl-basic-offset))
9176 (setq start (point))
9177 (vhdl-insert-keyword "USE ")
9178 (if (and optional-use
9179 (not (setq aspect (vhdl-template-field
9180 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9181 (progn (delete-region start (point)) 'no-use)
9182 (unless optional-use
9183 (setq aspect (vhdl-template-field
9184 "ENTITY | CONFIGURATION | OPEN" " ")))
9185 (setq aspect (upcase (or aspect "")))
9186 (cond ((equal aspect "ENTITY")
9187 (vhdl-template-field "library name" "." nil nil nil nil
9188 (vhdl-work-library))
9189 (vhdl-template-field "entity name" "(")
9190 (if (vhdl-template-field "[architecture name]" nil t)
9191 (insert ")")
9192 (delete-char -1))
9193 (insert "\n")
9194 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9195 (setq position (point))
9196 (vhdl-insert-keyword "GENERIC ")
9197 (when (vhdl-template-map position t t)
9198 (insert "\n")
9199 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9200 (setq position (point))
9201 (vhdl-insert-keyword "PORT ")
9202 (unless (vhdl-template-map position t t)
9203 (delete-region (line-beginning-position) (point))
9204 (delete-char -1))
9205 (insert ";")
9207 ((equal aspect "CONFIGURATION")
9208 (vhdl-template-field "library name" "." nil nil nil nil
9209 (vhdl-work-library))
9210 (vhdl-template-field "configuration name" ";"))
9211 (t (delete-char -1) (insert ";") t))))))
9214 (defun vhdl-template-configuration-decl ()
9215 "Insert a configuration declaration."
9216 (interactive)
9217 (let ((margin (current-indentation))
9218 (start (point))
9219 entity-exists string name position)
9220 (vhdl-insert-keyword "CONFIGURATION ")
9221 (when (setq name (vhdl-template-field "name" nil t start (point)))
9222 (vhdl-insert-keyword " OF ")
9223 (save-excursion
9224 (vhdl-prepare-search-1
9225 (setq entity-exists (vhdl-re-search-backward
9226 "\\<entity \\(\\w*\\) is\\>" nil t))
9227 (setq string (match-string 1))))
9228 (if (and entity-exists (not (equal string "")))
9229 (insert string)
9230 (vhdl-template-field "entity name"))
9231 (vhdl-insert-keyword " IS\n")
9232 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9233 (indent-to (+ margin vhdl-basic-offset))
9234 (setq position (point))
9235 (insert "\n")
9236 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9237 (indent-to margin)
9238 (vhdl-insert-keyword "END ")
9239 (unless (vhdl-standard-p '87)
9240 (vhdl-insert-keyword "CONFIGURATION "))
9241 (insert name ";")
9242 (goto-char position))))
9244 (defun vhdl-template-constant ()
9245 "Insert a constant declaration."
9246 (interactive)
9247 (let ((start (point))
9248 (in-arglist (vhdl-in-argument-list-p)))
9249 (vhdl-insert-keyword "CONSTANT ")
9250 (when (vhdl-template-field "name" nil t start (point))
9251 (insert " : ")
9252 (when in-arglist (vhdl-insert-keyword "IN "))
9253 (vhdl-template-field "type")
9254 (if in-arglist
9255 (progn (insert ";")
9256 (vhdl-comment-insert-inline))
9257 (let ((position (point)))
9258 (insert " := ")
9259 (unless (vhdl-template-field "[initialization]" nil t)
9260 (delete-region position (point)))
9261 (insert ";")
9262 (vhdl-comment-insert-inline))))))
9264 (defun vhdl-template-context ()
9265 "Insert a context declaration."
9266 (interactive)
9267 (let ((margin (current-indentation))
9268 (start (point))
9269 entity-exists string name position)
9270 (vhdl-insert-keyword "CONTEXT ")
9271 (when (setq name (vhdl-template-field "name" nil t start (point)))
9272 (vhdl-insert-keyword " IS\n")
9273 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9274 (indent-to (+ margin vhdl-basic-offset))
9275 (setq position (point))
9276 (insert "\n")
9277 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9278 (indent-to margin)
9279 (vhdl-insert-keyword "END ")
9280 (unless (vhdl-standard-p '87)
9281 (vhdl-insert-keyword "CONTEXT "))
9282 (insert name ";")
9283 (goto-char position))))
9285 (defun vhdl-template-default ()
9286 "Insert nothing."
9287 (interactive)
9288 (insert " ")
9289 (unexpand-abbrev)
9290 (backward-word-strictly 1)
9291 (vhdl-case-word 1)
9292 (forward-char 1))
9294 (defun vhdl-template-default-indent ()
9295 "Insert nothing and indent."
9296 (interactive)
9297 (insert " ")
9298 (unexpand-abbrev)
9299 (backward-word-strictly 1)
9300 (vhdl-case-word 1)
9301 (forward-char 1)
9302 (indent-according-to-mode))
9304 (defun vhdl-template-disconnect ()
9305 "Insert a disconnect statement."
9306 (interactive)
9307 (let ((start (point)))
9308 (vhdl-insert-keyword "DISCONNECT ")
9309 (when (vhdl-template-field "signal names | OTHERS | ALL"
9310 " : " t start (point))
9311 (vhdl-template-field "type")
9312 (vhdl-insert-keyword " AFTER ")
9313 (vhdl-template-field "time expression" ";"))))
9315 (defun vhdl-template-else ()
9316 "Insert an else statement."
9317 (interactive)
9318 (let (margin)
9319 (vhdl-prepare-search-1
9320 (vhdl-insert-keyword "ELSE")
9321 (if (and (save-excursion (vhdl-re-search-backward "\\(\\(\\<when\\>\\)\\|;\\)" nil t))
9322 (match-string 2))
9323 (insert " ")
9324 (unless (vhdl-sequential-statement-p)
9325 (vhdl-insert-keyword " GENERATE"))
9326 (indent-according-to-mode)
9327 (setq margin (current-indentation))
9328 (insert "\n")
9329 (indent-to (+ margin vhdl-basic-offset))))))
9331 (defun vhdl-template-elsif ()
9332 "Insert an elsif statement."
9333 (interactive)
9334 (let ((start (point))
9335 margin)
9336 (vhdl-insert-keyword "ELSIF ")
9337 (when vhdl-conditions-in-parenthesis (insert "("))
9338 (when (vhdl-template-field "condition" nil t start (point))
9339 (when vhdl-conditions-in-parenthesis (insert ")"))
9340 (indent-according-to-mode)
9341 (setq margin (current-indentation))
9342 (vhdl-insert-keyword
9343 (concat " " (cond ((vhdl-sequential-statement-p) "THEN")
9344 ((vhdl-standard-p 'ams) "USE")
9345 (t "GENERATE")) "\n"))
9346 (indent-to (+ margin vhdl-basic-offset)))))
9348 (defun vhdl-template-entity ()
9349 "Insert an entity."
9350 (interactive)
9351 (let ((margin (current-indentation))
9352 (start (point))
9353 name end-column)
9354 (vhdl-insert-keyword "ENTITY ")
9355 (when (setq name (vhdl-template-field "name" nil t start (point)))
9356 (vhdl-insert-keyword " IS\n\n")
9357 (indent-to margin)
9358 (vhdl-insert-keyword "END ")
9359 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9360 (insert name ";")
9361 (setq end-column (current-column))
9362 (end-of-line -0)
9363 (indent-to (+ margin vhdl-basic-offset))
9364 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9365 (indent-to (+ margin vhdl-basic-offset))
9366 (when (vhdl-template-generic-list t)
9367 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9368 (insert "\n")
9369 (indent-to (+ margin vhdl-basic-offset))
9370 (when (vhdl-template-port-list t)
9371 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9372 (beginning-of-line 2)
9373 (forward-char end-column))))
9375 (defun vhdl-template-exit ()
9376 "Insert an exit statement."
9377 (interactive)
9378 (let ((start (point)))
9379 (vhdl-insert-keyword "EXIT ")
9380 (if (vhdl-template-field "[loop label]" nil t start (point))
9381 (let ((position (point)))
9382 (vhdl-insert-keyword " WHEN ")
9383 (when vhdl-conditions-in-parenthesis (insert "("))
9384 (if (vhdl-template-field "[condition]" nil t)
9385 (when vhdl-conditions-in-parenthesis (insert ")"))
9386 (delete-region position (point))))
9387 (delete-char -1))
9388 (insert ";")))
9390 (defun vhdl-template-file ()
9391 "Insert a file declaration."
9392 (interactive)
9393 (let ((start (point)))
9394 (vhdl-insert-keyword "FILE ")
9395 (when (vhdl-template-field "name" nil t start (point))
9396 (insert " : ")
9397 (vhdl-template-field "type")
9398 (unless (vhdl-standard-p '87)
9399 (vhdl-insert-keyword " OPEN ")
9400 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9401 nil t)
9402 (delete-char -6)))
9403 (vhdl-insert-keyword " IS ")
9404 (when (vhdl-standard-p '87)
9405 (vhdl-template-field "[IN | OUT]" " " t))
9406 (vhdl-template-field "filename-string" nil nil nil nil t)
9407 (insert ";")
9408 (vhdl-comment-insert-inline))))
9410 (defun vhdl-template-for ()
9411 "Insert a block or component configuration if within a configuration
9412 declaration, a configuration specification if within an architecture
9413 declarative part (and not within a subprogram), a for-loop if within a
9414 sequential statement part (subprogram or process), and a for-generate
9415 otherwise."
9416 (interactive)
9417 (vhdl-prepare-search-1
9418 (cond
9419 ((vhdl-sequential-statement-p) ; sequential statement
9420 (vhdl-template-for-loop))
9421 ((and (save-excursion ; configuration declaration
9422 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9423 (equal "CONFIGURATION" (upcase (match-string 1))))
9424 (if (eq (vhdl-decision-query
9425 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9426 (vhdl-template-component-conf)
9427 (vhdl-template-block-configuration)))
9428 ((and (save-excursion
9429 (re-search-backward ; architecture declarative part
9430 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9431 (equal "ARCHITECTURE" (upcase (match-string 1))))
9432 (vhdl-template-configuration-spec))
9433 (t (vhdl-template-for-generate))))) ; concurrent statement
9435 (defun vhdl-template-for-generate ()
9436 "Insert a for-generate."
9437 (interactive)
9438 (let ((margin (current-indentation))
9439 (start (point))
9440 label position)
9441 (vhdl-insert-keyword ": FOR ")
9442 (setq position (point-marker))
9443 (goto-char start)
9444 (when (setq label (vhdl-template-field "label" nil t start position))
9445 (goto-char position)
9446 (vhdl-template-field "loop variable")
9447 (vhdl-insert-keyword " IN ")
9448 (vhdl-template-field "range")
9449 (vhdl-template-generate-body margin label))))
9451 (defun vhdl-template-for-loop ()
9452 "Insert a for loop."
9453 (interactive)
9454 (let ((margin (current-indentation))
9455 (start (point))
9456 label index)
9457 (if (not (eq vhdl-optional-labels 'all))
9458 (vhdl-insert-keyword "FOR ")
9459 (vhdl-insert-keyword ": FOR ")
9460 (goto-char start)
9461 (setq label (vhdl-template-field "[label]" nil t))
9462 (unless label (delete-char 2))
9463 (forward-word-strictly 1)
9464 (forward-char 1))
9465 (when (setq index (vhdl-template-field "loop variable"
9466 nil t start (point)))
9467 (vhdl-insert-keyword " IN ")
9468 (vhdl-template-field "range")
9469 (vhdl-insert-keyword " LOOP\n\n")
9470 (indent-to margin)
9471 (vhdl-insert-keyword "END LOOP")
9472 (if label
9473 (insert " " label ";")
9474 (insert ";")
9475 (when vhdl-self-insert-comments (insert " -- " index)))
9476 (forward-line -1)
9477 (indent-to (+ margin vhdl-basic-offset)))))
9479 (defun vhdl-template-function (&optional kind)
9480 "Insert a function declaration or body."
9481 (interactive)
9482 (let ((margin (current-indentation))
9483 (start (point))
9484 name)
9485 (vhdl-insert-keyword "FUNCTION ")
9486 (when (setq name (vhdl-template-field "name" nil t start (point)))
9487 (vhdl-template-argument-list t)
9488 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9489 (end-of-line)
9490 (insert "\n")
9491 (indent-to (+ margin vhdl-basic-offset))
9492 (vhdl-insert-keyword "RETURN ")
9493 (vhdl-template-field "type")
9494 (if (if kind (eq kind 'body)
9495 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9496 (progn (vhdl-insert-keyword " IS\n")
9497 (vhdl-template-begin-end
9498 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9499 (vhdl-comment-block))
9500 (insert ";")))))
9502 (defun vhdl-template-function-decl ()
9503 "Insert a function declaration."
9504 (interactive)
9505 (vhdl-template-function 'decl))
9507 (defun vhdl-template-function-body ()
9508 "Insert a function declaration."
9509 (interactive)
9510 (vhdl-template-function 'body))
9512 (defun vhdl-template-generate ()
9513 "Insert a generation scheme."
9514 (interactive)
9515 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9516 (vhdl-template-if-generate)
9517 (vhdl-template-for-generate)))
9519 (defun vhdl-template-generic ()
9520 "Insert generic declaration, or generic map in instantiation statements."
9521 (interactive)
9522 (let ((start (point)))
9523 (vhdl-prepare-search-1
9524 (cond
9525 ((and (save-excursion ; entity declaration
9526 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9527 (equal "ENTITY" (upcase (match-string 1))))
9528 (vhdl-template-generic-list nil))
9529 ((or (save-excursion
9530 (or (beginning-of-line)
9531 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9532 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9533 (vhdl-insert-keyword "GENERIC ")
9534 (vhdl-template-map start))
9535 (t (vhdl-template-generic-list nil t))))))
9537 (defun vhdl-template-group ()
9538 "Insert group or group template declaration."
9539 (interactive)
9540 (let ((start (point)))
9541 (if (eq (vhdl-decision-query
9542 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9543 (vhdl-template-group-template)
9544 (vhdl-template-group-decl))))
9546 (defun vhdl-template-group-decl ()
9547 "Insert group declaration."
9548 (interactive)
9549 (let ((start (point)))
9550 (vhdl-insert-keyword "GROUP ")
9551 (when (vhdl-template-field "name" " : " t start (point))
9552 (vhdl-template-field "template name" " (")
9553 (vhdl-template-field "constituent list" ");")
9554 (vhdl-comment-insert-inline))))
9556 (defun vhdl-template-group-template ()
9557 "Insert group template declaration."
9558 (interactive)
9559 (let ((start (point)))
9560 (vhdl-insert-keyword "GROUP ")
9561 (when (vhdl-template-field "template name" nil t start (point))
9562 (vhdl-insert-keyword " IS (")
9563 (vhdl-template-field "entity class list" ");")
9564 (vhdl-comment-insert-inline))))
9566 (defun vhdl-template-if ()
9567 "Insert a sequential if statement or an if-generate statement."
9568 (interactive)
9569 (if (vhdl-sequential-statement-p)
9570 (vhdl-template-if-then)
9571 (if (and (vhdl-standard-p 'ams)
9572 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9573 (vhdl-template-if-use)
9574 (vhdl-template-if-generate))))
9576 (defun vhdl-template-if-generate ()
9577 "Insert an if-generate."
9578 (interactive)
9579 (let ((margin (current-indentation))
9580 (start (point))
9581 label position)
9582 (vhdl-insert-keyword ": IF ")
9583 (setq position (point-marker))
9584 (goto-char start)
9585 (when (setq label (vhdl-template-field "label" nil t start position))
9586 (goto-char position)
9587 (when vhdl-conditions-in-parenthesis (insert "("))
9588 (vhdl-template-field "condition")
9589 (when vhdl-conditions-in-parenthesis (insert ")"))
9590 (vhdl-template-generate-body margin label))))
9592 (defun vhdl-template-if-then-use (kind)
9593 "Insert a sequential if statement."
9594 (interactive)
9595 (let ((margin (current-indentation))
9596 (start (point))
9597 label)
9598 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9599 (vhdl-insert-keyword "IF ")
9600 (vhdl-insert-keyword ": IF ")
9601 (goto-char start)
9602 (setq label (vhdl-template-field "[label]" nil t))
9603 (unless label (delete-char 2))
9604 (forward-word-strictly 1)
9605 (forward-char 1))
9606 (when vhdl-conditions-in-parenthesis (insert "("))
9607 (when (vhdl-template-field "condition" nil t start (point))
9608 (when vhdl-conditions-in-parenthesis (insert ")"))
9609 (vhdl-insert-keyword
9610 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9611 (indent-to margin)
9612 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9613 (when label (insert " " label))
9614 (insert ";")
9615 (forward-line -1)
9616 (indent-to (+ margin vhdl-basic-offset)))))
9618 (defun vhdl-template-if-then ()
9619 "Insert a sequential if statement."
9620 (interactive)
9621 (vhdl-template-if-then-use 'then))
9623 (defun vhdl-template-if-use ()
9624 "Insert a simultaneous if statement."
9625 (interactive)
9626 (vhdl-template-if-then-use 'use))
9628 (defun vhdl-template-instance ()
9629 "Insert a component instantiation statement."
9630 (interactive)
9631 (vhdl-template-component-inst))
9633 (defun vhdl-template-library ()
9634 "Insert a library specification."
9635 (interactive)
9636 (let ((margin (current-indentation))
9637 (start (point))
9638 name end-pos)
9639 (vhdl-insert-keyword "LIBRARY ")
9640 (when (setq name (vhdl-template-field "names" nil t start (point)))
9641 (insert ";")
9642 (unless (string-match "," name)
9643 (setq end-pos (point))
9644 (insert "\n")
9645 (indent-to margin)
9646 (vhdl-insert-keyword "USE ")
9647 (insert name)
9648 (vhdl-insert-keyword "..ALL;")
9649 (backward-char 5)
9650 (if (vhdl-template-field "package name")
9651 (forward-char 5)
9652 (delete-region end-pos (+ (point) 5)))))))
9654 (defun vhdl-template-limit ()
9655 "Insert a limit."
9656 (interactive)
9657 (let ((start (point)))
9658 (vhdl-insert-keyword "LIMIT ")
9659 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9660 t start (point))
9661 (vhdl-template-field "type")
9662 (vhdl-insert-keyword " WITH ")
9663 (vhdl-template-field "real expression" ";"))))
9665 (defun vhdl-template-loop ()
9666 "Insert a loop."
9667 (interactive)
9668 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9669 (cond ((eq char ?w)
9670 (vhdl-template-while-loop))
9671 ((eq char ?f)
9672 (vhdl-template-for-loop))
9673 (t (vhdl-template-bare-loop)))))
9675 (defun vhdl-template-bare-loop ()
9676 "Insert a loop."
9677 (interactive)
9678 (let ((margin (current-indentation))
9679 (start (point))
9680 label)
9681 (if (not (eq vhdl-optional-labels 'all))
9682 (vhdl-insert-keyword "LOOP ")
9683 (vhdl-insert-keyword ": LOOP ")
9684 (goto-char start)
9685 (setq label (vhdl-template-field "[label]" nil t))
9686 (unless label (delete-char 2))
9687 (forward-word-strictly 1)
9688 (delete-char 1))
9689 (insert "\n\n")
9690 (indent-to margin)
9691 (vhdl-insert-keyword "END LOOP")
9692 (insert (if label (concat " " label ";") ";"))
9693 (forward-line -1)
9694 (indent-to (+ margin vhdl-basic-offset))))
9696 (defun vhdl-template-map (&optional start optional secondary)
9697 "Insert a map specification with association list."
9698 (interactive)
9699 (let ((start (or start (point)))
9700 margin end-pos)
9701 (vhdl-insert-keyword "MAP (")
9702 (if (not vhdl-association-list-with-formals)
9703 (if (vhdl-template-field
9704 (concat (and optional "[") "association list" (and optional "]"))
9705 ")" (or (not secondary) optional)
9706 (and (not secondary) start) (point))
9708 (if (and optional secondary) (delete-region start (point)))
9709 nil)
9710 (if vhdl-argument-list-indent
9711 (setq margin (current-column))
9712 (setq margin (+ (current-indentation) vhdl-basic-offset))
9713 (insert "\n")
9714 (indent-to margin))
9715 (if (vhdl-template-field
9716 (concat (and optional "[") "formal" (and optional "]"))
9717 " => " (or (not secondary) optional)
9718 (and (not secondary) start) (point))
9719 (progn
9720 (vhdl-template-field "actual" ",")
9721 (setq end-pos (point))
9722 (insert "\n")
9723 (indent-to margin)
9724 (while (vhdl-template-field "[formal]" " => " t)
9725 (vhdl-template-field "actual" ",")
9726 (setq end-pos (point))
9727 (insert "\n")
9728 (indent-to margin))
9729 (delete-region end-pos (point))
9730 (delete-char -1)
9731 (insert ")")
9732 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9734 (when (and optional secondary) (delete-region start (point)))
9735 nil))))
9737 (defun vhdl-template-modify (&optional noerror)
9738 "Actualize modification date."
9739 (interactive)
9740 (vhdl-prepare-search-2
9741 (save-excursion
9742 (goto-char (point-min))
9743 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9744 (progn (delete-region (point) (progn (end-of-line) (point)))
9745 (vhdl-template-insert-date))
9746 (unless noerror
9747 (error "ERROR: Modification date prefix string \"%s\" not found"
9748 vhdl-modify-date-prefix-string))))))
9751 (defun vhdl-template-modify-noerror ()
9752 "Call `vhdl-template-modify' with NOERROR non-nil."
9753 (vhdl-template-modify t))
9755 (defun vhdl-template-nature ()
9756 "Insert a nature declaration."
9757 (interactive)
9758 (let ((start (point))
9759 name mid-pos end-pos)
9760 (vhdl-insert-keyword "NATURE ")
9761 (when (setq name (vhdl-template-field "name" nil t start (point)))
9762 (vhdl-insert-keyword " IS ")
9763 (let ((definition
9764 (upcase
9765 (or (vhdl-template-field
9766 "across type | ARRAY | RECORD")
9767 ""))))
9768 (cond ((equal definition "")
9769 (insert ";"))
9770 ((equal definition "ARRAY")
9771 (delete-region (point) (progn (forward-word-strictly -1)
9772 (point)))
9773 (vhdl-template-array 'nature t))
9774 ((equal definition "RECORD")
9775 (setq mid-pos (point-marker))
9776 (delete-region (point) (progn (forward-word-strictly -1)
9777 (point)))
9778 (vhdl-template-record 'nature name t))
9780 (vhdl-insert-keyword " ACROSS ")
9781 (vhdl-template-field "through type")
9782 (vhdl-insert-keyword " THROUGH ")
9783 (vhdl-template-field "reference name")
9784 (vhdl-insert-keyword " REFERENCE;")))
9785 (when mid-pos
9786 (setq end-pos (point-marker))
9787 (goto-char mid-pos)
9788 (end-of-line))
9789 (vhdl-comment-insert-inline)
9790 (when end-pos (goto-char end-pos))))))
9792 (defun vhdl-template-next ()
9793 "Insert a next statement."
9794 (interactive)
9795 (let ((start (point)))
9796 (vhdl-insert-keyword "NEXT ")
9797 (if (vhdl-template-field "[loop label]" nil t start (point))
9798 (let ((position (point)))
9799 (vhdl-insert-keyword " WHEN ")
9800 (when vhdl-conditions-in-parenthesis (insert "("))
9801 (if (vhdl-template-field "[condition]" nil t)
9802 (when vhdl-conditions-in-parenthesis (insert ")"))
9803 (delete-region position (point))))
9804 (delete-char -1))
9805 (insert ";")))
9807 (defun vhdl-template-others ()
9808 "Insert an others aggregate."
9809 (interactive)
9810 (let ((start (point)))
9811 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9812 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9813 (vhdl-insert-keyword "OTHERS => '")
9814 (when (vhdl-template-field "value" nil t start (point))
9815 (insert "')")))
9816 (vhdl-insert-keyword "OTHERS "))))
9818 (defun vhdl-template-package (&optional kind)
9819 "Insert a package specification or body."
9820 (interactive)
9821 (let ((margin (current-indentation))
9822 (start (point))
9823 name body position)
9824 (vhdl-insert-keyword "PACKAGE ")
9825 (setq body (if kind (eq kind 'body)
9826 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9827 (when body
9828 (vhdl-insert-keyword "BODY ")
9829 (when (save-excursion
9830 (vhdl-prepare-search-1
9831 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9832 (insert (setq name (match-string 1)))))
9833 (when (or name
9834 (setq name (vhdl-template-field "name" nil t start (point))))
9835 (vhdl-insert-keyword " IS\n")
9836 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9837 (indent-to (+ margin vhdl-basic-offset))
9838 (setq position (point))
9839 (insert "\n")
9840 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9841 (indent-to margin)
9842 (vhdl-insert-keyword "END ")
9843 (unless (vhdl-standard-p '87)
9844 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9845 (insert (or name "") ";")
9846 (goto-char position))))
9848 (defun vhdl-template-package-decl ()
9849 "Insert a package specification."
9850 (interactive)
9851 (vhdl-template-package 'decl))
9853 (defun vhdl-template-package-body ()
9854 "Insert a package body."
9855 (interactive)
9856 (vhdl-template-package 'body))
9858 (defun vhdl-template-port ()
9859 "Insert a port declaration, or port map in instantiation statements."
9860 (interactive)
9861 (let ((start (point)))
9862 (vhdl-prepare-search-1
9863 (cond
9864 ((and (save-excursion ; entity declaration
9865 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9866 (equal "ENTITY" (upcase (match-string 1))))
9867 (vhdl-template-port-list nil))
9868 ((or (save-excursion
9869 (or (beginning-of-line)
9870 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9871 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9872 (vhdl-insert-keyword "PORT ")
9873 (vhdl-template-map start))
9874 (t (vhdl-template-port-list nil))))))
9876 (defun vhdl-template-procedural ()
9877 "Insert a procedural."
9878 (interactive)
9879 (let ((margin (current-indentation))
9880 (start (point))
9881 (case-fold-search t)
9882 label)
9883 (vhdl-insert-keyword "PROCEDURAL ")
9884 (when (memq vhdl-optional-labels '(process all))
9885 (goto-char start)
9886 (insert ": ")
9887 (goto-char start)
9888 (setq label (vhdl-template-field "[label]" nil t))
9889 (unless label (delete-char 2))
9890 (forward-word-strictly 1)
9891 (forward-char 1))
9892 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9893 (insert "\n")
9894 (vhdl-template-begin-end "PROCEDURAL" label margin)
9895 (vhdl-comment-block)))
9897 (defun vhdl-template-procedure (&optional kind)
9898 "Insert a procedure declaration or body."
9899 (interactive)
9900 (let ((margin (current-indentation))
9901 (start (point))
9902 name)
9903 (vhdl-insert-keyword "PROCEDURE ")
9904 (when (setq name (vhdl-template-field "name" nil t start (point)))
9905 (vhdl-template-argument-list)
9906 (if (if kind (eq kind 'body)
9907 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9908 (progn (vhdl-insert-keyword " IS")
9909 (when vhdl-auto-align
9910 (vhdl-align-region-groups start (point) 1))
9911 (end-of-line) (insert "\n")
9912 (vhdl-template-begin-end
9913 (unless (vhdl-standard-p '87) "PROCEDURE")
9914 name margin)
9915 (vhdl-comment-block))
9916 (insert ";")
9917 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9918 (end-of-line)))))
9920 (defun vhdl-template-procedure-decl ()
9921 "Insert a procedure declaration."
9922 (interactive)
9923 (vhdl-template-procedure 'decl))
9925 (defun vhdl-template-procedure-body ()
9926 "Insert a procedure body."
9927 (interactive)
9928 (vhdl-template-procedure 'body))
9930 (defun vhdl-template-process (&optional kind)
9931 "Insert a process."
9932 (interactive)
9933 (let ((margin (current-indentation))
9934 (start (point))
9935 (reset-kind vhdl-reset-kind)
9936 label seq input-signals clock reset final-pos)
9937 (setq seq (if kind (eq kind 'seq)
9938 (eq (vhdl-decision-query
9939 "process" "(c)ombinational or (s)equential?" t) ?s)))
9940 (vhdl-insert-keyword "PROCESS ")
9941 (when (memq vhdl-optional-labels '(process all))
9942 (goto-char start)
9943 (insert ": ")
9944 (goto-char start)
9945 (setq label (vhdl-template-field "[label]" nil t))
9946 (unless label (delete-char 2))
9947 (forward-word-strictly 1)
9948 (forward-char 1))
9949 (insert "(")
9950 (if (not seq)
9951 (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
9952 (progn (insert "all)") (setq input-signals "all")))
9953 (setq input-signals
9954 (vhdl-template-field "[sensitivity list]" ")" t)))
9955 (setq input-signals "")
9956 (delete-char -2))
9957 (setq clock (or (and (not (equal "" vhdl-clock-name))
9958 (progn (insert vhdl-clock-name) vhdl-clock-name))
9959 (vhdl-template-field "clock name") "<clock>"))
9960 (when (eq reset-kind 'query)
9961 (setq reset-kind
9962 (if (eq (vhdl-decision-query
9963 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9964 'async
9965 'sync)))
9966 (when (eq reset-kind 'async)
9967 (insert ", ")
9968 (setq reset (or (and (not (equal "" vhdl-reset-name))
9969 (progn (insert vhdl-reset-name) vhdl-reset-name))
9970 (vhdl-template-field "reset name") "<reset>")))
9971 (insert ")"))
9972 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9973 (insert "\n")
9974 (vhdl-template-begin-end "PROCESS" label margin)
9975 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9976 (when vhdl-prompt-for-comments
9977 (setq final-pos (point-marker))
9978 (vhdl-prepare-search-2
9979 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9980 (vhdl-re-search-backward "\\<process\\>" nil t))
9981 (end-of-line -0)
9982 (if (bobp)
9983 (progn (insert "\n") (forward-line -1))
9984 (insert "\n"))
9985 (indent-to margin)
9986 (insert "-- purpose: ")
9987 (if (not (vhdl-template-field "[description]" nil t))
9988 (vhdl-line-kill-entire)
9989 (insert "\n")
9990 (indent-to margin)
9991 (insert "-- type : ")
9992 (insert (if seq "sequential" "combinational") "\n")
9993 (indent-to margin)
9994 (insert "-- inputs : ")
9995 (if (not seq)
9996 (insert input-signals)
9997 (insert clock ", ")
9998 (when reset (insert reset ", "))
9999 (unless (vhdl-template-field "[signal names]" nil t)
10000 (delete-char -2)))
10001 (insert "\n")
10002 (indent-to margin)
10003 (insert "-- outputs: ")
10004 (vhdl-template-field "[signal names]" nil t))))
10005 (goto-char final-pos))))
10007 (defun vhdl-template-process-comb ()
10008 "Insert a combinational process."
10009 (interactive)
10010 (vhdl-template-process 'comb))
10012 (defun vhdl-template-process-seq ()
10013 "Insert a sequential process."
10014 (interactive)
10015 (vhdl-template-process 'seq))
10017 (defun vhdl-template-quantity ()
10018 "Insert a quantity declaration."
10019 (interactive)
10020 (if (vhdl-in-argument-list-p)
10021 (let ((start (point)))
10022 (vhdl-insert-keyword "QUANTITY ")
10023 (when (vhdl-template-field "names" nil t start (point))
10024 (insert " : ")
10025 (vhdl-template-field "[IN | OUT]" " " t)
10026 (vhdl-template-field "type")
10027 (insert ";")
10028 (vhdl-comment-insert-inline)))
10029 (let ((char (vhdl-decision-query
10030 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
10031 (cond ((eq char ?f) (vhdl-template-quantity-free))
10032 ((eq char ?b) (vhdl-template-quantity-branch))
10033 ((eq char ?s) (vhdl-template-quantity-source))
10034 (t (vhdl-template-undo (point) (point)))))))
10036 (defun vhdl-template-quantity-free ()
10037 "Insert a free quantity declaration."
10038 (interactive)
10039 (vhdl-insert-keyword "QUANTITY ")
10040 (vhdl-template-field "names")
10041 (insert " : ")
10042 (vhdl-template-field "type")
10043 (let ((position (point)))
10044 (insert " := ")
10045 (unless (vhdl-template-field "[initialization]" nil t)
10046 (delete-region position (point)))
10047 (insert ";")
10048 (vhdl-comment-insert-inline)))
10050 (defun vhdl-template-quantity-branch ()
10051 "Insert a branch quantity declaration."
10052 (interactive)
10053 (let (position)
10054 (vhdl-insert-keyword "QUANTITY ")
10055 (when (vhdl-template-field "[across names]" " " t)
10056 (vhdl-insert-keyword "ACROSS "))
10057 (when (vhdl-template-field "[through names]" " " t)
10058 (vhdl-insert-keyword "THROUGH "))
10059 (vhdl-template-field "plus terminal name")
10060 (setq position (point))
10061 (vhdl-insert-keyword " TO ")
10062 (unless (vhdl-template-field "[minus terminal name]" nil t)
10063 (delete-region position (point)))
10064 (insert ";")
10065 (vhdl-comment-insert-inline)))
10067 (defun vhdl-template-quantity-source ()
10068 "Insert a source quantity declaration."
10069 (interactive)
10070 (vhdl-insert-keyword "QUANTITY ")
10071 (vhdl-template-field "names")
10072 (insert " : ")
10073 (vhdl-template-field "type" " ")
10074 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
10075 (progn (vhdl-insert-keyword "NOISE ")
10076 (vhdl-template-field "power expression"))
10077 (vhdl-insert-keyword "SPECTRUM ")
10078 (vhdl-template-field "magnitude expression" ", ")
10079 (vhdl-template-field "phase expression"))
10080 (insert ";")
10081 (vhdl-comment-insert-inline))
10083 (defun vhdl-template-record (kind &optional name secondary)
10084 "Insert a record type declaration."
10085 (interactive)
10086 (let ((margin (current-indentation))
10087 (start (point))
10088 (first t))
10089 (vhdl-insert-keyword "RECORD\n")
10090 (indent-to (+ margin vhdl-basic-offset))
10091 (when (or (vhdl-template-field "element names"
10092 nil (not secondary) start (point))
10093 secondary)
10094 (while (or first (vhdl-template-field "[element names]" nil t))
10095 (insert " : ")
10096 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
10097 (vhdl-comment-insert-inline)
10098 (insert "\n")
10099 (indent-to (+ margin vhdl-basic-offset))
10100 (setq first nil))
10101 (delete-region (line-beginning-position) (point))
10102 (indent-to margin)
10103 (vhdl-insert-keyword "END RECORD")
10104 (unless (vhdl-standard-p '87) (and name (insert " " name)))
10105 (insert ";")
10106 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10108 (defun vhdl-template-report ()
10109 "Insert a report statement."
10110 (interactive)
10111 (let ((start (point)))
10112 (vhdl-insert-keyword "REPORT ")
10113 (if (equal "\"\"" (vhdl-template-field
10114 "string expression" nil t start (point) t))
10115 (delete-char -2)
10116 (setq start (point))
10117 (vhdl-insert-keyword " SEVERITY ")
10118 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
10119 (delete-region start (point)))
10120 (insert ";"))))
10122 (defun vhdl-template-return ()
10123 "Insert a return statement."
10124 (interactive)
10125 (let ((start (point)))
10126 (vhdl-insert-keyword "RETURN ")
10127 (unless (vhdl-template-field "[expression]" nil t start (point))
10128 (delete-char -1))
10129 (insert ";")))
10131 (defun vhdl-template-selected-signal-asst ()
10132 "Insert a selected signal assignment."
10133 (interactive)
10134 (let ((margin (current-indentation))
10135 (start (point))
10136 (choices t))
10137 (let ((position (point)))
10138 (vhdl-insert-keyword " SELECT ")
10139 (goto-char position))
10140 (vhdl-insert-keyword "WITH ")
10141 (when (vhdl-template-field "selector expression"
10142 nil t start (+ (point) 7))
10143 (forward-word-strictly 1)
10144 (delete-char 1)
10145 (insert "\n")
10146 (indent-to (+ margin vhdl-basic-offset))
10147 (vhdl-template-field "target signal" " <= ")
10148 (insert "\n")
10149 (indent-to (+ margin vhdl-basic-offset))
10150 (vhdl-template-field "waveform")
10151 (vhdl-insert-keyword " WHEN ")
10152 (vhdl-template-field "choices" ",")
10153 (insert "\n")
10154 (indent-to (+ margin vhdl-basic-offset))
10155 (while (and choices (vhdl-template-field "[waveform]" nil t))
10156 (vhdl-insert-keyword " WHEN ")
10157 (if (setq choices (vhdl-template-field "[choices]" "," t))
10158 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10159 (vhdl-insert-keyword "OTHERS")))
10160 (when choices
10161 (fixup-whitespace)
10162 (delete-char -2))
10163 (insert ";")
10164 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10166 (defun vhdl-template-signal ()
10167 "Insert a signal declaration."
10168 (interactive)
10169 (let ((start (point))
10170 (in-arglist (vhdl-in-argument-list-p)))
10171 (vhdl-insert-keyword "SIGNAL ")
10172 (when (vhdl-template-field "names" nil t start (point))
10173 (insert " : ")
10174 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10175 (vhdl-template-field "type")
10176 (if in-arglist
10177 (progn (insert ";")
10178 (vhdl-comment-insert-inline))
10179 (let ((position (point)))
10180 (insert " := ")
10181 (unless (vhdl-template-field "[initialization]" nil t)
10182 (delete-region position (point)))
10183 (insert ";")
10184 (vhdl-comment-insert-inline))))))
10186 (defun vhdl-template-subnature ()
10187 "Insert a subnature declaration."
10188 (interactive)
10189 (let ((start (point))
10190 position)
10191 (vhdl-insert-keyword "SUBNATURE ")
10192 (when (vhdl-template-field "name" nil t start (point))
10193 (vhdl-insert-keyword " IS ")
10194 (vhdl-template-field "nature" " (")
10195 (if (vhdl-template-field "[index range]" nil t)
10196 (insert ")")
10197 (delete-char -2))
10198 (setq position (point))
10199 (vhdl-insert-keyword " TOLERANCE ")
10200 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10201 nil t nil nil t))
10202 (delete-region position (point))
10203 (vhdl-insert-keyword " ACROSS ")
10204 (vhdl-template-field "string expression" nil nil nil nil t)
10205 (vhdl-insert-keyword " THROUGH"))
10206 (insert ";")
10207 (vhdl-comment-insert-inline))))
10209 (defun vhdl-template-subprogram-body ()
10210 "Insert a subprogram body."
10211 (interactive)
10212 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10213 (vhdl-template-function-body)
10214 (vhdl-template-procedure-body)))
10216 (defun vhdl-template-subprogram-decl ()
10217 "Insert a subprogram declaration."
10218 (interactive)
10219 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10220 (vhdl-template-function-decl)
10221 (vhdl-template-procedure-decl)))
10223 (defun vhdl-template-subtype ()
10224 "Insert a subtype declaration."
10225 (interactive)
10226 (let ((start (point)))
10227 (vhdl-insert-keyword "SUBTYPE ")
10228 (when (vhdl-template-field "name" nil t start (point))
10229 (vhdl-insert-keyword " IS ")
10230 (vhdl-template-field "type" " ")
10231 (unless
10232 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10233 (delete-char -1))
10234 (insert ";")
10235 (vhdl-comment-insert-inline))))
10237 (defun vhdl-template-terminal ()
10238 "Insert a terminal declaration."
10239 (interactive)
10240 (let ((start (point)))
10241 (vhdl-insert-keyword "TERMINAL ")
10242 (when (vhdl-template-field "names" nil t start (point))
10243 (insert " : ")
10244 (vhdl-template-field "nature")
10245 (insert ";")
10246 (vhdl-comment-insert-inline))))
10248 (defun vhdl-template-type ()
10249 "Insert a type declaration."
10250 (interactive)
10251 (let ((start (point))
10252 name mid-pos end-pos)
10253 (vhdl-insert-keyword "TYPE ")
10254 (when (setq name (vhdl-template-field "name" nil t start (point)))
10255 (vhdl-insert-keyword " IS ")
10256 (let ((definition
10257 (upcase
10258 (or (vhdl-template-field
10259 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10260 ""))))
10261 (cond ((equal definition "")
10262 (delete-char -4)
10263 (insert ";"))
10264 ((equal definition "ARRAY")
10265 (delete-region (point) (progn (forward-word-strictly -1)
10266 (point)))
10267 (vhdl-template-array 'type t))
10268 ((equal definition "RECORD")
10269 (setq mid-pos (point-marker))
10270 (delete-region (point) (progn (forward-word-strictly -1)
10271 (point)))
10272 (vhdl-template-record 'type name t))
10273 ((equal definition "ACCESS")
10274 (insert " ")
10275 (vhdl-template-field "type" ";"))
10276 ((equal definition "FILE")
10277 (vhdl-insert-keyword " OF ")
10278 (vhdl-template-field "type" ";"))
10279 ((equal definition "ENUM")
10280 (kill-word -1)
10281 (insert "(")
10282 (setq end-pos (point-marker))
10283 (insert ");"))
10284 (t (insert ";")))
10285 (when mid-pos
10286 (setq end-pos (point-marker))
10287 (goto-char mid-pos)
10288 (end-of-line))
10289 (vhdl-comment-insert-inline)
10290 (when end-pos (goto-char end-pos))))))
10292 (defun vhdl-template-use ()
10293 "Insert a use clause."
10294 (interactive)
10295 (let ((start (point)))
10296 (vhdl-prepare-search-1
10297 (vhdl-insert-keyword "USE ")
10298 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10299 (vhdl-insert-keyword "..ALL;")
10300 (backward-char 6)
10301 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10302 (forward-char 1)
10303 (vhdl-template-field "package name")
10304 (forward-char 5))))))
10306 (defun vhdl-template-variable ()
10307 "Insert a variable declaration."
10308 (interactive)
10309 (let ((start (point))
10310 (in-arglist (vhdl-in-argument-list-p)))
10311 (vhdl-prepare-search-2
10312 (if (or (save-excursion
10313 (progn (vhdl-beginning-of-block)
10314 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10315 (save-excursion (backward-word-strictly 1)
10316 (looking-at "\\<shared\\>")))
10317 (vhdl-insert-keyword "VARIABLE ")
10318 (if (vhdl-standard-p '87)
10319 (error "ERROR: Not within sequential block")
10320 (vhdl-insert-keyword "SHARED VARIABLE "))))
10321 (when (vhdl-template-field "names" nil t start (point))
10322 (insert " : ")
10323 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10324 (vhdl-template-field "type")
10325 (if in-arglist
10326 (progn (insert ";")
10327 (vhdl-comment-insert-inline))
10328 (let ((position (point)))
10329 (insert " := ")
10330 (unless (vhdl-template-field "[initialization]" nil t)
10331 (delete-region position (point)))
10332 (insert ";")
10333 (vhdl-comment-insert-inline))))))
10335 (defun vhdl-template-wait ()
10336 "Insert a wait statement."
10337 (interactive)
10338 (vhdl-insert-keyword "WAIT ")
10339 (unless (vhdl-template-field
10340 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10341 nil t)
10342 (delete-char -1))
10343 (insert ";"))
10345 (defun vhdl-template-when ()
10346 "Indent correctly if within a case statement."
10347 (interactive)
10348 (let ((position (point))
10349 margin)
10350 (vhdl-prepare-search-2
10351 (if (and (= (current-column) (current-indentation))
10352 (vhdl-re-search-forward "\\<end\\>" nil t)
10353 (looking-at "\\s-*\\<case\\>"))
10354 (progn
10355 (setq margin (current-indentation))
10356 (goto-char position)
10357 (delete-horizontal-space)
10358 (indent-to (+ margin vhdl-basic-offset)))
10359 (goto-char position)))
10360 (vhdl-insert-keyword "WHEN ")))
10362 (defun vhdl-template-while-loop ()
10363 "Insert a while loop."
10364 (interactive)
10365 (let* ((margin (current-indentation))
10366 (start (point))
10367 label)
10368 (if (not (eq vhdl-optional-labels 'all))
10369 (vhdl-insert-keyword "WHILE ")
10370 (vhdl-insert-keyword ": WHILE ")
10371 (goto-char start)
10372 (setq label (vhdl-template-field "[label]" nil t))
10373 (unless label (delete-char 2))
10374 (forward-word-strictly 1)
10375 (forward-char 1))
10376 (when vhdl-conditions-in-parenthesis (insert "("))
10377 (when (vhdl-template-field "condition" nil t start (point))
10378 (when vhdl-conditions-in-parenthesis (insert ")"))
10379 (vhdl-insert-keyword " LOOP\n\n")
10380 (indent-to margin)
10381 (vhdl-insert-keyword "END LOOP")
10382 (insert (if label (concat " " label ";") ";"))
10383 (forward-line -1)
10384 (indent-to (+ margin vhdl-basic-offset)))))
10386 (defun vhdl-template-with ()
10387 "Insert a with statement (i.e. selected signal assignment)."
10388 (interactive)
10389 (vhdl-prepare-search-1
10390 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10391 (equal ";" (match-string 1)))
10392 (vhdl-template-selected-signal-asst)
10393 (vhdl-insert-keyword "WITH "))))
10395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10396 ;; Special templates
10398 (defun vhdl-template-clocked-wait ()
10399 "Insert a wait statement for rising/falling clock edge."
10400 (interactive)
10401 (let ((start (point))
10402 clock)
10403 (vhdl-insert-keyword "WAIT UNTIL ")
10404 (when (setq clock
10405 (or (and (not (equal "" vhdl-clock-name))
10406 (progn (insert vhdl-clock-name) vhdl-clock-name))
10407 (vhdl-template-field "clock name" nil t start (point))))
10408 (insert "'event")
10409 (vhdl-insert-keyword " AND ")
10410 (insert clock)
10411 (insert
10412 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10413 (vhdl-comment-insert-inline
10414 (concat (if vhdl-clock-rising-edge "rising" "falling")
10415 " clock edge")))))
10417 (defun vhdl-template-seq-process (clock reset reset-kind)
10418 "Insert a template for the body of a sequential process."
10419 (let ((margin (current-indentation))
10420 position)
10421 (vhdl-insert-keyword "IF ")
10422 (when vhdl-conditions-in-parenthesis (insert "("))
10423 (when (eq reset-kind 'async)
10424 (insert reset " = "
10425 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10426 (when vhdl-conditions-in-parenthesis (insert ")"))
10427 (vhdl-insert-keyword " THEN")
10428 (vhdl-comment-insert-inline
10429 (concat "asynchronous reset (active "
10430 (if vhdl-reset-active-high "high" "low") ")"))
10431 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10432 (setq position (point))
10433 (insert "\n") (indent-to margin)
10434 (vhdl-insert-keyword "ELSIF ")
10435 (when vhdl-conditions-in-parenthesis (insert "(")))
10436 (if (eq vhdl-clock-edge-condition 'function)
10437 (insert (if vhdl-clock-rising-edge "rising" "falling")
10438 "_edge(" clock ")")
10439 (insert clock "'event")
10440 (vhdl-insert-keyword " AND ")
10441 (insert clock " = "
10442 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10443 (when vhdl-conditions-in-parenthesis (insert ")"))
10444 (vhdl-insert-keyword " THEN")
10445 (vhdl-comment-insert-inline
10446 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10447 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10448 (when (eq reset-kind 'sync)
10449 (vhdl-insert-keyword "IF ")
10450 (when vhdl-conditions-in-parenthesis (insert "("))
10451 (setq reset (or (and (not (equal "" vhdl-reset-name))
10452 (progn (insert vhdl-reset-name) vhdl-reset-name))
10453 (vhdl-template-field "reset name") "<reset>"))
10454 (insert " = "
10455 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10456 (when vhdl-conditions-in-parenthesis (insert ")"))
10457 (vhdl-insert-keyword " THEN")
10458 (vhdl-comment-insert-inline
10459 (concat "synchronous reset (active "
10460 (if vhdl-reset-active-high "high" "low") ")"))
10461 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10462 (setq position (point))
10463 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10464 (vhdl-insert-keyword "ELSE")
10465 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10466 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10467 (vhdl-insert-keyword "END IF;"))
10468 (when (eq reset-kind 'none)
10469 (setq position (point)))
10470 (insert "\n") (indent-to margin)
10471 (vhdl-insert-keyword "END IF;")
10472 (goto-char position)
10473 reset))
10475 (defun vhdl-template-standard-package (library package)
10476 "Insert specification of a standard package. Include a library
10477 specification, if not already there."
10478 (let ((margin (current-indentation)))
10479 (unless (equal library "std")
10480 (unless (or (save-excursion
10481 (vhdl-prepare-search-1
10482 (and (not (bobp))
10483 (re-search-backward
10484 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10485 library "\\|end\\)\\>") nil t)
10486 (match-string 2))))
10487 (equal (downcase library) "work"))
10488 (vhdl-insert-keyword "LIBRARY ")
10489 (insert library ";")
10490 (when package
10491 (insert "\n")
10492 (indent-to margin))))
10493 (when package
10494 (vhdl-insert-keyword "USE ")
10495 (insert library "." package)
10496 (vhdl-insert-keyword ".ALL;"))))
10498 (defun vhdl-template-package-numeric-bit ()
10499 "Insert specification of `numeric_bit' package."
10500 (interactive)
10501 (vhdl-template-standard-package "ieee" "numeric_bit"))
10503 (defun vhdl-template-package-numeric-std ()
10504 "Insert specification of `numeric_std' package."
10505 (interactive)
10506 (vhdl-template-standard-package "ieee" "numeric_std"))
10508 (defun vhdl-template-package-std-logic-1164 ()
10509 "Insert specification of `std_logic_1164' package."
10510 (interactive)
10511 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10513 (defun vhdl-template-package-std-logic-arith ()
10514 "Insert specification of `std_logic_arith' package."
10515 (interactive)
10516 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10518 (defun vhdl-template-package-std-logic-misc ()
10519 "Insert specification of `std_logic_misc' package."
10520 (interactive)
10521 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10523 (defun vhdl-template-package-std-logic-signed ()
10524 "Insert specification of `std_logic_signed' package."
10525 (interactive)
10526 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10528 (defun vhdl-template-package-std-logic-textio ()
10529 "Insert specification of `std_logic_textio' package."
10530 (interactive)
10531 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10533 (defun vhdl-template-package-std-logic-unsigned ()
10534 "Insert specification of `std_logic_unsigned' package."
10535 (interactive)
10536 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10538 (defun vhdl-template-package-textio ()
10539 "Insert specification of `textio' package."
10540 (interactive)
10541 (vhdl-template-standard-package "std" "textio"))
10543 (defun vhdl-template-package-fundamental-constants ()
10544 "Insert specification of `fundamental_constants' package."
10545 (interactive)
10546 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10548 (defun vhdl-template-package-material-constants ()
10549 "Insert specification of `material_constants' package."
10550 (interactive)
10551 (vhdl-template-standard-package "ieee" "material_constants"))
10553 (defun vhdl-template-package-energy-systems ()
10554 "Insert specification of `energy_systems' package."
10555 (interactive)
10556 (vhdl-template-standard-package "ieee" "energy_systems"))
10558 (defun vhdl-template-package-electrical-systems ()
10559 "Insert specification of `electrical_systems' package."
10560 (interactive)
10561 (vhdl-template-standard-package "ieee" "electrical_systems"))
10563 (defun vhdl-template-package-mechanical-systems ()
10564 "Insert specification of `mechanical_systems' package."
10565 (interactive)
10566 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10568 (defun vhdl-template-package-radiant-systems ()
10569 "Insert specification of `radiant_systems' package."
10570 (interactive)
10571 (vhdl-template-standard-package "ieee" "radiant_systems"))
10573 (defun vhdl-template-package-thermal-systems ()
10574 "Insert specification of `thermal_systems' package."
10575 (interactive)
10576 (vhdl-template-standard-package "ieee" "thermal_systems"))
10578 (defun vhdl-template-package-fluidic-systems ()
10579 "Insert specification of `fluidic_systems' package."
10580 (interactive)
10581 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10583 (defun vhdl-template-package-math-complex ()
10584 "Insert specification of `math_complex' package."
10585 (interactive)
10586 (vhdl-template-standard-package "ieee" "math_complex"))
10588 (defun vhdl-template-package-math-real ()
10589 "Insert specification of `math_real' package."
10590 (interactive)
10591 (vhdl-template-standard-package "ieee" "math_real"))
10593 (defun vhdl-template-directive (directive)
10594 "Insert directive."
10595 (unless (= (current-indentation) (current-column))
10596 (delete-horizontal-space)
10597 (insert " "))
10598 (insert "-- pragma " directive))
10600 (defun vhdl-template-directive-translate-on ()
10601 "Insert directive `translate_on'."
10602 (interactive)
10603 (vhdl-template-directive "translate_on"))
10605 (defun vhdl-template-directive-translate-off ()
10606 "Insert directive `translate_off'."
10607 (interactive)
10608 (vhdl-template-directive "translate_off"))
10610 (defun vhdl-template-directive-synthesis-on ()
10611 "Insert directive `synthesis_on'."
10612 (interactive)
10613 (vhdl-template-directive "synthesis_on"))
10615 (defun vhdl-template-directive-synthesis-off ()
10616 "Insert directive `synthesis_off'."
10617 (interactive)
10618 (vhdl-template-directive "synthesis_off"))
10620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10621 ;; Header and footer templates
10623 (defun vhdl-template-header (&optional file-title)
10624 "Insert a VHDL file header."
10625 (interactive)
10626 (unless (equal vhdl-file-header "")
10627 (let (pos)
10628 (save-excursion
10629 (goto-char (point-min))
10630 (vhdl-insert-string-or-file vhdl-file-header)
10631 (setq pos (point-marker)))
10632 (vhdl-template-replace-header-keywords
10633 (point-min-marker) pos file-title))))
10635 (defun vhdl-template-footer ()
10636 "Insert a VHDL file footer."
10637 (interactive)
10638 (unless (equal vhdl-file-footer "")
10639 (let (pos)
10640 (save-excursion
10641 (goto-char (point-max))
10642 (setq pos (point-marker))
10643 (vhdl-insert-string-or-file vhdl-file-footer)
10644 (unless (= (preceding-char) ?\n)
10645 (insert "\n")))
10646 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10648 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10649 is-model)
10650 "Replace keywords in header and footer."
10651 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10652 ""))
10653 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10654 ""))
10655 pos)
10656 (vhdl-prepare-search-2
10657 (save-excursion
10658 (goto-char beg)
10659 (while (search-forward "<projectdesc>" end t)
10660 (replace-match project-desc t t))
10661 (goto-char beg)
10662 (while (search-forward "<filename>" end t)
10663 (replace-match (buffer-name) t t))
10664 (goto-char beg)
10665 (while (search-forward "<copyright>" end t)
10666 (replace-match vhdl-copyright-string t t))
10667 (goto-char beg)
10668 (while (search-forward "<author>" end t)
10669 (replace-match "" t t)
10670 (insert (user-full-name))
10671 (when user-mail-address (insert " <" user-mail-address ">")))
10672 (goto-char beg)
10673 (while (search-forward "<authorfull>" end t)
10674 (replace-match (user-full-name) t t))
10675 (goto-char beg)
10676 (while (search-forward "<login>" end t)
10677 (replace-match (user-login-name) t t))
10678 (goto-char beg)
10679 (while (search-forward "<project>" end t)
10680 (replace-match project-title t t))
10681 (goto-char beg)
10682 (while (search-forward "<company>" end t)
10683 (replace-match vhdl-company-name t t))
10684 (goto-char beg)
10685 (while (search-forward "<platform>" end t)
10686 (replace-match vhdl-platform-spec t t))
10687 (goto-char beg)
10688 (while (search-forward "<standard>" end t)
10689 (replace-match
10690 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10691 ((vhdl-standard-p '93) "'93/02")
10692 ((vhdl-standard-p '08) "'08"))
10693 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10694 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10695 (goto-char beg)
10696 ;; Replace <RCS> with $, so that RCS for the source is
10697 ;; not over-enthusiastic with replacements
10698 (while (search-forward "<RCS>" end t)
10699 (replace-match "$" nil t))
10700 (goto-char beg)
10701 (while (search-forward "<date>" end t)
10702 (replace-match "" t t)
10703 (vhdl-template-insert-date))
10704 (goto-char beg)
10705 (while (search-forward "<year>" end t)
10706 (replace-match (format-time-string "%Y" nil) t t))
10707 (goto-char beg)
10708 (when file-title
10709 (while (search-forward "<title string>" end t)
10710 (replace-match file-title t t))
10711 (goto-char beg))
10712 (let (string)
10713 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10714 (save-match-data
10715 (setq string (read-string (concat (match-string 1) ": "))))
10716 (replace-match string t t)))
10717 (goto-char beg)
10718 (when (and (not is-model) (search-forward "<cursor>" end t))
10719 (replace-match "" t t)
10720 (setq pos (point))))
10721 (when pos (goto-char pos))
10722 (unless is-model
10723 (when (or (not project-title) (equal project-title ""))
10724 (message "You can specify a project title in user option `vhdl-project-alist'"))
10725 (when (or (not project-desc) (equal project-desc ""))
10726 (message "You can specify a project description in user option `vhdl-project-alist'"))
10727 (when (equal vhdl-platform-spec "")
10728 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10729 (when (equal vhdl-company-name "")
10730 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10733 ;; Comment templates and functions
10735 (defun vhdl-comment-indent ()
10736 "Indent comments."
10737 (let* ((position (point))
10738 (col
10739 (progn
10740 (forward-line -1)
10741 (if (re-search-forward "--" position t)
10742 (- (current-column) 2) ; existing comment at bol stays there
10743 (goto-char position)
10744 (skip-chars-backward " \t")
10745 (max comment-column ; else indent to comment column
10746 (1+ (current-column))))))) ; except leave at least one space
10747 (goto-char position)
10748 col))
10750 (defun vhdl-comment-insert ()
10751 "Start a comment at the end of the line.
10752 If on line with code, indent at least `comment-column'.
10753 If starting after end-comment-column, start a new line."
10754 (interactive)
10755 (when (> (current-column) end-comment-column) (newline-and-indent))
10756 (if (or (looking-at "\\s-*$") ; end of line
10757 (and (not unread-command-events) ; called with key binding or menu
10758 (not (end-of-line))))
10759 (let (margin)
10760 (while (= (preceding-char) ?-) (delete-char -1))
10761 (setq margin (current-column))
10762 (delete-horizontal-space)
10763 (if (bolp)
10764 (progn (indent-to margin) (insert "--"))
10765 (insert " ")
10766 (indent-to comment-column)
10767 (insert "--"))
10768 (if (not unread-command-events) (insert " ")))
10769 ;; else code following current point implies commenting out code
10770 (let (next-input code)
10771 (while (= (preceding-char) ?-) (delete-char -2))
10772 (while (= (setq next-input (read-char)) 13) ; CR
10773 (insert "--") ; or have a space after it?
10774 (forward-char -2)
10775 (forward-line 1)
10776 (message "Enter CR if commenting out a line of code.")
10777 (setq code t))
10778 (unless code
10779 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10780 (push (vhdl-character-to-event next-input) ; pushback the char
10781 unread-command-events))))
10783 (defun vhdl-comment-display (&optional line-exists)
10784 "Add 2 comment lines at the current indent, making a display comment."
10785 (interactive)
10786 (let ((margin (current-indentation)))
10787 (unless line-exists (vhdl-comment-display-line))
10788 (insert "\n") (indent-to margin)
10789 (insert "\n") (indent-to margin)
10790 (vhdl-comment-display-line)
10791 (end-of-line -0)
10792 (insert "-- ")))
10794 (defun vhdl-comment-display-line ()
10795 "Displays one line of dashes."
10796 (interactive)
10797 (while (= (preceding-char) ?-) (delete-char -2))
10798 (insert "--")
10799 (let* ((col (current-column))
10800 (len (- end-comment-column col)))
10801 (insert-char vhdl-comment-display-line-char len)))
10803 (defun vhdl-comment-append-inline ()
10804 "Append empty inline comment to current line."
10805 (interactive)
10806 (end-of-line)
10807 (delete-horizontal-space)
10808 (insert " ")
10809 (indent-to comment-column)
10810 (insert "-- "))
10812 (defun vhdl-comment-insert-inline (&optional string always-insert)
10813 "Insert inline comment."
10814 (when (or (and string (or vhdl-self-insert-comments always-insert))
10815 (and (not string) vhdl-prompt-for-comments))
10816 (let ((position (point)))
10817 (insert " ")
10818 (indent-to comment-column)
10819 (insert "-- ")
10820 (if (not (or (and string (progn (insert string) t))
10821 (vhdl-template-field "[comment]" nil t)))
10822 (delete-region position (point))
10823 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10825 (defun vhdl-comment-block ()
10826 "Insert comment for code block."
10827 (when vhdl-prompt-for-comments
10828 (let ((final-pos (point-marker)))
10829 (vhdl-prepare-search-2
10830 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10831 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10832 (let (margin)
10833 (back-to-indentation)
10834 (setq margin (current-column))
10835 (end-of-line -0)
10836 (if (bobp)
10837 (progn (insert "\n") (forward-line -1))
10838 (insert "\n"))
10839 (indent-to margin)
10840 (insert "-- purpose: ")
10841 (unless (vhdl-template-field "[description]" nil t)
10842 (vhdl-line-kill-entire)))))
10843 (goto-char final-pos))))
10845 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10846 "Comment out region if not commented out, uncomment otherwise."
10847 (interactive "r\nP")
10848 (save-excursion
10849 (goto-char (1- end))
10850 (end-of-line)
10851 (setq end (point-marker))
10852 (goto-char beg)
10853 (beginning-of-line)
10854 (setq beg (point))
10855 (if (looking-at (concat "\\s-*" comment-start))
10856 (comment-region beg end '(4))
10857 (comment-region beg end))))
10859 (defun vhdl-comment-uncomment-line (&optional arg)
10860 "Comment out line if not commented out, uncomment otherwise."
10861 (interactive "p")
10862 (save-excursion
10863 (beginning-of-line)
10864 (let ((position (point)))
10865 (forward-line (or arg 1))
10866 (vhdl-comment-uncomment-region position (point)))))
10868 (defun vhdl-comment-kill-region (beg end)
10869 "Kill comments in region."
10870 (interactive "r")
10871 (save-excursion
10872 (goto-char end)
10873 (setq end (point-marker))
10874 (goto-char beg)
10875 (beginning-of-line)
10876 (while (< (point) end)
10877 (if (looking-at "^\\(\\s-*--.*\n\\)")
10878 (progn (delete-region (match-beginning 1) (match-end 1)))
10879 (beginning-of-line 2)))))
10881 (defun vhdl-comment-kill-inline-region (beg end)
10882 "Kill inline comments in region."
10883 (interactive "r")
10884 (save-excursion
10885 (goto-char end)
10886 (setq end (point-marker))
10887 (goto-char beg)
10888 (beginning-of-line)
10889 (while (< (point) end)
10890 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10891 (delete-region (match-beginning 1) (match-end 1)))
10892 (beginning-of-line 2))))
10894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10895 ;; Subtemplates
10897 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10898 "Insert a begin ... end pair with optional name after the end.
10899 Point is left between them."
10900 (let (position)
10901 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10902 (indent-to margin)
10903 (vhdl-insert-keyword "BEGIN")
10904 (when (and (or construct name) vhdl-self-insert-comments)
10905 (insert " --")
10906 (when construct (insert " ") (vhdl-insert-keyword construct))
10907 (when name (insert " " name)))
10908 (insert "\n")
10909 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10910 (indent-to (+ margin vhdl-basic-offset))
10911 (setq position (point))
10912 (insert "\n")
10913 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10914 (indent-to margin)
10915 (vhdl-insert-keyword "END")
10916 (when construct (insert " ") (vhdl-insert-keyword construct))
10917 (insert (if name (concat " " name) "") ";")
10918 (goto-char position)))
10920 (defun vhdl-template-argument-list (&optional is-function)
10921 "Read from user a procedure or function argument list."
10922 (insert " (")
10923 (let ((margin (current-column))
10924 (start (point))
10925 (end-pos (point))
10926 not-empty interface semicolon-pos)
10927 (unless vhdl-argument-list-indent
10928 (setq margin (+ (current-indentation) vhdl-basic-offset))
10929 (insert "\n")
10930 (indent-to margin))
10931 (setq interface (vhdl-template-field
10932 (concat "[CONSTANT | SIGNAL"
10933 (unless is-function " | VARIABLE") "]") " " t))
10934 (while (vhdl-template-field "[names]" nil t)
10935 (setq not-empty t)
10936 (insert " : ")
10937 (unless is-function
10938 (if (and interface (equal (upcase interface) "CONSTANT"))
10939 (vhdl-insert-keyword "IN ")
10940 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10941 (vhdl-template-field "type")
10942 (setq semicolon-pos (point))
10943 (insert ";")
10944 (vhdl-comment-insert-inline)
10945 (setq end-pos (point))
10946 (insert "\n")
10947 (indent-to margin)
10948 (setq interface (vhdl-template-field
10949 (concat "[CONSTANT | SIGNAL"
10950 (unless is-function " | VARIABLE") "]") " " t)))
10951 (delete-region end-pos (point))
10952 (when semicolon-pos (goto-char semicolon-pos))
10953 (if not-empty
10954 (progn (delete-char 1) (insert ")"))
10955 (delete-char -2))))
10957 (defun vhdl-template-generic-list (optional &optional no-value)
10958 "Read from user a generic spec argument list."
10959 (let (margin
10960 (start (point)))
10961 (vhdl-insert-keyword "GENERIC (")
10962 (setq margin (current-column))
10963 (unless vhdl-argument-list-indent
10964 (let ((position (point)))
10965 (back-to-indentation)
10966 (setq margin (+ (current-column) vhdl-basic-offset))
10967 (goto-char position)
10968 (insert "\n")
10969 (indent-to margin)))
10970 (let ((vhdl-generics (vhdl-template-field
10971 (concat (and optional "[") "name"
10972 (and no-value "s") (and optional "]"))
10973 nil optional)))
10974 (if (not vhdl-generics)
10975 (if optional
10976 (progn (vhdl-line-kill-entire) (end-of-line -0)
10977 (unless vhdl-argument-list-indent
10978 (vhdl-line-kill-entire) (end-of-line -0)))
10979 (vhdl-template-undo start (point))
10980 nil )
10981 (insert " : ")
10982 (let (semicolon-pos end-pos)
10983 (while vhdl-generics
10984 (vhdl-template-field "type")
10985 (if no-value
10986 (progn (setq semicolon-pos (point))
10987 (insert ";"))
10988 (insert " := ")
10989 (unless (vhdl-template-field "[value]" nil t)
10990 (delete-char -4))
10991 (setq semicolon-pos (point))
10992 (insert ";"))
10993 (vhdl-comment-insert-inline)
10994 (setq end-pos (point))
10995 (insert "\n")
10996 (indent-to margin)
10997 (setq vhdl-generics (vhdl-template-field
10998 (concat "[name" (and no-value "s") "]")
10999 " : " t)))
11000 (delete-region end-pos (point))
11001 (goto-char semicolon-pos)
11002 (insert ")")
11003 (end-of-line)
11004 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
11005 t)))))
11007 (defun vhdl-template-port-list (optional)
11008 "Read from user a port spec argument list."
11009 (let ((start (point))
11010 margin vhdl-ports object)
11011 (vhdl-insert-keyword "PORT (")
11012 (setq margin (current-column))
11013 (unless vhdl-argument-list-indent
11014 (let ((position (point)))
11015 (back-to-indentation)
11016 (setq margin (+ (current-column) vhdl-basic-offset))
11017 (goto-char position)
11018 (insert "\n")
11019 (indent-to margin)))
11020 (when (vhdl-standard-p 'ams)
11021 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11022 " " t)))
11023 (setq vhdl-ports (vhdl-template-field
11024 (concat (and optional "[") "names" (and optional "]"))
11025 nil optional))
11026 (if (not vhdl-ports)
11027 (if optional
11028 (progn (vhdl-line-kill-entire) (end-of-line -0)
11029 (unless vhdl-argument-list-indent
11030 (vhdl-line-kill-entire) (end-of-line -0)))
11031 (vhdl-template-undo start (point))
11032 nil)
11033 (insert " : ")
11034 (let (semicolon-pos end-pos)
11035 (while vhdl-ports
11036 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
11037 (vhdl-template-field "IN | OUT | INOUT" " "))
11038 ((equal "QUANTITY" (upcase object))
11039 (vhdl-template-field "[IN | OUT]" " " t)))
11040 (vhdl-template-field
11041 (if (and object (equal "TERMINAL" (upcase object)))
11042 "nature" "type"))
11043 (setq semicolon-pos (point))
11044 (insert ";")
11045 (vhdl-comment-insert-inline)
11046 (setq end-pos (point))
11047 (insert "\n")
11048 (indent-to margin)
11049 (when (vhdl-standard-p 'ams)
11050 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11051 " " t)))
11052 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
11053 (delete-region end-pos (point))
11054 (goto-char semicolon-pos)
11055 (insert ")")
11056 (end-of-line)
11057 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
11058 t))))
11060 (defun vhdl-template-generate-body (margin label)
11061 "Insert body for generate template."
11062 (vhdl-insert-keyword " GENERATE")
11063 (insert "\n\n")
11064 (indent-to margin)
11065 (vhdl-insert-keyword "END GENERATE ")
11066 (insert label ";")
11067 (end-of-line 0)
11068 (indent-to (+ margin vhdl-basic-offset)))
11070 (defun vhdl-template-insert-date ()
11071 "Insert date in appropriate format."
11072 (interactive)
11073 (insert
11074 (cond
11075 ;; 'american, 'european, 'scientific kept for backward compatibility
11076 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
11077 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
11078 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
11079 (t (format-time-string vhdl-date-format nil)))))
11081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11082 ;; Help functions
11084 (defun vhdl-electric-space (count)
11085 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
11086 if in comment and past end-comment-column."
11087 (interactive "p")
11088 (cond ((vhdl-in-comment-p)
11089 (self-insert-command count)
11090 (cond ((>= (current-column) (+ 2 end-comment-column))
11091 (backward-char 1)
11092 (skip-chars-backward "^ \t\n\r\f")
11093 (indent-new-comment-line)
11094 (skip-chars-forward "^ \t\n\r\f")
11095 (forward-char 1))
11096 ((>= (current-column) end-comment-column)
11097 (indent-new-comment-line))
11098 (t nil)))
11099 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
11100 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
11101 (vhdl-prepare-search-1
11102 (or (expand-abbrev) (vhdl-fix-case-word -1)))
11103 (self-insert-command count))
11104 (t (self-insert-command count))))
11106 (defun vhdl-template-field (prompt &optional follow-string optional
11107 begin end is-string default)
11108 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
11109 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
11110 an empty string is inserted, return nil and call `vhdl-template-undo' for
11111 the region between BEGIN and END. IS-STRING indicates whether a string
11112 with double-quotes is to be inserted. DEFAULT specifies a default string."
11113 (let ((position (point))
11114 string)
11115 (insert "<" prompt ">")
11116 (setq string
11117 (condition-case ()
11118 (read-from-minibuffer (concat prompt ": ")
11119 (or (and is-string '("\"\"" . 2)) default)
11120 vhdl-minibuffer-local-map)
11121 (quit (if (and optional begin end)
11122 (progn (beep) "")
11123 (keyboard-quit)))))
11124 (when (or (not (equal string "")) optional)
11125 (delete-region position (point)))
11126 (when (and (equal string "") optional begin end)
11127 (vhdl-template-undo begin end)
11128 (message "Template aborted"))
11129 (unless (equal string "")
11130 (insert string)
11131 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
11132 vhdl-keywords-regexp)
11133 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
11134 vhdl-types-regexp)
11135 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
11136 (concat "'" vhdl-attributes-regexp))
11137 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
11138 vhdl-enum-values-regexp)
11139 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
11140 vhdl-constants-regexp))
11141 (when (or (not (equal string "")) (not optional))
11142 (insert (or follow-string "")))
11143 (if (equal string "") nil string)))
11145 (defun vhdl-decision-query (string prompt &optional optional)
11146 "Query a decision from the user."
11147 (let ((start (point)))
11148 (when string (vhdl-insert-keyword (concat string " ")))
11149 (message "%s" (or prompt ""))
11150 (let ((char (read-char)))
11151 (delete-region start (point))
11152 (if (and optional (eq char ?\r))
11153 (progn (insert " ")
11154 (unexpand-abbrev)
11155 (throw 'abort "ERROR: Template aborted"))
11156 char))))
11158 (defun vhdl-insert-keyword (keyword)
11159 "Insert KEYWORD and adjust case."
11160 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11162 (defun vhdl-case-keyword (keyword)
11163 "Adjust case of KEYWORD."
11164 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11166 (defun vhdl-case-word (num)
11167 "Adjust case of following NUM words."
11168 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11170 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11171 "If preceding character is part of a word or a paren then hippie-expand,
11172 else insert tab (used for word completion in VHDL minibuffer)."
11173 (interactive "P")
11174 (cond
11175 ;; expand word
11176 ((= (char-syntax (preceding-char)) ?w)
11177 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11178 (case-replace nil)
11179 (hippie-expand-only-buffers
11180 (or (and (boundp 'hippie-expand-only-buffers)
11181 hippie-expand-only-buffers)
11182 '(vhdl-mode))))
11183 (vhdl-expand-abbrev prefix-arg)))
11184 ;; expand parenthesis
11185 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11186 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11187 (case-replace nil))
11188 (vhdl-expand-paren prefix-arg)))
11189 ;; insert tab
11190 (t (insert-tab))))
11192 (defun vhdl-template-search-prompt ()
11193 "Search for left out template prompts and query again."
11194 (interactive)
11195 (vhdl-prepare-search-2
11196 (when (or (re-search-forward
11197 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11198 (re-search-backward
11199 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11200 (let ((string (match-string 1)))
11201 (replace-match "")
11202 (vhdl-template-field string)))))
11204 (defun vhdl-template-undo (begin end)
11205 "Undo aborted template by deleting region and unexpanding the keyword."
11206 (cond (vhdl-template-invoked-by-hook
11207 (goto-char end)
11208 (insert " ")
11209 (delete-region begin end)
11210 (unexpand-abbrev))
11211 (t (delete-region begin end))))
11213 (defun vhdl-insert-string-or-file (string)
11214 "Insert STRING or file contents if STRING is an existing file name."
11215 (unless (equal string "")
11216 (let ((file-name
11217 (progn (string-match "^\\([^\n]+\\)" string)
11218 (vhdl-resolve-env-variable (match-string 1 string)))))
11219 (if (file-exists-p file-name)
11220 (forward-char (cadr (insert-file-contents file-name)))
11221 (insert string)))))
11223 (defun vhdl-beginning-of-block ()
11224 "Move cursor to the beginning of the enclosing block."
11225 (let (pos)
11226 (vhdl-prepare-search-2
11227 (save-excursion
11228 (beginning-of-line)
11229 ;; search backward for block beginning or end
11230 (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))
11231 ;; not consider subprogram declarations
11232 (or (and (match-string 5)
11233 (save-match-data
11234 (save-excursion
11235 (goto-char (match-end 5))
11236 (forward-word-strictly 1)
11237 (vhdl-forward-syntactic-ws)
11238 (when (looking-at "(")
11239 (forward-sexp))
11240 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11241 (match-string 1)))
11242 ;; not consider configuration specifications
11243 (and (match-string 6)
11244 (save-match-data
11245 (save-excursion
11246 (vhdl-end-of-block)
11247 (beginning-of-line)
11248 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11249 (match-string 2))
11250 ;; skip subblock if block end found
11251 (vhdl-beginning-of-block))))
11252 (when pos (goto-char pos))))
11254 (defun vhdl-end-of-block ()
11255 "Move cursor to the end of the enclosing block."
11256 (let (pos)
11257 (vhdl-prepare-search-2
11258 (save-excursion
11259 (end-of-line)
11260 ;; search forward for block beginning or end
11261 (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))
11262 ;; not consider subprogram declarations
11263 (or (and (match-string 5)
11264 (save-match-data
11265 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11266 (match-string 1)))
11267 ;; not consider configuration specifications
11268 (and (match-string 6)
11269 (save-match-data
11270 (save-excursion
11271 (vhdl-end-of-block)
11272 (beginning-of-line)
11273 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11274 (not (match-string 2)))
11275 ;; skip subblock if block beginning found
11276 (vhdl-end-of-block))))
11277 (when pos (goto-char pos))))
11279 (defun vhdl-sequential-statement-p ()
11280 "Check if point is within sequential statement part."
11281 (let ((start (point)))
11282 (save-excursion
11283 (vhdl-prepare-search-2
11284 ;; is sequential statement if ...
11285 (and (re-search-backward "^\\s-*begin\\>" nil t)
11286 ;; ... point is between "begin" and "end" of ...
11287 (progn (vhdl-end-of-block)
11288 (< start (point)))
11289 ;; ... a sequential block
11290 (progn (vhdl-beginning-of-block)
11291 (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\\)\\)\\>")))))))
11293 (defun vhdl-in-argument-list-p ()
11294 "Check if within an argument list."
11295 (save-excursion
11296 (vhdl-prepare-search-2
11297 (or (string-match "arglist"
11298 (format "%s" (caar (vhdl-get-syntactic-context))))
11299 (progn (beginning-of-line)
11300 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11303 ;; Abbrev hooks
11305 (defun vhdl-hooked-abbrev (func)
11306 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11307 but not if inside a comment or quote."
11308 (if (or (vhdl-in-literal)
11309 (save-excursion
11310 (forward-word-strictly -1)
11311 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11312 (progn
11313 (insert " ")
11314 (unexpand-abbrev)
11315 (backward-word-strictly 1)
11316 (vhdl-case-word 1)
11317 (delete-char 1))
11318 (if (not vhdl-electric-mode)
11319 (progn
11320 (insert " ")
11321 (unexpand-abbrev)
11322 (backward-word-strictly 1)
11323 (vhdl-case-word 1)
11324 (delete-char 1))
11325 (let ((invoke-char vhdl-last-input-event)
11326 (abbrev-mode -1)
11327 (vhdl-template-invoked-by-hook t))
11328 (let ((caught (catch 'abort
11329 (funcall func))))
11330 (when (stringp caught) (message "%s" caught)))
11331 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11332 ;; delete CR which is still in event queue
11333 (if (fboundp 'enqueue-eval-event)
11334 (enqueue-eval-event 'delete-char -1)
11335 (push (vhdl-character-to-event ?\177) ; push back a delete char
11336 unread-command-events))))))
11338 (defun vhdl-template-alias-hook ()
11339 (vhdl-hooked-abbrev 'vhdl-template-alias))
11340 (defun vhdl-template-architecture-hook ()
11341 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11342 (defun vhdl-template-assert-hook ()
11343 (vhdl-hooked-abbrev 'vhdl-template-assert))
11344 (defun vhdl-template-attribute-hook ()
11345 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11346 (defun vhdl-template-block-hook ()
11347 (vhdl-hooked-abbrev 'vhdl-template-block))
11348 (defun vhdl-template-break-hook ()
11349 (vhdl-hooked-abbrev 'vhdl-template-break))
11350 (defun vhdl-template-case-hook ()
11351 (vhdl-hooked-abbrev 'vhdl-template-case))
11352 (defun vhdl-template-component-hook ()
11353 (vhdl-hooked-abbrev 'vhdl-template-component))
11354 (defun vhdl-template-instance-hook ()
11355 (vhdl-hooked-abbrev 'vhdl-template-instance))
11356 (defun vhdl-template-conditional-signal-asst-hook ()
11357 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11358 (defun vhdl-template-configuration-hook ()
11359 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11360 (defun vhdl-template-constant-hook ()
11361 (vhdl-hooked-abbrev 'vhdl-template-constant))
11362 (defun vhdl-template-context-hook ()
11363 (vhdl-hooked-abbrev 'vhdl-template-context))
11364 (defun vhdl-template-disconnect-hook ()
11365 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11366 (defun vhdl-template-display-comment-hook ()
11367 (vhdl-hooked-abbrev 'vhdl-comment-display))
11368 (defun vhdl-template-else-hook ()
11369 (vhdl-hooked-abbrev 'vhdl-template-else))
11370 (defun vhdl-template-elsif-hook ()
11371 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11372 (defun vhdl-template-entity-hook ()
11373 (vhdl-hooked-abbrev 'vhdl-template-entity))
11374 (defun vhdl-template-exit-hook ()
11375 (vhdl-hooked-abbrev 'vhdl-template-exit))
11376 (defun vhdl-template-file-hook ()
11377 (vhdl-hooked-abbrev 'vhdl-template-file))
11378 (defun vhdl-template-for-hook ()
11379 (vhdl-hooked-abbrev 'vhdl-template-for))
11380 (defun vhdl-template-function-hook ()
11381 (vhdl-hooked-abbrev 'vhdl-template-function))
11382 (defun vhdl-template-generic-hook ()
11383 (vhdl-hooked-abbrev 'vhdl-template-generic))
11384 (defun vhdl-template-group-hook ()
11385 (vhdl-hooked-abbrev 'vhdl-template-group))
11386 (defun vhdl-template-library-hook ()
11387 (vhdl-hooked-abbrev 'vhdl-template-library))
11388 (defun vhdl-template-limit-hook ()
11389 (vhdl-hooked-abbrev 'vhdl-template-limit))
11390 (defun vhdl-template-if-hook ()
11391 (vhdl-hooked-abbrev 'vhdl-template-if))
11392 (defun vhdl-template-bare-loop-hook ()
11393 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11394 (defun vhdl-template-map-hook ()
11395 (vhdl-hooked-abbrev 'vhdl-template-map))
11396 (defun vhdl-template-nature-hook ()
11397 (vhdl-hooked-abbrev 'vhdl-template-nature))
11398 (defun vhdl-template-next-hook ()
11399 (vhdl-hooked-abbrev 'vhdl-template-next))
11400 (defun vhdl-template-others-hook ()
11401 (vhdl-hooked-abbrev 'vhdl-template-others))
11402 (defun vhdl-template-package-hook ()
11403 (vhdl-hooked-abbrev 'vhdl-template-package))
11404 (defun vhdl-template-port-hook ()
11405 (vhdl-hooked-abbrev 'vhdl-template-port))
11406 (defun vhdl-template-procedural-hook ()
11407 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11408 (defun vhdl-template-procedure-hook ()
11409 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11410 (defun vhdl-template-process-hook ()
11411 (vhdl-hooked-abbrev 'vhdl-template-process))
11412 (defun vhdl-template-quantity-hook ()
11413 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11414 (defun vhdl-template-report-hook ()
11415 (vhdl-hooked-abbrev 'vhdl-template-report))
11416 (defun vhdl-template-return-hook ()
11417 (vhdl-hooked-abbrev 'vhdl-template-return))
11418 (defun vhdl-template-selected-signal-asst-hook ()
11419 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11420 (defun vhdl-template-signal-hook ()
11421 (vhdl-hooked-abbrev 'vhdl-template-signal))
11422 (defun vhdl-template-subnature-hook ()
11423 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11424 (defun vhdl-template-subtype-hook ()
11425 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11426 (defun vhdl-template-terminal-hook ()
11427 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11428 (defun vhdl-template-type-hook ()
11429 (vhdl-hooked-abbrev 'vhdl-template-type))
11430 (defun vhdl-template-use-hook ()
11431 (vhdl-hooked-abbrev 'vhdl-template-use))
11432 (defun vhdl-template-variable-hook ()
11433 (vhdl-hooked-abbrev 'vhdl-template-variable))
11434 (defun vhdl-template-wait-hook ()
11435 (vhdl-hooked-abbrev 'vhdl-template-wait))
11436 (defun vhdl-template-when-hook ()
11437 (vhdl-hooked-abbrev 'vhdl-template-when))
11438 (defun vhdl-template-while-loop-hook ()
11439 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11440 (defun vhdl-template-with-hook ()
11441 (vhdl-hooked-abbrev 'vhdl-template-with))
11442 (defun vhdl-template-and-hook ()
11443 (vhdl-hooked-abbrev 'vhdl-template-and))
11444 (defun vhdl-template-or-hook ()
11445 (vhdl-hooked-abbrev 'vhdl-template-or))
11446 (defun vhdl-template-nand-hook ()
11447 (vhdl-hooked-abbrev 'vhdl-template-nand))
11448 (defun vhdl-template-nor-hook ()
11449 (vhdl-hooked-abbrev 'vhdl-template-nor))
11450 (defun vhdl-template-xor-hook ()
11451 (vhdl-hooked-abbrev 'vhdl-template-xor))
11452 (defun vhdl-template-xnor-hook ()
11453 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11454 (defun vhdl-template-not-hook ()
11455 (vhdl-hooked-abbrev 'vhdl-template-not))
11457 (defun vhdl-template-default-hook ()
11458 (vhdl-hooked-abbrev 'vhdl-template-default))
11459 (defun vhdl-template-default-indent-hook ()
11460 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11463 ;; Template insertion from completion list
11465 (defun vhdl-template-insert-construct (name)
11466 "Insert the built-in construct template with NAME."
11467 (interactive
11468 (list (let ((completion-ignore-case t))
11469 (completing-read "Construct name: "
11470 vhdl-template-construct-alist nil t))))
11471 (vhdl-template-insert-fun
11472 (cadr (assoc name vhdl-template-construct-alist))))
11474 (defun vhdl-template-insert-package (name)
11475 "Insert the built-in package template with NAME."
11476 (interactive
11477 (list (let ((completion-ignore-case t))
11478 (completing-read "Package name: "
11479 vhdl-template-package-alist nil t))))
11480 (vhdl-template-insert-fun
11481 (cadr (assoc name vhdl-template-package-alist))))
11483 (defun vhdl-template-insert-directive (name)
11484 "Insert the built-in directive template with NAME."
11485 (interactive
11486 (list (let ((completion-ignore-case t))
11487 (completing-read "Directive name: "
11488 vhdl-template-directive-alist nil t))))
11489 (vhdl-template-insert-fun
11490 (cadr (assoc name vhdl-template-directive-alist))))
11492 (defun vhdl-template-insert-fun (fun)
11493 "Call FUN to insert a built-in template."
11494 (let ((caught (catch 'abort (when fun (funcall fun)))))
11495 (when (stringp caught) (message "%s" caught))))
11498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11499 ;;; Models
11500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11502 (defun vhdl-model-insert (model-name)
11503 "Insert the user model with name MODEL-NAME."
11504 (interactive
11505 (let ((completion-ignore-case t))
11506 (list (completing-read "Model name: " vhdl-model-alist))))
11507 (indent-according-to-mode)
11508 (let ((start (point-marker))
11509 (margin (current-indentation))
11510 model position prompt string end)
11511 (vhdl-prepare-search-2
11512 (when (setq model (assoc model-name vhdl-model-alist))
11513 ;; insert model
11514 (beginning-of-line)
11515 (delete-horizontal-space)
11516 (goto-char start)
11517 (vhdl-insert-string-or-file (nth 1 model))
11518 (setq end (point-marker))
11519 ;; indent code
11520 (goto-char start)
11521 (beginning-of-line)
11522 (while (< (point) end)
11523 (unless (looking-at "^$")
11524 (insert-char ? margin))
11525 (beginning-of-line 2))
11526 (goto-char start)
11527 ;; insert clock
11528 (unless (equal "" vhdl-clock-name)
11529 (while (re-search-forward "<clock>" end t)
11530 (replace-match vhdl-clock-name)))
11531 (goto-char start)
11532 ;; insert reset
11533 (unless (equal "" vhdl-reset-name)
11534 (while (re-search-forward "<reset>" end t)
11535 (replace-match vhdl-reset-name)))
11536 ;; replace header prompts
11537 (vhdl-template-replace-header-keywords start end nil t)
11538 (goto-char start)
11539 ;; query other prompts
11540 (while (re-search-forward
11541 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11542 (unless (equal "cursor" (match-string 1))
11543 (setq position (match-beginning 1))
11544 (setq prompt (match-string 1))
11545 (replace-match "")
11546 (setq string (vhdl-template-field prompt nil t))
11547 ;; replace occurrences of same prompt
11548 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11549 (replace-match (or string "")))
11550 (goto-char position)))
11551 (goto-char start)
11552 ;; goto final position
11553 (if (re-search-forward "<cursor>" end t)
11554 (replace-match "")
11555 (goto-char end))))))
11557 (defun vhdl-model-defun ()
11558 "Define help and hook functions for user models."
11559 (let ((model-alist vhdl-model-alist)
11560 model-name model-keyword)
11561 (while model-alist
11562 ;; define functions for user models that can be invoked from menu and key
11563 ;; bindings and which themselves call `vhdl-model-insert' with the model
11564 ;; name as argument
11565 (setq model-name (nth 0 (car model-alist)))
11566 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11567 ,(concat "Insert model for \"" model-name "\".")
11568 (interactive)
11569 (vhdl-model-insert ,model-name)))
11570 ;; define hooks for user models that are invoked from keyword abbrevs
11571 (setq model-keyword (nth 3 (car model-alist)))
11572 (unless (equal model-keyword "")
11573 (eval `(defun
11574 ,(vhdl-function-name
11575 "vhdl-model" model-name "hook") ()
11576 (vhdl-hooked-abbrev
11577 ',(vhdl-function-name "vhdl-model" model-name)))))
11578 (setq model-alist (cdr model-alist)))))
11580 (vhdl-model-defun)
11583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11584 ;;; Port translation
11585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11587 (defvar vhdl-port-list nil
11588 "Variable to hold last port map parsed.")
11589 ;; structure: (parenthesized expression means list of such entries)
11590 ;; (ent-name
11591 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11592 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11593 ;; (lib-name pack-key))
11595 (defun vhdl-parse-string (string &optional optional)
11596 "Check that the text following point matches the regexp in STRING."
11597 (if (looking-at string)
11598 (progn (goto-char (match-end 0))
11599 (when (vhdl-in-literal)
11600 (end-of-line))
11601 (point))
11602 (unless optional
11603 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11604 (vhdl-current-line) string)))
11605 nil))
11607 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11608 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11609 (vhdl-prepare-search-1
11610 (if (string-match (car regexp-cons) string)
11611 (if adjust-case
11612 (funcall vhdl-file-name-case
11613 (replace-match (cdr regexp-cons) t nil string))
11614 (replace-match (cdr regexp-cons) t nil string))
11615 string)))
11617 (defun vhdl-parse-group-comment ()
11618 "Parse comment and empty lines between groups of lines."
11619 (let ((start (point))
11620 string)
11621 (vhdl-forward-comment (point-max))
11622 (setq string (buffer-substring-no-properties start (point)))
11623 (vhdl-forward-syntactic-ws)
11624 ;; strip off leading blanks and first newline
11625 (while (string-match "^\\(\\s-+\\)" string)
11626 (setq string (concat (substring string 0 (match-beginning 1))
11627 (substring string (match-end 1)))))
11628 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11629 (substring string 1)
11630 string)))
11632 (defun vhdl-paste-group-comment (string indent)
11633 "Paste comment and empty lines from STRING between groups of lines
11634 with INDENT."
11635 (let ((pos (point-marker)))
11636 (when (> indent 0)
11637 (while (string-match "^\\(--\\)" string)
11638 (setq string (concat (substring string 0 (match-beginning 1))
11639 (make-string indent ? )
11640 (substring string (match-beginning 1))))))
11641 (beginning-of-line)
11642 (insert string)
11643 (goto-char pos)))
11645 (defvar vhdl-port-flattened nil
11646 "Indicates whether a port has been flattened.")
11648 (defun vhdl-port-flatten (&optional as-alist)
11649 "Flatten port list so that only one generic/port exists per line.
11650 This operation is performed on an internally stored port and is only
11651 reflected in a subsequent paste operation."
11652 (interactive)
11653 (if (not vhdl-port-list)
11654 (error "ERROR: No port has been read")
11655 (message "Flattening port for next paste...")
11656 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11657 (old-vhdl-port-list (cdr vhdl-port-list))
11658 old-port-list new-port-list old-port new-port names)
11659 ;; traverse port list and flatten entries
11660 (while (cdr old-vhdl-port-list)
11661 (setq old-port-list (car old-vhdl-port-list))
11662 (setq new-port-list nil)
11663 (while old-port-list
11664 (setq old-port (car old-port-list))
11665 (setq names (car old-port))
11666 (while names
11667 (setq new-port (cons (if as-alist (car names) (list (car names)))
11668 (cdr old-port)))
11669 (setq new-port-list (append new-port-list (list new-port)))
11670 (setq names (cdr names)))
11671 (setq old-port-list (cdr old-port-list)))
11672 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11673 (setq new-vhdl-port-list (append new-vhdl-port-list
11674 (list new-port-list))))
11675 (setq vhdl-port-list
11676 (append new-vhdl-port-list (list old-vhdl-port-list))
11677 vhdl-port-flattened t)
11678 (message "Flattening port for next paste...done"))))
11680 (defvar vhdl-port-reversed-direction nil
11681 "Indicates whether port directions are reversed.")
11683 (defun vhdl-port-reverse-direction ()
11684 "Reverse direction for all ports (useful in testbenches).
11685 This operation is performed on an internally stored port and is only
11686 reflected in a subsequent paste operation."
11687 (interactive)
11688 (if (not vhdl-port-list)
11689 (error "ERROR: No port has been read")
11690 (message "Reversing port directions for next paste...")
11691 (let ((port-list (nth 2 vhdl-port-list))
11692 port-dir-car port-dir)
11693 ;; traverse port list and reverse directions
11694 (while port-list
11695 (setq port-dir-car (cddr (car port-list))
11696 port-dir (car port-dir-car))
11697 (setcar port-dir-car
11698 (cond ((equal port-dir "in") "out")
11699 ((equal port-dir "IN") "OUT")
11700 ((equal port-dir "out") "in")
11701 ((equal port-dir "OUT") "IN")
11702 (t port-dir)))
11703 (setq port-list (cdr port-list)))
11704 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11705 (message "Reversing port directions for next paste...done"))))
11707 (defun vhdl-port-copy ()
11708 "Get generic and port information from an entity or component declaration."
11709 (interactive)
11710 (save-excursion
11711 (let (parse-error end-of-list
11712 decl-type name generic-list port-list context-clause
11713 object names direct type init comment group-comment)
11714 (vhdl-prepare-search-2
11715 (setq
11716 parse-error
11717 (catch 'parse
11718 ;; check if within entity or component declaration
11719 (end-of-line)
11720 (when (or (not (re-search-backward
11721 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11722 (equal "END" (upcase (match-string 1))))
11723 (throw 'parse "ERROR: Not within an entity or component declaration"))
11724 (setq decl-type (downcase (match-string-no-properties 1)))
11725 (forward-word-strictly 1)
11726 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11727 (setq name (match-string-no-properties 1))
11728 (message "Reading port of %s \"%s\"..." decl-type name)
11729 (vhdl-forward-syntactic-ws)
11730 ;; parse generic clause
11731 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11732 ;; parse group comment and spacing
11733 (setq group-comment (vhdl-parse-group-comment))
11734 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11735 (while (not end-of-list)
11736 ;; parse names (accept extended identifiers)
11737 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11738 (setq names (list (match-string-no-properties 1)))
11739 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11740 (setq names
11741 (append names (list (match-string-no-properties 1)))))
11742 ;; parse type
11743 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11744 (setq type (match-string-no-properties 1))
11745 (when (vhdl-in-comment-p) ; if stuck in comment
11746 (setq type (concat type (and (vhdl-parse-string ".*")
11747 (match-string-no-properties 0)))))
11748 (setq comment nil)
11749 (while (looking-at "(")
11750 (setq type
11751 (concat type
11752 (buffer-substring-no-properties
11753 (point) (progn (forward-sexp) (point)))
11754 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11755 (match-string-no-properties 1)))))
11756 ;; special case: closing parenthesis is on separate line
11757 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11758 (setq comment (substring type (match-beginning 2)))
11759 (setq type (substring type 0 (match-beginning 1))))
11760 ;; strip of trailing group-comment
11761 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11762 (setq type (substring type 0 (match-end 1)))
11763 ;; parse initialization expression
11764 (setq init nil)
11765 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11766 (vhdl-parse-string "\\([^();\n]*\\)")
11767 (setq init (match-string-no-properties 1))
11768 (while (looking-at "(")
11769 (setq init
11770 (concat init
11771 (buffer-substring-no-properties
11772 (point) (progn (forward-sexp) (point)))
11773 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11774 (match-string-no-properties 1))))))
11775 ;; special case: closing parenthesis is on separate line
11776 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11777 (setq comment (substring init (match-beginning 2)))
11778 (setq init (substring init 0 (match-beginning 1)))
11779 (vhdl-forward-syntactic-ws))
11780 (skip-chars-forward " \t")
11781 ;; parse inline comment, special case: as above, no initial.
11782 (unless comment
11783 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11784 (match-string-no-properties 1))))
11785 (vhdl-forward-syntactic-ws)
11786 (setq end-of-list (vhdl-parse-string ")" t))
11787 (vhdl-parse-string "\\s-*;\\s-*")
11788 ;; parse inline comment
11789 (unless comment
11790 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11791 (match-string-no-properties 1))))
11792 ;; save everything in list
11793 (setq generic-list (append generic-list
11794 (list (list names type init
11795 comment group-comment))))
11796 ;; parse group comment and spacing
11797 (setq group-comment (vhdl-parse-group-comment))))
11798 ;; parse port clause
11799 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11800 ;; parse group comment and spacing
11801 (setq group-comment (vhdl-parse-group-comment))
11802 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11803 (while (not end-of-list)
11804 ;; parse object
11805 (setq object
11806 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11807 (match-string-no-properties 1)))
11808 ;; parse names (accept extended identifiers)
11809 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11810 (setq names (list (match-string-no-properties 1)))
11811 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11812 (setq names (append names (list (match-string-no-properties 1)))))
11813 ;; parse direction
11814 (vhdl-parse-string ":[ \t\n\r\f]*")
11815 (setq direct
11816 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11817 (match-string-no-properties 1)))
11818 ;; parse type
11819 (vhdl-parse-string "\\([^();\n]+\\)")
11820 (setq type (match-string-no-properties 1))
11821 (when (vhdl-in-comment-p) ; if stuck in comment
11822 (setq type (concat type (and (vhdl-parse-string ".*")
11823 (match-string-no-properties 0)))))
11824 (setq comment nil)
11825 (while (looking-at "(")
11826 (setq type (concat type
11827 (buffer-substring-no-properties
11828 (point) (progn (forward-sexp) (point)))
11829 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11830 (match-string-no-properties 1)))))
11831 ;; special case: closing parenthesis is on separate line
11832 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11833 (setq comment (substring type (match-beginning 2)))
11834 (setq type (substring type 0 (match-beginning 1))))
11835 ;; strip of trailing group-comment
11836 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11837 (setq type (substring type 0 (match-end 1)))
11838 (vhdl-forward-syntactic-ws)
11839 (setq end-of-list (vhdl-parse-string ")" t))
11840 (vhdl-parse-string "\\s-*;\\s-*")
11841 ;; parse inline comment
11842 (unless comment
11843 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11844 (match-string-no-properties 1))))
11845 ;; save everything in list
11846 (setq port-list (append port-list
11847 (list (list names object direct type
11848 comment group-comment))))
11849 ;; parse group comment and spacing
11850 (setq group-comment (vhdl-parse-group-comment))))
11851 ;; parse context clause
11852 (setq context-clause (vhdl-scan-context-clause))
11853 ; ;; add surrounding package to context clause
11854 ; (when (and (equal decl-type "component")
11855 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11856 ; (setq context-clause
11857 ; (append context-clause
11858 ; (list (cons (vhdl-work-library)
11859 ; (match-string-no-properties 1))))))
11860 (message "Reading port of %s \"%s\"...done" decl-type name)
11861 nil)))
11862 ;; finish parsing
11863 (if parse-error
11864 (error parse-error)
11865 (setq vhdl-port-list (list name generic-list port-list context-clause)
11866 vhdl-port-reversed-direction nil
11867 vhdl-port-flattened nil)))))
11869 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11870 "Paste a context clause."
11871 (let ((margin (current-indentation))
11872 (clause-list (nth 3 vhdl-port-list))
11873 clause)
11874 (while clause-list
11875 (setq clause (car clause-list))
11876 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11877 (downcase exclude-pack-name)))
11878 (save-excursion
11879 (re-search-backward
11880 (concat "^\\s-*use\\s-+" (car clause)
11881 "." (cdr clause) "\\>") nil t)))
11882 (vhdl-template-standard-package (car clause) (cdr clause))
11883 (insert "\n"))
11884 (setq clause-list (cdr clause-list)))))
11886 (defun vhdl-port-paste-generic (&optional no-init)
11887 "Paste a generic clause."
11888 (let ((margin (current-indentation))
11889 (generic-list (nth 1 vhdl-port-list))
11890 list-margin start names generic)
11891 ;; paste generic clause
11892 (when generic-list
11893 (setq start (point))
11894 (vhdl-insert-keyword "GENERIC (")
11895 (unless vhdl-argument-list-indent
11896 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11897 (setq list-margin (current-column))
11898 (while generic-list
11899 (setq generic (car generic-list))
11900 ;; paste group comment and spacing
11901 (when (memq vhdl-include-group-comments '(decl always))
11902 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11903 ;; paste names
11904 (setq names (nth 0 generic))
11905 (while names
11906 (insert (car names))
11907 (setq names (cdr names))
11908 (when names (insert ", ")))
11909 ;; paste type
11910 (insert " : " (nth 1 generic))
11911 ;; paste initialization
11912 (when (and (not no-init) (nth 2 generic))
11913 (insert " := " (nth 2 generic)))
11914 (unless (cdr generic-list) (insert ")"))
11915 (insert ";")
11916 ;; paste comment
11917 (when (and vhdl-include-port-comments (nth 3 generic))
11918 (vhdl-comment-insert-inline (nth 3 generic) t))
11919 (setq generic-list (cdr generic-list))
11920 (when generic-list (insert "\n") (indent-to list-margin)))
11921 ;; align generic clause
11922 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11924 (defun vhdl-port-paste-port ()
11925 "Paste a port clause."
11926 (let ((margin (current-indentation))
11927 (port-list (nth 2 vhdl-port-list))
11928 list-margin start names port)
11929 ;; paste port clause
11930 (when port-list
11931 (setq start (point))
11932 (vhdl-insert-keyword "PORT (")
11933 (unless vhdl-argument-list-indent
11934 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11935 (setq list-margin (current-column))
11936 (while port-list
11937 (setq port (car port-list))
11938 ;; paste group comment and spacing
11939 (when (memq vhdl-include-group-comments '(decl always))
11940 (vhdl-paste-group-comment (nth 5 port) list-margin))
11941 ;; paste object
11942 (when (nth 1 port) (insert (nth 1 port) " "))
11943 ;; paste names
11944 (setq names (nth 0 port))
11945 (while names
11946 (insert (car names))
11947 (setq names (cdr names))
11948 (when names (insert ", ")))
11949 ;; paste direction
11950 (insert " : ")
11951 (when (nth 2 port) (insert (nth 2 port) " "))
11952 ;; paste type
11953 (insert (nth 3 port))
11954 (unless (cdr port-list) (insert ")"))
11955 (insert ";")
11956 ;; paste comment
11957 (when (and vhdl-include-port-comments (nth 4 port))
11958 (vhdl-comment-insert-inline (nth 4 port) t))
11959 (setq port-list (cdr port-list))
11960 (when port-list (insert "\n") (indent-to list-margin)))
11961 ;; align port clause
11962 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11964 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11965 "Paste as an entity or component declaration."
11966 (unless no-indent (indent-according-to-mode))
11967 (let ((margin (current-indentation))
11968 (name (nth 0 vhdl-port-list)))
11969 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11970 (insert name)
11971 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11972 (vhdl-insert-keyword " IS"))
11973 ;; paste generic and port clause
11974 (when (nth 1 vhdl-port-list)
11975 (insert "\n")
11976 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11977 (insert "\n"))
11978 (indent-to (+ margin vhdl-basic-offset))
11979 (vhdl-port-paste-generic (eq kind 'component)))
11980 (when (nth 2 vhdl-port-list)
11981 (insert "\n")
11982 (when (and (memq vhdl-insert-empty-lines '(unit all))
11983 (eq kind 'entity))
11984 (insert "\n"))
11985 (indent-to (+ margin vhdl-basic-offset)))
11986 (vhdl-port-paste-port)
11987 (insert "\n")
11988 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11989 (insert "\n"))
11990 (indent-to margin)
11991 (vhdl-insert-keyword "END")
11992 (if (eq kind 'entity)
11993 (progn
11994 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11995 (insert " " name))
11996 (vhdl-insert-keyword " COMPONENT")
11997 (unless (vhdl-standard-p '87) (insert " " name)))
11998 (insert ";")))
12000 (defun vhdl-port-paste-entity (&optional no-indent)
12001 "Paste as an entity declaration."
12002 (interactive)
12003 (if (not vhdl-port-list)
12004 (error "ERROR: No port read")
12005 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
12006 (vhdl-port-paste-declaration 'entity no-indent)
12007 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
12009 (defun vhdl-port-paste-component (&optional no-indent)
12010 "Paste as a component declaration."
12011 (interactive)
12012 (if (not vhdl-port-list)
12013 (error "ERROR: No port read")
12014 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
12015 (vhdl-port-paste-declaration 'component no-indent)
12016 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
12018 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
12019 "Paste as a generic map."
12020 (interactive)
12021 (unless secondary (indent-according-to-mode))
12022 (let ((margin (current-indentation))
12023 list-margin start generic
12024 (generic-list (nth 1 vhdl-port-list)))
12025 (when generic-list
12026 (setq start (point))
12027 (vhdl-insert-keyword "GENERIC MAP (")
12028 (if (not vhdl-association-list-with-formals)
12029 ;; paste list of actual generics
12030 (while generic-list
12031 (insert (if no-constants
12032 (car (nth 0 (car generic-list)))
12033 (or (nth 2 (car generic-list)) " ")))
12034 (setq generic-list (cdr generic-list))
12035 (insert (if generic-list ", " ")"))
12036 (when (and (not generic-list) secondary
12037 (null (nth 2 vhdl-port-list)))
12038 (insert ";")))
12039 (unless vhdl-argument-list-indent
12040 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12041 (setq list-margin (current-column))
12042 (while generic-list
12043 (setq generic (car generic-list))
12044 ;; paste group comment and spacing
12045 (when (eq vhdl-include-group-comments 'always)
12046 (vhdl-paste-group-comment (nth 4 generic) list-margin))
12047 ;; paste formal and actual generic
12048 (insert (car (nth 0 generic)) " => "
12049 (if no-constants
12050 (vhdl-replace-string vhdl-actual-generic-name
12051 (car (nth 0 generic)))
12052 (or (nth 2 generic) "")))
12053 (setq generic-list (cdr generic-list))
12054 (insert (if generic-list "," ")"))
12055 (when (and (not generic-list) secondary
12056 (null (nth 2 vhdl-port-list)))
12057 (insert ";"))
12058 ;; paste comment
12059 (when (or vhdl-include-type-comments
12060 (and vhdl-include-port-comments (nth 3 generic)))
12061 (vhdl-comment-insert-inline
12062 (concat
12063 (when vhdl-include-type-comments
12064 (concat "[" (nth 1 generic) "] "))
12065 (when vhdl-include-port-comments (nth 3 generic))) t))
12066 (when generic-list (insert "\n") (indent-to list-margin)))
12067 ;; align generic map
12068 (when vhdl-auto-align
12069 (vhdl-align-region-groups start (point) 1 t))))))
12071 (defun vhdl-port-paste-port-map ()
12072 "Paste as a port map."
12073 (let ((margin (current-indentation))
12074 list-margin start port
12075 (port-list (nth 2 vhdl-port-list)))
12076 (when port-list
12077 (setq start (point))
12078 (vhdl-insert-keyword "PORT MAP (")
12079 (if (not vhdl-association-list-with-formals)
12080 ;; paste list of actual ports
12081 (while port-list
12082 (insert (vhdl-replace-string vhdl-actual-port-name
12083 (car (nth 0 (car port-list)))))
12084 (setq port-list (cdr port-list))
12085 (insert (if port-list ", " ")")))
12086 (unless vhdl-argument-list-indent
12087 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12088 (setq list-margin (current-column))
12089 (while port-list
12090 (setq port (car port-list))
12091 ;; paste group comment and spacing
12092 (when (eq vhdl-include-group-comments 'always)
12093 (vhdl-paste-group-comment (nth 5 port) list-margin))
12094 ;; paste formal and actual port
12095 (insert (car (nth 0 port)) " => ")
12096 (insert (vhdl-replace-string vhdl-actual-port-name
12097 (car (nth 0 port))))
12098 (setq port-list (cdr port-list))
12099 (insert (if port-list "," ");"))
12100 ;; paste comment
12101 (when (or (and vhdl-include-direction-comments (nth 2 port))
12102 vhdl-include-type-comments
12103 (and vhdl-include-port-comments (nth 4 port)))
12104 (vhdl-comment-insert-inline
12105 (concat
12106 (cond ((and vhdl-include-direction-comments
12107 vhdl-include-type-comments)
12108 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
12109 (nth 3 port) "] "))
12110 ((and vhdl-include-direction-comments (nth 2 port))
12111 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12112 (vhdl-include-direction-comments " ")
12113 (vhdl-include-type-comments
12114 (concat "[" (nth 3 port) "] ")))
12115 (when vhdl-include-port-comments (nth 4 port))) t))
12116 (when port-list (insert "\n") (indent-to list-margin)))
12117 ;; align port clause
12118 (when vhdl-auto-align
12119 (vhdl-align-region-groups start (point) 1))))))
12121 (defun vhdl-port-paste-instance (&optional name no-indent title)
12122 "Paste as an instantiation."
12123 (interactive)
12124 (if (not vhdl-port-list)
12125 (error "ERROR: No port read")
12126 (let ((orig-vhdl-port-list vhdl-port-list))
12127 ;; flatten local copy of port list (must be flat for port mapping)
12128 (vhdl-port-flatten)
12129 (unless no-indent (indent-according-to-mode))
12130 (let ((margin (current-indentation)))
12131 ;; paste instantiation
12132 (cond (name
12133 (insert name))
12134 ((equal (cdr vhdl-instance-name) "")
12135 (setq name (vhdl-template-field "instance name")))
12136 ((string-match "%d" (cdr vhdl-instance-name))
12137 (let ((n 1))
12138 (while (save-excursion
12139 (setq name (format (vhdl-replace-string
12140 vhdl-instance-name
12141 (nth 0 vhdl-port-list)) n))
12142 (goto-char (point-min))
12143 (vhdl-re-search-forward name nil t))
12144 (setq n (1+ n)))
12145 (insert name)))
12146 (t (insert (vhdl-replace-string vhdl-instance-name
12147 (nth 0 vhdl-port-list)))))
12148 (message "Pasting port as instantiation \"%s\"..." name)
12149 (insert ": ")
12150 (when title
12151 (save-excursion
12152 (beginning-of-line)
12153 (indent-to vhdl-basic-offset)
12154 (insert "-- instance \"" name "\"\n")))
12155 (if (not (vhdl-use-direct-instantiation))
12156 (insert (nth 0 vhdl-port-list))
12157 (vhdl-insert-keyword "ENTITY ")
12158 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12159 (when (nth 1 vhdl-port-list)
12160 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12161 (vhdl-port-paste-generic-map t t))
12162 (when (nth 2 vhdl-port-list)
12163 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12164 (vhdl-port-paste-port-map))
12165 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12166 (insert ";"))
12167 (message "Pasting port as instantiation \"%s\"...done" name))
12168 (setq vhdl-port-list orig-vhdl-port-list))))
12170 (defun vhdl-port-paste-constants (&optional no-indent)
12171 "Paste generics as constants."
12172 (interactive)
12173 (if (not vhdl-port-list)
12174 (error "ERROR: No port read")
12175 (let ((orig-vhdl-port-list vhdl-port-list))
12176 (message "Pasting port as constants...")
12177 ;; flatten local copy of port list (must be flat for constant initial.)
12178 (vhdl-port-flatten)
12179 (unless no-indent (indent-according-to-mode))
12180 (let ((margin (current-indentation))
12181 start generic name
12182 (generic-list (nth 1 vhdl-port-list)))
12183 (when generic-list
12184 (setq start (point))
12185 (while generic-list
12186 (setq generic (car generic-list))
12187 ;; paste group comment and spacing
12188 (when (memq vhdl-include-group-comments '(decl always))
12189 (vhdl-paste-group-comment (nth 4 generic) margin))
12190 (vhdl-insert-keyword "CONSTANT ")
12191 ;; paste generic constants
12192 (setq name (nth 0 generic))
12193 (when name
12194 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12195 ;; paste type
12196 (insert " : " (nth 1 generic))
12197 ;; paste initialization
12198 (when (nth 2 generic)
12199 (insert " := " (nth 2 generic)))
12200 (insert ";")
12201 ;; paste comment
12202 (when (and vhdl-include-port-comments (nth 3 generic))
12203 (vhdl-comment-insert-inline (nth 3 generic) t))
12204 (setq generic-list (cdr generic-list))
12205 (when generic-list (insert "\n") (indent-to margin))))
12206 ;; align signal list
12207 (when vhdl-auto-align
12208 (vhdl-align-region-groups start (point) 1))))
12209 (message "Pasting port as constants...done")
12210 (setq vhdl-port-list orig-vhdl-port-list))))
12212 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12213 "Paste ports as internal signals."
12214 (interactive)
12215 (if (not vhdl-port-list)
12216 (error "ERROR: No port read")
12217 (message "Pasting port as signals...")
12218 (unless no-indent (indent-according-to-mode))
12219 (let ((margin (current-indentation))
12220 start port names type generic-list port-name constant-name pos
12221 (port-list (nth 2 vhdl-port-list)))
12222 (when port-list
12223 (setq start (point))
12224 (while port-list
12225 (setq port (car port-list))
12226 ;; paste group comment and spacing
12227 (when (memq vhdl-include-group-comments '(decl always))
12228 (vhdl-paste-group-comment (nth 5 port) margin))
12229 ;; paste object
12230 (if (nth 1 port)
12231 (insert (nth 1 port) " ")
12232 (vhdl-insert-keyword "SIGNAL "))
12233 ;; paste actual port signals
12234 (setq names (nth 0 port))
12235 (while names
12236 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12237 (setq names (cdr names))
12238 (when names (insert ", ")))
12239 ;; paste type
12240 (setq type (nth 3 port))
12241 (setq generic-list (nth 1 vhdl-port-list))
12242 (vhdl-prepare-search-1
12243 (setq pos 0)
12244 ;; replace formal by actual generics
12245 (while generic-list
12246 (setq port-name (car (nth 0 (car generic-list))))
12247 (while (string-match (concat "\\<" port-name "\\>") type pos)
12248 (setq constant-name
12249 (save-match-data (vhdl-replace-string
12250 vhdl-actual-generic-name port-name)))
12251 (setq type (replace-match constant-name t nil type))
12252 (setq pos (match-end 0)))
12253 (setq generic-list (cdr generic-list))))
12254 (insert " : " type)
12255 ;; paste initialization (inputs only)
12256 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12257 (insert " := "
12258 (cond ((string-match "integer" (nth 3 port)) "0")
12259 ((string-match "natural" (nth 3 port)) "0")
12260 ((string-match "positive" (nth 3 port)) "0")
12261 ((string-match "real" (nth 3 port)) "0.0")
12262 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12263 (t "'0'"))))
12264 (insert ";")
12265 ;; paste comment
12266 (when (or (and vhdl-include-direction-comments (nth 2 port))
12267 (and vhdl-include-port-comments (nth 4 port)))
12268 (vhdl-comment-insert-inline
12269 (concat
12270 (cond ((and vhdl-include-direction-comments (nth 2 port))
12271 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12272 (vhdl-include-direction-comments " "))
12273 (when vhdl-include-port-comments (nth 4 port))) t))
12274 (setq port-list (cdr port-list))
12275 (when port-list (insert "\n") (indent-to margin)))
12276 ;; align signal list
12277 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12278 (message "Pasting port as signals...done")))
12280 (defun vhdl-port-paste-initializations (&optional no-indent)
12281 "Paste ports as signal initializations."
12282 (interactive)
12283 (if (not vhdl-port-list)
12284 (error "ERROR: No port read")
12285 (let ((orig-vhdl-port-list vhdl-port-list))
12286 (message "Pasting port as initializations...")
12287 ;; flatten local copy of port list (must be flat for signal initial.)
12288 (vhdl-port-flatten)
12289 (unless no-indent (indent-according-to-mode))
12290 (let ((margin (current-indentation))
12291 start port name
12292 (port-list (nth 2 vhdl-port-list)))
12293 (when port-list
12294 (setq start (point))
12295 (while port-list
12296 (setq port (car port-list))
12297 ;; paste actual port signal (inputs only)
12298 (when (equal "IN" (upcase (nth 2 port)))
12299 (setq name (car (nth 0 port)))
12300 (insert (vhdl-replace-string vhdl-actual-port-name name))
12301 ;; paste initialization
12302 (insert " <= "
12303 (cond ((string-match "integer" (nth 3 port)) "0")
12304 ((string-match "natural" (nth 3 port)) "0")
12305 ((string-match "positive" (nth 3 port)) "0")
12306 ((string-match "real" (nth 3 port)) "0.0")
12307 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12308 (t "'0'"))
12309 ";"))
12310 (setq port-list (cdr port-list))
12311 (when (and port-list
12312 (equal "IN" (upcase (nth 2 (car port-list)))))
12313 (insert "\n") (indent-to margin)))
12314 ;; align signal list
12315 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12316 (message "Pasting port as initializations...done")
12317 (setq vhdl-port-list orig-vhdl-port-list))))
12319 (defun vhdl-port-paste-testbench ()
12320 "Paste as a bare-bones testbench."
12321 (interactive)
12322 (if (not vhdl-port-list)
12323 (error "ERROR: No port read")
12324 (let ((case-fold-search t)
12325 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12326 (nth 0 vhdl-port-list)))
12327 (source-buffer (current-buffer))
12328 arch-name config-name ent-file-name arch-file-name
12329 ent-buffer arch-buffer position)
12330 ;; open entity file
12331 (unless (eq vhdl-testbench-create-files 'none)
12332 (setq ent-file-name
12333 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12334 ent-name t)
12335 "." (file-name-extension (buffer-file-name))))
12336 (if (file-exists-p ent-file-name)
12337 (if (y-or-n-p
12338 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12339 (progn (find-file ent-file-name)
12340 (erase-buffer)
12341 (set-buffer-modified-p nil))
12342 (if (eq vhdl-testbench-create-files 'separate)
12343 (setq ent-file-name nil)
12344 (error "ERROR: Pasting port as testbench...aborted")))
12345 (find-file ent-file-name)))
12346 (unless (and (eq vhdl-testbench-create-files 'separate)
12347 (null ent-file-name))
12348 ;; paste entity header
12349 (if vhdl-testbench-include-header
12350 (progn (vhdl-template-header
12351 (concat "Testbench for design \""
12352 (nth 0 vhdl-port-list) "\""))
12353 (goto-char (point-max)))
12354 (vhdl-comment-display-line) (insert "\n\n"))
12355 ;; paste std_logic_1164 package
12356 (when vhdl-testbench-include-library
12357 (vhdl-template-package-std-logic-1164)
12358 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12359 ;; paste entity declaration
12360 (vhdl-insert-keyword "ENTITY ")
12361 (insert ent-name)
12362 (vhdl-insert-keyword " IS")
12363 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12364 (insert "\n")
12365 (vhdl-insert-keyword "END ")
12366 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12367 (insert ent-name ";")
12368 (insert "\n\n")
12369 (vhdl-comment-display-line) (insert "\n"))
12370 ;; get architecture name
12371 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12372 (read-from-minibuffer "architecture name: "
12373 nil vhdl-minibuffer-local-map)
12374 (vhdl-replace-string vhdl-testbench-architecture-name
12375 (nth 0 vhdl-port-list))))
12376 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12377 ;; open architecture file
12378 (if (not (eq vhdl-testbench-create-files 'separate))
12379 (insert "\n")
12380 (setq ent-buffer (current-buffer))
12381 (setq arch-file-name
12382 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12383 (concat ent-name " " arch-name) t)
12384 "." (file-name-extension (buffer-file-name))))
12385 (when (and (file-exists-p arch-file-name)
12386 (not (y-or-n-p (concat "File \"" arch-file-name
12387 "\" exists; overwrite? "))))
12388 (error "ERROR: Pasting port as testbench...aborted"))
12389 (find-file arch-file-name)
12390 (erase-buffer)
12391 (set-buffer-modified-p nil)
12392 ;; paste architecture header
12393 (if vhdl-testbench-include-header
12394 (progn (vhdl-template-header
12395 (concat "Testbench architecture for design \""
12396 (nth 0 vhdl-port-list) "\""))
12397 (goto-char (point-max)))
12398 (vhdl-comment-display-line) (insert "\n\n")))
12399 ;; paste architecture body
12400 (vhdl-insert-keyword "ARCHITECTURE ")
12401 (insert arch-name)
12402 (vhdl-insert-keyword " OF ")
12403 (insert ent-name)
12404 (vhdl-insert-keyword " IS")
12405 (insert "\n\n") (indent-to vhdl-basic-offset)
12406 ;; paste component declaration
12407 (unless (vhdl-use-direct-instantiation)
12408 (vhdl-port-paste-component t)
12409 (insert "\n\n") (indent-to vhdl-basic-offset))
12410 ;; paste constants
12411 (when (nth 1 vhdl-port-list)
12412 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12413 (vhdl-port-paste-constants t)
12414 (insert "\n\n") (indent-to vhdl-basic-offset))
12415 ;; paste internal signals
12416 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12417 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12418 (insert "\n")
12419 ;; paste custom declarations
12420 (unless (equal "" vhdl-testbench-declarations)
12421 (insert "\n")
12422 (setq position (point))
12423 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12424 (vhdl-indent-region position (point)))
12425 (setq position (point))
12426 (insert "\n\n")
12427 (vhdl-comment-display-line) (insert "\n")
12428 (when vhdl-testbench-include-configuration
12429 (setq config-name (vhdl-replace-string
12430 vhdl-testbench-configuration-name
12431 (concat ent-name " " arch-name)))
12432 (insert "\n")
12433 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12434 (vhdl-insert-keyword " OF ") (insert ent-name)
12435 (vhdl-insert-keyword " IS\n")
12436 (indent-to vhdl-basic-offset)
12437 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12438 (indent-to vhdl-basic-offset)
12439 (vhdl-insert-keyword "END FOR;\n")
12440 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12441 (vhdl-comment-display-line) (insert "\n"))
12442 (goto-char position)
12443 (vhdl-template-begin-end
12444 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12445 ;; paste instantiation
12446 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12447 (vhdl-port-paste-instance
12448 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12449 (insert "\n")
12450 ;; paste custom statements
12451 (unless (equal "" vhdl-testbench-statements)
12452 (insert "\n")
12453 (setq position (point))
12454 (vhdl-insert-string-or-file vhdl-testbench-statements)
12455 (vhdl-indent-region position (point)))
12456 (insert "\n")
12457 (indent-to vhdl-basic-offset)
12458 (unless (eq vhdl-testbench-create-files 'none)
12459 (setq arch-buffer (current-buffer))
12460 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12461 (set-buffer arch-buffer) (save-buffer))
12462 (message "%s"
12463 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12464 ent-name arch-name)
12465 (and ent-file-name
12466 (format "\n File created: \"%s\"" ent-file-name))
12467 (and arch-file-name
12468 (format "\n File created: \"%s\"" arch-file-name)))))))
12471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12472 ;;; Subprogram interface translation
12473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12475 (defvar vhdl-subprog-list nil
12476 "Variable to hold last subprogram interface parsed.")
12477 ;; structure: (parenthesized expression means list of such entries)
12478 ;; (subprog-name kind
12479 ;; ((names) object direct type init comment group-comment)
12480 ;; return-type return-comment group-comment)
12482 (defvar vhdl-subprog-flattened nil
12483 "Indicates whether an subprogram interface has been flattened.")
12485 (defun vhdl-subprog-flatten ()
12486 "Flatten interface list so that only one parameter exists per line."
12487 (interactive)
12488 (if (not vhdl-subprog-list)
12489 (error "ERROR: No subprogram interface has been read")
12490 (message "Flattening subprogram interface...")
12491 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12492 new-subprog-list old-subprog new-subprog names)
12493 ;; traverse parameter list and flatten entries
12494 (while old-subprog-list
12495 (setq old-subprog (car old-subprog-list))
12496 (setq names (car old-subprog))
12497 (while names
12498 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12499 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12500 (setq names (cdr names)))
12501 (setq old-subprog-list (cdr old-subprog-list)))
12502 (setq vhdl-subprog-list
12503 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12504 new-subprog-list (nth 3 vhdl-subprog-list)
12505 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12506 vhdl-subprog-flattened t)
12507 (message "Flattening subprogram interface...done"))))
12509 (defun vhdl-subprog-copy ()
12510 "Get interface information from a subprogram specification."
12511 (interactive)
12512 (save-excursion
12513 (let (parse-error pos end-of-list
12514 name kind param-list object names direct type init
12515 comment group-comment
12516 return-type return-comment return-group-comment)
12517 (vhdl-prepare-search-2
12518 (setq
12519 parse-error
12520 (catch 'parse
12521 ;; check if within function declaration
12522 (setq pos (point))
12523 (end-of-line)
12524 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12525 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12526 (goto-char (match-end 0))
12527 (save-excursion (backward-char)
12528 (forward-sexp)
12529 (<= pos (point))))
12530 (throw 'parse "ERROR: Not within a subprogram specification"))
12531 (setq name (match-string-no-properties 5))
12532 (setq kind (if (match-string 2) 'procedure 'function))
12533 (setq end-of-list (not (match-string 7)))
12534 (message "Reading interface of subprogram \"%s\"..." name)
12535 ;; parse parameter list
12536 (setq group-comment (vhdl-parse-group-comment))
12537 (setq end-of-list (or end-of-list
12538 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12539 (while (not end-of-list)
12540 ;; parse object
12541 (setq object
12542 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12543 (match-string-no-properties 1)))
12544 ;; parse names (accept extended identifiers)
12545 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12546 (setq names (list (match-string-no-properties 1)))
12547 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12548 (setq names (append names (list (match-string-no-properties 1)))))
12549 ;; parse direction
12550 (vhdl-parse-string ":[ \t\n\r\f]*")
12551 (setq direct
12552 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12553 (match-string-no-properties 1)))
12554 ;; parse type
12555 (vhdl-parse-string "\\([^():;\n]+\\)")
12556 (setq type (match-string-no-properties 1))
12557 (setq comment nil)
12558 (while (looking-at "(")
12559 (setq type
12560 (concat type
12561 (buffer-substring-no-properties
12562 (point) (progn (forward-sexp) (point)))
12563 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12564 (match-string-no-properties 1)))))
12565 ;; special case: closing parenthesis is on separate line
12566 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12567 (setq comment (substring type (match-beginning 2)))
12568 (setq type (substring type 0 (match-beginning 1))))
12569 ;; strip off trailing group-comment
12570 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12571 (setq type (substring type 0 (match-end 1)))
12572 ;; parse initialization expression
12573 (setq init nil)
12574 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12575 (vhdl-parse-string "\\([^();\n]*\\)")
12576 (setq init (match-string-no-properties 1))
12577 (while (looking-at "(")
12578 (setq init
12579 (concat init
12580 (buffer-substring-no-properties
12581 (point) (progn (forward-sexp) (point)))
12582 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12583 (match-string-no-properties 1))))))
12584 ;; special case: closing parenthesis is on separate line
12585 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12586 (setq comment (substring init (match-beginning 2)))
12587 (setq init (substring init 0 (match-beginning 1)))
12588 (vhdl-forward-syntactic-ws))
12589 (skip-chars-forward " \t")
12590 ;; parse inline comment, special case: as above, no initial.
12591 (unless comment
12592 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12593 (match-string-no-properties 1))))
12594 (vhdl-forward-syntactic-ws)
12595 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12596 ;; parse inline comment
12597 (unless comment
12598 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12599 (match-string-no-properties 1))))
12600 (setq return-group-comment (vhdl-parse-group-comment))
12601 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12602 ;; parse return type
12603 (when (match-string 3)
12604 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12605 (setq return-type (match-string-no-properties 1))
12606 (when (and return-type
12607 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12608 (setq return-comment (substring return-type (match-beginning 2)))
12609 (setq return-type (substring return-type 0 (match-beginning 1))))
12610 ;; strip of trailing group-comment
12611 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12612 (setq return-type (substring return-type 0 (match-end 1)))
12613 ;; parse return comment
12614 (unless return-comment
12615 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12616 (match-string-no-properties 1)))))
12617 ;; parse inline comment
12618 (unless comment
12619 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12620 (match-string-no-properties 1))))
12621 ;; save everything in list
12622 (setq param-list (append param-list
12623 (list (list names object direct type init
12624 comment group-comment))))
12625 ;; parse group comment and spacing
12626 (setq group-comment (vhdl-parse-group-comment)))
12627 (message "Reading interface of subprogram \"%s\"...done" name)
12628 nil)))
12629 ;; finish parsing
12630 (if parse-error
12631 (error parse-error)
12632 (setq vhdl-subprog-list
12633 (list name kind param-list return-type return-comment
12634 return-group-comment)
12635 vhdl-subprog-flattened nil)))))
12637 (defun vhdl-subprog-paste-specification (kind)
12638 "Paste as a subprogram specification."
12639 (indent-according-to-mode)
12640 (let ((margin (current-column))
12641 (param-list (nth 2 vhdl-subprog-list))
12642 list-margin start names param)
12643 ;; paste keyword and name
12644 (vhdl-insert-keyword
12645 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12646 (insert (nth 0 vhdl-subprog-list))
12647 (if (not param-list)
12648 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12649 (setq start (point))
12650 ;; paste parameter list
12651 (insert " (")
12652 (unless vhdl-argument-list-indent
12653 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12654 (setq list-margin (current-column))
12655 (while param-list
12656 (setq param (car param-list))
12657 ;; paste group comment and spacing
12658 (when (memq vhdl-include-group-comments (list kind 'always))
12659 (vhdl-paste-group-comment (nth 6 param) list-margin))
12660 ;; paste object
12661 (when (nth 1 param) (insert (nth 1 param) " "))
12662 ;; paste names
12663 (setq names (nth 0 param))
12664 (while names
12665 (insert (car names))
12666 (setq names (cdr names))
12667 (when names (insert ", ")))
12668 ;; paste direction
12669 (insert " : ")
12670 (when (nth 2 param) (insert (nth 2 param) " "))
12671 ;; paste type
12672 (insert (nth 3 param))
12673 ;; paste initialization
12674 (when (nth 4 param) (insert " := " (nth 4 param)))
12675 ;; terminate line
12676 (if (cdr param-list)
12677 (insert ";")
12678 (insert ")")
12679 (when (null (nth 3 vhdl-subprog-list))
12680 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12681 ;; paste comment
12682 (when (and vhdl-include-port-comments (nth 5 param))
12683 (vhdl-comment-insert-inline (nth 5 param) t))
12684 (setq param-list (cdr param-list))
12685 (when param-list (insert "\n") (indent-to list-margin)))
12686 (when (nth 3 vhdl-subprog-list)
12687 (insert "\n") (indent-to list-margin)
12688 ;; paste group comment and spacing
12689 (when (memq vhdl-include-group-comments (list kind 'always))
12690 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12691 ;; paste return type
12692 (insert "return " (nth 3 vhdl-subprog-list))
12693 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12694 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12695 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12696 ;; align parameter list
12697 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12698 ;; paste body
12699 (when (eq kind 'body)
12700 (insert "\n")
12701 (vhdl-template-begin-end
12702 (unless (vhdl-standard-p '87)
12703 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12704 (nth 0 vhdl-subprog-list) margin))))
12706 (defun vhdl-subprog-paste-declaration ()
12707 "Paste as a subprogram declaration."
12708 (interactive)
12709 (if (not vhdl-subprog-list)
12710 (error "ERROR: No subprogram interface read")
12711 (message "Pasting interface as subprogram declaration \"%s\"..."
12712 (car vhdl-subprog-list))
12713 ;; paste specification
12714 (vhdl-subprog-paste-specification 'decl)
12715 (message "Pasting interface as subprogram declaration \"%s\"...done"
12716 (car vhdl-subprog-list))))
12718 (defun vhdl-subprog-paste-body ()
12719 "Paste as a subprogram body."
12720 (interactive)
12721 (if (not vhdl-subprog-list)
12722 (error "ERROR: No subprogram interface read")
12723 (message "Pasting interface as subprogram body \"%s\"..."
12724 (car vhdl-subprog-list))
12725 ;; paste specification and body
12726 (vhdl-subprog-paste-specification 'body)
12727 (message "Pasting interface as subprogram body \"%s\"...done"
12728 (car vhdl-subprog-list))))
12730 (defun vhdl-subprog-paste-call ()
12731 "Paste as a subprogram call."
12732 (interactive)
12733 (if (not vhdl-subprog-list)
12734 (error "ERROR: No subprogram interface read")
12735 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12736 param-list margin list-margin param start)
12737 ;; flatten local copy of interface list (must be flat for parameter mapping)
12738 (vhdl-subprog-flatten)
12739 (setq param-list (nth 2 vhdl-subprog-list))
12740 (indent-according-to-mode)
12741 (setq margin (current-indentation))
12742 (message "Pasting interface as subprogram call \"%s\"..."
12743 (car vhdl-subprog-list))
12744 ;; paste name
12745 (insert (nth 0 vhdl-subprog-list))
12746 (if (not param-list)
12747 (insert ";")
12748 (setq start (point))
12749 ;; paste parameter list
12750 (insert " (")
12751 (unless vhdl-argument-list-indent
12752 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12753 (setq list-margin (current-column))
12754 (while param-list
12755 (setq param (car param-list))
12756 ;; paste group comment and spacing
12757 (when (eq vhdl-include-group-comments 'always)
12758 (vhdl-paste-group-comment (nth 6 param) list-margin))
12759 ;; paste formal port
12760 (insert (car (nth 0 param)) " => ")
12761 (setq param-list (cdr param-list))
12762 (insert (if param-list "," ");"))
12763 ;; paste comment
12764 (when (and vhdl-include-port-comments (nth 5 param))
12765 (vhdl-comment-insert-inline (nth 5 param)))
12766 (when param-list (insert "\n") (indent-to list-margin)))
12767 ;; align parameter list
12768 (when vhdl-auto-align
12769 (vhdl-align-region-groups start (point) 1)))
12770 (message "Pasting interface as subprogram call \"%s\"...done"
12771 (car vhdl-subprog-list))
12772 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12775 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12776 ;;; Miscellaneous
12777 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12780 ;; Hippie expand customization
12782 (defvar vhdl-expand-upper-case nil)
12784 (defun vhdl-try-expand-abbrev (old)
12785 "Try expanding abbreviations from `vhdl-abbrev-list'."
12786 (unless old
12787 (he-init-string (he-dabbrev-beg) (point))
12788 (setq he-expand-list
12789 (let ((abbrev-list vhdl-abbrev-list)
12790 (sel-abbrev-list '()))
12791 (while abbrev-list
12792 (when (or (not (stringp (car abbrev-list)))
12793 (string-match
12794 (concat "^" he-search-string) (car abbrev-list)))
12795 (setq sel-abbrev-list
12796 (cons (car abbrev-list) sel-abbrev-list)))
12797 (setq abbrev-list (cdr abbrev-list)))
12798 (nreverse sel-abbrev-list))))
12799 (while (and he-expand-list
12800 (or (not (stringp (car he-expand-list)))
12801 (he-string-member (car he-expand-list) he-tried-table t)))
12802 (unless (stringp (car he-expand-list))
12803 (setq vhdl-expand-upper-case (car he-expand-list)))
12804 (setq he-expand-list (cdr he-expand-list)))
12805 (if (null he-expand-list)
12806 (progn (when old (he-reset-string))
12807 nil)
12808 (he-substitute-string
12809 (if vhdl-expand-upper-case
12810 (upcase (car he-expand-list))
12811 (car he-expand-list))
12813 (setq he-expand-list (cdr he-expand-list))
12816 (defun vhdl-he-list-beg ()
12817 "Also looks at the word before `(' in order to better match parenthesized
12818 expressions (e.g. for index ranges of types and signals)."
12819 (save-excursion
12820 (condition-case ()
12821 (progn (backward-up-list 1)
12822 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12823 (error ()))
12824 (point)))
12826 ;; override `he-list-beg' from `hippie-exp'
12827 (unless (and (boundp 'viper-mode) viper-mode)
12828 (defalias 'he-list-beg 'vhdl-he-list-beg))
12830 ;; function for expanding abbrevs and dabbrevs
12831 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12832 '(try-expand-dabbrev
12833 try-expand-dabbrev-all-buffers
12834 vhdl-try-expand-abbrev)))
12836 ;; function for expanding parenthesis
12837 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12838 '(try-expand-list
12839 try-expand-list-all-buffers)))
12841 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12842 ;; Line handling functions
12844 (defun vhdl-current-line ()
12845 "Return the line number of the line containing point."
12846 (save-restriction
12847 (widen)
12848 (1+ (count-lines (point-min) (point-at-bol)))))
12850 (defun vhdl-line-kill-entire (&optional arg)
12851 "Delete entire line."
12852 (interactive "p")
12853 (beginning-of-line)
12854 (kill-line (or arg 1)))
12856 (defun vhdl-line-kill (&optional arg)
12857 "Kill current line."
12858 (interactive "p")
12859 (vhdl-line-kill-entire arg))
12861 (defun vhdl-line-copy (&optional arg)
12862 "Copy current line."
12863 (interactive "p")
12864 (save-excursion
12865 (let ((position (point-at-bol)))
12866 (forward-line (or arg 1))
12867 (copy-region-as-kill position (point)))))
12869 (defun vhdl-line-yank ()
12870 "Yank entire line."
12871 (interactive)
12872 (beginning-of-line)
12873 (yank))
12875 (defun vhdl-line-expand (&optional prefix-arg)
12876 "Hippie-expand current line."
12877 (interactive "P")
12878 (require 'hippie-exp)
12879 (let ((case-fold-search t) (case-replace nil)
12880 (hippie-expand-try-functions-list
12881 '(try-expand-line try-expand-line-all-buffers)))
12882 (hippie-expand prefix-arg)))
12884 (defun vhdl-line-transpose-next (&optional arg)
12885 "Interchange this line with next line."
12886 (interactive "p")
12887 (forward-line 1)
12888 (transpose-lines (or arg 1))
12889 (forward-line -1))
12891 (defun vhdl-line-transpose-previous (&optional arg)
12892 "Interchange this line with previous line."
12893 (interactive "p")
12894 (forward-line 1)
12895 (transpose-lines (- 0 (or arg 0)))
12896 (forward-line -1))
12898 (defun vhdl-line-open ()
12899 "Open a new line and indent."
12900 (interactive)
12901 (end-of-line -0)
12902 (newline-and-indent))
12904 (defun vhdl-delete-indentation ()
12905 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12906 it works within comments too."
12907 (interactive)
12908 (let ((fill-prefix "-- "))
12909 (delete-indentation)))
12911 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12912 ;; Move functions
12914 (defun vhdl-forward-same-indent ()
12915 "Move forward to next line with same indent."
12916 (interactive)
12917 (let ((pos (point))
12918 (indent (current-indentation)))
12919 (beginning-of-line 2)
12920 (while (and (not (eobp))
12921 (or (looking-at "^\\s-*\\(--.*\\)?$")
12922 (> (current-indentation) indent)))
12923 (beginning-of-line 2))
12924 (if (= (current-indentation) indent)
12925 (back-to-indentation)
12926 (message "No following line with same indent found in this block")
12927 (goto-char pos)
12928 nil)))
12930 (defun vhdl-backward-same-indent ()
12931 "Move backward to previous line with same indent."
12932 (interactive)
12933 (let ((pos (point))
12934 (indent (current-indentation)))
12935 (beginning-of-line -0)
12936 (while (and (not (bobp))
12937 (or (looking-at "^\\s-*\\(--.*\\)?$")
12938 (> (current-indentation) indent)))
12939 (beginning-of-line -0))
12940 (if (= (current-indentation) indent)
12941 (back-to-indentation)
12942 (message "No preceding line with same indent found in this block")
12943 (goto-char pos)
12944 nil)))
12946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12947 ;; Statistics
12949 (defun vhdl-statistics-buffer ()
12950 "Get some file statistics."
12951 (interactive)
12952 (let ((no-stats 0)
12953 (no-code-lines 0)
12954 (no-empty-lines 0)
12955 (no-comm-lines 0)
12956 (no-comments 0)
12957 (no-lines (count-lines (point-min) (point-max))))
12958 (save-excursion
12959 ;; count statements
12960 (goto-char (point-min))
12961 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12962 (if (match-string 1)
12963 (goto-char (match-end 1))
12964 (setq no-stats (1+ no-stats))))
12965 ;; count code lines
12966 (goto-char (point-min))
12967 (while (not (eobp))
12968 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12969 (setq no-code-lines (1+ no-code-lines)))
12970 (beginning-of-line 2))
12971 ;; count empty lines
12972 (goto-char (point-min))
12973 (while (and (re-search-forward "^\\s-*$" nil t)
12974 (not (eq (point) (point-max))))
12975 (if (match-string 1)
12976 (goto-char (match-end 1))
12977 (setq no-empty-lines (1+ no-empty-lines))
12978 (unless (eq (point) (point-max))
12979 (forward-char))))
12980 ;; count comment-only lines
12981 (goto-char (point-min))
12982 (while (re-search-forward "^\\s-*--.*" nil t)
12983 (if (match-string 1)
12984 (goto-char (match-end 1))
12985 (setq no-comm-lines (1+ no-comm-lines))))
12986 ;; count comments
12987 (goto-char (point-min))
12988 (while (re-search-forward "--.*" nil t)
12989 (if (match-string 1)
12990 (goto-char (match-end 1))
12991 (setq no-comments (1+ no-comments)))))
12992 ;; print results
12993 (message "\n\
12994 File statistics: \"%s\"\n\
12995 -----------------------\n\
12996 # statements : %5d\n\
12997 # code lines : %5d\n\
12998 # empty lines : %5d\n\
12999 # comment lines : %5d\n\
13000 # comments : %5d\n\
13001 # total lines : %5d\n"
13002 (buffer-file-name) no-stats no-code-lines no-empty-lines
13003 no-comm-lines no-comments no-lines)
13004 (unless vhdl-emacs-21 (vhdl-show-messages))))
13006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13007 ;; Help functions
13009 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
13010 "Like `re-search-forward', but does not match within literals."
13011 (let (pos)
13012 (save-excursion
13013 (while (and (setq pos (re-search-forward regexp bound noerror count))
13014 (save-match-data (vhdl-in-literal)))))
13015 (when pos (goto-char pos))
13016 pos))
13018 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
13019 "Like `re-search-backward', but does not match within literals."
13020 (let (pos)
13021 (save-excursion
13022 (while (and (setq pos (re-search-backward regexp bound noerror count))
13023 (save-match-data (vhdl-in-literal)))))
13024 (when pos (goto-char pos))
13025 pos))
13028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13029 ;;; Project
13030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13032 (defun vhdl-set-project (name)
13033 "Set current project to NAME."
13034 (interactive
13035 (list (let ((completion-ignore-case t))
13036 (completing-read "Project name: " vhdl-project-alist nil t))))
13037 (cond ((equal name "")
13038 (setq vhdl-project nil)
13039 (message "Current VHDL project: None"))
13040 ((assoc name vhdl-project-alist)
13041 (setq vhdl-project name)
13042 (message "Current VHDL project: \"%s\"" name))
13044 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
13045 (vhdl-speedbar-update-current-project))
13047 (defun vhdl-set-default-project ()
13048 "Set current project as default on startup."
13049 (interactive)
13050 (customize-set-variable 'vhdl-project vhdl-project)
13051 (customize-save-customized))
13053 (defun vhdl-toggle-project (name token indent)
13054 "Set current project to NAME or unset if NAME is current project."
13055 (vhdl-set-project (if (equal name vhdl-project) "" name)))
13057 (defun vhdl-export-project (file-name)
13058 "Write project setup for current project."
13059 (interactive
13060 (let ((name (vhdl-resolve-env-variable
13061 (vhdl-replace-string
13062 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13063 (concat (subst-char-in-string
13064 ? ?_ (or (vhdl-project-p)
13065 (error "ERROR: No current project")))
13066 " " (user-login-name))))))
13067 (list (read-file-name
13068 "Write project file: "
13069 (when (file-name-absolute-p name) "") nil nil name))))
13070 (setq file-name (abbreviate-file-name file-name))
13071 (let ((orig-buffer (current-buffer)))
13072 (unless (file-exists-p (file-name-directory file-name))
13073 (make-directory (file-name-directory file-name) t))
13074 (if (not (file-writable-p file-name))
13075 (error "ERROR: File not writable: \"%s\"" file-name)
13076 (set-buffer (find-file-noselect file-name t t))
13077 (erase-buffer)
13078 (insert ";; -*- Emacs-Lisp -*-\n\n"
13079 ";;; " (file-name-nondirectory file-name)
13080 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
13081 ";; Project : " vhdl-project "\n"
13082 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
13083 (user-login-name) "\n\n\n"
13084 ";; project name\n"
13085 "(setq vhdl-project \"" vhdl-project "\")\n\n"
13086 ";; project setup\n"
13087 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
13088 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
13089 (insert ")\n")
13090 (save-buffer)
13091 (kill-buffer (current-buffer))
13092 (set-buffer orig-buffer))))
13094 (defun vhdl-import-project (file-name &optional auto not-make-current)
13095 "Read project setup and set current project."
13096 (interactive
13097 (let ((name (vhdl-resolve-env-variable
13098 (vhdl-replace-string
13099 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13100 (concat "" " " (user-login-name))))))
13101 (list (read-file-name
13102 "Read project file: " (when (file-name-absolute-p name) "") nil t
13103 (file-name-directory name)))))
13104 (when (file-exists-p file-name)
13105 (condition-case ()
13106 (let ((current-project vhdl-project))
13107 (load-file file-name)
13108 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
13109 (vhdl-adelete 'vhdl-project-alist vhdl-project)
13110 (error ""))
13111 (if not-make-current
13112 (setq vhdl-project current-project)
13113 (setq vhdl-compiler
13114 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
13115 (vhdl-update-mode-menu)
13116 (vhdl-speedbar-refresh)
13117 (unless not-make-current
13118 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
13119 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
13120 (error (vhdl-warning
13121 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
13123 (defun vhdl-duplicate-project ()
13124 "Duplicate setup of current project."
13125 (interactive)
13126 (let ((new-name (read-from-minibuffer "New project name: "))
13127 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
13128 (setq vhdl-project-alist
13129 (append vhdl-project-alist
13130 (list (cons new-name project-entry))))
13131 (vhdl-update-mode-menu)))
13133 (defun vhdl-auto-load-project ()
13134 "Automatically load project setup at startup."
13135 (let ((file-name-list vhdl-project-file-name)
13136 file-list list-length)
13137 (while file-name-list
13138 (setq file-list
13139 (append file-list
13140 (file-expand-wildcards
13141 (vhdl-resolve-env-variable
13142 (vhdl-replace-string
13143 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
13144 (concat "* " (user-login-name)))))))
13145 (setq list-length (or list-length (length file-list)))
13146 (setq file-name-list (cdr file-name-list)))
13147 (while file-list
13148 (vhdl-import-project (expand-file-name (car file-list)) t
13149 (not (> list-length 0)))
13150 (setq list-length (1- list-length))
13151 (setq file-list (cdr file-list)))))
13153 ;; automatically load project setup when idle after startup
13154 (when (memq 'startup vhdl-project-auto-load)
13155 (if noninteractive
13156 (vhdl-auto-load-project)
13157 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13161 ;;; Hideshow
13162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13163 ;; (using `hideshow.el')
13165 (defconst vhdl-hs-start-regexp
13166 (concat
13167 "\\(^\\)\\s-*\\("
13168 ;; generic/port clause
13169 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13170 ;; component
13171 "component\\>\\|"
13172 ;; component instantiation
13173 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13174 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13175 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13176 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13177 ;; subprogram
13178 "\\(function\\|procedure\\)\\>\\|"
13179 ;; process, block
13180 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13181 ;; configuration declaration
13182 "configuration\\>"
13183 "\\)")
13184 "Regexp to match start of construct to hide.")
13186 (defun vhdl-hs-forward-sexp-func (count)
13187 "Find end of construct to hide (for hideshow). Only searches forward."
13188 (let ((pos (point)))
13189 (vhdl-prepare-search-2
13190 (beginning-of-line)
13191 (cond
13192 ;; generic/port clause
13193 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13194 (goto-char (match-end 0))
13195 (backward-char)
13196 (forward-sexp))
13197 ;; component declaration
13198 ((looking-at "^\\s-*component\\>")
13199 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13200 ;; component instantiation
13201 ((looking-at
13202 (concat
13203 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13204 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13205 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13206 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13207 (goto-char (match-end 0))
13208 (backward-char)
13209 (forward-sexp)
13210 (setq pos (point))
13211 (vhdl-forward-syntactic-ws)
13212 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13213 (goto-char (match-end 0))
13214 (backward-char)
13215 (forward-sexp)
13216 (setq pos (point)))
13217 (goto-char pos))
13218 ;; subprogram declaration/body
13219 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13220 (goto-char (match-end 0))
13221 (vhdl-forward-syntactic-ws)
13222 (when (looking-at "(")
13223 (forward-sexp))
13224 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13225 (vhdl-in-literal)))
13226 ;; subprogram body
13227 (when (match-string 2)
13228 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13229 (backward-word-strictly 1)
13230 (vhdl-forward-sexp)))
13231 ;; block (recursive)
13232 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13233 (goto-char (match-end 0))
13234 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13235 (match-beginning 2))
13236 (vhdl-hs-forward-sexp-func count)))
13237 ;; process
13238 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13239 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13240 ;; configuration declaration
13241 ((looking-at "^\\s-*configuration\\>")
13242 (forward-word-strictly 4)
13243 (vhdl-forward-sexp))
13244 (t (goto-char pos))))))
13246 (defun vhdl-hideshow-init ()
13247 "Initialize `hideshow'."
13248 (when vhdl-hideshow-menu
13249 (vhdl-hs-minor-mode 1)))
13251 (defun vhdl-hs-minor-mode (&optional arg)
13252 "Toggle hideshow minor mode and update menu bar."
13253 (interactive "P")
13254 (require 'hideshow)
13255 ;; check for hideshow version 5.x
13256 (if (not (boundp 'hs-block-start-mdata-select))
13257 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13258 ;; initialize hideshow
13259 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13260 (setq hs-special-modes-alist
13261 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13262 'vhdl-hs-forward-sexp-func nil)
13263 hs-special-modes-alist)))
13264 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13265 (if vhdl-hide-all-init
13266 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13267 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13268 (hs-minor-mode arg)
13269 (force-mode-line-update))) ; hack to update menu bar
13272 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13273 ;;; Font locking
13274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13275 ;; (using `font-lock.el')
13277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13278 ;; Help functions
13280 (defun vhdl-within-translate-off ()
13281 "Return point if within translate-off region, else nil."
13282 (and (save-excursion
13283 (re-search-backward
13284 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13285 (equal "off" (match-string 1))
13286 (point)))
13288 (defun vhdl-start-translate-off (limit)
13289 "Return point before translate-off pragma if before LIMIT, else nil."
13290 (when (re-search-forward
13291 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13292 (match-beginning 0)))
13294 (defun vhdl-end-translate-off (limit)
13295 "Return point after translate-on pragma if before LIMIT, else nil."
13296 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13298 (defun vhdl-match-translate-off (limit)
13299 "Match a translate-off block, setting match-data and returning t, else nil."
13300 (when (< (point) limit)
13301 (let ((start (or (vhdl-within-translate-off)
13302 (vhdl-start-translate-off limit)))
13303 (case-fold-search t))
13304 (when start
13305 (let ((end (or (vhdl-end-translate-off limit) limit)))
13306 (set-match-data (list start end))
13307 (goto-char end))))))
13309 (defun vhdl-font-lock-match-item (limit)
13310 "Match, and move over, any declaration item after point. Adapted from
13311 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13312 (condition-case nil
13313 (save-restriction
13314 (narrow-to-region (point-min) limit)
13315 ;; match item
13316 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13317 (save-match-data
13318 (goto-char (match-end 1))
13319 ;; move to next item
13320 (if (looking-at "\\(\\s-*,\\)")
13321 (goto-char (match-end 1))
13322 (end-of-line) t))))
13323 (error t)))
13325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13326 ;; Syntax definitions
13328 (defconst vhdl-font-lock-syntactic-keywords
13329 '(("\\('\\).\\('\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13330 "Mark single quotes as having string quote syntax in `c' instances.")
13332 (defvar vhdl-font-lock-keywords nil
13333 "Regular expressions to highlight in VHDL Mode.")
13335 (defvar vhdl-font-lock-keywords-0
13336 ;; set in `vhdl-font-lock-init' because dependent on user options
13337 "For consideration as a value of `vhdl-font-lock-keywords'.
13338 This does highlighting of template prompts and directives (pragmas).")
13340 (defvar vhdl-font-lock-keywords-1 nil
13341 ;; set in `vhdl-font-lock-init' because dependent on user options
13342 "For consideration as a value of `vhdl-font-lock-keywords'.
13343 This does highlighting of keywords and standard identifiers.")
13345 (defconst vhdl-font-lock-keywords-2
13346 (list
13347 ;; highlight names of units, subprograms, and components when declared
13348 (list
13349 (concat
13350 "^\\s-*\\("
13351 "architecture\\|configuration\\|context\\|entity\\|package"
13352 "\\(\\s-+body\\)?\\|"
13353 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13354 "\\)\\s-+\\(\\w+\\)")
13355 5 'font-lock-function-name-face)
13357 ;; highlight entity names of architectures and configurations
13358 (list
13359 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13360 2 'font-lock-function-name-face)
13362 ;; highlight labels of common constructs
13363 (list
13364 (concat
13365 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13366 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13367 "postponed\\|process\\|"
13368 (when (vhdl-standard-p 'ams) "procedural\\|")
13369 "with\\|while"
13370 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13371 1 'font-lock-function-name-face)
13373 ;; highlight label and component name of component instantiations
13374 (list
13375 (concat
13376 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13377 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13378 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13380 ;; highlight label and instantiated unit of component instantiations
13381 (list
13382 (concat
13383 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13384 "\\(component\\|configuration\\|entity\\)\\s-+"
13385 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13386 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13387 '(5 font-lock-function-name-face nil t)
13388 '(7 font-lock-function-name-face nil t))
13390 ;; highlight names and labels at end of constructs
13391 (list
13392 (concat
13393 "^\\s-*end\\s-+\\(\\("
13394 "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
13395 "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
13396 "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
13397 (when (vhdl-standard-p 'ams) "procedural\\|")
13398 "units"
13399 "\\)\\s-+\\)?\\(\\w*\\)")
13400 5 'font-lock-function-name-face)
13402 ;; highlight labels in exit and next statements
13403 (list
13404 (concat
13405 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13406 3 'font-lock-function-name-face)
13408 ;; highlight entity name in attribute specifications
13409 (list
13410 (concat
13411 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13412 1 'font-lock-function-name-face)
13414 ;; highlight labels in block and component specifications
13415 (list
13416 (concat
13417 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13418 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13419 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13421 ;; highlight names in library clauses
13422 (list "^\\s-*library\\>"
13423 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13425 ;; highlight names in use clauses
13426 (list
13427 (concat
13428 "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13429 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13430 '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
13431 '(8 font-lock-function-name-face nil t))
13433 ;; highlight attribute name in attribute declarations/specifications
13434 (list
13435 (concat
13436 "^\\s-*attribute\\s-+\\(\\w+\\)")
13437 1 'vhdl-font-lock-attribute-face)
13439 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13440 (list
13441 (concat
13442 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13443 5 'font-lock-type-face)
13445 ;; highlight signal/variable/constant declaration names
13446 (list "\\(:[^=]\\)"
13447 '(vhdl-font-lock-match-item
13448 (progn (goto-char (match-beginning 1))
13449 (skip-syntax-backward " ")
13450 (skip-syntax-backward "w_")
13451 (skip-syntax-backward " ")
13452 (while (= (preceding-char) ?,)
13453 (backward-char 1)
13454 (skip-syntax-backward " ")
13455 (skip-syntax-backward "w_")
13456 (skip-syntax-backward " ")))
13457 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13459 ;; highlight formal parameters in component instantiations and subprogram
13460 ;; calls
13461 (list "\\(=>\\)"
13462 '(vhdl-font-lock-match-item
13463 (progn (goto-char (match-beginning 1))
13464 (skip-syntax-backward " ")
13465 (while (= (preceding-char) ?\)) (backward-sexp))
13466 (skip-syntax-backward "w_")
13467 (skip-syntax-backward " ")
13468 (when (memq (preceding-char) '(?n ?N ?|))
13469 (goto-char (point-max))))
13470 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13472 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13473 ;; variables
13474 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13475 '(vhdl-font-lock-match-item
13476 (progn (goto-char (match-end 1)) (match-beginning 2))
13477 nil (1 font-lock-variable-name-face)))
13479 ;; highlight tool directives
13480 (list
13481 (concat
13482 "^\\s-*\\(`\\w+\\)")
13483 1 'font-lock-preprocessor-face)
13485 "For consideration as a value of `vhdl-font-lock-keywords'.
13486 This does context sensitive highlighting of names and labels.")
13488 (defvar vhdl-font-lock-keywords-3 nil
13489 ;; set in `vhdl-font-lock-init' because dependent on user options
13490 "For consideration as a value of `vhdl-font-lock-keywords'.
13491 This does highlighting of words with special syntax.")
13493 (defvar vhdl-font-lock-keywords-4 nil
13494 ;; set in `vhdl-font-lock-init' because dependent on user options
13495 "For consideration as a value of `vhdl-font-lock-keywords'.
13496 This does highlighting of additional reserved words.")
13498 (defconst vhdl-font-lock-keywords-5
13499 ;; background highlight translate-off regions
13500 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13501 "For consideration as a value of `vhdl-font-lock-keywords'.
13502 This does background highlighting of translate-off regions.")
13504 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13505 ;; Font and color definitions
13507 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13508 "Face name to use for prompts.")
13510 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13511 "Face name to use for standardized attributes.")
13513 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13514 "Face name to use for standardized enumeration values.")
13516 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13517 "Face name to use for standardized functions and packages.")
13519 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13520 "Face name to use for directives.")
13522 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13523 "Face name to use for additional reserved words.")
13525 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13526 "Face name to use for translate-off regions.")
13528 ;; face names to use for words with special syntax.
13529 (let ((syntax-alist vhdl-special-syntax-alist)
13530 name)
13531 (while syntax-alist
13532 (setq name (vhdl-function-name
13533 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13534 (eval `(defvar ,name ',name
13535 ,(concat "Face name to use for "
13536 (nth 0 (car syntax-alist)) ".")))
13537 (setq syntax-alist (cdr syntax-alist))))
13539 (defgroup vhdl-highlight-faces nil
13540 "Faces for highlighting."
13541 :group 'vhdl-highlight)
13543 ;; add faces used from `font-lock'
13544 (custom-add-to-group
13545 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13546 (custom-add-to-group
13547 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13548 (custom-add-to-group
13549 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13550 (custom-add-to-group
13551 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13552 (custom-add-to-group
13553 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13554 (custom-add-to-group
13555 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13557 (defface vhdl-font-lock-prompt-face
13558 '((((min-colors 88) (class color) (background light))
13559 (:foreground "Red1" :bold t))
13560 (((class color) (background light)) (:foreground "Red" :bold t))
13561 (((class color) (background dark)) (:foreground "Pink" :bold t))
13562 (t (:inverse-video t)))
13563 "Font lock mode face used to highlight prompts."
13564 :group 'vhdl-highlight-faces)
13566 (defface vhdl-font-lock-attribute-face
13567 '((((class color) (background light)) (:foreground "Orchid"))
13568 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13569 (t (:italic t :bold t)))
13570 "Font lock mode face used to highlight standardized attributes."
13571 :group 'vhdl-highlight-faces)
13573 (defface vhdl-font-lock-enumvalue-face
13574 '((((class color) (background light)) (:foreground "SaddleBrown"))
13575 (((class color) (background dark)) (:foreground "BurlyWood"))
13576 (t (:italic t :bold t)))
13577 "Font lock mode face used to highlight standardized enumeration values."
13578 :group 'vhdl-highlight-faces)
13580 (defface vhdl-font-lock-function-face
13581 '((((class color) (background light)) (:foreground "Cyan4"))
13582 (((class color) (background dark)) (:foreground "Orchid1"))
13583 (t (:italic t :bold t)))
13584 "Font lock mode face used to highlight standardized functions and packages."
13585 :group 'vhdl-highlight-faces)
13587 (defface vhdl-font-lock-directive-face
13588 '((((class color) (background light)) (:foreground "CadetBlue"))
13589 (((class color) (background dark)) (:foreground "Aquamarine"))
13590 (t (:italic t :bold t)))
13591 "Font lock mode face used to highlight directives."
13592 :group 'vhdl-highlight-faces)
13594 (defface vhdl-font-lock-reserved-words-face
13595 '((((class color) (background light)) (:foreground "Orange" :bold t))
13596 (((min-colors 88) (class color) (background dark))
13597 (:foreground "Yellow1" :bold t))
13598 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13599 (t ()))
13600 "Font lock mode face used to highlight additional reserved words."
13601 :group 'vhdl-highlight-faces)
13603 (defface vhdl-font-lock-translate-off-face
13604 '((((class color) (background light)) (:background "LightGray"))
13605 (((class color) (background dark)) (:background "DimGray"))
13606 (t ()))
13607 "Font lock mode face used to background highlight translate-off regions."
13608 :group 'vhdl-highlight-faces)
13610 ;; font lock mode faces used to highlight words with special syntax.
13611 (let ((syntax-alist vhdl-special-syntax-alist))
13612 (while syntax-alist
13613 (eval `(defface ,(vhdl-function-name
13614 "vhdl-font-lock" (caar syntax-alist) "face")
13615 '((((class color) (background light))
13616 (:foreground ,(nth 2 (car syntax-alist))))
13617 (((class color) (background dark))
13618 (:foreground ,(nth 3 (car syntax-alist))))
13619 (t ()))
13620 ,(concat "Font lock mode face used to highlight "
13621 (nth 0 (car syntax-alist)) ".")
13622 :group 'vhdl-highlight-faces))
13623 (setq syntax-alist (cdr syntax-alist))))
13625 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13626 ;; Font lock initialization
13628 (defun vhdl-font-lock-init ()
13629 "Initialize fontification."
13630 ;; highlight template prompts and directives
13631 (setq vhdl-font-lock-keywords-0
13632 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13633 vhdl-template-prompt-syntax ">\\)")
13634 2 'vhdl-font-lock-prompt-face t)
13635 (list (concat "--\\s-*"
13636 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13637 2 'vhdl-font-lock-directive-face t)
13638 ;; highlight c-preprocessor directives
13639 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13640 '(1 font-lock-builtin-face)
13641 '(3 font-lock-variable-name-face nil t))))
13642 ;; highlight keywords and standardized types, attributes, enumeration
13643 ;; values, and subprograms
13644 (setq vhdl-font-lock-keywords-1
13645 (list
13646 (list (concat "'" vhdl-attributes-regexp)
13647 1 'vhdl-font-lock-attribute-face)
13648 (list vhdl-types-regexp 1 'font-lock-type-face)
13649 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13650 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13651 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13652 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13653 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13654 ;; highlight words with special syntax.
13655 (setq vhdl-font-lock-keywords-3
13656 (let ((syntax-alist vhdl-special-syntax-alist)
13657 keywords)
13658 (while syntax-alist
13659 (setq keywords
13660 (cons
13661 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13662 (vhdl-function-name
13663 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13664 (nth 4 (car syntax-alist)))
13665 keywords))
13666 (setq syntax-alist (cdr syntax-alist)))
13667 keywords))
13668 ;; highlight additional reserved words
13669 (setq vhdl-font-lock-keywords-4
13670 (list (list vhdl-reserved-words-regexp 1
13671 'vhdl-font-lock-reserved-words-face)))
13672 ;; highlight everything together
13673 (setq vhdl-font-lock-keywords
13674 (append
13675 vhdl-font-lock-keywords-0
13676 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13677 (when (or vhdl-highlight-forbidden-words
13678 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13679 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13680 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13681 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13683 ;; initialize fontification for VHDL Mode
13684 (vhdl-font-lock-init)
13686 (defun vhdl-fontify-buffer ()
13687 "Re-initialize fontification and fontify buffer."
13688 (interactive)
13689 (setq font-lock-defaults
13690 `(vhdl-font-lock-keywords
13691 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13692 beginning-of-line))
13693 (when (fboundp 'font-lock-unset-defaults)
13694 (font-lock-unset-defaults)) ; not implemented in XEmacs
13695 (font-lock-set-defaults)
13696 (font-lock-mode nil)
13697 (font-lock-mode t))
13699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13700 ;; Initialization for PostScript printing
13702 (defun vhdl-ps-print-settings ()
13703 "Initialize custom face and page settings for PostScript printing."
13704 ;; define custom face settings
13705 (unless (or (not vhdl-print-customize-faces)
13706 ps-print-color-p)
13707 (set (make-local-variable 'ps-bold-faces)
13708 '(font-lock-keyword-face
13709 font-lock-type-face
13710 vhdl-font-lock-attribute-face
13711 vhdl-font-lock-enumvalue-face
13712 vhdl-font-lock-directive-face))
13713 (set (make-local-variable 'ps-italic-faces)
13714 '(font-lock-comment-face
13715 font-lock-function-name-face
13716 font-lock-type-face
13717 vhdl-font-lock-attribute-face
13718 vhdl-font-lock-enumvalue-face
13719 vhdl-font-lock-directive-face))
13720 (set (make-local-variable 'ps-underlined-faces)
13721 '(font-lock-string-face))
13722 (setq ps-always-build-face-reference t))
13723 ;; define page settings, so that a line containing 79 characters (default)
13724 ;; fits into one column
13725 (when vhdl-print-two-column
13726 (set (make-local-variable 'ps-landscape-mode) t)
13727 (set (make-local-variable 'ps-number-of-columns) 2)
13728 (set (make-local-variable 'ps-font-size) 7.0)
13729 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13730 (set (make-local-variable 'ps-header-font-size) 9.0)
13731 (set (make-local-variable 'ps-header-offset) 12.0)
13732 (when (eq ps-paper-type 'letter)
13733 (set (make-local-variable 'ps-inter-column) 40.0)
13734 (set (make-local-variable 'ps-left-margin) 40.0)
13735 (set (make-local-variable 'ps-right-margin) 40.0))))
13737 (defun vhdl-ps-print-init ()
13738 "Initialize PostScript printing."
13739 (if (featurep 'xemacs)
13740 (when (boundp 'ps-print-color-p)
13741 (vhdl-ps-print-settings))
13742 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13743 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13747 ;;; Hierarchy browser (using `speedbar.el')
13748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13749 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13750 ;; directory by using the speedbar.
13752 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13753 ;; Variables
13755 (defvar vhdl-entity-alist nil
13756 "Cache with entities and corresponding architectures for each
13757 project/directory.")
13758 ;; structure: (parenthesized expression means list of such entries)
13759 ;; (cache-key
13760 ;; (ent-key ent-name ent-file ent-line
13761 ;; (arch-key arch-name arch-file arch-line
13762 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13763 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13764 ;; (lib-name pack-key))
13765 ;; mra-key (lib-name pack-key))
13767 (defvar vhdl-config-alist nil
13768 "Cache with configurations for each project/directory.")
13769 ;; structure: (parenthesized expression means list of such entries)
13770 ;; (cache-key
13771 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13772 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13773 ;; inst-conf-key inst-lib-key)
13774 ;; (lib-name pack-key)))
13776 (defvar vhdl-package-alist nil
13777 "Cache with packages for each project/directory.")
13778 ;; structure: (parenthesized expression means list of such entries)
13779 ;; (cache-key
13780 ;; (pack-key pack-name pack-file pack-line
13781 ;; (comp-key comp-name comp-file comp-line)
13782 ;; (func-key func-name func-file func-line)
13783 ;; (lib-name pack-key)
13784 ;; pack-body-file pack-body-line
13785 ;; (func-key func-name func-body-file func-body-line)
13786 ;; (lib-name pack-key)))
13788 (defvar vhdl-ent-inst-alist nil
13789 "Cache with instantiated entities for each project/directory.")
13790 ;; structure: (parenthesized expression means list of such entries)
13791 ;; (cache-key (inst-ent-key))
13793 (defvar vhdl-file-alist nil
13794 "Cache with design units in each file for each project/directory.")
13795 ;; structure: (parenthesized expression means list of such entries)
13796 ;; (cache-key
13797 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13798 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13800 (defvar vhdl-directory-alist nil
13801 "Cache with source directories for each project.")
13802 ;; structure: (parenthesized expression means list of such entries)
13803 ;; (cache-key (directory))
13805 (defvar vhdl-speedbar-shown-unit-alist nil
13806 "Alist of design units simultaneously open in the current speedbar for each
13807 directory and project.")
13809 (defvar vhdl-speedbar-shown-project-list nil
13810 "List of projects simultaneously open in the current speedbar.")
13812 (defvar vhdl-updated-project-list nil
13813 "List of projects and directories with updated files.")
13815 (defvar vhdl-modified-file-list nil
13816 "List of modified files to be rescanned for hierarchy updating.")
13818 (defvar vhdl-speedbar-hierarchy-depth 0
13819 "Depth of instantiation hierarchy to display.")
13821 (defvar vhdl-speedbar-show-projects nil
13822 "Non-nil means project hierarchy is displayed in speedbar, directory
13823 hierarchy otherwise.")
13825 (defun vhdl-get-end-of-unit ()
13826 "Return position of end of current unit."
13827 (let ((pos (point)))
13828 (save-excursion
13829 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
13830 (save-excursion
13831 (goto-char (match-beginning 0))
13832 (vhdl-backward-syntactic-ws)
13833 (and (/= (preceding-char) ?\;) (not (bobp))))))
13834 (re-search-backward "^[ \t]*end\\>" pos 1)
13835 (point))))
13837 (defun vhdl-match-string-downcase (num &optional string)
13838 "Like `match-string-no-properties' with down-casing."
13839 (let ((match (match-string-no-properties num string)))
13840 (and match (downcase match))))
13843 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13844 ;; Scan functions
13846 (defun vhdl-scan-context-clause ()
13847 "Scan the context clause that precedes a design unit."
13848 (let (lib-alist)
13849 (save-excursion
13850 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
13851 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13852 (equal "USE" (upcase (match-string 1))))
13853 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13854 (push (cons (match-string-no-properties 1)
13855 (vhdl-match-string-downcase 2))
13856 lib-alist)))))
13857 lib-alist))
13859 (defun vhdl-scan-directory-contents (name &optional project update num-string
13860 non-final)
13861 "Scan contents of VHDL files in directory or file pattern NAME."
13862 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13863 (let* ((dir-name (match-string 1 name))
13864 (file-pattern (match-string 2 name))
13865 (is-directory (= 0 (length file-pattern)))
13866 (file-list
13867 (if update
13868 (list name)
13869 (if is-directory
13870 (vhdl-get-source-files t dir-name)
13871 (vhdl-directory-files
13872 dir-name t (wildcard-to-regexp file-pattern)))))
13873 (key (or project dir-name))
13874 (file-exclude-regexp
13875 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13876 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13877 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13878 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13879 ent-alist conf-alist pack-alist ent-inst-list file-alist
13880 tmp-list tmp-entry no-files files-exist big-files)
13881 (when (or project update)
13882 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13883 conf-alist (vhdl-aget vhdl-config-alist key)
13884 pack-alist (vhdl-aget vhdl-package-alist key)
13885 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13886 file-alist (vhdl-aget vhdl-file-alist key)))
13887 (when (and (not is-directory) (null file-list))
13888 (message "No such file: \"%s\"" name))
13889 (setq files-exist file-list)
13890 (when file-list
13891 (setq no-files (length file-list))
13892 (message "Scanning %s %s\"%s\"..."
13893 (if is-directory "directory" "files") (or num-string "") name)
13894 ;; exclude files
13895 (unless (equal file-exclude-regexp "")
13896 (let ((case-fold-search nil)
13897 file-tmp-list)
13898 (while file-list
13899 (unless (string-match file-exclude-regexp (car file-list))
13900 (push (car file-list) file-tmp-list))
13901 (setq file-list (cdr file-list)))
13902 (setq file-list (nreverse file-tmp-list))))
13903 ;; do for all files
13904 (while file-list
13905 (unless noninteractive
13906 (message "Scanning %s %s\"%s\"... (%2d%%)"
13907 (if is-directory "directory" "files")
13908 (or num-string "") name
13909 (floor (* 100.0 (- no-files (length file-list))) no-files)))
13910 (let ((file-name (abbreviate-file-name (car file-list)))
13911 ent-list arch-list arch-ent-list conf-list
13912 pack-list pack-body-list inst-list inst-ent-list)
13913 ;; scan file
13914 (vhdl-visit-file
13915 file-name nil
13916 (vhdl-prepare-search-2
13917 (save-excursion
13918 ;; scan for design units
13919 (if (and limit-design-file-size
13920 (< limit-design-file-size (buffer-size)))
13921 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13922 (setq big-files t))
13923 ;; scan for entities
13924 (goto-char (point-min))
13925 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13926 (let* ((ent-name (match-string-no-properties 1))
13927 (ent-key (downcase ent-name))
13928 (ent-entry (vhdl-aget ent-alist ent-key))
13929 (lib-alist (vhdl-scan-context-clause)))
13930 (if (nth 1 ent-entry)
13931 (vhdl-warning-when-idle
13932 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13933 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13934 file-name (vhdl-current-line))
13935 (push ent-key ent-list)
13936 (vhdl-aput 'ent-alist ent-key
13937 (list ent-name file-name (vhdl-current-line)
13938 (nth 3 ent-entry) (nth 4 ent-entry)
13939 lib-alist)))))
13940 ;; scan for architectures
13941 (goto-char (point-min))
13942 (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)
13943 (let* ((arch-name (match-string-no-properties 1))
13944 (arch-key (downcase arch-name))
13945 (ent-name (match-string-no-properties 2))
13946 (ent-key (downcase ent-name))
13947 (ent-entry (vhdl-aget ent-alist ent-key))
13948 (arch-alist (nth 3 ent-entry))
13949 (arch-entry (vhdl-aget arch-alist arch-key))
13950 (lib-arch-alist (vhdl-scan-context-clause)))
13951 (if arch-entry
13952 (vhdl-warning-when-idle
13953 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13954 arch-name ent-name (nth 1 arch-entry)
13955 (nth 2 arch-entry) file-name (vhdl-current-line))
13956 (setq arch-list (cons arch-key arch-list)
13957 arch-ent-list (cons ent-key arch-ent-list))
13958 (vhdl-aput 'arch-alist arch-key
13959 (list arch-name file-name (vhdl-current-line)
13960 nil lib-arch-alist))
13961 (vhdl-aput 'ent-alist ent-key
13962 (list (or (nth 0 ent-entry) ent-name)
13963 (nth 1 ent-entry) (nth 2 ent-entry)
13964 (vhdl-sort-alist arch-alist)
13965 arch-key (nth 5 ent-entry))))))
13966 ;; scan for configurations
13967 (goto-char (point-min))
13968 (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)
13969 (let* ((conf-name (match-string-no-properties 1))
13970 (conf-key (downcase conf-name))
13971 (conf-entry (vhdl-aget conf-alist conf-key))
13972 (ent-name (match-string-no-properties 2))
13973 (ent-key (downcase ent-name))
13974 (lib-alist (vhdl-scan-context-clause))
13975 (conf-line (vhdl-current-line))
13976 (end-of-unit (vhdl-get-end-of-unit))
13977 arch-key comp-conf-list inst-key-list
13978 inst-comp-key inst-ent-key inst-arch-key
13979 inst-conf-key inst-lib-key)
13980 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13981 (setq arch-key (vhdl-match-string-downcase 1)))
13982 (if conf-entry
13983 (vhdl-warning-when-idle
13984 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13985 conf-name ent-name (nth 1 conf-entry)
13986 (nth 2 conf-entry) file-name conf-line)
13987 (push conf-key conf-list)
13988 ;; scan for subconfigurations and subentities
13989 (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)
13990 (setq inst-comp-key (vhdl-match-string-downcase 3)
13991 inst-key-list (split-string
13992 (vhdl-match-string-downcase 1)
13993 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13994 (vhdl-forward-syntactic-ws)
13995 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13996 (setq
13997 inst-lib-key (vhdl-match-string-downcase 3)
13998 inst-ent-key (and (match-string 2)
13999 (vhdl-match-string-downcase 4))
14000 inst-arch-key (and (match-string 2)
14001 (vhdl-match-string-downcase 6))
14002 inst-conf-key (and (not (match-string 2))
14003 (vhdl-match-string-downcase 4)))
14004 (while inst-key-list
14005 (setq comp-conf-list
14006 (cons (list (car inst-key-list)
14007 inst-comp-key inst-ent-key
14008 inst-arch-key inst-conf-key
14009 inst-lib-key)
14010 comp-conf-list))
14011 (setq inst-key-list (cdr inst-key-list)))))
14012 (vhdl-aput 'conf-alist conf-key
14013 (list conf-name file-name conf-line ent-key
14014 arch-key comp-conf-list lib-alist)))))
14015 ;; scan for packages
14016 (goto-char (point-min))
14017 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
14018 (let* ((pack-name (match-string-no-properties 2))
14019 (pack-key (downcase pack-name))
14020 (is-body (match-string-no-properties 1))
14021 (pack-entry (vhdl-aget pack-alist pack-key))
14022 (pack-line (vhdl-current-line))
14023 (end-of-unit (vhdl-get-end-of-unit))
14024 comp-name func-name comp-alist func-alist lib-alist)
14025 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14026 (vhdl-warning-when-idle
14027 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
14028 (if is-body " body" "") pack-name
14029 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14030 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
14031 file-name (vhdl-current-line))
14032 ;; scan for context clauses
14033 (setq lib-alist (vhdl-scan-context-clause))
14034 ;; scan for component and subprogram declarations/bodies
14035 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
14036 (if (equal (upcase (match-string 1)) "COMPONENT")
14037 (setq comp-name (match-string-no-properties 2)
14038 comp-alist
14039 (cons (list (downcase comp-name) comp-name
14040 file-name (vhdl-current-line))
14041 comp-alist))
14042 (setq func-name (match-string-no-properties 2)
14043 func-alist
14044 (cons (list (downcase func-name) func-name
14045 file-name (vhdl-current-line))
14046 func-alist))))
14047 (setq func-alist (nreverse func-alist))
14048 (setq comp-alist (nreverse comp-alist))
14049 (if is-body
14050 (push pack-key pack-body-list)
14051 (push pack-key pack-list))
14052 (vhdl-aput
14053 'pack-alist pack-key
14054 (if is-body
14055 (list (or (nth 0 pack-entry) pack-name)
14056 (nth 1 pack-entry) (nth 2 pack-entry)
14057 (nth 3 pack-entry) (nth 4 pack-entry)
14058 (nth 5 pack-entry)
14059 file-name pack-line func-alist lib-alist)
14060 (list pack-name file-name pack-line
14061 comp-alist func-alist lib-alist
14062 (nth 6 pack-entry) (nth 7 pack-entry)
14063 (nth 8 pack-entry) (nth 9 pack-entry))))))))
14064 ;; scan for hierarchy
14065 (if (and limit-hier-file-size
14066 (< limit-hier-file-size (buffer-size)))
14067 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
14068 (setq big-files t))
14069 ;; scan for architectures
14070 (goto-char (point-min))
14071 (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)
14072 (let* ((ent-name (match-string-no-properties 2))
14073 (ent-key (downcase ent-name))
14074 (arch-name (match-string-no-properties 1))
14075 (arch-key (downcase arch-name))
14076 (ent-entry (vhdl-aget ent-alist ent-key))
14077 (arch-alist (nth 3 ent-entry))
14078 (arch-entry (vhdl-aget arch-alist arch-key))
14079 (beg-of-unit (point))
14080 (end-of-unit (vhdl-get-end-of-unit))
14081 (inst-no 0)
14082 inst-alist inst-path)
14083 ;; scan for contained instantiations
14084 (while (and (re-search-forward
14085 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
14086 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
14087 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
14088 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
14089 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
14090 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
14091 (or (not limit-hier-inst-no)
14092 (<= (if (or (match-string 14)
14093 (match-string 16))
14094 inst-no
14095 (setq inst-no (1+ inst-no)))
14096 limit-hier-inst-no)))
14097 (cond
14098 ;; block/generate beginning found
14099 ((match-string 14)
14100 (setq inst-path
14101 (cons (match-string-no-properties 1) inst-path)))
14102 ;; block/generate end found
14103 ((match-string 16)
14104 (setq inst-path (cdr inst-path)))
14105 ;; instantiation found
14107 (let* ((inst-name (match-string-no-properties 1))
14108 (inst-key (downcase inst-name))
14109 (inst-comp-name
14110 (or (match-string-no-properties 3)
14111 (match-string-no-properties 6)))
14112 (inst-ent-key
14113 (or (and (match-string 8)
14114 (vhdl-match-string-downcase 11))
14115 (and inst-comp-name
14116 (downcase inst-comp-name))))
14117 (inst-arch-key (vhdl-match-string-downcase 13))
14118 (inst-conf-key
14119 (and (not (match-string 8))
14120 (vhdl-match-string-downcase 11)))
14121 (inst-lib-key (vhdl-match-string-downcase 10)))
14122 (goto-char (match-end 1))
14123 (setq inst-list (cons inst-key inst-list)
14124 inst-ent-list
14125 (cons inst-ent-key inst-ent-list))
14126 (setq inst-alist
14127 (append
14128 inst-alist
14129 (list (list inst-key inst-name file-name
14130 (vhdl-current-line) inst-comp-name
14131 inst-ent-key inst-arch-key
14132 inst-conf-key inst-lib-key
14133 (reverse inst-path)))))))))
14134 ;; scan for contained configuration specifications
14135 (goto-char beg-of-unit)
14136 (while (re-search-forward
14137 (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]*\\)*"
14138 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
14139 (let* ((inst-comp-name (match-string-no-properties 3))
14140 (inst-ent-key
14141 (and (match-string 6)
14142 (vhdl-match-string-downcase 9)))
14143 (inst-arch-key (vhdl-match-string-downcase 11))
14144 (inst-conf-key
14145 (and (not (match-string 6))
14146 (vhdl-match-string-downcase 9)))
14147 (inst-lib-key (vhdl-match-string-downcase 8))
14148 (inst-key-list
14149 (split-string (vhdl-match-string-downcase 1)
14150 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
14151 (tmp-inst-alist inst-alist)
14152 inst-entry)
14153 (while tmp-inst-alist
14154 (when (and (or (equal "all" (car inst-key-list))
14155 (member (nth 0 (car tmp-inst-alist))
14156 inst-key-list))
14157 (equal
14158 (downcase
14159 (or (nth 4 (car tmp-inst-alist)) ""))
14160 (downcase inst-comp-name)))
14161 (setq inst-entry (car tmp-inst-alist))
14162 (setq inst-ent-list
14163 (cons (or inst-ent-key (nth 5 inst-entry))
14164 (vhdl-delete
14165 (nth 5 inst-entry) inst-ent-list)))
14166 (setq inst-entry
14167 (list (nth 0 inst-entry) (nth 1 inst-entry)
14168 (nth 2 inst-entry) (nth 3 inst-entry)
14169 (nth 4 inst-entry)
14170 (or inst-ent-key (nth 5 inst-entry))
14171 (or inst-arch-key (nth 6 inst-entry))
14172 inst-conf-key inst-lib-key))
14173 (setcar tmp-inst-alist inst-entry))
14174 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14175 ;; save in cache
14176 (vhdl-aput 'arch-alist arch-key
14177 (list (nth 0 arch-entry) (nth 1 arch-entry)
14178 (nth 2 arch-entry) inst-alist
14179 (nth 4 arch-entry)))
14180 (vhdl-aput 'ent-alist ent-key
14181 (list (nth 0 ent-entry) (nth 1 ent-entry)
14182 (nth 2 ent-entry)
14183 (vhdl-sort-alist arch-alist)
14184 (nth 4 ent-entry) (nth 5 ent-entry)))
14185 (when (and limit-hier-inst-no
14186 (> inst-no limit-hier-inst-no))
14187 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14188 (setq big-files t))
14189 (goto-char end-of-unit))))
14190 ;; remember design units for this file
14191 (vhdl-aput 'file-alist file-name
14192 (list ent-list arch-list arch-ent-list conf-list
14193 pack-list pack-body-list
14194 inst-list inst-ent-list))
14195 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14196 (setq file-list (cdr file-list))))
14197 (when (or (and (not project) files-exist)
14198 (and project (not non-final)))
14199 ;; consistency checks:
14200 ;; check whether each architecture has a corresponding entity
14201 (setq tmp-list ent-alist)
14202 (while tmp-list
14203 (when (null (nth 2 (car tmp-list)))
14204 (setq tmp-entry (car (nth 4 (car tmp-list))))
14205 (vhdl-warning-when-idle
14206 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14207 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14208 (nth 3 tmp-entry)))
14209 (setq tmp-list (cdr tmp-list)))
14210 ;; check whether configuration has a corresponding entity/architecture
14211 (setq tmp-list conf-alist)
14212 (while tmp-list
14213 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14214 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14215 (setq tmp-entry (car tmp-list))
14216 (vhdl-warning-when-idle
14217 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14218 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14219 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14220 (setq tmp-entry (car tmp-list))
14221 (vhdl-warning-when-idle
14222 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14223 (nth 1 tmp-entry) (nth 4 tmp-entry)
14224 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14225 (setq tmp-list (cdr tmp-list)))
14226 ;; check whether each package body has a package declaration
14227 (setq tmp-list pack-alist)
14228 (while tmp-list
14229 (when (null (nth 2 (car tmp-list)))
14230 (setq tmp-entry (car tmp-list))
14231 (vhdl-warning-when-idle
14232 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14233 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14234 (setq tmp-list (cdr tmp-list)))
14235 ;; sort lists
14236 (setq ent-alist (vhdl-sort-alist ent-alist))
14237 (setq conf-alist (vhdl-sort-alist conf-alist))
14238 (setq pack-alist (vhdl-sort-alist pack-alist))
14239 ;; remember updated directory/project
14240 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14241 ;; clear directory alists
14242 (unless project
14243 (vhdl-adelete 'vhdl-entity-alist key)
14244 (vhdl-adelete 'vhdl-config-alist key)
14245 (vhdl-adelete 'vhdl-package-alist key)
14246 (vhdl-adelete 'vhdl-ent-inst-alist key)
14247 (vhdl-adelete 'vhdl-file-alist key))
14248 ;; put directory contents into cache
14249 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14250 (vhdl-aput 'vhdl-config-alist key conf-alist)
14251 (vhdl-aput 'vhdl-package-alist key pack-alist)
14252 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14253 (vhdl-aput 'vhdl-file-alist key file-alist)
14254 ;; final messages
14255 (message "Scanning %s %s\"%s\"...done"
14256 (if is-directory "directory" "files") (or num-string "") name)
14257 (unless project (message "Scanning directory...done"))
14258 (when big-files
14259 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14260 ;; save cache when scanned non-interactively
14261 (when (or (not project) (not non-final))
14262 (when (and noninteractive vhdl-speedbar-save-cache)
14263 (vhdl-save-cache key)))
14266 (defun vhdl-scan-project-contents (project)
14267 "Scan the contents of all VHDL files found in the directories and files
14268 of PROJECT."
14269 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14270 (default-dir (vhdl-resolve-env-variable
14271 (nth 1 (vhdl-aget vhdl-project-alist project))))
14272 (file-exclude-regexp
14273 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14274 dir-list-tmp dir dir-name num-dir act-dir recursive)
14275 ;; clear project alists
14276 (vhdl-adelete 'vhdl-entity-alist project)
14277 (vhdl-adelete 'vhdl-config-alist project)
14278 (vhdl-adelete 'vhdl-package-alist project)
14279 (vhdl-adelete 'vhdl-ent-inst-alist project)
14280 (vhdl-adelete 'vhdl-file-alist project)
14281 ;; expand directory names by default-directory
14282 (message "Collecting source files...")
14283 (while dir-list
14284 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14285 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14286 (setq recursive (match-string 1 dir)
14287 dir-name (match-string 3 dir))
14288 (setq dir-list-tmp
14289 (cons (concat recursive
14290 (if (file-name-absolute-p dir-name) "" default-dir)
14291 dir-name)
14292 dir-list-tmp))
14293 (setq dir-list (cdr dir-list)))
14294 ;; resolve path wildcards
14295 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14296 ;; expand directories
14297 (while dir-list-tmp
14298 (setq dir (car dir-list-tmp))
14299 ;; get subdirectories
14300 (if (string-match "-r \\(.*[/\\]\\)" dir)
14301 (setq dir-list (append dir-list (vhdl-get-subdirs
14302 (match-string 1 dir))))
14303 (setq dir-list (append dir-list (list dir))))
14304 (setq dir-list-tmp (cdr dir-list-tmp)))
14305 ;; exclude files
14306 (unless (equal file-exclude-regexp "")
14307 (let ((case-fold-search nil))
14308 (while dir-list
14309 (unless (string-match file-exclude-regexp (car dir-list))
14310 (push (car dir-list) dir-list-tmp))
14311 (setq dir-list (cdr dir-list)))
14312 (setq dir-list (nreverse dir-list-tmp))))
14313 (message "Collecting source files...done")
14314 ;; scan for design units for each directory in DIR-LIST
14315 (setq dir-list-tmp nil
14316 num-dir (length dir-list)
14317 act-dir 1)
14318 (while dir-list
14319 (setq dir-name (abbreviate-file-name
14320 (expand-file-name (car dir-list))))
14321 (vhdl-scan-directory-contents dir-name project nil
14322 (format "(%s/%s) " act-dir num-dir)
14323 (cdr dir-list))
14324 (pushnew (file-name-directory dir-name) dir-list-tmp :test #'equal)
14325 (setq dir-list (cdr dir-list)
14326 act-dir (1+ act-dir)))
14327 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14328 (message "Scanning project \"%s\"...done" project)))
14330 (defun vhdl-update-file-contents (file-name)
14331 "Update hierarchy information by contents of current buffer."
14332 (setq file-name (abbreviate-file-name file-name))
14333 (let* ((dir-name (file-name-directory file-name))
14334 (directory-alist vhdl-directory-alist)
14335 updated)
14336 (while directory-alist
14337 (when (member dir-name (nth 1 (car directory-alist)))
14338 (let* ((vhdl-project (nth 0 (car directory-alist)))
14339 (project (vhdl-project-p))
14340 (ent-alist (vhdl-aget vhdl-entity-alist
14341 (or project dir-name)))
14342 (conf-alist (vhdl-aget vhdl-config-alist
14343 (or project dir-name)))
14344 (pack-alist (vhdl-aget vhdl-package-alist
14345 (or project dir-name)))
14346 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14347 (or project dir-name))))
14348 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14349 (file-entry (vhdl-aget file-alist file-name))
14350 (ent-list (nth 0 file-entry))
14351 (arch-list (nth 1 file-entry))
14352 (arch-ent-list (nth 2 file-entry))
14353 (conf-list (nth 3 file-entry))
14354 (pack-list (nth 4 file-entry))
14355 (pack-body-list (nth 5 file-entry))
14356 (inst-ent-list (nth 7 file-entry))
14357 (cache-key (or project dir-name))
14358 arch-alist key ent-key entry)
14359 ;; delete design units previously contained in this file:
14360 ;; entities
14361 (while ent-list
14362 (setq key (car ent-list)
14363 entry (vhdl-aget ent-alist key))
14364 (when (equal file-name (nth 1 entry))
14365 (if (nth 3 entry)
14366 (vhdl-aput 'ent-alist key
14367 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14368 (vhdl-adelete 'ent-alist key)))
14369 (setq ent-list (cdr ent-list)))
14370 ;; architectures
14371 (while arch-list
14372 (setq key (car arch-list)
14373 ent-key (car arch-ent-list)
14374 entry (vhdl-aget ent-alist ent-key)
14375 arch-alist (nth 3 entry))
14376 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14377 (vhdl-adelete 'arch-alist key)
14378 (if (or (nth 1 entry) arch-alist)
14379 (vhdl-aput 'ent-alist ent-key
14380 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14381 arch-alist (nth 4 entry) (nth 5 entry)))
14382 (vhdl-adelete 'ent-alist ent-key)))
14383 (setq arch-list (cdr arch-list)
14384 arch-ent-list (cdr arch-ent-list)))
14385 ;; configurations
14386 (while conf-list
14387 (setq key (car conf-list))
14388 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14389 (vhdl-adelete 'conf-alist key))
14390 (setq conf-list (cdr conf-list)))
14391 ;; package declarations
14392 (while pack-list
14393 (setq key (car pack-list)
14394 entry (vhdl-aget pack-alist key))
14395 (when (equal file-name (nth 1 entry))
14396 (if (nth 6 entry)
14397 (vhdl-aput 'pack-alist key
14398 (list (nth 0 entry) nil nil nil nil nil
14399 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14400 (nth 9 entry)))
14401 (vhdl-adelete 'pack-alist key)))
14402 (setq pack-list (cdr pack-list)))
14403 ;; package bodies
14404 (while pack-body-list
14405 (setq key (car pack-body-list)
14406 entry (vhdl-aget pack-alist key))
14407 (when (equal file-name (nth 6 entry))
14408 (if (nth 1 entry)
14409 (vhdl-aput 'pack-alist key
14410 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14411 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14412 nil nil nil nil))
14413 (vhdl-adelete 'pack-alist key)))
14414 (setq pack-body-list (cdr pack-body-list)))
14415 ;; instantiated entities
14416 (while inst-ent-list
14417 (setq ent-inst-list
14418 (vhdl-delete (car inst-ent-list) ent-inst-list))
14419 (setq inst-ent-list (cdr inst-ent-list)))
14420 ;; update caches
14421 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14422 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14423 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14424 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14425 ;; scan file
14426 (vhdl-scan-directory-contents file-name project t)
14427 (when (or (and vhdl-speedbar-show-projects project)
14428 (and (not vhdl-speedbar-show-projects) (not project)))
14429 (vhdl-speedbar-refresh project))
14430 (setq updated t)))
14431 (setq directory-alist (cdr directory-alist)))
14432 updated))
14434 (defun vhdl-update-hierarchy ()
14435 "Update directory and hierarchy information in speedbar."
14436 (let ((file-list (reverse vhdl-modified-file-list))
14437 updated)
14438 (when (and vhdl-speedbar-update-on-saving file-list)
14439 (while file-list
14440 (setq updated
14441 (or (vhdl-update-file-contents (car file-list))
14442 updated))
14443 (setq file-list (cdr file-list)))
14444 (setq vhdl-modified-file-list nil)
14445 (vhdl-speedbar-update-current-unit)
14446 (when updated (message "Updating hierarchy...done")))))
14448 ;; structure (parenthesized expression means list of such entries)
14449 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14450 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14451 ;; comp-lib-name level)
14452 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14453 conf-inst-alist level indent
14454 &optional include-top ent-hier)
14455 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14456 entity ENT-KEY."
14457 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14458 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14459 (cdar (last (nth 3 ent-entry)))))
14460 (inst-alist (nth 3 arch-entry))
14461 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14462 hier-list subcomp-list tmp-list inst-key inst-comp-name
14463 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14464 (when (= level 0) (message "Extract design hierarchy..."))
14465 (when include-top
14466 (setq level (1+ level)))
14467 (when (member ent-key ent-hier)
14468 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14469 ;; process all instances
14470 (while inst-alist
14471 (setq inst-entry (car inst-alist)
14472 inst-key (nth 0 inst-entry)
14473 inst-comp-name (nth 4 inst-entry)
14474 inst-conf-key (nth 7 inst-entry))
14475 ;; search entry in configuration's instantiations list
14476 (setq tmp-list conf-inst-alist)
14477 (while (and tmp-list
14478 (not (and (member (nth 0 (car tmp-list))
14479 (list "all" inst-key))
14480 (equal (nth 1 (car tmp-list))
14481 (downcase (or inst-comp-name ""))))))
14482 (setq tmp-list (cdr tmp-list)))
14483 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14484 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14485 (when (and inst-conf-key (not inst-conf-entry))
14486 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14487 ;; determine entity
14488 (setq inst-ent-key
14489 (or (nth 2 (car tmp-list)) ; from configuration
14490 (nth 3 inst-conf-entry) ; from subconfiguration
14491 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14492 ; from configuration spec.
14493 (nth 5 inst-entry))) ; from direct instantiation
14494 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14495 ;; determine architecture
14496 (setq inst-arch-key
14497 (or (nth 3 (car tmp-list)) ; from configuration
14498 (nth 4 inst-conf-entry) ; from subconfiguration
14499 (nth 6 inst-entry) ; from direct instantiation
14500 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14501 ; from configuration spec.
14502 (nth 4 inst-ent-entry) ; MRA
14503 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14504 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14505 ;; set library
14506 (setq inst-lib-key
14507 (or (nth 5 (car tmp-list)) ; from configuration
14508 (nth 8 inst-entry))) ; from direct instantiation
14509 ;; gather information for this instance
14510 (setq comp-entry
14511 (list (nth 1 inst-entry)
14512 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14513 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14514 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14515 (or (nth 0 inst-arch-entry) inst-arch-key)
14516 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14517 (or (nth 0 inst-conf-entry) inst-conf-key)
14518 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14519 inst-lib-key level))
14520 ;; get subcomponent hierarchy
14521 (setq subcomp-list (vhdl-get-hierarchy
14522 ent-alist conf-alist
14523 inst-ent-key inst-arch-key inst-conf-key
14524 (nth 5 inst-conf-entry)
14525 (1+ level) indent nil (cons ent-key ent-hier)))
14526 ;; add to list
14527 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14528 (setq inst-alist (cdr inst-alist)))
14529 (when include-top
14530 (setq hier-list
14531 (cons (list nil nil (nth 0 ent-entry)
14532 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14533 (nth 0 arch-entry)
14534 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14535 nil nil
14536 nil (1- level))
14537 hier-list)))
14538 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14539 hier-list))
14541 (defun vhdl-get-instantiations (ent-key indent)
14542 "Get all instantiations of entity ENT-KEY."
14543 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14544 (vhdl-speedbar-line-key indent)))
14545 arch-alist inst-alist ent-inst-list
14546 ent-entry arch-entry inst-entry)
14547 (while ent-alist
14548 (setq ent-entry (car ent-alist))
14549 (setq arch-alist (nth 4 ent-entry))
14550 (while arch-alist
14551 (setq arch-entry (car arch-alist))
14552 (setq inst-alist (nth 4 arch-entry))
14553 (while inst-alist
14554 (setq inst-entry (car inst-alist))
14555 (when (equal ent-key (nth 5 inst-entry))
14556 (setq ent-inst-list
14557 (cons (list (nth 1 inst-entry)
14558 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14559 (nth 1 ent-entry)
14560 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14561 (nth 1 arch-entry)
14562 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14563 ent-inst-list)))
14564 (setq inst-alist (cdr inst-alist)))
14565 (setq arch-alist (cdr arch-alist)))
14566 (setq ent-alist (cdr ent-alist)))
14567 (nreverse ent-inst-list)))
14569 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14570 ;; Caching in file
14572 (defun vhdl-save-caches ()
14573 "Save all updated hierarchy caches to file."
14574 (interactive)
14575 (condition-case nil
14576 (when vhdl-speedbar-save-cache
14577 ;; update hierarchy
14578 (vhdl-update-hierarchy)
14579 (let ((project-list vhdl-updated-project-list))
14580 (message "Saving hierarchy caches...")
14581 ;; write updated project caches
14582 (while project-list
14583 (vhdl-save-cache (car project-list))
14584 (setq project-list (cdr project-list)))
14585 (message "Saving hierarchy caches...done")))
14586 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14587 (sit-for 2)))))
14589 (defun vhdl-save-cache (key)
14590 "Save current hierarchy cache to file."
14591 (let* ((orig-buffer (current-buffer))
14592 (vhdl-project key)
14593 (project (vhdl-project-p))
14594 (default-directory key)
14595 (directory (abbreviate-file-name (vhdl-default-directory)))
14596 (file-name (vhdl-resolve-env-variable
14597 (vhdl-replace-string
14598 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14599 (concat
14600 (subst-char-in-string ? ?_ (or project "dir"))
14601 " " (user-login-name)))))
14602 (file-dir-name (expand-file-name file-name directory))
14603 (cache-key (or project directory))
14604 (key (if project "project" "directory")))
14605 (unless (file-exists-p (file-name-directory file-dir-name))
14606 (make-directory (file-name-directory file-dir-name) t))
14607 (if (not (file-writable-p file-dir-name))
14608 (progn (vhdl-warning (format "File not writable: \"%s\""
14609 (abbreviate-file-name file-dir-name)))
14610 (sit-for 2))
14611 (message "Saving cache: \"%s\"" file-dir-name)
14612 (set-buffer (find-file-noselect file-dir-name t t))
14613 (erase-buffer)
14614 (insert ";; -*- Emacs-Lisp -*-\n\n"
14615 ";;; " (file-name-nondirectory file-name)
14616 " - design hierarchy cache file for Emacs VHDL Mode "
14617 vhdl-version "\n")
14618 (insert "\n;; " (if project "Project " "Directory") " : ")
14619 (if project (insert project) (prin1 directory (current-buffer)))
14620 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14621 (user-login-name) "\n\n"
14622 "\n;; version number\n"
14623 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14624 "\n;; " (if project "project" "directory") " name"
14625 "\n(setq " key " ")
14626 (prin1 (or project directory) (current-buffer))
14627 (insert ")\n")
14628 (when (member 'hierarchy vhdl-speedbar-save-cache)
14629 (insert "\n;; entity and architecture cache\n"
14630 "(vhdl-aput 'vhdl-entity-alist " key " '")
14631 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14632 (insert ")\n\n;; configuration cache\n"
14633 "(vhdl-aput 'vhdl-config-alist " key " '")
14634 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14635 (insert ")\n\n;; package cache\n"
14636 "(vhdl-aput 'vhdl-package-alist " key " '")
14637 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14638 (insert ")\n\n;; instantiated entities cache\n"
14639 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14640 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14641 (insert ")\n\n;; design units per file cache\n"
14642 "(vhdl-aput 'vhdl-file-alist " key " '")
14643 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14644 (when project
14645 (insert ")\n\n;; source directories in project cache\n"
14646 "(vhdl-aput 'vhdl-directory-alist " key " '")
14647 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14648 (insert ")\n"))
14649 (when (member 'display vhdl-speedbar-save-cache)
14650 (insert "\n;; shown design units cache\n"
14651 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14652 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14653 (current-buffer))
14654 (insert ")\n"))
14655 (setq vhdl-updated-project-list
14656 (delete cache-key vhdl-updated-project-list))
14657 (save-buffer)
14658 (kill-buffer (current-buffer))
14659 (set-buffer orig-buffer))))
14661 (defun vhdl-load-cache (key)
14662 "Load hierarchy cache information from file."
14663 (let* ((vhdl-project key)
14664 (default-directory key)
14665 (directory (vhdl-default-directory))
14666 (file-name (vhdl-resolve-env-variable
14667 (vhdl-replace-string
14668 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14669 (concat
14670 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14671 " " (user-login-name)))))
14672 (file-dir-name (expand-file-name file-name directory))
14673 vhdl-cache-version)
14674 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14675 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14676 (when (file-exists-p file-dir-name)
14677 (condition-case ()
14678 (progn (load-file file-dir-name)
14679 (string< (mapconcat
14680 (lambda (a) (format "%3d" (string-to-number a)))
14681 (split-string "3.33" "\\.") "")
14682 (mapconcat
14683 (lambda (a) (format "%3d" (string-to-number a)))
14684 (split-string vhdl-cache-version "\\.") "")))
14685 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14686 nil))))))
14688 (defun vhdl-require-hierarchy-info ()
14689 "Make sure that hierarchy information is available. Load cache or scan files
14690 if required."
14691 (if (vhdl-project-p)
14692 (unless (or (assoc vhdl-project vhdl-file-alist)
14693 (vhdl-load-cache vhdl-project))
14694 (vhdl-scan-project-contents vhdl-project))
14695 (let ((directory (abbreviate-file-name default-directory)))
14696 (unless (or (assoc directory vhdl-file-alist)
14697 (vhdl-load-cache directory))
14698 (vhdl-scan-directory-contents directory)))))
14700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14701 ;; Add hierarchy browser functionality to speedbar
14703 (defvar vhdl-speedbar-mode-map nil
14704 "Keymap used when in the VHDL hierarchy browser mode.")
14706 (defvar vhdl-speedbar-menu-items nil
14707 "Additional menu-items to add to speedbar frame.")
14709 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14710 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14711 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14712 (declare-function speedbar-change-initial-expansion-list "speedbar"
14713 (new-default))
14714 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14716 (defun vhdl-speedbar-initialize ()
14717 "Initialize speedbar."
14718 ;; general settings
14719 ;; VHDL file extensions (extracted from `auto-mode-alist')
14720 (let ((mode-alist auto-mode-alist))
14721 (while mode-alist
14722 (when (eq (cdar mode-alist) 'vhdl-mode)
14723 (speedbar-add-supported-extension (caar mode-alist)))
14724 (setq mode-alist (cdr mode-alist))))
14725 ;; hierarchy browser settings
14726 (when (boundp 'speedbar-mode-functions-list)
14727 ;; special functions
14728 (speedbar-add-mode-functions-list
14729 '("vhdl directory"
14730 (speedbar-item-info . vhdl-speedbar-item-info)
14731 (speedbar-line-directory . speedbar-files-line-path)))
14732 (speedbar-add-mode-functions-list
14733 '("vhdl project"
14734 (speedbar-item-info . vhdl-speedbar-item-info)
14735 (speedbar-line-directory . vhdl-speedbar-line-project)))
14736 ;; keymap
14737 (unless vhdl-speedbar-mode-map
14738 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14739 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14740 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14741 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14742 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14743 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14744 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14745 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14746 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14747 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14748 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14749 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14750 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14751 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14752 (let ((key 0))
14753 (while (<= key 9)
14754 (define-key vhdl-speedbar-mode-map (int-to-string key)
14755 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14756 (setq key (1+ key)))))
14757 (define-key speedbar-mode-map "h"
14758 (lambda () (interactive)
14759 (speedbar-change-initial-expansion-list "vhdl directory")))
14760 (define-key speedbar-mode-map "H"
14761 (lambda () (interactive)
14762 (speedbar-change-initial-expansion-list "vhdl project")))
14763 ;; menu
14764 (unless vhdl-speedbar-menu-items
14765 (setq
14766 vhdl-speedbar-menu-items
14767 `(["Edit" speedbar-edit-line t]
14768 ["Expand" speedbar-expand-line
14769 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14770 ["Contract" vhdl-speedbar-contract-level t]
14771 ["Expand All" vhdl-speedbar-expand-all t]
14772 ["Contract All" vhdl-speedbar-contract-all t]
14773 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14774 (while (<= key 9)
14775 (setq menu-list
14776 (cons `[,(if (= key 0) "All" (int-to-string key))
14777 (vhdl-speedbar-set-depth ,key)
14778 :style radio
14779 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14780 :keys ,(int-to-string key)]
14781 menu-list))
14782 (setq key (1+ key)))
14783 (nreverse menu-list))
14784 "--"
14785 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14786 (or (vhdl-speedbar-check-unit 'entity)
14787 (vhdl-speedbar-check-unit 'subprogram))]
14788 ["Place Component" vhdl-speedbar-place-component
14789 (vhdl-speedbar-check-unit 'entity)]
14790 ["Generate Configuration" vhdl-speedbar-configuration
14791 (vhdl-speedbar-check-unit 'architecture)]
14792 ["Select as MRA" vhdl-speedbar-select-mra
14793 (vhdl-speedbar-check-unit 'architecture)]
14794 ["Make" vhdl-speedbar-make-design
14795 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14796 ["Generate Makefile" vhdl-speedbar-generate-makefile
14797 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14798 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14799 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14800 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14801 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14802 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14803 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14804 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14805 ;; hook-ups
14806 (speedbar-add-expansion-list
14807 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14808 vhdl-speedbar-display-directory))
14809 (speedbar-add-expansion-list
14810 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14811 vhdl-speedbar-display-projects))
14812 (setq speedbar-stealthy-function-list
14813 (append
14814 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14815 ("vhdl project" vhdl-speedbar-update-current-project
14816 vhdl-speedbar-update-current-unit))
14817 speedbar-stealthy-function-list))
14818 (when (eq vhdl-speedbar-display-mode 'directory)
14819 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14820 (when (eq vhdl-speedbar-display-mode 'project)
14821 (setq speedbar-initial-expansion-list-name "vhdl project"))
14822 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14824 (defun vhdl-speedbar (&optional arg)
14825 "Open/close speedbar."
14826 (interactive)
14827 (if (not (fboundp 'speedbar))
14828 (error "WARNING: Speedbar is not available or not installed")
14829 (condition-case ()
14830 (speedbar-frame-mode arg)
14831 (error (error "WARNING: An error occurred while opening speedbar")))))
14833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14834 ;; Display functions
14836 (defvar vhdl-speedbar-last-selected-project nil
14837 "Name of last selected project.")
14839 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14840 ;;; (defmacro speedbar-with-writable (&rest forms)
14841 ;;; "Allow the buffer to be writable and evaluate FORMS."
14842 ;;; (list 'let '((inhibit-read-only t))
14843 ;;; (cons 'progn forms)))
14844 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14846 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14847 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14848 (declare-function speedbar-file-lists "speedbar" (directory))
14850 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14851 "Display directory and hierarchy information in speedbar."
14852 (setq vhdl-speedbar-show-projects nil)
14853 (setq speedbar-ignored-directory-regexp
14854 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14855 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14856 (setq speedbar-last-selected-file nil)
14857 (speedbar-with-writable
14858 (condition-case nil
14859 (progn
14860 ;; insert directory path
14861 (speedbar-directory-buttons directory depth)
14862 ;; insert subdirectories
14863 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14864 ;; scan and insert hierarchy of current directory
14865 (vhdl-speedbar-insert-dir-hierarchy directory depth
14866 speedbar-power-click)
14867 ;; expand subdirectories
14868 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14869 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14871 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14872 "Display projects and hierarchy information in speedbar."
14873 (setq vhdl-speedbar-show-projects t)
14874 (setq speedbar-ignored-directory-regexp ".")
14875 (setq speedbar-last-selected-file nil)
14876 (setq vhdl-speedbar-last-selected-project nil)
14877 (speedbar-with-writable
14878 (condition-case nil
14879 ;; insert projects
14880 (vhdl-speedbar-insert-projects)
14881 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14882 (setq speedbar-full-text-cache nil)) ; prevent caching
14884 (declare-function speedbar-make-tag-line "speedbar"
14885 (type char func data tag tfunc tdata tface depth))
14887 (defun vhdl-speedbar-insert-projects ()
14888 "Insert all projects in speedbar."
14889 (vhdl-speedbar-make-title-line "Projects:")
14890 (let ((project-alist (if vhdl-project-sort
14891 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14892 vhdl-project-alist))
14893 (vhdl-speedbar-update-current-unit nil))
14894 ;; insert projects
14895 (while project-alist
14896 (speedbar-make-tag-line
14897 'angle ?+ 'vhdl-speedbar-expand-project
14898 (caar project-alist) (caar project-alist)
14899 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14900 (setq project-alist (cdr project-alist)))
14901 (setq project-alist vhdl-project-alist)
14902 ;; expand projects
14903 (while project-alist
14904 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14905 (goto-char (point-min))
14906 (when (re-search-forward
14907 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14908 (goto-char (match-end 1))
14909 (speedbar-do-function-pointer)))
14910 (setq project-alist (cdr project-alist)))))
14912 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14913 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14914 otherwise use cached data."
14915 (when (or rescan (and (not (assoc project vhdl-file-alist))
14916 (not (vhdl-load-cache project))))
14917 (vhdl-scan-project-contents project))
14918 ;; insert design hierarchy
14919 (vhdl-speedbar-insert-hierarchy
14920 (vhdl-aget vhdl-entity-alist project)
14921 (vhdl-aget vhdl-config-alist project)
14922 (vhdl-aget vhdl-package-alist project)
14923 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14924 (insert (int-to-string indent) ":\n")
14925 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14926 (put-text-property (1- (point)) (point) 'invisible nil)
14927 ;; expand design units
14928 (vhdl-speedbar-expand-units project))
14930 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14931 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14932 otherwise use cached data."
14933 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14934 (not (vhdl-load-cache directory))))
14935 (vhdl-scan-directory-contents directory))
14936 ;; insert design hierarchy
14937 (vhdl-speedbar-insert-hierarchy
14938 (vhdl-aget vhdl-entity-alist directory)
14939 (vhdl-aget vhdl-config-alist directory)
14940 (vhdl-aget vhdl-package-alist directory)
14941 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14942 ;; expand design units
14943 (vhdl-speedbar-expand-units directory)
14944 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14946 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14947 ent-inst-list depth)
14948 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14949 (if (not (or ent-alist conf-alist pack-alist))
14950 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14951 (let (ent-entry conf-entry pack-entry)
14952 ;; insert entities
14953 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14954 (while ent-alist
14955 (setq ent-entry (car ent-alist))
14956 (speedbar-make-tag-line
14957 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14958 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14959 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14960 'vhdl-speedbar-entity-face depth)
14961 (unless (nth 2 ent-entry)
14962 (end-of-line 0) (insert "!") (forward-char 1))
14963 (unless (member (nth 0 ent-entry) ent-inst-list)
14964 (end-of-line 0) (insert " (top)") (forward-char 1))
14965 (setq ent-alist (cdr ent-alist)))
14966 ;; insert configurations
14967 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14968 (while conf-alist
14969 (setq conf-entry (car conf-alist))
14970 (speedbar-make-tag-line
14971 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14972 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14973 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14974 'vhdl-speedbar-configuration-face depth)
14975 (setq conf-alist (cdr conf-alist)))
14976 ;; insert packages
14977 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14978 (while pack-alist
14979 (setq pack-entry (car pack-alist))
14980 (vhdl-speedbar-make-pack-line
14981 (nth 0 pack-entry) (nth 1 pack-entry)
14982 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14983 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14984 depth)
14985 (setq pack-alist (cdr pack-alist))))))
14987 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14989 (defun vhdl-speedbar-rescan-hierarchy ()
14990 "Rescan hierarchy for the directory or project under the cursor."
14991 (interactive)
14992 (let (key path)
14993 (cond
14994 ;; current project
14995 (vhdl-speedbar-show-projects
14996 (setq key (vhdl-speedbar-line-project))
14997 (vhdl-scan-project-contents key))
14998 ;; top-level directory
14999 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
15000 (re-search-forward "[0-9]+:" nil t)
15001 (vhdl-scan-directory-contents
15002 (abbreviate-file-name (speedbar-line-directory))))
15003 ;; current directory
15004 (t (setq path (speedbar-line-directory))
15005 (string-match "^\\(.+[/\\]\\)" path)
15006 (vhdl-scan-directory-contents
15007 (abbreviate-file-name (match-string 1 path)))))
15008 (vhdl-speedbar-refresh key)))
15010 (declare-function speedbar-goto-this-file "speedbar" (file))
15012 (defun vhdl-speedbar-expand-dirs (directory)
15013 "Expand subdirectories in DIRECTORY according to
15014 `speedbar-shown-directories'."
15015 ;; (nicked from `speedbar-default-directory-list')
15016 (let ((sf (cdr (reverse speedbar-shown-directories)))
15017 (vhdl-speedbar-update-current-unit nil))
15018 (setq speedbar-shown-directories
15019 (list (expand-file-name default-directory)))
15020 (while sf
15021 (when (speedbar-goto-this-file (car sf))
15022 (beginning-of-line)
15023 (when (looking-at "[0-9]+:\\s-*<")
15024 (goto-char (match-end 0))
15025 (speedbar-do-function-pointer)))
15026 (setq sf (cdr sf))))
15027 (vhdl-speedbar-update-current-unit nil t))
15029 (defun vhdl-speedbar-expand-units (key)
15030 "Expand design units in directory/project KEY according to
15031 `vhdl-speedbar-shown-unit-alist'."
15032 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15033 (vhdl-speedbar-update-current-unit nil)
15034 vhdl-updated-project-list)
15035 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15036 (vhdl-prepare-search-1
15037 (while unit-alist ; expand units
15038 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
15039 (beginning-of-line)
15040 (let ((arch-alist (nth 1 (car unit-alist)))
15041 position)
15042 (when (looking-at "^[0-9]+:\\s-*\\[")
15043 (goto-char (match-end 0))
15044 (setq position (point))
15045 (speedbar-do-function-pointer)
15046 (select-frame speedbar-frame)
15047 (while arch-alist ; expand architectures
15048 (goto-char position)
15049 (when (re-search-forward
15050 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
15051 (car arch-alist) "\\>\\)") nil t)
15052 (beginning-of-line)
15053 (when (looking-at "^[0-9]+:\\s-*{")
15054 (goto-char (match-end 0))
15055 (speedbar-do-function-pointer)
15056 (select-frame speedbar-frame)))
15057 (setq arch-alist (cdr arch-alist))))
15058 (setq unit-alist (cdr unit-alist))))))
15059 (vhdl-speedbar-update-current-unit nil t))
15061 (declare-function speedbar-center-buffer-smartly "speedbar" ())
15063 (defun vhdl-speedbar-contract-level ()
15064 "Contract current level in current directory/project."
15065 (interactive)
15066 (when (or (save-excursion
15067 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
15068 (and (save-excursion
15069 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
15070 (re-search-backward
15071 (format "^[0-%d]:\\s-*[[{<]-"
15072 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
15073 (goto-char (match-end 0))
15074 (speedbar-do-function-pointer)
15075 (speedbar-center-buffer-smartly)))
15077 (defun vhdl-speedbar-contract-all ()
15078 "Contract all expanded design units in current directory/project."
15079 (interactive)
15080 (if (and vhdl-speedbar-show-projects
15081 (save-excursion (beginning-of-line) (looking-at "^0:")))
15082 (progn (setq vhdl-speedbar-shown-project-list nil)
15083 (vhdl-speedbar-refresh))
15084 (let ((key (vhdl-speedbar-line-key)))
15085 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15086 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
15087 (when (memq 'display vhdl-speedbar-save-cache)
15088 (add-to-list 'vhdl-updated-project-list key)))))
15090 (defun vhdl-speedbar-expand-all ()
15091 "Expand all design units in current directory/project."
15092 (interactive)
15093 (let* ((key (vhdl-speedbar-line-key))
15094 (ent-alist (vhdl-aget vhdl-entity-alist key))
15095 (conf-alist (vhdl-aget vhdl-config-alist key))
15096 (pack-alist (vhdl-aget vhdl-package-alist key))
15097 arch-alist unit-alist subunit-alist)
15098 (add-to-list 'vhdl-speedbar-shown-project-list key)
15099 (while ent-alist
15100 (setq arch-alist (nth 4 (car ent-alist)))
15101 (setq subunit-alist nil)
15102 (while arch-alist
15103 (push (caar arch-alist) subunit-alist)
15104 (setq arch-alist (cdr arch-alist)))
15105 (push (list (caar ent-alist) subunit-alist) unit-alist)
15106 (setq ent-alist (cdr ent-alist)))
15107 (while conf-alist
15108 (push (list (caar conf-alist)) unit-alist)
15109 (setq conf-alist (cdr conf-alist)))
15110 (while pack-alist
15111 (push (list (caar pack-alist)) unit-alist)
15112 (setq pack-alist (cdr pack-alist)))
15113 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15114 (vhdl-speedbar-refresh)
15115 (when (memq 'display vhdl-speedbar-save-cache)
15116 (add-to-list 'vhdl-updated-project-list key))))
15118 (declare-function speedbar-change-expand-button-char "speedbar" (char))
15119 (declare-function speedbar-delete-subblock "speedbar" (indent))
15121 (defun vhdl-speedbar-expand-project (text token indent)
15122 "Expand/contract the project under the cursor."
15123 (cond
15124 ((string-match "+" text) ; expand project
15125 (speedbar-change-expand-button-char ?-)
15126 (unless (member token vhdl-speedbar-shown-project-list)
15127 (setq vhdl-speedbar-shown-project-list
15128 (cons token vhdl-speedbar-shown-project-list)))
15129 (speedbar-with-writable
15130 (save-excursion
15131 (end-of-line) (forward-char 1)
15132 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
15133 speedbar-power-click))))
15134 ((string-match "-" text) ; contract project
15135 (speedbar-change-expand-button-char ?+)
15136 (setq vhdl-speedbar-shown-project-list
15137 (delete token vhdl-speedbar-shown-project-list))
15138 (speedbar-delete-subblock indent))
15139 (t (error "Nothing to display")))
15140 (when (equal (selected-frame) speedbar-frame)
15141 (speedbar-center-buffer-smartly)))
15143 (defun vhdl-speedbar-expand-entity (text token indent)
15144 "Expand/contract the entity under the cursor."
15145 (cond
15146 ((string-match "+" text) ; expand entity
15147 (let* ((key (vhdl-speedbar-line-key indent))
15148 (ent-alist (vhdl-aget vhdl-entity-alist key))
15149 (ent-entry (vhdl-aget ent-alist token))
15150 (arch-alist (nth 3 ent-entry))
15151 (inst-alist (vhdl-get-instantiations token indent))
15152 (subpack-alist (nth 5 ent-entry))
15153 (multiple-arch (> (length arch-alist) 1))
15154 arch-entry inst-entry)
15155 (if (not (or arch-alist inst-alist subpack-alist))
15156 (speedbar-change-expand-button-char ??)
15157 (speedbar-change-expand-button-char ?-)
15158 ;; add entity to `vhdl-speedbar-shown-unit-alist'
15159 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15160 (vhdl-aput 'unit-alist token nil)
15161 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15162 (speedbar-with-writable
15163 (save-excursion
15164 (end-of-line) (forward-char 1)
15165 ;; insert architectures
15166 (when arch-alist
15167 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15168 (while arch-alist
15169 (setq arch-entry (car arch-alist))
15170 (speedbar-make-tag-line
15171 'curly ?+ 'vhdl-speedbar-expand-architecture
15172 (cons token (nth 0 arch-entry))
15173 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15174 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15175 'vhdl-speedbar-architecture-face (1+ indent))
15176 (when (and multiple-arch
15177 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15178 (end-of-line 0) (insert " (mra)") (forward-char 1))
15179 (setq arch-alist (cdr arch-alist)))
15180 ;; insert instantiations
15181 (when inst-alist
15182 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15183 (while inst-alist
15184 (setq inst-entry (car inst-alist))
15185 (vhdl-speedbar-make-inst-line
15186 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15187 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15188 nil nil nil (1+ indent) 0 " in ")
15189 (setq inst-alist (cdr inst-alist)))
15190 ;; insert required packages
15191 (vhdl-speedbar-insert-subpackages
15192 subpack-alist (1+ indent) indent)))
15193 (when (memq 'display vhdl-speedbar-save-cache)
15194 (add-to-list 'vhdl-updated-project-list key))
15195 (vhdl-speedbar-update-current-unit t t))))
15196 ((string-match "-" text) ; contract entity
15197 (speedbar-change-expand-button-char ?+)
15198 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15199 (let* ((key (vhdl-speedbar-line-key indent))
15200 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15201 (vhdl-adelete 'unit-alist token)
15202 (if unit-alist
15203 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15204 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15205 (speedbar-delete-subblock indent)
15206 (when (memq 'display vhdl-speedbar-save-cache)
15207 (add-to-list 'vhdl-updated-project-list key))))
15208 (t (error "Nothing to display")))
15209 (when (equal (selected-frame) speedbar-frame)
15210 (speedbar-center-buffer-smartly)))
15212 (defun vhdl-speedbar-expand-architecture (text token indent)
15213 "Expand/contract the architecture under the cursor."
15214 (cond
15215 ((string-match "+" text) ; expand architecture
15216 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15217 (ent-alist (vhdl-aget vhdl-entity-alist key))
15218 (conf-alist (vhdl-aget vhdl-config-alist key))
15219 (hier-alist (vhdl-get-hierarchy
15220 ent-alist conf-alist (car token) (cdr token) nil nil
15221 0 (1- indent)))
15222 (ent-entry (vhdl-aget ent-alist (car token)))
15223 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15224 (subpack-alist (nth 4 arch-entry))
15225 entry)
15226 (if (not (or hier-alist subpack-alist))
15227 (speedbar-change-expand-button-char ??)
15228 (speedbar-change-expand-button-char ?-)
15229 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15230 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15231 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15232 (vhdl-aput 'unit-alist (car token)
15233 (list (cons (cdr token) arch-alist)))
15234 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15235 (speedbar-with-writable
15236 (save-excursion
15237 (end-of-line) (forward-char 1)
15238 ;; insert instance hierarchy
15239 (when hier-alist
15240 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15241 (1+ indent)))
15242 (while hier-alist
15243 (setq entry (car hier-alist))
15244 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15245 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15246 (vhdl-speedbar-make-inst-line
15247 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15248 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15249 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15250 (setq hier-alist (cdr hier-alist)))
15251 ;; insert required packages
15252 (vhdl-speedbar-insert-subpackages
15253 subpack-alist (1+ indent) (1- indent))))
15254 (when (memq 'display vhdl-speedbar-save-cache)
15255 (add-to-list 'vhdl-updated-project-list key))
15256 (vhdl-speedbar-update-current-unit t t))))
15257 ((string-match "-" text) ; contract architecture
15258 (speedbar-change-expand-button-char ?+)
15259 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15260 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15261 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15262 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15263 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15264 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15265 (speedbar-delete-subblock indent)
15266 (when (memq 'display vhdl-speedbar-save-cache)
15267 (add-to-list 'vhdl-updated-project-list key))))
15268 (t (error "Nothing to display")))
15269 (when (equal (selected-frame) speedbar-frame)
15270 (speedbar-center-buffer-smartly)))
15272 (defun vhdl-speedbar-expand-config (text token indent)
15273 "Expand/contract the configuration under the cursor."
15274 (cond
15275 ((string-match "+" text) ; expand configuration
15276 (let* ((key (vhdl-speedbar-line-key indent))
15277 (conf-alist (vhdl-aget vhdl-config-alist key))
15278 (conf-entry (vhdl-aget conf-alist token))
15279 (ent-alist (vhdl-aget vhdl-entity-alist key))
15280 (hier-alist (vhdl-get-hierarchy
15281 ent-alist conf-alist (nth 3 conf-entry)
15282 (nth 4 conf-entry) token (nth 5 conf-entry)
15283 0 indent t))
15284 (subpack-alist (nth 6 conf-entry))
15285 entry)
15286 (if (not (or hier-alist subpack-alist))
15287 (speedbar-change-expand-button-char ??)
15288 (speedbar-change-expand-button-char ?-)
15289 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15290 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15291 (vhdl-aput 'unit-alist token nil)
15292 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15293 (speedbar-with-writable
15294 (save-excursion
15295 (end-of-line) (forward-char 1)
15296 ;; insert instance hierarchy
15297 (when hier-alist
15298 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15299 (while hier-alist
15300 (setq entry (car hier-alist))
15301 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15302 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15303 (vhdl-speedbar-make-inst-line
15304 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15305 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15306 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15307 (setq hier-alist (cdr hier-alist)))
15308 ;; insert required packages
15309 (vhdl-speedbar-insert-subpackages
15310 subpack-alist (1+ indent) indent)))
15311 (when (memq 'display vhdl-speedbar-save-cache)
15312 (add-to-list 'vhdl-updated-project-list key))
15313 (vhdl-speedbar-update-current-unit t t))))
15314 ((string-match "-" text) ; contract configuration
15315 (speedbar-change-expand-button-char ?+)
15316 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15317 (let* ((key (vhdl-speedbar-line-key indent))
15318 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15319 (vhdl-adelete 'unit-alist token)
15320 (if unit-alist
15321 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15322 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15323 (speedbar-delete-subblock indent)
15324 (when (memq 'display vhdl-speedbar-save-cache)
15325 (add-to-list 'vhdl-updated-project-list key))))
15326 (t (error "Nothing to display")))
15327 (when (equal (selected-frame) speedbar-frame)
15328 (speedbar-center-buffer-smartly)))
15330 (defun vhdl-speedbar-expand-package (text token indent)
15331 "Expand/contract the package under the cursor."
15332 (cond
15333 ((string-match "+" text) ; expand package
15334 (let* ((key (vhdl-speedbar-line-key indent))
15335 (pack-alist (vhdl-aget vhdl-package-alist key))
15336 (pack-entry (vhdl-aget pack-alist token))
15337 (comp-alist (nth 3 pack-entry))
15338 (func-alist (nth 4 pack-entry))
15339 (func-body-alist (nth 8 pack-entry))
15340 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15341 comp-entry func-entry func-body-entry)
15342 (if (not (or comp-alist func-alist subpack-alist))
15343 (speedbar-change-expand-button-char ??)
15344 (speedbar-change-expand-button-char ?-)
15345 ;; add package to `vhdl-speedbar-shown-unit-alist'
15346 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15347 (vhdl-aput 'unit-alist token nil)
15348 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15349 (speedbar-with-writable
15350 (save-excursion
15351 (end-of-line) (forward-char 1)
15352 ;; insert components
15353 (when comp-alist
15354 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15355 (while comp-alist
15356 (setq comp-entry (car comp-alist))
15357 (speedbar-make-tag-line
15358 nil nil nil
15359 (cons token (nth 0 comp-entry))
15360 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15361 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15362 'vhdl-speedbar-entity-face (1+ indent))
15363 (setq comp-alist (cdr comp-alist)))
15364 ;; insert subprograms
15365 (when func-alist
15366 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15367 (while func-alist
15368 (setq func-entry (car func-alist)
15369 func-body-entry (vhdl-aget func-body-alist
15370 (car func-entry)))
15371 (when (nth 2 func-entry)
15372 (vhdl-speedbar-make-subprogram-line
15373 (nth 1 func-entry)
15374 (cons (nth 2 func-entry) (nth 3 func-entry))
15375 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15376 (1+ indent)))
15377 (setq func-alist (cdr func-alist)))
15378 ;; insert required packages
15379 (vhdl-speedbar-insert-subpackages
15380 subpack-alist (1+ indent) indent)))
15381 (when (memq 'display vhdl-speedbar-save-cache)
15382 (add-to-list 'vhdl-updated-project-list key))
15383 (vhdl-speedbar-update-current-unit t t))))
15384 ((string-match "-" text) ; contract package
15385 (speedbar-change-expand-button-char ?+)
15386 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15387 (let* ((key (vhdl-speedbar-line-key indent))
15388 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15389 (vhdl-adelete 'unit-alist token)
15390 (if unit-alist
15391 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15392 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15393 (speedbar-delete-subblock indent)
15394 (when (memq 'display vhdl-speedbar-save-cache)
15395 (add-to-list 'vhdl-updated-project-list key))))
15396 (t (error "Nothing to display")))
15397 (when (equal (selected-frame) speedbar-frame)
15398 (speedbar-center-buffer-smartly)))
15400 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15401 "Insert required packages."
15402 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15403 (vhdl-speedbar-line-key dir-indent)))
15404 pack-key lib-name pack-entry)
15405 (when subpack-alist
15406 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15407 (while subpack-alist
15408 (setq pack-key (cdar subpack-alist)
15409 lib-name (caar subpack-alist))
15410 (setq pack-entry (vhdl-aget pack-alist pack-key))
15411 (vhdl-speedbar-make-subpack-line
15412 (or (nth 0 pack-entry) pack-key) lib-name
15413 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15414 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15415 (setq subpack-alist (cdr subpack-alist)))))
15417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15418 ;; Display help functions
15420 (defvar vhdl-speedbar-update-current-unit t
15421 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15423 (defun vhdl-speedbar-update-current-project ()
15424 "Highlight project that is currently active."
15425 (when (and vhdl-speedbar-show-projects
15426 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15427 (and (boundp 'speedbar-frame)
15428 (frame-live-p speedbar-frame)))
15429 (let ((last-frame (selected-frame))
15430 (project-alist vhdl-project-alist)
15431 pos)
15432 (select-frame speedbar-frame)
15433 (speedbar-with-writable
15434 (save-excursion
15435 (while project-alist
15436 (goto-char (point-min))
15437 (when (re-search-forward
15438 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15439 (put-text-property (match-beginning 1) (match-end 1) 'face
15440 (if (equal (caar project-alist) vhdl-project)
15441 'speedbar-selected-face
15442 'speedbar-directory-face))
15443 (when (equal (caar project-alist) vhdl-project)
15444 (setq pos (1- (match-beginning 1)))))
15445 (setq project-alist (cdr project-alist))))
15446 (when pos (goto-char pos)))
15447 (select-frame last-frame)
15448 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15451 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15453 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15454 "Highlight all design units that are contained in the current file.
15455 NO-POSITION non-nil means do not re-position cursor."
15456 (let ((last-frame (selected-frame))
15457 (project-list vhdl-speedbar-shown-project-list)
15458 file-alist pos file-name)
15459 ;; get current file name
15460 (if (fboundp 'speedbar-select-attached-frame)
15461 (speedbar-select-attached-frame)
15462 (select-frame speedbar-attached-frame))
15463 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15464 (when (and vhdl-speedbar-update-current-unit
15465 (or always (not (equal file-name speedbar-last-selected-file))))
15466 (if vhdl-speedbar-show-projects
15467 (while project-list
15468 (setq file-alist (append file-alist
15469 (vhdl-aget vhdl-file-alist
15470 (car project-list))))
15471 (setq project-list (cdr project-list)))
15472 (setq file-alist
15473 (vhdl-aget vhdl-file-alist
15474 (abbreviate-file-name default-directory))))
15475 (select-frame speedbar-frame)
15476 (set-buffer speedbar-buffer)
15477 (speedbar-with-writable
15478 (vhdl-prepare-search-1
15479 (save-excursion
15480 ;; unhighlight last units
15481 (let* ((file-entry (vhdl-aget file-alist
15482 speedbar-last-selected-file)))
15483 (vhdl-speedbar-update-units
15484 "\\[.] " (nth 0 file-entry)
15485 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15486 (vhdl-speedbar-update-units
15487 "{.} " (nth 1 file-entry)
15488 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15489 (vhdl-speedbar-update-units
15490 "\\[.] " (nth 3 file-entry)
15491 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15492 (vhdl-speedbar-update-units
15493 "[]>] " (nth 4 file-entry)
15494 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15495 (vhdl-speedbar-update-units
15496 "\\[.].+(" '("body")
15497 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15498 (vhdl-speedbar-update-units
15499 "> " (nth 6 file-entry)
15500 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15501 ;; highlight current units
15502 (let* ((file-entry (vhdl-aget file-alist file-name)))
15503 (setq
15504 pos (vhdl-speedbar-update-units
15505 "\\[.] " (nth 0 file-entry)
15506 file-name 'vhdl-speedbar-entity-selected-face pos)
15507 pos (vhdl-speedbar-update-units
15508 "{.} " (nth 1 file-entry)
15509 file-name 'vhdl-speedbar-architecture-selected-face pos)
15510 pos (vhdl-speedbar-update-units
15511 "\\[.] " (nth 3 file-entry)
15512 file-name 'vhdl-speedbar-configuration-selected-face pos)
15513 pos (vhdl-speedbar-update-units
15514 "[]>] " (nth 4 file-entry)
15515 file-name 'vhdl-speedbar-package-selected-face pos)
15516 pos (vhdl-speedbar-update-units
15517 "\\[.].+(" '("body")
15518 file-name 'vhdl-speedbar-package-selected-face pos)
15519 pos (vhdl-speedbar-update-units
15520 "> " (nth 6 file-entry)
15521 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15522 ;; move speedbar so the first highlighted unit is visible
15523 (when (and pos (not no-position))
15524 (goto-char pos)
15525 (speedbar-center-buffer-smartly)
15526 (speedbar-position-cursor-on-line))
15527 (setq speedbar-last-selected-file file-name))
15528 (select-frame last-frame)
15531 (defun vhdl-speedbar-update-units (text unit-list file-name face
15532 &optional pos)
15533 "Help function to highlight design units."
15534 (while unit-list
15535 (goto-char (point-min))
15536 (while (re-search-forward
15537 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15538 (when (equal file-name (car (get-text-property
15539 (match-beginning 1) 'speedbar-token)))
15540 (setq pos (or pos (point-marker)))
15541 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15542 (setq unit-list (cdr unit-list)))
15543 pos)
15545 (declare-function speedbar-make-button "speedbar"
15546 (start end face mouse function &optional token))
15548 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15549 ent-name ent-file-marker
15550 arch-name arch-file-marker
15551 conf-name conf-file-marker
15552 lib-name depth offset delimiter)
15553 "Insert instantiation entry."
15554 (let ((start (point))
15555 visible-start)
15556 (insert (int-to-string depth) ":")
15557 (put-text-property start (point) 'invisible t)
15558 (setq visible-start (point))
15559 (insert-char ? (* depth speedbar-indentation-width))
15560 (while (> offset 0)
15561 (insert "|")
15562 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15563 (setq offset (1- offset)))
15564 (put-text-property visible-start (point) 'invisible nil)
15565 (setq start (point))
15566 (insert ">")
15567 (speedbar-make-button start (point) nil nil nil)
15568 (setq visible-start (point))
15569 (insert " ")
15570 (setq start (point))
15571 (if (not inst-name)
15572 (insert "(top)")
15573 (insert inst-name)
15574 (speedbar-make-button
15575 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15576 'vhdl-speedbar-find-file inst-file-marker))
15577 (insert delimiter)
15578 (when ent-name
15579 (setq start (point))
15580 (insert ent-name)
15581 (speedbar-make-button
15582 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15583 'vhdl-speedbar-find-file ent-file-marker)
15584 (when arch-name
15585 (insert " (")
15586 (setq start (point))
15587 (insert arch-name)
15588 (speedbar-make-button
15589 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15590 'vhdl-speedbar-find-file arch-file-marker)
15591 (insert ")"))
15592 (when conf-name
15593 (insert " (")
15594 (setq start (point))
15595 (insert conf-name)
15596 (speedbar-make-button
15597 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15598 'vhdl-speedbar-find-file conf-file-marker)
15599 (insert ")")))
15600 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15601 (setq start (point))
15602 (insert " (" lib-name ")")
15603 (put-text-property (+ 2 start) (1- (point)) 'face
15604 'vhdl-speedbar-library-face))
15605 (insert-char ?\n 1)
15606 (put-text-property visible-start (point) 'invisible nil)))
15608 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15609 body-file-marker depth)
15610 "Insert package entry."
15611 (let ((start (point))
15612 visible-start)
15613 (insert (int-to-string depth) ":")
15614 (put-text-property start (point) 'invisible t)
15615 (setq visible-start (point))
15616 (insert-char ? (* depth speedbar-indentation-width))
15617 (put-text-property visible-start (point) 'invisible nil)
15618 (setq start (point))
15619 (insert "[+]")
15620 (speedbar-make-button
15621 start (point) 'speedbar-button-face 'speedbar-highlight-face
15622 'vhdl-speedbar-expand-package pack-key)
15623 (setq visible-start (point))
15624 (insert-char ? 1 nil)
15625 (setq start (point))
15626 (insert pack-name)
15627 (speedbar-make-button
15628 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15629 'vhdl-speedbar-find-file pack-file-marker)
15630 (unless (car pack-file-marker)
15631 (insert "!"))
15632 (when (car body-file-marker)
15633 (insert " (")
15634 (setq start (point))
15635 (insert "body")
15636 (speedbar-make-button
15637 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15638 'vhdl-speedbar-find-file body-file-marker)
15639 (insert ")"))
15640 (insert-char ?\n 1)
15641 (put-text-property visible-start (point) 'invisible nil)))
15643 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15644 pack-body-file-marker depth)
15645 "Insert used package entry."
15646 (let ((start (point))
15647 visible-start)
15648 (insert (int-to-string depth) ":")
15649 (put-text-property start (point) 'invisible t)
15650 (setq visible-start (point))
15651 (insert-char ? (* depth speedbar-indentation-width))
15652 (put-text-property visible-start (point) 'invisible nil)
15653 (setq start (point))
15654 (insert ">")
15655 (speedbar-make-button start (point) nil nil nil)
15656 (setq visible-start (point))
15657 (insert " ")
15658 (setq start (point))
15659 (insert pack-name)
15660 (speedbar-make-button
15661 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15662 'vhdl-speedbar-find-file pack-file-marker)
15663 (when (car pack-body-file-marker)
15664 (insert " (")
15665 (setq start (point))
15666 (insert "body")
15667 (speedbar-make-button
15668 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15669 'vhdl-speedbar-find-file pack-body-file-marker)
15670 (insert ")"))
15671 (setq start (point))
15672 (insert " (" lib-name ")")
15673 (put-text-property (+ 2 start) (1- (point)) 'face
15674 'vhdl-speedbar-library-face)
15675 (insert-char ?\n 1)
15676 (put-text-property visible-start (point) 'invisible nil)))
15678 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15679 func-body-file-marker
15680 depth)
15681 "Insert subprogram entry."
15682 (let ((start (point))
15683 visible-start)
15684 (insert (int-to-string depth) ":")
15685 (put-text-property start (point) 'invisible t)
15686 (setq visible-start (point))
15687 (insert-char ? (* depth speedbar-indentation-width))
15688 (put-text-property visible-start (point) 'invisible nil)
15689 (setq start (point))
15690 (insert ">")
15691 (speedbar-make-button start (point) nil nil nil)
15692 (setq visible-start (point))
15693 (insert " ")
15694 (setq start (point))
15695 (insert func-name)
15696 (speedbar-make-button
15697 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15698 'vhdl-speedbar-find-file func-file-marker)
15699 (when (car func-body-file-marker)
15700 (insert " (")
15701 (setq start (point))
15702 (insert "body")
15703 (speedbar-make-button
15704 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15705 'vhdl-speedbar-find-file func-body-file-marker)
15706 (insert ")"))
15707 (insert-char ?\n 1)
15708 (put-text-property visible-start (point) 'invisible nil)))
15710 (defun vhdl-speedbar-make-title-line (text &optional depth)
15711 "Insert design unit title entry."
15712 (let ((start (point))
15713 visible-start)
15714 (when depth
15715 (insert (int-to-string depth) ":")
15716 (put-text-property start (point) 'invisible t))
15717 (setq visible-start (point))
15718 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15719 (setq start (point))
15720 (insert text)
15721 (speedbar-make-button start (point) nil nil nil nil)
15722 (insert-char ?\n 1)
15723 (put-text-property visible-start (point) 'invisible nil)))
15725 (defun vhdl-speedbar-insert-dirs (files level)
15726 "Insert subdirectories."
15727 (let ((dirs (car files)))
15728 (while dirs
15729 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15730 (car dirs) 'speedbar-dir-follow nil
15731 'speedbar-directory-face level)
15732 (setq dirs (cdr dirs)))))
15734 (declare-function speedbar-reset-scanners "speedbar" ())
15736 (defun vhdl-speedbar-dired (text token indent)
15737 "Speedbar click handler for directory expand button in hierarchy mode."
15738 (cond ((string-match "+" text) ; we have to expand this dir
15739 (setq speedbar-shown-directories
15740 (cons (expand-file-name
15741 (concat (speedbar-line-directory indent) token "/"))
15742 speedbar-shown-directories))
15743 (speedbar-change-expand-button-char ?-)
15744 (speedbar-reset-scanners)
15745 (speedbar-with-writable
15746 (save-excursion
15747 (end-of-line) (forward-char 1)
15748 (vhdl-speedbar-insert-dirs
15749 (speedbar-file-lists
15750 (concat (speedbar-line-directory indent) token "/"))
15751 (1+ indent))
15752 (speedbar-reset-scanners)
15753 (vhdl-speedbar-insert-dir-hierarchy
15754 (abbreviate-file-name
15755 (concat (speedbar-line-directory indent) token "/"))
15756 (1+ indent) speedbar-power-click)))
15757 (vhdl-speedbar-update-current-unit t t))
15758 ((string-match "-" text) ; we have to contract this node
15759 (speedbar-reset-scanners)
15760 (let ((oldl speedbar-shown-directories)
15761 (newl nil)
15762 (td (expand-file-name
15763 (concat (speedbar-line-directory indent) token))))
15764 (while oldl
15765 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15766 (push (car oldl) newl))
15767 (setq oldl (cdr oldl)))
15768 (setq speedbar-shown-directories (nreverse newl)))
15769 (speedbar-change-expand-button-char ?+)
15770 (speedbar-delete-subblock indent))
15771 (t (error "Nothing to display")))
15772 (when (equal (selected-frame) speedbar-frame)
15773 (speedbar-center-buffer-smartly)))
15775 (declare-function speedbar-files-item-info "speedbar" ())
15777 (defun vhdl-speedbar-item-info ()
15778 "Derive and display information about this line item."
15779 (save-excursion
15780 (beginning-of-line)
15781 ;; skip invisible number info
15782 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15783 (cond
15784 ;; project/directory entry
15785 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15786 (if vhdl-speedbar-show-projects
15787 (message "Project \"%s\"" (match-string-no-properties 1))
15788 (speedbar-files-item-info)))
15789 ;; design unit entry
15790 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15791 (goto-char (match-end 1))
15792 (let ((face (get-text-property (point) 'face)))
15793 (message
15794 "%s \"%s\" in \"%s\""
15795 ;; design unit kind
15796 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15797 (eq face 'vhdl-speedbar-entity-selected-face))
15798 (if (equal (match-string 2) ">") "Component" "Entity"))
15799 ((or (eq face 'vhdl-speedbar-architecture-face)
15800 (eq face 'vhdl-speedbar-architecture-selected-face))
15801 "Architecture")
15802 ((or (eq face 'vhdl-speedbar-configuration-face)
15803 (eq face 'vhdl-speedbar-configuration-selected-face))
15804 "Configuration")
15805 ((or (eq face 'vhdl-speedbar-package-face)
15806 (eq face 'vhdl-speedbar-package-selected-face))
15807 "Package")
15808 ((or (eq face 'vhdl-speedbar-instantiation-face)
15809 (eq face 'vhdl-speedbar-instantiation-selected-face))
15810 "Instantiation")
15811 ((eq face 'vhdl-speedbar-subprogram-face)
15812 "Subprogram")
15813 (t ""))
15814 ;; design unit name
15815 (buffer-substring-no-properties
15816 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15817 (match-end 1))
15818 ;; file name
15819 (file-relative-name
15820 (or (car (get-text-property (point) 'speedbar-token))
15821 "?")
15822 (vhdl-default-directory)))))
15823 (t (message "")))))
15825 (declare-function speedbar-line-text "speedbar" (&optional p))
15827 (defun vhdl-speedbar-line-text ()
15828 "Calls `speedbar-line-text' and removes text properties."
15829 (let ((string (speedbar-line-text)))
15830 (set-text-properties 0 (length string) nil string)
15831 string))
15833 (defun vhdl-speedbar-higher-text ()
15834 "Get speedbar-line-text of higher level."
15835 (let (depth string)
15836 (save-excursion
15837 (beginning-of-line)
15838 (looking-at "^\\([0-9]+\\):")
15839 (setq depth (string-to-number (match-string 1)))
15840 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15841 (setq string (match-string 1))
15842 (set-text-properties 0 (length string) nil string)
15843 string))))
15845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15846 ;; Help functions
15848 (defun vhdl-speedbar-line-key (&optional indent)
15849 "Get currently displayed directory of project name."
15850 (if vhdl-speedbar-show-projects
15851 (vhdl-speedbar-line-project)
15852 (abbreviate-file-name
15853 (file-name-as-directory (speedbar-line-directory indent)))))
15855 (defun vhdl-speedbar-line-project (&optional indent)
15856 "Get currently displayed project name."
15857 (and vhdl-speedbar-show-projects
15858 (save-excursion
15859 (end-of-line)
15860 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15861 (match-string-no-properties 1))))
15863 (defun vhdl-add-modified-file ()
15864 "Add file to `vhdl-modified-file-list'."
15865 (when vhdl-file-alist
15866 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15867 nil)
15869 (defun vhdl-resolve-paths (path-list)
15870 "Resolve path wildcards in PATH-LIST."
15871 (let (path-list-1 path-list-2 path-beg path-end dir)
15872 ;; eliminate non-existent directories
15873 (while path-list
15874 (setq dir (car path-list))
15875 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15876 (if (file-directory-p (match-string 2 dir))
15877 (push dir path-list-1)
15878 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15879 (setq path-list (cdr path-list)))
15880 ;; resolve path wildcards
15881 (while path-list-1
15882 (setq dir (car path-list-1))
15883 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15884 (progn
15885 (setq path-beg (match-string 1 dir)
15886 path-end (match-string 5 dir))
15887 (setq path-list-1
15888 (append
15889 (mapcar
15890 (function
15891 (lambda (var) (concat path-beg var path-end)))
15892 (let ((all-list (vhdl-directory-files
15893 (match-string 2 dir) t
15894 (concat "\\<" (wildcard-to-regexp
15895 (match-string 4 dir)))))
15896 dir-list)
15897 (while all-list
15898 (when (file-directory-p (car all-list))
15899 (push (car all-list) dir-list))
15900 (setq all-list (cdr all-list)))
15901 dir-list))
15902 (cdr path-list-1))))
15903 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15904 (when (file-directory-p (match-string 2 dir))
15905 (push dir path-list-2))
15906 (setq path-list-1 (cdr path-list-1))))
15907 (nreverse path-list-2)))
15909 (defun vhdl-speedbar-goto-this-unit (directory unit)
15910 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15911 (let ((dest (point)))
15912 (if (and (if vhdl-speedbar-show-projects
15913 (progn (goto-char (point-min)) t)
15914 (speedbar-goto-this-file directory))
15915 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15916 (progn (speedbar-position-cursor-on-line)
15918 (goto-char dest)
15919 nil)))
15921 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15922 (declare-function speedbar-set-timer "speedbar" (timeout))
15923 ;; speedbar loads dframe at runtime.
15924 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15926 (defun vhdl-speedbar-find-file (text token indent)
15927 "When user clicks on TEXT, load file with name and position in TOKEN.
15928 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15929 is already shown in a buffer."
15930 (if (not (car token))
15931 (error "ERROR: File cannot be found")
15932 (let ((buffer (get-file-buffer (car token))))
15933 (speedbar-find-file-in-frame (car token))
15934 (when (or vhdl-speedbar-jump-to-unit buffer)
15935 (goto-char (point-min))
15936 (forward-line (1- (cdr token)))
15937 (recenter))
15938 (vhdl-speedbar-update-current-unit t t)
15939 (speedbar-set-timer dframe-update-speed)
15940 (dframe-maybee-jump-to-attached-frame))))
15942 (defun vhdl-speedbar-port-copy ()
15943 "Copy the port of the entity/component or subprogram under the cursor."
15944 (interactive)
15945 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15946 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15947 (error "ERROR: No entity/component or subprogram under cursor")
15948 (beginning-of-line)
15949 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15950 (condition-case info
15951 (let ((token (get-text-property
15952 (match-beginning 3) 'speedbar-token)))
15953 (vhdl-visit-file (car token) t
15954 (progn (goto-char (point-min))
15955 (forward-line (1- (cdr token)))
15956 (end-of-line)
15957 (if is-entity
15958 (vhdl-port-copy)
15959 (vhdl-subprog-copy)))))
15960 (error (error "ERROR: %s not scanned successfully\n (%s)"
15961 (if is-entity "Port" "Interface") (cadr info))))
15962 (error "ERROR: No entity/component or subprogram on current line")))))
15964 (defun vhdl-speedbar-place-component ()
15965 "Place the entity/component under the cursor as component."
15966 (interactive)
15967 (if (not (vhdl-speedbar-check-unit 'entity))
15968 (error "ERROR: No entity/component under cursor")
15969 (vhdl-speedbar-port-copy)
15970 (if (fboundp 'speedbar-select-attached-frame)
15971 (speedbar-select-attached-frame)
15972 (select-frame speedbar-attached-frame))
15973 (vhdl-compose-place-component)
15974 (select-frame speedbar-frame)))
15976 (defun vhdl-speedbar-configuration ()
15977 "Generate configuration for the architecture under the cursor."
15978 (interactive)
15979 (if (not (vhdl-speedbar-check-unit 'architecture))
15980 (error "ERROR: No architecture under cursor")
15981 (let ((arch-name (vhdl-speedbar-line-text))
15982 (ent-name (vhdl-speedbar-higher-text)))
15983 (if (fboundp 'speedbar-select-attached-frame)
15984 (speedbar-select-attached-frame)
15985 (select-frame speedbar-attached-frame))
15986 (vhdl-compose-configuration ent-name arch-name))))
15988 (defun vhdl-speedbar-select-mra ()
15989 "Select the architecture under the cursor as MRA."
15990 (interactive)
15991 (if (not (vhdl-speedbar-check-unit 'architecture))
15992 (error "ERROR: No architecture under cursor")
15993 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15994 (ent-key (downcase (vhdl-speedbar-higher-text)))
15995 (ent-alist (vhdl-aget
15996 vhdl-entity-alist
15997 (or (vhdl-project-p)
15998 (abbreviate-file-name default-directory))))
15999 (ent-entry (vhdl-aget ent-alist ent-key)))
16000 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
16001 (speedbar-refresh))))
16003 (declare-function speedbar-line-file "speedbar" (&optional p))
16005 (defun vhdl-speedbar-make-design ()
16006 "Make (compile) design unit or directory/project under the cursor."
16007 (interactive)
16008 (if (not (save-excursion (beginning-of-line)
16009 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
16010 (error "ERROR: No primary design unit or directory/project under cursor")
16011 (let ((is-unit (match-string 2))
16012 (unit-name (vhdl-speedbar-line-text))
16013 (vhdl-project (vhdl-speedbar-line-project))
16014 (directory (file-name-as-directory
16015 (or (speedbar-line-file) (speedbar-line-directory)))))
16016 (if (fboundp 'speedbar-select-attached-frame)
16017 (speedbar-select-attached-frame)
16018 (select-frame speedbar-attached-frame))
16019 (let ((default-directory directory))
16020 (vhdl-make (and is-unit unit-name))))))
16022 (defun vhdl-speedbar-generate-makefile ()
16023 "Generate Makefile for directory/project under the cursor."
16024 (interactive)
16025 (let ((vhdl-project (vhdl-speedbar-line-project))
16026 (default-directory (file-name-as-directory
16027 (or (speedbar-line-file) (speedbar-line-directory)))))
16028 (vhdl-generate-makefile)))
16030 (defun vhdl-speedbar-check-unit (design-unit)
16031 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
16032 expansion function)."
16033 (save-excursion
16034 (speedbar-position-cursor-on-line)
16035 (cond ((eq design-unit 'entity)
16036 (memq (get-text-property (match-end 0) 'face)
16037 '(vhdl-speedbar-entity-face
16038 vhdl-speedbar-entity-selected-face)))
16039 ((eq design-unit 'architecture)
16040 (memq (get-text-property (match-end 0) 'face)
16041 '(vhdl-speedbar-architecture-face
16042 vhdl-speedbar-architecture-selected-face)))
16043 ((eq design-unit 'subprogram)
16044 (eq (get-text-property (match-end 0) 'face)
16045 'vhdl-speedbar-subprogram-face))
16046 (t nil))))
16048 (defun vhdl-speedbar-set-depth (depth)
16049 "Set hierarchy display depth to DEPTH and refresh speedbar."
16050 (setq vhdl-speedbar-hierarchy-depth depth)
16051 (speedbar-refresh))
16053 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16054 ;; Fontification
16056 (defface vhdl-speedbar-entity-face
16057 '((((class color) (background light)) (:foreground "ForestGreen"))
16058 (((class color) (background dark)) (:foreground "PaleGreen")))
16059 "Face used for displaying entity names."
16060 :group 'speedbar-faces)
16062 (defface vhdl-speedbar-architecture-face
16063 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
16064 (((class color) (background light)) (:foreground "Blue"))
16066 (((class color) (background dark)) (:foreground "LightSkyBlue")))
16067 "Face used for displaying architecture names."
16068 :group 'speedbar-faces)
16070 (defface vhdl-speedbar-configuration-face
16071 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
16072 (((class color) (background dark)) (:foreground "Salmon")))
16073 "Face used for displaying configuration names."
16074 :group 'speedbar-faces)
16076 (defface vhdl-speedbar-package-face
16077 '((((class color) (background light)) (:foreground "Grey50"))
16078 (((class color) (background dark)) (:foreground "Grey80")))
16079 "Face used for displaying package names."
16080 :group 'speedbar-faces)
16082 (defface vhdl-speedbar-library-face
16083 '((((class color) (background light)) (:foreground "Purple"))
16084 (((class color) (background dark)) (:foreground "Orchid1")))
16085 "Face used for displaying library names."
16086 :group 'speedbar-faces)
16088 (defface vhdl-speedbar-instantiation-face
16089 '((((class color) (background light)) (:foreground "Brown"))
16090 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
16091 (((class color) (background dark)) (:foreground "Yellow")))
16092 "Face used for displaying instantiation names."
16093 :group 'speedbar-faces)
16095 (defface vhdl-speedbar-subprogram-face
16096 '((((class color) (background light)) (:foreground "Orchid4"))
16097 (((class color) (background dark)) (:foreground "BurlyWood2")))
16098 "Face used for displaying subprogram names."
16099 :group 'speedbar-faces)
16101 (defface vhdl-speedbar-entity-selected-face
16102 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
16103 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
16104 "Face used for displaying entity names."
16105 :group 'speedbar-faces)
16107 (defface vhdl-speedbar-architecture-selected-face
16108 '((((min-colors 88) (class color) (background light)) (:foreground
16109 "Blue1" :underline t))
16110 (((class color) (background light)) (:foreground "Blue" :underline t))
16111 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
16112 "Face used for displaying architecture names."
16113 :group 'speedbar-faces)
16115 (defface vhdl-speedbar-configuration-selected-face
16116 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
16117 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
16118 "Face used for displaying configuration names."
16119 :group 'speedbar-faces)
16121 (defface vhdl-speedbar-package-selected-face
16122 '((((class color) (background light)) (:foreground "Grey50" :underline t))
16123 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
16124 "Face used for displaying package names."
16125 :group 'speedbar-faces)
16127 (defface vhdl-speedbar-instantiation-selected-face
16128 '((((class color) (background light)) (:foreground "Brown" :underline t))
16129 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
16130 "Face used for displaying instantiation names."
16131 :group 'speedbar-faces)
16133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16134 ;; Initialization
16136 ;; add speedbar
16137 (when (fboundp 'speedbar)
16138 (let ((current-frame (selected-frame)))
16139 (condition-case ()
16140 (when (and vhdl-speedbar-auto-open
16141 (not (and (boundp 'speedbar-frame)
16142 (frame-live-p speedbar-frame))))
16143 (speedbar-frame-mode 1))
16144 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
16145 (select-frame current-frame)))
16147 ;; initialize speedbar
16148 (if (not (boundp 'speedbar-frame))
16149 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
16150 (vhdl-speedbar-initialize)
16151 (when speedbar-frame (vhdl-speedbar-refresh)))
16154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16155 ;;; Structural composition
16156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16158 (defun vhdl-get-components-package-name ()
16159 "Return the name of the components package."
16160 (let ((project (vhdl-project-p)))
16161 (if project
16162 (vhdl-replace-string (car vhdl-components-package-name)
16163 (subst-char-in-string ? ?_ project))
16164 (cdr vhdl-components-package-name))))
16166 (defun vhdl-compose-new-component ()
16167 "Create entity and architecture for new component."
16168 (interactive)
16169 (let* ((case-fold-search t)
16170 (ent-name (read-from-minibuffer "entity name: "
16171 nil vhdl-minibuffer-local-map))
16172 (arch-name
16173 (if (equal (cdr vhdl-compose-architecture-name) "")
16174 (read-from-minibuffer "architecture name: "
16175 nil vhdl-minibuffer-local-map)
16176 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16177 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16178 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16179 ;; open entity file
16180 (unless (eq vhdl-compose-create-files 'none)
16181 (setq ent-file-name
16182 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16183 "." (file-name-extension (buffer-file-name))))
16184 (when (and (file-exists-p ent-file-name)
16185 (not (y-or-n-p (concat "File \"" ent-file-name
16186 "\" exists; overwrite? "))))
16187 (error "ERROR: Creating component...aborted"))
16188 (find-file ent-file-name)
16189 (erase-buffer)
16190 (set-buffer-modified-p nil))
16191 ;; insert header
16192 (if vhdl-compose-include-header
16193 (progn (vhdl-template-header)
16194 (setq end-pos (point))
16195 (goto-char (point-max)))
16196 (vhdl-comment-display-line) (insert "\n\n"))
16197 ;; insert library clause
16198 (vhdl-template-package-std-logic-1164)
16199 (when vhdl-use-components-package
16200 (insert "\n")
16201 (vhdl-template-standard-package (vhdl-work-library)
16202 (vhdl-get-components-package-name)))
16203 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16204 ;; insert entity declaration
16205 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16206 (vhdl-insert-keyword " IS\n")
16207 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16208 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16209 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16210 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16211 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16212 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16213 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16214 (vhdl-insert-keyword "END ")
16215 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16216 (insert ent-name ";\n\n")
16217 (vhdl-comment-display-line) (insert "\n")
16218 ;; open architecture file
16219 (if (not (eq vhdl-compose-create-files 'separate))
16220 (insert "\n")
16221 (goto-char (or end-pos (point-min)))
16222 (setq ent-buffer (current-buffer))
16223 (setq arch-file-name
16224 (concat (vhdl-replace-string vhdl-architecture-file-name
16225 (concat ent-name " " arch-name) t)
16226 "." (file-name-extension (buffer-file-name))))
16227 (when (and (file-exists-p arch-file-name)
16228 (not (y-or-n-p (concat "File \"" arch-file-name
16229 "\" exists; overwrite? "))))
16230 (error "ERROR: Creating component...aborted"))
16231 (find-file arch-file-name)
16232 (erase-buffer)
16233 (set-buffer-modified-p nil)
16234 ;; insert header
16235 (if vhdl-compose-include-header
16236 (progn (vhdl-template-header)
16237 (goto-char (point-max)))
16238 (vhdl-comment-display-line) (insert "\n\n")))
16239 ;; insert architecture body
16240 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16241 (vhdl-insert-keyword " OF ") (insert ent-name)
16242 (vhdl-insert-keyword " IS\n\n")
16243 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16244 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16245 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16246 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16247 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16248 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16249 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16250 (vhdl-insert-keyword "BEGIN")
16251 (when vhdl-self-insert-comments
16252 (insert " -- ")
16253 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16254 (insert arch-name))
16255 (insert "\n\n")
16256 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16257 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16258 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16259 (vhdl-insert-keyword "END ")
16260 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16261 (insert arch-name ";\n\n")
16262 ;; insert footer and save
16263 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16264 (vhdl-template-footer)
16265 (vhdl-comment-display-line) (insert "\n"))
16266 (goto-char (or end-pos (point-min)))
16267 (setq arch-buffer (current-buffer))
16268 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16269 (set-buffer arch-buffer) (save-buffer)
16270 (message "%s"
16271 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16272 (and ent-file-name
16273 (format "\n File created: \"%s\"" ent-file-name))
16274 (and arch-file-name
16275 (format "\n File created: \"%s\"" arch-file-name))))))
16277 (defun vhdl-compose-place-component ()
16278 "Place new component by pasting current port as component declaration and
16279 component instantiation."
16280 (interactive)
16281 (if (not vhdl-port-list)
16282 (error "ERROR: No port has been read")
16283 (save-excursion
16284 (vhdl-prepare-search-2
16285 (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)
16286 (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))
16287 (error "ERROR: No architecture found"))
16288 (let* ((ent-name (match-string 1))
16289 (ent-file-name
16290 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16291 "." (file-name-extension (buffer-file-name))))
16292 (orig-buffer (current-buffer)))
16293 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16294 ;; place component declaration
16295 (unless (or vhdl-use-components-package
16296 (vhdl-use-direct-instantiation)
16297 (save-excursion
16298 (re-search-forward
16299 (concat "^\\s-*component\\s-+"
16300 (car vhdl-port-list) "\\>") nil t)))
16301 (re-search-forward "^begin\\>" nil)
16302 (beginning-of-line)
16303 (skip-chars-backward " \t\n\r\f")
16304 (insert "\n\n") (indent-to vhdl-basic-offset)
16305 (vhdl-port-paste-component t))
16306 ;; place component instantiation
16307 (re-search-forward "^end\\>" nil)
16308 (beginning-of-line)
16309 (skip-chars-backward " \t\n\r\f")
16310 (insert "\n\n") (indent-to vhdl-basic-offset)
16311 (vhdl-port-paste-instance nil t t)
16312 ;; place use clause for used packages
16313 (when (nth 3 vhdl-port-list)
16314 ;; open entity file
16315 (when (file-exists-p ent-file-name)
16316 (find-file ent-file-name))
16317 (goto-char (point-min))
16318 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16319 (error "ERROR: Entity not found: \"%s\"" ent-name))
16320 (goto-char (match-beginning 0))
16321 (if (and (save-excursion
16322 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16323 (match-string 1))
16324 (progn (goto-char (match-end 0))
16325 (beginning-of-line 2))
16326 (insert "\n")
16327 (backward-char))
16328 (vhdl-port-paste-context-clause)
16329 (switch-to-buffer orig-buffer))
16330 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16332 (defun vhdl-compose-wire-components ()
16333 "Connect components."
16334 (interactive)
16335 (save-excursion
16336 (vhdl-prepare-search-2
16337 (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)
16338 (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))
16339 (error "ERROR: No architecture found"))
16340 (let* ((ent-name (match-string 1))
16341 (ent-file-name
16342 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16343 "." (file-name-extension (buffer-file-name))))
16344 (arch-decl-pos (point-marker))
16345 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16346 (arch-end-pos (re-search-forward "^end\\>" nil))
16347 (pack-name (vhdl-get-components-package-name))
16348 (pack-file-name
16349 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16350 "." (file-name-extension (buffer-file-name))))
16351 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16352 port-alist generic-alist inst-alist
16353 signal-name signal-entry signal-alist local-list written-list
16354 single-in-list multi-in-list single-out-list multi-out-list
16355 constant-name constant-entry constant-alist single-list multi-list
16356 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16357 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16358 signal-beg-pos signal-pos
16359 constant-temp-pos port-temp-pos signal-temp-pos)
16360 (message "Wiring components...")
16361 ;; process all instances
16362 (goto-char arch-stat-pos)
16363 (while (re-search-forward
16364 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16365 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16366 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16367 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16368 "[ \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)
16369 (setq inst-name (match-string-no-properties 1)
16370 comp-name (match-string-no-properties 4)
16371 comp-ent-name (match-string-no-properties 12)
16372 has-generic (or (match-string 7) (match-string 17)))
16373 ;; get port ...
16374 (if comp-name
16375 ;; ... from component declaration
16376 (vhdl-visit-file
16377 (when vhdl-use-components-package pack-file-name) t
16378 (save-excursion
16379 (goto-char (point-min))
16380 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16381 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16382 (vhdl-port-copy)))
16383 ;; ... from entity declaration (direct instantiation)
16384 (setq comp-ent-file-name
16385 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16386 "." (file-name-extension (buffer-file-name))))
16387 (vhdl-visit-file
16388 comp-ent-file-name t
16389 (save-excursion
16390 (goto-char (point-min))
16391 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16392 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16393 (vhdl-port-copy))))
16394 (vhdl-port-flatten t)
16395 (setq generic-alist (nth 1 vhdl-port-list)
16396 port-alist (nth 2 vhdl-port-list)
16397 vhdl-port-list nil)
16398 (setq constant-alist nil
16399 signal-alist nil)
16400 (when has-generic
16401 ;; process all constants in generic map
16402 (vhdl-forward-syntactic-ws)
16403 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16404 (setq constant-name (match-string-no-properties 3))
16405 (setq constant-entry
16406 (cons constant-name
16407 (if (match-string 1)
16408 (or (vhdl-aget generic-alist (match-string 2))
16409 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16410 (cdar generic-alist))))
16411 (push constant-entry constant-alist)
16412 (setq constant-name (downcase constant-name))
16413 (if (or (member constant-name single-list)
16414 (member constant-name multi-list))
16415 (progn (setq single-list (delete constant-name single-list))
16416 (pushnew constant-name multi-list :test #'equal))
16417 (pushnew constant-name single-list :test #'equal))
16418 (unless (match-string 1)
16419 (setq generic-alist (cdr generic-alist)))
16420 (vhdl-forward-syntactic-ws))
16421 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16422 ;; process all signals in port map
16423 (vhdl-forward-syntactic-ws)
16424 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16425 (setq signal-name (match-string-no-properties 3))
16426 (setq signal-entry
16427 (cons signal-name
16428 (if (match-string 1)
16429 (or (vhdl-aget port-alist (match-string 2))
16430 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16431 (cdar port-alist))))
16432 (push signal-entry signal-alist)
16433 (setq signal-name (downcase signal-name))
16434 (if (equal (upcase (nth 2 signal-entry)) "IN")
16435 ;; input signal
16436 (cond
16437 ((member signal-name local-list)
16438 nil)
16439 ((or (member signal-name single-out-list)
16440 (member signal-name multi-out-list))
16441 (setq single-out-list (delete signal-name single-out-list))
16442 (setq multi-out-list (delete signal-name multi-out-list))
16443 (pushnew signal-name local-list :test #'equal))
16444 ((member signal-name single-in-list)
16445 (setq single-in-list (delete signal-name single-in-list))
16446 (pushnew signal-name multi-in-list :test #'equal))
16447 ((not (member signal-name multi-in-list))
16448 (pushnew signal-name single-in-list :test #'equal)))
16449 ;; output signal
16450 (cond
16451 ((member signal-name local-list)
16452 nil)
16453 ((or (member signal-name single-in-list)
16454 (member signal-name multi-in-list))
16455 (setq single-in-list (delete signal-name single-in-list))
16456 (setq multi-in-list (delete signal-name multi-in-list))
16457 (pushnew signal-name local-list :test #'equal))
16458 ((member signal-name single-out-list)
16459 (setq single-out-list (delete signal-name single-out-list))
16460 (pushnew signal-name multi-out-list :test #'equal))
16461 ((not (member signal-name multi-out-list))
16462 (pushnew signal-name single-out-list :test #'equal))))
16463 (unless (match-string 1)
16464 (setq port-alist (cdr port-alist)))
16465 (vhdl-forward-syntactic-ws))
16466 (push (list inst-name (nreverse constant-alist)
16467 (nreverse signal-alist))
16468 inst-alist))
16469 ;; prepare signal insertion
16470 (vhdl-goto-marker arch-decl-pos)
16471 (forward-line 1)
16472 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16473 (setq signal-pos (point-marker))
16474 (while (progn (vhdl-forward-syntactic-ws)
16475 (looking-at "signal\\>"))
16476 (beginning-of-line 2)
16477 (delete-region signal-pos (point)))
16478 (setq signal-beg-pos signal-pos)
16479 ;; open entity file
16480 (when (file-exists-p ent-file-name)
16481 (find-file ent-file-name))
16482 (goto-char (point-min))
16483 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16484 (error "ERROR: Entity not found: \"%s\"" ent-name))
16485 ;; prepare generic clause insertion
16486 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16487 (match-string 1))
16488 (goto-char (match-beginning 0))
16489 (indent-to vhdl-basic-offset)
16490 (insert "generic ();\n\n")
16491 (backward-char 4))
16492 (backward-char)
16493 (setq generic-pos (point-marker))
16494 (forward-sexp) (end-of-line)
16495 (delete-region generic-pos (point)) (delete-char 1)
16496 (insert "(\n")
16497 (when multi-list
16498 (insert "\n")
16499 (indent-to (* 2 vhdl-basic-offset))
16500 (insert "-- global generics\n"))
16501 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16502 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16503 ;; prepare port clause insertion
16504 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16505 (match-string 1))
16506 (goto-char (match-beginning 0))
16507 (indent-to vhdl-basic-offset)
16508 (insert "port ();\n\n")
16509 (backward-char 4))
16510 (backward-char)
16511 (setq port-in-pos (point-marker))
16512 (forward-sexp) (end-of-line)
16513 (delete-region port-in-pos (point)) (delete-char 1)
16514 (insert "(\n")
16515 (when (or multi-in-list multi-out-list)
16516 (insert "\n")
16517 (indent-to (* 2 vhdl-basic-offset))
16518 (insert "-- global ports\n"))
16519 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16520 port-out-pos (point-marker) port-inst-pos (point-marker)
16521 port-end-pos (point-marker))
16522 ;; insert generics, ports and signals
16523 (setq inst-alist (nreverse inst-alist))
16524 (while inst-alist
16525 (setq inst-name (nth 0 (car inst-alist))
16526 constant-alist (nth 1 (car inst-alist))
16527 signal-alist (nth 2 (car inst-alist))
16528 constant-temp-pos generic-inst-pos
16529 port-temp-pos port-inst-pos
16530 signal-temp-pos signal-pos)
16531 ;; generics
16532 (while constant-alist
16533 (setq constant-name (downcase (caar constant-alist))
16534 constant-entry (car constant-alist))
16535 (unless (string-match "^[0-9]+" constant-name)
16536 (cond ((member constant-name written-list)
16537 nil)
16538 ((member constant-name multi-list)
16539 (vhdl-goto-marker generic-pos)
16540 (setq generic-end-pos
16541 (vhdl-max-marker
16542 generic-end-pos
16543 (vhdl-compose-insert-generic constant-entry)))
16544 (setq generic-pos (point-marker))
16545 (pushnew constant-name written-list :test #'equal))
16547 (vhdl-goto-marker
16548 (vhdl-max-marker generic-inst-pos generic-pos))
16549 (setq generic-end-pos
16550 (vhdl-compose-insert-generic constant-entry))
16551 (setq generic-inst-pos (point-marker))
16552 (pushnew constant-name written-list :test #'equal))))
16553 (setq constant-alist (cdr constant-alist)))
16554 (when (/= constant-temp-pos generic-inst-pos)
16555 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16556 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16557 (insert "-- generics for \"" inst-name "\"\n")
16558 (vhdl-goto-marker generic-inst-pos))
16559 ;; ports and signals
16560 (while signal-alist
16561 (setq signal-name (downcase (caar signal-alist))
16562 signal-entry (car signal-alist))
16563 (cond ((member signal-name written-list)
16564 nil)
16565 ((member signal-name multi-in-list)
16566 (vhdl-goto-marker port-in-pos)
16567 (setq port-end-pos
16568 (vhdl-max-marker
16569 port-end-pos (vhdl-compose-insert-port signal-entry)))
16570 (setq port-in-pos (point-marker))
16571 (pushnew signal-name written-list :test #'equal))
16572 ((member signal-name multi-out-list)
16573 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16574 (setq port-end-pos
16575 (vhdl-max-marker
16576 port-end-pos (vhdl-compose-insert-port signal-entry)))
16577 (setq port-out-pos (point-marker))
16578 (pushnew signal-name written-list :test #'equal))
16579 ((or (member signal-name single-in-list)
16580 (member signal-name single-out-list))
16581 (vhdl-goto-marker
16582 (vhdl-max-marker
16583 port-inst-pos
16584 (vhdl-max-marker port-out-pos port-in-pos)))
16585 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16586 (setq port-inst-pos (point-marker))
16587 (pushnew signal-name written-list :test #'equal))
16588 ((equal (upcase (nth 2 signal-entry)) "OUT")
16589 (vhdl-goto-marker signal-pos)
16590 (vhdl-compose-insert-signal signal-entry)
16591 (setq signal-pos (point-marker))
16592 (pushnew signal-name written-list :test #'equal)))
16593 (setq signal-alist (cdr signal-alist)))
16594 (when (/= port-temp-pos port-inst-pos)
16595 (vhdl-goto-marker
16596 (vhdl-max-marker port-temp-pos
16597 (vhdl-max-marker port-in-pos port-out-pos)))
16598 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16599 (insert "-- ports to \"" inst-name "\"\n")
16600 (vhdl-goto-marker port-inst-pos))
16601 (when (/= signal-temp-pos signal-pos)
16602 (vhdl-goto-marker signal-temp-pos)
16603 (insert "\n") (indent-to vhdl-basic-offset)
16604 (insert "-- outputs of \"" inst-name "\"\n")
16605 (vhdl-goto-marker signal-pos))
16606 (setq inst-alist (cdr inst-alist)))
16607 ;; finalize generic/port clause
16608 (vhdl-goto-marker generic-end-pos) (backward-char)
16609 (when (= generic-beg-pos generic-end-pos)
16610 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16611 (insert ";") (backward-char))
16612 (insert ")")
16613 (vhdl-goto-marker port-end-pos) (backward-char)
16614 (when (= port-beg-pos port-end-pos)
16615 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16616 (insert ";") (backward-char))
16617 (insert ")")
16618 ;; align everything
16619 (when vhdl-auto-align
16620 (vhdl-goto-marker generic-beg-pos)
16621 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16622 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16623 (vhdl-goto-marker signal-beg-pos)
16624 (vhdl-align-region-groups signal-beg-pos signal-pos))
16625 (switch-to-buffer (marker-buffer signal-beg-pos))
16626 (message "Wiring components...done")))))
16628 (defun vhdl-compose-insert-generic (entry)
16629 "Insert ENTRY as generic declaration."
16630 (let (pos)
16631 (indent-to (* 2 vhdl-basic-offset))
16632 (insert (nth 0 entry) " : " (nth 1 entry))
16633 (when (nth 2 entry)
16634 (insert " := " (nth 2 entry)))
16635 (insert ";")
16636 (setq pos (point-marker))
16637 (when (and vhdl-include-port-comments (nth 3 entry))
16638 (vhdl-comment-insert-inline (nth 3 entry) t))
16639 (insert "\n")
16640 pos))
16642 (defun vhdl-compose-insert-port (entry)
16643 "Insert ENTRY as port declaration."
16644 (let (pos)
16645 (indent-to (* 2 vhdl-basic-offset))
16646 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16647 (setq pos (point-marker))
16648 (when (and vhdl-include-port-comments (nth 4 entry))
16649 (vhdl-comment-insert-inline (nth 4 entry) t))
16650 (insert "\n")
16651 pos))
16653 (defun vhdl-compose-insert-signal (entry)
16654 "Insert ENTRY as signal declaration."
16655 (indent-to vhdl-basic-offset)
16656 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16657 (when (and vhdl-include-port-comments (nth 4 entry))
16658 (vhdl-comment-insert-inline (nth 4 entry) t))
16659 (insert "\n"))
16661 (defun vhdl-compose-components-package ()
16662 "Generate a package containing component declarations for all entities in the
16663 current project/directory."
16664 (interactive)
16665 (vhdl-require-hierarchy-info)
16666 (let* ((project (vhdl-project-p))
16667 (pack-name (vhdl-get-components-package-name))
16668 (pack-file-name
16669 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16670 "." (file-name-extension (buffer-file-name))))
16671 (ent-alist (vhdl-aget vhdl-entity-alist
16672 (or project
16673 (abbreviate-file-name default-directory))))
16674 (lazy-lock-minimum-size 0)
16675 clause-pos component-pos)
16676 (message "Generating components package \"%s\"..." pack-name)
16677 ;; open package file
16678 (when (and (file-exists-p pack-file-name)
16679 (not (y-or-n-p (concat "File \"" pack-file-name
16680 "\" exists; overwrite? "))))
16681 (error "ERROR: Generating components package...aborted"))
16682 (find-file pack-file-name)
16683 (erase-buffer)
16684 ;; insert header
16685 (if vhdl-compose-include-header
16686 (progn (vhdl-template-header
16687 (concat "Components package (generated by Emacs VHDL Mode "
16688 vhdl-version ")"))
16689 (goto-char (point-max)))
16690 (vhdl-comment-display-line) (insert "\n\n"))
16691 ;; insert std_logic_1164 package
16692 (vhdl-template-package-std-logic-1164)
16693 (insert "\n") (setq clause-pos (point-marker))
16694 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16695 ;; insert package declaration
16696 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16697 (vhdl-insert-keyword " IS\n\n")
16698 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16699 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16700 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16701 (indent-to vhdl-basic-offset)
16702 (setq component-pos (point-marker))
16703 (insert "\n\n") (vhdl-insert-keyword "END ")
16704 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16705 (insert pack-name ";\n\n")
16706 ;; insert footer
16707 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16708 (vhdl-template-footer)
16709 (vhdl-comment-display-line) (insert "\n"))
16710 ;; insert component declarations
16711 (while ent-alist
16712 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16713 (progn (goto-char (point-min))
16714 (forward-line (1- (nth 3 (car ent-alist))))
16715 (end-of-line)
16716 (vhdl-port-copy)))
16717 (goto-char component-pos)
16718 (vhdl-port-paste-component t)
16719 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16720 (setq component-pos (point-marker))
16721 (goto-char clause-pos)
16722 (vhdl-port-paste-context-clause pack-name)
16723 (setq clause-pos (point-marker))
16724 (setq ent-alist (cdr ent-alist)))
16725 (goto-char (point-min))
16726 (save-buffer)
16727 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16728 pack-name pack-file-name)))
16730 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16731 conf-alist inst-alist
16732 &optional insert-conf)
16733 "Generate block configuration for architecture."
16734 (let ((margin (current-indentation))
16735 (beg (point-at-bol))
16736 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16737 ;; insert block configuration (for architecture)
16738 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16739 (setq margin (+ margin vhdl-basic-offset))
16740 ;; process all instances
16741 (while inst-alist
16742 (setq inst-entry (car inst-alist))
16743 ;; is component?
16744 (when (nth 4 inst-entry)
16745 (setq insert-conf t)
16746 (setq inst-path (nth 9 inst-entry))
16747 ;; skip common path with previous instance
16748 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16749 (setq inst-path (cdr inst-path)
16750 inst-prev-path (cdr inst-prev-path)))
16751 ;; insert block configuration end (for previous block/generate)
16752 (while inst-prev-path
16753 (setq margin (- margin vhdl-basic-offset))
16754 (indent-to margin)
16755 (vhdl-insert-keyword "END FOR;\n")
16756 (setq inst-prev-path (cdr inst-prev-path)))
16757 ;; insert block configuration beginning (for current block/generate)
16758 (indent-to margin)
16759 (while inst-path
16760 (setq margin (+ margin vhdl-basic-offset))
16761 (vhdl-insert-keyword "FOR ")
16762 (insert (car inst-path) "\n")
16763 (indent-to margin)
16764 (setq inst-path (cdr inst-path)))
16765 ;; insert component configuration beginning
16766 (vhdl-insert-keyword "FOR ")
16767 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16768 ;; find subconfiguration
16769 (setq conf-key (nth 7 inst-entry))
16770 (setq tmp-alist conf-alist)
16771 ;; use first configuration found for instance's entity
16772 (while (and tmp-alist (null conf-key))
16773 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16774 (setq conf-key (nth 0 (car tmp-alist))))
16775 (setq tmp-alist (cdr tmp-alist)))
16776 (setq conf-entry (vhdl-aget conf-alist conf-key))
16777 ;; insert binding indication ...
16778 ;; ... with subconfiguration (if exists)
16779 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16780 (progn
16781 (indent-to (+ margin vhdl-basic-offset))
16782 (vhdl-insert-keyword "USE CONFIGURATION ")
16783 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16784 (insert ";\n"))
16785 ;; ... with entity (if exists)
16786 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16787 (when ent-entry
16788 (indent-to (+ margin vhdl-basic-offset))
16789 (vhdl-insert-keyword "USE ENTITY ")
16790 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16791 ;; insert architecture name (if architecture exists)
16792 (when (nth 3 ent-entry)
16793 (setq arch-name
16794 ;; choose architecture name a) from configuration,
16795 ;; b) from mra, or c) from first architecture
16796 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16797 (or (nth 6 inst-entry)
16798 (nth 4 ent-entry))))
16799 (nth 1 (car (nth 3 ent-entry)))))
16800 (insert "(" arch-name ")"))
16801 (insert ";\n")
16802 ;; insert block configuration (for architecture of subcomponent)
16803 (when (and vhdl-compose-configuration-hierarchical
16804 (nth 3 ent-entry))
16805 (indent-to (+ margin vhdl-basic-offset))
16806 (vhdl-compose-configuration-architecture
16807 (nth 0 ent-entry) arch-name ent-alist conf-alist
16808 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16809 ;; insert component configuration end
16810 (indent-to margin)
16811 (vhdl-insert-keyword "END FOR;\n")
16812 (setq inst-prev-path (nth 9 inst-entry)))
16813 (setq inst-alist (cdr inst-alist)))
16814 ;; insert block configuration end (for block/generate)
16815 (while inst-prev-path
16816 (setq margin (- margin vhdl-basic-offset))
16817 (indent-to margin)
16818 (vhdl-insert-keyword "END FOR;\n")
16819 (setq inst-prev-path (cdr inst-prev-path)))
16820 (indent-to (- margin vhdl-basic-offset))
16821 ;; insert block configuration end or remove beginning (for architecture)
16822 (if insert-conf
16823 (vhdl-insert-keyword "END FOR;\n")
16824 (delete-region beg (point)))))
16826 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16827 "Generate configuration declaration."
16828 (interactive)
16829 (vhdl-require-hierarchy-info)
16830 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16831 (or (vhdl-project-p)
16832 (abbreviate-file-name default-directory))))
16833 (conf-alist (vhdl-aget vhdl-config-alist
16834 (or (vhdl-project-p)
16835 (abbreviate-file-name default-directory))))
16836 (from-speedbar ent-name)
16837 inst-alist conf-name conf-file-name pos)
16838 (vhdl-prepare-search-2
16839 ;; get entity and architecture name
16840 (unless ent-name
16841 (save-excursion
16842 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16843 (not (equal "END" (upcase (match-string 1))))
16844 (setq ent-name (match-string-no-properties 3))
16845 (setq arch-name (match-string-no-properties 2)))
16846 (error "ERROR: Not within an architecture"))))
16847 (setq conf-name (vhdl-replace-string
16848 vhdl-compose-configuration-name
16849 (concat ent-name " " arch-name)))
16850 (setq inst-alist
16851 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16852 (downcase arch-name)))))
16853 (message "Generating configuration \"%s\"..." conf-name)
16854 (if vhdl-compose-configuration-create-file
16855 ;; open configuration file
16856 (progn
16857 (setq conf-file-name
16858 (concat (vhdl-replace-string vhdl-configuration-file-name
16859 conf-name t)
16860 "." (file-name-extension (buffer-file-name))))
16861 (when (and (file-exists-p conf-file-name)
16862 (not (y-or-n-p (concat "File \"" conf-file-name
16863 "\" exists; overwrite? "))))
16864 (error "ERROR: Creating configuration...aborted"))
16865 (find-file conf-file-name)
16866 (erase-buffer)
16867 (set-buffer-modified-p nil)
16868 ;; insert header
16869 (if vhdl-compose-include-header
16870 (progn (vhdl-template-header
16871 (concat "Configuration declaration for design \""
16872 ent-name "(" arch-name ")\""))
16873 (goto-char (point-max)))
16874 (vhdl-comment-display-line) (insert "\n\n")))
16875 ;; goto end of architecture
16876 (unless from-speedbar
16877 (re-search-forward "^end\\>" nil)
16878 (end-of-line) (insert "\n\n")
16879 (vhdl-comment-display-line) (insert "\n\n")))
16880 ;; insert library clause
16881 (setq pos (point))
16882 (vhdl-template-standard-package (vhdl-work-library) nil)
16883 (when (/= pos (point))
16884 (insert "\n\n"))
16885 ;; insert configuration
16886 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16887 (vhdl-insert-keyword " OF ") (insert ent-name)
16888 (vhdl-insert-keyword " IS\n")
16889 (indent-to vhdl-basic-offset)
16890 ;; insert block configuration (for architecture)
16891 (vhdl-compose-configuration-architecture
16892 ent-name arch-name ent-alist conf-alist inst-alist t)
16893 (vhdl-insert-keyword "END ") (insert conf-name ";")
16894 (when conf-file-name
16895 ;; insert footer and save
16896 (insert "\n\n")
16897 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16898 (vhdl-template-footer)
16899 (vhdl-comment-display-line) (insert "\n"))
16900 (save-buffer))
16901 (message "%s"
16902 (concat (format "Generating configuration \"%s\"...done" conf-name)
16903 (and conf-file-name
16904 (format "\n File created: \"%s\"" conf-file-name))))))
16907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16908 ;;; Compilation / Makefile generation
16909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16910 ;; (using `compile.el')
16912 (defvar vhdl-compile-post-command ""
16913 "String appended to compile command after file name.")
16915 (defun vhdl-makefile-name ()
16916 "Return the Makefile name of the current project or the current compiler if
16917 no project is defined."
16918 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16919 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16920 (vhdl-replace-string
16921 (cons "\\(.*\\)\n\\(.*\\)"
16922 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16923 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16925 (defun vhdl-compile-directory ()
16926 "Return the directory where compilation/make should be run."
16927 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16928 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16929 (directory (vhdl-resolve-env-variable
16930 (if project
16931 (vhdl-replace-string
16932 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16933 (nth 6 compiler)))))
16934 (file-name-as-directory
16935 (if (file-name-absolute-p directory)
16936 directory
16937 (expand-file-name directory (vhdl-default-directory))))))
16939 (defun vhdl-uniquify (in-list)
16940 "Remove duplicate elements from IN-LIST."
16941 (let (out-list)
16942 (while in-list
16943 (pushnew (car in-list) out-list :test #'equal)
16944 (setq in-list (cdr in-list)))
16945 out-list))
16947 (defun vhdl-set-compiler (name)
16948 "Set current compiler to NAME."
16949 (interactive
16950 (list (let ((completion-ignore-case t))
16951 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16952 (if (assoc name vhdl-compiler-alist)
16953 (progn (setq vhdl-compiler name)
16954 (message "Current compiler: \"%s\"" vhdl-compiler))
16955 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16958 ;; Compilation
16960 (defun vhdl-compile-init ()
16961 "Initialize for compilation."
16962 (when (and (not vhdl-emacs-22)
16963 (or (null compilation-error-regexp-alist)
16964 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16965 compilation-error-regexp-alist))))
16966 ;; `compilation-error-regexp-alist'
16967 (let ((commands-alist vhdl-compiler-alist)
16968 regexp-alist sublist)
16969 (while commands-alist
16970 (setq sublist (nth 11 (car commands-alist)))
16971 (unless (or (equal "" (car sublist))
16972 (assoc (car sublist) regexp-alist))
16973 (push (list (nth 0 sublist)
16974 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16976 (nth 1 sublist))
16977 (nth 2 sublist) (nth 3 sublist))
16978 regexp-alist))
16979 (setq commands-alist (cdr commands-alist)))
16980 (setq compilation-error-regexp-alist
16981 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16982 ;; `compilation-file-regexp-alist'
16983 (let ((commands-alist vhdl-compiler-alist)
16984 regexp-alist sublist)
16985 ;; matches vhdl-mode file name output
16986 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16987 (while commands-alist
16988 (setq sublist (nth 12 (car commands-alist)))
16989 (unless (or (equal "" (car sublist))
16990 (assoc (car sublist) regexp-alist))
16991 (push sublist regexp-alist))
16992 (setq commands-alist (cdr commands-alist)))
16993 (setq compilation-file-regexp-alist
16994 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16996 (defvar vhdl-compile-file-name nil
16997 "Name of file to be compiled.")
16999 (defun vhdl-compile-print-file-name ()
17000 "Function called within `compile' to print out file name for compilers that
17001 do not print any file names."
17002 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
17004 (defun vhdl-get-compile-options (project compiler file-name
17005 &optional file-options-only)
17006 "Get compiler options. Returning nil means do not compile this file."
17007 (let* ((compiler-options (nth 1 compiler))
17008 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17009 (project-options (nth 0 project-entry))
17010 (exception-list (and file-name (nth 2 project-entry)))
17011 (work-library (vhdl-work-library))
17012 (case-fold-search nil)
17013 file-options)
17014 (while (and exception-list
17015 (not (string-match (caar exception-list) file-name)))
17016 (setq exception-list (cdr exception-list)))
17017 (if (and exception-list (not (cdar exception-list)))
17019 (if (and file-options-only (not exception-list))
17020 'default
17021 (setq file-options (cdar exception-list))
17022 ;; insert library name in compiler-specific options
17023 (setq compiler-options
17024 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
17025 work-library))
17026 ;; insert compiler-specific options in project-specific options
17027 (when project-options
17028 (setq project-options
17029 (vhdl-replace-string
17030 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17031 (concat work-library "\n" compiler-options))))
17032 ;; insert project-specific options in file-specific options
17033 (when file-options
17034 (setq file-options
17035 (vhdl-replace-string
17036 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
17037 (concat work-library "\n" compiler-options "\n"
17038 project-options))))
17039 ;; return options
17040 (or file-options project-options compiler-options)))))
17042 (defun vhdl-get-make-options (project compiler)
17043 "Get make options."
17044 (let* ((compiler-options (nth 3 compiler))
17045 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17046 (project-options (nth 1 project-entry))
17047 (makefile-name (vhdl-makefile-name)))
17048 ;; insert Makefile name in compiler-specific options
17049 (setq compiler-options
17050 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
17051 makefile-name))
17052 ;; insert compiler-specific options in project-specific options
17053 (when project-options
17054 (setq project-options
17055 (vhdl-replace-string
17056 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17057 (concat makefile-name "\n" compiler-options))))
17058 ;; return options
17059 (or project-options compiler-options)))
17061 (defun vhdl-compile ()
17062 "Compile current buffer using the VHDL compiler specified in
17063 `vhdl-compiler'."
17064 (interactive)
17065 (vhdl-compile-init)
17066 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17067 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17068 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17069 (command (nth 0 compiler))
17070 (default-directory (vhdl-compile-directory))
17071 (file-name (if vhdl-compile-absolute-path
17072 (buffer-file-name)
17073 (file-relative-name (buffer-file-name))))
17074 (options (vhdl-get-compile-options project compiler file-name))
17075 compilation-process-setup-function)
17076 (unless (file-directory-p default-directory)
17077 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17078 ;; put file name into quotes if it contains spaces
17079 (when (string-match " " file-name)
17080 (setq file-name (concat "\"" file-name "\"")))
17081 ;; print out file name if compiler does not
17082 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
17083 (buffer-file-name)
17084 (file-relative-name (buffer-file-name))))
17085 (when (and (= 0 (nth 1 (nth 10 compiler)))
17086 (= 0 (nth 1 (nth 11 compiler))))
17087 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
17088 ;; run compilation
17089 (if options
17090 (when command
17091 (compile (concat command " " options " " file-name
17092 (unless (equal vhdl-compile-post-command "")
17093 (concat " " vhdl-compile-post-command)))))
17094 (vhdl-warning "Your project settings tell me not to compile this file"))))
17096 (defvar vhdl-make-target "all"
17097 "Default target for `vhdl-make' command.")
17099 (defun vhdl-make (&optional target)
17100 "Call make command for compilation of all updated source files (requires
17101 `Makefile'). Optional argument TARGET allows you to compile the design
17102 specified by a target."
17103 (interactive)
17104 (setq vhdl-make-target
17105 (or target (read-from-minibuffer "Target: " vhdl-make-target
17106 vhdl-minibuffer-local-map)))
17107 (vhdl-compile-init)
17108 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17109 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17110 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17111 (command (nth 2 compiler))
17112 (options (vhdl-get-make-options project compiler))
17113 (default-directory (vhdl-compile-directory)))
17114 (unless (file-directory-p default-directory)
17115 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17116 ;; run make
17117 (compile (concat (if (equal command "") "make" command)
17118 " " options " " vhdl-make-target))))
17120 ;; Emacs 22+ setup
17121 (defvar vhdl-error-regexp-emacs-alist
17122 ;; Get regexps from `vhdl-compiler-alist'
17123 (let ((compiler-alist vhdl-compiler-alist)
17124 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
17125 (while compiler-alist
17126 ;; only add regexps for currently selected compiler
17127 (when (or (not vhdl-compile-use-local-error-regexp)
17128 (equal vhdl-compiler (nth 0 (car compiler-alist))))
17129 ;; add error message regexps
17130 (setq error-regexp-alist
17131 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
17132 (nth 11 (car compiler-alist)))
17133 error-regexp-alist))
17134 ;; add filename regexps
17135 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
17136 (setq error-regexp-alist
17137 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
17138 (nth 12 (car compiler-alist)))
17139 error-regexp-alist))))
17140 (setq compiler-alist (cdr compiler-alist)))
17141 error-regexp-alist)
17142 "List of regexps for VHDL compilers. For Emacs 22+.")
17144 ;; Add error regexps using compilation-mode-hook.
17145 (defun vhdl-error-regexp-add-emacs ()
17146 "Set up Emacs compile for VHDL."
17147 (interactive)
17148 (when (and (boundp 'compilation-error-regexp-alist-alist)
17149 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
17150 ;; remove all other compilers
17151 (when vhdl-compile-use-local-error-regexp
17152 (setq compilation-error-regexp-alist nil))
17153 ;; add VHDL compilers
17154 (mapcar
17155 (lambda (item)
17156 (push (car item) compilation-error-regexp-alist)
17157 (push item compilation-error-regexp-alist-alist))
17158 vhdl-error-regexp-emacs-alist)))
17160 (when vhdl-emacs-22
17161 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
17163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17164 ;; Makefile generation
17166 (defun vhdl-generate-makefile ()
17167 "Generate `Makefile'."
17168 (interactive)
17169 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17170 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17171 (command (nth 4 compiler)))
17172 ;; generate makefile
17173 (if command
17174 (let ((default-directory (vhdl-compile-directory)))
17175 (compile (vhdl-replace-string
17176 (cons "\\(.*\\) \\(.*\\)" command)
17177 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17178 (vhdl-generate-makefile-1))))
17180 (defun vhdl-get-packages (lib-alist work-library)
17181 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17182 (let (pack-list)
17183 (while lib-alist
17184 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17185 (push (cdar lib-alist) pack-list))
17186 (setq lib-alist (cdr lib-alist)))
17187 pack-list))
17189 (defun vhdl-generate-makefile-1 ()
17190 "Generate Makefile for current project or directory."
17191 ;; scan hierarchy if required
17192 (if (vhdl-project-p)
17193 (unless (or (assoc vhdl-project vhdl-file-alist)
17194 (vhdl-load-cache vhdl-project))
17195 (vhdl-scan-project-contents vhdl-project))
17196 (let ((directory (abbreviate-file-name default-directory)))
17197 (unless (or (assoc directory vhdl-file-alist)
17198 (vhdl-load-cache directory))
17199 (vhdl-scan-directory-contents directory))))
17200 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17201 (project (vhdl-project-p))
17202 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17203 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17204 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17205 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17206 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17207 "\\1.vhd" "\\1_body.vhd" identity)))
17208 (mapping-exist
17209 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17210 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17211 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17212 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17213 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17214 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17215 (adjust-case (nth 5 regexp-list))
17216 (work-library (downcase (vhdl-work-library)))
17217 (compile-directory (expand-file-name (vhdl-compile-directory)
17218 default-directory))
17219 (makefile-name (vhdl-makefile-name))
17220 rule-alist arch-alist inst-alist
17221 target-list depend-list unit-list prim-list second-list subcomp-list
17222 lib-alist lib-body-alist pack-list all-pack-list
17223 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17224 conf-key conf-file-name pack-key pack-file-name
17225 ent-entry arch-entry conf-entry pack-entry inst-entry
17226 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17227 tmp-key tmp-list rule)
17228 ;; check prerequisites
17229 (unless (file-exists-p compile-directory)
17230 (make-directory compile-directory t))
17231 (unless mapping-exist
17232 (vhdl-warning
17233 (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\""
17234 vhdl-compiler vhdl-compiler) t))
17235 (message "Generating makefile \"%s\"..." makefile-name)
17236 ;; rules for all entities
17237 (setq tmp-list ent-alist)
17238 (while ent-alist
17239 (setq ent-entry (car ent-alist)
17240 ent-key (nth 0 ent-entry))
17241 (when (nth 2 ent-entry)
17242 (setq ent-file-name (if vhdl-compile-absolute-path
17243 (nth 2 ent-entry)
17244 (file-relative-name (nth 2 ent-entry)
17245 compile-directory))
17246 arch-alist (nth 4 ent-entry)
17247 lib-alist (nth 6 ent-entry)
17248 rule (vhdl-aget rule-alist ent-file-name)
17249 target-list (nth 0 rule)
17250 depend-list (nth 1 rule)
17251 second-list nil
17252 subcomp-list nil)
17253 (setq tmp-key (vhdl-replace-string
17254 ent-regexp
17255 (funcall adjust-case
17256 (concat ent-key " " work-library))))
17257 (push (cons ent-key tmp-key) unit-list)
17258 ;; rule target for this entity
17259 (push ent-key target-list)
17260 ;; rule dependencies for all used packages
17261 (setq pack-list (vhdl-get-packages lib-alist work-library))
17262 (setq depend-list (append depend-list pack-list))
17263 (setq all-pack-list pack-list)
17264 ;; add rule
17265 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17266 ;; rules for all corresponding architectures
17267 (while arch-alist
17268 (setq arch-entry (car arch-alist)
17269 arch-key (nth 0 arch-entry)
17270 ent-arch-key (concat ent-key "-" arch-key)
17271 arch-file-name (if vhdl-compile-absolute-path
17272 (nth 2 arch-entry)
17273 (file-relative-name (nth 2 arch-entry)
17274 compile-directory))
17275 inst-alist (nth 4 arch-entry)
17276 lib-alist (nth 5 arch-entry)
17277 rule (vhdl-aget rule-alist arch-file-name)
17278 target-list (nth 0 rule)
17279 depend-list (nth 1 rule))
17280 (setq tmp-key (vhdl-replace-string
17281 arch-regexp
17282 (funcall adjust-case
17283 (concat arch-key " " ent-key " "
17284 work-library))))
17285 (setq unit-list
17286 (cons (cons ent-arch-key tmp-key) unit-list))
17287 (push ent-arch-key second-list)
17288 ;; rule target for this architecture
17289 (push ent-arch-key target-list)
17290 ;; rule dependency for corresponding entity
17291 (push ent-key depend-list)
17292 ;; rule dependencies for contained component instantiations
17293 (while inst-alist
17294 (setq inst-entry (car inst-alist))
17295 (when (or (null (nth 8 inst-entry))
17296 (equal (downcase (nth 8 inst-entry)) work-library))
17297 (setq inst-ent-key (or (nth 7 inst-entry)
17298 (nth 5 inst-entry)))
17299 (setq depend-list (cons inst-ent-key depend-list)
17300 subcomp-list (cons inst-ent-key subcomp-list)))
17301 (setq inst-alist (cdr inst-alist)))
17302 ;; rule dependencies for all used packages
17303 (setq pack-list (vhdl-get-packages lib-alist work-library))
17304 (setq depend-list (append depend-list pack-list))
17305 (setq all-pack-list (append all-pack-list pack-list))
17306 ;; add rule
17307 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17308 (setq arch-alist (cdr arch-alist)))
17309 (push (list ent-key second-list (append subcomp-list all-pack-list))
17310 prim-list))
17311 (setq ent-alist (cdr ent-alist)))
17312 (setq ent-alist tmp-list)
17313 ;; rules for all configurations
17314 (setq tmp-list conf-alist)
17315 (while conf-alist
17316 (setq conf-entry (car conf-alist)
17317 conf-key (nth 0 conf-entry)
17318 conf-file-name (if vhdl-compile-absolute-path
17319 (nth 2 conf-entry)
17320 (file-relative-name (nth 2 conf-entry)
17321 compile-directory))
17322 ent-key (nth 4 conf-entry)
17323 arch-key (nth 5 conf-entry)
17324 inst-alist (nth 6 conf-entry)
17325 lib-alist (nth 7 conf-entry)
17326 rule (vhdl-aget rule-alist conf-file-name)
17327 target-list (nth 0 rule)
17328 depend-list (nth 1 rule)
17329 subcomp-list (list ent-key))
17330 (setq tmp-key (vhdl-replace-string
17331 conf-regexp
17332 (funcall adjust-case
17333 (concat conf-key " " work-library))))
17334 (push (cons conf-key tmp-key) unit-list)
17335 ;; rule target for this configuration
17336 (push conf-key target-list)
17337 ;; rule dependency for corresponding entity and architecture
17338 (setq depend-list
17339 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17340 ;; rule dependencies for used packages
17341 (setq pack-list (vhdl-get-packages lib-alist work-library))
17342 (setq depend-list (append depend-list pack-list))
17343 ;; rule dependencies for contained component configurations
17344 (while inst-alist
17345 (setq inst-entry (car inst-alist))
17346 (setq inst-ent-key (nth 2 inst-entry)
17347 inst-conf-key (nth 4 inst-entry))
17348 (when (equal (downcase (nth 5 inst-entry)) work-library)
17349 (when inst-ent-key
17350 (setq depend-list (cons inst-ent-key depend-list)
17351 subcomp-list (cons inst-ent-key subcomp-list)))
17352 (when inst-conf-key
17353 (setq depend-list (cons inst-conf-key depend-list)
17354 subcomp-list (cons inst-conf-key subcomp-list))))
17355 (setq inst-alist (cdr inst-alist)))
17356 ;; add rule
17357 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17358 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17359 (setq conf-alist (cdr conf-alist)))
17360 (setq conf-alist tmp-list)
17361 ;; rules for all packages
17362 (setq tmp-list pack-alist)
17363 (while pack-alist
17364 (setq pack-entry (car pack-alist)
17365 pack-key (nth 0 pack-entry)
17366 pack-body-key nil)
17367 (when (nth 2 pack-entry)
17368 (setq pack-file-name (if vhdl-compile-absolute-path
17369 (nth 2 pack-entry)
17370 (file-relative-name (nth 2 pack-entry)
17371 compile-directory))
17372 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17373 rule (vhdl-aget rule-alist pack-file-name)
17374 target-list (nth 0 rule) depend-list (nth 1 rule))
17375 (setq tmp-key (vhdl-replace-string
17376 pack-regexp
17377 (funcall adjust-case
17378 (concat pack-key " " work-library))))
17379 (push (cons pack-key tmp-key) unit-list)
17380 ;; rule target for this package
17381 (push pack-key target-list)
17382 ;; rule dependencies for all used packages
17383 (setq pack-list (vhdl-get-packages lib-alist work-library))
17384 (setq depend-list (append depend-list pack-list))
17385 (setq all-pack-list pack-list)
17386 ;; add rule
17387 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17388 ;; rules for this package's body
17389 (when (nth 7 pack-entry)
17390 (setq pack-body-key (concat pack-key "-body")
17391 pack-body-file-name (if vhdl-compile-absolute-path
17392 (nth 7 pack-entry)
17393 (file-relative-name (nth 7 pack-entry)
17394 compile-directory))
17395 rule (vhdl-aget rule-alist pack-body-file-name)
17396 target-list (nth 0 rule)
17397 depend-list (nth 1 rule))
17398 (setq tmp-key (vhdl-replace-string
17399 pack-body-regexp
17400 (funcall adjust-case
17401 (concat pack-key " " work-library))))
17402 (setq unit-list
17403 (cons (cons pack-body-key tmp-key) unit-list))
17404 ;; rule target for this package's body
17405 (push pack-body-key target-list)
17406 ;; rule dependency for corresponding package declaration
17407 (push pack-key depend-list)
17408 ;; rule dependencies for all used packages
17409 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17410 (setq depend-list (append depend-list pack-list))
17411 (setq all-pack-list (append all-pack-list pack-list))
17412 ;; add rule
17413 (vhdl-aput 'rule-alist pack-body-file-name
17414 (list target-list depend-list)))
17415 (setq prim-list
17416 (cons (list pack-key (when pack-body-key (list pack-body-key))
17417 all-pack-list)
17418 prim-list)))
17419 (setq pack-alist (cdr pack-alist)))
17420 (setq pack-alist tmp-list)
17421 ;; generate Makefile
17422 (let* ((project (vhdl-aget vhdl-project-alist project))
17423 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17424 (compiler-id (nth 9 compiler))
17425 (library-directory
17426 (vhdl-resolve-env-variable
17427 (vhdl-replace-string
17428 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17429 compiler-id)))
17430 (makefile-path-name (expand-file-name
17431 makefile-name compile-directory))
17432 (orig-buffer (current-buffer))
17433 cell second-list subcomp-list options unit-key unit-name)
17434 ;; sort lists
17435 (setq unit-list (vhdl-sort-alist unit-list))
17436 (setq prim-list (vhdl-sort-alist prim-list))
17437 (setq tmp-list rule-alist)
17438 (while tmp-list ; pre-sort rule targets
17439 (setq cell (cdar tmp-list))
17440 (setcar cell (sort (car cell) 'string<))
17441 (setq tmp-list (cdr tmp-list)))
17442 (setq rule-alist ; sort by first rule target
17443 (sort rule-alist
17444 (function (lambda (a b)
17445 (string< (car (cadr a)) (car (cadr b)))))))
17446 ;; open and clear Makefile
17447 (set-buffer (find-file-noselect makefile-path-name t t))
17448 (erase-buffer)
17449 (insert "# -*- Makefile -*-\n"
17450 "### " (file-name-nondirectory makefile-name)
17451 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17452 "\n")
17453 (if project
17454 (insert "\n# Project : " (nth 0 project))
17455 (insert "\n# Directory : \"" directory "\""))
17456 (insert "\n# Platform : " vhdl-compiler
17457 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17458 (user-login-name) "\n")
17459 ;; insert compile and option variable settings
17460 (insert "\n\n# Define compilation command and options\n"
17461 "\nCOMPILE = " (nth 0 compiler)
17462 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17463 (if (equal vhdl-compile-post-command "") ""
17464 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17465 "\n")
17466 ;; insert library paths
17467 (setq library-directory
17468 (directory-file-name
17469 (if (file-name-absolute-p library-directory)
17470 library-directory
17471 (file-relative-name
17472 (expand-file-name library-directory directory)
17473 compile-directory))))
17474 (insert "\n\n# Define library paths\n"
17475 "\nLIBRARY-" work-library " = " library-directory "\n")
17476 (unless mapping-exist
17477 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17478 ")/make" "\n"))
17479 ;; insert variable definitions for all library unit files
17480 (insert "\n\n# Define library unit files\n")
17481 (setq tmp-list unit-list)
17482 (while unit-list
17483 (insert "\nUNIT-" work-library "-" (caar unit-list)
17484 " = \\\n\t$(LIBRARY-" work-library
17485 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17486 (setq unit-list (cdr unit-list)))
17487 ;; insert variable definition for list of all library unit files
17488 (insert "\n\n\n# Define list of all library unit files\n"
17489 "\nALL_UNITS =")
17490 (setq unit-list tmp-list)
17491 (while unit-list
17492 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17493 (setq unit-list (cdr unit-list)))
17494 (insert "\n")
17495 (setq unit-list tmp-list)
17496 ;; insert `make all' rule
17497 (insert "\n\n\n# Rule for compiling entire design\n"
17498 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17499 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17500 " \\\n\t\t$(ALL_UNITS)\n")
17501 ;; insert `make clean' rule
17502 (insert "\n\n# Rule for cleaning entire design\n"
17503 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17504 "\n\t-rm -f $(ALL_UNITS)\n")
17505 ;; insert `make library' rule
17506 (insert "\n\n# Rule for creating library directory\n"
17507 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17508 " \\\n\t\t$(LIBRARY-" work-library ")"
17509 (if mapping-exist ""
17510 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17511 "\n"
17512 "\n$(LIBRARY-" work-library ") :"
17513 "\n\t"
17514 (vhdl-replace-string
17515 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17516 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17517 "\n")
17518 (unless mapping-exist
17519 (insert "\n$(LIBRARY-" work-library "-make) :"
17520 "\n\t"
17521 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17522 ;; insert '.PHONY' declaration
17523 (insert "\n\n.PHONY : "
17524 (nth 0 vhdl-makefile-default-targets) " "
17525 (nth 1 vhdl-makefile-default-targets) " "
17526 (nth 2 vhdl-makefile-default-targets) "\n")
17527 ;; insert rule for each library unit
17528 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17529 (while prim-list
17530 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17531 (setq subcomp-list
17532 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17533 (setq unit-key (caar prim-list)
17534 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17535 (nth 0 (vhdl-aget conf-alist unit-key))
17536 (nth 0 (vhdl-aget pack-alist unit-key))))
17537 (insert "\n" unit-key)
17538 (unless (equal unit-key unit-name)
17539 (insert " \\\n" unit-name))
17540 (insert " :"
17541 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17542 (while subcomp-list
17543 (when (and (assoc (car subcomp-list) unit-list)
17544 (not (equal unit-key (car subcomp-list))))
17545 (insert " \\\n\t\t" (car subcomp-list)))
17546 (setq subcomp-list (cdr subcomp-list)))
17547 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17548 (while second-list
17549 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17550 (setq second-list (cdr second-list)))
17551 (insert "\n")
17552 (setq prim-list (cdr prim-list)))
17553 ;; insert rule for each library unit file
17554 (insert "\n\n# Rules for compiling single library unit files\n")
17555 (while rule-alist
17556 (setq rule (car rule-alist))
17557 ;; get compiler options for this file
17558 (setq options
17559 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17560 ;; insert rule if file is supposed to be compiled
17561 (setq target-list (nth 1 rule)
17562 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17563 ;; insert targets
17564 (setq tmp-list target-list)
17565 (while target-list
17566 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17567 (if (cdr target-list) " \\" " :"))
17568 (setq target-list (cdr target-list)))
17569 (setq target-list tmp-list)
17570 ;; insert file name as first dependency
17571 (insert " \\\n\t\t" (nth 0 rule))
17572 ;; insert dependencies (except if also target or unit does not exist)
17573 (while depend-list
17574 (when (and (not (member (car depend-list) target-list))
17575 (assoc (car depend-list) unit-list))
17576 (insert " \\\n\t\t"
17577 "$(UNIT-" work-library "-" (car depend-list) ")"))
17578 (setq depend-list (cdr depend-list)))
17579 ;; insert compile command
17580 (if options
17581 (insert "\n\t$(COMPILE) "
17582 (if (eq options 'default) "$(OPTIONS)" options) " "
17583 (nth 0 rule)
17584 (if (equal vhdl-compile-post-command "") ""
17585 " $(POST-COMPILE)") "\n")
17586 (insert "\n"))
17587 (unless (and options mapping-exist)
17588 (setq tmp-list target-list)
17589 (while target-list
17590 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17591 (setq target-list (cdr target-list)))
17592 (setq target-list tmp-list))
17593 (setq rule-alist (cdr rule-alist)))
17595 (insert "\n\n### " makefile-name " ends here\n")
17596 ;; run Makefile generation hook
17597 (run-hooks 'vhdl-makefile-generation-hook)
17598 (message "Generating makefile \"%s\"...done" makefile-name)
17599 ;; save and close file
17600 (if (file-writable-p makefile-path-name)
17601 (progn (save-buffer)
17602 (kill-buffer (current-buffer))
17603 (set-buffer orig-buffer)
17604 (when (fboundp 'add-to-history)
17605 (add-to-history 'file-name-history makefile-path-name)))
17606 (vhdl-warning-when-idle
17607 (format "File not writable: \"%s\""
17608 (abbreviate-file-name makefile-path-name)))
17609 (switch-to-buffer (current-buffer))))))
17612 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17613 ;;; Bug reports
17614 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17615 ;; (using `reporter.el')
17617 (defconst vhdl-mode-help-address
17618 "Reto Zimmermann <reto@gnu.org>"
17619 "Address for VHDL Mode bug reports.")
17621 (defun vhdl-submit-bug-report ()
17622 "Submit via mail a bug report on VHDL Mode."
17623 (interactive)
17624 ;; load in reporter
17625 (and
17626 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17627 (let ((reporter-prompt-for-summary-p t))
17628 (reporter-submit-bug-report
17629 vhdl-mode-help-address
17630 (concat "VHDL Mode " vhdl-version)
17631 (list
17632 ;; report all important user options
17633 'vhdl-offsets-alist
17634 'vhdl-comment-only-line-offset
17635 'tab-width
17636 'vhdl-electric-mode
17637 'vhdl-stutter-mode
17638 'vhdl-indent-tabs-mode
17639 'vhdl-project-alist
17640 'vhdl-project
17641 'vhdl-project-file-name
17642 'vhdl-project-auto-load
17643 'vhdl-project-sort
17644 'vhdl-compiler-alist
17645 'vhdl-compiler
17646 'vhdl-compile-use-local-error-regexp
17647 'vhdl-makefile-default-targets
17648 'vhdl-makefile-generation-hook
17649 'vhdl-default-library
17650 'vhdl-standard
17651 'vhdl-basic-offset
17652 'vhdl-upper-case-keywords
17653 'vhdl-upper-case-types
17654 'vhdl-upper-case-attributes
17655 'vhdl-upper-case-enum-values
17656 'vhdl-upper-case-constants
17657 'vhdl-use-direct-instantiation
17658 'vhdl-array-index-record-field-in-sensitivity-list
17659 'vhdl-compose-configuration-name
17660 'vhdl-entity-file-name
17661 'vhdl-architecture-file-name
17662 'vhdl-configuration-file-name
17663 'vhdl-package-file-name
17664 'vhdl-file-name-case
17665 'vhdl-electric-keywords
17666 'vhdl-optional-labels
17667 'vhdl-insert-empty-lines
17668 'vhdl-argument-list-indent
17669 'vhdl-association-list-with-formals
17670 'vhdl-conditions-in-parenthesis
17671 'vhdl-sensitivity-list-all
17672 'vhdl-zero-string
17673 'vhdl-one-string
17674 'vhdl-file-header
17675 'vhdl-file-footer
17676 'vhdl-company-name
17677 'vhdl-copyright-string
17678 'vhdl-platform-spec
17679 'vhdl-date-format
17680 'vhdl-modify-date-prefix-string
17681 'vhdl-modify-date-on-saving
17682 'vhdl-reset-kind
17683 'vhdl-reset-active-high
17684 'vhdl-clock-rising-edge
17685 'vhdl-clock-edge-condition
17686 'vhdl-clock-name
17687 'vhdl-reset-name
17688 'vhdl-model-alist
17689 'vhdl-include-port-comments
17690 'vhdl-include-direction-comments
17691 'vhdl-include-type-comments
17692 'vhdl-include-group-comments
17693 'vhdl-actual-generic-name
17694 'vhdl-actual-port-name
17695 'vhdl-instance-name
17696 'vhdl-testbench-entity-name
17697 'vhdl-testbench-architecture-name
17698 'vhdl-testbench-configuration-name
17699 'vhdl-testbench-dut-name
17700 'vhdl-testbench-include-header
17701 'vhdl-testbench-declarations
17702 'vhdl-testbench-statements
17703 'vhdl-testbench-initialize-signals
17704 'vhdl-testbench-include-library
17705 'vhdl-testbench-include-configuration
17706 'vhdl-testbench-create-files
17707 'vhdl-testbench-entity-file-name
17708 'vhdl-testbench-architecture-file-name
17709 'vhdl-compose-create-files
17710 'vhdl-compose-configuration-create-file
17711 'vhdl-compose-configuration-hierarchical
17712 'vhdl-compose-configuration-use-subconfiguration
17713 'vhdl-compose-include-header
17714 'vhdl-compose-architecture-name
17715 'vhdl-components-package-name
17716 'vhdl-use-components-package
17717 'vhdl-self-insert-comments
17718 'vhdl-prompt-for-comments
17719 'vhdl-inline-comment-column
17720 'vhdl-end-comment-column
17721 'vhdl-auto-align
17722 'vhdl-align-groups
17723 'vhdl-align-group-separate
17724 'vhdl-align-same-indent
17725 'vhdl-highlight-keywords
17726 'vhdl-highlight-names
17727 'vhdl-highlight-special-words
17728 'vhdl-highlight-forbidden-words
17729 'vhdl-highlight-verilog-keywords
17730 'vhdl-highlight-translate-off
17731 'vhdl-highlight-case-sensitive
17732 'vhdl-special-syntax-alist
17733 'vhdl-forbidden-words
17734 'vhdl-forbidden-syntax
17735 'vhdl-directive-keywords
17736 'vhdl-speedbar-auto-open
17737 'vhdl-speedbar-display-mode
17738 'vhdl-speedbar-scan-limit
17739 'vhdl-speedbar-jump-to-unit
17740 'vhdl-speedbar-update-on-saving
17741 'vhdl-speedbar-save-cache
17742 'vhdl-speedbar-cache-file-name
17743 'vhdl-index-menu
17744 'vhdl-source-file-menu
17745 'vhdl-hideshow-menu
17746 'vhdl-hide-all-init
17747 'vhdl-print-two-column
17748 'vhdl-print-customize-faces
17749 'vhdl-intelligent-tab
17750 'vhdl-indent-syntax-based
17751 'vhdl-indent-comment-like-next-code-line
17752 'vhdl-word-completion-case-sensitive
17753 'vhdl-word-completion-in-minibuffer
17754 'vhdl-underscore-is-part-of-word
17755 'vhdl-mode-hook)
17756 (function
17757 (lambda ()
17758 (insert
17759 (if vhdl-special-indent-hook
17760 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17761 "vhdl-special-indent-hook is set to '"
17762 (format "%s" vhdl-special-indent-hook)
17763 ".\nPerhaps this is your problem?\n"
17764 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17765 "\n"))))
17767 "Hi Reto,"))))
17770 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17771 ;;; Documentation
17772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17774 (defconst vhdl-doc-release-notes nil
17776 Release Notes for VHDL Mode 3.37
17777 ================================
17779 - Added support for VHDL'08:
17780 - New keywords, types, functions, attributes, operators, packages
17781 - Context declaration
17782 - Block comments
17783 - Directives
17784 - `all' keyword in sensitivity list
17787 Release Notes for VHDL Mode 3.34
17788 ================================
17790 - Added support for GNU Emacs 22/23/24:
17791 - Compilation error parsing fixed for new `compile.el' package.
17793 - Port translation: Derive actual generic name from formal generic name.
17795 - New user options:
17796 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17799 Release Notes for VHDL Mode 3.33
17800 ================================
17802 New Features
17803 ------------
17805 CONFIGURATION DECLARATION GENERATION:
17806 - Automatic generation of a configuration declaration for a design.
17807 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17810 Key Bindings
17811 ------------
17813 For Emacs compliance the following key bindings have been changed:
17815 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17816 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17817 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17818 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17821 User Options
17822 ------------
17824 `vhdl-configuration-file-name': (new)
17825 Specify how the configuration file name is obtained.
17826 `vhdl-compose-configuration-name': (new)
17827 Specify how the configuration name is obtained.
17828 `vhdl-compose-configuration-create-file': (new)
17829 Specify whether a new file should be created for a configuration.
17830 `vhdl-compose-configuration-hierarchical': (new)
17831 Specify whether hierarchical configurations should be created.
17832 `vhdl-compose-configuration-use-subconfiguration': (new)
17833 Specify whether subconfigurations should be used inside configurations.
17834 `vhdl-makefile-default-targets': (new)
17835 Customize names of Makefile default targets.
17836 `vhdl-indent-comment-like-next-code-line': (new)
17837 Specify whether comment lines are indented like following code line.
17838 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17839 Specify whether to include array indices / record fields in sensitivity list.
17843 (defconst vhdl-doc-keywords nil
17845 Reserved words in VHDL
17846 ----------------------
17848 VHDL'08 (IEEE Std 1076-2008):
17849 `vhdl-08-keywords' : keywords
17850 `vhdl-08-types' : standardized types
17851 `vhdl-08-attributes' : standardized attributes
17852 `vhdl-08-functions' : standardized functions
17853 `vhdl-08-packages' : standardized packages and libraries
17855 VHDL'93/02 (IEEE Std 1076-1993/2002):
17856 `vhdl-02-keywords' : keywords
17857 `vhdl-02-types' : standardized types
17858 `vhdl-02-attributes' : standardized attributes
17859 `vhdl-02-enum-values' : standardized enumeration values
17860 `vhdl-02-functions' : standardized functions
17861 `vhdl-02-packages' : standardized packages and libraries
17863 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17864 `vhdl-ams-keywords' : keywords
17865 `vhdl-ams-types' : standardized types
17866 `vhdl-ams-attributes' : standardized attributes
17867 `vhdl-ams-enum-values' : standardized enumeration values
17868 `vhdl-ams-constants' : standardized constants
17869 `vhdl-ams-functions' : standardized functions
17871 Math Packages (IEEE Std 1076.2):
17872 `vhdl-math-types' : standardized types
17873 `vhdl-math-constants' : standardized constants
17874 `vhdl-math-functions' : standardized functions
17875 `vhdl-math-packages' : standardized packages
17877 Forbidden words:
17878 `vhdl-verilog-keywords' : Verilog reserved words
17880 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17883 (defconst vhdl-doc-coding-style nil
17885 For VHDL coding style and naming convention guidelines, see the following
17886 references:
17888 [1] Ben Cohen.
17889 \"VHDL Coding Styles and Methodologies\".
17890 Kluwer Academic Publishers, 1999.
17891 http://members.aol.com/vhdlcohen/vhdl/
17893 [2] Michael Keating and Pierre Bricaud.
17894 \"Reuse Methodology Manual, Second Edition\".
17895 Kluwer Academic Publishers, 1999.
17896 http://www.openmore.com/openmore/rmm2.html
17898 [3] European Space Agency.
17899 \"VHDL Modelling Guidelines\".
17900 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17902 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17903 to visually support naming conventions.")
17906 (defun vhdl-version ()
17907 "Echo the current version of VHDL Mode in the minibuffer."
17908 (interactive)
17909 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17910 (vhdl-keep-region-active))
17912 (defun vhdl-doc-variable (variable)
17913 "Display VARIABLE's documentation in *Help* buffer."
17914 (interactive)
17915 (unless (featurep 'xemacs)
17916 (help-setup-xref (list #'vhdl-doc-variable variable)
17917 (called-interactively-p 'interactive)))
17918 (with-output-to-temp-buffer
17919 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17920 (princ (documentation-property variable 'variable-documentation))
17921 (with-current-buffer standard-output
17922 (help-mode))
17923 (help-print-return-message)))
17925 (defun vhdl-doc-mode ()
17926 "Display VHDL Mode documentation in *Help* buffer."
17927 (interactive)
17928 (unless (featurep 'xemacs)
17929 (help-setup-xref (list #'vhdl-doc-mode)
17930 (called-interactively-p 'interactive)))
17931 (with-output-to-temp-buffer
17932 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17933 (princ mode-name)
17934 (princ " mode:\n")
17935 (princ (documentation 'vhdl-mode))
17936 (with-current-buffer standard-output
17937 (help-mode))
17938 (help-print-return-message)))
17941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17943 (provide 'vhdl-mode)
17945 ;;; vhdl-mode.el ends here