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, 2010
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-indent-tabs-mode nil
203 "*Non-nil means indentation can insert tabs.
204 Overrides local variable `indent-tabs-mode'."
209 (defgroup vhdl-compile nil
210 "Customizations for compilation."
213 (defcustom vhdl-compiler-alist
215 ;; Cadence Leapfrog: cv -file test.vhd
216 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
217 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
218 nil
"mkdir \\1" "./" "work/" "Makefile" "leapfrog"
219 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
220 ("\\1/entity" "\\2/\\1" "\\1/configuration"
221 "\\1/package" "\\1/body" downcase
))
222 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
223 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
224 ;; (PLL_400X_TOP) is not declared [10.3].
225 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
226 nil
"mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
227 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
228 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
229 "\\1/package/pc.db" "\\1/body/pc.db" downcase
))
230 ;; Ikos Voyager: analyze test.vhd
232 ;; E L4/C5: this library unit is inaccessible
233 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
234 nil
"mkdir \\1" "./" "work/" "Makefile" "ikos"
235 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
236 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
238 ;; ModelSim, Model Technology: vcom test.vhd
239 ;; ERROR: test.vhd(14): Unknown identifier: positiv
240 ;; WARNING[2]: test.vhd(85): Possible infinite loop
241 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
242 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
243 nil
"vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
244 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
245 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
246 "\\1/_primary.dat" "\\1/body.dat" downcase
))
247 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
248 ;; test.vhd:34: error message
249 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
250 nil
"mkdir \\1" "./" "work/" "Makefile" "provhdl"
251 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
252 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
253 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase
))
254 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
255 ;; ERROR: test.vhd(24): near "dnd": expecting: END
256 ;; WARNING[4]: test.vhd(30): A space is required between ...
257 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
258 nil
"mkdir \\1" "./" "work/" "Makefile" "quickhdl"
259 ("\\(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 ;; Savant: scram -publish-cc test.vhd
263 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
264 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
265 nil
"mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
266 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
267 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
268 "\\1_config.vhdl" "\\1_package.vhdl"
269 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase
))
270 ;; Simili: vhdlp -work test.vhd
271 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
272 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
273 nil
"mkdir \\1" "./" "work/" "Makefile" "simili"
274 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
275 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
276 "\\1/prim.var" "\\1/_body.var" downcase
))
277 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
278 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
279 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
280 nil
"mkdir \\1" "./" "work/" "Makefile" "speedwave"
281 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
283 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
284 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
285 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
286 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys"
287 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
288 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase
))
289 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
290 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
291 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
292 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
293 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
294 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase
))
296 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
297 ("Synplify" "n/a" "n/a" "make" "-f \\1"
298 nil
"mkdir \\1" "./" "work/" "Makefile" "synplify"
299 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
301 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
302 ;; Compiling "test.vhd" line 1...
303 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
304 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
305 nil
"mkdir \\1" "./" "work/" "Makefile" "vantage"
306 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
307 ("^ *Compiling \"\\(.+\\)\" " 1)
309 ;; VeriBest: vc vhdl test.vhd
310 ;; (no file name printed out!)
311 ;; 32: Z <= A and BitA ;
313 ;; [Error] Name BITA is unknown
314 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
315 nil
"mkdir \\1" "./" "work/" "Makefile" "veribest"
316 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
318 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
319 ;; Compiling "test.vhd" line 1...
320 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
321 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
322 nil
"mkdir \\1" "./" "work/" "Makefile" "viewlogic"
323 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
324 ("^ *Compiling \"\\(.+\\)\" " 1)
327 "*List of available VHDL compilers and their properties.
328 Each list entry specifies the following items for a compiler:
330 Compiler name : name used in option `vhdl-compiler' to choose compiler
331 Compile command : command used for source file compilation
332 Compile options : compile options (\"\\1\" inserts library name)
333 Make command : command used for compilation using a Makefile
334 Make options : make options (\"\\1\" inserts Makefile name)
335 Generate Makefile: use built-in function or command to generate a Makefile
336 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
337 Library command : command to create library directory \(\"\\1\" inserts
338 library directory, \"\\2\" inserts library name)
339 Compile directory: where compilation is run and the Makefile is placed
340 Library directory: directory of default library
341 Makefile name : name of Makefile (default is \"Makefile\")
342 ID string : compiler identification string (see `vhdl-project-alist')
344 Regexp : regular expression to match error messages (*)
345 File subexp index: index of subexpression that matches the file name
346 Line subexp index: index of subexpression that matches the line number
347 Column subexp idx: index of subexpression that matches the column number
349 Regexp : regular expression to match a file name message
350 File subexp index: index of subexpression that matches the file name
351 Unit-to-file name mapping: mapping of library unit names to names of files
352 generated by the compiler (used for Makefile generation)
353 To string : string a name is mapped to (\"\\1\" inserts the unit name,
354 \"\\2\" inserts the entity name for architectures)
355 Case adjustment : adjust case of inserted unit names
357 \(*) The regular expression must match the error message starting from the
358 beginning of the line (but not necessarily to the end of the line).
360 Compile options allows insertion of the library name (see `vhdl-project-alist')
361 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
363 For Makefile generation, the built-in function can be used (requires
364 specification of the unit-to-file name mapping). Alternatively, an
365 external command can be specified. Work directory allows specification of
366 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
367 used for Makefile generation). To use another library name than \"work\",
368 customize `vhdl-project-alist'. The library command is inserted in Makefiles
369 to automatically create the library directory if not existent.
371 Compile options, compile directory, library directory, and Makefile name are
372 overwritten by the project settings if a project is defined (see
373 `vhdl-project-alist'). Directory paths are relative to the source file
376 Some compilers do not include the file name in the error message, but print
377 out a file name message in advance. In this case, set \"File Subexp Index\"
378 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
379 If no file name at all is printed out, set both \"File Message\" entries to 0
380 \(a default file name message will be printed out instead, does not work in
383 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
384 assigning its name to option `vhdl-compiler'.
386 Please send any missing or erroneous compiler properties to the maintainer for
389 NOTE: Activate new error and file message regexps and reflect the new setting
390 in the choice list of option `vhdl-compiler' by restarting Emacs."
392 (list :tag
"Compiler" :indent
2
393 (string :tag
"Compiler name ")
394 (string :tag
"Compile command ")
395 (string :tag
"Compile options " "-work \\1")
396 (string :tag
"Make command " "make")
397 (string :tag
"Make options " "-f \\1")
398 (choice :tag
"Generate Makefile "
399 (const :tag
"Built-in function" nil
)
400 (string :tag
"Command" "vmake \\2 > \\1"))
401 (string :tag
"Library command " "mkdir \\1")
402 (directory :tag
"Compile directory "
403 :validate vhdl-widget-directory-validate
"./")
404 (directory :tag
"Library directory "
405 :validate vhdl-widget-directory-validate
"work/")
406 (file :tag
"Makefile name " "Makefile")
407 (string :tag
"ID string ")
408 (list :tag
"Error message" :indent
4
409 (regexp :tag
"Regexp ")
410 (integer :tag
"File subexp index")
411 (integer :tag
"Line subexp index")
412 (integer :tag
"Column subexp idx"))
413 (list :tag
"File message" :indent
4
414 (regexp :tag
"Regexp ")
415 (integer :tag
"File subexp index"))
416 (choice :tag
"Unit-to-file name mapping"
417 :format
"%t: %[Value Menu%] %v\n"
418 (const :tag
"Not defined" nil
)
419 (list :tag
"To string" :indent
4
420 (string :tag
"Entity " "\\1.vhd")
421 (string :tag
"Architecture " "\\2_\\1.vhd")
422 (string :tag
"Configuration " "\\1.vhd")
423 (string :tag
"Package " "\\1.vhd")
424 (string :tag
"Package Body " "\\1_body.vhd")
425 (choice :tag
"Case adjustment "
426 (const :tag
"None" identity
)
427 (const :tag
"Upcase" upcase
)
428 (const :tag
"Downcase" downcase
))))))
429 :set
(lambda (variable value
)
430 (vhdl-custom-set variable value
'vhdl-update-mode-menu
))
431 :group
'vhdl-compile
)
433 (defcustom vhdl-compiler
"ModelSim"
434 "*Specifies the VHDL compiler to be used for syntax analysis.
435 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
436 :type
(let ((alist vhdl-compiler-alist
) list
)
438 (setq list
(cons (list 'const
(caar alist
)) list
))
439 (setq alist
(cdr alist
)))
440 (append '(choice) (nreverse list
)))
441 :group
'vhdl-compile
)
443 (defcustom vhdl-compile-use-local-error-regexp t
444 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
445 In this case, only error message regexps for VHDL compilers are active if
446 compilation is started from a VHDL buffer. Otherwise, the error message
447 regexps are appended to the predefined global regexps, and all regexps are
448 active all the time. Note that by doing that, the predefined global regexps
449 might result in erroneous parsing of error messages for some VHDL compilers.
451 NOTE: Activate the new setting by restarting Emacs."
453 :group
'vhdl-compile
)
455 (defcustom vhdl-makefile-generation-hook nil
456 "*Functions to run at the end of Makefile generation.
457 Allows to insert user specific parts into a Makefile.
461 \(re-search-backward \"^# Rule for compiling entire design\")
462 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
464 :group
'vhdl-compile
)
466 (defcustom vhdl-default-library
"work"
467 "*Name of default library.
468 Is overwritten by project settings if a project is active."
470 :group
'vhdl-compile
)
473 (defgroup vhdl-project nil
474 "Customizations for projects."
477 (defcustom vhdl-project-alist
478 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
479 "~/example1/" ("src/system/" "src/components/") ""
480 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil
)
481 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" .
"-optimize \\3") (".*_tb\\.vhd" . nil
))))
482 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
483 ("Example 2" "Individual source files, multiple compilers in different directories"
484 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
485 nil
"\\1/" "work" "\\1/work/" "Makefile" "")
486 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
487 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
488 nil
"./" "work" "work-\\1/" "Makefile-\\1" "\
489 -------------------------------------------------------------------------------
490 -- This is a multi-line project description
491 -- that can be used as a project dependent part of the file header.
493 "*List of projects and their properties.
494 Name : name used in option `vhdl-project' to choose project
495 Title : title of project (single-line string)
496 Default directory: default project directory (absolute path)
497 Sources : a) source files : path + \"/\" + file name
498 b) directory : path + \"/\"
499 c) directory tree: \"-r \" + path + \"/\"
500 Exclude regexp : matches file/directory names to be excluded as sources
501 Compile options : project-specific options for each compiler
502 Compiler name : name of compiler for which these options are valid
503 Compile options: project-specific compiler options
504 (\"\\1\" inserts library name, \"\\2\" default options)
505 Make options: project-specific make options
506 (\"\\1\" inserts Makefile name, \"\\2\" default options)
507 Exceptions : file-specific exceptions
508 File name regexp: matches file names for which exceptions are valid
509 - Options : file-specific compiler options string
510 (\"\\1\" inserts library name, \"\\2\" default options,
511 \"\\3\" project-specific options)
512 - Do not compile: do not compile this file (in Makefile)
513 Compile directory: where compilation is run and the Makefile is placed
514 \(\"\\1\" inserts compiler ID string)
515 Library name : name of library (default is \"work\")
516 Library directory: path to library (\"\\1\" inserts compiler ID string)
517 Makefile name : name of Makefile
518 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
519 Description : description of project (multi-line string)
521 Project title and description are used to insert into the file header (see
522 option `vhdl-file-header').
524 The default directory must have an absolute path (use `M-TAB' for completion).
525 All other paths can be absolute or relative to the default directory. All
526 paths must end with '/'.
528 The design units found in the sources (files and directories) are shown in the
529 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
530 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
531 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
532 specified, the default directory is taken as source directory. Otherwise,
533 the default directory is only taken as source directory if there is a sources
534 entry with the empty string or \"./\". Exclude regexp allows to filter out
535 specific file and directory names from the list of sources (e.g. CVS
538 Files are compiled in the compile directory. Makefiles are also placed into
539 the compile directory. Library directory specifies which directory the
540 compiler compiles into (used to generate the Makefile).
542 Since different compile/library directories and Makefiles may exist for
543 different compilers within one project, these paths and names allow the
544 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
545 Compile options, compile directory, library directory, and Makefile name
546 overwrite the settings of the current compiler.
548 File-specific compiler options (highest priority) overwrite project-specific
549 options which overwrite default options (lowest priority). Lower priority
550 options can be inserted in higher priority options. This allows to reuse
551 default options (e.g. \"-file\") in project- or file-specific options (e.g.
554 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
555 by restarting Emacs."
557 (list :tag
"Project" :indent
2
558 (string :tag
"Name ")
559 (string :tag
"Title ")
560 (directory :tag
"Default directory"
561 :validate vhdl-widget-directory-validate
562 ,(abbreviate-file-name default-directory
))
563 (repeat :tag
"Sources " :indent
4
564 (directory :format
" %v" "./"))
565 (regexp :tag
"Exclude regexp ")
567 :tag
"Compile options " :indent
4
568 (list :tag
"Compiler" :indent
6
569 ,(let ((alist vhdl-compiler-alist
) list
)
571 (setq list
(cons (list 'const
(caar alist
)) list
))
572 (setq alist
(cdr alist
)))
573 (append '(choice :tag
"Compiler name")
575 (string :tag
"Compile options" "\\2")
576 (string :tag
"Make options " "\\2")
578 :tag
"Exceptions " :indent
8
580 (regexp :tag
"File name regexp ")
581 (choice :format
"%[Value Menu%] %v"
582 (string :tag
"Options" "\\3")
583 (const :tag
"Do not compile" nil
))))))
584 (directory :tag
"Compile directory"
585 :validate vhdl-widget-directory-validate
"./")
586 (string :tag
"Library name " "work")
587 (directory :tag
"Library directory"
588 :validate vhdl-widget-directory-validate
"work/")
589 (file :tag
"Makefile name " "Makefile")
590 (string :tag
"Description: (type `C-j' for newline)"
591 :format
"%t\n%v\n")))
592 :set
(lambda (variable value
)
593 (vhdl-custom-set variable value
594 'vhdl-update-mode-menu
595 'vhdl-speedbar-refresh
))
596 :group
'vhdl-project
)
598 (defcustom vhdl-project nil
599 "*Specifies the default for the current project.
600 Select a project name from the ones defined in option `vhdl-project-alist'.
601 Is used to determine the project title and description to be inserted in file
602 headers and the source files/directories to be scanned in the hierarchy
603 browser. The current project can also be changed temporarily in the menu."
604 :type
(let ((alist vhdl-project-alist
) list
)
606 (setq list
(cons (list 'const
(caar alist
)) list
))
607 (setq alist
(cdr alist
)))
608 (append '(choice (const :tag
"None" nil
) (const :tag
"--"))
610 :group
'vhdl-project
)
612 (defcustom vhdl-project-file-name
'("\\1.prj")
613 "*List of file names/paths for importing/exporting project setups.
614 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
615 replaced by the user name (allows to have user-specific project setups).
616 The first entry is used as file name to import/export individual project
617 setups. All entries are used to automatically import project setups at
618 startup (see option `vhdl-project-auto-load'). Projects loaded from the
619 first entry are automatically made current. Hint: specify local project
620 setups in first entry, global setups in following entries; loading a local
621 project setup will make it current, while loading the global setups
622 is done without changing the current project.
623 Names can also have an absolute path (i.e. project setups can be stored
624 in global directories)."
625 :type
'(repeat (string :tag
"File name" "\\1.prj"))
626 :group
'vhdl-project
)
628 (defcustom vhdl-project-auto-load
'(startup)
629 "*Automatically load project setups from files.
630 All project setup files that match the file names specified in option
631 `vhdl-project-file-name' are automatically loaded. The project of the
632 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
634 A project setup file can be obtained by exporting a project (see menu).
635 At startup: project setup file is loaded at Emacs startup"
636 :type
'(set (const :tag
"At startup" startup
))
637 :group
'vhdl-project
)
639 (defcustom vhdl-project-sort t
640 "*Non-nil means projects are displayed in alphabetical order."
642 :group
'vhdl-project
)
645 (defgroup vhdl-style nil
646 "Customizations for coding styles."
648 :group
'vhdl-template
650 :group
'vhdl-compose
)
652 (defcustom vhdl-standard
'(87 nil
)
653 "*VHDL standards used.
655 VHDL'87 : IEEE Std 1076-1987
656 VHDL'93 : IEEE Std 1076-1993
657 Additional standards:
658 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
659 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
661 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
662 \"Activate Options\"."
663 :type
'(list (choice :tag
"Basic standard"
664 (const :tag
"VHDL'87" 87)
665 (const :tag
"VHDL'93" 93))
666 (set :tag
"Additional standards" :indent
2
667 (const :tag
"VHDL-AMS" ams
)
668 (const :tag
"Math packages" math
)))
669 :set
(lambda (variable value
)
670 (vhdl-custom-set variable value
671 'vhdl-template-map-init
672 'vhdl-mode-abbrev-table-init
673 'vhdl-template-construct-alist-init
674 'vhdl-template-package-alist-init
675 'vhdl-update-mode-menu
676 'vhdl-words-init
'vhdl-font-lock-init
))
679 (defcustom vhdl-basic-offset
2
680 "*Amount of basic offset used for indentation.
681 This value is used by + and - symbols in `vhdl-offsets-alist'."
685 (defcustom vhdl-upper-case-keywords nil
686 "*Non-nil means convert keywords to upper case.
687 This is done when typed or expanded or by the fix case functions."
689 :set
(lambda (variable value
)
690 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
693 (defcustom vhdl-upper-case-types nil
694 "*Non-nil means convert standardized types to upper case.
695 This is done when expanded or by the fix case functions."
697 :set
(lambda (variable value
)
698 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
701 (defcustom vhdl-upper-case-attributes nil
702 "*Non-nil means convert standardized attributes to upper case.
703 This is done when expanded or by the fix case functions."
705 :set
(lambda (variable value
)
706 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
709 (defcustom vhdl-upper-case-enum-values nil
710 "*Non-nil means convert standardized enumeration values to upper case.
711 This is done when expanded or by the fix case functions."
713 :set
(lambda (variable value
)
714 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
717 (defcustom vhdl-upper-case-constants t
718 "*Non-nil means convert standardized constants to upper case.
719 This is done when expanded."
721 :set
(lambda (variable value
)
722 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
725 (defcustom vhdl-use-direct-instantiation
'standard
726 "*Non-nil means use VHDL'93 direct component instantiation.
728 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
730 :type
'(choice (const :tag
"Never" never
)
731 (const :tag
"Standard" standard
)
732 (const :tag
"Always" always
))
736 (defgroup vhdl-naming nil
737 "Customizations for naming conventions."
740 (defcustom vhdl-entity-file-name
'(".*" .
"\\&")
742 "*Specifies how the entity file name is obtained.
743 The entity file name can be obtained by modifying the entity name (e.g.
744 attaching or stripping off a substring). The file extension is automatically
745 taken from the file name of the current buffer."
746 vhdl-name-doc-string
)
747 :type
'(cons (regexp :tag
"From regexp")
748 (string :tag
"To string "))
750 :group
'vhdl-compose
)
752 (defcustom vhdl-architecture-file-name
'("\\(.*\\) \\(.*\\)" .
"\\1_\\2")
754 "*Specifies how the architecture file name is obtained.
755 The architecture file name can be obtained by modifying the entity
756 and/or architecture name (e.g. attaching or stripping off a substring). The
757 file extension is automatically taken from the file name of the current
758 buffer. The string that is matched against the regexp is the concatenation
759 of the entity and the architecture name separated by a space. This gives
760 access to both names (see default setting as example)."
761 vhdl-name-doc-string
)
762 :type
'(cons (regexp :tag
"From regexp")
763 (string :tag
"To string "))
765 :group
'vhdl-compose
)
767 (defcustom vhdl-configuration-file-name
'(".*" .
"\\&")
769 "*Specifies how the configuration file name is obtained.
770 The configuration file name can be obtained by modifying the configuration
771 name (e.g. attaching or stripping off a substring). The file extension is
772 automatically taken from the file name of the current buffer."
773 vhdl-name-doc-string
)
774 :type
'(cons (regexp :tag
"From regexp")
775 (string :tag
"To string "))
777 :group
'vhdl-compose
)
779 (defcustom vhdl-package-file-name
'(".*" .
"\\&")
781 "*Specifies how the package file name is obtained.
782 The package file name can be obtained by modifying the package name (e.g.
783 attaching or stripping off a substring). The file extension is automatically
784 taken from the file name of the current buffer. Package files can be created
785 in a different directory by prepending a relative or absolute path to the
787 vhdl-name-doc-string
)
788 :type
'(cons (regexp :tag
"From regexp")
789 (string :tag
"To string "))
791 :group
'vhdl-compose
)
793 (defcustom vhdl-file-name-case
'identity
794 "*Specifies how to change case for obtaining file names.
795 When deriving a file name from a VHDL unit name, case can be changed as
797 As Is: case is not changed (taken as is)
798 Lower Case: whole name is changed to lower case
799 Upper Case: whole name is changed to upper case
800 Capitalize: first letter of each word in name is capitalized"
801 :type
'(choice (const :tag
"As Is" identity
)
802 (const :tag
"Lower Case" downcase
)
803 (const :tag
"Upper Case" upcase
)
804 (const :tag
"Capitalize" capitalize
))
806 :group
'vhdl-compose
)
809 (defgroup vhdl-template nil
810 "Customizations for electrification."
813 (defcustom vhdl-electric-keywords
'(vhdl user
)
814 "*Type of keywords for which electrification is enabled.
815 VHDL keywords: invoke built-in templates
816 User keywords: invoke user models (see option `vhdl-model-alist')"
817 :type
'(set (const :tag
"VHDL keywords" vhdl
)
818 (const :tag
"User model keywords" user
))
819 :set
(lambda (variable value
)
820 (vhdl-custom-set variable value
'vhdl-mode-abbrev-table-init
))
821 :group
'vhdl-template
)
823 (defcustom vhdl-optional-labels
'process
824 "*Constructs for which labels are to be queried.
825 Template generators prompt for optional labels for:
827 Processes only: processes only (also procedurals in VHDL-AMS)
828 All constructs: all constructs with optional labels and keyword END"
829 :type
'(choice (const :tag
"None" none
)
830 (const :tag
"Processes only" process
)
831 (const :tag
"All constructs" all
))
832 :group
'vhdl-template
)
834 (defcustom vhdl-insert-empty-lines
'unit
835 "*Specifies whether to insert empty lines in some templates.
836 This improves readability of code. Empty lines are inserted in:
838 Design units only: entities, architectures, configurations, packages only
839 All constructs : also all constructs with BEGIN...END parts
841 Replaces option `vhdl-additional-empty-lines'."
842 :type
'(choice (const :tag
"None" none
)
843 (const :tag
"Design units only" unit
)
844 (const :tag
"All constructs" all
))
845 :group
'vhdl-template
847 :group
'vhdl-compose
)
849 (defcustom vhdl-argument-list-indent nil
850 "*Non-nil means indent argument lists relative to opening parenthesis.
851 That is, argument, association, and port lists start on the same line as the
852 opening parenthesis and subsequent lines are indented accordingly.
853 Otherwise, lists start on a new line and are indented as normal code."
855 :group
'vhdl-template
857 :group
'vhdl-compose
)
859 (defcustom vhdl-association-list-with-formals t
860 "*Non-nil means write association lists with formal parameters.
861 Templates prompt for formal and actual parameters (ports/generics).
862 When pasting component instantiations, formals are included.
863 If nil, only a list of actual parameters is entered."
865 :group
'vhdl-template
867 :group
'vhdl-compose
)
869 (defcustom vhdl-conditions-in-parenthesis nil
870 "*Non-nil means place parenthesis around condition expressions."
872 :group
'vhdl-template
)
874 (defcustom vhdl-zero-string
"'0'"
875 "*String to use for a logic zero."
877 :group
'vhdl-template
)
879 (defcustom vhdl-one-string
"'1'"
880 "*String to use for a logic one."
882 :group
'vhdl-template
)
885 (defgroup vhdl-header nil
886 "Customizations for file header."
887 :group
'vhdl-template
888 :group
'vhdl-compose
)
890 (defcustom vhdl-file-header
"\
891 -------------------------------------------------------------------------------
892 -- Title : <title string>
893 -- Project : <project>
894 -------------------------------------------------------------------------------
897 -- Company : <company>
899 -- Last update: <date>
900 -- Platform : <platform>
901 -- Standard : <standard>
902 <projectdesc>-------------------------------------------------------------------------------
903 -- Description: <cursor>
904 <copyright>-------------------------------------------------------------------------------
906 -- Date Version Author Description
907 -- <date> 1.0 <login>\tCreated
908 -------------------------------------------------------------------------------
911 "*String or file to insert as file header.
912 If the string specifies an existing file name, the contents of the file is
913 inserted, otherwise the string itself is inserted as file header.
914 Type `C-j' for newlines.
915 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
916 if the header needs to be version controlled.
918 The following keywords for template generation are supported:
919 <filename> : replaced by the name of the buffer
920 <author> : replaced by the user name and email address
921 \(`user-full-name', `mail-host-address', `user-mail-address')
922 <login> : replaced by user login name (`user-login-name')
923 <company> : replaced by contents of option `vhdl-company-name'
924 <date> : replaced by the current date
925 <year> : replaced by the current year
926 <project> : replaced by title of current project (`vhdl-project')
927 <projectdesc> : replaced by description of current project (`vhdl-project')
928 <copyright> : replaced by copyright string (`vhdl-copyright-string')
929 <platform> : replaced by contents of option `vhdl-platform-spec'
930 <standard> : replaced by the VHDL language standard(s) used
931 <... string> : replaced by a queried string (\"...\" is the prompt word)
932 <title string>: replaced by file title in automatically generated files
933 <cursor> : final cursor position
935 The (multi-line) project description <projectdesc> can be used as a project
936 dependent part of the file header and can also contain the above keywords."
940 (defcustom vhdl-file-footer
""
941 "*String or file to insert as file footer.
942 If the string specifies an existing file name, the contents of the file is
943 inserted, otherwise the string itself is inserted as file footer (i.e. at
944 the end of the file).
945 Type `C-j' for newlines.
946 The same keywords as in option `vhdl-file-header' can be used."
950 (defcustom vhdl-company-name
""
951 "*Name of company to insert in file header.
952 See option `vhdl-file-header'."
956 (defcustom vhdl-copyright-string
"\
957 -------------------------------------------------------------------------------
958 -- Copyright (c) <year> <company>
960 "*Copyright string to insert in file header.
961 Can be multi-line string (type `C-j' for newline) and contain other file
962 header keywords (see option `vhdl-file-header')."
966 (defcustom vhdl-platform-spec
""
967 "*Specification of VHDL platform to insert in file header.
968 The platform specification should contain names and versions of the
969 simulation and synthesis tools used.
970 See option `vhdl-file-header'."
974 (defcustom vhdl-date-format
"%Y-%m-%d"
975 "*Specifies the date format to use in the header.
976 This string is passed as argument to the command `format-time-string'.
977 For more information on format strings, see the documentation for the
978 `format-time-string' command (C-h f `format-time-string')."
982 (defcustom vhdl-modify-date-prefix-string
"-- Last update: "
983 "*Prefix string of modification date in VHDL file header.
984 If actualization of the modification date is called (menu,
985 `\\[vhdl-template-modify]'), this string is searched and the rest
986 of the line replaced by the current date."
990 (defcustom vhdl-modify-date-on-saving t
991 "*Non-nil means update the modification date when the buffer is saved.
992 Calls function `\\[vhdl-template-modify]').
994 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
995 \"Activate Options\"."
1000 (defgroup vhdl-sequential-process nil
1001 "Customizations for sequential processes."
1002 :group
'vhdl-template
)
1004 (defcustom vhdl-reset-kind
'async
1005 "*Specifies which kind of reset to use in sequential processes."
1006 :type
'(choice (const :tag
"None" none
)
1007 (const :tag
"Synchronous" sync
)
1008 (const :tag
"Asynchronous" async
))
1009 :group
'vhdl-sequential-process
)
1011 (defcustom vhdl-reset-active-high nil
1012 "*Non-nil means reset in sequential processes is active high.
1013 Otherwise, reset is active low."
1015 :group
'vhdl-sequential-process
)
1017 (defcustom vhdl-clock-rising-edge t
1018 "*Non-nil means rising edge of clock triggers sequential processes.
1019 Otherwise, falling edge triggers."
1021 :group
'vhdl-sequential-process
)
1023 (defcustom vhdl-clock-edge-condition
'standard
1024 "*Syntax of the clock edge condition.
1025 Standard: \"clk'event and clk = '1'\"
1026 Function: \"rising_edge(clk)\""
1027 :type
'(choice (const :tag
"Standard" standard
)
1028 (const :tag
"Function" function
))
1029 :group
'vhdl-sequential-process
)
1031 (defcustom vhdl-clock-name
""
1032 "*Name of clock signal to use in templates."
1034 :group
'vhdl-sequential-process
)
1036 (defcustom vhdl-reset-name
""
1037 "*Name of reset signal to use in templates."
1039 :group
'vhdl-sequential-process
)
1042 (defgroup vhdl-model nil
1043 "Customizations for user models."
1046 (defcustom vhdl-model-alist
1048 "<label> : process (<clock>, <reset>)
1049 begin -- process <label>
1050 if <reset> = '0' then -- asynchronous reset (active low)
1052 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1053 if <enable> = '1' then -- synchronous load
1057 end process <label>;"
1059 "*List of user models.
1060 VHDL models (templates) can be specified by the user in this list. They can be
1061 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1062 electrification (i.e. overriding existing or creating new keywords, see
1063 option `vhdl-electric-keywords').
1064 Name : name of model (string of words and spaces)
1065 String : string or name of file to be inserted as model (newline: `C-j')
1066 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1067 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1068 Keyword : keyword to invoke model
1070 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1071 A prompt that appears several times is queried once and replaced throughout
1072 the model. Special prompts are:
1073 <clock> : name specified in `vhdl-clock-name' (if not empty)
1074 <reset> : name specified in `vhdl-reset-name' (if not empty)
1075 <cursor>: final cursor position
1076 File header prompts (see variable `vhdl-file-header') are automatically
1077 replaced, so that user models can also be used to insert different types of
1080 If the string specifies an existing file name, the contents of the file is
1081 inserted, otherwise the string itself is inserted.
1082 The code within the models should be correctly indented.
1083 Type `C-j' for newlines.
1085 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1086 \"Activate Options\"."
1087 :type
'(repeat (list :tag
"Model" :indent
2
1088 (string :tag
"Name ")
1089 (string :tag
"String : (type `C-j' for newline)"
1091 (sexp :tag
"Key binding" x
)
1092 (string :tag
"Keyword " :format
"%t: %v\n")))
1093 :set
(lambda (variable value
)
1094 (vhdl-custom-set variable value
1095 'vhdl-model-map-init
1097 'vhdl-mode-abbrev-table-init
1098 'vhdl-update-mode-menu
))
1102 (defgroup vhdl-compose nil
1103 "Customizations for structural composition."
1106 (defcustom vhdl-compose-architecture-name
'(".*" .
"str")
1108 "*Specifies how the component architecture name is obtained.
1109 The component architecture name can be obtained by modifying the entity name
1110 \(e.g. attaching or stripping off a substring).
1111 If TO STRING is empty, the architecture name is queried."
1112 vhdl-name-doc-string
)
1113 :type
'(cons (regexp :tag
"From regexp")
1114 (string :tag
"To string "))
1115 :group
'vhdl-compose
)
1117 (defcustom vhdl-compose-configuration-name
1118 '("\\(.*\\) \\(.*\\)" .
"\\1_\\2_cfg")
1120 "*Specifies how the configuration name is obtained.
1121 The configuration name can be obtained by modifying the entity and/or
1122 architecture name (e.g. attaching or stripping off a substring). The string
1123 that is matched against the regexp is the concatenation of the entity and the
1124 architecture name separated by a space. This gives access to both names (see
1125 default setting as example)."
1126 vhdl-name-doc-string
)
1127 :type
'(cons (regexp :tag
"From regexp")
1128 (string :tag
"To string "))
1129 :group
'vhdl-compose
)
1131 (defcustom vhdl-components-package-name
1132 '((".*" .
"\\&_components") .
"components")
1134 "*Specifies how the name for the components package is obtained.
1135 The components package is a package containing all component declarations for
1136 the current design. Its name can be obtained by modifying the project name
1137 \(e.g. attaching or stripping off a substring). If no project is defined, the
1138 DIRECTORY entry is chosen."
1139 vhdl-name-doc-string
)
1140 :type
'(cons (cons :tag
"Project" :indent
2
1141 (regexp :tag
"From regexp")
1142 (string :tag
"To string "))
1143 (string :tag
"Directory:\n String "))
1144 :group
'vhdl-compose
)
1146 (defcustom vhdl-use-components-package nil
1147 "*Non-nil means use a separate components package for component declarations.
1148 Otherwise, component declarations are inserted and searched for in the
1149 architecture declarative parts."
1151 :group
'vhdl-compose
)
1153 (defcustom vhdl-compose-include-header t
1154 "*Non-nil means include a header in automatically generated files."
1156 :group
'vhdl-compose
)
1158 (defcustom vhdl-compose-create-files
'single
1159 "*Specifies whether new files should be created for the new component.
1160 The component's entity and architecture are inserted:
1161 None : in current buffer
1162 Single file : in new single file
1163 Separate files: in two separate files
1164 The file names are obtained from variables `vhdl-entity-file-name' and
1165 `vhdl-architecture-file-name'."
1166 :type
'(choice (const :tag
"None" none
)
1167 (const :tag
"Single file" single
)
1168 (const :tag
"Separate files" separate
))
1169 :group
'vhdl-compose
)
1171 (defcustom vhdl-compose-configuration-create-file nil
1172 "*Specifies whether a new file should be created for the configuration.
1173 If non-nil, a new file is created for the configuration.
1174 The file name is obtained from variable `vhdl-configuration-file-name'."
1176 :group
'vhdl-compose
)
1178 (defcustom vhdl-compose-configuration-hierarchical t
1179 "*Specifies whether hierarchical configurations should be created.
1180 If non-nil, automatically created configurations are hierarchical and include
1181 the whole hierarchy of subcomponents. Otherwise the configuration only
1182 includes one level of subcomponents."
1184 :group
'vhdl-compose
)
1186 (defcustom vhdl-compose-configuration-use-subconfiguration t
1187 "*Specifies whether subconfigurations should be used inside configurations.
1188 If non-nil, automatically created configurations use configurations in binding
1189 indications for subcomponents, if such configurations exist. Otherwise,
1190 entities are used in binding indications for subcomponents."
1192 :group
'vhdl-compose
)
1195 (defgroup vhdl-port nil
1196 "Customizations for port translation functions."
1198 :group
'vhdl-compose
)
1200 (defcustom vhdl-include-port-comments nil
1201 "*Non-nil means include port comments when a port is pasted."
1205 (defcustom vhdl-include-direction-comments nil
1206 "*Non-nil means include port direction in instantiations as comments."
1210 (defcustom vhdl-include-type-comments nil
1211 "*Non-nil means include generic/port type in instantiations as comments."
1215 (defcustom vhdl-include-group-comments
'never
1216 "*Specifies whether to include group comments and spacings.
1217 The comments and empty lines between groups of ports are pasted:
1219 Declarations: in entity/component/constant/signal declarations only
1220 Always : also in generic/port maps"
1221 :type
'(choice (const :tag
"Never" never
)
1222 (const :tag
"Declarations" decl
)
1223 (const :tag
"Always" always
))
1226 (defcustom vhdl-actual-port-name
'(".*" .
"\\&")
1228 "*Specifies how actual port names are obtained from formal port names.
1229 In a component instantiation, an actual port name can be obtained by
1230 modifying the formal port name (e.g. attaching or stripping off a substring)."
1231 vhdl-name-doc-string
)
1232 :type
'(cons (regexp :tag
"From regexp")
1233 (string :tag
"To string "))
1236 (defcustom vhdl-instance-name
'(".*" .
"\\&_%d")
1238 "*Specifies how an instance name is obtained.
1239 The instance name can be obtained by modifying the name of the component to be
1240 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1241 by a unique number (starting with 1).
1242 If TO STRING is empty, the instance name is queried."
1243 vhdl-name-doc-string
)
1244 :type
'(cons (regexp :tag
"From regexp")
1245 (string :tag
"To string "))
1249 (defgroup vhdl-testbench nil
1250 "Customizations for testbench generation."
1253 (defcustom vhdl-testbench-entity-name
'(".*" .
"\\&_tb")
1255 "*Specifies how the testbench entity name is obtained.
1256 The entity name of a testbench can be obtained by modifying the name of
1257 the component to be tested (e.g. attaching or stripping off a substring)."
1258 vhdl-name-doc-string
)
1259 :type
'(cons (regexp :tag
"From regexp")
1260 (string :tag
"To string "))
1261 :group
'vhdl-testbench
)
1263 (defcustom vhdl-testbench-architecture-name
'(".*" .
"")
1265 "*Specifies how the testbench architecture name is obtained.
1266 The testbench architecture name can be obtained by modifying the name of
1267 the component to be tested (e.g. attaching or stripping off a substring).
1268 If TO STRING is empty, the architecture name is queried."
1269 vhdl-name-doc-string
)
1270 :type
'(cons (regexp :tag
"From regexp")
1271 (string :tag
"To string "))
1272 :group
'vhdl-testbench
)
1274 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1276 "*Specifies how the testbench configuration name is obtained.
1277 The configuration name of a testbench can be obtained by modifying the entity
1278 and/or architecture name (e.g. attaching or stripping off a substring). The
1279 string that is matched against the regexp is the concatenation of the entity
1280 and the architecture name separated by a space. This gives access to both
1281 names (see default setting as example)."
1282 vhdl-name-doc-string
)
1283 :type
'(cons (regexp :tag
"From regexp")
1284 (string :tag
"To string "))
1285 :group
'vhdl-testbench
)
1287 (defcustom vhdl-testbench-dut-name
'(".*" .
"DUT")
1289 "*Specifies how a DUT instance name is obtained.
1290 The design-under-test instance name (i.e. the component instantiated in the
1291 testbench) can be obtained by modifying the component name (e.g. attaching
1292 or stripping off a substring)."
1293 vhdl-name-doc-string
)
1294 :type
'(cons (regexp :tag
"From regexp")
1295 (string :tag
"To string "))
1296 :group
'vhdl-testbench
)
1298 (defcustom vhdl-testbench-include-header t
1299 "*Non-nil means include a header in automatically generated files."
1301 :group
'vhdl-testbench
)
1303 (defcustom vhdl-testbench-declarations
"\
1305 signal Clk : std_logic := '1';
1307 "*String or file to be inserted in the testbench declarative part.
1308 If the string specifies an existing file name, the contents of the file is
1309 inserted, otherwise the string itself is inserted in the testbench
1310 architecture before the BEGIN keyword.
1311 Type `C-j' for newlines."
1313 :group
'vhdl-testbench
)
1315 (defcustom vhdl-testbench-statements
"\
1317 Clk <= not Clk after 10 ns;
1319 -- waveform generation
1320 WaveGen_Proc: process
1322 -- insert signal assignments here
1324 wait until Clk = '1';
1325 end process WaveGen_Proc;
1327 "*String or file to be inserted in the testbench statement part.
1328 If the string specifies an existing file name, the contents of the file is
1329 inserted, otherwise the string itself is inserted in the testbench
1330 architecture before the END keyword.
1331 Type `C-j' for newlines."
1333 :group
'vhdl-testbench
)
1335 (defcustom vhdl-testbench-initialize-signals nil
1336 "*Non-nil means initialize signals with `0' when declared in testbench."
1338 :group
'vhdl-testbench
)
1340 (defcustom vhdl-testbench-include-library t
1341 "*Non-nil means a library/use clause for std_logic_1164 is included."
1343 :group
'vhdl-testbench
)
1345 (defcustom vhdl-testbench-include-configuration t
1346 "*Non-nil means a testbench configuration is attached at the end."
1348 :group
'vhdl-testbench
)
1350 (defcustom vhdl-testbench-create-files
'single
1351 "*Specifies whether new files should be created for the testbench.
1352 testbench entity and architecture are inserted:
1353 None : in current buffer
1354 Single file : in new single file
1355 Separate files: in two separate files
1356 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1357 and `vhdl-testbench-architecture-file-name'."
1358 :type
'(choice (const :tag
"None" none
)
1359 (const :tag
"Single file" single
)
1360 (const :tag
"Separate files" separate
))
1361 :group
'vhdl-testbench
)
1363 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1365 "*Specifies how the testbench entity file name is obtained.
1366 The entity file name can be obtained by modifying the testbench entity name
1367 \(e.g. attaching or stripping off a substring). The file extension is
1368 automatically taken from the file name of the current buffer. Testbench
1369 files can be created in a different directory by prepending a relative or
1370 absolute path to the file name."
1371 vhdl-name-doc-string
)
1372 :type
'(cons (regexp :tag
"From regexp")
1373 (string :tag
"To string "))
1374 :group
'vhdl-testbench
)
1376 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1378 "*Specifies how the testbench architecture file name is obtained.
1379 The architecture file name can be obtained by modifying the testbench entity
1380 and/or architecture name (e.g. attaching or stripping off a substring). The
1381 string that is matched against the regexp is the concatenation of the entity
1382 and the architecture name separated by a space. This gives access to both
1383 names (see default setting as example). Testbench files can be created in
1384 a different directory by prepending a relative or absolute path to the file
1386 vhdl-name-doc-string
)
1387 :type
'(cons (regexp :tag
"From regexp")
1388 (string :tag
"To string "))
1389 :group
'vhdl-testbench
)
1392 (defgroup vhdl-comment nil
1393 "Customizations for comments."
1396 (defcustom vhdl-self-insert-comments t
1397 "*Non-nil means various templates automatically insert help comments."
1399 :group
'vhdl-comment
)
1401 (defcustom vhdl-prompt-for-comments t
1402 "*Non-nil means various templates prompt for user definable comments."
1404 :group
'vhdl-comment
)
1406 (defcustom vhdl-inline-comment-column
40
1407 "*Column to indent and align inline comments to.
1408 Overrides local option `comment-column'.
1410 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1411 \"Activate Options\"."
1413 :group
'vhdl-comment
)
1415 (defcustom vhdl-end-comment-column
79
1416 "*End of comment column.
1417 Comments that exceed this column number are wrapped.
1419 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1420 \"Activate Options\"."
1422 :group
'vhdl-comment
)
1424 (defvar end-comment-column
)
1427 (defgroup vhdl-align nil
1428 "Customizations for alignment."
1431 (defcustom vhdl-auto-align t
1432 "*Non-nil means align some templates automatically after generation."
1436 (defcustom vhdl-align-groups t
1437 "*Non-nil means align groups of code lines separately.
1438 A group of code lines is a region of consecutive lines between two lines that
1439 match the regexp in option `vhdl-align-group-separate'."
1443 (defcustom vhdl-align-group-separate
"^\\s-*$"
1444 "*Regexp for matching a line that separates groups of lines for alignment.
1446 \"^\\s-*$\": matches an empty line
1447 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1451 (defcustom vhdl-align-same-indent t
1452 "*Non-nil means align blocks with same indent separately.
1453 When a region or the entire buffer is aligned, the code is divided into
1454 blocks of same indent which are aligned separately (except for argument/port
1455 lists). This gives nicer alignment in most cases.
1456 Option `vhdl-align-groups' still applies within these blocks."
1461 (defgroup vhdl-highlight nil
1462 "Customizations for highlighting."
1465 (defcustom vhdl-highlight-keywords t
1466 "*Non-nil means highlight VHDL keywords and other standardized words.
1467 The following faces are used:
1468 `font-lock-keyword-face' : keywords
1469 `font-lock-type-face' : standardized types
1470 `vhdl-font-lock-attribute-face': standardized attributes
1471 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1472 `vhdl-font-lock-function-face' : standardized function and package names
1474 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1475 entry \"Fontify Buffer\")."
1477 :set
(lambda (variable value
)
1478 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1479 :group
'vhdl-highlight
)
1481 (defcustom vhdl-highlight-names t
1482 "*Non-nil means highlight declaration names and construct labels.
1483 The following faces are used:
1484 `font-lock-function-name-face' : names in declarations of units,
1485 subprograms, components, as well as labels of VHDL constructs
1486 `font-lock-type-face' : names in type/nature declarations
1487 `vhdl-font-lock-attribute-face': names in attribute declarations
1488 `font-lock-variable-name-face' : names in declarations of signals,
1489 variables, constants, subprogram parameters, generics, and ports
1491 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1492 entry \"Fontify Buffer\")."
1494 :set
(lambda (variable value
)
1495 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1496 :group
'vhdl-highlight
)
1498 (defcustom vhdl-highlight-special-words nil
1499 "*Non-nil means highlight words with special syntax.
1500 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1501 are highlighted accordingly.
1502 Can be used for visual support of naming conventions.
1504 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1505 entry \"Fontify Buffer\")."
1507 :set
(lambda (variable value
)
1508 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1509 :group
'vhdl-highlight
)
1511 (defcustom vhdl-highlight-forbidden-words nil
1512 "*Non-nil means highlight forbidden words.
1513 The reserved words specified in option `vhdl-forbidden-words' or having the
1514 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1515 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1518 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1519 entry \"Fontify Buffer\")."
1521 :set
(lambda (variable value
)
1522 (vhdl-custom-set variable value
1523 'vhdl-words-init
'vhdl-font-lock-init
))
1524 :group
'vhdl-highlight
)
1526 (defcustom vhdl-highlight-verilog-keywords nil
1527 "*Non-nil means highlight Verilog keywords as reserved words.
1528 Verilog keywords are highlighted in a warning color (face
1529 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1531 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1532 entry \"Fontify Buffer\")."
1534 :set
(lambda (variable value
)
1535 (vhdl-custom-set variable value
1536 'vhdl-words-init
'vhdl-font-lock-init
))
1537 :group
'vhdl-highlight
)
1539 (defcustom vhdl-highlight-translate-off nil
1540 "*Non-nil means background-highlight code excluded from translation.
1541 That is, all code between \"-- pragma translate_off\" and
1542 \"-- pragma translate_on\" is highlighted using a different background color
1543 \(face `vhdl-font-lock-translate-off-face').
1544 Note: this might slow down on-the-fly fontification (and thus editing).
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
'vhdl-font-lock-init
))
1551 :group
'vhdl-highlight
)
1553 (defcustom vhdl-highlight-case-sensitive nil
1554 "*Non-nil means consider case for highlighting.
1556 non-nil also upper-case VHDL words are highlighted, but case of words with
1557 special syntax is not considered
1558 nil only lower-case VHDL words are highlighted, but case of words with
1559 special syntax is considered
1560 Overrides local option `font-lock-keywords-case-fold-search'.
1562 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1563 entry \"Fontify Buffer\")."
1565 :group
'vhdl-highlight
)
1567 (defcustom vhdl-special-syntax-alist
1568 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1569 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1570 ("variable" "\\w+_v" "Grey50" "Grey80"))
1571 "*List of special syntax to be highlighted.
1572 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1573 syntax (as regular expression) are highlighted in the corresponding color.
1575 Name : string of words and spaces
1576 Regexp : regular expression describing word syntax
1577 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1578 Color (light): foreground color for light background
1579 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1580 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1581 Color (dark) : foreground color for dark background
1582 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1583 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1585 Can be used for visual support of naming conventions, such as highlighting
1586 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1587 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1588 common substrings or name suffices.
1589 For each entry, a new face is generated with the specified colors and name
1590 \"vhdl-font-lock-\" + name + \"-face\".
1592 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1593 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1594 :type
'(repeat (list :tag
"Face" :indent
2
1595 (string :tag
"Name ")
1596 (regexp :tag
"Regexp " "\\w+_")
1597 (string :tag
"Color (light)")
1598 (string :tag
"Color (dark) ")))
1599 :set
(lambda (variable value
)
1600 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1601 :group
'vhdl-highlight
)
1603 (defcustom vhdl-forbidden-words
'()
1604 "*List of forbidden words to be highlighted.
1605 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1606 words are highlighted in a warning color to indicate not to use them.
1608 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\")."
1610 :type
'(repeat (string :format
"%v"))
1611 :set
(lambda (variable value
)
1612 (vhdl-custom-set variable value
1613 'vhdl-words-init
'vhdl-font-lock-init
))
1614 :group
'vhdl-highlight
)
1616 (defcustom vhdl-forbidden-syntax
""
1617 "*Syntax of forbidden words to be highlighted.
1618 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1619 syntax are highlighted in a warning color to indicate not to use them.
1620 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1621 highlights identifiers with 10 or more characters).
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
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-directive-keywords
'("pragma" "synopsys")
1632 "*List of compiler directive keywords recognized for highlighting.
1634 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1635 entry \"Fontify Buffer\")."
1636 :type
'(repeat (string :format
"%v"))
1637 :set
(lambda (variable value
)
1638 (vhdl-custom-set variable value
1639 'vhdl-words-init
'vhdl-font-lock-init
))
1640 :group
'vhdl-highlight
)
1643 (defgroup vhdl-speedbar nil
1644 "Customizations for speedbar."
1647 (defcustom vhdl-speedbar-auto-open nil
1648 "*Non-nil means automatically open speedbar at startup.
1649 Alternatively, the speedbar can be opened from the VHDL menu."
1651 :group
'vhdl-speedbar
)
1653 (defcustom vhdl-speedbar-display-mode
'files
1654 "*Specifies the default displaying mode when opening speedbar.
1655 Alternatively, the displaying mode can be selected from the speedbar menu or
1656 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1657 :type
'(choice (const :tag
"Files" files
)
1658 (const :tag
"Directory hierarchy" directory
)
1659 (const :tag
"Project hierarchy" project
))
1660 :group
'vhdl-speedbar
)
1662 (defcustom vhdl-speedbar-scan-limit
'(10000000 (1000000 50))
1663 "*Limits scanning of large files and netlists.
1664 Design units: maximum file size to scan for design units
1665 Hierarchy (instances of subcomponents):
1666 File size: maximum file size to scan for instances (in bytes)
1667 Instances per arch: maximum number of instances to scan per architecture
1669 \"None\" always means that there is no limit.
1670 In case of files not or incompletely scanned, a warning message and the file
1671 names are printed out.
1672 Background: scanning for instances is considerably slower than scanning for
1673 design units, especially when there are many instances. These limits should
1674 prevent the scanning of large netlists."
1675 :type
'(list (choice :tag
"Design units"
1676 :format
"%t : %[Value Menu%] %v"
1677 (const :tag
"None" nil
)
1678 (integer :tag
"File size"))
1679 (list :tag
"Hierarchy" :indent
2
1680 (choice :tag
"File size"
1681 :format
"%t : %[Value Menu%] %v"
1682 (const :tag
"None" nil
)
1683 (integer :tag
"Size "))
1684 (choice :tag
"Instances per arch"
1685 (const :tag
"None" nil
)
1686 (integer :tag
"Number "))))
1687 :group
'vhdl-speedbar
)
1689 (defcustom vhdl-speedbar-jump-to-unit t
1690 "*Non-nil means jump to the design unit code when opened in a buffer.
1691 The buffer cursor position is left unchanged otherwise."
1693 :group
'vhdl-speedbar
)
1695 (defcustom vhdl-speedbar-update-on-saving t
1696 "*Automatically update design hierarchy when buffer is saved."
1698 :group
'vhdl-speedbar
)
1700 (defcustom vhdl-speedbar-save-cache
'(hierarchy display
)
1701 "*Automatically save modified hierarchy caches when exiting Emacs.
1702 Hierarchy: design hierarchy information
1703 Display: displaying information (which design units to expand)"
1704 :type
'(set (const :tag
"Hierarchy" hierarchy
)
1705 (const :tag
"Display" display
))
1706 :group
'vhdl-speedbar
)
1708 (defcustom vhdl-speedbar-cache-file-name
".emacs-vhdl-cache-\\1-\\2"
1709 "*Name of file for saving hierarchy cache.
1710 \"\\1\" is replaced by the project name if a project is specified,
1711 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1712 different users to have cache files in the same directory). Can also have
1713 an absolute path (i.e. all caches can be stored in one global directory)."
1715 :group
'vhdl-speedbar
)
1718 (defgroup vhdl-menu nil
1719 "Customizations for menues."
1722 (defcustom vhdl-index-menu nil
1723 "*Non-nil means add an index menu for a source file when loading.
1724 Alternatively, the speedbar can be used. Note that the index menu scans a file
1725 when it is opened, while speedbar only scans the file upon request."
1729 (defcustom vhdl-source-file-menu nil
1730 "*Non-nil means add a menu of all source files in current directory.
1731 Alternatively, the speedbar can be used."
1735 (defcustom vhdl-hideshow-menu nil
1736 "*Non-nil means add hideshow menu and functionality at startup.
1737 Hideshow can also be enabled from the VHDL Mode menu.
1738 Hideshow allows hiding code of various VHDL constructs.
1740 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1741 \"Activate Options\"."
1745 (defcustom vhdl-hide-all-init nil
1746 "*Non-nil means hide all design units initially after a file is loaded."
1751 (defgroup vhdl-print nil
1752 "Customizations for printing."
1755 (defcustom vhdl-print-two-column t
1756 "*Non-nil means print code in two columns and landscape format.
1757 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1758 prints VHDL files in a nice two-column landscape style.
1760 NOTE: Activate the new setting by restarting Emacs.
1761 Overrides `ps-print' settings locally."
1765 (defcustom vhdl-print-customize-faces t
1766 "*Non-nil means use an optimized set of faces for postscript printing.
1768 NOTE: Activate the new setting by restarting Emacs.
1769 Overrides `ps-print' settings locally."
1774 (defgroup vhdl-misc nil
1775 "Miscellaneous customizations."
1778 (defcustom vhdl-intelligent-tab t
1779 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1780 That is, if preceeding character is part of a word then complete word,
1781 else if not at beginning of line then insert tab,
1782 else if last command was a `TAB' or `RET' then dedent one step,
1783 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1784 If nil, TAB always indents current line (i.e. `TAB' is bound to
1785 `indent-according-to-mode').
1787 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1788 \"Activate Options\"."
1792 (defcustom vhdl-indent-syntax-based t
1793 "*Non-nil means indent lines of code based on their syntactic context.
1794 Otherwise, a line is indented like the previous nonblank line. This can be
1795 useful in large files where syntax-based indentation gets very slow."
1799 (defcustom vhdl-word-completion-case-sensitive nil
1800 "*Non-nil means word completion using `TAB' is case sensitive.
1801 That is, `TAB' completes words that start with the same letters and case.
1802 Otherwise, case is ignored."
1806 (defcustom vhdl-word-completion-in-minibuffer t
1807 "*Non-nil enables word completion in minibuffer (for template prompts).
1809 NOTE: Activate the new setting by restarting Emacs."
1813 (defcustom vhdl-underscore-is-part-of-word nil
1814 "*Non-nil means consider the underscore character `_' as part of word.
1815 An identifier containing underscores is then treated as a single word in
1816 select and move operations. All parts of an identifier separated by underscore
1817 are treated as single words otherwise.
1819 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1820 \"Activate Options\"."
1822 :set
(lambda (variable value
)
1823 (vhdl-custom-set variable value
'vhdl-mode-syntax-table-init
))
1827 (defgroup vhdl-related nil
1828 "Related general customizations."
1831 ;; add related general customizations
1832 (custom-add-to-group 'vhdl-related
'hideshow
'custom-group
)
1833 (if (featurep 'xemacs
)
1834 (custom-add-to-group 'vhdl-related
'paren-mode
'custom-variable
)
1835 (custom-add-to-group 'vhdl-related
'paren-showing
'custom-group
))
1836 (custom-add-to-group 'vhdl-related
'ps-print
'custom-group
)
1837 (custom-add-to-group 'vhdl-related
'speedbar
'custom-group
)
1838 (custom-add-to-group 'vhdl-related
'line-number-mode
'custom-variable
)
1839 (unless (featurep 'xemacs
)
1840 (custom-add-to-group 'vhdl-related
'transient-mark-mode
'custom-variable
))
1841 (custom-add-to-group 'vhdl-related
'user-full-name
'custom-variable
)
1842 (custom-add-to-group 'vhdl-related
'mail-host-address
'custom-variable
)
1843 (custom-add-to-group 'vhdl-related
'user-mail-address
'custom-variable
)
1845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1846 ;; Internal variables
1848 (defvar vhdl-menu-max-size
20
1849 "*Specifies the maximum size of a menu before splitting it into submenues.")
1851 (defvar vhdl-progress-interval
1
1852 "*Interval used to update progress status during long operations.
1853 If a number, percentage complete gets updated after each interval of
1854 that many seconds. To inhibit all messages, set this option to nil.")
1856 (defvar vhdl-inhibit-startup-warnings-p nil
1857 "*If non-nil, inhibits start up compatibility warnings.")
1859 (defvar vhdl-strict-syntax-p nil
1860 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1861 If the syntactic symbol for a particular line does not match a symbol
1862 in the offsets alist, an error is generated, otherwise no error is
1863 reported and the syntactic symbol is ignored.")
1865 (defvar vhdl-echo-syntactic-information-p nil
1866 "*If non-nil, syntactic info is echoed when the line is indented.")
1868 (defconst vhdl-offsets-alist-default
1874 (statement-cont . vhdl-lineup-statement-cont
)
1875 (statement-block-intro .
+)
1876 (statement-case-intro .
+)
1877 (case-alternative .
+)
1878 (comment . vhdl-lineup-comment
)
1881 (arglist-cont-nonempty . vhdl-lineup-arglist
)
1882 (arglist-close . vhdl-lineup-arglist
)
1889 "Default settings for offsets of syntactic elements.
1890 Do not change this constant! See the variable `vhdl-offsets-alist' for
1893 (defvar vhdl-offsets-alist
(copy-alist vhdl-offsets-alist-default
)
1894 "*Association list of syntactic element symbols and indentation offsets.
1895 As described below, each cons cell in this list has the form:
1897 (SYNTACTIC-SYMBOL . OFFSET)
1899 When a line is indented, `vhdl-mode' first determines the syntactic
1900 context of the line by generating a list of symbols called syntactic
1901 elements. This list can contain more than one syntactic element and
1902 the global variable `vhdl-syntactic-context' contains the context list
1903 for the line being indented. Each element in this list is actually a
1904 cons cell of the syntactic symbol and a buffer position. This buffer
1905 position is call the relative indent point for the line. Some
1906 syntactic symbols may not have a relative indent point associated with
1909 After the syntactic context list for a line is generated, `vhdl-mode'
1910 calculates the absolute indentation for the line by looking at each
1911 syntactic element in the list. First, it compares the syntactic
1912 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1913 finds a match, it adds the OFFSET to the column of the relative indent
1914 point. The sum of this calculation for each element in the syntactic
1915 list is the absolute offset for line being indented.
1917 If the syntactic element does not match any in the `vhdl-offsets-alist',
1918 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1919 the element is ignored.
1921 Actually, OFFSET can be an integer, a function, a variable, or one of
1922 the following symbols: `+', `-', `++', or `--'. These latter
1923 designate positive or negative multiples of `vhdl-basic-offset',
1924 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1925 called with a single argument containing the cons of the syntactic
1926 element symbol and the relative indent point. The function should
1927 return an integer offset.
1929 Here is the current list of valid syntactic element symbols:
1931 string -- inside multi-line string
1932 block-open -- statement block open
1933 block-close -- statement block close
1934 statement -- a VHDL statement
1935 statement-cont -- a continuation of a VHDL statement
1936 statement-block-intro -- the first line in a new statement block
1937 statement-case-intro -- the first line in a case alternative block
1938 case-alternative -- a case statement alternative clause
1939 comment -- a line containing only a comment
1940 arglist-intro -- the first line in an argument list
1941 arglist-cont -- subsequent argument list lines when no
1942 arguments follow on the same line as the
1943 the arglist opening paren
1944 arglist-cont-nonempty -- subsequent argument list lines when at
1945 least one argument follows on the same
1946 line as the arglist opening paren
1947 arglist-close -- the solo close paren of an argument list
1948 entity -- inside an entity declaration
1949 configuration -- inside a configuration declaration
1950 package -- inside a package declaration
1951 architecture -- inside an architecture body
1952 package-body -- inside a package body")
1954 (defvar vhdl-comment-only-line-offset
0
1955 "*Extra offset for line which contains only the start of a comment.
1956 Can contain an integer or a cons cell of the form:
1958 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1960 Where NON-ANCHORED-OFFSET is the amount of offset given to
1961 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1962 the amount of offset to give column-zero anchored comment-only lines.
1963 Just an integer as value is equivalent to (<val> . 0)")
1965 (defvar vhdl-special-indent-hook nil
1966 "*Hook for user defined special indentation adjustments.
1967 This hook gets called after a line is indented by the mode.")
1969 (defvar vhdl-style-alist
1971 (vhdl-basic-offset .
4)
1972 (vhdl-offsets-alist .
())))
1973 "Styles of Indentation.
1974 Elements of this alist are of the form:
1976 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1978 where STYLE-STRING is a short descriptive string used to select a
1979 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1980 value for that variable when using the selected style.
1982 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1983 case, the VALUE is a list containing elements of the form:
1985 (SYNTACTIC-SYMBOL . VALUE)
1987 as described in `vhdl-offsets-alist'. These are passed directly to
1988 `vhdl-set-offset' so there is no need to set every syntactic symbol in
1989 your style, only those that are different from the default.")
1991 ;; dynamically append the default value of most variables
1992 (or (assoc "Default" vhdl-style-alist
)
1993 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1994 vhdl-strict-syntax-p
1995 vhdl-echo-syntactic-information-p
1998 vhdl-comment-only-line-offset
))
1999 (default (cons "Default"
2003 (cons var
(symbol-value var
))))
2005 (setq vhdl-style-alist
(cons default vhdl-style-alist
))))
2007 (defvar vhdl-mode-hook nil
2008 "*Hook called by `vhdl-mode'.")
2011 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2012 ;;; Required packages
2013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2017 (require 'compile
) ; XEmacs
2019 (require 'hippie-exp
)
2021 ;; optional (minimize warning messages during compile)
2023 (require 'font-lock
)
2025 (require 'speedbar
))
2028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2033 ;; XEmacs compatibility
2036 (defun vhdl-keep-region-active ()
2037 "Do whatever is necessary to keep the region active in XEmacs.
2038 Ignore byte-compiler warnings you might see."
2039 (and (featurep 'xemacs
)
2040 (setq zmacs-region-stays t
)))
2042 ;; `wildcard-to-regexp' is included only in XEmacs 21
2043 (unless (fboundp 'wildcard-to-regexp
)
2044 (defun wildcard-to-regexp (wildcard)
2045 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2046 (let* ((i (string-match "[*?]" wildcard
))
2047 (result (substring wildcard
0 i
))
2048 (len (length wildcard
)))
2051 (let ((ch (aref wildcard i
)))
2052 (setq result
(concat result
2053 (cond ((eq ch ?
*) "[^\000]*")
2054 ((eq ch ??
) "[^\000]")
2055 (t (char-to-string ch
)))))
2057 (concat "\\`" result
"\\'"))))
2059 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2060 ;; `regexp-opt' accelerates fontification by 10-20%
2061 (unless (fboundp 'regexp-opt
)
2062 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2063 (defun regexp-opt (strings &optional paren
)
2064 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
2065 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
))))
2067 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2068 (unless (fboundp 'match-string-no-properties
)
2069 (defalias 'match-string-no-properties
'match-string
))
2071 ;; `subst-char-in-string' undefined (XEmacs)
2072 (unless (fboundp 'subst-char-in-string
)
2073 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
2074 (let ((i (length string
))
2075 (newstr (if inplace string
(copy-sequence string
))))
2078 (if (eq (aref newstr i
) fromchar
) (aset newstr i tochar
)))
2081 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2082 (when (and (featurep 'xemacs
) (string< itimer-version
"1.09")
2083 (not noninteractive
))
2085 (when (string< itimer-version
"1.09")
2086 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2087 (beep) (sit-for 5)))
2089 ;; `file-expand-wildcards' undefined (XEmacs)
2090 (unless (fboundp 'file-expand-wildcards
)
2091 (defun file-expand-wildcards (pattern &optional full
)
2092 "Taken from Emacs' `files.el'."
2093 (let* ((nondir (file-name-nondirectory pattern
))
2094 (dirpart (file-name-directory pattern
))
2095 (dirs (if (and dirpart
(string-match "[[*?]" dirpart
))
2096 (mapcar 'file-name-as-directory
2097 (file-expand-wildcards (directory-file-name dirpart
)))
2101 (when (or (null (car dirs
)) ; Possible if DIRPART is not wild.
2102 (file-directory-p (directory-file-name (car dirs
))))
2103 (let ((this-dir-contents
2105 (mapcar #'(lambda (name)
2106 (unless (string-match "\\`\\.\\.?\\'"
2107 (file-name-nondirectory name
))
2109 (directory-files (or (car dirs
) ".") full
2110 (wildcard-to-regexp nondir
))))))
2113 (if (and (car dirs
) (not full
))
2114 (mapcar (function (lambda (name) (concat (car dirs
) name
)))
2118 (setq dirs
(cdr dirs
)))
2121 ;; `member-ignore-case' undefined (XEmacs)
2122 (unless (fboundp 'member-ignore-case
)
2123 (defalias 'member-ignore-case
'member
))
2125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2126 ;; Compatibility with older VHDL Mode versions
2128 (defvar vhdl-warnings nil
2129 "Warnings to tell the user during start up.")
2131 (defun vhdl-run-when-idle (secs repeat function
)
2132 "Wait until idle, then run FUNCTION."
2133 (if (fboundp 'start-itimer
)
2134 (start-itimer "vhdl-mode" function secs repeat t
)
2135 ; (run-with-idle-timer secs repeat function)))
2136 ;; explicitely activate timer (necessary when Emacs is already idle)
2137 (aset (run-with-idle-timer secs repeat function
) 0 nil
)))
2139 (defun vhdl-warning-when-idle (&rest args
)
2140 "Wait until idle, then print out warning STRING and beep."
2142 (vhdl-warning (apply 'format args
) t
)
2143 (unless vhdl-warnings
2144 (vhdl-run-when-idle .1 nil
'vhdl-print-warnings
))
2145 (setq vhdl-warnings
(cons (apply 'format args
) vhdl-warnings
))))
2147 (defun vhdl-warning (string &optional nobeep
)
2148 "Print out warning STRING and beep."
2149 (message "WARNING: %s" string
)
2150 (unless (or nobeep noninteractive
) (beep)))
2152 (defun vhdl-print-warnings ()
2153 "Print out messages in variable `vhdl-warnings'."
2154 (let ((no-warnings (length vhdl-warnings
)))
2155 (setq vhdl-warnings
(nreverse vhdl-warnings
))
2156 (while vhdl-warnings
2157 (message "WARNING: %s" (car vhdl-warnings
))
2158 (setq vhdl-warnings
(cdr vhdl-warnings
)))
2160 (when (> no-warnings
1)
2161 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2163 ;; Backward compatibility checks and fixes
2164 ;; option `vhdl-compiler' changed format
2165 (unless (stringp vhdl-compiler
)
2166 (setq vhdl-compiler
"ModelSim")
2167 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2169 ;; option `vhdl-standard' changed format
2170 (unless (listp vhdl-standard
)
2171 (setq vhdl-standard
'(87 nil
))
2172 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2174 ;; option `vhdl-model-alist' changed format
2175 (when (= (length (car vhdl-model-alist
)) 3)
2176 (let ((old-alist vhdl-model-alist
)
2179 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2180 (setq old-alist
(cdr old-alist
)))
2181 (setq vhdl-model-alist
(nreverse new-alist
)))
2182 (customize-save-variable 'vhdl-model-alist vhdl-model-alist
))
2184 ;; option `vhdl-project-alist' changed format
2185 (when (= (length (car vhdl-project-alist
)) 3)
2186 (let ((old-alist vhdl-project-alist
)
2189 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2190 (setq old-alist
(cdr old-alist
)))
2191 (setq vhdl-project-alist
(nreverse new-alist
)))
2192 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2194 ;; option `vhdl-project-alist' changed format (3.31.1)
2195 (when (= (length (car vhdl-project-alist
)) 4)
2196 (let ((old-alist vhdl-project-alist
)
2199 (setq elem
(car old-alist
))
2201 (cons (list (nth 0 elem
) (nth 1 elem
) "" (nth 2 elem
)
2202 nil
"./" "work" "work/" "Makefile" (nth 3 elem
))
2204 (setq old-alist
(cdr old-alist
)))
2205 (setq vhdl-project-alist
(nreverse new-alist
)))
2206 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2208 ;; option `vhdl-project-alist' changed format (3.31.12)
2209 (when (= (length (car vhdl-project-alist
)) 10)
2210 (let ((tmp-alist vhdl-project-alist
))
2212 (setcdr (nthcdr 3 (car tmp-alist
))
2213 (cons "" (nthcdr 4 (car tmp-alist
))))
2214 (setq tmp-alist
(cdr tmp-alist
))))
2215 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2217 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2218 (when (= (length (car vhdl-compiler-alist
)) 7)
2219 (let ((old-alist vhdl-compiler-alist
)
2222 (setq elem
(car old-alist
))
2224 (cons (list (nth 0 elem
) (nth 1 elem
) "" "make -f \\1"
2225 (if (equal (nth 3 elem
) "") nil
(nth 3 elem
))
2226 (nth 4 elem
) "work/" "Makefile" (downcase (nth 0 elem
))
2227 (nth 5 elem
) (nth 6 elem
) nil
)
2229 (setq old-alist
(cdr old-alist
)))
2230 (setq vhdl-compiler-alist
(nreverse new-alist
)))
2231 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2233 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2234 (when (= (length (car vhdl-compiler-alist
)) 12)
2235 (let ((tmp-alist vhdl-compiler-alist
))
2237 (setcdr (nthcdr 4 (car tmp-alist
))
2238 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist
))))
2239 (setq tmp-alist
(cdr tmp-alist
))))
2240 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2242 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2243 (when (= (length (car vhdl-compiler-alist
)) 13)
2244 (let ((tmp-alist vhdl-compiler-alist
))
2246 (setcdr (nthcdr 3 (car tmp-alist
))
2247 (cons "" (nthcdr 4 (car tmp-alist
))))
2248 (setq tmp-alist
(cdr tmp-alist
))))
2249 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2251 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2252 (when (= (length (nth 11 (car vhdl-compiler-alist
))) 3)
2253 (let ((tmp-alist vhdl-compiler-alist
))
2255 (setcdr (nthcdr 2 (nth 11 (car tmp-alist
)))
2257 (setq tmp-alist
(cdr tmp-alist
))))
2258 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2260 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2261 (when (equal vhdl-project
"")
2262 (setq vhdl-project nil
)
2263 (customize-save-variable 'vhdl-project vhdl-project
))
2265 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2266 (when (stringp vhdl-project-file-name
)
2267 (setq vhdl-project-file-name
(list vhdl-project-file-name
))
2268 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name
))
2270 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2271 (if (not (boundp 'speedbar-indentation-width
))
2272 (defvar speedbar-indentation-width
2)
2273 ;; set default to 2 if not already customized
2274 (unless (get 'speedbar-indentation-width
'saved-value
)
2275 (setq speedbar-indentation-width
2)))
2278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279 ;;; Help functions / inline substitutions / macros
2280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2282 (defun vhdl-standard-p (standard)
2283 "Check if STANDARD is specified as used standard."
2284 (or (eq standard
(car vhdl-standard
))
2285 (memq standard
(cadr vhdl-standard
))))
2287 (defun vhdl-project-p (&optional warning
)
2288 "Return non-nil if a project is displayed, i.e. directories or files are
2290 (if (assoc vhdl-project vhdl-project-alist
)
2292 (when (and vhdl-project warning
)
2293 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project
))
2296 (defun vhdl-resolve-env-variable (string)
2297 "Resolve environment variables in STRING."
2298 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string
)
2299 (setq string
(concat (match-string 1 string
)
2300 (getenv (match-string 2 string
))
2301 (match-string 4 string
))))
2304 (defun vhdl-default-directory ()
2305 "Return the default directory of the current project or the directory of the
2306 current buffer if no project is defined."
2307 (if (vhdl-project-p)
2308 (expand-file-name (vhdl-resolve-env-variable
2309 (nth 1 (aget vhdl-project-alist vhdl-project
))))
2312 (defmacro vhdl-prepare-search-1
(&rest body
)
2313 "Enable case insensitive search and switch to syntax table that includes '_',
2314 then execute BODY, and finally restore the old environment. Used for
2315 consistent searching."
2316 `(let ((case-fold-search t
)) ; case insensitive search
2317 ;; use extended syntax table
2318 (with-syntax-table vhdl-mode-ext-syntax-table
2321 (defmacro vhdl-prepare-search-2
(&rest body
)
2322 "Enable case insensitive search, switch to syntax table that includes '_',
2323 and remove `intangible' overlays, then execute BODY, and finally restore the
2324 old environment. Used for consistent searching."
2325 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2326 `(let ((case-fold-search t
) ; case insensitive search
2327 (current-syntax-table (syntax-table))
2328 overlay-all-list overlay-intangible-list overlay
)
2329 ;; use extended syntax table
2330 (set-syntax-table vhdl-mode-ext-syntax-table
)
2331 ;; remove `intangible' overlays
2332 (when (fboundp 'overlay-lists
)
2333 (setq overlay-all-list
(overlay-lists))
2334 (setq overlay-all-list
2335 (append (car overlay-all-list
) (cdr overlay-all-list
)))
2336 (while overlay-all-list
2337 (setq overlay
(car overlay-all-list
))
2338 (when (memq 'intangible
(overlay-properties overlay
))
2339 (setq overlay-intangible-list
2340 (cons overlay overlay-intangible-list
))
2341 (overlay-put overlay
'intangible nil
))
2342 (setq overlay-all-list
(cdr overlay-all-list
))))
2343 ;; execute BODY safely
2346 ;; restore syntax table
2347 (set-syntax-table current-syntax-table
)
2348 ;; restore `intangible' overlays
2349 (when (fboundp 'overlay-lists
)
2350 (while overlay-intangible-list
2351 (overlay-put (car overlay-intangible-list
) 'intangible t
)
2352 (setq overlay-intangible-list
2353 (cdr overlay-intangible-list
)))))))
2355 (defmacro vhdl-visit-file
(file-name issue-error
&rest body
)
2356 "Visit file FILE-NAME and execute BODY."
2357 `(if (null ,file-name
)
2359 (unless (file-directory-p ,file-name
)
2360 (let ((source-buffer (current-buffer))
2361 (visiting-buffer (find-buffer-visiting ,file-name
))
2363 (when (or (and visiting-buffer
(set-buffer visiting-buffer
))
2365 (progn (set-buffer (create-file-buffer ,file-name
))
2366 (setq file-opened t
)
2367 (vhdl-insert-file-contents ,file-name
)
2368 (modify-syntax-entry ?\-
". 12" (syntax-table))
2369 (modify-syntax-entry ?
\n ">" (syntax-table))
2370 (modify-syntax-entry ?\^M
">" (syntax-table))
2371 (modify-syntax-entry ?_
"w" (syntax-table))
2376 (when file-opened
(kill-buffer (current-buffer)))
2377 (set-buffer source-buffer
)
2378 (error "ERROR: File cannot be opened: \"%s\"" ,file-name
))
2379 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name
) t
)
2381 (condition-case info
2386 (when file-opened
(kill-buffer (current-buffer)))
2387 (set-buffer source-buffer
)
2388 (error (cadr info
)))
2389 (vhdl-warning (cadr info
))))))
2390 (when file-opened
(kill-buffer (current-buffer)))
2391 (set-buffer source-buffer
)))))
2393 (defun vhdl-insert-file-contents (filename)
2394 "Nicked from `insert-file-contents-literally', but allow coding system
2396 (let ((format-alist nil
)
2397 (after-insert-file-functions nil
)
2398 (jka-compr-compression-info-list nil
))
2399 (insert-file-contents filename t
)))
2401 (defun vhdl-sort-alist (alist)
2403 (sort alist
(function (lambda (a b
) (string< (car a
) (car b
))))))
2405 (defun vhdl-get-subdirs (directory)
2406 "Recursively get subdirectories of DIRECTORY."
2407 (let ((dir-list (list (file-name-as-directory directory
)))
2409 (setq file-list
(vhdl-directory-files directory t
"\\w.*"))
2411 (when (file-directory-p (car file-list
))
2412 (setq dir-list
(append dir-list
(vhdl-get-subdirs (car file-list
)))))
2413 (setq file-list
(cdr file-list
)))
2416 (defun vhdl-aput (alist-symbol key
&optional value
)
2417 "As `aput', but delete key-value pair if VALUE is nil."
2419 (aput alist-symbol key value
)
2420 (adelete alist-symbol key
)))
2422 (defun vhdl-delete (elt list
)
2423 "Delete by side effect the first occurrence of ELT as a member of LIST."
2424 (setq list
(cons nil list
))
2426 (while (and (cdr list1
) (not (equal elt
(cadr list1
))))
2427 (setq list1
(cdr list1
)))
2429 (setcdr list1
(cddr list1
))))
2432 (defun vhdl-speedbar-refresh (&optional key
)
2433 "Refresh directory or project with name KEY."
2434 (when (and (boundp 'speedbar-frame
)
2435 (frame-live-p speedbar-frame
))
2437 (last-frame (selected-frame)))
2440 (select-frame speedbar-frame
)
2441 (when (save-excursion
2442 (goto-char (point-min))
2443 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key
"$") nil t
))
2444 (goto-char (match-end 1))
2445 (speedbar-do-function-pointer)
2447 (speedbar-do-function-pointer)
2448 (message "Refreshing speedbar...done"))
2449 (select-frame last-frame
)))))
2451 (defun vhdl-show-messages ()
2452 "Get *Messages* buffer to show recent messages."
2454 (display-buffer (if (featurep 'xemacs
) " *Message-Log*" "*Messages*")))
2456 (defun vhdl-use-direct-instantiation ()
2457 "Return whether direct instantiation is used."
2458 (or (eq vhdl-use-direct-instantiation
'always
)
2459 (and (eq vhdl-use-direct-instantiation
'standard
)
2460 (not (vhdl-standard-p '87)))))
2462 (defun vhdl-max-marker (marker1 marker2
)
2463 "Return larger marker."
2464 (if (> marker1 marker2
) marker1 marker2
))
2466 (defun vhdl-goto-marker (marker)
2467 "Goto marker in appropriate buffer."
2468 (when (markerp marker
)
2469 (set-buffer (marker-buffer marker
)))
2472 (defun vhdl-menu-split (list title
)
2473 "Split menu LIST into several submenues, if number of
2474 elements > `vhdl-menu-max-size'."
2475 (if (> (length list
) vhdl-menu-max-size
)
2482 (setq sublist
(cons (car remain
) sublist
))
2483 (setq remain
(cdr remain
))
2485 (if (= i vhdl-menu-max-size
)
2487 (setq result
(cons (cons (format "%s %s" title menuno
)
2488 (nreverse sublist
)) result
))
2490 (setq menuno
(+ menuno
1))
2491 (setq sublist
'()))))
2493 (setq result
(cons (cons (format "%s %s" title menuno
)
2494 (nreverse sublist
)) result
)))
2499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2503 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2506 (defvar vhdl-template-map nil
2507 "Keymap for VHDL templates.")
2509 (defun vhdl-template-map-init ()
2510 "Initialize `vhdl-template-map'."
2511 (setq vhdl-template-map
(make-sparse-keymap))
2512 ;; key bindings for VHDL templates
2513 (define-key vhdl-template-map
"al" 'vhdl-template-alias
)
2514 (define-key vhdl-template-map
"ar" 'vhdl-template-architecture
)
2515 (define-key vhdl-template-map
"at" 'vhdl-template-assert
)
2516 (define-key vhdl-template-map
"ad" 'vhdl-template-attribute-decl
)
2517 (define-key vhdl-template-map
"as" 'vhdl-template-attribute-spec
)
2518 (define-key vhdl-template-map
"bl" 'vhdl-template-block
)
2519 (define-key vhdl-template-map
"ca" 'vhdl-template-case-is
)
2520 (define-key vhdl-template-map
"cd" 'vhdl-template-component-decl
)
2521 (define-key vhdl-template-map
"ci" 'vhdl-template-component-inst
)
2522 (define-key vhdl-template-map
"cs" 'vhdl-template-conditional-signal-asst
)
2523 (define-key vhdl-template-map
"Cb" 'vhdl-template-block-configuration
)
2524 (define-key vhdl-template-map
"Cc" 'vhdl-template-component-conf
)
2525 (define-key vhdl-template-map
"Cd" 'vhdl-template-configuration-decl
)
2526 (define-key vhdl-template-map
"Cs" 'vhdl-template-configuration-spec
)
2527 (define-key vhdl-template-map
"co" 'vhdl-template-constant
)
2528 (define-key vhdl-template-map
"di" 'vhdl-template-disconnect
)
2529 (define-key vhdl-template-map
"el" 'vhdl-template-else
)
2530 (define-key vhdl-template-map
"ei" 'vhdl-template-elsif
)
2531 (define-key vhdl-template-map
"en" 'vhdl-template-entity
)
2532 (define-key vhdl-template-map
"ex" 'vhdl-template-exit
)
2533 (define-key vhdl-template-map
"fi" 'vhdl-template-file
)
2534 (define-key vhdl-template-map
"fg" 'vhdl-template-for-generate
)
2535 (define-key vhdl-template-map
"fl" 'vhdl-template-for-loop
)
2536 (define-key vhdl-template-map
"\C-f" 'vhdl-template-footer
)
2537 (define-key vhdl-template-map
"fb" 'vhdl-template-function-body
)
2538 (define-key vhdl-template-map
"fd" 'vhdl-template-function-decl
)
2539 (define-key vhdl-template-map
"ge" 'vhdl-template-generic
)
2540 (define-key vhdl-template-map
"gd" 'vhdl-template-group-decl
)
2541 (define-key vhdl-template-map
"gt" 'vhdl-template-group-template
)
2542 (define-key vhdl-template-map
"\C-h" 'vhdl-template-header
)
2543 (define-key vhdl-template-map
"ig" 'vhdl-template-if-generate
)
2544 (define-key vhdl-template-map
"it" 'vhdl-template-if-then
)
2545 (define-key vhdl-template-map
"li" 'vhdl-template-library
)
2546 (define-key vhdl-template-map
"lo" 'vhdl-template-bare-loop
)
2547 (define-key vhdl-template-map
"\C-m" 'vhdl-template-modify
)
2548 (define-key vhdl-template-map
"\C-t" 'vhdl-template-insert-date
)
2549 (define-key vhdl-template-map
"ma" 'vhdl-template-map
)
2550 (define-key vhdl-template-map
"ne" 'vhdl-template-next
)
2551 (define-key vhdl-template-map
"ot" 'vhdl-template-others
)
2552 (define-key vhdl-template-map
"Pd" 'vhdl-template-package-decl
)
2553 (define-key vhdl-template-map
"Pb" 'vhdl-template-package-body
)
2554 (define-key vhdl-template-map
"(" 'vhdl-template-paired-parens
)
2555 (define-key vhdl-template-map
"po" 'vhdl-template-port
)
2556 (define-key vhdl-template-map
"pb" 'vhdl-template-procedure-body
)
2557 (define-key vhdl-template-map
"pd" 'vhdl-template-procedure-decl
)
2558 (define-key vhdl-template-map
"pc" 'vhdl-template-process-comb
)
2559 (define-key vhdl-template-map
"ps" 'vhdl-template-process-seq
)
2560 (define-key vhdl-template-map
"rp" 'vhdl-template-report
)
2561 (define-key vhdl-template-map
"rt" 'vhdl-template-return
)
2562 (define-key vhdl-template-map
"ss" 'vhdl-template-selected-signal-asst
)
2563 (define-key vhdl-template-map
"si" 'vhdl-template-signal
)
2564 (define-key vhdl-template-map
"su" 'vhdl-template-subtype
)
2565 (define-key vhdl-template-map
"ty" 'vhdl-template-type
)
2566 (define-key vhdl-template-map
"us" 'vhdl-template-use
)
2567 (define-key vhdl-template-map
"va" 'vhdl-template-variable
)
2568 (define-key vhdl-template-map
"wa" 'vhdl-template-wait
)
2569 (define-key vhdl-template-map
"wl" 'vhdl-template-while-loop
)
2570 (define-key vhdl-template-map
"wi" 'vhdl-template-with
)
2571 (define-key vhdl-template-map
"wc" 'vhdl-template-clocked-wait
)
2572 (define-key vhdl-template-map
"\C-pb" 'vhdl-template-package-numeric-bit
)
2573 (define-key vhdl-template-map
"\C-pn" 'vhdl-template-package-numeric-std
)
2574 (define-key vhdl-template-map
"\C-ps" 'vhdl-template-package-std-logic-1164
)
2575 (define-key vhdl-template-map
"\C-pA" 'vhdl-template-package-std-logic-arith
)
2576 (define-key vhdl-template-map
"\C-pM" 'vhdl-template-package-std-logic-misc
)
2577 (define-key vhdl-template-map
"\C-pS" 'vhdl-template-package-std-logic-signed
)
2578 (define-key vhdl-template-map
"\C-pT" 'vhdl-template-package-std-logic-textio
)
2579 (define-key vhdl-template-map
"\C-pU" 'vhdl-template-package-std-logic-unsigned
)
2580 (define-key vhdl-template-map
"\C-pt" 'vhdl-template-package-textio
)
2581 (define-key vhdl-template-map
"\C-dn" 'vhdl-template-directive-translate-on
)
2582 (define-key vhdl-template-map
"\C-df" 'vhdl-template-directive-translate-off
)
2583 (define-key vhdl-template-map
"\C-dN" 'vhdl-template-directive-synthesis-on
)
2584 (define-key vhdl-template-map
"\C-dF" 'vhdl-template-directive-synthesis-off
)
2585 (define-key vhdl-template-map
"\C-q" 'vhdl-template-search-prompt
)
2586 (when (vhdl-standard-p 'ams
)
2587 (define-key vhdl-template-map
"br" 'vhdl-template-break
)
2588 (define-key vhdl-template-map
"cu" 'vhdl-template-case-use
)
2589 (define-key vhdl-template-map
"iu" 'vhdl-template-if-use
)
2590 (define-key vhdl-template-map
"lm" 'vhdl-template-limit
)
2591 (define-key vhdl-template-map
"na" 'vhdl-template-nature
)
2592 (define-key vhdl-template-map
"pa" 'vhdl-template-procedural
)
2593 (define-key vhdl-template-map
"qf" 'vhdl-template-quantity-free
)
2594 (define-key vhdl-template-map
"qb" 'vhdl-template-quantity-branch
)
2595 (define-key vhdl-template-map
"qs" 'vhdl-template-quantity-source
)
2596 (define-key vhdl-template-map
"sn" 'vhdl-template-subnature
)
2597 (define-key vhdl-template-map
"te" 'vhdl-template-terminal
)
2599 (when (vhdl-standard-p 'math
)
2600 (define-key vhdl-template-map
"\C-pc" 'vhdl-template-package-math-complex
)
2601 (define-key vhdl-template-map
"\C-pr" 'vhdl-template-package-math-real
)
2604 ;; initialize template map for VHDL Mode
2605 (vhdl-template-map-init)
2607 (defun vhdl-function-name (prefix string
&optional postfix
)
2608 "Generate a Lisp function name.
2609 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2610 STRING are replaced by `-' and substrings are converted to lower case."
2611 (let ((name prefix
))
2612 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string
)
2614 (concat name
"-" (downcase (substring string
0 (match-end 1)))))
2615 (setq string
(substring string
(match-beginning 2))))
2616 (when postfix
(setq name
(concat name
"-" postfix
)))
2619 (defvar vhdl-model-map nil
2620 "Keymap for VHDL models.")
2622 (defun vhdl-model-map-init ()
2623 "Initialize `vhdl-model-map'."
2624 (setq vhdl-model-map
(make-sparse-keymap))
2625 ;; key bindings for VHDL models
2626 (let ((model-alist vhdl-model-alist
) model
)
2628 (setq model
(car model-alist
))
2629 (define-key vhdl-model-map
(nth 2 model
)
2630 (vhdl-function-name "vhdl-model" (nth 0 model
)))
2631 (setq model-alist
(cdr model-alist
)))))
2633 ;; initialize user model map for VHDL Mode
2634 (vhdl-model-map-init)
2636 (defvar vhdl-mode-map nil
2637 "Keymap for VHDL Mode.")
2639 (defun vhdl-mode-map-init ()
2640 "Initialize `vhdl-mode-map'."
2641 (setq vhdl-mode-map
(make-sparse-keymap))
2642 ;; template key bindings
2643 (define-key vhdl-mode-map
"\C-c\C-t" vhdl-template-map
)
2644 ;; model key bindings
2645 (define-key vhdl-mode-map
"\C-c\C-m" vhdl-model-map
)
2646 ;; standard key bindings
2647 (define-key vhdl-mode-map
"\M-a" 'vhdl-beginning-of-statement
)
2648 (define-key vhdl-mode-map
"\M-e" 'vhdl-end-of-statement
)
2649 (define-key vhdl-mode-map
"\M-\C-f" 'vhdl-forward-sexp
)
2650 (define-key vhdl-mode-map
"\M-\C-b" 'vhdl-backward-sexp
)
2651 (define-key vhdl-mode-map
"\M-\C-u" 'vhdl-backward-up-list
)
2652 (define-key vhdl-mode-map
"\M-\C-a" 'vhdl-backward-same-indent
)
2653 (define-key vhdl-mode-map
"\M-\C-e" 'vhdl-forward-same-indent
)
2654 (unless (featurep 'xemacs
) ; would override `M-backspace' in XEmacs
2655 (define-key vhdl-mode-map
"\M-\C-h" 'vhdl-mark-defun
))
2656 (define-key vhdl-mode-map
"\M-\C-q" 'vhdl-indent-sexp
)
2657 (define-key vhdl-mode-map
"\M-^" 'vhdl-delete-indentation
)
2658 ;; backspace/delete key bindings
2659 (define-key vhdl-mode-map
[backspace] 'backward-delete-char-untabify)
2660 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2661 (define-key vhdl-mode-map [delete] 'delete-char)
2662 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2663 ;; mode specific key bindings
2664 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2665 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2666 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2667 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2668 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2669 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2670 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2671 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2672 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2673 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2674 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2675 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2676 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2677 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2678 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2679 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2680 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2681 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2682 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2683 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2684 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2685 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2686 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2687 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2688 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2689 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2690 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2691 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2692 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2693 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2694 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2695 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2696 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2697 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2698 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2699 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2700 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2701 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2702 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2703 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2704 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2705 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2706 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2707 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2708 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2709 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2710 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2711 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2712 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2713 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2714 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2715 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2716 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2717 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2718 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2719 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2720 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2721 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2722 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2723 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2724 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2725 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2726 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2727 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2728 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2729 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2730 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2731 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2732 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2733 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2734 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2735 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2736 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2737 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2738 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2739 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2740 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2741 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2742 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2743 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2744 ;; insert commands bindings
2745 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2746 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2747 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2748 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2749 ;; electric key bindings
2750 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2751 (when vhdl-intelligent-tab
2752 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2753 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2754 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2755 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2756 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2757 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2758 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2759 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2760 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2761 (when (vhdl-standard-p 'ams)
2762 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2764 ;; initialize mode map for VHDL Mode
2765 (vhdl-mode-map-init)
2767 ;; define special minibuffer keymap for enabling word completion in minibuffer
2768 ;; (useful in template generator prompts)
2769 (defvar vhdl-minibuffer-local-map
2770 (let ((map (make-sparse-keymap)))
2771 (set-keymap-parent map minibuffer-local-map)
2772 (when vhdl-word-completion-in-minibuffer
2773 (define-key map "\t" 'vhdl-minibuffer-tab))
2775 "Keymap for minibuffer used in VHDL Mode.")
2777 ;; set up electric character functions to work with
2778 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2782 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2783 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2784 '(vhdl-electric-space
2786 vhdl-electric-return
2788 vhdl-electric-open-bracket
2789 vhdl-electric-close-bracket
2791 vhdl-electric-semicolon
2793 vhdl-electric-period
2794 vhdl-electric-equal))
2796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2799 (defvar vhdl-mode-syntax-table nil
2800 "Syntax table used in `vhdl-mode' buffers.")
2802 (defvar vhdl-mode-ext-syntax-table nil
2803 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2805 (defun vhdl-mode-syntax-table-init ()
2806 "Initialize `vhdl-mode-syntax-table'."
2807 (setq vhdl-mode-syntax-table (make-syntax-table))
2808 ;; define punctuation
2809 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2810 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2811 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2812 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2813 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2814 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2815 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2816 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2817 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2818 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2819 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2820 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2821 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2822 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2823 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2824 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2826 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2827 ;; define underscore
2828 (when vhdl-underscore-is-part-of-word
2829 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2830 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2831 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2832 ;; and \n and \^M end a comment
2833 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2834 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2835 ;; define parentheses to match
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)
2840 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2841 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2842 ;; extended syntax table including '_' (for simpler search regexps)
2843 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2844 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2846 ;; initialize syntax table for VHDL Mode
2847 (vhdl-mode-syntax-table-init)
2849 (defvar vhdl-syntactic-context nil
2850 "Buffer local variable containing syntactic analysis list.")
2851 (make-variable-buffer-local 'vhdl-syntactic-context)
2853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2854 ;; Abbrev ook bindings
2856 (defvar vhdl-mode-abbrev-table nil
2857 "Abbrev table to use in `vhdl-mode' buffers.")
2859 (defun vhdl-mode-abbrev-table-init ()
2860 "Initialize `vhdl-mode-abbrev-table'."
2861 (define-abbrev-table 'vhdl-mode-abbrev-table
2863 (when (memq 'vhdl vhdl-electric-keywords)
2865 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2867 ("--" . vhdl-template-display-comment-hook)
2868 ("abs" . vhdl-template-default-hook)
2869 ("access" . vhdl-template-default-hook)
2870 ("after" . vhdl-template-default-hook)
2871 ("alias" . vhdl-template-alias-hook)
2872 ("all" . vhdl-template-default-hook)
2873 ("and" . vhdl-template-default-hook)
2874 ("arch" . vhdl-template-architecture-hook)
2875 ("architecture" . vhdl-template-architecture-hook)
2876 ("array" . vhdl-template-default-hook)
2877 ("assert" . vhdl-template-assert-hook)
2878 ("attr" . vhdl-template-attribute-hook)
2879 ("attribute" . vhdl-template-attribute-hook)
2880 ("begin" . vhdl-template-default-indent-hook)
2881 ("block" . vhdl-template-block-hook)
2882 ("body" . vhdl-template-default-hook)
2883 ("buffer" . vhdl-template-default-hook)
2884 ("bus" . vhdl-template-default-hook)
2885 ("case" . vhdl-template-case-hook)
2886 ("comp" . vhdl-template-component-hook)
2887 ("component" . vhdl-template-component-hook)
2888 ("cond" . vhdl-template-conditional-signal-asst-hook)
2889 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2890 ("conf" . vhdl-template-configuration-hook)
2891 ("configuration" . vhdl-template-configuration-hook)
2892 ("cons" . vhdl-template-constant-hook)
2893 ("constant" . vhdl-template-constant-hook)
2894 ("disconnect" . vhdl-template-disconnect-hook)
2895 ("downto" . vhdl-template-default-hook)
2896 ("else" . vhdl-template-else-hook)
2897 ("elseif" . vhdl-template-elsif-hook)
2898 ("elsif" . vhdl-template-elsif-hook)
2899 ("end" . vhdl-template-default-indent-hook)
2900 ("entity" . vhdl-template-entity-hook)
2901 ("exit" . vhdl-template-exit-hook)
2902 ("file" . vhdl-template-file-hook)
2903 ("for" . vhdl-template-for-hook)
2904 ("func" . vhdl-template-function-hook)
2905 ("function" . vhdl-template-function-hook)
2906 ("generic" . vhdl-template-generic-hook)
2907 ("group" . vhdl-template-group-hook)
2908 ("guarded" . vhdl-template-default-hook)
2909 ("if" . vhdl-template-if-hook)
2910 ("impure" . vhdl-template-default-hook)
2911 ("in" . vhdl-template-default-hook)
2912 ("inertial" . vhdl-template-default-hook)
2913 ("inout" . vhdl-template-default-hook)
2914 ("inst" . vhdl-template-instance-hook)
2915 ("instance" . vhdl-template-instance-hook)
2916 ("is" . vhdl-template-default-hook)
2917 ("label" . vhdl-template-default-hook)
2918 ("library" . vhdl-template-library-hook)
2919 ("linkage" . vhdl-template-default-hook)
2920 ("literal" . vhdl-template-default-hook)
2921 ("loop" . vhdl-template-bare-loop-hook)
2922 ("map" . vhdl-template-map-hook)
2923 ("mod" . vhdl-template-default-hook)
2924 ("nand" . vhdl-template-default-hook)
2925 ("new" . vhdl-template-default-hook)
2926 ("next" . vhdl-template-next-hook)
2927 ("nor" . vhdl-template-default-hook)
2928 ("not" . vhdl-template-default-hook)
2929 ("null" . vhdl-template-default-hook)
2930 ("of" . vhdl-template-default-hook)
2931 ("on" . vhdl-template-default-hook)
2932 ("open" . vhdl-template-default-hook)
2933 ("or" . vhdl-template-default-hook)
2934 ("others" . vhdl-template-others-hook)
2935 ("out" . vhdl-template-default-hook)
2936 ("pack" . vhdl-template-package-hook)
2937 ("package" . vhdl-template-package-hook)
2938 ("port" . vhdl-template-port-hook)
2939 ("postponed" . vhdl-template-default-hook)
2940 ("procedure" . vhdl-template-procedure-hook)
2941 ("process" . vhdl-template-process-hook)
2942 ("pure" . vhdl-template-default-hook)
2943 ("range" . vhdl-template-default-hook)
2944 ("record" . vhdl-template-default-hook)
2945 ("register" . vhdl-template-default-hook)
2946 ("reject" . vhdl-template-default-hook)
2947 ("rem" . vhdl-template-default-hook)
2948 ("report" . vhdl-template-report-hook)
2949 ("return" . vhdl-template-return-hook)
2950 ("rol" . vhdl-template-default-hook)
2951 ("ror" . vhdl-template-default-hook)
2952 ("select" . vhdl-template-selected-signal-asst-hook)
2953 ("severity" . vhdl-template-default-hook)
2954 ("shared" . vhdl-template-default-hook)
2955 ("sig" . vhdl-template-signal-hook)
2956 ("signal" . vhdl-template-signal-hook)
2957 ("sla" . vhdl-template-default-hook)
2958 ("sll" . vhdl-template-default-hook)
2959 ("sra" . vhdl-template-default-hook)
2960 ("srl" . vhdl-template-default-hook)
2961 ("subtype" . vhdl-template-subtype-hook)
2962 ("then" . vhdl-template-default-hook)
2963 ("to" . vhdl-template-default-hook)
2964 ("transport" . vhdl-template-default-hook)
2965 ("type" . vhdl-template-type-hook)
2966 ("unaffected" . vhdl-template-default-hook)
2967 ("units" . vhdl-template-default-hook)
2968 ("until" . vhdl-template-default-hook)
2969 ("use" . vhdl-template-use-hook)
2970 ("var" . vhdl-template-variable-hook)
2971 ("variable" . vhdl-template-variable-hook)
2972 ("wait" . vhdl-template-wait-hook)
2973 ("when" . vhdl-template-when-hook)
2974 ("while" . vhdl-template-while-loop-hook)
2975 ("with" . vhdl-template-with-hook)
2976 ("xnor" . vhdl-template-default-hook)
2977 ("xor" . vhdl-template-default-hook)
2979 ;; VHDL-AMS keywords
2980 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2981 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2983 ("across" . vhdl-template-default-hook)
2984 ("break" . vhdl-template-break-hook)
2985 ("limit" . vhdl-template-limit-hook)
2986 ("nature" . vhdl-template-nature-hook)
2987 ("noise" . vhdl-template-default-hook)
2988 ("procedural" . vhdl-template-procedural-hook)
2989 ("quantity" . vhdl-template-quantity-hook)
2990 ("reference" . vhdl-template-default-hook)
2991 ("spectrum" . vhdl-template-default-hook)
2992 ("subnature" . vhdl-template-subnature-hook)
2993 ("terminal" . vhdl-template-terminal-hook)
2994 ("through" . vhdl-template-default-hook)
2995 ("tolerance" . vhdl-template-default-hook)
2997 ;; user model keywords
2998 (when (memq 'user vhdl-electric-keywords)
2999 (let (abbrev-list keyword)
3000 (dolist (elem vhdl-model-alist)
3001 (setq keyword (nth 3 elem))
3002 (unless (equal keyword "")
3003 (push (list keyword ""
3005 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3009 ;; initialize abbrev table for VHDL Mode
3010 (vhdl-mode-abbrev-table-init)
3012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3013 ;; Template completion lists
3015 (defvar vhdl-template-construct-alist nil
3016 "List of built-in construct templates.")
3018 (defun vhdl-template-construct-alist-init ()
3019 "Initialize `vhdl-template-construct-alist'."
3021 vhdl-template-construct-alist
3024 ("alias declaration" vhdl-template-alias)
3025 ("architecture body" vhdl-template-architecture)
3026 ("assertion" vhdl-template-assert)
3027 ("attribute declaration" vhdl-template-attribute-decl)
3028 ("attribute specification" vhdl-template-attribute-spec)
3029 ("block configuration" vhdl-template-block-configuration)
3030 ("block statement" vhdl-template-block)
3031 ("case statement" vhdl-template-case-is)
3032 ("component configuration" vhdl-template-component-conf)
3033 ("component declaration" vhdl-template-component-decl)
3034 ("component instantiation statement" vhdl-template-component-inst)
3035 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3036 ("configuration declaration" vhdl-template-configuration-decl)
3037 ("configuration specification" vhdl-template-configuration-spec)
3038 ("constant declaration" vhdl-template-constant)
3039 ("disconnection specification" vhdl-template-disconnect)
3040 ("entity declaration" vhdl-template-entity)
3041 ("exit statement" vhdl-template-exit)
3042 ("file declaration" vhdl-template-file)
3043 ("generate statement" vhdl-template-generate)
3044 ("generic clause" vhdl-template-generic)
3045 ("group declaration" vhdl-template-group-decl)
3046 ("group template declaration" vhdl-template-group-template)
3047 ("if statement" vhdl-template-if-then)
3048 ("library clause" vhdl-template-library)
3049 ("loop statement" vhdl-template-loop)
3050 ("next statement" vhdl-template-next)
3051 ("package declaration" vhdl-template-package-decl)
3052 ("package body" vhdl-template-package-body)
3053 ("port clause" vhdl-template-port)
3054 ("process statement" vhdl-template-process)
3055 ("report statement" vhdl-template-report)
3056 ("return statement" vhdl-template-return)
3057 ("selected signal assignment" vhdl-template-selected-signal-asst)
3058 ("signal declaration" vhdl-template-signal)
3059 ("subprogram declaration" vhdl-template-subprogram-decl)
3060 ("subprogram body" vhdl-template-subprogram-body)
3061 ("subtype declaration" vhdl-template-subtype)
3062 ("type declaration" vhdl-template-type)
3063 ("use clause" vhdl-template-use)
3064 ("variable declaration" vhdl-template-variable)
3065 ("wait statement" vhdl-template-wait)
3067 (when (vhdl-standard-p 'ams)
3069 ("break statement" vhdl-template-break)
3070 ("nature declaration" vhdl-template-nature)
3071 ("quantity declaration" vhdl-template-quantity)
3072 ("simultaneous case statement" vhdl-template-case-use)
3073 ("simultaneous if statement" vhdl-template-if-use)
3074 ("simultaneous procedural statement" vhdl-template-procedural)
3075 ("step limit specification" vhdl-template-limit)
3076 ("subnature declaration" vhdl-template-subnature)
3077 ("terminal declaration" vhdl-template-terminal)
3080 ;; initialize for VHDL Mode
3081 (vhdl-template-construct-alist-init)
3083 (defvar vhdl-template-package-alist nil
3084 "List of built-in package templates.")
3086 (defun vhdl-template-package-alist-init ()
3087 "Initialize `vhdl-template-package-alist'."
3089 vhdl-template-package-alist
3092 ("numeric_bit" vhdl-template-package-numeric-bit)
3093 ("numeric_std" vhdl-template-package-numeric-std)
3094 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3095 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3096 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3097 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3098 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3099 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3100 ("textio" vhdl-template-package-textio)
3102 (when (vhdl-standard-p 'math)
3104 ("math_complex" vhdl-template-package-math-complex)
3105 ("math_real" vhdl-template-package-math-real)
3108 ;; initialize for VHDL Mode
3109 (vhdl-template-package-alist-init)
3111 (defvar vhdl-template-directive-alist
3113 ("translate_on" vhdl-template-directive-translate-on)
3114 ("translate_off" vhdl-template-directive-translate-off)
3115 ("synthesis_on" vhdl-template-directive-synthesis-on)
3116 ("synthesis_off" vhdl-template-directive-synthesis-off)
3118 "List of built-in directive templates.")
3121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3126 ;; VHDL menu (using `easy-menu.el')
3128 (defun vhdl-customize ()
3129 "Call the customize function with `vhdl' as argument."
3131 (customize-browse 'vhdl))
3133 (defun vhdl-create-mode-menu ()
3134 "Create VHDL Mode menu."
3138 ["None" (vhdl-set-project "")
3139 :style radio :selected (null vhdl-project)]
3141 ;; add menu entries for defined projects
3142 (let ((project-alist vhdl-project-alist) menu-list name)
3143 (while project-alist
3144 (setq name (caar project-alist))
3146 (cons `[,name (vhdl-set-project ,name)
3147 :style radio :selected (equal ,name vhdl-project)]
3149 (setq project-alist (cdr project-alist)))
3151 (if vhdl-project-sort
3153 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3154 (nreverse menu-list)))
3155 (vhdl-menu-split menu-list "Project"))
3157 ["Select Project..." vhdl-set-project t]
3158 ["Set As Default Project" vhdl-set-default-project t]
3160 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3161 ["Import Project..." vhdl-import-project
3162 :keys "C-c C-p C-m" :active t]
3163 ["Export Project" vhdl-export-project vhdl-project]
3165 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3168 ["Compile Buffer" vhdl-compile t]
3169 ["Stop Compilation" kill-compilation t]
3171 ["Make" vhdl-make t]
3172 ["Generate Makefile" vhdl-generate-makefile t]
3174 ["Next Error" next-error t]
3175 ["Previous Error" previous-error t]
3176 ["First Error" first-error t]
3180 ;; add menu entries for defined compilers
3181 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3183 (setq name (caar comp-alist))
3185 (cons `[,name (setq vhdl-compiler ,name)
3186 :style radio :selected (equal ,name vhdl-compiler)]
3188 (setq comp-alist (cdr comp-alist)))
3189 (setq menu-list (nreverse menu-list))
3190 (vhdl-menu-split menu-list "Compiler"))
3192 ["Select Compiler..." vhdl-set-compiler t]
3194 ["Customize Compiler..."
3195 (customize-option 'vhdl-compiler-alist) t])))
3200 ["Alias" vhdl-template-alias t]
3201 ["Architecture" vhdl-template-architecture t]
3202 ["Assert" vhdl-template-assert t]
3203 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3204 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3205 ["Block" vhdl-template-block t]
3206 ["Case" vhdl-template-case-is t]
3207 ["Component (Decl)" vhdl-template-component-decl t]
3208 ["(Component) Instance" vhdl-template-component-inst t]
3209 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3210 ["Configuration (Block)" vhdl-template-block-configuration t]
3211 ["Configuration (Comp)" vhdl-template-component-conf t]
3212 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3213 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3214 ["Constant" vhdl-template-constant t]
3215 ["Disconnect" vhdl-template-disconnect t]
3216 ["Else" vhdl-template-else t]
3217 ["Elsif" vhdl-template-elsif t]
3218 ["Entity" vhdl-template-entity t]
3219 ["Exit" vhdl-template-exit t]
3220 ["File" vhdl-template-file t]
3221 ["For (Generate)" vhdl-template-for-generate t]
3222 ["For (Loop)" vhdl-template-for-loop t]
3223 ["Function (Body)" vhdl-template-function-body t]
3224 ["Function (Decl)" vhdl-template-function-decl t]
3225 ["Generic" vhdl-template-generic t]
3226 ["Group (Decl)" vhdl-template-group-decl t]
3227 ["Group (Template)" vhdl-template-group-template t])
3229 ["If (Generate)" vhdl-template-if-generate t]
3230 ["If (Then)" vhdl-template-if-then t]
3231 ["Library" vhdl-template-library t]
3232 ["Loop" vhdl-template-bare-loop t]
3233 ["Map" vhdl-template-map t]
3234 ["Next" vhdl-template-next t]
3235 ["Others (Aggregate)" vhdl-template-others t]
3236 ["Package (Decl)" vhdl-template-package-decl t]
3237 ["Package (Body)" vhdl-template-package-body t]
3238 ["Port" vhdl-template-port t]
3239 ["Procedure (Body)" vhdl-template-procedure-body t]
3240 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3241 ["Process (Comb)" vhdl-template-process-comb t]
3242 ["Process (Seq)" vhdl-template-process-seq t]
3243 ["Report" vhdl-template-report t]
3244 ["Return" vhdl-template-return t]
3245 ["Select" vhdl-template-selected-signal-asst t]
3246 ["Signal" vhdl-template-signal t]
3247 ["Subtype" vhdl-template-subtype t]
3248 ["Type" vhdl-template-type t]
3249 ["Use" vhdl-template-use t]
3250 ["Variable" vhdl-template-variable t]
3251 ["Wait" vhdl-template-wait t]
3252 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3253 ["When" vhdl-template-when t]
3254 ["While (Loop)" vhdl-template-while-loop t]
3255 ["With" vhdl-template-with t]))
3256 (when (vhdl-standard-p 'ams)
3257 '(("VHDL-AMS Construct"
3258 ["Break" vhdl-template-break t]
3259 ["Case (Use)" vhdl-template-case-use t]
3260 ["If (Use)" vhdl-template-if-use t]
3261 ["Limit" vhdl-template-limit t]
3262 ["Nature" vhdl-template-nature t]
3263 ["Procedural" vhdl-template-procedural t]
3264 ["Quantity (Free)" vhdl-template-quantity-free t]
3265 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3266 ["Quantity (Source)" vhdl-template-quantity-source t]
3267 ["Subnature" vhdl-template-subnature t]
3268 ["Terminal" vhdl-template-terminal t])))
3269 '(["Insert Construct..." vhdl-template-insert-construct
3270 :keys "C-c C-i C-t"]
3275 (when (vhdl-standard-p 'math)
3276 '(["math_complex" vhdl-template-package-math-complex t]
3277 ["math_real" vhdl-template-package-math-real t]))
3278 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3279 ["numeric_std" vhdl-template-package-numeric-std t]
3280 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3281 ["textio" vhdl-template-package-textio t]
3283 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3284 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3285 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3286 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3287 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3289 ["Insert Package..." vhdl-template-insert-package
3290 :keys "C-c C-i C-p"])))
3292 ["translate_on" vhdl-template-directive-translate-on t]
3293 ["translate_off" vhdl-template-directive-translate-off t]
3294 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3295 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3297 ["Insert Directive..." vhdl-template-insert-directive
3298 :keys "C-c C-i C-d"])
3300 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3301 ["Insert Footer" vhdl-template-footer t]
3302 ["Insert Date" vhdl-template-insert-date t]
3303 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3305 ["Query Next Prompt" vhdl-template-search-prompt t]))
3308 ;; add menu entries for defined models
3309 (let ((model-alist vhdl-model-alist) menu-list model)
3311 (setq model (car model-alist))
3316 (vhdl-function-name "vhdl-model" (nth 0 model))
3317 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3319 (setq model-alist (cdr model-alist)))
3320 (setq menu-list (nreverse menu-list))
3321 (vhdl-menu-split menu-list "Model"))
3323 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3324 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3326 ["Copy" vhdl-port-copy t]
3328 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3329 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3330 ["Paste As Instance" vhdl-port-paste-instance
3331 :keys "C-c C-p C-i" :active vhdl-port-list]
3332 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3333 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3334 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3335 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3337 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3339 ["Flatten" vhdl-port-flatten
3340 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3341 ["Reverse Direction" vhdl-port-reverse-direction
3342 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3344 ["New Component" vhdl-compose-new-component t]
3345 ["Copy Component" vhdl-port-copy t]
3346 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3347 ["Wire Components" vhdl-compose-wire-components t]
3349 ["Generate Configuration" vhdl-compose-configuration t]
3350 ["Generate Components Package" vhdl-compose-components-package t])
3352 ["Copy" vhdl-subprog-copy t]
3354 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3355 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3356 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3358 ["Flatten" vhdl-subprog-flatten
3359 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3362 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3364 ["Insert Inline Comment" vhdl-comment-append-inline t]
3365 ["Insert Horizontal Line" vhdl-comment-display-line t]
3366 ["Insert Display Comment" vhdl-comment-display t]
3368 ["Fill Comment" fill-paragraph t]
3369 ["Fill Comment Region" fill-region (mark)]
3370 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3371 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3373 ["Kill" vhdl-line-kill t]
3374 ["Copy" vhdl-line-copy t]
3375 ["Yank" vhdl-line-yank t]
3376 ["Expand" vhdl-line-expand t]
3378 ["Transpose Next" vhdl-line-transpose-next t]
3379 ["Transpose Prev" vhdl-line-transpose-previous t]
3380 ["Open" vhdl-line-open t]
3381 ["Join" vhdl-delete-indentation t]
3383 ["Goto" goto-line t]
3384 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3386 ["Forward Statement" vhdl-end-of-statement t]
3387 ["Backward Statement" vhdl-beginning-of-statement t]
3388 ["Forward Expression" vhdl-forward-sexp t]
3389 ["Backward Expression" vhdl-backward-sexp t]
3390 ["Forward Same Indent" vhdl-forward-same-indent t]
3391 ["Backward Same Indent" vhdl-backward-same-indent t]
3392 ["Forward Function" vhdl-end-of-defun t]
3393 ["Backward Function" vhdl-beginning-of-defun t]
3394 ["Mark Function" vhdl-mark-defun t])
3397 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3398 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3399 ["Region" vhdl-indent-region (mark)]
3400 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3402 ["Group" vhdl-align-group t]
3403 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3404 ["List" vhdl-align-list t]
3405 ["Declarations" vhdl-align-declarations t]
3406 ["Region" vhdl-align-region (mark)]
3407 ["Buffer" vhdl-align-buffer t]
3409 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3410 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3411 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3413 ["List" vhdl-fill-list t]
3414 ["Group" vhdl-fill-group t]
3415 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3416 ["Region" vhdl-fill-region (mark)])
3418 ["Region" vhdl-beautify-region (mark)]
3419 ["Buffer" vhdl-beautify-buffer t])
3421 ["Generic/Port Clause" vhdl-fix-clause t]
3423 ["Case Region" vhdl-fix-case-region (mark)]
3424 ["Case Buffer" vhdl-fix-case-buffer t]
3426 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3427 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3429 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3431 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3432 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3434 ["Fontify Buffer" vhdl-fontify-buffer t]
3435 ["Statistics Buffer" vhdl-statistics-buffer t]
3436 ["Show Messages" vhdl-show-messages t]
3437 ["Syntactic Info" vhdl-show-syntactic-information t]
3439 ["Speedbar" vhdl-speedbar t]
3440 ["Hide/Show" vhdl-hs-minor-mode t]
3443 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3444 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3445 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3446 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3447 ["Version" vhdl-version t]
3448 ["Bug Report..." vhdl-submit-bug-report t]
3453 (progn (customize-set-variable 'vhdl-electric-mode
3454 (not vhdl-electric-mode)))
3455 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3457 (progn (customize-set-variable 'vhdl-stutter-mode
3458 (not vhdl-stutter-mode)))
3459 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3461 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3462 (not vhdl-indent-tabs-mode))
3463 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3464 :style toggle :selected vhdl-indent-tabs-mode]
3466 ["Customize Group..." (customize-group 'vhdl-mode) t])
3468 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3470 '("Selected Project at Startup"
3471 ["None" (progn (customize-set-variable 'vhdl-project nil)
3472 (vhdl-set-project ""))
3473 :style radio :selected (null vhdl-project)]
3475 ;; add menu entries for defined projects
3476 (let ((project-alist vhdl-project-alist) menu-list name)
3477 (while project-alist
3478 (setq name (caar project-alist))
3480 (cons `[,name (progn (customize-set-variable
3481 'vhdl-project ,name)
3482 (vhdl-set-project ,name))
3483 :style radio :selected (equal ,name vhdl-project)]
3485 (setq project-alist (cdr project-alist)))
3486 (setq menu-list (nreverse menu-list))
3487 (vhdl-menu-split menu-list "Project")))
3488 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3489 ("Auto Load Setup File"
3491 (customize-set-variable 'vhdl-project-auto-load
3492 (if (memq 'startup vhdl-project-auto-load)
3493 (delq 'startup vhdl-project-auto-load)
3494 (cons 'startup vhdl-project-auto-load)))
3495 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3497 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3498 :style toggle :selected vhdl-project-sort]
3500 ["Customize Group..." (customize-group 'vhdl-project) t])
3502 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3504 '("Selected Compiler at Startup")
3505 ;; add menu entries for defined compilers
3506 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3508 (setq name (caar comp-alist))
3510 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3511 :style radio :selected (equal ,name vhdl-compiler)]
3513 (setq comp-alist (cdr comp-alist)))
3514 (setq menu-list (nreverse menu-list))
3515 (vhdl-menu-split menu-list "Compler")))
3516 ["Use Local Error Regexp"
3517 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3518 (not vhdl-compile-use-local-error-regexp))
3519 :style toggle :selected vhdl-compile-use-local-error-regexp]
3520 ["Makefile Generation Hook..."
3521 (customize-option 'vhdl-makefile-generation-hook) t]
3522 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3524 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3528 (progn (customize-set-variable 'vhdl-standard
3529 (list '87 (cadr vhdl-standard)))
3530 (vhdl-activate-customizations))
3531 :style radio :selected (eq '87 (car vhdl-standard))]
3533 (progn (customize-set-variable 'vhdl-standard
3534 (list '93 (cadr vhdl-standard)))
3535 (vhdl-activate-customizations))
3536 :style radio :selected (eq '93 (car vhdl-standard))]
3539 (progn (customize-set-variable
3540 'vhdl-standard (list (car vhdl-standard)
3541 (if (memq 'ams (cadr vhdl-standard))
3542 (delq 'ams (cadr vhdl-standard))
3543 (cons 'ams (cadr vhdl-standard)))))
3544 (vhdl-activate-customizations))
3545 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3547 (progn (customize-set-variable
3548 'vhdl-standard (list (car vhdl-standard)
3549 (if (memq 'math (cadr vhdl-standard))
3550 (delq 'math (cadr vhdl-standard))
3551 (cons 'math (cadr vhdl-standard)))))
3552 (vhdl-activate-customizations))
3553 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3554 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3555 ["Upper Case Keywords"
3556 (customize-set-variable 'vhdl-upper-case-keywords
3557 (not vhdl-upper-case-keywords))
3558 :style toggle :selected vhdl-upper-case-keywords]
3560 (customize-set-variable 'vhdl-upper-case-types
3561 (not vhdl-upper-case-types))
3562 :style toggle :selected vhdl-upper-case-types]
3563 ["Upper Case Attributes"
3564 (customize-set-variable 'vhdl-upper-case-attributes
3565 (not vhdl-upper-case-attributes))
3566 :style toggle :selected vhdl-upper-case-attributes]
3567 ["Upper Case Enumeration Values"
3568 (customize-set-variable 'vhdl-upper-case-enum-values
3569 (not vhdl-upper-case-enum-values))
3570 :style toggle :selected vhdl-upper-case-enum-values]
3571 ["Upper Case Constants"
3572 (customize-set-variable 'vhdl-upper-case-constants
3573 (not vhdl-upper-case-constants))
3574 :style toggle :selected vhdl-upper-case-constants]
3575 ("Use Direct Instantiation"
3577 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3578 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3580 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3581 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3583 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3584 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3586 ["Customize Group..." (customize-group 'vhdl-style) t])
3588 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3589 ["Architecture File Name..."
3590 (customize-option 'vhdl-architecture-file-name) t]
3591 ["Configuration File Name..."
3592 (customize-option 'vhdl-configuration-file-name) t]
3593 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3596 (customize-set-variable 'vhdl-file-name-case 'identity)
3597 :style radio :selected (eq 'identity vhdl-file-name-case)]
3599 (customize-set-variable 'vhdl-file-name-case 'downcase)
3600 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3602 (customize-set-variable 'vhdl-file-name-case 'upcase)
3603 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3605 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3606 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3608 ["Customize Group..." (customize-group 'vhdl-naming) t])
3610 ("Electric Keywords"
3612 (customize-set-variable 'vhdl-electric-keywords
3613 (if (memq 'vhdl vhdl-electric-keywords)
3614 (delq 'vhdl vhdl-electric-keywords)
3615 (cons 'vhdl vhdl-electric-keywords)))
3616 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3617 ["User Model Keywords"
3618 (customize-set-variable 'vhdl-electric-keywords
3619 (if (memq 'user vhdl-electric-keywords)
3620 (delq 'user vhdl-electric-keywords)
3621 (cons 'user vhdl-electric-keywords)))
3622 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3623 ("Insert Optional Labels"
3625 (customize-set-variable 'vhdl-optional-labels 'none)
3626 :style radio :selected (eq 'none vhdl-optional-labels)]
3628 (customize-set-variable 'vhdl-optional-labels 'process)
3629 :style radio :selected (eq 'process vhdl-optional-labels)]
3631 (customize-set-variable 'vhdl-optional-labels 'all)
3632 :style radio :selected (eq 'all vhdl-optional-labels)])
3633 ("Insert Empty Lines"
3635 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3636 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3637 ["Design Units Only"
3638 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3639 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3641 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3642 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3643 ["Argument List Indent"
3644 (customize-set-variable 'vhdl-argument-list-indent
3645 (not vhdl-argument-list-indent))
3646 :style toggle :selected vhdl-argument-list-indent]
3647 ["Association List with Formals"
3648 (customize-set-variable 'vhdl-association-list-with-formals
3649 (not vhdl-association-list-with-formals))
3650 :style toggle :selected vhdl-association-list-with-formals]
3651 ["Conditions in Parenthesis"
3652 (customize-set-variable 'vhdl-conditions-in-parenthesis
3653 (not vhdl-conditions-in-parenthesis))
3654 :style toggle :selected vhdl-conditions-in-parenthesis]
3655 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3656 ["One String..." (customize-option 'vhdl-one-string) t]
3658 ["Header String..." (customize-option 'vhdl-file-header) t]
3659 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3660 ["Company Name..." (customize-option 'vhdl-company-name) t]
3661 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3662 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3663 ["Date Format..." (customize-option 'vhdl-date-format) t]
3664 ["Modify Date Prefix String..."
3665 (customize-option 'vhdl-modify-date-prefix-string) t]
3666 ["Modify Date on Saving"
3667 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3668 (not vhdl-modify-date-on-saving))
3669 (vhdl-activate-customizations))
3670 :style toggle :selected vhdl-modify-date-on-saving])
3671 ("Sequential Process"
3674 (customize-set-variable 'vhdl-reset-kind 'none)
3675 :style radio :selected (eq 'none vhdl-reset-kind)]
3677 (customize-set-variable 'vhdl-reset-kind 'sync)
3678 :style radio :selected (eq 'sync vhdl-reset-kind)]
3680 (customize-set-variable 'vhdl-reset-kind 'async)
3681 :style radio :selected (eq 'async vhdl-reset-kind)])
3682 ["Reset is Active High"
3683 (customize-set-variable 'vhdl-reset-active-high
3684 (not vhdl-reset-active-high))
3685 :style toggle :selected vhdl-reset-active-high]
3686 ["Use Rising Clock Edge"
3687 (customize-set-variable 'vhdl-clock-rising-edge
3688 (not vhdl-clock-rising-edge))
3689 :style toggle :selected vhdl-clock-rising-edge]
3690 ("Clock Edge Condition"
3692 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3693 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3694 ["Function \"rising_edge\""
3695 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3696 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3697 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3698 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3700 ["Customize Group..." (customize-group 'vhdl-template) t])
3702 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3704 ["Include Port Comments"
3705 (customize-set-variable 'vhdl-include-port-comments
3706 (not vhdl-include-port-comments))
3707 :style toggle :selected vhdl-include-port-comments]
3708 ["Include Direction Comments"
3709 (customize-set-variable 'vhdl-include-direction-comments
3710 (not vhdl-include-direction-comments))
3711 :style toggle :selected vhdl-include-direction-comments]
3712 ["Include Type Comments"
3713 (customize-set-variable 'vhdl-include-type-comments
3714 (not vhdl-include-type-comments))
3715 :style toggle :selected vhdl-include-type-comments]
3716 ("Include Group Comments"
3718 (customize-set-variable 'vhdl-include-group-comments 'never)
3719 :style radio :selected (eq 'never vhdl-include-group-comments)]
3721 (customize-set-variable 'vhdl-include-group-comments 'decl)
3722 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3724 (customize-set-variable 'vhdl-include-group-comments 'always)
3725 :style radio :selected (eq 'always vhdl-include-group-comments)])
3726 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3727 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3729 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3730 ["Architecture Name..."
3731 (customize-option 'vhdl-testbench-architecture-name) t]
3732 ["Configuration Name..."
3733 (customize-option 'vhdl-testbench-configuration-name) t]
3734 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3736 (customize-set-variable 'vhdl-testbench-include-header
3737 (not vhdl-testbench-include-header))
3738 :style toggle :selected vhdl-testbench-include-header]
3739 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3740 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3741 ["Initialize Signals"
3742 (customize-set-variable 'vhdl-testbench-initialize-signals
3743 (not vhdl-testbench-initialize-signals))
3744 :style toggle :selected vhdl-testbench-initialize-signals]
3745 ["Include Library Clause"
3746 (customize-set-variable 'vhdl-testbench-include-library
3747 (not vhdl-testbench-include-library))
3748 :style toggle :selected vhdl-testbench-include-library]
3749 ["Include Configuration"
3750 (customize-set-variable 'vhdl-testbench-include-configuration
3751 (not vhdl-testbench-include-configuration))
3752 :style toggle :selected vhdl-testbench-include-configuration]
3755 (customize-set-variable 'vhdl-testbench-create-files 'none)
3756 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3758 (customize-set-variable 'vhdl-testbench-create-files 'single)
3759 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3761 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3762 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3763 ["Testbench Entity File Name..."
3764 (customize-option 'vhdl-testbench-entity-file-name) t]
3765 ["Testbench Architecture File Name..."
3766 (customize-option 'vhdl-testbench-architecture-file-name) t])
3768 ["Customize Group..." (customize-group 'vhdl-port) t])
3770 ["Architecture Name..."
3771 (customize-option 'vhdl-compose-architecture-name) t]
3772 ["Configuration Name..."
3773 (customize-option 'vhdl-compose-configuration-name) t]
3774 ["Components Package Name..."
3775 (customize-option 'vhdl-components-package-name) t]
3776 ["Use Components Package"
3777 (customize-set-variable 'vhdl-use-components-package
3778 (not vhdl-use-components-package))
3779 :style toggle :selected vhdl-use-components-package]
3781 (customize-set-variable 'vhdl-compose-include-header
3782 (not vhdl-compose-include-header))
3783 :style toggle :selected vhdl-compose-include-header]
3784 ("Create Entity/Architecture Files"
3786 (customize-set-variable 'vhdl-compose-create-files 'none)
3787 :style radio :selected (eq 'none vhdl-compose-create-files)]
3789 (customize-set-variable 'vhdl-compose-create-files 'single)
3790 :style radio :selected (eq 'single vhdl-compose-create-files)]
3792 (customize-set-variable 'vhdl-compose-create-files 'separate)
3793 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3794 ["Create Configuration File"
3795 (customize-set-variable 'vhdl-compose-configuration-create-file
3796 (not vhdl-compose-configuration-create-file))
3797 :style toggle :selected vhdl-compose-configuration-create-file]
3798 ["Hierarchical Configuration"
3799 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3800 (not vhdl-compose-configuration-hierarchical))
3801 :style toggle :selected vhdl-compose-configuration-hierarchical]
3802 ["Use Subconfiguration"
3803 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3804 (not vhdl-compose-configuration-use-subconfiguration))
3805 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3807 ["Customize Group..." (customize-group 'vhdl-compose) t])
3809 ["Self Insert Comments"
3810 (customize-set-variable 'vhdl-self-insert-comments
3811 (not vhdl-self-insert-comments))
3812 :style toggle :selected vhdl-self-insert-comments]
3813 ["Prompt for Comments"
3814 (customize-set-variable 'vhdl-prompt-for-comments
3815 (not vhdl-prompt-for-comments))
3816 :style toggle :selected vhdl-prompt-for-comments]
3817 ["Inline Comment Column..."
3818 (customize-option 'vhdl-inline-comment-column) t]
3819 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3821 ["Customize Group..." (customize-group 'vhdl-comment) t])
3823 ["Auto Align Templates"
3824 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3825 :style toggle :selected vhdl-auto-align]
3826 ["Align Line Groups"
3827 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3828 :style toggle :selected vhdl-align-groups]
3829 ["Group Separation String..."
3830 (customize-set-variable 'vhdl-align-group-separate) t]
3831 ["Align Lines with Same Indent"
3832 (customize-set-variable 'vhdl-align-same-indent
3833 (not vhdl-align-same-indent))
3834 :style toggle :selected vhdl-align-same-indent]
3836 ["Customize Group..." (customize-group 'vhdl-align) t])
3838 ["Highlighting On/Off..."
3840 (if (fboundp 'global-font-lock-mode)
3841 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3842 ["Highlight Keywords"
3843 (progn (customize-set-variable 'vhdl-highlight-keywords
3844 (not vhdl-highlight-keywords))
3845 (vhdl-fontify-buffer))
3846 :style toggle :selected vhdl-highlight-keywords]
3848 (progn (customize-set-variable 'vhdl-highlight-names
3849 (not vhdl-highlight-names))
3850 (vhdl-fontify-buffer))
3851 :style toggle :selected vhdl-highlight-names]
3852 ["Highlight Special Words"
3853 (progn (customize-set-variable 'vhdl-highlight-special-words
3854 (not vhdl-highlight-special-words))
3855 (vhdl-fontify-buffer))
3856 :style toggle :selected vhdl-highlight-special-words]
3857 ["Highlight Forbidden Words"
3858 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3859 (not vhdl-highlight-forbidden-words))
3860 (vhdl-fontify-buffer))
3861 :style toggle :selected vhdl-highlight-forbidden-words]
3862 ["Highlight Verilog Keywords"
3863 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3864 (not vhdl-highlight-verilog-keywords))
3865 (vhdl-fontify-buffer))
3866 :style toggle :selected vhdl-highlight-verilog-keywords]
3867 ["Highlight \"translate_off\""
3868 (progn (customize-set-variable 'vhdl-highlight-translate-off
3869 (not vhdl-highlight-translate-off))
3870 (vhdl-fontify-buffer))
3871 :style toggle :selected vhdl-highlight-translate-off]
3872 ["Case Sensitive Highlighting"
3873 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3874 (not vhdl-highlight-case-sensitive))
3875 (vhdl-fontify-buffer))
3876 :style toggle :selected vhdl-highlight-case-sensitive]
3877 ["Special Syntax Definition..."
3878 (customize-option 'vhdl-special-syntax-alist) t]
3879 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3880 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3881 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3882 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3884 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3886 ["Auto Open at Startup"
3887 (customize-set-variable 'vhdl-speedbar-auto-open
3888 (not vhdl-speedbar-auto-open))
3889 :style toggle :selected vhdl-speedbar-auto-open]
3890 ("Default Displaying Mode"
3892 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3893 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3894 ["Directory Hierarchy"
3895 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3896 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3897 ["Project Hierarchy"
3898 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3899 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3900 ["Indentation Offset..."
3901 (customize-option 'speedbar-indentation-width) t]
3902 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3903 ["Jump to Unit when Opening"
3904 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3905 (not vhdl-speedbar-jump-to-unit))
3906 :style toggle :selected vhdl-speedbar-jump-to-unit]
3907 ["Update Hierarchy on File Saving"
3908 (customize-set-variable 'vhdl-speedbar-update-on-saving
3909 (not vhdl-speedbar-update-on-saving))
3910 :style toggle :selected vhdl-speedbar-update-on-saving]
3911 ("Save in Cache File"
3912 ["Hierarchy Information"
3913 (customize-set-variable 'vhdl-speedbar-save-cache
3914 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3915 (delq 'hierarchy vhdl-speedbar-save-cache)
3916 (cons 'hierarchy vhdl-speedbar-save-cache)))
3917 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3918 ["Displaying Status"
3919 (customize-set-variable 'vhdl-speedbar-save-cache
3920 (if (memq 'display vhdl-speedbar-save-cache)
3921 (delq 'display vhdl-speedbar-save-cache)
3922 (cons 'display vhdl-speedbar-save-cache)))
3923 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3924 ["Cache File Name..."
3925 (customize-option 'vhdl-speedbar-cache-file-name) t]
3927 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3929 ["Add Index Menu when Loading File"
3930 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3931 (vhdl-index-menu-init))
3932 :style toggle :selected vhdl-index-menu]
3933 ["Add Source File Menu when Loading File"
3934 (progn (customize-set-variable 'vhdl-source-file-menu
3935 (not vhdl-source-file-menu))
3936 (vhdl-add-source-files-menu))
3937 :style toggle :selected vhdl-source-file-menu]
3938 ["Add Hideshow Menu at Startup"
3939 (progn (customize-set-variable 'vhdl-hideshow-menu
3940 (not vhdl-hideshow-menu))
3941 (vhdl-activate-customizations))
3942 :style toggle :selected vhdl-hideshow-menu]
3943 ["Hide Everything Initially"
3944 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3945 :style toggle :selected vhdl-hide-all-init]
3947 ["Customize Group..." (customize-group 'vhdl-menu) t])
3949 ["In Two Column Format"
3950 (progn (customize-set-variable 'vhdl-print-two-column
3951 (not vhdl-print-two-column))
3952 (message "Activate new setting by saving options and restarting Emacs"))
3953 :style toggle :selected vhdl-print-two-column]
3954 ["Use Customized Faces"
3955 (progn (customize-set-variable 'vhdl-print-customize-faces
3956 (not vhdl-print-customize-faces))
3957 (message "Activate new setting by saving options and restarting Emacs"))
3958 :style toggle :selected vhdl-print-customize-faces]
3960 ["Customize Group..." (customize-group 'vhdl-print) t])
3962 ["Use Intelligent Tab"
3963 (progn (customize-set-variable 'vhdl-intelligent-tab
3964 (not vhdl-intelligent-tab))
3965 (vhdl-activate-customizations))
3966 :style toggle :selected vhdl-intelligent-tab]
3967 ["Indent Syntax-Based"
3968 (customize-set-variable 'vhdl-indent-syntax-based
3969 (not vhdl-indent-syntax-based))
3970 :style toggle :selected vhdl-indent-syntax-based]
3971 ["Word Completion is Case Sensitive"
3972 (customize-set-variable 'vhdl-word-completion-case-sensitive
3973 (not vhdl-word-completion-case-sensitive))
3974 :style toggle :selected vhdl-word-completion-case-sensitive]
3975 ["Word Completion in Minibuffer"
3976 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3977 (not vhdl-word-completion-in-minibuffer))
3978 (message "Activate new setting by saving options and restarting Emacs"))
3979 :style toggle :selected vhdl-word-completion-in-minibuffer]
3980 ["Underscore is Part of Word"
3981 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3982 (not vhdl-underscore-is-part-of-word))
3983 (vhdl-activate-customizations))
3984 :style toggle :selected vhdl-underscore-is-part-of-word]
3986 ["Customize Group..." (customize-group 'vhdl-misc) t])
3987 ["Related..." (customize-browse 'vhdl-related) t]
3989 ["Save Options" customize-save-customized t]
3990 ["Activate Options" vhdl-activate-customizations t]
3991 ["Browse Options..." vhdl-customize t])))
3993 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3996 (defun vhdl-update-mode-menu ()
3997 "Update VHDL Mode menu."
3999 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4000 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4001 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4002 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4003 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4006 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4008 (defconst vhdl-imenu-generic-expression
4011 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4014 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4017 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4020 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4023 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4026 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4029 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4032 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4035 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4038 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4041 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4043 (defun vhdl-index-menu-init ()
4044 "Initialize index menu."
4045 (set (make-local-variable 'imenu-case-fold-search) t)
4046 (set (make-local-variable 'imenu-generic-expression)
4047 vhdl-imenu-generic-expression)
4048 (when (and vhdl-index-menu (fboundp 'imenu))
4049 (if (or (not (boundp 'font-lock-maximum-size))
4050 (> font-lock-maximum-size (buffer-size)))
4051 (imenu-add-to-menubar "Index")
4052 (message "Scanning buffer for index...buffer too big"))))
4054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4055 ;; Source file menu (using `easy-menu.el')
4057 (defvar vhdl-sources-menu nil)
4059 (defun vhdl-directory-files (directory &optional full match)
4060 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4062 (if (not (file-directory-p directory))
4063 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4064 (let ((dir (directory-files directory full match)))
4065 (setq dir (delete "." dir))
4066 (setq dir (delete ".." dir))
4069 (defun vhdl-get-source-files (&optional full directory)
4070 "Get list of VHDL source files in DIRECTORY or current directory."
4071 (let ((mode-alist auto-mode-alist)
4073 ;; create regular expressions for matching file names
4074 (setq filename-regexp "\\`[^.].*\\(")
4076 (when (eq (cdar mode-alist) 'vhdl-mode)
4077 (setq filename-regexp
4078 (concat filename-regexp (caar mode-alist) "\\|")))
4079 (setq mode-alist (cdr mode-alist)))
4080 (setq filename-regexp
4081 (concat (substring filename-regexp 0
4082 (string-match "\\\\|$" filename-regexp)) "\\)"))
4084 (vhdl-directory-files
4085 (or directory default-directory) full filename-regexp)))
4087 (defun vhdl-add-source-files-menu ()
4088 "Scan directory for all VHDL source files and generate menu.
4089 The directory of the current source file is scanned."
4091 (message "Scanning directory for source files ...")
4092 (let ((newmap (current-local-map))
4093 (file-list (vhdl-get-source-files))
4095 ;; Create list for menu
4099 (setq menu-list (cons (vector (car file-list)
4100 (list 'find-file (car file-list)) t)
4102 (setq file-list (cdr file-list)))
4103 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4104 (when found (setq menu-list (cons "--" menu-list)))
4105 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4106 (setq menu-list (cons "Sources" menu-list))
4108 (easy-menu-add menu-list)
4109 (easy-menu-define vhdl-sources-menu newmap
4110 "VHDL source files menu" menu-list))
4114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4117 ;; performs all buffer local initializations
4121 "Major mode for editing VHDL code.
4126 TEMPLATE INSERTION (electrification):
4127 After typing a VHDL keyword and entering `SPC', you are prompted for
4128 arguments while a template is generated for that VHDL construct. Typing
4129 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4130 template generation. Optional arguments are indicated by square
4131 brackets and removed if the queried string is left empty. Prompts for
4132 mandatory arguments remain in the code if the queried string is left
4133 empty. They can be queried again by `C-c C-t C-q'. Enabled
4134 electrification is indicated by `/e' in the modeline.
4136 Typing `M-SPC' after a keyword inserts a space without calling the
4137 template generator. Automatic template generation (i.e.
4138 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4139 setting option `vhdl-electric-mode' (see OPTIONS).
4141 Template generators can be invoked from the VHDL menu, by key
4142 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4143 the keyword (i.e. first word of menu entry not in parenthesis) and
4144 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4145 conf, comp, cons, func, inst, pack, sig, var.
4147 Template styles can be customized in customization group
4148 `vhdl-template' \(see OPTIONS).
4152 A file header can be inserted by `C-c C-t C-h'. A file footer
4153 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4154 See customization group `vhdl-header'.
4158 Double striking of some keys inserts cumbersome VHDL syntax elements.
4159 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4160 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4161 the modeline. The stuttering keys and their effects are:
4163 ;; --> \" : \" [ --> ( -- --> comment
4164 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4165 .. --> \" => \" ] --> ) --- --> horizontal line
4166 ,, --> \" <= \" ]] --> ] ---- --> display comment
4167 == --> \" == \" '' --> \\\"
4171 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4172 word in the buffer that starts alike, inserts it and adjusts case.
4173 Re-typing `TAB' toggles through alternative word completions. This also
4174 works in the minibuffer (i.e. in template generator prompts).
4176 Typing `TAB' after `(' looks for and inserts complete parenthesized
4177 expressions (e.g. for array index ranges). All keywords as well as
4178 standard types and subprograms of VHDL have predefined abbreviations
4179 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4180 beginning with \"std\").
4182 Typing `TAB' after a non-word character indents the line if at the
4183 beginning of a line (i.e. no preceding non-blank characters), and
4184 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4189 `--' puts a single comment.
4190 `---' draws a horizontal line for separating code segments.
4191 `----' inserts a display comment, i.e. two horizontal lines
4192 with a comment in between.
4193 `--CR' comments out code on that line. Re-hitting CR comments
4194 out following lines.
4195 `C-c c' comments out a region if not commented out,
4196 uncomments a region if already commented out.
4198 You are prompted for comments after object definitions (i.e. signals,
4199 variables, constants, ports) and after subprogram and process
4200 specifications if option `vhdl-prompt-for-comments' is non-nil.
4201 Comments are automatically inserted as additional labels (e.g. after
4202 begin statements) and as help comments if `vhdl-self-insert-comments' is
4205 Inline comments (i.e. comments after a piece of code on the same line)
4206 are indented at least to `vhdl-inline-comment-column'. Comments go at
4207 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4208 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4209 in a comment automatically opens a new comment line. `M-q' re-fills
4210 multi-line comments.
4214 `TAB' indents a line if at the beginning of the line. The amount of
4215 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4216 always indents the current line (is bound to `TAB' if option
4217 `vhdl-intelligent-tab' is nil).
4219 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4220 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4221 indented normally (nil) or relative to the opening parenthesis (non-nil)
4222 according to option `vhdl-argument-list-indent'.
4224 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4225 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4228 Syntax-based indentation can be very slow in large files. Option
4229 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4233 The alignment functions align operators, keywords, and inline comments
4234 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4235 separated by blank lines, `C-c C-a C-i' a block of lines with same
4236 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4237 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4238 C-a C-d' all lines within the declarative part of a design unit. `C-c
4239 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4240 for a group of lines, and `C-c C-a M-c' for a region.
4242 If option `vhdl-align-groups' is non-nil, groups of code lines
4243 separated by special lines (see option `vhdl-align-group-separate') are
4244 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4245 blocks of lines with same indent are aligned separately. Some templates
4246 are automatically aligned after generation if option `vhdl-auto-align'
4249 Alignment tries to align inline comments at
4250 `vhdl-inline-comment-column' and tries inline comment not to exceed
4251 `vhdl-end-comment-column'.
4253 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4254 symbols are surrounded by one space, and multiple spaces are eliminated.
4258 Code filling allows to condense code (e.g. sensitivity lists or port
4259 maps) by removing comments and newlines and re-wrapping so that all
4260 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4261 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4262 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4263 `C-c C-f M-f' an entire region.
4266 CODE BEAUTIFICATION:
4267 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4268 buffer respectively. This inludes indentation, alignment, and case
4269 fixing. Code beautification can also be run non-interactively using the
4272 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4276 Generic and port clauses from entity or component declarations can be
4277 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4278 as component instantiations and corresponding internal constants and
4279 signals, as a generic map with constants as actual generics, and as
4280 internal signal initializations (menu).
4282 To include formals in component instantiations, see option
4283 `vhdl-association-list-with-formals'. To include comments in pasting,
4284 see options `vhdl-include-...-comments'.
4286 A clause with several generic/port names on the same line can be
4287 flattened (`C-c C-p C-f') so that only one name per line exists. The
4288 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4289 outputs and vice versa, which can be useful in testbenches. (This
4290 reversion is done on the internal data structure and is only reflected
4291 in subsequent paste operations.)
4293 Names for actual ports, instances, testbenches, and
4294 design-under-test instances can be derived from existing names according
4295 to options `vhdl-...-name'. See customization group `vhdl-port'.
4298 SUBPROGRAM TRANSLATION:
4299 Similar functionality exists for copying/pasting the interface of
4300 subprograms (function/procedure). A subprogram interface can be copied
4301 and then pasted as a subprogram declaration, body or call (uses
4302 association list with formals).
4305 TESTBENCH GENERATION:
4306 A copied port can also be pasted as a testbench. The generated
4307 testbench includes an entity, an architecture, and an optional
4308 configuration. The architecture contains the component declaration and
4309 instantiation of the DUT as well as internal constant and signal
4310 declarations. Additional user-defined templates can be inserted. The
4311 names used for entity/architecture/configuration/DUT as well as the file
4312 structure to be generated can be customized. See customization group
4317 Key bindings (`C-c ...') exist for most commands (see in menu).
4321 All commands can be found in the VHDL menu including their key bindings.
4325 The speedbar allows browsing of directories and file contents. It can
4326 be accessed from the VHDL menu and is automatically opened if option
4327 `vhdl-speedbar-auto-open' is non-nil.
4329 In speedbar, open files and directories with `mouse-2' on the name and
4330 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4333 DESIGN HIERARCHY BROWSER:
4334 The speedbar can also be used for browsing the hierarchy of design units
4335 contained in the source files of the current directory or the specified
4336 projects (see option `vhdl-project-alist').
4338 The speedbar can be switched between file, directory hierarchy and
4339 project hierarchy browsing mode in the speedbar menu or by typing `f',
4340 `h' or `H' in speedbar.
4342 In speedbar, open design units with `mouse-2' on the name and browse
4343 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4344 from entities and components (in packages). Individual design units and
4345 complete designs can directly be compiled (\"Make\" menu entry).
4347 The hierarchy is automatically updated upon saving a modified source
4348 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4349 hierarchy is only updated for projects that have been opened once in the
4350 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4351 options in group `vhdl-speedbar').
4353 Simple design consistency checks are done during scanning, such as
4354 multiple declarations of the same unit or missing primary units that are
4355 required by secondary units.
4358 STRUCTURAL COMPOSITION:
4359 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4360 for a new component. Subcomponents (i.e. component declaration and
4361 instantiation) can be automatically placed from a previously read port
4362 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4363 all subcomponents can be automatically connected using internal signals
4364 and ports (`C-c C-c C-w') following these rules:
4365 - subcomponent actual ports with same name are considered to be
4366 connected by a signal (internal signal or port)
4367 - signals that are only inputs to subcomponents are considered as
4368 inputs to this component -> input port created
4369 - signals that are only outputs from subcomponents are considered as
4370 outputs from this component -> output port created
4371 - signals that are inputs to AND outputs from subcomponents are
4372 considered as internal connections -> internal signal created
4374 Purpose: With appropriate naming conventions it is possible to
4375 create higher design levels with only a few mouse clicks or key
4376 strokes. A new design level can be created by simply generating a new
4377 component, placing the required subcomponents from the hierarchy
4378 browser, and wiring everything automatically.
4380 Note: Automatic wiring only works reliably on templates of new
4381 components and component instantiations that were created by VHDL mode.
4383 Component declarations can be placed in a components package (option
4384 `vhdl-use-components-package') which can be automatically generated for
4385 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4386 component instantiation is also supported (option
4387 `vhdl-use-direct-instantiation').
4389 | Configuration declarations can automatically be generated either from
4390 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4391 | the speedbar menu (for the architecture under the cursor). The
4392 | configurations can optionally be hierarchical (i.e. include all
4393 | component levels of a hierarchical design, option
4394 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4395 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4396 | subcomponents in hierarchical configurations, the most-recently-analyzed
4397 | (mra) architecture is selected. If another architecture is desired, it
4398 | can be marked as most-recently-analyzed (speedbar menu) before
4399 | generating the configuration.
4401 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4402 | declarations) are currently not considered when displaying
4403 | configurations in speedbar.
4405 See the options group `vhdl-compose' for all relevant user options.
4408 SOURCE FILE COMPILATION:
4409 The syntax of the current buffer can be analyzed by calling a VHDL
4410 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4411 option `vhdl-compiler'. The available compilers are listed in option
4412 `vhdl-compiler-alist' including all required compilation command,
4413 command options, compilation directory, and error message syntax
4414 information. New compilers can be added.
4416 All the source files of an entire design can be compiled by the `make'
4417 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4420 MAKEFILE GENERATION:
4421 Makefiles can be generated automatically by an internal generation
4422 routine (`C-c M-k'). The library unit dependency information is
4423 obtained from the hierarchy browser. Makefile generation can be
4424 customized for each compiler in option `vhdl-compiler-alist'.
4426 Makefile generation can also be run non-interactively using the
4429 emacs -batch -l ~/.emacs -l vhdl-mode
4430 [-compiler compilername] [-project projectname]
4431 -f vhdl-generate-makefile
4433 The Makefile's default target \"all\" compiles the entire design, the
4434 target \"clean\" removes it and the target \"library\" creates the
4435 library directory if not existent. The Makefile also includes a target
4436 for each primary library unit which allows selective compilation of this
4437 unit, its secondary units and its subhierarchy (example: compilation of
4438 a design specified by a configuration). User specific parts can be
4439 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4442 - Only library units and dependencies within the current library are
4443 considered. Makefiles for designs that span multiple libraries are
4444 not (yet) supported.
4445 - Only one-level configurations are supported (also hierarchical),
4446 but configurations that go down several levels are not.
4447 - The \"others\" keyword in configurations is not supported.
4451 Projects can be defined in option `vhdl-project-alist' and a current
4452 project be selected using option `vhdl-project' (permanently) or from
4453 the menu or speedbar (temporarily). For each project, title and
4454 description strings (for the file headers), source files/directories
4455 (for the hierarchy browser and Makefile generation), library name, and
4456 compiler-dependent options, exceptions and compilation directory can be
4457 specified. Compilation settings overwrite the settings of option
4458 `vhdl-compiler-alist'.
4460 Project setups can be exported (i.e. written to a file) and imported.
4461 Imported setups are not automatically saved in `vhdl-project-alist' but
4462 can be saved afterwards in its customization buffer. When starting
4463 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4464 vhdl-mode\") in a directory with an existing project setup file, it is
4465 automatically loaded and its project activated if option
4466 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4467 files can be specified in option `vhdl-project-file-name'. Multiple
4468 project setups can be automatically loaded from global directories.
4469 This is an alternative to specifying project setups with option
4470 `vhdl-project-alist'.
4474 As an alternative to the speedbar, an index menu can be added (set
4475 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4476 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4477 file) for browsing the file contents (is not populated if buffer is
4478 larger than `font-lock-maximum-size'). Also, a source file menu can be
4479 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4480 current directory for VHDL source files.
4484 The VHDL standards to be used are specified in option `vhdl-standard'.
4485 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4489 Lower and upper case for keywords and standardized types, attributes,
4490 and enumeration values is supported. If the option
4491 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4492 lower case and are converted into upper case automatically (not for
4493 types, attributes, and enumeration values). The case of keywords,
4494 types, attributes,and enumeration values can be fixed for an entire
4495 region (menu) or buffer (`C-c C-x C-c') according to the options
4496 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4499 HIGHLIGHTING (fontification):
4500 Keywords and standardized types, attributes, enumeration values, and
4501 function names (controlled by option `vhdl-highlight-keywords'), as well
4502 as comments, strings, and template prompts are highlighted using
4503 different colors. Unit, subprogram, signal, variable, constant,
4504 parameter and generic/port names in declarations as well as labels are
4505 highlighted if option `vhdl-highlight-names' is non-nil.
4507 Additional reserved words or words with a forbidden syntax (e.g. words
4508 that should be avoided) can be specified in option
4509 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4510 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4511 keywords are highlighted as forbidden words if option
4512 `vhdl-highlight-verilog-keywords' is non-nil.
4514 Words with special syntax can be highlighted by specifying their
4515 syntax and color in option `vhdl-special-syntax-alist' and by setting
4516 option `vhdl-highlight-special-words' to non-nil. This allows to
4517 establish some naming conventions (e.g. to distinguish different kinds
4518 of signals or other objects by using name suffices) and to support them
4521 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4522 to support case-sensitive highlighting. However, keywords are then only
4523 highlighted if written in lower case.
4525 Code between \"translate_off\" and \"translate_on\" pragmas is
4526 highlighted using a different background color if option
4527 `vhdl-highlight-translate-off' is non-nil.
4529 For documentation and customization of the used colors see
4530 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4531 highlighting of matching parenthesis, see customization group
4532 `paren-showing'. Automatic buffer highlighting is turned on/off by
4533 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4537 VHDL models (templates) can be specified by the user and made accessible
4538 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4539 electrification. See option `vhdl-model-alist'.
4543 The code of blocks, processes, subprograms, component declarations and
4544 instantiations, generic/port clauses, and configuration declarations can
4545 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4546 the code (see customization group `vhdl-menu'). XEmacs: limited
4547 functionality due to old `hideshow.el' package.
4551 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4552 current process, `C-c C-u M-s' of all processes in the current buffer.
4554 - Only declared local signals (ports, signals declared in
4555 architecture and blocks) are automatically inserted.
4556 - Global signals declared in packages are not automatically inserted.
4557 Insert them once manually (will be kept afterwards).
4558 - Out parameters of procedures are considered to be read.
4559 Use option `vhdl-entity-file-name' to specify the entity file name
4560 \(used to obtain the port names).
4564 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4565 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4569 Postscript printing with different faces (an optimized set of faces is
4570 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4571 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4572 postscript printing commands. Option `vhdl-print-two-column' defines
4573 appropriate default settings for nice landscape two-column printing.
4574 The paper format can be set by option `ps-paper-type'. Do not forget to
4575 switch `ps-print-color-p' to nil for printing on black-and-white
4580 User options allow customization of VHDL Mode. All options are
4581 accessible from the \"Options\" menu entry. Simple options (switches
4582 and choices) can directly be changed, while for complex options a
4583 customization buffer is opened. Changed options can be saved for future
4584 sessions using the \"Save Options\" menu entry.
4586 Options and their detailed descriptions can also be accessed by using
4587 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4588 customize-group' for groups). Some customizations only take effect
4589 after some action (read the NOTE in the option documentation).
4590 Customization can also be done globally (i.e. site-wide, read the
4593 Not all options are described in this documentation, so go and see
4594 what other useful user options there are (`M-x vhdl-customize' or menu)!
4598 As default, files with extensions \".vhd\" and \".vhdl\" are
4599 automatically recognized as VHDL source files. To add an extension
4600 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4602 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4606 - To start Emacs with open VHDL hierarchy browser without having to load
4607 a VHDL file first, use the command:
4609 emacs -l vhdl-mode -f speedbar-frame-mode
4611 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4613 - Some features only work on properly indented code.
4617 See also the release notes (menu) for added features in new releases.
4623 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4624 Add a description of the problem and include a reproducible test case.
4626 Questions and enhancement requests can be sent to <reto@gnu.org>.
4628 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4629 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4630 releases. You are kindly invited to participate in beta testing. Subscribe
4631 to above mailing lists by sending an email to <reto@gnu.org>.
4633 VHDL Mode is officially distributed at
4634 URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
4635 where the latest version can be found.
4641 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4642 - XEmacs: Incorrect start-up when automatically opening speedbar.
4643 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4646 The VHDL Mode Authors
4647 Reto Zimmermann and Rod Whitby
4654 (kill-all-local-variables)
4655 (setq major-mode 'vhdl-mode)
4656 (setq mode-name '("VHDL"
4657 (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4658 (vhdl-electric-mode "e")
4659 (vhdl-stutter-mode "s")))
4661 ;; set maps and tables
4662 (use-local-map vhdl-mode-map)
4663 (set-syntax-table vhdl-mode-syntax-table)
4664 (setq local-abbrev-table vhdl-mode-abbrev-table)
4666 ;; set local variables
4667 (set (make-local-variable 'paragraph-start)
4668 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4669 (set (make-local-variable 'paragraph-separate) paragraph-start)
4670 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4671 (set (make-local-variable 'require-final-newline)
4672 (if vhdl-emacs-22 mode-require-final-newline t))
4673 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4674 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4675 (set (make-local-variable 'comment-start) "--")
4676 (set (make-local-variable 'comment-end) "")
4678 (set (make-local-variable 'comment-padding) ""))
4679 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4680 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4681 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4682 (set (make-local-variable 'comment-multi-line) nil)
4683 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4684 (set (make-local-variable 'hippie-expand-verbose) nil)
4686 ;; setup the comment indent variable in a Emacs version portable way
4687 ;; ignore any byte compiler warnings you might get here
4688 (when (boundp 'comment-indent-function)
4689 (make-local-variable 'comment-indent-function)
4690 (setq comment-indent-function 'vhdl-comment-indent))
4692 ;; initialize font locking
4693 (set (make-local-variable 'font-lock-defaults)
4695 '(nil vhdl-font-lock-keywords) nil
4696 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4697 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4698 (unless vhdl-emacs-21
4699 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4700 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4701 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4702 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4703 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4704 ; (turn-on-font-lock)
4706 ;; variables for source file compilation
4707 (when vhdl-compile-use-local-error-regexp
4708 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4709 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4712 (vhdl-index-menu-init)
4713 ;; add source file menu
4714 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4716 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4717 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4718 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4719 ;; initialize hideshow and add menu
4720 (vhdl-hideshow-init)
4721 (run-hooks 'menu-bar-update-hook)
4724 (vhdl-ps-print-init)
4725 (vhdl-write-file-hooks-init)
4726 (message "VHDL Mode %s.%s" vhdl-version
4727 (if noninteractive "" " See menu for documentation and release notes."))
4731 (run-mode-hooks 'vhdl-mode-hook)
4732 (run-hooks 'vhdl-mode-hook)))
4734 (defun vhdl-activate-customizations ()
4735 "Activate all customizations on local variables."
4737 (vhdl-mode-map-init)
4738 (use-local-map vhdl-mode-map)
4739 (set-syntax-table vhdl-mode-syntax-table)
4740 (setq comment-column vhdl-inline-comment-column)
4741 (setq end-comment-column vhdl-end-comment-column)
4742 (vhdl-write-file-hooks-init)
4743 (vhdl-update-mode-menu)
4744 (vhdl-hideshow-init)
4745 (run-hooks 'menu-bar-update-hook))
4747 (defun vhdl-write-file-hooks-init ()
4748 "Add/remove hooks when buffer is saved."
4749 (if vhdl-modify-date-on-saving
4750 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4751 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4752 (make-local-variable 'after-save-hook)
4753 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4755 (defun vhdl-process-command-line-option (option)
4756 "Process command line options for VHDL Mode."
4759 ((equal option "-compiler")
4760 (vhdl-set-compiler (car command-line-args-left))
4761 (setq command-line-args-left (cdr command-line-args-left)))
4763 ((equal option "-project")
4764 (vhdl-set-project (car command-line-args-left))
4765 (setq command-line-args-left (cdr command-line-args-left)))))
4767 ;; make Emacs process VHDL Mode options
4768 (setq command-switch-alist
4769 (append command-switch-alist
4770 '(("-compiler" . vhdl-process-command-line-option)
4771 ("-project" . vhdl-process-command-line-option))))
4774 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4775 ;;; Keywords and standardized words
4776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4778 (defconst vhdl-93-keywords
4780 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4781 "assert" "attribute"
4782 "begin" "block" "body" "buffer" "bus"
4783 "case" "component" "configuration" "constant"
4784 "disconnect" "downto"
4785 "else" "elsif" "end" "entity" "exit"
4786 "file" "for" "function"
4787 "generate" "generic" "group" "guarded"
4788 "if" "impure" "in" "inertial" "inout" "is"
4789 "label" "library" "linkage" "literal" "loop"
4791 "nand" "new" "next" "nor" "not" "null"
4792 "of" "on" "open" "or" "others" "out"
4793 "package" "port" "postponed" "procedure" "process" "pure"
4794 "range" "record" "register" "reject" "rem" "report" "return"
4796 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4797 "then" "to" "transport" "type"
4798 "unaffected" "units" "until" "use"
4800 "wait" "when" "while" "with"
4803 "List of VHDL'93 keywords.")
4805 (defconst vhdl-ams-keywords
4807 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4808 "reference" "spectrum" "subnature" "terminal" "through"
4811 "List of VHDL-AMS keywords.")
4813 (defconst vhdl-verilog-keywords
4815 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4816 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4817 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4818 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4819 "endprimitive" "endspecify" "endtable" "endtask" "event"
4820 "for" "force" "forever" "fork" "function"
4821 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4822 "macromodule" "makefile" "medium" "module"
4823 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4824 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4826 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4827 "rtranif0" "rtranif1"
4828 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4829 "strong1" "supply" "supply0" "supply1"
4830 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4831 "triand" "trior" "trireg"
4832 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4834 "List of Verilog keywords as candidate for additional reserved words.")
4836 (defconst vhdl-93-types
4838 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4839 "real" "time" "natural" "positive" "string" "line" "text" "side"
4840 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4841 "std_logic" "std_logic_vector"
4842 "std_ulogic" "std_ulogic_vector"
4844 "List of VHDL'93 standardized types.")
4846 (defconst vhdl-ams-types
4848 "domain_type" "real_vector"
4849 ;; from `nature_pkg' package
4850 "voltage" "current" "electrical" "position" "velocity" "force"
4851 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4852 "pressure" "flowrate" "fluid"
4854 "List of VHDL-AMS standardized types.")
4856 (defconst vhdl-math-types
4858 "complex" "complex_polar"
4860 "List of Math Packages standardized types.")
4862 (defconst vhdl-93-attributes
4864 "base" "left" "right" "high" "low" "pos" "val" "succ"
4865 "pred" "leftof" "rightof" "range" "reverse_range"
4866 "length" "delayed" "stable" "quiet" "transaction"
4867 "event" "active" "last_event" "last_active" "last_value"
4868 "driving" "driving_value" "ascending" "value" "image"
4869 "simple_name" "instance_name" "path_name"
4872 "List of VHDL'93 standardized attributes.")
4874 (defconst vhdl-ams-attributes
4877 "reference" "contribution" "tolerance"
4878 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4881 "List of VHDL-AMS standardized attributes.")
4883 (defconst vhdl-93-enum-values
4886 "note" "warning" "error" "failure"
4887 "read_mode" "write_mode" "append_mode"
4888 "open_ok" "status_error" "name_error" "mode_error"
4889 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4892 "List of VHDL'93 standardized enumeration values.")
4894 (defconst vhdl-ams-enum-values
4896 "quiescent_domain" "time_domain" "frequency_domain"
4897 ;; from `nature_pkg' package
4898 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4900 "List of VHDL-AMS standardized enumeration values.")
4902 (defconst vhdl-math-constants
4904 "math_e" "math_1_over_e"
4905 "math_pi" "math_two_pi" "math_1_over_pi"
4906 "math_half_pi" "math_q_pi" "math_3_half_pi"
4907 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4908 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4909 "math_deg_to_rad" "math_rad_to_deg"
4910 "cbase_1" "cbase_j" "czero"
4912 "List of Math Packages standardized constants.")
4914 (defconst vhdl-93-functions
4916 "now" "resolved" "rising_edge" "falling_edge"
4917 "read" "readline" "write" "writeline" "endfile"
4918 "resize" "is_X" "std_match"
4919 "shift_left" "shift_right" "rotate_left" "rotate_right"
4920 "to_unsigned" "to_signed" "to_integer"
4921 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4922 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4923 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4924 "shl" "shr" "ext" "sxt"
4927 "List of VHDL'93 standardized functions.")
4929 (defconst vhdl-ams-functions
4933 "List of VHDL-AMS standardized functions.")
4935 (defconst vhdl-math-functions
4937 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4938 "sqrt" "cbrt" "exp" "log"
4939 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4940 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4941 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4943 "List of Math Packages standardized functions.")
4945 (defconst vhdl-93-packages
4947 "std_logic_1164" "numeric_std" "numeric_bit"
4949 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4950 "std_logic_misc" "std_logic_textio"
4953 "List of VHDL'93 standardized packages and libraries.")
4955 (defconst vhdl-ams-packages
4957 ;; from `nature_pkg' package
4960 "List of VHDL-AMS standardized packages and libraries.")
4962 (defconst vhdl-math-packages
4964 "math_real" "math_complex"
4966 "List of Math Packages standardized packages and libraries.")
4968 (defvar vhdl-keywords nil
4969 "List of VHDL keywords.")
4971 (defvar vhdl-types nil
4972 "List of VHDL standardized types.")
4974 (defvar vhdl-attributes nil
4975 "List of VHDL standardized attributes.")
4977 (defvar vhdl-enum-values nil
4978 "List of VHDL standardized enumeration values.")
4980 (defvar vhdl-constants nil
4981 "List of VHDL standardized constants.")
4983 (defvar vhdl-functions nil
4984 "List of VHDL standardized functions.")
4986 (defvar vhdl-packages nil
4987 "List of VHDL standardized packages and libraries.")
4989 (defvar vhdl-reserved-words nil
4990 "List of additional reserved words.")
4992 (defvar vhdl-keywords-regexp nil
4993 "Regexp for VHDL keywords.")
4995 (defvar vhdl-types-regexp nil
4996 "Regexp for VHDL standardized types.")
4998 (defvar vhdl-attributes-regexp nil
4999 "Regexp for VHDL standardized attributes.")
5001 (defvar vhdl-enum-values-regexp nil
5002 "Regexp for VHDL standardized enumeration values.")
5004 (defvar vhdl-functions-regexp nil
5005 "Regexp for VHDL standardized functions.")
5007 (defvar vhdl-packages-regexp nil
5008 "Regexp for VHDL standardized packages and libraries.")
5010 (defvar vhdl-reserved-words-regexp nil
5011 "Regexp for additional reserved words.")
5013 (defvar vhdl-directive-keywords-regexp nil
5014 "Regexp for compiler directive keywords.")
5016 (defun vhdl-words-init ()
5017 "Initialize reserved words."
5019 (append vhdl-93-keywords
5020 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5022 (append vhdl-93-types
5023 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5024 (when (vhdl-standard-p 'math) vhdl-math-types)))
5025 (setq vhdl-attributes
5026 (append vhdl-93-attributes
5027 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5028 (setq vhdl-enum-values
5029 (append vhdl-93-enum-values
5030 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5031 (setq vhdl-constants
5032 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5033 (setq vhdl-functions
5034 (append vhdl-93-functions
5035 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5036 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5038 (append vhdl-93-packages
5039 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5040 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5041 (setq vhdl-reserved-words
5042 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5043 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5045 (setq vhdl-keywords-regexp
5046 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5047 (setq vhdl-types-regexp
5048 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5049 (setq vhdl-attributes-regexp
5050 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5051 (setq vhdl-enum-values-regexp
5052 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5053 (setq vhdl-functions-regexp
5054 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5055 (setq vhdl-packages-regexp
5056 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5057 (setq vhdl-reserved-words-regexp
5059 (unless (equal vhdl-forbidden-syntax "")
5060 (concat vhdl-forbidden-syntax "\\|"))
5061 (regexp-opt vhdl-reserved-words)
5063 (setq vhdl-directive-keywords-regexp
5064 (concat "\\<\\(" (mapconcat 'regexp-quote
5065 vhdl-directive-keywords "\\|") "\\)\\>"))
5066 (vhdl-abbrev-list-init))
5068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5071 (defvar vhdl-abbrev-list nil
5072 "Predefined abbreviations for VHDL.")
5074 (defun vhdl-abbrev-list-init ()
5075 (setq vhdl-abbrev-list
5077 (list vhdl-upper-case-keywords) vhdl-keywords
5078 (list vhdl-upper-case-types) vhdl-types
5079 (list vhdl-upper-case-attributes) vhdl-attributes
5080 (list vhdl-upper-case-enum-values) vhdl-enum-values
5081 (list vhdl-upper-case-constants) vhdl-constants
5082 (list nil) vhdl-functions
5083 (list nil) vhdl-packages)))
5085 ;; initialize reserved words for VHDL Mode
5089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5091 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5096 ;; constant regular expressions for looking at various constructs
5098 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5099 "Regexp describing a VHDL symbol.
5100 We cannot use just `word' syntax class since `_' cannot be in word
5101 class. Putting underscore in word class breaks forward word movement
5102 behavior that users are familiar with.")
5104 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5105 "Regexp describing a case statement header key.")
5107 (defconst vhdl-label-key
5108 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5109 "Regexp describing a VHDL label.")
5111 ;; Macro definitions:
5113 (defmacro vhdl-point (position)
5114 "Return the value of point at certain commonly referenced POSITIONs.
5115 POSITION can be one of the following symbols:
5117 bol -- beginning of line
5119 bod -- beginning of defun
5120 boi -- back to indentation
5121 eoi -- last whitespace on line
5122 ionl -- indentation of next line
5123 iopl -- indentation of previous line
5124 bonl -- beginning of next line
5125 bopl -- beginning of previous line
5127 This function does not modify point or mark."
5128 (or (and (eq 'quote (car-safe position))
5129 (null (cddr position)))
5130 (error "ERROR: Bad buffer position requested: %s" position))
5131 (setq position (nth 1 position))
5132 `(let ((here (point)))
5134 ((eq position 'bol) '((beginning-of-line)))
5135 ((eq position 'eol) '((end-of-line)))
5136 ((eq position 'bod) '((save-match-data
5137 (vhdl-beginning-of-defun))))
5138 ((eq position 'boi) '((back-to-indentation)))
5139 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5140 ((eq position 'bonl) '((forward-line 1)))
5141 ((eq position 'bopl) '((forward-line -1)))
5142 ((eq position 'iopl)
5144 (back-to-indentation)))
5145 ((eq position 'ionl)
5147 (back-to-indentation)))
5148 (t (error "ERROR: Unknown buffer position requested: %s" position))
5153 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5154 ;; doesn't hurt for v19
5158 (defmacro vhdl-safe (&rest body)
5159 "Safely execute BODY, return nil if an error occurred."
5160 `(condition-case nil
5164 (defmacro vhdl-add-syntax (symbol &optional relpos)
5165 "A simple macro to append the syntax in SYMBOL to the syntax list.
5166 Try to increase performance by using this macro."
5167 `(setq vhdl-syntactic-context
5168 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5170 (defmacro vhdl-has-syntax (symbol)
5171 "A simple macro to return check the syntax list.
5172 Try to increase performance by using this macro."
5173 `(assoc ,symbol vhdl-syntactic-context))
5175 ;; Syntactic element offset manipulation:
5177 (defun vhdl-read-offset (langelem)
5178 "Read new offset value for LANGELEM from minibuffer.
5179 Return a valid value only."
5180 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5181 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5183 offset input interned)
5185 (setq input (read-string prompt oldoff)
5186 offset (cond ((string-equal "+" input) '+)
5187 ((string-equal "-" input) '-)
5188 ((string-equal "++" input) '++)
5189 ((string-equal "--" input) '--)
5190 ((string-match "^-?[0-9]+$" input)
5191 (string-to-number input))
5192 ((fboundp (setq interned (intern input)))
5194 ((boundp interned) interned)
5195 ;; error, but don't signal one, keep trying
5196 ;; to read an input value
5198 (setq prompt errmsg)
5202 (defun vhdl-set-offset (symbol offset &optional add-p)
5203 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5204 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5205 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5206 `vhdl-offsets-alist' if it doesn't already appear there."
5209 (intern (completing-read
5210 (concat "Syntactic symbol to change"
5211 (if current-prefix-arg " or add" "")
5216 (cons (format "%s" (car langelem)) nil)))
5218 nil (not current-prefix-arg)
5219 ;; initial contents tries to be the last element
5220 ;; on the syntactic analysis list for the current
5222 (let* ((syntax (vhdl-get-syntactic-context))
5223 (len (length syntax))
5224 (ic (format "%s" (car (nth (1- len) syntax)))))
5227 (offset (vhdl-read-offset langelem)))
5228 (list langelem offset current-prefix-arg)))
5229 ;; sanity check offset
5237 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5239 (let ((entry (assq symbol vhdl-offsets-alist)))
5241 (setcdr entry offset)
5243 (setq vhdl-offsets-alist
5244 (cons (cons symbol offset) vhdl-offsets-alist))
5245 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5246 (vhdl-keep-region-active))
5248 (defun vhdl-set-style (style &optional local)
5249 "Set `vhdl-mode' variables to use one of several different indentation styles.
5250 STYLE is a string representing the desired style and optional LOCAL is
5251 a flag which, if non-nil, means to make the style variables being
5252 changed buffer local, instead of the default, which is to set the
5253 global variables. Interactively, the flag comes from the prefix
5254 argument. The styles are chosen from the `vhdl-style-alist' variable."
5255 (interactive (list (completing-read "Use which VHDL indentation style? "
5256 vhdl-style-alist nil t)
5257 current-prefix-arg))
5258 (let ((vars (cdr (assoc style vhdl-style-alist))))
5260 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5261 ;; set all the variables
5265 (let ((var (car varentry))
5266 (val (cdr varentry)))
5268 (make-local-variable var))
5269 ;; special case for vhdl-offsets-alist
5270 (if (not (eq var 'vhdl-offsets-alist))
5272 ;; reset vhdl-offsets-alist to the default value first
5273 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5274 ;; now set the langelems that are different
5278 (let ((langelem (car langentry))
5279 (offset (cdr langentry)))
5280 (vhdl-set-offset langelem offset)
5285 (vhdl-keep-region-active))
5287 (defun vhdl-get-offset (langelem)
5288 "Get offset from LANGELEM which is a cons cell of the form:
5289 \(SYMBOL . RELPOS). The symbol is matched against
5290 vhdl-offsets-alist and the offset found there is either returned,
5291 or added to the indentation at RELPOS. If RELPOS is nil, then
5292 the offset is simply returned."
5293 (let* ((symbol (car langelem))
5294 (relpos (cdr langelem))
5295 (match (assq symbol vhdl-offsets-alist))
5296 (offset (cdr-safe match)))
5297 ;; offset can be a number, a function, a variable, or one of the
5301 (if vhdl-strict-syntax-p
5302 (error "ERROR: Don't know how to indent a %s" symbol)
5305 ((eq offset '+) (setq offset vhdl-basic-offset))
5306 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5307 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5308 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5309 ((and (not (numberp offset))
5311 (setq offset (funcall offset langelem)))
5312 ((not (numberp offset))
5313 (setq offset (eval offset)))
5316 (< relpos (vhdl-point 'bol)))
5323 ;; Syntactic support functions:
5325 (defun vhdl-in-comment-p ()
5326 "Check if point is in a comment."
5327 (eq (vhdl-in-literal) 'comment))
5329 (defun vhdl-in-string-p ()
5330 "Check if point is in a string."
5331 (eq (vhdl-in-literal) 'string))
5333 (defun vhdl-in-literal ()
5334 "Determine if point is in a VHDL literal."
5336 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5338 ((nth 3 state) 'string)
5339 ((nth 4 state) 'comment)
5340 ((vhdl-beginning-of-macro) 'pound)
5343 (defun vhdl-forward-comment (&optional direction)
5344 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5345 negative, skip forward otherwise."
5347 (if (and direction (< direction 0))
5350 (skip-chars-backward " \t\n")
5351 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5352 (goto-char (match-beginning 3))
5353 (skip-chars-backward " \t\n")))
5355 (skip-chars-forward " \t\n")
5356 (while (looking-at "--.*")
5357 (goto-char (match-end 0))
5358 (skip-chars-forward " \t\n"))))
5360 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5361 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5362 (defalias 'vhdl-forward-comment 'forward-comment))
5364 ;; This is the best we can do in Win-Emacs.
5365 (defun vhdl-win-il (&optional lim)
5366 "Determine if point is in a VHDL literal."
5368 (let* ((here (point))
5371 (lim (or lim (vhdl-point 'bod))))
5373 (while (< (point) here)
5375 (and (re-search-forward "--\\|[\"']"
5377 (buffer-substring (match-beginning 0) (match-end 0))))
5382 ;; looking at the opening of a VHDL style comment
5383 ((string= "--" match)
5384 (if (<= here (progn (end-of-line) (point))) 'comment))
5385 ;; looking at the opening of a double quote string
5386 ((string= "\"" match)
5387 (if (not (save-restriction
5388 ;; this seems to be necessary since the
5389 ;; re-search-forward will not work without it
5390 (narrow-to-region (point) here)
5392 ;; this regexp matches a double quote
5393 ;; which is preceded by an even number
5394 ;; of backslashes, including zero
5395 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5397 ;; looking at the opening of a single quote string
5398 ((string= "'" match)
5399 (if (not (save-restriction
5400 ;; see comments from above
5401 (narrow-to-region (point) here)
5403 ;; this matches a single quote which is
5404 ;; preceded by zero or two backslashes.
5405 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5412 (and (string-match "Win-Emacs" emacs-version)
5413 (fset 'vhdl-in-literal 'vhdl-win-il))
5415 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5416 ;; defined as lexical whitespace or comments. Search no farther back
5417 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5418 ;; used for backward skipping, (point-max) is used for forward
5421 (defun vhdl-forward-syntactic-ws (&optional lim)
5422 "Forward skip of syntactic whitespace."
5423 (let* ((here (point-max))
5424 (hugenum (point-max)))
5425 (while (/= here (point))
5427 (vhdl-forward-comment hugenum)
5428 ;; skip preprocessor directives
5429 (when (and (eq (char-after) ?#)
5430 (= (vhdl-point 'boi) (point)))
5431 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5432 (= (forward-line 1) 0)))
5434 (if lim (goto-char (min (point) lim)))))
5437 ;; This is the best we can do in Win-Emacs.
5438 (defun vhdl-win-fsws (&optional lim)
5439 "Forward skip syntactic whitespace for Win-Emacs."
5440 (let ((lim (or lim (point-max)))
5443 (skip-chars-forward " \t\n\r\f" lim)
5446 ((looking-at "--") (end-of-line))
5447 ;; none of the above
5448 (t (setq stop t))))))
5450 (and (string-match "Win-Emacs" emacs-version)
5451 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5453 (defun vhdl-beginning-of-macro (&optional lim)
5454 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5455 (let ((here (point)))
5457 (while (eq (char-before (1- (point))) ?\\)
5459 (back-to-indentation)
5460 (if (and (<= (point) here)
5461 (eq (char-after) ?#))
5466 (defun vhdl-backward-syntactic-ws (&optional lim)
5467 "Backward skip over syntactic whitespace."
5468 (let* ((here (point-min))
5469 (hugenum (- (point-max))))
5470 (while (/= here (point))
5472 (vhdl-forward-comment hugenum)
5473 (vhdl-beginning-of-macro))
5474 (if lim (goto-char (max (point) lim)))))
5476 ;; This is the best we can do in Win-Emacs.
5477 (defun vhdl-win-bsws (&optional lim)
5478 "Backward skip syntactic whitespace for Win-Emacs."
5479 (let ((lim (or lim (vhdl-point 'bod)))
5482 (skip-chars-backward " \t\n\r\f" lim)
5485 ((eq (vhdl-in-literal) 'comment)
5486 (skip-chars-backward "^-" lim)
5487 (skip-chars-backward "-" lim)
5488 (while (not (or (and (= (following-char) ?-)
5489 (= (char-after (1+ (point))) ?-))
5491 (skip-chars-backward "^-" lim)
5492 (skip-chars-backward "-" lim)))
5493 ;; none of the above
5494 (t (setq stop t))))))
5496 (and (string-match "Win-Emacs" emacs-version)
5497 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5499 ;; Functions to help finding the correct indentation column:
5501 (defun vhdl-first-word (point)
5502 "If the keyword at POINT is at boi, then return (current-column) at
5503 that point, else nil."
5505 (and (goto-char point)
5506 (eq (point) (vhdl-point 'boi))
5509 (defun vhdl-last-word (point)
5510 "If the keyword at POINT is at eoi, then return (current-column) at
5511 that point, else nil."
5513 (and (goto-char point)
5514 (save-excursion (or (eq (progn (forward-sexp) (point))
5516 (looking-at "\\s-*\\(--\\)?")))
5519 ;; Core syntactic evaluation functions:
5521 (defconst vhdl-libunit-re
5522 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5524 (defun vhdl-libunit-p ()
5528 (skip-chars-forward " \t\n")
5529 (not (looking-at "is\\b[^_]")))
5532 (and (not (looking-at "use\\b[^_]"))
5535 (vhdl-forward-syntactic-ws)
5536 (/= (following-char) ?:))))
5539 (defconst vhdl-defun-re
5540 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5542 (defun vhdl-defun-p ()
5544 (if (looking-at "block\\|process\\|procedural")
5545 ;; "block", "process", "procedural":
5548 (not (looking-at "end\\s-+\\w")))
5549 ;; "architecture", "configuration", "entity",
5550 ;; "package", "procedure", "function":
5553 (defun vhdl-corresponding-defun ()
5554 "If the word at the current position corresponds to a \"defun\"
5555 keyword, then return a string that can be used to find the
5556 corresponding \"begin\" keyword, else return nil."
5558 (and (looking-at vhdl-defun-re)
5560 (if (looking-at "block\\|process\\|procedural")
5561 ;; "block", "process". "procedural:
5562 (buffer-substring (match-beginning 0) (match-end 0))
5563 ;; "architecture", "configuration", "entity", "package",
5564 ;; "procedure", "function":
5567 (defconst vhdl-begin-fwd-re
5568 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5569 "A regular expression for searching forward that matches all known
5570 \"begin\" keywords.")
5572 (defconst vhdl-begin-bwd-re
5573 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5574 "A regular expression for searching backward that matches all known
5575 \"begin\" keywords.")
5577 (defun vhdl-begin-p (&optional lim)
5578 "Return t if we are looking at a real \"begin\" keyword.
5579 Assumes that the caller will make sure that we are looking at
5580 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5581 the middle of an identifier that just happens to contain a \"begin\"
5584 ;; "[architecture|case|configuration|entity|package|
5585 ;; procedure|function] ... is":
5586 ((and (looking-at "i")
5588 ;; Skip backward over first sexp (needed to skip over a
5589 ;; procedure interface list, and is harmless in other
5590 ;; situations). Note that we need "return" in the
5591 ;; following search list so that we don't run into
5592 ;; semicolons in the function interface list.
5595 (while (and (not foundp)
5597 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5599 (if (or (= (preceding-char) ?_)
5603 (and (/= (following-char) ?\;)
5604 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5607 ((looking-at "be\\|t")
5610 ((and (looking-at "e")
5611 ;; make sure that the "else" isn't inside a
5612 ;; conditional signal assignment.
5614 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5615 (or (eq (following-char) ?\;)
5618 ;; "block", "generate", "loop", "process", "procedural",
5619 ;; "units", "record":
5620 ((and (looking-at "bl\\|[glpur]")
5623 (not (looking-at "end\\s-+\\w"))))
5626 ((and (looking-at "c")
5629 (not (looking-at "end\\s-+\\w")))
5630 ;; look out for the dreaded entity class in an attribute
5632 (vhdl-backward-syntactic-ws lim)
5633 (/= (preceding-char) ?:)))
5635 ;; "for" (inside configuration declaration):
5636 ((and (looking-at "f")
5639 (not (looking-at "end\\s-+\\w")))
5640 (vhdl-has-syntax 'configuration))
5644 (defun vhdl-corresponding-mid (&optional lim)
5646 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5648 ((looking-at "then")
5653 (defun vhdl-corresponding-end (&optional lim)
5654 "If the word at the current position corresponds to a \"begin\"
5655 keyword, then return a vector containing enough information to find
5656 the corresponding \"end\" keyword, else return nil. The keyword to
5657 search forward for is aref 0. The column in which the keyword must
5658 appear is aref 1 or nil if any column is suitable.
5659 Assumes that the caller will make sure that we are not in the middle
5660 of an identifier that just happens to contain a \"begin\" keyword."
5662 (and (looking-at vhdl-begin-fwd-re)
5663 (/= (preceding-char) ?_)
5664 (not (vhdl-in-literal))
5667 ;; "is", "generate", "loop":
5668 ((looking-at "[igl]")
5670 (and (vhdl-last-word (point))
5671 (or (vhdl-first-word (point))
5673 (vhdl-beginning-of-statement-1 lim)
5674 (vhdl-backward-skip-label lim)
5675 (vhdl-first-word (point)))))))
5676 ;; "begin", "else", "for":
5677 ((looking-at "be\\|[ef]")
5679 (and (vhdl-last-word (point))
5680 (or (vhdl-first-word (point))
5682 (vhdl-beginning-of-statement-1 lim)
5683 (vhdl-backward-skip-label lim)
5684 (vhdl-first-word (point)))))))
5685 ;; "component", "units", "record":
5686 ((looking-at "[cur]")
5687 ;; The first end found will close the block
5689 ;; "block", "process", "procedural":
5690 ((looking-at "bl\\|p")
5692 (or (vhdl-first-word (point))
5694 (vhdl-beginning-of-statement-1 lim)
5695 (vhdl-backward-skip-label lim)
5696 (vhdl-first-word (point))))))
5699 (vector "elsif\\|else\\|end\\s-+if"
5700 (and (vhdl-last-word (point))
5701 (or (vhdl-first-word (point))
5703 (vhdl-beginning-of-statement-1 lim)
5704 (vhdl-backward-skip-label lim)
5705 (vhdl-first-word (point)))))))
5708 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5710 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5712 (defun vhdl-end-p (&optional lim)
5713 "Return t if we are looking at a real \"end\" keyword.
5714 Assumes that the caller will make sure that we are looking at
5715 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5716 the middle of an identifier that just happens to contain an \"end\"
5718 (or (not (looking-at "else"))
5719 ;; make sure that the "else" isn't inside a conditional signal
5722 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5723 (or (eq (following-char) ?\;)
5725 (vhdl-in-literal)))))
5727 (defun vhdl-corresponding-begin (&optional lim)
5728 "If the word at the current position corresponds to an \"end\"
5729 keyword, then return a vector containing enough information to find
5730 the corresponding \"begin\" keyword, else return nil. The keyword to
5731 search backward for is aref 0. The column in which the keyword must
5732 appear is aref 1 or nil if any column is suitable. The supplementary
5733 keyword to search forward for is aref 2 or nil if this is not
5734 required. If aref 3 is t, then the \"begin\" keyword may be found in
5735 the middle of a statement.
5736 Assumes that the caller will make sure that we are not in the middle
5737 of an identifier that just happens to contain an \"end\" keyword."
5740 (if (and (looking-at vhdl-end-fwd-re)
5741 (not (vhdl-in-literal))
5743 (if (looking-at "el")
5745 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5749 (skip-chars-forward " \t\n")
5752 ((looking-at "if\\b[^_]")
5753 (vector "else\\|elsif\\|if"
5754 (vhdl-first-word pos)
5757 ((looking-at "component\\b[^_]")
5758 (vector (buffer-substring (match-beginning 1)
5760 (vhdl-first-word pos)
5762 ;; "end units", "end record":
5763 ((looking-at "\\(units\\|record\\)\\b[^_]")
5764 (vector (buffer-substring (match-beginning 1)
5766 (vhdl-first-word pos)
5768 ;; "end block", "end process", "end procedural":
5769 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5770 (vector "begin" (vhdl-first-word pos) nil nil))
5772 ((looking-at "case\\b[^_]")
5773 (vector "case" (vhdl-first-word pos) "is" nil))
5775 ((looking-at "generate\\b[^_]")
5776 (vector "generate\\|for\\|if"
5777 (vhdl-first-word pos)
5780 ((looking-at "loop\\b[^_]")
5781 (vector "loop\\|while\\|for"
5782 (vhdl-first-word pos)
5784 ;; "end for" (inside configuration declaration):
5785 ((looking-at "for\\b[^_]")
5786 (vector "for" (vhdl-first-word pos) nil nil))
5789 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5790 (vhdl-first-word pos)
5791 ;; return an alist of (statement . keyword) mappings
5793 ;; "begin ... end [id]":
5795 ;; "architecture ... is ... begin ... end [id]":
5796 ("architecture" . "is")
5797 ;; "configuration ... is ... end [id]":
5798 ("configuration" . "is")
5799 ;; "entity ... is ... end [id]":
5801 ;; "package ... is ... end [id]":
5803 ;; "procedure ... is ... begin ... end [id]":
5804 ("procedure" . "is")
5805 ;; "function ... is ... begin ... end [id]":
5812 (defconst vhdl-leader-re
5813 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5815 (defun vhdl-end-of-leader ()
5817 (cond ((looking-at "block\\|process\\|procedural")
5820 (skip-chars-forward " \t\n")
5821 (= (following-char) ?\())
5824 (when (looking-at "[ \t\n]*is")
5825 (goto-char (match-end 0)))
5827 ((looking-at "component")
5829 (when (looking-at "[ \t\n]*is")
5830 (goto-char (match-end 0)))
5834 (skip-chars-forward " \t\n")
5835 (while (looking-at "[,:(]")
5837 (skip-chars-forward " \t\n"))
5842 (defconst vhdl-trailer-re
5843 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5845 (defconst vhdl-statement-fwd-re
5846 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5847 "A regular expression for searching forward that matches all known
5848 \"statement\" keywords.")
5850 (defconst vhdl-statement-bwd-re
5851 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5852 "A regular expression for searching backward that matches all known
5853 \"statement\" keywords.")
5855 (defun vhdl-statement-p (&optional lim)
5856 "Return t if we are looking at a real \"statement\" keyword.
5857 Assumes that the caller will make sure that we are looking at
5858 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5859 in the middle of an identifier that just happens to contain a
5860 \"statement\" keyword."
5862 ;; "for" ... "generate":
5863 ((and (looking-at "f")
5864 ;; Make sure it's the start of a parameter specification.
5867 (skip-chars-forward " \t\n")
5868 (looking-at "in\\b[^_]"))
5869 ;; Make sure it's not an "end for".
5872 (not (looking-at "end\\s-+\\w"))))
5874 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5875 ((and (looking-at "i")
5876 ;; Make sure it's not an "end if".
5879 (not (looking-at "end\\s-+\\w"))))
5881 ;; "while" ... "loop":
5886 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5887 "Regexp describing a case statement alternative key.")
5889 (defun vhdl-case-alternative-p (&optional lim)
5890 "Return t if we are looking at a real case alternative.
5891 Assumes that the caller will make sure that we are looking at
5892 vhdl-case-alternative-re, and are not inside a literal, and that
5893 we are not in the middle of an identifier that just happens to
5894 contain a \"when\" keyword."
5897 (while (and (not foundp)
5898 (re-search-backward ";\\|<=" lim 'move))
5899 (if (or (= (preceding-char) ?_)
5903 (or (eq (following-char) ?\;)
5907 ;; Core syntactic movement functions:
5909 (defconst vhdl-b-t-b-re
5910 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5912 (defun vhdl-backward-to-block (&optional lim)
5913 "Move backward to the previous \"begin\" or \"end\" keyword."
5915 (while (and (not foundp)
5916 (re-search-backward vhdl-b-t-b-re lim 'move))
5917 (if (or (= (preceding-char) ?_)
5922 ((and (looking-at vhdl-begin-fwd-re)
5923 (/= (preceding-char) ?_)
5925 (setq foundp 'begin))
5927 ((and (looking-at vhdl-end-fwd-re)
5928 (/= (preceding-char) ?_)
5936 (defun vhdl-forward-sexp (&optional count lim)
5937 "Move forward across one balanced expression (sexp).
5938 With COUNT, do it that many times."
5940 (let ((count (or count 1))
5941 (case-fold-search t)
5946 (skip-chars-forward " \t\n")
5947 ;; Check for an unbalanced "end" keyword
5948 (if (and (looking-at vhdl-end-fwd-re)
5949 (/= (preceding-char) ?_)
5950 (not (vhdl-in-literal))
5952 (not (looking-at "else")))
5954 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5955 ;; If the current keyword is a "begin" keyword, then find the
5956 ;; corresponding "end" keyword.
5957 (if (setq end-vec (vhdl-corresponding-end lim))
5959 ;; end-re is the statement keyword to search for
5961 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5962 ;; column is either the statement keyword target column
5964 (column (aref end-vec 1))
5965 (eol (vhdl-point 'eol))
5966 foundp literal placeholder)
5967 ;; Look for the statement keyword.
5968 (while (and (not foundp)
5969 (re-search-forward end-re nil t)
5970 (setq placeholder (match-end 1))
5971 (goto-char (match-beginning 0)))
5972 ;; If we are in a literal, or not in the right target
5973 ;; column and not on the same line as the begin, then
5976 (/= (current-indentation) column)
5978 (= (preceding-char) ?_)
5979 (setq literal (vhdl-in-literal)))
5980 (if (eq literal 'comment)
5983 ;; An "else" keyword corresponds to both the opening brace
5984 ;; of the following sexp and the closing brace of the
5986 (if (not (looking-at "else"))
5987 (goto-char placeholder))
5991 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5993 ;; If the current keyword is not a "begin" keyword, then just
5994 ;; perform the normal forward-sexp.
5997 (setq count (1- count))
5999 (setq target (point)))
6003 (defun vhdl-backward-sexp (&optional count lim)
6004 "Move backward across one balanced expression (sexp).
6005 With COUNT, do it that many times. LIM bounds any required backward
6008 (let ((count (or count 1))
6009 (case-fold-search t)
6013 ;; Perform the normal backward-sexp, unless we are looking at
6014 ;; "else" - an "else" keyword corresponds to both the opening brace
6015 ;; of the following sexp and the closing brace of the previous sexp.
6016 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6017 (/= (preceding-char) ?_)
6018 (not (vhdl-in-literal)))
6021 (if (and (looking-at vhdl-begin-fwd-re)
6022 (/= (preceding-char) ?_)
6023 (not (vhdl-in-literal))
6025 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6026 ;; If the current keyword is an "end" keyword, then find the
6027 ;; corresponding "begin" keyword.
6028 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6029 (/= (preceding-char) ?_))
6031 ;; begin-re is the statement keyword to search for
6033 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6034 ;; column is either the statement keyword target column
6036 (column (aref begin-vec 1))
6037 ;; internal-p controls where the statement keyword can
6039 (internal-p (aref begin-vec 3))
6040 (last-backward (point)) last-forward
6041 foundp literal keyword)
6042 ;; Look for the statement keyword.
6043 (while (and (not foundp)
6044 (re-search-backward begin-re lim t)
6046 (buffer-substring (match-beginning 1)
6048 ;; If we are in a literal or in the wrong column,
6051 (and (/= (current-indentation) column)
6052 ;; possibly accept current-column as
6053 ;; well as current-indentation.
6054 (or (not internal-p)
6055 (/= (current-column) column))))
6056 (= (preceding-char) ?_)
6059 ;; If there is a supplementary keyword, then
6060 ;; search forward for it.
6061 (if (and (setq begin-re (aref begin-vec 2))
6062 (or (not (listp begin-re))
6063 ;; If begin-re is an alist, then find the
6064 ;; element corresponding to the actual
6065 ;; keyword that we found.
6068 (assoc keyword begin-re))
6070 (setq begin-re (cdr begin-re))))))
6073 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6075 (setq last-forward (point))
6076 ;; Look for the supplementary keyword
6077 ;; (bounded by the backward search start
6079 (while (and (not foundp)
6080 (re-search-forward begin-re
6082 (goto-char (match-beginning 1)))
6083 ;; If we are in a literal, then try again.
6084 (if (or (= (preceding-char) ?_)
6087 (if (eq literal 'comment)
6089 (min (vhdl-point 'eol) last-backward))
6091 ;; We have found the supplementary keyword.
6092 ;; Save the position of the keyword in foundp.
6093 (setq foundp (point)))
6096 ;; If the supplementary keyword was found, then
6097 ;; move point to the supplementary keyword.
6099 ;; If there was no supplementary keyword, then
6100 ;; point is already at the statement keyword.
6102 ) ; end of the search for the statement keyword
6104 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6106 (setq count (1- count))
6108 (setq target (point)))
6112 (defun vhdl-backward-up-list (&optional count limit)
6113 "Move backward out of one level of blocks.
6114 With argument, do this that many times."
6116 (let ((count (or count 1))
6120 (if (looking-at vhdl-defun-re)
6121 (error "ERROR: Unbalanced blocks"))
6122 (vhdl-backward-to-block limit)
6123 (setq count (1- count)))
6124 (setq target (point)))
6125 (goto-char target)))
6127 (defun vhdl-end-of-defun (&optional count)
6128 "Move forward to the end of a VHDL defun."
6130 (let ((case-fold-search t))
6131 (vhdl-beginning-of-defun)
6132 (if (not (looking-at "block\\|process\\|procedural"))
6133 (re-search-forward "\\bis\\b"))
6134 (vhdl-forward-sexp)))
6136 (defun vhdl-mark-defun ()
6137 "Put mark at end of this \"defun\", point at beginning."
6139 (let ((case-fold-search t))
6141 (vhdl-beginning-of-defun)
6143 (if (not (looking-at "block\\|process\\|procedural"))
6144 (re-search-forward "\\bis\\b"))
6146 (exchange-point-and-mark)))
6148 (defun vhdl-beginning-of-libunit ()
6149 "Move backward to the beginning of a VHDL library unit.
6150 Returns the location of the corresponding begin keyword, unless search
6151 stops due to beginning or end of buffer.
6152 Note that if point is between the \"libunit\" keyword and the
6153 corresponding \"begin\" keyword, then that libunit will not be
6154 recognized, and the search will continue backwards. If point is
6155 at the \"begin\" keyword, then the defun will be recognized. The
6156 returned point is at the first character of the \"libunit\" keyword."
6157 (let ((last-forward (point))
6159 ;; Just in case we are actually sitting on the "begin"
6160 ;; keyword, allow for the keyword and an extra character,
6161 ;; as this will be used when looking forward for the
6163 (save-excursion (forward-word 1) (1+ (point))))
6164 foundp literal placeholder)
6165 ;; Find the "libunit" keyword.
6166 (while (and (not foundp)
6167 (re-search-backward vhdl-libunit-re nil 'move))
6168 ;; If we are in a literal, or not at a real libunit, then try again.
6169 (if (or (= (preceding-char) ?_)
6171 (not (vhdl-libunit-p)))
6173 ;; Find the corresponding "begin" keyword.
6174 (setq last-forward (point))
6175 (while (and (not foundp)
6176 (re-search-forward "\\bis\\b[^_]" last-backward t)
6177 (setq placeholder (match-beginning 0)))
6178 (if (or (= (preceding-char) ?_)
6179 (setq literal (vhdl-in-literal)))
6180 ;; It wasn't a real keyword, so keep searching.
6181 (if (eq literal 'comment)
6183 (min (vhdl-point 'eol) last-backward))
6185 ;; We have found the begin keyword, loop will exit.
6186 (setq foundp placeholder)))
6187 ;; Go back to the libunit keyword
6188 (goto-char last-forward)))
6191 (defun vhdl-beginning-of-defun (&optional count)
6192 "Move backward to the beginning of a VHDL defun.
6193 With argument, do it that many times.
6194 Returns the location of the corresponding begin keyword, unless search
6195 stops due to beginning or end of buffer."
6196 ;; Note that if point is between the "defun" keyword and the
6197 ;; corresponding "begin" keyword, then that defun will not be
6198 ;; recognized, and the search will continue backwards. If point is
6199 ;; at the "begin" keyword, then the defun will be recognized. The
6200 ;; returned point is at the first character of the "defun" keyword.
6202 (let ((count (or count 1))
6203 (case-fold-search t)
6204 (last-forward (point))
6208 (goto-char last-forward)
6209 (let ((last-backward
6210 ;; Just in case we are actually sitting on the "begin"
6211 ;; keyword, allow for the keyword and an extra character,
6212 ;; as this will be used when looking forward for the
6214 (save-excursion (forward-word 1) (1+ (point))))
6215 begin-string literal)
6216 (while (and (not foundp)
6217 (re-search-backward vhdl-defun-re nil 'move))
6218 ;; If we are in a literal, then try again.
6219 (if (or (= (preceding-char) ?_)
6222 (if (setq begin-string (vhdl-corresponding-defun))
6223 ;; This is a real defun keyword.
6224 ;; Find the corresponding "begin" keyword.
6225 ;; Look for the begin keyword.
6227 ;; Save the search start point.
6228 (setq last-forward (point))
6229 (while (and (not foundp)
6230 (search-forward begin-string last-backward t))
6231 (if (or (= (preceding-char) ?_)
6233 (setq literal (vhdl-in-literal))))
6234 ;; It wasn't a real keyword, so keep searching.
6235 (if (eq literal 'comment)
6237 (min (vhdl-point 'eol) last-backward))
6239 ;; We have found the begin keyword, loop will exit.
6240 (setq foundp (match-beginning 0)))
6242 ;; Go back to the defun keyword
6243 (goto-char last-forward)) ; end search for begin keyword
6245 ) ; end of the search for the defun keyword
6247 (setq count (1- count))
6249 (vhdl-keep-region-active)
6252 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6253 "Go to the beginning of the innermost VHDL statement.
6254 With prefix arg, go back N - 1 statements. If already at the
6255 beginning of a statement then go to the beginning of the preceding
6256 one. If within a string or comment, or next to a comment (only
6257 whitespace between), move by sentences instead of statements.
6259 When called from a program, this function takes 3 optional args: the
6260 prefix arg, a buffer position limit which is the farthest back to
6261 search, and an argument indicating an interactive call."
6262 (interactive "p\np")
6263 (let ((count (or count 1))
6264 (case-fold-search t)
6265 (lim (or lim (point-min)))
6270 (setq state (parse-partial-sexp (point) here nil nil)))
6271 (if (and interactive
6274 (looking-at (concat "[ \t]*" comment-start-skip))))
6275 (forward-sentence (- count))
6277 (vhdl-beginning-of-statement-1 lim)
6278 (setq count (1- count))))
6279 ;; its possible we've been left up-buf of lim
6280 (goto-char (max (point) lim))
6282 (vhdl-keep-region-active))
6284 (defconst vhdl-e-o-s-re
6285 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6287 (defun vhdl-end-of-statement ()
6288 "Very simple implementation."
6290 (re-search-forward vhdl-e-o-s-re))
6292 (defconst vhdl-b-o-s-re
6293 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6294 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6296 (defun vhdl-beginning-of-statement-1 (&optional lim)
6297 "Move to the start of the current statement, or the previous
6298 statement if already at the beginning of one."
6299 (let ((lim (or lim (point-min)))
6303 ;; go backwards one balanced expression, but be careful of
6304 ;; unbalanced paren being reached
6305 (if (not (vhdl-safe (progn (backward-sexp) t)))
6307 (backward-up-list 1)
6309 (vhdl-forward-syntactic-ws here)
6311 (while (and (not donep)
6313 ;; look backwards for a statement boundary
6314 (re-search-backward vhdl-b-o-s-re lim 'move))
6315 (if (or (= (preceding-char) ?_)
6319 ;; If we are looking at an open paren, then stop after it
6320 ((eq (following-char) ?\()
6322 (vhdl-forward-syntactic-ws here)
6324 ;; If we are looking at a close paren, then skip it
6325 ((eq (following-char) ?\))
6330 (progn (goto-char pos)
6331 (vhdl-forward-syntactic-ws here)
6333 ;; If we are looking at a semicolon, then stop
6334 ((eq (following-char) ?\;)
6337 (vhdl-forward-syntactic-ws here)
6339 ;; If we are looking at a "begin", then stop
6340 ((and (looking-at vhdl-begin-fwd-re)
6341 (/= (preceding-char) ?_)
6343 ;; If it's a leader "begin", then find the
6345 (if (looking-at vhdl-leader-re)
6347 ;; set a default stop point at the begin
6349 ;; is the start point inside the leader area ?
6350 (goto-char (vhdl-end-of-leader))
6351 (vhdl-forward-syntactic-ws here)
6352 (if (< (point) here)
6353 ;; start point was not inside leader area
6354 ;; set stop point at word after leader
6355 (setq pos (point))))
6357 (vhdl-forward-syntactic-ws here)
6361 ;; If we are looking at a "statement", then stop
6362 ((and (looking-at vhdl-statement-fwd-re)
6363 (/= (preceding-char) ?_)
6364 (vhdl-statement-p nil))
6366 ;; If we are looking at a case alternative key, then stop
6367 ((and (looking-at vhdl-case-alternative-re)
6368 (vhdl-case-alternative-p lim))
6370 ;; set a default stop point at the when
6372 ;; is the start point inside the case alternative key ?
6373 (looking-at vhdl-case-alternative-re)
6374 (goto-char (match-end 0))
6375 (vhdl-forward-syntactic-ws here)
6376 (if (< (point) here)
6377 ;; start point was not inside the case alternative key
6378 ;; set stop point at word after case alternative keyleader
6379 (setq pos (point))))
6382 ;; Bogus find, continue
6387 ;; Defuns for calculating the current syntactic state:
6389 (defun vhdl-get-library-unit (bod placeholder)
6390 "If there is an enclosing library unit at BOD, with its \"begin\"
6391 keyword at PLACEHOLDER, then return the library unit type."
6392 (let ((here (vhdl-point 'bol)))
6394 (goto-char placeholder)
6395 (vhdl-safe (vhdl-forward-sexp 1 bod))
6400 ((looking-at "e") 'entity)
6401 ((looking-at "a") 'architecture)
6402 ((looking-at "c") 'configuration)
6407 (vhdl-forward-syntactic-ws here)
6408 (if (looking-at "body\\b[^_]")
6409 'package-body 'package))))))
6412 (defun vhdl-get-block-state (&optional lim)
6413 "Finds and records all the closest opens.
6414 LIM is the furthest back we need to search (it should be the
6415 previous libunit keyword)."
6416 (let ((here (point))
6417 (lim (or lim (point-min)))
6418 keyword sexp-start sexp-mid sexp-end
6419 preceding-sexp containing-sexp
6420 containing-begin containing-mid containing-paren)
6422 ;; Find the containing-paren, and use that as the limit
6423 (if (setq containing-paren
6425 (narrow-to-region lim (point))
6426 (vhdl-safe (scan-lists (point) -1 1))))
6427 (setq lim containing-paren))
6428 ;; Look backwards for "begin" and "end" keywords.
6429 (while (and (> (point) lim)
6430 (not containing-sexp))
6431 (setq keyword (vhdl-backward-to-block lim))
6433 ((eq keyword 'begin)
6434 ;; Found a "begin" keyword
6435 (setq sexp-start (point))
6436 (setq sexp-mid (vhdl-corresponding-mid lim))
6437 (setq sexp-end (vhdl-safe
6439 (vhdl-forward-sexp 1 lim) (point))))
6440 (if (and sexp-end (<= sexp-end here))
6441 ;; we want to record this sexp, but we only want to
6442 ;; record the last-most of any of them before here
6444 (setq preceding-sexp sexp-start))
6445 ;; we're contained in this sexp so put sexp-start on
6447 (setq containing-sexp sexp-start)
6448 (setq containing-mid sexp-mid)
6449 (setq containing-begin t)))
6451 ;; Found an "end" keyword
6453 (setq sexp-end (point))
6456 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6457 (progn (backward-sexp) (point))))
6458 ;; we want to record this sexp, but we only want to
6459 ;; record the last-most of any of them before here
6461 (setq preceding-sexp sexp-start)))
6463 ;; Check if the containing-paren should be the containing-sexp
6464 (if (and containing-paren
6465 (or (null containing-sexp)
6466 (< containing-sexp containing-paren)))
6467 (setq containing-sexp containing-paren
6469 containing-begin nil
6470 containing-mid nil))
6471 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6475 (defconst vhdl-s-c-a-re
6476 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6478 (defun vhdl-skip-case-alternative (&optional lim)
6479 "Skip forward over case/when bodies, with optional maximal
6480 limit. If no next case alternative is found, nil is returned and
6481 point is not moved."
6482 (let ((lim (or lim (point-max)))
6485 (while (and (< (point) lim)
6487 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6489 (not (vhdl-in-literal)))
6490 (/= (match-beginning 0) here))
6492 (goto-char (match-beginning 0))
6494 ((and (looking-at "case")
6495 (re-search-forward "\\bis[^_]" lim t))
6497 (vhdl-forward-sexp))
6505 (defun vhdl-backward-skip-label (&optional lim)
6506 "Skip backward over a label, with optional maximal
6507 limit. If label is not found, nil is returned and point
6509 (let ((lim (or lim (point-min)))
6512 (vhdl-backward-syntactic-ws lim)
6513 (and (eq (preceding-char) ?:)
6516 (setq placeholder (point))
6517 (looking-at vhdl-label-key))))
6518 (goto-char placeholder))
6521 (defun vhdl-forward-skip-label (&optional lim)
6522 "Skip forward over a label, with optional maximal
6523 limit. If label is not found, nil is returned and point
6525 (let ((lim (or lim (point-max))))
6526 (if (looking-at vhdl-label-key)
6528 (goto-char (match-end 0))
6529 (vhdl-forward-syntactic-ws lim)))
6532 (defun vhdl-get-syntactic-context ()
6533 "Guess the syntactic description of the current line of VHDL code."
6537 (let* ((indent-point (point))
6538 (case-fold-search t)
6539 vec literal containing-sexp preceding-sexp
6540 containing-begin containing-mid containing-leader
6541 char-before-ip char-after-ip begin-after-ip end-after-ip
6542 placeholder lim library-unit
6545 ;; Reset the syntactic context
6546 (setq vhdl-syntactic-context nil)
6549 ;; Move to the start of the previous library unit, and
6550 ;; record the position of the "begin" keyword.
6551 (setq placeholder (vhdl-beginning-of-libunit))
6552 ;; The position of the "libunit" keyword gives us a gross
6557 ;; If there is a previous library unit, and we are enclosed by
6558 ;; it, then set the syntax accordingly.
6560 (setq library-unit (vhdl-get-library-unit lim placeholder))
6561 (vhdl-add-syntax library-unit lim))
6563 ;; Find the surrounding state.
6564 (if (setq vec (vhdl-get-block-state lim))
6566 (setq containing-sexp (aref vec 0))
6567 (setq preceding-sexp (aref vec 1))
6568 (setq containing-begin (aref vec 2))
6569 (setq containing-mid (aref vec 3))
6572 ;; set the limit on the farthest back we need to search
6573 (setq lim (if containing-sexp
6575 (goto-char containing-sexp)
6576 ;; set containing-leader if required
6577 (if (looking-at vhdl-leader-re)
6578 (setq containing-leader (vhdl-end-of-leader)))
6582 ;; cache char before and after indent point, and move point to
6583 ;; the most likely position to perform the majority of tests
6584 (goto-char indent-point)
6585 (skip-chars-forward " \t")
6586 (setq literal (vhdl-in-literal))
6587 (setq char-after-ip (following-char))
6588 (setq begin-after-ip (and
6590 (looking-at vhdl-begin-fwd-re)
6592 (setq end-after-ip (and
6594 (looking-at vhdl-end-fwd-re)
6596 (vhdl-backward-syntactic-ws lim)
6597 (setq char-before-ip (preceding-char))
6598 (goto-char indent-point)
6599 (skip-chars-forward " \t")
6601 ;; now figure out syntactic qualities of the current line
6603 ;; CASE 1: in a string or comment.
6604 ((memq literal '(string comment))
6605 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6606 ;; CASE 2: Line is at top level.
6607 ((null containing-sexp)
6608 ;; Find the point to which indentation will be relative
6610 (if (null preceding-sexp)
6612 ;; no preceding-sexp -> use the preceding statement
6613 (vhdl-beginning-of-statement-1 lim)
6615 ;; if there is a preceding-sexp then indent relative to it
6616 (goto-char preceding-sexp)
6617 ;; if not at boi, then the block-opening keyword is
6618 ;; probably following a label, so we need a different
6620 (if (/= (point) (vhdl-point 'boi))
6622 (vhdl-beginning-of-statement-1 lim)))
6623 ;; v-b-o-s could have left us at point-min
6626 (vhdl-forward-syntactic-ws indent-point))
6627 (setq placeholder (point)))
6629 ;; CASE 2A : we are looking at a block-open
6631 (vhdl-add-syntax 'block-open placeholder))
6632 ;; CASE 2B: we are looking at a block-close
6634 (vhdl-add-syntax 'block-close placeholder))
6635 ;; CASE 2C: we are looking at a top-level statement
6637 (vhdl-backward-syntactic-ws lim)
6639 (= (preceding-char) ?\;)))
6640 (vhdl-add-syntax 'statement placeholder))
6641 ;; CASE 2D: we are looking at a top-level statement-cont
6643 (vhdl-beginning-of-statement-1 lim)
6644 ;; v-b-o-s could have left us at point-min
6647 (vhdl-forward-syntactic-ws indent-point))
6648 (vhdl-add-syntax 'statement-cont (point)))
6650 ;; CASE 3: line is inside parentheses. Most likely we are
6651 ;; either in a subprogram argument (interface) list, or a
6652 ;; continued expression containing parentheses.
6653 ((null containing-begin)
6654 (vhdl-backward-syntactic-ws containing-sexp)
6656 ;; CASE 3A: we are looking at the arglist closing paren
6657 ((eq char-after-ip ?\))
6658 (goto-char containing-sexp)
6659 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6660 ;; CASE 3B: we are looking at the first argument in an empty
6662 ((eq char-before-ip ?\()
6663 (goto-char containing-sexp)
6664 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6665 ;; CASE 3C: we are looking at an arglist continuation line,
6666 ;; but the preceding argument is on the same line as the
6667 ;; opening paren. This case includes multi-line
6668 ;; expression paren groupings.
6669 ((and (save-excursion
6670 (goto-char (1+ containing-sexp))
6671 (skip-chars-forward " \t")
6673 (not (looking-at "--")))
6675 (vhdl-beginning-of-statement-1 containing-sexp)
6676 (skip-chars-backward " \t(")
6677 (<= (point) containing-sexp)))
6678 (goto-char containing-sexp)
6679 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6680 ;; CASE 3D: we are looking at just a normal arglist
6681 ;; continuation line
6682 (t (vhdl-beginning-of-statement-1 containing-sexp)
6683 (vhdl-forward-syntactic-ws indent-point)
6684 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6686 ;; CASE 4: A block mid open
6687 ((and begin-after-ip
6688 (looking-at containing-mid))
6689 (goto-char containing-sexp)
6690 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6691 (if (looking-at vhdl-trailer-re)
6693 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6694 (vhdl-backward-skip-label (vhdl-point 'boi))
6695 (vhdl-add-syntax 'block-open (point)))
6696 ;; CASE 5: block close brace
6698 (goto-char containing-sexp)
6699 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6700 (if (looking-at vhdl-trailer-re)
6702 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6703 (vhdl-backward-skip-label (vhdl-point 'boi))
6704 (vhdl-add-syntax 'block-close (point)))
6705 ;; CASE 6: A continued statement
6706 ((and (/= char-before-ip ?\;)
6707 ;; check it's not a trailer begin keyword, or a begin
6708 ;; keyword immediately following a label.
6709 (not (and begin-after-ip
6710 (or (looking-at vhdl-trailer-re)
6712 (vhdl-backward-skip-label containing-sexp)))))
6713 ;; check it's not a statement keyword
6714 (not (and (looking-at vhdl-statement-fwd-re)
6715 (vhdl-statement-p)))
6716 ;; see if the b-o-s is before the indent point
6719 (vhdl-beginning-of-statement-1 containing-sexp)
6720 ;; If we ended up after a leader, then this will
6721 ;; move us forward to the start of the first
6722 ;; statement. Note that a containing sexp here is
6723 ;; always a keyword, not a paren, so this will
6724 ;; have no effect if we hit the containing-sexp.
6725 (vhdl-forward-syntactic-ws indent-point)
6726 (setq placeholder (point))))
6727 ;; check it's not a block-intro
6728 (/= placeholder containing-sexp)
6729 ;; check it's not a case block-intro
6731 (goto-char placeholder)
6732 (or (not (looking-at vhdl-case-alternative-re))
6733 (> (match-end 0) indent-point))))
6734 ;; Make placeholder skip a label, but only if it puts us
6735 ;; before the indent point at the start of a line.
6736 (let ((new placeholder))
6737 (if (and (> indent-point
6739 (goto-char placeholder)
6740 (vhdl-forward-skip-label indent-point)
6741 (setq new (point))))
6744 (eq new (progn (back-to-indentation) (point)))))
6745 (setq placeholder new)))
6746 (vhdl-add-syntax 'statement-cont placeholder)
6748 (vhdl-add-syntax 'block-open)))
6749 ;; Statement. But what kind?
6750 ;; CASE 7: A case alternative key
6751 ((and (looking-at vhdl-case-alternative-re)
6752 (vhdl-case-alternative-p containing-sexp))
6753 ;; for a case alternative key, we set relpos to the first
6754 ;; non-whitespace char on the line containing the "case"
6756 (goto-char containing-sexp)
6757 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6758 (if (looking-at vhdl-trailer-re)
6759 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6760 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6761 ;; CASE 8: statement catchall
6763 ;; we know its a statement, but we need to find out if it is
6764 ;; the first statement in a block
6765 (if containing-leader
6766 (goto-char containing-leader)
6767 (goto-char containing-sexp)
6768 ;; Note that a containing sexp here is always a keyword,
6769 ;; not a paren, so skip over the keyword.
6771 ;; move to the start of the first statement
6772 (vhdl-forward-syntactic-ws indent-point)
6773 (setq placeholder (point))
6774 ;; we want to ignore case alternatives keys when skipping forward
6776 (while (looking-at vhdl-case-alternative-re)
6777 (setq incase-p (point))
6778 ;; we also want to skip over the body of the
6779 ;; case/when statement if that doesn't put us at
6780 ;; after the indent-point
6781 (while (vhdl-skip-case-alternative indent-point))
6782 ;; set up the match end
6783 (looking-at vhdl-case-alternative-re)
6784 (goto-char (match-end 0))
6785 ;; move to the start of the first case alternative statement
6786 (vhdl-forward-syntactic-ws indent-point)
6787 (setq placeholder (point)))
6789 ;; CASE 8A: we saw a case/when statement so we must be
6790 ;; in a switch statement. find out if we are at the
6791 ;; statement just after a case alternative key
6793 (= (point) indent-point))
6794 ;; relpos is the "when" keyword
6795 (vhdl-add-syntax 'statement-case-intro incase-p))
6796 ;; CASE 8B: any old statement
6797 ((< (point) indent-point)
6798 ;; relpos is the first statement of the block
6799 (vhdl-add-syntax 'statement placeholder)
6801 (vhdl-add-syntax 'block-open)))
6802 ;; CASE 8C: first statement in a block
6804 (goto-char containing-sexp)
6805 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6806 (if (looking-at vhdl-trailer-re)
6807 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6808 (vhdl-backward-skip-label (vhdl-point 'boi))
6809 (vhdl-add-syntax 'statement-block-intro (point))
6811 (vhdl-add-syntax 'block-open)))
6815 ;; now we need to look at any modifiers
6816 (goto-char indent-point)
6817 (skip-chars-forward " \t")
6818 (if (looking-at "--")
6819 (vhdl-add-syntax 'comment))
6820 (if (eq literal 'pound)
6821 (vhdl-add-syntax 'cpp-macro))
6822 ;; return the syntax
6823 vhdl-syntactic-context))))
6825 ;; Standard indentation line-ups:
6827 (defun vhdl-lineup-arglist (langelem)
6828 "Lineup the current arglist line with the arglist appearing just
6829 after the containing paren which starts the arglist."
6831 (let* ((containing-sexp
6833 ;; arglist-cont-nonempty gives relpos ==
6834 ;; to boi of containing-sexp paren. This
6835 ;; is good when offset is +, but bad
6836 ;; when it is vhdl-lineup-arglist, so we
6837 ;; have to special case a kludge here.
6838 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6841 (backward-up-list 1)
6842 (skip-chars-forward " \t" (vhdl-point 'eol)))
6843 (goto-char (cdr langelem)))
6845 (cs-curcol (save-excursion
6846 (goto-char (cdr langelem))
6850 (looking-at "[ \t]*)"))
6851 (progn (goto-char (match-end 0))
6854 (vhdl-forward-syntactic-ws)
6855 (- (current-column) cs-curcol))
6856 (goto-char containing-sexp)
6858 (let ((eol (vhdl-point 'eol))
6861 (skip-chars-forward " \t")
6863 (vhdl-forward-syntactic-ws)
6866 (- (current-column) cs-curcol)
6869 (defun vhdl-lineup-arglist-intro (langelem)
6870 "Lineup an arglist-intro line to just after the open paren."
6872 (let ((cs-curcol (save-excursion
6873 (goto-char (cdr langelem))
6875 (ce-curcol (save-excursion
6877 (backward-up-list 1)
6878 (skip-chars-forward " \t" (vhdl-point 'eol))
6880 (- ce-curcol cs-curcol -1))))
6882 (defun vhdl-lineup-comment (langelem)
6883 "Support old behavior for comment indentation. We look at
6884 vhdl-comment-only-line-offset to decide how to indent comment
6887 (back-to-indentation)
6888 ;; at or to the right of comment-column
6889 (if (>= (current-column) comment-column)
6890 (vhdl-comment-indent)
6891 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6893 (or (car-safe vhdl-comment-only-line-offset)
6894 vhdl-comment-only-line-offset)
6895 (or (cdr-safe vhdl-comment-only-line-offset)
6896 (car-safe vhdl-comment-only-line-offset)
6897 -1000 ;jam it against the left side
6900 (defun vhdl-lineup-statement-cont (langelem)
6901 "Line up statement-cont after the assignment operator."
6903 (let* ((relpos (cdr langelem))
6904 (assignp (save-excursion
6905 (goto-char (vhdl-point 'boi))
6906 (and (re-search-forward "\\(<\\|:\\)="
6907 (vhdl-point 'eol) t)
6908 (- (point) (vhdl-point 'boi)))))
6913 (while (and (not foundp)
6914 (< (point) (vhdl-point 'eol)))
6915 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6916 (if (vhdl-in-literal)
6918 (if (= (preceding-char) ?\()
6919 ;; skip over any parenthesized expressions
6920 (goto-char (min (vhdl-point 'eol)
6921 (scan-lists (point) 1 1)))
6922 ;; found an assignment operator (not at eol)
6923 (setq foundp (not (looking-at "\\s-*$"))))))
6925 ;; there's no assignment operator on the line
6927 ;; calculate indentation column after assign and ws, unless
6928 ;; our line contains an assignment operator
6932 (skip-chars-forward " \t")
6934 (- (current-column) assignp curcol))
6937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6938 ;; Progress reporting
6940 (defvar vhdl-progress-info nil
6941 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6943 (defun vhdl-update-progress-info (string pos)
6944 "Update progress information."
6945 (when (and vhdl-progress-info (not noninteractive)
6946 (< vhdl-progress-interval
6947 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6948 (let ((delta (- (aref vhdl-progress-info 1)
6949 (aref vhdl-progress-info 0))))
6951 (message (concat string "... (100%s)") "%")
6952 (message (concat string "... (%2d%s)")
6953 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6955 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6958 ;; Indentation commands
6960 (defun vhdl-electric-tab (&optional prefix-arg)
6961 "If preceeding character is part of a word or a paren then hippie-expand,
6962 else if right of non whitespace on line then insert tab,
6963 else if last command was a tab or return then dedent one step or if a comment
6964 toggle between normal indent and inline comment indent,
6965 else indent `correctly'."
6967 (vhdl-prepare-search-2
6969 ;; indent region if region is active
6970 ((and (not (featurep 'xemacs)) (use-region-p))
6971 (vhdl-indent-region (region-beginning) (region-end) nil))
6973 ((= (char-syntax (preceding-char)) ?w)
6974 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6976 (hippie-expand-only-buffers
6977 (or (and (boundp 'hippie-expand-only-buffers)
6978 hippie-expand-only-buffers)
6980 (vhdl-expand-abbrev prefix-arg)))
6981 ;; expand parenthesis
6982 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6983 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6985 (vhdl-expand-paren prefix-arg)))
6987 ((> (current-column) (current-indentation))
6989 ;; toggle comment indent
6990 ((and (looking-at "--")
6991 (or (eq last-command 'vhdl-electric-tab)
6992 (eq last-command 'vhdl-electric-return)))
6993 (cond ((= (current-indentation) 0) ; no indent
6995 (indent-according-to-mode))
6996 ((< (current-indentation) comment-column) ; normal indent
6997 (indent-to comment-column)
6998 (indent-according-to-mode))
6999 (t ; inline comment indent
7000 (delete-region (line-beginning-position) (point)))))
7002 ((and (>= (current-indentation) vhdl-basic-offset)
7003 (or (eq last-command 'vhdl-electric-tab)
7004 (eq last-command 'vhdl-electric-return)))
7005 (backward-delete-char-untabify vhdl-basic-offset nil))
7007 (t (indent-according-to-mode)))
7008 (setq this-command 'vhdl-electric-tab)))
7010 (defun vhdl-electric-return ()
7011 "newline-and-indent or indent-new-comment-line if in comment and preceding
7012 character is a space."
7014 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7015 (indent-new-comment-line)
7016 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7017 (vhdl-fix-case-word -1))
7018 (newline-and-indent)))
7020 (defun vhdl-indent-line ()
7021 "Indent the current line as VHDL code. Returns the amount of
7022 indentation change."
7024 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7025 (pos (- (point-max) (point)))
7028 ;; indent syntax-based
7029 (if (and (eq (caar syntax) 'comment)
7030 (>= (vhdl-get-offset (car syntax)) comment-column))
7031 ;; special case: comments at or right of comment-column
7032 (vhdl-get-offset (car syntax))
7033 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7034 ;; indent like previous nonblank line
7035 (save-excursion (beginning-of-line)
7036 (re-search-backward "^[^\n]" nil t)
7037 (current-indentation))))
7038 (shift-amt (- indent (current-indentation))))
7039 (and vhdl-echo-syntactic-information-p
7040 (message "syntax: %s, indent= %d" syntax indent))
7041 (unless (zerop shift-amt)
7042 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7045 (if (< (point) (vhdl-point 'boi))
7046 (back-to-indentation)
7047 ;; If initial point was within line's indentation, position after
7048 ;; the indentation. Else stay at same point in text.
7049 (when (> (- (point-max) pos) (point))
7050 (goto-char (- (point-max) pos))))
7051 (run-hooks 'vhdl-special-indent-hook)
7052 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7055 (defun vhdl-indent-region (beg end column)
7056 "Indent region as VHDL code.
7057 Adds progress reporting to `indent-region'."
7058 (interactive "r\nP")
7059 (when vhdl-progress-interval
7060 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7061 (count-lines (point-min) end) 0)))
7062 (indent-region beg end column)
7063 (when vhdl-progress-interval (message "Indenting...done"))
7064 (setq vhdl-progress-info nil))
7066 (defun vhdl-indent-buffer ()
7067 "Indent whole buffer as VHDL code.
7068 Calls `indent-region' for whole buffer and adds progress reporting."
7070 (vhdl-indent-region (point-min) (point-max) nil))
7072 (defun vhdl-indent-group ()
7073 "Indent group of lines between empty lines."
7075 (let ((beg (save-excursion
7076 (if (re-search-backward vhdl-align-group-separate nil t)
7078 (point-min-marker))))
7079 (end (save-excursion
7080 (if (re-search-forward vhdl-align-group-separate nil t)
7082 (point-max-marker)))))
7083 (vhdl-indent-region beg end nil)))
7085 (defun vhdl-indent-sexp (&optional endpos)
7086 "Indent each line of the list starting just after point.
7087 If optional arg ENDPOS is given, indent each line, stopping when
7088 ENDPOS is encountered."
7092 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7093 (indent-region beg end nil))))
7095 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7096 ;; Miscellaneous commands
7098 (defun vhdl-show-syntactic-information ()
7099 "Show syntactic information for current line."
7101 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7102 (vhdl-keep-region-active))
7104 ;; Verification and regression functions:
7106 (defun vhdl-regress-line (&optional arg)
7107 "Check syntactic information for current line."
7109 (let ((expected (save-excursion
7111 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7113 (read (current-buffer)))))
7114 (actual (vhdl-get-syntactic-context))
7116 ;; remove the library unit symbols
7120 (if (memq (car elt) '(entity configuration package
7121 package-body architecture))
7123 (setq expurgated (append expurgated (list elt))))))
7125 (if (and (not arg) expected (listp expected))
7126 (if (not (equal expected expurgated))
7127 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7130 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7132 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7133 (delete-region (point) (line-end-position)))
7135 (insert (format "%s" expurgated))))))
7136 (vhdl-keep-region-active))
7139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7140 ;;; Alignment, whitespace fixup, beautifying
7141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7143 (defconst vhdl-align-alist
7145 ;; after some keywords
7146 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7147 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7149 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7150 ;; after direction specifications
7151 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7152 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7153 ;; before "==", ":=", "=>", and "<="
7154 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7155 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7156 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7157 ;; before some keywords
7158 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7159 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7160 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7161 ;; before "=>" since "when/else ... =>" can occur
7162 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7164 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7165 It is searched in order. If REGEXP is found anywhere in the first
7166 line of a region to be aligned, ALIGN-PATTERN will be used for that
7167 region. ALIGN-PATTERN must include the whitespace to be expanded or
7168 contracted. It may also provide regexps for the text surrounding the
7169 whitespace. SUBEXP specifies which sub-expression of
7170 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7175 (defvar vhdl-align-try-all-clauses t
7176 "If REGEXP is not found on the first line of the region that clause
7177 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7179 (defun vhdl-do-group (function &optional spacing)
7180 "Apply FUNCTION on group of lines between empty lines."
7182 ;; search for group beginning
7183 ((beg (save-excursion
7184 (if (re-search-backward vhdl-align-group-separate nil t)
7185 (progn (beginning-of-line 2) (back-to-indentation) (point))
7187 ;; search for group end
7188 (end (save-excursion
7189 (if (re-search-forward vhdl-align-group-separate nil t)
7190 (progn (beginning-of-line) (point))
7193 (funcall function beg end spacing)))
7195 (defun vhdl-do-list (function &optional spacing)
7196 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7200 ;; search for beginning of balanced group of parentheses
7201 (setq beg (vhdl-re-search-backward "[()]" nil t))
7202 (while (looking-at ")")
7203 (forward-char) (backward-sexp)
7204 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7205 ;; search for end of balanced group of parentheses
7209 (goto-char (1+ beg))
7210 (skip-chars-forward " \t\n")
7211 (setq beg (point))))
7214 (funcall function beg end spacing)
7215 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7217 (defun vhdl-do-same-indent (function &optional spacing)
7218 "Apply FUNCTION to block of lines with same indent."
7219 (let ((indent (current-indentation))
7221 ;; search for first line with same indent
7223 (while (and (not (bobp))
7224 (or (looking-at "^\\s-*\\(--.*\\)?$")
7225 (= (current-indentation) indent)))
7226 (unless (looking-at "^\\s-*$")
7227 (back-to-indentation) (setq beg (point)))
7228 (beginning-of-line -0)))
7229 ;; search for last line with same indent
7231 (while (and (not (eobp))
7232 (or (looking-at "^\\s-*\\(--.*\\)?$")
7233 (= (current-indentation) indent)))
7234 (if (looking-at "^\\s-*$")
7235 (beginning-of-line 2)
7236 (beginning-of-line 2)
7237 (setq end (point)))))
7239 (funcall function beg end spacing)))
7241 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7242 "Attempt to align a range of lines based on the content of the
7243 lines. The definition of `alignment-list' determines the matching
7244 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7245 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7246 indentation is done before aligning."
7247 (interactive "r\np")
7248 (setq alignment-list (or alignment-list vhdl-align-alist))
7249 (setq spacing (or spacing 1))
7253 (setq end (point-marker))
7255 (setq bol (setq begin (progn (beginning-of-line) (point))))
7256 ; (untabify bol end)
7258 (indent-region bol end nil))))
7259 (let ((copy (copy-alist alignment-list)))
7260 (vhdl-prepare-search-2
7265 (eol (save-excursion (progn (end-of-line) (point)))))
7266 (setq element (nth 0 copy))
7267 (when (and (or (and (listp (car element))
7268 (memq major-mode (car element)))
7269 (eq major-mode (car element)))
7270 (or vhdl-align-try-all-clauses
7271 (re-search-forward (car (cdr element)) eol t)))
7272 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7273 (car (cdr (cdr (cdr element)))) spacing))
7274 (setq copy (cdr copy))))))))
7276 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7277 "Align a range of lines from BEGIN to END. The regular expression
7278 MATCH must match exactly one field: the whitespace to be
7279 contracted/expanded. The alignment column will equal the
7280 rightmost column of the widest whitespace block. SPACING is
7281 the amount of extra spaces to add to the calculated maximum required.
7282 SPACING defaults to 1 so that at least one space is inserted after
7283 the token in MATCH."
7284 (setq spacing (or spacing 1))
7285 (setq substr (or substr 1))
7287 (let (distance (max 0) (lines 0) bol eol width)
7288 ;; Determine the greatest whitespace distance to the alignment
7291 (setq eol (progn (end-of-line) (point))
7292 bol (setq begin (progn (beginning-of-line) (point))))
7295 (when (and (re-search-forward match eol t)
7296 (not (vhdl-in-literal)))
7297 (setq distance (- (match-beginning substr) bol))
7298 (when (> distance max)
7299 (setq max distance))))
7302 eol (save-excursion (end-of-line) (point)))
7303 (setq lines (1+ lines)))
7304 ;; Now insert enough maxs to push each assignment operator to
7305 ;; the same column. We need to use 'lines' as a counter, since
7306 ;; the location of the mark may change
7307 (goto-char (setq bol begin))
7308 (setq eol (save-excursion (end-of-line) (point)))
7310 (when (and (re-search-forward match eol t)
7311 (not (vhdl-in-literal)))
7312 (setq width (- (match-end substr) (match-beginning substr)))
7313 (setq distance (- (match-beginning substr) bol))
7314 (goto-char (match-beginning substr))
7316 (insert-char ? (+ (- max distance) spacing)))
7320 eol (save-excursion (end-of-line) (point)))
7321 (setq lines (1- lines))))))
7323 (defun vhdl-align-region-groups (beg end &optional spacing
7324 no-message no-comments)
7325 "Align region, treat groups of lines separately."
7326 (interactive "r\nP")
7331 (setq orig (point-marker))
7334 (setq end (point-marker))
7337 (when vhdl-progress-interval
7338 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7339 (count-lines (point-min) end) 0))))
7340 (vhdl-fixup-whitespace-region beg end t)
7342 (if (not vhdl-align-groups)
7343 ;; align entire region
7344 (progn (vhdl-align-region-1 beg end spacing)
7346 (vhdl-align-inline-comment-region-1 beg end)))
7348 (while (and (< beg end)
7349 (re-search-forward vhdl-align-group-separate end t))
7350 (setq pos (point-marker))
7351 (vhdl-align-region-1 beg pos spacing)
7352 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7353 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7358 (vhdl-align-region-1 beg end spacing)
7359 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7360 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7361 (when vhdl-indent-tabs-mode
7364 (when vhdl-progress-interval (message "Aligning...done"))
7365 (setq vhdl-progress-info nil)))))
7367 (defun vhdl-align-region (beg end &optional spacing)
7368 "Align region, treat blocks with same indent and argument lists separately."
7369 (interactive "r\nP")
7370 (if (not vhdl-align-same-indent)
7371 ;; align entire region
7372 (vhdl-align-region-groups beg end spacing)
7373 ;; align blocks with same indent and argument lists
7377 (when vhdl-progress-interval
7378 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7379 (count-lines (point-min) end) 0)))
7381 (setq end (point-marker))
7383 (while (< (point) end)
7384 ;; is argument list opening?
7385 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7386 (point) (vhdl-point 'eol)))))
7387 ;; determine region for argument list
7388 (progn (goto-char cur-beg)
7390 (setq cur-end (point))
7391 (beginning-of-line 2))
7392 ;; determine region with same indent
7393 (setq indent (current-indentation))
7394 (setq cur-beg (point))
7395 (setq cur-end (vhdl-point 'bonl))
7396 (beginning-of-line 2)
7397 (while (and (< (point) end)
7398 (or (looking-at "^\\s-*\\(--.*\\)?$")
7399 (= (current-indentation) indent))
7401 (nth 0 (parse-partial-sexp
7402 (point) (vhdl-point 'eol)))) 0))
7403 (unless (looking-at "^\\s-*$")
7404 (setq cur-end (vhdl-point 'bonl)))
7405 (beginning-of-line 2)))
7407 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7408 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7409 (when vhdl-progress-interval (message "Aligning...done"))
7410 (setq vhdl-progress-info nil)))))
7412 (defun vhdl-align-group (&optional spacing)
7413 "Align group of lines between empty lines."
7415 (vhdl-do-group 'vhdl-align-region spacing))
7417 (defun vhdl-align-list (&optional spacing)
7418 "Align the lines of a list surrounded by a balanced group of parentheses."
7420 (vhdl-do-list 'vhdl-align-region-groups spacing))
7422 (defun vhdl-align-same-indent (&optional spacing)
7423 "Align block of lines with same indent."
7425 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7427 (defun vhdl-align-declarations (&optional spacing)
7428 "Align the lines within the declarative part of a design unit."
7431 (vhdl-prepare-search-2
7433 ;; search for declarative part
7434 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7435 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7437 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7438 (setq end (point)))))
7440 (vhdl-align-region-groups beg end spacing)
7441 (error "ERROR: Not within the declarative part of a design unit"))))
7443 (defun vhdl-align-buffer ()
7446 (vhdl-align-region (point-min) (point-max)))
7448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7449 ;; Align inline comments
7451 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7452 "Align inline comments in region."
7454 (let ((start-max comment-column)
7456 comment-list start-list tmp-list start length
7457 cur-start prev-start no-code)
7458 (setq spacing (or spacing 2))
7459 (vhdl-prepare-search-2
7461 ;; search for comment start positions and lengths
7462 (while (< (point) end)
7463 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7464 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7465 (not (save-excursion (goto-char (match-beginning 2))
7466 (vhdl-in-literal))))
7467 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7468 (setq length (- (match-end 2) (match-beginning 2)))
7469 (setq start-max (max start start-max))
7470 (setq length-max (max length length-max))
7471 (setq comment-list (cons (cons start length) comment-list)))
7472 (beginning-of-line 2))
7474 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7475 ;; reduce start positions
7476 (setq start-list (list (caar comment-list)))
7477 (setq comment-list (cdr comment-list))
7479 (unless (or (= (caar comment-list) (car start-list))
7480 (<= (+ (car start-list) (cdar comment-list))
7481 end-comment-column))
7482 (setq start-list (cons (caar comment-list) start-list)))
7483 (setq comment-list (cdr comment-list)))
7484 ;; align lines as nicely as possible
7486 (while (< (point) end)
7487 (setq cur-start nil)
7488 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7489 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7490 (not (save-excursion
7491 (goto-char (match-beginning 3))
7492 (vhdl-in-literal))))
7493 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7494 (>= (- (match-end 2) (match-beginning 2))
7496 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7497 (setq length (- (match-end 3) (match-beginning 3)))
7498 (setq no-code (= (match-beginning 1) (match-end 1)))
7499 ;; insert minimum whitespace
7500 (goto-char (match-end 2))
7501 (delete-region (match-beginning 2) (match-end 2))
7502 (insert-char ?\ spacing)
7503 (setq tmp-list start-list)
7504 ;; insert additional whitespace to align
7507 ;; align comment-only line to inline comment of previous line
7508 ((and no-code prev-start
7509 (<= length (- end-comment-column prev-start)))
7511 ;; align all comments at `start-max' if this is possible
7512 ((<= (+ start-max length-max) end-comment-column)
7514 ;; align at `comment-column' if possible
7515 ((and (<= start comment-column)
7516 (<= length (- end-comment-column comment-column)))
7518 ;; align at left-most possible start position otherwise
7520 (while (and tmp-list (< (car tmp-list) start))
7521 (setq tmp-list (cdr tmp-list)))
7523 (indent-to cur-start))
7524 (setq prev-start cur-start)
7525 (beginning-of-line 2))))))
7527 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7528 "Align inline comments within a region. Groups of code lines separated by
7529 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7530 (interactive "r\nP")
7535 (setq orig (point-marker))
7538 (setq end (point-marker))
7540 (unless no-message (message "Aligning inline comments..."))
7542 (if (not vhdl-align-groups)
7543 ;; align entire region
7544 (vhdl-align-inline-comment-region-1 beg end spacing)
7546 (while (and (< beg end)
7547 (re-search-forward vhdl-align-group-separate end t))
7548 (setq pos (point-marker))
7549 (vhdl-align-inline-comment-region-1 beg pos spacing)
7554 (vhdl-align-inline-comment-region-1 beg end spacing)))
7555 (when vhdl-indent-tabs-mode
7557 (unless no-message (message "Aligning inline comments...done")))))
7559 (defun vhdl-align-inline-comment-group (&optional spacing)
7560 "Align inline comments within a group of lines between empty lines."
7563 (let ((start (point))
7565 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7566 (point-marker) (point-max)))
7568 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7569 (point) (point-min)))
7571 (message "Aligning inline comments...")
7572 (vhdl-align-inline-comment-region-1 beg end)
7573 (when vhdl-indent-tabs-mode
7575 (message "Aligning inline comments...done"))))
7577 (defun vhdl-align-inline-comment-buffer ()
7578 "Align inline comments within buffer. Groups of code lines separated by
7579 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7581 (vhdl-align-inline-comment-region (point-min) (point-max)))
7583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7586 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7587 "Fixup whitespace in region. Surround operator symbols by one space,
7588 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7589 end of line, do nothing in comments and strings."
7591 (unless no-message (message "Fixing up whitespace..."))
7594 (setq end (point-marker))
7595 ;; have no space before and one space after `,' and ';'
7597 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7598 (if (match-string 1)
7599 (goto-char (match-end 1))
7600 (replace-match "\\3 " nil nil nil 3)))
7601 ;; have no space after `('
7603 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7604 (if (match-string 1)
7605 (goto-char (match-end 1))
7606 (replace-match "\\2")))
7607 ;; have no space before `)'
7609 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7610 (if (match-string 1)
7611 (goto-char (match-end 1))
7612 (replace-match "\\2")))
7613 ;; surround operator symbols by one space
7615 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7616 (if (match-string 1)
7617 (goto-char (match-end 1))
7618 (replace-match "\\3 \\4 \\5")
7619 (goto-char (match-end 2))))
7620 ;; eliminate multiple spaces and spaces at end of line
7622 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7623 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7624 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7625 (progn (replace-match "" nil nil) t))
7626 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7627 (progn (replace-match ";" nil nil) t))
7628 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7629 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7630 (progn (replace-match " " nil nil) t))
7631 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7632 (progn (replace-match " " nil nil) t))
7633 ; (re-search-forward "[^ \t-]+" end t))))
7634 (re-search-forward "[^ \t\"-]+" end t))))
7635 (unless no-message (message "Fixing up whitespace...done")))
7637 (defun vhdl-fixup-whitespace-buffer ()
7638 "Fixup whitespace in buffer. Surround operator symbols by one space,
7639 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7640 end of line, do nothing in comments."
7642 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7644 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7647 (defun vhdl-beautify-region (beg end)
7648 "Beautify region by applying indentation, whitespace fixup, alignment, and
7649 case fixing to a region. Calls functions `vhdl-indent-buffer',
7650 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7651 `vhdl-fix-case-buffer'."
7653 (setq end (save-excursion (goto-char end) (point-marker)))
7654 (vhdl-indent-region beg end nil)
7655 (let ((vhdl-align-groups t))
7656 (vhdl-align-region beg end))
7657 (vhdl-fix-case-region beg end))
7659 (defun vhdl-beautify-buffer ()
7660 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7661 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7664 (vhdl-beautify-region (point-min) (point-max))
7665 (when noninteractive (save-buffer)))
7667 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7670 (defun vhdl-fill-region (beg end &optional arg)
7671 "Fill lines for a region of code."
7672 (interactive "r\np")
7675 (let ((margin (if arg (current-indentation) (current-column))))
7677 (setq end (point-marker))
7678 ;; remove inline comments, newlines and whitespace
7679 (vhdl-comment-kill-region beg end)
7680 (vhdl-comment-kill-inline-region beg end)
7681 (subst-char-in-region beg (1- end) ?\n ?\ )
7682 (vhdl-fixup-whitespace-region beg end)
7683 ;; wrap and end-comment-column
7685 (while (re-search-forward "\\s-" end t)
7686 (when(> (current-column) vhdl-end-comment-column)
7688 (when (re-search-backward "\\s-" beg t)
7689 (replace-match "\n")
7690 (indent-to margin)))))))
7692 (defun vhdl-fill-group ()
7693 "Fill group of lines between empty lines."
7695 (vhdl-do-group 'vhdl-fill-region))
7697 (defun vhdl-fill-list ()
7698 "Fill the lines of a list surrounded by a balanced group of parentheses."
7700 (vhdl-do-list 'vhdl-fill-region))
7702 (defun vhdl-fill-same-indent ()
7703 "Fill the lines of block of lines with same indent."
7705 (vhdl-do-same-indent 'vhdl-fill-region))
7708 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7709 ;;; Code updating/fixing
7710 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7713 ;; Sensitivity list update
7716 ;; - no sensitivity list is generated for processes with wait statements
7717 ;; - otherwise, do the following:
7718 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7719 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7720 ;; manually entered global signals)
7721 ;; 3. signals from 1. and 2. form the list of visible signals
7722 ;; 4. search for if/elsif conditions containing an event (sequential code)
7723 ;; 5. scan for strings that are within syntactical regions where signals are
7724 ;; read but not within sequential code, and that correspond to visible
7726 ;; 6. replace sensitivity list by list of signals from 5.
7728 (defun vhdl-update-sensitivity-list-process ()
7729 "Update sensitivity list of current process."
7732 (vhdl-prepare-search-2
7734 ;; look whether in process
7735 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7736 (equal (upcase (match-string 2)) "PROCESS")
7737 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7738 (error "ERROR: Not within a process")
7739 (message "Updating sensitivity list...")
7740 (vhdl-update-sensitivity-list)
7741 (message "Updating sensitivity list...done")))))
7743 (defun vhdl-update-sensitivity-list-buffer ()
7744 "Update sensitivity list of all processes in current buffer."
7747 (vhdl-prepare-search-2
7748 (goto-char (point-min))
7749 (message "Updating sensitivity lists...")
7750 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7751 (goto-char (match-beginning 0))
7752 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7753 (message "Updating sensitivity lists...done"))))
7755 (defun vhdl-update-sensitivity-list ()
7756 "Update sensitivity list."
7757 (let ((proc-beg (point))
7758 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7759 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7762 ;; search for wait statement (no sensitivity list allowed)
7763 ((progn (goto-char proc-mid)
7764 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7765 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7766 ;; combinational process (update sensitivity list)
7769 ;; scan for visible signals
7770 ((visible-list (vhdl-get-visible-signals))
7771 ;; define syntactic regions where signals are read
7773 '(;; right-hand side of signal/variable assignment
7774 ;; (special case: "<=" is relational operator in a condition)
7775 ((re-search-forward "[<:]=" proc-end t)
7776 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7778 ((re-search-forward "^\\s-*if\\>" proc-end t)
7779 (re-search-forward "\\<then\\>" proc-end t))
7781 ((re-search-forward "\\<elsif\\>" proc-end t)
7782 (re-search-forward "\\<then\\>" proc-end t))
7783 ;; while loop condition
7784 ((re-search-forward "^\\s-*while\\>" proc-end t)
7785 (re-search-forward "\\<loop\\>" proc-end t))
7786 ;; exit/next condition
7787 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7788 (re-search-forward ";" proc-end t))
7790 ((re-search-forward "\\<assert\\>" proc-end t)
7791 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7793 ((re-search-forward "^\\s-*case\\>" proc-end t)
7794 (re-search-forward "\\<is\\>" proc-end t))
7795 ;; parameter list of procedure call
7796 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7798 (progn (backward-char) (forward-sexp)
7799 (while (looking-at "(") (forward-sexp)) (point)))))
7800 name read-list sens-list signal-list
7801 sens-beg sens-end beg end margin)
7802 ;; scan for signals in old sensitivity list
7803 (goto-char proc-beg)
7804 (re-search-forward "\\<process\\>" proc-mid t)
7805 (if (not (looking-at "[ \t\n]*("))
7806 (setq sens-beg (point))
7807 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7808 (goto-char (match-end 1))
7810 (setq sens-end (1- (point)))
7811 (goto-char sens-beg)
7812 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7814 (cons (downcase (match-string 0)) sens-list))
7815 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7816 (setq signal-list (append visible-list sens-list))
7817 ;; search for sequential parts
7818 (goto-char proc-mid)
7819 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7820 (setq end (re-search-forward "\\<then\\>" proc-end t))
7821 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7825 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7826 (beginning-of-line)))
7827 ;; scan for signals read in process
7828 (while scan-regions-list
7829 (goto-char proc-mid)
7830 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7831 (setq end (eval (nth 1 (car scan-regions-list)))))
7833 (unless (or (vhdl-in-literal)
7834 (and seq-region-list
7835 (let ((tmp-list seq-region-list))
7836 (while (and tmp-list
7837 (< (point) (caar tmp-list)))
7838 (setq tmp-list (cdr tmp-list)))
7839 (and tmp-list (< (point) (cdar tmp-list))))))
7840 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7841 (setq name (match-string 1))
7842 (when (and (not (match-string 4)) ; not when formal parameter
7843 (not (and (match-string 3) ; not event attribute
7844 (not (member (downcase (match-string 3))
7845 '("event" "last_event" "transaction")))))
7846 (member (downcase name) signal-list))
7847 (unless (member-ignore-case name read-list)
7848 (setq read-list (cons name read-list))))
7849 (goto-char (match-end 1)))))
7850 (setq scan-regions-list (cdr scan-regions-list)))
7851 ;; update sensitivity list
7852 (goto-char sens-beg)
7854 (delete-region sens-beg sens-end)
7856 (insert " ()") (backward-char)))
7857 (setq read-list (sort read-list 'string<))
7859 (setq margin (current-column))
7860 (insert (car read-list))
7861 (setq read-list (cdr read-list))
7864 (if (<= (+ (current-column) (length (car read-list)) 2)
7867 (insert "\n") (indent-to margin))
7868 (insert (car read-list))
7869 (setq read-list (cdr read-list)))))))))
7871 (defun vhdl-get-visible-signals ()
7872 "Get all signals visible in the current block."
7873 (let (beg end signal-list entity-name file-name)
7874 (vhdl-prepare-search-2
7877 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7878 (not (equal "END" (upcase (match-string 1))))
7879 (setq entity-name (match-string 2)))
7880 (error "ERROR: Not within an architecture")))
7881 ;; search for signals declared in entity port clause
7883 (goto-char (point-min))
7884 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7886 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7887 "." (file-name-extension (buffer-file-name)))))
7890 (vhdl-prepare-search-2
7891 (goto-char (point-min))
7892 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7893 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7894 (when (setq beg (re-search-forward
7895 "^\\s-*port[ \t\n]*("
7897 (re-search-forward "^end\\>" nil t)) t))
7898 (setq end (save-excursion
7899 (backward-char) (forward-sexp) (point)))
7900 (vhdl-forward-syntactic-ws)
7901 (while (< (point) end)
7902 (when (looking-at "signal[ \t\n]+")
7903 (goto-char (match-end 0)))
7904 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7906 (cons (downcase (match-string 1)) signal-list))
7907 (goto-char (match-end 0))
7908 (vhdl-forward-syntactic-ws))
7909 (re-search-forward ";" end 1)
7910 (vhdl-forward-syntactic-ws)))))))
7911 ;; search for signals declared in architecture declarative part
7913 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7914 (not (equal "END" (upcase (match-string 1))))
7915 (setq end (re-search-forward "^begin\\>" nil t))))
7916 (error "ERROR: No architecture declarative part found")
7917 ;; scan for all declared signal and alias names
7919 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7920 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7921 (if (match-string 2)
7923 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7925 (cons (downcase (match-string 1)) signal-list))
7926 (goto-char (match-end 0)))
7927 ;; scan alias name, check is alias of (declared) signal
7928 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7929 (member (downcase (match-string 2)) signal-list))
7931 (cons (downcase (match-string 1)) signal-list))
7932 (goto-char (match-end 0))))
7933 (setq beg (point))))))
7934 ;; search for signals declared in surrounding block declarative parts
7936 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7938 (goto-char (match-end 2))
7939 (vhdl-backward-sexp)
7940 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7942 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7943 ;; scan for all declared signal names
7945 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7946 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7947 (if (match-string 2)
7949 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7951 (cons (downcase (match-string 1)) signal-list))
7952 (goto-char (match-end 0)))
7953 ;; scan alias name, check is alias of (declared) signal
7954 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7955 (member (downcase (match-string 2)) signal-list))
7957 (cons (downcase (match-string 1)) signal-list))
7958 (goto-char (match-end 0))))))
7962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7963 ;; Generic/port clause fixing
7965 (defun vhdl-fix-clause ()
7966 "Fix closing parenthesis within generic/port clause."
7969 (vhdl-prepare-search-2
7972 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7973 (error "ERROR: Not within a generic/port clause")
7974 ;; search for end of clause
7975 (goto-char (match-end 0))
7976 (setq beg (1- (point)))
7977 (vhdl-forward-syntactic-ws)
7978 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7979 (goto-char (1- (match-end 0)))
7980 (setq end (point-marker))
7982 (vhdl-forward-syntactic-ws))
7984 (when (> pos (save-excursion (end-of-line) (point)))
7985 (error "ERROR: Not within a generic/port clause"))
7986 ;; delete closing parenthesis on separate line (not supported style)
7987 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7989 (vhdl-backward-syntactic-ws)
7990 (setq end (point-marker))
7992 ;; delete superfluous parentheses
7993 (while (progn (goto-char beg)
7994 (condition-case () (forward-sexp)
7995 (error (goto-char (point-max))))
7998 ;; add closing parenthesis
7999 (when (> (point) end)
8003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8006 (defun vhdl-remove-trailing-spaces ()
8007 "Remove trailing spaces in the whole buffer."
8011 (goto-char (point-min))
8012 (while (re-search-forward "[ \t]+$" (point-max) t)
8013 (unless (vhdl-in-literal)
8014 (replace-match "" nil nil))))))
8017 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8019 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8021 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8022 "Syntax of prompt inserted by template generators.")
8024 (defvar vhdl-template-invoked-by-hook nil
8025 "Indicates whether a template has been invoked by a hook or by key or menu.
8026 Used for undoing after template abortion.")
8028 ;; correct different behavior of function `unread-command-events' in XEmacs
8029 (defun vhdl-character-to-event (arg))
8030 (defalias 'vhdl-character-to-event
8031 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8033 (defun vhdl-work-library ()
8034 "Return the working library name of the current project or \"work\" if no
8035 project is defined."
8036 (vhdl-resolve-env-variable
8037 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8040 ;; Enabling/disabling
8042 (define-minor-mode vhdl-electric-mode
8043 "Toggle VHDL electric mode.
8044 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8047 (define-minor-mode vhdl-stutter-mode
8048 "Toggle VHDL stuttering mode.
8049 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8052 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8055 (defun vhdl-electric-dash (count)
8056 "-- starts a comment, --- draws a horizontal line,
8057 ---- starts a display comment."
8059 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8061 ((and abbrev-start-location (= abbrev-start-location (point)))
8062 (setq abbrev-start-location nil)
8063 (goto-char last-abbrev-location)
8064 (beginning-of-line nil)
8065 (vhdl-comment-display))
8066 ((/= (preceding-char) ?-) ; standard dash (minus)
8067 (self-insert-command count))
8068 (t (self-insert-command count)
8069 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8070 (let ((next-input (read-char)))
8071 (if (= next-input ?-) ; triple dash
8073 (vhdl-comment-display-line)
8075 "Enter '-' for display comment, else continue coding")
8076 (let ((next-input (read-char)))
8077 (if (= next-input ?-) ; four dashes
8078 (vhdl-comment-display t)
8079 (setq unread-command-events ; pushback the char
8080 (list (vhdl-character-to-event next-input))))))
8081 (setq unread-command-events ; pushback the char
8082 (list (vhdl-character-to-event next-input)))
8083 (vhdl-comment-insert)))))
8084 (self-insert-command count)))
8086 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8088 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8089 (if (= (preceding-char) ?\()
8090 (progn (delete-char -1) (insert-char ?\[ 1))
8091 (insert-char ?\( 1))
8092 (self-insert-command count)))
8094 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8096 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8098 (if (= (preceding-char) ?\))
8099 (progn (delete-char -1) (insert-char ?\] 1))
8100 (insert-char ?\) 1))
8101 (blink-matching-open))
8102 (self-insert-command count)))
8104 (defun vhdl-electric-quote (count) "'' --> \""
8106 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8107 (if (= (preceding-char) last-input-event)
8108 (progn (delete-char -1) (insert-char ?\" 1))
8109 (insert-char ?\' 1))
8110 (self-insert-command count)))
8112 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8114 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8115 (cond ((= (preceding-char) last-input-event)
8116 (progn (delete-char -1)
8117 (unless (eq (preceding-char) ? ) (insert " "))
8119 (setq this-command 'vhdl-electric-colon)))
8121 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8122 (progn (delete-char -1) (insert "= ")))
8123 (t (insert-char ?\; 1)))
8124 (self-insert-command count)))
8126 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8128 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8129 (cond ((= (preceding-char) last-input-event)
8130 (progn (delete-char -1)
8131 (unless (eq (preceding-char) ? ) (insert " "))
8133 (t (insert-char ?\, 1)))
8134 (self-insert-command count)))
8136 (defun vhdl-electric-period (count) "'..' --> ' => '"
8138 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8139 (cond ((= (preceding-char) last-input-event)
8140 (progn (delete-char -1)
8141 (unless (eq (preceding-char) ? ) (insert " "))
8143 (t (insert-char ?\. 1)))
8144 (self-insert-command count)))
8146 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8148 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8149 (cond ((= (preceding-char) last-input-event)
8150 (progn (delete-char -1)
8151 (unless (eq (preceding-char) ? ) (insert " "))
8153 (t (insert-char ?\= 1)))
8154 (self-insert-command count)))
8156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8159 (defun vhdl-template-paired-parens ()
8160 "Insert a pair of round parentheses, placing point between them."
8165 (defun vhdl-template-alias ()
8166 "Insert alias declaration."
8168 (let ((start (point)))
8169 (vhdl-insert-keyword "ALIAS ")
8170 (when (vhdl-template-field "name" nil t start (point))
8172 (unless (vhdl-template-field
8173 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8176 (vhdl-insert-keyword " IS ")
8177 (vhdl-template-field "name" ";")
8178 (vhdl-comment-insert-inline))))
8180 (defun vhdl-template-architecture ()
8181 "Insert architecture."
8183 (let ((margin (current-indentation))
8186 (vhdl-insert-keyword "ARCHITECTURE ")
8187 (when (setq arch-name
8188 (vhdl-template-field "name" nil t start (point)))
8189 (vhdl-insert-keyword " OF ")
8191 (vhdl-prepare-search-1
8192 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8193 (insert (match-string 1))
8194 (vhdl-template-field "entity name"))
8195 (vhdl-insert-keyword " IS\n")
8196 (vhdl-template-begin-end
8197 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8198 (memq vhdl-insert-empty-lines '(unit all))))))
8200 (defun vhdl-template-array (kind &optional secondary)
8201 "Insert array type definition."
8203 (let ((start (point)))
8204 (vhdl-insert-keyword "ARRAY (")
8205 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8207 (vhdl-insert-keyword ") OF ")
8208 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8209 (vhdl-insert-keyword ";"))))
8211 (defun vhdl-template-assert ()
8212 "Insert an assertion statement."
8214 (let ((start (point)))
8215 (vhdl-insert-keyword "ASSERT ")
8216 (when vhdl-conditions-in-parenthesis (insert "("))
8217 (when (vhdl-template-field "condition (negated)" nil t start (point))
8218 (when vhdl-conditions-in-parenthesis (insert ")"))
8219 (setq start (point))
8220 (vhdl-insert-keyword " REPORT ")
8221 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8222 (delete-region start (point)))
8223 (setq start (point))
8224 (vhdl-insert-keyword " SEVERITY ")
8225 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8226 (delete-region start (point)))
8229 (defun vhdl-template-attribute ()
8230 "Insert an attribute declaration or specification."
8232 (if (eq (vhdl-decision-query
8233 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8234 (vhdl-template-attribute-spec)
8235 (vhdl-template-attribute-decl)))
8237 (defun vhdl-template-attribute-decl ()
8238 "Insert an attribute declaration."
8240 (let ((start (point)))
8241 (vhdl-insert-keyword "ATTRIBUTE ")
8242 (when (vhdl-template-field "name" " : " t start (point))
8243 (vhdl-template-field "type" ";")
8244 (vhdl-comment-insert-inline))))
8246 (defun vhdl-template-attribute-spec ()
8247 "Insert an attribute specification."
8249 (let ((start (point)))
8250 (vhdl-insert-keyword "ATTRIBUTE ")
8251 (when (vhdl-template-field "name" nil t start (point))
8252 (vhdl-insert-keyword " OF ")
8253 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8254 (vhdl-template-field "entity class")
8255 (vhdl-insert-keyword " IS ")
8256 (vhdl-template-field "expression" ";"))))
8258 (defun vhdl-template-block ()
8261 (let ((margin (current-indentation))
8264 (vhdl-insert-keyword ": BLOCK ")
8266 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8270 (if (vhdl-template-field "[guard expression]" nil t)
8273 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8275 (vhdl-template-begin-end "BLOCK" label margin)
8276 (vhdl-comment-block))))
8278 (defun vhdl-template-block-configuration ()
8279 "Insert a block configuration statement."
8281 (let ((margin (current-indentation))
8283 (vhdl-insert-keyword "FOR ")
8284 (when (vhdl-template-field "block name" nil t start (point))
8285 (vhdl-insert-keyword "\n\n")
8287 (vhdl-insert-keyword "END FOR;")
8289 (indent-to (+ margin vhdl-basic-offset)))))
8291 (defun vhdl-template-break ()
8292 "Insert a break statement."
8295 (vhdl-insert-keyword "BREAK")
8296 (setq position (point))
8299 (progn (vhdl-insert-keyword "FOR ")
8300 (if (vhdl-template-field "[quantity name]" " USE " t)
8301 (progn (vhdl-template-field "quantity name" " => ") t)
8302 (delete-region (point)
8303 (progn (forward-word -1) (point)))
8305 (vhdl-template-field "[quantity name]" " => " t))
8306 (vhdl-template-field "expression")
8307 (setq position (point))
8309 (delete-region position (point))
8310 (unless (vhdl-sequential-statement-p)
8311 (vhdl-insert-keyword " ON ")
8312 (if (vhdl-template-field "[sensitivity list]" nil t)
8313 (setq position (point))
8314 (delete-region position (point))))
8315 (vhdl-insert-keyword " WHEN ")
8316 (when vhdl-conditions-in-parenthesis (insert "("))
8317 (if (vhdl-template-field "[condition]" nil t)
8318 (when vhdl-conditions-in-parenthesis (insert ")"))
8319 (delete-region position (point)))
8322 (defun vhdl-template-case (&optional kind)
8323 "Insert a case statement."
8325 (let ((margin (current-indentation))
8328 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8329 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8330 (vhdl-insert-keyword "CASE ")
8331 (vhdl-insert-keyword ": CASE ")
8333 (setq label (vhdl-template-field "[label]" nil t))
8334 (unless label (delete-char 2))
8337 (when (vhdl-template-field "expression" nil t start (point))
8338 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8340 (vhdl-insert-keyword "END CASE")
8341 (when label (insert " " label))
8344 (indent-to (+ margin vhdl-basic-offset))
8345 (vhdl-insert-keyword "WHEN ")
8346 (let ((position (point)))
8348 (indent-to (+ margin vhdl-basic-offset))
8349 (vhdl-insert-keyword "WHEN OTHERS => null;")
8350 (goto-char position)))))
8352 (defun vhdl-template-case-is ()
8353 "Insert a sequential case statement."
8355 (vhdl-template-case 'is))
8357 (defun vhdl-template-case-use ()
8358 "Insert a simultaneous case statement."
8360 (vhdl-template-case 'use))
8362 (defun vhdl-template-component ()
8363 "Insert a component declaration."
8365 (vhdl-template-component-decl))
8367 (defun vhdl-template-component-conf ()
8368 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8369 since these are almost equivalent)."
8371 (let ((margin (current-indentation))
8372 (result (vhdl-template-configuration-spec t)))
8376 (vhdl-insert-keyword "END FOR;")
8377 (when (eq result 'no-use)
8378 (end-of-line -0)))))
8380 (defun vhdl-template-component-decl ()
8381 "Insert a component declaration."
8383 (let ((margin (current-indentation))
8386 (vhdl-insert-keyword "COMPONENT ")
8387 (when (setq name (vhdl-template-field "name" nil t start (point)))
8388 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8391 (vhdl-insert-keyword "END COMPONENT")
8392 (unless (vhdl-standard-p '87) (insert " " name))
8394 (setq end-column (current-column))
8396 (indent-to (+ margin vhdl-basic-offset))
8397 (vhdl-template-generic-list t t)
8399 (indent-to (+ margin vhdl-basic-offset))
8400 (vhdl-template-port-list t)
8401 (beginning-of-line 2)
8402 (forward-char end-column))))
8404 (defun vhdl-template-component-inst ()
8405 "Insert a component instantiation statement."
8407 (let ((margin (current-indentation))
8410 (when (vhdl-template-field "instance label" nil t start (point))
8412 (if (not (vhdl-use-direct-instantiation))
8413 (vhdl-template-field "component name")
8414 ;; direct instantiation
8415 (setq unit (vhdl-template-field
8416 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8417 (setq unit (upcase (or unit "")))
8418 (cond ((equal unit "ENTITY")
8419 (vhdl-template-field "library name" "." nil nil nil nil
8420 (vhdl-work-library))
8421 (vhdl-template-field "entity name" "(")
8422 (if (vhdl-template-field "[architecture name]" nil t)
8425 ((equal unit "CONFIGURATION")
8426 (vhdl-template-field "library name" "." nil nil nil nil
8427 (vhdl-work-library))
8428 (vhdl-template-field "configuration name"))
8429 (t (vhdl-template-field "component name"))))
8431 (indent-to (+ margin vhdl-basic-offset))
8432 (setq position (point))
8433 (vhdl-insert-keyword "GENERIC ")
8434 (when (vhdl-template-map position t t)
8436 (indent-to (+ margin vhdl-basic-offset)))
8437 (setq position (point))
8438 (vhdl-insert-keyword "PORT ")
8439 (unless (vhdl-template-map position t t)
8440 (delete-region (line-beginning-position) (point))
8444 (defun vhdl-template-conditional-signal-asst ()
8445 "Insert a conditional signal assignment."
8447 (when (vhdl-template-field "target signal")
8449 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8451 (let ((margin (current-column))
8454 (vhdl-template-field "waveform")
8455 (setq position (point))
8456 (vhdl-insert-keyword " WHEN ")
8457 (when vhdl-conditions-in-parenthesis (insert "("))
8458 (while (and (vhdl-template-field "[condition]" nil t)
8460 (when vhdl-conditions-in-parenthesis (insert ")"))
8461 (setq position (point))
8462 (vhdl-insert-keyword " ELSE")
8465 (vhdl-template-field "[waveform]" nil t)))
8466 (setq position (point))
8467 (vhdl-insert-keyword " WHEN ")
8468 (when vhdl-conditions-in-parenthesis (insert "(")))
8469 (delete-region position (point))
8471 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8473 (defun vhdl-template-configuration ()
8474 "Insert a configuration specification if within an architecture,
8475 a block or component configuration if within a configuration declaration,
8476 a configuration declaration if not within a design unit."
8478 (vhdl-prepare-search-1
8480 ((and (save-excursion ; architecture body
8481 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8482 (equal "ARCHITECTURE" (upcase (match-string 1))))
8483 (vhdl-template-configuration-spec))
8484 ((and (save-excursion ; configuration declaration
8485 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8486 (equal "CONFIGURATION" (upcase (match-string 1))))
8487 (if (eq (vhdl-decision-query
8488 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8489 (vhdl-template-component-conf)
8490 (vhdl-template-block-configuration)))
8491 (t (vhdl-template-configuration-decl))))) ; otherwise
8493 (defun vhdl-template-configuration-spec (&optional optional-use)
8494 "Insert a configuration specification."
8496 (let ((margin (current-indentation))
8499 (vhdl-insert-keyword "FOR ")
8500 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8502 (vhdl-template-field "component name" "\n")
8503 (indent-to (+ margin vhdl-basic-offset))
8504 (setq start (point))
8505 (vhdl-insert-keyword "USE ")
8506 (if (and optional-use
8507 (not (setq aspect (vhdl-template-field
8508 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8509 (progn (delete-region start (point)) 'no-use)
8510 (unless optional-use
8511 (setq aspect (vhdl-template-field
8512 "ENTITY | CONFIGURATION | OPEN" " ")))
8513 (setq aspect (upcase (or aspect "")))
8514 (cond ((equal aspect "ENTITY")
8515 (vhdl-template-field "library name" "." nil nil nil nil
8516 (vhdl-work-library))
8517 (vhdl-template-field "entity name" "(")
8518 (if (vhdl-template-field "[architecture name]" nil t)
8522 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8523 (setq position (point))
8524 (vhdl-insert-keyword "GENERIC ")
8525 (when (vhdl-template-map position t t)
8527 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8528 (setq position (point))
8529 (vhdl-insert-keyword "PORT ")
8530 (unless (vhdl-template-map position t t)
8531 (delete-region (line-beginning-position) (point))
8535 ((equal aspect "CONFIGURATION")
8536 (vhdl-template-field "library name" "." nil nil nil nil
8537 (vhdl-work-library))
8538 (vhdl-template-field "configuration name" ";"))
8539 (t (delete-char -1) (insert ";") t))))))
8542 (defun vhdl-template-configuration-decl ()
8543 "Insert a configuration declaration."
8545 (let ((margin (current-indentation))
8547 entity-exists string name position)
8548 (vhdl-insert-keyword "CONFIGURATION ")
8549 (when (setq name (vhdl-template-field "name" nil t start (point)))
8550 (vhdl-insert-keyword " OF ")
8552 (vhdl-prepare-search-1
8553 (setq entity-exists (vhdl-re-search-backward
8554 "\\<entity \\(\\w*\\) is\\>" nil t))
8555 (setq string (match-string 1))))
8556 (if (and entity-exists (not (equal string "")))
8558 (vhdl-template-field "entity name"))
8559 (vhdl-insert-keyword " IS\n")
8560 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8561 (indent-to (+ margin vhdl-basic-offset))
8562 (setq position (point))
8564 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8566 (vhdl-insert-keyword "END ")
8567 (unless (vhdl-standard-p '87)
8568 (vhdl-insert-keyword "CONFIGURATION "))
8570 (goto-char position))))
8572 (defun vhdl-template-constant ()
8573 "Insert a constant declaration."
8575 (let ((start (point))
8576 (in-arglist (vhdl-in-argument-list-p)))
8577 (vhdl-insert-keyword "CONSTANT ")
8578 (when (vhdl-template-field "name" nil t start (point))
8580 (when in-arglist (vhdl-insert-keyword "IN "))
8581 (vhdl-template-field "type")
8584 (vhdl-comment-insert-inline))
8585 (let ((position (point)))
8587 (unless (vhdl-template-field "[initialization]" nil t)
8588 (delete-region position (point)))
8590 (vhdl-comment-insert-inline))))))
8592 (defun vhdl-template-default ()
8601 (defun vhdl-template-default-indent ()
8602 "Insert nothing and indent."
8609 (indent-according-to-mode))
8611 (defun vhdl-template-disconnect ()
8612 "Insert a disconnect statement."
8614 (let ((start (point)))
8615 (vhdl-insert-keyword "DISCONNECT ")
8616 (when (vhdl-template-field "signal names | OTHERS | ALL"
8617 " : " t start (point))
8618 (vhdl-template-field "type")
8619 (vhdl-insert-keyword " AFTER ")
8620 (vhdl-template-field "time expression" ";"))))
8622 (defun vhdl-template-else ()
8623 "Insert an else statement."
8626 (vhdl-prepare-search-1
8627 (vhdl-insert-keyword "ELSE")
8628 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8629 (equal "WHEN" (upcase (match-string 1))))
8631 (indent-according-to-mode)
8632 (setq margin (current-indentation))
8634 (indent-to (+ margin vhdl-basic-offset))))))
8636 (defun vhdl-template-elsif ()
8637 "Insert an elsif statement."
8639 (let ((start (point))
8641 (vhdl-insert-keyword "ELSIF ")
8642 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8643 (when vhdl-conditions-in-parenthesis (insert "("))
8644 (when (vhdl-template-field "condition" nil t start (point))
8645 (when vhdl-conditions-in-parenthesis (insert ")"))
8646 (indent-according-to-mode)
8647 (setq margin (current-indentation))
8648 (vhdl-insert-keyword
8649 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8650 (indent-to (+ margin vhdl-basic-offset))))))
8652 (defun vhdl-template-entity ()
8655 (let ((margin (current-indentation))
8658 (vhdl-insert-keyword "ENTITY ")
8659 (when (setq name (vhdl-template-field "name" nil t start (point)))
8660 (vhdl-insert-keyword " IS\n\n")
8662 (vhdl-insert-keyword "END ")
8663 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8665 (setq end-column (current-column))
8667 (indent-to (+ margin vhdl-basic-offset))
8668 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8669 (indent-to (+ margin vhdl-basic-offset))
8670 (when (vhdl-template-generic-list t)
8671 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8673 (indent-to (+ margin vhdl-basic-offset))
8674 (when (vhdl-template-port-list t)
8675 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8676 (beginning-of-line 2)
8677 (forward-char end-column))))
8679 (defun vhdl-template-exit ()
8680 "Insert an exit statement."
8682 (let ((start (point)))
8683 (vhdl-insert-keyword "EXIT ")
8684 (if (vhdl-template-field "[loop label]" nil t start (point))
8685 (let ((position (point)))
8686 (vhdl-insert-keyword " WHEN ")
8687 (when vhdl-conditions-in-parenthesis (insert "("))
8688 (if (vhdl-template-field "[condition]" nil t)
8689 (when vhdl-conditions-in-parenthesis (insert ")"))
8690 (delete-region position (point))))
8694 (defun vhdl-template-file ()
8695 "Insert a file declaration."
8697 (let ((start (point)))
8698 (vhdl-insert-keyword "FILE ")
8699 (when (vhdl-template-field "name" nil t start (point))
8701 (vhdl-template-field "type")
8702 (unless (vhdl-standard-p '87)
8703 (vhdl-insert-keyword " OPEN ")
8704 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8707 (vhdl-insert-keyword " IS ")
8708 (when (vhdl-standard-p '87)
8709 (vhdl-template-field "[IN | OUT]" " " t))
8710 (vhdl-template-field "filename-string" nil nil nil nil t)
8712 (vhdl-comment-insert-inline))))
8714 (defun vhdl-template-for ()
8715 "Insert a block or component configuration if within a configuration
8716 declaration, a configuration specification if within an architecture
8717 declarative part (and not within a subprogram), a for-loop if within a
8718 sequential statement part (subprogram or process), and a for-generate
8721 (vhdl-prepare-search-1
8723 ((vhdl-sequential-statement-p) ; sequential statement
8724 (vhdl-template-for-loop))
8725 ((and (save-excursion ; configuration declaration
8726 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8727 (equal "CONFIGURATION" (upcase (match-string 1))))
8728 (if (eq (vhdl-decision-query
8729 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8730 (vhdl-template-component-conf)
8731 (vhdl-template-block-configuration)))
8732 ((and (save-excursion
8733 (re-search-backward ; architecture declarative part
8734 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8735 (equal "ARCHITECTURE" (upcase (match-string 1))))
8736 (vhdl-template-configuration-spec))
8737 (t (vhdl-template-for-generate))))) ; concurrent statement
8739 (defun vhdl-template-for-generate ()
8740 "Insert a for-generate."
8742 (let ((margin (current-indentation))
8745 (vhdl-insert-keyword ": FOR ")
8746 (setq position (point-marker))
8748 (when (setq label (vhdl-template-field "label" nil t start position))
8749 (goto-char position)
8750 (vhdl-template-field "loop variable")
8751 (vhdl-insert-keyword " IN ")
8752 (vhdl-template-field "range")
8753 (vhdl-template-generate-body margin label))))
8755 (defun vhdl-template-for-loop ()
8756 "Insert a for loop."
8758 (let ((margin (current-indentation))
8761 (if (not (eq vhdl-optional-labels 'all))
8762 (vhdl-insert-keyword "FOR ")
8763 (vhdl-insert-keyword ": FOR ")
8765 (setq label (vhdl-template-field "[label]" nil t))
8766 (unless label (delete-char 2))
8769 (when (setq index (vhdl-template-field "loop variable"
8770 nil t start (point)))
8771 (vhdl-insert-keyword " IN ")
8772 (vhdl-template-field "range")
8773 (vhdl-insert-keyword " LOOP\n\n")
8775 (vhdl-insert-keyword "END LOOP")
8777 (insert " " label ";")
8779 (when vhdl-self-insert-comments (insert " -- " index)))
8781 (indent-to (+ margin vhdl-basic-offset)))))
8783 (defun vhdl-template-function (&optional kind)
8784 "Insert a function declaration or body."
8786 (let ((margin (current-indentation))
8789 (vhdl-insert-keyword "FUNCTION ")
8790 (when (setq name (vhdl-template-field "name" nil t start (point)))
8791 (vhdl-template-argument-list t)
8792 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8795 (indent-to (+ margin vhdl-basic-offset))
8796 (vhdl-insert-keyword "RETURN ")
8797 (vhdl-template-field "type")
8798 (if (if kind (eq kind 'body)
8799 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8800 (progn (vhdl-insert-keyword " IS\n")
8801 (vhdl-template-begin-end
8802 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8803 (vhdl-comment-block))
8806 (defun vhdl-template-function-decl ()
8807 "Insert a function declaration."
8809 (vhdl-template-function 'decl))
8811 (defun vhdl-template-function-body ()
8812 "Insert a function declaration."
8814 (vhdl-template-function 'body))
8816 (defun vhdl-template-generate ()
8817 "Insert a generation scheme."
8819 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8820 (vhdl-template-if-generate)
8821 (vhdl-template-for-generate)))
8823 (defun vhdl-template-generic ()
8824 "Insert generic declaration, or generic map in instantiation statements."
8826 (let ((start (point)))
8827 (vhdl-prepare-search-1
8829 ((and (save-excursion ; entity declaration
8830 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8831 (equal "ENTITY" (upcase (match-string 1))))
8832 (vhdl-template-generic-list nil))
8833 ((or (save-excursion
8834 (or (beginning-of-line)
8835 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8836 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8837 (vhdl-insert-keyword "GENERIC ")
8838 (vhdl-template-map start))
8839 (t (vhdl-template-generic-list nil t))))))
8841 (defun vhdl-template-group ()
8842 "Insert group or group template declaration."
8844 (let ((start (point)))
8845 (if (eq (vhdl-decision-query
8846 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8847 (vhdl-template-group-template)
8848 (vhdl-template-group-decl))))
8850 (defun vhdl-template-group-decl ()
8851 "Insert group declaration."
8853 (let ((start (point)))
8854 (vhdl-insert-keyword "GROUP ")
8855 (when (vhdl-template-field "name" " : " t start (point))
8856 (vhdl-template-field "template name" " (")
8857 (vhdl-template-field "constituent list" ");")
8858 (vhdl-comment-insert-inline))))
8860 (defun vhdl-template-group-template ()
8861 "Insert group template declaration."
8863 (let ((start (point)))
8864 (vhdl-insert-keyword "GROUP ")
8865 (when (vhdl-template-field "template name" nil t start (point))
8866 (vhdl-insert-keyword " IS (")
8867 (vhdl-template-field "entity class list" ");")
8868 (vhdl-comment-insert-inline))))
8870 (defun vhdl-template-if ()
8871 "Insert a sequential if statement or an if-generate statement."
8873 (if (vhdl-sequential-statement-p)
8874 (vhdl-template-if-then)
8875 (if (and (vhdl-standard-p 'ams)
8876 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8877 (vhdl-template-if-use)
8878 (vhdl-template-if-generate))))
8880 (defun vhdl-template-if-generate ()
8881 "Insert an if-generate."
8883 (let ((margin (current-indentation))
8886 (vhdl-insert-keyword ": IF ")
8887 (setq position (point-marker))
8889 (when (setq label (vhdl-template-field "label" nil t start position))
8890 (goto-char position)
8891 (when vhdl-conditions-in-parenthesis (insert "("))
8892 (vhdl-template-field "condition")
8893 (when vhdl-conditions-in-parenthesis (insert ")"))
8894 (vhdl-template-generate-body margin label))))
8896 (defun vhdl-template-if-then-use (kind)
8897 "Insert a sequential if statement."
8899 (let ((margin (current-indentation))
8902 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8903 (vhdl-insert-keyword "IF ")
8904 (vhdl-insert-keyword ": IF ")
8906 (setq label (vhdl-template-field "[label]" nil t))
8907 (unless label (delete-char 2))
8910 (when vhdl-conditions-in-parenthesis (insert "("))
8911 (when (vhdl-template-field "condition" nil t start (point))
8912 (when vhdl-conditions-in-parenthesis (insert ")"))
8913 (vhdl-insert-keyword
8914 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8916 (vhdl-insert-keyword "END IF")
8917 (when label (insert " " label))
8920 (indent-to (+ margin vhdl-basic-offset)))))
8922 (defun vhdl-template-if-then ()
8923 "Insert a sequential if statement."
8925 (vhdl-template-if-then-use 'then))
8927 (defun vhdl-template-if-use ()
8928 "Insert a simultaneous if statement."
8930 (vhdl-template-if-then-use 'use))
8932 (defun vhdl-template-instance ()
8933 "Insert a component instantiation statement."
8935 (vhdl-template-component-inst))
8937 (defun vhdl-template-library ()
8938 "Insert a library specification."
8940 (let ((margin (current-indentation))
8943 (vhdl-insert-keyword "LIBRARY ")
8944 (when (setq name (vhdl-template-field "names" nil t start (point)))
8946 (unless (string-match "," name)
8947 (setq end-pos (point))
8950 (vhdl-insert-keyword "USE ")
8952 (vhdl-insert-keyword "..ALL;")
8954 (if (vhdl-template-field "package name")
8956 (delete-region end-pos (+ (point) 5)))))))
8958 (defun vhdl-template-limit ()
8961 (let ((start (point)))
8962 (vhdl-insert-keyword "LIMIT ")
8963 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8965 (vhdl-template-field "type")
8966 (vhdl-insert-keyword " WITH ")
8967 (vhdl-template-field "real expression" ";"))))
8969 (defun vhdl-template-loop ()
8972 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8974 (vhdl-template-while-loop))
8976 (vhdl-template-for-loop))
8977 (t (vhdl-template-bare-loop)))))
8979 (defun vhdl-template-bare-loop ()
8982 (let ((margin (current-indentation))
8985 (if (not (eq vhdl-optional-labels 'all))
8986 (vhdl-insert-keyword "LOOP ")
8987 (vhdl-insert-keyword ": LOOP ")
8989 (setq label (vhdl-template-field "[label]" nil t))
8990 (unless label (delete-char 2))
8995 (vhdl-insert-keyword "END LOOP")
8996 (insert (if label (concat " " label ";") ";"))
8998 (indent-to (+ margin vhdl-basic-offset))))
9000 (defun vhdl-template-map (&optional start optional secondary)
9001 "Insert a map specification with association list."
9003 (let ((start (or start (point)))
9005 (vhdl-insert-keyword "MAP (")
9006 (if (not vhdl-association-list-with-formals)
9007 (if (vhdl-template-field
9008 (concat (and optional "[") "association list" (and optional "]"))
9009 ")" (or (not secondary) optional)
9010 (and (not secondary) start) (point))
9012 (if (and optional secondary) (delete-region start (point)))
9014 (if vhdl-argument-list-indent
9015 (setq margin (current-column))
9016 (setq margin (+ (current-indentation) vhdl-basic-offset))
9019 (if (vhdl-template-field
9020 (concat (and optional "[") "formal" (and optional "]"))
9021 " => " (or (not secondary) optional)
9022 (and (not secondary) start) (point))
9024 (vhdl-template-field "actual" ",")
9025 (setq end-pos (point))
9028 (while (vhdl-template-field "[formal]" " => " t)
9029 (vhdl-template-field "actual" ",")
9030 (setq end-pos (point))
9033 (delete-region end-pos (point))
9036 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9038 (when (and optional secondary) (delete-region start (point)))
9041 (defun vhdl-template-modify (&optional noerror)
9042 "Actualize modification date."
9044 (vhdl-prepare-search-2
9046 (goto-char (point-min))
9047 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9048 (progn (delete-region (point) (progn (end-of-line) (point)))
9049 (vhdl-template-insert-date))
9051 (error "ERROR: Modification date prefix string \"%s\" not found"
9052 vhdl-modify-date-prefix-string))))))
9055 (defun vhdl-template-modify-noerror ()
9056 "Call `vhdl-template-modify' with NOERROR non-nil."
9057 (vhdl-template-modify t))
9059 (defun vhdl-template-nature ()
9060 "Insert a nature declaration."
9062 (let ((start (point))
9063 name mid-pos end-pos)
9064 (vhdl-insert-keyword "NATURE ")
9065 (when (setq name (vhdl-template-field "name" nil t start (point)))
9066 (vhdl-insert-keyword " IS ")
9069 (or (vhdl-template-field
9070 "across type | ARRAY | RECORD")
9072 (cond ((equal definition "")
9074 ((equal definition "ARRAY")
9075 (delete-region (point) (progn (forward-word -1) (point)))
9076 (vhdl-template-array 'nature t))
9077 ((equal definition "RECORD")
9078 (setq mid-pos (point-marker))
9079 (delete-region (point) (progn (forward-word -1) (point)))
9080 (vhdl-template-record 'nature name t))
9082 (vhdl-insert-keyword " ACROSS ")
9083 (vhdl-template-field "through type")
9084 (vhdl-insert-keyword " THROUGH ")
9085 (vhdl-template-field "reference name")
9086 (vhdl-insert-keyword " REFERENCE;")))
9088 (setq end-pos (point-marker))
9091 (vhdl-comment-insert-inline)
9092 (when end-pos (goto-char end-pos))))))
9094 (defun vhdl-template-next ()
9095 "Insert a next statement."
9097 (let ((start (point)))
9098 (vhdl-insert-keyword "NEXT ")
9099 (if (vhdl-template-field "[loop label]" nil t start (point))
9100 (let ((position (point)))
9101 (vhdl-insert-keyword " WHEN ")
9102 (when vhdl-conditions-in-parenthesis (insert "("))
9103 (if (vhdl-template-field "[condition]" nil t)
9104 (when vhdl-conditions-in-parenthesis (insert ")"))
9105 (delete-region position (point))))
9109 (defun vhdl-template-others ()
9110 "Insert an others aggregate."
9112 (let ((start (point)))
9113 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9114 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9115 (vhdl-insert-keyword "OTHERS => '")
9116 (when (vhdl-template-field "value" nil t start (point))
9118 (vhdl-insert-keyword "OTHERS "))))
9120 (defun vhdl-template-package (&optional kind)
9121 "Insert a package specification or body."
9123 (let ((margin (current-indentation))
9126 (vhdl-insert-keyword "PACKAGE ")
9127 (setq body (if kind (eq kind 'body)
9128 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9130 (vhdl-insert-keyword "BODY ")
9131 (when (save-excursion
9132 (vhdl-prepare-search-1
9133 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9134 (insert (setq name (match-string 1)))))
9136 (setq name (vhdl-template-field "name" nil t start (point))))
9137 (vhdl-insert-keyword " IS\n")
9138 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9139 (indent-to (+ margin vhdl-basic-offset))
9140 (setq position (point))
9142 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9144 (vhdl-insert-keyword "END ")
9145 (unless (vhdl-standard-p '87)
9146 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9147 (insert (or name "") ";")
9148 (goto-char position))))
9150 (defun vhdl-template-package-decl ()
9151 "Insert a package specification."
9153 (vhdl-template-package 'decl))
9155 (defun vhdl-template-package-body ()
9156 "Insert a package body."
9158 (vhdl-template-package 'body))
9160 (defun vhdl-template-port ()
9161 "Insert a port declaration, or port map in instantiation statements."
9163 (let ((start (point)))
9164 (vhdl-prepare-search-1
9166 ((and (save-excursion ; entity declaration
9167 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9168 (equal "ENTITY" (upcase (match-string 1))))
9169 (vhdl-template-port-list nil))
9170 ((or (save-excursion
9171 (or (beginning-of-line)
9172 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9173 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9174 (vhdl-insert-keyword "PORT ")
9175 (vhdl-template-map start))
9176 (t (vhdl-template-port-list nil))))))
9178 (defun vhdl-template-procedural ()
9179 "Insert a procedural."
9181 (let ((margin (current-indentation))
9183 (case-fold-search t)
9185 (vhdl-insert-keyword "PROCEDURAL ")
9186 (when (memq vhdl-optional-labels '(process all))
9190 (setq label (vhdl-template-field "[label]" nil t))
9191 (unless label (delete-char 2))
9194 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9196 (vhdl-template-begin-end "PROCEDURAL" label margin)
9197 (vhdl-comment-block)))
9199 (defun vhdl-template-procedure (&optional kind)
9200 "Insert a procedure declaration or body."
9202 (let ((margin (current-indentation))
9205 (vhdl-insert-keyword "PROCEDURE ")
9206 (when (setq name (vhdl-template-field "name" nil t start (point)))
9207 (vhdl-template-argument-list)
9208 (if (if kind (eq kind 'body)
9209 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9210 (progn (vhdl-insert-keyword " IS")
9211 (when vhdl-auto-align
9212 (vhdl-align-region-groups start (point) 1))
9213 (end-of-line) (insert "\n")
9214 (vhdl-template-begin-end
9215 (unless (vhdl-standard-p '87) "PROCEDURE")
9217 (vhdl-comment-block))
9219 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9222 (defun vhdl-template-procedure-decl ()
9223 "Insert a procedure declaration."
9225 (vhdl-template-procedure 'decl))
9227 (defun vhdl-template-procedure-body ()
9228 "Insert a procedure body."
9230 (vhdl-template-procedure 'body))
9232 (defun vhdl-template-process (&optional kind)
9235 (let ((margin (current-indentation))
9237 label seq input-signals clock reset final-pos)
9238 (setq seq (if kind (eq kind 'seq)
9239 (eq (vhdl-decision-query
9240 "process" "(c)ombinational or (s)equential?" t) ?s)))
9241 (vhdl-insert-keyword "PROCESS ")
9242 (when (memq vhdl-optional-labels '(process all))
9246 (setq label (vhdl-template-field "[label]" nil t))
9247 (unless label (delete-char 2))
9252 (unless (setq input-signals
9253 (vhdl-template-field "[sensitivity list]" ")" t))
9254 (setq input-signals "")
9256 (setq clock (or (and (not (equal "" vhdl-clock-name))
9257 (progn (insert vhdl-clock-name) vhdl-clock-name))
9258 (vhdl-template-field "clock name") "<clock>"))
9259 (when (eq vhdl-reset-kind 'async)
9261 (setq reset (or (and (not (equal "" vhdl-reset-name))
9262 (progn (insert vhdl-reset-name) vhdl-reset-name))
9263 (vhdl-template-field "reset name") "<reset>")))
9265 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9267 (vhdl-template-begin-end "PROCESS" label margin)
9268 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9269 (when vhdl-prompt-for-comments
9270 (setq final-pos (point-marker))
9271 (vhdl-prepare-search-2
9272 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9273 (vhdl-re-search-backward "\\<process\\>" nil t))
9276 (progn (insert "\n") (forward-line -1))
9279 (insert "-- purpose: ")
9280 (if (not (vhdl-template-field "[description]" nil t))
9281 (vhdl-line-kill-entire)
9284 (insert "-- type : ")
9285 (insert (if seq "sequential" "combinational") "\n")
9287 (insert "-- inputs : ")
9289 (insert input-signals)
9291 (when reset (insert reset ", "))
9292 (unless (vhdl-template-field "[signal names]" nil t)
9296 (insert "-- outputs: ")
9297 (vhdl-template-field "[signal names]" nil t))))
9298 (goto-char final-pos))))
9300 (defun vhdl-template-process-comb ()
9301 "Insert a combinational process."
9303 (vhdl-template-process 'comb))
9305 (defun vhdl-template-process-seq ()
9306 "Insert a sequential process."
9308 (vhdl-template-process 'seq))
9310 (defun vhdl-template-quantity ()
9311 "Insert a quantity declaration."
9313 (if (vhdl-in-argument-list-p)
9314 (let ((start (point)))
9315 (vhdl-insert-keyword "QUANTITY ")
9316 (when (vhdl-template-field "names" nil t start (point))
9318 (vhdl-template-field "[IN | OUT]" " " t)
9319 (vhdl-template-field "type")
9321 (vhdl-comment-insert-inline)))
9322 (let ((char (vhdl-decision-query
9323 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9324 (cond ((eq char ?f) (vhdl-template-quantity-free))
9325 ((eq char ?b) (vhdl-template-quantity-branch))
9326 ((eq char ?s) (vhdl-template-quantity-source))
9327 (t (vhdl-template-undo (point) (point)))))))
9329 (defun vhdl-template-quantity-free ()
9330 "Insert a free quantity declaration."
9332 (vhdl-insert-keyword "QUANTITY ")
9333 (vhdl-template-field "names")
9335 (vhdl-template-field "type")
9336 (let ((position (point)))
9338 (unless (vhdl-template-field "[initialization]" nil t)
9339 (delete-region position (point)))
9341 (vhdl-comment-insert-inline)))
9343 (defun vhdl-template-quantity-branch ()
9344 "Insert a branch quantity declaration."
9347 (vhdl-insert-keyword "QUANTITY ")
9348 (when (vhdl-template-field "[across names]" " " t)
9349 (vhdl-insert-keyword "ACROSS "))
9350 (when (vhdl-template-field "[through names]" " " t)
9351 (vhdl-insert-keyword "THROUGH "))
9352 (vhdl-template-field "plus terminal name")
9353 (setq position (point))
9354 (vhdl-insert-keyword " TO ")
9355 (unless (vhdl-template-field "[minus terminal name]" nil t)
9356 (delete-region position (point)))
9358 (vhdl-comment-insert-inline)))
9360 (defun vhdl-template-quantity-source ()
9361 "Insert a source quantity declaration."
9363 (vhdl-insert-keyword "QUANTITY ")
9364 (vhdl-template-field "names")
9366 (vhdl-template-field "type" " ")
9367 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9368 (progn (vhdl-insert-keyword "NOISE ")
9369 (vhdl-template-field "power expression"))
9370 (vhdl-insert-keyword "SPECTRUM ")
9371 (vhdl-template-field "magnitude expression" ", ")
9372 (vhdl-template-field "phase expression"))
9374 (vhdl-comment-insert-inline))
9376 (defun vhdl-template-record (kind &optional name secondary)
9377 "Insert a record type declaration."
9379 (let ((margin (current-column))
9382 (vhdl-insert-keyword "RECORD\n")
9383 (indent-to (+ margin vhdl-basic-offset))
9384 (when (or (vhdl-template-field "element names"
9385 nil (not secondary) start (point))
9387 (while (or first (vhdl-template-field "[element names]" nil t))
9389 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9390 (vhdl-comment-insert-inline)
9392 (indent-to (+ margin vhdl-basic-offset))
9394 (delete-region (line-beginning-position) (point))
9396 (vhdl-insert-keyword "END RECORD")
9397 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9399 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9401 (defun vhdl-template-report ()
9402 "Insert a report statement."
9404 (let ((start (point)))
9405 (vhdl-insert-keyword "REPORT ")
9406 (if (equal "\"\"" (vhdl-template-field
9407 "string expression" nil t start (point) t))
9409 (setq start (point))
9410 (vhdl-insert-keyword " SEVERITY ")
9411 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9412 (delete-region start (point)))
9415 (defun vhdl-template-return ()
9416 "Insert a return statement."
9418 (let ((start (point)))
9419 (vhdl-insert-keyword "RETURN ")
9420 (unless (vhdl-template-field "[expression]" nil t start (point))
9424 (defun vhdl-template-selected-signal-asst ()
9425 "Insert a selected signal assignment."
9427 (let ((margin (current-indentation))
9430 (let ((position (point)))
9431 (vhdl-insert-keyword " SELECT ")
9432 (goto-char position))
9433 (vhdl-insert-keyword "WITH ")
9434 (when (vhdl-template-field "selector expression"
9435 nil t start (+ (point) 7))
9439 (indent-to (+ margin vhdl-basic-offset))
9440 (vhdl-template-field "target signal" " <= ")
9441 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9443 (indent-to (+ margin vhdl-basic-offset))
9444 (vhdl-template-field "waveform")
9445 (vhdl-insert-keyword " WHEN ")
9446 (vhdl-template-field "choices" ",")
9448 (indent-to (+ margin vhdl-basic-offset))
9449 (while (and choices (vhdl-template-field "[waveform]" nil t))
9450 (vhdl-insert-keyword " WHEN ")
9451 (if (setq choices (vhdl-template-field "[choices]" "," t))
9452 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9453 (vhdl-insert-keyword "OTHERS")))
9458 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9460 (defun vhdl-template-signal ()
9461 "Insert a signal declaration."
9463 (let ((start (point))
9464 (in-arglist (vhdl-in-argument-list-p)))
9465 (vhdl-insert-keyword "SIGNAL ")
9466 (when (vhdl-template-field "names" nil t start (point))
9468 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9469 (vhdl-template-field "type")
9472 (vhdl-comment-insert-inline))
9473 (let ((position (point)))
9475 (unless (vhdl-template-field "[initialization]" nil t)
9476 (delete-region position (point)))
9478 (vhdl-comment-insert-inline))))))
9480 (defun vhdl-template-subnature ()
9481 "Insert a subnature declaration."
9483 (let ((start (point))
9485 (vhdl-insert-keyword "SUBNATURE ")
9486 (when (vhdl-template-field "name" nil t start (point))
9487 (vhdl-insert-keyword " IS ")
9488 (vhdl-template-field "nature" " (")
9489 (if (vhdl-template-field "[index range]" nil t)
9492 (setq position (point))
9493 (vhdl-insert-keyword " TOLERANCE ")
9494 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9496 (delete-region position (point))
9497 (vhdl-insert-keyword " ACROSS ")
9498 (vhdl-template-field "string expression" nil nil nil nil t)
9499 (vhdl-insert-keyword " THROUGH"))
9501 (vhdl-comment-insert-inline))))
9503 (defun vhdl-template-subprogram-body ()
9504 "Insert a subprogram body."
9506 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9507 (vhdl-template-function-body)
9508 (vhdl-template-procedure-body)))
9510 (defun vhdl-template-subprogram-decl ()
9511 "Insert a subprogram declaration."
9513 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9514 (vhdl-template-function-decl)
9515 (vhdl-template-procedure-decl)))
9517 (defun vhdl-template-subtype ()
9518 "Insert a subtype declaration."
9520 (let ((start (point)))
9521 (vhdl-insert-keyword "SUBTYPE ")
9522 (when (vhdl-template-field "name" nil t start (point))
9523 (vhdl-insert-keyword " IS ")
9524 (vhdl-template-field "type" " ")
9526 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9529 (vhdl-comment-insert-inline))))
9531 (defun vhdl-template-terminal ()
9532 "Insert a terminal declaration."
9534 (let ((start (point)))
9535 (vhdl-insert-keyword "TERMINAL ")
9536 (when (vhdl-template-field "names" nil t start (point))
9538 (vhdl-template-field "nature")
9540 (vhdl-comment-insert-inline))))
9542 (defun vhdl-template-type ()
9543 "Insert a type declaration."
9545 (let ((start (point))
9546 name mid-pos end-pos)
9547 (vhdl-insert-keyword "TYPE ")
9548 (when (setq name (vhdl-template-field "name" nil t start (point)))
9549 (vhdl-insert-keyword " IS ")
9552 (or (vhdl-template-field
9553 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9555 (cond ((equal definition "")
9558 ((equal definition "ARRAY")
9559 (delete-region (point) (progn (forward-word -1) (point)))
9560 (vhdl-template-array 'type t))
9561 ((equal definition "RECORD")
9562 (setq mid-pos (point-marker))
9563 (delete-region (point) (progn (forward-word -1) (point)))
9564 (vhdl-template-record 'type name t))
9565 ((equal definition "ACCESS")
9567 (vhdl-template-field "type" ";"))
9568 ((equal definition "FILE")
9569 (vhdl-insert-keyword " OF ")
9570 (vhdl-template-field "type" ";"))
9573 (setq end-pos (point-marker))
9576 (vhdl-comment-insert-inline)
9577 (when end-pos (goto-char end-pos))))))
9579 (defun vhdl-template-use ()
9580 "Insert a use clause."
9582 (let ((start (point)))
9583 (vhdl-prepare-search-1
9584 (vhdl-insert-keyword "USE ")
9585 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9586 (vhdl-insert-keyword "..ALL;")
9588 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9590 (vhdl-template-field "package name")
9591 (forward-char 5))))))
9593 (defun vhdl-template-variable ()
9594 "Insert a variable declaration."
9596 (let ((start (point))
9597 (in-arglist (vhdl-in-argument-list-p)))
9598 (vhdl-prepare-search-2
9599 (if (or (save-excursion
9600 (and (vhdl-re-search-backward
9601 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9603 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9604 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9605 (vhdl-insert-keyword "VARIABLE ")
9606 (vhdl-insert-keyword "SHARED VARIABLE ")))
9607 (when (vhdl-template-field "names" nil t start (point))
9609 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9610 (vhdl-template-field "type")
9613 (vhdl-comment-insert-inline))
9614 (let ((position (point)))
9616 (unless (vhdl-template-field "[initialization]" nil t)
9617 (delete-region position (point)))
9619 (vhdl-comment-insert-inline))))))
9621 (defun vhdl-template-wait ()
9622 "Insert a wait statement."
9624 (vhdl-insert-keyword "WAIT ")
9625 (unless (vhdl-template-field
9626 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9631 (defun vhdl-template-when ()
9632 "Indent correctly if within a case statement."
9634 (let ((position (point))
9636 (vhdl-prepare-search-2
9637 (if (and (= (current-column) (current-indentation))
9638 (vhdl-re-search-forward "\\<end\\>" nil t)
9639 (looking-at "\\s-*\\<case\\>"))
9641 (setq margin (current-indentation))
9642 (goto-char position)
9643 (delete-horizontal-space)
9644 (indent-to (+ margin vhdl-basic-offset)))
9645 (goto-char position)))
9646 (vhdl-insert-keyword "WHEN ")))
9648 (defun vhdl-template-while-loop ()
9649 "Insert a while loop."
9651 (let* ((margin (current-indentation))
9654 (if (not (eq vhdl-optional-labels 'all))
9655 (vhdl-insert-keyword "WHILE ")
9656 (vhdl-insert-keyword ": WHILE ")
9658 (setq label (vhdl-template-field "[label]" nil t))
9659 (unless label (delete-char 2))
9662 (when vhdl-conditions-in-parenthesis (insert "("))
9663 (when (vhdl-template-field "condition" nil t start (point))
9664 (when vhdl-conditions-in-parenthesis (insert ")"))
9665 (vhdl-insert-keyword " LOOP\n\n")
9667 (vhdl-insert-keyword "END LOOP")
9668 (insert (if label (concat " " label ";") ";"))
9670 (indent-to (+ margin vhdl-basic-offset)))))
9672 (defun vhdl-template-with ()
9673 "Insert a with statement (i.e. selected signal assignment)."
9675 (vhdl-prepare-search-1
9676 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9677 (equal ";" (match-string 1)))
9678 (vhdl-template-selected-signal-asst)
9679 (vhdl-insert-keyword "WITH "))))
9681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9682 ;; Special templates
9684 (defun vhdl-template-clocked-wait ()
9685 "Insert a wait statement for rising/falling clock edge."
9687 (let ((start (point))
9689 (vhdl-insert-keyword "WAIT UNTIL ")
9691 (or (and (not (equal "" vhdl-clock-name))
9692 (progn (insert vhdl-clock-name) vhdl-clock-name))
9693 (vhdl-template-field "clock name" nil t start (point))))
9695 (vhdl-insert-keyword " AND ")
9698 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9699 (vhdl-comment-insert-inline
9700 (concat (if vhdl-clock-rising-edge "rising" "falling")
9703 (defun vhdl-template-seq-process (clock reset)
9704 "Insert a template for the body of a sequential process."
9705 (let ((margin (current-indentation))
9707 (vhdl-insert-keyword "IF ")
9708 (when (eq vhdl-reset-kind 'async)
9710 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9711 (vhdl-insert-keyword " THEN")
9712 (vhdl-comment-insert-inline
9713 (concat "asynchronous reset (active "
9714 (if vhdl-reset-active-high "high" "low") ")"))
9715 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9716 (setq position (point))
9717 (insert "\n") (indent-to margin)
9718 (vhdl-insert-keyword "ELSIF "))
9719 (if (eq vhdl-clock-edge-condition 'function)
9720 (insert (if vhdl-clock-rising-edge "rising" "falling")
9722 (insert clock "'event")
9723 (vhdl-insert-keyword " AND ")
9725 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9726 (vhdl-insert-keyword " THEN")
9727 (vhdl-comment-insert-inline
9728 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9729 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9730 (when (eq vhdl-reset-kind 'sync)
9731 (vhdl-insert-keyword "IF ")
9732 (setq reset (or (and (not (equal "" vhdl-reset-name))
9733 (progn (insert vhdl-reset-name) vhdl-reset-name))
9734 (vhdl-template-field "reset name") "<reset>"))
9736 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9737 (vhdl-insert-keyword " THEN")
9738 (vhdl-comment-insert-inline
9739 (concat "synchronous reset (active "
9740 (if vhdl-reset-active-high "high" "low") ")"))
9741 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9742 (setq position (point))
9743 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9744 (vhdl-insert-keyword "ELSE")
9745 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9746 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9747 (vhdl-insert-keyword "END IF;"))
9748 (when (eq vhdl-reset-kind 'none)
9749 (setq position (point)))
9750 (insert "\n") (indent-to margin)
9751 (vhdl-insert-keyword "END IF;")
9752 (goto-char position)
9755 (defun vhdl-template-standard-package (library package)
9756 "Insert specification of a standard package. Include a library
9757 specification, if not already there."
9758 (let ((margin (current-indentation)))
9759 (unless (equal library "std")
9760 (unless (or (save-excursion
9761 (vhdl-prepare-search-1
9764 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9765 library "\\|end\\)\\>") nil t)
9767 (equal (downcase library) "work"))
9768 (vhdl-insert-keyword "LIBRARY ")
9769 (insert library ";")
9772 (indent-to margin)))
9774 (vhdl-insert-keyword "USE ")
9775 (insert library "." package)
9776 (vhdl-insert-keyword ".ALL;")))))
9778 (defun vhdl-template-package-math-complex ()
9779 "Insert specification of `math_complex' package."
9781 (vhdl-template-standard-package "ieee" "math_complex"))
9783 (defun vhdl-template-package-math-real ()
9784 "Insert specification of `math_real' package."
9786 (vhdl-template-standard-package "ieee" "math_real"))
9788 (defun vhdl-template-package-numeric-bit ()
9789 "Insert specification of `numeric_bit' package."
9791 (vhdl-template-standard-package "ieee" "numeric_bit"))
9793 (defun vhdl-template-package-numeric-std ()
9794 "Insert specification of `numeric_std' package."
9796 (vhdl-template-standard-package "ieee" "numeric_std"))
9798 (defun vhdl-template-package-std-logic-1164 ()
9799 "Insert specification of `std_logic_1164' package."
9801 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9803 (defun vhdl-template-package-std-logic-arith ()
9804 "Insert specification of `std_logic_arith' package."
9806 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9808 (defun vhdl-template-package-std-logic-misc ()
9809 "Insert specification of `std_logic_misc' package."
9811 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9813 (defun vhdl-template-package-std-logic-signed ()
9814 "Insert specification of `std_logic_signed' package."
9816 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9818 (defun vhdl-template-package-std-logic-textio ()
9819 "Insert specification of `std_logic_textio' package."
9821 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9823 (defun vhdl-template-package-std-logic-unsigned ()
9824 "Insert specification of `std_logic_unsigned' package."
9826 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9828 (defun vhdl-template-package-textio ()
9829 "Insert specification of `textio' package."
9831 (vhdl-template-standard-package "std" "textio"))
9833 (defun vhdl-template-directive (directive)
9835 (unless (= (current-indentation) (current-column))
9836 (delete-horizontal-space)
9838 (insert "-- pragma " directive))
9840 (defun vhdl-template-directive-translate-on ()
9841 "Insert directive 'translate_on'."
9843 (vhdl-template-directive "translate_on"))
9845 (defun vhdl-template-directive-translate-off ()
9846 "Insert directive 'translate_off'."
9848 (vhdl-template-directive "translate_off"))
9850 (defun vhdl-template-directive-synthesis-on ()
9851 "Insert directive 'synthesis_on'."
9853 (vhdl-template-directive "synthesis_on"))
9855 (defun vhdl-template-directive-synthesis-off ()
9856 "Insert directive 'synthesis_off'."
9858 (vhdl-template-directive "synthesis_off"))
9860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9861 ;; Header and footer templates
9863 (defun vhdl-template-header (&optional file-title)
9864 "Insert a VHDL file header."
9866 (unless (equal vhdl-file-header "")
9869 (goto-char (point-min))
9870 (vhdl-insert-string-or-file vhdl-file-header)
9871 (setq pos (point-marker)))
9872 (vhdl-template-replace-header-keywords
9873 (point-min-marker) pos file-title))))
9875 (defun vhdl-template-footer ()
9876 "Insert a VHDL file footer."
9878 (unless (equal vhdl-file-footer "")
9881 (goto-char (point-max))
9882 (setq pos (point-marker))
9883 (vhdl-insert-string-or-file vhdl-file-footer)
9884 (unless (= (preceding-char) ?\n)
9886 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9888 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9890 "Replace keywords in header and footer."
9891 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9892 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9894 (vhdl-prepare-search-2
9897 (while (search-forward "<projectdesc>" end t)
9898 (replace-match project-desc t t))
9900 (while (search-forward "<filename>" end t)
9901 (replace-match (buffer-name) t t))
9903 (while (search-forward "<copyright>" end t)
9904 (replace-match vhdl-copyright-string t t))
9906 (while (search-forward "<author>" end t)
9907 (replace-match "" t t)
9908 (insert (user-full-name))
9909 (when user-mail-address (insert " <" user-mail-address ">")))
9911 (while (search-forward "<login>" end t)
9912 (replace-match (user-login-name) t t))
9914 (while (search-forward "<project>" end t)
9915 (replace-match project-title t t))
9917 (while (search-forward "<company>" end t)
9918 (replace-match vhdl-company-name t t))
9920 (while (search-forward "<platform>" end t)
9921 (replace-match vhdl-platform-spec t t))
9923 (while (search-forward "<standard>" end t)
9925 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9926 ((vhdl-standard-p '93) "'93"))
9927 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9928 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9930 ;; Replace <RCS> with $, so that RCS for the source is
9931 ;; not over-enthusiastic with replacements
9932 (while (search-forward "<RCS>" end t)
9933 (replace-match "$" nil t))
9935 (while (search-forward "<date>" end t)
9936 (replace-match "" t t)
9937 (vhdl-template-insert-date))
9939 (while (search-forward "<year>" end t)
9940 (replace-match (format-time-string "%Y" nil) t t))
9943 (while (search-forward "<title string>" end t)
9944 (replace-match file-title t t))
9948 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9949 (setq string (read-string (concat (match-string 1) ": ")))
9950 (replace-match string t t)))
9952 (when (and (not is-model) (search-forward "<cursor>" end t))
9953 (replace-match "" t t)
9954 (setq pos (point))))
9955 (when pos (goto-char pos))
9957 (when (or (not project-title) (equal project-title ""))
9958 (message "You can specify a project title in user option `vhdl-project-alist'"))
9959 (when (or (not project-desc) (equal project-desc ""))
9960 (message "You can specify a project description in user option `vhdl-project-alist'"))
9961 (when (equal vhdl-platform-spec "")
9962 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9963 (when (equal vhdl-company-name "")
9964 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9966 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9967 ;; Comment templates and functions
9969 (defun vhdl-comment-indent ()
9971 (let* ((position (point))
9975 (if (re-search-forward "--" position t)
9976 (- (current-column) 2) ; existing comment at bol stays there
9977 (goto-char position)
9978 (skip-chars-backward " \t")
9979 (max comment-column ; else indent to comment column
9980 (1+ (current-column))))))) ; except leave at least one space
9981 (goto-char position)
9984 (defun vhdl-comment-insert ()
9985 "Start a comment at the end of the line.
9986 If on line with code, indent at least `comment-column'.
9987 If starting after end-comment-column, start a new line."
9989 (when (> (current-column) end-comment-column) (newline-and-indent))
9990 (if (or (looking-at "\\s-*$") ; end of line
9991 (and (not unread-command-events) ; called with key binding or menu
9992 (not (end-of-line))))
9994 (while (= (preceding-char) ?-) (delete-char -1))
9995 (setq margin (current-column))
9996 (delete-horizontal-space)
9998 (progn (indent-to margin) (insert "--"))
10000 (indent-to comment-column)
10002 (if (not unread-command-events) (insert " ")))
10003 ;; else code following current point implies commenting out code
10004 (let (next-input code)
10005 (while (= (preceding-char) ?-) (delete-char -2))
10006 (while (= (setq next-input (read-char)) 13) ; CR
10007 (insert "--") ; or have a space after it?
10010 (message "Enter CR if commenting out a line of code.")
10013 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10014 (setq unread-command-events
10015 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10017 (defun vhdl-comment-display (&optional line-exists)
10018 "Add 2 comment lines at the current indent, making a display comment."
10020 (let ((margin (current-indentation)))
10021 (unless line-exists (vhdl-comment-display-line))
10022 (insert "\n") (indent-to margin)
10023 (insert "\n") (indent-to margin)
10024 (vhdl-comment-display-line)
10028 (defun vhdl-comment-display-line ()
10029 "Displays one line of dashes."
10031 (while (= (preceding-char) ?-) (delete-char -2))
10032 (let* ((col (current-column))
10033 (len (- end-comment-column col)))
10034 (insert-char ?- len)))
10036 (defun vhdl-comment-append-inline ()
10037 "Append empty inline comment to current line."
10040 (delete-horizontal-space)
10042 (indent-to comment-column)
10045 (defun vhdl-comment-insert-inline (&optional string always-insert)
10046 "Insert inline comment."
10047 (when (or (and string (or vhdl-self-insert-comments always-insert))
10048 (and (not string) vhdl-prompt-for-comments))
10049 (let ((position (point)))
10051 (indent-to comment-column)
10053 (if (not (or (and string (progn (insert string) t))
10054 (vhdl-template-field "[comment]" nil t)))
10055 (delete-region position (point))
10056 (while (= (preceding-char) ?\ ) (delete-char -1))
10057 ;; (when (> (current-column) end-comment-column)
10058 ;; (setq position (point-marker))
10059 ;; (re-search-backward "-- ")
10061 ;; (indent-to comment-column)
10062 ;; (goto-char position))
10065 (defun vhdl-comment-block ()
10066 "Insert comment for code block."
10067 (when vhdl-prompt-for-comments
10068 (let ((final-pos (point-marker)))
10069 (vhdl-prepare-search-2
10070 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10071 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10073 (back-to-indentation)
10074 (setq margin (current-column))
10077 (progn (insert "\n") (forward-line -1))
10080 (insert "-- purpose: ")
10081 (unless (vhdl-template-field "[description]" nil t)
10082 (vhdl-line-kill-entire)))))
10083 (goto-char final-pos))))
10085 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10086 "Comment out region if not commented out, uncomment otherwise."
10087 (interactive "r\nP")
10089 (goto-char (1- end))
10091 (setq end (point-marker))
10093 (beginning-of-line)
10095 (if (looking-at comment-start)
10096 (comment-region beg end '(4))
10097 (comment-region beg end))))
10099 (defun vhdl-comment-uncomment-line (&optional arg)
10100 "Comment out line if not commented out, uncomment otherwise."
10103 (beginning-of-line)
10104 (let ((position (point)))
10105 (forward-line (or arg 1))
10106 (vhdl-comment-uncomment-region position (point)))))
10108 (defun vhdl-comment-kill-region (beg end)
10109 "Kill comments in region."
10113 (setq end (point-marker))
10115 (beginning-of-line)
10116 (while (< (point) end)
10117 (if (looking-at "^\\(\\s-*--.*\n\\)")
10118 (progn (delete-region (match-beginning 1) (match-end 1)))
10119 (beginning-of-line 2)))))
10121 (defun vhdl-comment-kill-inline-region (beg end)
10122 "Kill inline comments in region."
10126 (setq end (point-marker))
10128 (beginning-of-line)
10129 (while (< (point) end)
10130 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10131 (delete-region (match-beginning 1) (match-end 1)))
10132 (beginning-of-line 2))))
10134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10137 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10138 "Insert a begin ... end pair with optional name after the end.
10139 Point is left between them."
10141 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10143 (vhdl-insert-keyword "BEGIN")
10144 (when (and (or construct name) vhdl-self-insert-comments)
10146 (when construct (insert " ") (vhdl-insert-keyword construct))
10147 (when name (insert " " name)))
10149 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10150 (indent-to (+ margin vhdl-basic-offset))
10151 (setq position (point))
10153 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10155 (vhdl-insert-keyword "END")
10156 (when construct (insert " ") (vhdl-insert-keyword construct))
10157 (insert (if name (concat " " name) "") ";")
10158 (goto-char position)))
10160 (defun vhdl-template-argument-list (&optional is-function)
10161 "Read from user a procedure or function argument list."
10163 (let ((margin (current-column))
10166 not-empty interface semicolon-pos)
10167 (unless vhdl-argument-list-indent
10168 (setq margin (+ (current-indentation) vhdl-basic-offset))
10170 (indent-to margin))
10171 (setq interface (vhdl-template-field
10172 (concat "[CONSTANT | SIGNAL"
10173 (unless is-function " | VARIABLE") "]") " " t))
10174 (while (vhdl-template-field "[names]" nil t)
10177 (unless is-function
10178 (if (and interface (equal (upcase interface) "CONSTANT"))
10179 (vhdl-insert-keyword "IN ")
10180 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10181 (vhdl-template-field "type")
10182 (setq semicolon-pos (point))
10184 (vhdl-comment-insert-inline)
10185 (setq end-pos (point))
10188 (setq interface (vhdl-template-field
10189 (concat "[CONSTANT | SIGNAL"
10190 (unless is-function " | VARIABLE") "]") " " t)))
10191 (delete-region end-pos (point))
10192 (when semicolon-pos (goto-char semicolon-pos))
10194 (progn (delete-char 1) (insert ")"))
10195 (delete-char -2))))
10197 (defun vhdl-template-generic-list (optional &optional no-value)
10198 "Read from user a generic spec argument list."
10201 (vhdl-insert-keyword "GENERIC (")
10202 (setq margin (current-column))
10203 (unless vhdl-argument-list-indent
10204 (let ((position (point)))
10205 (back-to-indentation)
10206 (setq margin (+ (current-column) vhdl-basic-offset))
10207 (goto-char position)
10209 (indent-to margin)))
10210 (let ((vhdl-generics (vhdl-template-field
10211 (concat (and optional "[") "name"
10212 (and no-value "s") (and optional "]"))
10214 (if (not vhdl-generics)
10216 (progn (vhdl-line-kill-entire) (end-of-line -0)
10217 (unless vhdl-argument-list-indent
10218 (vhdl-line-kill-entire) (end-of-line -0)))
10219 (vhdl-template-undo start (point))
10222 (let (semicolon-pos end-pos)
10223 (while vhdl-generics
10224 (vhdl-template-field "type")
10226 (progn (setq semicolon-pos (point))
10229 (unless (vhdl-template-field "[value]" nil t)
10231 (setq semicolon-pos (point))
10233 (vhdl-comment-insert-inline)
10234 (setq end-pos (point))
10237 (setq vhdl-generics (vhdl-template-field
10238 (concat "[name" (and no-value "s") "]")
10240 (delete-region end-pos (point))
10241 (goto-char semicolon-pos)
10244 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10247 (defun vhdl-template-port-list (optional)
10248 "Read from user a port spec argument list."
10249 (let ((start (point))
10250 margin vhdl-ports object)
10251 (vhdl-insert-keyword "PORT (")
10252 (setq margin (current-column))
10253 (unless vhdl-argument-list-indent
10254 (let ((position (point)))
10255 (back-to-indentation)
10256 (setq margin (+ (current-column) vhdl-basic-offset))
10257 (goto-char position)
10259 (indent-to margin)))
10260 (when (vhdl-standard-p 'ams)
10261 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10263 (setq vhdl-ports (vhdl-template-field
10264 (concat (and optional "[") "names" (and optional "]"))
10266 (if (not vhdl-ports)
10268 (progn (vhdl-line-kill-entire) (end-of-line -0)
10269 (unless vhdl-argument-list-indent
10270 (vhdl-line-kill-entire) (end-of-line -0)))
10271 (vhdl-template-undo start (point))
10274 (let (semicolon-pos end-pos)
10276 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10277 (vhdl-template-field "IN | OUT | INOUT" " "))
10278 ((equal "QUANTITY" (upcase object))
10279 (vhdl-template-field "[IN | OUT]" " " t)))
10280 (vhdl-template-field
10281 (if (and object (equal "TERMINAL" (upcase object)))
10283 (setq semicolon-pos (point))
10285 (vhdl-comment-insert-inline)
10286 (setq end-pos (point))
10289 (when (vhdl-standard-p 'ams)
10290 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10292 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10293 (delete-region end-pos (point))
10294 (goto-char semicolon-pos)
10297 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10300 (defun vhdl-template-generate-body (margin label)
10301 "Insert body for generate template."
10302 (vhdl-insert-keyword " GENERATE")
10303 ; (if (not (vhdl-standard-p '87))
10304 ; (vhdl-template-begin-end "GENERATE" label margin)
10307 (vhdl-insert-keyword "END GENERATE ")
10310 (indent-to (+ margin vhdl-basic-offset)))
10312 (defun vhdl-template-insert-date ()
10313 "Insert date in appropriate format."
10317 ;; 'american, 'european, 'scientific kept for backward compatibility
10318 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10319 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10320 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10321 (t (format-time-string vhdl-date-format nil)))))
10323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10326 (defun vhdl-electric-space (count)
10327 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10328 if in comment and past end-comment-column."
10330 (cond ((vhdl-in-comment-p)
10331 (self-insert-command count)
10332 (cond ((>= (current-column) (+ 2 end-comment-column))
10334 (skip-chars-backward "^ \t\n")
10335 (indent-new-comment-line)
10336 (skip-chars-forward "^ \t\n")
10338 ((>= (current-column) end-comment-column)
10339 (indent-new-comment-line))
10341 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10342 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10343 (vhdl-prepare-search-1
10344 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10345 (self-insert-command count))
10346 (t (self-insert-command count))))
10348 (defun vhdl-template-field (prompt &optional follow-string optional
10349 begin end is-string default)
10350 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10351 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10352 an empty string is inserted, return nil and call `vhdl-template-undo' for
10353 the region between BEGIN and END. IS-STRING indicates whether a string
10354 with double-quotes is to be inserted. DEFAULT specifies a default string."
10355 (let ((position (point))
10357 (insert "<" prompt ">")
10360 (read-from-minibuffer (concat prompt ": ")
10361 (or (and is-string '("\"\"" . 2)) default)
10362 vhdl-minibuffer-local-map)
10363 (quit (if (and optional begin end)
10365 (keyboard-quit)))))
10366 (when (or (not (equal string "")) optional)
10367 (delete-region position (point)))
10368 (when (and (equal string "") optional begin end)
10369 (vhdl-template-undo begin end)
10370 (message "Template aborted"))
10371 (unless (equal string "")
10373 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10374 vhdl-keywords-regexp)
10375 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10377 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10378 (concat "'" vhdl-attributes-regexp))
10379 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10380 vhdl-enum-values-regexp))
10381 (when (or (not (equal string "")) (not optional))
10382 (insert (or follow-string "")))
10383 (if (equal string "") nil string)))
10385 (defun vhdl-decision-query (string prompt &optional optional)
10386 "Query a decision from the user."
10387 (let ((start (point)))
10388 (when string (vhdl-insert-keyword (concat string " ")))
10389 (message "%s" (or prompt ""))
10390 (let ((char (read-char)))
10391 (delete-region start (point))
10392 (if (and optional (eq char ?\r))
10393 (progn (insert " ")
10395 (throw 'abort "ERROR: Template aborted"))
10398 (defun vhdl-insert-keyword (keyword)
10399 "Insert KEYWORD and adjust case."
10400 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10402 (defun vhdl-case-keyword (keyword)
10403 "Adjust case of KEYWORD."
10404 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10406 (defun vhdl-case-word (num)
10407 "Adjust case of following NUM words."
10408 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10410 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10411 "If preceeding character is part of a word or a paren then hippie-expand,
10412 else insert tab (used for word completion in VHDL minibuffer)."
10416 ((= (char-syntax (preceding-char)) ?w)
10417 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10419 (hippie-expand-only-buffers
10420 (or (and (boundp 'hippie-expand-only-buffers)
10421 hippie-expand-only-buffers)
10423 (vhdl-expand-abbrev prefix-arg)))
10424 ;; expand parenthesis
10425 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10426 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10427 (case-replace nil))
10428 (vhdl-expand-paren prefix-arg)))
10432 (defun vhdl-template-search-prompt ()
10433 "Search for left out template prompts and query again."
10435 (vhdl-prepare-search-2
10436 (when (or (re-search-forward
10437 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10438 (re-search-backward
10439 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10440 (let ((string (match-string 1)))
10442 (vhdl-template-field string)))))
10444 (defun vhdl-template-undo (begin end)
10445 "Undo aborted template by deleting region and unexpanding the keyword."
10446 (cond (vhdl-template-invoked-by-hook
10449 (delete-region begin end)
10451 (t (delete-region begin end))))
10453 (defun vhdl-insert-string-or-file (string)
10454 "Insert STRING or file contents if STRING is an existing file name."
10455 (unless (equal string "")
10457 (progn (string-match "^\\([^\n]+\\)" string)
10458 (vhdl-resolve-env-variable (match-string 1 string)))))
10459 (if (file-exists-p file-name)
10460 (forward-char (cadr (insert-file-contents file-name)))
10461 (insert string)))))
10463 (defun vhdl-beginning-of-block ()
10464 "Move cursor to the beginning of the enclosing block."
10467 (beginning-of-line)
10468 ;; search backward for block beginning or end
10469 (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))
10470 ;; not consider subprogram declarations
10471 (or (and (match-string 5)
10474 (goto-char (match-end 5))
10476 (vhdl-forward-syntactic-ws)
10477 (when (looking-at "(")
10479 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10481 ;; not consider configuration specifications
10482 (and (match-string 6)
10485 (vhdl-end-of-block)
10486 (beginning-of-line)
10487 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10489 ;; skip subblock if block end found
10490 (vhdl-beginning-of-block)))
10491 (when pos (goto-char pos))))
10493 (defun vhdl-end-of-block ()
10494 "Move cursor to the end of the enclosing block."
10498 ;; search forward for block beginning or end
10499 (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))
10500 ;; not consider subprogram declarations
10501 (or (and (match-string 5)
10503 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10505 ;; not consider configuration specifications
10506 (and (match-string 6)
10509 (vhdl-end-of-block)
10510 (beginning-of-line)
10511 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10512 (not (match-string 2)))
10513 ;; skip subblock if block beginning found
10514 (vhdl-end-of-block)))
10515 (when pos (goto-char pos))))
10517 (defun vhdl-sequential-statement-p ()
10518 "Check if point is within sequential statement part."
10519 (let ((start (point)))
10521 (vhdl-prepare-search-2
10522 ;; is sequential statement if ...
10523 (and (re-search-backward "^\\s-*begin\\>" nil t)
10524 ;; ... point is between "begin" and "end" of ...
10525 (progn (vhdl-end-of-block)
10527 ;; ... a sequential block
10528 (progn (vhdl-beginning-of-block)
10529 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10531 (defun vhdl-in-argument-list-p ()
10532 "Check if within an argument list."
10534 (vhdl-prepare-search-2
10535 (or (string-match "arglist"
10536 (format "%s" (caar (vhdl-get-syntactic-context))))
10537 (progn (beginning-of-line)
10538 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10543 (defun vhdl-hooked-abbrev (func)
10544 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10545 but not if inside a comment or quote."
10546 (if (or (vhdl-in-literal)
10549 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10554 (if (not vhdl-electric-mode)
10561 (let ((invoke-char last-command-event)
10563 (vhdl-template-invoked-by-hook t))
10564 (let ((caught (catch 'abort
10566 (when (stringp caught) (message "%s" caught)))
10567 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10568 ;; delete CR which is still in event queue
10569 (if (fboundp 'enqueue-eval-event)
10570 (enqueue-eval-event 'delete-char -1)
10571 (setq unread-command-events ; push back a delete char
10572 (list (vhdl-character-to-event ?\177))))))))
10574 (defun vhdl-template-alias-hook ()
10575 (vhdl-hooked-abbrev 'vhdl-template-alias))
10576 (defun vhdl-template-architecture-hook ()
10577 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10578 (defun vhdl-template-assert-hook ()
10579 (vhdl-hooked-abbrev 'vhdl-template-assert))
10580 (defun vhdl-template-attribute-hook ()
10581 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10582 (defun vhdl-template-block-hook ()
10583 (vhdl-hooked-abbrev 'vhdl-template-block))
10584 (defun vhdl-template-break-hook ()
10585 (vhdl-hooked-abbrev 'vhdl-template-break))
10586 (defun vhdl-template-case-hook ()
10587 (vhdl-hooked-abbrev 'vhdl-template-case))
10588 (defun vhdl-template-component-hook ()
10589 (vhdl-hooked-abbrev 'vhdl-template-component))
10590 (defun vhdl-template-instance-hook ()
10591 (vhdl-hooked-abbrev 'vhdl-template-instance))
10592 (defun vhdl-template-conditional-signal-asst-hook ()
10593 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10594 (defun vhdl-template-configuration-hook ()
10595 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10596 (defun vhdl-template-constant-hook ()
10597 (vhdl-hooked-abbrev 'vhdl-template-constant))
10598 (defun vhdl-template-disconnect-hook ()
10599 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10600 (defun vhdl-template-display-comment-hook ()
10601 (vhdl-hooked-abbrev 'vhdl-comment-display))
10602 (defun vhdl-template-else-hook ()
10603 (vhdl-hooked-abbrev 'vhdl-template-else))
10604 (defun vhdl-template-elsif-hook ()
10605 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10606 (defun vhdl-template-entity-hook ()
10607 (vhdl-hooked-abbrev 'vhdl-template-entity))
10608 (defun vhdl-template-exit-hook ()
10609 (vhdl-hooked-abbrev 'vhdl-template-exit))
10610 (defun vhdl-template-file-hook ()
10611 (vhdl-hooked-abbrev 'vhdl-template-file))
10612 (defun vhdl-template-for-hook ()
10613 (vhdl-hooked-abbrev 'vhdl-template-for))
10614 (defun vhdl-template-function-hook ()
10615 (vhdl-hooked-abbrev 'vhdl-template-function))
10616 (defun vhdl-template-generic-hook ()
10617 (vhdl-hooked-abbrev 'vhdl-template-generic))
10618 (defun vhdl-template-group-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-group))
10620 (defun vhdl-template-library-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-library))
10622 (defun vhdl-template-limit-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-limit))
10624 (defun vhdl-template-if-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-if))
10626 (defun vhdl-template-bare-loop-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10628 (defun vhdl-template-map-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-map))
10630 (defun vhdl-template-nature-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-nature))
10632 (defun vhdl-template-next-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-next))
10634 (defun vhdl-template-others-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-others))
10636 (defun vhdl-template-package-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-package))
10638 (defun vhdl-template-port-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-port))
10640 (defun vhdl-template-procedural-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10642 (defun vhdl-template-procedure-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10644 (defun vhdl-template-process-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-process))
10646 (defun vhdl-template-quantity-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10648 (defun vhdl-template-report-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-report))
10650 (defun vhdl-template-return-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-return))
10652 (defun vhdl-template-selected-signal-asst-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10654 (defun vhdl-template-signal-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-signal))
10656 (defun vhdl-template-subnature-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10658 (defun vhdl-template-subtype-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10660 (defun vhdl-template-terminal-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10662 (defun vhdl-template-type-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-type))
10664 (defun vhdl-template-use-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-use))
10666 (defun vhdl-template-variable-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-variable))
10668 (defun vhdl-template-wait-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-wait))
10670 (defun vhdl-template-when-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-when))
10672 (defun vhdl-template-while-loop-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10674 (defun vhdl-template-with-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-with))
10676 (defun vhdl-template-and-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-and))
10678 (defun vhdl-template-or-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-or))
10680 (defun vhdl-template-nand-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-nand))
10682 (defun vhdl-template-nor-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-nor))
10684 (defun vhdl-template-xor-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-xor))
10686 (defun vhdl-template-xnor-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10688 (defun vhdl-template-not-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-not))
10691 (defun vhdl-template-default-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-default))
10693 (defun vhdl-template-default-indent-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10697 ;; Template insertion from completion list
10699 (defun vhdl-template-insert-construct (name)
10700 "Insert the built-in construct template with NAME."
10702 (list (let ((completion-ignore-case t))
10703 (completing-read "Construct name: "
10704 vhdl-template-construct-alist nil t))))
10705 (vhdl-template-insert-fun
10706 (cadr (assoc name vhdl-template-construct-alist))))
10708 (defun vhdl-template-insert-package (name)
10709 "Insert the built-in package template with NAME."
10711 (list (let ((completion-ignore-case t))
10712 (completing-read "Package name: "
10713 vhdl-template-package-alist nil t))))
10714 (vhdl-template-insert-fun
10715 (cadr (assoc name vhdl-template-package-alist))))
10717 (defun vhdl-template-insert-directive (name)
10718 "Insert the built-in directive template with NAME."
10720 (list (let ((completion-ignore-case t))
10721 (completing-read "Directive name: "
10722 vhdl-template-directive-alist nil t))))
10723 (vhdl-template-insert-fun
10724 (cadr (assoc name vhdl-template-directive-alist))))
10726 (defun vhdl-template-insert-fun (fun)
10727 "Call FUN to insert a built-in template."
10728 (let ((caught (catch 'abort (when fun (funcall fun)))))
10729 (when (stringp caught) (message "%s" caught))))
10732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10734 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10736 (defun vhdl-model-insert (model-name)
10737 "Insert the user model with name MODEL-NAME."
10739 (let ((completion-ignore-case t))
10740 (list (completing-read "Model name: " vhdl-model-alist))))
10741 (indent-according-to-mode)
10742 (let ((start (point-marker))
10743 (margin (current-indentation))
10744 model position prompt string end)
10745 (vhdl-prepare-search-2
10746 (when (setq model (assoc model-name vhdl-model-alist))
10748 (beginning-of-line)
10749 (delete-horizontal-space)
10751 (vhdl-insert-string-or-file (nth 1 model))
10752 (setq end (point-marker))
10755 (beginning-of-line)
10756 (while (< (point) end)
10757 (unless (looking-at "^$")
10758 (insert-char ? margin))
10759 (beginning-of-line 2))
10762 (unless (equal "" vhdl-clock-name)
10763 (while (re-search-forward "<clock>" end t)
10764 (replace-match vhdl-clock-name)))
10767 (unless (equal "" vhdl-reset-name)
10768 (while (re-search-forward "<reset>" end t)
10769 (replace-match vhdl-reset-name)))
10770 ;; replace header prompts
10771 (vhdl-template-replace-header-keywords start end nil t)
10773 ;; query other prompts
10774 (while (re-search-forward
10775 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10776 (unless (equal "cursor" (match-string 1))
10777 (setq position (match-beginning 1))
10778 (setq prompt (match-string 1))
10780 (setq string (vhdl-template-field prompt nil t))
10781 ;; replace occurrences of same prompt
10782 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10783 (replace-match (or string "")))
10784 (goto-char position)))
10786 ;; goto final position
10787 (if (re-search-forward "<cursor>" end t)
10789 (goto-char end))))))
10791 (defun vhdl-model-defun ()
10792 "Define help and hook functions for user models."
10793 (let ((model-alist vhdl-model-alist)
10794 model-name model-keyword)
10796 ;; define functions for user models that can be invoked from menu and key
10797 ;; bindings and which themselves call `vhdl-model-insert' with the model
10798 ;; name as argument
10799 (setq model-name (nth 0 (car model-alist)))
10800 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10801 ,(concat "Insert model for \"" model-name "\".")
10803 (vhdl-model-insert ,model-name)))
10804 ;; define hooks for user models that are invoked from keyword abbrevs
10805 (setq model-keyword (nth 3 (car model-alist)))
10806 (unless (equal model-keyword "")
10808 ,(vhdl-function-name
10809 "vhdl-model" model-name "hook") ()
10810 (vhdl-hooked-abbrev
10811 ',(vhdl-function-name "vhdl-model" model-name)))))
10812 (setq model-alist (cdr model-alist)))))
10817 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10818 ;;; Port translation
10819 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10821 (defvar vhdl-port-list nil
10822 "Variable to hold last port map parsed.")
10823 ;; structure: (parenthesised expression means list of such entries)
10825 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10826 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10827 ;; (lib-name pack-key))
10829 (defun vhdl-parse-string (string &optional optional)
10830 "Check that the text following point matches the regexp in STRING."
10831 (if (looking-at string)
10832 (goto-char (match-end 0))
10834 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10835 (vhdl-current-line) string)))
10838 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10839 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10840 (vhdl-prepare-search-1
10841 (if (string-match (car regexp-cons) string)
10843 (funcall vhdl-file-name-case
10844 (replace-match (cdr regexp-cons) t nil string))
10845 (replace-match (cdr regexp-cons) t nil string))
10848 (defun vhdl-parse-group-comment ()
10849 "Parse comment and empty lines between groups of lines."
10850 (let ((start (point))
10852 (vhdl-forward-comment (point-max))
10853 (setq string (buffer-substring-no-properties start (point)))
10854 (vhdl-forward-syntactic-ws)
10855 ;; strip off leading blanks and first newline
10856 (while (string-match "^\\(\\s-+\\)" string)
10857 (setq string (concat (substring string 0 (match-beginning 1))
10858 (substring string (match-end 1)))))
10859 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10860 (substring string 1)
10863 (defun vhdl-paste-group-comment (string indent)
10864 "Paste comment and empty lines from STRING between groups of lines
10866 (let ((pos (point-marker)))
10868 (while (string-match "^\\(--\\)" string)
10869 (setq string (concat (substring string 0 (match-beginning 1))
10870 (make-string indent ? )
10871 (substring string (match-beginning 1))))))
10872 (beginning-of-line)
10876 (defvar vhdl-port-flattened nil
10877 "Indicates whether a port has been flattened.")
10879 (defun vhdl-port-flatten (&optional as-alist)
10880 "Flatten port list so that only one generic/port exists per line.
10881 This operation is performed on an internally stored port and is only
10882 reflected in a subsequent paste operation."
10884 (if (not vhdl-port-list)
10885 (error "ERROR: No port has been read")
10886 (message "Flattening port for next paste...")
10887 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10888 (old-vhdl-port-list (cdr vhdl-port-list))
10889 old-port-list new-port-list old-port new-port names)
10890 ;; traverse port list and flatten entries
10891 (while (cdr old-vhdl-port-list)
10892 (setq old-port-list (car old-vhdl-port-list))
10893 (setq new-port-list nil)
10894 (while old-port-list
10895 (setq old-port (car old-port-list))
10896 (setq names (car old-port))
10898 (setq new-port (cons (if as-alist (car names) (list (car names)))
10900 (setq new-port-list (append new-port-list (list new-port)))
10901 (setq names (cdr names)))
10902 (setq old-port-list (cdr old-port-list)))
10903 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10904 (setq new-vhdl-port-list (append new-vhdl-port-list
10905 (list new-port-list))))
10906 (setq vhdl-port-list
10907 (append new-vhdl-port-list (list old-vhdl-port-list))
10908 vhdl-port-flattened t)
10909 (message "Flattening port for next paste...done"))))
10911 (defvar vhdl-port-reversed-direction nil
10912 "Indicates whether port directions are reversed.")
10914 (defun vhdl-port-reverse-direction ()
10915 "Reverse direction for all ports (useful in testbenches).
10916 This operation is performed on an internally stored port and is only
10917 reflected in a subsequent paste operation."
10919 (if (not vhdl-port-list)
10920 (error "ERROR: No port has been read")
10921 (message "Reversing port directions for next paste...")
10922 (let ((port-list (nth 2 vhdl-port-list))
10923 port-dir-car port-dir)
10924 ;; traverse port list and reverse directions
10926 (setq port-dir-car (cddr (car port-list))
10927 port-dir (car port-dir-car))
10928 (setcar port-dir-car
10929 (cond ((equal port-dir "in") "out")
10930 ((equal port-dir "out") "in")
10932 (setq port-list (cdr port-list)))
10933 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10934 (message "Reversing port directions for next paste...done"))))
10936 (defun vhdl-port-copy ()
10937 "Get generic and port information from an entity or component declaration."
10940 (let (parse-error end-of-list
10941 decl-type name generic-list port-list context-clause
10942 object names direct type init comment group-comment)
10943 (vhdl-prepare-search-2
10947 ;; check if within entity or component declaration
10949 (when (or (not (re-search-backward
10950 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10951 (equal "END" (upcase (match-string 1))))
10952 (throw 'parse "ERROR: Not within an entity or component declaration"))
10953 (setq decl-type (downcase (match-string-no-properties 1)))
10955 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10956 (setq name (match-string-no-properties 1))
10957 (message "Reading port of %s \"%s\"..." decl-type name)
10958 (vhdl-forward-syntactic-ws)
10959 ;; parse generic clause
10960 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10961 ;; parse group comment and spacing
10962 (setq group-comment (vhdl-parse-group-comment))
10963 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10964 (while (not end-of-list)
10965 ;; parse names (accept extended identifiers)
10966 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10967 (setq names (list (match-string-no-properties 1)))
10968 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10970 (append names (list (match-string-no-properties 1)))))
10972 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10973 (setq type (match-string-no-properties 1))
10975 (while (looking-at "(")
10978 (buffer-substring-no-properties
10979 (point) (progn (forward-sexp) (point)))
10980 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10981 (match-string-no-properties 1)))))
10982 ;; special case: closing parenthesis is on separate line
10983 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10984 (setq comment (substring type (match-beginning 2)))
10985 (setq type (substring type 0 (match-beginning 1))))
10986 ;; strip of trailing group-comment
10987 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10988 (setq type (substring type 0 (match-end 1)))
10989 ;; parse initialization expression
10991 (when (vhdl-parse-string ":=[ \t\n]*" t)
10992 (vhdl-parse-string "\\([^();\n]*\\)")
10993 (setq init (match-string-no-properties 1))
10994 (while (looking-at "(")
10997 (buffer-substring-no-properties
10998 (point) (progn (forward-sexp) (point)))
10999 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11000 (match-string-no-properties 1))))))
11001 ;; special case: closing parenthesis is on separate line
11002 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11003 (setq comment (substring init (match-beginning 2)))
11004 (setq init (substring init 0 (match-beginning 1)))
11005 (vhdl-forward-syntactic-ws))
11006 (skip-chars-forward " \t")
11007 ;; parse inline comment, special case: as above, no initial.
11009 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11010 (match-string-no-properties 1))))
11011 (vhdl-forward-syntactic-ws)
11012 (setq end-of-list (vhdl-parse-string ")" t))
11013 (vhdl-parse-string "\\s-*;\\s-*")
11014 ;; parse inline comment
11016 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11017 (match-string-no-properties 1))))
11018 ;; save everything in list
11019 (setq generic-list (append generic-list
11020 (list (list names type init
11021 comment group-comment))))
11022 ;; parse group comment and spacing
11023 (setq group-comment (vhdl-parse-group-comment))))
11024 ;; parse port clause
11025 (when (vhdl-parse-string "port[ \t\n]*(" t)
11026 ;; parse group comment and spacing
11027 (setq group-comment (vhdl-parse-group-comment))
11028 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11029 (while (not end-of-list)
11032 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11033 (match-string-no-properties 1)))
11034 ;; parse names (accept extended identifiers)
11035 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11036 (setq names (list (match-string-no-properties 1)))
11037 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11038 (setq names (append names (list (match-string-no-properties 1)))))
11040 (vhdl-parse-string ":[ \t\n]*")
11042 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11043 (match-string-no-properties 1)))
11045 (vhdl-parse-string "\\([^();\n]+\\)")
11046 (setq type (match-string-no-properties 1))
11048 (while (looking-at "(")
11049 (setq type (concat type
11050 (buffer-substring-no-properties
11051 (point) (progn (forward-sexp) (point)))
11052 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11053 (match-string-no-properties 1)))))
11054 ;; special case: closing parenthesis is on separate line
11055 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11056 (setq comment (substring type (match-beginning 2)))
11057 (setq type (substring type 0 (match-beginning 1))))
11058 ;; strip of trailing group-comment
11059 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11060 (setq type (substring type 0 (match-end 1)))
11061 (vhdl-forward-syntactic-ws)
11062 (setq end-of-list (vhdl-parse-string ")" t))
11063 (vhdl-parse-string "\\s-*;\\s-*")
11064 ;; parse inline comment
11066 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11067 (match-string-no-properties 1))))
11068 ;; save everything in list
11069 (setq port-list (append port-list
11070 (list (list names object direct type
11071 comment group-comment))))
11072 ;; parse group comment and spacing
11073 (setq group-comment (vhdl-parse-group-comment))))
11074 ; (vhdl-parse-string "end\\>")
11075 ;; parse context clause
11076 (setq context-clause (vhdl-scan-context-clause))
11077 ; ;; add surrounding package to context clause
11078 ; (when (and (equal decl-type "component")
11079 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11080 ; (setq context-clause
11081 ; (append context-clause
11082 ; (list (cons (vhdl-work-library)
11083 ; (match-string-no-properties 1))))))
11084 (message "Reading port of %s \"%s\"...done" decl-type name)
11088 (error parse-error)
11089 (setq vhdl-port-list (list name generic-list port-list context-clause)
11090 vhdl-port-reversed-direction nil
11091 vhdl-port-flattened nil)))))
11093 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11094 "Paste a context clause."
11095 (let ((margin (current-indentation))
11096 (clause-list (nth 3 vhdl-port-list))
11099 (setq clause (car clause-list))
11100 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11101 (downcase exclude-pack-name)))
11103 (re-search-backward
11104 (concat "^\\s-*use\\s-+" (car clause)
11105 "\." (cdr clause) "\\>") nil t)))
11106 (vhdl-template-standard-package (car clause) (cdr clause))
11108 (setq clause-list (cdr clause-list)))))
11110 (defun vhdl-port-paste-generic (&optional no-init)
11111 "Paste a generic clause."
11112 (let ((margin (current-indentation))
11113 (generic-list (nth 1 vhdl-port-list))
11114 list-margin start names generic)
11115 ;; paste generic clause
11117 (setq start (point))
11118 (vhdl-insert-keyword "GENERIC (")
11119 (unless vhdl-argument-list-indent
11120 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11121 (setq list-margin (current-column))
11122 (while generic-list
11123 (setq generic (car generic-list))
11124 ;; paste group comment and spacing
11125 (when (memq vhdl-include-group-comments '(decl always))
11126 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11128 (setq names (nth 0 generic))
11130 (insert (car names))
11131 (setq names (cdr names))
11132 (when names (insert ", ")))
11134 (insert " : " (nth 1 generic))
11135 ;; paste initialization
11136 (when (and (not no-init) (nth 2 generic))
11137 (insert " := " (nth 2 generic)))
11138 (unless (cdr generic-list) (insert ")"))
11141 (when (and vhdl-include-port-comments (nth 3 generic))
11142 (vhdl-comment-insert-inline (nth 3 generic) t))
11143 (setq generic-list (cdr generic-list))
11144 (when generic-list (insert "\n") (indent-to list-margin)))
11145 ;; align generic clause
11146 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11148 (defun vhdl-port-paste-port ()
11149 "Paste a port clause."
11150 (let ((margin (current-indentation))
11151 (port-list (nth 2 vhdl-port-list))
11152 list-margin start names port)
11153 ;; paste port clause
11155 (setq start (point))
11156 (vhdl-insert-keyword "PORT (")
11157 (unless vhdl-argument-list-indent
11158 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11159 (setq list-margin (current-column))
11161 (setq port (car port-list))
11162 ;; paste group comment and spacing
11163 (when (memq vhdl-include-group-comments '(decl always))
11164 (vhdl-paste-group-comment (nth 5 port) list-margin))
11166 (when (nth 1 port) (insert (nth 1 port) " "))
11168 (setq names (nth 0 port))
11170 (insert (car names))
11171 (setq names (cdr names))
11172 (when names (insert ", ")))
11175 (when (nth 2 port) (insert (nth 2 port) " "))
11177 (insert (nth 3 port))
11178 (unless (cdr port-list) (insert ")"))
11181 (when (and vhdl-include-port-comments (nth 4 port))
11182 (vhdl-comment-insert-inline (nth 4 port) t))
11183 (setq port-list (cdr port-list))
11184 (when port-list (insert "\n") (indent-to list-margin)))
11185 ;; align port clause
11186 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11188 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11189 "Paste as an entity or component declaration."
11190 (unless no-indent (indent-according-to-mode))
11191 (let ((margin (current-indentation))
11192 (name (nth 0 vhdl-port-list)))
11193 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11195 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11196 (vhdl-insert-keyword " IS"))
11197 ;; paste generic and port clause
11198 (when (nth 1 vhdl-port-list)
11200 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11202 (indent-to (+ margin vhdl-basic-offset))
11203 (vhdl-port-paste-generic (eq kind 'component)))
11204 (when (nth 2 vhdl-port-list)
11206 (when (and (memq vhdl-insert-empty-lines '(unit all))
11209 (indent-to (+ margin vhdl-basic-offset)))
11210 (vhdl-port-paste-port)
11212 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11215 (vhdl-insert-keyword "END")
11216 (if (eq kind 'entity)
11218 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11220 (vhdl-insert-keyword " COMPONENT")
11221 (unless (vhdl-standard-p '87) (insert " " name)))
11224 (defun vhdl-port-paste-entity (&optional no-indent)
11225 "Paste as an entity declaration."
11227 (if (not vhdl-port-list)
11228 (error "ERROR: No port read")
11229 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11230 (vhdl-port-paste-declaration 'entity no-indent)
11231 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11233 (defun vhdl-port-paste-component (&optional no-indent)
11234 "Paste as a component declaration."
11236 (if (not vhdl-port-list)
11237 (error "ERROR: No port read")
11238 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11239 (vhdl-port-paste-declaration 'component no-indent)
11240 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11242 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11243 "Paste as a generic map."
11245 (unless secondary (indent-according-to-mode))
11246 (let ((margin (current-indentation))
11247 list-margin start generic
11248 (generic-list (nth 1 vhdl-port-list)))
11250 (setq start (point))
11251 (vhdl-insert-keyword "GENERIC MAP (")
11252 (if (not vhdl-association-list-with-formals)
11253 ;; paste list of actual generics
11254 (while generic-list
11255 (insert (if no-constants
11256 (car (nth 0 (car generic-list)))
11257 (or (nth 2 (car generic-list)) " ")))
11258 (setq generic-list (cdr generic-list))
11259 (insert (if generic-list ", " ")"))
11260 (when (and (not generic-list) secondary
11261 (null (nth 2 vhdl-port-list)))
11263 (unless vhdl-argument-list-indent
11264 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11265 (setq list-margin (current-column))
11266 (while generic-list
11267 (setq generic (car generic-list))
11268 ;; paste group comment and spacing
11269 (when (eq vhdl-include-group-comments 'always)
11270 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11271 ;; paste formal and actual generic
11272 (insert (car (nth 0 generic)) " => "
11274 (car (nth 0 generic))
11275 (or (nth 2 generic) "")))
11276 (setq generic-list (cdr generic-list))
11277 (insert (if generic-list "," ")"))
11278 (when (and (not generic-list) secondary
11279 (null (nth 2 vhdl-port-list)))
11282 (when (or vhdl-include-type-comments
11283 (and vhdl-include-port-comments (nth 3 generic)))
11284 (vhdl-comment-insert-inline
11286 (when vhdl-include-type-comments
11287 (concat "[" (nth 1 generic) "] "))
11288 (when vhdl-include-port-comments (nth 3 generic))) t))
11289 (when generic-list (insert "\n") (indent-to list-margin)))
11290 ;; align generic map
11291 (when vhdl-auto-align
11292 (vhdl-align-region-groups start (point) 1 t))))))
11294 (defun vhdl-port-paste-port-map ()
11295 "Paste as a port map."
11296 (let ((margin (current-indentation))
11297 list-margin start port
11298 (port-list (nth 2 vhdl-port-list)))
11300 (setq start (point))
11301 (vhdl-insert-keyword "PORT MAP (")
11302 (if (not vhdl-association-list-with-formals)
11303 ;; paste list of actual ports
11305 (insert (vhdl-replace-string vhdl-actual-port-name
11306 (car (nth 0 (car port-list)))))
11307 (setq port-list (cdr port-list))
11308 (insert (if port-list ", " ")")))
11309 (unless vhdl-argument-list-indent
11310 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11311 (setq list-margin (current-column))
11313 (setq port (car port-list))
11314 ;; paste group comment and spacing
11315 (when (eq vhdl-include-group-comments 'always)
11316 (vhdl-paste-group-comment (nth 5 port) list-margin))
11317 ;; paste formal and actual port
11318 (insert (car (nth 0 port)) " => ")
11319 (insert (vhdl-replace-string vhdl-actual-port-name
11320 (car (nth 0 port))))
11321 (setq port-list (cdr port-list))
11322 (insert (if port-list "," ");"))
11324 (when (or vhdl-include-direction-comments
11325 vhdl-include-type-comments
11326 (and vhdl-include-port-comments (nth 4 port)))
11327 (vhdl-comment-insert-inline
11329 (cond ((and vhdl-include-direction-comments
11330 vhdl-include-type-comments)
11331 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11332 (nth 3 port) "] "))
11333 ((and vhdl-include-direction-comments (nth 2 port))
11334 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11335 (vhdl-include-direction-comments " ")
11336 (vhdl-include-type-comments
11337 (concat "[" (nth 3 port) "] ")))
11338 (when vhdl-include-port-comments (nth 4 port))) t))
11339 (when port-list (insert "\n") (indent-to list-margin)))
11340 ;; align port clause
11341 (when vhdl-auto-align
11342 (vhdl-align-region-groups start (point) 1))))))
11344 (defun vhdl-port-paste-instance (&optional name no-indent title)
11345 "Paste as an instantiation."
11347 (if (not vhdl-port-list)
11348 (error "ERROR: No port read")
11349 (let ((orig-vhdl-port-list vhdl-port-list))
11350 ;; flatten local copy of port list (must be flat for port mapping)
11351 (vhdl-port-flatten)
11352 (unless no-indent (indent-according-to-mode))
11353 (let ((margin (current-indentation)))
11354 ;; paste instantiation
11357 ((equal (cdr vhdl-instance-name) "")
11358 (setq name (vhdl-template-field "instance name")))
11359 ((string-match "\%d" (cdr vhdl-instance-name))
11361 (while (save-excursion
11362 (setq name (format (vhdl-replace-string
11364 (nth 0 vhdl-port-list)) n))
11365 (goto-char (point-min))
11366 (vhdl-re-search-forward name nil t))
11369 (t (insert (vhdl-replace-string vhdl-instance-name
11370 (nth 0 vhdl-port-list)))))
11371 (message "Pasting port as instantiation \"%s\"..." name)
11375 (beginning-of-line)
11376 (indent-to vhdl-basic-offset)
11377 (insert "-- instance \"" name "\"\n")))
11378 (if (not (vhdl-use-direct-instantiation))
11379 (insert (nth 0 vhdl-port-list))
11380 (vhdl-insert-keyword "ENTITY ")
11381 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11382 (when (nth 1 vhdl-port-list)
11383 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11384 (vhdl-port-paste-generic-map t t))
11385 (when (nth 2 vhdl-port-list)
11386 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11387 (vhdl-port-paste-port-map))
11388 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11390 (message "Pasting port as instantiation \"%s\"...done" name))
11391 (setq vhdl-port-list orig-vhdl-port-list))))
11393 (defun vhdl-port-paste-constants (&optional no-indent)
11394 "Paste generics as constants."
11396 (if (not vhdl-port-list)
11397 (error "ERROR: No port read")
11398 (let ((orig-vhdl-port-list vhdl-port-list))
11399 (message "Pasting port as constants...")
11400 ;; flatten local copy of port list (must be flat for constant initial.)
11401 (vhdl-port-flatten)
11402 (unless no-indent (indent-according-to-mode))
11403 (let ((margin (current-indentation))
11405 (generic-list (nth 1 vhdl-port-list)))
11407 (setq start (point))
11408 (while generic-list
11409 (setq generic (car generic-list))
11410 ;; paste group comment and spacing
11411 (when (memq vhdl-include-group-comments '(decl always))
11412 (vhdl-paste-group-comment (nth 4 generic) margin))
11413 (vhdl-insert-keyword "CONSTANT ")
11414 ;; paste generic constants
11415 (setq name (nth 0 generic))
11417 (insert (car name))
11419 (insert " : " (nth 1 generic))
11420 ;; paste initialization
11421 (when (nth 2 generic)
11422 (insert " := " (nth 2 generic)))
11425 (when (and vhdl-include-port-comments (nth 3 generic))
11426 (vhdl-comment-insert-inline (nth 3 generic) t))
11427 (setq generic-list (cdr generic-list))
11428 (when generic-list (insert "\n") (indent-to margin))))
11429 ;; align signal list
11430 (when vhdl-auto-align
11431 (vhdl-align-region-groups start (point) 1))))
11432 (message "Pasting port as constants...done")
11433 (setq vhdl-port-list orig-vhdl-port-list))))
11435 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11436 "Paste ports as internal signals."
11438 (if (not vhdl-port-list)
11439 (error "ERROR: No port read")
11440 (message "Pasting port as signals...")
11441 (unless no-indent (indent-according-to-mode))
11442 (let ((margin (current-indentation))
11444 (port-list (nth 2 vhdl-port-list)))
11446 (setq start (point))
11448 (setq port (car port-list))
11449 ;; paste group comment and spacing
11450 (when (memq vhdl-include-group-comments '(decl always))
11451 (vhdl-paste-group-comment (nth 5 port) margin))
11454 (insert (nth 1 port) " ")
11455 (vhdl-insert-keyword "SIGNAL "))
11456 ;; paste actual port signals
11457 (setq names (nth 0 port))
11459 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11460 (setq names (cdr names))
11461 (when names (insert ", ")))
11463 (insert " : " (nth 3 port))
11464 ;; paste initialization (inputs only)
11465 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11466 (insert " := " (if (string-match "(.+)" (nth 3 port))
11467 "(others => '0')" "'0'")))
11470 (when (or vhdl-include-direction-comments
11471 (and vhdl-include-port-comments (nth 4 port)))
11472 (vhdl-comment-insert-inline
11474 (cond ((and vhdl-include-direction-comments (nth 2 port))
11475 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11476 (vhdl-include-direction-comments " "))
11477 (when vhdl-include-port-comments (nth 4 port))) t))
11478 (setq port-list (cdr port-list))
11479 (when port-list (insert "\n") (indent-to margin)))
11480 ;; align signal list
11481 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11482 (message "Pasting port as signals...done")))
11484 (defun vhdl-port-paste-initializations (&optional no-indent)
11485 "Paste ports as signal initializations."
11487 (if (not vhdl-port-list)
11488 (error "ERROR: No port read")
11489 (let ((orig-vhdl-port-list vhdl-port-list))
11490 (message "Pasting port as initializations...")
11491 ;; flatten local copy of port list (must be flat for signal initial.)
11492 (vhdl-port-flatten)
11493 (unless no-indent (indent-according-to-mode))
11494 (let ((margin (current-indentation))
11496 (port-list (nth 2 vhdl-port-list)))
11498 (setq start (point))
11500 (setq port (car port-list))
11501 ;; paste actual port signal (inputs only)
11502 (when (equal "IN" (upcase (nth 2 port)))
11503 (setq name (car (nth 0 port)))
11504 (insert (vhdl-replace-string vhdl-actual-port-name name))
11505 ;; paste initialization
11506 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11507 "(others => '0')" "'0'") ";"))
11508 (setq port-list (cdr port-list))
11509 (when (and port-list
11510 (equal "IN" (upcase (nth 2 (car port-list)))))
11511 (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 initializations...done")
11515 (setq vhdl-port-list orig-vhdl-port-list))))
11517 (defun vhdl-port-paste-testbench ()
11518 "Paste as a bare-bones testbench."
11520 (if (not vhdl-port-list)
11521 (error "ERROR: No port read")
11522 (let ((case-fold-search t)
11523 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11524 (nth 0 vhdl-port-list)))
11525 (source-buffer (current-buffer))
11526 arch-name config-name ent-file-name arch-file-name
11527 ent-buffer arch-buffer position)
11528 ;; open entity file
11529 (unless (eq vhdl-testbench-create-files 'none)
11530 (setq ent-file-name
11531 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11533 "." (file-name-extension (buffer-file-name))))
11534 (if (file-exists-p ent-file-name)
11536 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11537 (progn (find-file ent-file-name)
11539 (set-buffer-modified-p nil))
11540 (if (eq vhdl-testbench-create-files 'separate)
11541 (setq ent-file-name nil)
11542 (error "ERROR: Pasting port as testbench...aborted")))
11543 (find-file ent-file-name)))
11544 (unless (and (eq vhdl-testbench-create-files 'separate)
11545 (null ent-file-name))
11546 ;; paste entity header
11547 (if vhdl-testbench-include-header
11548 (progn (vhdl-template-header
11549 (concat "Testbench for design \""
11550 (nth 0 vhdl-port-list) "\""))
11551 (goto-char (point-max)))
11552 (vhdl-comment-display-line) (insert "\n\n"))
11553 ;; paste std_logic_1164 package
11554 (when vhdl-testbench-include-library
11555 (vhdl-template-package-std-logic-1164)
11556 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11557 ;; paste entity declaration
11558 (vhdl-insert-keyword "ENTITY ")
11560 (vhdl-insert-keyword " IS")
11561 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11563 (vhdl-insert-keyword "END ")
11564 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11565 (insert ent-name ";")
11567 (vhdl-comment-display-line) (insert "\n"))
11568 ;; get architecture name
11569 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11570 (read-from-minibuffer "architecture name: "
11571 nil vhdl-minibuffer-local-map)
11572 (vhdl-replace-string vhdl-testbench-architecture-name
11573 (nth 0 vhdl-port-list))))
11574 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11575 ;; open architecture file
11576 (if (not (eq vhdl-testbench-create-files 'separate))
11578 (setq ent-buffer (current-buffer))
11579 (setq arch-file-name
11580 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11581 (concat ent-name " " arch-name) t)
11582 "." (file-name-extension (buffer-file-name))))
11583 (when (and (file-exists-p arch-file-name)
11584 (not (y-or-n-p (concat "File \"" arch-file-name
11585 "\" exists; overwrite? "))))
11586 (error "ERROR: Pasting port as testbench...aborted"))
11587 (find-file arch-file-name)
11589 (set-buffer-modified-p nil)
11590 ;; paste architecture header
11591 (if vhdl-testbench-include-header
11592 (progn (vhdl-template-header
11593 (concat "Testbench architecture for design \""
11594 (nth 0 vhdl-port-list) "\""))
11595 (goto-char (point-max)))
11596 (vhdl-comment-display-line) (insert "\n\n")))
11597 ;; paste architecture body
11598 (vhdl-insert-keyword "ARCHITECTURE ")
11600 (vhdl-insert-keyword " OF ")
11602 (vhdl-insert-keyword " IS")
11603 (insert "\n\n") (indent-to vhdl-basic-offset)
11604 ;; paste component declaration
11605 (unless (vhdl-use-direct-instantiation)
11606 (vhdl-port-paste-component t)
11607 (insert "\n\n") (indent-to vhdl-basic-offset))
11609 (when (nth 1 vhdl-port-list)
11610 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11611 (vhdl-port-paste-constants t)
11612 (insert "\n\n") (indent-to vhdl-basic-offset))
11613 ;; paste internal signals
11614 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11615 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11617 ;; paste custom declarations
11618 (unless (equal "" vhdl-testbench-declarations)
11620 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11621 (setq position (point))
11623 (vhdl-comment-display-line) (insert "\n")
11624 (when vhdl-testbench-include-configuration
11625 (setq config-name (vhdl-replace-string
11626 vhdl-testbench-configuration-name
11627 (concat ent-name " " arch-name)))
11629 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11630 (vhdl-insert-keyword " OF ") (insert ent-name)
11631 (vhdl-insert-keyword " IS\n")
11632 (indent-to vhdl-basic-offset)
11633 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11634 (indent-to vhdl-basic-offset)
11635 (vhdl-insert-keyword "END FOR;\n")
11636 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11637 (vhdl-comment-display-line) (insert "\n"))
11638 (goto-char position)
11639 (vhdl-template-begin-end
11640 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11641 ;; paste instantiation
11642 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11643 (vhdl-port-paste-instance
11644 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11646 ;; paste custom statements
11647 (unless (equal "" vhdl-testbench-statements)
11649 (vhdl-insert-string-or-file vhdl-testbench-statements))
11651 (indent-to vhdl-basic-offset)
11652 (unless (eq vhdl-testbench-create-files 'none)
11653 (setq arch-buffer (current-buffer))
11654 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11655 (set-buffer arch-buffer) (save-buffer))
11657 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11658 ent-name arch-name)
11660 (format "\n File created: \"%s\"" ent-file-name))
11661 (and arch-file-name
11662 (format "\n File created: \"%s\"" arch-file-name)))))))
11665 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11666 ;;; Subprogram interface translation
11667 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11669 (defvar vhdl-subprog-list nil
11670 "Variable to hold last subprogram interface parsed.")
11671 ;; structure: (parenthesised expression means list of such entries)
11672 ;; (subprog-name kind
11673 ;; ((names) object direct type init comment group-comment)
11674 ;; return-type return-comment group-comment)
11676 (defvar vhdl-subprog-flattened nil
11677 "Indicates whether an subprogram interface has been flattened.")
11679 (defun vhdl-subprog-flatten ()
11680 "Flatten interface list so that only one parameter exists per line."
11682 (if (not vhdl-subprog-list)
11683 (error "ERROR: No subprogram interface has been read")
11684 (message "Flattening subprogram interface...")
11685 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11686 new-subprog-list old-subprog new-subprog names)
11687 ;; traverse parameter list and flatten entries
11688 (while old-subprog-list
11689 (setq old-subprog (car old-subprog-list))
11690 (setq names (car old-subprog))
11692 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11693 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11694 (setq names (cdr names)))
11695 (setq old-subprog-list (cdr old-subprog-list)))
11696 (setq vhdl-subprog-list
11697 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11698 new-subprog-list (nth 3 vhdl-subprog-list)
11699 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11700 vhdl-subprog-flattened t)
11701 (message "Flattening subprogram interface...done"))))
11703 (defun vhdl-subprog-copy ()
11704 "Get interface information from a subprogram specification."
11707 (let (parse-error pos end-of-list
11708 name kind param-list object names direct type init
11709 comment group-comment
11710 return-type return-comment return-group-comment)
11711 (vhdl-prepare-search-2
11715 ;; check if within function declaration
11718 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11719 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11720 (goto-char (match-end 0))
11721 (save-excursion (backward-char)
11724 (throw 'parse "ERROR: Not within a subprogram specification"))
11725 (setq name (match-string-no-properties 5))
11726 (setq kind (if (match-string 2) 'procedure 'function))
11727 (setq end-of-list (not (match-string 7)))
11728 (message "Reading interface of subprogram \"%s\"..." name)
11729 ;; parse parameter list
11730 (setq group-comment (vhdl-parse-group-comment))
11731 (setq end-of-list (or end-of-list
11732 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11733 (while (not end-of-list)
11736 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11737 (match-string-no-properties 1)))
11738 ;; parse names (accept extended identifiers)
11739 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11740 (setq names (list (match-string-no-properties 1)))
11741 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11742 (setq names (append names (list (match-string-no-properties 1)))))
11744 (vhdl-parse-string ":[ \t\n]*")
11746 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11747 (match-string-no-properties 1)))
11749 (vhdl-parse-string "\\([^():;\n]+\\)")
11750 (setq type (match-string-no-properties 1))
11752 (while (looking-at "(")
11755 (buffer-substring-no-properties
11756 (point) (progn (forward-sexp) (point)))
11757 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11758 (match-string-no-properties 1)))))
11759 ;; special case: closing parenthesis is on separate line
11760 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11761 (setq comment (substring type (match-beginning 2)))
11762 (setq type (substring type 0 (match-beginning 1))))
11763 ;; strip off trailing group-comment
11764 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11765 (setq type (substring type 0 (match-end 1)))
11766 ;; parse initialization expression
11768 (when (vhdl-parse-string ":=[ \t\n]*" t)
11769 (vhdl-parse-string "\\([^();\n]*\\)")
11770 (setq init (match-string-no-properties 1))
11771 (while (looking-at "(")
11774 (buffer-substring-no-properties
11775 (point) (progn (forward-sexp) (point)))
11776 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11777 (match-string-no-properties 1))))))
11778 ;; special case: closing parenthesis is on separate line
11779 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11780 (setq comment (substring init (match-beginning 2)))
11781 (setq init (substring init 0 (match-beginning 1)))
11782 (vhdl-forward-syntactic-ws))
11783 (skip-chars-forward " \t")
11784 ;; parse inline comment, special case: as above, no initial.
11786 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11787 (match-string-no-properties 1))))
11788 (vhdl-forward-syntactic-ws)
11789 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11790 ;; parse inline comment
11792 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11793 (match-string-no-properties 1))))
11794 (setq return-group-comment (vhdl-parse-group-comment))
11795 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11796 ;; parse return type
11797 (when (match-string 3)
11798 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11799 (setq return-type (match-string-no-properties 1))
11800 (when (and return-type
11801 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11802 (setq return-comment (substring return-type (match-beginning 2)))
11803 (setq return-type (substring return-type 0 (match-beginning 1))))
11804 ;; strip of trailing group-comment
11805 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11806 (setq return-type (substring return-type 0 (match-end 1)))
11807 ;; parse return comment
11808 (unless return-comment
11809 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11810 (match-string-no-properties 1)))))
11811 ;; parse inline comment
11813 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11814 (match-string-no-properties 1))))
11815 ;; save everything in list
11816 (setq param-list (append param-list
11817 (list (list names object direct type init
11818 comment group-comment))))
11819 ;; parse group comment and spacing
11820 (setq group-comment (vhdl-parse-group-comment)))
11821 (message "Reading interface of subprogram \"%s\"...done" name)
11825 (error parse-error)
11826 (setq vhdl-subprog-list
11827 (list name kind param-list return-type return-comment
11828 return-group-comment)
11829 vhdl-subprog-flattened nil)))))
11831 (defun vhdl-subprog-paste-specification (kind)
11832 "Paste as a subprogram specification."
11833 (indent-according-to-mode)
11834 (let ((margin (current-column))
11835 (param-list (nth 2 vhdl-subprog-list))
11836 list-margin start names param)
11837 ;; paste keyword and name
11838 (vhdl-insert-keyword
11839 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11840 (insert (nth 0 vhdl-subprog-list))
11841 (if (not param-list)
11842 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11843 (setq start (point))
11844 ;; paste parameter list
11846 (unless vhdl-argument-list-indent
11847 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11848 (setq list-margin (current-column))
11850 (setq param (car param-list))
11851 ;; paste group comment and spacing
11852 (when (memq vhdl-include-group-comments (list kind 'always))
11853 (vhdl-paste-group-comment (nth 6 param) list-margin))
11855 (when (nth 1 param) (insert (nth 1 param) " "))
11857 (setq names (nth 0 param))
11859 (insert (car names))
11860 (setq names (cdr names))
11861 (when names (insert ", ")))
11864 (when (nth 2 param) (insert (nth 2 param) " "))
11866 (insert (nth 3 param))
11867 ;; paste initialization
11868 (when (nth 4 param) (insert " := " (nth 4 param)))
11870 (if (cdr param-list)
11873 (when (null (nth 3 vhdl-subprog-list))
11874 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11876 (when (and vhdl-include-port-comments (nth 5 param))
11877 (vhdl-comment-insert-inline (nth 5 param) t))
11878 (setq param-list (cdr param-list))
11879 (when param-list (insert "\n") (indent-to list-margin)))
11880 (when (nth 3 vhdl-subprog-list)
11881 (insert "\n") (indent-to list-margin)
11882 ;; paste group comment and spacing
11883 (when (memq vhdl-include-group-comments (list kind 'always))
11884 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11885 ;; paste return type
11886 (insert "return " (nth 3 vhdl-subprog-list))
11887 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11888 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11889 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11890 ;; align parameter list
11891 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11893 (when (eq kind 'body)
11895 (vhdl-template-begin-end
11896 (unless (vhdl-standard-p '87)
11897 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11898 (nth 0 vhdl-subprog-list) margin))))
11900 (defun vhdl-subprog-paste-declaration ()
11901 "Paste as a subprogram declaration."
11903 (if (not vhdl-subprog-list)
11904 (error "ERROR: No subprogram interface read")
11905 (message "Pasting interface as subprogram declaration \"%s\"..."
11906 (car vhdl-subprog-list))
11907 ;; paste specification
11908 (vhdl-subprog-paste-specification 'decl)
11909 (message "Pasting interface as subprogram declaration \"%s\"...done"
11910 (car vhdl-subprog-list))))
11912 (defun vhdl-subprog-paste-body ()
11913 "Paste as a subprogram body."
11915 (if (not vhdl-subprog-list)
11916 (error "ERROR: No subprogram interface read")
11917 (message "Pasting interface as subprogram body \"%s\"..."
11918 (car vhdl-subprog-list))
11919 ;; paste specification and body
11920 (vhdl-subprog-paste-specification 'body)
11921 (message "Pasting interface as subprogram body \"%s\"...done"
11922 (car vhdl-subprog-list))))
11924 (defun vhdl-subprog-paste-call ()
11925 "Paste as a subprogram call."
11927 (if (not vhdl-subprog-list)
11928 (error "ERROR: No subprogram interface read")
11929 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11930 param-list margin list-margin param start)
11931 ;; flatten local copy of interface list (must be flat for parameter mapping)
11932 (vhdl-subprog-flatten)
11933 (setq param-list (nth 2 vhdl-subprog-list))
11934 (indent-according-to-mode)
11935 (setq margin (current-indentation))
11936 (message "Pasting interface as subprogram call \"%s\"..."
11937 (car vhdl-subprog-list))
11939 (insert (nth 0 vhdl-subprog-list))
11940 (if (not param-list)
11942 (setq start (point))
11943 ;; paste parameter list
11945 (unless vhdl-argument-list-indent
11946 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11947 (setq list-margin (current-column))
11949 (setq param (car param-list))
11950 ;; paste group comment and spacing
11951 (when (eq vhdl-include-group-comments 'always)
11952 (vhdl-paste-group-comment (nth 6 param) list-margin))
11953 ;; paste formal port
11954 (insert (car (nth 0 param)) " => ")
11955 (setq param-list (cdr param-list))
11956 (insert (if param-list "," ");"))
11958 (when (and vhdl-include-port-comments (nth 5 param))
11959 (vhdl-comment-insert-inline (nth 5 param)))
11960 (when param-list (insert "\n") (indent-to list-margin)))
11961 ;; align parameter list
11962 (when vhdl-auto-align
11963 (vhdl-align-region-groups start (point) 1)))
11964 (message "Pasting interface as subprogram call \"%s\"...done"
11965 (car vhdl-subprog-list))
11966 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11971 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11974 ;; Hippie expand customization
11976 (defvar vhdl-expand-upper-case nil)
11978 (defun vhdl-try-expand-abbrev (old)
11979 "Try expanding abbreviations from `vhdl-abbrev-list'."
11981 (he-init-string (he-dabbrev-beg) (point))
11982 (setq he-expand-list
11983 (let ((abbrev-list vhdl-abbrev-list)
11984 (sel-abbrev-list '()))
11986 (when (or (not (stringp (car abbrev-list)))
11988 (concat "^" he-search-string) (car abbrev-list)))
11989 (setq sel-abbrev-list
11990 (cons (car abbrev-list) sel-abbrev-list)))
11991 (setq abbrev-list (cdr abbrev-list)))
11992 (nreverse sel-abbrev-list))))
11993 (while (and he-expand-list
11994 (or (not (stringp (car he-expand-list)))
11995 (he-string-member (car he-expand-list) he-tried-table t)))
11996 ; (equal (car he-expand-list) he-search-string)))
11997 (unless (stringp (car he-expand-list))
11998 (setq vhdl-expand-upper-case (car he-expand-list)))
11999 (setq he-expand-list (cdr he-expand-list)))
12000 (if (null he-expand-list)
12001 (progn (when old (he-reset-string))
12003 (he-substitute-string
12004 (if vhdl-expand-upper-case
12005 (upcase (car he-expand-list))
12006 (car he-expand-list))
12008 (setq he-expand-list (cdr he-expand-list))
12011 (defun vhdl-he-list-beg ()
12012 "Also looks at the word before `(' in order to better match parenthesized
12013 expressions (e.g. for index ranges of types and signals)."
12016 (progn (backward-up-list 1)
12017 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12021 ;; override `he-list-beg' from `hippie-exp'
12022 (unless (and (boundp 'viper-mode) viper-mode)
12023 (defalias 'he-list-beg 'vhdl-he-list-beg))
12025 ;; function for expanding abbrevs and dabbrevs
12026 (defun vhdl-expand-abbrev (arg))
12027 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12028 '(try-expand-dabbrev
12029 try-expand-dabbrev-all-buffers
12030 vhdl-try-expand-abbrev)))
12032 ;; function for expanding parenthesis
12033 (defun vhdl-expand-paren (arg))
12034 (fset 'vhdl-expand-paren (make-hippie-expand-function
12036 try-expand-list-all-buffers)))
12038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12041 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12042 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12043 depending on parameter UPPER-CASE."
12044 (let ((case-replace nil)
12046 (vhdl-prepare-search-2
12049 (setq end (point-marker))
12051 (while (re-search-forward word-regexp end t)
12052 (or (vhdl-in-literal)
12055 (downcase-word -1)))
12056 (when (and count vhdl-progress-interval (not noninteractive)
12057 (< vhdl-progress-interval
12058 (- (nth 1 (current-time)) last-update)))
12059 (message "Fixing case... (%2d%s)"
12060 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12062 (setq last-update (nth 1 (current-time)))))
12063 (goto-char end)))))
12065 (defun vhdl-fix-case-region (beg end &optional arg)
12066 "Convert all VHDL words in region to lower or upper case, depending on
12067 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12068 (interactive "r\nP")
12069 (vhdl-fix-case-region-1
12070 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12071 (vhdl-fix-case-region-1
12072 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12073 (vhdl-fix-case-region-1
12074 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12075 (vhdl-fix-case-region-1
12076 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12077 (when vhdl-progress-interval (message "Fixing case...done")))
12079 (defun vhdl-fix-case-buffer ()
12080 "Convert all VHDL words in buffer to lower or upper case, depending on
12081 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12083 (vhdl-fix-case-region (point-min) (point-max)))
12085 (defun vhdl-fix-case-word (&optional arg)
12086 "Convert word after cursor to upper case if necessary."
12089 (when arg (backward-word 1))
12090 (vhdl-prepare-search-1
12091 (when (and vhdl-upper-case-keywords
12092 (looking-at vhdl-keywords-regexp))
12094 (when (and vhdl-upper-case-types
12095 (looking-at vhdl-types-regexp))
12097 (when (and vhdl-upper-case-attributes
12098 (looking-at vhdl-attributes-regexp))
12100 (when (and vhdl-upper-case-enum-values
12101 (looking-at vhdl-enum-values-regexp))
12102 (upcase-word 1)))))
12104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12105 ;; Line handling functions
12107 (defun vhdl-current-line ()
12108 "Return the line number of the line containing point."
12112 (beginning-of-line)
12113 (1+ (count-lines (point-min) (point))))))
12115 (defun vhdl-line-kill-entire (&optional arg)
12116 "Delete entire line."
12118 (beginning-of-line)
12119 (kill-line (or arg 1)))
12121 (defun vhdl-line-kill (&optional arg)
12122 "Kill current line."
12124 (vhdl-line-kill-entire arg))
12126 (defun vhdl-line-copy (&optional arg)
12127 "Copy current line."
12130 (beginning-of-line)
12131 (let ((position (point)))
12132 (forward-line (or arg 1))
12133 (copy-region-as-kill position (point)))))
12135 (defun vhdl-line-yank ()
12136 "Yank entire line."
12138 (beginning-of-line)
12141 (defun vhdl-line-expand (&optional prefix-arg)
12142 "Hippie-expand current line."
12144 (let ((case-fold-search t) (case-replace nil)
12145 (hippie-expand-try-functions-list
12146 '(try-expand-line try-expand-line-all-buffers)))
12147 (hippie-expand prefix-arg)))
12149 (defun vhdl-line-transpose-next (&optional arg)
12150 "Interchange this line with next line."
12153 (transpose-lines (or arg 1))
12156 (defun vhdl-line-transpose-previous (&optional arg)
12157 "Interchange this line with previous line."
12160 (transpose-lines (- 0 (or arg 0)))
12163 (defun vhdl-line-open ()
12164 "Open a new line and indent."
12167 (newline-and-indent))
12169 (defun vhdl-delete-indentation ()
12170 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12171 it works within comments too."
12173 (let ((fill-prefix "-- "))
12174 (delete-indentation)))
12176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12179 (defun vhdl-forward-same-indent ()
12180 "Move forward to next line with same indent."
12182 (let ((pos (point))
12183 (indent (current-indentation)))
12184 (beginning-of-line 2)
12185 (while (and (not (eobp))
12186 (or (looking-at "^\\s-*\\(--.*\\)?$")
12187 (> (current-indentation) indent)))
12188 (beginning-of-line 2))
12189 (if (= (current-indentation) indent)
12190 (back-to-indentation)
12191 (message "No following line with same indent found in this block")
12195 (defun vhdl-backward-same-indent ()
12196 "Move backward to previous line with same indent."
12198 (let ((pos (point))
12199 (indent (current-indentation)))
12200 (beginning-of-line -0)
12201 (while (and (not (bobp))
12202 (or (looking-at "^\\s-*\\(--.*\\)?$")
12203 (> (current-indentation) indent)))
12204 (beginning-of-line -0))
12205 (if (= (current-indentation) indent)
12206 (back-to-indentation)
12207 (message "No preceding line with same indent found in this block")
12211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12214 (defun vhdl-statistics-buffer ()
12215 "Get some file statistics."
12219 (no-lines (count-lines (point-min) (point-max))))
12221 ;; count statements
12222 (goto-char (point-min))
12223 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12224 (if (match-string 1)
12225 (goto-char (match-end 1))
12226 (setq no-stats (1+ no-stats))))
12227 ;; count code lines
12228 (goto-char (point-min))
12229 (while (not (eobp))
12230 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12231 (setq no-code-lines (1+ no-code-lines)))
12232 (beginning-of-line 2)))
12235 File statistics: \"%s\"\n\
12236 ---------------------\n\
12237 # statements : %5d\n\
12238 # code lines : %5d\n\
12239 # total lines : %5d\n\ "
12240 (buffer-file-name) no-stats no-code-lines no-lines)
12241 (unless vhdl-emacs-21 (vhdl-show-messages))))
12243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12246 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12247 "Like `re-search-forward', but does not match within literals."
12250 (while (and (setq pos (re-search-forward regexp bound noerror count))
12251 (vhdl-in-literal))))
12252 (when pos (goto-char pos))
12255 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12256 "Like `re-search-backward', but does not match within literals."
12259 (while (and (setq pos (re-search-backward regexp bound noerror count))
12260 (vhdl-in-literal))))
12261 (when pos (goto-char pos))
12265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12269 (defun vhdl-set-project (name)
12270 "Set current project to NAME."
12272 (list (let ((completion-ignore-case t))
12273 (completing-read "Project name: " vhdl-project-alist nil t))))
12274 (cond ((equal name "")
12275 (setq vhdl-project nil)
12276 (message "Current VHDL project: None"))
12277 ((assoc name vhdl-project-alist)
12278 (setq vhdl-project name)
12279 (message "Current VHDL project: \"%s\"" name))
12281 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12282 (vhdl-speedbar-update-current-project))
12284 (defun vhdl-set-default-project ()
12285 "Set current project as default on startup."
12287 (customize-set-variable 'vhdl-project vhdl-project)
12288 (customize-save-customized))
12290 (defun vhdl-toggle-project (name token indent)
12291 "Set current project to NAME or unset if NAME is current project."
12292 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12294 (defun vhdl-export-project (file-name)
12295 "Write project setup for current project."
12297 (let ((name (vhdl-resolve-env-variable
12298 (vhdl-replace-string
12299 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12300 (concat (subst-char-in-string
12301 ? ?_ (or (vhdl-project-p)
12302 (error "ERROR: No current project")))
12303 " " (user-login-name))))))
12304 (list (read-file-name
12305 "Write project file: "
12306 (when (file-name-absolute-p name) "") nil nil name))))
12307 (setq file-name (abbreviate-file-name file-name))
12308 (let ((orig-buffer (current-buffer)))
12309 (unless (file-exists-p (file-name-directory file-name))
12310 (make-directory (file-name-directory file-name) t))
12311 (if (not (file-writable-p file-name))
12312 (error "ERROR: File not writable: \"%s\"" file-name)
12313 (set-buffer (find-file-noselect file-name t t))
12315 (insert ";; -*- Emacs-Lisp -*-\n\n"
12316 ";;; " (file-name-nondirectory file-name)
12317 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12318 ";; Project : " vhdl-project "\n"
12319 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12320 (user-login-name) "\n\n\n"
12321 ";; project name\n"
12322 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12323 ";; project setup\n"
12324 "(aput 'vhdl-project-alist vhdl-project\n'")
12325 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12328 (kill-buffer (current-buffer))
12329 (set-buffer orig-buffer))))
12331 (defun vhdl-import-project (file-name &optional auto not-make-current)
12332 "Read project setup and set current project."
12334 (let ((name (vhdl-resolve-env-variable
12335 (vhdl-replace-string
12336 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12337 (concat "" " " (user-login-name))))))
12338 (list (read-file-name
12339 "Read project file: " (when (file-name-absolute-p name) "") nil t
12340 (file-name-directory name)))))
12341 (when (file-exists-p file-name)
12343 (let ((current-project vhdl-project))
12344 (load-file file-name)
12345 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12346 (adelete 'vhdl-project-alist vhdl-project)
12348 (when not-make-current
12349 (setq vhdl-project current-project))
12350 (vhdl-update-mode-menu)
12351 (vhdl-speedbar-refresh)
12352 (unless not-make-current
12353 (message "Current VHDL project: \"%s\"%s"
12354 vhdl-project (if auto " (auto-loaded)" ""))))
12355 (error (vhdl-warning
12356 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12358 (defun vhdl-duplicate-project ()
12359 "Duplicate setup of current project."
12361 (let ((new-name (read-from-minibuffer "New project name: "))
12362 (project-entry (aget vhdl-project-alist vhdl-project t)))
12363 (setq vhdl-project-alist
12364 (append vhdl-project-alist
12365 (list (cons new-name project-entry))))
12366 (vhdl-update-mode-menu)))
12368 (defun vhdl-auto-load-project ()
12369 "Automatically load project setup at startup."
12370 (let ((file-name-list vhdl-project-file-name)
12371 file-list list-length)
12372 (while file-name-list
12375 (file-expand-wildcards
12376 (vhdl-resolve-env-variable
12377 (vhdl-replace-string
12378 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12379 (concat "\*" " " (user-login-name)))))))
12380 (setq list-length (or list-length (length file-list)))
12381 (setq file-name-list (cdr file-name-list)))
12383 (vhdl-import-project (expand-file-name (car file-list)) t
12384 (not (> list-length 0)))
12385 (setq list-length (1- list-length))
12386 (setq file-list (cdr file-list)))))
12388 ;; automatically load project setup when idle after startup
12389 (when (memq 'startup vhdl-project-auto-load)
12391 (vhdl-auto-load-project)
12392 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12397 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12398 ;; (using `hideshow.el')
12400 (defconst vhdl-hs-start-regexp
12403 ;; generic/port clause
12404 "\\(generic\\|port\\)[ \t\n]*(\\|"
12407 ;; component instantiation
12408 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12409 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12410 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12411 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12413 "\\(function\\|procedure\\)\\>\\|"
12415 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12416 ;; configuration declaration
12419 "Regexp to match start of construct to hide.")
12421 (defun vhdl-hs-forward-sexp-func (count)
12422 "Find end of construct to hide (for hideshow). Only searches forward."
12423 (let ((pos (point)))
12424 (vhdl-prepare-search-2
12425 (beginning-of-line)
12427 ;; generic/port clause
12428 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12429 (goto-char (match-end 0))
12432 ;; component declaration
12433 ((looking-at "^\\s-*component\\>")
12434 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12435 ;; component instantiation
12438 "^\\s-*\\w+\\s-*:[ \t\n]*"
12439 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12440 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12441 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12442 (goto-char (match-end 0))
12446 (vhdl-forward-syntactic-ws)
12447 (when (looking-at "port\\s-+map[ \t\n]*(")
12448 (goto-char (match-end 0))
12451 (setq pos (point)))
12453 ;; subprogram declaration/body
12454 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12455 (goto-char (match-end 0))
12456 (vhdl-forward-syntactic-ws)
12457 (when (looking-at "(")
12459 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12460 (vhdl-in-literal)))
12462 (when (match-string 2)
12463 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12465 (vhdl-forward-sexp)))
12466 ;; block (recursive)
12467 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12468 (goto-char (match-end 0))
12469 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12470 (match-beginning 2))
12471 (vhdl-hs-forward-sexp-func count)))
12473 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12474 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12475 ;; configuration declaration
12476 ((looking-at "^\\s-*configuration\\>")
12478 (vhdl-forward-sexp))
12479 (t (goto-char pos))))))
12481 (defun vhdl-hideshow-init ()
12482 "Initialize `hideshow'."
12483 (when vhdl-hideshow-menu
12484 (vhdl-hs-minor-mode 1)))
12486 (defun vhdl-hs-minor-mode (&optional arg)
12487 "Toggle hideshow minor mode and update menu bar."
12489 (require 'hideshow)
12490 ;; check for hideshow version 5.x
12491 (if (not (boundp 'hs-block-start-mdata-select))
12492 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12493 ;; initialize hideshow
12494 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12495 (setq hs-special-modes-alist
12496 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12497 'vhdl-hs-forward-sexp-func nil)
12498 hs-special-modes-alist)))
12499 (make-local-variable 'hs-minor-mode-hook)
12500 (if vhdl-hide-all-init
12501 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12502 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12503 (hs-minor-mode arg)
12504 (force-mode-line-update))) ; hack to update menu bar
12507 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12509 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12510 ;; (using `font-lock.el')
12512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12515 (defun vhdl-within-translate-off ()
12516 "Return point if within translate-off region, else nil."
12517 (and (save-excursion
12518 (re-search-backward
12519 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12520 (equal "off" (match-string 1))
12523 (defun vhdl-start-translate-off (limit)
12524 "Return point before translate-off pragma if before LIMIT, else nil."
12525 (when (re-search-forward
12526 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12527 (match-beginning 0)))
12529 (defun vhdl-end-translate-off (limit)
12530 "Return point after translate-on pragma if before LIMIT, else nil."
12531 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12533 (defun vhdl-match-translate-off (limit)
12534 "Match a translate-off block, setting match-data and returning t, else nil."
12535 (when (< (point) limit)
12536 (let ((start (or (vhdl-within-translate-off)
12537 (vhdl-start-translate-off limit)))
12538 (case-fold-search t))
12540 (let ((end (or (vhdl-end-translate-off limit) limit)))
12541 (set-match-data (list start end))
12542 (goto-char end))))))
12544 (defun vhdl-font-lock-match-item (limit)
12545 "Match, and move over, any declaration item after point. Adapted from
12546 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12547 (condition-case nil
12549 (narrow-to-region (point-min) limit)
12551 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12553 (goto-char (match-end 1))
12554 ;; move to next item
12555 (if (looking-at "\\(\\s-*,\\)")
12556 (goto-char (match-end 1))
12557 (end-of-line) t))))
12560 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12561 ;; Syntax definitions
12563 (defconst vhdl-font-lock-syntactic-keywords
12564 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12565 "Mark single quotes as having string quote syntax in 'c' instances.")
12567 (defvar vhdl-font-lock-keywords nil
12568 "Regular expressions to highlight in VHDL Mode.")
12570 (defvar vhdl-font-lock-keywords-0
12571 ;; set in `vhdl-font-lock-init' because dependent on user options
12572 "For consideration as a value of `vhdl-font-lock-keywords'.
12573 This does highlighting of template prompts and directives (pragmas).")
12575 (defvar vhdl-font-lock-keywords-1 nil
12576 ;; set in `vhdl-font-lock-init' because dependent on user options
12577 "For consideration as a value of `vhdl-font-lock-keywords'.
12578 This does highlighting of keywords and standard identifiers.")
12580 (defconst vhdl-font-lock-keywords-2
12582 ;; highlight names of units, subprograms, and components when declared
12586 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12587 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12588 "\\)\\s-+\\(\\w+\\)")
12589 5 'font-lock-function-name-face)
12591 ;; highlight entity names of architectures and configurations
12593 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12594 2 'font-lock-function-name-face)
12596 ;; highlight labels of common constructs
12599 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12600 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12601 "postponed\\|process\\|"
12602 (when (vhdl-standard-p 'ams) "procedural\\|")
12604 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12605 1 'font-lock-function-name-face)
12607 ;; highlight label and component name of component instantiations
12610 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12611 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12612 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12614 ;; highlight label and instantiated unit of component instantiations
12617 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12618 "\\(component\\|configuration\\|entity\\)\\s-+"
12619 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12620 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12621 '(5 font-lock-function-name-face nil t)
12622 '(7 font-lock-function-name-face nil t))
12624 ;; highlight names and labels at end of constructs
12627 "^\\s-*end\\s-+\\(\\("
12628 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12629 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12630 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12631 (when (vhdl-standard-p 'ams) "procedural\\|")
12633 "\\)\\s-+\\)?\\(\\w*\\)")
12634 5 'font-lock-function-name-face)
12636 ;; highlight labels in exit and next statements
12639 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12640 3 'font-lock-function-name-face)
12642 ;; highlight entity name in attribute specifications
12645 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12646 1 'font-lock-function-name-face)
12648 ;; highlight labels in block and component specifications
12651 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12652 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12653 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12655 ;; highlight names in library clauses
12656 (list "^\\s-*library\\>"
12657 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12659 ;; highlight names in use clauses
12662 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12663 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12664 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12665 '(7 font-lock-function-name-face nil t))
12667 ;; highlight attribute name in attribute declarations/specifications
12670 "^\\s-*attribute\\s-+\\(\\w+\\)")
12671 1 'vhdl-font-lock-attribute-face)
12673 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12676 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12677 3 'font-lock-type-face)
12679 ;; highlight signal/variable/constant declaration names
12680 (list "\\(:[^=]\\)"
12681 '(vhdl-font-lock-match-item
12682 (progn (goto-char (match-beginning 1))
12683 (skip-syntax-backward " ")
12684 (skip-syntax-backward "w_")
12685 (skip-syntax-backward " ")
12686 (while (= (preceding-char) ?,)
12688 (skip-syntax-backward " ")
12689 (skip-syntax-backward "w_")
12690 (skip-syntax-backward " ")))
12691 ; (skip-chars-backward "^-(\n\";")
12692 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12694 ;; highlight formal parameters in component instantiations and subprogram
12697 '(vhdl-font-lock-match-item
12698 (progn (goto-char (match-beginning 1))
12699 (skip-syntax-backward " ")
12700 (while (= (preceding-char) ?\)) (backward-sexp))
12701 (skip-syntax-backward "w_")
12702 (skip-syntax-backward " ")
12703 (when (memq (preceding-char) '(?n ?N ?|))
12704 (goto-char (point-max))))
12705 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12707 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12709 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12710 '(vhdl-font-lock-match-item
12711 (progn (goto-char (match-end 1)) (match-beginning 2))
12712 nil (1 font-lock-variable-name-face)))
12714 "For consideration as a value of `vhdl-font-lock-keywords'.
12715 This does context sensitive highlighting of names and labels.")
12717 (defvar vhdl-font-lock-keywords-3 nil
12718 ;; set in `vhdl-font-lock-init' because dependent on user options
12719 "For consideration as a value of `vhdl-font-lock-keywords'.
12720 This does highlighting of words with special syntax.")
12722 (defvar vhdl-font-lock-keywords-4 nil
12723 ;; set in `vhdl-font-lock-init' because dependent on user options
12724 "For consideration as a value of `vhdl-font-lock-keywords'.
12725 This does highlighting of additional reserved words.")
12727 (defconst vhdl-font-lock-keywords-5
12728 ;; background highlight translate-off regions
12729 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12730 "For consideration as a value of `vhdl-font-lock-keywords'.
12731 This does background highlighting of translate-off regions.")
12733 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12734 ;; Font and color definitions
12736 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12737 "Face name to use for prompts.")
12739 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12740 "Face name to use for standardized attributes.")
12742 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12743 "Face name to use for standardized enumeration values.")
12745 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12746 "Face name to use for standardized functions and packages.")
12748 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12749 "Face name to use for directives.")
12751 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12752 "Face name to use for additional reserved words.")
12754 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12755 "Face name to use for translate-off regions.")
12757 ;; face names to use for words with special syntax.
12758 (let ((syntax-alist vhdl-special-syntax-alist)
12760 (while syntax-alist
12761 (setq name (vhdl-function-name
12762 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12763 (eval `(defvar ,name ',name
12764 ,(concat "Face name to use for "
12765 (nth 0 (car syntax-alist)) ".")))
12766 (setq syntax-alist (cdr syntax-alist))))
12768 (defgroup vhdl-highlight-faces nil
12769 "Faces for highlighting."
12770 :group 'vhdl-highlight)
12772 ;; add faces used from `font-lock'
12773 (custom-add-to-group
12774 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12775 (custom-add-to-group
12776 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12777 (custom-add-to-group
12778 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12779 (custom-add-to-group
12780 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12781 (custom-add-to-group
12782 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12783 (custom-add-to-group
12784 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12786 (defface vhdl-font-lock-prompt-face
12787 '((((min-colors 88) (class color) (background light))
12788 (:foreground "Red1" :bold t))
12789 (((class color) (background light)) (:foreground "Red" :bold t))
12790 (((class color) (background dark)) (:foreground "Pink" :bold t))
12791 (t (:inverse-video t)))
12792 "Font lock mode face used to highlight prompts."
12793 :group 'vhdl-highlight-faces)
12795 (defface vhdl-font-lock-attribute-face
12796 '((((class color) (background light)) (:foreground "Orchid"))
12797 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12798 (t (:italic t :bold t)))
12799 "Font lock mode face used to highlight standardized attributes."
12800 :group 'vhdl-highlight-faces)
12802 (defface vhdl-font-lock-enumvalue-face
12803 '((((class color) (background light)) (:foreground "SaddleBrown"))
12804 (((class color) (background dark)) (:foreground "BurlyWood"))
12805 (t (:italic t :bold t)))
12806 "Font lock mode face used to highlight standardized enumeration values."
12807 :group 'vhdl-highlight-faces)
12809 (defface vhdl-font-lock-function-face
12810 '((((class color) (background light)) (:foreground "Cyan4"))
12811 (((class color) (background dark)) (:foreground "Orchid1"))
12812 (t (:italic t :bold t)))
12813 "Font lock mode face used to highlight standardized functions and packages."
12814 :group 'vhdl-highlight-faces)
12816 (defface vhdl-font-lock-directive-face
12817 '((((class color) (background light)) (:foreground "CadetBlue"))
12818 (((class color) (background dark)) (:foreground "Aquamarine"))
12819 (t (:italic t :bold t)))
12820 "Font lock mode face used to highlight directives."
12821 :group 'vhdl-highlight-faces)
12823 (defface vhdl-font-lock-reserved-words-face
12824 '((((class color) (background light)) (:foreground "Orange" :bold t))
12825 (((min-colors 88) (class color) (background dark))
12826 (:foreground "Yellow1" :bold t))
12827 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12829 "Font lock mode face used to highlight additional reserved words."
12830 :group 'vhdl-highlight-faces)
12832 (defface vhdl-font-lock-translate-off-face
12833 '((((class color) (background light)) (:background "LightGray"))
12834 (((class color) (background dark)) (:background "DimGray"))
12836 "Font lock mode face used to background highlight translate-off regions."
12837 :group 'vhdl-highlight-faces)
12839 ;; font lock mode faces used to highlight words with special syntax.
12840 (let ((syntax-alist vhdl-special-syntax-alist))
12841 (while syntax-alist
12842 (eval `(defface ,(vhdl-function-name
12843 "vhdl-font-lock" (caar syntax-alist) "face")
12844 '((((class color) (background light))
12845 (:foreground ,(nth 2 (car syntax-alist))))
12846 (((class color) (background dark))
12847 (:foreground ,(nth 3 (car syntax-alist))))
12849 ,(concat "Font lock mode face used to highlight "
12850 (nth 0 (car syntax-alist)) ".")
12851 :group 'vhdl-highlight-faces))
12852 (setq syntax-alist (cdr syntax-alist))))
12854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12855 ;; Font lock initialization
12857 (defun vhdl-font-lock-init ()
12858 "Initialize fontification."
12859 ;; highlight template prompts and directives
12860 (setq vhdl-font-lock-keywords-0
12861 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12862 vhdl-template-prompt-syntax ">\\)")
12863 2 'vhdl-font-lock-prompt-face t)
12864 (list (concat "--\\s-*"
12865 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12866 2 'vhdl-font-lock-directive-face t)
12867 ;; highlight c-preprocessor directives
12868 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12869 '(1 font-lock-builtin-face)
12870 '(3 font-lock-variable-name-face nil t))))
12871 ;; highlight keywords and standardized types, attributes, enumeration
12872 ;; values, and subprograms
12873 (setq vhdl-font-lock-keywords-1
12875 (list (concat "'" vhdl-attributes-regexp)
12876 1 'vhdl-font-lock-attribute-face)
12877 (list vhdl-types-regexp 1 'font-lock-type-face)
12878 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12879 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12880 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12881 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12882 ;; highlight words with special syntax.
12883 (setq vhdl-font-lock-keywords-3
12884 (let ((syntax-alist vhdl-special-syntax-alist)
12886 (while syntax-alist
12889 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12890 (vhdl-function-name
12891 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12893 (setq syntax-alist (cdr syntax-alist)))
12895 ;; highlight additional reserved words
12896 (setq vhdl-font-lock-keywords-4
12897 (list (list vhdl-reserved-words-regexp 1
12898 'vhdl-font-lock-reserved-words-face)))
12899 ;; highlight everything together
12900 (setq vhdl-font-lock-keywords
12902 vhdl-font-lock-keywords-0
12903 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12904 (when (or vhdl-highlight-forbidden-words
12905 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12906 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12907 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12908 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12910 ;; initialize fontification for VHDL Mode
12911 (vhdl-font-lock-init)
12913 (defun vhdl-fontify-buffer ()
12914 "Re-initialize fontification and fontify buffer."
12916 (setq font-lock-defaults
12918 'vhdl-font-lock-keywords nil
12919 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12920 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12921 (when (fboundp 'font-lock-unset-defaults)
12922 (font-lock-unset-defaults)) ; not implemented in XEmacs
12923 (font-lock-set-defaults)
12924 (font-lock-mode nil)
12925 (font-lock-mode t))
12927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12928 ;; Initialization for postscript printing
12930 (defun vhdl-ps-print-settings ()
12931 "Initialize custom face and page settings for postscript printing."
12932 ;; define custom face settings
12933 (unless (or (not vhdl-print-customize-faces)
12935 (set (make-local-variable 'ps-bold-faces)
12936 '(font-lock-keyword-face
12937 font-lock-type-face
12938 vhdl-font-lock-attribute-face
12939 vhdl-font-lock-enumvalue-face
12940 vhdl-font-lock-directive-face))
12941 (set (make-local-variable 'ps-italic-faces)
12942 '(font-lock-comment-face
12943 font-lock-function-name-face
12944 font-lock-type-face
12945 vhdl-font-lock-attribute-face
12946 vhdl-font-lock-enumvalue-face
12947 vhdl-font-lock-directive-face))
12948 (set (make-local-variable 'ps-underlined-faces)
12949 '(font-lock-string-face))
12950 (setq ps-always-build-face-reference t))
12951 ;; define page settings, so that a line containing 79 characters (default)
12952 ;; fits into one column
12953 (when vhdl-print-two-column
12954 (set (make-local-variable 'ps-landscape-mode) t)
12955 (set (make-local-variable 'ps-number-of-columns) 2)
12956 (set (make-local-variable 'ps-font-size) 7.0)
12957 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12958 (set (make-local-variable 'ps-header-font-size) 9.0)
12959 (set (make-local-variable 'ps-header-offset) 12.0)
12960 (when (eq ps-paper-type 'letter)
12961 (set (make-local-variable 'ps-inter-column) 40.0)
12962 (set (make-local-variable 'ps-left-margin) 40.0)
12963 (set (make-local-variable 'ps-right-margin) 40.0))))
12965 (defun vhdl-ps-print-init ()
12966 "Initialize postscript printing."
12967 (if (featurep 'xemacs)
12968 (when (boundp 'ps-print-color-p)
12969 (vhdl-ps-print-settings))
12970 (make-local-variable 'ps-print-hook)
12971 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12975 ;;; Hierarchy browser (using `speedbar.el')
12976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12977 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12978 ;; directory by using the speedbar.
12980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12983 (defvar vhdl-entity-alist nil
12984 "Cache with entities and corresponding architectures for each
12985 project/directory.")
12986 ;; structure: (parenthesised expression means list of such entries)
12988 ;; (ent-key ent-name ent-file ent-line
12989 ;; (arch-key arch-name arch-file arch-line
12990 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12991 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12992 ;; (lib-name pack-key))
12993 ;; mra-key (lib-name pack-key))
12995 (defvar vhdl-config-alist nil
12996 "Cache with configurations for each project/directory.")
12997 ;; structure: (parenthesised expression means list of such entries)
12999 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13000 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13001 ;; inst-conf-key inst-lib-key)
13002 ;; (lib-name pack-key)))
13004 (defvar vhdl-package-alist nil
13005 "Cache with packages for each project/directory.")
13006 ;; structure: (parenthesised expression means list of such entries)
13008 ;; (pack-key pack-name pack-file pack-line
13009 ;; (comp-key comp-name comp-file comp-line)
13010 ;; (func-key func-name func-file func-line)
13011 ;; (lib-name pack-key)
13012 ;; pack-body-file pack-body-line
13013 ;; (func-key func-name func-body-file func-body-line)
13014 ;; (lib-name pack-key)))
13016 (defvar vhdl-ent-inst-alist nil
13017 "Cache with instantiated entities for each project/directory.")
13018 ;; structure: (parenthesised expression means list of such entries)
13019 ;; (cache-key (inst-ent-key))
13021 (defvar vhdl-file-alist nil
13022 "Cache with design units in each file for each project/directory.")
13023 ;; structure: (parenthesised expression means list of such entries)
13025 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13026 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13028 (defvar vhdl-directory-alist nil
13029 "Cache with source directories for each project.")
13030 ;; structure: (parenthesised expression means list of such entries)
13031 ;; (cache-key (directory))
13033 (defvar vhdl-speedbar-shown-unit-alist nil
13034 "Alist of design units simultaneously open in the current speedbar for each
13035 directory and project.")
13037 (defvar vhdl-speedbar-shown-project-list nil
13038 "List of projects simultaneously open in the current speedbar.")
13040 (defvar vhdl-updated-project-list nil
13041 "List of projects and directories with updated files.")
13043 (defvar vhdl-modified-file-list nil
13044 "List of modified files to be rescanned for hierarchy updating.")
13046 (defvar vhdl-speedbar-hierarchy-depth 0
13047 "Depth of instantiation hierarchy to display.")
13049 (defvar vhdl-speedbar-show-projects nil
13050 "Non-nil means project hierarchy is displayed in speedbar, directory
13051 hierarchy otherwise.")
13053 (defun vhdl-get-end-of-unit ()
13054 "Return position of end of current unit."
13055 (let ((pos (point)))
13057 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13059 (goto-char (match-beginning 0))
13060 (vhdl-backward-syntactic-ws)
13061 (and (/= (preceding-char) ?\;) (not (bobp))))))
13062 (re-search-backward "^[ \t]*end\\>" pos 1)
13065 (defun vhdl-match-string-downcase (num &optional string)
13066 "Like `match-string-no-properties' with down-casing."
13067 (let ((match (match-string-no-properties num string)))
13068 (and match (downcase match))))
13071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13074 (defun vhdl-scan-context-clause ()
13075 "Scan the context clause that preceeds a design unit."
13078 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13079 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13080 (equal "USE" (upcase (match-string 1))))
13081 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13082 (setq lib-alist (cons (cons (match-string-no-properties 1)
13083 (vhdl-match-string-downcase 2))
13087 (defun vhdl-scan-directory-contents (name &optional project update num-string
13089 "Scan contents of VHDL files in directory or file pattern NAME."
13090 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13091 ; (unless (file-directory-p (match-string 1 name))
13092 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13093 (let* ((dir-name (match-string 1 name))
13094 (file-pattern (match-string 2 name))
13095 (is-directory (= 0 (length file-pattern)))
13100 (vhdl-get-source-files t dir-name)
13101 (vhdl-directory-files
13102 dir-name t (wildcard-to-regexp file-pattern)))))
13103 (key (or project dir-name))
13104 (file-exclude-regexp
13105 (or (nth 3 (aget vhdl-project-alist project)) ""))
13106 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13107 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13108 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13109 ent-alist conf-alist pack-alist ent-inst-list file-alist
13110 tmp-list tmp-entry no-files files-exist big-files)
13111 (when (or project update)
13112 (setq ent-alist (aget vhdl-entity-alist key t)
13113 conf-alist (aget vhdl-config-alist key t)
13114 pack-alist (aget vhdl-package-alist key t)
13115 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13116 file-alist (aget vhdl-file-alist key t)))
13117 (when (and (not is-directory) (null file-list))
13118 (message "No such file: \"%s\"" name))
13119 (setq files-exist file-list)
13121 (setq no-files (length file-list))
13122 (message "Scanning %s %s\"%s\"..."
13123 (if is-directory "directory" "files") (or num-string "") name)
13125 (unless (equal file-exclude-regexp "")
13126 (let ((case-fold-search nil)
13129 (unless (string-match file-exclude-regexp (car file-list))
13130 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13131 (setq file-list (cdr file-list)))
13132 (setq file-list (nreverse file-tmp-list))))
13133 ;; do for all files
13135 (unless noninteractive
13136 (message "Scanning %s %s\"%s\"... (%2d%s)"
13137 (if is-directory "directory" "files")
13138 (or num-string "") name
13139 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13140 (let ((file-name (abbreviate-file-name (car file-list)))
13141 ent-list arch-list arch-ent-list conf-list
13142 pack-list pack-body-list inst-list inst-ent-list)
13146 (vhdl-prepare-search-2
13148 ;; scan for design units
13149 (if (and limit-design-file-size
13150 (< limit-design-file-size (buffer-size)))
13151 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13152 (setq big-files t))
13153 ;; scan for entities
13154 (goto-char (point-min))
13155 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13156 (let* ((ent-name (match-string-no-properties 1))
13157 (ent-key (downcase ent-name))
13158 (ent-entry (aget ent-alist ent-key t))
13159 (lib-alist (vhdl-scan-context-clause)))
13160 (if (nth 1 ent-entry)
13161 (vhdl-warning-when-idle
13162 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13163 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13164 file-name (vhdl-current-line))
13165 (setq ent-list (cons ent-key ent-list))
13166 (aput 'ent-alist ent-key
13167 (list ent-name file-name (vhdl-current-line)
13168 (nth 3 ent-entry) (nth 4 ent-entry)
13170 ;; scan for architectures
13171 (goto-char (point-min))
13172 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13173 (let* ((arch-name (match-string-no-properties 1))
13174 (arch-key (downcase arch-name))
13175 (ent-name (match-string-no-properties 2))
13176 (ent-key (downcase ent-name))
13177 (ent-entry (aget ent-alist ent-key t))
13178 (arch-alist (nth 3 ent-entry))
13179 (arch-entry (aget arch-alist arch-key t))
13180 (lib-arch-alist (vhdl-scan-context-clause)))
13182 (vhdl-warning-when-idle
13183 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13184 arch-name ent-name (nth 1 arch-entry)
13185 (nth 2 arch-entry) file-name (vhdl-current-line))
13186 (setq arch-list (cons arch-key arch-list)
13187 arch-ent-list (cons ent-key arch-ent-list))
13188 (aput 'arch-alist arch-key
13189 (list arch-name file-name (vhdl-current-line) nil
13191 (aput 'ent-alist ent-key
13192 (list (or (nth 0 ent-entry) ent-name)
13193 (nth 1 ent-entry) (nth 2 ent-entry)
13194 (vhdl-sort-alist arch-alist)
13195 arch-key (nth 5 ent-entry))))))
13196 ;; scan for configurations
13197 (goto-char (point-min))
13198 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13199 (let* ((conf-name (match-string-no-properties 1))
13200 (conf-key (downcase conf-name))
13201 (conf-entry (aget conf-alist conf-key t))
13202 (ent-name (match-string-no-properties 2))
13203 (ent-key (downcase ent-name))
13204 (lib-alist (vhdl-scan-context-clause))
13205 (conf-line (vhdl-current-line))
13206 (end-of-unit (vhdl-get-end-of-unit))
13207 arch-key comp-conf-list inst-key-list
13208 inst-comp-key inst-ent-key inst-arch-key
13209 inst-conf-key inst-lib-key)
13210 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13211 (setq arch-key (vhdl-match-string-downcase 1)))
13213 (vhdl-warning-when-idle
13214 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13215 conf-name ent-name (nth 1 conf-entry)
13216 (nth 2 conf-entry) file-name conf-line)
13217 (setq conf-list (cons conf-key conf-list))
13218 ;; scan for subconfigurations and subentities
13219 (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)
13220 (setq inst-comp-key (vhdl-match-string-downcase 3)
13221 inst-key-list (split-string
13222 (vhdl-match-string-downcase 1)
13223 "[ \t\n]*,[ \t\n]*"))
13224 (vhdl-forward-syntactic-ws)
13225 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13227 inst-lib-key (vhdl-match-string-downcase 3)
13228 inst-ent-key (and (match-string 2)
13229 (vhdl-match-string-downcase 4))
13230 inst-arch-key (and (match-string 2)
13231 (vhdl-match-string-downcase 6))
13232 inst-conf-key (and (not (match-string 2))
13233 (vhdl-match-string-downcase 4)))
13234 (while inst-key-list
13235 (setq comp-conf-list
13236 (cons (list (car inst-key-list)
13237 inst-comp-key inst-ent-key
13238 inst-arch-key inst-conf-key
13241 (setq inst-key-list (cdr inst-key-list)))))
13242 (aput 'conf-alist conf-key
13243 (list conf-name file-name conf-line ent-key
13244 arch-key comp-conf-list lib-alist)))))
13245 ;; scan for packages
13246 (goto-char (point-min))
13247 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13248 (let* ((pack-name (match-string-no-properties 2))
13249 (pack-key (downcase pack-name))
13250 (is-body (match-string-no-properties 1))
13251 (pack-entry (aget pack-alist pack-key t))
13252 (pack-line (vhdl-current-line))
13253 (end-of-unit (vhdl-get-end-of-unit))
13254 comp-name func-name comp-alist func-alist lib-alist)
13255 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13256 (vhdl-warning-when-idle
13257 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13258 (if is-body " body" "") pack-name
13259 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13260 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13261 file-name (vhdl-current-line))
13262 ;; scan for context clauses
13263 (setq lib-alist (vhdl-scan-context-clause))
13264 ;; scan for component and subprogram declarations/bodies
13265 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13266 (if (equal (upcase (match-string 1)) "COMPONENT")
13267 (setq comp-name (match-string-no-properties 2)
13269 (cons (list (downcase comp-name) comp-name
13270 file-name (vhdl-current-line))
13272 (setq func-name (match-string-no-properties 2)
13274 (cons (list (downcase func-name) func-name
13275 file-name (vhdl-current-line))
13277 (setq func-alist (nreverse func-alist))
13278 (setq comp-alist (nreverse comp-alist))
13280 (setq pack-body-list (cons pack-key pack-body-list))
13281 (setq pack-list (cons pack-key pack-list)))
13283 'pack-alist pack-key
13285 (list (or (nth 0 pack-entry) pack-name)
13286 (nth 1 pack-entry) (nth 2 pack-entry)
13287 (nth 3 pack-entry) (nth 4 pack-entry)
13289 file-name pack-line func-alist lib-alist)
13290 (list pack-name file-name pack-line
13291 comp-alist func-alist lib-alist
13292 (nth 6 pack-entry) (nth 7 pack-entry)
13293 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13294 ;; scan for hierarchy
13295 (if (and limit-hier-file-size
13296 (< limit-hier-file-size (buffer-size)))
13297 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13298 (setq big-files t))
13299 ;; scan for architectures
13300 (goto-char (point-min))
13301 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13302 (let* ((ent-name (match-string-no-properties 2))
13303 (ent-key (downcase ent-name))
13304 (arch-name (match-string-no-properties 1))
13305 (arch-key (downcase arch-name))
13306 (ent-entry (aget ent-alist ent-key t))
13307 (arch-alist (nth 3 ent-entry))
13308 (arch-entry (aget arch-alist arch-key t))
13309 (beg-of-unit (point))
13310 (end-of-unit (vhdl-get-end-of-unit))
13312 inst-alist inst-path)
13313 ;; scan for contained instantiations
13314 (while (and (re-search-forward
13315 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13316 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13317 "component[ \t\n]+\\(\\w+\\)\\|"
13318 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13319 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13320 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13321 (or (not limit-hier-inst-no)
13322 (<= (setq inst-no (1+ inst-no))
13323 limit-hier-inst-no)))
13325 ;; block/generate beginning found
13328 (cons (match-string-no-properties 1) inst-path)))
13329 ;; block/generate end found
13331 (setq inst-path (cdr inst-path)))
13332 ;; instantiation found
13334 (let* ((inst-name (match-string-no-properties 1))
13335 (inst-key (downcase inst-name))
13337 (or (match-string-no-properties 3)
13338 (match-string-no-properties 6)))
13340 (or (and (match-string 8)
13341 (vhdl-match-string-downcase 11))
13342 (and inst-comp-name
13343 (downcase inst-comp-name))))
13344 (inst-arch-key (vhdl-match-string-downcase 13))
13346 (and (not (match-string 8))
13347 (vhdl-match-string-downcase 11)))
13348 (inst-lib-key (vhdl-match-string-downcase 10)))
13349 (goto-char (match-end 1))
13350 (setq inst-list (cons inst-key inst-list)
13352 (cons inst-ent-key inst-ent-list))
13356 (list (list inst-key inst-name file-name
13357 (vhdl-current-line) inst-comp-name
13358 inst-ent-key inst-arch-key
13359 inst-conf-key inst-lib-key
13360 (reverse inst-path)))))))))
13361 ;; scan for contained configuration specifications
13362 (goto-char beg-of-unit)
13363 (while (re-search-forward
13364 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13365 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13366 (let* ((inst-comp-name (match-string-no-properties 3))
13368 (and (match-string 6)
13369 (vhdl-match-string-downcase 9)))
13370 (inst-arch-key (vhdl-match-string-downcase 11))
13372 (and (not (match-string 6))
13373 (vhdl-match-string-downcase 9)))
13374 (inst-lib-key (vhdl-match-string-downcase 8))
13376 (split-string (vhdl-match-string-downcase 1)
13377 "[ \t\n]*,[ \t\n]*"))
13378 (tmp-inst-alist inst-alist)
13380 (while tmp-inst-alist
13381 (when (and (or (equal "all" (car inst-key-list))
13382 (member (nth 0 (car tmp-inst-alist))
13386 (or (nth 4 (car tmp-inst-alist)) ""))
13387 (downcase inst-comp-name)))
13388 (setq inst-entry (car tmp-inst-alist))
13389 (setq inst-ent-list
13390 (cons (or inst-ent-key (nth 5 inst-entry))
13392 (nth 5 inst-entry) inst-ent-list)))
13394 (list (nth 0 inst-entry) (nth 1 inst-entry)
13395 (nth 2 inst-entry) (nth 3 inst-entry)
13397 (or inst-ent-key (nth 5 inst-entry))
13398 (or inst-arch-key (nth 6 inst-entry))
13399 inst-conf-key inst-lib-key))
13400 (setcar tmp-inst-alist inst-entry))
13401 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13403 (aput 'arch-alist arch-key
13404 (list (nth 0 arch-entry) (nth 1 arch-entry)
13405 (nth 2 arch-entry) inst-alist
13406 (nth 4 arch-entry)))
13407 (aput 'ent-alist ent-key
13408 (list (nth 0 ent-entry) (nth 1 ent-entry)
13409 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13410 (nth 4 ent-entry) (nth 5 ent-entry)))
13411 (when (and limit-hier-inst-no
13412 (> inst-no limit-hier-inst-no))
13413 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13414 (setq big-files t))
13415 (goto-char end-of-unit))))
13416 ;; remember design units for this file
13417 (aput 'file-alist file-name
13418 (list ent-list arch-list arch-ent-list conf-list
13419 pack-list pack-body-list inst-list inst-ent-list))
13420 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13421 (setq file-list (cdr file-list))))
13422 (when (or (and (not project) files-exist)
13423 (and project (not non-final)))
13424 ;; consistency checks:
13425 ;; check whether each architecture has a corresponding entity
13426 (setq tmp-list ent-alist)
13428 (when (null (nth 2 (car tmp-list)))
13429 (setq tmp-entry (car (nth 4 (car tmp-list))))
13430 (vhdl-warning-when-idle
13431 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13432 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13433 (nth 3 tmp-entry)))
13434 (setq tmp-list (cdr tmp-list)))
13435 ;; check whether configuration has a corresponding entity/architecture
13436 (setq tmp-list conf-alist)
13438 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13439 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13440 (setq tmp-entry (car tmp-list))
13441 (vhdl-warning-when-idle
13442 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13443 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13444 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13445 (setq tmp-entry (car tmp-list))
13446 (vhdl-warning-when-idle
13447 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13448 (nth 1 tmp-entry) (nth 4 tmp-entry)
13449 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13450 (setq tmp-list (cdr tmp-list)))
13451 ;; check whether each package body has a package declaration
13452 (setq tmp-list pack-alist)
13454 (when (null (nth 2 (car tmp-list)))
13455 (setq tmp-entry (car tmp-list))
13456 (vhdl-warning-when-idle
13457 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13458 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13459 (setq tmp-list (cdr tmp-list)))
13461 (setq ent-alist (vhdl-sort-alist ent-alist))
13462 (setq conf-alist (vhdl-sort-alist conf-alist))
13463 (setq pack-alist (vhdl-sort-alist pack-alist))
13464 ;; remember updated directory/project
13465 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13466 ;; clear directory alists
13468 (adelete 'vhdl-entity-alist key)
13469 (adelete 'vhdl-config-alist key)
13470 (adelete 'vhdl-package-alist key)
13471 (adelete 'vhdl-ent-inst-alist key)
13472 (adelete 'vhdl-file-alist key))
13473 ;; put directory contents into cache
13474 (aput 'vhdl-entity-alist key ent-alist)
13475 (aput 'vhdl-config-alist key conf-alist)
13476 (aput 'vhdl-package-alist key pack-alist)
13477 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13478 (aput 'vhdl-file-alist key file-alist)
13480 (message "Scanning %s %s\"%s\"...done"
13481 (if is-directory "directory" "files") (or num-string "") name)
13482 (unless project (message "Scanning directory...done"))
13484 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13485 ;; save cache when scanned non-interactively
13486 (when (or (not project) (not non-final))
13487 (when (and noninteractive vhdl-speedbar-save-cache)
13488 (vhdl-save-cache key)))
13491 (defun vhdl-scan-project-contents (project)
13492 "Scan the contents of all VHDL files found in the directories and files
13494 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13495 (default-dir (vhdl-resolve-env-variable
13496 (nth 1 (aget vhdl-project-alist project))))
13497 (file-exclude-regexp
13498 (or (nth 3 (aget vhdl-project-alist project)) ""))
13499 dir-list-tmp dir dir-name num-dir act-dir recursive)
13500 ;; clear project alists
13501 (adelete 'vhdl-entity-alist project)
13502 (adelete 'vhdl-config-alist project)
13503 (adelete 'vhdl-package-alist project)
13504 (adelete 'vhdl-ent-inst-alist project)
13505 (adelete 'vhdl-file-alist project)
13506 ;; expand directory names by default-directory
13507 (message "Collecting source files...")
13509 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13510 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13511 (setq recursive (match-string 1 dir)
13512 dir-name (match-string 3 dir))
13514 (cons (concat recursive
13515 (if (file-name-absolute-p dir-name) "" default-dir)
13518 (setq dir-list (cdr dir-list)))
13519 ;; resolve path wildcards
13520 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13521 ;; expand directories
13522 (while dir-list-tmp
13523 (setq dir (car dir-list-tmp))
13524 ;; get subdirectories
13525 (if (string-match "-r \\(.*[/\\]\\)" dir)
13526 (setq dir-list (append dir-list (vhdl-get-subdirs
13527 (match-string 1 dir))))
13528 (setq dir-list (append dir-list (list dir))))
13529 (setq dir-list-tmp (cdr dir-list-tmp)))
13531 (unless (equal file-exclude-regexp "")
13532 (let ((case-fold-search nil))
13534 (unless (string-match file-exclude-regexp (car dir-list))
13535 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13536 (setq dir-list (cdr dir-list)))
13537 (setq dir-list (nreverse dir-list-tmp))))
13538 (message "Collecting source files...done")
13539 ;; scan for design units for each directory in DIR-LIST
13540 (setq dir-list-tmp nil
13541 num-dir (length dir-list)
13544 (setq dir-name (abbreviate-file-name
13545 (expand-file-name (car dir-list))))
13546 (vhdl-scan-directory-contents dir-name project nil
13547 (format "(%s/%s) " act-dir num-dir)
13549 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13550 (setq dir-list (cdr dir-list)
13551 act-dir (1+ act-dir)))
13552 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13553 (message "Scanning project \"%s\"...done" project)))
13555 (defun vhdl-update-file-contents (file-name)
13556 "Update hierarchy information by contents of current buffer."
13557 (setq file-name (abbreviate-file-name file-name))
13558 (let* ((dir-name (file-name-directory file-name))
13559 (directory-alist vhdl-directory-alist)
13561 (while directory-alist
13562 (when (member dir-name (nth 1 (car directory-alist)))
13563 (let* ((vhdl-project (nth 0 (car directory-alist)))
13564 (project (vhdl-project-p))
13565 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13566 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13567 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13568 (ent-inst-list (car (aget vhdl-ent-inst-alist
13569 (or project dir-name) t)))
13570 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13571 (file-entry (aget file-alist file-name t))
13572 (ent-list (nth 0 file-entry))
13573 (arch-list (nth 1 file-entry))
13574 (arch-ent-list (nth 2 file-entry))
13575 (conf-list (nth 3 file-entry))
13576 (pack-list (nth 4 file-entry))
13577 (pack-body-list (nth 5 file-entry))
13578 (inst-ent-list (nth 7 file-entry))
13579 (cache-key (or project dir-name))
13580 arch-alist key ent-key entry)
13581 ;; delete design units previously contained in this file:
13584 (setq key (car ent-list)
13585 entry (aget ent-alist key t))
13586 (when (equal file-name (nth 1 entry))
13588 (aput 'ent-alist key
13589 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13590 (adelete 'ent-alist key)))
13591 (setq ent-list (cdr ent-list)))
13594 (setq key (car arch-list)
13595 ent-key (car arch-ent-list)
13596 entry (aget ent-alist ent-key t)
13597 arch-alist (nth 3 entry))
13598 (when (equal file-name (nth 1 (aget arch-alist key t)))
13599 (adelete 'arch-alist key)
13600 (if (or (nth 1 entry) arch-alist)
13601 (aput 'ent-alist ent-key
13602 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13603 arch-alist (nth 4 entry) (nth 5 entry)))
13604 (adelete 'ent-alist ent-key)))
13605 (setq arch-list (cdr arch-list)
13606 arch-ent-list (cdr arch-ent-list)))
13609 (setq key (car conf-list))
13610 (when (equal file-name (nth 1 (aget conf-alist key t)))
13611 (adelete 'conf-alist key))
13612 (setq conf-list (cdr conf-list)))
13613 ;; package declarations
13615 (setq key (car pack-list)
13616 entry (aget pack-alist key t))
13617 (when (equal file-name (nth 1 entry))
13619 (aput 'pack-alist key
13620 (list (nth 0 entry) nil nil nil nil nil
13621 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13623 (adelete 'pack-alist key)))
13624 (setq pack-list (cdr pack-list)))
13626 (while pack-body-list
13627 (setq key (car pack-body-list)
13628 entry (aget pack-alist key t))
13629 (when (equal file-name (nth 6 entry))
13631 (aput 'pack-alist key
13632 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13633 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13635 (adelete 'pack-alist key)))
13636 (setq pack-body-list (cdr pack-body-list)))
13637 ;; instantiated entities
13638 (while inst-ent-list
13639 (setq ent-inst-list
13640 (vhdl-delete (car inst-ent-list) ent-inst-list))
13641 (setq inst-ent-list (cdr inst-ent-list)))
13643 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13644 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13645 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13646 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13648 (vhdl-scan-directory-contents file-name project t)
13649 (when (or (and vhdl-speedbar-show-projects project)
13650 (and (not vhdl-speedbar-show-projects) (not project)))
13651 (vhdl-speedbar-refresh project))
13653 (setq directory-alist (cdr directory-alist)))
13656 (defun vhdl-update-hierarchy ()
13657 "Update directory and hierarchy information in speedbar."
13658 (let ((file-list (reverse vhdl-modified-file-list))
13660 (when (and vhdl-speedbar-update-on-saving file-list)
13663 (or (vhdl-update-file-contents (car file-list))
13665 (setq file-list (cdr file-list)))
13666 (setq vhdl-modified-file-list nil)
13667 (vhdl-speedbar-update-current-unit)
13668 (when updated (message "Updating hierarchy...done")))))
13670 ;; structure (parenthesised expression means list of such entries)
13671 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13672 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13673 ;; comp-lib-name level)
13674 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13675 conf-inst-alist level indent
13676 &optional include-top ent-hier)
13677 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13679 (let* ((ent-entry (aget ent-alist ent-key t))
13680 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13681 (cdar (last (nth 3 ent-entry)))))
13682 (inst-alist (nth 3 arch-entry))
13683 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13684 hier-list subcomp-list tmp-list inst-key inst-comp-name
13685 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13686 (when (= level 0) (message "Extract design hierarchy..."))
13688 (setq level (1+ level)))
13689 (when (member ent-key ent-hier)
13690 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13691 ;; check configured architecture (already checked during scanning)
13692 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13693 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13694 ;; process all instances
13696 (setq inst-entry (car inst-alist)
13697 inst-key (nth 0 inst-entry)
13698 inst-comp-name (nth 4 inst-entry)
13699 inst-conf-key (nth 7 inst-entry))
13700 ;; search entry in configuration's instantiations list
13701 (setq tmp-list conf-inst-alist)
13702 (while (and tmp-list
13703 (not (and (member (nth 0 (car tmp-list))
13704 (list "all" inst-key))
13705 (equal (nth 1 (car tmp-list))
13706 (downcase (or inst-comp-name ""))))))
13707 (setq tmp-list (cdr tmp-list)))
13708 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13709 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13710 (when (and inst-conf-key (not inst-conf-entry))
13711 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13712 ;; determine entity
13714 (or (nth 2 (car tmp-list)) ; from configuration
13715 (nth 3 inst-conf-entry) ; from subconfiguration
13716 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13717 ; from configuration spec.
13718 (nth 5 inst-entry))) ; from direct instantiation
13719 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13720 ;; determine architecture
13721 (setq inst-arch-key
13722 (or (nth 3 (car tmp-list)) ; from configuration
13723 (nth 4 inst-conf-entry) ; from subconfiguration
13724 (nth 6 inst-entry) ; from direct instantiation
13725 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13726 ; from configuration spec.
13727 (nth 4 inst-ent-entry) ; MRA
13728 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13729 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13732 (or (nth 5 (car tmp-list)) ; from configuration
13733 (nth 8 inst-entry))) ; from direct instantiation
13734 ;; gather information for this instance
13736 (list (nth 1 inst-entry)
13737 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13738 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13739 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13740 (or (nth 0 inst-arch-entry) inst-arch-key)
13741 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13742 (or (nth 0 inst-conf-entry) inst-conf-key)
13743 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13744 inst-lib-key level))
13745 ;; get subcomponent hierarchy
13746 (setq subcomp-list (vhdl-get-hierarchy
13747 ent-alist conf-alist
13748 inst-ent-key inst-arch-key inst-conf-key
13749 (nth 5 inst-conf-entry)
13750 (1+ level) indent nil (cons ent-key ent-hier)))
13752 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13753 (setq inst-alist (cdr inst-alist)))
13756 (cons (list nil nil (nth 0 ent-entry)
13757 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13759 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13763 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13766 (defun vhdl-get-instantiations (ent-key indent)
13767 "Get all instantiations of entity ENT-KEY."
13768 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13769 arch-alist inst-alist ent-inst-list
13770 ent-entry arch-entry inst-entry)
13772 (setq ent-entry (car ent-alist))
13773 (setq arch-alist (nth 4 ent-entry))
13775 (setq arch-entry (car arch-alist))
13776 (setq inst-alist (nth 4 arch-entry))
13778 (setq inst-entry (car inst-alist))
13779 (when (equal ent-key (nth 5 inst-entry))
13780 (setq ent-inst-list
13781 (cons (list (nth 1 inst-entry)
13782 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13784 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13786 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13788 (setq inst-alist (cdr inst-alist)))
13789 (setq arch-alist (cdr arch-alist)))
13790 (setq ent-alist (cdr ent-alist)))
13791 (nreverse ent-inst-list)))
13793 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13796 (defun vhdl-save-caches ()
13797 "Save all updated hierarchy caches to file."
13799 (condition-case nil
13800 (when vhdl-speedbar-save-cache
13801 ;; update hierarchy
13802 (vhdl-update-hierarchy)
13803 (let ((project-list vhdl-updated-project-list))
13804 (message "Saving hierarchy caches...")
13805 ;; write updated project caches
13806 (while project-list
13807 (vhdl-save-cache (car project-list))
13808 (setq project-list (cdr project-list)))
13809 (message "Saving hierarchy caches...done")))
13810 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13813 (defun vhdl-save-cache (key)
13814 "Save current hierarchy cache to file."
13815 (let* ((orig-buffer (current-buffer))
13817 (project (vhdl-project-p))
13818 (default-directory key)
13819 (directory (abbreviate-file-name (vhdl-default-directory)))
13820 (file-name (vhdl-resolve-env-variable
13821 (vhdl-replace-string
13822 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13824 (subst-char-in-string ? ?_ (or project "dir"))
13825 " " (user-login-name)))))
13826 (file-dir-name (expand-file-name file-name directory))
13827 (cache-key (or project directory))
13828 (key (if project "project" "directory")))
13829 (unless (file-exists-p (file-name-directory file-dir-name))
13830 (make-directory (file-name-directory file-dir-name) t))
13831 (if (not (file-writable-p file-dir-name))
13832 (progn (vhdl-warning (format "File not writable: \"%s\""
13833 (abbreviate-file-name file-dir-name)))
13835 (message "Saving cache: \"%s\"" file-dir-name)
13836 (set-buffer (find-file-noselect file-dir-name t t))
13838 (insert ";; -*- Emacs-Lisp -*-\n\n"
13839 ";;; " (file-name-nondirectory file-name)
13840 " - design hierarchy cache file for Emacs VHDL Mode "
13842 (insert "\n;; " (if project "Project " "Directory") " : ")
13843 (if project (insert project) (prin1 directory (current-buffer)))
13844 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13845 (user-login-name) "\n\n"
13846 "\n;; version number\n"
13847 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13848 "\n;; " (if project "project" "directory") " name"
13849 "\n(setq " key " ")
13850 (prin1 (or project directory) (current-buffer))
13852 (when (member 'hierarchy vhdl-speedbar-save-cache)
13853 (insert "\n;; entity and architecture cache\n"
13854 "(aput 'vhdl-entity-alist " key " '")
13855 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13856 (insert ")\n\n;; configuration cache\n"
13857 "(aput 'vhdl-config-alist " key " '")
13858 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13859 (insert ")\n\n;; package cache\n"
13860 "(aput 'vhdl-package-alist " key " '")
13861 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13862 (insert ")\n\n;; instantiated entities cache\n"
13863 "(aput 'vhdl-ent-inst-alist " key " '")
13864 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13865 (insert ")\n\n;; design units per file cache\n"
13866 "(aput 'vhdl-file-alist " key " '")
13867 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13869 (insert ")\n\n;; source directories in project cache\n"
13870 "(aput 'vhdl-directory-alist " key " '")
13871 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13873 (when (member 'display vhdl-speedbar-save-cache)
13874 (insert "\n;; shown design units cache\n"
13875 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13876 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13879 (setq vhdl-updated-project-list
13880 (delete cache-key vhdl-updated-project-list))
13882 (kill-buffer (current-buffer))
13883 (set-buffer orig-buffer))))
13885 (defun vhdl-load-cache (key)
13886 "Load hierarchy cache information from file."
13887 (let* ((vhdl-project key)
13888 (default-directory key)
13889 (directory (vhdl-default-directory))
13890 (file-name (vhdl-resolve-env-variable
13891 (vhdl-replace-string
13892 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13894 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13895 " " (user-login-name)))))
13896 (file-dir-name (expand-file-name file-name directory))
13897 vhdl-cache-version)
13898 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13899 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13900 (when (file-exists-p file-dir-name)
13902 (progn (load-file file-dir-name)
13903 (string< (mapconcat
13904 (lambda (a) (format "%3d" (string-to-number a)))
13905 (split-string "3.33" "\\.") "")
13907 (lambda (a) (format "%3d" (string-to-number a)))
13908 (split-string vhdl-cache-version "\\.") "")))
13909 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13912 (defun vhdl-require-hierarchy-info ()
13913 "Make sure that hierarchy information is available. Load cache or scan files
13915 (if (vhdl-project-p)
13916 (unless (or (assoc vhdl-project vhdl-file-alist)
13917 (vhdl-load-cache vhdl-project))
13918 (vhdl-scan-project-contents vhdl-project))
13919 (let ((directory (abbreviate-file-name default-directory)))
13920 (unless (or (assoc directory vhdl-file-alist)
13921 (vhdl-load-cache directory))
13922 (vhdl-scan-directory-contents directory)))))
13924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13925 ;; Add hierarchy browser functionality to speedbar
13927 (defvar vhdl-speedbar-key-map nil
13928 "Keymap used when in the VHDL hierarchy browser mode.")
13930 (defvar vhdl-speedbar-menu-items nil
13931 "Additional menu-items to add to speedbar frame.")
13933 (defun vhdl-speedbar-initialize ()
13934 "Initialize speedbar."
13935 ;; general settings
13936 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13937 ;; VHDL file extensions (extracted from `auto-mode-alist')
13938 (let ((mode-alist auto-mode-alist))
13940 (when (eq (cdar mode-alist) 'vhdl-mode)
13941 (speedbar-add-supported-extension (caar mode-alist)))
13942 (setq mode-alist (cdr mode-alist))))
13943 ;; hierarchy browser settings
13944 (when (boundp 'speedbar-mode-functions-list)
13945 ;; special functions
13946 (speedbar-add-mode-functions-list
13948 (speedbar-item-info . vhdl-speedbar-item-info)
13949 (speedbar-line-directory . speedbar-files-line-path)))
13950 (speedbar-add-mode-functions-list
13952 (speedbar-item-info . vhdl-speedbar-item-info)
13953 (speedbar-line-directory . vhdl-speedbar-line-project)))
13955 (unless vhdl-speedbar-key-map
13956 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13957 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13958 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13959 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13960 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13961 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13962 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13963 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13964 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13965 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13966 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
13967 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13968 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13969 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13972 (define-key vhdl-speedbar-key-map (int-to-string key)
13973 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13974 (setq key (1+ key)))))
13975 (define-key speedbar-key-map "h"
13976 (lambda () (interactive)
13977 (speedbar-change-initial-expansion-list "vhdl directory")))
13978 (define-key speedbar-key-map "H"
13979 (lambda () (interactive)
13980 (speedbar-change-initial-expansion-list "vhdl project")))
13982 (unless vhdl-speedbar-menu-items
13984 vhdl-speedbar-menu-items
13985 `(["Edit" speedbar-edit-line t]
13986 ["Expand" speedbar-expand-line
13987 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13988 ["Contract" vhdl-speedbar-contract-level t]
13989 ["Expand All" vhdl-speedbar-expand-all t]
13990 ["Contract All" vhdl-speedbar-contract-all t]
13991 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13994 (cons `[,(if (= key 0) "All" (int-to-string key))
13995 (vhdl-speedbar-set-depth ,key)
13997 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13998 :keys ,(int-to-string key)]
14000 (setq key (1+ key)))
14001 (nreverse menu-list))
14003 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14004 (or (vhdl-speedbar-check-unit 'entity)
14005 (vhdl-speedbar-check-unit 'subprogram))]
14006 ["Place Component" vhdl-speedbar-place-component
14007 (vhdl-speedbar-check-unit 'entity)]
14008 ["Generate Configuration" vhdl-speedbar-configuration
14009 (vhdl-speedbar-check-unit 'architecture)]
14010 ["Select as MRA" vhdl-speedbar-select-mra
14011 (vhdl-speedbar-check-unit 'architecture)]
14012 ["Make" vhdl-speedbar-make-design
14013 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14014 ["Generate Makefile" vhdl-speedbar-generate-makefile
14015 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14016 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14017 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14018 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14019 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14020 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14021 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14022 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14024 (speedbar-add-expansion-list
14025 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14026 vhdl-speedbar-display-directory))
14027 (speedbar-add-expansion-list
14028 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14029 vhdl-speedbar-display-projects))
14030 (setq speedbar-stealthy-function-list
14032 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14033 ("vhdl project" vhdl-speedbar-update-current-project
14034 vhdl-speedbar-update-current-unit)
14035 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14036 ; (speedbar-extension-list-to-regex
14037 ; speedbar-ignored-path-expressions))))
14039 speedbar-stealthy-function-list))
14040 (when (eq vhdl-speedbar-display-mode 'directory)
14041 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14042 (when (eq vhdl-speedbar-display-mode 'project)
14043 (setq speedbar-initial-expansion-list-name "vhdl project"))
14044 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14046 (defun vhdl-speedbar (&optional arg)
14047 "Open/close speedbar."
14049 (if (not (fboundp 'speedbar))
14050 (error "WARNING: Speedbar is not available or not installed")
14052 (speedbar-frame-mode arg)
14053 (error (error "WARNING: An error occurred while opening speedbar")))))
14055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14056 ;; Display functions
14058 (defvar vhdl-speedbar-last-selected-project nil
14059 "Name of last selected project.")
14061 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14062 (defmacro speedbar-with-writable (&rest forms)
14063 "Allow the buffer to be writable and evaluate FORMS."
14064 (list 'let '((inhibit-read-only t))
14065 (cons 'progn forms)))
14066 (put 'speedbar-with-writable 'lisp-indent-function 0)
14068 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14069 "Display directory and hierarchy information in speedbar."
14070 (setq vhdl-speedbar-show-projects nil)
14071 (setq speedbar-ignored-directory-regexp
14072 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14073 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14074 (setq speedbar-last-selected-file nil)
14075 (speedbar-with-writable
14076 (condition-case nil
14078 ;; insert directory path
14079 (speedbar-directory-buttons directory depth)
14080 ;; insert subdirectories
14081 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14082 ;; scan and insert hierarchy of current directory
14083 (vhdl-speedbar-insert-dir-hierarchy directory depth
14084 speedbar-power-click)
14085 ;; expand subdirectories
14086 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14087 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14089 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14090 "Display projects and hierarchy information in speedbar."
14091 (setq vhdl-speedbar-show-projects t)
14092 (setq speedbar-ignored-directory-regexp ".")
14093 (setq speedbar-last-selected-file nil)
14094 (setq vhdl-speedbar-last-selected-project nil)
14095 (speedbar-with-writable
14096 (condition-case nil
14098 (vhdl-speedbar-insert-projects)
14099 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14100 (setq speedbar-full-text-cache nil)) ; prevent caching
14102 (defun vhdl-speedbar-insert-projects ()
14103 "Insert all projects in speedbar."
14104 (vhdl-speedbar-make-title-line "Projects:")
14105 (let ((project-alist (if vhdl-project-sort
14106 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14107 vhdl-project-alist))
14108 (vhdl-speedbar-update-current-unit nil))
14110 (while project-alist
14111 (speedbar-make-tag-line
14112 'angle ?+ 'vhdl-speedbar-expand-project
14113 (caar project-alist) (caar project-alist)
14114 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14115 (setq project-alist (cdr project-alist)))
14116 (setq project-alist vhdl-project-alist)
14118 (while project-alist
14119 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14120 (goto-char (point-min))
14121 (when (re-search-forward
14122 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14123 (goto-char (match-end 1))
14124 (speedbar-do-function-pointer)))
14125 (setq project-alist (cdr project-alist))))
14126 ; (vhdl-speedbar-update-current-project)
14127 ; (vhdl-speedbar-update-current-unit nil t)
14130 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14131 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14132 otherwise use cached data."
14133 (when (or rescan (and (not (assoc project vhdl-file-alist))
14134 (not (vhdl-load-cache project))))
14135 (vhdl-scan-project-contents project))
14136 ;; insert design hierarchy
14137 (vhdl-speedbar-insert-hierarchy
14138 (aget vhdl-entity-alist project t)
14139 (aget vhdl-config-alist project t)
14140 (aget vhdl-package-alist project t)
14141 (car (aget vhdl-ent-inst-alist project t)) indent)
14142 (insert (int-to-string indent) ":\n")
14143 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14144 (put-text-property (1- (point)) (point) 'invisible nil)
14145 ;; expand design units
14146 (vhdl-speedbar-expand-units project))
14148 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14149 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14150 otherwise use cached data."
14151 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14152 (not (vhdl-load-cache directory))))
14153 (vhdl-scan-directory-contents directory))
14154 ;; insert design hierarchy
14155 (vhdl-speedbar-insert-hierarchy
14156 (aget vhdl-entity-alist directory t)
14157 (aget vhdl-config-alist directory t)
14158 (aget vhdl-package-alist directory t)
14159 (car (aget vhdl-ent-inst-alist directory t)) depth)
14160 ;; expand design units
14161 (vhdl-speedbar-expand-units directory)
14162 (aput 'vhdl-directory-alist directory (list (list directory))))
14164 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14165 ent-inst-list depth)
14166 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14167 (if (not (or ent-alist conf-alist pack-alist))
14168 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14169 (let (ent-entry conf-entry pack-entry)
14171 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14173 (setq ent-entry (car ent-alist))
14174 (speedbar-make-tag-line
14175 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14176 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14177 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14178 'vhdl-speedbar-entity-face depth)
14179 (unless (nth 2 ent-entry)
14180 (end-of-line 0) (insert "!") (forward-char 1))
14181 (unless (member (nth 0 ent-entry) ent-inst-list)
14182 (end-of-line 0) (insert " (top)") (forward-char 1))
14183 (setq ent-alist (cdr ent-alist)))
14184 ;; insert configurations
14185 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14187 (setq conf-entry (car conf-alist))
14188 (speedbar-make-tag-line
14189 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14190 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14191 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14192 'vhdl-speedbar-configuration-face depth)
14193 (setq conf-alist (cdr conf-alist)))
14195 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14197 (setq pack-entry (car pack-alist))
14198 (vhdl-speedbar-make-pack-line
14199 (nth 0 pack-entry) (nth 1 pack-entry)
14200 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14201 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14203 (setq pack-alist (cdr pack-alist))))))
14205 (defun vhdl-speedbar-rescan-hierarchy ()
14206 "Rescan hierarchy for the directory or project under the cursor."
14211 (vhdl-speedbar-show-projects
14212 (setq key (vhdl-speedbar-line-project))
14213 (vhdl-scan-project-contents key))
14214 ;; top-level directory
14215 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14216 (re-search-forward "[0-9]+:" nil t)
14217 (vhdl-scan-directory-contents
14218 (abbreviate-file-name (speedbar-line-directory))))
14219 ;; current directory
14220 (t (setq path (speedbar-line-directory))
14221 (string-match "^\\(.+[/\\]\\)" path)
14222 (vhdl-scan-directory-contents
14223 (abbreviate-file-name (match-string 1 path)))))
14224 (vhdl-speedbar-refresh key)))
14226 (defun vhdl-speedbar-expand-dirs (directory)
14227 "Expand subdirectories in DIRECTORY according to
14228 `speedbar-shown-directories'."
14229 ;; (nicked from `speedbar-default-directory-list')
14230 (let ((sf (cdr (reverse speedbar-shown-directories)))
14231 (vhdl-speedbar-update-current-unit nil))
14232 (setq speedbar-shown-directories
14233 (list (expand-file-name default-directory)))
14235 (when (speedbar-goto-this-file (car sf))
14236 (beginning-of-line)
14237 (when (looking-at "[0-9]+:\\s-*<")
14238 (goto-char (match-end 0))
14239 (speedbar-do-function-pointer)))
14240 (setq sf (cdr sf))))
14241 (vhdl-speedbar-update-current-unit nil t))
14243 (defun vhdl-speedbar-expand-units (key)
14244 "Expand design units in directory/project KEY according to
14245 `vhdl-speedbar-shown-unit-alist'."
14246 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14247 (vhdl-speedbar-update-current-unit nil)
14248 vhdl-updated-project-list)
14249 (adelete 'vhdl-speedbar-shown-unit-alist key)
14250 (vhdl-prepare-search-1
14251 (while unit-alist ; expand units
14252 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14253 (beginning-of-line)
14254 (let ((arch-alist (nth 1 (car unit-alist)))
14256 (when (looking-at "^[0-9]+:\\s-*\\[")
14257 (goto-char (match-end 0))
14258 (setq position (point))
14259 (speedbar-do-function-pointer)
14260 (select-frame speedbar-frame)
14261 (while arch-alist ; expand architectures
14262 (goto-char position)
14263 (when (re-search-forward
14264 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14265 (car arch-alist) "\\>\\)") nil t)
14266 (beginning-of-line)
14267 (when (looking-at "^[0-9]+:\\s-*{")
14268 (goto-char (match-end 0))
14269 (speedbar-do-function-pointer)
14270 (select-frame speedbar-frame)))
14271 (setq arch-alist (cdr arch-alist))))
14272 (setq unit-alist (cdr unit-alist))))))
14273 (vhdl-speedbar-update-current-unit nil t))
14275 (defun vhdl-speedbar-contract-level ()
14276 "Contract current level in current directory/project."
14278 (when (or (save-excursion
14279 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14280 (and (save-excursion
14281 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14282 (re-search-backward
14283 (format "^[0-%d]:\\s-*[[{<]-"
14284 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14285 (goto-char (match-end 0))
14286 (speedbar-do-function-pointer)
14287 (speedbar-center-buffer-smartly)))
14289 (defun vhdl-speedbar-contract-all ()
14290 "Contract all expanded design units in current directory/project."
14292 (if (and vhdl-speedbar-show-projects
14293 (save-excursion (beginning-of-line) (looking-at "^0:")))
14294 (progn (setq vhdl-speedbar-shown-project-list nil)
14295 (vhdl-speedbar-refresh))
14296 (let ((key (vhdl-speedbar-line-key)))
14297 (adelete 'vhdl-speedbar-shown-unit-alist key)
14298 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14299 (when (memq 'display vhdl-speedbar-save-cache)
14300 (add-to-list 'vhdl-updated-project-list key)))))
14302 (defun vhdl-speedbar-expand-all ()
14303 "Expand all design units in current directory/project."
14305 (let* ((key (vhdl-speedbar-line-key))
14306 (ent-alist (aget vhdl-entity-alist key t))
14307 (conf-alist (aget vhdl-config-alist key t))
14308 (pack-alist (aget vhdl-package-alist key t))
14309 arch-alist unit-alist subunit-alist)
14310 (add-to-list 'vhdl-speedbar-shown-project-list key)
14312 (setq arch-alist (nth 4 (car ent-alist)))
14313 (setq subunit-alist nil)
14315 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14316 (setq arch-alist (cdr arch-alist)))
14317 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14318 (setq ent-alist (cdr ent-alist)))
14320 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14321 (setq conf-alist (cdr conf-alist)))
14323 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14324 (setq pack-alist (cdr pack-alist)))
14325 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14326 (vhdl-speedbar-refresh)
14327 (when (memq 'display vhdl-speedbar-save-cache)
14328 (add-to-list 'vhdl-updated-project-list key))))
14330 (defun vhdl-speedbar-expand-project (text token indent)
14331 "Expand/contract the project under the cursor."
14333 ((string-match "+" text) ; expand project
14334 (speedbar-change-expand-button-char ?-)
14335 (unless (member token vhdl-speedbar-shown-project-list)
14336 (setq vhdl-speedbar-shown-project-list
14337 (cons token vhdl-speedbar-shown-project-list)))
14338 (speedbar-with-writable
14340 (end-of-line) (forward-char 1)
14341 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14342 speedbar-power-click))))
14343 ((string-match "-" text) ; contract project
14344 (speedbar-change-expand-button-char ?+)
14345 (setq vhdl-speedbar-shown-project-list
14346 (delete token vhdl-speedbar-shown-project-list))
14347 (speedbar-delete-subblock indent))
14348 (t (error "Nothing to display")))
14349 (when (equal (selected-frame) speedbar-frame)
14350 (speedbar-center-buffer-smartly)))
14352 (defun vhdl-speedbar-expand-entity (text token indent)
14353 "Expand/contract the entity under the cursor."
14355 ((string-match "+" text) ; expand entity
14356 (let* ((key (vhdl-speedbar-line-key indent))
14357 (ent-alist (aget vhdl-entity-alist key t))
14358 (ent-entry (aget ent-alist token t))
14359 (arch-alist (nth 3 ent-entry))
14360 (inst-alist (vhdl-get-instantiations token indent))
14361 (subpack-alist (nth 5 ent-entry))
14362 (multiple-arch (> (length arch-alist) 1))
14363 arch-entry inst-entry)
14364 (if (not (or arch-alist inst-alist subpack-alist))
14365 (speedbar-change-expand-button-char ??)
14366 (speedbar-change-expand-button-char ?-)
14367 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14368 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14369 (aput 'unit-alist token nil)
14370 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14371 (speedbar-with-writable
14373 (end-of-line) (forward-char 1)
14374 ;; insert architectures
14376 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14378 (setq arch-entry (car arch-alist))
14379 (speedbar-make-tag-line
14380 'curly ?+ 'vhdl-speedbar-expand-architecture
14381 (cons token (nth 0 arch-entry))
14382 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14383 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14384 'vhdl-speedbar-architecture-face (1+ indent))
14385 (when (and multiple-arch
14386 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14387 (end-of-line 0) (insert " (mra)") (forward-char 1))
14388 (setq arch-alist (cdr arch-alist)))
14389 ;; insert instantiations
14391 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14393 (setq inst-entry (car inst-alist))
14394 (vhdl-speedbar-make-inst-line
14395 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14396 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14397 nil nil nil (1+ indent) 0 " in ")
14398 (setq inst-alist (cdr inst-alist)))
14399 ;; insert required packages
14400 (vhdl-speedbar-insert-subpackages
14401 subpack-alist (1+ indent) indent)))
14402 (when (memq 'display vhdl-speedbar-save-cache)
14403 (add-to-list 'vhdl-updated-project-list key))
14404 (vhdl-speedbar-update-current-unit t t))))
14405 ((string-match "-" text) ; contract entity
14406 (speedbar-change-expand-button-char ?+)
14407 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14408 (let* ((key (vhdl-speedbar-line-key indent))
14409 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14410 (adelete 'unit-alist token)
14412 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14413 (adelete 'vhdl-speedbar-shown-unit-alist key))
14414 (speedbar-delete-subblock indent)
14415 (when (memq 'display vhdl-speedbar-save-cache)
14416 (add-to-list 'vhdl-updated-project-list key))))
14417 (t (error "Nothing to display")))
14418 (when (equal (selected-frame) speedbar-frame)
14419 (speedbar-center-buffer-smartly)))
14421 (defun vhdl-speedbar-expand-architecture (text token indent)
14422 "Expand/contract the architecture under the cursor."
14424 ((string-match "+" text) ; expand architecture
14425 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14426 (ent-alist (aget vhdl-entity-alist key t))
14427 (conf-alist (aget vhdl-config-alist key t))
14428 (hier-alist (vhdl-get-hierarchy
14429 ent-alist conf-alist (car token) (cdr token) nil nil
14431 (ent-entry (aget ent-alist (car token) t))
14432 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14433 (subpack-alist (nth 4 arch-entry))
14435 (if (not (or hier-alist subpack-alist))
14436 (speedbar-change-expand-button-char ??)
14437 (speedbar-change-expand-button-char ?-)
14438 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14439 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14440 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14441 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14442 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14443 (speedbar-with-writable
14445 (end-of-line) (forward-char 1)
14446 ;; insert instance hierarchy
14448 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14451 (setq entry (car hier-alist))
14452 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14453 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14454 (vhdl-speedbar-make-inst-line
14455 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14456 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14457 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14458 (setq hier-alist (cdr hier-alist)))
14459 ;; insert required packages
14460 (vhdl-speedbar-insert-subpackages
14461 subpack-alist (1+ indent) (1- indent))))
14462 (when (memq 'display vhdl-speedbar-save-cache)
14463 (add-to-list 'vhdl-updated-project-list key))
14464 (vhdl-speedbar-update-current-unit t t))))
14465 ((string-match "-" text) ; contract architecture
14466 (speedbar-change-expand-button-char ?+)
14467 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14468 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14469 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14470 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14471 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14472 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14473 (speedbar-delete-subblock indent)
14474 (when (memq 'display vhdl-speedbar-save-cache)
14475 (add-to-list 'vhdl-updated-project-list key))))
14476 (t (error "Nothing to display")))
14477 (when (equal (selected-frame) speedbar-frame)
14478 (speedbar-center-buffer-smartly)))
14480 (defun vhdl-speedbar-expand-config (text token indent)
14481 "Expand/contract the configuration under the cursor."
14483 ((string-match "+" text) ; expand configuration
14484 (let* ((key (vhdl-speedbar-line-key indent))
14485 (conf-alist (aget vhdl-config-alist key t))
14486 (conf-entry (aget conf-alist token))
14487 (ent-alist (aget vhdl-entity-alist key t))
14488 (hier-alist (vhdl-get-hierarchy
14489 ent-alist conf-alist (nth 3 conf-entry)
14490 (nth 4 conf-entry) token (nth 5 conf-entry)
14492 (subpack-alist (nth 6 conf-entry))
14494 (if (not (or hier-alist subpack-alist))
14495 (speedbar-change-expand-button-char ??)
14496 (speedbar-change-expand-button-char ?-)
14497 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14498 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14499 (aput 'unit-alist token nil)
14500 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14501 (speedbar-with-writable
14503 (end-of-line) (forward-char 1)
14504 ;; insert instance hierarchy
14506 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14508 (setq entry (car hier-alist))
14509 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14510 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14511 (vhdl-speedbar-make-inst-line
14512 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14513 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14514 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14515 (setq hier-alist (cdr hier-alist)))
14516 ;; insert required packages
14517 (vhdl-speedbar-insert-subpackages
14518 subpack-alist (1+ indent) indent)))
14519 (when (memq 'display vhdl-speedbar-save-cache)
14520 (add-to-list 'vhdl-updated-project-list key))
14521 (vhdl-speedbar-update-current-unit t t))))
14522 ((string-match "-" text) ; contract configuration
14523 (speedbar-change-expand-button-char ?+)
14524 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14525 (let* ((key (vhdl-speedbar-line-key indent))
14526 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14527 (adelete 'unit-alist token)
14529 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14530 (adelete 'vhdl-speedbar-shown-unit-alist key))
14531 (speedbar-delete-subblock indent)
14532 (when (memq 'display vhdl-speedbar-save-cache)
14533 (add-to-list 'vhdl-updated-project-list key))))
14534 (t (error "Nothing to display")))
14535 (when (equal (selected-frame) speedbar-frame)
14536 (speedbar-center-buffer-smartly)))
14538 (defun vhdl-speedbar-expand-package (text token indent)
14539 "Expand/contract the package under the cursor."
14541 ((string-match "+" text) ; expand package
14542 (let* ((key (vhdl-speedbar-line-key indent))
14543 (pack-alist (aget vhdl-package-alist key t))
14544 (pack-entry (aget pack-alist token t))
14545 (comp-alist (nth 3 pack-entry))
14546 (func-alist (nth 4 pack-entry))
14547 (func-body-alist (nth 8 pack-entry))
14548 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14549 comp-entry func-entry func-body-entry)
14550 (if (not (or comp-alist func-alist subpack-alist))
14551 (speedbar-change-expand-button-char ??)
14552 (speedbar-change-expand-button-char ?-)
14553 ;; add package to `vhdl-speedbar-shown-unit-alist'
14554 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14555 (aput 'unit-alist token nil)
14556 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14557 (speedbar-with-writable
14559 (end-of-line) (forward-char 1)
14560 ;; insert components
14562 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14564 (setq comp-entry (car comp-alist))
14565 (speedbar-make-tag-line
14567 (cons token (nth 0 comp-entry))
14568 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14569 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14570 'vhdl-speedbar-entity-face (1+ indent))
14571 (setq comp-alist (cdr comp-alist)))
14572 ;; insert subprograms
14574 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14576 (setq func-entry (car func-alist)
14577 func-body-entry (aget func-body-alist (car func-entry) t))
14578 (when (nth 2 func-entry)
14579 (vhdl-speedbar-make-subprogram-line
14581 (cons (nth 2 func-entry) (nth 3 func-entry))
14582 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14584 (setq func-alist (cdr func-alist)))
14585 ;; insert required packages
14586 (vhdl-speedbar-insert-subpackages
14587 subpack-alist (1+ indent) indent)))
14588 (when (memq 'display vhdl-speedbar-save-cache)
14589 (add-to-list 'vhdl-updated-project-list key))
14590 (vhdl-speedbar-update-current-unit t t))))
14591 ((string-match "-" text) ; contract package
14592 (speedbar-change-expand-button-char ?+)
14593 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14594 (let* ((key (vhdl-speedbar-line-key indent))
14595 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14596 (adelete 'unit-alist token)
14598 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14599 (adelete 'vhdl-speedbar-shown-unit-alist key))
14600 (speedbar-delete-subblock indent)
14601 (when (memq 'display vhdl-speedbar-save-cache)
14602 (add-to-list 'vhdl-updated-project-list key))))
14603 (t (error "Nothing to display")))
14604 (when (equal (selected-frame) speedbar-frame)
14605 (speedbar-center-buffer-smartly)))
14607 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14608 "Insert required packages."
14609 (let* ((pack-alist (aget vhdl-package-alist
14610 (vhdl-speedbar-line-key dir-indent) t))
14611 pack-key lib-name pack-entry)
14612 (when subpack-alist
14613 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14614 (while subpack-alist
14615 (setq pack-key (cdar subpack-alist)
14616 lib-name (caar subpack-alist))
14617 (setq pack-entry (aget pack-alist pack-key t))
14618 (vhdl-speedbar-make-subpack-line
14619 (or (nth 0 pack-entry) pack-key) lib-name
14620 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14621 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14622 (setq subpack-alist (cdr subpack-alist)))))
14624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14625 ;; Display help functions
14627 (defvar vhdl-speedbar-update-current-unit t
14628 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14630 (defun vhdl-speedbar-update-current-project ()
14631 "Highlight project that is currently active."
14632 (when (and vhdl-speedbar-show-projects
14633 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14634 (and (boundp 'speedbar-frame)
14635 (frame-live-p speedbar-frame)))
14636 (let ((last-frame (selected-frame))
14637 (project-alist vhdl-project-alist)
14639 (select-frame speedbar-frame)
14640 (speedbar-with-writable
14642 (while project-alist
14643 (goto-char (point-min))
14644 (when (re-search-forward
14645 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14646 (put-text-property (match-beginning 1) (match-end 1) 'face
14647 (if (equal (caar project-alist) vhdl-project)
14648 'speedbar-selected-face
14649 'speedbar-directory-face))
14650 (when (equal (caar project-alist) vhdl-project)
14651 (setq pos (1- (match-beginning 1)))))
14652 (setq project-alist (cdr project-alist))))
14653 (when pos (goto-char pos)))
14654 (select-frame last-frame)
14655 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14658 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14659 "Highlight all design units that are contained in the current file.
14660 NO-POSITION non-nil means do not re-position cursor."
14661 (let ((last-frame (selected-frame))
14662 (project-list vhdl-speedbar-shown-project-list)
14663 file-alist pos file-name)
14664 ;; get current file name
14665 (if (fboundp 'speedbar-select-attached-frame)
14666 (speedbar-select-attached-frame)
14667 (select-frame speedbar-attached-frame))
14668 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14669 (when (and vhdl-speedbar-update-current-unit
14670 (or always (not (equal file-name speedbar-last-selected-file))))
14671 (if vhdl-speedbar-show-projects
14672 (while project-list
14673 (setq file-alist (append file-alist (aget vhdl-file-alist
14674 (car project-list) t)))
14675 (setq project-list (cdr project-list)))
14676 (setq file-alist (aget vhdl-file-alist
14677 (abbreviate-file-name default-directory) t)))
14678 (select-frame speedbar-frame)
14679 (set-buffer speedbar-buffer)
14680 (speedbar-with-writable
14681 (vhdl-prepare-search-1
14683 ;; unhighlight last units
14684 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14685 (vhdl-speedbar-update-units
14686 "\\[.\\] " (nth 0 file-entry)
14687 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14688 (vhdl-speedbar-update-units
14689 "{.} " (nth 1 file-entry)
14690 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14691 (vhdl-speedbar-update-units
14692 "\\[.\\] " (nth 3 file-entry)
14693 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14694 (vhdl-speedbar-update-units
14695 "[]>] " (nth 4 file-entry)
14696 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14697 (vhdl-speedbar-update-units
14698 "\\[.\\].+(" '("body")
14699 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14700 (vhdl-speedbar-update-units
14701 "> " (nth 6 file-entry)
14702 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14703 ;; highlight current units
14704 (let* ((file-entry (aget file-alist file-name t)))
14706 pos (vhdl-speedbar-update-units
14707 "\\[.\\] " (nth 0 file-entry)
14708 file-name 'vhdl-speedbar-entity-selected-face pos)
14709 pos (vhdl-speedbar-update-units
14710 "{.} " (nth 1 file-entry)
14711 file-name 'vhdl-speedbar-architecture-selected-face pos)
14712 pos (vhdl-speedbar-update-units
14713 "\\[.\\] " (nth 3 file-entry)
14714 file-name 'vhdl-speedbar-configuration-selected-face pos)
14715 pos (vhdl-speedbar-update-units
14716 "[]>] " (nth 4 file-entry)
14717 file-name 'vhdl-speedbar-package-selected-face pos)
14718 pos (vhdl-speedbar-update-units
14719 "\\[.\\].+(" '("body")
14720 file-name 'vhdl-speedbar-package-selected-face pos)
14721 pos (vhdl-speedbar-update-units
14722 "> " (nth 6 file-entry)
14723 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14724 ;; move speedbar so the first highlighted unit is visible
14725 (when (and pos (not no-position))
14727 (speedbar-center-buffer-smartly)
14728 (speedbar-position-cursor-on-line))
14729 (setq speedbar-last-selected-file file-name))
14730 (select-frame last-frame)
14733 (defun vhdl-speedbar-update-units (text unit-list file-name face
14735 "Help function to highlight design units."
14737 (goto-char (point-min))
14738 (while (re-search-forward
14739 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14740 (when (equal file-name (car (get-text-property
14741 (match-beginning 1) 'speedbar-token)))
14742 (setq pos (or pos (point-marker)))
14743 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14744 (setq unit-list (cdr unit-list)))
14747 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14748 ent-name ent-file-marker
14749 arch-name arch-file-marker
14750 conf-name conf-file-marker
14751 lib-name depth offset delimiter)
14752 "Insert instantiation entry."
14753 (let ((start (point))
14755 (insert (int-to-string depth) ":")
14756 (put-text-property start (point) 'invisible t)
14757 (setq visible-start (point))
14758 (insert-char ? (* depth speedbar-indentation-width))
14759 (while (> offset 0)
14761 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14762 (setq offset (1- offset)))
14763 (put-text-property visible-start (point) 'invisible nil)
14764 (setq start (point))
14766 (speedbar-make-button start (point) nil nil nil)
14767 (setq visible-start (point))
14769 (setq start (point))
14770 (if (not inst-name)
14773 (speedbar-make-button
14774 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14775 'vhdl-speedbar-find-file inst-file-marker))
14778 (setq start (point))
14780 (speedbar-make-button
14781 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14782 'vhdl-speedbar-find-file ent-file-marker)
14785 (setq start (point))
14787 (speedbar-make-button
14788 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14789 'vhdl-speedbar-find-file arch-file-marker)
14793 (setq start (point))
14795 (speedbar-make-button
14796 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14797 'vhdl-speedbar-find-file conf-file-marker)
14799 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14800 (setq start (point))
14801 (insert " (" lib-name ")")
14802 (put-text-property (+ 2 start) (1- (point)) 'face
14803 'vhdl-speedbar-library-face))
14804 (insert-char ?\n 1)
14805 (put-text-property visible-start (point) 'invisible nil)))
14807 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14808 body-file-marker depth)
14809 "Insert package entry."
14810 (let ((start (point))
14812 (insert (int-to-string depth) ":")
14813 (put-text-property start (point) 'invisible t)
14814 (setq visible-start (point))
14815 (insert-char ? (* depth speedbar-indentation-width))
14816 (put-text-property visible-start (point) 'invisible nil)
14817 (setq start (point))
14819 (speedbar-make-button
14820 start (point) 'speedbar-button-face 'speedbar-highlight-face
14821 'vhdl-speedbar-expand-package pack-key)
14822 (setq visible-start (point))
14823 (insert-char ? 1 nil)
14824 (setq start (point))
14826 (speedbar-make-button
14827 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14828 'vhdl-speedbar-find-file pack-file-marker)
14829 (unless (car pack-file-marker)
14831 (when (car body-file-marker)
14833 (setq start (point))
14835 (speedbar-make-button
14836 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14837 'vhdl-speedbar-find-file body-file-marker)
14839 (insert-char ?\n 1)
14840 (put-text-property visible-start (point) 'invisible nil)))
14842 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14843 pack-body-file-marker depth)
14844 "Insert used package entry."
14845 (let ((start (point))
14847 (insert (int-to-string depth) ":")
14848 (put-text-property start (point) 'invisible t)
14849 (setq visible-start (point))
14850 (insert-char ? (* depth speedbar-indentation-width))
14851 (put-text-property visible-start (point) 'invisible nil)
14852 (setq start (point))
14854 (speedbar-make-button start (point) nil nil nil)
14855 (setq visible-start (point))
14857 (setq start (point))
14859 (speedbar-make-button
14860 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14861 'vhdl-speedbar-find-file pack-file-marker)
14862 (when (car pack-body-file-marker)
14864 (setq start (point))
14866 (speedbar-make-button
14867 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14868 'vhdl-speedbar-find-file pack-body-file-marker)
14870 (setq start (point))
14871 (insert " (" lib-name ")")
14872 (put-text-property (+ 2 start) (1- (point)) 'face
14873 'vhdl-speedbar-library-face)
14874 (insert-char ?\n 1)
14875 (put-text-property visible-start (point) 'invisible nil)))
14877 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14878 func-body-file-marker
14880 "Insert subprogram entry."
14881 (let ((start (point))
14883 (insert (int-to-string depth) ":")
14884 (put-text-property start (point) 'invisible t)
14885 (setq visible-start (point))
14886 (insert-char ? (* depth speedbar-indentation-width))
14887 (put-text-property visible-start (point) 'invisible nil)
14888 (setq start (point))
14890 (speedbar-make-button start (point) nil nil nil)
14891 (setq visible-start (point))
14893 (setq start (point))
14895 (speedbar-make-button
14896 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14897 'vhdl-speedbar-find-file func-file-marker)
14898 (when (car func-body-file-marker)
14900 (setq start (point))
14902 (speedbar-make-button
14903 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14904 'vhdl-speedbar-find-file func-body-file-marker)
14906 (insert-char ?\n 1)
14907 (put-text-property visible-start (point) 'invisible nil)))
14909 (defun vhdl-speedbar-make-title-line (text &optional depth)
14910 "Insert design unit title entry."
14911 (let ((start (point))
14914 (insert (int-to-string depth) ":")
14915 (put-text-property start (point) 'invisible t))
14916 (setq visible-start (point))
14917 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14918 (setq start (point))
14920 (speedbar-make-button start (point) nil nil nil nil)
14921 (insert-char ?\n 1)
14922 (put-text-property visible-start (point) 'invisible nil)))
14924 (defun vhdl-speedbar-insert-dirs (files level)
14925 "Insert subdirectories."
14926 (let ((dirs (car files)))
14928 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14929 (car dirs) 'speedbar-dir-follow nil
14930 'speedbar-directory-face level)
14931 (setq dirs (cdr dirs)))))
14933 (defun vhdl-speedbar-dired (text token indent)
14934 "Speedbar click handler for directory expand button in hierarchy mode."
14935 (cond ((string-match "+" text) ; we have to expand this dir
14936 (setq speedbar-shown-directories
14937 (cons (expand-file-name
14938 (concat (speedbar-line-directory indent) token "/"))
14939 speedbar-shown-directories))
14940 (speedbar-change-expand-button-char ?-)
14941 (speedbar-reset-scanners)
14942 (speedbar-with-writable
14944 (end-of-line) (forward-char 1)
14945 (vhdl-speedbar-insert-dirs
14946 (speedbar-file-lists
14947 (concat (speedbar-line-directory indent) token "/"))
14949 (speedbar-reset-scanners)
14950 (vhdl-speedbar-insert-dir-hierarchy
14951 (abbreviate-file-name
14952 (concat (speedbar-line-directory indent) token "/"))
14953 (1+ indent) speedbar-power-click)))
14954 (vhdl-speedbar-update-current-unit t t))
14955 ((string-match "-" text) ; we have to contract this node
14956 (speedbar-reset-scanners)
14957 (let ((oldl speedbar-shown-directories)
14959 (td (expand-file-name
14960 (concat (speedbar-line-directory indent) token))))
14962 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14963 (setq newl (cons (car oldl) newl)))
14964 (setq oldl (cdr oldl)))
14965 (setq speedbar-shown-directories (nreverse newl)))
14966 (speedbar-change-expand-button-char ?+)
14967 (speedbar-delete-subblock indent))
14968 (t (error "Nothing to display")))
14969 (when (equal (selected-frame) speedbar-frame)
14970 (speedbar-center-buffer-smartly)))
14972 (defun vhdl-speedbar-item-info ()
14973 "Derive and display information about this line item."
14975 (beginning-of-line)
14976 ;; skip invisible number info
14977 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14979 ;; project/directory entry
14980 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14981 (if vhdl-speedbar-show-projects
14982 (message "Project \"%s\"" (match-string-no-properties 1))
14983 (speedbar-files-item-info)))
14984 ;; design unit entry
14985 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14986 (goto-char (match-end 1))
14987 (let ((face (get-text-property (point) 'face)))
14989 "%s \"%s\" in \"%s\""
14990 ;; design unit kind
14991 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14992 (eq face 'vhdl-speedbar-entity-selected-face))
14993 (if (equal (match-string 2) ">") "Component" "Entity"))
14994 ((or (eq face 'vhdl-speedbar-architecture-face)
14995 (eq face 'vhdl-speedbar-architecture-selected-face))
14997 ((or (eq face 'vhdl-speedbar-configuration-face)
14998 (eq face 'vhdl-speedbar-configuration-selected-face))
15000 ((or (eq face 'vhdl-speedbar-package-face)
15001 (eq face 'vhdl-speedbar-package-selected-face))
15003 ((or (eq face 'vhdl-speedbar-instantiation-face)
15004 (eq face 'vhdl-speedbar-instantiation-selected-face))
15006 ((eq face 'vhdl-speedbar-subprogram-face)
15009 ;; design unit name
15010 (buffer-substring-no-properties
15011 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15014 (file-relative-name
15015 (or (car (get-text-property (point) 'speedbar-token))
15017 (vhdl-default-directory)))))
15018 (t (message "")))))
15020 (defun vhdl-speedbar-line-text ()
15021 "Calls `speedbar-line-text' and removes text properties."
15022 (let ((string (speedbar-line-text)))
15023 (set-text-properties 0 (length string) nil string)
15026 (defun vhdl-speedbar-higher-text ()
15027 "Get speedbar-line-text of higher level."
15028 (let (depth string)
15030 (beginning-of-line)
15031 (looking-at "^\\([0-9]+\\):")
15032 (setq depth (string-to-number (match-string 1)))
15033 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15034 (setq string (match-string 1))
15035 (set-text-properties 0 (length string) nil string)
15038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15041 (defun vhdl-speedbar-line-key (&optional indent)
15042 "Get currently displayed directory of project name."
15043 (if vhdl-speedbar-show-projects
15044 (vhdl-speedbar-line-project)
15045 (abbreviate-file-name
15046 (file-name-as-directory (speedbar-line-directory indent)))))
15048 (defun vhdl-speedbar-line-project (&optional indent)
15049 "Get currently displayed project name."
15050 (and vhdl-speedbar-show-projects
15053 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15054 (match-string-no-properties 1))))
15056 (defun vhdl-add-modified-file ()
15057 "Add file to `vhdl-modified-file-list'."
15058 (when vhdl-file-alist
15059 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15062 (defun vhdl-resolve-paths (path-list)
15063 "Resolve path wildcards in PATH-LIST."
15064 (let (path-list-1 path-list-2 path-beg path-end dir)
15065 ;; eliminate non-existent directories
15067 (setq dir (car path-list))
15068 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15069 (if (file-directory-p (match-string 2 dir))
15070 (setq path-list-1 (cons dir path-list-1))
15071 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15072 (setq path-list (cdr path-list)))
15073 ;; resolve path wildcards
15075 (setq dir (car path-list-1))
15076 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15078 (setq path-beg (match-string 1 dir)
15079 path-end (match-string 5 dir))
15084 (lambda (var) (concat path-beg var path-end)))
15085 (let ((all-list (vhdl-directory-files
15086 (match-string 2 dir) t
15087 (concat "\\<" (wildcard-to-regexp
15088 (match-string 4 dir)))))
15091 (when (file-directory-p (car all-list))
15092 (setq dir-list (cons (car all-list) dir-list)))
15093 (setq all-list (cdr all-list)))
15095 (cdr path-list-1))))
15096 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15097 (when (file-directory-p (match-string 2 dir))
15098 (setq path-list-2 (cons dir path-list-2)))
15099 (setq path-list-1 (cdr path-list-1))))
15100 (nreverse path-list-2)))
15102 (defun vhdl-speedbar-goto-this-unit (directory unit)
15103 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15104 (let ((dest (point)))
15105 (if (and (if vhdl-speedbar-show-projects
15106 (progn (goto-char (point-min)) t)
15107 (speedbar-goto-this-file directory))
15108 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15109 (progn (speedbar-position-cursor-on-line)
15114 (defun vhdl-speedbar-find-file (text token indent)
15115 "When user clicks on TEXT, load file with name and position in TOKEN.
15116 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15117 is already shown in a buffer."
15118 (if (not (car token))
15119 (error "ERROR: File cannot be found")
15120 (let ((buffer (get-file-buffer (car token))))
15121 (speedbar-find-file-in-frame (car token))
15122 (when (or vhdl-speedbar-jump-to-unit buffer)
15123 (goto-char (point-min))
15124 (forward-line (1- (cdr token)))
15126 (vhdl-speedbar-update-current-unit t t)
15127 (speedbar-set-timer dframe-update-speed)
15128 (speedbar-maybee-jump-to-attached-frame))))
15130 (defun vhdl-speedbar-port-copy ()
15131 "Copy the port of the entity/component or subprogram under the cursor."
15133 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15134 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15135 (error "ERROR: No entity/component or subprogram under cursor")
15136 (beginning-of-line)
15137 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15138 (condition-case info
15139 (let ((token (get-text-property
15140 (match-beginning 3) 'speedbar-token)))
15141 (vhdl-visit-file (car token) t
15142 (progn (goto-char (point-min))
15143 (forward-line (1- (cdr token)))
15147 (vhdl-subprog-copy)))))
15148 (error (error "ERROR: %s not scanned successfully\n (%s)"
15149 (if is-entity "Port" "Interface") (cadr info))))
15150 (error "ERROR: No entity/component or subprogram on current line")))))
15152 (defun vhdl-speedbar-place-component ()
15153 "Place the entity/component under the cursor as component."
15155 (if (not (vhdl-speedbar-check-unit 'entity))
15156 (error "ERROR: No entity/component under cursor")
15157 (vhdl-speedbar-port-copy)
15158 (if (fboundp 'speedbar-select-attached-frame)
15159 (speedbar-select-attached-frame)
15160 (select-frame speedbar-attached-frame))
15161 (vhdl-compose-place-component)
15162 (select-frame speedbar-frame)))
15164 (defun vhdl-speedbar-configuration ()
15165 "Generate configuration for the architecture under the cursor."
15167 (if (not (vhdl-speedbar-check-unit 'architecture))
15168 (error "ERROR: No architecture under cursor")
15169 (let ((arch-name (vhdl-speedbar-line-text))
15170 (ent-name (vhdl-speedbar-higher-text)))
15171 (if (fboundp 'speedbar-select-attached-frame)
15172 (speedbar-select-attached-frame)
15173 (select-frame speedbar-attached-frame))
15174 (vhdl-compose-configuration ent-name arch-name))))
15176 (defun vhdl-speedbar-select-mra ()
15177 "Select the architecture under the cursor as MRA."
15179 (if (not (vhdl-speedbar-check-unit 'architecture))
15180 (error "ERROR: No architecture under cursor")
15181 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15182 (ent-key (downcase (vhdl-speedbar-higher-text)))
15183 (ent-alist (aget vhdl-entity-alist
15184 (or (vhdl-project-p) default-directory) t))
15185 (ent-entry (aget ent-alist ent-key t)))
15186 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15187 (speedbar-refresh))))
15189 (defun vhdl-speedbar-make-design ()
15190 "Make (compile) design unit or directory/project under the cursor."
15192 (if (not (save-excursion (beginning-of-line)
15193 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15194 (error "ERROR: No primary design unit or directory/project under cursor")
15195 (let ((is-unit (match-string 2))
15196 (unit-name (vhdl-speedbar-line-text))
15197 (vhdl-project (vhdl-speedbar-line-project))
15198 (directory (file-name-as-directory
15199 (or (speedbar-line-file) (speedbar-line-directory)))))
15200 (if (fboundp 'speedbar-select-attached-frame)
15201 (speedbar-select-attached-frame)
15202 (select-frame speedbar-attached-frame))
15203 (let ((default-directory directory))
15204 (vhdl-make (and is-unit unit-name))))))
15206 (defun vhdl-speedbar-generate-makefile ()
15207 "Generate Makefile for directory/project under the cursor."
15209 (let ((vhdl-project (vhdl-speedbar-line-project))
15210 (default-directory (file-name-as-directory
15211 (or (speedbar-line-file) (speedbar-line-directory)))))
15212 (vhdl-generate-makefile)))
15214 (defun vhdl-speedbar-check-unit (design-unit)
15215 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15216 expansion function)."
15218 (speedbar-position-cursor-on-line)
15219 (cond ((eq design-unit 'entity)
15220 (memq (get-text-property (match-end 0) 'face)
15221 '(vhdl-speedbar-entity-face
15222 vhdl-speedbar-entity-selected-face)))
15223 ((eq design-unit 'architecture)
15224 (memq (get-text-property (match-end 0) 'face)
15225 '(vhdl-speedbar-architecture-face
15226 vhdl-speedbar-architecture-selected-face)))
15227 ((eq design-unit 'subprogram)
15228 (eq (get-text-property (match-end 0) 'face)
15229 'vhdl-speedbar-subprogram-face))
15232 (defun vhdl-speedbar-set-depth (depth)
15233 "Set hierarchy display depth to DEPTH and refresh speedbar."
15234 (setq vhdl-speedbar-hierarchy-depth depth)
15235 (speedbar-refresh))
15237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15240 (defface vhdl-speedbar-entity-face
15241 '((((class color) (background light)) (:foreground "ForestGreen"))
15242 (((class color) (background dark)) (:foreground "PaleGreen")))
15243 "Face used for displaying entity names."
15244 :group 'speedbar-faces)
15246 (defface vhdl-speedbar-architecture-face
15247 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15248 (((class color) (background light)) (:foreground "Blue"))
15250 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15251 "Face used for displaying architecture names."
15252 :group 'speedbar-faces)
15254 (defface vhdl-speedbar-configuration-face
15255 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15256 (((class color) (background dark)) (:foreground "Salmon")))
15257 "Face used for displaying configuration names."
15258 :group 'speedbar-faces)
15260 (defface vhdl-speedbar-package-face
15261 '((((class color) (background light)) (:foreground "Grey50"))
15262 (((class color) (background dark)) (:foreground "Grey80")))
15263 "Face used for displaying package names."
15264 :group 'speedbar-faces)
15266 (defface vhdl-speedbar-library-face
15267 '((((class color) (background light)) (:foreground "Purple"))
15268 (((class color) (background dark)) (:foreground "Orchid1")))
15269 "Face used for displaying library names."
15270 :group 'speedbar-faces)
15272 (defface vhdl-speedbar-instantiation-face
15273 '((((class color) (background light)) (:foreground "Brown"))
15274 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15275 (((class color) (background dark)) (:foreground "Yellow")))
15276 "Face used for displaying instantiation names."
15277 :group 'speedbar-faces)
15279 (defface vhdl-speedbar-subprogram-face
15280 '((((class color) (background light)) (:foreground "Orchid4"))
15281 (((class color) (background dark)) (:foreground "BurlyWood2")))
15282 "Face used for displaying subprogram names."
15283 :group 'speedbar-faces)
15285 (defface vhdl-speedbar-entity-selected-face
15286 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15287 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15288 "Face used for displaying entity names."
15289 :group 'speedbar-faces)
15291 (defface vhdl-speedbar-architecture-selected-face
15292 '((((min-colors 88) (class color) (background light)) (:foreground
15293 "Blue1" :underline t))
15294 (((class color) (background light)) (:foreground "Blue" :underline t))
15295 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15296 "Face used for displaying architecture names."
15297 :group 'speedbar-faces)
15299 (defface vhdl-speedbar-configuration-selected-face
15300 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15301 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15302 "Face used for displaying configuration names."
15303 :group 'speedbar-faces)
15305 (defface vhdl-speedbar-package-selected-face
15306 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15307 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15308 "Face used for displaying package names."
15309 :group 'speedbar-faces)
15311 (defface vhdl-speedbar-instantiation-selected-face
15312 '((((class color) (background light)) (:foreground "Brown" :underline t))
15313 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15314 "Face used for displaying instantiation names."
15315 :group 'speedbar-faces)
15317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15321 (when (fboundp 'speedbar)
15323 (when (and vhdl-speedbar-auto-open
15324 (not (and (boundp 'speedbar-frame)
15325 (frame-live-p speedbar-frame))))
15326 (speedbar-frame-mode 1)
15327 (if (fboundp 'speedbar-select-attached-frame)
15328 (speedbar-select-attached-frame)
15329 (select-frame speedbar-attached-frame)))
15330 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15332 ;; initialize speedbar
15333 (if (not (boundp 'speedbar-frame))
15334 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15335 (vhdl-speedbar-initialize)
15336 (when speedbar-frame (vhdl-speedbar-refresh)))
15339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15340 ;;; Structural composition
15341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15343 (defun vhdl-get-components-package-name ()
15344 "Return the name of the components package."
15345 (let ((project (vhdl-project-p)))
15347 (vhdl-replace-string (car vhdl-components-package-name)
15348 (subst-char-in-string ? ?_ project))
15349 (cdr vhdl-components-package-name))))
15351 (defun vhdl-compose-new-component ()
15352 "Create entity and architecture for new component."
15354 (let* ((case-fold-search t)
15355 (ent-name (read-from-minibuffer "entity name: "
15356 nil vhdl-minibuffer-local-map))
15358 (if (equal (cdr vhdl-compose-architecture-name) "")
15359 (read-from-minibuffer "architecture name: "
15360 nil vhdl-minibuffer-local-map)
15361 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15362 ent-file-name arch-file-name ent-buffer arch-buffer project)
15363 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15364 ;; open entity file
15365 (unless (eq vhdl-compose-create-files 'none)
15366 (setq ent-file-name
15367 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15368 "." (file-name-extension (buffer-file-name))))
15369 (when (and (file-exists-p ent-file-name)
15370 (not (y-or-n-p (concat "File \"" ent-file-name
15371 "\" exists; overwrite? "))))
15372 (error "ERROR: Creating component...aborted"))
15373 (find-file ent-file-name)
15375 (set-buffer-modified-p nil))
15377 (if vhdl-compose-include-header
15378 (progn (vhdl-template-header)
15379 (goto-char (point-max)))
15380 (vhdl-comment-display-line) (insert "\n\n"))
15381 ;; insert library clause
15382 (vhdl-template-package-std-logic-1164)
15383 (when vhdl-use-components-package
15385 (vhdl-template-standard-package (vhdl-work-library)
15386 (vhdl-get-components-package-name)))
15387 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15388 ;; insert entity declaration
15389 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15390 (vhdl-insert-keyword " IS\n")
15391 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15392 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15393 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15394 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15395 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15396 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15397 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15398 (vhdl-insert-keyword "END ")
15399 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15400 (insert ent-name ";\n\n")
15401 (vhdl-comment-display-line) (insert "\n")
15402 ;; open architecture file
15403 (if (not (eq vhdl-compose-create-files 'separate))
15405 (setq ent-buffer (current-buffer))
15406 (setq arch-file-name
15407 (concat (vhdl-replace-string vhdl-architecture-file-name
15408 (concat ent-name " " arch-name) t)
15409 "." (file-name-extension (buffer-file-name))))
15410 (when (and (file-exists-p arch-file-name)
15411 (not (y-or-n-p (concat "File \"" arch-file-name
15412 "\" exists; overwrite? "))))
15413 (error "ERROR: Creating component...aborted"))
15414 (find-file arch-file-name)
15416 (set-buffer-modified-p nil)
15418 (if vhdl-compose-include-header
15419 (progn (vhdl-template-header)
15420 (goto-char (point-max)))
15421 (vhdl-comment-display-line) (insert "\n\n")))
15422 ;; insert architecture body
15423 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15424 (vhdl-insert-keyword " OF ") (insert ent-name)
15425 (vhdl-insert-keyword " IS\n\n")
15426 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15427 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15428 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15429 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15430 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15431 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15432 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15433 (vhdl-insert-keyword "BEGIN")
15434 (when vhdl-self-insert-comments
15436 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15437 (insert arch-name))
15439 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15440 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15441 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15442 (vhdl-insert-keyword "END ")
15443 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15444 (insert arch-name ";\n\n")
15445 ;; insert footer and save
15446 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15447 (vhdl-template-footer)
15448 (vhdl-comment-display-line) (insert "\n"))
15449 (goto-char (point-min))
15450 (setq arch-buffer (current-buffer))
15451 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15452 (set-buffer arch-buffer) (save-buffer)
15454 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15456 (format "\n File created: \"%s\"" ent-file-name))
15457 (and arch-file-name
15458 (format "\n File created: \"%s\"" arch-file-name))))))
15460 (defun vhdl-compose-place-component ()
15461 "Place new component by pasting current port as component declaration and
15462 component instantiation."
15464 (if (not vhdl-port-list)
15465 (error "ERROR: No port has been read")
15467 (vhdl-prepare-search-2
15468 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15469 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15470 (error "ERROR: No architecture found"))
15471 (let* ((ent-name (match-string 1))
15473 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15474 "." (file-name-extension (buffer-file-name))))
15475 (orig-buffer (current-buffer)))
15476 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15477 ;; place component declaration
15478 (unless (or vhdl-use-components-package
15479 (vhdl-use-direct-instantiation)
15482 (concat "^\\s-*component\\s-+"
15483 (car vhdl-port-list) "\\>") nil t)))
15484 (re-search-forward "^begin\\>" nil)
15485 (beginning-of-line)
15486 (skip-chars-backward " \t\n")
15487 (insert "\n\n") (indent-to vhdl-basic-offset)
15488 (vhdl-port-paste-component t))
15489 ;; place component instantiation
15490 (re-search-forward "^end\\>" nil)
15491 (beginning-of-line)
15492 (skip-chars-backward " \t\n")
15493 (insert "\n\n") (indent-to vhdl-basic-offset)
15494 (vhdl-port-paste-instance nil t t)
15495 ;; place use clause for used packages
15496 (when (nth 3 vhdl-port-list)
15497 ;; open entity file
15498 (when (file-exists-p ent-file-name)
15499 (find-file ent-file-name))
15500 (goto-char (point-min))
15501 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15502 (error "ERROR: Entity not found: \"%s\"" ent-name))
15503 (goto-char (match-beginning 0))
15504 (if (and (save-excursion
15505 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15507 (progn (goto-char (match-end 0))
15508 (beginning-of-line 2))
15511 (vhdl-port-paste-context-clause)
15512 (switch-to-buffer orig-buffer))
15513 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15515 (defun vhdl-compose-wire-components ()
15516 "Connect components."
15519 (vhdl-prepare-search-2
15520 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15521 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15522 (error "ERROR: No architecture found"))
15523 (let* ((ent-name (match-string 1))
15525 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15526 "." (file-name-extension (buffer-file-name))))
15527 (arch-decl-pos (point-marker))
15528 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15529 (arch-end-pos (re-search-forward "^end\\>" nil))
15530 (pack-name (vhdl-get-components-package-name))
15532 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15533 "." (file-name-extension (buffer-file-name))))
15534 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15535 port-alist generic-alist inst-alist
15536 signal-name signal-entry signal-alist local-list written-list
15537 single-in-list multi-in-list single-out-list multi-out-list
15538 constant-name constant-entry constant-alist single-list multi-list
15539 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15540 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15541 signal-beg-pos signal-pos
15542 constant-temp-pos port-temp-pos signal-temp-pos)
15543 (message "Wiring components...")
15544 ;; process all instances
15545 (goto-char arch-stat-pos)
15546 (while (re-search-forward
15547 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15548 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15549 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15550 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15551 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15552 (setq inst-name (match-string-no-properties 1)
15553 comp-name (match-string-no-properties 4)
15554 comp-ent-name (match-string-no-properties 12)
15555 has-generic (or (match-string 7) (match-string 17)))
15558 ;; ... from component declaration
15560 (when vhdl-use-components-package pack-file-name) t
15562 (goto-char (point-min))
15563 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15564 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15566 ;; ... from entity declaration (direct instantiation)
15567 (setq comp-ent-file-name
15568 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15569 "." (file-name-extension (buffer-file-name))))
15571 comp-ent-file-name t
15573 (goto-char (point-min))
15574 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15575 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15576 (vhdl-port-copy))))
15577 (vhdl-port-flatten t)
15578 (setq generic-alist (nth 1 vhdl-port-list)
15579 port-alist (nth 2 vhdl-port-list)
15580 vhdl-port-list nil)
15581 (setq constant-alist nil
15584 ;; process all constants in generic map
15585 (vhdl-forward-syntactic-ws)
15586 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15587 (setq constant-name (match-string-no-properties 3))
15588 (setq constant-entry
15589 (cons constant-name
15590 (if (match-string 1)
15591 (or (aget generic-alist (match-string 2) t)
15592 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15593 (cdar generic-alist))))
15594 (setq constant-alist (cons constant-entry constant-alist))
15595 (setq constant-name (downcase constant-name))
15596 (if (or (member constant-name single-list)
15597 (member constant-name multi-list))
15598 (progn (setq single-list (delete constant-name single-list))
15599 (add-to-list 'multi-list constant-name))
15600 (add-to-list 'single-list constant-name))
15601 (unless (match-string 1)
15602 (setq generic-alist (cdr generic-alist)))
15603 (vhdl-forward-syntactic-ws))
15604 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15605 ;; process all signals in port map
15606 (vhdl-forward-syntactic-ws)
15607 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15608 (setq signal-name (match-string-no-properties 3))
15609 (setq signal-entry (cons signal-name
15610 (if (match-string 1)
15611 (or (aget port-alist (match-string 2) t)
15612 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15613 (cdar port-alist))))
15614 (setq signal-alist (cons signal-entry signal-alist))
15615 (setq signal-name (downcase signal-name))
15616 (if (equal (upcase (nth 2 signal-entry)) "IN")
15619 ((member signal-name local-list)
15621 ((or (member signal-name single-out-list)
15622 (member signal-name multi-out-list))
15623 (setq single-out-list (delete signal-name single-out-list))
15624 (setq multi-out-list (delete signal-name multi-out-list))
15625 (add-to-list 'local-list signal-name))
15626 ((member signal-name single-in-list)
15627 (setq single-in-list (delete signal-name single-in-list))
15628 (add-to-list 'multi-in-list signal-name))
15629 ((not (member signal-name multi-in-list))
15630 (add-to-list 'single-in-list signal-name)))
15633 ((member signal-name local-list)
15635 ((or (member signal-name single-in-list)
15636 (member signal-name multi-in-list))
15637 (setq single-in-list (delete signal-name single-in-list))
15638 (setq multi-in-list (delete signal-name multi-in-list))
15639 (add-to-list 'local-list signal-name))
15640 ((member signal-name single-out-list)
15641 (setq single-out-list (delete signal-name single-out-list))
15642 (add-to-list 'multi-out-list signal-name))
15643 ((not (member signal-name multi-out-list))
15644 (add-to-list 'single-out-list signal-name))))
15645 (unless (match-string 1)
15646 (setq port-alist (cdr port-alist)))
15647 (vhdl-forward-syntactic-ws))
15648 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15649 (nreverse signal-alist)) inst-alist)))
15650 ;; prepare signal insertion
15651 (vhdl-goto-marker arch-decl-pos)
15653 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15654 (setq signal-pos (point-marker))
15655 (while (progn (vhdl-forward-syntactic-ws)
15656 (looking-at "signal\\>"))
15657 (beginning-of-line 2)
15658 (delete-region signal-pos (point)))
15659 (setq signal-beg-pos signal-pos)
15660 ;; open entity file
15661 (when (file-exists-p ent-file-name)
15662 (find-file ent-file-name))
15663 (goto-char (point-min))
15664 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15665 (error "ERROR: Entity not found: \"%s\"" ent-name))
15666 ;; prepare generic clause insertion
15667 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15669 (goto-char (match-beginning 0))
15670 (indent-to vhdl-basic-offset)
15671 (insert "generic ();\n\n")
15674 (setq generic-pos (point-marker))
15675 (forward-sexp) (end-of-line)
15676 (delete-region generic-pos (point)) (delete-char 1)
15680 (indent-to (* 2 vhdl-basic-offset))
15681 (insert "-- global generics\n"))
15682 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15683 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15684 ;; prepare port clause insertion
15685 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15687 (goto-char (match-beginning 0))
15688 (indent-to vhdl-basic-offset)
15689 (insert "port ();\n\n")
15692 (setq port-in-pos (point-marker))
15693 (forward-sexp) (end-of-line)
15694 (delete-region port-in-pos (point)) (delete-char 1)
15696 (when (or multi-in-list multi-out-list)
15698 (indent-to (* 2 vhdl-basic-offset))
15699 (insert "-- global ports\n"))
15700 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15701 port-out-pos (point-marker) port-inst-pos (point-marker)
15702 port-end-pos (point-marker))
15703 ;; insert generics, ports and signals
15704 (setq inst-alist (nreverse inst-alist))
15706 (setq inst-name (nth 0 (car inst-alist))
15707 constant-alist (nth 1 (car inst-alist))
15708 signal-alist (nth 2 (car inst-alist))
15709 constant-temp-pos generic-inst-pos
15710 port-temp-pos port-inst-pos
15711 signal-temp-pos signal-pos)
15713 (while constant-alist
15714 (setq constant-name (downcase (caar constant-alist))
15715 constant-entry (car constant-alist))
15716 (cond ((member constant-name written-list)
15718 ((member constant-name multi-list)
15719 (vhdl-goto-marker generic-pos)
15720 (setq generic-end-pos
15723 (vhdl-compose-insert-generic constant-entry)))
15724 (setq generic-pos (point-marker))
15725 (add-to-list 'written-list constant-name))
15728 (vhdl-max-marker generic-inst-pos generic-pos))
15729 (setq generic-end-pos
15730 (vhdl-compose-insert-generic constant-entry))
15731 (setq generic-inst-pos (point-marker))
15732 (add-to-list 'written-list constant-name)))
15733 (setq constant-alist (cdr constant-alist)))
15734 (when (/= constant-temp-pos generic-inst-pos)
15735 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15736 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15737 (insert "-- generics for \"" inst-name "\"\n")
15738 (vhdl-goto-marker generic-inst-pos))
15739 ;; ports and signals
15740 (while signal-alist
15741 (setq signal-name (downcase (caar signal-alist))
15742 signal-entry (car signal-alist))
15743 (cond ((member signal-name written-list)
15745 ((member signal-name multi-in-list)
15746 (vhdl-goto-marker port-in-pos)
15749 port-end-pos (vhdl-compose-insert-port signal-entry)))
15750 (setq port-in-pos (point-marker))
15751 (add-to-list 'written-list signal-name))
15752 ((member signal-name multi-out-list)
15753 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15756 port-end-pos (vhdl-compose-insert-port signal-entry)))
15757 (setq port-out-pos (point-marker))
15758 (add-to-list 'written-list signal-name))
15759 ((or (member signal-name single-in-list)
15760 (member signal-name single-out-list))
15764 (vhdl-max-marker port-out-pos port-in-pos)))
15765 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15766 (setq port-inst-pos (point-marker))
15767 (add-to-list 'written-list signal-name))
15768 ((equal (upcase (nth 2 signal-entry)) "OUT")
15769 (vhdl-goto-marker signal-pos)
15770 (vhdl-compose-insert-signal signal-entry)
15771 (setq signal-pos (point-marker))
15772 (add-to-list 'written-list signal-name)))
15773 (setq signal-alist (cdr signal-alist)))
15774 (when (/= port-temp-pos port-inst-pos)
15776 (vhdl-max-marker port-temp-pos
15777 (vhdl-max-marker port-in-pos port-out-pos)))
15778 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15779 (insert "-- ports to \"" inst-name "\"\n")
15780 (vhdl-goto-marker port-inst-pos))
15781 (when (/= signal-temp-pos signal-pos)
15782 (vhdl-goto-marker signal-temp-pos)
15783 (insert "\n") (indent-to vhdl-basic-offset)
15784 (insert "-- outputs of \"" inst-name "\"\n")
15785 (vhdl-goto-marker signal-pos))
15786 (setq inst-alist (cdr inst-alist)))
15787 ;; finalize generic/port clause
15788 (vhdl-goto-marker generic-end-pos) (backward-char)
15789 (when (= generic-beg-pos generic-end-pos)
15790 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15791 (insert ";") (backward-char))
15793 (vhdl-goto-marker port-end-pos) (backward-char)
15794 (when (= port-beg-pos port-end-pos)
15795 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15796 (insert ";") (backward-char))
15798 ;; align everything
15799 (when vhdl-auto-align
15800 (vhdl-goto-marker generic-beg-pos)
15801 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15802 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15803 (vhdl-goto-marker signal-beg-pos)
15804 (vhdl-align-region-groups signal-beg-pos signal-pos))
15805 (switch-to-buffer (marker-buffer signal-beg-pos))
15806 (message "Wiring components...done")))))
15808 (defun vhdl-compose-insert-generic (entry)
15809 "Insert ENTRY as generic declaration."
15811 (indent-to (* 2 vhdl-basic-offset))
15812 (insert (nth 0 entry) " : " (nth 1 entry))
15813 (when (nth 2 entry)
15814 (insert " := " (nth 2 entry)))
15816 (setq pos (point-marker))
15817 (when (and vhdl-include-port-comments (nth 3 entry))
15818 (vhdl-comment-insert-inline (nth 3 entry) t))
15822 (defun vhdl-compose-insert-port (entry)
15823 "Insert ENTRY as port declaration."
15825 (indent-to (* 2 vhdl-basic-offset))
15826 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15827 (setq pos (point-marker))
15828 (when (and vhdl-include-port-comments (nth 4 entry))
15829 (vhdl-comment-insert-inline (nth 4 entry) t))
15833 (defun vhdl-compose-insert-signal (entry)
15834 "Insert ENTRY as signal declaration."
15835 (indent-to vhdl-basic-offset)
15836 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15837 (when (and vhdl-include-port-comments (nth 4 entry))
15838 (vhdl-comment-insert-inline (nth 4 entry) t))
15841 (defun vhdl-compose-components-package ()
15842 "Generate a package containing component declarations for all entities in the
15843 current project/directory."
15845 (vhdl-require-hierarchy-info)
15846 (let* ((project (vhdl-project-p))
15847 (pack-name (vhdl-get-components-package-name))
15849 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15850 "." (file-name-extension (buffer-file-name))))
15851 (ent-alist (aget vhdl-entity-alist
15852 (or project default-directory) t))
15853 (lazy-lock-minimum-size 0)
15854 clause-pos component-pos)
15855 (message "Generating components package \"%s\"..." pack-name)
15856 ;; open package file
15857 (when (and (file-exists-p pack-file-name)
15858 (not (y-or-n-p (concat "File \"" pack-file-name
15859 "\" exists; overwrite? "))))
15860 (error "ERROR: Generating components package...aborted"))
15861 (find-file pack-file-name)
15864 (if vhdl-compose-include-header
15865 (progn (vhdl-template-header
15866 (concat "Components package (generated by Emacs VHDL Mode "
15868 (goto-char (point-max)))
15869 (vhdl-comment-display-line) (insert "\n\n"))
15870 ;; insert std_logic_1164 package
15871 (vhdl-template-package-std-logic-1164)
15872 (insert "\n") (setq clause-pos (point-marker))
15873 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15874 ;; insert package declaration
15875 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15876 (vhdl-insert-keyword " IS\n\n")
15877 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15878 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15879 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15880 (indent-to vhdl-basic-offset)
15881 (setq component-pos (point-marker))
15882 (insert "\n\n") (vhdl-insert-keyword "END ")
15883 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15884 (insert pack-name ";\n\n")
15886 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15887 (vhdl-template-footer)
15888 (vhdl-comment-display-line) (insert "\n"))
15889 ;; insert component declarations
15891 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15892 (progn (goto-char (point-min))
15893 (forward-line (1- (nth 3 (car ent-alist))))
15896 (goto-char component-pos)
15897 (vhdl-port-paste-component t)
15898 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15899 (setq component-pos (point-marker))
15900 (goto-char clause-pos)
15901 (vhdl-port-paste-context-clause pack-name)
15902 (setq clause-pos (point-marker))
15903 (setq ent-alist (cdr ent-alist)))
15904 (goto-char (point-min))
15906 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15907 pack-name pack-file-name)))
15909 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15910 &optional insert-conf)
15911 "Generate block configuration for architecture."
15912 (let ((margin (current-indentation))
15913 (beg (save-excursion (beginning-of-line) (point)))
15914 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15915 ;; insert block configuration (for architecture)
15916 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15917 (setq margin (+ margin vhdl-basic-offset))
15918 ;; process all instances
15920 (setq inst-entry (car inst-alist))
15922 (when (nth 4 inst-entry)
15923 (setq insert-conf t)
15924 (setq inst-path (nth 9 inst-entry))
15925 ;; skip common path with previous instance
15926 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15927 (setq inst-path (cdr inst-path)
15928 inst-prev-path (cdr inst-prev-path)))
15929 ;; insert block configuration end (for previous block/generate)
15930 (while inst-prev-path
15931 (setq margin (- margin vhdl-basic-offset))
15933 (vhdl-insert-keyword "END FOR;\n")
15934 (setq inst-prev-path (cdr inst-prev-path)))
15935 ;; insert block configuration beginning (for current block/generate)
15938 (setq margin (+ margin vhdl-basic-offset))
15939 (vhdl-insert-keyword "FOR ")
15940 (insert (car inst-path) "\n")
15942 (setq inst-path (cdr inst-path)))
15943 ;; insert component configuration beginning
15944 (vhdl-insert-keyword "FOR ")
15945 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15946 ;; find subconfiguration
15947 (setq conf-key (nth 7 inst-entry))
15948 (setq tmp-alist conf-alist)
15949 ;; use first configuration found for instance's entity
15950 (while (and tmp-alist (null conf-key))
15951 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15952 (setq conf-key (nth 0 (car tmp-alist))))
15953 (setq tmp-alist (cdr tmp-alist)))
15954 (setq conf-entry (aget conf-alist conf-key t))
15955 ;; insert binding indication ...
15956 ;; ... with subconfiguration (if exists)
15957 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15959 (indent-to (+ margin vhdl-basic-offset))
15960 (vhdl-insert-keyword "USE CONFIGURATION ")
15961 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15963 ;; ... with entity (if exists)
15964 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15966 (indent-to (+ margin vhdl-basic-offset))
15967 (vhdl-insert-keyword "USE ENTITY ")
15968 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15969 ;; insert architecture name (if architecture exists)
15970 (when (nth 3 ent-entry)
15972 ;; choose architecture name a) from configuration,
15973 ;; b) from mra, or c) from first architecture
15974 (or (nth 0 (aget (nth 3 ent-entry)
15975 (or (nth 6 inst-entry)
15976 (nth 4 ent-entry)) t))
15977 (nth 1 (car (nth 3 ent-entry)))))
15978 (insert "(" arch-name ")"))
15980 ;; insert block configuration (for architecture of subcomponent)
15981 (when (and vhdl-compose-configuration-hierarchical
15983 (indent-to (+ margin vhdl-basic-offset))
15984 (vhdl-compose-configuration-architecture
15985 (nth 0 ent-entry) arch-name
15986 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15987 ;; insert component configuration end
15989 (vhdl-insert-keyword "END FOR;\n")
15990 (setq inst-prev-path (nth 9 inst-entry)))
15991 (setq inst-alist (cdr inst-alist)))
15992 ;; insert block configuration end (for block/generate)
15993 (while inst-prev-path
15994 (setq margin (- margin vhdl-basic-offset))
15996 (vhdl-insert-keyword "END FOR;\n")
15997 (setq inst-prev-path (cdr inst-prev-path)))
15998 (indent-to (- margin vhdl-basic-offset))
15999 ;; insert block configuration end or remove beginning (for architecture)
16001 (vhdl-insert-keyword "END FOR;\n")
16002 (delete-region beg (point)))))
16004 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16005 "Generate configuration declaration."
16007 (vhdl-require-hierarchy-info)
16008 (let ((ent-alist (aget vhdl-entity-alist
16009 (or (vhdl-project-p) default-directory) t))
16010 (conf-alist (aget vhdl-config-alist
16011 (or (vhdl-project-p) default-directory) t))
16012 (from-speedbar ent-name)
16013 inst-alist conf-name conf-file-name pos)
16014 (vhdl-prepare-search-2
16015 ;; get entity and architecture name
16018 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16019 (not (equal "END" (upcase (match-string 1))))
16020 (setq ent-name (match-string-no-properties 3))
16021 (setq arch-name (match-string-no-properties 2)))
16022 (error "ERROR: Not within an architecture"))))
16023 (setq conf-name (vhdl-replace-string
16024 vhdl-compose-configuration-name
16025 (concat ent-name " " arch-name)))
16027 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16028 (downcase arch-name) t))))
16029 (message "Generating configuration \"%s\"..." conf-name)
16030 (if vhdl-compose-configuration-create-file
16031 ;; open configuration file
16033 (setq conf-file-name
16034 (concat (vhdl-replace-string vhdl-configuration-file-name
16036 "." (file-name-extension (buffer-file-name))))
16037 (when (and (file-exists-p conf-file-name)
16038 (not (y-or-n-p (concat "File \"" conf-file-name
16039 "\" exists; overwrite? "))))
16040 (error "ERROR: Creating configuration...aborted"))
16041 (find-file conf-file-name)
16043 (set-buffer-modified-p nil)
16045 (if vhdl-compose-include-header
16046 (progn (vhdl-template-header
16047 (concat "Configuration declaration for design \""
16048 ent-name "(" arch-name ")\""))
16049 (goto-char (point-max)))
16050 (vhdl-comment-display-line) (insert "\n\n")))
16051 ;; goto end of architecture
16052 (unless from-speedbar
16053 (re-search-forward "^end\\>" nil)
16054 (end-of-line) (insert "\n\n")
16055 (vhdl-comment-display-line) (insert "\n\n")))
16056 ;; insert library clause
16058 (vhdl-template-standard-package (vhdl-work-library) nil)
16059 (when (/= pos (point))
16061 ;; insert configuration
16062 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16063 (vhdl-insert-keyword " OF ") (insert ent-name)
16064 (vhdl-insert-keyword " IS\n")
16065 (indent-to vhdl-basic-offset)
16066 ;; insert block configuration (for architecture)
16067 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16068 (vhdl-insert-keyword "END ") (insert conf-name ";")
16069 (when conf-file-name
16070 ;; insert footer and save
16072 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16073 (vhdl-template-footer)
16074 (vhdl-comment-display-line) (insert "\n"))
16077 (concat (format "Generating configuration \"%s\"...done" conf-name)
16078 (and conf-file-name
16079 (format "\n File created: \"%s\"" conf-file-name))))))
16082 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16083 ;;; Compilation / Makefile generation
16084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16085 ;; (using `compile.el')
16087 (defun vhdl-makefile-name ()
16088 "Return the Makefile name of the current project or the current compiler if
16089 no project is defined."
16090 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16091 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16092 (vhdl-replace-string
16093 (cons "\\(.*\\)\n\\(.*\\)"
16094 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16095 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16097 (defun vhdl-compile-directory ()
16098 "Return the directory where compilation/make should be run."
16099 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16100 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16101 (directory (vhdl-resolve-env-variable
16103 (vhdl-replace-string
16104 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16105 (nth 6 compiler)))))
16106 (file-name-as-directory
16107 (if (file-name-absolute-p directory)
16109 (expand-file-name directory (vhdl-default-directory))))))
16111 (defun vhdl-uniquify (in-list)
16112 "Remove duplicate elements from IN-LIST."
16115 (add-to-list 'out-list (car in-list))
16116 (setq in-list (cdr in-list)))
16119 (defun vhdl-set-compiler (name)
16120 "Set current compiler to NAME."
16122 (list (let ((completion-ignore-case t))
16123 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16124 (if (assoc name vhdl-compiler-alist)
16125 (progn (setq vhdl-compiler name)
16126 (message "Current compiler: \"%s\"" vhdl-compiler))
16127 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16132 (defun vhdl-compile-init ()
16133 "Initialize for compilation."
16134 (when (or (null compilation-error-regexp-alist)
16135 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16136 compilation-error-regexp-alist)))
16137 ;; `compilation-error-regexp-alist'
16138 (let ((commands-alist vhdl-compiler-alist)
16139 regexp-alist sublist)
16140 (while commands-alist
16141 (setq sublist (nth 11 (car commands-alist)))
16142 (unless (or (equal "" (car sublist))
16143 (assoc (car sublist) regexp-alist))
16144 (setq regexp-alist (cons (list (nth 0 sublist)
16145 (if (= 0 (nth 1 sublist))
16146 (if (featurep 'xemacs) 9 nil)
16148 (nth 2 sublist) (nth 3 sublist))
16150 (setq commands-alist (cdr commands-alist)))
16151 (setq compilation-error-regexp-alist
16152 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16153 ;; `compilation-file-regexp-alist'
16154 (let ((commands-alist vhdl-compiler-alist)
16155 regexp-alist sublist)
16156 ;; matches vhdl-mode file name output
16157 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16158 (while commands-alist
16159 (setq sublist (nth 12 (car commands-alist)))
16160 (unless (or (equal "" (car sublist))
16161 (assoc (car sublist) regexp-alist))
16162 (setq regexp-alist (cons sublist regexp-alist)))
16163 (setq commands-alist (cdr commands-alist)))
16164 (setq compilation-file-regexp-alist
16165 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16167 (defvar vhdl-compile-file-name nil
16168 "Name of file to be compiled.")
16170 (defun vhdl-compile-print-file-name ()
16171 "Function called within `compile' to print out file name for compilers that
16172 do not print any file names."
16173 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16175 (defun vhdl-get-compile-options (project compiler file-name
16176 &optional file-options-only)
16177 "Get compiler options. Returning nil means do not compile this file."
16178 (let* ((compiler-options (nth 1 compiler))
16179 (project-entry (aget (nth 4 project) vhdl-compiler))
16180 (project-options (nth 0 project-entry))
16181 (exception-list (and file-name (nth 2 project-entry)))
16182 (work-library (vhdl-work-library))
16183 (case-fold-search nil)
16185 (while (and exception-list
16186 (not (string-match (caar exception-list) file-name)))
16187 (setq exception-list (cdr exception-list)))
16188 (if (and exception-list (not (cdar exception-list)))
16190 (if (and file-options-only (not exception-list))
16192 (setq file-options (cdar exception-list))
16193 ;; insert library name in compiler-specific options
16194 (setq compiler-options
16195 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16197 ;; insert compiler-specific options in project-specific options
16198 (when project-options
16199 (setq project-options
16200 (vhdl-replace-string
16201 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16202 (concat work-library "\n" compiler-options))))
16203 ;; insert project-specific options in file-specific options
16206 (vhdl-replace-string
16207 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16208 (concat work-library "\n" compiler-options "\n"
16209 project-options))))
16211 (or file-options project-options compiler-options)))))
16213 (defun vhdl-get-make-options (project compiler)
16214 "Get make options."
16215 (let* ((compiler-options (nth 3 compiler))
16216 (project-entry (aget (nth 4 project) vhdl-compiler))
16217 (project-options (nth 1 project-entry))
16218 (makefile-name (vhdl-makefile-name)))
16219 ;; insert Makefile name in compiler-specific options
16220 (setq compiler-options
16221 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16223 ;; insert compiler-specific options in project-specific options
16224 (when project-options
16225 (setq project-options
16226 (vhdl-replace-string
16227 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16228 (concat makefile-name "\n" compiler-options))))
16230 (or project-options compiler-options)))
16232 (defun vhdl-compile ()
16233 "Compile current buffer using the VHDL compiler specified in
16236 (vhdl-compile-init)
16237 (let* ((project (aget vhdl-project-alist vhdl-project))
16238 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16239 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16240 (command (nth 0 compiler))
16241 (file-name (buffer-file-name))
16242 (options (vhdl-get-compile-options project compiler file-name))
16243 (default-directory (vhdl-compile-directory))
16244 compilation-process-setup-function)
16245 (unless (file-directory-p default-directory)
16246 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16247 ;; put file name into quotes if it contains spaces
16248 (when (string-match " " file-name)
16249 (setq file-name (concat "\"" file-name "\"")))
16250 ;; print out file name if compiler does not
16251 (setq vhdl-compile-file-name (buffer-file-name))
16252 (when (and (= 0 (nth 1 (nth 10 compiler)))
16253 (= 0 (nth 1 (nth 11 compiler))))
16254 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16258 (compile (concat command " " options " " file-name)))
16259 (vhdl-warning "Your project settings tell me not to compile this file"))))
16261 (defvar vhdl-make-target "all"
16262 "Default target for `vhdl-make' command.")
16264 (defun vhdl-make (&optional target)
16265 "Call make command for compilation of all updated source files (requires
16266 `Makefile'). Optional argument TARGET allows to compile the design
16267 specified by a target."
16269 (setq vhdl-make-target
16270 (or target (read-from-minibuffer "Target: " vhdl-make-target
16271 vhdl-minibuffer-local-map)))
16272 (vhdl-compile-init)
16273 (let* ((project (aget vhdl-project-alist vhdl-project))
16274 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16275 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16276 (command (nth 2 compiler))
16277 (options (vhdl-get-make-options project compiler))
16278 (default-directory (vhdl-compile-directory)))
16279 (unless (file-directory-p default-directory)
16280 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16282 (compile (concat (if (equal command "") "make" command)
16283 " " options " " vhdl-make-target))))
16285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16286 ;; Makefile generation
16288 (defun vhdl-generate-makefile ()
16289 "Generate `Makefile'."
16291 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16292 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16293 (command (nth 4 compiler)))
16294 ;; generate makefile
16296 (let ((default-directory (vhdl-compile-directory)))
16297 (compile (vhdl-replace-string
16298 (cons "\\(.*\\) \\(.*\\)" command)
16299 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16300 (vhdl-generate-makefile-1))))
16302 (defun vhdl-get-packages (lib-alist work-library)
16303 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16306 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16307 (setq pack-list (cons (cdar lib-alist) pack-list)))
16308 (setq lib-alist (cdr lib-alist)))
16311 (defun vhdl-generate-makefile-1 ()
16312 "Generate Makefile for current project or directory."
16313 ;; scan hierarchy if required
16314 (if (vhdl-project-p)
16315 (unless (or (assoc vhdl-project vhdl-file-alist)
16316 (vhdl-load-cache vhdl-project))
16317 (vhdl-scan-project-contents vhdl-project))
16318 (let ((directory (abbreviate-file-name default-directory)))
16319 (unless (or (assoc directory vhdl-file-alist)
16320 (vhdl-load-cache directory))
16321 (vhdl-scan-directory-contents directory))))
16322 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16323 (project (vhdl-project-p))
16324 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16325 (conf-alist (aget vhdl-config-alist (or project directory) t))
16326 (pack-alist (aget vhdl-package-alist (or project directory) t))
16327 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16328 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16329 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16330 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16331 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16332 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16333 (adjust-case (nth 5 regexp-list))
16334 (work-library (downcase (vhdl-work-library)))
16335 (compile-directory (expand-file-name (vhdl-compile-directory)
16336 default-directory))
16337 (makefile-name (vhdl-makefile-name))
16338 rule-alist arch-alist inst-alist
16339 target-list depend-list unit-list prim-list second-list subcomp-list
16340 lib-alist lib-body-alist pack-list all-pack-list
16341 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16342 conf-key conf-file-name pack-key pack-file-name
16343 ent-entry arch-entry conf-entry pack-entry inst-entry
16344 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16345 tmp-key tmp-list rule)
16346 ;; check prerequisites
16347 (unless (file-exists-p compile-directory)
16348 (make-directory compile-directory t))
16349 (unless regexp-list
16350 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16352 (message "Generating makefile \"%s\"..." makefile-name)
16353 ;; rules for all entities
16354 (setq tmp-list ent-alist)
16356 (setq ent-entry (car ent-alist)
16357 ent-key (nth 0 ent-entry))
16358 (when (nth 2 ent-entry)
16359 (setq ent-file-name (file-relative-name
16360 (nth 2 ent-entry) compile-directory)
16361 arch-alist (nth 4 ent-entry)
16362 lib-alist (nth 6 ent-entry)
16363 rule (aget rule-alist ent-file-name)
16364 target-list (nth 0 rule)
16365 depend-list (nth 1 rule)
16368 (setq tmp-key (vhdl-replace-string
16369 ent-regexp (funcall adjust-case ent-key)))
16370 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16371 ;; rule target for this entity
16372 (setq target-list (cons ent-key target-list))
16373 ;; rule dependencies for all used packages
16374 (setq pack-list (vhdl-get-packages lib-alist work-library))
16375 (setq depend-list (append depend-list pack-list))
16376 (setq all-pack-list pack-list)
16378 (aput 'rule-alist ent-file-name (list target-list depend-list))
16379 ;; rules for all corresponding architectures
16381 (setq arch-entry (car arch-alist)
16382 arch-key (nth 0 arch-entry)
16383 ent-arch-key (concat ent-key "-" arch-key)
16384 arch-file-name (file-relative-name (nth 2 arch-entry)
16386 inst-alist (nth 4 arch-entry)
16387 lib-alist (nth 5 arch-entry)
16388 rule (aget rule-alist arch-file-name)
16389 target-list (nth 0 rule)
16390 depend-list (nth 1 rule))
16391 (setq tmp-key (vhdl-replace-string
16393 (funcall adjust-case (concat arch-key " " ent-key))))
16395 (cons (cons ent-arch-key tmp-key) unit-list))
16396 (setq second-list (cons ent-arch-key second-list))
16397 ;; rule target for this architecture
16398 (setq target-list (cons ent-arch-key target-list))
16399 ;; rule dependency for corresponding entity
16400 (setq depend-list (cons ent-key depend-list))
16401 ;; rule dependencies for contained component instantiations
16403 (setq inst-entry (car inst-alist))
16404 (when (or (null (nth 8 inst-entry))
16405 (equal (downcase (nth 8 inst-entry)) work-library))
16406 (setq inst-ent-key (or (nth 7 inst-entry)
16407 (nth 5 inst-entry)))
16408 (setq depend-list (cons inst-ent-key depend-list)
16409 subcomp-list (cons inst-ent-key subcomp-list)))
16410 (setq inst-alist (cdr inst-alist)))
16411 ;; rule dependencies for all used packages
16412 (setq pack-list (vhdl-get-packages lib-alist work-library))
16413 (setq depend-list (append depend-list pack-list))
16414 (setq all-pack-list (append all-pack-list pack-list))
16416 (aput 'rule-alist arch-file-name (list target-list depend-list))
16417 (setq arch-alist (cdr arch-alist)))
16418 (setq prim-list (cons (list ent-key second-list
16419 (append subcomp-list all-pack-list))
16421 (setq ent-alist (cdr ent-alist)))
16422 (setq ent-alist tmp-list)
16423 ;; rules for all configurations
16424 (setq tmp-list conf-alist)
16426 (setq conf-entry (car conf-alist)
16427 conf-key (nth 0 conf-entry)
16428 conf-file-name (file-relative-name
16429 (nth 2 conf-entry) compile-directory)
16430 ent-key (nth 4 conf-entry)
16431 arch-key (nth 5 conf-entry)
16432 inst-alist (nth 6 conf-entry)
16433 lib-alist (nth 7 conf-entry)
16434 rule (aget rule-alist conf-file-name)
16435 target-list (nth 0 rule)
16436 depend-list (nth 1 rule)
16437 subcomp-list (list ent-key))
16438 (setq tmp-key (vhdl-replace-string
16439 conf-regexp (funcall adjust-case conf-key)))
16440 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16441 ;; rule target for this configuration
16442 (setq target-list (cons conf-key target-list))
16443 ;; rule dependency for corresponding entity and architecture
16445 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16446 ;; rule dependencies for used packages
16447 (setq pack-list (vhdl-get-packages lib-alist work-library))
16448 (setq depend-list (append depend-list pack-list))
16449 ;; rule dependencies for contained component configurations
16451 (setq inst-entry (car inst-alist))
16452 (setq inst-ent-key (nth 2 inst-entry)
16453 ; comp-arch-key (nth 2 inst-entry))
16454 inst-conf-key (nth 4 inst-entry))
16455 (when (equal (downcase (nth 5 inst-entry)) work-library)
16457 (setq depend-list (cons inst-ent-key depend-list)
16458 subcomp-list (cons inst-ent-key subcomp-list)))
16459 ; (when comp-arch-key
16460 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16462 (when inst-conf-key
16463 (setq depend-list (cons inst-conf-key depend-list)
16464 subcomp-list (cons inst-conf-key subcomp-list))))
16465 (setq inst-alist (cdr inst-alist)))
16467 (aput 'rule-alist conf-file-name (list target-list depend-list))
16468 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16470 (setq conf-alist (cdr conf-alist)))
16471 (setq conf-alist tmp-list)
16472 ;; rules for all packages
16473 (setq tmp-list pack-alist)
16475 (setq pack-entry (car pack-alist)
16476 pack-key (nth 0 pack-entry)
16478 (when (nth 2 pack-entry)
16479 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16481 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16482 rule (aget rule-alist pack-file-name)
16483 target-list (nth 0 rule) depend-list (nth 1 rule))
16484 (setq tmp-key (vhdl-replace-string
16485 pack-regexp (funcall adjust-case pack-key)))
16486 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16487 ;; rule target for this package
16488 (setq target-list (cons pack-key target-list))
16489 ;; rule dependencies for all used packages
16490 (setq pack-list (vhdl-get-packages lib-alist work-library))
16491 (setq depend-list (append depend-list pack-list))
16492 (setq all-pack-list pack-list)
16494 (aput 'rule-alist pack-file-name (list target-list depend-list))
16495 ;; rules for this package's body
16496 (when (nth 7 pack-entry)
16497 (setq pack-body-key (concat pack-key "-body")
16498 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16500 rule (aget rule-alist pack-body-file-name)
16501 target-list (nth 0 rule)
16502 depend-list (nth 1 rule))
16503 (setq tmp-key (vhdl-replace-string
16504 pack-body-regexp (funcall adjust-case pack-key)))
16506 (cons (cons pack-body-key tmp-key) unit-list))
16507 ;; rule target for this package's body
16508 (setq target-list (cons pack-body-key target-list))
16509 ;; rule dependency for corresponding package declaration
16510 (setq depend-list (cons pack-key depend-list))
16511 ;; rule dependencies for all used packages
16512 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16513 (setq depend-list (append depend-list pack-list))
16514 (setq all-pack-list (append all-pack-list pack-list))
16516 (aput 'rule-alist pack-body-file-name
16517 (list target-list depend-list)))
16519 (cons (list pack-key (when pack-body-key (list pack-body-key))
16522 (setq pack-alist (cdr pack-alist)))
16523 (setq pack-alist tmp-list)
16524 ;; generate Makefile
16525 (let* ((project (aget vhdl-project-alist project))
16526 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16527 (compiler-id (nth 9 compiler))
16529 (vhdl-resolve-env-variable
16530 (vhdl-replace-string
16531 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16533 (makefile-path-name (expand-file-name
16534 makefile-name compile-directory))
16535 (orig-buffer (current-buffer))
16536 cell second-list subcomp-list options unit-key unit-name)
16538 (setq unit-list (vhdl-sort-alist unit-list))
16539 (setq prim-list (vhdl-sort-alist prim-list))
16540 (setq tmp-list rule-alist)
16541 (while tmp-list ; pre-sort rule targets
16542 (setq cell (cdar tmp-list))
16543 (setcar cell (sort (car cell) 'string<))
16544 (setq tmp-list (cdr tmp-list)))
16545 (setq rule-alist ; sort by first rule target
16547 (function (lambda (a b)
16548 (string< (car (cadr a)) (car (cadr b)))))))
16549 ;; open and clear Makefile
16550 (set-buffer (find-file-noselect makefile-path-name t t))
16552 (insert "# -*- Makefile -*-\n"
16553 "### " (file-name-nondirectory makefile-name)
16554 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16557 (insert "\n# Project : " (nth 0 project))
16558 (insert "\n# Directory : \"" directory "\""))
16559 (insert "\n# Platform : " vhdl-compiler
16560 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16561 (user-login-name) "\n")
16562 ;; insert compile and option variable settings
16563 (insert "\n\n# Define compilation command and options\n"
16564 "\nCOMPILE = " (nth 0 compiler)
16565 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16567 ;; insert library paths
16568 (setq library-directory
16569 (directory-file-name
16570 (if (file-name-absolute-p library-directory)
16572 (file-relative-name
16573 (expand-file-name library-directory directory)
16574 compile-directory))))
16575 (insert "\n\n# Define library paths\n"
16576 "\nLIBRARY-" work-library " = " library-directory "\n")
16577 ;; insert variable definitions for all library unit files
16578 (insert "\n\n# Define library unit files\n")
16579 (setq tmp-list unit-list)
16581 (insert "\nUNIT-" work-library "-" (caar unit-list)
16582 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16583 (setq unit-list (cdr unit-list)))
16584 ;; insert variable definition for list of all library unit files
16585 (insert "\n\n\n# Define list of all library unit files\n"
16587 (setq unit-list tmp-list)
16589 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16590 (setq unit-list (cdr unit-list)))
16592 (setq unit-list tmp-list)
16593 ;; insert `make all' rule
16594 (insert "\n\n\n# Rule for compiling entire design\n"
16597 " \\\n\t\t$(ALL_UNITS)\n")
16598 ;; insert `make clean' rule
16599 (insert "\n\n# Rule for cleaning entire design\n"
16601 "\n\t-rm -f $(ALL_UNITS)\n")
16602 ;; insert `make library' rule
16603 (insert "\n\n# Rule for creating library directory\n"
16605 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16606 "\n$(LIBRARY-" work-library ") :"
16608 (vhdl-replace-string
16609 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16610 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16612 ;; insert rule for each library unit
16613 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16615 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16617 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16618 (setq unit-key (caar prim-list)
16619 unit-name (or (nth 0 (aget ent-alist unit-key t))
16620 (nth 0 (aget conf-alist unit-key t))
16621 (nth 0 (aget pack-alist unit-key t))))
16622 (insert "\n" unit-key)
16623 (unless (equal unit-key unit-name)
16624 (insert " \\\n" unit-name))
16627 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16629 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16630 (setq second-list (cdr second-list)))
16631 (while subcomp-list
16632 (when (and (assoc (car subcomp-list) unit-list)
16633 (not (equal unit-key (car subcomp-list))))
16634 (insert " \\\n\t\t" (car subcomp-list)))
16635 (setq subcomp-list (cdr subcomp-list)))
16637 (setq prim-list (cdr prim-list)))
16638 ;; insert rule for each library unit file
16639 (insert "\n\n# Rules for compiling single library unit files\n")
16641 (setq rule (car rule-alist))
16642 ;; get compiler options for this file
16644 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16645 ;; insert rule if file is supposed to be compiled
16646 (setq target-list (nth 1 rule)
16647 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16649 (setq tmp-list target-list)
16651 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16652 (if (cdr target-list) " \\" " :"))
16653 (setq target-list (cdr target-list)))
16654 (setq target-list tmp-list)
16655 ;; insert file name as first dependency
16656 (insert " \\\n\t\t" (nth 0 rule))
16657 ;; insert dependencies (except if also target or unit does not exist)
16659 (when (and (not (member (car depend-list) target-list))
16660 (assoc (car depend-list) unit-list))
16661 (insert " \\\n\t\t"
16662 "$(UNIT-" work-library "-" (car depend-list) ")"))
16663 (setq depend-list (cdr depend-list)))
16664 ;; insert compile command
16666 (insert "\n\t$(COMPILE) "
16667 (if (eq options 'default) "$(OPTIONS)" options) " "
16669 (setq tmp-list target-list)
16671 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16672 (if (cdr target-list) " \\" "\n"))
16673 (setq target-list (cdr target-list)))
16674 (setq target-list tmp-list))
16675 (setq rule-alist (cdr rule-alist)))
16676 (insert "\n\n### " makefile-name " ends here\n")
16677 ;; run Makefile generation hook
16678 (run-hooks 'vhdl-makefile-generation-hook)
16679 (message "Generating makefile \"%s\"...done" makefile-name)
16680 ;; save and close file
16681 (if (file-writable-p makefile-path-name)
16682 (progn (save-buffer)
16683 (kill-buffer (current-buffer))
16684 (set-buffer orig-buffer)
16685 (add-to-history 'file-name-history makefile-path-name))
16686 (vhdl-warning-when-idle
16687 (format "File not writable: \"%s\""
16688 (abbreviate-file-name makefile-path-name)))
16689 (switch-to-buffer (current-buffer))))))
16692 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16695 ;; (using `reporter.el')
16697 (defconst vhdl-mode-help-address
16698 "Reto Zimmermann <reto@gnu.org>"
16699 "Address for VHDL Mode bug reports.")
16701 (defun vhdl-submit-bug-report ()
16702 "Submit via mail a bug report on VHDL Mode."
16704 ;; load in reporter
16706 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16707 (let ((reporter-prompt-for-summary-p t))
16708 (reporter-submit-bug-report
16709 vhdl-mode-help-address
16710 (concat "VHDL Mode " vhdl-version)
16712 ;; report all important user options
16713 'vhdl-offsets-alist
16714 'vhdl-comment-only-line-offset
16716 'vhdl-electric-mode
16718 'vhdl-indent-tabs-mode
16719 'vhdl-project-alist
16721 'vhdl-project-file-name
16722 'vhdl-project-auto-load
16724 'vhdl-compiler-alist
16726 'vhdl-compile-use-local-error-regexp
16727 'vhdl-makefile-generation-hook
16728 'vhdl-default-library
16731 'vhdl-upper-case-keywords
16732 'vhdl-upper-case-types
16733 'vhdl-upper-case-attributes
16734 'vhdl-upper-case-enum-values
16735 'vhdl-upper-case-constants
16736 'vhdl-use-direct-instantiation
16737 'vhdl-compose-configuration-name
16738 'vhdl-entity-file-name
16739 'vhdl-architecture-file-name
16740 'vhdl-configuration-file-name
16741 'vhdl-package-file-name
16742 'vhdl-file-name-case
16743 'vhdl-electric-keywords
16744 'vhdl-optional-labels
16745 'vhdl-insert-empty-lines
16746 'vhdl-argument-list-indent
16747 'vhdl-association-list-with-formals
16748 'vhdl-conditions-in-parenthesis
16754 'vhdl-copyright-string
16755 'vhdl-platform-spec
16757 'vhdl-modify-date-prefix-string
16758 'vhdl-modify-date-on-saving
16760 'vhdl-reset-active-high
16761 'vhdl-clock-rising-edge
16762 'vhdl-clock-edge-condition
16766 'vhdl-include-port-comments
16767 'vhdl-include-direction-comments
16768 'vhdl-include-type-comments
16769 'vhdl-include-group-comments
16770 'vhdl-actual-port-name
16771 'vhdl-instance-name
16772 'vhdl-testbench-entity-name
16773 'vhdl-testbench-architecture-name
16774 'vhdl-testbench-configuration-name
16775 'vhdl-testbench-dut-name
16776 'vhdl-testbench-include-header
16777 'vhdl-testbench-declarations
16778 'vhdl-testbench-statements
16779 'vhdl-testbench-initialize-signals
16780 'vhdl-testbench-include-library
16781 'vhdl-testbench-include-configuration
16782 'vhdl-testbench-create-files
16783 'vhdl-testbench-entity-file-name
16784 'vhdl-testbench-architecture-file-name
16785 'vhdl-compose-create-files
16786 'vhdl-compose-configuration-create-file
16787 'vhdl-compose-configuration-hierarchical
16788 'vhdl-compose-configuration-use-subconfiguration
16789 'vhdl-compose-include-header
16790 'vhdl-compose-architecture-name
16791 'vhdl-components-package-name
16792 'vhdl-use-components-package
16793 'vhdl-self-insert-comments
16794 'vhdl-prompt-for-comments
16795 'vhdl-inline-comment-column
16796 'vhdl-end-comment-column
16799 'vhdl-align-group-separate
16800 'vhdl-align-same-indent
16801 'vhdl-highlight-keywords
16802 'vhdl-highlight-names
16803 'vhdl-highlight-special-words
16804 'vhdl-highlight-forbidden-words
16805 'vhdl-highlight-verilog-keywords
16806 'vhdl-highlight-translate-off
16807 'vhdl-highlight-case-sensitive
16808 'vhdl-special-syntax-alist
16809 'vhdl-forbidden-words
16810 'vhdl-forbidden-syntax
16811 'vhdl-directive-keywords
16812 'vhdl-speedbar-auto-open
16813 'vhdl-speedbar-display-mode
16814 'vhdl-speedbar-scan-limit
16815 'vhdl-speedbar-jump-to-unit
16816 'vhdl-speedbar-update-on-saving
16817 'vhdl-speedbar-save-cache
16818 'vhdl-speedbar-cache-file-name
16820 'vhdl-source-file-menu
16821 'vhdl-hideshow-menu
16822 'vhdl-hide-all-init
16823 'vhdl-print-two-column
16824 'vhdl-print-customize-faces
16825 'vhdl-intelligent-tab
16826 'vhdl-indent-syntax-based
16827 'vhdl-word-completion-case-sensitive
16828 'vhdl-word-completion-in-minibuffer
16829 'vhdl-underscore-is-part-of-word
16834 (if vhdl-special-indent-hook
16835 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16836 "vhdl-special-indent-hook is set to '"
16837 (format "%s" vhdl-special-indent-hook)
16838 ".\nPerhaps this is your problem?\n"
16839 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16847 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16849 (defconst vhdl-doc-release-notes nil
16851 Release Notes for VHDL Mode 3.33
16852 ================================
16861 CONFIGURATION DECLARATION GENERATION:
16862 - Automatic generation of a configuration declaration for a design.
16863 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16869 `vhdl-configuration-file-name': (new)
16870 Specify how the configuration file name is obtained.
16871 `vhdl-compose-configuration-name': (new)
16872 Specify how the configuration name is optained.
16873 `vhdl-compose-configuration-create-file': (new)
16874 Specify whether a new file should be created for a configuration.
16875 `vhdl-compose-configuration-hierarchical': (new)
16876 Specify whether hierarchical configurations should be created.
16877 `vhdl-compose-configuration-use-subconfiguration': (new)
16878 Specify whether subconfigurations should be used inside configurations.
16882 (defconst vhdl-doc-keywords nil
16884 Reserved words in VHDL
16885 ----------------------
16887 VHDL'93 (IEEE Std 1076-1993):
16888 `vhdl-93-keywords' : keywords
16889 `vhdl-93-types' : standardized types
16890 `vhdl-93-attributes' : standardized attributes
16891 `vhdl-93-enum-values' : standardized enumeration values
16892 `vhdl-93-functions' : standardized functions
16893 `vhdl-93-packages' : standardized packages and libraries
16895 VHDL-AMS (IEEE Std 1076.1):
16896 `vhdl-ams-keywords' : keywords
16897 `vhdl-ams-types' : standardized types
16898 `vhdl-ams-attributes' : standardized attributes
16899 `vhdl-ams-enum-values' : standardized enumeration values
16900 `vhdl-ams-functions' : standardized functions
16902 Math Packages (IEEE Std 1076.2):
16903 `vhdl-math-types' : standardized types
16904 `vhdl-math-constants' : standardized constants
16905 `vhdl-math-functions' : standardized functions
16906 `vhdl-math-packages' : standardized packages
16909 `vhdl-verilog-keywords' : Verilog reserved words
16911 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16914 (defconst vhdl-doc-coding-style nil
16916 For VHDL coding style and naming convention guidelines, see the following
16920 \"VHDL Coding Styles and Methodologies\".
16921 Kluwer Academic Publishers, 1999.
16922 http://members.aol.com/vhdlcohen/vhdl/
16924 \[2] Michael Keating and Pierre Bricaud.
16925 \"Reuse Methodology Manual, Second Edition\".
16926 Kluwer Academic Publishers, 1999.
16927 http://www.openmore.com/openmore/rmm2.html
16929 \[3] European Space Agency.
16930 \"VHDL Modelling Guidelines\".
16931 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16933 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16934 to visually support naming conventions.")
16937 (defun vhdl-version ()
16938 "Echo the current version of VHDL Mode in the minibuffer."
16940 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16941 (vhdl-keep-region-active))
16943 (defun vhdl-doc-variable (variable)
16944 "Display VARIABLE's documentation in *Help* buffer."
16946 (unless (featurep 'xemacs)
16947 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16948 (with-output-to-temp-buffer
16949 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16950 (princ (documentation-property variable 'variable-documentation))
16951 (with-current-buffer standard-output
16953 (help-print-return-message)))
16955 (defun vhdl-doc-mode ()
16956 "Display VHDL Mode documentation in *Help* buffer."
16958 (unless (featurep 'xemacs)
16959 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16960 (with-output-to-temp-buffer
16961 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16964 (princ (documentation 'vhdl-mode))
16965 (with-current-buffer standard-output
16967 (help-print-return-message)))
16970 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16972 (provide 'vhdl-mode)
16974 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
16975 ;;; vhdl-mode.el ends here