1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Reto Zimmermann <reto@gnu.org>
8 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
9 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
10 ;; Keywords: languages vhdl
11 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
13 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
14 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
15 ;; filed in the Emacs bug reporting system against this file, a copy
16 ;; of the bug report be sent to the maintainer's email address.
18 (defconst vhdl-version
"3.33.6"
19 "VHDL Mode version number.")
21 (defconst vhdl-time-stamp
"2005-08-30"
22 "VHDL Mode time stamp for last update.")
24 ;; This file is part of GNU Emacs.
26 ;; GNU Emacs is free software: you can redistribute it and/or modify
27 ;; it under the terms of the GNU General Public License as published by
28 ;; the Free Software Foundation, either version 3 of the License, or
29 ;; (at your option) any later version.
31 ;; GNU Emacs is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;; This package provides an Emacs major mode for editing VHDL code.
44 ;; It includes the following features:
46 ;; - Syntax highlighting
48 ;; - Template insertion (electrification)
49 ;; - Insertion of file headers
50 ;; - Insertion of user-specified models
51 ;; - Port translation / testbench generation
52 ;; - Structural composition
53 ;; - Configuration generation
54 ;; - Sensitivity list updating
56 ;; - Design hierarchy browser
57 ;; - Source file compilation (syntax analysis)
58 ;; - Makefile generation
60 ;; - Word/keyword completion
62 ;; - Code fixing/alignment/beautification
63 ;; - Postscript printing
64 ;; - VHDL'87/'93 and VHDL-AMS supported
65 ;; - Comprehensive menu
66 ;; - Fully customizable
67 ;; - Works under GNU Emacs (recommended) and XEmacs
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
78 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
85 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
86 ;; or into an arbitrary directory that is added to the load path by the
87 ;; following line in your Emacs start-up file `.emacs':
89 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
91 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
92 ;; directory. Otherwise, byte-compile the source file:
93 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
94 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
96 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
97 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
98 ;; (not required in Emacs 20.X):
100 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
101 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
103 ;; More detailed installation instructions are included in the official
104 ;; VHDL Mode distribution.
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
112 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
113 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
115 ;; Many thanks to all the users who sent me bug reports and enhancement
117 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
118 ;; enhancement suggestions and the fruitful discussions.
119 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
120 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
122 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
123 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
124 ;; giving me the opportunity to develop this code.
125 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
126 ;; of the Swiss Government.
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132 ;; Emacs 21+ handling
133 (defconst vhdl-emacs-21
(and (<= 21 emacs-major-version
) (not (featurep 'xemacs
)))
134 "Non-nil if GNU Emacs 21, 22, ... is used.")
135 (defconst vhdl-emacs-22
(and (<= 22 emacs-major-version
) (not (featurep 'xemacs
)))
136 "Non-nil if GNU Emacs 22, ... is used.")
138 (defvar compilation-file-regexp-alist
)
143 (defvar itimer-version
)
144 (defvar lazy-lock-defer-contextually
)
145 (defvar lazy-lock-defer-on-scrolling
)
146 (defvar lazy-lock-defer-on-the-fly
)
147 (defvar speedbar-attached-frame
)
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154 ;; help function for user options
155 (defun vhdl-custom-set (variable value
&rest functions
)
156 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
157 (if (fboundp 'custom-set-default
)
158 (custom-set-default variable value
)
159 (set-default variable value
))
161 (when (fboundp (car functions
)) (funcall (car functions
)))
162 (setq functions
(cdr functions
))))
164 (defun vhdl-widget-directory-validate (widget)
165 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
167 (let ((val (widget-value widget
)))
168 (unless (string-match "^\\(\\|.*/\\)$" val
)
169 (widget-put widget
:error
"Invalid directory entry: must end with '/'")
172 ;; help string for user options
173 (defconst vhdl-name-doc-string
"
175 FROM REGEXP is a regular expression matching the original name:
176 \".*\" matches the entire string
177 \"\\(...\\)\" matches a substring
178 TO STRING specifies the string to be inserted as new name:
179 \"\\&\" means substitute entire matched text
180 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
182 \".*\" \"\\&\" inserts original string
183 \".*\" \"\\&_i\" attaches \"_i\" to original string
184 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
185 \".*\" \"foo\" inserts constant string \"foo\"
186 \".*\" \"\" inserts empty string")
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 "Customizations for VHDL Mode."
195 ; :version "21.2" ; comment out for XEmacs
198 (defgroup vhdl-mode nil
199 "Customizations for modes."
202 (defcustom vhdl-electric-mode t
203 "*Non-nil enables electrification (automatic template generation).
204 If nil, template generators can still be invoked through key bindings and
205 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
206 toggled by `\\[vhdl-electric-mode]'."
210 (defcustom vhdl-stutter-mode t
211 "*Non-nil enables stuttering.
212 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
213 by `\\[vhdl-stutter-mode]'."
217 (defcustom vhdl-indent-tabs-mode nil
218 "*Non-nil means indentation can insert tabs.
219 Overrides local variable `indent-tabs-mode'."
224 (defgroup vhdl-compile nil
225 "Customizations for compilation."
228 (defcustom vhdl-compiler-alist
230 ;; Cadence Leapfrog: cv -file test.vhd
231 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
232 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
233 nil
"mkdir \\1" "./" "work/" "Makefile" "leapfrog"
234 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
235 ("\\1/entity" "\\2/\\1" "\\1/configuration"
236 "\\1/package" "\\1/body" downcase
))
237 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
238 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
239 ;; (PLL_400X_TOP) is not declared [10.3].
240 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
241 nil
"mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
242 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
243 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
244 "\\1/package/pc.db" "\\1/body/pc.db" downcase
))
245 ;; Ikos Voyager: analyze test.vhd
247 ;; E L4/C5: this library unit is inaccessible
248 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
249 nil
"mkdir \\1" "./" "work/" "Makefile" "ikos"
250 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
251 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
253 ;; ModelSim, Model Technology: vcom test.vhd
254 ;; ERROR: test.vhd(14): Unknown identifier: positiv
255 ;; WARNING[2]: test.vhd(85): Possible infinite loop
256 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
257 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
258 nil
"vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
259 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
260 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
261 "\\1/_primary.dat" "\\1/body.dat" downcase
))
262 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
263 ;; test.vhd:34: error message
264 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
265 nil
"mkdir \\1" "./" "work/" "Makefile" "provhdl"
266 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
267 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
268 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase
))
269 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
270 ;; ERROR: test.vhd(24): near "dnd": expecting: END
271 ;; WARNING[4]: test.vhd(30): A space is required between ...
272 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
273 nil
"mkdir \\1" "./" "work/" "Makefile" "quickhdl"
274 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
275 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
276 "\\1/_primary.dat" "\\1/body.dat" downcase
))
277 ;; Savant: scram -publish-cc test.vhd
278 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
279 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
280 nil
"mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
281 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
282 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
283 "\\1_config.vhdl" "\\1_package.vhdl"
284 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase
))
285 ;; Simili: vhdlp -work test.vhd
286 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
287 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
288 nil
"mkdir \\1" "./" "work/" "Makefile" "simili"
289 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
290 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
291 "\\1/prim.var" "\\1/_body.var" downcase
))
292 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
293 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
294 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
295 nil
"mkdir \\1" "./" "work/" "Makefile" "speedwave"
296 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
298 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
299 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
300 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
301 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys"
302 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
303 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase
))
304 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
305 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
306 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
307 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
308 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
309 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase
))
311 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
312 ("Synplify" "n/a" "n/a" "make" "-f \\1"
313 nil
"mkdir \\1" "./" "work/" "Makefile" "synplify"
314 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
316 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
317 ;; Compiling "test.vhd" line 1...
318 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
319 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
320 nil
"mkdir \\1" "./" "work/" "Makefile" "vantage"
321 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
322 ("^ *Compiling \"\\(.+\\)\" " 1)
324 ;; VeriBest: vc vhdl test.vhd
325 ;; (no file name printed out!)
326 ;; 32: Z <= A and BitA ;
328 ;; [Error] Name BITA is unknown
329 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
330 nil
"mkdir \\1" "./" "work/" "Makefile" "veribest"
331 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
333 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
334 ;; Compiling "test.vhd" line 1...
335 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
336 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
337 nil
"mkdir \\1" "./" "work/" "Makefile" "viewlogic"
338 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
339 ("^ *Compiling \"\\(.+\\)\" " 1)
342 "*List of available VHDL compilers and their properties.
343 Each list entry specifies the following items for a compiler:
345 Compiler name : name used in option `vhdl-compiler' to choose compiler
346 Compile command : command used for source file compilation
347 Compile options : compile options (\"\\1\" inserts library name)
348 Make command : command used for compilation using a Makefile
349 Make options : make options (\"\\1\" inserts Makefile name)
350 Generate Makefile: use built-in function or command to generate a Makefile
351 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
352 Library command : command to create library directory \(\"\\1\" inserts
353 library directory, \"\\2\" inserts library name)
354 Compile directory: where compilation is run and the Makefile is placed
355 Library directory: directory of default library
356 Makefile name : name of Makefile (default is \"Makefile\")
357 ID string : compiler identification string (see `vhdl-project-alist')
359 Regexp : regular expression to match error messages (*)
360 File subexp index: index of subexpression that matches the file name
361 Line subexp index: index of subexpression that matches the line number
362 Column subexp idx: index of subexpression that matches the column number
364 Regexp : regular expression to match a file name message
365 File subexp index: index of subexpression that matches the file name
366 Unit-to-file name mapping: mapping of library unit names to names of files
367 generated by the compiler (used for Makefile generation)
368 To string : string a name is mapped to (\"\\1\" inserts the unit name,
369 \"\\2\" inserts the entity name for architectures)
370 Case adjustment : adjust case of inserted unit names
372 \(*) The regular expression must match the error message starting from the
373 beginning of the line (but not necessarily to the end of the line).
375 Compile options allows insertion of the library name (see `vhdl-project-alist')
376 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
378 For Makefile generation, the built-in function can be used (requires
379 specification of the unit-to-file name mapping). Alternatively, an
380 external command can be specified. Work directory allows specification of
381 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
382 used for Makefile generation). To use another library name than \"work\",
383 customize `vhdl-project-alist'. The library command is inserted in Makefiles
384 to automatically create the library directory if not existent.
386 Compile options, compile directory, library directory, and Makefile name are
387 overwritten by the project settings if a project is defined (see
388 `vhdl-project-alist'). Directory paths are relative to the source file
391 Some compilers do not include the file name in the error message, but print
392 out a file name message in advance. In this case, set \"File Subexp Index\"
393 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
394 If no file name at all is printed out, set both \"File Message\" entries to 0
395 \(a default file name message will be printed out instead, does not work in
398 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
399 assigning its name to option `vhdl-compiler'.
401 Please send any missing or erroneous compiler properties to the maintainer for
404 NOTE: Activate new error and file message regexps and reflect the new setting
405 in the choice list of option `vhdl-compiler' by restarting Emacs."
407 (list :tag
"Compiler" :indent
2
408 (string :tag
"Compiler name ")
409 (string :tag
"Compile command ")
410 (string :tag
"Compile options " "-work \\1")
411 (string :tag
"Make command " "make")
412 (string :tag
"Make options " "-f \\1")
413 (choice :tag
"Generate Makefile "
414 (const :tag
"Built-in function" nil
)
415 (string :tag
"Command" "vmake \\2 > \\1"))
416 (string :tag
"Library command " "mkdir \\1")
417 (directory :tag
"Compile directory "
418 :validate vhdl-widget-directory-validate
"./")
419 (directory :tag
"Library directory "
420 :validate vhdl-widget-directory-validate
"work/")
421 (file :tag
"Makefile name " "Makefile")
422 (string :tag
"ID string ")
423 (list :tag
"Error message" :indent
4
424 (regexp :tag
"Regexp ")
425 (integer :tag
"File subexp index")
426 (integer :tag
"Line subexp index")
427 (integer :tag
"Column subexp idx"))
428 (list :tag
"File message" :indent
4
429 (regexp :tag
"Regexp ")
430 (integer :tag
"File subexp index"))
431 (choice :tag
"Unit-to-file name mapping"
432 :format
"%t: %[Value Menu%] %v\n"
433 (const :tag
"Not defined" nil
)
434 (list :tag
"To string" :indent
4
435 (string :tag
"Entity " "\\1.vhd")
436 (string :tag
"Architecture " "\\2_\\1.vhd")
437 (string :tag
"Configuration " "\\1.vhd")
438 (string :tag
"Package " "\\1.vhd")
439 (string :tag
"Package Body " "\\1_body.vhd")
440 (choice :tag
"Case adjustment "
441 (const :tag
"None" identity
)
442 (const :tag
"Upcase" upcase
)
443 (const :tag
"Downcase" downcase
))))))
444 :set
(lambda (variable value
)
445 (vhdl-custom-set variable value
'vhdl-update-mode-menu
))
446 :group
'vhdl-compile
)
448 (defcustom vhdl-compiler
"ModelSim"
449 "*Specifies the VHDL compiler to be used for syntax analysis.
450 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
451 :type
(let ((alist vhdl-compiler-alist
) list
)
453 (setq list
(cons (list 'const
(caar alist
)) list
))
454 (setq alist
(cdr alist
)))
455 (append '(choice) (nreverse list
)))
456 :group
'vhdl-compile
)
458 (defcustom vhdl-compile-use-local-error-regexp t
459 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
460 In this case, only error message regexps for VHDL compilers are active if
461 compilation is started from a VHDL buffer. Otherwise, the error message
462 regexps are appended to the predefined global regexps, and all regexps are
463 active all the time. Note that by doing that, the predefined global regexps
464 might result in erroneous parsing of error messages for some VHDL compilers.
466 NOTE: Activate the new setting by restarting Emacs."
468 :group
'vhdl-compile
)
470 (defcustom vhdl-makefile-generation-hook nil
471 "*Functions to run at the end of Makefile generation.
472 Allows to insert user specific parts into a Makefile.
476 \(re-search-backward \"^# Rule for compiling entire design\")
477 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
479 :group
'vhdl-compile
)
481 (defcustom vhdl-default-library
"work"
482 "*Name of default library.
483 Is overwritten by project settings if a project is active."
485 :group
'vhdl-compile
)
488 (defgroup vhdl-project nil
489 "Customizations for projects."
492 (defcustom vhdl-project-alist
493 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
494 "~/example1/" ("src/system/" "src/components/") ""
495 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil
)
496 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" .
"-optimize \\3") (".*_tb\\.vhd" . nil
))))
497 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
498 ("Example 2" "Individual source files, multiple compilers in different directories"
499 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
500 nil
"\\1/" "work" "\\1/work/" "Makefile" "")
501 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
502 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
503 nil
"./" "work" "work-\\1/" "Makefile-\\1" "\
504 -------------------------------------------------------------------------------
505 -- This is a multi-line project description
506 -- that can be used as a project dependent part of the file header.
508 "*List of projects and their properties.
509 Name : name used in option `vhdl-project' to choose project
510 Title : title of project (single-line string)
511 Default directory: default project directory (absolute path)
512 Sources : a) source files : path + \"/\" + file name
513 b) directory : path + \"/\"
514 c) directory tree: \"-r \" + path + \"/\"
515 Exclude regexp : matches file/directory names to be excluded as sources
516 Compile options : project-specific options for each compiler
517 Compiler name : name of compiler for which these options are valid
518 Compile options: project-specific compiler options
519 (\"\\1\" inserts library name, \"\\2\" default options)
520 Make options: project-specific make options
521 (\"\\1\" inserts Makefile name, \"\\2\" default options)
522 Exceptions : file-specific exceptions
523 File name regexp: matches file names for which exceptions are valid
524 - Options : file-specific compiler options string
525 (\"\\1\" inserts library name, \"\\2\" default options,
526 \"\\3\" project-specific options)
527 - Do not compile: do not compile this file (in Makefile)
528 Compile directory: where compilation is run and the Makefile is placed
529 \(\"\\1\" inserts compiler ID string)
530 Library name : name of library (default is \"work\")
531 Library directory: path to library (\"\\1\" inserts compiler ID string)
532 Makefile name : name of Makefile
533 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
534 Description : description of project (multi-line string)
536 Project title and description are used to insert into the file header (see
537 option `vhdl-file-header').
539 The default directory must have an absolute path (use `M-TAB' for completion).
540 All other paths can be absolute or relative to the default directory. All
541 paths must end with '/'.
543 The design units found in the sources (files and directories) are shown in the
544 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
545 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
546 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
547 specified, the default directory is taken as source directory. Otherwise,
548 the default directory is only taken as source directory if there is a sources
549 entry with the empty string or \"./\". Exclude regexp allows to filter out
550 specific file and directory names from the list of sources (e.g. CVS
553 Files are compiled in the compile directory. Makefiles are also placed into
554 the compile directory. Library directory specifies which directory the
555 compiler compiles into (used to generate the Makefile).
557 Since different compile/library directories and Makefiles may exist for
558 different compilers within one project, these paths and names allow the
559 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
560 Compile options, compile directory, library directory, and Makefile name
561 overwrite the settings of the current compiler.
563 File-specific compiler options (highest priority) overwrite project-specific
564 options which overwrite default options (lowest priority). Lower priority
565 options can be inserted in higher priority options. This allows to reuse
566 default options (e.g. \"-file\") in project- or file-specific options (e.g.
569 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
570 by restarting Emacs."
572 (list :tag
"Project" :indent
2
573 (string :tag
"Name ")
574 (string :tag
"Title ")
575 (directory :tag
"Default directory"
576 :validate vhdl-widget-directory-validate
577 ,(abbreviate-file-name default-directory
))
578 (repeat :tag
"Sources " :indent
4
579 (directory :format
" %v" "./"))
580 (regexp :tag
"Exclude regexp ")
582 :tag
"Compile options " :indent
4
583 (list :tag
"Compiler" :indent
6
584 ,(let ((alist vhdl-compiler-alist
) list
)
586 (setq list
(cons (list 'const
(caar alist
)) list
))
587 (setq alist
(cdr alist
)))
588 (append '(choice :tag
"Compiler name")
590 (string :tag
"Compile options" "\\2")
591 (string :tag
"Make options " "\\2")
593 :tag
"Exceptions " :indent
8
595 (regexp :tag
"File name regexp ")
596 (choice :format
"%[Value Menu%] %v"
597 (string :tag
"Options" "\\3")
598 (const :tag
"Do not compile" nil
))))))
599 (directory :tag
"Compile directory"
600 :validate vhdl-widget-directory-validate
"./")
601 (string :tag
"Library name " "work")
602 (directory :tag
"Library directory"
603 :validate vhdl-widget-directory-validate
"work/")
604 (file :tag
"Makefile name " "Makefile")
605 (string :tag
"Description: (type `C-j' for newline)"
606 :format
"%t\n%v\n")))
607 :set
(lambda (variable value
)
608 (vhdl-custom-set variable value
609 'vhdl-update-mode-menu
610 'vhdl-speedbar-refresh
))
611 :group
'vhdl-project
)
613 (defcustom vhdl-project nil
614 "*Specifies the default for the current project.
615 Select a project name from the ones defined in option `vhdl-project-alist'.
616 Is used to determine the project title and description to be inserted in file
617 headers and the source files/directories to be scanned in the hierarchy
618 browser. The current project can also be changed temporarily in the menu."
619 :type
(let ((alist vhdl-project-alist
) list
)
621 (setq list
(cons (list 'const
(caar alist
)) list
))
622 (setq alist
(cdr alist
)))
623 (append '(choice (const :tag
"None" nil
) (const :tag
"--"))
625 :group
'vhdl-project
)
627 (defcustom vhdl-project-file-name
'("\\1.prj")
628 "*List of file names/paths for importing/exporting project setups.
629 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
630 replaced by the user name (allows to have user-specific project setups).
631 The first entry is used as file name to import/export individual project
632 setups. All entries are used to automatically import project setups at
633 startup (see option `vhdl-project-auto-load'). Projects loaded from the
634 first entry are automatically made current. Hint: specify local project
635 setups in first entry, global setups in following entries; loading a local
636 project setup will make it current, while loading the global setups
637 is done without changing the current project.
638 Names can also have an absolute path (i.e. project setups can be stored
639 in global directories)."
640 :type
'(repeat (string :tag
"File name" "\\1.prj"))
641 :group
'vhdl-project
)
643 (defcustom vhdl-project-auto-load
'(startup)
644 "*Automatically load project setups from files.
645 All project setup files that match the file names specified in option
646 `vhdl-project-file-name' are automatically loaded. The project of the
647 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
649 A project setup file can be obtained by exporting a project (see menu).
650 At startup: project setup file is loaded at Emacs startup"
651 :type
'(set (const :tag
"At startup" startup
))
652 :group
'vhdl-project
)
654 (defcustom vhdl-project-sort t
655 "*Non-nil means projects are displayed in alphabetical order."
657 :group
'vhdl-project
)
660 (defgroup vhdl-style nil
661 "Customizations for coding styles."
663 :group
'vhdl-template
665 :group
'vhdl-compose
)
667 (defcustom vhdl-standard
'(87 nil
)
668 "*VHDL standards used.
670 VHDL'87 : IEEE Std 1076-1987
671 VHDL'93 : IEEE Std 1076-1993
672 Additional standards:
673 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
674 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
676 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
677 \"Activate Options\"."
678 :type
'(list (choice :tag
"Basic standard"
679 (const :tag
"VHDL'87" 87)
680 (const :tag
"VHDL'93" 93))
681 (set :tag
"Additional standards" :indent
2
682 (const :tag
"VHDL-AMS" ams
)
683 (const :tag
"Math packages" math
)))
684 :set
(lambda (variable value
)
685 (vhdl-custom-set variable value
686 'vhdl-template-map-init
687 'vhdl-mode-abbrev-table-init
688 'vhdl-template-construct-alist-init
689 'vhdl-template-package-alist-init
690 'vhdl-update-mode-menu
691 'vhdl-words-init
'vhdl-font-lock-init
))
694 (defcustom vhdl-basic-offset
2
695 "*Amount of basic offset used for indentation.
696 This value is used by + and - symbols in `vhdl-offsets-alist'."
700 (defcustom vhdl-upper-case-keywords nil
701 "*Non-nil means convert keywords to upper case.
702 This is done when typed or expanded or by the fix case functions."
704 :set
(lambda (variable value
)
705 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
708 (defcustom vhdl-upper-case-types nil
709 "*Non-nil means convert standardized types to upper case.
710 This is done when expanded or by the fix case functions."
712 :set
(lambda (variable value
)
713 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
716 (defcustom vhdl-upper-case-attributes nil
717 "*Non-nil means convert standardized attributes to upper case.
718 This is done when expanded or by the fix case functions."
720 :set
(lambda (variable value
)
721 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
724 (defcustom vhdl-upper-case-enum-values nil
725 "*Non-nil means convert standardized enumeration values to upper case.
726 This is done when expanded or by the fix case functions."
728 :set
(lambda (variable value
)
729 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
732 (defcustom vhdl-upper-case-constants t
733 "*Non-nil means convert standardized constants to upper case.
734 This is done when expanded."
736 :set
(lambda (variable value
)
737 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
740 (defcustom vhdl-use-direct-instantiation
'standard
741 "*Non-nil means use VHDL'93 direct component instantiation.
743 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
745 :type
'(choice (const :tag
"Never" never
)
746 (const :tag
"Standard" standard
)
747 (const :tag
"Always" always
))
751 (defgroup vhdl-naming nil
752 "Customizations for naming conventions."
755 (defcustom vhdl-entity-file-name
'(".*" .
"\\&")
757 "*Specifies how the entity file name is obtained.
758 The entity file name can be obtained by modifying the entity name (e.g.
759 attaching or stripping off a substring). The file extension is automatically
760 taken from the file name of the current buffer."
761 vhdl-name-doc-string
)
762 :type
'(cons (regexp :tag
"From regexp")
763 (string :tag
"To string "))
765 :group
'vhdl-compose
)
767 (defcustom vhdl-architecture-file-name
'("\\(.*\\) \\(.*\\)" .
"\\1_\\2")
769 "*Specifies how the architecture file name is obtained.
770 The architecture file name can be obtained by modifying the entity
771 and/or architecture name (e.g. attaching or stripping off a substring). The
772 file extension is automatically taken from the file name of the current
773 buffer. The string that is matched against the regexp is the concatenation
774 of the entity and the architecture name separated by a space. This gives
775 access to both names (see default setting as example)."
776 vhdl-name-doc-string
)
777 :type
'(cons (regexp :tag
"From regexp")
778 (string :tag
"To string "))
780 :group
'vhdl-compose
)
782 (defcustom vhdl-configuration-file-name
'(".*" .
"\\&")
784 "*Specifies how the configuration file name is obtained.
785 The configuration file name can be obtained by modifying the configuration
786 name (e.g. attaching or stripping off a substring). The file extension is
787 automatically taken from the file name of the current buffer."
788 vhdl-name-doc-string
)
789 :type
'(cons (regexp :tag
"From regexp")
790 (string :tag
"To string "))
792 :group
'vhdl-compose
)
794 (defcustom vhdl-package-file-name
'(".*" .
"\\&")
796 "*Specifies how the package file name is obtained.
797 The package file name can be obtained by modifying the package name (e.g.
798 attaching or stripping off a substring). The file extension is automatically
799 taken from the file name of the current buffer. Package files can be created
800 in a different directory by prepending a relative or absolute path to the
802 vhdl-name-doc-string
)
803 :type
'(cons (regexp :tag
"From regexp")
804 (string :tag
"To string "))
806 :group
'vhdl-compose
)
808 (defcustom vhdl-file-name-case
'identity
809 "*Specifies how to change case for obtaining file names.
810 When deriving a file name from a VHDL unit name, case can be changed as
812 As Is: case is not changed (taken as is)
813 Lower Case: whole name is changed to lower case
814 Upper Case: whole name is changed to upper case
815 Capitalize: first letter of each word in name is capitalized"
816 :type
'(choice (const :tag
"As Is" identity
)
817 (const :tag
"Lower Case" downcase
)
818 (const :tag
"Upper Case" upcase
)
819 (const :tag
"Capitalize" capitalize
))
821 :group
'vhdl-compose
)
824 (defgroup vhdl-template nil
825 "Customizations for electrification."
828 (defcustom vhdl-electric-keywords
'(vhdl user
)
829 "*Type of keywords for which electrification is enabled.
830 VHDL keywords: invoke built-in templates
831 User keywords: invoke user models (see option `vhdl-model-alist')"
832 :type
'(set (const :tag
"VHDL keywords" vhdl
)
833 (const :tag
"User model keywords" user
))
834 :set
(lambda (variable value
)
835 (vhdl-custom-set variable value
'vhdl-mode-abbrev-table-init
))
836 :group
'vhdl-template
)
838 (defcustom vhdl-optional-labels
'process
839 "*Constructs for which labels are to be queried.
840 Template generators prompt for optional labels for:
842 Processes only: processes only (also procedurals in VHDL-AMS)
843 All constructs: all constructs with optional labels and keyword END"
844 :type
'(choice (const :tag
"None" none
)
845 (const :tag
"Processes only" process
)
846 (const :tag
"All constructs" all
))
847 :group
'vhdl-template
)
849 (defcustom vhdl-insert-empty-lines
'unit
850 "*Specifies whether to insert empty lines in some templates.
851 This improves readability of code. Empty lines are inserted in:
853 Design units only: entities, architectures, configurations, packages only
854 All constructs : also all constructs with BEGIN...END parts
856 Replaces option `vhdl-additional-empty-lines'."
857 :type
'(choice (const :tag
"None" none
)
858 (const :tag
"Design units only" unit
)
859 (const :tag
"All constructs" all
))
860 :group
'vhdl-template
862 :group
'vhdl-compose
)
864 (defcustom vhdl-argument-list-indent nil
865 "*Non-nil means indent argument lists relative to opening parenthesis.
866 That is, argument, association, and port lists start on the same line as the
867 opening parenthesis and subsequent lines are indented accordingly.
868 Otherwise, lists start on a new line and are indented as normal code."
870 :group
'vhdl-template
872 :group
'vhdl-compose
)
874 (defcustom vhdl-association-list-with-formals t
875 "*Non-nil means write association lists with formal parameters.
876 Templates prompt for formal and actual parameters (ports/generics).
877 When pasting component instantiations, formals are included.
878 If nil, only a list of actual parameters is entered."
880 :group
'vhdl-template
882 :group
'vhdl-compose
)
884 (defcustom vhdl-conditions-in-parenthesis nil
885 "*Non-nil means place parenthesis around condition expressions."
887 :group
'vhdl-template
)
889 (defcustom vhdl-zero-string
"'0'"
890 "*String to use for a logic zero."
892 :group
'vhdl-template
)
894 (defcustom vhdl-one-string
"'1'"
895 "*String to use for a logic one."
897 :group
'vhdl-template
)
900 (defgroup vhdl-header nil
901 "Customizations for file header."
902 :group
'vhdl-template
903 :group
'vhdl-compose
)
905 (defcustom vhdl-file-header
"\
906 -------------------------------------------------------------------------------
907 -- Title : <title string>
908 -- Project : <project>
909 -------------------------------------------------------------------------------
912 -- Company : <company>
914 -- Last update: <date>
915 -- Platform : <platform>
916 -- Standard : <standard>
917 <projectdesc>-------------------------------------------------------------------------------
918 -- Description: <cursor>
919 <copyright>-------------------------------------------------------------------------------
921 -- Date Version Author Description
922 -- <date> 1.0 <login>\tCreated
923 -------------------------------------------------------------------------------
926 "*String or file to insert as file header.
927 If the string specifies an existing file name, the contents of the file is
928 inserted, otherwise the string itself is inserted as file header.
929 Type `C-j' for newlines.
930 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
931 if the header needs to be version controlled.
933 The following keywords for template generation are supported:
934 <filename> : replaced by the name of the buffer
935 <author> : replaced by the user name and email address
936 \(`user-full-name', `mail-host-address', `user-mail-address')
937 <login> : replaced by user login name (`user-login-name')
938 <company> : replaced by contents of option `vhdl-company-name'
939 <date> : replaced by the current date
940 <year> : replaced by the current year
941 <project> : replaced by title of current project (`vhdl-project')
942 <projectdesc> : replaced by description of current project (`vhdl-project')
943 <copyright> : replaced by copyright string (`vhdl-copyright-string')
944 <platform> : replaced by contents of option `vhdl-platform-spec'
945 <standard> : replaced by the VHDL language standard(s) used
946 <... string> : replaced by a queried string (\"...\" is the prompt word)
947 <title string>: replaced by file title in automatically generated files
948 <cursor> : final cursor position
950 The (multi-line) project description <projectdesc> can be used as a project
951 dependent part of the file header and can also contain the above keywords."
955 (defcustom vhdl-file-footer
""
956 "*String or file to insert as file footer.
957 If the string specifies an existing file name, the contents of the file is
958 inserted, otherwise the string itself is inserted as file footer (i.e. at
959 the end of the file).
960 Type `C-j' for newlines.
961 The same keywords as in option `vhdl-file-header' can be used."
965 (defcustom vhdl-company-name
""
966 "*Name of company to insert in file header.
967 See option `vhdl-file-header'."
971 (defcustom vhdl-copyright-string
"\
972 -------------------------------------------------------------------------------
973 -- Copyright (c) <year> <company>
975 "*Copyright string to insert in file header.
976 Can be multi-line string (type `C-j' for newline) and contain other file
977 header keywords (see option `vhdl-file-header')."
981 (defcustom vhdl-platform-spec
""
982 "*Specification of VHDL platform to insert in file header.
983 The platform specification should contain names and versions of the
984 simulation and synthesis tools used.
985 See option `vhdl-file-header'."
989 (defcustom vhdl-date-format
"%Y-%m-%d"
990 "*Specifies the date format to use in the header.
991 This string is passed as argument to the command `format-time-string'.
992 For more information on format strings, see the documentation for the
993 `format-time-string' command (C-h f `format-time-string')."
997 (defcustom vhdl-modify-date-prefix-string
"-- Last update: "
998 "*Prefix string of modification date in VHDL file header.
999 If actualization of the modification date is called (menu,
1000 `\\[vhdl-template-modify]'), this string is searched and the rest
1001 of the line replaced by the current date."
1003 :group
'vhdl-header
)
1005 (defcustom vhdl-modify-date-on-saving t
1006 "*Non-nil means update the modification date when the buffer is saved.
1007 Calls function `\\[vhdl-template-modify]').
1009 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1010 \"Activate Options\"."
1012 :group
'vhdl-header
)
1015 (defgroup vhdl-sequential-process nil
1016 "Customizations for sequential processes."
1017 :group
'vhdl-template
)
1019 (defcustom vhdl-reset-kind
'async
1020 "*Specifies which kind of reset to use in sequential processes."
1021 :type
'(choice (const :tag
"None" none
)
1022 (const :tag
"Synchronous" sync
)
1023 (const :tag
"Asynchronous" async
))
1024 :group
'vhdl-sequential-process
)
1026 (defcustom vhdl-reset-active-high nil
1027 "*Non-nil means reset in sequential processes is active high.
1028 Otherwise, reset is active low."
1030 :group
'vhdl-sequential-process
)
1032 (defcustom vhdl-clock-rising-edge t
1033 "*Non-nil means rising edge of clock triggers sequential processes.
1034 Otherwise, falling edge triggers."
1036 :group
'vhdl-sequential-process
)
1038 (defcustom vhdl-clock-edge-condition
'standard
1039 "*Syntax of the clock edge condition.
1040 Standard: \"clk'event and clk = '1'\"
1041 Function: \"rising_edge(clk)\""
1042 :type
'(choice (const :tag
"Standard" standard
)
1043 (const :tag
"Function" function
))
1044 :group
'vhdl-sequential-process
)
1046 (defcustom vhdl-clock-name
""
1047 "*Name of clock signal to use in templates."
1049 :group
'vhdl-sequential-process
)
1051 (defcustom vhdl-reset-name
""
1052 "*Name of reset signal to use in templates."
1054 :group
'vhdl-sequential-process
)
1057 (defgroup vhdl-model nil
1058 "Customizations for user models."
1061 (defcustom vhdl-model-alist
1063 "<label> : process (<clock>, <reset>)
1064 begin -- process <label>
1065 if <reset> = '0' then -- asynchronous reset (active low)
1067 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1068 if <enable> = '1' then -- synchronous load
1072 end process <label>;"
1074 "*List of user models.
1075 VHDL models (templates) can be specified by the user in this list. They can be
1076 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1077 electrification (i.e. overriding existing or creating new keywords, see
1078 option `vhdl-electric-keywords').
1079 Name : name of model (string of words and spaces)
1080 String : string or name of file to be inserted as model (newline: `C-j')
1081 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1082 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1083 Keyword : keyword to invoke model
1085 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1086 A prompt that appears several times is queried once and replaced throughout
1087 the model. Special prompts are:
1088 <clock> : name specified in `vhdl-clock-name' (if not empty)
1089 <reset> : name specified in `vhdl-reset-name' (if not empty)
1090 <cursor>: final cursor position
1091 File header prompts (see variable `vhdl-file-header') are automatically
1092 replaced, so that user models can also be used to insert different types of
1095 If the string specifies an existing file name, the contents of the file is
1096 inserted, otherwise the string itself is inserted.
1097 The code within the models should be correctly indented.
1098 Type `C-j' for newlines.
1100 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1101 \"Activate Options\"."
1102 :type
'(repeat (list :tag
"Model" :indent
2
1103 (string :tag
"Name ")
1104 (string :tag
"String : (type `C-j' for newline)"
1106 (sexp :tag
"Key binding" x
)
1107 (string :tag
"Keyword " :format
"%t: %v\n")))
1108 :set
(lambda (variable value
)
1109 (vhdl-custom-set variable value
1110 'vhdl-model-map-init
1112 'vhdl-mode-abbrev-table-init
1113 'vhdl-update-mode-menu
))
1117 (defgroup vhdl-compose nil
1118 "Customizations for structural composition."
1121 (defcustom vhdl-compose-architecture-name
'(".*" .
"str")
1123 "*Specifies how the component architecture name is obtained.
1124 The component architecture name can be obtained by modifying the entity name
1125 \(e.g. attaching or stripping off a substring).
1126 If TO STRING is empty, the architecture name is queried."
1127 vhdl-name-doc-string
)
1128 :type
'(cons (regexp :tag
"From regexp")
1129 (string :tag
"To string "))
1130 :group
'vhdl-compose
)
1132 (defcustom vhdl-compose-configuration-name
1133 '("\\(.*\\) \\(.*\\)" .
"\\1_\\2_cfg")
1135 "*Specifies how the configuration name is obtained.
1136 The configuration name can be obtained by modifying the entity and/or
1137 architecture name (e.g. attaching or stripping off a substring). The string
1138 that is matched against the regexp is the concatenation of the entity and the
1139 architecture name separated by a space. This gives access to both names (see
1140 default setting as example)."
1141 vhdl-name-doc-string
)
1142 :type
'(cons (regexp :tag
"From regexp")
1143 (string :tag
"To string "))
1144 :group
'vhdl-compose
)
1146 (defcustom vhdl-components-package-name
1147 '((".*" .
"\\&_components") .
"components")
1149 "*Specifies how the name for the components package is obtained.
1150 The components package is a package containing all component declarations for
1151 the current design. Its name can be obtained by modifying the project name
1152 \(e.g. attaching or stripping off a substring). If no project is defined, the
1153 DIRECTORY entry is chosen."
1154 vhdl-name-doc-string
)
1155 :type
'(cons (cons :tag
"Project" :indent
2
1156 (regexp :tag
"From regexp")
1157 (string :tag
"To string "))
1158 (string :tag
"Directory:\n String "))
1159 :group
'vhdl-compose
)
1161 (defcustom vhdl-use-components-package nil
1162 "*Non-nil means use a separate components package for component declarations.
1163 Otherwise, component declarations are inserted and searched for in the
1164 architecture declarative parts."
1166 :group
'vhdl-compose
)
1168 (defcustom vhdl-compose-include-header t
1169 "*Non-nil means include a header in automatically generated files."
1171 :group
'vhdl-compose
)
1173 (defcustom vhdl-compose-create-files
'single
1174 "*Specifies whether new files should be created for the new component.
1175 The component's entity and architecture are inserted:
1176 None : in current buffer
1177 Single file : in new single file
1178 Separate files: in two separate files
1179 The file names are obtained from variables `vhdl-entity-file-name' and
1180 `vhdl-architecture-file-name'."
1181 :type
'(choice (const :tag
"None" none
)
1182 (const :tag
"Single file" single
)
1183 (const :tag
"Separate files" separate
))
1184 :group
'vhdl-compose
)
1186 (defcustom vhdl-compose-configuration-create-file nil
1187 "*Specifies whether a new file should be created for the configuration.
1188 If non-nil, a new file is created for the configuration.
1189 The file name is obtained from variable `vhdl-configuration-file-name'."
1191 :group
'vhdl-compose
)
1193 (defcustom vhdl-compose-configuration-hierarchical t
1194 "*Specifies whether hierarchical configurations should be created.
1195 If non-nil, automatically created configurations are hierarchical and include
1196 the whole hierarchy of subcomponents. Otherwise the configuration only
1197 includes one level of subcomponents."
1199 :group
'vhdl-compose
)
1201 (defcustom vhdl-compose-configuration-use-subconfiguration t
1202 "*Specifies whether subconfigurations should be used inside configurations.
1203 If non-nil, automatically created configurations use configurations in binding
1204 indications for subcomponents, if such configurations exist. Otherwise,
1205 entities are used in binding indications for subcomponents."
1207 :group
'vhdl-compose
)
1210 (defgroup vhdl-port nil
1211 "Customizations for port translation functions."
1213 :group
'vhdl-compose
)
1215 (defcustom vhdl-include-port-comments nil
1216 "*Non-nil means include port comments when a port is pasted."
1220 (defcustom vhdl-include-direction-comments nil
1221 "*Non-nil means include port direction in instantiations as comments."
1225 (defcustom vhdl-include-type-comments nil
1226 "*Non-nil means include generic/port type in instantiations as comments."
1230 (defcustom vhdl-include-group-comments
'never
1231 "*Specifies whether to include group comments and spacings.
1232 The comments and empty lines between groups of ports are pasted:
1234 Declarations: in entity/component/constant/signal declarations only
1235 Always : also in generic/port maps"
1236 :type
'(choice (const :tag
"Never" never
)
1237 (const :tag
"Declarations" decl
)
1238 (const :tag
"Always" always
))
1241 (defcustom vhdl-actual-port-name
'(".*" .
"\\&")
1243 "*Specifies how actual port names are obtained from formal port names.
1244 In a component instantiation, an actual port name can be obtained by
1245 modifying the formal port name (e.g. attaching or stripping off a substring)."
1246 vhdl-name-doc-string
)
1247 :type
'(cons (regexp :tag
"From regexp")
1248 (string :tag
"To string "))
1251 (defcustom vhdl-instance-name
'(".*" .
"\\&_%d")
1253 "*Specifies how an instance name is obtained.
1254 The instance name can be obtained by modifying the name of the component to be
1255 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1256 by a unique number (starting with 1).
1257 If TO STRING is empty, the instance name is queried."
1258 vhdl-name-doc-string
)
1259 :type
'(cons (regexp :tag
"From regexp")
1260 (string :tag
"To string "))
1264 (defgroup vhdl-testbench nil
1265 "Customizations for testbench generation."
1268 (defcustom vhdl-testbench-entity-name
'(".*" .
"\\&_tb")
1270 "*Specifies how the testbench entity name is obtained.
1271 The entity name of a testbench can be obtained by modifying the name of
1272 the component to be tested (e.g. attaching or stripping off a substring)."
1273 vhdl-name-doc-string
)
1274 :type
'(cons (regexp :tag
"From regexp")
1275 (string :tag
"To string "))
1276 :group
'vhdl-testbench
)
1278 (defcustom vhdl-testbench-architecture-name
'(".*" .
"")
1280 "*Specifies how the testbench architecture name is obtained.
1281 The testbench architecture name can be obtained by modifying the name of
1282 the component to be tested (e.g. attaching or stripping off a substring).
1283 If TO STRING is empty, the architecture name is queried."
1284 vhdl-name-doc-string
)
1285 :type
'(cons (regexp :tag
"From regexp")
1286 (string :tag
"To string "))
1287 :group
'vhdl-testbench
)
1289 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1291 "*Specifies how the testbench configuration name is obtained.
1292 The configuration name of a testbench can be obtained by modifying the entity
1293 and/or architecture name (e.g. attaching or stripping off a substring). The
1294 string that is matched against the regexp is the concatenation of the entity
1295 and the architecture name separated by a space. This gives access to both
1296 names (see default setting as example)."
1297 vhdl-name-doc-string
)
1298 :type
'(cons (regexp :tag
"From regexp")
1299 (string :tag
"To string "))
1300 :group
'vhdl-testbench
)
1302 (defcustom vhdl-testbench-dut-name
'(".*" .
"DUT")
1304 "*Specifies how a DUT instance name is obtained.
1305 The design-under-test instance name (i.e. the component instantiated in the
1306 testbench) can be obtained by modifying the component name (e.g. attaching
1307 or stripping off a substring)."
1308 vhdl-name-doc-string
)
1309 :type
'(cons (regexp :tag
"From regexp")
1310 (string :tag
"To string "))
1311 :group
'vhdl-testbench
)
1313 (defcustom vhdl-testbench-include-header t
1314 "*Non-nil means include a header in automatically generated files."
1316 :group
'vhdl-testbench
)
1318 (defcustom vhdl-testbench-declarations
"\
1320 signal Clk : std_logic := '1';
1322 "*String or file to be inserted in the testbench declarative part.
1323 If the string specifies an existing file name, the contents of the file is
1324 inserted, otherwise the string itself is inserted in the testbench
1325 architecture before the BEGIN keyword.
1326 Type `C-j' for newlines."
1328 :group
'vhdl-testbench
)
1330 (defcustom vhdl-testbench-statements
"\
1332 Clk <= not Clk after 10 ns;
1334 -- waveform generation
1335 WaveGen_Proc: process
1337 -- insert signal assignments here
1339 wait until Clk = '1';
1340 end process WaveGen_Proc;
1342 "*String or file to be inserted in the testbench statement part.
1343 If the string specifies an existing file name, the contents of the file is
1344 inserted, otherwise the string itself is inserted in the testbench
1345 architecture before the END keyword.
1346 Type `C-j' for newlines."
1348 :group
'vhdl-testbench
)
1350 (defcustom vhdl-testbench-initialize-signals nil
1351 "*Non-nil means initialize signals with `0' when declared in testbench."
1353 :group
'vhdl-testbench
)
1355 (defcustom vhdl-testbench-include-library t
1356 "*Non-nil means a library/use clause for std_logic_1164 is included."
1358 :group
'vhdl-testbench
)
1360 (defcustom vhdl-testbench-include-configuration t
1361 "*Non-nil means a testbench configuration is attached at the end."
1363 :group
'vhdl-testbench
)
1365 (defcustom vhdl-testbench-create-files
'single
1366 "*Specifies whether new files should be created for the testbench.
1367 testbench entity and architecture are inserted:
1368 None : in current buffer
1369 Single file : in new single file
1370 Separate files: in two separate files
1371 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1372 and `vhdl-testbench-architecture-file-name'."
1373 :type
'(choice (const :tag
"None" none
)
1374 (const :tag
"Single file" single
)
1375 (const :tag
"Separate files" separate
))
1376 :group
'vhdl-testbench
)
1378 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1380 "*Specifies how the testbench entity file name is obtained.
1381 The entity file name can be obtained by modifying the testbench entity name
1382 \(e.g. attaching or stripping off a substring). The file extension is
1383 automatically taken from the file name of the current buffer. Testbench
1384 files can be created in a different directory by prepending a relative or
1385 absolute path to the file name."
1386 vhdl-name-doc-string
)
1387 :type
'(cons (regexp :tag
"From regexp")
1388 (string :tag
"To string "))
1389 :group
'vhdl-testbench
)
1391 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1393 "*Specifies how the testbench architecture file name is obtained.
1394 The architecture file name can be obtained by modifying the testbench entity
1395 and/or architecture name (e.g. attaching or stripping off a substring). The
1396 string that is matched against the regexp is the concatenation of the entity
1397 and the architecture name separated by a space. This gives access to both
1398 names (see default setting as example). Testbench files can be created in
1399 a different directory by prepending a relative or absolute path to the file
1401 vhdl-name-doc-string
)
1402 :type
'(cons (regexp :tag
"From regexp")
1403 (string :tag
"To string "))
1404 :group
'vhdl-testbench
)
1407 (defgroup vhdl-comment nil
1408 "Customizations for comments."
1411 (defcustom vhdl-self-insert-comments t
1412 "*Non-nil means various templates automatically insert help comments."
1414 :group
'vhdl-comment
)
1416 (defcustom vhdl-prompt-for-comments t
1417 "*Non-nil means various templates prompt for user definable comments."
1419 :group
'vhdl-comment
)
1421 (defcustom vhdl-inline-comment-column
40
1422 "*Column to indent and align inline comments to.
1423 Overrides local option `comment-column'.
1425 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1426 \"Activate Options\"."
1428 :group
'vhdl-comment
)
1430 (defcustom vhdl-end-comment-column
79
1431 "*End of comment column.
1432 Comments that exceed this column number are wrapped.
1434 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1435 \"Activate Options\"."
1437 :group
'vhdl-comment
)
1439 (defvar end-comment-column
)
1442 (defgroup vhdl-align nil
1443 "Customizations for alignment."
1446 (defcustom vhdl-auto-align t
1447 "*Non-nil means align some templates automatically after generation."
1451 (defcustom vhdl-align-groups t
1452 "*Non-nil means align groups of code lines separately.
1453 A group of code lines is a region of consecutive lines between two lines that
1454 match the regexp in option `vhdl-align-group-separate'."
1458 (defcustom vhdl-align-group-separate
"^\\s-*$"
1459 "*Regexp for matching a line that separates groups of lines for alignment.
1461 \"^\\s-*$\": matches an empty line
1462 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1466 (defcustom vhdl-align-same-indent t
1467 "*Non-nil means align blocks with same indent separately.
1468 When a region or the entire buffer is aligned, the code is divided into
1469 blocks of same indent which are aligned separately (except for argument/port
1470 lists). This gives nicer alignment in most cases.
1471 Option `vhdl-align-groups' still applies within these blocks."
1476 (defgroup vhdl-highlight nil
1477 "Customizations for highlighting."
1480 (defcustom vhdl-highlight-keywords t
1481 "*Non-nil means highlight VHDL keywords and other standardized words.
1482 The following faces are used:
1483 `font-lock-keyword-face' : keywords
1484 `font-lock-type-face' : standardized types
1485 `vhdl-font-lock-attribute-face': standardized attributes
1486 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1487 `vhdl-font-lock-function-face' : standardized function and package names
1489 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1490 entry \"Fontify Buffer\")."
1492 :set
(lambda (variable value
)
1493 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1494 :group
'vhdl-highlight
)
1496 (defcustom vhdl-highlight-names t
1497 "*Non-nil means highlight declaration names and construct labels.
1498 The following faces are used:
1499 `font-lock-function-name-face' : names in declarations of units,
1500 subprograms, components, as well as labels of VHDL constructs
1501 `font-lock-type-face' : names in type/nature declarations
1502 `vhdl-font-lock-attribute-face': names in attribute declarations
1503 `font-lock-variable-name-face' : names in declarations of signals,
1504 variables, constants, subprogram parameters, generics, and ports
1506 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1507 entry \"Fontify Buffer\")."
1509 :set
(lambda (variable value
)
1510 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1511 :group
'vhdl-highlight
)
1513 (defcustom vhdl-highlight-special-words nil
1514 "*Non-nil means highlight words with special syntax.
1515 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1516 are highlighted accordingly.
1517 Can be used for visual support of naming conventions.
1519 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1520 entry \"Fontify Buffer\")."
1522 :set
(lambda (variable value
)
1523 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1524 :group
'vhdl-highlight
)
1526 (defcustom vhdl-highlight-forbidden-words nil
1527 "*Non-nil means highlight forbidden words.
1528 The reserved words specified in option `vhdl-forbidden-words' or having the
1529 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1530 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1533 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1534 entry \"Fontify Buffer\")."
1536 :set
(lambda (variable value
)
1537 (vhdl-custom-set variable value
1538 'vhdl-words-init
'vhdl-font-lock-init
))
1539 :group
'vhdl-highlight
)
1541 (defcustom vhdl-highlight-verilog-keywords nil
1542 "*Non-nil means highlight Verilog keywords as reserved words.
1543 Verilog keywords are highlighted in a warning color (face
1544 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1546 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1547 entry \"Fontify Buffer\")."
1549 :set
(lambda (variable value
)
1550 (vhdl-custom-set variable value
1551 'vhdl-words-init
'vhdl-font-lock-init
))
1552 :group
'vhdl-highlight
)
1554 (defcustom vhdl-highlight-translate-off nil
1555 "*Non-nil means background-highlight code excluded from translation.
1556 That is, all code between \"-- pragma translate_off\" and
1557 \"-- pragma translate_on\" is highlighted using a different background color
1558 \(face `vhdl-font-lock-translate-off-face').
1559 Note: this might slow down on-the-fly fontification (and thus editing).
1561 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1562 entry \"Fontify Buffer\")."
1564 :set
(lambda (variable value
)
1565 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1566 :group
'vhdl-highlight
)
1568 (defcustom vhdl-highlight-case-sensitive nil
1569 "*Non-nil means consider case for highlighting.
1571 non-nil also upper-case VHDL words are highlighted, but case of words with
1572 special syntax is not considered
1573 nil only lower-case VHDL words are highlighted, but case of words with
1574 special syntax is considered
1575 Overrides local option `font-lock-keywords-case-fold-search'.
1577 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1578 entry \"Fontify Buffer\")."
1580 :group
'vhdl-highlight
)
1582 (defcustom vhdl-special-syntax-alist
1583 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1584 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1585 ("variable" "\\w+_v" "Grey50" "Grey80"))
1586 "*List of special syntax to be highlighted.
1587 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1588 syntax (as regular expression) are highlighted in the corresponding color.
1590 Name : string of words and spaces
1591 Regexp : regular expression describing word syntax
1592 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1593 Color (light): foreground color for light background
1594 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1595 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1596 Color (dark) : foreground color for dark background
1597 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1598 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1600 Can be used for visual support of naming conventions, such as highlighting
1601 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1602 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1603 common substrings or name suffices.
1604 For each entry, a new face is generated with the specified colors and name
1605 \"vhdl-font-lock-\" + name + \"-face\".
1607 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1608 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1609 :type
'(repeat (list :tag
"Face" :indent
2
1610 (string :tag
"Name ")
1611 (regexp :tag
"Regexp " "\\w+_")
1612 (string :tag
"Color (light)")
1613 (string :tag
"Color (dark) ")))
1614 :set
(lambda (variable value
)
1615 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1616 :group
'vhdl-highlight
)
1618 (defcustom vhdl-forbidden-words
'()
1619 "*List of forbidden words to be highlighted.
1620 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1621 words are highlighted in a warning color to indicate not to use them.
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
1625 :type
'(repeat (string :format
"%v"))
1626 :set
(lambda (variable value
)
1627 (vhdl-custom-set variable value
1628 'vhdl-words-init
'vhdl-font-lock-init
))
1629 :group
'vhdl-highlight
)
1631 (defcustom vhdl-forbidden-syntax
""
1632 "*Syntax of forbidden words to be highlighted.
1633 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1634 syntax are highlighted in a warning color to indicate not to use them.
1635 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1636 highlights identifiers with 10 or more characters).
1638 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1639 entry \"Fontify Buffer\")."
1641 :set
(lambda (variable value
)
1642 (vhdl-custom-set variable value
1643 'vhdl-words-init
'vhdl-font-lock-init
))
1644 :group
'vhdl-highlight
)
1646 (defcustom vhdl-directive-keywords
'("pragma" "synopsys")
1647 "*List of compiler directive keywords recognized for highlighting.
1649 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1650 entry \"Fontify Buffer\")."
1651 :type
'(repeat (string :format
"%v"))
1652 :set
(lambda (variable value
)
1653 (vhdl-custom-set variable value
1654 'vhdl-words-init
'vhdl-font-lock-init
))
1655 :group
'vhdl-highlight
)
1658 (defgroup vhdl-speedbar nil
1659 "Customizations for speedbar."
1662 (defcustom vhdl-speedbar-auto-open nil
1663 "*Non-nil means automatically open speedbar at startup.
1664 Alternatively, the speedbar can be opened from the VHDL menu."
1666 :group
'vhdl-speedbar
)
1668 (defcustom vhdl-speedbar-display-mode
'files
1669 "*Specifies the default displaying mode when opening speedbar.
1670 Alternatively, the displaying mode can be selected from the speedbar menu or
1671 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1672 :type
'(choice (const :tag
"Files" files
)
1673 (const :tag
"Directory hierarchy" directory
)
1674 (const :tag
"Project hierarchy" project
))
1675 :group
'vhdl-speedbar
)
1677 (defcustom vhdl-speedbar-scan-limit
'(10000000 (1000000 50))
1678 "*Limits scanning of large files and netlists.
1679 Design units: maximum file size to scan for design units
1680 Hierarchy (instances of subcomponents):
1681 File size: maximum file size to scan for instances (in bytes)
1682 Instances per arch: maximum number of instances to scan per architecture
1684 \"None\" always means that there is no limit.
1685 In case of files not or incompletely scanned, a warning message and the file
1686 names are printed out.
1687 Background: scanning for instances is considerably slower than scanning for
1688 design units, especially when there are many instances. These limits should
1689 prevent the scanning of large netlists."
1690 :type
'(list (choice :tag
"Design units"
1691 :format
"%t : %[Value Menu%] %v"
1692 (const :tag
"None" nil
)
1693 (integer :tag
"File size"))
1694 (list :tag
"Hierarchy" :indent
2
1695 (choice :tag
"File size"
1696 :format
"%t : %[Value Menu%] %v"
1697 (const :tag
"None" nil
)
1698 (integer :tag
"Size "))
1699 (choice :tag
"Instances per arch"
1700 (const :tag
"None" nil
)
1701 (integer :tag
"Number "))))
1702 :group
'vhdl-speedbar
)
1704 (defcustom vhdl-speedbar-jump-to-unit t
1705 "*Non-nil means jump to the design unit code when opened in a buffer.
1706 The buffer cursor position is left unchanged otherwise."
1708 :group
'vhdl-speedbar
)
1710 (defcustom vhdl-speedbar-update-on-saving t
1711 "*Automatically update design hierarchy when buffer is saved."
1713 :group
'vhdl-speedbar
)
1715 (defcustom vhdl-speedbar-save-cache
'(hierarchy display
)
1716 "*Automatically save modified hierarchy caches when exiting Emacs.
1717 Hierarchy: design hierarchy information
1718 Display: displaying information (which design units to expand)"
1719 :type
'(set (const :tag
"Hierarchy" hierarchy
)
1720 (const :tag
"Display" display
))
1721 :group
'vhdl-speedbar
)
1723 (defcustom vhdl-speedbar-cache-file-name
".emacs-vhdl-cache-\\1-\\2"
1724 "*Name of file for saving hierarchy cache.
1725 \"\\1\" is replaced by the project name if a project is specified,
1726 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1727 different users to have cache files in the same directory). Can also have
1728 an absolute path (i.e. all caches can be stored in one global directory)."
1730 :group
'vhdl-speedbar
)
1733 (defgroup vhdl-menu nil
1734 "Customizations for menues."
1737 (defcustom vhdl-index-menu nil
1738 "*Non-nil means add an index menu for a source file when loading.
1739 Alternatively, the speedbar can be used. Note that the index menu scans a file
1740 when it is opened, while speedbar only scans the file upon request."
1744 (defcustom vhdl-source-file-menu nil
1745 "*Non-nil means add a menu of all source files in current directory.
1746 Alternatively, the speedbar can be used."
1750 (defcustom vhdl-hideshow-menu nil
1751 "*Non-nil means add hideshow menu and functionality at startup.
1752 Hideshow can also be enabled from the VHDL Mode menu.
1753 Hideshow allows hiding code of various VHDL constructs.
1755 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1756 \"Activate Options\"."
1760 (defcustom vhdl-hide-all-init nil
1761 "*Non-nil means hide all design units initially after a file is loaded."
1766 (defgroup vhdl-print nil
1767 "Customizations for printing."
1770 (defcustom vhdl-print-two-column t
1771 "*Non-nil means print code in two columns and landscape format.
1772 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1773 prints VHDL files in a nice two-column landscape style.
1775 NOTE: Activate the new setting by restarting Emacs.
1776 Overrides `ps-print' settings locally."
1780 (defcustom vhdl-print-customize-faces t
1781 "*Non-nil means use an optimized set of faces for postscript printing.
1783 NOTE: Activate the new setting by restarting Emacs.
1784 Overrides `ps-print' settings locally."
1789 (defgroup vhdl-misc nil
1790 "Miscellaneous customizations."
1793 (defcustom vhdl-intelligent-tab t
1794 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1795 That is, if preceeding character is part of a word then complete word,
1796 else if not at beginning of line then insert tab,
1797 else if last command was a `TAB' or `RET' then dedent one step,
1798 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1799 If nil, TAB always indents current line (i.e. `TAB' is bound to
1800 `indent-according-to-mode').
1802 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1803 \"Activate Options\"."
1807 (defcustom vhdl-indent-syntax-based t
1808 "*Non-nil means indent lines of code based on their syntactic context.
1809 Otherwise, a line is indented like the previous nonblank line. This can be
1810 useful in large files where syntax-based indentation gets very slow."
1814 (defcustom vhdl-word-completion-case-sensitive nil
1815 "*Non-nil means word completion using `TAB' is case sensitive.
1816 That is, `TAB' completes words that start with the same letters and case.
1817 Otherwise, case is ignored."
1821 (defcustom vhdl-word-completion-in-minibuffer t
1822 "*Non-nil enables word completion in minibuffer (for template prompts).
1824 NOTE: Activate the new setting by restarting Emacs."
1828 (defcustom vhdl-underscore-is-part-of-word nil
1829 "*Non-nil means consider the underscore character `_' as part of word.
1830 An identifier containing underscores is then treated as a single word in
1831 select and move operations. All parts of an identifier separated by underscore
1832 are treated as single words otherwise.
1834 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1835 \"Activate Options\"."
1837 :set
(lambda (variable value
)
1838 (vhdl-custom-set variable value
'vhdl-mode-syntax-table-init
))
1842 (defgroup vhdl-related nil
1843 "Related general customizations."
1846 ;; add related general customizations
1847 (custom-add-to-group 'vhdl-related
'hideshow
'custom-group
)
1848 (if (featurep 'xemacs
)
1849 (custom-add-to-group 'vhdl-related
'paren-mode
'custom-variable
)
1850 (custom-add-to-group 'vhdl-related
'paren-showing
'custom-group
))
1851 (custom-add-to-group 'vhdl-related
'ps-print
'custom-group
)
1852 (custom-add-to-group 'vhdl-related
'speedbar
'custom-group
)
1853 (custom-add-to-group 'vhdl-related
'line-number-mode
'custom-variable
)
1854 (unless (featurep 'xemacs
)
1855 (custom-add-to-group 'vhdl-related
'transient-mark-mode
'custom-variable
))
1856 (custom-add-to-group 'vhdl-related
'user-full-name
'custom-variable
)
1857 (custom-add-to-group 'vhdl-related
'mail-host-address
'custom-variable
)
1858 (custom-add-to-group 'vhdl-related
'user-mail-address
'custom-variable
)
1860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1861 ;; Internal variables
1863 (defvar vhdl-menu-max-size
20
1864 "*Specifies the maximum size of a menu before splitting it into submenues.")
1866 (defvar vhdl-progress-interval
1
1867 "*Interval used to update progress status during long operations.
1868 If a number, percentage complete gets updated after each interval of
1869 that many seconds. To inhibit all messages, set this option to nil.")
1871 (defvar vhdl-inhibit-startup-warnings-p nil
1872 "*If non-nil, inhibits start up compatibility warnings.")
1874 (defvar vhdl-strict-syntax-p nil
1875 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1876 If the syntactic symbol for a particular line does not match a symbol
1877 in the offsets alist, an error is generated, otherwise no error is
1878 reported and the syntactic symbol is ignored.")
1880 (defvar vhdl-echo-syntactic-information-p nil
1881 "*If non-nil, syntactic info is echoed when the line is indented.")
1883 (defconst vhdl-offsets-alist-default
1889 (statement-cont . vhdl-lineup-statement-cont
)
1890 (statement-block-intro .
+)
1891 (statement-case-intro .
+)
1892 (case-alternative .
+)
1893 (comment . vhdl-lineup-comment
)
1896 (arglist-cont-nonempty . vhdl-lineup-arglist
)
1897 (arglist-close . vhdl-lineup-arglist
)
1904 "Default settings for offsets of syntactic elements.
1905 Do not change this constant! See the variable `vhdl-offsets-alist' for
1908 (defvar vhdl-offsets-alist
(copy-alist vhdl-offsets-alist-default
)
1909 "*Association list of syntactic element symbols and indentation offsets.
1910 As described below, each cons cell in this list has the form:
1912 (SYNTACTIC-SYMBOL . OFFSET)
1914 When a line is indented, `vhdl-mode' first determines the syntactic
1915 context of the line by generating a list of symbols called syntactic
1916 elements. This list can contain more than one syntactic element and
1917 the global variable `vhdl-syntactic-context' contains the context list
1918 for the line being indented. Each element in this list is actually a
1919 cons cell of the syntactic symbol and a buffer position. This buffer
1920 position is call the relative indent point for the line. Some
1921 syntactic symbols may not have a relative indent point associated with
1924 After the syntactic context list for a line is generated, `vhdl-mode'
1925 calculates the absolute indentation for the line by looking at each
1926 syntactic element in the list. First, it compares the syntactic
1927 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1928 finds a match, it adds the OFFSET to the column of the relative indent
1929 point. The sum of this calculation for each element in the syntactic
1930 list is the absolute offset for line being indented.
1932 If the syntactic element does not match any in the `vhdl-offsets-alist',
1933 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1934 the element is ignored.
1936 Actually, OFFSET can be an integer, a function, a variable, or one of
1937 the following symbols: `+', `-', `++', or `--'. These latter
1938 designate positive or negative multiples of `vhdl-basic-offset',
1939 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1940 called with a single argument containing the cons of the syntactic
1941 element symbol and the relative indent point. The function should
1942 return an integer offset.
1944 Here is the current list of valid syntactic element symbols:
1946 string -- inside multi-line string
1947 block-open -- statement block open
1948 block-close -- statement block close
1949 statement -- a VHDL statement
1950 statement-cont -- a continuation of a VHDL statement
1951 statement-block-intro -- the first line in a new statement block
1952 statement-case-intro -- the first line in a case alternative block
1953 case-alternative -- a case statement alternative clause
1954 comment -- a line containing only a comment
1955 arglist-intro -- the first line in an argument list
1956 arglist-cont -- subsequent argument list lines when no
1957 arguments follow on the same line as the
1958 the arglist opening paren
1959 arglist-cont-nonempty -- subsequent argument list lines when at
1960 least one argument follows on the same
1961 line as the arglist opening paren
1962 arglist-close -- the solo close paren of an argument list
1963 entity -- inside an entity declaration
1964 configuration -- inside a configuration declaration
1965 package -- inside a package declaration
1966 architecture -- inside an architecture body
1967 package-body -- inside a package body")
1969 (defvar vhdl-comment-only-line-offset
0
1970 "*Extra offset for line which contains only the start of a comment.
1971 Can contain an integer or a cons cell of the form:
1973 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1975 Where NON-ANCHORED-OFFSET is the amount of offset given to
1976 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1977 the amount of offset to give column-zero anchored comment-only lines.
1978 Just an integer as value is equivalent to (<val> . 0)")
1980 (defvar vhdl-special-indent-hook nil
1981 "*Hook for user defined special indentation adjustments.
1982 This hook gets called after a line is indented by the mode.")
1984 (defvar vhdl-style-alist
1986 (vhdl-basic-offset .
4)
1987 (vhdl-offsets-alist .
())))
1988 "Styles of Indentation.
1989 Elements of this alist are of the form:
1991 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1993 where STYLE-STRING is a short descriptive string used to select a
1994 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1995 value for that variable when using the selected style.
1997 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1998 case, the VALUE is a list containing elements of the form:
2000 (SYNTACTIC-SYMBOL . VALUE)
2002 as described in `vhdl-offsets-alist'. These are passed directly to
2003 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2004 your style, only those that are different from the default.")
2006 ;; dynamically append the default value of most variables
2007 (or (assoc "Default" vhdl-style-alist
)
2008 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2009 vhdl-strict-syntax-p
2010 vhdl-echo-syntactic-information-p
2013 vhdl-comment-only-line-offset
))
2014 (default (cons "Default"
2018 (cons var
(symbol-value var
))))
2020 (setq vhdl-style-alist
(cons default vhdl-style-alist
))))
2022 (defvar vhdl-mode-hook nil
2023 "*Hook called by `vhdl-mode'.")
2026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2027 ;;; Required packages
2028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032 (require 'compile
) ; XEmacs
2034 (require 'hippie-exp
)
2036 ;; optional (minimize warning messages during compile)
2038 (require 'font-lock
)
2040 (require 'speedbar
))
2043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2047 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2048 ;; XEmacs compatibility
2051 (defun vhdl-keep-region-active ()
2052 "Do whatever is necessary to keep the region active in XEmacs.
2053 Ignore byte-compiler warnings you might see."
2054 (and (featurep 'xemacs
)
2055 (setq zmacs-region-stays t
)))
2057 ;; `wildcard-to-regexp' is included only in XEmacs 21
2058 (unless (fboundp 'wildcard-to-regexp
)
2059 (defun wildcard-to-regexp (wildcard)
2060 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2061 (let* ((i (string-match "[*?]" wildcard
))
2062 (result (substring wildcard
0 i
))
2063 (len (length wildcard
)))
2066 (let ((ch (aref wildcard i
)))
2067 (setq result
(concat result
2068 (cond ((eq ch ?
*) "[^\000]*")
2069 ((eq ch ??
) "[^\000]")
2070 (t (char-to-string ch
)))))
2072 (concat "\\`" result
"\\'"))))
2074 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2075 ;; `regexp-opt' accelerates fontification by 10-20%
2076 (unless (fboundp 'regexp-opt
)
2077 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2078 (defun regexp-opt (strings &optional paren
)
2079 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
2080 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
))))
2082 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2083 (unless (fboundp 'match-string-no-properties
)
2084 (defalias 'match-string-no-properties
'match-string
))
2086 ;; `subst-char-in-string' undefined (XEmacs)
2087 (unless (fboundp 'subst-char-in-string
)
2088 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
2089 (let ((i (length string
))
2090 (newstr (if inplace string
(copy-sequence string
))))
2093 (if (eq (aref newstr i
) fromchar
) (aset newstr i tochar
)))
2096 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2097 (when (and (featurep 'xemacs
) (string< itimer-version
"1.09")
2098 (not noninteractive
))
2100 (when (string< itimer-version
"1.09")
2101 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2102 (beep) (sit-for 5)))
2104 ;; `file-expand-wildcards' undefined (XEmacs)
2105 (unless (fboundp 'file-expand-wildcards
)
2106 (defun file-expand-wildcards (pattern &optional full
)
2107 "Taken from Emacs' `files.el'."
2108 (let* ((nondir (file-name-nondirectory pattern
))
2109 (dirpart (file-name-directory pattern
))
2110 (dirs (if (and dirpart
(string-match "[[*?]" dirpart
))
2111 (mapcar 'file-name-as-directory
2112 (file-expand-wildcards (directory-file-name dirpart
)))
2116 (when (or (null (car dirs
)) ; Possible if DIRPART is not wild.
2117 (file-directory-p (directory-file-name (car dirs
))))
2118 (let ((this-dir-contents
2120 (mapcar #'(lambda (name)
2121 (unless (string-match "\\`\\.\\.?\\'"
2122 (file-name-nondirectory name
))
2124 (directory-files (or (car dirs
) ".") full
2125 (wildcard-to-regexp nondir
))))))
2128 (if (and (car dirs
) (not full
))
2129 (mapcar (function (lambda (name) (concat (car dirs
) name
)))
2133 (setq dirs
(cdr dirs
)))
2136 ;; `member-ignore-case' undefined (XEmacs)
2137 (unless (fboundp 'member-ignore-case
)
2138 (defalias 'member-ignore-case
'member
))
2140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2141 ;; Compatibility with older VHDL Mode versions
2143 (defvar vhdl-warnings nil
2144 "Warnings to tell the user during start up.")
2146 (defun vhdl-run-when-idle (secs repeat function
)
2147 "Wait until idle, then run FUNCTION."
2148 (if (fboundp 'start-itimer
)
2149 (start-itimer "vhdl-mode" function secs repeat t
)
2150 ; (run-with-idle-timer secs repeat function)))
2151 ;; explicitely activate timer (necessary when Emacs is already idle)
2152 (aset (run-with-idle-timer secs repeat function
) 0 nil
)))
2154 (defun vhdl-warning-when-idle (&rest args
)
2155 "Wait until idle, then print out warning STRING and beep."
2157 (vhdl-warning (apply 'format args
) t
)
2158 (unless vhdl-warnings
2159 (vhdl-run-when-idle .1 nil
'vhdl-print-warnings
))
2160 (setq vhdl-warnings
(cons (apply 'format args
) vhdl-warnings
))))
2162 (defun vhdl-warning (string &optional nobeep
)
2163 "Print out warning STRING and beep."
2164 (message "WARNING: %s" string
)
2165 (unless (or nobeep noninteractive
) (beep)))
2167 (defun vhdl-print-warnings ()
2168 "Print out messages in variable `vhdl-warnings'."
2169 (let ((no-warnings (length vhdl-warnings
)))
2170 (setq vhdl-warnings
(nreverse vhdl-warnings
))
2171 (while vhdl-warnings
2172 (message "WARNING: %s" (car vhdl-warnings
))
2173 (setq vhdl-warnings
(cdr vhdl-warnings
)))
2175 (when (> no-warnings
1)
2176 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2178 ;; Backward compatibility checks and fixes
2179 ;; option `vhdl-compiler' changed format
2180 (unless (stringp vhdl-compiler
)
2181 (setq vhdl-compiler
"ModelSim")
2182 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2184 ;; option `vhdl-standard' changed format
2185 (unless (listp vhdl-standard
)
2186 (setq vhdl-standard
'(87 nil
))
2187 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2189 ;; option `vhdl-model-alist' changed format
2190 (when (= (length (car vhdl-model-alist
)) 3)
2191 (let ((old-alist vhdl-model-alist
)
2194 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2195 (setq old-alist
(cdr old-alist
)))
2196 (setq vhdl-model-alist
(nreverse new-alist
)))
2197 (customize-save-variable 'vhdl-model-alist vhdl-model-alist
))
2199 ;; option `vhdl-project-alist' changed format
2200 (when (= (length (car vhdl-project-alist
)) 3)
2201 (let ((old-alist vhdl-project-alist
)
2204 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2205 (setq old-alist
(cdr old-alist
)))
2206 (setq vhdl-project-alist
(nreverse new-alist
)))
2207 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2209 ;; option `vhdl-project-alist' changed format (3.31.1)
2210 (when (= (length (car vhdl-project-alist
)) 4)
2211 (let ((old-alist vhdl-project-alist
)
2214 (setq elem
(car old-alist
))
2216 (cons (list (nth 0 elem
) (nth 1 elem
) "" (nth 2 elem
)
2217 nil
"./" "work" "work/" "Makefile" (nth 3 elem
))
2219 (setq old-alist
(cdr old-alist
)))
2220 (setq vhdl-project-alist
(nreverse new-alist
)))
2221 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2223 ;; option `vhdl-project-alist' changed format (3.31.12)
2224 (when (= (length (car vhdl-project-alist
)) 10)
2225 (let ((tmp-alist vhdl-project-alist
))
2227 (setcdr (nthcdr 3 (car tmp-alist
))
2228 (cons "" (nthcdr 4 (car tmp-alist
))))
2229 (setq tmp-alist
(cdr tmp-alist
))))
2230 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2232 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2233 (when (= (length (car vhdl-compiler-alist
)) 7)
2234 (let ((old-alist vhdl-compiler-alist
)
2237 (setq elem
(car old-alist
))
2239 (cons (list (nth 0 elem
) (nth 1 elem
) "" "make -f \\1"
2240 (if (equal (nth 3 elem
) "") nil
(nth 3 elem
))
2241 (nth 4 elem
) "work/" "Makefile" (downcase (nth 0 elem
))
2242 (nth 5 elem
) (nth 6 elem
) nil
)
2244 (setq old-alist
(cdr old-alist
)))
2245 (setq vhdl-compiler-alist
(nreverse new-alist
)))
2246 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2248 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2249 (when (= (length (car vhdl-compiler-alist
)) 12)
2250 (let ((tmp-alist vhdl-compiler-alist
))
2252 (setcdr (nthcdr 4 (car tmp-alist
))
2253 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist
))))
2254 (setq tmp-alist
(cdr tmp-alist
))))
2255 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2257 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2258 (when (= (length (car vhdl-compiler-alist
)) 13)
2259 (let ((tmp-alist vhdl-compiler-alist
))
2261 (setcdr (nthcdr 3 (car tmp-alist
))
2262 (cons "" (nthcdr 4 (car tmp-alist
))))
2263 (setq tmp-alist
(cdr tmp-alist
))))
2264 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2266 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2267 (when (= (length (nth 11 (car vhdl-compiler-alist
))) 3)
2268 (let ((tmp-alist vhdl-compiler-alist
))
2270 (setcdr (nthcdr 2 (nth 11 (car tmp-alist
)))
2272 (setq tmp-alist
(cdr tmp-alist
))))
2273 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2275 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2276 (when (equal vhdl-project
"")
2277 (setq vhdl-project nil
)
2278 (customize-save-variable 'vhdl-project vhdl-project
))
2280 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2281 (when (stringp vhdl-project-file-name
)
2282 (setq vhdl-project-file-name
(list vhdl-project-file-name
))
2283 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name
))
2285 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2286 (if (not (boundp 'speedbar-indentation-width
))
2287 (defvar speedbar-indentation-width
2)
2288 ;; set default to 2 if not already customized
2289 (unless (get 'speedbar-indentation-width
'saved-value
)
2290 (setq speedbar-indentation-width
2)))
2293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2294 ;;; Help functions / inline substitutions / macros
2295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2297 (defun vhdl-standard-p (standard)
2298 "Check if STANDARD is specified as used standard."
2299 (or (eq standard
(car vhdl-standard
))
2300 (memq standard
(cadr vhdl-standard
))))
2302 (defun vhdl-project-p (&optional warning
)
2303 "Return non-nil if a project is displayed, i.e. directories or files are
2305 (if (assoc vhdl-project vhdl-project-alist
)
2307 (when (and vhdl-project warning
)
2308 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project
))
2311 (defun vhdl-resolve-env-variable (string)
2312 "Resolve environment variables in STRING."
2313 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string
)
2314 (setq string
(concat (match-string 1 string
)
2315 (getenv (match-string 2 string
))
2316 (match-string 4 string
))))
2319 (defun vhdl-default-directory ()
2320 "Return the default directory of the current project or the directory of the
2321 current buffer if no project is defined."
2322 (if (vhdl-project-p)
2323 (expand-file-name (vhdl-resolve-env-variable
2324 (nth 1 (aget vhdl-project-alist vhdl-project
))))
2327 (defmacro vhdl-prepare-search-1
(&rest body
)
2328 "Enable case insensitive search and switch to syntax table that includes '_',
2329 then execute BODY, and finally restore the old environment. Used for
2330 consistent searching."
2331 `(let ((case-fold-search t
)) ; case insensitive search
2332 ;; use extended syntax table
2333 (with-syntax-table vhdl-mode-ext-syntax-table
2336 (defmacro vhdl-prepare-search-2
(&rest body
)
2337 "Enable case insensitive search, switch to syntax table that includes '_',
2338 and remove `intangible' overlays, then execute BODY, and finally restore the
2339 old environment. Used for consistent searching."
2340 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2341 `(let ((case-fold-search t
) ; case insensitive search
2342 (current-syntax-table (syntax-table))
2343 overlay-all-list overlay-intangible-list overlay
)
2344 ;; use extended syntax table
2345 (set-syntax-table vhdl-mode-ext-syntax-table
)
2346 ;; remove `intangible' overlays
2347 (when (fboundp 'overlay-lists
)
2348 (setq overlay-all-list
(overlay-lists))
2349 (setq overlay-all-list
2350 (append (car overlay-all-list
) (cdr overlay-all-list
)))
2351 (while overlay-all-list
2352 (setq overlay
(car overlay-all-list
))
2353 (when (memq 'intangible
(overlay-properties overlay
))
2354 (setq overlay-intangible-list
2355 (cons overlay overlay-intangible-list
))
2356 (overlay-put overlay
'intangible nil
))
2357 (setq overlay-all-list
(cdr overlay-all-list
))))
2358 ;; execute BODY safely
2361 ;; restore syntax table
2362 (set-syntax-table current-syntax-table
)
2363 ;; restore `intangible' overlays
2364 (when (fboundp 'overlay-lists
)
2365 (while overlay-intangible-list
2366 (overlay-put (car overlay-intangible-list
) 'intangible t
)
2367 (setq overlay-intangible-list
2368 (cdr overlay-intangible-list
)))))))
2370 (defmacro vhdl-visit-file
(file-name issue-error
&rest body
)
2371 "Visit file FILE-NAME and execute BODY."
2372 `(if (null ,file-name
)
2374 (unless (file-directory-p ,file-name
)
2375 (let ((source-buffer (current-buffer))
2376 (visiting-buffer (find-buffer-visiting ,file-name
))
2378 (when (or (and visiting-buffer
(set-buffer visiting-buffer
))
2380 (progn (set-buffer (create-file-buffer ,file-name
))
2381 (setq file-opened t
)
2382 (vhdl-insert-file-contents ,file-name
)
2383 (modify-syntax-entry ?\-
". 12" (syntax-table))
2384 (modify-syntax-entry ?
\n ">" (syntax-table))
2385 (modify-syntax-entry ?\^M
">" (syntax-table))
2386 (modify-syntax-entry ?_
"w" (syntax-table))
2391 (when file-opened
(kill-buffer (current-buffer)))
2392 (set-buffer source-buffer
)
2393 (error "ERROR: File cannot be opened: \"%s\"" ,file-name
))
2394 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name
) t
)
2396 (condition-case info
2401 (when file-opened
(kill-buffer (current-buffer)))
2402 (set-buffer source-buffer
)
2403 (error (cadr info
)))
2404 (vhdl-warning (cadr info
))))))
2405 (when file-opened
(kill-buffer (current-buffer)))
2406 (set-buffer source-buffer
)))))
2408 (defun vhdl-insert-file-contents (filename)
2409 "Nicked from `insert-file-contents-literally', but allow coding system
2411 (let ((format-alist nil
)
2412 (after-insert-file-functions nil
)
2413 (jka-compr-compression-info-list nil
))
2414 (insert-file-contents filename t
)))
2416 (defun vhdl-sort-alist (alist)
2418 (sort alist
(function (lambda (a b
) (string< (car a
) (car b
))))))
2420 (defun vhdl-get-subdirs (directory)
2421 "Recursively get subdirectories of DIRECTORY."
2422 (let ((dir-list (list (file-name-as-directory directory
)))
2424 (setq file-list
(vhdl-directory-files directory t
"\\w.*"))
2426 (when (file-directory-p (car file-list
))
2427 (setq dir-list
(append dir-list
(vhdl-get-subdirs (car file-list
)))))
2428 (setq file-list
(cdr file-list
)))
2431 (defun vhdl-aput (alist-symbol key
&optional value
)
2432 "As `aput', but delete key-value pair if VALUE is nil."
2434 (aput alist-symbol key value
)
2435 (adelete alist-symbol key
)))
2437 (defun vhdl-delete (elt list
)
2438 "Delete by side effect the first occurrence of ELT as a member of LIST."
2439 (setq list
(cons nil list
))
2441 (while (and (cdr list1
) (not (equal elt
(cadr list1
))))
2442 (setq list1
(cdr list1
)))
2444 (setcdr list1
(cddr list1
))))
2447 (defun vhdl-speedbar-refresh (&optional key
)
2448 "Refresh directory or project with name KEY."
2449 (when (and (boundp 'speedbar-frame
)
2450 (frame-live-p speedbar-frame
))
2452 (last-frame (selected-frame)))
2455 (select-frame speedbar-frame
)
2456 (when (save-excursion
2457 (goto-char (point-min))
2458 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key
"$") nil t
))
2459 (goto-char (match-end 1))
2460 (speedbar-do-function-pointer)
2462 (speedbar-do-function-pointer)
2463 (message "Refreshing speedbar...done"))
2464 (select-frame last-frame
)))))
2466 (defun vhdl-show-messages ()
2467 "Get *Messages* buffer to show recent messages."
2469 (display-buffer (if (featurep 'xemacs
) " *Message-Log*" "*Messages*")))
2471 (defun vhdl-use-direct-instantiation ()
2472 "Return whether direct instantiation is used."
2473 (or (eq vhdl-use-direct-instantiation
'always
)
2474 (and (eq vhdl-use-direct-instantiation
'standard
)
2475 (not (vhdl-standard-p '87)))))
2477 (defun vhdl-max-marker (marker1 marker2
)
2478 "Return larger marker."
2479 (if (> marker1 marker2
) marker1 marker2
))
2481 (defun vhdl-goto-marker (marker)
2482 "Goto marker in appropriate buffer."
2483 (when (markerp marker
)
2484 (set-buffer (marker-buffer marker
)))
2487 (defun vhdl-menu-split (list title
)
2488 "Split menu LIST into several submenues, if number of
2489 elements > `vhdl-menu-max-size'."
2490 (if (> (length list
) vhdl-menu-max-size
)
2497 (setq sublist
(cons (car remain
) sublist
))
2498 (setq remain
(cdr remain
))
2500 (if (= i vhdl-menu-max-size
)
2502 (setq result
(cons (cons (format "%s %s" title menuno
)
2503 (nreverse sublist
)) result
))
2505 (setq menuno
(+ menuno
1))
2506 (setq sublist
'()))))
2508 (setq result
(cons (cons (format "%s %s" title menuno
)
2509 (nreverse sublist
)) result
)))
2514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2521 (defvar vhdl-template-map nil
2522 "Keymap for VHDL templates.")
2524 (defun vhdl-template-map-init ()
2525 "Initialize `vhdl-template-map'."
2526 (setq vhdl-template-map
(make-sparse-keymap))
2527 ;; key bindings for VHDL templates
2528 (define-key vhdl-template-map
"al" 'vhdl-template-alias
)
2529 (define-key vhdl-template-map
"ar" 'vhdl-template-architecture
)
2530 (define-key vhdl-template-map
"at" 'vhdl-template-assert
)
2531 (define-key vhdl-template-map
"ad" 'vhdl-template-attribute-decl
)
2532 (define-key vhdl-template-map
"as" 'vhdl-template-attribute-spec
)
2533 (define-key vhdl-template-map
"bl" 'vhdl-template-block
)
2534 (define-key vhdl-template-map
"ca" 'vhdl-template-case-is
)
2535 (define-key vhdl-template-map
"cd" 'vhdl-template-component-decl
)
2536 (define-key vhdl-template-map
"ci" 'vhdl-template-component-inst
)
2537 (define-key vhdl-template-map
"cs" 'vhdl-template-conditional-signal-asst
)
2538 (define-key vhdl-template-map
"Cb" 'vhdl-template-block-configuration
)
2539 (define-key vhdl-template-map
"Cc" 'vhdl-template-component-conf
)
2540 (define-key vhdl-template-map
"Cd" 'vhdl-template-configuration-decl
)
2541 (define-key vhdl-template-map
"Cs" 'vhdl-template-configuration-spec
)
2542 (define-key vhdl-template-map
"co" 'vhdl-template-constant
)
2543 (define-key vhdl-template-map
"di" 'vhdl-template-disconnect
)
2544 (define-key vhdl-template-map
"el" 'vhdl-template-else
)
2545 (define-key vhdl-template-map
"ei" 'vhdl-template-elsif
)
2546 (define-key vhdl-template-map
"en" 'vhdl-template-entity
)
2547 (define-key vhdl-template-map
"ex" 'vhdl-template-exit
)
2548 (define-key vhdl-template-map
"fi" 'vhdl-template-file
)
2549 (define-key vhdl-template-map
"fg" 'vhdl-template-for-generate
)
2550 (define-key vhdl-template-map
"fl" 'vhdl-template-for-loop
)
2551 (define-key vhdl-template-map
"\C-f" 'vhdl-template-footer
)
2552 (define-key vhdl-template-map
"fb" 'vhdl-template-function-body
)
2553 (define-key vhdl-template-map
"fd" 'vhdl-template-function-decl
)
2554 (define-key vhdl-template-map
"ge" 'vhdl-template-generic
)
2555 (define-key vhdl-template-map
"gd" 'vhdl-template-group-decl
)
2556 (define-key vhdl-template-map
"gt" 'vhdl-template-group-template
)
2557 (define-key vhdl-template-map
"\C-h" 'vhdl-template-header
)
2558 (define-key vhdl-template-map
"ig" 'vhdl-template-if-generate
)
2559 (define-key vhdl-template-map
"it" 'vhdl-template-if-then
)
2560 (define-key vhdl-template-map
"li" 'vhdl-template-library
)
2561 (define-key vhdl-template-map
"lo" 'vhdl-template-bare-loop
)
2562 (define-key vhdl-template-map
"\C-m" 'vhdl-template-modify
)
2563 (define-key vhdl-template-map
"\C-t" 'vhdl-template-insert-date
)
2564 (define-key vhdl-template-map
"ma" 'vhdl-template-map
)
2565 (define-key vhdl-template-map
"ne" 'vhdl-template-next
)
2566 (define-key vhdl-template-map
"ot" 'vhdl-template-others
)
2567 (define-key vhdl-template-map
"Pd" 'vhdl-template-package-decl
)
2568 (define-key vhdl-template-map
"Pb" 'vhdl-template-package-body
)
2569 (define-key vhdl-template-map
"(" 'vhdl-template-paired-parens
)
2570 (define-key vhdl-template-map
"po" 'vhdl-template-port
)
2571 (define-key vhdl-template-map
"pb" 'vhdl-template-procedure-body
)
2572 (define-key vhdl-template-map
"pd" 'vhdl-template-procedure-decl
)
2573 (define-key vhdl-template-map
"pc" 'vhdl-template-process-comb
)
2574 (define-key vhdl-template-map
"ps" 'vhdl-template-process-seq
)
2575 (define-key vhdl-template-map
"rp" 'vhdl-template-report
)
2576 (define-key vhdl-template-map
"rt" 'vhdl-template-return
)
2577 (define-key vhdl-template-map
"ss" 'vhdl-template-selected-signal-asst
)
2578 (define-key vhdl-template-map
"si" 'vhdl-template-signal
)
2579 (define-key vhdl-template-map
"su" 'vhdl-template-subtype
)
2580 (define-key vhdl-template-map
"ty" 'vhdl-template-type
)
2581 (define-key vhdl-template-map
"us" 'vhdl-template-use
)
2582 (define-key vhdl-template-map
"va" 'vhdl-template-variable
)
2583 (define-key vhdl-template-map
"wa" 'vhdl-template-wait
)
2584 (define-key vhdl-template-map
"wl" 'vhdl-template-while-loop
)
2585 (define-key vhdl-template-map
"wi" 'vhdl-template-with
)
2586 (define-key vhdl-template-map
"wc" 'vhdl-template-clocked-wait
)
2587 (define-key vhdl-template-map
"\C-pb" 'vhdl-template-package-numeric-bit
)
2588 (define-key vhdl-template-map
"\C-pn" 'vhdl-template-package-numeric-std
)
2589 (define-key vhdl-template-map
"\C-ps" 'vhdl-template-package-std-logic-1164
)
2590 (define-key vhdl-template-map
"\C-pA" 'vhdl-template-package-std-logic-arith
)
2591 (define-key vhdl-template-map
"\C-pM" 'vhdl-template-package-std-logic-misc
)
2592 (define-key vhdl-template-map
"\C-pS" 'vhdl-template-package-std-logic-signed
)
2593 (define-key vhdl-template-map
"\C-pT" 'vhdl-template-package-std-logic-textio
)
2594 (define-key vhdl-template-map
"\C-pU" 'vhdl-template-package-std-logic-unsigned
)
2595 (define-key vhdl-template-map
"\C-pt" 'vhdl-template-package-textio
)
2596 (define-key vhdl-template-map
"\C-dn" 'vhdl-template-directive-translate-on
)
2597 (define-key vhdl-template-map
"\C-df" 'vhdl-template-directive-translate-off
)
2598 (define-key vhdl-template-map
"\C-dN" 'vhdl-template-directive-synthesis-on
)
2599 (define-key vhdl-template-map
"\C-dF" 'vhdl-template-directive-synthesis-off
)
2600 (define-key vhdl-template-map
"\C-q" 'vhdl-template-search-prompt
)
2601 (when (vhdl-standard-p 'ams
)
2602 (define-key vhdl-template-map
"br" 'vhdl-template-break
)
2603 (define-key vhdl-template-map
"cu" 'vhdl-template-case-use
)
2604 (define-key vhdl-template-map
"iu" 'vhdl-template-if-use
)
2605 (define-key vhdl-template-map
"lm" 'vhdl-template-limit
)
2606 (define-key vhdl-template-map
"na" 'vhdl-template-nature
)
2607 (define-key vhdl-template-map
"pa" 'vhdl-template-procedural
)
2608 (define-key vhdl-template-map
"qf" 'vhdl-template-quantity-free
)
2609 (define-key vhdl-template-map
"qb" 'vhdl-template-quantity-branch
)
2610 (define-key vhdl-template-map
"qs" 'vhdl-template-quantity-source
)
2611 (define-key vhdl-template-map
"sn" 'vhdl-template-subnature
)
2612 (define-key vhdl-template-map
"te" 'vhdl-template-terminal
)
2614 (when (vhdl-standard-p 'math
)
2615 (define-key vhdl-template-map
"\C-pc" 'vhdl-template-package-math-complex
)
2616 (define-key vhdl-template-map
"\C-pr" 'vhdl-template-package-math-real
)
2619 ;; initialize template map for VHDL Mode
2620 (vhdl-template-map-init)
2622 (defun vhdl-function-name (prefix string
&optional postfix
)
2623 "Generate a Lisp function name.
2624 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2625 STRING are replaced by `-' and substrings are converted to lower case."
2626 (let ((name prefix
))
2627 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string
)
2629 (concat name
"-" (downcase (substring string
0 (match-end 1)))))
2630 (setq string
(substring string
(match-beginning 2))))
2631 (when postfix
(setq name
(concat name
"-" postfix
)))
2634 (defvar vhdl-model-map nil
2635 "Keymap for VHDL models.")
2637 (defun vhdl-model-map-init ()
2638 "Initialize `vhdl-model-map'."
2639 (setq vhdl-model-map
(make-sparse-keymap))
2640 ;; key bindings for VHDL models
2641 (let ((model-alist vhdl-model-alist
) model
)
2643 (setq model
(car model-alist
))
2644 (define-key vhdl-model-map
(nth 2 model
)
2645 (vhdl-function-name "vhdl-model" (nth 0 model
)))
2646 (setq model-alist
(cdr model-alist
)))))
2648 ;; initialize user model map for VHDL Mode
2649 (vhdl-model-map-init)
2651 (defvar vhdl-mode-map nil
2652 "Keymap for VHDL Mode.")
2654 (defun vhdl-mode-map-init ()
2655 "Initialize `vhdl-mode-map'."
2656 (setq vhdl-mode-map
(make-sparse-keymap))
2657 ;; template key bindings
2658 (define-key vhdl-mode-map
"\C-c\C-t" vhdl-template-map
)
2659 ;; model key bindings
2660 (define-key vhdl-mode-map
"\C-c\C-m" vhdl-model-map
)
2661 ;; standard key bindings
2662 (define-key vhdl-mode-map
"\M-a" 'vhdl-beginning-of-statement
)
2663 (define-key vhdl-mode-map
"\M-e" 'vhdl-end-of-statement
)
2664 (define-key vhdl-mode-map
"\M-\C-f" 'vhdl-forward-sexp
)
2665 (define-key vhdl-mode-map
"\M-\C-b" 'vhdl-backward-sexp
)
2666 (define-key vhdl-mode-map
"\M-\C-u" 'vhdl-backward-up-list
)
2667 (define-key vhdl-mode-map
"\M-\C-a" 'vhdl-backward-same-indent
)
2668 (define-key vhdl-mode-map
"\M-\C-e" 'vhdl-forward-same-indent
)
2669 (unless (featurep 'xemacs
) ; would override `M-backspace' in XEmacs
2670 (define-key vhdl-mode-map
"\M-\C-h" 'vhdl-mark-defun
))
2671 (define-key vhdl-mode-map
"\M-\C-q" 'vhdl-indent-sexp
)
2672 (define-key vhdl-mode-map
"\M-^" 'vhdl-delete-indentation
)
2673 ;; backspace/delete key bindings
2674 (define-key vhdl-mode-map
[backspace] 'backward-delete-char-untabify)
2675 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2676 (define-key vhdl-mode-map [delete] 'delete-char)
2677 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2678 ;; mode specific key bindings
2679 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2680 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2681 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2682 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2683 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2684 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2685 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2686 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2687 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2688 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2689 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2690 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2691 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2692 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2693 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2694 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2695 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2696 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2697 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2698 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2699 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2700 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2701 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2702 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2703 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2704 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2705 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2706 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2707 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2708 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2709 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2710 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2711 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2712 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2713 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2714 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2715 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2716 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2717 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2718 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2719 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2720 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2721 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2722 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2723 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2724 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2725 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2726 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2727 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2728 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2729 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2730 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2731 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2732 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2733 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2734 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2735 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2736 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2737 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2738 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2739 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2740 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2741 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2742 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2743 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2744 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2745 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2746 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2747 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2748 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2749 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2750 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2751 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2752 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2753 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2754 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2755 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2756 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2757 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2758 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2759 ;; insert commands bindings
2760 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2761 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2762 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2763 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2764 ;; electric key bindings
2765 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2766 (when vhdl-intelligent-tab
2767 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2768 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2769 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2770 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2771 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2772 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2773 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2774 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2775 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2776 (when (vhdl-standard-p 'ams)
2777 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2779 ;; initialize mode map for VHDL Mode
2780 (vhdl-mode-map-init)
2782 ;; define special minibuffer keymap for enabling word completion in minibuffer
2783 ;; (useful in template generator prompts)
2784 (defvar vhdl-minibuffer-local-map
2785 (let ((map (make-sparse-keymap)))
2786 (set-keymap-parent map minibuffer-local-map)
2787 (when vhdl-word-completion-in-minibuffer
2788 (define-key map "\t" 'vhdl-minibuffer-tab))
2790 "Keymap for minibuffer used in VHDL Mode.")
2792 ;; set up electric character functions to work with
2793 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2797 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2798 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2799 '(vhdl-electric-space
2801 vhdl-electric-return
2803 vhdl-electric-open-bracket
2804 vhdl-electric-close-bracket
2806 vhdl-electric-semicolon
2808 vhdl-electric-period
2809 vhdl-electric-equal))
2811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2814 (defvar vhdl-mode-syntax-table nil
2815 "Syntax table used in `vhdl-mode' buffers.")
2817 (defvar vhdl-mode-ext-syntax-table nil
2818 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2820 (defun vhdl-mode-syntax-table-init ()
2821 "Initialize `vhdl-mode-syntax-table'."
2822 (setq vhdl-mode-syntax-table (make-syntax-table))
2823 ;; define punctuation
2824 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2825 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2826 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2827 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2828 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2829 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2830 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2831 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2832 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2833 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2834 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2835 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2836 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2837 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2838 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2839 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2841 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2842 ;; define underscore
2843 (when vhdl-underscore-is-part-of-word
2844 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2845 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2846 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2847 ;; and \n and \^M end a comment
2848 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2850 ;; define parentheses to match
2851 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2857 ;; extended syntax table including '_' (for simpler search regexps)
2858 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2859 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2861 ;; initialize syntax table for VHDL Mode
2862 (vhdl-mode-syntax-table-init)
2864 (defvar vhdl-syntactic-context nil
2865 "Buffer local variable containing syntactic analysis list.")
2866 (make-variable-buffer-local 'vhdl-syntactic-context)
2868 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2869 ;; Abbrev ook bindings
2871 (defvar vhdl-mode-abbrev-table nil
2872 "Abbrev table to use in `vhdl-mode' buffers.")
2874 (defun vhdl-mode-abbrev-table-init ()
2875 "Initialize `vhdl-mode-abbrev-table'."
2876 (define-abbrev-table 'vhdl-mode-abbrev-table
2878 (when (memq 'vhdl vhdl-electric-keywords)
2880 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2882 ("--" . vhdl-template-display-comment-hook)
2883 ("abs" . vhdl-template-default-hook)
2884 ("access" . vhdl-template-default-hook)
2885 ("after" . vhdl-template-default-hook)
2886 ("alias" . vhdl-template-alias-hook)
2887 ("all" . vhdl-template-default-hook)
2888 ("and" . vhdl-template-default-hook)
2889 ("arch" . vhdl-template-architecture-hook)
2890 ("architecture" . vhdl-template-architecture-hook)
2891 ("array" . vhdl-template-default-hook)
2892 ("assert" . vhdl-template-assert-hook)
2893 ("attr" . vhdl-template-attribute-hook)
2894 ("attribute" . vhdl-template-attribute-hook)
2895 ("begin" . vhdl-template-default-indent-hook)
2896 ("block" . vhdl-template-block-hook)
2897 ("body" . vhdl-template-default-hook)
2898 ("buffer" . vhdl-template-default-hook)
2899 ("bus" . vhdl-template-default-hook)
2900 ("case" . vhdl-template-case-hook)
2901 ("comp" . vhdl-template-component-hook)
2902 ("component" . vhdl-template-component-hook)
2903 ("cond" . vhdl-template-conditional-signal-asst-hook)
2904 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2905 ("conf" . vhdl-template-configuration-hook)
2906 ("configuration" . vhdl-template-configuration-hook)
2907 ("cons" . vhdl-template-constant-hook)
2908 ("constant" . vhdl-template-constant-hook)
2909 ("disconnect" . vhdl-template-disconnect-hook)
2910 ("downto" . vhdl-template-default-hook)
2911 ("else" . vhdl-template-else-hook)
2912 ("elseif" . vhdl-template-elsif-hook)
2913 ("elsif" . vhdl-template-elsif-hook)
2914 ("end" . vhdl-template-default-indent-hook)
2915 ("entity" . vhdl-template-entity-hook)
2916 ("exit" . vhdl-template-exit-hook)
2917 ("file" . vhdl-template-file-hook)
2918 ("for" . vhdl-template-for-hook)
2919 ("func" . vhdl-template-function-hook)
2920 ("function" . vhdl-template-function-hook)
2921 ("generic" . vhdl-template-generic-hook)
2922 ("group" . vhdl-template-group-hook)
2923 ("guarded" . vhdl-template-default-hook)
2924 ("if" . vhdl-template-if-hook)
2925 ("impure" . vhdl-template-default-hook)
2926 ("in" . vhdl-template-default-hook)
2927 ("inertial" . vhdl-template-default-hook)
2928 ("inout" . vhdl-template-default-hook)
2929 ("inst" . vhdl-template-instance-hook)
2930 ("instance" . vhdl-template-instance-hook)
2931 ("is" . vhdl-template-default-hook)
2932 ("label" . vhdl-template-default-hook)
2933 ("library" . vhdl-template-library-hook)
2934 ("linkage" . vhdl-template-default-hook)
2935 ("literal" . vhdl-template-default-hook)
2936 ("loop" . vhdl-template-bare-loop-hook)
2937 ("map" . vhdl-template-map-hook)
2938 ("mod" . vhdl-template-default-hook)
2939 ("nand" . vhdl-template-default-hook)
2940 ("new" . vhdl-template-default-hook)
2941 ("next" . vhdl-template-next-hook)
2942 ("nor" . vhdl-template-default-hook)
2943 ("not" . vhdl-template-default-hook)
2944 ("null" . vhdl-template-default-hook)
2945 ("of" . vhdl-template-default-hook)
2946 ("on" . vhdl-template-default-hook)
2947 ("open" . vhdl-template-default-hook)
2948 ("or" . vhdl-template-default-hook)
2949 ("others" . vhdl-template-others-hook)
2950 ("out" . vhdl-template-default-hook)
2951 ("pack" . vhdl-template-package-hook)
2952 ("package" . vhdl-template-package-hook)
2953 ("port" . vhdl-template-port-hook)
2954 ("postponed" . vhdl-template-default-hook)
2955 ("procedure" . vhdl-template-procedure-hook)
2956 ("process" . vhdl-template-process-hook)
2957 ("pure" . vhdl-template-default-hook)
2958 ("range" . vhdl-template-default-hook)
2959 ("record" . vhdl-template-default-hook)
2960 ("register" . vhdl-template-default-hook)
2961 ("reject" . vhdl-template-default-hook)
2962 ("rem" . vhdl-template-default-hook)
2963 ("report" . vhdl-template-report-hook)
2964 ("return" . vhdl-template-return-hook)
2965 ("rol" . vhdl-template-default-hook)
2966 ("ror" . vhdl-template-default-hook)
2967 ("select" . vhdl-template-selected-signal-asst-hook)
2968 ("severity" . vhdl-template-default-hook)
2969 ("shared" . vhdl-template-default-hook)
2970 ("sig" . vhdl-template-signal-hook)
2971 ("signal" . vhdl-template-signal-hook)
2972 ("sla" . vhdl-template-default-hook)
2973 ("sll" . vhdl-template-default-hook)
2974 ("sra" . vhdl-template-default-hook)
2975 ("srl" . vhdl-template-default-hook)
2976 ("subtype" . vhdl-template-subtype-hook)
2977 ("then" . vhdl-template-default-hook)
2978 ("to" . vhdl-template-default-hook)
2979 ("transport" . vhdl-template-default-hook)
2980 ("type" . vhdl-template-type-hook)
2981 ("unaffected" . vhdl-template-default-hook)
2982 ("units" . vhdl-template-default-hook)
2983 ("until" . vhdl-template-default-hook)
2984 ("use" . vhdl-template-use-hook)
2985 ("var" . vhdl-template-variable-hook)
2986 ("variable" . vhdl-template-variable-hook)
2987 ("wait" . vhdl-template-wait-hook)
2988 ("when" . vhdl-template-when-hook)
2989 ("while" . vhdl-template-while-loop-hook)
2990 ("with" . vhdl-template-with-hook)
2991 ("xnor" . vhdl-template-default-hook)
2992 ("xor" . vhdl-template-default-hook)
2994 ;; VHDL-AMS keywords
2995 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2996 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2998 ("across" . vhdl-template-default-hook)
2999 ("break" . vhdl-template-break-hook)
3000 ("limit" . vhdl-template-limit-hook)
3001 ("nature" . vhdl-template-nature-hook)
3002 ("noise" . vhdl-template-default-hook)
3003 ("procedural" . vhdl-template-procedural-hook)
3004 ("quantity" . vhdl-template-quantity-hook)
3005 ("reference" . vhdl-template-default-hook)
3006 ("spectrum" . vhdl-template-default-hook)
3007 ("subnature" . vhdl-template-subnature-hook)
3008 ("terminal" . vhdl-template-terminal-hook)
3009 ("through" . vhdl-template-default-hook)
3010 ("tolerance" . vhdl-template-default-hook)
3012 ;; user model keywords
3013 (when (memq 'user vhdl-electric-keywords)
3014 (let (abbrev-list keyword)
3015 (dolist (elem vhdl-model-alist)
3016 (setq keyword (nth 3 elem))
3017 (unless (equal keyword "")
3018 (push (list keyword ""
3020 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3024 ;; initialize abbrev table for VHDL Mode
3025 (vhdl-mode-abbrev-table-init)
3027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3028 ;; Template completion lists
3030 (defvar vhdl-template-construct-alist nil
3031 "List of built-in construct templates.")
3033 (defun vhdl-template-construct-alist-init ()
3034 "Initialize `vhdl-template-construct-alist'."
3036 vhdl-template-construct-alist
3039 ("alias declaration" vhdl-template-alias)
3040 ("architecture body" vhdl-template-architecture)
3041 ("assertion" vhdl-template-assert)
3042 ("attribute declaration" vhdl-template-attribute-decl)
3043 ("attribute specification" vhdl-template-attribute-spec)
3044 ("block configuration" vhdl-template-block-configuration)
3045 ("block statement" vhdl-template-block)
3046 ("case statement" vhdl-template-case-is)
3047 ("component configuration" vhdl-template-component-conf)
3048 ("component declaration" vhdl-template-component-decl)
3049 ("component instantiation statement" vhdl-template-component-inst)
3050 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3051 ("configuration declaration" vhdl-template-configuration-decl)
3052 ("configuration specification" vhdl-template-configuration-spec)
3053 ("constant declaration" vhdl-template-constant)
3054 ("disconnection specification" vhdl-template-disconnect)
3055 ("entity declaration" vhdl-template-entity)
3056 ("exit statement" vhdl-template-exit)
3057 ("file declaration" vhdl-template-file)
3058 ("generate statement" vhdl-template-generate)
3059 ("generic clause" vhdl-template-generic)
3060 ("group declaration" vhdl-template-group-decl)
3061 ("group template declaration" vhdl-template-group-template)
3062 ("if statement" vhdl-template-if-then)
3063 ("library clause" vhdl-template-library)
3064 ("loop statement" vhdl-template-loop)
3065 ("next statement" vhdl-template-next)
3066 ("package declaration" vhdl-template-package-decl)
3067 ("package body" vhdl-template-package-body)
3068 ("port clause" vhdl-template-port)
3069 ("process statement" vhdl-template-process)
3070 ("report statement" vhdl-template-report)
3071 ("return statement" vhdl-template-return)
3072 ("selected signal assignment" vhdl-template-selected-signal-asst)
3073 ("signal declaration" vhdl-template-signal)
3074 ("subprogram declaration" vhdl-template-subprogram-decl)
3075 ("subprogram body" vhdl-template-subprogram-body)
3076 ("subtype declaration" vhdl-template-subtype)
3077 ("type declaration" vhdl-template-type)
3078 ("use clause" vhdl-template-use)
3079 ("variable declaration" vhdl-template-variable)
3080 ("wait statement" vhdl-template-wait)
3082 (when (vhdl-standard-p 'ams)
3084 ("break statement" vhdl-template-break)
3085 ("nature declaration" vhdl-template-nature)
3086 ("quantity declaration" vhdl-template-quantity)
3087 ("simultaneous case statement" vhdl-template-case-use)
3088 ("simultaneous if statement" vhdl-template-if-use)
3089 ("simultaneous procedural statement" vhdl-template-procedural)
3090 ("step limit specification" vhdl-template-limit)
3091 ("subnature declaration" vhdl-template-subnature)
3092 ("terminal declaration" vhdl-template-terminal)
3095 ;; initialize for VHDL Mode
3096 (vhdl-template-construct-alist-init)
3098 (defvar vhdl-template-package-alist nil
3099 "List of built-in package templates.")
3101 (defun vhdl-template-package-alist-init ()
3102 "Initialize `vhdl-template-package-alist'."
3104 vhdl-template-package-alist
3107 ("numeric_bit" vhdl-template-package-numeric-bit)
3108 ("numeric_std" vhdl-template-package-numeric-std)
3109 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3110 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3111 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3112 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3113 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3114 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3115 ("textio" vhdl-template-package-textio)
3117 (when (vhdl-standard-p 'math)
3119 ("math_complex" vhdl-template-package-math-complex)
3120 ("math_real" vhdl-template-package-math-real)
3123 ;; initialize for VHDL Mode
3124 (vhdl-template-package-alist-init)
3126 (defvar vhdl-template-directive-alist
3128 ("translate_on" vhdl-template-directive-translate-on)
3129 ("translate_off" vhdl-template-directive-translate-off)
3130 ("synthesis_on" vhdl-template-directive-synthesis-on)
3131 ("synthesis_off" vhdl-template-directive-synthesis-off)
3133 "List of built-in directive templates.")
3136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3141 ;; VHDL menu (using `easy-menu.el')
3143 (defun vhdl-customize ()
3144 "Call the customize function with `vhdl' as argument."
3146 (customize-browse 'vhdl))
3148 (defun vhdl-create-mode-menu ()
3149 "Create VHDL Mode menu."
3153 ["None" (vhdl-set-project "")
3154 :style radio :selected (null vhdl-project)]
3156 ;; add menu entries for defined projects
3157 (let ((project-alist vhdl-project-alist) menu-list name)
3158 (while project-alist
3159 (setq name (caar project-alist))
3161 (cons `[,name (vhdl-set-project ,name)
3162 :style radio :selected (equal ,name vhdl-project)]
3164 (setq project-alist (cdr project-alist)))
3166 (if vhdl-project-sort
3168 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3169 (nreverse menu-list)))
3170 (vhdl-menu-split menu-list "Project"))
3172 ["Select Project..." vhdl-set-project t]
3173 ["Set As Default Project" vhdl-set-default-project t]
3175 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3176 ["Import Project..." vhdl-import-project
3177 :keys "C-c C-p C-m" :active t]
3178 ["Export Project" vhdl-export-project vhdl-project]
3180 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3183 ["Compile Buffer" vhdl-compile t]
3184 ["Stop Compilation" kill-compilation t]
3186 ["Make" vhdl-make t]
3187 ["Generate Makefile" vhdl-generate-makefile t]
3189 ["Next Error" next-error t]
3190 ["Previous Error" previous-error t]
3191 ["First Error" first-error t]
3195 ;; add menu entries for defined compilers
3196 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3198 (setq name (caar comp-alist))
3200 (cons `[,name (setq vhdl-compiler ,name)
3201 :style radio :selected (equal ,name vhdl-compiler)]
3203 (setq comp-alist (cdr comp-alist)))
3204 (setq menu-list (nreverse menu-list))
3205 (vhdl-menu-split menu-list "Compiler"))
3207 ["Select Compiler..." vhdl-set-compiler t]
3209 ["Customize Compiler..."
3210 (customize-option 'vhdl-compiler-alist) t])))
3215 ["Alias" vhdl-template-alias t]
3216 ["Architecture" vhdl-template-architecture t]
3217 ["Assert" vhdl-template-assert t]
3218 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3219 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3220 ["Block" vhdl-template-block t]
3221 ["Case" vhdl-template-case-is t]
3222 ["Component (Decl)" vhdl-template-component-decl t]
3223 ["(Component) Instance" vhdl-template-component-inst t]
3224 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3225 ["Configuration (Block)" vhdl-template-block-configuration t]
3226 ["Configuration (Comp)" vhdl-template-component-conf t]
3227 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3228 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3229 ["Constant" vhdl-template-constant t]
3230 ["Disconnect" vhdl-template-disconnect t]
3231 ["Else" vhdl-template-else t]
3232 ["Elsif" vhdl-template-elsif t]
3233 ["Entity" vhdl-template-entity t]
3234 ["Exit" vhdl-template-exit t]
3235 ["File" vhdl-template-file t]
3236 ["For (Generate)" vhdl-template-for-generate t]
3237 ["For (Loop)" vhdl-template-for-loop t]
3238 ["Function (Body)" vhdl-template-function-body t]
3239 ["Function (Decl)" vhdl-template-function-decl t]
3240 ["Generic" vhdl-template-generic t]
3241 ["Group (Decl)" vhdl-template-group-decl t]
3242 ["Group (Template)" vhdl-template-group-template t])
3244 ["If (Generate)" vhdl-template-if-generate t]
3245 ["If (Then)" vhdl-template-if-then t]
3246 ["Library" vhdl-template-library t]
3247 ["Loop" vhdl-template-bare-loop t]
3248 ["Map" vhdl-template-map t]
3249 ["Next" vhdl-template-next t]
3250 ["Others (Aggregate)" vhdl-template-others t]
3251 ["Package (Decl)" vhdl-template-package-decl t]
3252 ["Package (Body)" vhdl-template-package-body t]
3253 ["Port" vhdl-template-port t]
3254 ["Procedure (Body)" vhdl-template-procedure-body t]
3255 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3256 ["Process (Comb)" vhdl-template-process-comb t]
3257 ["Process (Seq)" vhdl-template-process-seq t]
3258 ["Report" vhdl-template-report t]
3259 ["Return" vhdl-template-return t]
3260 ["Select" vhdl-template-selected-signal-asst t]
3261 ["Signal" vhdl-template-signal t]
3262 ["Subtype" vhdl-template-subtype t]
3263 ["Type" vhdl-template-type t]
3264 ["Use" vhdl-template-use t]
3265 ["Variable" vhdl-template-variable t]
3266 ["Wait" vhdl-template-wait t]
3267 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3268 ["When" vhdl-template-when t]
3269 ["While (Loop)" vhdl-template-while-loop t]
3270 ["With" vhdl-template-with t]))
3271 (when (vhdl-standard-p 'ams)
3272 '(("VHDL-AMS Construct"
3273 ["Break" vhdl-template-break t]
3274 ["Case (Use)" vhdl-template-case-use t]
3275 ["If (Use)" vhdl-template-if-use t]
3276 ["Limit" vhdl-template-limit t]
3277 ["Nature" vhdl-template-nature t]
3278 ["Procedural" vhdl-template-procedural t]
3279 ["Quantity (Free)" vhdl-template-quantity-free t]
3280 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3281 ["Quantity (Source)" vhdl-template-quantity-source t]
3282 ["Subnature" vhdl-template-subnature t]
3283 ["Terminal" vhdl-template-terminal t])))
3284 '(["Insert Construct..." vhdl-template-insert-construct
3285 :keys "C-c C-i C-t"]
3290 (when (vhdl-standard-p 'math)
3291 '(["math_complex" vhdl-template-package-math-complex t]
3292 ["math_real" vhdl-template-package-math-real t]))
3293 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3294 ["numeric_std" vhdl-template-package-numeric-std t]
3295 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3296 ["textio" vhdl-template-package-textio t]
3298 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3299 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3300 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3301 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3302 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3304 ["Insert Package..." vhdl-template-insert-package
3305 :keys "C-c C-i C-p"])))
3307 ["translate_on" vhdl-template-directive-translate-on t]
3308 ["translate_off" vhdl-template-directive-translate-off t]
3309 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3310 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3312 ["Insert Directive..." vhdl-template-insert-directive
3313 :keys "C-c C-i C-d"])
3315 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3316 ["Insert Footer" vhdl-template-footer t]
3317 ["Insert Date" vhdl-template-insert-date t]
3318 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3320 ["Query Next Prompt" vhdl-template-search-prompt t]))
3323 ;; add menu entries for defined models
3324 (let ((model-alist vhdl-model-alist) menu-list model)
3326 (setq model (car model-alist))
3331 (vhdl-function-name "vhdl-model" (nth 0 model))
3332 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3334 (setq model-alist (cdr model-alist)))
3335 (setq menu-list (nreverse menu-list))
3336 (vhdl-menu-split menu-list "Model"))
3338 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3339 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3341 ["Copy" vhdl-port-copy t]
3343 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3344 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3345 ["Paste As Instance" vhdl-port-paste-instance
3346 :keys "C-c C-p C-i" :active vhdl-port-list]
3347 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3348 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3349 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3350 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3352 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3354 ["Flatten" vhdl-port-flatten
3355 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3356 ["Reverse Direction" vhdl-port-reverse-direction
3357 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3359 ["New Component" vhdl-compose-new-component t]
3360 ["Copy Component" vhdl-port-copy t]
3361 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3362 ["Wire Components" vhdl-compose-wire-components t]
3364 ["Generate Configuration" vhdl-compose-configuration t]
3365 ["Generate Components Package" vhdl-compose-components-package t])
3367 ["Copy" vhdl-subprog-copy t]
3369 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3370 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3371 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3373 ["Flatten" vhdl-subprog-flatten
3374 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3377 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3379 ["Insert Inline Comment" vhdl-comment-append-inline t]
3380 ["Insert Horizontal Line" vhdl-comment-display-line t]
3381 ["Insert Display Comment" vhdl-comment-display t]
3383 ["Fill Comment" fill-paragraph t]
3384 ["Fill Comment Region" fill-region (mark)]
3385 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3386 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3388 ["Kill" vhdl-line-kill t]
3389 ["Copy" vhdl-line-copy t]
3390 ["Yank" vhdl-line-yank t]
3391 ["Expand" vhdl-line-expand t]
3393 ["Transpose Next" vhdl-line-transpose-next t]
3394 ["Transpose Prev" vhdl-line-transpose-previous t]
3395 ["Open" vhdl-line-open t]
3396 ["Join" vhdl-delete-indentation t]
3398 ["Goto" goto-line t]
3399 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3401 ["Forward Statement" vhdl-end-of-statement t]
3402 ["Backward Statement" vhdl-beginning-of-statement t]
3403 ["Forward Expression" vhdl-forward-sexp t]
3404 ["Backward Expression" vhdl-backward-sexp t]
3405 ["Forward Same Indent" vhdl-forward-same-indent t]
3406 ["Backward Same Indent" vhdl-backward-same-indent t]
3407 ["Forward Function" vhdl-end-of-defun t]
3408 ["Backward Function" vhdl-beginning-of-defun t]
3409 ["Mark Function" vhdl-mark-defun t])
3412 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3413 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3414 ["Region" vhdl-indent-region (mark)]
3415 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3417 ["Group" vhdl-align-group t]
3418 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3419 ["List" vhdl-align-list t]
3420 ["Declarations" vhdl-align-declarations t]
3421 ["Region" vhdl-align-region (mark)]
3422 ["Buffer" vhdl-align-buffer t]
3424 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3425 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3426 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3428 ["List" vhdl-fill-list t]
3429 ["Group" vhdl-fill-group t]
3430 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3431 ["Region" vhdl-fill-region (mark)])
3433 ["Region" vhdl-beautify-region (mark)]
3434 ["Buffer" vhdl-beautify-buffer t])
3436 ["Generic/Port Clause" vhdl-fix-clause t]
3438 ["Case Region" vhdl-fix-case-region (mark)]
3439 ["Case Buffer" vhdl-fix-case-buffer t]
3441 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3442 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3444 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3446 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3447 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3449 ["Fontify Buffer" vhdl-fontify-buffer t]
3450 ["Statistics Buffer" vhdl-statistics-buffer t]
3451 ["Show Messages" vhdl-show-messages t]
3452 ["Syntactic Info" vhdl-show-syntactic-information t]
3454 ["Speedbar" vhdl-speedbar t]
3455 ["Hide/Show" vhdl-hs-minor-mode t]
3458 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3459 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3460 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3461 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3462 ["Version" vhdl-version t]
3463 ["Bug Report..." vhdl-submit-bug-report t]
3468 (progn (customize-set-variable 'vhdl-electric-mode
3469 (not vhdl-electric-mode))
3470 (vhdl-mode-line-update))
3471 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3473 (progn (customize-set-variable 'vhdl-stutter-mode
3474 (not vhdl-stutter-mode))
3475 (vhdl-mode-line-update))
3476 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3478 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3479 (not vhdl-indent-tabs-mode))
3480 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3481 :style toggle :selected vhdl-indent-tabs-mode]
3483 ["Customize Group..." (customize-group 'vhdl-mode) t])
3485 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3487 '("Selected Project at Startup"
3488 ["None" (progn (customize-set-variable 'vhdl-project nil)
3489 (vhdl-set-project ""))
3490 :style radio :selected (null vhdl-project)]
3492 ;; add menu entries for defined projects
3493 (let ((project-alist vhdl-project-alist) menu-list name)
3494 (while project-alist
3495 (setq name (caar project-alist))
3497 (cons `[,name (progn (customize-set-variable
3498 'vhdl-project ,name)
3499 (vhdl-set-project ,name))
3500 :style radio :selected (equal ,name vhdl-project)]
3502 (setq project-alist (cdr project-alist)))
3503 (setq menu-list (nreverse menu-list))
3504 (vhdl-menu-split menu-list "Project")))
3505 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3506 ("Auto Load Setup File"
3508 (customize-set-variable 'vhdl-project-auto-load
3509 (if (memq 'startup vhdl-project-auto-load)
3510 (delq 'startup vhdl-project-auto-load)
3511 (cons 'startup vhdl-project-auto-load)))
3512 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3514 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3515 :style toggle :selected vhdl-project-sort]
3517 ["Customize Group..." (customize-group 'vhdl-project) t])
3519 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3521 '("Selected Compiler at Startup")
3522 ;; add menu entries for defined compilers
3523 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3525 (setq name (caar comp-alist))
3527 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3528 :style radio :selected (equal ,name vhdl-compiler)]
3530 (setq comp-alist (cdr comp-alist)))
3531 (setq menu-list (nreverse menu-list))
3532 (vhdl-menu-split menu-list "Compler")))
3533 ["Use Local Error Regexp"
3534 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3535 (not vhdl-compile-use-local-error-regexp))
3536 :style toggle :selected vhdl-compile-use-local-error-regexp]
3537 ["Makefile Generation Hook..."
3538 (customize-option 'vhdl-makefile-generation-hook) t]
3539 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3541 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3545 (progn (customize-set-variable 'vhdl-standard
3546 (list '87 (cadr vhdl-standard)))
3547 (vhdl-activate-customizations))
3548 :style radio :selected (eq '87 (car vhdl-standard))]
3550 (progn (customize-set-variable 'vhdl-standard
3551 (list '93 (cadr vhdl-standard)))
3552 (vhdl-activate-customizations))
3553 :style radio :selected (eq '93 (car vhdl-standard))]
3556 (progn (customize-set-variable
3557 'vhdl-standard (list (car vhdl-standard)
3558 (if (memq 'ams (cadr vhdl-standard))
3559 (delq 'ams (cadr vhdl-standard))
3560 (cons 'ams (cadr vhdl-standard)))))
3561 (vhdl-activate-customizations))
3562 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3564 (progn (customize-set-variable
3565 'vhdl-standard (list (car vhdl-standard)
3566 (if (memq 'math (cadr vhdl-standard))
3567 (delq 'math (cadr vhdl-standard))
3568 (cons 'math (cadr vhdl-standard)))))
3569 (vhdl-activate-customizations))
3570 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3571 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3572 ["Upper Case Keywords"
3573 (customize-set-variable 'vhdl-upper-case-keywords
3574 (not vhdl-upper-case-keywords))
3575 :style toggle :selected vhdl-upper-case-keywords]
3577 (customize-set-variable 'vhdl-upper-case-types
3578 (not vhdl-upper-case-types))
3579 :style toggle :selected vhdl-upper-case-types]
3580 ["Upper Case Attributes"
3581 (customize-set-variable 'vhdl-upper-case-attributes
3582 (not vhdl-upper-case-attributes))
3583 :style toggle :selected vhdl-upper-case-attributes]
3584 ["Upper Case Enumeration Values"
3585 (customize-set-variable 'vhdl-upper-case-enum-values
3586 (not vhdl-upper-case-enum-values))
3587 :style toggle :selected vhdl-upper-case-enum-values]
3588 ["Upper Case Constants"
3589 (customize-set-variable 'vhdl-upper-case-constants
3590 (not vhdl-upper-case-constants))
3591 :style toggle :selected vhdl-upper-case-constants]
3592 ("Use Direct Instantiation"
3594 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3595 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3597 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3598 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3600 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3601 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3603 ["Customize Group..." (customize-group 'vhdl-style) t])
3605 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3606 ["Architecture File Name..."
3607 (customize-option 'vhdl-architecture-file-name) t]
3608 ["Configuration File Name..."
3609 (customize-option 'vhdl-configuration-file-name) t]
3610 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3613 (customize-set-variable 'vhdl-file-name-case 'identity)
3614 :style radio :selected (eq 'identity vhdl-file-name-case)]
3616 (customize-set-variable 'vhdl-file-name-case 'downcase)
3617 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3619 (customize-set-variable 'vhdl-file-name-case 'upcase)
3620 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3622 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3623 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3625 ["Customize Group..." (customize-group 'vhdl-naming) t])
3627 ("Electric Keywords"
3629 (customize-set-variable 'vhdl-electric-keywords
3630 (if (memq 'vhdl vhdl-electric-keywords)
3631 (delq 'vhdl vhdl-electric-keywords)
3632 (cons 'vhdl vhdl-electric-keywords)))
3633 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3634 ["User Model Keywords"
3635 (customize-set-variable 'vhdl-electric-keywords
3636 (if (memq 'user vhdl-electric-keywords)
3637 (delq 'user vhdl-electric-keywords)
3638 (cons 'user vhdl-electric-keywords)))
3639 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3640 ("Insert Optional Labels"
3642 (customize-set-variable 'vhdl-optional-labels 'none)
3643 :style radio :selected (eq 'none vhdl-optional-labels)]
3645 (customize-set-variable 'vhdl-optional-labels 'process)
3646 :style radio :selected (eq 'process vhdl-optional-labels)]
3648 (customize-set-variable 'vhdl-optional-labels 'all)
3649 :style radio :selected (eq 'all vhdl-optional-labels)])
3650 ("Insert Empty Lines"
3652 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3653 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3654 ["Design Units Only"
3655 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3656 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3658 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3659 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3660 ["Argument List Indent"
3661 (customize-set-variable 'vhdl-argument-list-indent
3662 (not vhdl-argument-list-indent))
3663 :style toggle :selected vhdl-argument-list-indent]
3664 ["Association List with Formals"
3665 (customize-set-variable 'vhdl-association-list-with-formals
3666 (not vhdl-association-list-with-formals))
3667 :style toggle :selected vhdl-association-list-with-formals]
3668 ["Conditions in Parenthesis"
3669 (customize-set-variable 'vhdl-conditions-in-parenthesis
3670 (not vhdl-conditions-in-parenthesis))
3671 :style toggle :selected vhdl-conditions-in-parenthesis]
3672 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3673 ["One String..." (customize-option 'vhdl-one-string) t]
3675 ["Header String..." (customize-option 'vhdl-file-header) t]
3676 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3677 ["Company Name..." (customize-option 'vhdl-company-name) t]
3678 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3679 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3680 ["Date Format..." (customize-option 'vhdl-date-format) t]
3681 ["Modify Date Prefix String..."
3682 (customize-option 'vhdl-modify-date-prefix-string) t]
3683 ["Modify Date on Saving"
3684 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3685 (not vhdl-modify-date-on-saving))
3686 (vhdl-activate-customizations))
3687 :style toggle :selected vhdl-modify-date-on-saving])
3688 ("Sequential Process"
3691 (customize-set-variable 'vhdl-reset-kind 'none)
3692 :style radio :selected (eq 'none vhdl-reset-kind)]
3694 (customize-set-variable 'vhdl-reset-kind 'sync)
3695 :style radio :selected (eq 'sync vhdl-reset-kind)]
3697 (customize-set-variable 'vhdl-reset-kind 'async)
3698 :style radio :selected (eq 'async vhdl-reset-kind)])
3699 ["Reset is Active High"
3700 (customize-set-variable 'vhdl-reset-active-high
3701 (not vhdl-reset-active-high))
3702 :style toggle :selected vhdl-reset-active-high]
3703 ["Use Rising Clock Edge"
3704 (customize-set-variable 'vhdl-clock-rising-edge
3705 (not vhdl-clock-rising-edge))
3706 :style toggle :selected vhdl-clock-rising-edge]
3707 ("Clock Edge Condition"
3709 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3710 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3711 ["Function \"rising_edge\""
3712 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3713 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3714 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3715 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3717 ["Customize Group..." (customize-group 'vhdl-template) t])
3719 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3721 ["Include Port Comments"
3722 (customize-set-variable 'vhdl-include-port-comments
3723 (not vhdl-include-port-comments))
3724 :style toggle :selected vhdl-include-port-comments]
3725 ["Include Direction Comments"
3726 (customize-set-variable 'vhdl-include-direction-comments
3727 (not vhdl-include-direction-comments))
3728 :style toggle :selected vhdl-include-direction-comments]
3729 ["Include Type Comments"
3730 (customize-set-variable 'vhdl-include-type-comments
3731 (not vhdl-include-type-comments))
3732 :style toggle :selected vhdl-include-type-comments]
3733 ("Include Group Comments"
3735 (customize-set-variable 'vhdl-include-group-comments 'never)
3736 :style radio :selected (eq 'never vhdl-include-group-comments)]
3738 (customize-set-variable 'vhdl-include-group-comments 'decl)
3739 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3741 (customize-set-variable 'vhdl-include-group-comments 'always)
3742 :style radio :selected (eq 'always vhdl-include-group-comments)])
3743 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3744 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3746 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3747 ["Architecture Name..."
3748 (customize-option 'vhdl-testbench-architecture-name) t]
3749 ["Configuration Name..."
3750 (customize-option 'vhdl-testbench-configuration-name) t]
3751 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3753 (customize-set-variable 'vhdl-testbench-include-header
3754 (not vhdl-testbench-include-header))
3755 :style toggle :selected vhdl-testbench-include-header]
3756 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3757 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3758 ["Initialize Signals"
3759 (customize-set-variable 'vhdl-testbench-initialize-signals
3760 (not vhdl-testbench-initialize-signals))
3761 :style toggle :selected vhdl-testbench-initialize-signals]
3762 ["Include Library Clause"
3763 (customize-set-variable 'vhdl-testbench-include-library
3764 (not vhdl-testbench-include-library))
3765 :style toggle :selected vhdl-testbench-include-library]
3766 ["Include Configuration"
3767 (customize-set-variable 'vhdl-testbench-include-configuration
3768 (not vhdl-testbench-include-configuration))
3769 :style toggle :selected vhdl-testbench-include-configuration]
3772 (customize-set-variable 'vhdl-testbench-create-files 'none)
3773 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3775 (customize-set-variable 'vhdl-testbench-create-files 'single)
3776 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3778 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3779 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3780 ["Testbench Entity File Name..."
3781 (customize-option 'vhdl-testbench-entity-file-name) t]
3782 ["Testbench Architecture File Name..."
3783 (customize-option 'vhdl-testbench-architecture-file-name) t])
3785 ["Customize Group..." (customize-group 'vhdl-port) t])
3787 ["Architecture Name..."
3788 (customize-option 'vhdl-compose-architecture-name) t]
3789 ["Configuration Name..."
3790 (customize-option 'vhdl-compose-configuration-name) t]
3791 ["Components Package Name..."
3792 (customize-option 'vhdl-components-package-name) t]
3793 ["Use Components Package"
3794 (customize-set-variable 'vhdl-use-components-package
3795 (not vhdl-use-components-package))
3796 :style toggle :selected vhdl-use-components-package]
3798 (customize-set-variable 'vhdl-compose-include-header
3799 (not vhdl-compose-include-header))
3800 :style toggle :selected vhdl-compose-include-header]
3801 ("Create Entity/Architecture Files"
3803 (customize-set-variable 'vhdl-compose-create-files 'none)
3804 :style radio :selected (eq 'none vhdl-compose-create-files)]
3806 (customize-set-variable 'vhdl-compose-create-files 'single)
3807 :style radio :selected (eq 'single vhdl-compose-create-files)]
3809 (customize-set-variable 'vhdl-compose-create-files 'separate)
3810 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3811 ["Create Configuration File"
3812 (customize-set-variable 'vhdl-compose-configuration-create-file
3813 (not vhdl-compose-configuration-create-file))
3814 :style toggle :selected vhdl-compose-configuration-create-file]
3815 ["Hierarchical Configuration"
3816 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3817 (not vhdl-compose-configuration-hierarchical))
3818 :style toggle :selected vhdl-compose-configuration-hierarchical]
3819 ["Use Subconfiguration"
3820 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3821 (not vhdl-compose-configuration-use-subconfiguration))
3822 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3824 ["Customize Group..." (customize-group 'vhdl-compose) t])
3826 ["Self Insert Comments"
3827 (customize-set-variable 'vhdl-self-insert-comments
3828 (not vhdl-self-insert-comments))
3829 :style toggle :selected vhdl-self-insert-comments]
3830 ["Prompt for Comments"
3831 (customize-set-variable 'vhdl-prompt-for-comments
3832 (not vhdl-prompt-for-comments))
3833 :style toggle :selected vhdl-prompt-for-comments]
3834 ["Inline Comment Column..."
3835 (customize-option 'vhdl-inline-comment-column) t]
3836 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3838 ["Customize Group..." (customize-group 'vhdl-comment) t])
3840 ["Auto Align Templates"
3841 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3842 :style toggle :selected vhdl-auto-align]
3843 ["Align Line Groups"
3844 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3845 :style toggle :selected vhdl-align-groups]
3846 ["Group Separation String..."
3847 (customize-set-variable 'vhdl-align-group-separate) t]
3848 ["Align Lines with Same Indent"
3849 (customize-set-variable 'vhdl-align-same-indent
3850 (not vhdl-align-same-indent))
3851 :style toggle :selected vhdl-align-same-indent]
3853 ["Customize Group..." (customize-group 'vhdl-align) t])
3855 ["Highlighting On/Off..."
3857 (if (fboundp 'global-font-lock-mode)
3858 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3859 ["Highlight Keywords"
3860 (progn (customize-set-variable 'vhdl-highlight-keywords
3861 (not vhdl-highlight-keywords))
3862 (vhdl-fontify-buffer))
3863 :style toggle :selected vhdl-highlight-keywords]
3865 (progn (customize-set-variable 'vhdl-highlight-names
3866 (not vhdl-highlight-names))
3867 (vhdl-fontify-buffer))
3868 :style toggle :selected vhdl-highlight-names]
3869 ["Highlight Special Words"
3870 (progn (customize-set-variable 'vhdl-highlight-special-words
3871 (not vhdl-highlight-special-words))
3872 (vhdl-fontify-buffer))
3873 :style toggle :selected vhdl-highlight-special-words]
3874 ["Highlight Forbidden Words"
3875 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3876 (not vhdl-highlight-forbidden-words))
3877 (vhdl-fontify-buffer))
3878 :style toggle :selected vhdl-highlight-forbidden-words]
3879 ["Highlight Verilog Keywords"
3880 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3881 (not vhdl-highlight-verilog-keywords))
3882 (vhdl-fontify-buffer))
3883 :style toggle :selected vhdl-highlight-verilog-keywords]
3884 ["Highlight \"translate_off\""
3885 (progn (customize-set-variable 'vhdl-highlight-translate-off
3886 (not vhdl-highlight-translate-off))
3887 (vhdl-fontify-buffer))
3888 :style toggle :selected vhdl-highlight-translate-off]
3889 ["Case Sensitive Highlighting"
3890 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3891 (not vhdl-highlight-case-sensitive))
3892 (vhdl-fontify-buffer))
3893 :style toggle :selected vhdl-highlight-case-sensitive]
3894 ["Special Syntax Definition..."
3895 (customize-option 'vhdl-special-syntax-alist) t]
3896 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3897 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3898 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3899 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3901 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3903 ["Auto Open at Startup"
3904 (customize-set-variable 'vhdl-speedbar-auto-open
3905 (not vhdl-speedbar-auto-open))
3906 :style toggle :selected vhdl-speedbar-auto-open]
3907 ("Default Displaying Mode"
3909 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3910 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3911 ["Directory Hierarchy"
3912 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3913 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3914 ["Project Hierarchy"
3915 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3916 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3917 ["Indentation Offset..."
3918 (customize-option 'speedbar-indentation-width) t]
3919 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3920 ["Jump to Unit when Opening"
3921 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3922 (not vhdl-speedbar-jump-to-unit))
3923 :style toggle :selected vhdl-speedbar-jump-to-unit]
3924 ["Update Hierarchy on File Saving"
3925 (customize-set-variable 'vhdl-speedbar-update-on-saving
3926 (not vhdl-speedbar-update-on-saving))
3927 :style toggle :selected vhdl-speedbar-update-on-saving]
3928 ("Save in Cache File"
3929 ["Hierarchy Information"
3930 (customize-set-variable 'vhdl-speedbar-save-cache
3931 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3932 (delq 'hierarchy vhdl-speedbar-save-cache)
3933 (cons 'hierarchy vhdl-speedbar-save-cache)))
3934 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3935 ["Displaying Status"
3936 (customize-set-variable 'vhdl-speedbar-save-cache
3937 (if (memq 'display vhdl-speedbar-save-cache)
3938 (delq 'display vhdl-speedbar-save-cache)
3939 (cons 'display vhdl-speedbar-save-cache)))
3940 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3941 ["Cache File Name..."
3942 (customize-option 'vhdl-speedbar-cache-file-name) t]
3944 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3946 ["Add Index Menu when Loading File"
3947 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3948 (vhdl-index-menu-init))
3949 :style toggle :selected vhdl-index-menu]
3950 ["Add Source File Menu when Loading File"
3951 (progn (customize-set-variable 'vhdl-source-file-menu
3952 (not vhdl-source-file-menu))
3953 (vhdl-add-source-files-menu))
3954 :style toggle :selected vhdl-source-file-menu]
3955 ["Add Hideshow Menu at Startup"
3956 (progn (customize-set-variable 'vhdl-hideshow-menu
3957 (not vhdl-hideshow-menu))
3958 (vhdl-activate-customizations))
3959 :style toggle :selected vhdl-hideshow-menu]
3960 ["Hide Everything Initially"
3961 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3962 :style toggle :selected vhdl-hide-all-init]
3964 ["Customize Group..." (customize-group 'vhdl-menu) t])
3966 ["In Two Column Format"
3967 (progn (customize-set-variable 'vhdl-print-two-column
3968 (not vhdl-print-two-column))
3969 (message "Activate new setting by saving options and restarting Emacs"))
3970 :style toggle :selected vhdl-print-two-column]
3971 ["Use Customized Faces"
3972 (progn (customize-set-variable 'vhdl-print-customize-faces
3973 (not vhdl-print-customize-faces))
3974 (message "Activate new setting by saving options and restarting Emacs"))
3975 :style toggle :selected vhdl-print-customize-faces]
3977 ["Customize Group..." (customize-group 'vhdl-print) t])
3979 ["Use Intelligent Tab"
3980 (progn (customize-set-variable 'vhdl-intelligent-tab
3981 (not vhdl-intelligent-tab))
3982 (vhdl-activate-customizations))
3983 :style toggle :selected vhdl-intelligent-tab]
3984 ["Indent Syntax-Based"
3985 (customize-set-variable 'vhdl-indent-syntax-based
3986 (not vhdl-indent-syntax-based))
3987 :style toggle :selected vhdl-indent-syntax-based]
3988 ["Word Completion is Case Sensitive"
3989 (customize-set-variable 'vhdl-word-completion-case-sensitive
3990 (not vhdl-word-completion-case-sensitive))
3991 :style toggle :selected vhdl-word-completion-case-sensitive]
3992 ["Word Completion in Minibuffer"
3993 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3994 (not vhdl-word-completion-in-minibuffer))
3995 (message "Activate new setting by saving options and restarting Emacs"))
3996 :style toggle :selected vhdl-word-completion-in-minibuffer]
3997 ["Underscore is Part of Word"
3998 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3999 (not vhdl-underscore-is-part-of-word))
4000 (vhdl-activate-customizations))
4001 :style toggle :selected vhdl-underscore-is-part-of-word]
4003 ["Customize Group..." (customize-group 'vhdl-misc) t])
4004 ["Related..." (customize-browse 'vhdl-related) t]
4006 ["Save Options" customize-save-customized t]
4007 ["Activate Options" vhdl-activate-customizations t]
4008 ["Browse Options..." vhdl-customize t])))
4010 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4013 (defun vhdl-update-mode-menu ()
4014 "Update VHDL Mode menu."
4016 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4017 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4018 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4019 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4020 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4022 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4023 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4025 (defconst vhdl-imenu-generic-expression
4028 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4031 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4034 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4037 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4040 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4043 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4046 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4049 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4052 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4055 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4058 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4060 (defun vhdl-index-menu-init ()
4061 "Initialize index menu."
4062 (set (make-local-variable 'imenu-case-fold-search) t)
4063 (set (make-local-variable 'imenu-generic-expression)
4064 vhdl-imenu-generic-expression)
4065 (when (and vhdl-index-menu (fboundp 'imenu))
4066 (if (or (not (boundp 'font-lock-maximum-size))
4067 (> font-lock-maximum-size (buffer-size)))
4068 (imenu-add-to-menubar "Index")
4069 (message "Scanning buffer for index...buffer too big"))))
4071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4072 ;; Source file menu (using `easy-menu.el')
4074 (defvar vhdl-sources-menu nil)
4076 (defun vhdl-directory-files (directory &optional full match)
4077 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4079 (if (not (file-directory-p directory))
4080 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4081 (let ((dir (directory-files directory full match)))
4082 (setq dir (delete "." dir))
4083 (setq dir (delete ".." dir))
4086 (defun vhdl-get-source-files (&optional full directory)
4087 "Get list of VHDL source files in DIRECTORY or current directory."
4088 (let ((mode-alist auto-mode-alist)
4090 ;; create regular expressions for matching file names
4091 (setq filename-regexp "\\`[^.].*\\(")
4093 (when (eq (cdar mode-alist) 'vhdl-mode)
4094 (setq filename-regexp
4095 (concat filename-regexp (caar mode-alist) "\\|")))
4096 (setq mode-alist (cdr mode-alist)))
4097 (setq filename-regexp
4098 (concat (substring filename-regexp 0
4099 (string-match "\\\\|$" filename-regexp)) "\\)"))
4101 (vhdl-directory-files
4102 (or directory default-directory) full filename-regexp)))
4104 (defun vhdl-add-source-files-menu ()
4105 "Scan directory for all VHDL source files and generate menu.
4106 The directory of the current source file is scanned."
4108 (message "Scanning directory for source files ...")
4109 (let ((newmap (current-local-map))
4110 (file-list (vhdl-get-source-files))
4112 ;; Create list for menu
4116 (setq menu-list (cons (vector (car file-list)
4117 (list 'find-file (car file-list)) t)
4119 (setq file-list (cdr file-list)))
4120 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4121 (when found (setq menu-list (cons "--" menu-list)))
4122 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4123 (setq menu-list (cons "Sources" menu-list))
4125 (easy-menu-add menu-list)
4126 (easy-menu-define vhdl-sources-menu newmap
4127 "VHDL source files menu" menu-list))
4131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4134 ;; performs all buffer local initializations
4138 "Major mode for editing VHDL code.
4143 TEMPLATE INSERTION (electrification):
4144 After typing a VHDL keyword and entering `SPC', you are prompted for
4145 arguments while a template is generated for that VHDL construct. Typing
4146 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4147 template generation. Optional arguments are indicated by square
4148 brackets and removed if the queried string is left empty. Prompts for
4149 mandatory arguments remain in the code if the queried string is left
4150 empty. They can be queried again by `C-c C-t C-q'. Enabled
4151 electrification is indicated by `/e' in the modeline.
4153 Typing `M-SPC' after a keyword inserts a space without calling the
4154 template generator. Automatic template generation (i.e.
4155 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4156 setting option `vhdl-electric-mode' (see OPTIONS).
4158 Template generators can be invoked from the VHDL menu, by key
4159 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4160 the keyword (i.e. first word of menu entry not in parenthesis) and
4161 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4162 conf, comp, cons, func, inst, pack, sig, var.
4164 Template styles can be customized in customization group
4165 `vhdl-template' \(see OPTIONS).
4169 A file header can be inserted by `C-c C-t C-h'. A file footer
4170 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4171 See customization group `vhdl-header'.
4175 Double striking of some keys inserts cumbersome VHDL syntax elements.
4176 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4177 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4178 the modeline. The stuttering keys and their effects are:
4180 ;; --> \" : \" [ --> ( -- --> comment
4181 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4182 .. --> \" => \" ] --> ) --- --> horizontal line
4183 ,, --> \" <= \" ]] --> ] ---- --> display comment
4184 == --> \" == \" '' --> \\\"
4188 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4189 word in the buffer that starts alike, inserts it and adjusts case.
4190 Re-typing `TAB' toggles through alternative word completions. This also
4191 works in the minibuffer (i.e. in template generator prompts).
4193 Typing `TAB' after `(' looks for and inserts complete parenthesized
4194 expressions (e.g. for array index ranges). All keywords as well as
4195 standard types and subprograms of VHDL have predefined abbreviations
4196 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4197 beginning with \"std\").
4199 Typing `TAB' after a non-word character indents the line if at the
4200 beginning of a line (i.e. no preceding non-blank characters), and
4201 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4206 `--' puts a single comment.
4207 `---' draws a horizontal line for separating code segments.
4208 `----' inserts a display comment, i.e. two horizontal lines
4209 with a comment in between.
4210 `--CR' comments out code on that line. Re-hitting CR comments
4211 out following lines.
4212 `C-c c' comments out a region if not commented out,
4213 uncomments a region if already commented out.
4215 You are prompted for comments after object definitions (i.e. signals,
4216 variables, constants, ports) and after subprogram and process
4217 specifications if option `vhdl-prompt-for-comments' is non-nil.
4218 Comments are automatically inserted as additional labels (e.g. after
4219 begin statements) and as help comments if `vhdl-self-insert-comments' is
4222 Inline comments (i.e. comments after a piece of code on the same line)
4223 are indented at least to `vhdl-inline-comment-column'. Comments go at
4224 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4225 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4226 in a comment automatically opens a new comment line. `M-q' re-fills
4227 multi-line comments.
4231 `TAB' indents a line if at the beginning of the line. The amount of
4232 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4233 always indents the current line (is bound to `TAB' if option
4234 `vhdl-intelligent-tab' is nil).
4236 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4237 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4238 indented normally (nil) or relative to the opening parenthesis (non-nil)
4239 according to option `vhdl-argument-list-indent'.
4241 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4242 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4245 Syntax-based indentation can be very slow in large files. Option
4246 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4250 The alignment functions align operators, keywords, and inline comments
4251 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4252 separated by blank lines, `C-c C-a C-i' a block of lines with same
4253 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4254 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4255 C-a C-d' all lines within the declarative part of a design unit. `C-c
4256 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4257 for a group of lines, and `C-c C-a M-c' for a region.
4259 If option `vhdl-align-groups' is non-nil, groups of code lines
4260 separated by special lines (see option `vhdl-align-group-separate') are
4261 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4262 blocks of lines with same indent are aligned separately. Some templates
4263 are automatically aligned after generation if option `vhdl-auto-align'
4266 Alignment tries to align inline comments at
4267 `vhdl-inline-comment-column' and tries inline comment not to exceed
4268 `vhdl-end-comment-column'.
4270 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4271 symbols are surrounded by one space, and multiple spaces are eliminated.
4275 Code filling allows to condense code (e.g. sensitivity lists or port
4276 maps) by removing comments and newlines and re-wrapping so that all
4277 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4278 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4279 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4280 `C-c C-f M-f' an entire region.
4283 CODE BEAUTIFICATION:
4284 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4285 buffer respectively. This inludes indentation, alignment, and case
4286 fixing. Code beautification can also be run non-interactively using the
4289 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4293 Generic and port clauses from entity or component declarations can be
4294 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4295 as component instantiations and corresponding internal constants and
4296 signals, as a generic map with constants as actual generics, and as
4297 internal signal initializations (menu).
4299 To include formals in component instantiations, see option
4300 `vhdl-association-list-with-formals'. To include comments in pasting,
4301 see options `vhdl-include-...-comments'.
4303 A clause with several generic/port names on the same line can be
4304 flattened (`C-c C-p C-f') so that only one name per line exists. The
4305 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4306 outputs and vice versa, which can be useful in testbenches. (This
4307 reversion is done on the internal data structure and is only reflected
4308 in subsequent paste operations.)
4310 Names for actual ports, instances, testbenches, and
4311 design-under-test instances can be derived from existing names according
4312 to options `vhdl-...-name'. See customization group `vhdl-port'.
4315 SUBPROGRAM TRANSLATION:
4316 Similar functionality exists for copying/pasting the interface of
4317 subprograms (function/procedure). A subprogram interface can be copied
4318 and then pasted as a subprogram declaration, body or call (uses
4319 association list with formals).
4322 TESTBENCH GENERATION:
4323 A copied port can also be pasted as a testbench. The generated
4324 testbench includes an entity, an architecture, and an optional
4325 configuration. The architecture contains the component declaration and
4326 instantiation of the DUT as well as internal constant and signal
4327 declarations. Additional user-defined templates can be inserted. The
4328 names used for entity/architecture/configuration/DUT as well as the file
4329 structure to be generated can be customized. See customization group
4334 Key bindings (`C-c ...') exist for most commands (see in menu).
4338 All commands can be found in the VHDL menu including their key bindings.
4342 The speedbar allows browsing of directories and file contents. It can
4343 be accessed from the VHDL menu and is automatically opened if option
4344 `vhdl-speedbar-auto-open' is non-nil.
4346 In speedbar, open files and directories with `mouse-2' on the name and
4347 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4350 DESIGN HIERARCHY BROWSER:
4351 The speedbar can also be used for browsing the hierarchy of design units
4352 contained in the source files of the current directory or the specified
4353 projects (see option `vhdl-project-alist').
4355 The speedbar can be switched between file, directory hierarchy and
4356 project hierarchy browsing mode in the speedbar menu or by typing `f',
4357 `h' or `H' in speedbar.
4359 In speedbar, open design units with `mouse-2' on the name and browse
4360 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4361 from entities and components (in packages). Individual design units and
4362 complete designs can directly be compiled (\"Make\" menu entry).
4364 The hierarchy is automatically updated upon saving a modified source
4365 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4366 hierarchy is only updated for projects that have been opened once in the
4367 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4368 options in group `vhdl-speedbar').
4370 Simple design consistency checks are done during scanning, such as
4371 multiple declarations of the same unit or missing primary units that are
4372 required by secondary units.
4375 STRUCTURAL COMPOSITION:
4376 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4377 for a new component. Subcomponents (i.e. component declaration and
4378 instantiation) can be automatically placed from a previously read port
4379 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4380 all subcomponents can be automatically connected using internal signals
4381 and ports (`C-c C-c C-w') following these rules:
4382 - subcomponent actual ports with same name are considered to be
4383 connected by a signal (internal signal or port)
4384 - signals that are only inputs to subcomponents are considered as
4385 inputs to this component -> input port created
4386 - signals that are only outputs from subcomponents are considered as
4387 outputs from this component -> output port created
4388 - signals that are inputs to AND outputs from subcomponents are
4389 considered as internal connections -> internal signal created
4391 Purpose: With appropriate naming conventions it is possible to
4392 create higher design levels with only a few mouse clicks or key
4393 strokes. A new design level can be created by simply generating a new
4394 component, placing the required subcomponents from the hierarchy
4395 browser, and wiring everything automatically.
4397 Note: Automatic wiring only works reliably on templates of new
4398 components and component instantiations that were created by VHDL mode.
4400 Component declarations can be placed in a components package (option
4401 `vhdl-use-components-package') which can be automatically generated for
4402 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4403 component instantiation is also supported (option
4404 `vhdl-use-direct-instantiation').
4406 | Configuration declarations can automatically be generated either from
4407 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4408 | the speedbar menu (for the architecture under the cursor). The
4409 | configurations can optionally be hierarchical (i.e. include all
4410 | component levels of a hierarchical design, option
4411 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4412 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4413 | subcomponents in hierarchical configurations, the most-recently-analyzed
4414 | (mra) architecture is selected. If another architecture is desired, it
4415 | can be marked as most-recently-analyzed (speedbar menu) before
4416 | generating the configuration.
4418 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4419 | declarations) are currently not considered when displaying
4420 | configurations in speedbar.
4422 See the options group `vhdl-compose' for all relevant user options.
4425 SOURCE FILE COMPILATION:
4426 The syntax of the current buffer can be analyzed by calling a VHDL
4427 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4428 option `vhdl-compiler'. The available compilers are listed in option
4429 `vhdl-compiler-alist' including all required compilation command,
4430 command options, compilation directory, and error message syntax
4431 information. New compilers can be added.
4433 All the source files of an entire design can be compiled by the `make'
4434 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4437 MAKEFILE GENERATION:
4438 Makefiles can be generated automatically by an internal generation
4439 routine (`C-c M-k'). The library unit dependency information is
4440 obtained from the hierarchy browser. Makefile generation can be
4441 customized for each compiler in option `vhdl-compiler-alist'.
4443 Makefile generation can also be run non-interactively using the
4446 emacs -batch -l ~/.emacs -l vhdl-mode
4447 [-compiler compilername] [-project projectname]
4448 -f vhdl-generate-makefile
4450 The Makefile's default target \"all\" compiles the entire design, the
4451 target \"clean\" removes it and the target \"library\" creates the
4452 library directory if not existent. The Makefile also includes a target
4453 for each primary library unit which allows selective compilation of this
4454 unit, its secondary units and its subhierarchy (example: compilation of
4455 a design specified by a configuration). User specific parts can be
4456 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4459 - Only library units and dependencies within the current library are
4460 considered. Makefiles for designs that span multiple libraries are
4461 not (yet) supported.
4462 - Only one-level configurations are supported (also hierarchical),
4463 but configurations that go down several levels are not.
4464 - The \"others\" keyword in configurations is not supported.
4468 Projects can be defined in option `vhdl-project-alist' and a current
4469 project be selected using option `vhdl-project' (permanently) or from
4470 the menu or speedbar (temporarily). For each project, title and
4471 description strings (for the file headers), source files/directories
4472 (for the hierarchy browser and Makefile generation), library name, and
4473 compiler-dependent options, exceptions and compilation directory can be
4474 specified. Compilation settings overwrite the settings of option
4475 `vhdl-compiler-alist'.
4477 Project setups can be exported (i.e. written to a file) and imported.
4478 Imported setups are not automatically saved in `vhdl-project-alist' but
4479 can be saved afterwards in its customization buffer. When starting
4480 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4481 vhdl-mode\") in a directory with an existing project setup file, it is
4482 automatically loaded and its project activated if option
4483 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4484 files can be specified in option `vhdl-project-file-name'. Multiple
4485 project setups can be automatically loaded from global directories.
4486 This is an alternative to specifying project setups with option
4487 `vhdl-project-alist'.
4491 As an alternative to the speedbar, an index menu can be added (set
4492 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4493 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4494 file) for browsing the file contents (is not populated if buffer is
4495 larger than `font-lock-maximum-size'). Also, a source file menu can be
4496 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4497 current directory for VHDL source files.
4501 The VHDL standards to be used are specified in option `vhdl-standard'.
4502 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4506 Lower and upper case for keywords and standardized types, attributes,
4507 and enumeration values is supported. If the option
4508 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4509 lower case and are converted into upper case automatically (not for
4510 types, attributes, and enumeration values). The case of keywords,
4511 types, attributes,and enumeration values can be fixed for an entire
4512 region (menu) or buffer (`C-c C-x C-c') according to the options
4513 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4516 HIGHLIGHTING (fontification):
4517 Keywords and standardized types, attributes, enumeration values, and
4518 function names (controlled by option `vhdl-highlight-keywords'), as well
4519 as comments, strings, and template prompts are highlighted using
4520 different colors. Unit, subprogram, signal, variable, constant,
4521 parameter and generic/port names in declarations as well as labels are
4522 highlighted if option `vhdl-highlight-names' is non-nil.
4524 Additional reserved words or words with a forbidden syntax (e.g. words
4525 that should be avoided) can be specified in option
4526 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4527 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4528 keywords are highlighted as forbidden words if option
4529 `vhdl-highlight-verilog-keywords' is non-nil.
4531 Words with special syntax can be highlighted by specifying their
4532 syntax and color in option `vhdl-special-syntax-alist' and by setting
4533 option `vhdl-highlight-special-words' to non-nil. This allows to
4534 establish some naming conventions (e.g. to distinguish different kinds
4535 of signals or other objects by using name suffices) and to support them
4538 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4539 to support case-sensitive highlighting. However, keywords are then only
4540 highlighted if written in lower case.
4542 Code between \"translate_off\" and \"translate_on\" pragmas is
4543 highlighted using a different background color if option
4544 `vhdl-highlight-translate-off' is non-nil.
4546 For documentation and customization of the used colors see
4547 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4548 highlighting of matching parenthesis, see customization group
4549 `paren-showing'. Automatic buffer highlighting is turned on/off by
4550 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4554 VHDL models (templates) can be specified by the user and made accessible
4555 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4556 electrification. See option `vhdl-model-alist'.
4560 The code of blocks, processes, subprograms, component declarations and
4561 instantiations, generic/port clauses, and configuration declarations can
4562 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4563 the code (see customization group `vhdl-menu'). XEmacs: limited
4564 functionality due to old `hideshow.el' package.
4568 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4569 current process, `C-c C-u M-s' of all processes in the current buffer.
4571 - Only declared local signals (ports, signals declared in
4572 architecture and blocks) are automatically inserted.
4573 - Global signals declared in packages are not automatically inserted.
4574 Insert them once manually (will be kept afterwards).
4575 - Out parameters of procedures are considered to be read.
4576 Use option `vhdl-entity-file-name' to specify the entity file name
4577 \(used to obtain the port names).
4581 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4582 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4586 Postscript printing with different faces (an optimized set of faces is
4587 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4588 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4589 postscript printing commands. Option `vhdl-print-two-column' defines
4590 appropriate default settings for nice landscape two-column printing.
4591 The paper format can be set by option `ps-paper-type'. Do not forget to
4592 switch `ps-print-color-p' to nil for printing on black-and-white
4597 User options allow customization of VHDL Mode. All options are
4598 accessible from the \"Options\" menu entry. Simple options (switches
4599 and choices) can directly be changed, while for complex options a
4600 customization buffer is opened. Changed options can be saved for future
4601 sessions using the \"Save Options\" menu entry.
4603 Options and their detailed descriptions can also be accessed by using
4604 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4605 customize-group' for groups). Some customizations only take effect
4606 after some action (read the NOTE in the option documentation).
4607 Customization can also be done globally (i.e. site-wide, read the
4610 Not all options are described in this documentation, so go and see
4611 what other useful user options there are (`M-x vhdl-customize' or menu)!
4615 As default, files with extensions \".vhd\" and \".vhdl\" are
4616 automatically recognized as VHDL source files. To add an extension
4617 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4619 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4623 - To start Emacs with open VHDL hierarchy browser without having to load
4624 a VHDL file first, use the command:
4626 emacs -l vhdl-mode -f speedbar-frame-mode
4628 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4630 - Some features only work on properly indented code.
4634 See also the release notes (menu) for added features in new releases.
4640 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4641 Add a description of the problem and include a reproducible test case.
4643 Questions and enhancement requests can be sent to <reto@gnu.org>.
4645 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4646 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4647 releases. You are kindly invited to participate in beta testing. Subscribe
4648 to above mailing lists by sending an email to <reto@gnu.org>.
4650 VHDL Mode is officially distributed at
4651 http://opensource.ethz.ch/emacs/vhdl-mode.html
4652 where the latest version can be found.
4658 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4659 - XEmacs: Incorrect start-up when automatically opening speedbar.
4660 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4663 The VHDL Mode Authors
4664 Reto Zimmermann and Rod Whitby
4671 (kill-all-local-variables)
4672 (setq major-mode 'vhdl-mode)
4673 (setq mode-name "VHDL")
4675 ;; set maps and tables
4676 (use-local-map vhdl-mode-map)
4677 (set-syntax-table vhdl-mode-syntax-table)
4678 (setq local-abbrev-table vhdl-mode-abbrev-table)
4680 ;; set local variables
4681 (set (make-local-variable 'paragraph-start)
4682 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4683 (set (make-local-variable 'paragraph-separate) paragraph-start)
4684 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4685 (set (make-local-variable 'require-final-newline)
4686 (if vhdl-emacs-22 mode-require-final-newline t))
4687 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4688 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4689 (set (make-local-variable 'comment-start) "--")
4690 (set (make-local-variable 'comment-end) "")
4692 (set (make-local-variable 'comment-padding) ""))
4693 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4694 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4695 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4696 (set (make-local-variable 'comment-multi-line) nil)
4697 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4698 (set (make-local-variable 'hippie-expand-verbose) nil)
4700 ;; setup the comment indent variable in a Emacs version portable way
4701 ;; ignore any byte compiler warnings you might get here
4702 (when (boundp 'comment-indent-function)
4703 (make-local-variable 'comment-indent-function)
4704 (setq comment-indent-function 'vhdl-comment-indent))
4706 ;; initialize font locking
4707 (set (make-local-variable 'font-lock-defaults)
4709 '(nil vhdl-font-lock-keywords) nil
4710 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4711 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4712 (unless vhdl-emacs-21
4713 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4714 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4715 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4716 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4717 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4718 ; (turn-on-font-lock)
4720 ;; variables for source file compilation
4721 (when vhdl-compile-use-local-error-regexp
4722 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4723 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4726 (vhdl-index-menu-init)
4727 ;; add source file menu
4728 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4730 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4731 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4732 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4733 ;; initialize hideshow and add menu
4734 (vhdl-hideshow-init)
4735 (run-hooks 'menu-bar-update-hook)
4738 (vhdl-ps-print-init)
4739 (vhdl-write-file-hooks-init)
4740 (vhdl-mode-line-update)
4741 (message "VHDL Mode %s.%s" vhdl-version
4742 (if noninteractive "" " See menu for documentation and release notes."))
4746 (run-mode-hooks 'vhdl-mode-hook)
4747 (run-hooks 'vhdl-mode-hook)))
4749 (defun vhdl-activate-customizations ()
4750 "Activate all customizations on local variables."
4752 (vhdl-mode-map-init)
4753 (use-local-map vhdl-mode-map)
4754 (set-syntax-table vhdl-mode-syntax-table)
4755 (setq comment-column vhdl-inline-comment-column)
4756 (setq end-comment-column vhdl-end-comment-column)
4757 (vhdl-write-file-hooks-init)
4758 (vhdl-update-mode-menu)
4759 (vhdl-hideshow-init)
4760 (run-hooks 'menu-bar-update-hook)
4761 (vhdl-mode-line-update))
4763 (defun vhdl-write-file-hooks-init ()
4764 "Add/remove hooks when buffer is saved."
4765 (if vhdl-modify-date-on-saving
4766 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4767 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4768 (make-local-variable 'after-save-hook)
4769 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4771 (defun vhdl-process-command-line-option (option)
4772 "Process command line options for VHDL Mode."
4775 ((equal option "-compiler")
4776 (vhdl-set-compiler (car command-line-args-left))
4777 (setq command-line-args-left (cdr command-line-args-left)))
4779 ((equal option "-project")
4780 (vhdl-set-project (car command-line-args-left))
4781 (setq command-line-args-left (cdr command-line-args-left)))))
4783 ;; make Emacs process VHDL Mode options
4784 (setq command-switch-alist
4785 (append command-switch-alist
4786 '(("-compiler" . vhdl-process-command-line-option)
4787 ("-project" . vhdl-process-command-line-option))))
4790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4791 ;;; Keywords and standardized words
4792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4794 (defconst vhdl-93-keywords
4796 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4797 "assert" "attribute"
4798 "begin" "block" "body" "buffer" "bus"
4799 "case" "component" "configuration" "constant"
4800 "disconnect" "downto"
4801 "else" "elsif" "end" "entity" "exit"
4802 "file" "for" "function"
4803 "generate" "generic" "group" "guarded"
4804 "if" "impure" "in" "inertial" "inout" "is"
4805 "label" "library" "linkage" "literal" "loop"
4807 "nand" "new" "next" "nor" "not" "null"
4808 "of" "on" "open" "or" "others" "out"
4809 "package" "port" "postponed" "procedure" "process" "pure"
4810 "range" "record" "register" "reject" "rem" "report" "return"
4812 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4813 "then" "to" "transport" "type"
4814 "unaffected" "units" "until" "use"
4816 "wait" "when" "while" "with"
4819 "List of VHDL'93 keywords.")
4821 (defconst vhdl-ams-keywords
4823 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4824 "reference" "spectrum" "subnature" "terminal" "through"
4827 "List of VHDL-AMS keywords.")
4829 (defconst vhdl-verilog-keywords
4831 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4832 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4833 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4834 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4835 "endprimitive" "endspecify" "endtable" "endtask" "event"
4836 "for" "force" "forever" "fork" "function"
4837 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4838 "macromodule" "makefile" "medium" "module"
4839 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4840 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4842 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4843 "rtranif0" "rtranif1"
4844 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4845 "strong1" "supply" "supply0" "supply1"
4846 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4847 "triand" "trior" "trireg"
4848 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4850 "List of Verilog keywords as candidate for additional reserved words.")
4852 (defconst vhdl-93-types
4854 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4855 "real" "time" "natural" "positive" "string" "line" "text" "side"
4856 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4857 "std_logic" "std_logic_vector"
4858 "std_ulogic" "std_ulogic_vector"
4860 "List of VHDL'93 standardized types.")
4862 (defconst vhdl-ams-types
4864 "domain_type" "real_vector"
4865 ;; from `nature_pkg' package
4866 "voltage" "current" "electrical" "position" "velocity" "force"
4867 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4868 "pressure" "flowrate" "fluid"
4870 "List of VHDL-AMS standardized types.")
4872 (defconst vhdl-math-types
4874 "complex" "complex_polar"
4876 "List of Math Packages standardized types.")
4878 (defconst vhdl-93-attributes
4880 "base" "left" "right" "high" "low" "pos" "val" "succ"
4881 "pred" "leftof" "rightof" "range" "reverse_range"
4882 "length" "delayed" "stable" "quiet" "transaction"
4883 "event" "active" "last_event" "last_active" "last_value"
4884 "driving" "driving_value" "ascending" "value" "image"
4885 "simple_name" "instance_name" "path_name"
4888 "List of VHDL'93 standardized attributes.")
4890 (defconst vhdl-ams-attributes
4893 "reference" "contribution" "tolerance"
4894 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4897 "List of VHDL-AMS standardized attributes.")
4899 (defconst vhdl-93-enum-values
4902 "note" "warning" "error" "failure"
4903 "read_mode" "write_mode" "append_mode"
4904 "open_ok" "status_error" "name_error" "mode_error"
4905 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4908 "List of VHDL'93 standardized enumeration values.")
4910 (defconst vhdl-ams-enum-values
4912 "quiescent_domain" "time_domain" "frequency_domain"
4913 ;; from `nature_pkg' package
4914 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4916 "List of VHDL-AMS standardized enumeration values.")
4918 (defconst vhdl-math-constants
4920 "math_e" "math_1_over_e"
4921 "math_pi" "math_two_pi" "math_1_over_pi"
4922 "math_half_pi" "math_q_pi" "math_3_half_pi"
4923 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4924 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4925 "math_deg_to_rad" "math_rad_to_deg"
4926 "cbase_1" "cbase_j" "czero"
4928 "List of Math Packages standardized constants.")
4930 (defconst vhdl-93-functions
4932 "now" "resolved" "rising_edge" "falling_edge"
4933 "read" "readline" "write" "writeline" "endfile"
4934 "resize" "is_X" "std_match"
4935 "shift_left" "shift_right" "rotate_left" "rotate_right"
4936 "to_unsigned" "to_signed" "to_integer"
4937 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4938 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4939 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4940 "shl" "shr" "ext" "sxt"
4943 "List of VHDL'93 standardized functions.")
4945 (defconst vhdl-ams-functions
4949 "List of VHDL-AMS standardized functions.")
4951 (defconst vhdl-math-functions
4953 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4954 "sqrt" "cbrt" "exp" "log"
4955 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4956 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4957 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4959 "List of Math Packages standardized functions.")
4961 (defconst vhdl-93-packages
4963 "std_logic_1164" "numeric_std" "numeric_bit"
4965 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4966 "std_logic_misc" "std_logic_textio"
4969 "List of VHDL'93 standardized packages and libraries.")
4971 (defconst vhdl-ams-packages
4973 ;; from `nature_pkg' package
4976 "List of VHDL-AMS standardized packages and libraries.")
4978 (defconst vhdl-math-packages
4980 "math_real" "math_complex"
4982 "List of Math Packages standardized packages and libraries.")
4984 (defvar vhdl-keywords nil
4985 "List of VHDL keywords.")
4987 (defvar vhdl-types nil
4988 "List of VHDL standardized types.")
4990 (defvar vhdl-attributes nil
4991 "List of VHDL standardized attributes.")
4993 (defvar vhdl-enum-values nil
4994 "List of VHDL standardized enumeration values.")
4996 (defvar vhdl-constants nil
4997 "List of VHDL standardized constants.")
4999 (defvar vhdl-functions nil
5000 "List of VHDL standardized functions.")
5002 (defvar vhdl-packages nil
5003 "List of VHDL standardized packages and libraries.")
5005 (defvar vhdl-reserved-words nil
5006 "List of additional reserved words.")
5008 (defvar vhdl-keywords-regexp nil
5009 "Regexp for VHDL keywords.")
5011 (defvar vhdl-types-regexp nil
5012 "Regexp for VHDL standardized types.")
5014 (defvar vhdl-attributes-regexp nil
5015 "Regexp for VHDL standardized attributes.")
5017 (defvar vhdl-enum-values-regexp nil
5018 "Regexp for VHDL standardized enumeration values.")
5020 (defvar vhdl-functions-regexp nil
5021 "Regexp for VHDL standardized functions.")
5023 (defvar vhdl-packages-regexp nil
5024 "Regexp for VHDL standardized packages and libraries.")
5026 (defvar vhdl-reserved-words-regexp nil
5027 "Regexp for additional reserved words.")
5029 (defvar vhdl-directive-keywords-regexp nil
5030 "Regexp for compiler directive keywords.")
5032 (defun vhdl-words-init ()
5033 "Initialize reserved words."
5035 (append vhdl-93-keywords
5036 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5038 (append vhdl-93-types
5039 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5040 (when (vhdl-standard-p 'math) vhdl-math-types)))
5041 (setq vhdl-attributes
5042 (append vhdl-93-attributes
5043 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5044 (setq vhdl-enum-values
5045 (append vhdl-93-enum-values
5046 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5047 (setq vhdl-constants
5048 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5049 (setq vhdl-functions
5050 (append vhdl-93-functions
5051 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5052 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5054 (append vhdl-93-packages
5055 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5056 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5057 (setq vhdl-reserved-words
5058 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5059 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5061 (setq vhdl-keywords-regexp
5062 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5063 (setq vhdl-types-regexp
5064 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5065 (setq vhdl-attributes-regexp
5066 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5067 (setq vhdl-enum-values-regexp
5068 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5069 (setq vhdl-functions-regexp
5070 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5071 (setq vhdl-packages-regexp
5072 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5073 (setq vhdl-reserved-words-regexp
5075 (unless (equal vhdl-forbidden-syntax "")
5076 (concat vhdl-forbidden-syntax "\\|"))
5077 (regexp-opt vhdl-reserved-words)
5079 (setq vhdl-directive-keywords-regexp
5080 (concat "\\<\\(" (mapconcat 'regexp-quote
5081 vhdl-directive-keywords "\\|") "\\)\\>"))
5082 (vhdl-abbrev-list-init))
5084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5087 (defvar vhdl-abbrev-list nil
5088 "Predefined abbreviations for VHDL.")
5090 (defun vhdl-abbrev-list-init ()
5091 (setq vhdl-abbrev-list
5093 (list vhdl-upper-case-keywords) vhdl-keywords
5094 (list vhdl-upper-case-types) vhdl-types
5095 (list vhdl-upper-case-attributes) vhdl-attributes
5096 (list vhdl-upper-case-enum-values) vhdl-enum-values
5097 (list vhdl-upper-case-constants) vhdl-constants
5098 (list nil) vhdl-functions
5099 (list nil) vhdl-packages)))
5101 ;; initialize reserved words for VHDL Mode
5105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5112 ;; constant regular expressions for looking at various constructs
5114 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5115 "Regexp describing a VHDL symbol.
5116 We cannot use just `word' syntax class since `_' cannot be in word
5117 class. Putting underscore in word class breaks forward word movement
5118 behavior that users are familiar with.")
5120 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5121 "Regexp describing a case statement header key.")
5123 (defconst vhdl-label-key
5124 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5125 "Regexp describing a VHDL label.")
5127 ;; Macro definitions:
5129 (defmacro vhdl-point (position)
5130 "Return the value of point at certain commonly referenced POSITIONs.
5131 POSITION can be one of the following symbols:
5133 bol -- beginning of line
5135 bod -- beginning of defun
5136 boi -- back to indentation
5137 eoi -- last whitespace on line
5138 ionl -- indentation of next line
5139 iopl -- indentation of previous line
5140 bonl -- beginning of next line
5141 bopl -- beginning of previous line
5143 This function does not modify point or mark."
5144 (or (and (eq 'quote (car-safe position))
5145 (null (cddr position)))
5146 (error "ERROR: Bad buffer position requested: %s" position))
5147 (setq position (nth 1 position))
5148 `(let ((here (point)))
5150 ((eq position 'bol) '((beginning-of-line)))
5151 ((eq position 'eol) '((end-of-line)))
5152 ((eq position 'bod) '((save-match-data
5153 (vhdl-beginning-of-defun))))
5154 ((eq position 'boi) '((back-to-indentation)))
5155 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5156 ((eq position 'bonl) '((forward-line 1)))
5157 ((eq position 'bopl) '((forward-line -1)))
5158 ((eq position 'iopl)
5160 (back-to-indentation)))
5161 ((eq position 'ionl)
5163 (back-to-indentation)))
5164 (t (error "ERROR: Unknown buffer position requested: %s" position))
5169 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5170 ;; doesn't hurt for v19
5174 (defmacro vhdl-safe (&rest body)
5175 "Safely execute BODY, return nil if an error occurred."
5176 `(condition-case nil
5180 (defmacro vhdl-add-syntax (symbol &optional relpos)
5181 "A simple macro to append the syntax in SYMBOL to the syntax list.
5182 Try to increase performance by using this macro."
5183 `(setq vhdl-syntactic-context
5184 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5186 (defmacro vhdl-has-syntax (symbol)
5187 "A simple macro to return check the syntax list.
5188 Try to increase performance by using this macro."
5189 `(assoc ,symbol vhdl-syntactic-context))
5191 ;; Syntactic element offset manipulation:
5193 (defun vhdl-read-offset (langelem)
5194 "Read new offset value for LANGELEM from minibuffer.
5195 Return a valid value only."
5196 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5197 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5199 offset input interned)
5201 (setq input (read-string prompt oldoff)
5202 offset (cond ((string-equal "+" input) '+)
5203 ((string-equal "-" input) '-)
5204 ((string-equal "++" input) '++)
5205 ((string-equal "--" input) '--)
5206 ((string-match "^-?[0-9]+$" input)
5207 (string-to-number input))
5208 ((fboundp (setq interned (intern input)))
5210 ((boundp interned) interned)
5211 ;; error, but don't signal one, keep trying
5212 ;; to read an input value
5214 (setq prompt errmsg)
5218 (defun vhdl-set-offset (symbol offset &optional add-p)
5219 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5220 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5221 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5222 `vhdl-offsets-alist' if it doesn't already appear there."
5225 (intern (completing-read
5226 (concat "Syntactic symbol to change"
5227 (if current-prefix-arg " or add" "")
5232 (cons (format "%s" (car langelem)) nil)))
5234 nil (not current-prefix-arg)
5235 ;; initial contents tries to be the last element
5236 ;; on the syntactic analysis list for the current
5238 (let* ((syntax (vhdl-get-syntactic-context))
5239 (len (length syntax))
5240 (ic (format "%s" (car (nth (1- len) syntax)))))
5243 (offset (vhdl-read-offset langelem)))
5244 (list langelem offset current-prefix-arg)))
5245 ;; sanity check offset
5253 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5255 (let ((entry (assq symbol vhdl-offsets-alist)))
5257 (setcdr entry offset)
5259 (setq vhdl-offsets-alist
5260 (cons (cons symbol offset) vhdl-offsets-alist))
5261 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5262 (vhdl-keep-region-active))
5264 (defun vhdl-set-style (style &optional local)
5265 "Set `vhdl-mode' variables to use one of several different indentation styles.
5266 STYLE is a string representing the desired style and optional LOCAL is
5267 a flag which, if non-nil, means to make the style variables being
5268 changed buffer local, instead of the default, which is to set the
5269 global variables. Interactively, the flag comes from the prefix
5270 argument. The styles are chosen from the `vhdl-style-alist' variable."
5271 (interactive (list (completing-read "Use which VHDL indentation style? "
5272 vhdl-style-alist nil t)
5273 current-prefix-arg))
5274 (let ((vars (cdr (assoc style vhdl-style-alist))))
5276 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5277 ;; set all the variables
5281 (let ((var (car varentry))
5282 (val (cdr varentry)))
5284 (make-local-variable var))
5285 ;; special case for vhdl-offsets-alist
5286 (if (not (eq var 'vhdl-offsets-alist))
5288 ;; reset vhdl-offsets-alist to the default value first
5289 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5290 ;; now set the langelems that are different
5294 (let ((langelem (car langentry))
5295 (offset (cdr langentry)))
5296 (vhdl-set-offset langelem offset)
5301 (vhdl-keep-region-active))
5303 (defun vhdl-get-offset (langelem)
5304 "Get offset from LANGELEM which is a cons cell of the form:
5305 \(SYMBOL . RELPOS). The symbol is matched against
5306 vhdl-offsets-alist and the offset found there is either returned,
5307 or added to the indentation at RELPOS. If RELPOS is nil, then
5308 the offset is simply returned."
5309 (let* ((symbol (car langelem))
5310 (relpos (cdr langelem))
5311 (match (assq symbol vhdl-offsets-alist))
5312 (offset (cdr-safe match)))
5313 ;; offset can be a number, a function, a variable, or one of the
5317 (if vhdl-strict-syntax-p
5318 (error "ERROR: Don't know how to indent a %s" symbol)
5321 ((eq offset '+) (setq offset vhdl-basic-offset))
5322 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5323 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5324 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5325 ((and (not (numberp offset))
5327 (setq offset (funcall offset langelem)))
5328 ((not (numberp offset))
5329 (setq offset (eval offset)))
5332 (< relpos (vhdl-point 'bol)))
5339 ;; Syntactic support functions:
5341 (defun vhdl-in-comment-p ()
5342 "Check if point is in a comment."
5343 (eq (vhdl-in-literal) 'comment))
5345 (defun vhdl-in-string-p ()
5346 "Check if point is in a string."
5347 (eq (vhdl-in-literal) 'string))
5349 (defun vhdl-in-literal ()
5350 "Determine if point is in a VHDL literal."
5352 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5354 ((nth 3 state) 'string)
5355 ((nth 4 state) 'comment)
5356 ((vhdl-beginning-of-macro) 'pound)
5359 (defun vhdl-forward-comment (&optional direction)
5360 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5361 negative, skip forward otherwise."
5363 (if (and direction (< direction 0))
5366 (skip-chars-backward " \t\n")
5367 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5368 (goto-char (match-beginning 3))
5369 (skip-chars-backward " \t\n")))
5371 (skip-chars-forward " \t\n")
5372 (while (looking-at "--.*")
5373 (goto-char (match-end 0))
5374 (skip-chars-forward " \t\n"))))
5376 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5377 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5378 (defalias 'vhdl-forward-comment 'forward-comment))
5380 ;; This is the best we can do in Win-Emacs.
5381 (defun vhdl-win-il (&optional lim)
5382 "Determine if point is in a VHDL literal."
5384 (let* ((here (point))
5387 (lim (or lim (vhdl-point 'bod))))
5389 (while (< (point) here)
5391 (and (re-search-forward "--\\|[\"']"
5393 (buffer-substring (match-beginning 0) (match-end 0))))
5398 ;; looking at the opening of a VHDL style comment
5399 ((string= "--" match)
5400 (if (<= here (progn (end-of-line) (point))) 'comment))
5401 ;; looking at the opening of a double quote string
5402 ((string= "\"" match)
5403 (if (not (save-restriction
5404 ;; this seems to be necessary since the
5405 ;; re-search-forward will not work without it
5406 (narrow-to-region (point) here)
5408 ;; this regexp matches a double quote
5409 ;; which is preceded by an even number
5410 ;; of backslashes, including zero
5411 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5413 ;; looking at the opening of a single quote string
5414 ((string= "'" match)
5415 (if (not (save-restriction
5416 ;; see comments from above
5417 (narrow-to-region (point) here)
5419 ;; this matches a single quote which is
5420 ;; preceded by zero or two backslashes.
5421 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5428 (and (string-match "Win-Emacs" emacs-version)
5429 (fset 'vhdl-in-literal 'vhdl-win-il))
5431 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5432 ;; defined as lexical whitespace or comments. Search no farther back
5433 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5434 ;; used for backward skipping, (point-max) is used for forward
5437 (defun vhdl-forward-syntactic-ws (&optional lim)
5438 "Forward skip of syntactic whitespace."
5439 (let* ((here (point-max))
5440 (hugenum (point-max)))
5441 (while (/= here (point))
5443 (vhdl-forward-comment hugenum)
5444 ;; skip preprocessor directives
5445 (when (and (eq (char-after) ?#)
5446 (= (vhdl-point 'boi) (point)))
5447 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5448 (= (forward-line 1) 0)))
5450 (if lim (goto-char (min (point) lim)))))
5453 ;; This is the best we can do in Win-Emacs.
5454 (defun vhdl-win-fsws (&optional lim)
5455 "Forward skip syntactic whitespace for Win-Emacs."
5456 (let ((lim (or lim (point-max)))
5459 (skip-chars-forward " \t\n\r\f" lim)
5462 ((looking-at "--") (end-of-line))
5463 ;; none of the above
5464 (t (setq stop t))))))
5466 (and (string-match "Win-Emacs" emacs-version)
5467 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5469 (defun vhdl-beginning-of-macro (&optional lim)
5470 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5471 (let ((here (point)))
5473 (while (eq (char-before (1- (point))) ?\\)
5475 (back-to-indentation)
5476 (if (and (<= (point) here)
5477 (eq (char-after) ?#))
5482 (defun vhdl-backward-syntactic-ws (&optional lim)
5483 "Backward skip over syntactic whitespace."
5484 (let* ((here (point-min))
5485 (hugenum (- (point-max))))
5486 (while (/= here (point))
5488 (vhdl-forward-comment hugenum)
5489 (vhdl-beginning-of-macro))
5490 (if lim (goto-char (max (point) lim)))))
5492 ;; This is the best we can do in Win-Emacs.
5493 (defun vhdl-win-bsws (&optional lim)
5494 "Backward skip syntactic whitespace for Win-Emacs."
5495 (let ((lim (or lim (vhdl-point 'bod)))
5498 (skip-chars-backward " \t\n\r\f" lim)
5501 ((eq (vhdl-in-literal) 'comment)
5502 (skip-chars-backward "^-" lim)
5503 (skip-chars-backward "-" lim)
5504 (while (not (or (and (= (following-char) ?-)
5505 (= (char-after (1+ (point))) ?-))
5507 (skip-chars-backward "^-" lim)
5508 (skip-chars-backward "-" lim)))
5509 ;; none of the above
5510 (t (setq stop t))))))
5512 (and (string-match "Win-Emacs" emacs-version)
5513 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5515 ;; Functions to help finding the correct indentation column:
5517 (defun vhdl-first-word (point)
5518 "If the keyword at POINT is at boi, then return (current-column) at
5519 that point, else nil."
5521 (and (goto-char point)
5522 (eq (point) (vhdl-point 'boi))
5525 (defun vhdl-last-word (point)
5526 "If the keyword at POINT is at eoi, then return (current-column) at
5527 that point, else nil."
5529 (and (goto-char point)
5530 (save-excursion (or (eq (progn (forward-sexp) (point))
5532 (looking-at "\\s-*\\(--\\)?")))
5535 ;; Core syntactic evaluation functions:
5537 (defconst vhdl-libunit-re
5538 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5540 (defun vhdl-libunit-p ()
5544 (skip-chars-forward " \t\n")
5545 (not (looking-at "is\\b[^_]")))
5548 (and (not (looking-at "use\\b[^_]"))
5551 (vhdl-forward-syntactic-ws)
5552 (/= (following-char) ?:))))
5555 (defconst vhdl-defun-re
5556 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5558 (defun vhdl-defun-p ()
5560 (if (looking-at "block\\|process\\|procedural")
5561 ;; "block", "process", "procedural":
5564 (not (looking-at "end\\s-+\\w")))
5565 ;; "architecture", "configuration", "entity",
5566 ;; "package", "procedure", "function":
5569 (defun vhdl-corresponding-defun ()
5570 "If the word at the current position corresponds to a \"defun\"
5571 keyword, then return a string that can be used to find the
5572 corresponding \"begin\" keyword, else return nil."
5574 (and (looking-at vhdl-defun-re)
5576 (if (looking-at "block\\|process\\|procedural")
5577 ;; "block", "process". "procedural:
5578 (buffer-substring (match-beginning 0) (match-end 0))
5579 ;; "architecture", "configuration", "entity", "package",
5580 ;; "procedure", "function":
5583 (defconst vhdl-begin-fwd-re
5584 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5585 "A regular expression for searching forward that matches all known
5586 \"begin\" keywords.")
5588 (defconst vhdl-begin-bwd-re
5589 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5590 "A regular expression for searching backward that matches all known
5591 \"begin\" keywords.")
5593 (defun vhdl-begin-p (&optional lim)
5594 "Return t if we are looking at a real \"begin\" keyword.
5595 Assumes that the caller will make sure that we are looking at
5596 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5597 the middle of an identifier that just happens to contain a \"begin\"
5600 ;; "[architecture|case|configuration|entity|package|
5601 ;; procedure|function] ... is":
5602 ((and (looking-at "i")
5604 ;; Skip backward over first sexp (needed to skip over a
5605 ;; procedure interface list, and is harmless in other
5606 ;; situations). Note that we need "return" in the
5607 ;; following search list so that we don't run into
5608 ;; semicolons in the function interface list.
5611 (while (and (not foundp)
5613 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5615 (if (or (= (preceding-char) ?_)
5619 (and (/= (following-char) ?\;)
5620 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5623 ((looking-at "be\\|t")
5626 ((and (looking-at "e")
5627 ;; make sure that the "else" isn't inside a
5628 ;; conditional signal assignment.
5630 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5631 (or (eq (following-char) ?\;)
5634 ;; "block", "generate", "loop", "process", "procedural",
5635 ;; "units", "record":
5636 ((and (looking-at "bl\\|[glpur]")
5639 (not (looking-at "end\\s-+\\w"))))
5642 ((and (looking-at "c")
5645 (not (looking-at "end\\s-+\\w")))
5646 ;; look out for the dreaded entity class in an attribute
5648 (vhdl-backward-syntactic-ws lim)
5649 (/= (preceding-char) ?:)))
5651 ;; "for" (inside configuration declaration):
5652 ((and (looking-at "f")
5655 (not (looking-at "end\\s-+\\w")))
5656 (vhdl-has-syntax 'configuration))
5660 (defun vhdl-corresponding-mid (&optional lim)
5662 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5664 ((looking-at "then")
5669 (defun vhdl-corresponding-end (&optional lim)
5670 "If the word at the current position corresponds to a \"begin\"
5671 keyword, then return a vector containing enough information to find
5672 the corresponding \"end\" keyword, else return nil. The keyword to
5673 search forward for is aref 0. The column in which the keyword must
5674 appear is aref 1 or nil if any column is suitable.
5675 Assumes that the caller will make sure that we are not in the middle
5676 of an identifier that just happens to contain a \"begin\" keyword."
5678 (and (looking-at vhdl-begin-fwd-re)
5679 (/= (preceding-char) ?_)
5680 (not (vhdl-in-literal))
5683 ;; "is", "generate", "loop":
5684 ((looking-at "[igl]")
5686 (and (vhdl-last-word (point))
5687 (or (vhdl-first-word (point))
5689 (vhdl-beginning-of-statement-1 lim)
5690 (vhdl-backward-skip-label lim)
5691 (vhdl-first-word (point)))))))
5692 ;; "begin", "else", "for":
5693 ((looking-at "be\\|[ef]")
5695 (and (vhdl-last-word (point))
5696 (or (vhdl-first-word (point))
5698 (vhdl-beginning-of-statement-1 lim)
5699 (vhdl-backward-skip-label lim)
5700 (vhdl-first-word (point)))))))
5701 ;; "component", "units", "record":
5702 ((looking-at "[cur]")
5703 ;; The first end found will close the block
5705 ;; "block", "process", "procedural":
5706 ((looking-at "bl\\|p")
5708 (or (vhdl-first-word (point))
5710 (vhdl-beginning-of-statement-1 lim)
5711 (vhdl-backward-skip-label lim)
5712 (vhdl-first-word (point))))))
5715 (vector "elsif\\|else\\|end\\s-+if"
5716 (and (vhdl-last-word (point))
5717 (or (vhdl-first-word (point))
5719 (vhdl-beginning-of-statement-1 lim)
5720 (vhdl-backward-skip-label lim)
5721 (vhdl-first-word (point)))))))
5724 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5726 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5728 (defun vhdl-end-p (&optional lim)
5729 "Return t if we are looking at a real \"end\" keyword.
5730 Assumes that the caller will make sure that we are looking at
5731 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5732 the middle of an identifier that just happens to contain an \"end\"
5734 (or (not (looking-at "else"))
5735 ;; make sure that the "else" isn't inside a conditional signal
5738 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5739 (or (eq (following-char) ?\;)
5741 (vhdl-in-literal)))))
5743 (defun vhdl-corresponding-begin (&optional lim)
5744 "If the word at the current position corresponds to an \"end\"
5745 keyword, then return a vector containing enough information to find
5746 the corresponding \"begin\" keyword, else return nil. The keyword to
5747 search backward for is aref 0. The column in which the keyword must
5748 appear is aref 1 or nil if any column is suitable. The supplementary
5749 keyword to search forward for is aref 2 or nil if this is not
5750 required. If aref 3 is t, then the \"begin\" keyword may be found in
5751 the middle of a statement.
5752 Assumes that the caller will make sure that we are not in the middle
5753 of an identifier that just happens to contain an \"end\" keyword."
5756 (if (and (looking-at vhdl-end-fwd-re)
5757 (not (vhdl-in-literal))
5759 (if (looking-at "el")
5761 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5765 (skip-chars-forward " \t\n")
5768 ((looking-at "if\\b[^_]")
5769 (vector "else\\|elsif\\|if"
5770 (vhdl-first-word pos)
5773 ((looking-at "component\\b[^_]")
5774 (vector (buffer-substring (match-beginning 1)
5776 (vhdl-first-word pos)
5778 ;; "end units", "end record":
5779 ((looking-at "\\(units\\|record\\)\\b[^_]")
5780 (vector (buffer-substring (match-beginning 1)
5782 (vhdl-first-word pos)
5784 ;; "end block", "end process", "end procedural":
5785 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5786 (vector "begin" (vhdl-first-word pos) nil nil))
5788 ((looking-at "case\\b[^_]")
5789 (vector "case" (vhdl-first-word pos) "is" nil))
5791 ((looking-at "generate\\b[^_]")
5792 (vector "generate\\|for\\|if"
5793 (vhdl-first-word pos)
5796 ((looking-at "loop\\b[^_]")
5797 (vector "loop\\|while\\|for"
5798 (vhdl-first-word pos)
5800 ;; "end for" (inside configuration declaration):
5801 ((looking-at "for\\b[^_]")
5802 (vector "for" (vhdl-first-word pos) nil nil))
5805 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5806 (vhdl-first-word pos)
5807 ;; return an alist of (statement . keyword) mappings
5809 ;; "begin ... end [id]":
5811 ;; "architecture ... is ... begin ... end [id]":
5812 ("architecture" . "is")
5813 ;; "configuration ... is ... end [id]":
5814 ("configuration" . "is")
5815 ;; "entity ... is ... end [id]":
5817 ;; "package ... is ... end [id]":
5819 ;; "procedure ... is ... begin ... end [id]":
5820 ("procedure" . "is")
5821 ;; "function ... is ... begin ... end [id]":
5828 (defconst vhdl-leader-re
5829 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5831 (defun vhdl-end-of-leader ()
5833 (cond ((looking-at "block\\|process\\|procedural")
5836 (skip-chars-forward " \t\n")
5837 (= (following-char) ?\())
5840 (when (looking-at "[ \t\n]*is")
5841 (goto-char (match-end 0)))
5843 ((looking-at "component")
5845 (when (looking-at "[ \t\n]*is")
5846 (goto-char (match-end 0)))
5850 (skip-chars-forward " \t\n")
5851 (while (looking-at "[,:(]")
5853 (skip-chars-forward " \t\n"))
5858 (defconst vhdl-trailer-re
5859 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5861 (defconst vhdl-statement-fwd-re
5862 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5863 "A regular expression for searching forward that matches all known
5864 \"statement\" keywords.")
5866 (defconst vhdl-statement-bwd-re
5867 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5868 "A regular expression for searching backward that matches all known
5869 \"statement\" keywords.")
5871 (defun vhdl-statement-p (&optional lim)
5872 "Return t if we are looking at a real \"statement\" keyword.
5873 Assumes that the caller will make sure that we are looking at
5874 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5875 in the middle of an identifier that just happens to contain a
5876 \"statement\" keyword."
5878 ;; "for" ... "generate":
5879 ((and (looking-at "f")
5880 ;; Make sure it's the start of a parameter specification.
5883 (skip-chars-forward " \t\n")
5884 (looking-at "in\\b[^_]"))
5885 ;; Make sure it's not an "end for".
5888 (not (looking-at "end\\s-+\\w"))))
5890 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5891 ((and (looking-at "i")
5892 ;; Make sure it's not an "end if".
5895 (not (looking-at "end\\s-+\\w"))))
5897 ;; "while" ... "loop":
5902 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5903 "Regexp describing a case statement alternative key.")
5905 (defun vhdl-case-alternative-p (&optional lim)
5906 "Return t if we are looking at a real case alternative.
5907 Assumes that the caller will make sure that we are looking at
5908 vhdl-case-alternative-re, and are not inside a literal, and that
5909 we are not in the middle of an identifier that just happens to
5910 contain a \"when\" keyword."
5913 (while (and (not foundp)
5914 (re-search-backward ";\\|<=" lim 'move))
5915 (if (or (= (preceding-char) ?_)
5919 (or (eq (following-char) ?\;)
5923 ;; Core syntactic movement functions:
5925 (defconst vhdl-b-t-b-re
5926 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5928 (defun vhdl-backward-to-block (&optional lim)
5929 "Move backward to the previous \"begin\" or \"end\" keyword."
5931 (while (and (not foundp)
5932 (re-search-backward vhdl-b-t-b-re lim 'move))
5933 (if (or (= (preceding-char) ?_)
5938 ((and (looking-at vhdl-begin-fwd-re)
5939 (/= (preceding-char) ?_)
5941 (setq foundp 'begin))
5943 ((and (looking-at vhdl-end-fwd-re)
5944 (/= (preceding-char) ?_)
5952 (defun vhdl-forward-sexp (&optional count lim)
5953 "Move forward across one balanced expression (sexp).
5954 With COUNT, do it that many times."
5956 (let ((count (or count 1))
5957 (case-fold-search t)
5962 (skip-chars-forward " \t\n")
5963 ;; Check for an unbalanced "end" keyword
5964 (if (and (looking-at vhdl-end-fwd-re)
5965 (/= (preceding-char) ?_)
5966 (not (vhdl-in-literal))
5968 (not (looking-at "else")))
5970 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5971 ;; If the current keyword is a "begin" keyword, then find the
5972 ;; corresponding "end" keyword.
5973 (if (setq end-vec (vhdl-corresponding-end lim))
5975 ;; end-re is the statement keyword to search for
5977 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5978 ;; column is either the statement keyword target column
5980 (column (aref end-vec 1))
5981 (eol (vhdl-point 'eol))
5982 foundp literal placeholder)
5983 ;; Look for the statement keyword.
5984 (while (and (not foundp)
5985 (re-search-forward end-re nil t)
5986 (setq placeholder (match-end 1))
5987 (goto-char (match-beginning 0)))
5988 ;; If we are in a literal, or not in the right target
5989 ;; column and not on the same line as the begin, then
5992 (/= (current-indentation) column)
5994 (= (preceding-char) ?_)
5995 (setq literal (vhdl-in-literal)))
5996 (if (eq literal 'comment)
5999 ;; An "else" keyword corresponds to both the opening brace
6000 ;; of the following sexp and the closing brace of the
6002 (if (not (looking-at "else"))
6003 (goto-char placeholder))
6007 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6009 ;; If the current keyword is not a "begin" keyword, then just
6010 ;; perform the normal forward-sexp.
6013 (setq count (1- count))
6015 (setq target (point)))
6019 (defun vhdl-backward-sexp (&optional count lim)
6020 "Move backward across one balanced expression (sexp).
6021 With COUNT, do it that many times. LIM bounds any required backward
6024 (let ((count (or count 1))
6025 (case-fold-search t)
6029 ;; Perform the normal backward-sexp, unless we are looking at
6030 ;; "else" - an "else" keyword corresponds to both the opening brace
6031 ;; of the following sexp and the closing brace of the previous sexp.
6032 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6033 (/= (preceding-char) ?_)
6034 (not (vhdl-in-literal)))
6037 (if (and (looking-at vhdl-begin-fwd-re)
6038 (/= (preceding-char) ?_)
6039 (not (vhdl-in-literal))
6041 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6042 ;; If the current keyword is an "end" keyword, then find the
6043 ;; corresponding "begin" keyword.
6044 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6045 (/= (preceding-char) ?_))
6047 ;; begin-re is the statement keyword to search for
6049 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6050 ;; column is either the statement keyword target column
6052 (column (aref begin-vec 1))
6053 ;; internal-p controls where the statement keyword can
6055 (internal-p (aref begin-vec 3))
6056 (last-backward (point)) last-forward
6057 foundp literal keyword)
6058 ;; Look for the statement keyword.
6059 (while (and (not foundp)
6060 (re-search-backward begin-re lim t)
6062 (buffer-substring (match-beginning 1)
6064 ;; If we are in a literal or in the wrong column,
6067 (and (/= (current-indentation) column)
6068 ;; possibly accept current-column as
6069 ;; well as current-indentation.
6070 (or (not internal-p)
6071 (/= (current-column) column))))
6072 (= (preceding-char) ?_)
6075 ;; If there is a supplementary keyword, then
6076 ;; search forward for it.
6077 (if (and (setq begin-re (aref begin-vec 2))
6078 (or (not (listp begin-re))
6079 ;; If begin-re is an alist, then find the
6080 ;; element corresponding to the actual
6081 ;; keyword that we found.
6084 (assoc keyword begin-re))
6086 (setq begin-re (cdr begin-re))))))
6089 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6091 (setq last-forward (point))
6092 ;; Look for the supplementary keyword
6093 ;; (bounded by the backward search start
6095 (while (and (not foundp)
6096 (re-search-forward begin-re
6098 (goto-char (match-beginning 1)))
6099 ;; If we are in a literal, then try again.
6100 (if (or (= (preceding-char) ?_)
6103 (if (eq literal 'comment)
6105 (min (vhdl-point 'eol) last-backward))
6107 ;; We have found the supplementary keyword.
6108 ;; Save the position of the keyword in foundp.
6109 (setq foundp (point)))
6112 ;; If the supplementary keyword was found, then
6113 ;; move point to the supplementary keyword.
6115 ;; If there was no supplementary keyword, then
6116 ;; point is already at the statement keyword.
6118 ) ; end of the search for the statement keyword
6120 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6122 (setq count (1- count))
6124 (setq target (point)))
6128 (defun vhdl-backward-up-list (&optional count limit)
6129 "Move backward out of one level of blocks.
6130 With argument, do this that many times."
6132 (let ((count (or count 1))
6136 (if (looking-at vhdl-defun-re)
6137 (error "ERROR: Unbalanced blocks"))
6138 (vhdl-backward-to-block limit)
6139 (setq count (1- count)))
6140 (setq target (point)))
6141 (goto-char target)))
6143 (defun vhdl-end-of-defun (&optional count)
6144 "Move forward to the end of a VHDL defun."
6146 (let ((case-fold-search t))
6147 (vhdl-beginning-of-defun)
6148 (if (not (looking-at "block\\|process\\|procedural"))
6149 (re-search-forward "\\bis\\b"))
6150 (vhdl-forward-sexp)))
6152 (defun vhdl-mark-defun ()
6153 "Put mark at end of this \"defun\", point at beginning."
6155 (let ((case-fold-search t))
6157 (vhdl-beginning-of-defun)
6159 (if (not (looking-at "block\\|process\\|procedural"))
6160 (re-search-forward "\\bis\\b"))
6162 (exchange-point-and-mark)))
6164 (defun vhdl-beginning-of-libunit ()
6165 "Move backward to the beginning of a VHDL library unit.
6166 Returns the location of the corresponding begin keyword, unless search
6167 stops due to beginning or end of buffer.
6168 Note that if point is between the \"libunit\" keyword and the
6169 corresponding \"begin\" keyword, then that libunit will not be
6170 recognized, and the search will continue backwards. If point is
6171 at the \"begin\" keyword, then the defun will be recognized. The
6172 returned point is at the first character of the \"libunit\" keyword."
6173 (let ((last-forward (point))
6175 ;; Just in case we are actually sitting on the "begin"
6176 ;; keyword, allow for the keyword and an extra character,
6177 ;; as this will be used when looking forward for the
6179 (save-excursion (forward-word 1) (1+ (point))))
6180 foundp literal placeholder)
6181 ;; Find the "libunit" keyword.
6182 (while (and (not foundp)
6183 (re-search-backward vhdl-libunit-re nil 'move))
6184 ;; If we are in a literal, or not at a real libunit, then try again.
6185 (if (or (= (preceding-char) ?_)
6187 (not (vhdl-libunit-p)))
6189 ;; Find the corresponding "begin" keyword.
6190 (setq last-forward (point))
6191 (while (and (not foundp)
6192 (re-search-forward "\\bis\\b[^_]" last-backward t)
6193 (setq placeholder (match-beginning 0)))
6194 (if (or (= (preceding-char) ?_)
6195 (setq literal (vhdl-in-literal)))
6196 ;; It wasn't a real keyword, so keep searching.
6197 (if (eq literal 'comment)
6199 (min (vhdl-point 'eol) last-backward))
6201 ;; We have found the begin keyword, loop will exit.
6202 (setq foundp placeholder)))
6203 ;; Go back to the libunit keyword
6204 (goto-char last-forward)))
6207 (defun vhdl-beginning-of-defun (&optional count)
6208 "Move backward to the beginning of a VHDL defun.
6209 With argument, do it that many times.
6210 Returns the location of the corresponding begin keyword, unless search
6211 stops due to beginning or end of buffer."
6212 ;; Note that if point is between the "defun" keyword and the
6213 ;; corresponding "begin" keyword, then that defun will not be
6214 ;; recognized, and the search will continue backwards. If point is
6215 ;; at the "begin" keyword, then the defun will be recognized. The
6216 ;; returned point is at the first character of the "defun" keyword.
6218 (let ((count (or count 1))
6219 (case-fold-search t)
6220 (last-forward (point))
6224 (goto-char last-forward)
6225 (let ((last-backward
6226 ;; Just in case we are actually sitting on the "begin"
6227 ;; keyword, allow for the keyword and an extra character,
6228 ;; as this will be used when looking forward for the
6230 (save-excursion (forward-word 1) (1+ (point))))
6231 begin-string literal)
6232 (while (and (not foundp)
6233 (re-search-backward vhdl-defun-re nil 'move))
6234 ;; If we are in a literal, then try again.
6235 (if (or (= (preceding-char) ?_)
6238 (if (setq begin-string (vhdl-corresponding-defun))
6239 ;; This is a real defun keyword.
6240 ;; Find the corresponding "begin" keyword.
6241 ;; Look for the begin keyword.
6243 ;; Save the search start point.
6244 (setq last-forward (point))
6245 (while (and (not foundp)
6246 (search-forward begin-string last-backward t))
6247 (if (or (= (preceding-char) ?_)
6249 (setq literal (vhdl-in-literal))))
6250 ;; It wasn't a real keyword, so keep searching.
6251 (if (eq literal 'comment)
6253 (min (vhdl-point 'eol) last-backward))
6255 ;; We have found the begin keyword, loop will exit.
6256 (setq foundp (match-beginning 0)))
6258 ;; Go back to the defun keyword
6259 (goto-char last-forward)) ; end search for begin keyword
6261 ) ; end of the search for the defun keyword
6263 (setq count (1- count))
6265 (vhdl-keep-region-active)
6268 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6269 "Go to the beginning of the innermost VHDL statement.
6270 With prefix arg, go back N - 1 statements. If already at the
6271 beginning of a statement then go to the beginning of the preceding
6272 one. If within a string or comment, or next to a comment (only
6273 whitespace between), move by sentences instead of statements.
6275 When called from a program, this function takes 3 optional args: the
6276 prefix arg, a buffer position limit which is the farthest back to
6277 search, and an argument indicating an interactive call."
6278 (interactive "p\np")
6279 (let ((count (or count 1))
6280 (case-fold-search t)
6281 (lim (or lim (point-min)))
6286 (setq state (parse-partial-sexp (point) here nil nil)))
6287 (if (and interactive
6290 (looking-at (concat "[ \t]*" comment-start-skip))))
6291 (forward-sentence (- count))
6293 (vhdl-beginning-of-statement-1 lim)
6294 (setq count (1- count))))
6295 ;; its possible we've been left up-buf of lim
6296 (goto-char (max (point) lim))
6298 (vhdl-keep-region-active))
6300 (defconst vhdl-e-o-s-re
6301 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6303 (defun vhdl-end-of-statement ()
6304 "Very simple implementation."
6306 (re-search-forward vhdl-e-o-s-re))
6308 (defconst vhdl-b-o-s-re
6309 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6310 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6312 (defun vhdl-beginning-of-statement-1 (&optional lim)
6313 "Move to the start of the current statement, or the previous
6314 statement if already at the beginning of one."
6315 (let ((lim (or lim (point-min)))
6319 ;; go backwards one balanced expression, but be careful of
6320 ;; unbalanced paren being reached
6321 (if (not (vhdl-safe (progn (backward-sexp) t)))
6323 (backward-up-list 1)
6325 (vhdl-forward-syntactic-ws here)
6327 (while (and (not donep)
6329 ;; look backwards for a statement boundary
6330 (re-search-backward vhdl-b-o-s-re lim 'move))
6331 (if (or (= (preceding-char) ?_)
6335 ;; If we are looking at an open paren, then stop after it
6336 ((eq (following-char) ?\()
6338 (vhdl-forward-syntactic-ws here)
6340 ;; If we are looking at a close paren, then skip it
6341 ((eq (following-char) ?\))
6346 (progn (goto-char pos)
6347 (vhdl-forward-syntactic-ws here)
6349 ;; If we are looking at a semicolon, then stop
6350 ((eq (following-char) ?\;)
6353 (vhdl-forward-syntactic-ws here)
6355 ;; If we are looking at a "begin", then stop
6356 ((and (looking-at vhdl-begin-fwd-re)
6357 (/= (preceding-char) ?_)
6359 ;; If it's a leader "begin", then find the
6361 (if (looking-at vhdl-leader-re)
6363 ;; set a default stop point at the begin
6365 ;; is the start point inside the leader area ?
6366 (goto-char (vhdl-end-of-leader))
6367 (vhdl-forward-syntactic-ws here)
6368 (if (< (point) here)
6369 ;; start point was not inside leader area
6370 ;; set stop point at word after leader
6371 (setq pos (point))))
6373 (vhdl-forward-syntactic-ws here)
6377 ;; If we are looking at a "statement", then stop
6378 ((and (looking-at vhdl-statement-fwd-re)
6379 (/= (preceding-char) ?_)
6380 (vhdl-statement-p nil))
6382 ;; If we are looking at a case alternative key, then stop
6383 ((and (looking-at vhdl-case-alternative-re)
6384 (vhdl-case-alternative-p lim))
6386 ;; set a default stop point at the when
6388 ;; is the start point inside the case alternative key ?
6389 (looking-at vhdl-case-alternative-re)
6390 (goto-char (match-end 0))
6391 (vhdl-forward-syntactic-ws here)
6392 (if (< (point) here)
6393 ;; start point was not inside the case alternative key
6394 ;; set stop point at word after case alternative keyleader
6395 (setq pos (point))))
6398 ;; Bogus find, continue
6403 ;; Defuns for calculating the current syntactic state:
6405 (defun vhdl-get-library-unit (bod placeholder)
6406 "If there is an enclosing library unit at BOD, with its \"begin\"
6407 keyword at PLACEHOLDER, then return the library unit type."
6408 (let ((here (vhdl-point 'bol)))
6410 (goto-char placeholder)
6411 (vhdl-safe (vhdl-forward-sexp 1 bod))
6416 ((looking-at "e") 'entity)
6417 ((looking-at "a") 'architecture)
6418 ((looking-at "c") 'configuration)
6423 (vhdl-forward-syntactic-ws here)
6424 (if (looking-at "body\\b[^_]")
6425 'package-body 'package))))))
6428 (defun vhdl-get-block-state (&optional lim)
6429 "Finds and records all the closest opens.
6430 LIM is the furthest back we need to search (it should be the
6431 previous libunit keyword)."
6432 (let ((here (point))
6433 (lim (or lim (point-min)))
6434 keyword sexp-start sexp-mid sexp-end
6435 preceding-sexp containing-sexp
6436 containing-begin containing-mid containing-paren)
6438 ;; Find the containing-paren, and use that as the limit
6439 (if (setq containing-paren
6441 (narrow-to-region lim (point))
6442 (vhdl-safe (scan-lists (point) -1 1))))
6443 (setq lim containing-paren))
6444 ;; Look backwards for "begin" and "end" keywords.
6445 (while (and (> (point) lim)
6446 (not containing-sexp))
6447 (setq keyword (vhdl-backward-to-block lim))
6449 ((eq keyword 'begin)
6450 ;; Found a "begin" keyword
6451 (setq sexp-start (point))
6452 (setq sexp-mid (vhdl-corresponding-mid lim))
6453 (setq sexp-end (vhdl-safe
6455 (vhdl-forward-sexp 1 lim) (point))))
6456 (if (and sexp-end (<= sexp-end here))
6457 ;; we want to record this sexp, but we only want to
6458 ;; record the last-most of any of them before here
6460 (setq preceding-sexp sexp-start))
6461 ;; we're contained in this sexp so put sexp-start on
6463 (setq containing-sexp sexp-start)
6464 (setq containing-mid sexp-mid)
6465 (setq containing-begin t)))
6467 ;; Found an "end" keyword
6469 (setq sexp-end (point))
6472 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6473 (progn (backward-sexp) (point))))
6474 ;; we want to record this sexp, but we only want to
6475 ;; record the last-most of any of them before here
6477 (setq preceding-sexp sexp-start)))
6479 ;; Check if the containing-paren should be the containing-sexp
6480 (if (and containing-paren
6481 (or (null containing-sexp)
6482 (< containing-sexp containing-paren)))
6483 (setq containing-sexp containing-paren
6485 containing-begin nil
6486 containing-mid nil))
6487 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6491 (defconst vhdl-s-c-a-re
6492 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6494 (defun vhdl-skip-case-alternative (&optional lim)
6495 "Skip forward over case/when bodies, with optional maximal
6496 limit. If no next case alternative is found, nil is returned and
6497 point is not moved."
6498 (let ((lim (or lim (point-max)))
6501 (while (and (< (point) lim)
6503 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6505 (not (vhdl-in-literal)))
6506 (/= (match-beginning 0) here))
6508 (goto-char (match-beginning 0))
6510 ((and (looking-at "case")
6511 (re-search-forward "\\bis[^_]" lim t))
6513 (vhdl-forward-sexp))
6521 (defun vhdl-backward-skip-label (&optional lim)
6522 "Skip backward over a label, with optional maximal
6523 limit. If label is not found, nil is returned and point
6525 (let ((lim (or lim (point-min)))
6528 (vhdl-backward-syntactic-ws lim)
6529 (and (eq (preceding-char) ?:)
6532 (setq placeholder (point))
6533 (looking-at vhdl-label-key))))
6534 (goto-char placeholder))
6537 (defun vhdl-forward-skip-label (&optional lim)
6538 "Skip forward over a label, with optional maximal
6539 limit. If label is not found, nil is returned and point
6541 (let ((lim (or lim (point-max))))
6542 (if (looking-at vhdl-label-key)
6544 (goto-char (match-end 0))
6545 (vhdl-forward-syntactic-ws lim)))
6548 (defun vhdl-get-syntactic-context ()
6549 "Guess the syntactic description of the current line of VHDL code."
6553 (let* ((indent-point (point))
6554 (case-fold-search t)
6555 vec literal containing-sexp preceding-sexp
6556 containing-begin containing-mid containing-leader
6557 char-before-ip char-after-ip begin-after-ip end-after-ip
6558 placeholder lim library-unit
6561 ;; Reset the syntactic context
6562 (setq vhdl-syntactic-context nil)
6565 ;; Move to the start of the previous library unit, and
6566 ;; record the position of the "begin" keyword.
6567 (setq placeholder (vhdl-beginning-of-libunit))
6568 ;; The position of the "libunit" keyword gives us a gross
6573 ;; If there is a previous library unit, and we are enclosed by
6574 ;; it, then set the syntax accordingly.
6576 (setq library-unit (vhdl-get-library-unit lim placeholder))
6577 (vhdl-add-syntax library-unit lim))
6579 ;; Find the surrounding state.
6580 (if (setq vec (vhdl-get-block-state lim))
6582 (setq containing-sexp (aref vec 0))
6583 (setq preceding-sexp (aref vec 1))
6584 (setq containing-begin (aref vec 2))
6585 (setq containing-mid (aref vec 3))
6588 ;; set the limit on the farthest back we need to search
6589 (setq lim (if containing-sexp
6591 (goto-char containing-sexp)
6592 ;; set containing-leader if required
6593 (if (looking-at vhdl-leader-re)
6594 (setq containing-leader (vhdl-end-of-leader)))
6598 ;; cache char before and after indent point, and move point to
6599 ;; the most likely position to perform the majority of tests
6600 (goto-char indent-point)
6601 (skip-chars-forward " \t")
6602 (setq literal (vhdl-in-literal))
6603 (setq char-after-ip (following-char))
6604 (setq begin-after-ip (and
6606 (looking-at vhdl-begin-fwd-re)
6608 (setq end-after-ip (and
6610 (looking-at vhdl-end-fwd-re)
6612 (vhdl-backward-syntactic-ws lim)
6613 (setq char-before-ip (preceding-char))
6614 (goto-char indent-point)
6615 (skip-chars-forward " \t")
6617 ;; now figure out syntactic qualities of the current line
6619 ;; CASE 1: in a string or comment.
6620 ((memq literal '(string comment))
6621 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6622 ;; CASE 2: Line is at top level.
6623 ((null containing-sexp)
6624 ;; Find the point to which indentation will be relative
6626 (if (null preceding-sexp)
6628 ;; no preceding-sexp -> use the preceding statement
6629 (vhdl-beginning-of-statement-1 lim)
6631 ;; if there is a preceding-sexp then indent relative to it
6632 (goto-char preceding-sexp)
6633 ;; if not at boi, then the block-opening keyword is
6634 ;; probably following a label, so we need a different
6636 (if (/= (point) (vhdl-point 'boi))
6638 (vhdl-beginning-of-statement-1 lim)))
6639 ;; v-b-o-s could have left us at point-min
6642 (vhdl-forward-syntactic-ws indent-point))
6643 (setq placeholder (point)))
6645 ;; CASE 2A : we are looking at a block-open
6647 (vhdl-add-syntax 'block-open placeholder))
6648 ;; CASE 2B: we are looking at a block-close
6650 (vhdl-add-syntax 'block-close placeholder))
6651 ;; CASE 2C: we are looking at a top-level statement
6653 (vhdl-backward-syntactic-ws lim)
6655 (= (preceding-char) ?\;)))
6656 (vhdl-add-syntax 'statement placeholder))
6657 ;; CASE 2D: we are looking at a top-level statement-cont
6659 (vhdl-beginning-of-statement-1 lim)
6660 ;; v-b-o-s could have left us at point-min
6663 (vhdl-forward-syntactic-ws indent-point))
6664 (vhdl-add-syntax 'statement-cont (point)))
6666 ;; CASE 3: line is inside parentheses. Most likely we are
6667 ;; either in a subprogram argument (interface) list, or a
6668 ;; continued expression containing parentheses.
6669 ((null containing-begin)
6670 (vhdl-backward-syntactic-ws containing-sexp)
6672 ;; CASE 3A: we are looking at the arglist closing paren
6673 ((eq char-after-ip ?\))
6674 (goto-char containing-sexp)
6675 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6676 ;; CASE 3B: we are looking at the first argument in an empty
6678 ((eq char-before-ip ?\()
6679 (goto-char containing-sexp)
6680 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6681 ;; CASE 3C: we are looking at an arglist continuation line,
6682 ;; but the preceding argument is on the same line as the
6683 ;; opening paren. This case includes multi-line
6684 ;; expression paren groupings.
6685 ((and (save-excursion
6686 (goto-char (1+ containing-sexp))
6687 (skip-chars-forward " \t")
6689 (not (looking-at "--")))
6691 (vhdl-beginning-of-statement-1 containing-sexp)
6692 (skip-chars-backward " \t(")
6693 (<= (point) containing-sexp)))
6694 (goto-char containing-sexp)
6695 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6696 ;; CASE 3D: we are looking at just a normal arglist
6697 ;; continuation line
6698 (t (vhdl-beginning-of-statement-1 containing-sexp)
6699 (vhdl-forward-syntactic-ws indent-point)
6700 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6702 ;; CASE 4: A block mid open
6703 ((and begin-after-ip
6704 (looking-at containing-mid))
6705 (goto-char containing-sexp)
6706 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6707 (if (looking-at vhdl-trailer-re)
6709 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6710 (vhdl-backward-skip-label (vhdl-point 'boi))
6711 (vhdl-add-syntax 'block-open (point)))
6712 ;; CASE 5: block close brace
6714 (goto-char containing-sexp)
6715 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6716 (if (looking-at vhdl-trailer-re)
6718 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6719 (vhdl-backward-skip-label (vhdl-point 'boi))
6720 (vhdl-add-syntax 'block-close (point)))
6721 ;; CASE 6: A continued statement
6722 ((and (/= char-before-ip ?\;)
6723 ;; check it's not a trailer begin keyword, or a begin
6724 ;; keyword immediately following a label.
6725 (not (and begin-after-ip
6726 (or (looking-at vhdl-trailer-re)
6728 (vhdl-backward-skip-label containing-sexp)))))
6729 ;; check it's not a statement keyword
6730 (not (and (looking-at vhdl-statement-fwd-re)
6731 (vhdl-statement-p)))
6732 ;; see if the b-o-s is before the indent point
6735 (vhdl-beginning-of-statement-1 containing-sexp)
6736 ;; If we ended up after a leader, then this will
6737 ;; move us forward to the start of the first
6738 ;; statement. Note that a containing sexp here is
6739 ;; always a keyword, not a paren, so this will
6740 ;; have no effect if we hit the containing-sexp.
6741 (vhdl-forward-syntactic-ws indent-point)
6742 (setq placeholder (point))))
6743 ;; check it's not a block-intro
6744 (/= placeholder containing-sexp)
6745 ;; check it's not a case block-intro
6747 (goto-char placeholder)
6748 (or (not (looking-at vhdl-case-alternative-re))
6749 (> (match-end 0) indent-point))))
6750 ;; Make placeholder skip a label, but only if it puts us
6751 ;; before the indent point at the start of a line.
6752 (let ((new placeholder))
6753 (if (and (> indent-point
6755 (goto-char placeholder)
6756 (vhdl-forward-skip-label indent-point)
6757 (setq new (point))))
6760 (eq new (progn (back-to-indentation) (point)))))
6761 (setq placeholder new)))
6762 (vhdl-add-syntax 'statement-cont placeholder)
6764 (vhdl-add-syntax 'block-open)))
6765 ;; Statement. But what kind?
6766 ;; CASE 7: A case alternative key
6767 ((and (looking-at vhdl-case-alternative-re)
6768 (vhdl-case-alternative-p containing-sexp))
6769 ;; for a case alternative key, we set relpos to the first
6770 ;; non-whitespace char on the line containing the "case"
6772 (goto-char containing-sexp)
6773 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6774 (if (looking-at vhdl-trailer-re)
6775 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6776 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6777 ;; CASE 8: statement catchall
6779 ;; we know its a statement, but we need to find out if it is
6780 ;; the first statement in a block
6781 (if containing-leader
6782 (goto-char containing-leader)
6783 (goto-char containing-sexp)
6784 ;; Note that a containing sexp here is always a keyword,
6785 ;; not a paren, so skip over the keyword.
6787 ;; move to the start of the first statement
6788 (vhdl-forward-syntactic-ws indent-point)
6789 (setq placeholder (point))
6790 ;; we want to ignore case alternatives keys when skipping forward
6792 (while (looking-at vhdl-case-alternative-re)
6793 (setq incase-p (point))
6794 ;; we also want to skip over the body of the
6795 ;; case/when statement if that doesn't put us at
6796 ;; after the indent-point
6797 (while (vhdl-skip-case-alternative indent-point))
6798 ;; set up the match end
6799 (looking-at vhdl-case-alternative-re)
6800 (goto-char (match-end 0))
6801 ;; move to the start of the first case alternative statement
6802 (vhdl-forward-syntactic-ws indent-point)
6803 (setq placeholder (point)))
6805 ;; CASE 8A: we saw a case/when statement so we must be
6806 ;; in a switch statement. find out if we are at the
6807 ;; statement just after a case alternative key
6809 (= (point) indent-point))
6810 ;; relpos is the "when" keyword
6811 (vhdl-add-syntax 'statement-case-intro incase-p))
6812 ;; CASE 8B: any old statement
6813 ((< (point) indent-point)
6814 ;; relpos is the first statement of the block
6815 (vhdl-add-syntax 'statement placeholder)
6817 (vhdl-add-syntax 'block-open)))
6818 ;; CASE 8C: first statement in a block
6820 (goto-char containing-sexp)
6821 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6822 (if (looking-at vhdl-trailer-re)
6823 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6824 (vhdl-backward-skip-label (vhdl-point 'boi))
6825 (vhdl-add-syntax 'statement-block-intro (point))
6827 (vhdl-add-syntax 'block-open)))
6831 ;; now we need to look at any modifiers
6832 (goto-char indent-point)
6833 (skip-chars-forward " \t")
6834 (if (looking-at "--")
6835 (vhdl-add-syntax 'comment))
6836 (if (eq literal 'pound)
6837 (vhdl-add-syntax 'cpp-macro))
6838 ;; return the syntax
6839 vhdl-syntactic-context))))
6841 ;; Standard indentation line-ups:
6843 (defun vhdl-lineup-arglist (langelem)
6844 "Lineup the current arglist line with the arglist appearing just
6845 after the containing paren which starts the arglist."
6847 (let* ((containing-sexp
6849 ;; arglist-cont-nonempty gives relpos ==
6850 ;; to boi of containing-sexp paren. This
6851 ;; is good when offset is +, but bad
6852 ;; when it is vhdl-lineup-arglist, so we
6853 ;; have to special case a kludge here.
6854 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6857 (backward-up-list 1)
6858 (skip-chars-forward " \t" (vhdl-point 'eol)))
6859 (goto-char (cdr langelem)))
6861 (cs-curcol (save-excursion
6862 (goto-char (cdr langelem))
6866 (looking-at "[ \t]*)"))
6867 (progn (goto-char (match-end 0))
6870 (vhdl-forward-syntactic-ws)
6871 (- (current-column) cs-curcol))
6872 (goto-char containing-sexp)
6874 (let ((eol (vhdl-point 'eol))
6877 (skip-chars-forward " \t")
6879 (vhdl-forward-syntactic-ws)
6882 (- (current-column) cs-curcol)
6885 (defun vhdl-lineup-arglist-intro (langelem)
6886 "Lineup an arglist-intro line to just after the open paren."
6888 (let ((cs-curcol (save-excursion
6889 (goto-char (cdr langelem))
6891 (ce-curcol (save-excursion
6893 (backward-up-list 1)
6894 (skip-chars-forward " \t" (vhdl-point 'eol))
6896 (- ce-curcol cs-curcol -1))))
6898 (defun vhdl-lineup-comment (langelem)
6899 "Support old behavior for comment indentation. We look at
6900 vhdl-comment-only-line-offset to decide how to indent comment
6903 (back-to-indentation)
6904 ;; at or to the right of comment-column
6905 (if (>= (current-column) comment-column)
6906 (vhdl-comment-indent)
6907 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6909 (or (car-safe vhdl-comment-only-line-offset)
6910 vhdl-comment-only-line-offset)
6911 (or (cdr-safe vhdl-comment-only-line-offset)
6912 (car-safe vhdl-comment-only-line-offset)
6913 -1000 ;jam it against the left side
6916 (defun vhdl-lineup-statement-cont (langelem)
6917 "Line up statement-cont after the assignment operator."
6919 (let* ((relpos (cdr langelem))
6920 (assignp (save-excursion
6921 (goto-char (vhdl-point 'boi))
6922 (and (re-search-forward "\\(<\\|:\\)="
6923 (vhdl-point 'eol) t)
6924 (- (point) (vhdl-point 'boi)))))
6929 (while (and (not foundp)
6930 (< (point) (vhdl-point 'eol)))
6931 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6932 (if (vhdl-in-literal)
6934 (if (= (preceding-char) ?\()
6935 ;; skip over any parenthesized expressions
6936 (goto-char (min (vhdl-point 'eol)
6937 (scan-lists (point) 1 1)))
6938 ;; found an assignment operator (not at eol)
6939 (setq foundp (not (looking-at "\\s-*$"))))))
6941 ;; there's no assignment operator on the line
6943 ;; calculate indentation column after assign and ws, unless
6944 ;; our line contains an assignment operator
6948 (skip-chars-forward " \t")
6950 (- (current-column) assignp curcol))
6953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6954 ;; Progress reporting
6956 (defvar vhdl-progress-info nil
6957 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6959 (defun vhdl-update-progress-info (string pos)
6960 "Update progress information."
6961 (when (and vhdl-progress-info (not noninteractive)
6962 (< vhdl-progress-interval
6963 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6964 (let ((delta (- (aref vhdl-progress-info 1)
6965 (aref vhdl-progress-info 0))))
6967 (message (concat string "... (100%s)") "%")
6968 (message (concat string "... (%2d%s)")
6969 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6971 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6974 ;; Indentation commands
6976 (defun vhdl-electric-tab (&optional prefix-arg)
6977 "If preceeding character is part of a word or a paren then hippie-expand,
6978 else if right of non whitespace on line then insert tab,
6979 else if last command was a tab or return then dedent one step or if a comment
6980 toggle between normal indent and inline comment indent,
6981 else indent `correctly'."
6983 (vhdl-prepare-search-2
6985 ;; indent region if region is active
6986 ((and (not (featurep 'xemacs)) (use-region-p))
6987 (vhdl-indent-region (region-beginning) (region-end) nil))
6989 ((= (char-syntax (preceding-char)) ?w)
6990 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6992 (hippie-expand-only-buffers
6993 (or (and (boundp 'hippie-expand-only-buffers)
6994 hippie-expand-only-buffers)
6996 (vhdl-expand-abbrev prefix-arg)))
6997 ;; expand parenthesis
6998 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6999 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7001 (vhdl-expand-paren prefix-arg)))
7003 ((> (current-column) (current-indentation))
7005 ;; toggle comment indent
7006 ((and (looking-at "--")
7007 (or (eq last-command 'vhdl-electric-tab)
7008 (eq last-command 'vhdl-electric-return)))
7009 (cond ((= (current-indentation) 0) ; no indent
7011 (indent-according-to-mode))
7012 ((< (current-indentation) comment-column) ; normal indent
7013 (indent-to comment-column)
7014 (indent-according-to-mode))
7015 (t ; inline comment indent
7016 (delete-region (line-beginning-position) (point)))))
7018 ((and (>= (current-indentation) vhdl-basic-offset)
7019 (or (eq last-command 'vhdl-electric-tab)
7020 (eq last-command 'vhdl-electric-return)))
7021 (backward-delete-char-untabify vhdl-basic-offset nil))
7023 (t (indent-according-to-mode)))
7024 (setq this-command 'vhdl-electric-tab)))
7026 (defun vhdl-electric-return ()
7027 "newline-and-indent or indent-new-comment-line if in comment and preceding
7028 character is a space."
7030 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7031 (indent-new-comment-line)
7032 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7033 (vhdl-fix-case-word -1))
7034 (newline-and-indent)))
7036 (defun vhdl-indent-line ()
7037 "Indent the current line as VHDL code. Returns the amount of
7038 indentation change."
7040 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7041 (pos (- (point-max) (point)))
7044 ;; indent syntax-based
7045 (if (and (eq (caar syntax) 'comment)
7046 (>= (vhdl-get-offset (car syntax)) comment-column))
7047 ;; special case: comments at or right of comment-column
7048 (vhdl-get-offset (car syntax))
7049 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7050 ;; indent like previous nonblank line
7051 (save-excursion (beginning-of-line)
7052 (re-search-backward "^[^\n]" nil t)
7053 (current-indentation))))
7054 (shift-amt (- indent (current-indentation))))
7055 (and vhdl-echo-syntactic-information-p
7056 (message "syntax: %s, indent= %d" syntax indent))
7057 (unless (zerop shift-amt)
7058 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7061 (if (< (point) (vhdl-point 'boi))
7062 (back-to-indentation)
7063 ;; If initial point was within line's indentation, position after
7064 ;; the indentation. Else stay at same point in text.
7065 (when (> (- (point-max) pos) (point))
7066 (goto-char (- (point-max) pos))))
7067 (run-hooks 'vhdl-special-indent-hook)
7068 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7071 (defun vhdl-indent-region (beg end column)
7072 "Indent region as VHDL code.
7073 Adds progress reporting to `indent-region'."
7074 (interactive "r\nP")
7075 (when vhdl-progress-interval
7076 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7077 (count-lines (point-min) end) 0)))
7078 (indent-region beg end column)
7079 (when vhdl-progress-interval (message "Indenting...done"))
7080 (setq vhdl-progress-info nil))
7082 (defun vhdl-indent-buffer ()
7083 "Indent whole buffer as VHDL code.
7084 Calls `indent-region' for whole buffer and adds progress reporting."
7086 (vhdl-indent-region (point-min) (point-max) nil))
7088 (defun vhdl-indent-group ()
7089 "Indent group of lines between empty lines."
7091 (let ((beg (save-excursion
7092 (if (re-search-backward vhdl-align-group-separate nil t)
7094 (point-min-marker))))
7095 (end (save-excursion
7096 (if (re-search-forward vhdl-align-group-separate nil t)
7098 (point-max-marker)))))
7099 (vhdl-indent-region beg end nil)))
7101 (defun vhdl-indent-sexp (&optional endpos)
7102 "Indent each line of the list starting just after point.
7103 If optional arg ENDPOS is given, indent each line, stopping when
7104 ENDPOS is encountered."
7108 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7109 (indent-region beg end nil))))
7111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7112 ;; Miscellaneous commands
7114 (defun vhdl-show-syntactic-information ()
7115 "Show syntactic information for current line."
7117 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7118 (vhdl-keep-region-active))
7120 ;; Verification and regression functions:
7122 (defun vhdl-regress-line (&optional arg)
7123 "Check syntactic information for current line."
7125 (let ((expected (save-excursion
7127 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7129 (read (current-buffer)))))
7130 (actual (vhdl-get-syntactic-context))
7132 ;; remove the library unit symbols
7136 (if (memq (car elt) '(entity configuration package
7137 package-body architecture))
7139 (setq expurgated (append expurgated (list elt))))))
7141 (if (and (not arg) expected (listp expected))
7142 (if (not (equal expected expurgated))
7143 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7146 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7148 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7149 (delete-region (point) (line-end-position)))
7151 (insert (format "%s" expurgated))))))
7152 (vhdl-keep-region-active))
7155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7156 ;;; Alignment, whitespace fixup, beautifying
7157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7159 (defconst vhdl-align-alist
7161 ;; after some keywords
7162 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7163 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7165 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7166 ;; after direction specifications
7167 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7168 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7169 ;; before "==", ":=", "=>", and "<="
7170 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7171 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7172 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7173 ;; before some keywords
7174 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7175 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7176 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7177 ;; before "=>" since "when/else ... =>" can occur
7178 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7180 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7181 It is searched in order. If REGEXP is found anywhere in the first
7182 line of a region to be aligned, ALIGN-PATTERN will be used for that
7183 region. ALIGN-PATTERN must include the whitespace to be expanded or
7184 contracted. It may also provide regexps for the text surrounding the
7185 whitespace. SUBEXP specifies which sub-expression of
7186 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7191 (defvar vhdl-align-try-all-clauses t
7192 "If REGEXP is not found on the first line of the region that clause
7193 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7195 (defun vhdl-do-group (function &optional spacing)
7196 "Apply FUNCTION on group of lines between empty lines."
7198 ;; search for group beginning
7199 ((beg (save-excursion
7200 (if (re-search-backward vhdl-align-group-separate nil t)
7201 (progn (beginning-of-line 2) (back-to-indentation) (point))
7203 ;; search for group end
7204 (end (save-excursion
7205 (if (re-search-forward vhdl-align-group-separate nil t)
7206 (progn (beginning-of-line) (point))
7209 (funcall function beg end spacing)))
7211 (defun vhdl-do-list (function &optional spacing)
7212 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7216 ;; search for beginning of balanced group of parentheses
7217 (setq beg (vhdl-re-search-backward "[()]" nil t))
7218 (while (looking-at ")")
7219 (forward-char) (backward-sexp)
7220 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7221 ;; search for end of balanced group of parentheses
7225 (goto-char (1+ beg))
7226 (skip-chars-forward " \t\n")
7227 (setq beg (point))))
7230 (funcall function beg end spacing)
7231 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7233 (defun vhdl-do-same-indent (function &optional spacing)
7234 "Apply FUNCTION to block of lines with same indent."
7235 (let ((indent (current-indentation))
7237 ;; search for first line with same indent
7239 (while (and (not (bobp))
7240 (or (looking-at "^\\s-*\\(--.*\\)?$")
7241 (= (current-indentation) indent)))
7242 (unless (looking-at "^\\s-*$")
7243 (back-to-indentation) (setq beg (point)))
7244 (beginning-of-line -0)))
7245 ;; search for last line with same indent
7247 (while (and (not (eobp))
7248 (or (looking-at "^\\s-*\\(--.*\\)?$")
7249 (= (current-indentation) indent)))
7250 (if (looking-at "^\\s-*$")
7251 (beginning-of-line 2)
7252 (beginning-of-line 2)
7253 (setq end (point)))))
7255 (funcall function beg end spacing)))
7257 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7258 "Attempt to align a range of lines based on the content of the
7259 lines. The definition of `alignment-list' determines the matching
7260 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7261 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7262 indentation is done before aligning."
7263 (interactive "r\np")
7264 (setq alignment-list (or alignment-list vhdl-align-alist))
7265 (setq spacing (or spacing 1))
7269 (setq end (point-marker))
7271 (setq bol (setq begin (progn (beginning-of-line) (point))))
7272 ; (untabify bol end)
7274 (indent-region bol end nil))))
7275 (let ((copy (copy-alist alignment-list)))
7276 (vhdl-prepare-search-2
7281 (eol (save-excursion (progn (end-of-line) (point)))))
7282 (setq element (nth 0 copy))
7283 (when (and (or (and (listp (car element))
7284 (memq major-mode (car element)))
7285 (eq major-mode (car element)))
7286 (or vhdl-align-try-all-clauses
7287 (re-search-forward (car (cdr element)) eol t)))
7288 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7289 (car (cdr (cdr (cdr element)))) spacing))
7290 (setq copy (cdr copy))))))))
7292 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7293 "Align a range of lines from BEGIN to END. The regular expression
7294 MATCH must match exactly one field: the whitespace to be
7295 contracted/expanded. The alignment column will equal the
7296 rightmost column of the widest whitespace block. SPACING is
7297 the amount of extra spaces to add to the calculated maximum required.
7298 SPACING defaults to 1 so that at least one space is inserted after
7299 the token in MATCH."
7300 (setq spacing (or spacing 1))
7301 (setq substr (or substr 1))
7303 (let (distance (max 0) (lines 0) bol eol width)
7304 ;; Determine the greatest whitespace distance to the alignment
7307 (setq eol (progn (end-of-line) (point))
7308 bol (setq begin (progn (beginning-of-line) (point))))
7311 (when (and (re-search-forward match eol t)
7312 (not (vhdl-in-literal)))
7313 (setq distance (- (match-beginning substr) bol))
7314 (when (> distance max)
7315 (setq max distance))))
7318 eol (save-excursion (end-of-line) (point)))
7319 (setq lines (1+ lines)))
7320 ;; Now insert enough maxs to push each assignment operator to
7321 ;; the same column. We need to use 'lines' as a counter, since
7322 ;; the location of the mark may change
7323 (goto-char (setq bol begin))
7324 (setq eol (save-excursion (end-of-line) (point)))
7326 (when (and (re-search-forward match eol t)
7327 (not (vhdl-in-literal)))
7328 (setq width (- (match-end substr) (match-beginning substr)))
7329 (setq distance (- (match-beginning substr) bol))
7330 (goto-char (match-beginning substr))
7332 (insert-char ? (+ (- max distance) spacing)))
7336 eol (save-excursion (end-of-line) (point)))
7337 (setq lines (1- lines))))))
7339 (defun vhdl-align-region-groups (beg end &optional spacing
7340 no-message no-comments)
7341 "Align region, treat groups of lines separately."
7342 (interactive "r\nP")
7347 (setq orig (point-marker))
7350 (setq end (point-marker))
7353 (when vhdl-progress-interval
7354 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7355 (count-lines (point-min) end) 0))))
7356 (vhdl-fixup-whitespace-region beg end t)
7358 (if (not vhdl-align-groups)
7359 ;; align entire region
7360 (progn (vhdl-align-region-1 beg end spacing)
7362 (vhdl-align-inline-comment-region-1 beg end)))
7364 (while (and (< beg end)
7365 (re-search-forward vhdl-align-group-separate end t))
7366 (setq pos (point-marker))
7367 (vhdl-align-region-1 beg pos spacing)
7368 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7369 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7374 (vhdl-align-region-1 beg end spacing)
7375 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7376 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7377 (when vhdl-indent-tabs-mode
7380 (when vhdl-progress-interval (message "Aligning...done"))
7381 (setq vhdl-progress-info nil)))))
7383 (defun vhdl-align-region (beg end &optional spacing)
7384 "Align region, treat blocks with same indent and argument lists separately."
7385 (interactive "r\nP")
7386 (if (not vhdl-align-same-indent)
7387 ;; align entire region
7388 (vhdl-align-region-groups beg end spacing)
7389 ;; align blocks with same indent and argument lists
7393 (when vhdl-progress-interval
7394 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7395 (count-lines (point-min) end) 0)))
7397 (setq end (point-marker))
7399 (while (< (point) end)
7400 ;; is argument list opening?
7401 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7402 (point) (vhdl-point 'eol)))))
7403 ;; determine region for argument list
7404 (progn (goto-char cur-beg)
7406 (setq cur-end (point))
7407 (beginning-of-line 2))
7408 ;; determine region with same indent
7409 (setq indent (current-indentation))
7410 (setq cur-beg (point))
7411 (setq cur-end (vhdl-point 'bonl))
7412 (beginning-of-line 2)
7413 (while (and (< (point) end)
7414 (or (looking-at "^\\s-*\\(--.*\\)?$")
7415 (= (current-indentation) indent))
7417 (nth 0 (parse-partial-sexp
7418 (point) (vhdl-point 'eol)))) 0))
7419 (unless (looking-at "^\\s-*$")
7420 (setq cur-end (vhdl-point 'bonl)))
7421 (beginning-of-line 2)))
7423 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7424 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7425 (when vhdl-progress-interval (message "Aligning...done"))
7426 (setq vhdl-progress-info nil)))))
7428 (defun vhdl-align-group (&optional spacing)
7429 "Align group of lines between empty lines."
7431 (vhdl-do-group 'vhdl-align-region spacing))
7433 (defun vhdl-align-list (&optional spacing)
7434 "Align the lines of a list surrounded by a balanced group of parentheses."
7436 (vhdl-do-list 'vhdl-align-region-groups spacing))
7438 (defun vhdl-align-same-indent (&optional spacing)
7439 "Align block of lines with same indent."
7441 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7443 (defun vhdl-align-declarations (&optional spacing)
7444 "Align the lines within the declarative part of a design unit."
7447 (vhdl-prepare-search-2
7449 ;; search for declarative part
7450 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7451 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7453 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7454 (setq end (point)))))
7456 (vhdl-align-region-groups beg end spacing)
7457 (error "ERROR: Not within the declarative part of a design unit"))))
7459 (defun vhdl-align-buffer ()
7462 (vhdl-align-region (point-min) (point-max)))
7464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7465 ;; Align inline comments
7467 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7468 "Align inline comments in region."
7470 (let ((start-max comment-column)
7472 comment-list start-list tmp-list start length
7473 cur-start prev-start no-code)
7474 (setq spacing (or spacing 2))
7475 (vhdl-prepare-search-2
7477 ;; search for comment start positions and lengths
7478 (while (< (point) end)
7479 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7480 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7481 (not (save-excursion (goto-char (match-beginning 2))
7482 (vhdl-in-literal))))
7483 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7484 (setq length (- (match-end 2) (match-beginning 2)))
7485 (setq start-max (max start start-max))
7486 (setq length-max (max length length-max))
7487 (setq comment-list (cons (cons start length) comment-list)))
7488 (beginning-of-line 2))
7490 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7491 ;; reduce start positions
7492 (setq start-list (list (caar comment-list)))
7493 (setq comment-list (cdr comment-list))
7495 (unless (or (= (caar comment-list) (car start-list))
7496 (<= (+ (car start-list) (cdar comment-list))
7497 end-comment-column))
7498 (setq start-list (cons (caar comment-list) start-list)))
7499 (setq comment-list (cdr comment-list)))
7500 ;; align lines as nicely as possible
7502 (while (< (point) end)
7503 (setq cur-start nil)
7504 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7505 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7506 (not (save-excursion
7507 (goto-char (match-beginning 3))
7508 (vhdl-in-literal))))
7509 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7510 (>= (- (match-end 2) (match-beginning 2))
7512 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7513 (setq length (- (match-end 3) (match-beginning 3)))
7514 (setq no-code (= (match-beginning 1) (match-end 1)))
7515 ;; insert minimum whitespace
7516 (goto-char (match-end 2))
7517 (delete-region (match-beginning 2) (match-end 2))
7518 (insert-char ?\ spacing)
7519 (setq tmp-list start-list)
7520 ;; insert additional whitespace to align
7523 ;; align comment-only line to inline comment of previous line
7524 ((and no-code prev-start
7525 (<= length (- end-comment-column prev-start)))
7527 ;; align all comments at `start-max' if this is possible
7528 ((<= (+ start-max length-max) end-comment-column)
7530 ;; align at `comment-column' if possible
7531 ((and (<= start comment-column)
7532 (<= length (- end-comment-column comment-column)))
7534 ;; align at left-most possible start position otherwise
7536 (while (and tmp-list (< (car tmp-list) start))
7537 (setq tmp-list (cdr tmp-list)))
7539 (indent-to cur-start))
7540 (setq prev-start cur-start)
7541 (beginning-of-line 2))))))
7543 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7544 "Align inline comments within a region. Groups of code lines separated by
7545 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7546 (interactive "r\nP")
7551 (setq orig (point-marker))
7554 (setq end (point-marker))
7556 (unless no-message (message "Aligning inline comments..."))
7558 (if (not vhdl-align-groups)
7559 ;; align entire region
7560 (vhdl-align-inline-comment-region-1 beg end spacing)
7562 (while (and (< beg end)
7563 (re-search-forward vhdl-align-group-separate end t))
7564 (setq pos (point-marker))
7565 (vhdl-align-inline-comment-region-1 beg pos spacing)
7570 (vhdl-align-inline-comment-region-1 beg end spacing)))
7571 (when vhdl-indent-tabs-mode
7573 (unless no-message (message "Aligning inline comments...done")))))
7575 (defun vhdl-align-inline-comment-group (&optional spacing)
7576 "Align inline comments within a group of lines between empty lines."
7579 (let ((start (point))
7581 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7582 (point-marker) (point-max)))
7584 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7585 (point) (point-min)))
7587 (message "Aligning inline comments...")
7588 (vhdl-align-inline-comment-region-1 beg end)
7589 (when vhdl-indent-tabs-mode
7591 (message "Aligning inline comments...done"))))
7593 (defun vhdl-align-inline-comment-buffer ()
7594 "Align inline comments within buffer. Groups of code lines separated by
7595 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7597 (vhdl-align-inline-comment-region (point-min) (point-max)))
7599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7602 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7603 "Fixup whitespace in region. Surround operator symbols by one space,
7604 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7605 end of line, do nothing in comments and strings."
7607 (unless no-message (message "Fixing up whitespace..."))
7610 (setq end (point-marker))
7611 ;; have no space before and one space after `,' and ';'
7613 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7614 (if (match-string 1)
7615 (goto-char (match-end 1))
7616 (replace-match "\\3 " nil nil nil 3)))
7617 ;; have no space after `('
7619 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7620 (if (match-string 1)
7621 (goto-char (match-end 1))
7622 (replace-match "\\2")))
7623 ;; have no space before `)'
7625 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7626 (if (match-string 1)
7627 (goto-char (match-end 1))
7628 (replace-match "\\2")))
7629 ;; surround operator symbols by one space
7631 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7632 (if (match-string 1)
7633 (goto-char (match-end 1))
7634 (replace-match "\\3 \\4 \\5")
7635 (goto-char (match-end 2))))
7636 ;; eliminate multiple spaces and spaces at end of line
7638 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7639 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7640 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7641 (progn (replace-match "" nil nil) t))
7642 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7643 (progn (replace-match ";" nil nil) t))
7644 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7645 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7646 (progn (replace-match " " nil nil) t))
7647 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7648 (progn (replace-match " " nil nil) t))
7649 ; (re-search-forward "[^ \t-]+" end t))))
7650 (re-search-forward "[^ \t\"-]+" end t))))
7651 (unless no-message (message "Fixing up whitespace...done")))
7653 (defun vhdl-fixup-whitespace-buffer ()
7654 "Fixup whitespace in buffer. Surround operator symbols by one space,
7655 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7656 end of line, do nothing in comments."
7658 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7663 (defun vhdl-beautify-region (beg end)
7664 "Beautify region by applying indentation, whitespace fixup, alignment, and
7665 case fixing to a region. Calls functions `vhdl-indent-buffer',
7666 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7667 `vhdl-fix-case-buffer'."
7669 (setq end (save-excursion (goto-char end) (point-marker)))
7670 (vhdl-indent-region beg end nil)
7671 (let ((vhdl-align-groups t))
7672 (vhdl-align-region beg end))
7673 (vhdl-fix-case-region beg end))
7675 (defun vhdl-beautify-buffer ()
7676 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7677 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7680 (vhdl-beautify-region (point-min) (point-max))
7681 (when noninteractive (save-buffer)))
7683 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7686 (defun vhdl-fill-region (beg end &optional arg)
7687 "Fill lines for a region of code."
7688 (interactive "r\np")
7691 (let ((margin (if arg (current-indentation) (current-column))))
7693 (setq end (point-marker))
7694 ;; remove inline comments, newlines and whitespace
7695 (vhdl-comment-kill-region beg end)
7696 (vhdl-comment-kill-inline-region beg end)
7697 (subst-char-in-region beg (1- end) ?\n ?\ )
7698 (vhdl-fixup-whitespace-region beg end)
7699 ;; wrap and end-comment-column
7701 (while (re-search-forward "\\s-" end t)
7702 (when(> (current-column) vhdl-end-comment-column)
7704 (when (re-search-backward "\\s-" beg t)
7705 (replace-match "\n")
7706 (indent-to margin)))))))
7708 (defun vhdl-fill-group ()
7709 "Fill group of lines between empty lines."
7711 (vhdl-do-group 'vhdl-fill-region))
7713 (defun vhdl-fill-list ()
7714 "Fill the lines of a list surrounded by a balanced group of parentheses."
7716 (vhdl-do-list 'vhdl-fill-region))
7718 (defun vhdl-fill-same-indent ()
7719 "Fill the lines of block of lines with same indent."
7721 (vhdl-do-same-indent 'vhdl-fill-region))
7724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7725 ;;; Code updating/fixing
7726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7729 ;; Sensitivity list update
7732 ;; - no sensitivity list is generated for processes with wait statements
7733 ;; - otherwise, do the following:
7734 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7735 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7736 ;; manually entered global signals)
7737 ;; 3. signals from 1. and 2. form the list of visible signals
7738 ;; 4. search for if/elsif conditions containing an event (sequential code)
7739 ;; 5. scan for strings that are within syntactical regions where signals are
7740 ;; read but not within sequential code, and that correspond to visible
7742 ;; 6. replace sensitivity list by list of signals from 5.
7744 (defun vhdl-update-sensitivity-list-process ()
7745 "Update sensitivity list of current process."
7748 (vhdl-prepare-search-2
7750 ;; look whether in process
7751 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7752 (equal (upcase (match-string 2)) "PROCESS")
7753 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7754 (error "ERROR: Not within a process")
7755 (message "Updating sensitivity list...")
7756 (vhdl-update-sensitivity-list)
7757 (message "Updating sensitivity list...done")))))
7759 (defun vhdl-update-sensitivity-list-buffer ()
7760 "Update sensitivity list of all processes in current buffer."
7763 (vhdl-prepare-search-2
7764 (goto-char (point-min))
7765 (message "Updating sensitivity lists...")
7766 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7767 (goto-char (match-beginning 0))
7768 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7769 (message "Updating sensitivity lists...done"))))
7771 (defun vhdl-update-sensitivity-list ()
7772 "Update sensitivity list."
7773 (let ((proc-beg (point))
7774 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7775 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7778 ;; search for wait statement (no sensitivity list allowed)
7779 ((progn (goto-char proc-mid)
7780 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7781 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7782 ;; combinational process (update sensitivity list)
7785 ;; scan for visible signals
7786 ((visible-list (vhdl-get-visible-signals))
7787 ;; define syntactic regions where signals are read
7789 '(;; right-hand side of signal/variable assignment
7790 ;; (special case: "<=" is relational operator in a condition)
7791 ((re-search-forward "[<:]=" proc-end t)
7792 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7794 ((re-search-forward "^\\s-*if\\>" proc-end t)
7795 (re-search-forward "\\<then\\>" proc-end t))
7797 ((re-search-forward "\\<elsif\\>" proc-end t)
7798 (re-search-forward "\\<then\\>" proc-end t))
7799 ;; while loop condition
7800 ((re-search-forward "^\\s-*while\\>" proc-end t)
7801 (re-search-forward "\\<loop\\>" proc-end t))
7802 ;; exit/next condition
7803 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7804 (re-search-forward ";" proc-end t))
7806 ((re-search-forward "\\<assert\\>" proc-end t)
7807 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7809 ((re-search-forward "^\\s-*case\\>" proc-end t)
7810 (re-search-forward "\\<is\\>" proc-end t))
7811 ;; parameter list of procedure call
7812 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7814 (progn (backward-char) (forward-sexp)
7815 (while (looking-at "(") (forward-sexp)) (point)))))
7816 name read-list sens-list signal-list
7817 sens-beg sens-end beg end margin)
7818 ;; scan for signals in old sensitivity list
7819 (goto-char proc-beg)
7820 (re-search-forward "\\<process\\>" proc-mid t)
7821 (if (not (looking-at "[ \t\n]*("))
7822 (setq sens-beg (point))
7823 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7824 (goto-char (match-end 1))
7826 (setq sens-end (1- (point)))
7827 (goto-char sens-beg)
7828 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7830 (cons (downcase (match-string 0)) sens-list))
7831 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7832 (setq signal-list (append visible-list sens-list))
7833 ;; search for sequential parts
7834 (goto-char proc-mid)
7835 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7836 (setq end (re-search-forward "\\<then\\>" proc-end t))
7837 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7841 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7842 (beginning-of-line)))
7843 ;; scan for signals read in process
7844 (while scan-regions-list
7845 (goto-char proc-mid)
7846 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7847 (setq end (eval (nth 1 (car scan-regions-list)))))
7849 (unless (or (vhdl-in-literal)
7850 (and seq-region-list
7851 (let ((tmp-list seq-region-list))
7852 (while (and tmp-list
7853 (< (point) (caar tmp-list)))
7854 (setq tmp-list (cdr tmp-list)))
7855 (and tmp-list (< (point) (cdar tmp-list))))))
7856 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7857 (setq name (match-string 1))
7858 (when (and (not (match-string 4)) ; not when formal parameter
7859 (not (and (match-string 3) ; not event attribute
7860 (not (member (downcase (match-string 3))
7861 '("event" "last_event" "transaction")))))
7862 (member (downcase name) signal-list))
7863 (unless (member-ignore-case name read-list)
7864 (setq read-list (cons name read-list))))
7865 (goto-char (match-end 1)))))
7866 (setq scan-regions-list (cdr scan-regions-list)))
7867 ;; update sensitivity list
7868 (goto-char sens-beg)
7870 (delete-region sens-beg sens-end)
7872 (insert " ()") (backward-char)))
7873 (setq read-list (sort read-list 'string<))
7875 (setq margin (current-column))
7876 (insert (car read-list))
7877 (setq read-list (cdr read-list))
7880 (if (<= (+ (current-column) (length (car read-list)) 2)
7883 (insert "\n") (indent-to margin))
7884 (insert (car read-list))
7885 (setq read-list (cdr read-list)))))))))
7887 (defun vhdl-get-visible-signals ()
7888 "Get all signals visible in the current block."
7889 (let (beg end signal-list entity-name file-name)
7890 (vhdl-prepare-search-2
7893 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7894 (not (equal "END" (upcase (match-string 1))))
7895 (setq entity-name (match-string 2)))
7896 (error "ERROR: Not within an architecture")))
7897 ;; search for signals declared in entity port clause
7899 (goto-char (point-min))
7900 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7902 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7903 "." (file-name-extension (buffer-file-name)))))
7906 (vhdl-prepare-search-2
7907 (goto-char (point-min))
7908 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7909 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7910 (when (setq beg (re-search-forward
7911 "^\\s-*port[ \t\n]*("
7913 (re-search-forward "^end\\>" nil t)) t))
7914 (setq end (save-excursion
7915 (backward-char) (forward-sexp) (point)))
7916 (vhdl-forward-syntactic-ws)
7917 (while (< (point) end)
7918 (when (looking-at "signal[ \t\n]+")
7919 (goto-char (match-end 0)))
7920 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7922 (cons (downcase (match-string 1)) signal-list))
7923 (goto-char (match-end 0))
7924 (vhdl-forward-syntactic-ws))
7925 (re-search-forward ";" end 1)
7926 (vhdl-forward-syntactic-ws)))))))
7927 ;; search for signals declared in architecture declarative part
7929 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7930 (not (equal "END" (upcase (match-string 1))))
7931 (setq end (re-search-forward "^begin\\>" nil t))))
7932 (error "ERROR: No architecture declarative part found")
7933 ;; scan for all declared signal and alias names
7935 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7936 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7937 (if (match-string 2)
7939 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7941 (cons (downcase (match-string 1)) signal-list))
7942 (goto-char (match-end 0)))
7943 ;; scan alias name, check is alias of (declared) signal
7944 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7945 (member (downcase (match-string 2)) signal-list))
7947 (cons (downcase (match-string 1)) signal-list))
7948 (goto-char (match-end 0))))
7949 (setq beg (point))))))
7950 ;; search for signals declared in surrounding block declarative parts
7952 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7954 (goto-char (match-end 2))
7955 (vhdl-backward-sexp)
7956 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7958 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7959 ;; scan for all declared signal names
7961 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7962 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7963 (if (match-string 2)
7965 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7967 (cons (downcase (match-string 1)) signal-list))
7968 (goto-char (match-end 0)))
7969 ;; scan alias name, check is alias of (declared) signal
7970 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7971 (member (downcase (match-string 2)) signal-list))
7973 (cons (downcase (match-string 1)) signal-list))
7974 (goto-char (match-end 0))))))
7978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7979 ;; Generic/port clause fixing
7981 (defun vhdl-fix-clause ()
7982 "Fix closing parenthesis within generic/port clause."
7985 (vhdl-prepare-search-2
7988 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7989 (error "ERROR: Not within a generic/port clause")
7990 ;; search for end of clause
7991 (goto-char (match-end 0))
7992 (setq beg (1- (point)))
7993 (vhdl-forward-syntactic-ws)
7994 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7995 (goto-char (1- (match-end 0)))
7996 (setq end (point-marker))
7998 (vhdl-forward-syntactic-ws))
8000 (when (> pos (save-excursion (end-of-line) (point)))
8001 (error "ERROR: Not within a generic/port clause"))
8002 ;; delete closing parenthesis on separate line (not supported style)
8003 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8005 (vhdl-backward-syntactic-ws)
8006 (setq end (point-marker))
8008 ;; delete superfluous parentheses
8009 (while (progn (goto-char beg)
8010 (condition-case () (forward-sexp)
8011 (error (goto-char (point-max))))
8013 (delete-backward-char 1))
8014 ;; add closing parenthesis
8015 (when (> (point) end)
8019 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8022 (defun vhdl-remove-trailing-spaces ()
8023 "Remove trailing spaces in the whole buffer."
8027 (goto-char (point-min))
8028 (while (re-search-forward "[ \t]+$" (point-max) t)
8029 (unless (vhdl-in-literal)
8030 (replace-match "" nil nil))))))
8033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8035 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8037 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8038 "Syntax of prompt inserted by template generators.")
8040 (defvar vhdl-template-invoked-by-hook nil
8041 "Indicates whether a template has been invoked by a hook or by key or menu.
8042 Used for undoing after template abortion.")
8044 ;; correct different behavior of function `unread-command-events' in XEmacs
8045 (defun vhdl-character-to-event (arg))
8046 (defalias 'vhdl-character-to-event
8047 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8049 (defun vhdl-work-library ()
8050 "Return the working library name of the current project or \"work\" if no
8051 project is defined."
8052 (vhdl-resolve-env-variable
8053 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8056 ;; Enabling/disabling
8058 (defun vhdl-mode-line-update ()
8059 "Update the modeline string for VHDL major mode."
8060 (setq mode-name (concat "VHDL"
8061 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8062 (and vhdl-electric-mode "e")
8063 (and vhdl-stutter-mode "s")))
8064 (force-mode-line-update t))
8066 (defun vhdl-electric-mode (arg)
8067 "Toggle VHDL electric mode.
8068 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8070 (setq vhdl-electric-mode
8071 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8072 ((> arg 0) t) (t nil)))
8073 (vhdl-mode-line-update))
8075 (defun vhdl-stutter-mode (arg)
8076 "Toggle VHDL stuttering mode.
8077 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8079 (setq vhdl-stutter-mode
8080 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8081 ((> arg 0) t) (t nil)))
8082 (vhdl-mode-line-update))
8084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8087 (defun vhdl-electric-dash (count)
8088 "-- starts a comment, --- draws a horizontal line,
8089 ---- starts a display comment."
8091 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8093 ((and abbrev-start-location (= abbrev-start-location (point)))
8094 (setq abbrev-start-location nil)
8095 (goto-char last-abbrev-location)
8096 (beginning-of-line nil)
8097 (vhdl-comment-display))
8098 ((/= (preceding-char) ?-) ; standard dash (minus)
8099 (self-insert-command count))
8100 (t (self-insert-command count)
8101 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8102 (let ((next-input (read-char)))
8103 (if (= next-input ?-) ; triple dash
8105 (vhdl-comment-display-line)
8107 "Enter '-' for display comment, else continue coding")
8108 (let ((next-input (read-char)))
8109 (if (= next-input ?-) ; four dashes
8110 (vhdl-comment-display t)
8111 (setq unread-command-events ; pushback the char
8112 (list (vhdl-character-to-event next-input))))))
8113 (setq unread-command-events ; pushback the char
8114 (list (vhdl-character-to-event next-input)))
8115 (vhdl-comment-insert)))))
8116 (self-insert-command count)))
8118 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8120 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8121 (if (= (preceding-char) ?\()
8122 (progn (delete-char -1) (insert-char ?\[ 1))
8123 (insert-char ?\( 1))
8124 (self-insert-command count)))
8126 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8128 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8130 (if (= (preceding-char) ?\))
8131 (progn (delete-char -1) (insert-char ?\] 1))
8132 (insert-char ?\) 1))
8133 (blink-matching-open))
8134 (self-insert-command count)))
8136 (defun vhdl-electric-quote (count) "'' --> \""
8138 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8139 (if (= (preceding-char) last-input-event)
8140 (progn (delete-backward-char 1) (insert-char ?\" 1))
8141 (insert-char ?\' 1))
8142 (self-insert-command count)))
8144 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8146 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8147 (cond ((= (preceding-char) last-input-event)
8148 (progn (delete-char -1)
8149 (unless (eq (preceding-char) ? ) (insert " "))
8151 (setq this-command 'vhdl-electric-colon)))
8153 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8154 (progn (delete-char -1) (insert "= ")))
8155 (t (insert-char ?\; 1)))
8156 (self-insert-command count)))
8158 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8160 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8161 (cond ((= (preceding-char) last-input-event)
8162 (progn (delete-char -1)
8163 (unless (eq (preceding-char) ? ) (insert " "))
8165 (t (insert-char ?\, 1)))
8166 (self-insert-command count)))
8168 (defun vhdl-electric-period (count) "'..' --> ' => '"
8170 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8171 (cond ((= (preceding-char) last-input-event)
8172 (progn (delete-char -1)
8173 (unless (eq (preceding-char) ? ) (insert " "))
8175 (t (insert-char ?\. 1)))
8176 (self-insert-command count)))
8178 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8180 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8181 (cond ((= (preceding-char) last-input-event)
8182 (progn (delete-char -1)
8183 (unless (eq (preceding-char) ? ) (insert " "))
8185 (t (insert-char ?\= 1)))
8186 (self-insert-command count)))
8188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8191 (defun vhdl-template-paired-parens ()
8192 "Insert a pair of round parentheses, placing point between them."
8197 (defun vhdl-template-alias ()
8198 "Insert alias declaration."
8200 (let ((start (point)))
8201 (vhdl-insert-keyword "ALIAS ")
8202 (when (vhdl-template-field "name" nil t start (point))
8204 (unless (vhdl-template-field
8205 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8207 (delete-backward-char 3))
8208 (vhdl-insert-keyword " IS ")
8209 (vhdl-template-field "name" ";")
8210 (vhdl-comment-insert-inline))))
8212 (defun vhdl-template-architecture ()
8213 "Insert architecture."
8215 (let ((margin (current-indentation))
8218 (vhdl-insert-keyword "ARCHITECTURE ")
8219 (when (setq arch-name
8220 (vhdl-template-field "name" nil t start (point)))
8221 (vhdl-insert-keyword " OF ")
8223 (vhdl-prepare-search-1
8224 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8225 (insert (match-string 1))
8226 (vhdl-template-field "entity name"))
8227 (vhdl-insert-keyword " IS\n")
8228 (vhdl-template-begin-end
8229 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8230 (memq vhdl-insert-empty-lines '(unit all))))))
8232 (defun vhdl-template-array (kind &optional secondary)
8233 "Insert array type definition."
8235 (let ((start (point)))
8236 (vhdl-insert-keyword "ARRAY (")
8237 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8239 (vhdl-insert-keyword ") OF ")
8240 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8241 (vhdl-insert-keyword ";"))))
8243 (defun vhdl-template-assert ()
8244 "Insert an assertion statement."
8246 (let ((start (point)))
8247 (vhdl-insert-keyword "ASSERT ")
8248 (when vhdl-conditions-in-parenthesis (insert "("))
8249 (when (vhdl-template-field "condition (negated)" nil t start (point))
8250 (when vhdl-conditions-in-parenthesis (insert ")"))
8251 (setq start (point))
8252 (vhdl-insert-keyword " REPORT ")
8253 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8254 (delete-region start (point)))
8255 (setq start (point))
8256 (vhdl-insert-keyword " SEVERITY ")
8257 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8258 (delete-region start (point)))
8261 (defun vhdl-template-attribute ()
8262 "Insert an attribute declaration or specification."
8264 (if (eq (vhdl-decision-query
8265 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8266 (vhdl-template-attribute-spec)
8267 (vhdl-template-attribute-decl)))
8269 (defun vhdl-template-attribute-decl ()
8270 "Insert an attribute declaration."
8272 (let ((start (point)))
8273 (vhdl-insert-keyword "ATTRIBUTE ")
8274 (when (vhdl-template-field "name" " : " t start (point))
8275 (vhdl-template-field "type" ";")
8276 (vhdl-comment-insert-inline))))
8278 (defun vhdl-template-attribute-spec ()
8279 "Insert an attribute specification."
8281 (let ((start (point)))
8282 (vhdl-insert-keyword "ATTRIBUTE ")
8283 (when (vhdl-template-field "name" nil t start (point))
8284 (vhdl-insert-keyword " OF ")
8285 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8286 (vhdl-template-field "entity class")
8287 (vhdl-insert-keyword " IS ")
8288 (vhdl-template-field "expression" ";"))))
8290 (defun vhdl-template-block ()
8293 (let ((margin (current-indentation))
8296 (vhdl-insert-keyword ": BLOCK ")
8298 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8302 (if (vhdl-template-field "[guard expression]" nil t)
8305 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8307 (vhdl-template-begin-end "BLOCK" label margin)
8308 (vhdl-comment-block))))
8310 (defun vhdl-template-block-configuration ()
8311 "Insert a block configuration statement."
8313 (let ((margin (current-indentation))
8315 (vhdl-insert-keyword "FOR ")
8316 (when (vhdl-template-field "block name" nil t start (point))
8317 (vhdl-insert-keyword "\n\n")
8319 (vhdl-insert-keyword "END FOR;")
8321 (indent-to (+ margin vhdl-basic-offset)))))
8323 (defun vhdl-template-break ()
8324 "Insert a break statement."
8327 (vhdl-insert-keyword "BREAK")
8328 (setq position (point))
8331 (progn (vhdl-insert-keyword "FOR ")
8332 (if (vhdl-template-field "[quantity name]" " USE " t)
8333 (progn (vhdl-template-field "quantity name" " => ") t)
8334 (delete-region (point)
8335 (progn (forward-word -1) (point)))
8337 (vhdl-template-field "[quantity name]" " => " t))
8338 (vhdl-template-field "expression")
8339 (setq position (point))
8341 (delete-region position (point))
8342 (unless (vhdl-sequential-statement-p)
8343 (vhdl-insert-keyword " ON ")
8344 (if (vhdl-template-field "[sensitivity list]" nil t)
8345 (setq position (point))
8346 (delete-region position (point))))
8347 (vhdl-insert-keyword " WHEN ")
8348 (when vhdl-conditions-in-parenthesis (insert "("))
8349 (if (vhdl-template-field "[condition]" nil t)
8350 (when vhdl-conditions-in-parenthesis (insert ")"))
8351 (delete-region position (point)))
8354 (defun vhdl-template-case (&optional kind)
8355 "Insert a case statement."
8357 (let ((margin (current-indentation))
8360 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8361 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8362 (vhdl-insert-keyword "CASE ")
8363 (vhdl-insert-keyword ": CASE ")
8365 (setq label (vhdl-template-field "[label]" nil t))
8366 (unless label (delete-char 2))
8369 (when (vhdl-template-field "expression" nil t start (point))
8370 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8372 (vhdl-insert-keyword "END CASE")
8373 (when label (insert " " label))
8376 (indent-to (+ margin vhdl-basic-offset))
8377 (vhdl-insert-keyword "WHEN ")
8378 (let ((position (point)))
8380 (indent-to (+ margin vhdl-basic-offset))
8381 (vhdl-insert-keyword "WHEN OTHERS => null;")
8382 (goto-char position)))))
8384 (defun vhdl-template-case-is ()
8385 "Insert a sequential case statement."
8387 (vhdl-template-case 'is))
8389 (defun vhdl-template-case-use ()
8390 "Insert a simultaneous case statement."
8392 (vhdl-template-case 'use))
8394 (defun vhdl-template-component ()
8395 "Insert a component declaration."
8397 (vhdl-template-component-decl))
8399 (defun vhdl-template-component-conf ()
8400 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8401 since these are almost equivalent)."
8403 (let ((margin (current-indentation))
8404 (result (vhdl-template-configuration-spec t)))
8408 (vhdl-insert-keyword "END FOR;")
8409 (when (eq result 'no-use)
8410 (end-of-line -0)))))
8412 (defun vhdl-template-component-decl ()
8413 "Insert a component declaration."
8415 (let ((margin (current-indentation))
8418 (vhdl-insert-keyword "COMPONENT ")
8419 (when (setq name (vhdl-template-field "name" nil t start (point)))
8420 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8423 (vhdl-insert-keyword "END COMPONENT")
8424 (unless (vhdl-standard-p '87) (insert " " name))
8426 (setq end-column (current-column))
8428 (indent-to (+ margin vhdl-basic-offset))
8429 (vhdl-template-generic-list t t)
8431 (indent-to (+ margin vhdl-basic-offset))
8432 (vhdl-template-port-list t)
8433 (beginning-of-line 2)
8434 (forward-char end-column))))
8436 (defun vhdl-template-component-inst ()
8437 "Insert a component instantiation statement."
8439 (let ((margin (current-indentation))
8442 (when (vhdl-template-field "instance label" nil t start (point))
8444 (if (not (vhdl-use-direct-instantiation))
8445 (vhdl-template-field "component name")
8446 ;; direct instantiation
8447 (setq unit (vhdl-template-field
8448 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8449 (setq unit (upcase (or unit "")))
8450 (cond ((equal unit "ENTITY")
8451 (vhdl-template-field "library name" "." nil nil nil nil
8452 (vhdl-work-library))
8453 (vhdl-template-field "entity name" "(")
8454 (if (vhdl-template-field "[architecture name]" nil t)
8457 ((equal unit "CONFIGURATION")
8458 (vhdl-template-field "library name" "." nil nil nil nil
8459 (vhdl-work-library))
8460 (vhdl-template-field "configuration name"))
8461 (t (vhdl-template-field "component name"))))
8463 (indent-to (+ margin vhdl-basic-offset))
8464 (setq position (point))
8465 (vhdl-insert-keyword "GENERIC ")
8466 (when (vhdl-template-map position t t)
8468 (indent-to (+ margin vhdl-basic-offset)))
8469 (setq position (point))
8470 (vhdl-insert-keyword "PORT ")
8471 (unless (vhdl-template-map position t t)
8472 (delete-region (line-beginning-position) (point))
8476 (defun vhdl-template-conditional-signal-asst ()
8477 "Insert a conditional signal assignment."
8479 (when (vhdl-template-field "target signal")
8481 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8483 (let ((margin (current-column))
8486 (vhdl-template-field "waveform")
8487 (setq position (point))
8488 (vhdl-insert-keyword " WHEN ")
8489 (when vhdl-conditions-in-parenthesis (insert "("))
8490 (while (and (vhdl-template-field "[condition]" nil t)
8492 (when vhdl-conditions-in-parenthesis (insert ")"))
8493 (setq position (point))
8494 (vhdl-insert-keyword " ELSE")
8497 (vhdl-template-field "[waveform]" nil t)))
8498 (setq position (point))
8499 (vhdl-insert-keyword " WHEN ")
8500 (when vhdl-conditions-in-parenthesis (insert "(")))
8501 (delete-region position (point))
8503 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8505 (defun vhdl-template-configuration ()
8506 "Insert a configuration specification if within an architecture,
8507 a block or component configuration if within a configuration declaration,
8508 a configuration declaration if not within a design unit."
8510 (vhdl-prepare-search-1
8512 ((and (save-excursion ; architecture body
8513 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8514 (equal "ARCHITECTURE" (upcase (match-string 1))))
8515 (vhdl-template-configuration-spec))
8516 ((and (save-excursion ; configuration declaration
8517 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8518 (equal "CONFIGURATION" (upcase (match-string 1))))
8519 (if (eq (vhdl-decision-query
8520 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8521 (vhdl-template-component-conf)
8522 (vhdl-template-block-configuration)))
8523 (t (vhdl-template-configuration-decl))))) ; otherwise
8525 (defun vhdl-template-configuration-spec (&optional optional-use)
8526 "Insert a configuration specification."
8528 (let ((margin (current-indentation))
8531 (vhdl-insert-keyword "FOR ")
8532 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8534 (vhdl-template-field "component name" "\n")
8535 (indent-to (+ margin vhdl-basic-offset))
8536 (setq start (point))
8537 (vhdl-insert-keyword "USE ")
8538 (if (and optional-use
8539 (not (setq aspect (vhdl-template-field
8540 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8541 (progn (delete-region start (point)) 'no-use)
8542 (unless optional-use
8543 (setq aspect (vhdl-template-field
8544 "ENTITY | CONFIGURATION | OPEN" " ")))
8545 (setq aspect (upcase (or aspect "")))
8546 (cond ((equal aspect "ENTITY")
8547 (vhdl-template-field "library name" "." nil nil nil nil
8548 (vhdl-work-library))
8549 (vhdl-template-field "entity name" "(")
8550 (if (vhdl-template-field "[architecture name]" nil t)
8554 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8555 (setq position (point))
8556 (vhdl-insert-keyword "GENERIC ")
8557 (when (vhdl-template-map position t t)
8559 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8560 (setq position (point))
8561 (vhdl-insert-keyword "PORT ")
8562 (unless (vhdl-template-map position t t)
8563 (delete-region (line-beginning-position) (point))
8567 ((equal aspect "CONFIGURATION")
8568 (vhdl-template-field "library name" "." nil nil nil nil
8569 (vhdl-work-library))
8570 (vhdl-template-field "configuration name" ";"))
8571 (t (delete-backward-char 1) (insert ";") t))))))
8574 (defun vhdl-template-configuration-decl ()
8575 "Insert a configuration declaration."
8577 (let ((margin (current-indentation))
8579 entity-exists string name position)
8580 (vhdl-insert-keyword "CONFIGURATION ")
8581 (when (setq name (vhdl-template-field "name" nil t start (point)))
8582 (vhdl-insert-keyword " OF ")
8584 (vhdl-prepare-search-1
8585 (setq entity-exists (vhdl-re-search-backward
8586 "\\<entity \\(\\w*\\) is\\>" nil t))
8587 (setq string (match-string 1))))
8588 (if (and entity-exists (not (equal string "")))
8590 (vhdl-template-field "entity name"))
8591 (vhdl-insert-keyword " IS\n")
8592 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8593 (indent-to (+ margin vhdl-basic-offset))
8594 (setq position (point))
8596 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8598 (vhdl-insert-keyword "END ")
8599 (unless (vhdl-standard-p '87)
8600 (vhdl-insert-keyword "CONFIGURATION "))
8602 (goto-char position))))
8604 (defun vhdl-template-constant ()
8605 "Insert a constant declaration."
8607 (let ((start (point))
8608 (in-arglist (vhdl-in-argument-list-p)))
8609 (vhdl-insert-keyword "CONSTANT ")
8610 (when (vhdl-template-field "name" nil t start (point))
8612 (when in-arglist (vhdl-insert-keyword "IN "))
8613 (vhdl-template-field "type")
8616 (vhdl-comment-insert-inline))
8617 (let ((position (point)))
8619 (unless (vhdl-template-field "[initialization]" nil t)
8620 (delete-region position (point)))
8622 (vhdl-comment-insert-inline))))))
8624 (defun vhdl-template-default ()
8633 (defun vhdl-template-default-indent ()
8634 "Insert nothing and indent."
8641 (indent-according-to-mode))
8643 (defun vhdl-template-disconnect ()
8644 "Insert a disconnect statement."
8646 (let ((start (point)))
8647 (vhdl-insert-keyword "DISCONNECT ")
8648 (when (vhdl-template-field "signal names | OTHERS | ALL"
8649 " : " t start (point))
8650 (vhdl-template-field "type")
8651 (vhdl-insert-keyword " AFTER ")
8652 (vhdl-template-field "time expression" ";"))))
8654 (defun vhdl-template-else ()
8655 "Insert an else statement."
8658 (vhdl-prepare-search-1
8659 (vhdl-insert-keyword "ELSE")
8660 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8661 (equal "WHEN" (upcase (match-string 1))))
8663 (indent-according-to-mode)
8664 (setq margin (current-indentation))
8666 (indent-to (+ margin vhdl-basic-offset))))))
8668 (defun vhdl-template-elsif ()
8669 "Insert an elsif statement."
8671 (let ((start (point))
8673 (vhdl-insert-keyword "ELSIF ")
8674 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8675 (when vhdl-conditions-in-parenthesis (insert "("))
8676 (when (vhdl-template-field "condition" nil t start (point))
8677 (when vhdl-conditions-in-parenthesis (insert ")"))
8678 (indent-according-to-mode)
8679 (setq margin (current-indentation))
8680 (vhdl-insert-keyword
8681 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8682 (indent-to (+ margin vhdl-basic-offset))))))
8684 (defun vhdl-template-entity ()
8687 (let ((margin (current-indentation))
8690 (vhdl-insert-keyword "ENTITY ")
8691 (when (setq name (vhdl-template-field "name" nil t start (point)))
8692 (vhdl-insert-keyword " IS\n\n")
8694 (vhdl-insert-keyword "END ")
8695 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8697 (setq end-column (current-column))
8699 (indent-to (+ margin vhdl-basic-offset))
8700 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8701 (indent-to (+ margin vhdl-basic-offset))
8702 (when (vhdl-template-generic-list t)
8703 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8705 (indent-to (+ margin vhdl-basic-offset))
8706 (when (vhdl-template-port-list t)
8707 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8708 (beginning-of-line 2)
8709 (forward-char end-column))))
8711 (defun vhdl-template-exit ()
8712 "Insert an exit statement."
8714 (let ((start (point)))
8715 (vhdl-insert-keyword "EXIT ")
8716 (if (vhdl-template-field "[loop label]" nil t start (point))
8717 (let ((position (point)))
8718 (vhdl-insert-keyword " WHEN ")
8719 (when vhdl-conditions-in-parenthesis (insert "("))
8720 (if (vhdl-template-field "[condition]" nil t)
8721 (when vhdl-conditions-in-parenthesis (insert ")"))
8722 (delete-region position (point))))
8726 (defun vhdl-template-file ()
8727 "Insert a file declaration."
8729 (let ((start (point)))
8730 (vhdl-insert-keyword "FILE ")
8731 (when (vhdl-template-field "name" nil t start (point))
8733 (vhdl-template-field "type")
8734 (unless (vhdl-standard-p '87)
8735 (vhdl-insert-keyword " OPEN ")
8736 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8738 (delete-backward-char 6)))
8739 (vhdl-insert-keyword " IS ")
8740 (when (vhdl-standard-p '87)
8741 (vhdl-template-field "[IN | OUT]" " " t))
8742 (vhdl-template-field "filename-string" nil nil nil nil t)
8744 (vhdl-comment-insert-inline))))
8746 (defun vhdl-template-for ()
8747 "Insert a block or component configuration if within a configuration
8748 declaration, a configuration specification if within an architecture
8749 declarative part (and not within a subprogram), a for-loop if within a
8750 sequential statement part (subprogram or process), and a for-generate
8753 (vhdl-prepare-search-1
8755 ((vhdl-sequential-statement-p) ; sequential statement
8756 (vhdl-template-for-loop))
8757 ((and (save-excursion ; configuration declaration
8758 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8759 (equal "CONFIGURATION" (upcase (match-string 1))))
8760 (if (eq (vhdl-decision-query
8761 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8762 (vhdl-template-component-conf)
8763 (vhdl-template-block-configuration)))
8764 ((and (save-excursion
8765 (re-search-backward ; architecture declarative part
8766 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8767 (equal "ARCHITECTURE" (upcase (match-string 1))))
8768 (vhdl-template-configuration-spec))
8769 (t (vhdl-template-for-generate))))) ; concurrent statement
8771 (defun vhdl-template-for-generate ()
8772 "Insert a for-generate."
8774 (let ((margin (current-indentation))
8777 (vhdl-insert-keyword ": FOR ")
8778 (setq position (point-marker))
8780 (when (setq label (vhdl-template-field "label" nil t start position))
8781 (goto-char position)
8782 (vhdl-template-field "loop variable")
8783 (vhdl-insert-keyword " IN ")
8784 (vhdl-template-field "range")
8785 (vhdl-template-generate-body margin label))))
8787 (defun vhdl-template-for-loop ()
8788 "Insert a for loop."
8790 (let ((margin (current-indentation))
8793 (if (not (eq vhdl-optional-labels 'all))
8794 (vhdl-insert-keyword "FOR ")
8795 (vhdl-insert-keyword ": FOR ")
8797 (setq label (vhdl-template-field "[label]" nil t))
8798 (unless label (delete-char 2))
8801 (when (setq index (vhdl-template-field "loop variable"
8802 nil t start (point)))
8803 (vhdl-insert-keyword " IN ")
8804 (vhdl-template-field "range")
8805 (vhdl-insert-keyword " LOOP\n\n")
8807 (vhdl-insert-keyword "END LOOP")
8809 (insert " " label ";")
8811 (when vhdl-self-insert-comments (insert " -- " index)))
8813 (indent-to (+ margin vhdl-basic-offset)))))
8815 (defun vhdl-template-function (&optional kind)
8816 "Insert a function declaration or body."
8818 (let ((margin (current-indentation))
8821 (vhdl-insert-keyword "FUNCTION ")
8822 (when (setq name (vhdl-template-field "name" nil t start (point)))
8823 (vhdl-template-argument-list t)
8824 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8827 (indent-to (+ margin vhdl-basic-offset))
8828 (vhdl-insert-keyword "RETURN ")
8829 (vhdl-template-field "type")
8830 (if (if kind (eq kind 'body)
8831 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8832 (progn (vhdl-insert-keyword " IS\n")
8833 (vhdl-template-begin-end
8834 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8835 (vhdl-comment-block))
8838 (defun vhdl-template-function-decl ()
8839 "Insert a function declaration."
8841 (vhdl-template-function 'decl))
8843 (defun vhdl-template-function-body ()
8844 "Insert a function declaration."
8846 (vhdl-template-function 'body))
8848 (defun vhdl-template-generate ()
8849 "Insert a generation scheme."
8851 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8852 (vhdl-template-if-generate)
8853 (vhdl-template-for-generate)))
8855 (defun vhdl-template-generic ()
8856 "Insert generic declaration, or generic map in instantiation statements."
8858 (let ((start (point)))
8859 (vhdl-prepare-search-1
8861 ((and (save-excursion ; entity declaration
8862 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8863 (equal "ENTITY" (upcase (match-string 1))))
8864 (vhdl-template-generic-list nil))
8865 ((or (save-excursion
8866 (or (beginning-of-line)
8867 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8868 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8869 (vhdl-insert-keyword "GENERIC ")
8870 (vhdl-template-map start))
8871 (t (vhdl-template-generic-list nil t))))))
8873 (defun vhdl-template-group ()
8874 "Insert group or group template declaration."
8876 (let ((start (point)))
8877 (if (eq (vhdl-decision-query
8878 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8879 (vhdl-template-group-template)
8880 (vhdl-template-group-decl))))
8882 (defun vhdl-template-group-decl ()
8883 "Insert group declaration."
8885 (let ((start (point)))
8886 (vhdl-insert-keyword "GROUP ")
8887 (when (vhdl-template-field "name" " : " t start (point))
8888 (vhdl-template-field "template name" " (")
8889 (vhdl-template-field "constituent list" ");")
8890 (vhdl-comment-insert-inline))))
8892 (defun vhdl-template-group-template ()
8893 "Insert group template declaration."
8895 (let ((start (point)))
8896 (vhdl-insert-keyword "GROUP ")
8897 (when (vhdl-template-field "template name" nil t start (point))
8898 (vhdl-insert-keyword " IS (")
8899 (vhdl-template-field "entity class list" ");")
8900 (vhdl-comment-insert-inline))))
8902 (defun vhdl-template-if ()
8903 "Insert a sequential if statement or an if-generate statement."
8905 (if (vhdl-sequential-statement-p)
8906 (vhdl-template-if-then)
8907 (if (and (vhdl-standard-p 'ams)
8908 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8909 (vhdl-template-if-use)
8910 (vhdl-template-if-generate))))
8912 (defun vhdl-template-if-generate ()
8913 "Insert an if-generate."
8915 (let ((margin (current-indentation))
8918 (vhdl-insert-keyword ": IF ")
8919 (setq position (point-marker))
8921 (when (setq label (vhdl-template-field "label" nil t start position))
8922 (goto-char position)
8923 (when vhdl-conditions-in-parenthesis (insert "("))
8924 (vhdl-template-field "condition")
8925 (when vhdl-conditions-in-parenthesis (insert ")"))
8926 (vhdl-template-generate-body margin label))))
8928 (defun vhdl-template-if-then-use (kind)
8929 "Insert a sequential if statement."
8931 (let ((margin (current-indentation))
8934 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8935 (vhdl-insert-keyword "IF ")
8936 (vhdl-insert-keyword ": IF ")
8938 (setq label (vhdl-template-field "[label]" nil t))
8939 (unless label (delete-char 2))
8942 (when vhdl-conditions-in-parenthesis (insert "("))
8943 (when (vhdl-template-field "condition" nil t start (point))
8944 (when vhdl-conditions-in-parenthesis (insert ")"))
8945 (vhdl-insert-keyword
8946 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8948 (vhdl-insert-keyword "END IF")
8949 (when label (insert " " label))
8952 (indent-to (+ margin vhdl-basic-offset)))))
8954 (defun vhdl-template-if-then ()
8955 "Insert a sequential if statement."
8957 (vhdl-template-if-then-use 'then))
8959 (defun vhdl-template-if-use ()
8960 "Insert a simultaneous if statement."
8962 (vhdl-template-if-then-use 'use))
8964 (defun vhdl-template-instance ()
8965 "Insert a component instantiation statement."
8967 (vhdl-template-component-inst))
8969 (defun vhdl-template-library ()
8970 "Insert a library specification."
8972 (let ((margin (current-indentation))
8975 (vhdl-insert-keyword "LIBRARY ")
8976 (when (setq name (vhdl-template-field "names" nil t start (point)))
8978 (unless (string-match "," name)
8979 (setq end-pos (point))
8982 (vhdl-insert-keyword "USE ")
8984 (vhdl-insert-keyword "..ALL;")
8986 (if (vhdl-template-field "package name")
8988 (delete-region end-pos (+ (point) 5)))))))
8990 (defun vhdl-template-limit ()
8993 (let ((start (point)))
8994 (vhdl-insert-keyword "LIMIT ")
8995 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8997 (vhdl-template-field "type")
8998 (vhdl-insert-keyword " WITH ")
8999 (vhdl-template-field "real expression" ";"))))
9001 (defun vhdl-template-loop ()
9004 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9006 (vhdl-template-while-loop))
9008 (vhdl-template-for-loop))
9009 (t (vhdl-template-bare-loop)))))
9011 (defun vhdl-template-bare-loop ()
9014 (let ((margin (current-indentation))
9017 (if (not (eq vhdl-optional-labels 'all))
9018 (vhdl-insert-keyword "LOOP ")
9019 (vhdl-insert-keyword ": LOOP ")
9021 (setq label (vhdl-template-field "[label]" nil t))
9022 (unless label (delete-char 2))
9027 (vhdl-insert-keyword "END LOOP")
9028 (insert (if label (concat " " label ";") ";"))
9030 (indent-to (+ margin vhdl-basic-offset))))
9032 (defun vhdl-template-map (&optional start optional secondary)
9033 "Insert a map specification with association list."
9035 (let ((start (or start (point)))
9037 (vhdl-insert-keyword "MAP (")
9038 (if (not vhdl-association-list-with-formals)
9039 (if (vhdl-template-field
9040 (concat (and optional "[") "association list" (and optional "]"))
9041 ")" (or (not secondary) optional)
9042 (and (not secondary) start) (point))
9044 (if (and optional secondary) (delete-region start (point)))
9046 (if vhdl-argument-list-indent
9047 (setq margin (current-column))
9048 (setq margin (+ (current-indentation) vhdl-basic-offset))
9051 (if (vhdl-template-field
9052 (concat (and optional "[") "formal" (and optional "]"))
9053 " => " (or (not secondary) optional)
9054 (and (not secondary) start) (point))
9056 (vhdl-template-field "actual" ",")
9057 (setq end-pos (point))
9060 (while (vhdl-template-field "[formal]" " => " t)
9061 (vhdl-template-field "actual" ",")
9062 (setq end-pos (point))
9065 (delete-region end-pos (point))
9066 (delete-backward-char 1)
9068 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9070 (when (and optional secondary) (delete-region start (point)))
9073 (defun vhdl-template-modify (&optional noerror)
9074 "Actualize modification date."
9076 (vhdl-prepare-search-2
9078 (goto-char (point-min))
9079 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9080 (progn (delete-region (point) (progn (end-of-line) (point)))
9081 (vhdl-template-insert-date))
9083 (error "ERROR: Modification date prefix string \"%s\" not found"
9084 vhdl-modify-date-prefix-string))))))
9087 (defun vhdl-template-modify-noerror ()
9088 "Call `vhdl-template-modify' with NOERROR non-nil."
9089 (vhdl-template-modify t))
9091 (defun vhdl-template-nature ()
9092 "Insert a nature declaration."
9094 (let ((start (point))
9095 name mid-pos end-pos)
9096 (vhdl-insert-keyword "NATURE ")
9097 (when (setq name (vhdl-template-field "name" nil t start (point)))
9098 (vhdl-insert-keyword " IS ")
9101 (or (vhdl-template-field
9102 "across type | ARRAY | RECORD")
9104 (cond ((equal definition "")
9106 ((equal definition "ARRAY")
9107 (delete-region (point) (progn (forward-word -1) (point)))
9108 (vhdl-template-array 'nature t))
9109 ((equal definition "RECORD")
9110 (setq mid-pos (point-marker))
9111 (delete-region (point) (progn (forward-word -1) (point)))
9112 (vhdl-template-record 'nature name t))
9114 (vhdl-insert-keyword " ACROSS ")
9115 (vhdl-template-field "through type")
9116 (vhdl-insert-keyword " THROUGH ")
9117 (vhdl-template-field "reference name")
9118 (vhdl-insert-keyword " REFERENCE;")))
9120 (setq end-pos (point-marker))
9123 (vhdl-comment-insert-inline)
9124 (when end-pos (goto-char end-pos))))))
9126 (defun vhdl-template-next ()
9127 "Insert a next statement."
9129 (let ((start (point)))
9130 (vhdl-insert-keyword "NEXT ")
9131 (if (vhdl-template-field "[loop label]" nil t start (point))
9132 (let ((position (point)))
9133 (vhdl-insert-keyword " WHEN ")
9134 (when vhdl-conditions-in-parenthesis (insert "("))
9135 (if (vhdl-template-field "[condition]" nil t)
9136 (when vhdl-conditions-in-parenthesis (insert ")"))
9137 (delete-region position (point))))
9141 (defun vhdl-template-others ()
9142 "Insert an others aggregate."
9144 (let ((start (point)))
9145 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9146 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9147 (vhdl-insert-keyword "OTHERS => '")
9148 (when (vhdl-template-field "value" nil t start (point))
9150 (vhdl-insert-keyword "OTHERS "))))
9152 (defun vhdl-template-package (&optional kind)
9153 "Insert a package specification or body."
9155 (let ((margin (current-indentation))
9158 (vhdl-insert-keyword "PACKAGE ")
9159 (setq body (if kind (eq kind 'body)
9160 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9162 (vhdl-insert-keyword "BODY ")
9163 (when (save-excursion
9164 (vhdl-prepare-search-1
9165 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9166 (insert (setq name (match-string 1)))))
9168 (setq name (vhdl-template-field "name" nil t start (point))))
9169 (vhdl-insert-keyword " IS\n")
9170 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9171 (indent-to (+ margin vhdl-basic-offset))
9172 (setq position (point))
9174 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9176 (vhdl-insert-keyword "END ")
9177 (unless (vhdl-standard-p '87)
9178 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9179 (insert (or name "") ";")
9180 (goto-char position))))
9182 (defun vhdl-template-package-decl ()
9183 "Insert a package specification."
9185 (vhdl-template-package 'decl))
9187 (defun vhdl-template-package-body ()
9188 "Insert a package body."
9190 (vhdl-template-package 'body))
9192 (defun vhdl-template-port ()
9193 "Insert a port declaration, or port map in instantiation statements."
9195 (let ((start (point)))
9196 (vhdl-prepare-search-1
9198 ((and (save-excursion ; entity declaration
9199 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9200 (equal "ENTITY" (upcase (match-string 1))))
9201 (vhdl-template-port-list nil))
9202 ((or (save-excursion
9203 (or (beginning-of-line)
9204 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9205 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9206 (vhdl-insert-keyword "PORT ")
9207 (vhdl-template-map start))
9208 (t (vhdl-template-port-list nil))))))
9210 (defun vhdl-template-procedural ()
9211 "Insert a procedural."
9213 (let ((margin (current-indentation))
9215 (case-fold-search t)
9217 (vhdl-insert-keyword "PROCEDURAL ")
9218 (when (memq vhdl-optional-labels '(process all))
9222 (setq label (vhdl-template-field "[label]" nil t))
9223 (unless label (delete-char 2))
9226 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9228 (vhdl-template-begin-end "PROCEDURAL" label margin)
9229 (vhdl-comment-block)))
9231 (defun vhdl-template-procedure (&optional kind)
9232 "Insert a procedure declaration or body."
9234 (let ((margin (current-indentation))
9237 (vhdl-insert-keyword "PROCEDURE ")
9238 (when (setq name (vhdl-template-field "name" nil t start (point)))
9239 (vhdl-template-argument-list)
9240 (if (if kind (eq kind 'body)
9241 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9242 (progn (vhdl-insert-keyword " IS")
9243 (when vhdl-auto-align
9244 (vhdl-align-region-groups start (point) 1))
9245 (end-of-line) (insert "\n")
9246 (vhdl-template-begin-end
9247 (unless (vhdl-standard-p '87) "PROCEDURE")
9249 (vhdl-comment-block))
9251 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9254 (defun vhdl-template-procedure-decl ()
9255 "Insert a procedure declaration."
9257 (vhdl-template-procedure 'decl))
9259 (defun vhdl-template-procedure-body ()
9260 "Insert a procedure body."
9262 (vhdl-template-procedure 'body))
9264 (defun vhdl-template-process (&optional kind)
9267 (let ((margin (current-indentation))
9269 label seq input-signals clock reset final-pos)
9270 (setq seq (if kind (eq kind 'seq)
9271 (eq (vhdl-decision-query
9272 "process" "(c)ombinational or (s)equential?" t) ?s)))
9273 (vhdl-insert-keyword "PROCESS ")
9274 (when (memq vhdl-optional-labels '(process all))
9278 (setq label (vhdl-template-field "[label]" nil t))
9279 (unless label (delete-char 2))
9284 (unless (setq input-signals
9285 (vhdl-template-field "[sensitivity list]" ")" t))
9286 (setq input-signals "")
9288 (setq clock (or (and (not (equal "" vhdl-clock-name))
9289 (progn (insert vhdl-clock-name) vhdl-clock-name))
9290 (vhdl-template-field "clock name") "<clock>"))
9291 (when (eq vhdl-reset-kind 'async)
9293 (setq reset (or (and (not (equal "" vhdl-reset-name))
9294 (progn (insert vhdl-reset-name) vhdl-reset-name))
9295 (vhdl-template-field "reset name") "<reset>")))
9297 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9299 (vhdl-template-begin-end "PROCESS" label margin)
9300 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9301 (when vhdl-prompt-for-comments
9302 (setq final-pos (point-marker))
9303 (vhdl-prepare-search-2
9304 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9305 (vhdl-re-search-backward "\\<process\\>" nil t))
9308 (progn (insert "\n") (forward-line -1))
9311 (insert "-- purpose: ")
9312 (if (not (vhdl-template-field "[description]" nil t))
9313 (vhdl-line-kill-entire)
9316 (insert "-- type : ")
9317 (insert (if seq "sequential" "combinational") "\n")
9319 (insert "-- inputs : ")
9321 (insert input-signals)
9323 (when reset (insert reset ", "))
9324 (unless (vhdl-template-field "[signal names]" nil t)
9328 (insert "-- outputs: ")
9329 (vhdl-template-field "[signal names]" nil t))))
9330 (goto-char final-pos))))
9332 (defun vhdl-template-process-comb ()
9333 "Insert a combinational process."
9335 (vhdl-template-process 'comb))
9337 (defun vhdl-template-process-seq ()
9338 "Insert a sequential process."
9340 (vhdl-template-process 'seq))
9342 (defun vhdl-template-quantity ()
9343 "Insert a quantity declaration."
9345 (if (vhdl-in-argument-list-p)
9346 (let ((start (point)))
9347 (vhdl-insert-keyword "QUANTITY ")
9348 (when (vhdl-template-field "names" nil t start (point))
9350 (vhdl-template-field "[IN | OUT]" " " t)
9351 (vhdl-template-field "type")
9353 (vhdl-comment-insert-inline)))
9354 (let ((char (vhdl-decision-query
9355 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9356 (cond ((eq char ?f) (vhdl-template-quantity-free))
9357 ((eq char ?b) (vhdl-template-quantity-branch))
9358 ((eq char ?s) (vhdl-template-quantity-source))
9359 (t (vhdl-template-undo (point) (point)))))))
9361 (defun vhdl-template-quantity-free ()
9362 "Insert a free quantity declaration."
9364 (vhdl-insert-keyword "QUANTITY ")
9365 (vhdl-template-field "names")
9367 (vhdl-template-field "type")
9368 (let ((position (point)))
9370 (unless (vhdl-template-field "[initialization]" nil t)
9371 (delete-region position (point)))
9373 (vhdl-comment-insert-inline)))
9375 (defun vhdl-template-quantity-branch ()
9376 "Insert a branch quantity declaration."
9379 (vhdl-insert-keyword "QUANTITY ")
9380 (when (vhdl-template-field "[across names]" " " t)
9381 (vhdl-insert-keyword "ACROSS "))
9382 (when (vhdl-template-field "[through names]" " " t)
9383 (vhdl-insert-keyword "THROUGH "))
9384 (vhdl-template-field "plus terminal name")
9385 (setq position (point))
9386 (vhdl-insert-keyword " TO ")
9387 (unless (vhdl-template-field "[minus terminal name]" nil t)
9388 (delete-region position (point)))
9390 (vhdl-comment-insert-inline)))
9392 (defun vhdl-template-quantity-source ()
9393 "Insert a source quantity declaration."
9395 (vhdl-insert-keyword "QUANTITY ")
9396 (vhdl-template-field "names")
9398 (vhdl-template-field "type" " ")
9399 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9400 (progn (vhdl-insert-keyword "NOISE ")
9401 (vhdl-template-field "power expression"))
9402 (vhdl-insert-keyword "SPECTRUM ")
9403 (vhdl-template-field "magnitude expression" ", ")
9404 (vhdl-template-field "phase expression"))
9406 (vhdl-comment-insert-inline))
9408 (defun vhdl-template-record (kind &optional name secondary)
9409 "Insert a record type declaration."
9411 (let ((margin (current-column))
9414 (vhdl-insert-keyword "RECORD\n")
9415 (indent-to (+ margin vhdl-basic-offset))
9416 (when (or (vhdl-template-field "element names"
9417 nil (not secondary) start (point))
9419 (while (or first (vhdl-template-field "[element names]" nil t))
9421 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9422 (vhdl-comment-insert-inline)
9424 (indent-to (+ margin vhdl-basic-offset))
9426 (delete-region (line-beginning-position) (point))
9428 (vhdl-insert-keyword "END RECORD")
9429 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9431 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9433 (defun vhdl-template-report ()
9434 "Insert a report statement."
9436 (let ((start (point)))
9437 (vhdl-insert-keyword "REPORT ")
9438 (if (equal "\"\"" (vhdl-template-field
9439 "string expression" nil t start (point) t))
9440 (delete-backward-char 2)
9441 (setq start (point))
9442 (vhdl-insert-keyword " SEVERITY ")
9443 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9444 (delete-region start (point)))
9447 (defun vhdl-template-return ()
9448 "Insert a return statement."
9450 (let ((start (point)))
9451 (vhdl-insert-keyword "RETURN ")
9452 (unless (vhdl-template-field "[expression]" nil t start (point))
9456 (defun vhdl-template-selected-signal-asst ()
9457 "Insert a selected signal assignment."
9459 (let ((margin (current-indentation))
9462 (let ((position (point)))
9463 (vhdl-insert-keyword " SELECT ")
9464 (goto-char position))
9465 (vhdl-insert-keyword "WITH ")
9466 (when (vhdl-template-field "selector expression"
9467 nil t start (+ (point) 7))
9471 (indent-to (+ margin vhdl-basic-offset))
9472 (vhdl-template-field "target signal" " <= ")
9473 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9475 (indent-to (+ margin vhdl-basic-offset))
9476 (vhdl-template-field "waveform")
9477 (vhdl-insert-keyword " WHEN ")
9478 (vhdl-template-field "choices" ",")
9480 (indent-to (+ margin vhdl-basic-offset))
9481 (while (and choices (vhdl-template-field "[waveform]" nil t))
9482 (vhdl-insert-keyword " WHEN ")
9483 (if (setq choices (vhdl-template-field "[choices]" "," t))
9484 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9485 (vhdl-insert-keyword "OTHERS")))
9490 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9492 (defun vhdl-template-signal ()
9493 "Insert a signal declaration."
9495 (let ((start (point))
9496 (in-arglist (vhdl-in-argument-list-p)))
9497 (vhdl-insert-keyword "SIGNAL ")
9498 (when (vhdl-template-field "names" nil t start (point))
9500 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9501 (vhdl-template-field "type")
9504 (vhdl-comment-insert-inline))
9505 (let ((position (point)))
9507 (unless (vhdl-template-field "[initialization]" nil t)
9508 (delete-region position (point)))
9510 (vhdl-comment-insert-inline))))))
9512 (defun vhdl-template-subnature ()
9513 "Insert a subnature declaration."
9515 (let ((start (point))
9517 (vhdl-insert-keyword "SUBNATURE ")
9518 (when (vhdl-template-field "name" nil t start (point))
9519 (vhdl-insert-keyword " IS ")
9520 (vhdl-template-field "nature" " (")
9521 (if (vhdl-template-field "[index range]" nil t)
9524 (setq position (point))
9525 (vhdl-insert-keyword " TOLERANCE ")
9526 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9528 (delete-region position (point))
9529 (vhdl-insert-keyword " ACROSS ")
9530 (vhdl-template-field "string expression" nil nil nil nil t)
9531 (vhdl-insert-keyword " THROUGH"))
9533 (vhdl-comment-insert-inline))))
9535 (defun vhdl-template-subprogram-body ()
9536 "Insert a subprogram body."
9538 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9539 (vhdl-template-function-body)
9540 (vhdl-template-procedure-body)))
9542 (defun vhdl-template-subprogram-decl ()
9543 "Insert a subprogram declaration."
9545 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9546 (vhdl-template-function-decl)
9547 (vhdl-template-procedure-decl)))
9549 (defun vhdl-template-subtype ()
9550 "Insert a subtype declaration."
9552 (let ((start (point)))
9553 (vhdl-insert-keyword "SUBTYPE ")
9554 (when (vhdl-template-field "name" nil t start (point))
9555 (vhdl-insert-keyword " IS ")
9556 (vhdl-template-field "type" " ")
9558 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9561 (vhdl-comment-insert-inline))))
9563 (defun vhdl-template-terminal ()
9564 "Insert a terminal declaration."
9566 (let ((start (point)))
9567 (vhdl-insert-keyword "TERMINAL ")
9568 (when (vhdl-template-field "names" nil t start (point))
9570 (vhdl-template-field "nature")
9572 (vhdl-comment-insert-inline))))
9574 (defun vhdl-template-type ()
9575 "Insert a type declaration."
9577 (let ((start (point))
9578 name mid-pos end-pos)
9579 (vhdl-insert-keyword "TYPE ")
9580 (when (setq name (vhdl-template-field "name" nil t start (point)))
9581 (vhdl-insert-keyword " IS ")
9584 (or (vhdl-template-field
9585 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9587 (cond ((equal definition "")
9588 (delete-backward-char 4)
9590 ((equal definition "ARRAY")
9591 (delete-region (point) (progn (forward-word -1) (point)))
9592 (vhdl-template-array 'type t))
9593 ((equal definition "RECORD")
9594 (setq mid-pos (point-marker))
9595 (delete-region (point) (progn (forward-word -1) (point)))
9596 (vhdl-template-record 'type name t))
9597 ((equal definition "ACCESS")
9599 (vhdl-template-field "type" ";"))
9600 ((equal definition "FILE")
9601 (vhdl-insert-keyword " OF ")
9602 (vhdl-template-field "type" ";"))
9605 (setq end-pos (point-marker))
9608 (vhdl-comment-insert-inline)
9609 (when end-pos (goto-char end-pos))))))
9611 (defun vhdl-template-use ()
9612 "Insert a use clause."
9614 (let ((start (point)))
9615 (vhdl-prepare-search-1
9616 (vhdl-insert-keyword "USE ")
9617 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9618 (vhdl-insert-keyword "..ALL;")
9620 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9622 (vhdl-template-field "package name")
9623 (forward-char 5))))))
9625 (defun vhdl-template-variable ()
9626 "Insert a variable declaration."
9628 (let ((start (point))
9629 (in-arglist (vhdl-in-argument-list-p)))
9630 (vhdl-prepare-search-2
9631 (if (or (save-excursion
9632 (and (vhdl-re-search-backward
9633 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9635 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9636 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9637 (vhdl-insert-keyword "VARIABLE ")
9638 (vhdl-insert-keyword "SHARED VARIABLE ")))
9639 (when (vhdl-template-field "names" nil t start (point))
9641 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9642 (vhdl-template-field "type")
9645 (vhdl-comment-insert-inline))
9646 (let ((position (point)))
9648 (unless (vhdl-template-field "[initialization]" nil t)
9649 (delete-region position (point)))
9651 (vhdl-comment-insert-inline))))))
9653 (defun vhdl-template-wait ()
9654 "Insert a wait statement."
9656 (vhdl-insert-keyword "WAIT ")
9657 (unless (vhdl-template-field
9658 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9663 (defun vhdl-template-when ()
9664 "Indent correctly if within a case statement."
9666 (let ((position (point))
9668 (vhdl-prepare-search-2
9669 (if (and (= (current-column) (current-indentation))
9670 (vhdl-re-search-forward "\\<end\\>" nil t)
9671 (looking-at "\\s-*\\<case\\>"))
9673 (setq margin (current-indentation))
9674 (goto-char position)
9675 (delete-horizontal-space)
9676 (indent-to (+ margin vhdl-basic-offset)))
9677 (goto-char position)))
9678 (vhdl-insert-keyword "WHEN ")))
9680 (defun vhdl-template-while-loop ()
9681 "Insert a while loop."
9683 (let* ((margin (current-indentation))
9686 (if (not (eq vhdl-optional-labels 'all))
9687 (vhdl-insert-keyword "WHILE ")
9688 (vhdl-insert-keyword ": WHILE ")
9690 (setq label (vhdl-template-field "[label]" nil t))
9691 (unless label (delete-char 2))
9694 (when vhdl-conditions-in-parenthesis (insert "("))
9695 (when (vhdl-template-field "condition" nil t start (point))
9696 (when vhdl-conditions-in-parenthesis (insert ")"))
9697 (vhdl-insert-keyword " LOOP\n\n")
9699 (vhdl-insert-keyword "END LOOP")
9700 (insert (if label (concat " " label ";") ";"))
9702 (indent-to (+ margin vhdl-basic-offset)))))
9704 (defun vhdl-template-with ()
9705 "Insert a with statement (i.e. selected signal assignment)."
9707 (vhdl-prepare-search-1
9708 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9709 (equal ";" (match-string 1)))
9710 (vhdl-template-selected-signal-asst)
9711 (vhdl-insert-keyword "WITH "))))
9713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9714 ;; Special templates
9716 (defun vhdl-template-clocked-wait ()
9717 "Insert a wait statement for rising/falling clock edge."
9719 (let ((start (point))
9721 (vhdl-insert-keyword "WAIT UNTIL ")
9723 (or (and (not (equal "" vhdl-clock-name))
9724 (progn (insert vhdl-clock-name) vhdl-clock-name))
9725 (vhdl-template-field "clock name" nil t start (point))))
9727 (vhdl-insert-keyword " AND ")
9730 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9731 (vhdl-comment-insert-inline
9732 (concat (if vhdl-clock-rising-edge "rising" "falling")
9735 (defun vhdl-template-seq-process (clock reset)
9736 "Insert a template for the body of a sequential process."
9737 (let ((margin (current-indentation))
9739 (vhdl-insert-keyword "IF ")
9740 (when (eq vhdl-reset-kind 'async)
9742 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9743 (vhdl-insert-keyword " THEN")
9744 (vhdl-comment-insert-inline
9745 (concat "asynchronous reset (active "
9746 (if vhdl-reset-active-high "high" "low") ")"))
9747 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9748 (setq position (point))
9749 (insert "\n") (indent-to margin)
9750 (vhdl-insert-keyword "ELSIF "))
9751 (if (eq vhdl-clock-edge-condition 'function)
9752 (insert (if vhdl-clock-rising-edge "rising" "falling")
9754 (insert clock "'event")
9755 (vhdl-insert-keyword " AND ")
9757 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9758 (vhdl-insert-keyword " THEN")
9759 (vhdl-comment-insert-inline
9760 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9761 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9762 (when (eq vhdl-reset-kind 'sync)
9763 (vhdl-insert-keyword "IF ")
9764 (setq reset (or (and (not (equal "" vhdl-reset-name))
9765 (progn (insert vhdl-reset-name) vhdl-reset-name))
9766 (vhdl-template-field "reset name") "<reset>"))
9768 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9769 (vhdl-insert-keyword " THEN")
9770 (vhdl-comment-insert-inline
9771 (concat "synchronous reset (active "
9772 (if vhdl-reset-active-high "high" "low") ")"))
9773 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9774 (setq position (point))
9775 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9776 (vhdl-insert-keyword "ELSE")
9777 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9778 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9779 (vhdl-insert-keyword "END IF;"))
9780 (when (eq vhdl-reset-kind 'none)
9781 (setq position (point)))
9782 (insert "\n") (indent-to margin)
9783 (vhdl-insert-keyword "END IF;")
9784 (goto-char position)
9787 (defun vhdl-template-standard-package (library package)
9788 "Insert specification of a standard package. Include a library
9789 specification, if not already there."
9790 (let ((margin (current-indentation)))
9791 (unless (equal library "std")
9792 (unless (or (save-excursion
9793 (vhdl-prepare-search-1
9796 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9797 library "\\|end\\)\\>") nil t)
9799 (equal (downcase library) "work"))
9800 (vhdl-insert-keyword "LIBRARY ")
9801 (insert library ";")
9804 (indent-to margin)))
9806 (vhdl-insert-keyword "USE ")
9807 (insert library "." package)
9808 (vhdl-insert-keyword ".ALL;")))))
9810 (defun vhdl-template-package-math-complex ()
9811 "Insert specification of `math_complex' package."
9813 (vhdl-template-standard-package "ieee" "math_complex"))
9815 (defun vhdl-template-package-math-real ()
9816 "Insert specification of `math_real' package."
9818 (vhdl-template-standard-package "ieee" "math_real"))
9820 (defun vhdl-template-package-numeric-bit ()
9821 "Insert specification of `numeric_bit' package."
9823 (vhdl-template-standard-package "ieee" "numeric_bit"))
9825 (defun vhdl-template-package-numeric-std ()
9826 "Insert specification of `numeric_std' package."
9828 (vhdl-template-standard-package "ieee" "numeric_std"))
9830 (defun vhdl-template-package-std-logic-1164 ()
9831 "Insert specification of `std_logic_1164' package."
9833 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9835 (defun vhdl-template-package-std-logic-arith ()
9836 "Insert specification of `std_logic_arith' package."
9838 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9840 (defun vhdl-template-package-std-logic-misc ()
9841 "Insert specification of `std_logic_misc' package."
9843 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9845 (defun vhdl-template-package-std-logic-signed ()
9846 "Insert specification of `std_logic_signed' package."
9848 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9850 (defun vhdl-template-package-std-logic-textio ()
9851 "Insert specification of `std_logic_textio' package."
9853 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9855 (defun vhdl-template-package-std-logic-unsigned ()
9856 "Insert specification of `std_logic_unsigned' package."
9858 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9860 (defun vhdl-template-package-textio ()
9861 "Insert specification of `textio' package."
9863 (vhdl-template-standard-package "std" "textio"))
9865 (defun vhdl-template-directive (directive)
9867 (unless (= (current-indentation) (current-column))
9868 (delete-horizontal-space)
9870 (insert "-- pragma " directive))
9872 (defun vhdl-template-directive-translate-on ()
9873 "Insert directive 'translate_on'."
9875 (vhdl-template-directive "translate_on"))
9877 (defun vhdl-template-directive-translate-off ()
9878 "Insert directive 'translate_off'."
9880 (vhdl-template-directive "translate_off"))
9882 (defun vhdl-template-directive-synthesis-on ()
9883 "Insert directive 'synthesis_on'."
9885 (vhdl-template-directive "synthesis_on"))
9887 (defun vhdl-template-directive-synthesis-off ()
9888 "Insert directive 'synthesis_off'."
9890 (vhdl-template-directive "synthesis_off"))
9892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9893 ;; Header and footer templates
9895 (defun vhdl-template-header (&optional file-title)
9896 "Insert a VHDL file header."
9898 (unless (equal vhdl-file-header "")
9901 (goto-char (point-min))
9902 (vhdl-insert-string-or-file vhdl-file-header)
9903 (setq pos (point-marker)))
9904 (vhdl-template-replace-header-keywords
9905 (point-min-marker) pos file-title))))
9907 (defun vhdl-template-footer ()
9908 "Insert a VHDL file footer."
9910 (unless (equal vhdl-file-footer "")
9913 (goto-char (point-max))
9914 (setq pos (point-marker))
9915 (vhdl-insert-string-or-file vhdl-file-footer)
9916 (unless (= (preceding-char) ?\n)
9918 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9920 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9922 "Replace keywords in header and footer."
9923 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9924 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9926 (vhdl-prepare-search-2
9929 (while (search-forward "<projectdesc>" end t)
9930 (replace-match project-desc t t))
9932 (while (search-forward "<filename>" end t)
9933 (replace-match (buffer-name) t t))
9935 (while (search-forward "<copyright>" end t)
9936 (replace-match vhdl-copyright-string t t))
9938 (while (search-forward "<author>" end t)
9939 (replace-match "" t t)
9940 (insert (user-full-name))
9941 (when user-mail-address (insert " <" user-mail-address ">")))
9943 (while (search-forward "<login>" end t)
9944 (replace-match (user-login-name) t t))
9946 (while (search-forward "<project>" end t)
9947 (replace-match project-title t t))
9949 (while (search-forward "<company>" end t)
9950 (replace-match vhdl-company-name t t))
9952 (while (search-forward "<platform>" end t)
9953 (replace-match vhdl-platform-spec t t))
9955 (while (search-forward "<standard>" end t)
9957 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9958 ((vhdl-standard-p '93) "'93"))
9959 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9960 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9962 ;; Replace <RCS> with $, so that RCS for the source is
9963 ;; not over-enthusiastic with replacements
9964 (while (search-forward "<RCS>" end t)
9965 (replace-match "$" nil t))
9967 (while (search-forward "<date>" end t)
9968 (replace-match "" t t)
9969 (vhdl-template-insert-date))
9971 (while (search-forward "<year>" end t)
9972 (replace-match (format-time-string "%Y" nil) t t))
9975 (while (search-forward "<title string>" end t)
9976 (replace-match file-title t t))
9980 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9981 (setq string (read-string (concat (match-string 1) ": ")))
9982 (replace-match string t t)))
9984 (when (and (not is-model) (search-forward "<cursor>" end t))
9985 (replace-match "" t t)
9986 (setq pos (point))))
9987 (when pos (goto-char pos))
9989 (when (or (not project-title) (equal project-title ""))
9990 (message "You can specify a project title in user option `vhdl-project-alist'"))
9991 (when (or (not project-desc) (equal project-desc ""))
9992 (message "You can specify a project description in user option `vhdl-project-alist'"))
9993 (when (equal vhdl-platform-spec "")
9994 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9995 (when (equal vhdl-company-name "")
9996 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9999 ;; Comment templates and functions
10001 (defun vhdl-comment-indent ()
10003 (let* ((position (point))
10007 (if (re-search-forward "--" position t)
10008 (- (current-column) 2) ; existing comment at bol stays there
10009 (goto-char position)
10010 (skip-chars-backward " \t")
10011 (max comment-column ; else indent to comment column
10012 (1+ (current-column))))))) ; except leave at least one space
10013 (goto-char position)
10016 (defun vhdl-comment-insert ()
10017 "Start a comment at the end of the line.
10018 If on line with code, indent at least `comment-column'.
10019 If starting after end-comment-column, start a new line."
10021 (when (> (current-column) end-comment-column) (newline-and-indent))
10022 (if (or (looking-at "\\s-*$") ; end of line
10023 (and (not unread-command-events) ; called with key binding or menu
10024 (not (end-of-line))))
10026 (while (= (preceding-char) ?-) (delete-char -1))
10027 (setq margin (current-column))
10028 (delete-horizontal-space)
10030 (progn (indent-to margin) (insert "--"))
10032 (indent-to comment-column)
10034 (if (not unread-command-events) (insert " ")))
10035 ;; else code following current point implies commenting out code
10036 (let (next-input code)
10037 (while (= (preceding-char) ?-) (delete-char -2))
10038 (while (= (setq next-input (read-char)) 13) ; CR
10039 (insert "--") ; or have a space after it?
10042 (message "Enter CR if commenting out a line of code.")
10045 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10046 (setq unread-command-events
10047 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10049 (defun vhdl-comment-display (&optional line-exists)
10050 "Add 2 comment lines at the current indent, making a display comment."
10052 (let ((margin (current-indentation)))
10053 (unless line-exists (vhdl-comment-display-line))
10054 (insert "\n") (indent-to margin)
10055 (insert "\n") (indent-to margin)
10056 (vhdl-comment-display-line)
10060 (defun vhdl-comment-display-line ()
10061 "Displays one line of dashes."
10063 (while (= (preceding-char) ?-) (delete-char -2))
10064 (let* ((col (current-column))
10065 (len (- end-comment-column col)))
10066 (insert-char ?- len)))
10068 (defun vhdl-comment-append-inline ()
10069 "Append empty inline comment to current line."
10072 (delete-horizontal-space)
10074 (indent-to comment-column)
10077 (defun vhdl-comment-insert-inline (&optional string always-insert)
10078 "Insert inline comment."
10079 (when (or (and string (or vhdl-self-insert-comments always-insert))
10080 (and (not string) vhdl-prompt-for-comments))
10081 (let ((position (point)))
10083 (indent-to comment-column)
10085 (if (not (or (and string (progn (insert string) t))
10086 (vhdl-template-field "[comment]" nil t)))
10087 (delete-region position (point))
10088 (while (= (preceding-char) ? ) (delete-backward-char 1))
10089 ; (when (> (current-column) end-comment-column)
10090 ; (setq position (point-marker))
10091 ; (re-search-backward "-- ")
10093 ; (indent-to comment-column)
10094 ; (goto-char position))
10097 (defun vhdl-comment-block ()
10098 "Insert comment for code block."
10099 (when vhdl-prompt-for-comments
10100 (let ((final-pos (point-marker)))
10101 (vhdl-prepare-search-2
10102 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10103 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10105 (back-to-indentation)
10106 (setq margin (current-column))
10109 (progn (insert "\n") (forward-line -1))
10112 (insert "-- purpose: ")
10113 (unless (vhdl-template-field "[description]" nil t)
10114 (vhdl-line-kill-entire)))))
10115 (goto-char final-pos))))
10117 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10118 "Comment out region if not commented out, uncomment otherwise."
10119 (interactive "r\nP")
10121 (goto-char (1- end))
10123 (setq end (point-marker))
10125 (beginning-of-line)
10127 (if (looking-at comment-start)
10128 (comment-region beg end '(4))
10129 (comment-region beg end))))
10131 (defun vhdl-comment-uncomment-line (&optional arg)
10132 "Comment out line if not commented out, uncomment otherwise."
10135 (beginning-of-line)
10136 (let ((position (point)))
10137 (forward-line (or arg 1))
10138 (vhdl-comment-uncomment-region position (point)))))
10140 (defun vhdl-comment-kill-region (beg end)
10141 "Kill comments in region."
10145 (setq end (point-marker))
10147 (beginning-of-line)
10148 (while (< (point) end)
10149 (if (looking-at "^\\(\\s-*--.*\n\\)")
10150 (progn (delete-region (match-beginning 1) (match-end 1)))
10151 (beginning-of-line 2)))))
10153 (defun vhdl-comment-kill-inline-region (beg end)
10154 "Kill inline comments in region."
10158 (setq end (point-marker))
10160 (beginning-of-line)
10161 (while (< (point) end)
10162 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10163 (delete-region (match-beginning 1) (match-end 1)))
10164 (beginning-of-line 2))))
10166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10169 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10170 "Insert a begin ... end pair with optional name after the end.
10171 Point is left between them."
10173 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10175 (vhdl-insert-keyword "BEGIN")
10176 (when (and (or construct name) vhdl-self-insert-comments)
10178 (when construct (insert " ") (vhdl-insert-keyword construct))
10179 (when name (insert " " name)))
10181 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10182 (indent-to (+ margin vhdl-basic-offset))
10183 (setq position (point))
10185 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10187 (vhdl-insert-keyword "END")
10188 (when construct (insert " ") (vhdl-insert-keyword construct))
10189 (insert (if name (concat " " name) "") ";")
10190 (goto-char position)))
10192 (defun vhdl-template-argument-list (&optional is-function)
10193 "Read from user a procedure or function argument list."
10195 (let ((margin (current-column))
10198 not-empty interface semicolon-pos)
10199 (unless vhdl-argument-list-indent
10200 (setq margin (+ (current-indentation) vhdl-basic-offset))
10202 (indent-to margin))
10203 (setq interface (vhdl-template-field
10204 (concat "[CONSTANT | SIGNAL"
10205 (unless is-function " | VARIABLE") "]") " " t))
10206 (while (vhdl-template-field "[names]" nil t)
10209 (unless is-function
10210 (if (and interface (equal (upcase interface) "CONSTANT"))
10211 (vhdl-insert-keyword "IN ")
10212 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10213 (vhdl-template-field "type")
10214 (setq semicolon-pos (point))
10216 (vhdl-comment-insert-inline)
10217 (setq end-pos (point))
10220 (setq interface (vhdl-template-field
10221 (concat "[CONSTANT | SIGNAL"
10222 (unless is-function " | VARIABLE") "]") " " t)))
10223 (delete-region end-pos (point))
10224 (when semicolon-pos (goto-char semicolon-pos))
10226 (progn (delete-char 1) (insert ")"))
10227 (delete-backward-char 2))))
10229 (defun vhdl-template-generic-list (optional &optional no-value)
10230 "Read from user a generic spec argument list."
10233 (vhdl-insert-keyword "GENERIC (")
10234 (setq margin (current-column))
10235 (unless vhdl-argument-list-indent
10236 (let ((position (point)))
10237 (back-to-indentation)
10238 (setq margin (+ (current-column) vhdl-basic-offset))
10239 (goto-char position)
10241 (indent-to margin)))
10242 (let ((vhdl-generics (vhdl-template-field
10243 (concat (and optional "[") "name"
10244 (and no-value "s") (and optional "]"))
10246 (if (not vhdl-generics)
10248 (progn (vhdl-line-kill-entire) (end-of-line -0)
10249 (unless vhdl-argument-list-indent
10250 (vhdl-line-kill-entire) (end-of-line -0)))
10251 (vhdl-template-undo start (point))
10254 (let (semicolon-pos end-pos)
10255 (while vhdl-generics
10256 (vhdl-template-field "type")
10258 (progn (setq semicolon-pos (point))
10261 (unless (vhdl-template-field "[value]" nil t)
10263 (setq semicolon-pos (point))
10265 (vhdl-comment-insert-inline)
10266 (setq end-pos (point))
10269 (setq vhdl-generics (vhdl-template-field
10270 (concat "[name" (and no-value "s") "]")
10272 (delete-region end-pos (point))
10273 (goto-char semicolon-pos)
10276 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10279 (defun vhdl-template-port-list (optional)
10280 "Read from user a port spec argument list."
10281 (let ((start (point))
10282 margin vhdl-ports object)
10283 (vhdl-insert-keyword "PORT (")
10284 (setq margin (current-column))
10285 (unless vhdl-argument-list-indent
10286 (let ((position (point)))
10287 (back-to-indentation)
10288 (setq margin (+ (current-column) vhdl-basic-offset))
10289 (goto-char position)
10291 (indent-to margin)))
10292 (when (vhdl-standard-p 'ams)
10293 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10295 (setq vhdl-ports (vhdl-template-field
10296 (concat (and optional "[") "names" (and optional "]"))
10298 (if (not vhdl-ports)
10300 (progn (vhdl-line-kill-entire) (end-of-line -0)
10301 (unless vhdl-argument-list-indent
10302 (vhdl-line-kill-entire) (end-of-line -0)))
10303 (vhdl-template-undo start (point))
10306 (let (semicolon-pos end-pos)
10308 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10309 (vhdl-template-field "IN | OUT | INOUT" " "))
10310 ((equal "QUANTITY" (upcase object))
10311 (vhdl-template-field "[IN | OUT]" " " t)))
10312 (vhdl-template-field
10313 (if (and object (equal "TERMINAL" (upcase object)))
10315 (setq semicolon-pos (point))
10317 (vhdl-comment-insert-inline)
10318 (setq end-pos (point))
10321 (when (vhdl-standard-p 'ams)
10322 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10324 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10325 (delete-region end-pos (point))
10326 (goto-char semicolon-pos)
10329 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10332 (defun vhdl-template-generate-body (margin label)
10333 "Insert body for generate template."
10334 (vhdl-insert-keyword " GENERATE")
10335 ; (if (not (vhdl-standard-p '87))
10336 ; (vhdl-template-begin-end "GENERATE" label margin)
10339 (vhdl-insert-keyword "END GENERATE ")
10342 (indent-to (+ margin vhdl-basic-offset)))
10344 (defun vhdl-template-insert-date ()
10345 "Insert date in appropriate format."
10349 ;; 'american, 'european, 'scientific kept for backward compatibility
10350 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10351 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10352 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10353 (t (format-time-string vhdl-date-format nil)))))
10355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10358 (defun vhdl-electric-space (count)
10359 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10360 if in comment and past end-comment-column."
10362 (cond ((vhdl-in-comment-p)
10363 (self-insert-command count)
10364 (cond ((>= (current-column) (+ 2 end-comment-column))
10366 (skip-chars-backward "^ \t\n")
10367 (indent-new-comment-line)
10368 (skip-chars-forward "^ \t\n")
10370 ((>= (current-column) end-comment-column)
10371 (indent-new-comment-line))
10373 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10374 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10375 (vhdl-prepare-search-1
10376 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10377 (self-insert-command count))
10378 (t (self-insert-command count))))
10380 (defun vhdl-template-field (prompt &optional follow-string optional
10381 begin end is-string default)
10382 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10383 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10384 an empty string is inserted, return nil and call `vhdl-template-undo' for
10385 the region between BEGIN and END. IS-STRING indicates whether a string
10386 with double-quotes is to be inserted. DEFAULT specifies a default string."
10387 (let ((position (point))
10389 (insert "<" prompt ">")
10392 (read-from-minibuffer (concat prompt ": ")
10393 (or (and is-string '("\"\"" . 2)) default)
10394 vhdl-minibuffer-local-map)
10395 (quit (if (and optional begin end)
10397 (keyboard-quit)))))
10398 (when (or (not (equal string "")) optional)
10399 (delete-region position (point)))
10400 (when (and (equal string "") optional begin end)
10401 (vhdl-template-undo begin end)
10402 (message "Template aborted"))
10403 (unless (equal string "")
10405 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10406 vhdl-keywords-regexp)
10407 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10409 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10410 (concat "'" vhdl-attributes-regexp))
10411 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10412 vhdl-enum-values-regexp))
10413 (when (or (not (equal string "")) (not optional))
10414 (insert (or follow-string "")))
10415 (if (equal string "") nil string)))
10417 (defun vhdl-decision-query (string prompt &optional optional)
10418 "Query a decision from the user."
10419 (let ((start (point)))
10420 (when string (vhdl-insert-keyword (concat string " ")))
10421 (message "%s" (or prompt ""))
10422 (let ((char (read-char)))
10423 (delete-region start (point))
10424 (if (and optional (eq char ?\r))
10425 (progn (insert " ")
10427 (throw 'abort "ERROR: Template aborted"))
10430 (defun vhdl-insert-keyword (keyword)
10431 "Insert KEYWORD and adjust case."
10432 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10434 (defun vhdl-case-keyword (keyword)
10435 "Adjust case of KEYWORD."
10436 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10438 (defun vhdl-case-word (num)
10439 "Adjust case of following NUM words."
10440 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10442 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10443 "If preceeding character is part of a word or a paren then hippie-expand,
10444 else insert tab (used for word completion in VHDL minibuffer)."
10448 ((= (char-syntax (preceding-char)) ?w)
10449 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10451 (hippie-expand-only-buffers
10452 (or (and (boundp 'hippie-expand-only-buffers)
10453 hippie-expand-only-buffers)
10455 (vhdl-expand-abbrev prefix-arg)))
10456 ;; expand parenthesis
10457 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10458 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10459 (case-replace nil))
10460 (vhdl-expand-paren prefix-arg)))
10464 (defun vhdl-template-search-prompt ()
10465 "Search for left out template prompts and query again."
10467 (vhdl-prepare-search-2
10468 (when (or (re-search-forward
10469 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10470 (re-search-backward
10471 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10472 (let ((string (match-string 1)))
10474 (vhdl-template-field string)))))
10476 (defun vhdl-template-undo (begin end)
10477 "Undo aborted template by deleting region and unexpanding the keyword."
10478 (cond (vhdl-template-invoked-by-hook
10481 (delete-region begin end)
10483 (t (delete-region begin end))))
10485 (defun vhdl-insert-string-or-file (string)
10486 "Insert STRING or file contents if STRING is an existing file name."
10487 (unless (equal string "")
10489 (progn (string-match "^\\([^\n]+\\)" string)
10490 (vhdl-resolve-env-variable (match-string 1 string)))))
10491 (if (file-exists-p file-name)
10492 (forward-char (cadr (insert-file-contents file-name)))
10493 (insert string)))))
10495 (defun vhdl-beginning-of-block ()
10496 "Move cursor to the beginning of the enclosing block."
10499 (beginning-of-line)
10500 ;; search backward for block beginning or end
10501 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\|record\\|units\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(postponed[ \t\n]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\)\\)\\>" nil t))
10502 ;; not consider subprogram declarations
10503 (or (and (match-string 5)
10506 (goto-char (match-end 5))
10508 (vhdl-forward-syntactic-ws)
10509 (when (looking-at "(")
10511 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10513 ;; not consider configuration specifications
10514 (and (match-string 6)
10517 (vhdl-end-of-block)
10518 (beginning-of-line)
10519 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10521 ;; skip subblock if block end found
10522 (vhdl-beginning-of-block)))
10523 (when pos (goto-char pos))))
10525 (defun vhdl-end-of-block ()
10526 "Move cursor to the end of the enclosing block."
10530 ;; search forward for block beginning or end
10531 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\|record\\|units\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(postponed[ \t\n]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\)\\)\\>" nil t))
10532 ;; not consider subprogram declarations
10533 (or (and (match-string 5)
10535 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10537 ;; not consider configuration specifications
10538 (and (match-string 6)
10541 (vhdl-end-of-block)
10542 (beginning-of-line)
10543 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10544 (not (match-string 2)))
10545 ;; skip subblock if block beginning found
10546 (vhdl-end-of-block)))
10547 (when pos (goto-char pos))))
10549 (defun vhdl-sequential-statement-p ()
10550 "Check if point is within sequential statement part."
10551 (let ((start (point)))
10553 (vhdl-prepare-search-2
10554 ;; is sequential statement if ...
10555 (and (re-search-backward "^\\s-*begin\\>" nil t)
10556 ;; ... point is between "begin" and "end" of ...
10557 (progn (vhdl-end-of-block)
10559 ;; ... a sequential block
10560 (progn (vhdl-beginning-of-block)
10561 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10563 (defun vhdl-in-argument-list-p ()
10564 "Check if within an argument list."
10566 (vhdl-prepare-search-2
10567 (or (string-match "arglist"
10568 (format "%s" (caar (vhdl-get-syntactic-context))))
10569 (progn (beginning-of-line)
10570 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10575 (defun vhdl-hooked-abbrev (func)
10576 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10577 but not if inside a comment or quote."
10578 (if (or (vhdl-in-literal)
10581 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10586 (if (not vhdl-electric-mode)
10593 (let ((invoke-char last-command-event)
10595 (vhdl-template-invoked-by-hook t))
10596 (let ((caught (catch 'abort
10598 (when (stringp caught) (message "%s" caught)))
10599 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10600 ;; delete CR which is still in event queue
10601 (if (fboundp 'enqueue-eval-event)
10602 (enqueue-eval-event 'delete-char -1)
10603 (setq unread-command-events ; push back a delete char
10604 (list (vhdl-character-to-event ?\177))))))))
10606 (defun vhdl-template-alias-hook ()
10607 (vhdl-hooked-abbrev 'vhdl-template-alias))
10608 (defun vhdl-template-architecture-hook ()
10609 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10610 (defun vhdl-template-assert-hook ()
10611 (vhdl-hooked-abbrev 'vhdl-template-assert))
10612 (defun vhdl-template-attribute-hook ()
10613 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10614 (defun vhdl-template-block-hook ()
10615 (vhdl-hooked-abbrev 'vhdl-template-block))
10616 (defun vhdl-template-break-hook ()
10617 (vhdl-hooked-abbrev 'vhdl-template-break))
10618 (defun vhdl-template-case-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-case))
10620 (defun vhdl-template-component-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-component))
10622 (defun vhdl-template-instance-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-instance))
10624 (defun vhdl-template-conditional-signal-asst-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10626 (defun vhdl-template-configuration-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10628 (defun vhdl-template-constant-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-constant))
10630 (defun vhdl-template-disconnect-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10632 (defun vhdl-template-display-comment-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-comment-display))
10634 (defun vhdl-template-else-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-else))
10636 (defun vhdl-template-elsif-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10638 (defun vhdl-template-entity-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-entity))
10640 (defun vhdl-template-exit-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-exit))
10642 (defun vhdl-template-file-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-file))
10644 (defun vhdl-template-for-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-for))
10646 (defun vhdl-template-function-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-function))
10648 (defun vhdl-template-generic-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-generic))
10650 (defun vhdl-template-group-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-group))
10652 (defun vhdl-template-library-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-library))
10654 (defun vhdl-template-limit-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-limit))
10656 (defun vhdl-template-if-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-if))
10658 (defun vhdl-template-bare-loop-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10660 (defun vhdl-template-map-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-map))
10662 (defun vhdl-template-nature-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-nature))
10664 (defun vhdl-template-next-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-next))
10666 (defun vhdl-template-others-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-others))
10668 (defun vhdl-template-package-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-package))
10670 (defun vhdl-template-port-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-port))
10672 (defun vhdl-template-procedural-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10674 (defun vhdl-template-procedure-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10676 (defun vhdl-template-process-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-process))
10678 (defun vhdl-template-quantity-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10680 (defun vhdl-template-report-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-report))
10682 (defun vhdl-template-return-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-return))
10684 (defun vhdl-template-selected-signal-asst-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10686 (defun vhdl-template-signal-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-signal))
10688 (defun vhdl-template-subnature-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10690 (defun vhdl-template-subtype-hook ()
10691 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10692 (defun vhdl-template-terminal-hook ()
10693 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10694 (defun vhdl-template-type-hook ()
10695 (vhdl-hooked-abbrev 'vhdl-template-type))
10696 (defun vhdl-template-use-hook ()
10697 (vhdl-hooked-abbrev 'vhdl-template-use))
10698 (defun vhdl-template-variable-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-variable))
10700 (defun vhdl-template-wait-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-wait))
10702 (defun vhdl-template-when-hook ()
10703 (vhdl-hooked-abbrev 'vhdl-template-when))
10704 (defun vhdl-template-while-loop-hook ()
10705 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10706 (defun vhdl-template-with-hook ()
10707 (vhdl-hooked-abbrev 'vhdl-template-with))
10708 (defun vhdl-template-and-hook ()
10709 (vhdl-hooked-abbrev 'vhdl-template-and))
10710 (defun vhdl-template-or-hook ()
10711 (vhdl-hooked-abbrev 'vhdl-template-or))
10712 (defun vhdl-template-nand-hook ()
10713 (vhdl-hooked-abbrev 'vhdl-template-nand))
10714 (defun vhdl-template-nor-hook ()
10715 (vhdl-hooked-abbrev 'vhdl-template-nor))
10716 (defun vhdl-template-xor-hook ()
10717 (vhdl-hooked-abbrev 'vhdl-template-xor))
10718 (defun vhdl-template-xnor-hook ()
10719 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10720 (defun vhdl-template-not-hook ()
10721 (vhdl-hooked-abbrev 'vhdl-template-not))
10723 (defun vhdl-template-default-hook ()
10724 (vhdl-hooked-abbrev 'vhdl-template-default))
10725 (defun vhdl-template-default-indent-hook ()
10726 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10729 ;; Template insertion from completion list
10731 (defun vhdl-template-insert-construct (name)
10732 "Insert the built-in construct template with NAME."
10734 (list (let ((completion-ignore-case t))
10735 (completing-read "Construct name: "
10736 vhdl-template-construct-alist nil t))))
10737 (vhdl-template-insert-fun
10738 (cadr (assoc name vhdl-template-construct-alist))))
10740 (defun vhdl-template-insert-package (name)
10741 "Insert the built-in package template with NAME."
10743 (list (let ((completion-ignore-case t))
10744 (completing-read "Package name: "
10745 vhdl-template-package-alist nil t))))
10746 (vhdl-template-insert-fun
10747 (cadr (assoc name vhdl-template-package-alist))))
10749 (defun vhdl-template-insert-directive (name)
10750 "Insert the built-in directive template with NAME."
10752 (list (let ((completion-ignore-case t))
10753 (completing-read "Directive name: "
10754 vhdl-template-directive-alist nil t))))
10755 (vhdl-template-insert-fun
10756 (cadr (assoc name vhdl-template-directive-alist))))
10758 (defun vhdl-template-insert-fun (fun)
10759 "Call FUN to insert a built-in template."
10760 (let ((caught (catch 'abort (when fun (funcall fun)))))
10761 (when (stringp caught) (message "%s" caught))))
10764 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10768 (defun vhdl-model-insert (model-name)
10769 "Insert the user model with name MODEL-NAME."
10771 (let ((completion-ignore-case t))
10772 (list (completing-read "Model name: " vhdl-model-alist))))
10773 (indent-according-to-mode)
10774 (let ((start (point-marker))
10775 (margin (current-indentation))
10776 model position prompt string end)
10777 (vhdl-prepare-search-2
10778 (when (setq model (assoc model-name vhdl-model-alist))
10780 (beginning-of-line)
10781 (delete-horizontal-space)
10783 (vhdl-insert-string-or-file (nth 1 model))
10784 (setq end (point-marker))
10787 (beginning-of-line)
10788 (while (< (point) end)
10789 (unless (looking-at "^$")
10790 (insert-char ? margin))
10791 (beginning-of-line 2))
10794 (unless (equal "" vhdl-clock-name)
10795 (while (re-search-forward "<clock>" end t)
10796 (replace-match vhdl-clock-name)))
10799 (unless (equal "" vhdl-reset-name)
10800 (while (re-search-forward "<reset>" end t)
10801 (replace-match vhdl-reset-name)))
10802 ;; replace header prompts
10803 (vhdl-template-replace-header-keywords start end nil t)
10805 ;; query other prompts
10806 (while (re-search-forward
10807 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10808 (unless (equal "cursor" (match-string 1))
10809 (setq position (match-beginning 1))
10810 (setq prompt (match-string 1))
10812 (setq string (vhdl-template-field prompt nil t))
10813 ;; replace occurrences of same prompt
10814 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10815 (replace-match (or string "")))
10816 (goto-char position)))
10818 ;; goto final position
10819 (if (re-search-forward "<cursor>" end t)
10821 (goto-char end))))))
10823 (defun vhdl-model-defun ()
10824 "Define help and hook functions for user models."
10825 (let ((model-alist vhdl-model-alist)
10826 model-name model-keyword)
10828 ;; define functions for user models that can be invoked from menu and key
10829 ;; bindings and which themselves call `vhdl-model-insert' with the model
10830 ;; name as argument
10831 (setq model-name (nth 0 (car model-alist)))
10832 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10833 ,(concat "Insert model for \"" model-name "\".")
10835 (vhdl-model-insert ,model-name)))
10836 ;; define hooks for user models that are invoked from keyword abbrevs
10837 (setq model-keyword (nth 3 (car model-alist)))
10838 (unless (equal model-keyword "")
10840 ,(vhdl-function-name
10841 "vhdl-model" model-name "hook") ()
10842 (vhdl-hooked-abbrev
10843 ',(vhdl-function-name "vhdl-model" model-name)))))
10844 (setq model-alist (cdr model-alist)))))
10849 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10850 ;;; Port translation
10851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10853 (defvar vhdl-port-list nil
10854 "Variable to hold last port map parsed.")
10855 ;; structure: (parenthesised expression means list of such entries)
10857 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10858 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10859 ;; (lib-name pack-key))
10861 (defun vhdl-parse-string (string &optional optional)
10862 "Check that the text following point matches the regexp in STRING."
10863 (if (looking-at string)
10864 (goto-char (match-end 0))
10866 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10867 (vhdl-current-line) string)))
10870 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10871 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10872 (vhdl-prepare-search-1
10873 (if (string-match (car regexp-cons) string)
10875 (funcall vhdl-file-name-case
10876 (replace-match (cdr regexp-cons) t nil string))
10877 (replace-match (cdr regexp-cons) t nil string))
10880 (defun vhdl-parse-group-comment ()
10881 "Parse comment and empty lines between groups of lines."
10882 (let ((start (point))
10884 (vhdl-forward-comment (point-max))
10885 (setq string (buffer-substring-no-properties start (point)))
10886 (vhdl-forward-syntactic-ws)
10887 ;; strip off leading blanks and first newline
10888 (while (string-match "^\\(\\s-+\\)" string)
10889 (setq string (concat (substring string 0 (match-beginning 1))
10890 (substring string (match-end 1)))))
10891 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10892 (substring string 1)
10895 (defun vhdl-paste-group-comment (string indent)
10896 "Paste comment and empty lines from STRING between groups of lines
10898 (let ((pos (point-marker)))
10900 (while (string-match "^\\(--\\)" string)
10901 (setq string (concat (substring string 0 (match-beginning 1))
10902 (make-string indent ? )
10903 (substring string (match-beginning 1))))))
10904 (beginning-of-line)
10908 (defvar vhdl-port-flattened nil
10909 "Indicates whether a port has been flattened.")
10911 (defun vhdl-port-flatten (&optional as-alist)
10912 "Flatten port list so that only one generic/port exists per line.
10913 This operation is performed on an internally stored port and is only
10914 reflected in a subsequent paste operation."
10916 (if (not vhdl-port-list)
10917 (error "ERROR: No port has been read")
10918 (message "Flattening port for next paste...")
10919 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10920 (old-vhdl-port-list (cdr vhdl-port-list))
10921 old-port-list new-port-list old-port new-port names)
10922 ;; traverse port list and flatten entries
10923 (while (cdr old-vhdl-port-list)
10924 (setq old-port-list (car old-vhdl-port-list))
10925 (setq new-port-list nil)
10926 (while old-port-list
10927 (setq old-port (car old-port-list))
10928 (setq names (car old-port))
10930 (setq new-port (cons (if as-alist (car names) (list (car names)))
10932 (setq new-port-list (append new-port-list (list new-port)))
10933 (setq names (cdr names)))
10934 (setq old-port-list (cdr old-port-list)))
10935 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10936 (setq new-vhdl-port-list (append new-vhdl-port-list
10937 (list new-port-list))))
10938 (setq vhdl-port-list
10939 (append new-vhdl-port-list (list old-vhdl-port-list))
10940 vhdl-port-flattened t)
10941 (message "Flattening port for next paste...done"))))
10943 (defvar vhdl-port-reversed-direction nil
10944 "Indicates whether port directions are reversed.")
10946 (defun vhdl-port-reverse-direction ()
10947 "Reverse direction for all ports (useful in testbenches).
10948 This operation is performed on an internally stored port and is only
10949 reflected in a subsequent paste operation."
10951 (if (not vhdl-port-list)
10952 (error "ERROR: No port has been read")
10953 (message "Reversing port directions for next paste...")
10954 (let ((port-list (nth 2 vhdl-port-list))
10955 port-dir-car port-dir)
10956 ;; traverse port list and reverse directions
10958 (setq port-dir-car (cddr (car port-list))
10959 port-dir (car port-dir-car))
10960 (setcar port-dir-car
10961 (cond ((equal port-dir "in") "out")
10962 ((equal port-dir "out") "in")
10964 (setq port-list (cdr port-list)))
10965 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10966 (message "Reversing port directions for next paste...done"))))
10968 (defun vhdl-port-copy ()
10969 "Get generic and port information from an entity or component declaration."
10972 (let (parse-error end-of-list
10973 decl-type name generic-list port-list context-clause
10974 object names direct type init comment group-comment)
10975 (vhdl-prepare-search-2
10979 ;; check if within entity or component declaration
10981 (when (or (not (re-search-backward
10982 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10983 (equal "END" (upcase (match-string 1))))
10984 (throw 'parse "ERROR: Not within an entity or component declaration"))
10985 (setq decl-type (downcase (match-string-no-properties 1)))
10987 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10988 (setq name (match-string-no-properties 1))
10989 (message "Reading port of %s \"%s\"..." decl-type name)
10990 (vhdl-forward-syntactic-ws)
10991 ;; parse generic clause
10992 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10993 ;; parse group comment and spacing
10994 (setq group-comment (vhdl-parse-group-comment))
10995 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10996 (while (not end-of-list)
10997 ;; parse names (accept extended identifiers)
10998 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10999 (setq names (list (match-string-no-properties 1)))
11000 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
11002 (append names (list (match-string-no-properties 1)))))
11004 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
11005 (setq type (match-string-no-properties 1))
11007 (while (looking-at "(")
11010 (buffer-substring-no-properties
11011 (point) (progn (forward-sexp) (point)))
11012 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11013 (match-string-no-properties 1)))))
11014 ;; special case: closing parenthesis is on separate line
11015 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11016 (setq comment (substring type (match-beginning 2)))
11017 (setq type (substring type 0 (match-beginning 1))))
11018 ;; strip of trailing group-comment
11019 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11020 (setq type (substring type 0 (match-end 1)))
11021 ;; parse initialization expression
11023 (when (vhdl-parse-string ":=[ \t\n]*" t)
11024 (vhdl-parse-string "\\([^();\n]*\\)")
11025 (setq init (match-string-no-properties 1))
11026 (while (looking-at "(")
11029 (buffer-substring-no-properties
11030 (point) (progn (forward-sexp) (point)))
11031 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11032 (match-string-no-properties 1))))))
11033 ;; special case: closing parenthesis is on separate line
11034 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11035 (setq comment (substring init (match-beginning 2)))
11036 (setq init (substring init 0 (match-beginning 1)))
11037 (vhdl-forward-syntactic-ws))
11038 (skip-chars-forward " \t")
11039 ;; parse inline comment, special case: as above, no initial.
11041 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11042 (match-string-no-properties 1))))
11043 (vhdl-forward-syntactic-ws)
11044 (setq end-of-list (vhdl-parse-string ")" t))
11045 (vhdl-parse-string "\\s-*;\\s-*")
11046 ;; parse inline comment
11048 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11049 (match-string-no-properties 1))))
11050 ;; save everything in list
11051 (setq generic-list (append generic-list
11052 (list (list names type init
11053 comment group-comment))))
11054 ;; parse group comment and spacing
11055 (setq group-comment (vhdl-parse-group-comment))))
11056 ;; parse port clause
11057 (when (vhdl-parse-string "port[ \t\n]*(" t)
11058 ;; parse group comment and spacing
11059 (setq group-comment (vhdl-parse-group-comment))
11060 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11061 (while (not end-of-list)
11064 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11065 (match-string-no-properties 1)))
11066 ;; parse names (accept extended identifiers)
11067 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11068 (setq names (list (match-string-no-properties 1)))
11069 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11070 (setq names (append names (list (match-string-no-properties 1)))))
11072 (vhdl-parse-string ":[ \t\n]*")
11074 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11075 (match-string-no-properties 1)))
11077 (vhdl-parse-string "\\([^();\n]+\\)")
11078 (setq type (match-string-no-properties 1))
11080 (while (looking-at "(")
11081 (setq type (concat type
11082 (buffer-substring-no-properties
11083 (point) (progn (forward-sexp) (point)))
11084 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11085 (match-string-no-properties 1)))))
11086 ;; special case: closing parenthesis is on separate line
11087 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11088 (setq comment (substring type (match-beginning 2)))
11089 (setq type (substring type 0 (match-beginning 1))))
11090 ;; strip of trailing group-comment
11091 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11092 (setq type (substring type 0 (match-end 1)))
11093 (vhdl-forward-syntactic-ws)
11094 (setq end-of-list (vhdl-parse-string ")" t))
11095 (vhdl-parse-string "\\s-*;\\s-*")
11096 ;; parse inline comment
11098 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11099 (match-string-no-properties 1))))
11100 ;; save everything in list
11101 (setq port-list (append port-list
11102 (list (list names object direct type
11103 comment group-comment))))
11104 ;; parse group comment and spacing
11105 (setq group-comment (vhdl-parse-group-comment))))
11106 ; (vhdl-parse-string "end\\>")
11107 ;; parse context clause
11108 (setq context-clause (vhdl-scan-context-clause))
11109 ; ;; add surrounding package to context clause
11110 ; (when (and (equal decl-type "component")
11111 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11112 ; (setq context-clause
11113 ; (append context-clause
11114 ; (list (cons (vhdl-work-library)
11115 ; (match-string-no-properties 1))))))
11116 (message "Reading port of %s \"%s\"...done" decl-type name)
11120 (error parse-error)
11121 (setq vhdl-port-list (list name generic-list port-list context-clause)
11122 vhdl-port-reversed-direction nil
11123 vhdl-port-flattened nil)))))
11125 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11126 "Paste a context clause."
11127 (let ((margin (current-indentation))
11128 (clause-list (nth 3 vhdl-port-list))
11131 (setq clause (car clause-list))
11132 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11133 (downcase exclude-pack-name)))
11135 (re-search-backward
11136 (concat "^\\s-*use\\s-+" (car clause)
11137 "\." (cdr clause) "\\>") nil t)))
11138 (vhdl-template-standard-package (car clause) (cdr clause))
11140 (setq clause-list (cdr clause-list)))))
11142 (defun vhdl-port-paste-generic (&optional no-init)
11143 "Paste a generic clause."
11144 (let ((margin (current-indentation))
11145 (generic-list (nth 1 vhdl-port-list))
11146 list-margin start names generic)
11147 ;; paste generic clause
11149 (setq start (point))
11150 (vhdl-insert-keyword "GENERIC (")
11151 (unless vhdl-argument-list-indent
11152 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11153 (setq list-margin (current-column))
11154 (while generic-list
11155 (setq generic (car generic-list))
11156 ;; paste group comment and spacing
11157 (when (memq vhdl-include-group-comments '(decl always))
11158 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11160 (setq names (nth 0 generic))
11162 (insert (car names))
11163 (setq names (cdr names))
11164 (when names (insert ", ")))
11166 (insert " : " (nth 1 generic))
11167 ;; paste initialization
11168 (when (and (not no-init) (nth 2 generic))
11169 (insert " := " (nth 2 generic)))
11170 (unless (cdr generic-list) (insert ")"))
11173 (when (and vhdl-include-port-comments (nth 3 generic))
11174 (vhdl-comment-insert-inline (nth 3 generic) t))
11175 (setq generic-list (cdr generic-list))
11176 (when generic-list (insert "\n") (indent-to list-margin)))
11177 ;; align generic clause
11178 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11180 (defun vhdl-port-paste-port ()
11181 "Paste a port clause."
11182 (let ((margin (current-indentation))
11183 (port-list (nth 2 vhdl-port-list))
11184 list-margin start names port)
11185 ;; paste port clause
11187 (setq start (point))
11188 (vhdl-insert-keyword "PORT (")
11189 (unless vhdl-argument-list-indent
11190 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11191 (setq list-margin (current-column))
11193 (setq port (car port-list))
11194 ;; paste group comment and spacing
11195 (when (memq vhdl-include-group-comments '(decl always))
11196 (vhdl-paste-group-comment (nth 5 port) list-margin))
11198 (when (nth 1 port) (insert (nth 1 port) " "))
11200 (setq names (nth 0 port))
11202 (insert (car names))
11203 (setq names (cdr names))
11204 (when names (insert ", ")))
11207 (when (nth 2 port) (insert (nth 2 port) " "))
11209 (insert (nth 3 port))
11210 (unless (cdr port-list) (insert ")"))
11213 (when (and vhdl-include-port-comments (nth 4 port))
11214 (vhdl-comment-insert-inline (nth 4 port) t))
11215 (setq port-list (cdr port-list))
11216 (when port-list (insert "\n") (indent-to list-margin)))
11217 ;; align port clause
11218 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11220 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11221 "Paste as an entity or component declaration."
11222 (unless no-indent (indent-according-to-mode))
11223 (let ((margin (current-indentation))
11224 (name (nth 0 vhdl-port-list)))
11225 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11227 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11228 (vhdl-insert-keyword " IS"))
11229 ;; paste generic and port clause
11230 (when (nth 1 vhdl-port-list)
11232 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11234 (indent-to (+ margin vhdl-basic-offset))
11235 (vhdl-port-paste-generic (eq kind 'component)))
11236 (when (nth 2 vhdl-port-list)
11238 (when (and (memq vhdl-insert-empty-lines '(unit all))
11241 (indent-to (+ margin vhdl-basic-offset)))
11242 (vhdl-port-paste-port)
11244 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11247 (vhdl-insert-keyword "END")
11248 (if (eq kind 'entity)
11250 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11252 (vhdl-insert-keyword " COMPONENT")
11253 (unless (vhdl-standard-p '87) (insert " " name)))
11256 (defun vhdl-port-paste-entity (&optional no-indent)
11257 "Paste as an entity declaration."
11259 (if (not vhdl-port-list)
11260 (error "ERROR: No port read")
11261 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11262 (vhdl-port-paste-declaration 'entity no-indent)
11263 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11265 (defun vhdl-port-paste-component (&optional no-indent)
11266 "Paste as a component declaration."
11268 (if (not vhdl-port-list)
11269 (error "ERROR: No port read")
11270 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11271 (vhdl-port-paste-declaration 'component no-indent)
11272 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11274 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11275 "Paste as a generic map."
11277 (unless secondary (indent-according-to-mode))
11278 (let ((margin (current-indentation))
11279 list-margin start generic
11280 (generic-list (nth 1 vhdl-port-list)))
11282 (setq start (point))
11283 (vhdl-insert-keyword "GENERIC MAP (")
11284 (if (not vhdl-association-list-with-formals)
11285 ;; paste list of actual generics
11286 (while generic-list
11287 (insert (if no-constants
11288 (car (nth 0 (car generic-list)))
11289 (or (nth 2 (car generic-list)) " ")))
11290 (setq generic-list (cdr generic-list))
11291 (insert (if generic-list ", " ")"))
11292 (when (and (not generic-list) secondary
11293 (null (nth 2 vhdl-port-list)))
11295 (unless vhdl-argument-list-indent
11296 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11297 (setq list-margin (current-column))
11298 (while generic-list
11299 (setq generic (car generic-list))
11300 ;; paste group comment and spacing
11301 (when (eq vhdl-include-group-comments 'always)
11302 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11303 ;; paste formal and actual generic
11304 (insert (car (nth 0 generic)) " => "
11306 (car (nth 0 generic))
11307 (or (nth 2 generic) "")))
11308 (setq generic-list (cdr generic-list))
11309 (insert (if generic-list "," ")"))
11310 (when (and (not generic-list) secondary
11311 (null (nth 2 vhdl-port-list)))
11314 (when (or vhdl-include-type-comments
11315 (and vhdl-include-port-comments (nth 3 generic)))
11316 (vhdl-comment-insert-inline
11318 (when vhdl-include-type-comments
11319 (concat "[" (nth 1 generic) "] "))
11320 (when vhdl-include-port-comments (nth 3 generic))) t))
11321 (when generic-list (insert "\n") (indent-to list-margin)))
11322 ;; align generic map
11323 (when vhdl-auto-align
11324 (vhdl-align-region-groups start (point) 1 t))))))
11326 (defun vhdl-port-paste-port-map ()
11327 "Paste as a port map."
11328 (let ((margin (current-indentation))
11329 list-margin start port
11330 (port-list (nth 2 vhdl-port-list)))
11332 (setq start (point))
11333 (vhdl-insert-keyword "PORT MAP (")
11334 (if (not vhdl-association-list-with-formals)
11335 ;; paste list of actual ports
11337 (insert (vhdl-replace-string vhdl-actual-port-name
11338 (car (nth 0 (car port-list)))))
11339 (setq port-list (cdr port-list))
11340 (insert (if port-list ", " ")")))
11341 (unless vhdl-argument-list-indent
11342 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11343 (setq list-margin (current-column))
11345 (setq port (car port-list))
11346 ;; paste group comment and spacing
11347 (when (eq vhdl-include-group-comments 'always)
11348 (vhdl-paste-group-comment (nth 5 port) list-margin))
11349 ;; paste formal and actual port
11350 (insert (car (nth 0 port)) " => ")
11351 (insert (vhdl-replace-string vhdl-actual-port-name
11352 (car (nth 0 port))))
11353 (setq port-list (cdr port-list))
11354 (insert (if port-list "," ");"))
11356 (when (or vhdl-include-direction-comments
11357 vhdl-include-type-comments
11358 (and vhdl-include-port-comments (nth 4 port)))
11359 (vhdl-comment-insert-inline
11361 (cond ((and vhdl-include-direction-comments
11362 vhdl-include-type-comments)
11363 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11364 (nth 3 port) "] "))
11365 ((and vhdl-include-direction-comments (nth 2 port))
11366 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11367 (vhdl-include-direction-comments " ")
11368 (vhdl-include-type-comments
11369 (concat "[" (nth 3 port) "] ")))
11370 (when vhdl-include-port-comments (nth 4 port))) t))
11371 (when port-list (insert "\n") (indent-to list-margin)))
11372 ;; align port clause
11373 (when vhdl-auto-align
11374 (vhdl-align-region-groups start (point) 1))))))
11376 (defun vhdl-port-paste-instance (&optional name no-indent title)
11377 "Paste as an instantiation."
11379 (if (not vhdl-port-list)
11380 (error "ERROR: No port read")
11381 (let ((orig-vhdl-port-list vhdl-port-list))
11382 ;; flatten local copy of port list (must be flat for port mapping)
11383 (vhdl-port-flatten)
11384 (unless no-indent (indent-according-to-mode))
11385 (let ((margin (current-indentation)))
11386 ;; paste instantiation
11389 ((equal (cdr vhdl-instance-name) "")
11390 (setq name (vhdl-template-field "instance name")))
11391 ((string-match "\%d" (cdr vhdl-instance-name))
11393 (while (save-excursion
11394 (setq name (format (vhdl-replace-string
11396 (nth 0 vhdl-port-list)) n))
11397 (goto-char (point-min))
11398 (vhdl-re-search-forward name nil t))
11401 (t (insert (vhdl-replace-string vhdl-instance-name
11402 (nth 0 vhdl-port-list)))))
11403 (message "Pasting port as instantiation \"%s\"..." name)
11407 (beginning-of-line)
11408 (indent-to vhdl-basic-offset)
11409 (insert "-- instance \"" name "\"\n")))
11410 (if (not (vhdl-use-direct-instantiation))
11411 (insert (nth 0 vhdl-port-list))
11412 (vhdl-insert-keyword "ENTITY ")
11413 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11414 (when (nth 1 vhdl-port-list)
11415 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11416 (vhdl-port-paste-generic-map t t))
11417 (when (nth 2 vhdl-port-list)
11418 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11419 (vhdl-port-paste-port-map))
11420 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11422 (message "Pasting port as instantiation \"%s\"...done" name))
11423 (setq vhdl-port-list orig-vhdl-port-list))))
11425 (defun vhdl-port-paste-constants (&optional no-indent)
11426 "Paste generics as constants."
11428 (if (not vhdl-port-list)
11429 (error "ERROR: No port read")
11430 (let ((orig-vhdl-port-list vhdl-port-list))
11431 (message "Pasting port as constants...")
11432 ;; flatten local copy of port list (must be flat for constant initial.)
11433 (vhdl-port-flatten)
11434 (unless no-indent (indent-according-to-mode))
11435 (let ((margin (current-indentation))
11437 (generic-list (nth 1 vhdl-port-list)))
11439 (setq start (point))
11440 (while generic-list
11441 (setq generic (car generic-list))
11442 ;; paste group comment and spacing
11443 (when (memq vhdl-include-group-comments '(decl always))
11444 (vhdl-paste-group-comment (nth 4 generic) margin))
11445 (vhdl-insert-keyword "CONSTANT ")
11446 ;; paste generic constants
11447 (setq name (nth 0 generic))
11449 (insert (car name))
11451 (insert " : " (nth 1 generic))
11452 ;; paste initialization
11453 (when (nth 2 generic)
11454 (insert " := " (nth 2 generic)))
11457 (when (and vhdl-include-port-comments (nth 3 generic))
11458 (vhdl-comment-insert-inline (nth 3 generic) t))
11459 (setq generic-list (cdr generic-list))
11460 (when generic-list (insert "\n") (indent-to margin))))
11461 ;; align signal list
11462 (when vhdl-auto-align
11463 (vhdl-align-region-groups start (point) 1))))
11464 (message "Pasting port as constants...done")
11465 (setq vhdl-port-list orig-vhdl-port-list))))
11467 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11468 "Paste ports as internal signals."
11470 (if (not vhdl-port-list)
11471 (error "ERROR: No port read")
11472 (message "Pasting port as signals...")
11473 (unless no-indent (indent-according-to-mode))
11474 (let ((margin (current-indentation))
11476 (port-list (nth 2 vhdl-port-list)))
11478 (setq start (point))
11480 (setq port (car port-list))
11481 ;; paste group comment and spacing
11482 (when (memq vhdl-include-group-comments '(decl always))
11483 (vhdl-paste-group-comment (nth 5 port) margin))
11486 (insert (nth 1 port) " ")
11487 (vhdl-insert-keyword "SIGNAL "))
11488 ;; paste actual port signals
11489 (setq names (nth 0 port))
11491 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11492 (setq names (cdr names))
11493 (when names (insert ", ")))
11495 (insert " : " (nth 3 port))
11496 ;; paste initialization (inputs only)
11497 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11498 (insert " := " (if (string-match "(.+)" (nth 3 port))
11499 "(others => '0')" "'0'")))
11502 (when (or vhdl-include-direction-comments
11503 (and vhdl-include-port-comments (nth 4 port)))
11504 (vhdl-comment-insert-inline
11506 (cond ((and vhdl-include-direction-comments (nth 2 port))
11507 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11508 (vhdl-include-direction-comments " "))
11509 (when vhdl-include-port-comments (nth 4 port))) t))
11510 (setq port-list (cdr port-list))
11511 (when port-list (insert "\n") (indent-to margin)))
11512 ;; align signal list
11513 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11514 (message "Pasting port as signals...done")))
11516 (defun vhdl-port-paste-initializations (&optional no-indent)
11517 "Paste ports as signal initializations."
11519 (if (not vhdl-port-list)
11520 (error "ERROR: No port read")
11521 (let ((orig-vhdl-port-list vhdl-port-list))
11522 (message "Pasting port as initializations...")
11523 ;; flatten local copy of port list (must be flat for signal initial.)
11524 (vhdl-port-flatten)
11525 (unless no-indent (indent-according-to-mode))
11526 (let ((margin (current-indentation))
11528 (port-list (nth 2 vhdl-port-list)))
11530 (setq start (point))
11532 (setq port (car port-list))
11533 ;; paste actual port signal (inputs only)
11534 (when (equal "IN" (upcase (nth 2 port)))
11535 (setq name (car (nth 0 port)))
11536 (insert (vhdl-replace-string vhdl-actual-port-name name))
11537 ;; paste initialization
11538 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11539 "(others => '0')" "'0'") ";"))
11540 (setq port-list (cdr port-list))
11541 (when (and port-list
11542 (equal "IN" (upcase (nth 2 (car port-list)))))
11543 (insert "\n") (indent-to margin)))
11544 ;; align signal list
11545 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11546 (message "Pasting port as initializations...done")
11547 (setq vhdl-port-list orig-vhdl-port-list))))
11549 (defun vhdl-port-paste-testbench ()
11550 "Paste as a bare-bones testbench."
11552 (if (not vhdl-port-list)
11553 (error "ERROR: No port read")
11554 (let ((case-fold-search t)
11555 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11556 (nth 0 vhdl-port-list)))
11557 (source-buffer (current-buffer))
11558 arch-name config-name ent-file-name arch-file-name
11559 ent-buffer arch-buffer position)
11560 ;; open entity file
11561 (unless (eq vhdl-testbench-create-files 'none)
11562 (setq ent-file-name
11563 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11565 "." (file-name-extension (buffer-file-name))))
11566 (if (file-exists-p ent-file-name)
11568 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11569 (progn (find-file ent-file-name)
11571 (set-buffer-modified-p nil))
11572 (if (eq vhdl-testbench-create-files 'separate)
11573 (setq ent-file-name nil)
11574 (error "ERROR: Pasting port as testbench...aborted")))
11575 (find-file ent-file-name)))
11576 (unless (and (eq vhdl-testbench-create-files 'separate)
11577 (null ent-file-name))
11578 ;; paste entity header
11579 (if vhdl-testbench-include-header
11580 (progn (vhdl-template-header
11581 (concat "Testbench for design \""
11582 (nth 0 vhdl-port-list) "\""))
11583 (goto-char (point-max)))
11584 (vhdl-comment-display-line) (insert "\n\n"))
11585 ;; paste std_logic_1164 package
11586 (when vhdl-testbench-include-library
11587 (vhdl-template-package-std-logic-1164)
11588 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11589 ;; paste entity declaration
11590 (vhdl-insert-keyword "ENTITY ")
11592 (vhdl-insert-keyword " IS")
11593 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11595 (vhdl-insert-keyword "END ")
11596 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11597 (insert ent-name ";")
11599 (vhdl-comment-display-line) (insert "\n"))
11600 ;; get architecture name
11601 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11602 (read-from-minibuffer "architecture name: "
11603 nil vhdl-minibuffer-local-map)
11604 (vhdl-replace-string vhdl-testbench-architecture-name
11605 (nth 0 vhdl-port-list))))
11606 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11607 ;; open architecture file
11608 (if (not (eq vhdl-testbench-create-files 'separate))
11610 (setq ent-buffer (current-buffer))
11611 (setq arch-file-name
11612 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11613 (concat ent-name " " arch-name) t)
11614 "." (file-name-extension (buffer-file-name))))
11615 (when (and (file-exists-p arch-file-name)
11616 (not (y-or-n-p (concat "File \"" arch-file-name
11617 "\" exists; overwrite? "))))
11618 (error "ERROR: Pasting port as testbench...aborted"))
11619 (find-file arch-file-name)
11621 (set-buffer-modified-p nil)
11622 ;; paste architecture header
11623 (if vhdl-testbench-include-header
11624 (progn (vhdl-template-header
11625 (concat "Testbench architecture for design \""
11626 (nth 0 vhdl-port-list) "\""))
11627 (goto-char (point-max)))
11628 (vhdl-comment-display-line) (insert "\n\n")))
11629 ;; paste architecture body
11630 (vhdl-insert-keyword "ARCHITECTURE ")
11632 (vhdl-insert-keyword " OF ")
11634 (vhdl-insert-keyword " IS")
11635 (insert "\n\n") (indent-to vhdl-basic-offset)
11636 ;; paste component declaration
11637 (unless (vhdl-use-direct-instantiation)
11638 (vhdl-port-paste-component t)
11639 (insert "\n\n") (indent-to vhdl-basic-offset))
11641 (when (nth 1 vhdl-port-list)
11642 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11643 (vhdl-port-paste-constants t)
11644 (insert "\n\n") (indent-to vhdl-basic-offset))
11645 ;; paste internal signals
11646 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11647 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11649 ;; paste custom declarations
11650 (unless (equal "" vhdl-testbench-declarations)
11652 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11653 (setq position (point))
11655 (vhdl-comment-display-line) (insert "\n")
11656 (when vhdl-testbench-include-configuration
11657 (setq config-name (vhdl-replace-string
11658 vhdl-testbench-configuration-name
11659 (concat ent-name " " arch-name)))
11661 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11662 (vhdl-insert-keyword " OF ") (insert ent-name)
11663 (vhdl-insert-keyword " IS\n")
11664 (indent-to vhdl-basic-offset)
11665 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11666 (indent-to vhdl-basic-offset)
11667 (vhdl-insert-keyword "END FOR;\n")
11668 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11669 (vhdl-comment-display-line) (insert "\n"))
11670 (goto-char position)
11671 (vhdl-template-begin-end
11672 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11673 ;; paste instantiation
11674 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11675 (vhdl-port-paste-instance
11676 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11678 ;; paste custom statements
11679 (unless (equal "" vhdl-testbench-statements)
11681 (vhdl-insert-string-or-file vhdl-testbench-statements))
11683 (indent-to vhdl-basic-offset)
11684 (unless (eq vhdl-testbench-create-files 'none)
11685 (setq arch-buffer (current-buffer))
11686 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11687 (set-buffer arch-buffer) (save-buffer))
11689 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11690 ent-name arch-name)
11692 (format "\n File created: \"%s\"" ent-file-name))
11693 (and arch-file-name
11694 (format "\n File created: \"%s\"" arch-file-name)))))))
11697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11698 ;;; Subprogram interface translation
11699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11701 (defvar vhdl-subprog-list nil
11702 "Variable to hold last subprogram interface parsed.")
11703 ;; structure: (parenthesised expression means list of such entries)
11704 ;; (subprog-name kind
11705 ;; ((names) object direct type init comment group-comment)
11706 ;; return-type return-comment group-comment)
11708 (defvar vhdl-subprog-flattened nil
11709 "Indicates whether an subprogram interface has been flattened.")
11711 (defun vhdl-subprog-flatten ()
11712 "Flatten interface list so that only one parameter exists per line."
11714 (if (not vhdl-subprog-list)
11715 (error "ERROR: No subprogram interface has been read")
11716 (message "Flattening subprogram interface...")
11717 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11718 new-subprog-list old-subprog new-subprog names)
11719 ;; traverse parameter list and flatten entries
11720 (while old-subprog-list
11721 (setq old-subprog (car old-subprog-list))
11722 (setq names (car old-subprog))
11724 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11725 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11726 (setq names (cdr names)))
11727 (setq old-subprog-list (cdr old-subprog-list)))
11728 (setq vhdl-subprog-list
11729 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11730 new-subprog-list (nth 3 vhdl-subprog-list)
11731 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11732 vhdl-subprog-flattened t)
11733 (message "Flattening subprogram interface...done"))))
11735 (defun vhdl-subprog-copy ()
11736 "Get interface information from a subprogram specification."
11739 (let (parse-error pos end-of-list
11740 name kind param-list object names direct type init
11741 comment group-comment
11742 return-type return-comment return-group-comment)
11743 (vhdl-prepare-search-2
11747 ;; check if within function declaration
11750 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11751 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11752 (goto-char (match-end 0))
11753 (save-excursion (backward-char)
11756 (throw 'parse "ERROR: Not within a subprogram specification"))
11757 (setq name (match-string-no-properties 5))
11758 (setq kind (if (match-string 2) 'procedure 'function))
11759 (setq end-of-list (not (match-string 7)))
11760 (message "Reading interface of subprogram \"%s\"..." name)
11761 ;; parse parameter list
11762 (setq group-comment (vhdl-parse-group-comment))
11763 (setq end-of-list (or end-of-list
11764 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11765 (while (not end-of-list)
11768 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11769 (match-string-no-properties 1)))
11770 ;; parse names (accept extended identifiers)
11771 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11772 (setq names (list (match-string-no-properties 1)))
11773 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11774 (setq names (append names (list (match-string-no-properties 1)))))
11776 (vhdl-parse-string ":[ \t\n]*")
11778 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11779 (match-string-no-properties 1)))
11781 (vhdl-parse-string "\\([^():;\n]+\\)")
11782 (setq type (match-string-no-properties 1))
11784 (while (looking-at "(")
11787 (buffer-substring-no-properties
11788 (point) (progn (forward-sexp) (point)))
11789 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11790 (match-string-no-properties 1)))))
11791 ;; special case: closing parenthesis is on separate line
11792 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11793 (setq comment (substring type (match-beginning 2)))
11794 (setq type (substring type 0 (match-beginning 1))))
11795 ;; strip off trailing group-comment
11796 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11797 (setq type (substring type 0 (match-end 1)))
11798 ;; parse initialization expression
11800 (when (vhdl-parse-string ":=[ \t\n]*" t)
11801 (vhdl-parse-string "\\([^();\n]*\\)")
11802 (setq init (match-string-no-properties 1))
11803 (while (looking-at "(")
11806 (buffer-substring-no-properties
11807 (point) (progn (forward-sexp) (point)))
11808 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11809 (match-string-no-properties 1))))))
11810 ;; special case: closing parenthesis is on separate line
11811 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11812 (setq comment (substring init (match-beginning 2)))
11813 (setq init (substring init 0 (match-beginning 1)))
11814 (vhdl-forward-syntactic-ws))
11815 (skip-chars-forward " \t")
11816 ;; parse inline comment, special case: as above, no initial.
11818 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11819 (match-string-no-properties 1))))
11820 (vhdl-forward-syntactic-ws)
11821 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11822 ;; parse inline comment
11824 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11825 (match-string-no-properties 1))))
11826 (setq return-group-comment (vhdl-parse-group-comment))
11827 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11828 ;; parse return type
11829 (when (match-string 3)
11830 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11831 (setq return-type (match-string-no-properties 1))
11832 (when (and return-type
11833 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11834 (setq return-comment (substring return-type (match-beginning 2)))
11835 (setq return-type (substring return-type 0 (match-beginning 1))))
11836 ;; strip of trailing group-comment
11837 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11838 (setq return-type (substring return-type 0 (match-end 1)))
11839 ;; parse return comment
11840 (unless return-comment
11841 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11842 (match-string-no-properties 1)))))
11843 ;; parse inline comment
11845 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11846 (match-string-no-properties 1))))
11847 ;; save everything in list
11848 (setq param-list (append param-list
11849 (list (list names object direct type init
11850 comment group-comment))))
11851 ;; parse group comment and spacing
11852 (setq group-comment (vhdl-parse-group-comment)))
11853 (message "Reading interface of subprogram \"%s\"...done" name)
11857 (error parse-error)
11858 (setq vhdl-subprog-list
11859 (list name kind param-list return-type return-comment
11860 return-group-comment)
11861 vhdl-subprog-flattened nil)))))
11863 (defun vhdl-subprog-paste-specification (kind)
11864 "Paste as a subprogram specification."
11865 (indent-according-to-mode)
11866 (let ((margin (current-column))
11867 (param-list (nth 2 vhdl-subprog-list))
11868 list-margin start names param)
11869 ;; paste keyword and name
11870 (vhdl-insert-keyword
11871 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11872 (insert (nth 0 vhdl-subprog-list))
11873 (if (not param-list)
11874 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11875 (setq start (point))
11876 ;; paste parameter list
11878 (unless vhdl-argument-list-indent
11879 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11880 (setq list-margin (current-column))
11882 (setq param (car param-list))
11883 ;; paste group comment and spacing
11884 (when (memq vhdl-include-group-comments (list kind 'always))
11885 (vhdl-paste-group-comment (nth 6 param) list-margin))
11887 (when (nth 1 param) (insert (nth 1 param) " "))
11889 (setq names (nth 0 param))
11891 (insert (car names))
11892 (setq names (cdr names))
11893 (when names (insert ", ")))
11896 (when (nth 2 param) (insert (nth 2 param) " "))
11898 (insert (nth 3 param))
11899 ;; paste initialization
11900 (when (nth 4 param) (insert " := " (nth 4 param)))
11902 (if (cdr param-list)
11905 (when (null (nth 3 vhdl-subprog-list))
11906 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11908 (when (and vhdl-include-port-comments (nth 5 param))
11909 (vhdl-comment-insert-inline (nth 5 param) t))
11910 (setq param-list (cdr param-list))
11911 (when param-list (insert "\n") (indent-to list-margin)))
11912 (when (nth 3 vhdl-subprog-list)
11913 (insert "\n") (indent-to list-margin)
11914 ;; paste group comment and spacing
11915 (when (memq vhdl-include-group-comments (list kind 'always))
11916 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11917 ;; paste return type
11918 (insert "return " (nth 3 vhdl-subprog-list))
11919 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11920 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11921 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11922 ;; align parameter list
11923 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11925 (when (eq kind 'body)
11927 (vhdl-template-begin-end
11928 (unless (vhdl-standard-p '87)
11929 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11930 (nth 0 vhdl-subprog-list) margin))))
11932 (defun vhdl-subprog-paste-declaration ()
11933 "Paste as a subprogram declaration."
11935 (if (not vhdl-subprog-list)
11936 (error "ERROR: No subprogram interface read")
11937 (message "Pasting interface as subprogram declaration \"%s\"..."
11938 (car vhdl-subprog-list))
11939 ;; paste specification
11940 (vhdl-subprog-paste-specification 'decl)
11941 (message "Pasting interface as subprogram declaration \"%s\"...done"
11942 (car vhdl-subprog-list))))
11944 (defun vhdl-subprog-paste-body ()
11945 "Paste as a subprogram body."
11947 (if (not vhdl-subprog-list)
11948 (error "ERROR: No subprogram interface read")
11949 (message "Pasting interface as subprogram body \"%s\"..."
11950 (car vhdl-subprog-list))
11951 ;; paste specification and body
11952 (vhdl-subprog-paste-specification 'body)
11953 (message "Pasting interface as subprogram body \"%s\"...done"
11954 (car vhdl-subprog-list))))
11956 (defun vhdl-subprog-paste-call ()
11957 "Paste as a subprogram call."
11959 (if (not vhdl-subprog-list)
11960 (error "ERROR: No subprogram interface read")
11961 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11962 param-list margin list-margin param start)
11963 ;; flatten local copy of interface list (must be flat for parameter mapping)
11964 (vhdl-subprog-flatten)
11965 (setq param-list (nth 2 vhdl-subprog-list))
11966 (indent-according-to-mode)
11967 (setq margin (current-indentation))
11968 (message "Pasting interface as subprogram call \"%s\"..."
11969 (car vhdl-subprog-list))
11971 (insert (nth 0 vhdl-subprog-list))
11972 (if (not param-list)
11974 (setq start (point))
11975 ;; paste parameter list
11977 (unless vhdl-argument-list-indent
11978 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11979 (setq list-margin (current-column))
11981 (setq param (car param-list))
11982 ;; paste group comment and spacing
11983 (when (eq vhdl-include-group-comments 'always)
11984 (vhdl-paste-group-comment (nth 6 param) list-margin))
11985 ;; paste formal port
11986 (insert (car (nth 0 param)) " => ")
11987 (setq param-list (cdr param-list))
11988 (insert (if param-list "," ");"))
11990 (when (and vhdl-include-port-comments (nth 5 param))
11991 (vhdl-comment-insert-inline (nth 5 param)))
11992 (when param-list (insert "\n") (indent-to list-margin)))
11993 ;; align parameter list
11994 (when vhdl-auto-align
11995 (vhdl-align-region-groups start (point) 1)))
11996 (message "Pasting interface as subprogram call \"%s\"...done"
11997 (car vhdl-subprog-list))
11998 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12006 ;; Hippie expand customization
12008 (defvar vhdl-expand-upper-case nil)
12010 (defun vhdl-try-expand-abbrev (old)
12011 "Try expanding abbreviations from `vhdl-abbrev-list'."
12013 (he-init-string (he-dabbrev-beg) (point))
12014 (setq he-expand-list
12015 (let ((abbrev-list vhdl-abbrev-list)
12016 (sel-abbrev-list '()))
12018 (when (or (not (stringp (car abbrev-list)))
12020 (concat "^" he-search-string) (car abbrev-list)))
12021 (setq sel-abbrev-list
12022 (cons (car abbrev-list) sel-abbrev-list)))
12023 (setq abbrev-list (cdr abbrev-list)))
12024 (nreverse sel-abbrev-list))))
12025 (while (and he-expand-list
12026 (or (not (stringp (car he-expand-list)))
12027 (he-string-member (car he-expand-list) he-tried-table t)))
12028 ; (equal (car he-expand-list) he-search-string)))
12029 (unless (stringp (car he-expand-list))
12030 (setq vhdl-expand-upper-case (car he-expand-list)))
12031 (setq he-expand-list (cdr he-expand-list)))
12032 (if (null he-expand-list)
12033 (progn (when old (he-reset-string))
12035 (he-substitute-string
12036 (if vhdl-expand-upper-case
12037 (upcase (car he-expand-list))
12038 (car he-expand-list))
12040 (setq he-expand-list (cdr he-expand-list))
12043 (defun vhdl-he-list-beg ()
12044 "Also looks at the word before `(' in order to better match parenthesized
12045 expressions (e.g. for index ranges of types and signals)."
12048 (progn (backward-up-list 1)
12049 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12053 ;; override `he-list-beg' from `hippie-exp'
12054 (unless (and (boundp 'viper-mode) viper-mode)
12055 (defalias 'he-list-beg 'vhdl-he-list-beg))
12057 ;; function for expanding abbrevs and dabbrevs
12058 (defun vhdl-expand-abbrev (arg))
12059 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12060 '(try-expand-dabbrev
12061 try-expand-dabbrev-all-buffers
12062 vhdl-try-expand-abbrev)))
12064 ;; function for expanding parenthesis
12065 (defun vhdl-expand-paren (arg))
12066 (fset 'vhdl-expand-paren (make-hippie-expand-function
12068 try-expand-list-all-buffers)))
12070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12073 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12074 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12075 depending on parameter UPPER-CASE."
12076 (let ((case-replace nil)
12078 (vhdl-prepare-search-2
12081 (setq end (point-marker))
12083 (while (re-search-forward word-regexp end t)
12084 (or (vhdl-in-literal)
12087 (downcase-word -1)))
12088 (when (and count vhdl-progress-interval (not noninteractive)
12089 (< vhdl-progress-interval
12090 (- (nth 1 (current-time)) last-update)))
12091 (message "Fixing case... (%2d%s)"
12092 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12094 (setq last-update (nth 1 (current-time)))))
12095 (goto-char end)))))
12097 (defun vhdl-fix-case-region (beg end &optional arg)
12098 "Convert all VHDL words in region to lower or upper case, depending on
12099 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12100 (interactive "r\nP")
12101 (vhdl-fix-case-region-1
12102 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12103 (vhdl-fix-case-region-1
12104 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12105 (vhdl-fix-case-region-1
12106 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12107 (vhdl-fix-case-region-1
12108 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12109 (when vhdl-progress-interval (message "Fixing case...done")))
12111 (defun vhdl-fix-case-buffer ()
12112 "Convert all VHDL words in buffer to lower or upper case, depending on
12113 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12115 (vhdl-fix-case-region (point-min) (point-max)))
12117 (defun vhdl-fix-case-word (&optional arg)
12118 "Convert word after cursor to upper case if necessary."
12121 (when arg (backward-word 1))
12122 (vhdl-prepare-search-1
12123 (when (and vhdl-upper-case-keywords
12124 (looking-at vhdl-keywords-regexp))
12126 (when (and vhdl-upper-case-types
12127 (looking-at vhdl-types-regexp))
12129 (when (and vhdl-upper-case-attributes
12130 (looking-at vhdl-attributes-regexp))
12132 (when (and vhdl-upper-case-enum-values
12133 (looking-at vhdl-enum-values-regexp))
12134 (upcase-word 1)))))
12136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12137 ;; Line handling functions
12139 (defun vhdl-current-line ()
12140 "Return the line number of the line containing point."
12144 (beginning-of-line)
12145 (1+ (count-lines (point-min) (point))))))
12147 (defun vhdl-line-kill-entire (&optional arg)
12148 "Delete entire line."
12150 (beginning-of-line)
12151 (kill-line (or arg 1)))
12153 (defun vhdl-line-kill (&optional arg)
12154 "Kill current line."
12156 (vhdl-line-kill-entire arg))
12158 (defun vhdl-line-copy (&optional arg)
12159 "Copy current line."
12162 (beginning-of-line)
12163 (let ((position (point)))
12164 (forward-line (or arg 1))
12165 (copy-region-as-kill position (point)))))
12167 (defun vhdl-line-yank ()
12168 "Yank entire line."
12170 (beginning-of-line)
12173 (defun vhdl-line-expand (&optional prefix-arg)
12174 "Hippie-expand current line."
12176 (let ((case-fold-search t) (case-replace nil)
12177 (hippie-expand-try-functions-list
12178 '(try-expand-line try-expand-line-all-buffers)))
12179 (hippie-expand prefix-arg)))
12181 (defun vhdl-line-transpose-next (&optional arg)
12182 "Interchange this line with next line."
12185 (transpose-lines (or arg 1))
12188 (defun vhdl-line-transpose-previous (&optional arg)
12189 "Interchange this line with previous line."
12192 (transpose-lines (- 0 (or arg 0)))
12195 (defun vhdl-line-open ()
12196 "Open a new line and indent."
12199 (newline-and-indent))
12201 (defun vhdl-delete-indentation ()
12202 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12203 it works within comments too."
12205 (let ((fill-prefix "-- "))
12206 (delete-indentation)))
12208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12211 (defun vhdl-forward-same-indent ()
12212 "Move forward to next line with same indent."
12214 (let ((pos (point))
12215 (indent (current-indentation)))
12216 (beginning-of-line 2)
12217 (while (and (not (eobp))
12218 (or (looking-at "^\\s-*\\(--.*\\)?$")
12219 (> (current-indentation) indent)))
12220 (beginning-of-line 2))
12221 (if (= (current-indentation) indent)
12222 (back-to-indentation)
12223 (message "No following line with same indent found in this block")
12227 (defun vhdl-backward-same-indent ()
12228 "Move backward to previous line with same indent."
12230 (let ((pos (point))
12231 (indent (current-indentation)))
12232 (beginning-of-line -0)
12233 (while (and (not (bobp))
12234 (or (looking-at "^\\s-*\\(--.*\\)?$")
12235 (> (current-indentation) indent)))
12236 (beginning-of-line -0))
12237 (if (= (current-indentation) indent)
12238 (back-to-indentation)
12239 (message "No preceding line with same indent found in this block")
12243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12246 (defun vhdl-statistics-buffer ()
12247 "Get some file statistics."
12251 (no-lines (count-lines (point-min) (point-max))))
12253 ;; count statements
12254 (goto-char (point-min))
12255 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12256 (if (match-string 1)
12257 (goto-char (match-end 1))
12258 (setq no-stats (1+ no-stats))))
12259 ;; count code lines
12260 (goto-char (point-min))
12261 (while (not (eobp))
12262 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12263 (setq no-code-lines (1+ no-code-lines)))
12264 (beginning-of-line 2)))
12267 File statistics: \"%s\"\n\
12268 ---------------------\n\
12269 # statements : %5d\n\
12270 # code lines : %5d\n\
12271 # total lines : %5d\n\ "
12272 (buffer-file-name) no-stats no-code-lines no-lines)
12273 (unless vhdl-emacs-21 (vhdl-show-messages))))
12275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12278 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12279 "Like `re-search-forward', but does not match within literals."
12282 (while (and (setq pos (re-search-forward regexp bound noerror count))
12283 (vhdl-in-literal))))
12284 (when pos (goto-char pos))
12287 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12288 "Like `re-search-backward', but does not match within literals."
12291 (while (and (setq pos (re-search-backward regexp bound noerror count))
12292 (vhdl-in-literal))))
12293 (when pos (goto-char pos))
12297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12301 (defun vhdl-set-project (name)
12302 "Set current project to NAME."
12304 (list (let ((completion-ignore-case t))
12305 (completing-read "Project name: " vhdl-project-alist nil t))))
12306 (cond ((equal name "")
12307 (setq vhdl-project nil)
12308 (message "Current VHDL project: None"))
12309 ((assoc name vhdl-project-alist)
12310 (setq vhdl-project name)
12311 (message "Current VHDL project: \"%s\"" name))
12313 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12314 (vhdl-speedbar-update-current-project))
12316 (defun vhdl-set-default-project ()
12317 "Set current project as default on startup."
12319 (customize-set-variable 'vhdl-project vhdl-project)
12320 (customize-save-customized))
12322 (defun vhdl-toggle-project (name token indent)
12323 "Set current project to NAME or unset if NAME is current project."
12324 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12326 (defun vhdl-export-project (file-name)
12327 "Write project setup for current project."
12329 (let ((name (vhdl-resolve-env-variable
12330 (vhdl-replace-string
12331 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12332 (concat (subst-char-in-string
12333 ? ?_ (or (vhdl-project-p)
12334 (error "ERROR: No current project")))
12335 " " (user-login-name))))))
12336 (list (read-file-name
12337 "Write project file: "
12338 (when (file-name-absolute-p name) "") nil nil name))))
12339 (setq file-name (abbreviate-file-name file-name))
12340 (let ((orig-buffer (current-buffer)))
12341 (unless (file-exists-p (file-name-directory file-name))
12342 (make-directory (file-name-directory file-name) t))
12343 (if (not (file-writable-p file-name))
12344 (error "ERROR: File not writable: \"%s\"" file-name)
12345 (set-buffer (find-file-noselect file-name t t))
12347 (insert ";; -*- Emacs-Lisp -*-\n\n"
12348 ";;; " (file-name-nondirectory file-name)
12349 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12350 ";; Project : " vhdl-project "\n"
12351 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12352 (user-login-name) "\n\n\n"
12353 ";; project name\n"
12354 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12355 ";; project setup\n"
12356 "(aput 'vhdl-project-alist vhdl-project\n'")
12357 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12360 (kill-buffer (current-buffer))
12361 (set-buffer orig-buffer))))
12363 (defun vhdl-import-project (file-name &optional auto not-make-current)
12364 "Read project setup and set current project."
12366 (let ((name (vhdl-resolve-env-variable
12367 (vhdl-replace-string
12368 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12369 (concat "" " " (user-login-name))))))
12370 (list (read-file-name
12371 "Read project file: " (when (file-name-absolute-p name) "") nil t
12372 (file-name-directory name)))))
12373 (when (file-exists-p file-name)
12375 (let ((current-project vhdl-project))
12376 (load-file file-name)
12377 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12378 (adelete 'vhdl-project-alist vhdl-project)
12380 (when not-make-current
12381 (setq vhdl-project current-project))
12382 (vhdl-update-mode-menu)
12383 (vhdl-speedbar-refresh)
12384 (unless not-make-current
12385 (message "Current VHDL project: \"%s\"%s"
12386 vhdl-project (if auto " (auto-loaded)" ""))))
12387 (error (vhdl-warning
12388 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12390 (defun vhdl-duplicate-project ()
12391 "Duplicate setup of current project."
12393 (let ((new-name (read-from-minibuffer "New project name: "))
12394 (project-entry (aget vhdl-project-alist vhdl-project t)))
12395 (setq vhdl-project-alist
12396 (append vhdl-project-alist
12397 (list (cons new-name project-entry))))
12398 (vhdl-update-mode-menu)))
12400 (defun vhdl-auto-load-project ()
12401 "Automatically load project setup at startup."
12402 (let ((file-name-list vhdl-project-file-name)
12403 file-list list-length)
12404 (while file-name-list
12407 (file-expand-wildcards
12408 (vhdl-resolve-env-variable
12409 (vhdl-replace-string
12410 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12411 (concat "\*" " " (user-login-name)))))))
12412 (setq list-length (or list-length (length file-list)))
12413 (setq file-name-list (cdr file-name-list)))
12415 (vhdl-import-project (expand-file-name (car file-list)) t
12416 (not (> list-length 0)))
12417 (setq list-length (1- list-length))
12418 (setq file-list (cdr file-list)))))
12420 ;; automatically load project setup when idle after startup
12421 (when (memq 'startup vhdl-project-auto-load)
12423 (vhdl-auto-load-project)
12424 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12430 ;; (using `hideshow.el')
12432 (defconst vhdl-hs-start-regexp
12435 ;; generic/port clause
12436 "\\(generic\\|port\\)[ \t\n]*(\\|"
12439 ;; component instantiation
12440 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12441 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12442 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12443 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12445 "\\(function\\|procedure\\)\\>\\|"
12447 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12448 ;; configuration declaration
12451 "Regexp to match start of construct to hide.")
12453 (defun vhdl-hs-forward-sexp-func (count)
12454 "Find end of construct to hide (for hideshow). Only searches forward."
12455 (let ((pos (point)))
12456 (vhdl-prepare-search-2
12457 (beginning-of-line)
12459 ;; generic/port clause
12460 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12461 (goto-char (match-end 0))
12464 ;; component declaration
12465 ((looking-at "^\\s-*component\\>")
12466 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12467 ;; component instantiation
12470 "^\\s-*\\w+\\s-*:[ \t\n]*"
12471 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12472 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12473 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12474 (goto-char (match-end 0))
12478 (vhdl-forward-syntactic-ws)
12479 (when (looking-at "port\\s-+map[ \t\n]*(")
12480 (goto-char (match-end 0))
12483 (setq pos (point)))
12485 ;; subprogram declaration/body
12486 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12487 (goto-char (match-end 0))
12488 (vhdl-forward-syntactic-ws)
12489 (when (looking-at "(")
12491 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12492 (vhdl-in-literal)))
12494 (when (match-string 2)
12495 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12497 (vhdl-forward-sexp)))
12498 ;; block (recursive)
12499 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12500 (goto-char (match-end 0))
12501 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12502 (match-beginning 2))
12503 (vhdl-hs-forward-sexp-func count)))
12505 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12506 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12507 ;; configuration declaration
12508 ((looking-at "^\\s-*configuration\\>")
12510 (vhdl-forward-sexp))
12511 (t (goto-char pos))))))
12513 (defun vhdl-hideshow-init ()
12514 "Initialize `hideshow'."
12515 (when vhdl-hideshow-menu
12516 (vhdl-hs-minor-mode 1)))
12518 (defun vhdl-hs-minor-mode (&optional arg)
12519 "Toggle hideshow minor mode and update menu bar."
12521 (require 'hideshow)
12522 ;; check for hideshow version 5.x
12523 (if (not (boundp 'hs-block-start-mdata-select))
12524 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12525 ;; initialize hideshow
12526 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12527 (setq hs-special-modes-alist
12528 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12529 'vhdl-hs-forward-sexp-func nil)
12530 hs-special-modes-alist)))
12531 (make-local-variable 'hs-minor-mode-hook)
12532 (if vhdl-hide-all-init
12533 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12534 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12535 (hs-minor-mode arg)
12536 (vhdl-mode-line-update))) ; hack to update menu bar
12539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12542 ;; (using `font-lock.el')
12544 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12547 (defun vhdl-within-translate-off ()
12548 "Return point if within translate-off region, else nil."
12549 (and (save-excursion
12550 (re-search-backward
12551 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12552 (equal "off" (match-string 1))
12555 (defun vhdl-start-translate-off (limit)
12556 "Return point before translate-off pragma if before LIMIT, else nil."
12557 (when (re-search-forward
12558 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12559 (match-beginning 0)))
12561 (defun vhdl-end-translate-off (limit)
12562 "Return point after translate-on pragma if before LIMIT, else nil."
12563 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12565 (defun vhdl-match-translate-off (limit)
12566 "Match a translate-off block, setting match-data and returning t, else nil."
12567 (when (< (point) limit)
12568 (let ((start (or (vhdl-within-translate-off)
12569 (vhdl-start-translate-off limit)))
12570 (case-fold-search t))
12572 (let ((end (or (vhdl-end-translate-off limit) limit)))
12573 (set-match-data (list start end))
12574 (goto-char end))))))
12576 (defun vhdl-font-lock-match-item (limit)
12577 "Match, and move over, any declaration item after point. Adapted from
12578 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12579 (condition-case nil
12581 (narrow-to-region (point-min) limit)
12583 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12585 (goto-char (match-end 1))
12586 ;; move to next item
12587 (if (looking-at "\\(\\s-*,\\)")
12588 (goto-char (match-end 1))
12589 (end-of-line) t))))
12592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12593 ;; Syntax definitions
12595 (defconst vhdl-font-lock-syntactic-keywords
12596 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12597 "Mark single quotes as having string quote syntax in 'c' instances.")
12599 (defvar vhdl-font-lock-keywords nil
12600 "Regular expressions to highlight in VHDL Mode.")
12602 (defvar vhdl-font-lock-keywords-0
12603 ;; set in `vhdl-font-lock-init' because dependent on user options
12604 "For consideration as a value of `vhdl-font-lock-keywords'.
12605 This does highlighting of template prompts and directives (pragmas).")
12607 (defvar vhdl-font-lock-keywords-1 nil
12608 ;; set in `vhdl-font-lock-init' because dependent on user options
12609 "For consideration as a value of `vhdl-font-lock-keywords'.
12610 This does highlighting of keywords and standard identifiers.")
12612 (defconst vhdl-font-lock-keywords-2
12614 ;; highlight names of units, subprograms, and components when declared
12618 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12619 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12620 "\\)\\s-+\\(\\w+\\)")
12621 5 'font-lock-function-name-face)
12623 ;; highlight entity names of architectures and configurations
12625 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12626 2 'font-lock-function-name-face)
12628 ;; highlight labels of common constructs
12631 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12632 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12633 "postponed\\|process\\|"
12634 (when (vhdl-standard-p 'ams) "procedural\\|")
12636 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12637 1 'font-lock-function-name-face)
12639 ;; highlight label and component name of component instantiations
12642 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12643 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12644 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12646 ;; highlight label and instantiated unit of component instantiations
12649 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12650 "\\(component\\|configuration\\|entity\\)\\s-+"
12651 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12652 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12653 '(5 font-lock-function-name-face nil t)
12654 '(7 font-lock-function-name-face nil t))
12656 ;; highlight names and labels at end of constructs
12659 "^\\s-*end\\s-+\\(\\("
12660 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12661 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12662 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12663 (when (vhdl-standard-p 'ams) "procedural\\|")
12665 "\\)\\s-+\\)?\\(\\w*\\)")
12666 5 'font-lock-function-name-face)
12668 ;; highlight labels in exit and next statements
12671 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12672 3 'font-lock-function-name-face)
12674 ;; highlight entity name in attribute specifications
12677 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12678 1 'font-lock-function-name-face)
12680 ;; highlight labels in block and component specifications
12683 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12684 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12685 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12687 ;; highlight names in library clauses
12688 (list "^\\s-*library\\>"
12689 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12691 ;; highlight names in use clauses
12694 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12695 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12696 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12697 '(7 font-lock-function-name-face nil t))
12699 ;; highlight attribute name in attribute declarations/specifications
12702 "^\\s-*attribute\\s-+\\(\\w+\\)")
12703 1 'vhdl-font-lock-attribute-face)
12705 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12708 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12709 3 'font-lock-type-face)
12711 ;; highlight signal/variable/constant declaration names
12712 (list "\\(:[^=]\\)"
12713 '(vhdl-font-lock-match-item
12714 (progn (goto-char (match-beginning 1))
12715 (skip-syntax-backward " ")
12716 (skip-syntax-backward "w_")
12717 (skip-syntax-backward " ")
12718 (while (= (preceding-char) ?,)
12720 (skip-syntax-backward " ")
12721 (skip-syntax-backward "w_")
12722 (skip-syntax-backward " ")))
12723 ; (skip-chars-backward "^-(\n\";")
12724 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12726 ;; highlight formal parameters in component instantiations and subprogram
12729 '(vhdl-font-lock-match-item
12730 (progn (goto-char (match-beginning 1))
12731 (skip-syntax-backward " ")
12732 (while (= (preceding-char) ?\)) (backward-sexp))
12733 (skip-syntax-backward "w_")
12734 (skip-syntax-backward " ")
12735 (when (memq (preceding-char) '(?n ?N ?|))
12736 (goto-char (point-max))))
12737 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12739 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12741 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12742 '(vhdl-font-lock-match-item
12743 (progn (goto-char (match-end 1)) (match-beginning 2))
12744 nil (1 font-lock-variable-name-face)))
12746 "For consideration as a value of `vhdl-font-lock-keywords'.
12747 This does context sensitive highlighting of names and labels.")
12749 (defvar vhdl-font-lock-keywords-3 nil
12750 ;; set in `vhdl-font-lock-init' because dependent on user options
12751 "For consideration as a value of `vhdl-font-lock-keywords'.
12752 This does highlighting of words with special syntax.")
12754 (defvar vhdl-font-lock-keywords-4 nil
12755 ;; set in `vhdl-font-lock-init' because dependent on user options
12756 "For consideration as a value of `vhdl-font-lock-keywords'.
12757 This does highlighting of additional reserved words.")
12759 (defconst vhdl-font-lock-keywords-5
12760 ;; background highlight translate-off regions
12761 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12762 "For consideration as a value of `vhdl-font-lock-keywords'.
12763 This does background highlighting of translate-off regions.")
12765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12766 ;; Font and color definitions
12768 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12769 "Face name to use for prompts.")
12771 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12772 "Face name to use for standardized attributes.")
12774 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12775 "Face name to use for standardized enumeration values.")
12777 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12778 "Face name to use for standardized functions and packages.")
12780 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12781 "Face name to use for directives.")
12783 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12784 "Face name to use for additional reserved words.")
12786 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12787 "Face name to use for translate-off regions.")
12789 ;; face names to use for words with special syntax.
12790 (let ((syntax-alist vhdl-special-syntax-alist)
12792 (while syntax-alist
12793 (setq name (vhdl-function-name
12794 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12795 (eval `(defvar ,name ',name
12796 ,(concat "Face name to use for "
12797 (nth 0 (car syntax-alist)) ".")))
12798 (setq syntax-alist (cdr syntax-alist))))
12800 (defgroup vhdl-highlight-faces nil
12801 "Faces for highlighting."
12802 :group 'vhdl-highlight)
12804 ;; add faces used from `font-lock'
12805 (custom-add-to-group
12806 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12807 (custom-add-to-group
12808 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12809 (custom-add-to-group
12810 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12811 (custom-add-to-group
12812 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12813 (custom-add-to-group
12814 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12815 (custom-add-to-group
12816 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12818 (defface vhdl-font-lock-prompt-face
12819 '((((min-colors 88) (class color) (background light))
12820 (:foreground "Red1" :bold t))
12821 (((class color) (background light)) (:foreground "Red" :bold t))
12822 (((class color) (background dark)) (:foreground "Pink" :bold t))
12823 (t (:inverse-video t)))
12824 "Font lock mode face used to highlight prompts."
12825 :group 'vhdl-highlight-faces)
12827 (defface vhdl-font-lock-attribute-face
12828 '((((class color) (background light)) (:foreground "Orchid"))
12829 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12830 (t (:italic t :bold t)))
12831 "Font lock mode face used to highlight standardized attributes."
12832 :group 'vhdl-highlight-faces)
12834 (defface vhdl-font-lock-enumvalue-face
12835 '((((class color) (background light)) (:foreground "SaddleBrown"))
12836 (((class color) (background dark)) (:foreground "BurlyWood"))
12837 (t (:italic t :bold t)))
12838 "Font lock mode face used to highlight standardized enumeration values."
12839 :group 'vhdl-highlight-faces)
12841 (defface vhdl-font-lock-function-face
12842 '((((class color) (background light)) (:foreground "Cyan4"))
12843 (((class color) (background dark)) (:foreground "Orchid1"))
12844 (t (:italic t :bold t)))
12845 "Font lock mode face used to highlight standardized functions and packages."
12846 :group 'vhdl-highlight-faces)
12848 (defface vhdl-font-lock-directive-face
12849 '((((class color) (background light)) (:foreground "CadetBlue"))
12850 (((class color) (background dark)) (:foreground "Aquamarine"))
12851 (t (:italic t :bold t)))
12852 "Font lock mode face used to highlight directives."
12853 :group 'vhdl-highlight-faces)
12855 (defface vhdl-font-lock-reserved-words-face
12856 '((((class color) (background light)) (:foreground "Orange" :bold t))
12857 (((min-colors 88) (class color) (background dark))
12858 (:foreground "Yellow1" :bold t))
12859 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12861 "Font lock mode face used to highlight additional reserved words."
12862 :group 'vhdl-highlight-faces)
12864 (defface vhdl-font-lock-translate-off-face
12865 '((((class color) (background light)) (:background "LightGray"))
12866 (((class color) (background dark)) (:background "DimGray"))
12868 "Font lock mode face used to background highlight translate-off regions."
12869 :group 'vhdl-highlight-faces)
12871 ;; font lock mode faces used to highlight words with special syntax.
12872 (let ((syntax-alist vhdl-special-syntax-alist))
12873 (while syntax-alist
12874 (eval `(defface ,(vhdl-function-name
12875 "vhdl-font-lock" (caar syntax-alist) "face")
12876 '((((class color) (background light))
12877 (:foreground ,(nth 2 (car syntax-alist))))
12878 (((class color) (background dark))
12879 (:foreground ,(nth 3 (car syntax-alist))))
12881 ,(concat "Font lock mode face used to highlight "
12882 (nth 0 (car syntax-alist)) ".")
12883 :group 'vhdl-highlight-faces))
12884 (setq syntax-alist (cdr syntax-alist))))
12886 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12887 ;; Font lock initialization
12889 (defun vhdl-font-lock-init ()
12890 "Initialize fontification."
12891 ;; highlight template prompts and directives
12892 (setq vhdl-font-lock-keywords-0
12893 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12894 vhdl-template-prompt-syntax ">\\)")
12895 2 'vhdl-font-lock-prompt-face t)
12896 (list (concat "--\\s-*"
12897 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12898 2 'vhdl-font-lock-directive-face t)
12899 ;; highlight c-preprocessor directives
12900 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12901 '(1 font-lock-builtin-face)
12902 '(3 font-lock-variable-name-face nil t))))
12903 ;; highlight keywords and standardized types, attributes, enumeration
12904 ;; values, and subprograms
12905 (setq vhdl-font-lock-keywords-1
12907 (list (concat "'" vhdl-attributes-regexp)
12908 1 'vhdl-font-lock-attribute-face)
12909 (list vhdl-types-regexp 1 'font-lock-type-face)
12910 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12911 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12912 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12913 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12914 ;; highlight words with special syntax.
12915 (setq vhdl-font-lock-keywords-3
12916 (let ((syntax-alist vhdl-special-syntax-alist)
12918 (while syntax-alist
12921 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12922 (vhdl-function-name
12923 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12925 (setq syntax-alist (cdr syntax-alist)))
12927 ;; highlight additional reserved words
12928 (setq vhdl-font-lock-keywords-4
12929 (list (list vhdl-reserved-words-regexp 1
12930 'vhdl-font-lock-reserved-words-face)))
12931 ;; highlight everything together
12932 (setq vhdl-font-lock-keywords
12934 vhdl-font-lock-keywords-0
12935 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12936 (when (or vhdl-highlight-forbidden-words
12937 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12938 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12939 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12940 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12942 ;; initialize fontification for VHDL Mode
12943 (vhdl-font-lock-init)
12945 (defun vhdl-fontify-buffer ()
12946 "Re-initialize fontification and fontify buffer."
12948 (setq font-lock-defaults
12950 'vhdl-font-lock-keywords nil
12951 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12952 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12953 (when (fboundp 'font-lock-unset-defaults)
12954 (font-lock-unset-defaults)) ; not implemented in XEmacs
12955 (font-lock-set-defaults)
12956 (font-lock-mode nil)
12957 (font-lock-mode t))
12959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12960 ;; Initialization for postscript printing
12962 (defun vhdl-ps-print-settings ()
12963 "Initialize custom face and page settings for postscript printing."
12964 ;; define custom face settings
12965 (unless (or (not vhdl-print-customize-faces)
12967 (set (make-local-variable 'ps-bold-faces)
12968 '(font-lock-keyword-face
12969 font-lock-type-face
12970 vhdl-font-lock-attribute-face
12971 vhdl-font-lock-enumvalue-face
12972 vhdl-font-lock-directive-face))
12973 (set (make-local-variable 'ps-italic-faces)
12974 '(font-lock-comment-face
12975 font-lock-function-name-face
12976 font-lock-type-face
12977 vhdl-font-lock-attribute-face
12978 vhdl-font-lock-enumvalue-face
12979 vhdl-font-lock-directive-face))
12980 (set (make-local-variable 'ps-underlined-faces)
12981 '(font-lock-string-face))
12982 (setq ps-always-build-face-reference t))
12983 ;; define page settings, so that a line containing 79 characters (default)
12984 ;; fits into one column
12985 (when vhdl-print-two-column
12986 (set (make-local-variable 'ps-landscape-mode) t)
12987 (set (make-local-variable 'ps-number-of-columns) 2)
12988 (set (make-local-variable 'ps-font-size) 7.0)
12989 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12990 (set (make-local-variable 'ps-header-font-size) 9.0)
12991 (set (make-local-variable 'ps-header-offset) 12.0)
12992 (when (eq ps-paper-type 'letter)
12993 (set (make-local-variable 'ps-inter-column) 40.0)
12994 (set (make-local-variable 'ps-left-margin) 40.0)
12995 (set (make-local-variable 'ps-right-margin) 40.0))))
12997 (defun vhdl-ps-print-init ()
12998 "Initialize postscript printing."
12999 (if (featurep 'xemacs)
13000 (when (boundp 'ps-print-color-p)
13001 (vhdl-ps-print-settings))
13002 (make-local-variable 'ps-print-hook)
13003 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13007 ;;; Hierarchy browser (using `speedbar.el')
13008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13009 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13010 ;; directory by using the speedbar.
13012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13015 (defvar vhdl-entity-alist nil
13016 "Cache with entities and corresponding architectures for each
13017 project/directory.")
13018 ;; structure: (parenthesised expression means list of such entries)
13020 ;; (ent-key ent-name ent-file ent-line
13021 ;; (arch-key arch-name arch-file arch-line
13022 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13023 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13024 ;; (lib-name pack-key))
13025 ;; mra-key (lib-name pack-key))
13027 (defvar vhdl-config-alist nil
13028 "Cache with configurations for each project/directory.")
13029 ;; structure: (parenthesised expression means list of such entries)
13031 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13032 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13033 ;; inst-conf-key inst-lib-key)
13034 ;; (lib-name pack-key)))
13036 (defvar vhdl-package-alist nil
13037 "Cache with packages for each project/directory.")
13038 ;; structure: (parenthesised expression means list of such entries)
13040 ;; (pack-key pack-name pack-file pack-line
13041 ;; (comp-key comp-name comp-file comp-line)
13042 ;; (func-key func-name func-file func-line)
13043 ;; (lib-name pack-key)
13044 ;; pack-body-file pack-body-line
13045 ;; (func-key func-name func-body-file func-body-line)
13046 ;; (lib-name pack-key)))
13048 (defvar vhdl-ent-inst-alist nil
13049 "Cache with instantiated entities for each project/directory.")
13050 ;; structure: (parenthesised expression means list of such entries)
13051 ;; (cache-key (inst-ent-key))
13053 (defvar vhdl-file-alist nil
13054 "Cache with design units in each file for each project/directory.")
13055 ;; structure: (parenthesised expression means list of such entries)
13057 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13058 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13060 (defvar vhdl-directory-alist nil
13061 "Cache with source directories for each project.")
13062 ;; structure: (parenthesised expression means list of such entries)
13063 ;; (cache-key (directory))
13065 (defvar vhdl-speedbar-shown-unit-alist nil
13066 "Alist of design units simultaneously open in the current speedbar for each
13067 directory and project.")
13069 (defvar vhdl-speedbar-shown-project-list nil
13070 "List of projects simultaneously open in the current speedbar.")
13072 (defvar vhdl-updated-project-list nil
13073 "List of projects and directories with updated files.")
13075 (defvar vhdl-modified-file-list nil
13076 "List of modified files to be rescanned for hierarchy updating.")
13078 (defvar vhdl-speedbar-hierarchy-depth 0
13079 "Depth of instantiation hierarchy to display.")
13081 (defvar vhdl-speedbar-show-projects nil
13082 "Non-nil means project hierarchy is displayed in speedbar, directory
13083 hierarchy otherwise.")
13085 (defun vhdl-get-end-of-unit ()
13086 "Return position of end of current unit."
13087 (let ((pos (point)))
13089 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13091 (goto-char (match-beginning 0))
13092 (vhdl-backward-syntactic-ws)
13093 (and (/= (preceding-char) ?\;) (not (bobp))))))
13094 (re-search-backward "^[ \t]*end\\>" pos 1)
13097 (defun vhdl-match-string-downcase (num &optional string)
13098 "Like `match-string-no-properties' with down-casing."
13099 (let ((match (match-string-no-properties num string)))
13100 (and match (downcase match))))
13103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13106 (defun vhdl-scan-context-clause ()
13107 "Scan the context clause that preceeds a design unit."
13110 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13111 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13112 (equal "USE" (upcase (match-string 1))))
13113 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13114 (setq lib-alist (cons (cons (match-string-no-properties 1)
13115 (vhdl-match-string-downcase 2))
13119 (defun vhdl-scan-directory-contents (name &optional project update num-string
13121 "Scan contents of VHDL files in directory or file pattern NAME."
13122 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13123 ; (unless (file-directory-p (match-string 1 name))
13124 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13125 (let* ((dir-name (match-string 1 name))
13126 (file-pattern (match-string 2 name))
13127 (is-directory (= 0 (length file-pattern)))
13132 (vhdl-get-source-files t dir-name)
13133 (vhdl-directory-files
13134 dir-name t (wildcard-to-regexp file-pattern)))))
13135 (key (or project dir-name))
13136 (file-exclude-regexp
13137 (or (nth 3 (aget vhdl-project-alist project)) ""))
13138 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13139 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13140 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13141 ent-alist conf-alist pack-alist ent-inst-list file-alist
13142 tmp-list tmp-entry no-files files-exist big-files)
13143 (when (or project update)
13144 (setq ent-alist (aget vhdl-entity-alist key t)
13145 conf-alist (aget vhdl-config-alist key t)
13146 pack-alist (aget vhdl-package-alist key t)
13147 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13148 file-alist (aget vhdl-file-alist key t)))
13149 (when (and (not is-directory) (null file-list))
13150 (message "No such file: \"%s\"" name))
13151 (setq files-exist file-list)
13153 (setq no-files (length file-list))
13154 (message "Scanning %s %s\"%s\"..."
13155 (if is-directory "directory" "files") (or num-string "") name)
13157 (unless (equal file-exclude-regexp "")
13158 (let ((case-fold-search nil)
13161 (unless (string-match file-exclude-regexp (car file-list))
13162 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13163 (setq file-list (cdr file-list)))
13164 (setq file-list (nreverse file-tmp-list))))
13165 ;; do for all files
13167 (unless noninteractive
13168 (message "Scanning %s %s\"%s\"... (%2d%s)"
13169 (if is-directory "directory" "files")
13170 (or num-string "") name
13171 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13172 (let ((file-name (abbreviate-file-name (car file-list)))
13173 ent-list arch-list arch-ent-list conf-list
13174 pack-list pack-body-list inst-list inst-ent-list)
13178 (vhdl-prepare-search-2
13180 ;; scan for design units
13181 (if (and limit-design-file-size
13182 (< limit-design-file-size (buffer-size)))
13183 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13184 (setq big-files t))
13185 ;; scan for entities
13186 (goto-char (point-min))
13187 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13188 (let* ((ent-name (match-string-no-properties 1))
13189 (ent-key (downcase ent-name))
13190 (ent-entry (aget ent-alist ent-key t))
13191 (lib-alist (vhdl-scan-context-clause)))
13192 (if (nth 1 ent-entry)
13193 (vhdl-warning-when-idle
13194 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13195 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13196 file-name (vhdl-current-line))
13197 (setq ent-list (cons ent-key ent-list))
13198 (aput 'ent-alist ent-key
13199 (list ent-name file-name (vhdl-current-line)
13200 (nth 3 ent-entry) (nth 4 ent-entry)
13202 ;; scan for architectures
13203 (goto-char (point-min))
13204 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13205 (let* ((arch-name (match-string-no-properties 1))
13206 (arch-key (downcase arch-name))
13207 (ent-name (match-string-no-properties 2))
13208 (ent-key (downcase ent-name))
13209 (ent-entry (aget ent-alist ent-key t))
13210 (arch-alist (nth 3 ent-entry))
13211 (arch-entry (aget arch-alist arch-key t))
13212 (lib-arch-alist (vhdl-scan-context-clause)))
13214 (vhdl-warning-when-idle
13215 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13216 arch-name ent-name (nth 1 arch-entry)
13217 (nth 2 arch-entry) file-name (vhdl-current-line))
13218 (setq arch-list (cons arch-key arch-list)
13219 arch-ent-list (cons ent-key arch-ent-list))
13220 (aput 'arch-alist arch-key
13221 (list arch-name file-name (vhdl-current-line) nil
13223 (aput 'ent-alist ent-key
13224 (list (or (nth 0 ent-entry) ent-name)
13225 (nth 1 ent-entry) (nth 2 ent-entry)
13226 (vhdl-sort-alist arch-alist)
13227 arch-key (nth 5 ent-entry))))))
13228 ;; scan for configurations
13229 (goto-char (point-min))
13230 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13231 (let* ((conf-name (match-string-no-properties 1))
13232 (conf-key (downcase conf-name))
13233 (conf-entry (aget conf-alist conf-key t))
13234 (ent-name (match-string-no-properties 2))
13235 (ent-key (downcase ent-name))
13236 (lib-alist (vhdl-scan-context-clause))
13237 (conf-line (vhdl-current-line))
13238 (end-of-unit (vhdl-get-end-of-unit))
13239 arch-key comp-conf-list inst-key-list
13240 inst-comp-key inst-ent-key inst-arch-key
13241 inst-conf-key inst-lib-key)
13242 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13243 (setq arch-key (vhdl-match-string-downcase 1)))
13245 (vhdl-warning-when-idle
13246 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13247 conf-name ent-name (nth 1 conf-entry)
13248 (nth 2 conf-entry) file-name conf-line)
13249 (setq conf-list (cons conf-key conf-list))
13250 ;; scan for subconfigurations and subentities
13251 (while (re-search-forward "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+" end-of-unit t)
13252 (setq inst-comp-key (vhdl-match-string-downcase 3)
13253 inst-key-list (split-string
13254 (vhdl-match-string-downcase 1)
13255 "[ \t\n]*,[ \t\n]*"))
13256 (vhdl-forward-syntactic-ws)
13257 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13259 inst-lib-key (vhdl-match-string-downcase 3)
13260 inst-ent-key (and (match-string 2)
13261 (vhdl-match-string-downcase 4))
13262 inst-arch-key (and (match-string 2)
13263 (vhdl-match-string-downcase 6))
13264 inst-conf-key (and (not (match-string 2))
13265 (vhdl-match-string-downcase 4)))
13266 (while inst-key-list
13267 (setq comp-conf-list
13268 (cons (list (car inst-key-list)
13269 inst-comp-key inst-ent-key
13270 inst-arch-key inst-conf-key
13273 (setq inst-key-list (cdr inst-key-list)))))
13274 (aput 'conf-alist conf-key
13275 (list conf-name file-name conf-line ent-key
13276 arch-key comp-conf-list lib-alist)))))
13277 ;; scan for packages
13278 (goto-char (point-min))
13279 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13280 (let* ((pack-name (match-string-no-properties 2))
13281 (pack-key (downcase pack-name))
13282 (is-body (match-string-no-properties 1))
13283 (pack-entry (aget pack-alist pack-key t))
13284 (pack-line (vhdl-current-line))
13285 (end-of-unit (vhdl-get-end-of-unit))
13286 comp-name func-name comp-alist func-alist lib-alist)
13287 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13288 (vhdl-warning-when-idle
13289 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13290 (if is-body " body" "") pack-name
13291 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13292 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13293 file-name (vhdl-current-line))
13294 ;; scan for context clauses
13295 (setq lib-alist (vhdl-scan-context-clause))
13296 ;; scan for component and subprogram declarations/bodies
13297 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13298 (if (equal (upcase (match-string 1)) "COMPONENT")
13299 (setq comp-name (match-string-no-properties 2)
13301 (cons (list (downcase comp-name) comp-name
13302 file-name (vhdl-current-line))
13304 (setq func-name (match-string-no-properties 2)
13306 (cons (list (downcase func-name) func-name
13307 file-name (vhdl-current-line))
13309 (setq func-alist (nreverse func-alist))
13310 (setq comp-alist (nreverse comp-alist))
13312 (setq pack-body-list (cons pack-key pack-body-list))
13313 (setq pack-list (cons pack-key pack-list)))
13315 'pack-alist pack-key
13317 (list (or (nth 0 pack-entry) pack-name)
13318 (nth 1 pack-entry) (nth 2 pack-entry)
13319 (nth 3 pack-entry) (nth 4 pack-entry)
13321 file-name pack-line func-alist lib-alist)
13322 (list pack-name file-name pack-line
13323 comp-alist func-alist lib-alist
13324 (nth 6 pack-entry) (nth 7 pack-entry)
13325 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13326 ;; scan for hierarchy
13327 (if (and limit-hier-file-size
13328 (< limit-hier-file-size (buffer-size)))
13329 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13330 (setq big-files t))
13331 ;; scan for architectures
13332 (goto-char (point-min))
13333 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13334 (let* ((ent-name (match-string-no-properties 2))
13335 (ent-key (downcase ent-name))
13336 (arch-name (match-string-no-properties 1))
13337 (arch-key (downcase arch-name))
13338 (ent-entry (aget ent-alist ent-key t))
13339 (arch-alist (nth 3 ent-entry))
13340 (arch-entry (aget arch-alist arch-key t))
13341 (beg-of-unit (point))
13342 (end-of-unit (vhdl-get-end-of-unit))
13344 inst-alist inst-path)
13345 ;; scan for contained instantiations
13346 (while (and (re-search-forward
13347 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13348 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13349 "component[ \t\n]+\\(\\w+\\)\\|"
13350 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13351 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13352 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13353 (or (not limit-hier-inst-no)
13354 (<= (setq inst-no (1+ inst-no))
13355 limit-hier-inst-no)))
13357 ;; block/generate beginning found
13360 (cons (match-string-no-properties 1) inst-path)))
13361 ;; block/generate end found
13363 (setq inst-path (cdr inst-path)))
13364 ;; instantiation found
13366 (let* ((inst-name (match-string-no-properties 1))
13367 (inst-key (downcase inst-name))
13369 (or (match-string-no-properties 3)
13370 (match-string-no-properties 6)))
13372 (or (and (match-string 8)
13373 (vhdl-match-string-downcase 11))
13374 (and inst-comp-name
13375 (downcase inst-comp-name))))
13376 (inst-arch-key (vhdl-match-string-downcase 13))
13378 (and (not (match-string 8))
13379 (vhdl-match-string-downcase 11)))
13380 (inst-lib-key (vhdl-match-string-downcase 10)))
13381 (goto-char (match-end 1))
13382 (setq inst-list (cons inst-key inst-list)
13384 (cons inst-ent-key inst-ent-list))
13388 (list (list inst-key inst-name file-name
13389 (vhdl-current-line) inst-comp-name
13390 inst-ent-key inst-arch-key
13391 inst-conf-key inst-lib-key
13392 (reverse inst-path)))))))))
13393 ;; scan for contained configuration specifications
13394 (goto-char beg-of-unit)
13395 (while (re-search-forward
13396 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13397 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13398 (let* ((inst-comp-name (match-string-no-properties 3))
13400 (and (match-string 6)
13401 (vhdl-match-string-downcase 9)))
13402 (inst-arch-key (vhdl-match-string-downcase 11))
13404 (and (not (match-string 6))
13405 (vhdl-match-string-downcase 9)))
13406 (inst-lib-key (vhdl-match-string-downcase 8))
13408 (split-string (vhdl-match-string-downcase 1)
13409 "[ \t\n]*,[ \t\n]*"))
13410 (tmp-inst-alist inst-alist)
13412 (while tmp-inst-alist
13413 (when (and (or (equal "all" (car inst-key-list))
13414 (member (nth 0 (car tmp-inst-alist))
13418 (or (nth 4 (car tmp-inst-alist)) ""))
13419 (downcase inst-comp-name)))
13420 (setq inst-entry (car tmp-inst-alist))
13421 (setq inst-ent-list
13422 (cons (or inst-ent-key (nth 5 inst-entry))
13424 (nth 5 inst-entry) inst-ent-list)))
13426 (list (nth 0 inst-entry) (nth 1 inst-entry)
13427 (nth 2 inst-entry) (nth 3 inst-entry)
13429 (or inst-ent-key (nth 5 inst-entry))
13430 (or inst-arch-key (nth 6 inst-entry))
13431 inst-conf-key inst-lib-key))
13432 (setcar tmp-inst-alist inst-entry))
13433 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13435 (aput 'arch-alist arch-key
13436 (list (nth 0 arch-entry) (nth 1 arch-entry)
13437 (nth 2 arch-entry) inst-alist
13438 (nth 4 arch-entry)))
13439 (aput 'ent-alist ent-key
13440 (list (nth 0 ent-entry) (nth 1 ent-entry)
13441 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13442 (nth 4 ent-entry) (nth 5 ent-entry)))
13443 (when (and limit-hier-inst-no
13444 (> inst-no limit-hier-inst-no))
13445 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13446 (setq big-files t))
13447 (goto-char end-of-unit))))
13448 ;; remember design units for this file
13449 (aput 'file-alist file-name
13450 (list ent-list arch-list arch-ent-list conf-list
13451 pack-list pack-body-list inst-list inst-ent-list))
13452 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13453 (setq file-list (cdr file-list))))
13454 (when (or (and (not project) files-exist)
13455 (and project (not non-final)))
13456 ;; consistency checks:
13457 ;; check whether each architecture has a corresponding entity
13458 (setq tmp-list ent-alist)
13460 (when (null (nth 2 (car tmp-list)))
13461 (setq tmp-entry (car (nth 4 (car tmp-list))))
13462 (vhdl-warning-when-idle
13463 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13464 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13465 (nth 3 tmp-entry)))
13466 (setq tmp-list (cdr tmp-list)))
13467 ;; check whether configuration has a corresponding entity/architecture
13468 (setq tmp-list conf-alist)
13470 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13471 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13472 (setq tmp-entry (car tmp-list))
13473 (vhdl-warning-when-idle
13474 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13475 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13476 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13477 (setq tmp-entry (car tmp-list))
13478 (vhdl-warning-when-idle
13479 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13480 (nth 1 tmp-entry) (nth 4 tmp-entry)
13481 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13482 (setq tmp-list (cdr tmp-list)))
13483 ;; check whether each package body has a package declaration
13484 (setq tmp-list pack-alist)
13486 (when (null (nth 2 (car tmp-list)))
13487 (setq tmp-entry (car tmp-list))
13488 (vhdl-warning-when-idle
13489 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13490 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13491 (setq tmp-list (cdr tmp-list)))
13493 (setq ent-alist (vhdl-sort-alist ent-alist))
13494 (setq conf-alist (vhdl-sort-alist conf-alist))
13495 (setq pack-alist (vhdl-sort-alist pack-alist))
13496 ;; remember updated directory/project
13497 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13498 ;; clear directory alists
13500 (adelete 'vhdl-entity-alist key)
13501 (adelete 'vhdl-config-alist key)
13502 (adelete 'vhdl-package-alist key)
13503 (adelete 'vhdl-ent-inst-alist key)
13504 (adelete 'vhdl-file-alist key))
13505 ;; put directory contents into cache
13506 (aput 'vhdl-entity-alist key ent-alist)
13507 (aput 'vhdl-config-alist key conf-alist)
13508 (aput 'vhdl-package-alist key pack-alist)
13509 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13510 (aput 'vhdl-file-alist key file-alist)
13512 (message "Scanning %s %s\"%s\"...done"
13513 (if is-directory "directory" "files") (or num-string "") name)
13514 (unless project (message "Scanning directory...done"))
13516 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13517 ;; save cache when scanned non-interactively
13518 (when (or (not project) (not non-final))
13519 (when (and noninteractive vhdl-speedbar-save-cache)
13520 (vhdl-save-cache key)))
13523 (defun vhdl-scan-project-contents (project)
13524 "Scan the contents of all VHDL files found in the directories and files
13526 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13527 (default-dir (vhdl-resolve-env-variable
13528 (nth 1 (aget vhdl-project-alist project))))
13529 (file-exclude-regexp
13530 (or (nth 3 (aget vhdl-project-alist project)) ""))
13531 dir-list-tmp dir dir-name num-dir act-dir recursive)
13532 ;; clear project alists
13533 (adelete 'vhdl-entity-alist project)
13534 (adelete 'vhdl-config-alist project)
13535 (adelete 'vhdl-package-alist project)
13536 (adelete 'vhdl-ent-inst-alist project)
13537 (adelete 'vhdl-file-alist project)
13538 ;; expand directory names by default-directory
13539 (message "Collecting source files...")
13541 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13542 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13543 (setq recursive (match-string 1 dir)
13544 dir-name (match-string 3 dir))
13546 (cons (concat recursive
13547 (if (file-name-absolute-p dir-name) "" default-dir)
13550 (setq dir-list (cdr dir-list)))
13551 ;; resolve path wildcards
13552 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13553 ;; expand directories
13554 (while dir-list-tmp
13555 (setq dir (car dir-list-tmp))
13556 ;; get subdirectories
13557 (if (string-match "-r \\(.*[/\\]\\)" dir)
13558 (setq dir-list (append dir-list (vhdl-get-subdirs
13559 (match-string 1 dir))))
13560 (setq dir-list (append dir-list (list dir))))
13561 (setq dir-list-tmp (cdr dir-list-tmp)))
13563 (unless (equal file-exclude-regexp "")
13564 (let ((case-fold-search nil))
13566 (unless (string-match file-exclude-regexp (car dir-list))
13567 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13568 (setq dir-list (cdr dir-list)))
13569 (setq dir-list (nreverse dir-list-tmp))))
13570 (message "Collecting source files...done")
13571 ;; scan for design units for each directory in DIR-LIST
13572 (setq dir-list-tmp nil
13573 num-dir (length dir-list)
13576 (setq dir-name (abbreviate-file-name
13577 (expand-file-name (car dir-list))))
13578 (vhdl-scan-directory-contents dir-name project nil
13579 (format "(%s/%s) " act-dir num-dir)
13581 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13582 (setq dir-list (cdr dir-list)
13583 act-dir (1+ act-dir)))
13584 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13585 (message "Scanning project \"%s\"...done" project)))
13587 (defun vhdl-update-file-contents (file-name)
13588 "Update hierarchy information by contents of current buffer."
13589 (setq file-name (abbreviate-file-name file-name))
13590 (let* ((dir-name (file-name-directory file-name))
13591 (directory-alist vhdl-directory-alist)
13593 (while directory-alist
13594 (when (member dir-name (nth 1 (car directory-alist)))
13595 (let* ((vhdl-project (nth 0 (car directory-alist)))
13596 (project (vhdl-project-p))
13597 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13598 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13599 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13600 (ent-inst-list (car (aget vhdl-ent-inst-alist
13601 (or project dir-name) t)))
13602 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13603 (file-entry (aget file-alist file-name t))
13604 (ent-list (nth 0 file-entry))
13605 (arch-list (nth 1 file-entry))
13606 (arch-ent-list (nth 2 file-entry))
13607 (conf-list (nth 3 file-entry))
13608 (pack-list (nth 4 file-entry))
13609 (pack-body-list (nth 5 file-entry))
13610 (inst-ent-list (nth 7 file-entry))
13611 (cache-key (or project dir-name))
13612 arch-alist key ent-key entry)
13613 ;; delete design units previously contained in this file:
13616 (setq key (car ent-list)
13617 entry (aget ent-alist key t))
13618 (when (equal file-name (nth 1 entry))
13620 (aput 'ent-alist key
13621 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13622 (adelete 'ent-alist key)))
13623 (setq ent-list (cdr ent-list)))
13626 (setq key (car arch-list)
13627 ent-key (car arch-ent-list)
13628 entry (aget ent-alist ent-key t)
13629 arch-alist (nth 3 entry))
13630 (when (equal file-name (nth 1 (aget arch-alist key t)))
13631 (adelete 'arch-alist key)
13632 (if (or (nth 1 entry) arch-alist)
13633 (aput 'ent-alist ent-key
13634 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13635 arch-alist (nth 4 entry) (nth 5 entry)))
13636 (adelete 'ent-alist ent-key)))
13637 (setq arch-list (cdr arch-list)
13638 arch-ent-list (cdr arch-ent-list)))
13641 (setq key (car conf-list))
13642 (when (equal file-name (nth 1 (aget conf-alist key t)))
13643 (adelete 'conf-alist key))
13644 (setq conf-list (cdr conf-list)))
13645 ;; package declarations
13647 (setq key (car pack-list)
13648 entry (aget pack-alist key t))
13649 (when (equal file-name (nth 1 entry))
13651 (aput 'pack-alist key
13652 (list (nth 0 entry) nil nil nil nil nil
13653 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13655 (adelete 'pack-alist key)))
13656 (setq pack-list (cdr pack-list)))
13658 (while pack-body-list
13659 (setq key (car pack-body-list)
13660 entry (aget pack-alist key t))
13661 (when (equal file-name (nth 6 entry))
13663 (aput 'pack-alist key
13664 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13665 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13667 (adelete 'pack-alist key)))
13668 (setq pack-body-list (cdr pack-body-list)))
13669 ;; instantiated entities
13670 (while inst-ent-list
13671 (setq ent-inst-list
13672 (vhdl-delete (car inst-ent-list) ent-inst-list))
13673 (setq inst-ent-list (cdr inst-ent-list)))
13675 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13676 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13677 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13678 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13680 (vhdl-scan-directory-contents file-name project t)
13681 (when (or (and vhdl-speedbar-show-projects project)
13682 (and (not vhdl-speedbar-show-projects) (not project)))
13683 (vhdl-speedbar-refresh project))
13685 (setq directory-alist (cdr directory-alist)))
13688 (defun vhdl-update-hierarchy ()
13689 "Update directory and hierarchy information in speedbar."
13690 (let ((file-list (reverse vhdl-modified-file-list))
13692 (when (and vhdl-speedbar-update-on-saving file-list)
13695 (or (vhdl-update-file-contents (car file-list))
13697 (setq file-list (cdr file-list)))
13698 (setq vhdl-modified-file-list nil)
13699 (vhdl-speedbar-update-current-unit)
13700 (when updated (message "Updating hierarchy...done")))))
13702 ;; structure (parenthesised expression means list of such entries)
13703 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13704 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13705 ;; comp-lib-name level)
13706 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13707 conf-inst-alist level indent
13708 &optional include-top ent-hier)
13709 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13711 (let* ((ent-entry (aget ent-alist ent-key t))
13712 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13713 (cdar (last (nth 3 ent-entry)))))
13714 (inst-alist (nth 3 arch-entry))
13715 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13716 hier-list subcomp-list tmp-list inst-key inst-comp-name
13717 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13718 (when (= level 0) (message "Extract design hierarchy..."))
13720 (setq level (1+ level)))
13721 (when (member ent-key ent-hier)
13722 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13723 ;; check configured architecture (already checked during scanning)
13724 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13725 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13726 ;; process all instances
13728 (setq inst-entry (car inst-alist)
13729 inst-key (nth 0 inst-entry)
13730 inst-comp-name (nth 4 inst-entry)
13731 inst-conf-key (nth 7 inst-entry))
13732 ;; search entry in configuration's instantiations list
13733 (setq tmp-list conf-inst-alist)
13734 (while (and tmp-list
13735 (not (and (member (nth 0 (car tmp-list))
13736 (list "all" inst-key))
13737 (equal (nth 1 (car tmp-list))
13738 (downcase (or inst-comp-name ""))))))
13739 (setq tmp-list (cdr tmp-list)))
13740 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13741 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13742 (when (and inst-conf-key (not inst-conf-entry))
13743 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13744 ;; determine entity
13746 (or (nth 2 (car tmp-list)) ; from configuration
13747 (nth 3 inst-conf-entry) ; from subconfiguration
13748 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13749 ; from configuration spec.
13750 (nth 5 inst-entry))) ; from direct instantiation
13751 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13752 ;; determine architecture
13753 (setq inst-arch-key
13754 (or (nth 3 (car tmp-list)) ; from configuration
13755 (nth 4 inst-conf-entry) ; from subconfiguration
13756 (nth 6 inst-entry) ; from direct instantiation
13757 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13758 ; from configuration spec.
13759 (nth 4 inst-ent-entry) ; MRA
13760 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13761 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13764 (or (nth 5 (car tmp-list)) ; from configuration
13765 (nth 8 inst-entry))) ; from direct instantiation
13766 ;; gather information for this instance
13768 (list (nth 1 inst-entry)
13769 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13770 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13771 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13772 (or (nth 0 inst-arch-entry) inst-arch-key)
13773 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13774 (or (nth 0 inst-conf-entry) inst-conf-key)
13775 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13776 inst-lib-key level))
13777 ;; get subcomponent hierarchy
13778 (setq subcomp-list (vhdl-get-hierarchy
13779 ent-alist conf-alist
13780 inst-ent-key inst-arch-key inst-conf-key
13781 (nth 5 inst-conf-entry)
13782 (1+ level) indent nil (cons ent-key ent-hier)))
13784 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13785 (setq inst-alist (cdr inst-alist)))
13788 (cons (list nil nil (nth 0 ent-entry)
13789 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13791 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13795 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13798 (defun vhdl-get-instantiations (ent-key indent)
13799 "Get all instantiations of entity ENT-KEY."
13800 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13801 arch-alist inst-alist ent-inst-list
13802 ent-entry arch-entry inst-entry)
13804 (setq ent-entry (car ent-alist))
13805 (setq arch-alist (nth 4 ent-entry))
13807 (setq arch-entry (car arch-alist))
13808 (setq inst-alist (nth 4 arch-entry))
13810 (setq inst-entry (car inst-alist))
13811 (when (equal ent-key (nth 5 inst-entry))
13812 (setq ent-inst-list
13813 (cons (list (nth 1 inst-entry)
13814 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13816 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13818 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13820 (setq inst-alist (cdr inst-alist)))
13821 (setq arch-alist (cdr arch-alist)))
13822 (setq ent-alist (cdr ent-alist)))
13823 (nreverse ent-inst-list)))
13825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13828 (defun vhdl-save-caches ()
13829 "Save all updated hierarchy caches to file."
13831 (condition-case nil
13832 (when vhdl-speedbar-save-cache
13833 ;; update hierarchy
13834 (vhdl-update-hierarchy)
13835 (let ((project-list vhdl-updated-project-list))
13836 (message "Saving hierarchy caches...")
13837 ;; write updated project caches
13838 (while project-list
13839 (vhdl-save-cache (car project-list))
13840 (setq project-list (cdr project-list)))
13841 (message "Saving hierarchy caches...done")))
13842 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13845 (defun vhdl-save-cache (key)
13846 "Save current hierarchy cache to file."
13847 (let* ((orig-buffer (current-buffer))
13849 (project (vhdl-project-p))
13850 (default-directory key)
13851 (directory (abbreviate-file-name (vhdl-default-directory)))
13852 (file-name (vhdl-resolve-env-variable
13853 (vhdl-replace-string
13854 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13856 (subst-char-in-string ? ?_ (or project "dir"))
13857 " " (user-login-name)))))
13858 (file-dir-name (expand-file-name file-name directory))
13859 (cache-key (or project directory))
13860 (key (if project "project" "directory")))
13861 (unless (file-exists-p (file-name-directory file-dir-name))
13862 (make-directory (file-name-directory file-dir-name) t))
13863 (if (not (file-writable-p file-dir-name))
13864 (progn (vhdl-warning (format "File not writable: \"%s\""
13865 (abbreviate-file-name file-dir-name)))
13867 (message "Saving cache: \"%s\"" file-dir-name)
13868 (set-buffer (find-file-noselect file-dir-name t t))
13870 (insert ";; -*- Emacs-Lisp -*-\n\n"
13871 ";;; " (file-name-nondirectory file-name)
13872 " - design hierarchy cache file for Emacs VHDL Mode "
13874 (insert "\n;; " (if project "Project " "Directory") " : ")
13875 (if project (insert project) (prin1 directory (current-buffer)))
13876 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13877 (user-login-name) "\n\n"
13878 "\n;; version number\n"
13879 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13880 "\n;; " (if project "project" "directory") " name"
13881 "\n(setq " key " ")
13882 (prin1 (or project directory) (current-buffer))
13884 (when (member 'hierarchy vhdl-speedbar-save-cache)
13885 (insert "\n;; entity and architecture cache\n"
13886 "(aput 'vhdl-entity-alist " key " '")
13887 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13888 (insert ")\n\n;; configuration cache\n"
13889 "(aput 'vhdl-config-alist " key " '")
13890 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13891 (insert ")\n\n;; package cache\n"
13892 "(aput 'vhdl-package-alist " key " '")
13893 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13894 (insert ")\n\n;; instantiated entities cache\n"
13895 "(aput 'vhdl-ent-inst-alist " key " '")
13896 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13897 (insert ")\n\n;; design units per file cache\n"
13898 "(aput 'vhdl-file-alist " key " '")
13899 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13901 (insert ")\n\n;; source directories in project cache\n"
13902 "(aput 'vhdl-directory-alist " key " '")
13903 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13905 (when (member 'display vhdl-speedbar-save-cache)
13906 (insert "\n;; shown design units cache\n"
13907 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13908 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13911 (setq vhdl-updated-project-list
13912 (delete cache-key vhdl-updated-project-list))
13914 (kill-buffer (current-buffer))
13915 (set-buffer orig-buffer))))
13917 (defun vhdl-load-cache (key)
13918 "Load hierarchy cache information from file."
13919 (let* ((vhdl-project key)
13920 (default-directory key)
13921 (directory (vhdl-default-directory))
13922 (file-name (vhdl-resolve-env-variable
13923 (vhdl-replace-string
13924 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13926 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13927 " " (user-login-name)))))
13928 (file-dir-name (expand-file-name file-name directory))
13929 vhdl-cache-version)
13930 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13931 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13932 (when (file-exists-p file-dir-name)
13934 (progn (load-file file-dir-name)
13935 (string< (mapconcat
13936 (lambda (a) (format "%3d" (string-to-number a)))
13937 (split-string "3.33" "\\.") "")
13939 (lambda (a) (format "%3d" (string-to-number a)))
13940 (split-string vhdl-cache-version "\\.") "")))
13941 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13944 (defun vhdl-require-hierarchy-info ()
13945 "Make sure that hierarchy information is available. Load cache or scan files
13947 (if (vhdl-project-p)
13948 (unless (or (assoc vhdl-project vhdl-file-alist)
13949 (vhdl-load-cache vhdl-project))
13950 (vhdl-scan-project-contents vhdl-project))
13951 (let ((directory (abbreviate-file-name default-directory)))
13952 (unless (or (assoc directory vhdl-file-alist)
13953 (vhdl-load-cache directory))
13954 (vhdl-scan-directory-contents directory)))))
13956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13957 ;; Add hierarchy browser functionality to speedbar
13959 (defvar vhdl-speedbar-key-map nil
13960 "Keymap used when in the VHDL hierarchy browser mode.")
13962 (defvar vhdl-speedbar-menu-items nil
13963 "Additional menu-items to add to speedbar frame.")
13965 (defun vhdl-speedbar-initialize ()
13966 "Initialize speedbar."
13967 ;; general settings
13968 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13969 ;; VHDL file extensions (extracted from `auto-mode-alist')
13970 (let ((mode-alist auto-mode-alist))
13972 (when (eq (cdar mode-alist) 'vhdl-mode)
13973 (speedbar-add-supported-extension (caar mode-alist)))
13974 (setq mode-alist (cdr mode-alist))))
13975 ;; hierarchy browser settings
13976 (when (boundp 'speedbar-mode-functions-list)
13977 ;; special functions
13978 (speedbar-add-mode-functions-list
13980 (speedbar-item-info . vhdl-speedbar-item-info)
13981 (speedbar-line-directory . speedbar-files-line-path)))
13982 (speedbar-add-mode-functions-list
13984 (speedbar-item-info . vhdl-speedbar-item-info)
13985 (speedbar-line-directory . vhdl-speedbar-line-project)))
13987 (unless vhdl-speedbar-key-map
13988 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13989 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13990 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13991 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13992 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13993 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13994 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13995 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13996 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13997 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13998 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
13999 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14000 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14001 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14004 (define-key vhdl-speedbar-key-map (int-to-string key)
14005 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14006 (setq key (1+ key)))))
14007 (define-key speedbar-key-map "h"
14008 (lambda () (interactive)
14009 (speedbar-change-initial-expansion-list "vhdl directory")))
14010 (define-key speedbar-key-map "H"
14011 (lambda () (interactive)
14012 (speedbar-change-initial-expansion-list "vhdl project")))
14014 (unless vhdl-speedbar-menu-items
14016 vhdl-speedbar-menu-items
14017 `(["Edit" speedbar-edit-line t]
14018 ["Expand" speedbar-expand-line
14019 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14020 ["Contract" vhdl-speedbar-contract-level t]
14021 ["Expand All" vhdl-speedbar-expand-all t]
14022 ["Contract All" vhdl-speedbar-contract-all t]
14023 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14026 (cons `[,(if (= key 0) "All" (int-to-string key))
14027 (vhdl-speedbar-set-depth ,key)
14029 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14030 :keys ,(int-to-string key)]
14032 (setq key (1+ key)))
14033 (nreverse menu-list))
14035 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14036 (or (vhdl-speedbar-check-unit 'entity)
14037 (vhdl-speedbar-check-unit 'subprogram))]
14038 ["Place Component" vhdl-speedbar-place-component
14039 (vhdl-speedbar-check-unit 'entity)]
14040 ["Generate Configuration" vhdl-speedbar-configuration
14041 (vhdl-speedbar-check-unit 'architecture)]
14042 ["Select as MRA" vhdl-speedbar-select-mra
14043 (vhdl-speedbar-check-unit 'architecture)]
14044 ["Make" vhdl-speedbar-make-design
14045 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14046 ["Generate Makefile" vhdl-speedbar-generate-makefile
14047 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14048 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14049 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14050 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14051 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14052 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14053 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14054 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14056 (speedbar-add-expansion-list
14057 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14058 vhdl-speedbar-display-directory))
14059 (speedbar-add-expansion-list
14060 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14061 vhdl-speedbar-display-projects))
14062 (setq speedbar-stealthy-function-list
14064 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14065 ("vhdl project" vhdl-speedbar-update-current-project
14066 vhdl-speedbar-update-current-unit)
14067 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14068 ; (speedbar-extension-list-to-regex
14069 ; speedbar-ignored-path-expressions))))
14071 speedbar-stealthy-function-list))
14072 (when (eq vhdl-speedbar-display-mode 'directory)
14073 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14074 (when (eq vhdl-speedbar-display-mode 'project)
14075 (setq speedbar-initial-expansion-list-name "vhdl project"))
14076 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14078 (defun vhdl-speedbar (&optional arg)
14079 "Open/close speedbar."
14081 (if (not (fboundp 'speedbar))
14082 (error "WARNING: Speedbar is not available or not installed")
14084 (speedbar-frame-mode arg)
14085 (error (error "WARNING: An error occurred while opening speedbar")))))
14087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14088 ;; Display functions
14090 (defvar vhdl-speedbar-last-selected-project nil
14091 "Name of last selected project.")
14093 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14094 (defmacro speedbar-with-writable (&rest forms)
14095 "Allow the buffer to be writable and evaluate FORMS."
14096 (list 'let '((inhibit-read-only t))
14097 (cons 'progn forms)))
14098 (put 'speedbar-with-writable 'lisp-indent-function 0)
14100 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14101 "Display directory and hierarchy information in speedbar."
14102 (setq vhdl-speedbar-show-projects nil)
14103 (setq speedbar-ignored-directory-regexp
14104 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14105 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14106 (setq speedbar-last-selected-file nil)
14107 (speedbar-with-writable
14108 (condition-case nil
14110 ;; insert directory path
14111 (speedbar-directory-buttons directory depth)
14112 ;; insert subdirectories
14113 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14114 ;; scan and insert hierarchy of current directory
14115 (vhdl-speedbar-insert-dir-hierarchy directory depth
14116 speedbar-power-click)
14117 ;; expand subdirectories
14118 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14119 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14121 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14122 "Display projects and hierarchy information in speedbar."
14123 (setq vhdl-speedbar-show-projects t)
14124 (setq speedbar-ignored-directory-regexp ".")
14125 (setq speedbar-last-selected-file nil)
14126 (setq vhdl-speedbar-last-selected-project nil)
14127 (speedbar-with-writable
14128 (condition-case nil
14130 (vhdl-speedbar-insert-projects)
14131 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14132 (setq speedbar-full-text-cache nil)) ; prevent caching
14134 (defun vhdl-speedbar-insert-projects ()
14135 "Insert all projects in speedbar."
14136 (vhdl-speedbar-make-title-line "Projects:")
14137 (let ((project-alist (if vhdl-project-sort
14138 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14139 vhdl-project-alist))
14140 (vhdl-speedbar-update-current-unit nil))
14142 (while project-alist
14143 (speedbar-make-tag-line
14144 'angle ?+ 'vhdl-speedbar-expand-project
14145 (caar project-alist) (caar project-alist)
14146 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14147 (setq project-alist (cdr project-alist)))
14148 (setq project-alist vhdl-project-alist)
14150 (while project-alist
14151 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14152 (goto-char (point-min))
14153 (when (re-search-forward
14154 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14155 (goto-char (match-end 1))
14156 (speedbar-do-function-pointer)))
14157 (setq project-alist (cdr project-alist))))
14158 ; (vhdl-speedbar-update-current-project)
14159 ; (vhdl-speedbar-update-current-unit nil t)
14162 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14163 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14164 otherwise use cached data."
14165 (when (or rescan (and (not (assoc project vhdl-file-alist))
14166 (not (vhdl-load-cache project))))
14167 (vhdl-scan-project-contents project))
14168 ;; insert design hierarchy
14169 (vhdl-speedbar-insert-hierarchy
14170 (aget vhdl-entity-alist project t)
14171 (aget vhdl-config-alist project t)
14172 (aget vhdl-package-alist project t)
14173 (car (aget vhdl-ent-inst-alist project t)) indent)
14174 (insert (int-to-string indent) ":\n")
14175 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14176 (put-text-property (1- (point)) (point) 'invisible nil)
14177 ;; expand design units
14178 (vhdl-speedbar-expand-units project))
14180 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14181 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14182 otherwise use cached data."
14183 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14184 (not (vhdl-load-cache directory))))
14185 (vhdl-scan-directory-contents directory))
14186 ;; insert design hierarchy
14187 (vhdl-speedbar-insert-hierarchy
14188 (aget vhdl-entity-alist directory t)
14189 (aget vhdl-config-alist directory t)
14190 (aget vhdl-package-alist directory t)
14191 (car (aget vhdl-ent-inst-alist directory t)) depth)
14192 ;; expand design units
14193 (vhdl-speedbar-expand-units directory)
14194 (aput 'vhdl-directory-alist directory (list (list directory))))
14196 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14197 ent-inst-list depth)
14198 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14199 (if (not (or ent-alist conf-alist pack-alist))
14200 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14201 (let (ent-entry conf-entry pack-entry)
14203 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14205 (setq ent-entry (car ent-alist))
14206 (speedbar-make-tag-line
14207 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14208 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14209 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14210 'vhdl-speedbar-entity-face depth)
14211 (unless (nth 2 ent-entry)
14212 (end-of-line 0) (insert "!") (forward-char 1))
14213 (unless (member (nth 0 ent-entry) ent-inst-list)
14214 (end-of-line 0) (insert " (top)") (forward-char 1))
14215 (setq ent-alist (cdr ent-alist)))
14216 ;; insert configurations
14217 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14219 (setq conf-entry (car conf-alist))
14220 (speedbar-make-tag-line
14221 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14222 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14223 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14224 'vhdl-speedbar-configuration-face depth)
14225 (setq conf-alist (cdr conf-alist)))
14227 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14229 (setq pack-entry (car pack-alist))
14230 (vhdl-speedbar-make-pack-line
14231 (nth 0 pack-entry) (nth 1 pack-entry)
14232 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14233 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14235 (setq pack-alist (cdr pack-alist))))))
14237 (defun vhdl-speedbar-rescan-hierarchy ()
14238 "Rescan hierarchy for the directory or project under the cursor."
14243 (vhdl-speedbar-show-projects
14244 (setq key (vhdl-speedbar-line-project))
14245 (vhdl-scan-project-contents key))
14246 ;; top-level directory
14247 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14248 (re-search-forward "[0-9]+:" nil t)
14249 (vhdl-scan-directory-contents
14250 (abbreviate-file-name (speedbar-line-directory))))
14251 ;; current directory
14252 (t (setq path (speedbar-line-directory))
14253 (string-match "^\\(.+[/\\]\\)" path)
14254 (vhdl-scan-directory-contents
14255 (abbreviate-file-name (match-string 1 path)))))
14256 (vhdl-speedbar-refresh key)))
14258 (defun vhdl-speedbar-expand-dirs (directory)
14259 "Expand subdirectories in DIRECTORY according to
14260 `speedbar-shown-directories'."
14261 ;; (nicked from `speedbar-default-directory-list')
14262 (let ((sf (cdr (reverse speedbar-shown-directories)))
14263 (vhdl-speedbar-update-current-unit nil))
14264 (setq speedbar-shown-directories
14265 (list (expand-file-name default-directory)))
14267 (when (speedbar-goto-this-file (car sf))
14268 (beginning-of-line)
14269 (when (looking-at "[0-9]+:\\s-*<")
14270 (goto-char (match-end 0))
14271 (speedbar-do-function-pointer)))
14272 (setq sf (cdr sf))))
14273 (vhdl-speedbar-update-current-unit nil t))
14275 (defun vhdl-speedbar-expand-units (key)
14276 "Expand design units in directory/project KEY according to
14277 `vhdl-speedbar-shown-unit-alist'."
14278 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14279 (vhdl-speedbar-update-current-unit nil)
14280 vhdl-updated-project-list)
14281 (adelete 'vhdl-speedbar-shown-unit-alist key)
14282 (vhdl-prepare-search-1
14283 (while unit-alist ; expand units
14284 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14285 (beginning-of-line)
14286 (let ((arch-alist (nth 1 (car unit-alist)))
14288 (when (looking-at "^[0-9]+:\\s-*\\[")
14289 (goto-char (match-end 0))
14290 (setq position (point))
14291 (speedbar-do-function-pointer)
14292 (select-frame speedbar-frame)
14293 (while arch-alist ; expand architectures
14294 (goto-char position)
14295 (when (re-search-forward
14296 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14297 (car arch-alist) "\\>\\)") nil t)
14298 (beginning-of-line)
14299 (when (looking-at "^[0-9]+:\\s-*{")
14300 (goto-char (match-end 0))
14301 (speedbar-do-function-pointer)
14302 (select-frame speedbar-frame)))
14303 (setq arch-alist (cdr arch-alist))))
14304 (setq unit-alist (cdr unit-alist))))))
14305 (vhdl-speedbar-update-current-unit nil t))
14307 (defun vhdl-speedbar-contract-level ()
14308 "Contract current level in current directory/project."
14310 (when (or (save-excursion
14311 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14312 (and (save-excursion
14313 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14314 (re-search-backward
14315 (format "^[0-%d]:\\s-*[[{<]-"
14316 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14317 (goto-char (match-end 0))
14318 (speedbar-do-function-pointer)
14319 (speedbar-center-buffer-smartly)))
14321 (defun vhdl-speedbar-contract-all ()
14322 "Contract all expanded design units in current directory/project."
14324 (if (and vhdl-speedbar-show-projects
14325 (save-excursion (beginning-of-line) (looking-at "^0:")))
14326 (progn (setq vhdl-speedbar-shown-project-list nil)
14327 (vhdl-speedbar-refresh))
14328 (let ((key (vhdl-speedbar-line-key)))
14329 (adelete 'vhdl-speedbar-shown-unit-alist key)
14330 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14331 (when (memq 'display vhdl-speedbar-save-cache)
14332 (add-to-list 'vhdl-updated-project-list key)))))
14334 (defun vhdl-speedbar-expand-all ()
14335 "Expand all design units in current directory/project."
14337 (let* ((key (vhdl-speedbar-line-key))
14338 (ent-alist (aget vhdl-entity-alist key t))
14339 (conf-alist (aget vhdl-config-alist key t))
14340 (pack-alist (aget vhdl-package-alist key t))
14341 arch-alist unit-alist subunit-alist)
14342 (add-to-list 'vhdl-speedbar-shown-project-list key)
14344 (setq arch-alist (nth 4 (car ent-alist)))
14345 (setq subunit-alist nil)
14347 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14348 (setq arch-alist (cdr arch-alist)))
14349 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14350 (setq ent-alist (cdr ent-alist)))
14352 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14353 (setq conf-alist (cdr conf-alist)))
14355 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14356 (setq pack-alist (cdr pack-alist)))
14357 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14358 (vhdl-speedbar-refresh)
14359 (when (memq 'display vhdl-speedbar-save-cache)
14360 (add-to-list 'vhdl-updated-project-list key))))
14362 (defun vhdl-speedbar-expand-project (text token indent)
14363 "Expand/contract the project under the cursor."
14365 ((string-match "+" text) ; expand project
14366 (speedbar-change-expand-button-char ?-)
14367 (unless (member token vhdl-speedbar-shown-project-list)
14368 (setq vhdl-speedbar-shown-project-list
14369 (cons token vhdl-speedbar-shown-project-list)))
14370 (speedbar-with-writable
14372 (end-of-line) (forward-char 1)
14373 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14374 speedbar-power-click))))
14375 ((string-match "-" text) ; contract project
14376 (speedbar-change-expand-button-char ?+)
14377 (setq vhdl-speedbar-shown-project-list
14378 (delete token vhdl-speedbar-shown-project-list))
14379 (speedbar-delete-subblock indent))
14380 (t (error "Nothing to display")))
14381 (when (equal (selected-frame) speedbar-frame)
14382 (speedbar-center-buffer-smartly)))
14384 (defun vhdl-speedbar-expand-entity (text token indent)
14385 "Expand/contract the entity under the cursor."
14387 ((string-match "+" text) ; expand entity
14388 (let* ((key (vhdl-speedbar-line-key indent))
14389 (ent-alist (aget vhdl-entity-alist key t))
14390 (ent-entry (aget ent-alist token t))
14391 (arch-alist (nth 3 ent-entry))
14392 (inst-alist (vhdl-get-instantiations token indent))
14393 (subpack-alist (nth 5 ent-entry))
14394 (multiple-arch (> (length arch-alist) 1))
14395 arch-entry inst-entry)
14396 (if (not (or arch-alist inst-alist subpack-alist))
14397 (speedbar-change-expand-button-char ??)
14398 (speedbar-change-expand-button-char ?-)
14399 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14400 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14401 (aput 'unit-alist token nil)
14402 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14403 (speedbar-with-writable
14405 (end-of-line) (forward-char 1)
14406 ;; insert architectures
14408 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14410 (setq arch-entry (car arch-alist))
14411 (speedbar-make-tag-line
14412 'curly ?+ 'vhdl-speedbar-expand-architecture
14413 (cons token (nth 0 arch-entry))
14414 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14415 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14416 'vhdl-speedbar-architecture-face (1+ indent))
14417 (when (and multiple-arch
14418 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14419 (end-of-line 0) (insert " (mra)") (forward-char 1))
14420 (setq arch-alist (cdr arch-alist)))
14421 ;; insert instantiations
14423 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14425 (setq inst-entry (car inst-alist))
14426 (vhdl-speedbar-make-inst-line
14427 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14428 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14429 nil nil nil (1+ indent) 0 " in ")
14430 (setq inst-alist (cdr inst-alist)))
14431 ;; insert required packages
14432 (vhdl-speedbar-insert-subpackages
14433 subpack-alist (1+ indent) indent)))
14434 (when (memq 'display vhdl-speedbar-save-cache)
14435 (add-to-list 'vhdl-updated-project-list key))
14436 (vhdl-speedbar-update-current-unit t t))))
14437 ((string-match "-" text) ; contract entity
14438 (speedbar-change-expand-button-char ?+)
14439 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14440 (let* ((key (vhdl-speedbar-line-key indent))
14441 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14442 (adelete 'unit-alist token)
14444 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14445 (adelete 'vhdl-speedbar-shown-unit-alist key))
14446 (speedbar-delete-subblock indent)
14447 (when (memq 'display vhdl-speedbar-save-cache)
14448 (add-to-list 'vhdl-updated-project-list key))))
14449 (t (error "Nothing to display")))
14450 (when (equal (selected-frame) speedbar-frame)
14451 (speedbar-center-buffer-smartly)))
14453 (defun vhdl-speedbar-expand-architecture (text token indent)
14454 "Expand/contract the architecture under the cursor."
14456 ((string-match "+" text) ; expand architecture
14457 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14458 (ent-alist (aget vhdl-entity-alist key t))
14459 (conf-alist (aget vhdl-config-alist key t))
14460 (hier-alist (vhdl-get-hierarchy
14461 ent-alist conf-alist (car token) (cdr token) nil nil
14463 (ent-entry (aget ent-alist (car token) t))
14464 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14465 (subpack-alist (nth 4 arch-entry))
14467 (if (not (or hier-alist subpack-alist))
14468 (speedbar-change-expand-button-char ??)
14469 (speedbar-change-expand-button-char ?-)
14470 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14471 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14472 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14473 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14474 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14475 (speedbar-with-writable
14477 (end-of-line) (forward-char 1)
14478 ;; insert instance hierarchy
14480 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14483 (setq entry (car hier-alist))
14484 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14485 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14486 (vhdl-speedbar-make-inst-line
14487 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14488 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14489 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14490 (setq hier-alist (cdr hier-alist)))
14491 ;; insert required packages
14492 (vhdl-speedbar-insert-subpackages
14493 subpack-alist (1+ indent) (1- indent))))
14494 (when (memq 'display vhdl-speedbar-save-cache)
14495 (add-to-list 'vhdl-updated-project-list key))
14496 (vhdl-speedbar-update-current-unit t t))))
14497 ((string-match "-" text) ; contract architecture
14498 (speedbar-change-expand-button-char ?+)
14499 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14500 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14501 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14502 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14503 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14504 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14505 (speedbar-delete-subblock indent)
14506 (when (memq 'display vhdl-speedbar-save-cache)
14507 (add-to-list 'vhdl-updated-project-list key))))
14508 (t (error "Nothing to display")))
14509 (when (equal (selected-frame) speedbar-frame)
14510 (speedbar-center-buffer-smartly)))
14512 (defun vhdl-speedbar-expand-config (text token indent)
14513 "Expand/contract the configuration under the cursor."
14515 ((string-match "+" text) ; expand configuration
14516 (let* ((key (vhdl-speedbar-line-key indent))
14517 (conf-alist (aget vhdl-config-alist key t))
14518 (conf-entry (aget conf-alist token))
14519 (ent-alist (aget vhdl-entity-alist key t))
14520 (hier-alist (vhdl-get-hierarchy
14521 ent-alist conf-alist (nth 3 conf-entry)
14522 (nth 4 conf-entry) token (nth 5 conf-entry)
14524 (subpack-alist (nth 6 conf-entry))
14526 (if (not (or hier-alist subpack-alist))
14527 (speedbar-change-expand-button-char ??)
14528 (speedbar-change-expand-button-char ?-)
14529 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14530 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14531 (aput 'unit-alist token nil)
14532 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14533 (speedbar-with-writable
14535 (end-of-line) (forward-char 1)
14536 ;; insert instance hierarchy
14538 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14540 (setq entry (car hier-alist))
14541 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14542 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14543 (vhdl-speedbar-make-inst-line
14544 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14545 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14546 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14547 (setq hier-alist (cdr hier-alist)))
14548 ;; insert required packages
14549 (vhdl-speedbar-insert-subpackages
14550 subpack-alist (1+ indent) indent)))
14551 (when (memq 'display vhdl-speedbar-save-cache)
14552 (add-to-list 'vhdl-updated-project-list key))
14553 (vhdl-speedbar-update-current-unit t t))))
14554 ((string-match "-" text) ; contract configuration
14555 (speedbar-change-expand-button-char ?+)
14556 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14557 (let* ((key (vhdl-speedbar-line-key indent))
14558 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14559 (adelete 'unit-alist token)
14561 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14562 (adelete 'vhdl-speedbar-shown-unit-alist key))
14563 (speedbar-delete-subblock indent)
14564 (when (memq 'display vhdl-speedbar-save-cache)
14565 (add-to-list 'vhdl-updated-project-list key))))
14566 (t (error "Nothing to display")))
14567 (when (equal (selected-frame) speedbar-frame)
14568 (speedbar-center-buffer-smartly)))
14570 (defun vhdl-speedbar-expand-package (text token indent)
14571 "Expand/contract the package under the cursor."
14573 ((string-match "+" text) ; expand package
14574 (let* ((key (vhdl-speedbar-line-key indent))
14575 (pack-alist (aget vhdl-package-alist key t))
14576 (pack-entry (aget pack-alist token t))
14577 (comp-alist (nth 3 pack-entry))
14578 (func-alist (nth 4 pack-entry))
14579 (func-body-alist (nth 8 pack-entry))
14580 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14581 comp-entry func-entry func-body-entry)
14582 (if (not (or comp-alist func-alist subpack-alist))
14583 (speedbar-change-expand-button-char ??)
14584 (speedbar-change-expand-button-char ?-)
14585 ;; add package to `vhdl-speedbar-shown-unit-alist'
14586 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14587 (aput 'unit-alist token nil)
14588 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14589 (speedbar-with-writable
14591 (end-of-line) (forward-char 1)
14592 ;; insert components
14594 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14596 (setq comp-entry (car comp-alist))
14597 (speedbar-make-tag-line
14599 (cons token (nth 0 comp-entry))
14600 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14601 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14602 'vhdl-speedbar-entity-face (1+ indent))
14603 (setq comp-alist (cdr comp-alist)))
14604 ;; insert subprograms
14606 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14608 (setq func-entry (car func-alist)
14609 func-body-entry (aget func-body-alist (car func-entry) t))
14610 (when (nth 2 func-entry)
14611 (vhdl-speedbar-make-subprogram-line
14613 (cons (nth 2 func-entry) (nth 3 func-entry))
14614 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14616 (setq func-alist (cdr func-alist)))
14617 ;; insert required packages
14618 (vhdl-speedbar-insert-subpackages
14619 subpack-alist (1+ indent) indent)))
14620 (when (memq 'display vhdl-speedbar-save-cache)
14621 (add-to-list 'vhdl-updated-project-list key))
14622 (vhdl-speedbar-update-current-unit t t))))
14623 ((string-match "-" text) ; contract package
14624 (speedbar-change-expand-button-char ?+)
14625 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14626 (let* ((key (vhdl-speedbar-line-key indent))
14627 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14628 (adelete 'unit-alist token)
14630 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14631 (adelete 'vhdl-speedbar-shown-unit-alist key))
14632 (speedbar-delete-subblock indent)
14633 (when (memq 'display vhdl-speedbar-save-cache)
14634 (add-to-list 'vhdl-updated-project-list key))))
14635 (t (error "Nothing to display")))
14636 (when (equal (selected-frame) speedbar-frame)
14637 (speedbar-center-buffer-smartly)))
14639 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14640 "Insert required packages."
14641 (let* ((pack-alist (aget vhdl-package-alist
14642 (vhdl-speedbar-line-key dir-indent) t))
14643 pack-key lib-name pack-entry)
14644 (when subpack-alist
14645 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14646 (while subpack-alist
14647 (setq pack-key (cdar subpack-alist)
14648 lib-name (caar subpack-alist))
14649 (setq pack-entry (aget pack-alist pack-key t))
14650 (vhdl-speedbar-make-subpack-line
14651 (or (nth 0 pack-entry) pack-key) lib-name
14652 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14653 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14654 (setq subpack-alist (cdr subpack-alist)))))
14656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14657 ;; Display help functions
14659 (defvar vhdl-speedbar-update-current-unit t
14660 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14662 (defun vhdl-speedbar-update-current-project ()
14663 "Highlight project that is currently active."
14664 (when (and vhdl-speedbar-show-projects
14665 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14666 (and (boundp 'speedbar-frame)
14667 (frame-live-p speedbar-frame)))
14668 (let ((last-frame (selected-frame))
14669 (project-alist vhdl-project-alist)
14671 (select-frame speedbar-frame)
14672 (speedbar-with-writable
14674 (while project-alist
14675 (goto-char (point-min))
14676 (when (re-search-forward
14677 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14678 (put-text-property (match-beginning 1) (match-end 1) 'face
14679 (if (equal (caar project-alist) vhdl-project)
14680 'speedbar-selected-face
14681 'speedbar-directory-face))
14682 (when (equal (caar project-alist) vhdl-project)
14683 (setq pos (1- (match-beginning 1)))))
14684 (setq project-alist (cdr project-alist))))
14685 (when pos (goto-char pos)))
14686 (select-frame last-frame)
14687 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14690 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14691 "Highlight all design units that are contained in the current file.
14692 NO-POSITION non-nil means do not re-position cursor."
14693 (let ((last-frame (selected-frame))
14694 (project-list vhdl-speedbar-shown-project-list)
14695 file-alist pos file-name)
14696 ;; get current file name
14697 (if (fboundp 'speedbar-select-attached-frame)
14698 (speedbar-select-attached-frame)
14699 (select-frame speedbar-attached-frame))
14700 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14701 (when (and vhdl-speedbar-update-current-unit
14702 (or always (not (equal file-name speedbar-last-selected-file))))
14703 (if vhdl-speedbar-show-projects
14704 (while project-list
14705 (setq file-alist (append file-alist (aget vhdl-file-alist
14706 (car project-list) t)))
14707 (setq project-list (cdr project-list)))
14708 (setq file-alist (aget vhdl-file-alist
14709 (abbreviate-file-name default-directory) t)))
14710 (select-frame speedbar-frame)
14711 (set-buffer speedbar-buffer)
14712 (speedbar-with-writable
14713 (vhdl-prepare-search-1
14715 ;; unhighlight last units
14716 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14717 (vhdl-speedbar-update-units
14718 "\\[.\\] " (nth 0 file-entry)
14719 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14720 (vhdl-speedbar-update-units
14721 "{.} " (nth 1 file-entry)
14722 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14723 (vhdl-speedbar-update-units
14724 "\\[.\\] " (nth 3 file-entry)
14725 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14726 (vhdl-speedbar-update-units
14727 "[]>] " (nth 4 file-entry)
14728 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14729 (vhdl-speedbar-update-units
14730 "\\[.\\].+(" '("body")
14731 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14732 (vhdl-speedbar-update-units
14733 "> " (nth 6 file-entry)
14734 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14735 ;; highlight current units
14736 (let* ((file-entry (aget file-alist file-name t)))
14738 pos (vhdl-speedbar-update-units
14739 "\\[.\\] " (nth 0 file-entry)
14740 file-name 'vhdl-speedbar-entity-selected-face pos)
14741 pos (vhdl-speedbar-update-units
14742 "{.} " (nth 1 file-entry)
14743 file-name 'vhdl-speedbar-architecture-selected-face pos)
14744 pos (vhdl-speedbar-update-units
14745 "\\[.\\] " (nth 3 file-entry)
14746 file-name 'vhdl-speedbar-configuration-selected-face pos)
14747 pos (vhdl-speedbar-update-units
14748 "[]>] " (nth 4 file-entry)
14749 file-name 'vhdl-speedbar-package-selected-face pos)
14750 pos (vhdl-speedbar-update-units
14751 "\\[.\\].+(" '("body")
14752 file-name 'vhdl-speedbar-package-selected-face pos)
14753 pos (vhdl-speedbar-update-units
14754 "> " (nth 6 file-entry)
14755 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14756 ;; move speedbar so the first highlighted unit is visible
14757 (when (and pos (not no-position))
14759 (speedbar-center-buffer-smartly)
14760 (speedbar-position-cursor-on-line))
14761 (setq speedbar-last-selected-file file-name))
14762 (select-frame last-frame)
14765 (defun vhdl-speedbar-update-units (text unit-list file-name face
14767 "Help function to highlight design units."
14769 (goto-char (point-min))
14770 (while (re-search-forward
14771 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14772 (when (equal file-name (car (get-text-property
14773 (match-beginning 1) 'speedbar-token)))
14774 (setq pos (or pos (point-marker)))
14775 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14776 (setq unit-list (cdr unit-list)))
14779 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14780 ent-name ent-file-marker
14781 arch-name arch-file-marker
14782 conf-name conf-file-marker
14783 lib-name depth offset delimiter)
14784 "Insert instantiation entry."
14785 (let ((start (point))
14787 (insert (int-to-string depth) ":")
14788 (put-text-property start (point) 'invisible t)
14789 (setq visible-start (point))
14790 (insert-char ? (* depth speedbar-indentation-width))
14791 (while (> offset 0)
14793 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14794 (setq offset (1- offset)))
14795 (put-text-property visible-start (point) 'invisible nil)
14796 (setq start (point))
14798 (speedbar-make-button start (point) nil nil nil)
14799 (setq visible-start (point))
14801 (setq start (point))
14802 (if (not inst-name)
14805 (speedbar-make-button
14806 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14807 'vhdl-speedbar-find-file inst-file-marker))
14810 (setq start (point))
14812 (speedbar-make-button
14813 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14814 'vhdl-speedbar-find-file ent-file-marker)
14817 (setq start (point))
14819 (speedbar-make-button
14820 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14821 'vhdl-speedbar-find-file arch-file-marker)
14825 (setq start (point))
14827 (speedbar-make-button
14828 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14829 'vhdl-speedbar-find-file conf-file-marker)
14831 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14832 (setq start (point))
14833 (insert " (" lib-name ")")
14834 (put-text-property (+ 2 start) (1- (point)) 'face
14835 'vhdl-speedbar-library-face))
14836 (insert-char ?\n 1)
14837 (put-text-property visible-start (point) 'invisible nil)))
14839 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14840 body-file-marker depth)
14841 "Insert package entry."
14842 (let ((start (point))
14844 (insert (int-to-string depth) ":")
14845 (put-text-property start (point) 'invisible t)
14846 (setq visible-start (point))
14847 (insert-char ? (* depth speedbar-indentation-width))
14848 (put-text-property visible-start (point) 'invisible nil)
14849 (setq start (point))
14851 (speedbar-make-button
14852 start (point) 'speedbar-button-face 'speedbar-highlight-face
14853 'vhdl-speedbar-expand-package pack-key)
14854 (setq visible-start (point))
14855 (insert-char ? 1 nil)
14856 (setq start (point))
14858 (speedbar-make-button
14859 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14860 'vhdl-speedbar-find-file pack-file-marker)
14861 (unless (car pack-file-marker)
14863 (when (car body-file-marker)
14865 (setq start (point))
14867 (speedbar-make-button
14868 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14869 'vhdl-speedbar-find-file body-file-marker)
14871 (insert-char ?\n 1)
14872 (put-text-property visible-start (point) 'invisible nil)))
14874 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14875 pack-body-file-marker depth)
14876 "Insert used package entry."
14877 (let ((start (point))
14879 (insert (int-to-string depth) ":")
14880 (put-text-property start (point) 'invisible t)
14881 (setq visible-start (point))
14882 (insert-char ? (* depth speedbar-indentation-width))
14883 (put-text-property visible-start (point) 'invisible nil)
14884 (setq start (point))
14886 (speedbar-make-button start (point) nil nil nil)
14887 (setq visible-start (point))
14889 (setq start (point))
14891 (speedbar-make-button
14892 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14893 'vhdl-speedbar-find-file pack-file-marker)
14894 (when (car pack-body-file-marker)
14896 (setq start (point))
14898 (speedbar-make-button
14899 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14900 'vhdl-speedbar-find-file pack-body-file-marker)
14902 (setq start (point))
14903 (insert " (" lib-name ")")
14904 (put-text-property (+ 2 start) (1- (point)) 'face
14905 'vhdl-speedbar-library-face)
14906 (insert-char ?\n 1)
14907 (put-text-property visible-start (point) 'invisible nil)))
14909 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14910 func-body-file-marker
14912 "Insert subprogram entry."
14913 (let ((start (point))
14915 (insert (int-to-string depth) ":")
14916 (put-text-property start (point) 'invisible t)
14917 (setq visible-start (point))
14918 (insert-char ? (* depth speedbar-indentation-width))
14919 (put-text-property visible-start (point) 'invisible nil)
14920 (setq start (point))
14922 (speedbar-make-button start (point) nil nil nil)
14923 (setq visible-start (point))
14925 (setq start (point))
14927 (speedbar-make-button
14928 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14929 'vhdl-speedbar-find-file func-file-marker)
14930 (when (car func-body-file-marker)
14932 (setq start (point))
14934 (speedbar-make-button
14935 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14936 'vhdl-speedbar-find-file func-body-file-marker)
14938 (insert-char ?\n 1)
14939 (put-text-property visible-start (point) 'invisible nil)))
14941 (defun vhdl-speedbar-make-title-line (text &optional depth)
14942 "Insert design unit title entry."
14943 (let ((start (point))
14946 (insert (int-to-string depth) ":")
14947 (put-text-property start (point) 'invisible t))
14948 (setq visible-start (point))
14949 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14950 (setq start (point))
14952 (speedbar-make-button start (point) nil nil nil nil)
14953 (insert-char ?\n 1)
14954 (put-text-property visible-start (point) 'invisible nil)))
14956 (defun vhdl-speedbar-insert-dirs (files level)
14957 "Insert subdirectories."
14958 (let ((dirs (car files)))
14960 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14961 (car dirs) 'speedbar-dir-follow nil
14962 'speedbar-directory-face level)
14963 (setq dirs (cdr dirs)))))
14965 (defun vhdl-speedbar-dired (text token indent)
14966 "Speedbar click handler for directory expand button in hierarchy mode."
14967 (cond ((string-match "+" text) ; we have to expand this dir
14968 (setq speedbar-shown-directories
14969 (cons (expand-file-name
14970 (concat (speedbar-line-directory indent) token "/"))
14971 speedbar-shown-directories))
14972 (speedbar-change-expand-button-char ?-)
14973 (speedbar-reset-scanners)
14974 (speedbar-with-writable
14976 (end-of-line) (forward-char 1)
14977 (vhdl-speedbar-insert-dirs
14978 (speedbar-file-lists
14979 (concat (speedbar-line-directory indent) token "/"))
14981 (speedbar-reset-scanners)
14982 (vhdl-speedbar-insert-dir-hierarchy
14983 (abbreviate-file-name
14984 (concat (speedbar-line-directory indent) token "/"))
14985 (1+ indent) speedbar-power-click)))
14986 (vhdl-speedbar-update-current-unit t t))
14987 ((string-match "-" text) ; we have to contract this node
14988 (speedbar-reset-scanners)
14989 (let ((oldl speedbar-shown-directories)
14991 (td (expand-file-name
14992 (concat (speedbar-line-directory indent) token))))
14994 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14995 (setq newl (cons (car oldl) newl)))
14996 (setq oldl (cdr oldl)))
14997 (setq speedbar-shown-directories (nreverse newl)))
14998 (speedbar-change-expand-button-char ?+)
14999 (speedbar-delete-subblock indent))
15000 (t (error "Nothing to display")))
15001 (when (equal (selected-frame) speedbar-frame)
15002 (speedbar-center-buffer-smartly)))
15004 (defun vhdl-speedbar-item-info ()
15005 "Derive and display information about this line item."
15007 (beginning-of-line)
15008 ;; skip invisible number info
15009 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15011 ;; project/directory entry
15012 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15013 (if vhdl-speedbar-show-projects
15014 (message "Project \"%s\"" (match-string-no-properties 1))
15015 (speedbar-files-item-info)))
15016 ;; design unit entry
15017 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15018 (goto-char (match-end 1))
15019 (let ((face (get-text-property (point) 'face)))
15021 "%s \"%s\" in \"%s\""
15022 ;; design unit kind
15023 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15024 (eq face 'vhdl-speedbar-entity-selected-face))
15025 (if (equal (match-string 2) ">") "Component" "Entity"))
15026 ((or (eq face 'vhdl-speedbar-architecture-face)
15027 (eq face 'vhdl-speedbar-architecture-selected-face))
15029 ((or (eq face 'vhdl-speedbar-configuration-face)
15030 (eq face 'vhdl-speedbar-configuration-selected-face))
15032 ((or (eq face 'vhdl-speedbar-package-face)
15033 (eq face 'vhdl-speedbar-package-selected-face))
15035 ((or (eq face 'vhdl-speedbar-instantiation-face)
15036 (eq face 'vhdl-speedbar-instantiation-selected-face))
15038 ((eq face 'vhdl-speedbar-subprogram-face)
15041 ;; design unit name
15042 (buffer-substring-no-properties
15043 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15046 (file-relative-name
15047 (or (car (get-text-property (point) 'speedbar-token))
15049 (vhdl-default-directory)))))
15050 (t (message "")))))
15052 (defun vhdl-speedbar-line-text ()
15053 "Calls `speedbar-line-text' and removes text properties."
15054 (let ((string (speedbar-line-text)))
15055 (set-text-properties 0 (length string) nil string)
15058 (defun vhdl-speedbar-higher-text ()
15059 "Get speedbar-line-text of higher level."
15060 (let (depth string)
15062 (beginning-of-line)
15063 (looking-at "^\\([0-9]+\\):")
15064 (setq depth (string-to-number (match-string 1)))
15065 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15066 (setq string (match-string 1))
15067 (set-text-properties 0 (length string) nil string)
15070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15073 (defun vhdl-speedbar-line-key (&optional indent)
15074 "Get currently displayed directory of project name."
15075 (if vhdl-speedbar-show-projects
15076 (vhdl-speedbar-line-project)
15077 (abbreviate-file-name
15078 (file-name-as-directory (speedbar-line-directory indent)))))
15080 (defun vhdl-speedbar-line-project (&optional indent)
15081 "Get currently displayed project name."
15082 (and vhdl-speedbar-show-projects
15085 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15086 (match-string-no-properties 1))))
15088 (defun vhdl-add-modified-file ()
15089 "Add file to `vhdl-modified-file-list'."
15090 (when vhdl-file-alist
15091 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15094 (defun vhdl-resolve-paths (path-list)
15095 "Resolve path wildcards in PATH-LIST."
15096 (let (path-list-1 path-list-2 path-beg path-end dir)
15097 ;; eliminate non-existent directories
15099 (setq dir (car path-list))
15100 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15101 (if (file-directory-p (match-string 2 dir))
15102 (setq path-list-1 (cons dir path-list-1))
15103 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15104 (setq path-list (cdr path-list)))
15105 ;; resolve path wildcards
15107 (setq dir (car path-list-1))
15108 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15110 (setq path-beg (match-string 1 dir)
15111 path-end (match-string 5 dir))
15116 (lambda (var) (concat path-beg var path-end)))
15117 (let ((all-list (vhdl-directory-files
15118 (match-string 2 dir) t
15119 (concat "\\<" (wildcard-to-regexp
15120 (match-string 4 dir)))))
15123 (when (file-directory-p (car all-list))
15124 (setq dir-list (cons (car all-list) dir-list)))
15125 (setq all-list (cdr all-list)))
15127 (cdr path-list-1))))
15128 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15129 (when (file-directory-p (match-string 2 dir))
15130 (setq path-list-2 (cons dir path-list-2)))
15131 (setq path-list-1 (cdr path-list-1))))
15132 (nreverse path-list-2)))
15134 (defun vhdl-speedbar-goto-this-unit (directory unit)
15135 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15136 (let ((dest (point)))
15137 (if (and (if vhdl-speedbar-show-projects
15138 (progn (goto-char (point-min)) t)
15139 (speedbar-goto-this-file directory))
15140 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15141 (progn (speedbar-position-cursor-on-line)
15146 (defun vhdl-speedbar-find-file (text token indent)
15147 "When user clicks on TEXT, load file with name and position in TOKEN.
15148 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15149 is already shown in a buffer."
15150 (if (not (car token))
15151 (error "ERROR: File cannot be found")
15152 (let ((buffer (get-file-buffer (car token))))
15153 (speedbar-find-file-in-frame (car token))
15154 (when (or vhdl-speedbar-jump-to-unit buffer)
15155 (goto-line (cdr token))
15157 (vhdl-speedbar-update-current-unit t t)
15158 (speedbar-set-timer dframe-update-speed)
15159 (speedbar-maybee-jump-to-attached-frame))))
15161 (defun vhdl-speedbar-port-copy ()
15162 "Copy the port of the entity/component or subprogram under the cursor."
15164 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15165 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15166 (error "ERROR: No entity/component or subprogram under cursor")
15167 (beginning-of-line)
15168 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15169 (condition-case info
15170 (let ((token (get-text-property
15171 (match-beginning 3) 'speedbar-token)))
15172 (vhdl-visit-file (car token) t
15173 (progn (goto-line (cdr token))
15177 (vhdl-subprog-copy)))))
15178 (error (error "ERROR: %s not scanned successfully\n (%s)"
15179 (if is-entity "Port" "Interface") (cadr info))))
15180 (error "ERROR: No entity/component or subprogram on current line")))))
15182 (defun vhdl-speedbar-place-component ()
15183 "Place the entity/component under the cursor as component."
15185 (if (not (vhdl-speedbar-check-unit 'entity))
15186 (error "ERROR: No entity/component under cursor")
15187 (vhdl-speedbar-port-copy)
15188 (if (fboundp 'speedbar-select-attached-frame)
15189 (speedbar-select-attached-frame)
15190 (select-frame speedbar-attached-frame))
15191 (vhdl-compose-place-component)
15192 (select-frame speedbar-frame)))
15194 (defun vhdl-speedbar-configuration ()
15195 "Generate configuration for the architecture under the cursor."
15197 (if (not (vhdl-speedbar-check-unit 'architecture))
15198 (error "ERROR: No architecture under cursor")
15199 (let ((arch-name (vhdl-speedbar-line-text))
15200 (ent-name (vhdl-speedbar-higher-text)))
15201 (if (fboundp 'speedbar-select-attached-frame)
15202 (speedbar-select-attached-frame)
15203 (select-frame speedbar-attached-frame))
15204 (vhdl-compose-configuration ent-name arch-name))))
15206 (defun vhdl-speedbar-select-mra ()
15207 "Select the architecture under the cursor as MRA."
15209 (if (not (vhdl-speedbar-check-unit 'architecture))
15210 (error "ERROR: No architecture under cursor")
15211 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15212 (ent-key (downcase (vhdl-speedbar-higher-text)))
15213 (ent-alist (aget vhdl-entity-alist
15214 (or (vhdl-project-p) default-directory) t))
15215 (ent-entry (aget ent-alist ent-key t)))
15216 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15217 (speedbar-refresh))))
15219 (defun vhdl-speedbar-make-design ()
15220 "Make (compile) design unit or directory/project under the cursor."
15222 (if (not (save-excursion (beginning-of-line)
15223 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15224 (error "ERROR: No primary design unit or directory/project under cursor")
15225 (let ((is-unit (match-string 2))
15226 (unit-name (vhdl-speedbar-line-text))
15227 (vhdl-project (vhdl-speedbar-line-project))
15228 (directory (file-name-as-directory
15229 (or (speedbar-line-file) (speedbar-line-directory)))))
15230 (if (fboundp 'speedbar-select-attached-frame)
15231 (speedbar-select-attached-frame)
15232 (select-frame speedbar-attached-frame))
15233 (let ((default-directory directory))
15234 (vhdl-make (and is-unit unit-name))))))
15236 (defun vhdl-speedbar-generate-makefile ()
15237 "Generate Makefile for directory/project under the cursor."
15239 (let ((vhdl-project (vhdl-speedbar-line-project))
15240 (default-directory (file-name-as-directory
15241 (or (speedbar-line-file) (speedbar-line-directory)))))
15242 (vhdl-generate-makefile)))
15244 (defun vhdl-speedbar-check-unit (design-unit)
15245 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15246 expansion function)."
15248 (speedbar-position-cursor-on-line)
15249 (cond ((eq design-unit 'entity)
15250 (memq (get-text-property (match-end 0) 'face)
15251 '(vhdl-speedbar-entity-face
15252 vhdl-speedbar-entity-selected-face)))
15253 ((eq design-unit 'architecture)
15254 (memq (get-text-property (match-end 0) 'face)
15255 '(vhdl-speedbar-architecture-face
15256 vhdl-speedbar-architecture-selected-face)))
15257 ((eq design-unit 'subprogram)
15258 (eq (get-text-property (match-end 0) 'face)
15259 'vhdl-speedbar-subprogram-face))
15262 (defun vhdl-speedbar-set-depth (depth)
15263 "Set hierarchy display depth to DEPTH and refresh speedbar."
15264 (setq vhdl-speedbar-hierarchy-depth depth)
15265 (speedbar-refresh))
15267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15270 (defface vhdl-speedbar-entity-face
15271 '((((class color) (background light)) (:foreground "ForestGreen"))
15272 (((class color) (background dark)) (:foreground "PaleGreen")))
15273 "Face used for displaying entity names."
15274 :group 'speedbar-faces)
15276 (defface vhdl-speedbar-architecture-face
15277 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15278 (((class color) (background light)) (:foreground "Blue"))
15280 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15281 "Face used for displaying architecture names."
15282 :group 'speedbar-faces)
15284 (defface vhdl-speedbar-configuration-face
15285 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15286 (((class color) (background dark)) (:foreground "Salmon")))
15287 "Face used for displaying configuration names."
15288 :group 'speedbar-faces)
15290 (defface vhdl-speedbar-package-face
15291 '((((class color) (background light)) (:foreground "Grey50"))
15292 (((class color) (background dark)) (:foreground "Grey80")))
15293 "Face used for displaying package names."
15294 :group 'speedbar-faces)
15296 (defface vhdl-speedbar-library-face
15297 '((((class color) (background light)) (:foreground "Purple"))
15298 (((class color) (background dark)) (:foreground "Orchid1")))
15299 "Face used for displaying library names."
15300 :group 'speedbar-faces)
15302 (defface vhdl-speedbar-instantiation-face
15303 '((((class color) (background light)) (:foreground "Brown"))
15304 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15305 (((class color) (background dark)) (:foreground "Yellow")))
15306 "Face used for displaying instantiation names."
15307 :group 'speedbar-faces)
15309 (defface vhdl-speedbar-subprogram-face
15310 '((((class color) (background light)) (:foreground "Orchid4"))
15311 (((class color) (background dark)) (:foreground "BurlyWood2")))
15312 "Face used for displaying subprogram names."
15313 :group 'speedbar-faces)
15315 (defface vhdl-speedbar-entity-selected-face
15316 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15317 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15318 "Face used for displaying entity names."
15319 :group 'speedbar-faces)
15321 (defface vhdl-speedbar-architecture-selected-face
15322 '((((min-colors 88) (class color) (background light)) (:foreground
15323 "Blue1" :underline t))
15324 (((class color) (background light)) (:foreground "Blue" :underline t))
15325 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15326 "Face used for displaying architecture names."
15327 :group 'speedbar-faces)
15329 (defface vhdl-speedbar-configuration-selected-face
15330 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15331 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15332 "Face used for displaying configuration names."
15333 :group 'speedbar-faces)
15335 (defface vhdl-speedbar-package-selected-face
15336 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15337 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15338 "Face used for displaying package names."
15339 :group 'speedbar-faces)
15341 (defface vhdl-speedbar-instantiation-selected-face
15342 '((((class color) (background light)) (:foreground "Brown" :underline t))
15343 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15344 "Face used for displaying instantiation names."
15345 :group 'speedbar-faces)
15347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15351 (when (fboundp 'speedbar)
15353 (when (and vhdl-speedbar-auto-open
15354 (not (and (boundp 'speedbar-frame)
15355 (frame-live-p speedbar-frame))))
15356 (speedbar-frame-mode 1)
15357 (if (fboundp 'speedbar-select-attached-frame)
15358 (speedbar-select-attached-frame)
15359 (select-frame speedbar-attached-frame)))
15360 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15362 ;; initialize speedbar
15363 (if (not (boundp 'speedbar-frame))
15364 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15365 (vhdl-speedbar-initialize)
15366 (when speedbar-frame (vhdl-speedbar-refresh)))
15369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15370 ;;; Structural composition
15371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15373 (defun vhdl-get-components-package-name ()
15374 "Return the name of the components package."
15375 (let ((project (vhdl-project-p)))
15377 (vhdl-replace-string (car vhdl-components-package-name)
15378 (subst-char-in-string ? ?_ project))
15379 (cdr vhdl-components-package-name))))
15381 (defun vhdl-compose-new-component ()
15382 "Create entity and architecture for new component."
15384 (let* ((case-fold-search t)
15385 (ent-name (read-from-minibuffer "entity name: "
15386 nil vhdl-minibuffer-local-map))
15388 (if (equal (cdr vhdl-compose-architecture-name) "")
15389 (read-from-minibuffer "architecture name: "
15390 nil vhdl-minibuffer-local-map)
15391 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15392 ent-file-name arch-file-name ent-buffer arch-buffer project)
15393 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15394 ;; open entity file
15395 (unless (eq vhdl-compose-create-files 'none)
15396 (setq ent-file-name
15397 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15398 "." (file-name-extension (buffer-file-name))))
15399 (when (and (file-exists-p ent-file-name)
15400 (not (y-or-n-p (concat "File \"" ent-file-name
15401 "\" exists; overwrite? "))))
15402 (error "ERROR: Creating component...aborted"))
15403 (find-file ent-file-name)
15405 (set-buffer-modified-p nil))
15407 (if vhdl-compose-include-header
15408 (progn (vhdl-template-header)
15409 (goto-char (point-max)))
15410 (vhdl-comment-display-line) (insert "\n\n"))
15411 ;; insert library clause
15412 (vhdl-template-package-std-logic-1164)
15413 (when vhdl-use-components-package
15415 (vhdl-template-standard-package (vhdl-work-library)
15416 (vhdl-get-components-package-name)))
15417 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15418 ;; insert entity declaration
15419 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15420 (vhdl-insert-keyword " IS\n")
15421 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15422 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15423 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15424 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15425 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15426 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15427 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15428 (vhdl-insert-keyword "END ")
15429 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15430 (insert ent-name ";\n\n")
15431 (vhdl-comment-display-line) (insert "\n")
15432 ;; open architecture file
15433 (if (not (eq vhdl-compose-create-files 'separate))
15435 (setq ent-buffer (current-buffer))
15436 (setq arch-file-name
15437 (concat (vhdl-replace-string vhdl-architecture-file-name
15438 (concat ent-name " " arch-name) t)
15439 "." (file-name-extension (buffer-file-name))))
15440 (when (and (file-exists-p arch-file-name)
15441 (not (y-or-n-p (concat "File \"" arch-file-name
15442 "\" exists; overwrite? "))))
15443 (error "ERROR: Creating component...aborted"))
15444 (find-file arch-file-name)
15446 (set-buffer-modified-p nil)
15448 (if vhdl-compose-include-header
15449 (progn (vhdl-template-header)
15450 (goto-char (point-max)))
15451 (vhdl-comment-display-line) (insert "\n\n")))
15452 ;; insert architecture body
15453 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15454 (vhdl-insert-keyword " OF ") (insert ent-name)
15455 (vhdl-insert-keyword " IS\n\n")
15456 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15457 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15458 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15459 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15460 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15461 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15462 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15463 (vhdl-insert-keyword "BEGIN")
15464 (when vhdl-self-insert-comments
15466 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15467 (insert arch-name))
15469 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15470 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15471 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15472 (vhdl-insert-keyword "END ")
15473 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15474 (insert arch-name ";\n\n")
15475 ;; insert footer and save
15476 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15477 (vhdl-template-footer)
15478 (vhdl-comment-display-line) (insert "\n"))
15479 (goto-char (point-min))
15480 (setq arch-buffer (current-buffer))
15481 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15482 (set-buffer arch-buffer) (save-buffer)
15484 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15486 (format "\n File created: \"%s\"" ent-file-name))
15487 (and arch-file-name
15488 (format "\n File created: \"%s\"" arch-file-name))))))
15490 (defun vhdl-compose-place-component ()
15491 "Place new component by pasting current port as component declaration and
15492 component instantiation."
15494 (if (not vhdl-port-list)
15495 (error "ERROR: No port has been read")
15497 (vhdl-prepare-search-2
15498 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15499 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15500 (error "ERROR: No architecture found"))
15501 (let* ((ent-name (match-string 1))
15503 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15504 "." (file-name-extension (buffer-file-name))))
15505 (orig-buffer (current-buffer)))
15506 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15507 ;; place component declaration
15508 (unless (or vhdl-use-components-package
15509 (vhdl-use-direct-instantiation)
15512 (concat "^\\s-*component\\s-+"
15513 (car vhdl-port-list) "\\>") nil t)))
15514 (re-search-forward "^begin\\>" nil)
15515 (beginning-of-line)
15516 (skip-chars-backward " \t\n")
15517 (insert "\n\n") (indent-to vhdl-basic-offset)
15518 (vhdl-port-paste-component t))
15519 ;; place component instantiation
15520 (re-search-forward "^end\\>" nil)
15521 (beginning-of-line)
15522 (skip-chars-backward " \t\n")
15523 (insert "\n\n") (indent-to vhdl-basic-offset)
15524 (vhdl-port-paste-instance nil t t)
15525 ;; place use clause for used packages
15526 (when (nth 3 vhdl-port-list)
15527 ;; open entity file
15528 (when (file-exists-p ent-file-name)
15529 (find-file ent-file-name))
15530 (goto-char (point-min))
15531 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15532 (error "ERROR: Entity not found: \"%s\"" ent-name))
15533 (goto-char (match-beginning 0))
15534 (if (and (save-excursion
15535 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15537 (progn (goto-char (match-end 0))
15538 (beginning-of-line 2))
15541 (vhdl-port-paste-context-clause)
15542 (switch-to-buffer orig-buffer))
15543 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15545 (defun vhdl-compose-wire-components ()
15546 "Connect components."
15549 (vhdl-prepare-search-2
15550 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15551 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15552 (error "ERROR: No architecture found"))
15553 (let* ((ent-name (match-string 1))
15555 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15556 "." (file-name-extension (buffer-file-name))))
15557 (arch-decl-pos (point-marker))
15558 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15559 (arch-end-pos (re-search-forward "^end\\>" nil))
15560 (pack-name (vhdl-get-components-package-name))
15562 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15563 "." (file-name-extension (buffer-file-name))))
15564 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15565 port-alist generic-alist inst-alist
15566 signal-name signal-entry signal-alist local-list written-list
15567 single-in-list multi-in-list single-out-list multi-out-list
15568 constant-name constant-entry constant-alist single-list multi-list
15569 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15570 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15571 signal-beg-pos signal-pos
15572 constant-temp-pos port-temp-pos signal-temp-pos)
15573 (message "Wiring components...")
15574 ;; process all instances
15575 (goto-char arch-stat-pos)
15576 (while (re-search-forward
15577 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15578 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15579 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15580 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15581 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15582 (setq inst-name (match-string-no-properties 1)
15583 comp-name (match-string-no-properties 4)
15584 comp-ent-name (match-string-no-properties 12)
15585 has-generic (or (match-string 7) (match-string 17)))
15588 ;; ... from component declaration
15590 (when vhdl-use-components-package pack-file-name) t
15592 (goto-char (point-min))
15593 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15594 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15596 ;; ... from entity declaration (direct instantiation)
15597 (setq comp-ent-file-name
15598 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15599 "." (file-name-extension (buffer-file-name))))
15601 comp-ent-file-name t
15603 (goto-char (point-min))
15604 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15605 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15606 (vhdl-port-copy))))
15607 (vhdl-port-flatten t)
15608 (setq generic-alist (nth 1 vhdl-port-list)
15609 port-alist (nth 2 vhdl-port-list)
15610 vhdl-port-list nil)
15611 (setq constant-alist nil
15614 ;; process all constants in generic map
15615 (vhdl-forward-syntactic-ws)
15616 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15617 (setq constant-name (match-string-no-properties 3))
15618 (setq constant-entry
15619 (cons constant-name
15620 (if (match-string 1)
15621 (or (aget generic-alist (match-string 2) t)
15622 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15623 (cdar generic-alist))))
15624 (setq constant-alist (cons constant-entry constant-alist))
15625 (setq constant-name (downcase constant-name))
15626 (if (or (member constant-name single-list)
15627 (member constant-name multi-list))
15628 (progn (setq single-list (delete constant-name single-list))
15629 (add-to-list 'multi-list constant-name))
15630 (add-to-list 'single-list constant-name))
15631 (unless (match-string 1)
15632 (setq generic-alist (cdr generic-alist)))
15633 (vhdl-forward-syntactic-ws))
15634 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15635 ;; process all signals in port map
15636 (vhdl-forward-syntactic-ws)
15637 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15638 (setq signal-name (match-string-no-properties 3))
15639 (setq signal-entry (cons signal-name
15640 (if (match-string 1)
15641 (or (aget port-alist (match-string 2) t)
15642 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15643 (cdar port-alist))))
15644 (setq signal-alist (cons signal-entry signal-alist))
15645 (setq signal-name (downcase signal-name))
15646 (if (equal (upcase (nth 2 signal-entry)) "IN")
15649 ((member signal-name local-list)
15651 ((or (member signal-name single-out-list)
15652 (member signal-name multi-out-list))
15653 (setq single-out-list (delete signal-name single-out-list))
15654 (setq multi-out-list (delete signal-name multi-out-list))
15655 (add-to-list 'local-list signal-name))
15656 ((member signal-name single-in-list)
15657 (setq single-in-list (delete signal-name single-in-list))
15658 (add-to-list 'multi-in-list signal-name))
15659 ((not (member signal-name multi-in-list))
15660 (add-to-list 'single-in-list signal-name)))
15663 ((member signal-name local-list)
15665 ((or (member signal-name single-in-list)
15666 (member signal-name multi-in-list))
15667 (setq single-in-list (delete signal-name single-in-list))
15668 (setq multi-in-list (delete signal-name multi-in-list))
15669 (add-to-list 'local-list signal-name))
15670 ((member signal-name single-out-list)
15671 (setq single-out-list (delete signal-name single-out-list))
15672 (add-to-list 'multi-out-list signal-name))
15673 ((not (member signal-name multi-out-list))
15674 (add-to-list 'single-out-list signal-name))))
15675 (unless (match-string 1)
15676 (setq port-alist (cdr port-alist)))
15677 (vhdl-forward-syntactic-ws))
15678 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15679 (nreverse signal-alist)) inst-alist)))
15680 ;; prepare signal insertion
15681 (vhdl-goto-marker arch-decl-pos)
15683 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15684 (setq signal-pos (point-marker))
15685 (while (progn (vhdl-forward-syntactic-ws)
15686 (looking-at "signal\\>"))
15687 (beginning-of-line 2)
15688 (delete-region signal-pos (point)))
15689 (setq signal-beg-pos signal-pos)
15690 ;; open entity file
15691 (when (file-exists-p ent-file-name)
15692 (find-file ent-file-name))
15693 (goto-char (point-min))
15694 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15695 (error "ERROR: Entity not found: \"%s\"" ent-name))
15696 ;; prepare generic clause insertion
15697 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15699 (goto-char (match-beginning 0))
15700 (indent-to vhdl-basic-offset)
15701 (insert "generic ();\n\n")
15704 (setq generic-pos (point-marker))
15705 (forward-sexp) (end-of-line)
15706 (delete-region generic-pos (point)) (delete-char 1)
15710 (indent-to (* 2 vhdl-basic-offset))
15711 (insert "-- global generics\n"))
15712 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15713 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15714 ;; prepare port clause insertion
15715 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15717 (goto-char (match-beginning 0))
15718 (indent-to vhdl-basic-offset)
15719 (insert "port ();\n\n")
15722 (setq port-in-pos (point-marker))
15723 (forward-sexp) (end-of-line)
15724 (delete-region port-in-pos (point)) (delete-char 1)
15726 (when (or multi-in-list multi-out-list)
15728 (indent-to (* 2 vhdl-basic-offset))
15729 (insert "-- global ports\n"))
15730 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15731 port-out-pos (point-marker) port-inst-pos (point-marker)
15732 port-end-pos (point-marker))
15733 ;; insert generics, ports and signals
15734 (setq inst-alist (nreverse inst-alist))
15736 (setq inst-name (nth 0 (car inst-alist))
15737 constant-alist (nth 1 (car inst-alist))
15738 signal-alist (nth 2 (car inst-alist))
15739 constant-temp-pos generic-inst-pos
15740 port-temp-pos port-inst-pos
15741 signal-temp-pos signal-pos)
15743 (while constant-alist
15744 (setq constant-name (downcase (caar constant-alist))
15745 constant-entry (car constant-alist))
15746 (cond ((member constant-name written-list)
15748 ((member constant-name multi-list)
15749 (vhdl-goto-marker generic-pos)
15750 (setq generic-end-pos
15753 (vhdl-compose-insert-generic constant-entry)))
15754 (setq generic-pos (point-marker))
15755 (add-to-list 'written-list constant-name))
15758 (vhdl-max-marker generic-inst-pos generic-pos))
15759 (setq generic-end-pos
15760 (vhdl-compose-insert-generic constant-entry))
15761 (setq generic-inst-pos (point-marker))
15762 (add-to-list 'written-list constant-name)))
15763 (setq constant-alist (cdr constant-alist)))
15764 (when (/= constant-temp-pos generic-inst-pos)
15765 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15766 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15767 (insert "-- generics for \"" inst-name "\"\n")
15768 (vhdl-goto-marker generic-inst-pos))
15769 ;; ports and signals
15770 (while signal-alist
15771 (setq signal-name (downcase (caar signal-alist))
15772 signal-entry (car signal-alist))
15773 (cond ((member signal-name written-list)
15775 ((member signal-name multi-in-list)
15776 (vhdl-goto-marker port-in-pos)
15779 port-end-pos (vhdl-compose-insert-port signal-entry)))
15780 (setq port-in-pos (point-marker))
15781 (add-to-list 'written-list signal-name))
15782 ((member signal-name multi-out-list)
15783 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15786 port-end-pos (vhdl-compose-insert-port signal-entry)))
15787 (setq port-out-pos (point-marker))
15788 (add-to-list 'written-list signal-name))
15789 ((or (member signal-name single-in-list)
15790 (member signal-name single-out-list))
15794 (vhdl-max-marker port-out-pos port-in-pos)))
15795 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15796 (setq port-inst-pos (point-marker))
15797 (add-to-list 'written-list signal-name))
15798 ((equal (upcase (nth 2 signal-entry)) "OUT")
15799 (vhdl-goto-marker signal-pos)
15800 (vhdl-compose-insert-signal signal-entry)
15801 (setq signal-pos (point-marker))
15802 (add-to-list 'written-list signal-name)))
15803 (setq signal-alist (cdr signal-alist)))
15804 (when (/= port-temp-pos port-inst-pos)
15806 (vhdl-max-marker port-temp-pos
15807 (vhdl-max-marker port-in-pos port-out-pos)))
15808 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15809 (insert "-- ports to \"" inst-name "\"\n")
15810 (vhdl-goto-marker port-inst-pos))
15811 (when (/= signal-temp-pos signal-pos)
15812 (vhdl-goto-marker signal-temp-pos)
15813 (insert "\n") (indent-to vhdl-basic-offset)
15814 (insert "-- outputs of \"" inst-name "\"\n")
15815 (vhdl-goto-marker signal-pos))
15816 (setq inst-alist (cdr inst-alist)))
15817 ;; finalize generic/port clause
15818 (vhdl-goto-marker generic-end-pos) (backward-char)
15819 (when (= generic-beg-pos generic-end-pos)
15820 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15821 (insert ";") (backward-char))
15823 (vhdl-goto-marker port-end-pos) (backward-char)
15824 (when (= port-beg-pos port-end-pos)
15825 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15826 (insert ";") (backward-char))
15828 ;; align everything
15829 (when vhdl-auto-align
15830 (vhdl-goto-marker generic-beg-pos)
15831 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15832 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15833 (vhdl-goto-marker signal-beg-pos)
15834 (vhdl-align-region-groups signal-beg-pos signal-pos))
15835 (switch-to-buffer (marker-buffer signal-beg-pos))
15836 (message "Wiring components...done")))))
15838 (defun vhdl-compose-insert-generic (entry)
15839 "Insert ENTRY as generic declaration."
15841 (indent-to (* 2 vhdl-basic-offset))
15842 (insert (nth 0 entry) " : " (nth 1 entry))
15843 (when (nth 2 entry)
15844 (insert " := " (nth 2 entry)))
15846 (setq pos (point-marker))
15847 (when (and vhdl-include-port-comments (nth 3 entry))
15848 (vhdl-comment-insert-inline (nth 3 entry) t))
15852 (defun vhdl-compose-insert-port (entry)
15853 "Insert ENTRY as port declaration."
15855 (indent-to (* 2 vhdl-basic-offset))
15856 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15857 (setq pos (point-marker))
15858 (when (and vhdl-include-port-comments (nth 4 entry))
15859 (vhdl-comment-insert-inline (nth 4 entry) t))
15863 (defun vhdl-compose-insert-signal (entry)
15864 "Insert ENTRY as signal declaration."
15865 (indent-to vhdl-basic-offset)
15866 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15867 (when (and vhdl-include-port-comments (nth 4 entry))
15868 (vhdl-comment-insert-inline (nth 4 entry) t))
15871 (defun vhdl-compose-components-package ()
15872 "Generate a package containing component declarations for all entities in the
15873 current project/directory."
15875 (vhdl-require-hierarchy-info)
15876 (let* ((project (vhdl-project-p))
15877 (pack-name (vhdl-get-components-package-name))
15879 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15880 "." (file-name-extension (buffer-file-name))))
15881 (ent-alist (aget vhdl-entity-alist
15882 (or project default-directory) t))
15883 (lazy-lock-minimum-size 0)
15884 clause-pos component-pos)
15885 (message "Generating components package \"%s\"..." pack-name)
15886 ;; open package file
15887 (when (and (file-exists-p pack-file-name)
15888 (not (y-or-n-p (concat "File \"" pack-file-name
15889 "\" exists; overwrite? "))))
15890 (error "ERROR: Generating components package...aborted"))
15891 (find-file pack-file-name)
15894 (if vhdl-compose-include-header
15895 (progn (vhdl-template-header
15896 (concat "Components package (generated by Emacs VHDL Mode "
15898 (goto-char (point-max)))
15899 (vhdl-comment-display-line) (insert "\n\n"))
15900 ;; insert std_logic_1164 package
15901 (vhdl-template-package-std-logic-1164)
15902 (insert "\n") (setq clause-pos (point-marker))
15903 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15904 ;; insert package declaration
15905 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15906 (vhdl-insert-keyword " IS\n\n")
15907 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15908 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15909 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15910 (indent-to vhdl-basic-offset)
15911 (setq component-pos (point-marker))
15912 (insert "\n\n") (vhdl-insert-keyword "END ")
15913 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15914 (insert pack-name ";\n\n")
15916 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15917 (vhdl-template-footer)
15918 (vhdl-comment-display-line) (insert "\n"))
15919 ;; insert component declarations
15921 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15922 (progn (goto-line (nth 3 (car ent-alist)))
15925 (goto-char component-pos)
15926 (vhdl-port-paste-component t)
15927 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15928 (setq component-pos (point-marker))
15929 (goto-char clause-pos)
15930 (vhdl-port-paste-context-clause pack-name)
15931 (setq clause-pos (point-marker))
15932 (setq ent-alist (cdr ent-alist)))
15933 (goto-char (point-min))
15935 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15936 pack-name pack-file-name)))
15938 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15939 &optional insert-conf)
15940 "Generate block configuration for architecture."
15941 (let ((margin (current-indentation))
15942 (beg (save-excursion (beginning-of-line) (point)))
15943 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15944 ;; insert block configuration (for architecture)
15945 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15946 (setq margin (+ margin vhdl-basic-offset))
15947 ;; process all instances
15949 (setq inst-entry (car inst-alist))
15951 (when (nth 4 inst-entry)
15952 (setq insert-conf t)
15953 (setq inst-path (nth 9 inst-entry))
15954 ;; skip common path with previous instance
15955 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15956 (setq inst-path (cdr inst-path)
15957 inst-prev-path (cdr inst-prev-path)))
15958 ;; insert block configuration end (for previous block/generate)
15959 (while inst-prev-path
15960 (setq margin (- margin vhdl-basic-offset))
15962 (vhdl-insert-keyword "END FOR;\n")
15963 (setq inst-prev-path (cdr inst-prev-path)))
15964 ;; insert block configuration beginning (for current block/generate)
15967 (setq margin (+ margin vhdl-basic-offset))
15968 (vhdl-insert-keyword "FOR ")
15969 (insert (car inst-path) "\n")
15971 (setq inst-path (cdr inst-path)))
15972 ;; insert component configuration beginning
15973 (vhdl-insert-keyword "FOR ")
15974 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15975 ;; find subconfiguration
15976 (setq conf-key (nth 7 inst-entry))
15977 (setq tmp-alist conf-alist)
15978 ;; use first configuration found for instance's entity
15979 (while (and tmp-alist (null conf-key))
15980 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15981 (setq conf-key (nth 0 (car tmp-alist))))
15982 (setq tmp-alist (cdr tmp-alist)))
15983 (setq conf-entry (aget conf-alist conf-key t))
15984 ;; insert binding indication ...
15985 ;; ... with subconfiguration (if exists)
15986 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15988 (indent-to (+ margin vhdl-basic-offset))
15989 (vhdl-insert-keyword "USE CONFIGURATION ")
15990 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15992 ;; ... with entity (if exists)
15993 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15995 (indent-to (+ margin vhdl-basic-offset))
15996 (vhdl-insert-keyword "USE ENTITY ")
15997 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15998 ;; insert architecture name (if architecture exists)
15999 (when (nth 3 ent-entry)
16001 ;; choose architecture name a) from configuration,
16002 ;; b) from mra, or c) from first architecture
16003 (or (nth 0 (aget (nth 3 ent-entry)
16004 (or (nth 6 inst-entry)
16005 (nth 4 ent-entry)) t))
16006 (nth 1 (car (nth 3 ent-entry)))))
16007 (insert "(" arch-name ")"))
16009 ;; insert block configuration (for architecture of subcomponent)
16010 (when (and vhdl-compose-configuration-hierarchical
16012 (indent-to (+ margin vhdl-basic-offset))
16013 (vhdl-compose-configuration-architecture
16014 (nth 0 ent-entry) arch-name
16015 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16016 ;; insert component configuration end
16018 (vhdl-insert-keyword "END FOR;\n")
16019 (setq inst-prev-path (nth 9 inst-entry)))
16020 (setq inst-alist (cdr inst-alist)))
16021 ;; insert block configuration end (for block/generate)
16022 (while inst-prev-path
16023 (setq margin (- margin vhdl-basic-offset))
16025 (vhdl-insert-keyword "END FOR;\n")
16026 (setq inst-prev-path (cdr inst-prev-path)))
16027 (indent-to (- margin vhdl-basic-offset))
16028 ;; insert block configuration end or remove beginning (for architecture)
16030 (vhdl-insert-keyword "END FOR;\n")
16031 (delete-region beg (point)))))
16033 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16034 "Generate configuration declaration."
16036 (vhdl-require-hierarchy-info)
16037 (let ((ent-alist (aget vhdl-entity-alist
16038 (or (vhdl-project-p) default-directory) t))
16039 (conf-alist (aget vhdl-config-alist
16040 (or (vhdl-project-p) default-directory) t))
16041 (from-speedbar ent-name)
16042 inst-alist conf-name conf-file-name pos)
16043 (vhdl-prepare-search-2
16044 ;; get entity and architecture name
16047 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16048 (not (equal "END" (upcase (match-string 1))))
16049 (setq ent-name (match-string-no-properties 3))
16050 (setq arch-name (match-string-no-properties 2)))
16051 (error "ERROR: Not within an architecture"))))
16052 (setq conf-name (vhdl-replace-string
16053 vhdl-compose-configuration-name
16054 (concat ent-name " " arch-name)))
16056 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16057 (downcase arch-name) t))))
16058 (message "Generating configuration \"%s\"..." conf-name)
16059 (if vhdl-compose-configuration-create-file
16060 ;; open configuration file
16062 (setq conf-file-name
16063 (concat (vhdl-replace-string vhdl-configuration-file-name
16065 "." (file-name-extension (buffer-file-name))))
16066 (when (and (file-exists-p conf-file-name)
16067 (not (y-or-n-p (concat "File \"" conf-file-name
16068 "\" exists; overwrite? "))))
16069 (error "ERROR: Creating configuration...aborted"))
16070 (find-file conf-file-name)
16072 (set-buffer-modified-p nil)
16074 (if vhdl-compose-include-header
16075 (progn (vhdl-template-header
16076 (concat "Configuration declaration for design \""
16077 ent-name "(" arch-name ")\""))
16078 (goto-char (point-max)))
16079 (vhdl-comment-display-line) (insert "\n\n")))
16080 ;; goto end of architecture
16081 (unless from-speedbar
16082 (re-search-forward "^end\\>" nil)
16083 (end-of-line) (insert "\n\n")
16084 (vhdl-comment-display-line) (insert "\n\n")))
16085 ;; insert library clause
16087 (vhdl-template-standard-package (vhdl-work-library) nil)
16088 (when (/= pos (point))
16090 ;; insert configuration
16091 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16092 (vhdl-insert-keyword " OF ") (insert ent-name)
16093 (vhdl-insert-keyword " IS\n")
16094 (indent-to vhdl-basic-offset)
16095 ;; insert block configuration (for architecture)
16096 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16097 (vhdl-insert-keyword "END ") (insert conf-name ";")
16098 (when conf-file-name
16099 ;; insert footer and save
16101 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16102 (vhdl-template-footer)
16103 (vhdl-comment-display-line) (insert "\n"))
16106 (concat (format "Generating configuration \"%s\"...done" conf-name)
16107 (and conf-file-name
16108 (format "\n File created: \"%s\"" conf-file-name))))))
16111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16112 ;;; Compilation / Makefile generation
16113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16114 ;; (using `compile.el')
16116 (defun vhdl-makefile-name ()
16117 "Return the Makefile name of the current project or the current compiler if
16118 no project is defined."
16119 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16120 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16121 (vhdl-replace-string
16122 (cons "\\(.*\\)\n\\(.*\\)"
16123 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16124 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16126 (defun vhdl-compile-directory ()
16127 "Return the directory where compilation/make should be run."
16128 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16129 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16130 (directory (vhdl-resolve-env-variable
16132 (vhdl-replace-string
16133 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16134 (nth 6 compiler)))))
16135 (file-name-as-directory
16136 (if (file-name-absolute-p directory)
16138 (expand-file-name directory (vhdl-default-directory))))))
16140 (defun vhdl-uniquify (in-list)
16141 "Remove duplicate elements from IN-LIST."
16144 (add-to-list 'out-list (car in-list))
16145 (setq in-list (cdr in-list)))
16148 (defun vhdl-set-compiler (name)
16149 "Set current compiler to NAME."
16151 (list (let ((completion-ignore-case t))
16152 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16153 (if (assoc name vhdl-compiler-alist)
16154 (progn (setq vhdl-compiler name)
16155 (message "Current compiler: \"%s\"" vhdl-compiler))
16156 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16161 (defun vhdl-compile-init ()
16162 "Initialize for compilation."
16163 (when (or (null compilation-error-regexp-alist)
16164 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16165 compilation-error-regexp-alist)))
16166 ;; `compilation-error-regexp-alist'
16167 (let ((commands-alist vhdl-compiler-alist)
16168 regexp-alist sublist)
16169 (while commands-alist
16170 (setq sublist (nth 11 (car commands-alist)))
16171 (unless (or (equal "" (car sublist))
16172 (assoc (car sublist) regexp-alist))
16173 (setq regexp-alist (cons (list (nth 0 sublist)
16174 (if (= 0 (nth 1 sublist))
16175 (if (featurep 'xemacs) 9 nil)
16177 (nth 2 sublist) (nth 3 sublist))
16179 (setq commands-alist (cdr commands-alist)))
16180 (setq compilation-error-regexp-alist
16181 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16182 ;; `compilation-file-regexp-alist'
16183 (let ((commands-alist vhdl-compiler-alist)
16184 regexp-alist sublist)
16185 ;; matches vhdl-mode file name output
16186 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16187 (while commands-alist
16188 (setq sublist (nth 12 (car commands-alist)))
16189 (unless (or (equal "" (car sublist))
16190 (assoc (car sublist) regexp-alist))
16191 (setq regexp-alist (cons sublist regexp-alist)))
16192 (setq commands-alist (cdr commands-alist)))
16193 (setq compilation-file-regexp-alist
16194 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16196 (defvar vhdl-compile-file-name nil
16197 "Name of file to be compiled.")
16199 (defun vhdl-compile-print-file-name ()
16200 "Function called within `compile' to print out file name for compilers that
16201 do not print any file names."
16202 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16204 (defun vhdl-get-compile-options (project compiler file-name
16205 &optional file-options-only)
16206 "Get compiler options. Returning nil means do not compile this file."
16207 (let* ((compiler-options (nth 1 compiler))
16208 (project-entry (aget (nth 4 project) vhdl-compiler))
16209 (project-options (nth 0 project-entry))
16210 (exception-list (and file-name (nth 2 project-entry)))
16211 (work-library (vhdl-work-library))
16212 (case-fold-search nil)
16214 (while (and exception-list
16215 (not (string-match (caar exception-list) file-name)))
16216 (setq exception-list (cdr exception-list)))
16217 (if (and exception-list (not (cdar exception-list)))
16219 (if (and file-options-only (not exception-list))
16221 (setq file-options (cdar exception-list))
16222 ;; insert library name in compiler-specific options
16223 (setq compiler-options
16224 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16226 ;; insert compiler-specific options in project-specific options
16227 (when project-options
16228 (setq project-options
16229 (vhdl-replace-string
16230 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16231 (concat work-library "\n" compiler-options))))
16232 ;; insert project-specific options in file-specific options
16235 (vhdl-replace-string
16236 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16237 (concat work-library "\n" compiler-options "\n"
16238 project-options))))
16240 (or file-options project-options compiler-options)))))
16242 (defun vhdl-get-make-options (project compiler)
16243 "Get make options."
16244 (let* ((compiler-options (nth 3 compiler))
16245 (project-entry (aget (nth 4 project) vhdl-compiler))
16246 (project-options (nth 1 project-entry))
16247 (makefile-name (vhdl-makefile-name)))
16248 ;; insert Makefile name in compiler-specific options
16249 (setq compiler-options
16250 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16252 ;; insert compiler-specific options in project-specific options
16253 (when project-options
16254 (setq project-options
16255 (vhdl-replace-string
16256 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16257 (concat makefile-name "\n" compiler-options))))
16259 (or project-options compiler-options)))
16261 (defun vhdl-compile ()
16262 "Compile current buffer using the VHDL compiler specified in
16265 (vhdl-compile-init)
16266 (let* ((project (aget vhdl-project-alist vhdl-project))
16267 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16268 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16269 (command (nth 0 compiler))
16270 (file-name (buffer-file-name))
16271 (options (vhdl-get-compile-options project compiler file-name))
16272 (default-directory (vhdl-compile-directory))
16273 compilation-process-setup-function)
16274 (unless (file-directory-p default-directory)
16275 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16276 ;; put file name into quotes if it contains spaces
16277 (when (string-match " " file-name)
16278 (setq file-name (concat "\"" file-name "\"")))
16279 ;; print out file name if compiler does not
16280 (setq vhdl-compile-file-name (buffer-file-name))
16281 (when (and (= 0 (nth 1 (nth 10 compiler)))
16282 (= 0 (nth 1 (nth 11 compiler))))
16283 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16287 (compile (concat command " " options " " file-name)))
16288 (vhdl-warning "Your project settings tell me not to compile this file"))))
16290 (defvar vhdl-make-target "all"
16291 "Default target for `vhdl-make' command.")
16293 (defun vhdl-make (&optional target)
16294 "Call make command for compilation of all updated source files (requires
16295 `Makefile'). Optional argument TARGET allows to compile the design
16296 specified by a target."
16298 (setq vhdl-make-target
16299 (or target (read-from-minibuffer "Target: " vhdl-make-target
16300 vhdl-minibuffer-local-map)))
16301 (vhdl-compile-init)
16302 (let* ((project (aget vhdl-project-alist vhdl-project))
16303 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16304 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16305 (command (nth 2 compiler))
16306 (options (vhdl-get-make-options project compiler))
16307 (default-directory (vhdl-compile-directory)))
16308 (unless (file-directory-p default-directory)
16309 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16311 (compile (concat (if (equal command "") "make" command)
16312 " " options " " vhdl-make-target))))
16314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16315 ;; Makefile generation
16317 (defun vhdl-generate-makefile ()
16318 "Generate `Makefile'."
16320 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16321 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16322 (command (nth 4 compiler)))
16323 ;; generate makefile
16325 (let ((default-directory (vhdl-compile-directory)))
16326 (compile (vhdl-replace-string
16327 (cons "\\(.*\\) \\(.*\\)" command)
16328 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16329 (vhdl-generate-makefile-1))))
16331 (defun vhdl-get-packages (lib-alist work-library)
16332 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16335 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16336 (setq pack-list (cons (cdar lib-alist) pack-list)))
16337 (setq lib-alist (cdr lib-alist)))
16340 (defun vhdl-generate-makefile-1 ()
16341 "Generate Makefile for current project or directory."
16342 ;; scan hierarchy if required
16343 (if (vhdl-project-p)
16344 (unless (or (assoc vhdl-project vhdl-file-alist)
16345 (vhdl-load-cache vhdl-project))
16346 (vhdl-scan-project-contents vhdl-project))
16347 (let ((directory (abbreviate-file-name default-directory)))
16348 (unless (or (assoc directory vhdl-file-alist)
16349 (vhdl-load-cache directory))
16350 (vhdl-scan-directory-contents directory))))
16351 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16352 (project (vhdl-project-p))
16353 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16354 (conf-alist (aget vhdl-config-alist (or project directory) t))
16355 (pack-alist (aget vhdl-package-alist (or project directory) t))
16356 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16357 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16358 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16359 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16360 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16361 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16362 (adjust-case (nth 5 regexp-list))
16363 (work-library (downcase (vhdl-work-library)))
16364 (compile-directory (expand-file-name (vhdl-compile-directory)
16365 default-directory))
16366 (makefile-name (vhdl-makefile-name))
16367 rule-alist arch-alist inst-alist
16368 target-list depend-list unit-list prim-list second-list subcomp-list
16369 lib-alist lib-body-alist pack-list all-pack-list
16370 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16371 conf-key conf-file-name pack-key pack-file-name
16372 ent-entry arch-entry conf-entry pack-entry inst-entry
16373 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16374 tmp-key tmp-list rule)
16375 ;; check prerequisites
16376 (unless (file-exists-p compile-directory)
16377 (make-directory compile-directory t))
16378 (unless regexp-list
16379 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16381 (message "Generating makefile \"%s\"..." makefile-name)
16382 ;; rules for all entities
16383 (setq tmp-list ent-alist)
16385 (setq ent-entry (car ent-alist)
16386 ent-key (nth 0 ent-entry))
16387 (when (nth 2 ent-entry)
16388 (setq ent-file-name (file-relative-name
16389 (nth 2 ent-entry) compile-directory)
16390 arch-alist (nth 4 ent-entry)
16391 lib-alist (nth 6 ent-entry)
16392 rule (aget rule-alist ent-file-name)
16393 target-list (nth 0 rule)
16394 depend-list (nth 1 rule)
16397 (setq tmp-key (vhdl-replace-string
16398 ent-regexp (funcall adjust-case ent-key)))
16399 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16400 ;; rule target for this entity
16401 (setq target-list (cons ent-key target-list))
16402 ;; rule dependencies for all used packages
16403 (setq pack-list (vhdl-get-packages lib-alist work-library))
16404 (setq depend-list (append depend-list pack-list))
16405 (setq all-pack-list pack-list)
16407 (aput 'rule-alist ent-file-name (list target-list depend-list))
16408 ;; rules for all corresponding architectures
16410 (setq arch-entry (car arch-alist)
16411 arch-key (nth 0 arch-entry)
16412 ent-arch-key (concat ent-key "-" arch-key)
16413 arch-file-name (file-relative-name (nth 2 arch-entry)
16415 inst-alist (nth 4 arch-entry)
16416 lib-alist (nth 5 arch-entry)
16417 rule (aget rule-alist arch-file-name)
16418 target-list (nth 0 rule)
16419 depend-list (nth 1 rule))
16420 (setq tmp-key (vhdl-replace-string
16422 (funcall adjust-case (concat arch-key " " ent-key))))
16424 (cons (cons ent-arch-key tmp-key) unit-list))
16425 (setq second-list (cons ent-arch-key second-list))
16426 ;; rule target for this architecture
16427 (setq target-list (cons ent-arch-key target-list))
16428 ;; rule dependency for corresponding entity
16429 (setq depend-list (cons ent-key depend-list))
16430 ;; rule dependencies for contained component instantiations
16432 (setq inst-entry (car inst-alist))
16433 (when (or (null (nth 8 inst-entry))
16434 (equal (downcase (nth 8 inst-entry)) work-library))
16435 (setq inst-ent-key (or (nth 7 inst-entry)
16436 (nth 5 inst-entry)))
16437 (setq depend-list (cons inst-ent-key depend-list)
16438 subcomp-list (cons inst-ent-key subcomp-list)))
16439 (setq inst-alist (cdr inst-alist)))
16440 ;; rule dependencies for all used packages
16441 (setq pack-list (vhdl-get-packages lib-alist work-library))
16442 (setq depend-list (append depend-list pack-list))
16443 (setq all-pack-list (append all-pack-list pack-list))
16445 (aput 'rule-alist arch-file-name (list target-list depend-list))
16446 (setq arch-alist (cdr arch-alist)))
16447 (setq prim-list (cons (list ent-key second-list
16448 (append subcomp-list all-pack-list))
16450 (setq ent-alist (cdr ent-alist)))
16451 (setq ent-alist tmp-list)
16452 ;; rules for all configurations
16453 (setq tmp-list conf-alist)
16455 (setq conf-entry (car conf-alist)
16456 conf-key (nth 0 conf-entry)
16457 conf-file-name (file-relative-name
16458 (nth 2 conf-entry) compile-directory)
16459 ent-key (nth 4 conf-entry)
16460 arch-key (nth 5 conf-entry)
16461 inst-alist (nth 6 conf-entry)
16462 lib-alist (nth 7 conf-entry)
16463 rule (aget rule-alist conf-file-name)
16464 target-list (nth 0 rule)
16465 depend-list (nth 1 rule)
16466 subcomp-list (list ent-key))
16467 (setq tmp-key (vhdl-replace-string
16468 conf-regexp (funcall adjust-case conf-key)))
16469 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16470 ;; rule target for this configuration
16471 (setq target-list (cons conf-key target-list))
16472 ;; rule dependency for corresponding entity and architecture
16474 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16475 ;; rule dependencies for used packages
16476 (setq pack-list (vhdl-get-packages lib-alist work-library))
16477 (setq depend-list (append depend-list pack-list))
16478 ;; rule dependencies for contained component configurations
16480 (setq inst-entry (car inst-alist))
16481 (setq inst-ent-key (nth 2 inst-entry)
16482 ; comp-arch-key (nth 2 inst-entry))
16483 inst-conf-key (nth 4 inst-entry))
16484 (when (equal (downcase (nth 5 inst-entry)) work-library)
16486 (setq depend-list (cons inst-ent-key depend-list)
16487 subcomp-list (cons inst-ent-key subcomp-list)))
16488 ; (when comp-arch-key
16489 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16491 (when inst-conf-key
16492 (setq depend-list (cons inst-conf-key depend-list)
16493 subcomp-list (cons inst-conf-key subcomp-list))))
16494 (setq inst-alist (cdr inst-alist)))
16496 (aput 'rule-alist conf-file-name (list target-list depend-list))
16497 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16499 (setq conf-alist (cdr conf-alist)))
16500 (setq conf-alist tmp-list)
16501 ;; rules for all packages
16502 (setq tmp-list pack-alist)
16504 (setq pack-entry (car pack-alist)
16505 pack-key (nth 0 pack-entry)
16507 (when (nth 2 pack-entry)
16508 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16510 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16511 rule (aget rule-alist pack-file-name)
16512 target-list (nth 0 rule) depend-list (nth 1 rule))
16513 (setq tmp-key (vhdl-replace-string
16514 pack-regexp (funcall adjust-case pack-key)))
16515 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16516 ;; rule target for this package
16517 (setq target-list (cons pack-key target-list))
16518 ;; rule dependencies for all used packages
16519 (setq pack-list (vhdl-get-packages lib-alist work-library))
16520 (setq depend-list (append depend-list pack-list))
16521 (setq all-pack-list pack-list)
16523 (aput 'rule-alist pack-file-name (list target-list depend-list))
16524 ;; rules for this package's body
16525 (when (nth 7 pack-entry)
16526 (setq pack-body-key (concat pack-key "-body")
16527 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16529 rule (aget rule-alist pack-body-file-name)
16530 target-list (nth 0 rule)
16531 depend-list (nth 1 rule))
16532 (setq tmp-key (vhdl-replace-string
16533 pack-body-regexp (funcall adjust-case pack-key)))
16535 (cons (cons pack-body-key tmp-key) unit-list))
16536 ;; rule target for this package's body
16537 (setq target-list (cons pack-body-key target-list))
16538 ;; rule dependency for corresponding package declaration
16539 (setq depend-list (cons pack-key depend-list))
16540 ;; rule dependencies for all used packages
16541 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16542 (setq depend-list (append depend-list pack-list))
16543 (setq all-pack-list (append all-pack-list pack-list))
16545 (aput 'rule-alist pack-body-file-name
16546 (list target-list depend-list)))
16548 (cons (list pack-key (when pack-body-key (list pack-body-key))
16551 (setq pack-alist (cdr pack-alist)))
16552 (setq pack-alist tmp-list)
16553 ;; generate Makefile
16554 (let* ((project (aget vhdl-project-alist project))
16555 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16556 (compiler-id (nth 9 compiler))
16558 (vhdl-resolve-env-variable
16559 (vhdl-replace-string
16560 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16562 (makefile-path-name (expand-file-name
16563 makefile-name compile-directory))
16564 (orig-buffer (current-buffer))
16565 cell second-list subcomp-list options unit-key unit-name)
16567 (setq unit-list (vhdl-sort-alist unit-list))
16568 (setq prim-list (vhdl-sort-alist prim-list))
16569 (setq tmp-list rule-alist)
16570 (while tmp-list ; pre-sort rule targets
16571 (setq cell (cdar tmp-list))
16572 (setcar cell (sort (car cell) 'string<))
16573 (setq tmp-list (cdr tmp-list)))
16574 (setq rule-alist ; sort by first rule target
16576 (function (lambda (a b)
16577 (string< (car (cadr a)) (car (cadr b)))))))
16578 ;; open and clear Makefile
16579 (set-buffer (find-file-noselect makefile-path-name t t))
16581 (insert "# -*- Makefile -*-\n"
16582 "### " (file-name-nondirectory makefile-name)
16583 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16586 (insert "\n# Project : " (nth 0 project))
16587 (insert "\n# Directory : \"" directory "\""))
16588 (insert "\n# Platform : " vhdl-compiler
16589 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16590 (user-login-name) "\n")
16591 ;; insert compile and option variable settings
16592 (insert "\n\n# Define compilation command and options\n"
16593 "\nCOMPILE = " (nth 0 compiler)
16594 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16596 ;; insert library paths
16597 (setq library-directory
16598 (directory-file-name
16599 (if (file-name-absolute-p library-directory)
16601 (file-relative-name
16602 (expand-file-name library-directory directory)
16603 compile-directory))))
16604 (insert "\n\n# Define library paths\n"
16605 "\nLIBRARY-" work-library " = " library-directory "\n")
16606 ;; insert variable definitions for all library unit files
16607 (insert "\n\n# Define library unit files\n")
16608 (setq tmp-list unit-list)
16610 (insert "\nUNIT-" work-library "-" (caar unit-list)
16611 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16612 (setq unit-list (cdr unit-list)))
16613 ;; insert variable definition for list of all library unit files
16614 (insert "\n\n\n# Define list of all library unit files\n"
16616 (setq unit-list tmp-list)
16618 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16619 (setq unit-list (cdr unit-list)))
16621 (setq unit-list tmp-list)
16622 ;; insert `make all' rule
16623 (insert "\n\n\n# Rule for compiling entire design\n"
16626 " \\\n\t\t$(ALL_UNITS)\n")
16627 ;; insert `make clean' rule
16628 (insert "\n\n# Rule for cleaning entire design\n"
16630 "\n\t-rm -f $(ALL_UNITS)\n")
16631 ;; insert `make library' rule
16632 (insert "\n\n# Rule for creating library directory\n"
16634 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16635 "\n$(LIBRARY-" work-library ") :"
16637 (vhdl-replace-string
16638 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16639 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16641 ;; insert rule for each library unit
16642 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16644 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16646 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16647 (setq unit-key (caar prim-list)
16648 unit-name (or (nth 0 (aget ent-alist unit-key t))
16649 (nth 0 (aget conf-alist unit-key t))
16650 (nth 0 (aget pack-alist unit-key t))))
16651 (insert "\n" unit-key)
16652 (unless (equal unit-key unit-name)
16653 (insert " \\\n" unit-name))
16656 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16658 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16659 (setq second-list (cdr second-list)))
16660 (while subcomp-list
16661 (when (and (assoc (car subcomp-list) unit-list)
16662 (not (equal unit-key (car subcomp-list))))
16663 (insert " \\\n\t\t" (car subcomp-list)))
16664 (setq subcomp-list (cdr subcomp-list)))
16666 (setq prim-list (cdr prim-list)))
16667 ;; insert rule for each library unit file
16668 (insert "\n\n# Rules for compiling single library unit files\n")
16670 (setq rule (car rule-alist))
16671 ;; get compiler options for this file
16673 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16674 ;; insert rule if file is supposed to be compiled
16675 (setq target-list (nth 1 rule)
16676 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16678 (setq tmp-list target-list)
16680 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16681 (if (cdr target-list) " \\" " :"))
16682 (setq target-list (cdr target-list)))
16683 (setq target-list tmp-list)
16684 ;; insert file name as first dependency
16685 (insert " \\\n\t\t" (nth 0 rule))
16686 ;; insert dependencies (except if also target or unit does not exist)
16688 (when (and (not (member (car depend-list) target-list))
16689 (assoc (car depend-list) unit-list))
16690 (insert " \\\n\t\t"
16691 "$(UNIT-" work-library "-" (car depend-list) ")"))
16692 (setq depend-list (cdr depend-list)))
16693 ;; insert compile command
16695 (insert "\n\t$(COMPILE) "
16696 (if (eq options 'default) "$(OPTIONS)" options) " "
16698 (setq tmp-list target-list)
16700 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16701 (if (cdr target-list) " \\" "\n"))
16702 (setq target-list (cdr target-list)))
16703 (setq target-list tmp-list))
16704 (setq rule-alist (cdr rule-alist)))
16705 (insert "\n\n### " makefile-name " ends here\n")
16706 ;; run Makefile generation hook
16707 (run-hooks 'vhdl-makefile-generation-hook)
16708 (message "Generating makefile \"%s\"...done" makefile-name)
16709 ;; save and close file
16710 (if (file-writable-p makefile-path-name)
16711 (progn (save-buffer)
16712 (kill-buffer (current-buffer))
16713 (set-buffer orig-buffer)
16714 (add-to-history 'file-name-history makefile-path-name))
16715 (vhdl-warning-when-idle
16716 (format "File not writable: \"%s\""
16717 (abbreviate-file-name makefile-path-name)))
16718 (switch-to-buffer (current-buffer))))))
16721 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16723 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16724 ;; (using `reporter.el')
16726 (defconst vhdl-mode-help-address
16727 "Reto Zimmermann <reto@gnu.org>"
16728 "Address for VHDL Mode bug reports.")
16730 (defun vhdl-submit-bug-report ()
16731 "Submit via mail a bug report on VHDL Mode."
16733 ;; load in reporter
16735 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16736 (let ((reporter-prompt-for-summary-p t))
16737 (reporter-submit-bug-report
16738 vhdl-mode-help-address
16739 (concat "VHDL Mode " vhdl-version)
16741 ;; report all important user options
16742 'vhdl-offsets-alist
16743 'vhdl-comment-only-line-offset
16745 'vhdl-electric-mode
16747 'vhdl-indent-tabs-mode
16748 'vhdl-project-alist
16750 'vhdl-project-file-name
16751 'vhdl-project-auto-load
16753 'vhdl-compiler-alist
16755 'vhdl-compile-use-local-error-regexp
16756 'vhdl-makefile-generation-hook
16757 'vhdl-default-library
16760 'vhdl-upper-case-keywords
16761 'vhdl-upper-case-types
16762 'vhdl-upper-case-attributes
16763 'vhdl-upper-case-enum-values
16764 'vhdl-upper-case-constants
16765 'vhdl-use-direct-instantiation
16766 'vhdl-compose-configuration-name
16767 'vhdl-entity-file-name
16768 'vhdl-architecture-file-name
16769 'vhdl-configuration-file-name
16770 'vhdl-package-file-name
16771 'vhdl-file-name-case
16772 'vhdl-electric-keywords
16773 'vhdl-optional-labels
16774 'vhdl-insert-empty-lines
16775 'vhdl-argument-list-indent
16776 'vhdl-association-list-with-formals
16777 'vhdl-conditions-in-parenthesis
16783 'vhdl-copyright-string
16784 'vhdl-platform-spec
16786 'vhdl-modify-date-prefix-string
16787 'vhdl-modify-date-on-saving
16789 'vhdl-reset-active-high
16790 'vhdl-clock-rising-edge
16791 'vhdl-clock-edge-condition
16795 'vhdl-include-port-comments
16796 'vhdl-include-direction-comments
16797 'vhdl-include-type-comments
16798 'vhdl-include-group-comments
16799 'vhdl-actual-port-name
16800 'vhdl-instance-name
16801 'vhdl-testbench-entity-name
16802 'vhdl-testbench-architecture-name
16803 'vhdl-testbench-configuration-name
16804 'vhdl-testbench-dut-name
16805 'vhdl-testbench-include-header
16806 'vhdl-testbench-declarations
16807 'vhdl-testbench-statements
16808 'vhdl-testbench-initialize-signals
16809 'vhdl-testbench-include-library
16810 'vhdl-testbench-include-configuration
16811 'vhdl-testbench-create-files
16812 'vhdl-testbench-entity-file-name
16813 'vhdl-testbench-architecture-file-name
16814 'vhdl-compose-create-files
16815 'vhdl-compose-configuration-create-file
16816 'vhdl-compose-configuration-hierarchical
16817 'vhdl-compose-configuration-use-subconfiguration
16818 'vhdl-compose-include-header
16819 'vhdl-compose-architecture-name
16820 'vhdl-components-package-name
16821 'vhdl-use-components-package
16822 'vhdl-self-insert-comments
16823 'vhdl-prompt-for-comments
16824 'vhdl-inline-comment-column
16825 'vhdl-end-comment-column
16828 'vhdl-align-group-separate
16829 'vhdl-align-same-indent
16830 'vhdl-highlight-keywords
16831 'vhdl-highlight-names
16832 'vhdl-highlight-special-words
16833 'vhdl-highlight-forbidden-words
16834 'vhdl-highlight-verilog-keywords
16835 'vhdl-highlight-translate-off
16836 'vhdl-highlight-case-sensitive
16837 'vhdl-special-syntax-alist
16838 'vhdl-forbidden-words
16839 'vhdl-forbidden-syntax
16840 'vhdl-directive-keywords
16841 'vhdl-speedbar-auto-open
16842 'vhdl-speedbar-display-mode
16843 'vhdl-speedbar-scan-limit
16844 'vhdl-speedbar-jump-to-unit
16845 'vhdl-speedbar-update-on-saving
16846 'vhdl-speedbar-save-cache
16847 'vhdl-speedbar-cache-file-name
16849 'vhdl-source-file-menu
16850 'vhdl-hideshow-menu
16851 'vhdl-hide-all-init
16852 'vhdl-print-two-column
16853 'vhdl-print-customize-faces
16854 'vhdl-intelligent-tab
16855 'vhdl-indent-syntax-based
16856 'vhdl-word-completion-case-sensitive
16857 'vhdl-word-completion-in-minibuffer
16858 'vhdl-underscore-is-part-of-word
16863 (if vhdl-special-indent-hook
16864 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16865 "vhdl-special-indent-hook is set to '"
16866 (format "%s" vhdl-special-indent-hook)
16867 ".\nPerhaps this is your problem?\n"
16868 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16878 (defconst vhdl-doc-release-notes nil
16880 Release Notes for VHDL Mode 3.33
16881 ================================
16890 CONFIGURATION DECLARATION GENERATION:
16891 - Automatic generation of a configuration declaration for a design.
16892 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16898 `vhdl-configuration-file-name': (new)
16899 Specify how the configuration file name is obtained.
16900 `vhdl-compose-configuration-name': (new)
16901 Specify how the configuration name is optained.
16902 `vhdl-compose-configuration-create-file': (new)
16903 Specify whether a new file should be created for a configuration.
16904 `vhdl-compose-configuration-hierarchical': (new)
16905 Specify whether hierarchical configurations should be created.
16906 `vhdl-compose-configuration-use-subconfiguration': (new)
16907 Specify whether subconfigurations should be used inside configurations.
16911 (defconst vhdl-doc-keywords nil
16913 Reserved words in VHDL
16914 ----------------------
16916 VHDL'93 (IEEE Std 1076-1993):
16917 `vhdl-93-keywords' : keywords
16918 `vhdl-93-types' : standardized types
16919 `vhdl-93-attributes' : standardized attributes
16920 `vhdl-93-enum-values' : standardized enumeration values
16921 `vhdl-93-functions' : standardized functions
16922 `vhdl-93-packages' : standardized packages and libraries
16924 VHDL-AMS (IEEE Std 1076.1):
16925 `vhdl-ams-keywords' : keywords
16926 `vhdl-ams-types' : standardized types
16927 `vhdl-ams-attributes' : standardized attributes
16928 `vhdl-ams-enum-values' : standardized enumeration values
16929 `vhdl-ams-functions' : standardized functions
16931 Math Packages (IEEE Std 1076.2):
16932 `vhdl-math-types' : standardized types
16933 `vhdl-math-constants' : standardized constants
16934 `vhdl-math-functions' : standardized functions
16935 `vhdl-math-packages' : standardized packages
16938 `vhdl-verilog-keywords' : Verilog reserved words
16940 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16943 (defconst vhdl-doc-coding-style nil
16945 For VHDL coding style and naming convention guidelines, see the following
16949 \"VHDL Coding Styles and Methodologies\".
16950 Kluwer Academic Publishers, 1999.
16951 http://members.aol.com/vhdlcohen/vhdl/
16953 \[2] Michael Keating and Pierre Bricaud.
16954 \"Reuse Methodology Manual, Second Edition\".
16955 Kluwer Academic Publishers, 1999.
16956 http://www.openmore.com/openmore/rmm2.html
16958 \[3] European Space Agency.
16959 \"VHDL Modelling Guidelines\".
16960 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16962 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16963 to visually support naming conventions.")
16966 (defun vhdl-version ()
16967 "Echo the current version of VHDL Mode in the minibuffer."
16969 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16970 (vhdl-keep-region-active))
16972 (defun vhdl-doc-variable (variable)
16973 "Display VARIABLE's documentation in *Help* buffer."
16975 (unless (featurep 'xemacs)
16976 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16977 (with-output-to-temp-buffer
16978 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16979 (princ (documentation-property variable 'variable-documentation))
16980 (with-current-buffer standard-output
16982 (print-help-return-message)))
16984 (defun vhdl-doc-mode ()
16985 "Display VHDL Mode documentation in *Help* buffer."
16987 (unless (featurep 'xemacs)
16988 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16989 (with-output-to-temp-buffer
16990 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16993 (princ (documentation 'vhdl-mode))
16994 (with-current-buffer standard-output
16996 (print-help-return-message)))
16999 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17001 (provide 'vhdl-mode)
17003 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
17004 ;;; vhdl-mode.el ends here