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 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4698 (set (make-local-variable 'syntax-propertize-function)
4699 (syntax-propertize-rules
4700 ;; Mark single quotes as having string quote syntax in
4702 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4703 (set (make-local-variable 'font-lock-syntactic-keywords)
4704 vhdl-font-lock-syntactic-keywords))
4705 (unless vhdl-emacs-21
4706 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4707 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4708 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4709 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4710 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4711 ; (turn-on-font-lock)
4713 ;; variables for source file compilation
4714 (when vhdl-compile-use-local-error-regexp
4715 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4716 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4719 (vhdl-index-menu-init)
4720 ;; add source file menu
4721 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4723 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4724 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4725 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4726 ;; initialize hideshow and add menu
4727 (vhdl-hideshow-init)
4728 (run-hooks 'menu-bar-update-hook)
4731 (vhdl-ps-print-init)
4732 (vhdl-write-file-hooks-init)
4733 (message "VHDL Mode %s.%s" vhdl-version
4734 (if noninteractive "" " See menu for documentation and release notes."))
4738 (run-mode-hooks 'vhdl-mode-hook)
4739 (run-hooks 'vhdl-mode-hook)))
4741 (defun vhdl-activate-customizations ()
4742 "Activate all customizations on local variables."
4744 (vhdl-mode-map-init)
4745 (use-local-map vhdl-mode-map)
4746 (set-syntax-table vhdl-mode-syntax-table)
4747 (setq comment-column vhdl-inline-comment-column)
4748 (setq end-comment-column vhdl-end-comment-column)
4749 (vhdl-write-file-hooks-init)
4750 (vhdl-update-mode-menu)
4751 (vhdl-hideshow-init)
4752 (run-hooks 'menu-bar-update-hook))
4754 (defun vhdl-write-file-hooks-init ()
4755 "Add/remove hooks when buffer is saved."
4756 (if vhdl-modify-date-on-saving
4757 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4758 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4759 (make-local-variable 'after-save-hook)
4760 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4762 (defun vhdl-process-command-line-option (option)
4763 "Process command line options for VHDL Mode."
4766 ((equal option "-compiler")
4767 (vhdl-set-compiler (car command-line-args-left))
4768 (setq command-line-args-left (cdr command-line-args-left)))
4770 ((equal option "-project")
4771 (vhdl-set-project (car command-line-args-left))
4772 (setq command-line-args-left (cdr command-line-args-left)))))
4774 ;; make Emacs process VHDL Mode options
4775 (setq command-switch-alist
4776 (append command-switch-alist
4777 '(("-compiler" . vhdl-process-command-line-option)
4778 ("-project" . vhdl-process-command-line-option))))
4781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4782 ;;; Keywords and standardized words
4783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4785 (defconst vhdl-93-keywords
4787 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4788 "assert" "attribute"
4789 "begin" "block" "body" "buffer" "bus"
4790 "case" "component" "configuration" "constant"
4791 "disconnect" "downto"
4792 "else" "elsif" "end" "entity" "exit"
4793 "file" "for" "function"
4794 "generate" "generic" "group" "guarded"
4795 "if" "impure" "in" "inertial" "inout" "is"
4796 "label" "library" "linkage" "literal" "loop"
4798 "nand" "new" "next" "nor" "not" "null"
4799 "of" "on" "open" "or" "others" "out"
4800 "package" "port" "postponed" "procedure" "process" "pure"
4801 "range" "record" "register" "reject" "rem" "report" "return"
4803 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4804 "then" "to" "transport" "type"
4805 "unaffected" "units" "until" "use"
4807 "wait" "when" "while" "with"
4810 "List of VHDL'93 keywords.")
4812 (defconst vhdl-ams-keywords
4814 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4815 "reference" "spectrum" "subnature" "terminal" "through"
4818 "List of VHDL-AMS keywords.")
4820 (defconst vhdl-verilog-keywords
4822 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4823 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4824 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4825 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4826 "endprimitive" "endspecify" "endtable" "endtask" "event"
4827 "for" "force" "forever" "fork" "function"
4828 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4829 "macromodule" "makefile" "medium" "module"
4830 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4831 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4833 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4834 "rtranif0" "rtranif1"
4835 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4836 "strong1" "supply" "supply0" "supply1"
4837 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4838 "triand" "trior" "trireg"
4839 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4841 "List of Verilog keywords as candidate for additional reserved words.")
4843 (defconst vhdl-93-types
4845 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4846 "real" "time" "natural" "positive" "string" "line" "text" "side"
4847 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4848 "std_logic" "std_logic_vector"
4849 "std_ulogic" "std_ulogic_vector"
4851 "List of VHDL'93 standardized types.")
4853 (defconst vhdl-ams-types
4855 "domain_type" "real_vector"
4856 ;; from `nature_pkg' package
4857 "voltage" "current" "electrical" "position" "velocity" "force"
4858 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4859 "pressure" "flowrate" "fluid"
4861 "List of VHDL-AMS standardized types.")
4863 (defconst vhdl-math-types
4865 "complex" "complex_polar"
4867 "List of Math Packages standardized types.")
4869 (defconst vhdl-93-attributes
4871 "base" "left" "right" "high" "low" "pos" "val" "succ"
4872 "pred" "leftof" "rightof" "range" "reverse_range"
4873 "length" "delayed" "stable" "quiet" "transaction"
4874 "event" "active" "last_event" "last_active" "last_value"
4875 "driving" "driving_value" "ascending" "value" "image"
4876 "simple_name" "instance_name" "path_name"
4879 "List of VHDL'93 standardized attributes.")
4881 (defconst vhdl-ams-attributes
4884 "reference" "contribution" "tolerance"
4885 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4888 "List of VHDL-AMS standardized attributes.")
4890 (defconst vhdl-93-enum-values
4893 "note" "warning" "error" "failure"
4894 "read_mode" "write_mode" "append_mode"
4895 "open_ok" "status_error" "name_error" "mode_error"
4896 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4899 "List of VHDL'93 standardized enumeration values.")
4901 (defconst vhdl-ams-enum-values
4903 "quiescent_domain" "time_domain" "frequency_domain"
4904 ;; from `nature_pkg' package
4905 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4907 "List of VHDL-AMS standardized enumeration values.")
4909 (defconst vhdl-math-constants
4911 "math_e" "math_1_over_e"
4912 "math_pi" "math_two_pi" "math_1_over_pi"
4913 "math_half_pi" "math_q_pi" "math_3_half_pi"
4914 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4915 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4916 "math_deg_to_rad" "math_rad_to_deg"
4917 "cbase_1" "cbase_j" "czero"
4919 "List of Math Packages standardized constants.")
4921 (defconst vhdl-93-functions
4923 "now" "resolved" "rising_edge" "falling_edge"
4924 "read" "readline" "write" "writeline" "endfile"
4925 "resize" "is_X" "std_match"
4926 "shift_left" "shift_right" "rotate_left" "rotate_right"
4927 "to_unsigned" "to_signed" "to_integer"
4928 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4929 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4930 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4931 "shl" "shr" "ext" "sxt"
4934 "List of VHDL'93 standardized functions.")
4936 (defconst vhdl-ams-functions
4940 "List of VHDL-AMS standardized functions.")
4942 (defconst vhdl-math-functions
4944 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4945 "sqrt" "cbrt" "exp" "log"
4946 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4947 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4948 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4950 "List of Math Packages standardized functions.")
4952 (defconst vhdl-93-packages
4954 "std_logic_1164" "numeric_std" "numeric_bit"
4956 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4957 "std_logic_misc" "std_logic_textio"
4960 "List of VHDL'93 standardized packages and libraries.")
4962 (defconst vhdl-ams-packages
4964 ;; from `nature_pkg' package
4967 "List of VHDL-AMS standardized packages and libraries.")
4969 (defconst vhdl-math-packages
4971 "math_real" "math_complex"
4973 "List of Math Packages standardized packages and libraries.")
4975 (defvar vhdl-keywords nil
4976 "List of VHDL keywords.")
4978 (defvar vhdl-types nil
4979 "List of VHDL standardized types.")
4981 (defvar vhdl-attributes nil
4982 "List of VHDL standardized attributes.")
4984 (defvar vhdl-enum-values nil
4985 "List of VHDL standardized enumeration values.")
4987 (defvar vhdl-constants nil
4988 "List of VHDL standardized constants.")
4990 (defvar vhdl-functions nil
4991 "List of VHDL standardized functions.")
4993 (defvar vhdl-packages nil
4994 "List of VHDL standardized packages and libraries.")
4996 (defvar vhdl-reserved-words nil
4997 "List of additional reserved words.")
4999 (defvar vhdl-keywords-regexp nil
5000 "Regexp for VHDL keywords.")
5002 (defvar vhdl-types-regexp nil
5003 "Regexp for VHDL standardized types.")
5005 (defvar vhdl-attributes-regexp nil
5006 "Regexp for VHDL standardized attributes.")
5008 (defvar vhdl-enum-values-regexp nil
5009 "Regexp for VHDL standardized enumeration values.")
5011 (defvar vhdl-functions-regexp nil
5012 "Regexp for VHDL standardized functions.")
5014 (defvar vhdl-packages-regexp nil
5015 "Regexp for VHDL standardized packages and libraries.")
5017 (defvar vhdl-reserved-words-regexp nil
5018 "Regexp for additional reserved words.")
5020 (defvar vhdl-directive-keywords-regexp nil
5021 "Regexp for compiler directive keywords.")
5023 (defun vhdl-words-init ()
5024 "Initialize reserved words."
5026 (append vhdl-93-keywords
5027 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5029 (append vhdl-93-types
5030 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5031 (when (vhdl-standard-p 'math) vhdl-math-types)))
5032 (setq vhdl-attributes
5033 (append vhdl-93-attributes
5034 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5035 (setq vhdl-enum-values
5036 (append vhdl-93-enum-values
5037 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5038 (setq vhdl-constants
5039 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5040 (setq vhdl-functions
5041 (append vhdl-93-functions
5042 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5043 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5045 (append vhdl-93-packages
5046 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5047 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5048 (setq vhdl-reserved-words
5049 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5050 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5052 (setq vhdl-keywords-regexp
5053 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5054 (setq vhdl-types-regexp
5055 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5056 (setq vhdl-attributes-regexp
5057 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5058 (setq vhdl-enum-values-regexp
5059 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5060 (setq vhdl-functions-regexp
5061 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5062 (setq vhdl-packages-regexp
5063 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5064 (setq vhdl-reserved-words-regexp
5066 (unless (equal vhdl-forbidden-syntax "")
5067 (concat vhdl-forbidden-syntax "\\|"))
5068 (regexp-opt vhdl-reserved-words)
5070 (setq vhdl-directive-keywords-regexp
5071 (concat "\\<\\(" (mapconcat 'regexp-quote
5072 vhdl-directive-keywords "\\|") "\\)\\>"))
5073 (vhdl-abbrev-list-init))
5075 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5078 (defvar vhdl-abbrev-list nil
5079 "Predefined abbreviations for VHDL.")
5081 (defun vhdl-abbrev-list-init ()
5082 (setq vhdl-abbrev-list
5084 (list vhdl-upper-case-keywords) vhdl-keywords
5085 (list vhdl-upper-case-types) vhdl-types
5086 (list vhdl-upper-case-attributes) vhdl-attributes
5087 (list vhdl-upper-case-enum-values) vhdl-enum-values
5088 (list vhdl-upper-case-constants) vhdl-constants
5089 (list nil) vhdl-functions
5090 (list nil) vhdl-packages)))
5092 ;; initialize reserved words for VHDL Mode
5096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5098 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5103 ;; constant regular expressions for looking at various constructs
5105 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5106 "Regexp describing a VHDL symbol.
5107 We cannot use just `word' syntax class since `_' cannot be in word
5108 class. Putting underscore in word class breaks forward word movement
5109 behavior that users are familiar with.")
5111 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5112 "Regexp describing a case statement header key.")
5114 (defconst vhdl-label-key
5115 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5116 "Regexp describing a VHDL label.")
5118 ;; Macro definitions:
5120 (defmacro vhdl-point (position)
5121 "Return the value of point at certain commonly referenced POSITIONs.
5122 POSITION can be one of the following symbols:
5124 bol -- beginning of line
5126 bod -- beginning of defun
5127 boi -- back to indentation
5128 eoi -- last whitespace on line
5129 ionl -- indentation of next line
5130 iopl -- indentation of previous line
5131 bonl -- beginning of next line
5132 bopl -- beginning of previous line
5134 This function does not modify point or mark."
5135 (or (and (eq 'quote (car-safe position))
5136 (null (cddr position)))
5137 (error "ERROR: Bad buffer position requested: %s" position))
5138 (setq position (nth 1 position))
5139 `(let ((here (point)))
5141 ((eq position 'bol) '((beginning-of-line)))
5142 ((eq position 'eol) '((end-of-line)))
5143 ((eq position 'bod) '((save-match-data
5144 (vhdl-beginning-of-defun))))
5145 ((eq position 'boi) '((back-to-indentation)))
5146 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5147 ((eq position 'bonl) '((forward-line 1)))
5148 ((eq position 'bopl) '((forward-line -1)))
5149 ((eq position 'iopl)
5151 (back-to-indentation)))
5152 ((eq position 'ionl)
5154 (back-to-indentation)))
5155 (t (error "ERROR: Unknown buffer position requested: %s" position))
5160 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5161 ;; doesn't hurt for v19
5165 (defmacro vhdl-safe (&rest body)
5166 "Safely execute BODY, return nil if an error occurred."
5167 `(condition-case nil
5171 (defmacro vhdl-add-syntax (symbol &optional relpos)
5172 "A simple macro to append the syntax in SYMBOL to the syntax list.
5173 Try to increase performance by using this macro."
5174 `(setq vhdl-syntactic-context
5175 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5177 (defmacro vhdl-has-syntax (symbol)
5178 "A simple macro to return check the syntax list.
5179 Try to increase performance by using this macro."
5180 `(assoc ,symbol vhdl-syntactic-context))
5182 ;; Syntactic element offset manipulation:
5184 (defun vhdl-read-offset (langelem)
5185 "Read new offset value for LANGELEM from minibuffer.
5186 Return a valid value only."
5187 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5188 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5190 offset input interned)
5192 (setq input (read-string prompt oldoff)
5193 offset (cond ((string-equal "+" input) '+)
5194 ((string-equal "-" input) '-)
5195 ((string-equal "++" input) '++)
5196 ((string-equal "--" input) '--)
5197 ((string-match "^-?[0-9]+$" input)
5198 (string-to-number input))
5199 ((fboundp (setq interned (intern input)))
5201 ((boundp interned) interned)
5202 ;; error, but don't signal one, keep trying
5203 ;; to read an input value
5205 (setq prompt errmsg)
5209 (defun vhdl-set-offset (symbol offset &optional add-p)
5210 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5211 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5212 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5213 `vhdl-offsets-alist' if it doesn't already appear there."
5216 (intern (completing-read
5217 (concat "Syntactic symbol to change"
5218 (if current-prefix-arg " or add" "")
5223 (cons (format "%s" (car langelem)) nil)))
5225 nil (not current-prefix-arg)
5226 ;; initial contents tries to be the last element
5227 ;; on the syntactic analysis list for the current
5229 (let* ((syntax (vhdl-get-syntactic-context))
5230 (len (length syntax))
5231 (ic (format "%s" (car (nth (1- len) syntax)))))
5234 (offset (vhdl-read-offset langelem)))
5235 (list langelem offset current-prefix-arg)))
5236 ;; sanity check offset
5244 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5246 (let ((entry (assq symbol vhdl-offsets-alist)))
5248 (setcdr entry offset)
5250 (setq vhdl-offsets-alist
5251 (cons (cons symbol offset) vhdl-offsets-alist))
5252 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5253 (vhdl-keep-region-active))
5255 (defun vhdl-set-style (style &optional local)
5256 "Set `vhdl-mode' variables to use one of several different indentation styles.
5257 STYLE is a string representing the desired style and optional LOCAL is
5258 a flag which, if non-nil, means to make the style variables being
5259 changed buffer local, instead of the default, which is to set the
5260 global variables. Interactively, the flag comes from the prefix
5261 argument. The styles are chosen from the `vhdl-style-alist' variable."
5262 (interactive (list (completing-read "Use which VHDL indentation style? "
5263 vhdl-style-alist nil t)
5264 current-prefix-arg))
5265 (let ((vars (cdr (assoc style vhdl-style-alist))))
5267 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5268 ;; set all the variables
5272 (let ((var (car varentry))
5273 (val (cdr varentry)))
5275 (make-local-variable var))
5276 ;; special case for vhdl-offsets-alist
5277 (if (not (eq var 'vhdl-offsets-alist))
5279 ;; reset vhdl-offsets-alist to the default value first
5280 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5281 ;; now set the langelems that are different
5285 (let ((langelem (car langentry))
5286 (offset (cdr langentry)))
5287 (vhdl-set-offset langelem offset)
5292 (vhdl-keep-region-active))
5294 (defun vhdl-get-offset (langelem)
5295 "Get offset from LANGELEM which is a cons cell of the form:
5296 \(SYMBOL . RELPOS). The symbol is matched against
5297 vhdl-offsets-alist and the offset found there is either returned,
5298 or added to the indentation at RELPOS. If RELPOS is nil, then
5299 the offset is simply returned."
5300 (let* ((symbol (car langelem))
5301 (relpos (cdr langelem))
5302 (match (assq symbol vhdl-offsets-alist))
5303 (offset (cdr-safe match)))
5304 ;; offset can be a number, a function, a variable, or one of the
5308 (if vhdl-strict-syntax-p
5309 (error "ERROR: Don't know how to indent a %s" symbol)
5312 ((eq offset '+) (setq offset vhdl-basic-offset))
5313 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5314 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5315 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5316 ((and (not (numberp offset))
5318 (setq offset (funcall offset langelem)))
5319 ((not (numberp offset))
5320 (setq offset (eval offset)))
5323 (< relpos (vhdl-point 'bol)))
5330 ;; Syntactic support functions:
5332 (defun vhdl-in-comment-p ()
5333 "Check if point is in a comment."
5334 (eq (vhdl-in-literal) 'comment))
5336 (defun vhdl-in-string-p ()
5337 "Check if point is in a string."
5338 (eq (vhdl-in-literal) 'string))
5340 (defun vhdl-in-literal ()
5341 "Determine if point is in a VHDL literal."
5343 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5345 ((nth 3 state) 'string)
5346 ((nth 4 state) 'comment)
5347 ((vhdl-beginning-of-macro) 'pound)
5350 (defun vhdl-forward-comment (&optional direction)
5351 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5352 negative, skip forward otherwise."
5354 (if (and direction (< direction 0))
5357 (skip-chars-backward " \t\n")
5358 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5359 (goto-char (match-beginning 3))
5360 (skip-chars-backward " \t\n")))
5362 (skip-chars-forward " \t\n")
5363 (while (looking-at "--.*")
5364 (goto-char (match-end 0))
5365 (skip-chars-forward " \t\n"))))
5367 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5368 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5369 (defalias 'vhdl-forward-comment 'forward-comment))
5371 ;; This is the best we can do in Win-Emacs.
5372 (defun vhdl-win-il (&optional lim)
5373 "Determine if point is in a VHDL literal."
5375 (let* ((here (point))
5378 (lim (or lim (vhdl-point 'bod))))
5380 (while (< (point) here)
5382 (and (re-search-forward "--\\|[\"']"
5384 (buffer-substring (match-beginning 0) (match-end 0))))
5389 ;; looking at the opening of a VHDL style comment
5390 ((string= "--" match)
5391 (if (<= here (progn (end-of-line) (point))) 'comment))
5392 ;; looking at the opening of a double quote string
5393 ((string= "\"" match)
5394 (if (not (save-restriction
5395 ;; this seems to be necessary since the
5396 ;; re-search-forward will not work without it
5397 (narrow-to-region (point) here)
5399 ;; this regexp matches a double quote
5400 ;; which is preceded by an even number
5401 ;; of backslashes, including zero
5402 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5404 ;; looking at the opening of a single quote string
5405 ((string= "'" match)
5406 (if (not (save-restriction
5407 ;; see comments from above
5408 (narrow-to-region (point) here)
5410 ;; this matches a single quote which is
5411 ;; preceded by zero or two backslashes.
5412 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5419 (and (string-match "Win-Emacs" emacs-version)
5420 (fset 'vhdl-in-literal 'vhdl-win-il))
5422 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5423 ;; defined as lexical whitespace or comments. Search no farther back
5424 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5425 ;; used for backward skipping, (point-max) is used for forward
5428 (defun vhdl-forward-syntactic-ws (&optional lim)
5429 "Forward skip of syntactic whitespace."
5430 (let* ((here (point-max))
5431 (hugenum (point-max)))
5432 (while (/= here (point))
5434 (vhdl-forward-comment hugenum)
5435 ;; skip preprocessor directives
5436 (when (and (eq (char-after) ?#)
5437 (= (vhdl-point 'boi) (point)))
5438 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5439 (= (forward-line 1) 0)))
5441 (if lim (goto-char (min (point) lim)))))
5444 ;; This is the best we can do in Win-Emacs.
5445 (defun vhdl-win-fsws (&optional lim)
5446 "Forward skip syntactic whitespace for Win-Emacs."
5447 (let ((lim (or lim (point-max)))
5450 (skip-chars-forward " \t\n\r\f" lim)
5453 ((looking-at "--") (end-of-line))
5454 ;; none of the above
5455 (t (setq stop t))))))
5457 (and (string-match "Win-Emacs" emacs-version)
5458 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5460 (defun vhdl-beginning-of-macro (&optional lim)
5461 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5462 (let ((here (point)))
5464 (while (eq (char-before (1- (point))) ?\\)
5466 (back-to-indentation)
5467 (if (and (<= (point) here)
5468 (eq (char-after) ?#))
5473 (defun vhdl-backward-syntactic-ws (&optional lim)
5474 "Backward skip over syntactic whitespace."
5475 (let* ((here (point-min))
5476 (hugenum (- (point-max))))
5477 (while (/= here (point))
5479 (vhdl-forward-comment hugenum)
5480 (vhdl-beginning-of-macro))
5481 (if lim (goto-char (max (point) lim)))))
5483 ;; This is the best we can do in Win-Emacs.
5484 (defun vhdl-win-bsws (&optional lim)
5485 "Backward skip syntactic whitespace for Win-Emacs."
5486 (let ((lim (or lim (vhdl-point 'bod)))
5489 (skip-chars-backward " \t\n\r\f" lim)
5492 ((eq (vhdl-in-literal) 'comment)
5493 (skip-chars-backward "^-" lim)
5494 (skip-chars-backward "-" lim)
5495 (while (not (or (and (= (following-char) ?-)
5496 (= (char-after (1+ (point))) ?-))
5498 (skip-chars-backward "^-" lim)
5499 (skip-chars-backward "-" lim)))
5500 ;; none of the above
5501 (t (setq stop t))))))
5503 (and (string-match "Win-Emacs" emacs-version)
5504 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5506 ;; Functions to help finding the correct indentation column:
5508 (defun vhdl-first-word (point)
5509 "If the keyword at POINT is at boi, then return (current-column) at
5510 that point, else nil."
5512 (and (goto-char point)
5513 (eq (point) (vhdl-point 'boi))
5516 (defun vhdl-last-word (point)
5517 "If the keyword at POINT is at eoi, then return (current-column) at
5518 that point, else nil."
5520 (and (goto-char point)
5521 (save-excursion (or (eq (progn (forward-sexp) (point))
5523 (looking-at "\\s-*\\(--\\)?")))
5526 ;; Core syntactic evaluation functions:
5528 (defconst vhdl-libunit-re
5529 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5531 (defun vhdl-libunit-p ()
5535 (skip-chars-forward " \t\n")
5536 (not (looking-at "is\\b[^_]")))
5539 (and (not (looking-at "use\\b[^_]"))
5542 (vhdl-forward-syntactic-ws)
5543 (/= (following-char) ?:))))
5546 (defconst vhdl-defun-re
5547 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5549 (defun vhdl-defun-p ()
5551 (if (looking-at "block\\|process\\|procedural")
5552 ;; "block", "process", "procedural":
5555 (not (looking-at "end\\s-+\\w")))
5556 ;; "architecture", "configuration", "entity",
5557 ;; "package", "procedure", "function":
5560 (defun vhdl-corresponding-defun ()
5561 "If the word at the current position corresponds to a \"defun\"
5562 keyword, then return a string that can be used to find the
5563 corresponding \"begin\" keyword, else return nil."
5565 (and (looking-at vhdl-defun-re)
5567 (if (looking-at "block\\|process\\|procedural")
5568 ;; "block", "process". "procedural:
5569 (buffer-substring (match-beginning 0) (match-end 0))
5570 ;; "architecture", "configuration", "entity", "package",
5571 ;; "procedure", "function":
5574 (defconst vhdl-begin-fwd-re
5575 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5576 "A regular expression for searching forward that matches all known
5577 \"begin\" keywords.")
5579 (defconst vhdl-begin-bwd-re
5580 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5581 "A regular expression for searching backward that matches all known
5582 \"begin\" keywords.")
5584 (defun vhdl-begin-p (&optional lim)
5585 "Return t if we are looking at a real \"begin\" keyword.
5586 Assumes that the caller will make sure that we are looking at
5587 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5588 the middle of an identifier that just happens to contain a \"begin\"
5591 ;; "[architecture|case|configuration|entity|package|
5592 ;; procedure|function] ... is":
5593 ((and (looking-at "i")
5595 ;; Skip backward over first sexp (needed to skip over a
5596 ;; procedure interface list, and is harmless in other
5597 ;; situations). Note that we need "return" in the
5598 ;; following search list so that we don't run into
5599 ;; semicolons in the function interface list.
5602 (while (and (not foundp)
5604 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5606 (if (or (= (preceding-char) ?_)
5610 (and (/= (following-char) ?\;)
5611 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5614 ((looking-at "be\\|t")
5617 ((and (looking-at "e")
5618 ;; make sure that the "else" isn't inside a
5619 ;; conditional signal assignment.
5621 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5622 (or (eq (following-char) ?\;)
5625 ;; "block", "generate", "loop", "process", "procedural",
5626 ;; "units", "record":
5627 ((and (looking-at "bl\\|[glpur]")
5630 (not (looking-at "end\\s-+\\w"))))
5633 ((and (looking-at "c")
5636 (not (looking-at "end\\s-+\\w")))
5637 ;; look out for the dreaded entity class in an attribute
5639 (vhdl-backward-syntactic-ws lim)
5640 (/= (preceding-char) ?:)))
5642 ;; "for" (inside configuration declaration):
5643 ((and (looking-at "f")
5646 (not (looking-at "end\\s-+\\w")))
5647 (vhdl-has-syntax 'configuration))
5651 (defun vhdl-corresponding-mid (&optional lim)
5653 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5655 ((looking-at "then")
5660 (defun vhdl-corresponding-end (&optional lim)
5661 "If the word at the current position corresponds to a \"begin\"
5662 keyword, then return a vector containing enough information to find
5663 the corresponding \"end\" keyword, else return nil. The keyword to
5664 search forward for is aref 0. The column in which the keyword must
5665 appear is aref 1 or nil if any column is suitable.
5666 Assumes that the caller will make sure that we are not in the middle
5667 of an identifier that just happens to contain a \"begin\" keyword."
5669 (and (looking-at vhdl-begin-fwd-re)
5670 (/= (preceding-char) ?_)
5671 (not (vhdl-in-literal))
5674 ;; "is", "generate", "loop":
5675 ((looking-at "[igl]")
5677 (and (vhdl-last-word (point))
5678 (or (vhdl-first-word (point))
5680 (vhdl-beginning-of-statement-1 lim)
5681 (vhdl-backward-skip-label lim)
5682 (vhdl-first-word (point)))))))
5683 ;; "begin", "else", "for":
5684 ((looking-at "be\\|[ef]")
5686 (and (vhdl-last-word (point))
5687 (or (vhdl-first-word (point))
5689 (vhdl-beginning-of-statement-1 lim)
5690 (vhdl-backward-skip-label lim)
5691 (vhdl-first-word (point)))))))
5692 ;; "component", "units", "record":
5693 ((looking-at "[cur]")
5694 ;; The first end found will close the block
5696 ;; "block", "process", "procedural":
5697 ((looking-at "bl\\|p")
5699 (or (vhdl-first-word (point))
5701 (vhdl-beginning-of-statement-1 lim)
5702 (vhdl-backward-skip-label lim)
5703 (vhdl-first-word (point))))))
5706 (vector "elsif\\|else\\|end\\s-+if"
5707 (and (vhdl-last-word (point))
5708 (or (vhdl-first-word (point))
5710 (vhdl-beginning-of-statement-1 lim)
5711 (vhdl-backward-skip-label lim)
5712 (vhdl-first-word (point)))))))
5715 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5717 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5719 (defun vhdl-end-p (&optional lim)
5720 "Return t if we are looking at a real \"end\" keyword.
5721 Assumes that the caller will make sure that we are looking at
5722 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5723 the middle of an identifier that just happens to contain an \"end\"
5725 (or (not (looking-at "else"))
5726 ;; make sure that the "else" isn't inside a conditional signal
5729 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5730 (or (eq (following-char) ?\;)
5732 (vhdl-in-literal)))))
5734 (defun vhdl-corresponding-begin (&optional lim)
5735 "If the word at the current position corresponds to an \"end\"
5736 keyword, then return a vector containing enough information to find
5737 the corresponding \"begin\" keyword, else return nil. The keyword to
5738 search backward for is aref 0. The column in which the keyword must
5739 appear is aref 1 or nil if any column is suitable. The supplementary
5740 keyword to search forward for is aref 2 or nil if this is not
5741 required. If aref 3 is t, then the \"begin\" keyword may be found in
5742 the middle of a statement.
5743 Assumes that the caller will make sure that we are not in the middle
5744 of an identifier that just happens to contain an \"end\" keyword."
5747 (if (and (looking-at vhdl-end-fwd-re)
5748 (not (vhdl-in-literal))
5750 (if (looking-at "el")
5752 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5756 (skip-chars-forward " \t\n")
5759 ((looking-at "if\\b[^_]")
5760 (vector "else\\|elsif\\|if"
5761 (vhdl-first-word pos)
5764 ((looking-at "component\\b[^_]")
5765 (vector (buffer-substring (match-beginning 1)
5767 (vhdl-first-word pos)
5769 ;; "end units", "end record":
5770 ((looking-at "\\(units\\|record\\)\\b[^_]")
5771 (vector (buffer-substring (match-beginning 1)
5773 (vhdl-first-word pos)
5775 ;; "end block", "end process", "end procedural":
5776 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5777 (vector "begin" (vhdl-first-word pos) nil nil))
5779 ((looking-at "case\\b[^_]")
5780 (vector "case" (vhdl-first-word pos) "is" nil))
5782 ((looking-at "generate\\b[^_]")
5783 (vector "generate\\|for\\|if"
5784 (vhdl-first-word pos)
5787 ((looking-at "loop\\b[^_]")
5788 (vector "loop\\|while\\|for"
5789 (vhdl-first-word pos)
5791 ;; "end for" (inside configuration declaration):
5792 ((looking-at "for\\b[^_]")
5793 (vector "for" (vhdl-first-word pos) nil nil))
5796 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5797 (vhdl-first-word pos)
5798 ;; return an alist of (statement . keyword) mappings
5800 ;; "begin ... end [id]":
5802 ;; "architecture ... is ... begin ... end [id]":
5803 ("architecture" . "is")
5804 ;; "configuration ... is ... end [id]":
5805 ("configuration" . "is")
5806 ;; "entity ... is ... end [id]":
5808 ;; "package ... is ... end [id]":
5810 ;; "procedure ... is ... begin ... end [id]":
5811 ("procedure" . "is")
5812 ;; "function ... is ... begin ... end [id]":
5819 (defconst vhdl-leader-re
5820 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5822 (defun vhdl-end-of-leader ()
5824 (cond ((looking-at "block\\|process\\|procedural")
5827 (skip-chars-forward " \t\n")
5828 (= (following-char) ?\())
5831 (when (looking-at "[ \t\n]*is")
5832 (goto-char (match-end 0)))
5834 ((looking-at "component")
5836 (when (looking-at "[ \t\n]*is")
5837 (goto-char (match-end 0)))
5841 (skip-chars-forward " \t\n")
5842 (while (looking-at "[,:(]")
5844 (skip-chars-forward " \t\n"))
5849 (defconst vhdl-trailer-re
5850 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5852 (defconst vhdl-statement-fwd-re
5853 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5854 "A regular expression for searching forward that matches all known
5855 \"statement\" keywords.")
5857 (defconst vhdl-statement-bwd-re
5858 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5859 "A regular expression for searching backward that matches all known
5860 \"statement\" keywords.")
5862 (defun vhdl-statement-p (&optional lim)
5863 "Return t if we are looking at a real \"statement\" keyword.
5864 Assumes that the caller will make sure that we are looking at
5865 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5866 in the middle of an identifier that just happens to contain a
5867 \"statement\" keyword."
5869 ;; "for" ... "generate":
5870 ((and (looking-at "f")
5871 ;; Make sure it's the start of a parameter specification.
5874 (skip-chars-forward " \t\n")
5875 (looking-at "in\\b[^_]"))
5876 ;; Make sure it's not an "end for".
5879 (not (looking-at "end\\s-+\\w"))))
5881 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5882 ((and (looking-at "i")
5883 ;; Make sure it's not an "end if".
5886 (not (looking-at "end\\s-+\\w"))))
5888 ;; "while" ... "loop":
5893 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5894 "Regexp describing a case statement alternative key.")
5896 (defun vhdl-case-alternative-p (&optional lim)
5897 "Return t if we are looking at a real case alternative.
5898 Assumes that the caller will make sure that we are looking at
5899 vhdl-case-alternative-re, and are not inside a literal, and that
5900 we are not in the middle of an identifier that just happens to
5901 contain a \"when\" keyword."
5904 (while (and (not foundp)
5905 (re-search-backward ";\\|<=" lim 'move))
5906 (if (or (= (preceding-char) ?_)
5910 (or (eq (following-char) ?\;)
5914 ;; Core syntactic movement functions:
5916 (defconst vhdl-b-t-b-re
5917 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5919 (defun vhdl-backward-to-block (&optional lim)
5920 "Move backward to the previous \"begin\" or \"end\" keyword."
5922 (while (and (not foundp)
5923 (re-search-backward vhdl-b-t-b-re lim 'move))
5924 (if (or (= (preceding-char) ?_)
5929 ((and (looking-at vhdl-begin-fwd-re)
5930 (/= (preceding-char) ?_)
5932 (setq foundp 'begin))
5934 ((and (looking-at vhdl-end-fwd-re)
5935 (/= (preceding-char) ?_)
5943 (defun vhdl-forward-sexp (&optional count lim)
5944 "Move forward across one balanced expression (sexp).
5945 With COUNT, do it that many times."
5947 (let ((count (or count 1))
5948 (case-fold-search t)
5953 (skip-chars-forward " \t\n")
5954 ;; Check for an unbalanced "end" keyword
5955 (if (and (looking-at vhdl-end-fwd-re)
5956 (/= (preceding-char) ?_)
5957 (not (vhdl-in-literal))
5959 (not (looking-at "else")))
5961 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5962 ;; If the current keyword is a "begin" keyword, then find the
5963 ;; corresponding "end" keyword.
5964 (if (setq end-vec (vhdl-corresponding-end lim))
5966 ;; end-re is the statement keyword to search for
5968 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5969 ;; column is either the statement keyword target column
5971 (column (aref end-vec 1))
5972 (eol (vhdl-point 'eol))
5973 foundp literal placeholder)
5974 ;; Look for the statement keyword.
5975 (while (and (not foundp)
5976 (re-search-forward end-re nil t)
5977 (setq placeholder (match-end 1))
5978 (goto-char (match-beginning 0)))
5979 ;; If we are in a literal, or not in the right target
5980 ;; column and not on the same line as the begin, then
5983 (/= (current-indentation) column)
5985 (= (preceding-char) ?_)
5986 (setq literal (vhdl-in-literal)))
5987 (if (eq literal 'comment)
5990 ;; An "else" keyword corresponds to both the opening brace
5991 ;; of the following sexp and the closing brace of the
5993 (if (not (looking-at "else"))
5994 (goto-char placeholder))
5998 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6000 ;; If the current keyword is not a "begin" keyword, then just
6001 ;; perform the normal forward-sexp.
6004 (setq count (1- count))
6006 (setq target (point)))
6010 (defun vhdl-backward-sexp (&optional count lim)
6011 "Move backward across one balanced expression (sexp).
6012 With COUNT, do it that many times. LIM bounds any required backward
6015 (let ((count (or count 1))
6016 (case-fold-search t)
6020 ;; Perform the normal backward-sexp, unless we are looking at
6021 ;; "else" - an "else" keyword corresponds to both the opening brace
6022 ;; of the following sexp and the closing brace of the previous sexp.
6023 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6024 (/= (preceding-char) ?_)
6025 (not (vhdl-in-literal)))
6028 (if (and (looking-at vhdl-begin-fwd-re)
6029 (/= (preceding-char) ?_)
6030 (not (vhdl-in-literal))
6032 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6033 ;; If the current keyword is an "end" keyword, then find the
6034 ;; corresponding "begin" keyword.
6035 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6036 (/= (preceding-char) ?_))
6038 ;; begin-re is the statement keyword to search for
6040 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6041 ;; column is either the statement keyword target column
6043 (column (aref begin-vec 1))
6044 ;; internal-p controls where the statement keyword can
6046 (internal-p (aref begin-vec 3))
6047 (last-backward (point)) last-forward
6048 foundp literal keyword)
6049 ;; Look for the statement keyword.
6050 (while (and (not foundp)
6051 (re-search-backward begin-re lim t)
6053 (buffer-substring (match-beginning 1)
6055 ;; If we are in a literal or in the wrong column,
6058 (and (/= (current-indentation) column)
6059 ;; possibly accept current-column as
6060 ;; well as current-indentation.
6061 (or (not internal-p)
6062 (/= (current-column) column))))
6063 (= (preceding-char) ?_)
6066 ;; If there is a supplementary keyword, then
6067 ;; search forward for it.
6068 (if (and (setq begin-re (aref begin-vec 2))
6069 (or (not (listp begin-re))
6070 ;; If begin-re is an alist, then find the
6071 ;; element corresponding to the actual
6072 ;; keyword that we found.
6075 (assoc keyword begin-re))
6077 (setq begin-re (cdr begin-re))))))
6080 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6082 (setq last-forward (point))
6083 ;; Look for the supplementary keyword
6084 ;; (bounded by the backward search start
6086 (while (and (not foundp)
6087 (re-search-forward begin-re
6089 (goto-char (match-beginning 1)))
6090 ;; If we are in a literal, then try again.
6091 (if (or (= (preceding-char) ?_)
6094 (if (eq literal 'comment)
6096 (min (vhdl-point 'eol) last-backward))
6098 ;; We have found the supplementary keyword.
6099 ;; Save the position of the keyword in foundp.
6100 (setq foundp (point)))
6103 ;; If the supplementary keyword was found, then
6104 ;; move point to the supplementary keyword.
6106 ;; If there was no supplementary keyword, then
6107 ;; point is already at the statement keyword.
6109 ) ; end of the search for the statement keyword
6111 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6113 (setq count (1- count))
6115 (setq target (point)))
6119 (defun vhdl-backward-up-list (&optional count limit)
6120 "Move backward out of one level of blocks.
6121 With argument, do this that many times."
6123 (let ((count (or count 1))
6127 (if (looking-at vhdl-defun-re)
6128 (error "ERROR: Unbalanced blocks"))
6129 (vhdl-backward-to-block limit)
6130 (setq count (1- count)))
6131 (setq target (point)))
6132 (goto-char target)))
6134 (defun vhdl-end-of-defun (&optional count)
6135 "Move forward to the end of a VHDL defun."
6137 (let ((case-fold-search t))
6138 (vhdl-beginning-of-defun)
6139 (if (not (looking-at "block\\|process\\|procedural"))
6140 (re-search-forward "\\bis\\b"))
6141 (vhdl-forward-sexp)))
6143 (defun vhdl-mark-defun ()
6144 "Put mark at end of this \"defun\", point at beginning."
6146 (let ((case-fold-search t))
6148 (vhdl-beginning-of-defun)
6150 (if (not (looking-at "block\\|process\\|procedural"))
6151 (re-search-forward "\\bis\\b"))
6153 (exchange-point-and-mark)))
6155 (defun vhdl-beginning-of-libunit ()
6156 "Move backward to the beginning of a VHDL library unit.
6157 Returns the location of the corresponding begin keyword, unless search
6158 stops due to beginning or end of buffer.
6159 Note that if point is between the \"libunit\" keyword and the
6160 corresponding \"begin\" keyword, then that libunit will not be
6161 recognized, and the search will continue backwards. If point is
6162 at the \"begin\" keyword, then the defun will be recognized. The
6163 returned point is at the first character of the \"libunit\" keyword."
6164 (let ((last-forward (point))
6166 ;; Just in case we are actually sitting on the "begin"
6167 ;; keyword, allow for the keyword and an extra character,
6168 ;; as this will be used when looking forward for the
6170 (save-excursion (forward-word 1) (1+ (point))))
6171 foundp literal placeholder)
6172 ;; Find the "libunit" keyword.
6173 (while (and (not foundp)
6174 (re-search-backward vhdl-libunit-re nil 'move))
6175 ;; If we are in a literal, or not at a real libunit, then try again.
6176 (if (or (= (preceding-char) ?_)
6178 (not (vhdl-libunit-p)))
6180 ;; Find the corresponding "begin" keyword.
6181 (setq last-forward (point))
6182 (while (and (not foundp)
6183 (re-search-forward "\\bis\\b[^_]" last-backward t)
6184 (setq placeholder (match-beginning 0)))
6185 (if (or (= (preceding-char) ?_)
6186 (setq literal (vhdl-in-literal)))
6187 ;; It wasn't a real keyword, so keep searching.
6188 (if (eq literal 'comment)
6190 (min (vhdl-point 'eol) last-backward))
6192 ;; We have found the begin keyword, loop will exit.
6193 (setq foundp placeholder)))
6194 ;; Go back to the libunit keyword
6195 (goto-char last-forward)))
6198 (defun vhdl-beginning-of-defun (&optional count)
6199 "Move backward to the beginning of a VHDL defun.
6200 With argument, do it that many times.
6201 Returns the location of the corresponding begin keyword, unless search
6202 stops due to beginning or end of buffer."
6203 ;; Note that if point is between the "defun" keyword and the
6204 ;; corresponding "begin" keyword, then that defun will not be
6205 ;; recognized, and the search will continue backwards. If point is
6206 ;; at the "begin" keyword, then the defun will be recognized. The
6207 ;; returned point is at the first character of the "defun" keyword.
6209 (let ((count (or count 1))
6210 (case-fold-search t)
6211 (last-forward (point))
6215 (goto-char last-forward)
6216 (let ((last-backward
6217 ;; Just in case we are actually sitting on the "begin"
6218 ;; keyword, allow for the keyword and an extra character,
6219 ;; as this will be used when looking forward for the
6221 (save-excursion (forward-word 1) (1+ (point))))
6222 begin-string literal)
6223 (while (and (not foundp)
6224 (re-search-backward vhdl-defun-re nil 'move))
6225 ;; If we are in a literal, then try again.
6226 (if (or (= (preceding-char) ?_)
6229 (if (setq begin-string (vhdl-corresponding-defun))
6230 ;; This is a real defun keyword.
6231 ;; Find the corresponding "begin" keyword.
6232 ;; Look for the begin keyword.
6234 ;; Save the search start point.
6235 (setq last-forward (point))
6236 (while (and (not foundp)
6237 (search-forward begin-string last-backward t))
6238 (if (or (= (preceding-char) ?_)
6240 (setq literal (vhdl-in-literal))))
6241 ;; It wasn't a real keyword, so keep searching.
6242 (if (eq literal 'comment)
6244 (min (vhdl-point 'eol) last-backward))
6246 ;; We have found the begin keyword, loop will exit.
6247 (setq foundp (match-beginning 0)))
6249 ;; Go back to the defun keyword
6250 (goto-char last-forward)) ; end search for begin keyword
6252 ) ; end of the search for the defun keyword
6254 (setq count (1- count))
6256 (vhdl-keep-region-active)
6259 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6260 "Go to the beginning of the innermost VHDL statement.
6261 With prefix arg, go back N - 1 statements. If already at the
6262 beginning of a statement then go to the beginning of the preceding
6263 one. If within a string or comment, or next to a comment (only
6264 whitespace between), move by sentences instead of statements.
6266 When called from a program, this function takes 3 optional args: the
6267 prefix arg, a buffer position limit which is the farthest back to
6268 search, and an argument indicating an interactive call."
6269 (interactive "p\np")
6270 (let ((count (or count 1))
6271 (case-fold-search t)
6272 (lim (or lim (point-min)))
6277 (setq state (parse-partial-sexp (point) here nil nil)))
6278 (if (and interactive
6281 (looking-at (concat "[ \t]*" comment-start-skip))))
6282 (forward-sentence (- count))
6284 (vhdl-beginning-of-statement-1 lim)
6285 (setq count (1- count))))
6286 ;; its possible we've been left up-buf of lim
6287 (goto-char (max (point) lim))
6289 (vhdl-keep-region-active))
6291 (defconst vhdl-e-o-s-re
6292 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6294 (defun vhdl-end-of-statement ()
6295 "Very simple implementation."
6297 (re-search-forward vhdl-e-o-s-re))
6299 (defconst vhdl-b-o-s-re
6300 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6301 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6303 (defun vhdl-beginning-of-statement-1 (&optional lim)
6304 "Move to the start of the current statement, or the previous
6305 statement if already at the beginning of one."
6306 (let ((lim (or lim (point-min)))
6310 ;; go backwards one balanced expression, but be careful of
6311 ;; unbalanced paren being reached
6312 (if (not (vhdl-safe (progn (backward-sexp) t)))
6314 (backward-up-list 1)
6316 (vhdl-forward-syntactic-ws here)
6318 (while (and (not donep)
6320 ;; look backwards for a statement boundary
6321 (re-search-backward vhdl-b-o-s-re lim 'move))
6322 (if (or (= (preceding-char) ?_)
6326 ;; If we are looking at an open paren, then stop after it
6327 ((eq (following-char) ?\()
6329 (vhdl-forward-syntactic-ws here)
6331 ;; If we are looking at a close paren, then skip it
6332 ((eq (following-char) ?\))
6337 (progn (goto-char pos)
6338 (vhdl-forward-syntactic-ws here)
6340 ;; If we are looking at a semicolon, then stop
6341 ((eq (following-char) ?\;)
6344 (vhdl-forward-syntactic-ws here)
6346 ;; If we are looking at a "begin", then stop
6347 ((and (looking-at vhdl-begin-fwd-re)
6348 (/= (preceding-char) ?_)
6350 ;; If it's a leader "begin", then find the
6352 (if (looking-at vhdl-leader-re)
6354 ;; set a default stop point at the begin
6356 ;; is the start point inside the leader area ?
6357 (goto-char (vhdl-end-of-leader))
6358 (vhdl-forward-syntactic-ws here)
6359 (if (< (point) here)
6360 ;; start point was not inside leader area
6361 ;; set stop point at word after leader
6362 (setq pos (point))))
6364 (vhdl-forward-syntactic-ws here)
6368 ;; If we are looking at a "statement", then stop
6369 ((and (looking-at vhdl-statement-fwd-re)
6370 (/= (preceding-char) ?_)
6371 (vhdl-statement-p nil))
6373 ;; If we are looking at a case alternative key, then stop
6374 ((and (looking-at vhdl-case-alternative-re)
6375 (vhdl-case-alternative-p lim))
6377 ;; set a default stop point at the when
6379 ;; is the start point inside the case alternative key ?
6380 (looking-at vhdl-case-alternative-re)
6381 (goto-char (match-end 0))
6382 (vhdl-forward-syntactic-ws here)
6383 (if (< (point) here)
6384 ;; start point was not inside the case alternative key
6385 ;; set stop point at word after case alternative keyleader
6386 (setq pos (point))))
6389 ;; Bogus find, continue
6394 ;; Defuns for calculating the current syntactic state:
6396 (defun vhdl-get-library-unit (bod placeholder)
6397 "If there is an enclosing library unit at BOD, with its \"begin\"
6398 keyword at PLACEHOLDER, then return the library unit type."
6399 (let ((here (vhdl-point 'bol)))
6401 (goto-char placeholder)
6402 (vhdl-safe (vhdl-forward-sexp 1 bod))
6407 ((looking-at "e") 'entity)
6408 ((looking-at "a") 'architecture)
6409 ((looking-at "c") 'configuration)
6414 (vhdl-forward-syntactic-ws here)
6415 (if (looking-at "body\\b[^_]")
6416 'package-body 'package))))))
6419 (defun vhdl-get-block-state (&optional lim)
6420 "Finds and records all the closest opens.
6421 LIM is the furthest back we need to search (it should be the
6422 previous libunit keyword)."
6423 (let ((here (point))
6424 (lim (or lim (point-min)))
6425 keyword sexp-start sexp-mid sexp-end
6426 preceding-sexp containing-sexp
6427 containing-begin containing-mid containing-paren)
6429 ;; Find the containing-paren, and use that as the limit
6430 (if (setq containing-paren
6432 (narrow-to-region lim (point))
6433 (vhdl-safe (scan-lists (point) -1 1))))
6434 (setq lim containing-paren))
6435 ;; Look backwards for "begin" and "end" keywords.
6436 (while (and (> (point) lim)
6437 (not containing-sexp))
6438 (setq keyword (vhdl-backward-to-block lim))
6440 ((eq keyword 'begin)
6441 ;; Found a "begin" keyword
6442 (setq sexp-start (point))
6443 (setq sexp-mid (vhdl-corresponding-mid lim))
6444 (setq sexp-end (vhdl-safe
6446 (vhdl-forward-sexp 1 lim) (point))))
6447 (if (and sexp-end (<= sexp-end here))
6448 ;; we want to record this sexp, but we only want to
6449 ;; record the last-most of any of them before here
6451 (setq preceding-sexp sexp-start))
6452 ;; we're contained in this sexp so put sexp-start on
6454 (setq containing-sexp sexp-start)
6455 (setq containing-mid sexp-mid)
6456 (setq containing-begin t)))
6458 ;; Found an "end" keyword
6460 (setq sexp-end (point))
6463 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6464 (progn (backward-sexp) (point))))
6465 ;; we want to record this sexp, but we only want to
6466 ;; record the last-most of any of them before here
6468 (setq preceding-sexp sexp-start)))
6470 ;; Check if the containing-paren should be the containing-sexp
6471 (if (and containing-paren
6472 (or (null containing-sexp)
6473 (< containing-sexp containing-paren)))
6474 (setq containing-sexp containing-paren
6476 containing-begin nil
6477 containing-mid nil))
6478 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6482 (defconst vhdl-s-c-a-re
6483 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6485 (defun vhdl-skip-case-alternative (&optional lim)
6486 "Skip forward over case/when bodies, with optional maximal
6487 limit. If no next case alternative is found, nil is returned and
6488 point is not moved."
6489 (let ((lim (or lim (point-max)))
6492 (while (and (< (point) lim)
6494 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6496 (not (vhdl-in-literal)))
6497 (/= (match-beginning 0) here))
6499 (goto-char (match-beginning 0))
6501 ((and (looking-at "case")
6502 (re-search-forward "\\bis[^_]" lim t))
6504 (vhdl-forward-sexp))
6512 (defun vhdl-backward-skip-label (&optional lim)
6513 "Skip backward over a label, with optional maximal
6514 limit. If label is not found, nil is returned and point
6516 (let ((lim (or lim (point-min)))
6519 (vhdl-backward-syntactic-ws lim)
6520 (and (eq (preceding-char) ?:)
6523 (setq placeholder (point))
6524 (looking-at vhdl-label-key))))
6525 (goto-char placeholder))
6528 (defun vhdl-forward-skip-label (&optional lim)
6529 "Skip forward over a label, with optional maximal
6530 limit. If label is not found, nil is returned and point
6532 (let ((lim (or lim (point-max))))
6533 (if (looking-at vhdl-label-key)
6535 (goto-char (match-end 0))
6536 (vhdl-forward-syntactic-ws lim)))
6539 (defun vhdl-get-syntactic-context ()
6540 "Guess the syntactic description of the current line of VHDL code."
6544 (let* ((indent-point (point))
6545 (case-fold-search t)
6546 vec literal containing-sexp preceding-sexp
6547 containing-begin containing-mid containing-leader
6548 char-before-ip char-after-ip begin-after-ip end-after-ip
6549 placeholder lim library-unit
6552 ;; Reset the syntactic context
6553 (setq vhdl-syntactic-context nil)
6556 ;; Move to the start of the previous library unit, and
6557 ;; record the position of the "begin" keyword.
6558 (setq placeholder (vhdl-beginning-of-libunit))
6559 ;; The position of the "libunit" keyword gives us a gross
6564 ;; If there is a previous library unit, and we are enclosed by
6565 ;; it, then set the syntax accordingly.
6567 (setq library-unit (vhdl-get-library-unit lim placeholder))
6568 (vhdl-add-syntax library-unit lim))
6570 ;; Find the surrounding state.
6571 (if (setq vec (vhdl-get-block-state lim))
6573 (setq containing-sexp (aref vec 0))
6574 (setq preceding-sexp (aref vec 1))
6575 (setq containing-begin (aref vec 2))
6576 (setq containing-mid (aref vec 3))
6579 ;; set the limit on the farthest back we need to search
6580 (setq lim (if containing-sexp
6582 (goto-char containing-sexp)
6583 ;; set containing-leader if required
6584 (if (looking-at vhdl-leader-re)
6585 (setq containing-leader (vhdl-end-of-leader)))
6589 ;; cache char before and after indent point, and move point to
6590 ;; the most likely position to perform the majority of tests
6591 (goto-char indent-point)
6592 (skip-chars-forward " \t")
6593 (setq literal (vhdl-in-literal))
6594 (setq char-after-ip (following-char))
6595 (setq begin-after-ip (and
6597 (looking-at vhdl-begin-fwd-re)
6599 (setq end-after-ip (and
6601 (looking-at vhdl-end-fwd-re)
6603 (vhdl-backward-syntactic-ws lim)
6604 (setq char-before-ip (preceding-char))
6605 (goto-char indent-point)
6606 (skip-chars-forward " \t")
6608 ;; now figure out syntactic qualities of the current line
6610 ;; CASE 1: in a string or comment.
6611 ((memq literal '(string comment))
6612 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6613 ;; CASE 2: Line is at top level.
6614 ((null containing-sexp)
6615 ;; Find the point to which indentation will be relative
6617 (if (null preceding-sexp)
6619 ;; no preceding-sexp -> use the preceding statement
6620 (vhdl-beginning-of-statement-1 lim)
6622 ;; if there is a preceding-sexp then indent relative to it
6623 (goto-char preceding-sexp)
6624 ;; if not at boi, then the block-opening keyword is
6625 ;; probably following a label, so we need a different
6627 (if (/= (point) (vhdl-point 'boi))
6629 (vhdl-beginning-of-statement-1 lim)))
6630 ;; v-b-o-s could have left us at point-min
6633 (vhdl-forward-syntactic-ws indent-point))
6634 (setq placeholder (point)))
6636 ;; CASE 2A : we are looking at a block-open
6638 (vhdl-add-syntax 'block-open placeholder))
6639 ;; CASE 2B: we are looking at a block-close
6641 (vhdl-add-syntax 'block-close placeholder))
6642 ;; CASE 2C: we are looking at a top-level statement
6644 (vhdl-backward-syntactic-ws lim)
6646 (= (preceding-char) ?\;)))
6647 (vhdl-add-syntax 'statement placeholder))
6648 ;; CASE 2D: we are looking at a top-level statement-cont
6650 (vhdl-beginning-of-statement-1 lim)
6651 ;; v-b-o-s could have left us at point-min
6654 (vhdl-forward-syntactic-ws indent-point))
6655 (vhdl-add-syntax 'statement-cont (point)))
6657 ;; CASE 3: line is inside parentheses. Most likely we are
6658 ;; either in a subprogram argument (interface) list, or a
6659 ;; continued expression containing parentheses.
6660 ((null containing-begin)
6661 (vhdl-backward-syntactic-ws containing-sexp)
6663 ;; CASE 3A: we are looking at the arglist closing paren
6664 ((eq char-after-ip ?\))
6665 (goto-char containing-sexp)
6666 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6667 ;; CASE 3B: we are looking at the first argument in an empty
6669 ((eq char-before-ip ?\()
6670 (goto-char containing-sexp)
6671 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6672 ;; CASE 3C: we are looking at an arglist continuation line,
6673 ;; but the preceding argument is on the same line as the
6674 ;; opening paren. This case includes multi-line
6675 ;; expression paren groupings.
6676 ((and (save-excursion
6677 (goto-char (1+ containing-sexp))
6678 (skip-chars-forward " \t")
6680 (not (looking-at "--")))
6682 (vhdl-beginning-of-statement-1 containing-sexp)
6683 (skip-chars-backward " \t(")
6684 (<= (point) containing-sexp)))
6685 (goto-char containing-sexp)
6686 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6687 ;; CASE 3D: we are looking at just a normal arglist
6688 ;; continuation line
6689 (t (vhdl-beginning-of-statement-1 containing-sexp)
6690 (vhdl-forward-syntactic-ws indent-point)
6691 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6693 ;; CASE 4: A block mid open
6694 ((and begin-after-ip
6695 (looking-at containing-mid))
6696 (goto-char containing-sexp)
6697 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6698 (if (looking-at vhdl-trailer-re)
6700 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6701 (vhdl-backward-skip-label (vhdl-point 'boi))
6702 (vhdl-add-syntax 'block-open (point)))
6703 ;; CASE 5: block close brace
6705 (goto-char containing-sexp)
6706 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6707 (if (looking-at vhdl-trailer-re)
6709 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6710 (vhdl-backward-skip-label (vhdl-point 'boi))
6711 (vhdl-add-syntax 'block-close (point)))
6712 ;; CASE 6: A continued statement
6713 ((and (/= char-before-ip ?\;)
6714 ;; check it's not a trailer begin keyword, or a begin
6715 ;; keyword immediately following a label.
6716 (not (and begin-after-ip
6717 (or (looking-at vhdl-trailer-re)
6719 (vhdl-backward-skip-label containing-sexp)))))
6720 ;; check it's not a statement keyword
6721 (not (and (looking-at vhdl-statement-fwd-re)
6722 (vhdl-statement-p)))
6723 ;; see if the b-o-s is before the indent point
6726 (vhdl-beginning-of-statement-1 containing-sexp)
6727 ;; If we ended up after a leader, then this will
6728 ;; move us forward to the start of the first
6729 ;; statement. Note that a containing sexp here is
6730 ;; always a keyword, not a paren, so this will
6731 ;; have no effect if we hit the containing-sexp.
6732 (vhdl-forward-syntactic-ws indent-point)
6733 (setq placeholder (point))))
6734 ;; check it's not a block-intro
6735 (/= placeholder containing-sexp)
6736 ;; check it's not a case block-intro
6738 (goto-char placeholder)
6739 (or (not (looking-at vhdl-case-alternative-re))
6740 (> (match-end 0) indent-point))))
6741 ;; Make placeholder skip a label, but only if it puts us
6742 ;; before the indent point at the start of a line.
6743 (let ((new placeholder))
6744 (if (and (> indent-point
6746 (goto-char placeholder)
6747 (vhdl-forward-skip-label indent-point)
6748 (setq new (point))))
6751 (eq new (progn (back-to-indentation) (point)))))
6752 (setq placeholder new)))
6753 (vhdl-add-syntax 'statement-cont placeholder)
6755 (vhdl-add-syntax 'block-open)))
6756 ;; Statement. But what kind?
6757 ;; CASE 7: A case alternative key
6758 ((and (looking-at vhdl-case-alternative-re)
6759 (vhdl-case-alternative-p containing-sexp))
6760 ;; for a case alternative key, we set relpos to the first
6761 ;; non-whitespace char on the line containing the "case"
6763 (goto-char containing-sexp)
6764 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6765 (if (looking-at vhdl-trailer-re)
6766 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6767 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6768 ;; CASE 8: statement catchall
6770 ;; we know its a statement, but we need to find out if it is
6771 ;; the first statement in a block
6772 (if containing-leader
6773 (goto-char containing-leader)
6774 (goto-char containing-sexp)
6775 ;; Note that a containing sexp here is always a keyword,
6776 ;; not a paren, so skip over the keyword.
6778 ;; move to the start of the first statement
6779 (vhdl-forward-syntactic-ws indent-point)
6780 (setq placeholder (point))
6781 ;; we want to ignore case alternatives keys when skipping forward
6783 (while (looking-at vhdl-case-alternative-re)
6784 (setq incase-p (point))
6785 ;; we also want to skip over the body of the
6786 ;; case/when statement if that doesn't put us at
6787 ;; after the indent-point
6788 (while (vhdl-skip-case-alternative indent-point))
6789 ;; set up the match end
6790 (looking-at vhdl-case-alternative-re)
6791 (goto-char (match-end 0))
6792 ;; move to the start of the first case alternative statement
6793 (vhdl-forward-syntactic-ws indent-point)
6794 (setq placeholder (point)))
6796 ;; CASE 8A: we saw a case/when statement so we must be
6797 ;; in a switch statement. find out if we are at the
6798 ;; statement just after a case alternative key
6800 (= (point) indent-point))
6801 ;; relpos is the "when" keyword
6802 (vhdl-add-syntax 'statement-case-intro incase-p))
6803 ;; CASE 8B: any old statement
6804 ((< (point) indent-point)
6805 ;; relpos is the first statement of the block
6806 (vhdl-add-syntax 'statement placeholder)
6808 (vhdl-add-syntax 'block-open)))
6809 ;; CASE 8C: first statement in a block
6811 (goto-char containing-sexp)
6812 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6813 (if (looking-at vhdl-trailer-re)
6814 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6815 (vhdl-backward-skip-label (vhdl-point 'boi))
6816 (vhdl-add-syntax 'statement-block-intro (point))
6818 (vhdl-add-syntax 'block-open)))
6822 ;; now we need to look at any modifiers
6823 (goto-char indent-point)
6824 (skip-chars-forward " \t")
6825 (if (looking-at "--")
6826 (vhdl-add-syntax 'comment))
6827 (if (eq literal 'pound)
6828 (vhdl-add-syntax 'cpp-macro))
6829 ;; return the syntax
6830 vhdl-syntactic-context))))
6832 ;; Standard indentation line-ups:
6834 (defun vhdl-lineup-arglist (langelem)
6835 "Lineup the current arglist line with the arglist appearing just
6836 after the containing paren which starts the arglist."
6838 (let* ((containing-sexp
6840 ;; arglist-cont-nonempty gives relpos ==
6841 ;; to boi of containing-sexp paren. This
6842 ;; is good when offset is +, but bad
6843 ;; when it is vhdl-lineup-arglist, so we
6844 ;; have to special case a kludge here.
6845 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6848 (backward-up-list 1)
6849 (skip-chars-forward " \t" (vhdl-point 'eol)))
6850 (goto-char (cdr langelem)))
6852 (cs-curcol (save-excursion
6853 (goto-char (cdr langelem))
6857 (looking-at "[ \t]*)"))
6858 (progn (goto-char (match-end 0))
6861 (vhdl-forward-syntactic-ws)
6862 (- (current-column) cs-curcol))
6863 (goto-char containing-sexp)
6865 (let ((eol (vhdl-point 'eol))
6868 (skip-chars-forward " \t")
6870 (vhdl-forward-syntactic-ws)
6873 (- (current-column) cs-curcol)
6876 (defun vhdl-lineup-arglist-intro (langelem)
6877 "Lineup an arglist-intro line to just after the open paren."
6879 (let ((cs-curcol (save-excursion
6880 (goto-char (cdr langelem))
6882 (ce-curcol (save-excursion
6884 (backward-up-list 1)
6885 (skip-chars-forward " \t" (vhdl-point 'eol))
6887 (- ce-curcol cs-curcol -1))))
6889 (defun vhdl-lineup-comment (langelem)
6890 "Support old behavior for comment indentation. We look at
6891 vhdl-comment-only-line-offset to decide how to indent comment
6894 (back-to-indentation)
6895 ;; at or to the right of comment-column
6896 (if (>= (current-column) comment-column)
6897 (vhdl-comment-indent)
6898 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6900 (or (car-safe vhdl-comment-only-line-offset)
6901 vhdl-comment-only-line-offset)
6902 (or (cdr-safe vhdl-comment-only-line-offset)
6903 (car-safe vhdl-comment-only-line-offset)
6904 -1000 ;jam it against the left side
6907 (defun vhdl-lineup-statement-cont (langelem)
6908 "Line up statement-cont after the assignment operator."
6910 (let* ((relpos (cdr langelem))
6911 (assignp (save-excursion
6912 (goto-char (vhdl-point 'boi))
6913 (and (re-search-forward "\\(<\\|:\\)="
6914 (vhdl-point 'eol) t)
6915 (- (point) (vhdl-point 'boi)))))
6920 (while (and (not foundp)
6921 (< (point) (vhdl-point 'eol)))
6922 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6923 (if (vhdl-in-literal)
6925 (if (= (preceding-char) ?\()
6926 ;; skip over any parenthesized expressions
6927 (goto-char (min (vhdl-point 'eol)
6928 (scan-lists (point) 1 1)))
6929 ;; found an assignment operator (not at eol)
6930 (setq foundp (not (looking-at "\\s-*$"))))))
6932 ;; there's no assignment operator on the line
6934 ;; calculate indentation column after assign and ws, unless
6935 ;; our line contains an assignment operator
6939 (skip-chars-forward " \t")
6941 (- (current-column) assignp curcol))
6944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6945 ;; Progress reporting
6947 (defvar vhdl-progress-info nil
6948 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6950 (defun vhdl-update-progress-info (string pos)
6951 "Update progress information."
6952 (when (and vhdl-progress-info (not noninteractive)
6953 (< vhdl-progress-interval
6954 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6955 (let ((delta (- (aref vhdl-progress-info 1)
6956 (aref vhdl-progress-info 0))))
6958 (message (concat string "... (100%s)") "%")
6959 (message (concat string "... (%2d%s)")
6960 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6962 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6964 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6965 ;; Indentation commands
6967 (defun vhdl-electric-tab (&optional prefix-arg)
6968 "If preceeding character is part of a word or a paren then hippie-expand,
6969 else if right of non whitespace on line then insert tab,
6970 else if last command was a tab or return then dedent one step or if a comment
6971 toggle between normal indent and inline comment indent,
6972 else indent `correctly'."
6974 (vhdl-prepare-search-2
6976 ;; indent region if region is active
6977 ((and (not (featurep 'xemacs)) (use-region-p))
6978 (vhdl-indent-region (region-beginning) (region-end) nil))
6980 ((= (char-syntax (preceding-char)) ?w)
6981 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6983 (hippie-expand-only-buffers
6984 (or (and (boundp 'hippie-expand-only-buffers)
6985 hippie-expand-only-buffers)
6987 (vhdl-expand-abbrev prefix-arg)))
6988 ;; expand parenthesis
6989 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6990 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6992 (vhdl-expand-paren prefix-arg)))
6994 ((> (current-column) (current-indentation))
6996 ;; toggle comment indent
6997 ((and (looking-at "--")
6998 (or (eq last-command 'vhdl-electric-tab)
6999 (eq last-command 'vhdl-electric-return)))
7000 (cond ((= (current-indentation) 0) ; no indent
7002 (indent-according-to-mode))
7003 ((< (current-indentation) comment-column) ; normal indent
7004 (indent-to comment-column)
7005 (indent-according-to-mode))
7006 (t ; inline comment indent
7007 (delete-region (line-beginning-position) (point)))))
7009 ((and (>= (current-indentation) vhdl-basic-offset)
7010 (or (eq last-command 'vhdl-electric-tab)
7011 (eq last-command 'vhdl-electric-return)))
7012 (backward-delete-char-untabify vhdl-basic-offset nil))
7014 (t (indent-according-to-mode)))
7015 (setq this-command 'vhdl-electric-tab)))
7017 (defun vhdl-electric-return ()
7018 "newline-and-indent or indent-new-comment-line if in comment and preceding
7019 character is a space."
7021 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7022 (indent-new-comment-line)
7023 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7024 (vhdl-fix-case-word -1))
7025 (newline-and-indent)))
7027 (defun vhdl-indent-line ()
7028 "Indent the current line as VHDL code. Returns the amount of
7029 indentation change."
7031 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7032 (pos (- (point-max) (point)))
7035 ;; indent syntax-based
7036 (if (and (eq (caar syntax) 'comment)
7037 (>= (vhdl-get-offset (car syntax)) comment-column))
7038 ;; special case: comments at or right of comment-column
7039 (vhdl-get-offset (car syntax))
7040 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7041 ;; indent like previous nonblank line
7042 (save-excursion (beginning-of-line)
7043 (re-search-backward "^[^\n]" nil t)
7044 (current-indentation))))
7045 (shift-amt (- indent (current-indentation))))
7046 (and vhdl-echo-syntactic-information-p
7047 (message "syntax: %s, indent= %d" syntax indent))
7048 (unless (zerop shift-amt)
7049 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7052 (if (< (point) (vhdl-point 'boi))
7053 (back-to-indentation)
7054 ;; If initial point was within line's indentation, position after
7055 ;; the indentation. Else stay at same point in text.
7056 (when (> (- (point-max) pos) (point))
7057 (goto-char (- (point-max) pos))))
7058 (run-hooks 'vhdl-special-indent-hook)
7059 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7062 (defun vhdl-indent-region (beg end column)
7063 "Indent region as VHDL code.
7064 Adds progress reporting to `indent-region'."
7065 (interactive "r\nP")
7066 (when vhdl-progress-interval
7067 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7068 (count-lines (point-min) end) 0)))
7069 (indent-region beg end column)
7070 (when vhdl-progress-interval (message "Indenting...done"))
7071 (setq vhdl-progress-info nil))
7073 (defun vhdl-indent-buffer ()
7074 "Indent whole buffer as VHDL code.
7075 Calls `indent-region' for whole buffer and adds progress reporting."
7077 (vhdl-indent-region (point-min) (point-max) nil))
7079 (defun vhdl-indent-group ()
7080 "Indent group of lines between empty lines."
7082 (let ((beg (save-excursion
7083 (if (re-search-backward vhdl-align-group-separate nil t)
7085 (point-min-marker))))
7086 (end (save-excursion
7087 (if (re-search-forward vhdl-align-group-separate nil t)
7089 (point-max-marker)))))
7090 (vhdl-indent-region beg end nil)))
7092 (defun vhdl-indent-sexp (&optional endpos)
7093 "Indent each line of the list starting just after point.
7094 If optional arg ENDPOS is given, indent each line, stopping when
7095 ENDPOS is encountered."
7099 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7100 (indent-region beg end nil))))
7102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7103 ;; Miscellaneous commands
7105 (defun vhdl-show-syntactic-information ()
7106 "Show syntactic information for current line."
7108 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7109 (vhdl-keep-region-active))
7111 ;; Verification and regression functions:
7113 (defun vhdl-regress-line (&optional arg)
7114 "Check syntactic information for current line."
7116 (let ((expected (save-excursion
7118 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7120 (read (current-buffer)))))
7121 (actual (vhdl-get-syntactic-context))
7123 ;; remove the library unit symbols
7127 (if (memq (car elt) '(entity configuration package
7128 package-body architecture))
7130 (setq expurgated (append expurgated (list elt))))))
7132 (if (and (not arg) expected (listp expected))
7133 (if (not (equal expected expurgated))
7134 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7137 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7139 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7140 (delete-region (point) (line-end-position)))
7142 (insert (format "%s" expurgated))))))
7143 (vhdl-keep-region-active))
7146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7147 ;;; Alignment, whitespace fixup, beautifying
7148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7150 (defconst vhdl-align-alist
7152 ;; after some keywords
7153 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7154 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7156 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7157 ;; after direction specifications
7158 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7159 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7160 ;; before "==", ":=", "=>", and "<="
7161 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7162 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7163 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7164 ;; before some keywords
7165 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7166 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7167 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7168 ;; before "=>" since "when/else ... =>" can occur
7169 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7171 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7172 It is searched in order. If REGEXP is found anywhere in the first
7173 line of a region to be aligned, ALIGN-PATTERN will be used for that
7174 region. ALIGN-PATTERN must include the whitespace to be expanded or
7175 contracted. It may also provide regexps for the text surrounding the
7176 whitespace. SUBEXP specifies which sub-expression of
7177 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7182 (defvar vhdl-align-try-all-clauses t
7183 "If REGEXP is not found on the first line of the region that clause
7184 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7186 (defun vhdl-do-group (function &optional spacing)
7187 "Apply FUNCTION on group of lines between empty lines."
7189 ;; search for group beginning
7190 ((beg (save-excursion
7191 (if (re-search-backward vhdl-align-group-separate nil t)
7192 (progn (beginning-of-line 2) (back-to-indentation) (point))
7194 ;; search for group end
7195 (end (save-excursion
7196 (if (re-search-forward vhdl-align-group-separate nil t)
7197 (progn (beginning-of-line) (point))
7200 (funcall function beg end spacing)))
7202 (defun vhdl-do-list (function &optional spacing)
7203 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7207 ;; search for beginning of balanced group of parentheses
7208 (setq beg (vhdl-re-search-backward "[()]" nil t))
7209 (while (looking-at ")")
7210 (forward-char) (backward-sexp)
7211 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7212 ;; search for end of balanced group of parentheses
7216 (goto-char (1+ beg))
7217 (skip-chars-forward " \t\n")
7218 (setq beg (point))))
7221 (funcall function beg end spacing)
7222 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7224 (defun vhdl-do-same-indent (function &optional spacing)
7225 "Apply FUNCTION to block of lines with same indent."
7226 (let ((indent (current-indentation))
7228 ;; search for first line with same indent
7230 (while (and (not (bobp))
7231 (or (looking-at "^\\s-*\\(--.*\\)?$")
7232 (= (current-indentation) indent)))
7233 (unless (looking-at "^\\s-*$")
7234 (back-to-indentation) (setq beg (point)))
7235 (beginning-of-line -0)))
7236 ;; search for last line with same indent
7238 (while (and (not (eobp))
7239 (or (looking-at "^\\s-*\\(--.*\\)?$")
7240 (= (current-indentation) indent)))
7241 (if (looking-at "^\\s-*$")
7242 (beginning-of-line 2)
7243 (beginning-of-line 2)
7244 (setq end (point)))))
7246 (funcall function beg end spacing)))
7248 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7249 "Attempt to align a range of lines based on the content of the
7250 lines. The definition of `alignment-list' determines the matching
7251 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7252 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7253 indentation is done before aligning."
7254 (interactive "r\np")
7255 (setq alignment-list (or alignment-list vhdl-align-alist))
7256 (setq spacing (or spacing 1))
7260 (setq end (point-marker))
7262 (setq bol (setq begin (progn (beginning-of-line) (point))))
7263 ; (untabify bol end)
7265 (indent-region bol end nil))))
7266 (let ((copy (copy-alist alignment-list)))
7267 (vhdl-prepare-search-2
7272 (eol (point-at-eol)))
7273 (setq element (nth 0 copy))
7274 (when (and (or (and (listp (car element))
7275 (memq major-mode (car element)))
7276 (eq major-mode (car element)))
7277 (or vhdl-align-try-all-clauses
7278 (re-search-forward (car (cdr element)) eol t)))
7279 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7280 (car (cdr (cdr (cdr element)))) spacing))
7281 (setq copy (cdr copy))))))))
7283 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7284 "Align a range of lines from BEGIN to END. The regular expression
7285 MATCH must match exactly one field: the whitespace to be
7286 contracted/expanded. The alignment column will equal the
7287 rightmost column of the widest whitespace block. SPACING is
7288 the amount of extra spaces to add to the calculated maximum required.
7289 SPACING defaults to 1 so that at least one space is inserted after
7290 the token in MATCH."
7291 (setq spacing (or spacing 1))
7292 (setq substr (or substr 1))
7294 (let (distance (max 0) (lines 0) bol eol width)
7295 ;; Determine the greatest whitespace distance to the alignment
7298 (setq eol (point-at-eol)
7299 bol (setq begin (progn (beginning-of-line) (point))))
7302 (when (and (re-search-forward match eol t)
7303 (not (vhdl-in-literal)))
7304 (setq distance (- (match-beginning substr) bol))
7305 (when (> distance max)
7306 (setq max distance))))
7310 (setq lines (1+ lines)))
7311 ;; Now insert enough maxs to push each assignment operator to
7312 ;; the same column. We need to use 'lines' as a counter, since
7313 ;; the location of the mark may change
7314 (goto-char (setq bol begin))
7315 (setq eol (point-at-eol))
7317 (when (and (re-search-forward match eol t)
7318 (not (vhdl-in-literal)))
7319 (setq width (- (match-end substr) (match-beginning substr)))
7320 (setq distance (- (match-beginning substr) bol))
7321 (goto-char (match-beginning substr))
7323 (insert-char ? (+ (- max distance) spacing)))
7328 (setq lines (1- lines))))))
7330 (defun vhdl-align-region-groups (beg end &optional spacing
7331 no-message no-comments)
7332 "Align region, treat groups of lines separately."
7333 (interactive "r\nP")
7338 (setq orig (point-marker))
7341 (setq end (point-marker))
7344 (when vhdl-progress-interval
7345 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7346 (count-lines (point-min) end) 0))))
7347 (vhdl-fixup-whitespace-region beg end t)
7349 (if (not vhdl-align-groups)
7350 ;; align entire region
7351 (progn (vhdl-align-region-1 beg end spacing)
7353 (vhdl-align-inline-comment-region-1 beg end)))
7355 (while (and (< beg end)
7356 (re-search-forward vhdl-align-group-separate end t))
7357 (setq pos (point-marker))
7358 (vhdl-align-region-1 beg pos spacing)
7359 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7360 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7365 (vhdl-align-region-1 beg end spacing)
7366 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7367 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7368 (when vhdl-indent-tabs-mode
7371 (when vhdl-progress-interval (message "Aligning...done"))
7372 (setq vhdl-progress-info nil)))))
7374 (defun vhdl-align-region (beg end &optional spacing)
7375 "Align region, treat blocks with same indent and argument lists separately."
7376 (interactive "r\nP")
7377 (if (not vhdl-align-same-indent)
7378 ;; align entire region
7379 (vhdl-align-region-groups beg end spacing)
7380 ;; align blocks with same indent and argument lists
7384 (when vhdl-progress-interval
7385 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7386 (count-lines (point-min) end) 0)))
7388 (setq end (point-marker))
7390 (while (< (point) end)
7391 ;; is argument list opening?
7392 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7393 (point) (vhdl-point 'eol)))))
7394 ;; determine region for argument list
7395 (progn (goto-char cur-beg)
7397 (setq cur-end (point))
7398 (beginning-of-line 2))
7399 ;; determine region with same indent
7400 (setq indent (current-indentation))
7401 (setq cur-beg (point))
7402 (setq cur-end (vhdl-point 'bonl))
7403 (beginning-of-line 2)
7404 (while (and (< (point) end)
7405 (or (looking-at "^\\s-*\\(--.*\\)?$")
7406 (= (current-indentation) indent))
7408 (nth 0 (parse-partial-sexp
7409 (point) (vhdl-point 'eol)))) 0))
7410 (unless (looking-at "^\\s-*$")
7411 (setq cur-end (vhdl-point 'bonl)))
7412 (beginning-of-line 2)))
7414 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7415 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7416 (when vhdl-progress-interval (message "Aligning...done"))
7417 (setq vhdl-progress-info nil)))))
7419 (defun vhdl-align-group (&optional spacing)
7420 "Align group of lines between empty lines."
7422 (vhdl-do-group 'vhdl-align-region spacing))
7424 (defun vhdl-align-list (&optional spacing)
7425 "Align the lines of a list surrounded by a balanced group of parentheses."
7427 (vhdl-do-list 'vhdl-align-region-groups spacing))
7429 (defun vhdl-align-same-indent (&optional spacing)
7430 "Align block of lines with same indent."
7432 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7434 (defun vhdl-align-declarations (&optional spacing)
7435 "Align the lines within the declarative part of a design unit."
7438 (vhdl-prepare-search-2
7440 ;; search for declarative part
7441 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7442 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7444 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7445 (setq end (point)))))
7447 (vhdl-align-region-groups beg end spacing)
7448 (error "ERROR: Not within the declarative part of a design unit"))))
7450 (defun vhdl-align-buffer ()
7453 (vhdl-align-region (point-min) (point-max)))
7455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7456 ;; Align inline comments
7458 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7459 "Align inline comments in region."
7461 (let ((start-max comment-column)
7463 comment-list start-list tmp-list start length
7464 cur-start prev-start no-code)
7465 (setq spacing (or spacing 2))
7466 (vhdl-prepare-search-2
7468 ;; search for comment start positions and lengths
7469 (while (< (point) end)
7470 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7471 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7472 (not (save-excursion (goto-char (match-beginning 2))
7473 (vhdl-in-literal))))
7474 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7475 (setq length (- (match-end 2) (match-beginning 2)))
7476 (setq start-max (max start start-max))
7477 (setq length-max (max length length-max))
7478 (setq comment-list (cons (cons start length) comment-list)))
7479 (beginning-of-line 2))
7481 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7482 ;; reduce start positions
7483 (setq start-list (list (caar comment-list)))
7484 (setq comment-list (cdr comment-list))
7486 (unless (or (= (caar comment-list) (car start-list))
7487 (<= (+ (car start-list) (cdar comment-list))
7488 end-comment-column))
7489 (setq start-list (cons (caar comment-list) start-list)))
7490 (setq comment-list (cdr comment-list)))
7491 ;; align lines as nicely as possible
7493 (while (< (point) end)
7494 (setq cur-start nil)
7495 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7496 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7497 (not (save-excursion
7498 (goto-char (match-beginning 3))
7499 (vhdl-in-literal))))
7500 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7501 (>= (- (match-end 2) (match-beginning 2))
7503 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7504 (setq length (- (match-end 3) (match-beginning 3)))
7505 (setq no-code (= (match-beginning 1) (match-end 1)))
7506 ;; insert minimum whitespace
7507 (goto-char (match-end 2))
7508 (delete-region (match-beginning 2) (match-end 2))
7509 (insert-char ?\ spacing)
7510 (setq tmp-list start-list)
7511 ;; insert additional whitespace to align
7514 ;; align comment-only line to inline comment of previous line
7515 ((and no-code prev-start
7516 (<= length (- end-comment-column prev-start)))
7518 ;; align all comments at `start-max' if this is possible
7519 ((<= (+ start-max length-max) end-comment-column)
7521 ;; align at `comment-column' if possible
7522 ((and (<= start comment-column)
7523 (<= length (- end-comment-column comment-column)))
7525 ;; align at left-most possible start position otherwise
7527 (while (and tmp-list (< (car tmp-list) start))
7528 (setq tmp-list (cdr tmp-list)))
7530 (indent-to cur-start))
7531 (setq prev-start cur-start)
7532 (beginning-of-line 2))))))
7534 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7535 "Align inline comments within a region. Groups of code lines separated by
7536 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7537 (interactive "r\nP")
7542 (setq orig (point-marker))
7545 (setq end (point-marker))
7547 (unless no-message (message "Aligning inline comments..."))
7549 (if (not vhdl-align-groups)
7550 ;; align entire region
7551 (vhdl-align-inline-comment-region-1 beg end spacing)
7553 (while (and (< beg end)
7554 (re-search-forward vhdl-align-group-separate end t))
7555 (setq pos (point-marker))
7556 (vhdl-align-inline-comment-region-1 beg pos spacing)
7561 (vhdl-align-inline-comment-region-1 beg end spacing)))
7562 (when vhdl-indent-tabs-mode
7564 (unless no-message (message "Aligning inline comments...done")))))
7566 (defun vhdl-align-inline-comment-group (&optional spacing)
7567 "Align inline comments within a group of lines between empty lines."
7570 (let ((start (point))
7572 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7573 (point-marker) (point-max)))
7575 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7576 (point) (point-min)))
7578 (message "Aligning inline comments...")
7579 (vhdl-align-inline-comment-region-1 beg end)
7580 (when vhdl-indent-tabs-mode
7582 (message "Aligning inline comments...done"))))
7584 (defun vhdl-align-inline-comment-buffer ()
7585 "Align inline comments within buffer. Groups of code lines separated by
7586 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7588 (vhdl-align-inline-comment-region (point-min) (point-max)))
7590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7593 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7594 "Fixup whitespace in region. Surround operator symbols by one space,
7595 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7596 end of line, do nothing in comments and strings."
7598 (unless no-message (message "Fixing up whitespace..."))
7601 (setq end (point-marker))
7602 ;; have no space before and one space after `,' and ';'
7604 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7605 (if (match-string 1)
7606 (goto-char (match-end 1))
7607 (replace-match "\\3 " nil nil nil 3)))
7608 ;; have no space after `('
7610 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7611 (if (match-string 1)
7612 (goto-char (match-end 1))
7613 (replace-match "\\2")))
7614 ;; have no space before `)'
7616 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7617 (if (match-string 1)
7618 (goto-char (match-end 1))
7619 (replace-match "\\2")))
7620 ;; surround operator symbols by one space
7622 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7623 (if (match-string 1)
7624 (goto-char (match-end 1))
7625 (replace-match "\\3 \\4 \\5")
7626 (goto-char (match-end 2))))
7627 ;; eliminate multiple spaces and spaces at end of line
7629 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7630 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7631 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7632 (progn (replace-match "" nil nil) t))
7633 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7634 (progn (replace-match ";" nil nil) t))
7635 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7636 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7637 (progn (replace-match " " nil nil) t))
7638 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7639 (progn (replace-match " " nil nil) t))
7640 ; (re-search-forward "[^ \t-]+" end t))))
7641 (re-search-forward "[^ \t\"-]+" end t))))
7642 (unless no-message (message "Fixing up whitespace...done")))
7644 (defun vhdl-fixup-whitespace-buffer ()
7645 "Fixup whitespace in buffer. Surround operator symbols by one space,
7646 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7647 end of line, do nothing in comments."
7649 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7654 (defun vhdl-beautify-region (beg end)
7655 "Beautify region by applying indentation, whitespace fixup, alignment, and
7656 case fixing to a region. Calls functions `vhdl-indent-buffer',
7657 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7658 `vhdl-fix-case-buffer'."
7660 (setq end (save-excursion (goto-char end) (point-marker)))
7661 (vhdl-indent-region beg end nil)
7662 (let ((vhdl-align-groups t))
7663 (vhdl-align-region beg end))
7664 (vhdl-fix-case-region beg end))
7666 (defun vhdl-beautify-buffer ()
7667 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7668 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7671 (vhdl-beautify-region (point-min) (point-max))
7672 (when noninteractive (save-buffer)))
7674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7677 (defun vhdl-fill-region (beg end &optional arg)
7678 "Fill lines for a region of code."
7679 (interactive "r\np")
7682 (let ((margin (if arg (current-indentation) (current-column))))
7684 (setq end (point-marker))
7685 ;; remove inline comments, newlines and whitespace
7686 (vhdl-comment-kill-region beg end)
7687 (vhdl-comment-kill-inline-region beg end)
7688 (subst-char-in-region beg (1- end) ?\n ?\ )
7689 (vhdl-fixup-whitespace-region beg end)
7690 ;; wrap and end-comment-column
7692 (while (re-search-forward "\\s-" end t)
7693 (when(> (current-column) vhdl-end-comment-column)
7695 (when (re-search-backward "\\s-" beg t)
7696 (replace-match "\n")
7697 (indent-to margin)))))))
7699 (defun vhdl-fill-group ()
7700 "Fill group of lines between empty lines."
7702 (vhdl-do-group 'vhdl-fill-region))
7704 (defun vhdl-fill-list ()
7705 "Fill the lines of a list surrounded by a balanced group of parentheses."
7707 (vhdl-do-list 'vhdl-fill-region))
7709 (defun vhdl-fill-same-indent ()
7710 "Fill the lines of block of lines with same indent."
7712 (vhdl-do-same-indent 'vhdl-fill-region))
7715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7716 ;;; Code updating/fixing
7717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7720 ;; Sensitivity list update
7723 ;; - no sensitivity list is generated for processes with wait statements
7724 ;; - otherwise, do the following:
7725 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7726 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7727 ;; manually entered global signals)
7728 ;; 3. signals from 1. and 2. form the list of visible signals
7729 ;; 4. search for if/elsif conditions containing an event (sequential code)
7730 ;; 5. scan for strings that are within syntactical regions where signals are
7731 ;; read but not within sequential code, and that correspond to visible
7733 ;; 6. replace sensitivity list by list of signals from 5.
7735 (defun vhdl-update-sensitivity-list-process ()
7736 "Update sensitivity list of current process."
7739 (vhdl-prepare-search-2
7741 ;; look whether in process
7742 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7743 (equal (upcase (match-string 2)) "PROCESS")
7744 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7745 (error "ERROR: Not within a process")
7746 (message "Updating sensitivity list...")
7747 (vhdl-update-sensitivity-list)
7748 (message "Updating sensitivity list...done")))))
7750 (defun vhdl-update-sensitivity-list-buffer ()
7751 "Update sensitivity list of all processes in current buffer."
7754 (vhdl-prepare-search-2
7755 (goto-char (point-min))
7756 (message "Updating sensitivity lists...")
7757 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7758 (goto-char (match-beginning 0))
7759 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7760 (message "Updating sensitivity lists...done"))))
7762 (defun vhdl-update-sensitivity-list ()
7763 "Update sensitivity list."
7764 (let ((proc-beg (point))
7765 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7766 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7769 ;; search for wait statement (no sensitivity list allowed)
7770 ((progn (goto-char proc-mid)
7771 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7772 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7773 ;; combinational process (update sensitivity list)
7776 ;; scan for visible signals
7777 ((visible-list (vhdl-get-visible-signals))
7778 ;; define syntactic regions where signals are read
7780 '(;; right-hand side of signal/variable assignment
7781 ;; (special case: "<=" is relational operator in a condition)
7782 ((re-search-forward "[<:]=" proc-end t)
7783 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7785 ((re-search-forward "^\\s-*if\\>" proc-end t)
7786 (re-search-forward "\\<then\\>" proc-end t))
7788 ((re-search-forward "\\<elsif\\>" proc-end t)
7789 (re-search-forward "\\<then\\>" proc-end t))
7790 ;; while loop condition
7791 ((re-search-forward "^\\s-*while\\>" proc-end t)
7792 (re-search-forward "\\<loop\\>" proc-end t))
7793 ;; exit/next condition
7794 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7795 (re-search-forward ";" proc-end t))
7797 ((re-search-forward "\\<assert\\>" proc-end t)
7798 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7800 ((re-search-forward "^\\s-*case\\>" proc-end t)
7801 (re-search-forward "\\<is\\>" proc-end t))
7802 ;; parameter list of procedure call
7803 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7805 (progn (backward-char) (forward-sexp)
7806 (while (looking-at "(") (forward-sexp)) (point)))))
7807 name read-list sens-list signal-list
7808 sens-beg sens-end beg end margin)
7809 ;; scan for signals in old sensitivity list
7810 (goto-char proc-beg)
7811 (re-search-forward "\\<process\\>" proc-mid t)
7812 (if (not (looking-at "[ \t\n]*("))
7813 (setq sens-beg (point))
7814 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7815 (goto-char (match-end 1))
7817 (setq sens-end (1- (point)))
7818 (goto-char sens-beg)
7819 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7821 (cons (downcase (match-string 0)) sens-list))
7822 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7823 (setq signal-list (append visible-list sens-list))
7824 ;; search for sequential parts
7825 (goto-char proc-mid)
7826 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7827 (setq end (re-search-forward "\\<then\\>" proc-end t))
7828 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7832 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7833 (beginning-of-line)))
7834 ;; scan for signals read in process
7835 (while scan-regions-list
7836 (goto-char proc-mid)
7837 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7838 (setq end (eval (nth 1 (car scan-regions-list)))))
7840 (unless (or (vhdl-in-literal)
7841 (and seq-region-list
7842 (let ((tmp-list seq-region-list))
7843 (while (and tmp-list
7844 (< (point) (caar tmp-list)))
7845 (setq tmp-list (cdr tmp-list)))
7846 (and tmp-list (< (point) (cdar tmp-list))))))
7847 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7848 (setq name (match-string 1))
7849 (when (and (not (match-string 4)) ; not when formal parameter
7850 (not (and (match-string 3) ; not event attribute
7851 (not (member (downcase (match-string 3))
7852 '("event" "last_event" "transaction")))))
7853 (member (downcase name) signal-list))
7854 (unless (member-ignore-case name read-list)
7855 (setq read-list (cons name read-list))))
7856 (goto-char (match-end 1)))))
7857 (setq scan-regions-list (cdr scan-regions-list)))
7858 ;; update sensitivity list
7859 (goto-char sens-beg)
7861 (delete-region sens-beg sens-end)
7863 (insert " ()") (backward-char)))
7864 (setq read-list (sort read-list 'string<))
7866 (setq margin (current-column))
7867 (insert (car read-list))
7868 (setq read-list (cdr read-list))
7871 (if (<= (+ (current-column) (length (car read-list)) 2)
7874 (insert "\n") (indent-to margin))
7875 (insert (car read-list))
7876 (setq read-list (cdr read-list)))))))))
7878 (defun vhdl-get-visible-signals ()
7879 "Get all signals visible in the current block."
7880 (let (beg end signal-list entity-name file-name)
7881 (vhdl-prepare-search-2
7884 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7885 (not (equal "END" (upcase (match-string 1))))
7886 (setq entity-name (match-string 2)))
7887 (error "ERROR: Not within an architecture")))
7888 ;; search for signals declared in entity port clause
7890 (goto-char (point-min))
7891 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7893 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7894 "." (file-name-extension (buffer-file-name)))))
7897 (vhdl-prepare-search-2
7898 (goto-char (point-min))
7899 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7900 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7901 (when (setq beg (re-search-forward
7902 "^\\s-*port[ \t\n]*("
7904 (re-search-forward "^end\\>" nil t)) t))
7905 (setq end (save-excursion
7906 (backward-char) (forward-sexp) (point)))
7907 (vhdl-forward-syntactic-ws)
7908 (while (< (point) end)
7909 (when (looking-at "signal[ \t\n]+")
7910 (goto-char (match-end 0)))
7911 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7913 (cons (downcase (match-string 1)) signal-list))
7914 (goto-char (match-end 0))
7915 (vhdl-forward-syntactic-ws))
7916 (re-search-forward ";" end 1)
7917 (vhdl-forward-syntactic-ws)))))))
7918 ;; search for signals declared in architecture declarative part
7920 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7921 (not (equal "END" (upcase (match-string 1))))
7922 (setq end (re-search-forward "^begin\\>" nil t))))
7923 (error "ERROR: No architecture declarative part found")
7924 ;; scan for all declared signal and alias names
7926 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7927 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7928 (if (match-string 2)
7930 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7932 (cons (downcase (match-string 1)) signal-list))
7933 (goto-char (match-end 0)))
7934 ;; scan alias name, check is alias of (declared) signal
7935 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7936 (member (downcase (match-string 2)) signal-list))
7938 (cons (downcase (match-string 1)) signal-list))
7939 (goto-char (match-end 0))))
7940 (setq beg (point))))))
7941 ;; search for signals declared in surrounding block declarative parts
7943 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7945 (goto-char (match-end 2))
7946 (vhdl-backward-sexp)
7947 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7949 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7950 ;; scan for all declared signal names
7952 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7953 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7954 (if (match-string 2)
7956 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7958 (cons (downcase (match-string 1)) signal-list))
7959 (goto-char (match-end 0)))
7960 ;; scan alias name, check is alias of (declared) signal
7961 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7962 (member (downcase (match-string 2)) signal-list))
7964 (cons (downcase (match-string 1)) signal-list))
7965 (goto-char (match-end 0))))))
7969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7970 ;; Generic/port clause fixing
7972 (defun vhdl-fix-clause ()
7973 "Fix closing parenthesis within generic/port clause."
7976 (vhdl-prepare-search-2
7979 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7980 (error "ERROR: Not within a generic/port clause")
7981 ;; search for end of clause
7982 (goto-char (match-end 0))
7983 (setq beg (1- (point)))
7984 (vhdl-forward-syntactic-ws)
7985 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7986 (goto-char (1- (match-end 0)))
7987 (setq end (point-marker))
7989 (vhdl-forward-syntactic-ws))
7991 (when (> pos (point-at-eol))
7992 (error "ERROR: Not within a generic/port clause"))
7993 ;; delete closing parenthesis on separate line (not supported style)
7994 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7996 (vhdl-backward-syntactic-ws)
7997 (setq end (point-marker))
7999 ;; delete superfluous parentheses
8000 (while (progn (goto-char beg)
8001 (condition-case () (forward-sexp)
8002 (error (goto-char (point-max))))
8005 ;; add closing parenthesis
8006 (when (> (point) end)
8010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8013 (defun vhdl-remove-trailing-spaces ()
8014 "Remove trailing spaces in the whole buffer."
8018 (goto-char (point-min))
8019 (while (re-search-forward "[ \t]+$" (point-max) t)
8020 (unless (vhdl-in-literal)
8021 (replace-match "" nil nil))))))
8024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8028 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8029 "Syntax of prompt inserted by template generators.")
8031 (defvar vhdl-template-invoked-by-hook nil
8032 "Indicates whether a template has been invoked by a hook or by key or menu.
8033 Used for undoing after template abortion.")
8035 ;; correct different behavior of function `unread-command-events' in XEmacs
8036 (defun vhdl-character-to-event (arg))
8037 (defalias 'vhdl-character-to-event
8038 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8040 (defun vhdl-work-library ()
8041 "Return the working library name of the current project or \"work\" if no
8042 project is defined."
8043 (vhdl-resolve-env-variable
8044 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8047 ;; Enabling/disabling
8049 (define-minor-mode vhdl-electric-mode
8050 "Toggle VHDL electric mode.
8051 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8054 (define-minor-mode vhdl-stutter-mode
8055 "Toggle VHDL stuttering mode.
8056 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8062 (defun vhdl-electric-dash (count)
8063 "-- starts a comment, --- draws a horizontal line,
8064 ---- starts a display comment."
8066 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8068 ((and abbrev-start-location (= abbrev-start-location (point)))
8069 (setq abbrev-start-location nil)
8070 (goto-char last-abbrev-location)
8071 (beginning-of-line nil)
8072 (vhdl-comment-display))
8073 ((/= (preceding-char) ?-) ; standard dash (minus)
8074 (self-insert-command count))
8075 (t (self-insert-command count)
8076 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8077 (let ((next-input (read-char)))
8078 (if (= next-input ?-) ; triple dash
8080 (vhdl-comment-display-line)
8082 "Enter '-' for display comment, else continue coding")
8083 (let ((next-input (read-char)))
8084 (if (= next-input ?-) ; four dashes
8085 (vhdl-comment-display t)
8086 (setq unread-command-events ; pushback the char
8087 (list (vhdl-character-to-event next-input))))))
8088 (setq unread-command-events ; pushback the char
8089 (list (vhdl-character-to-event next-input)))
8090 (vhdl-comment-insert)))))
8091 (self-insert-command count)))
8093 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8095 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8096 (if (= (preceding-char) ?\()
8097 (progn (delete-char -1) (insert-char ?\[ 1))
8098 (insert-char ?\( 1))
8099 (self-insert-command count)))
8101 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8103 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8105 (if (= (preceding-char) ?\))
8106 (progn (delete-char -1) (insert-char ?\] 1))
8107 (insert-char ?\) 1))
8108 (blink-matching-open))
8109 (self-insert-command count)))
8111 (defun vhdl-electric-quote (count) "'' --> \""
8113 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8114 (if (= (preceding-char) last-input-event)
8115 (progn (delete-char -1) (insert-char ?\" 1))
8116 (insert-char ?\' 1))
8117 (self-insert-command count)))
8119 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8121 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8122 (cond ((= (preceding-char) last-input-event)
8123 (progn (delete-char -1)
8124 (unless (eq (preceding-char) ? ) (insert " "))
8126 (setq this-command 'vhdl-electric-colon)))
8128 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8129 (progn (delete-char -1) (insert "= ")))
8130 (t (insert-char ?\; 1)))
8131 (self-insert-command count)))
8133 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8135 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8136 (cond ((= (preceding-char) last-input-event)
8137 (progn (delete-char -1)
8138 (unless (eq (preceding-char) ? ) (insert " "))
8140 (t (insert-char ?\, 1)))
8141 (self-insert-command count)))
8143 (defun vhdl-electric-period (count) "'..' --> ' => '"
8145 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8146 (cond ((= (preceding-char) last-input-event)
8147 (progn (delete-char -1)
8148 (unless (eq (preceding-char) ? ) (insert " "))
8150 (t (insert-char ?\. 1)))
8151 (self-insert-command count)))
8153 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8155 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8156 (cond ((= (preceding-char) last-input-event)
8157 (progn (delete-char -1)
8158 (unless (eq (preceding-char) ? ) (insert " "))
8160 (t (insert-char ?\= 1)))
8161 (self-insert-command count)))
8163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8166 (defun vhdl-template-paired-parens ()
8167 "Insert a pair of round parentheses, placing point between them."
8172 (defun vhdl-template-alias ()
8173 "Insert alias declaration."
8175 (let ((start (point)))
8176 (vhdl-insert-keyword "ALIAS ")
8177 (when (vhdl-template-field "name" nil t start (point))
8179 (unless (vhdl-template-field
8180 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8183 (vhdl-insert-keyword " IS ")
8184 (vhdl-template-field "name" ";")
8185 (vhdl-comment-insert-inline))))
8187 (defun vhdl-template-architecture ()
8188 "Insert architecture."
8190 (let ((margin (current-indentation))
8193 (vhdl-insert-keyword "ARCHITECTURE ")
8194 (when (setq arch-name
8195 (vhdl-template-field "name" nil t start (point)))
8196 (vhdl-insert-keyword " OF ")
8198 (vhdl-prepare-search-1
8199 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8200 (insert (match-string 1))
8201 (vhdl-template-field "entity name"))
8202 (vhdl-insert-keyword " IS\n")
8203 (vhdl-template-begin-end
8204 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8205 (memq vhdl-insert-empty-lines '(unit all))))))
8207 (defun vhdl-template-array (kind &optional secondary)
8208 "Insert array type definition."
8210 (let ((start (point)))
8211 (vhdl-insert-keyword "ARRAY (")
8212 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8214 (vhdl-insert-keyword ") OF ")
8215 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8216 (vhdl-insert-keyword ";"))))
8218 (defun vhdl-template-assert ()
8219 "Insert an assertion statement."
8221 (let ((start (point)))
8222 (vhdl-insert-keyword "ASSERT ")
8223 (when vhdl-conditions-in-parenthesis (insert "("))
8224 (when (vhdl-template-field "condition (negated)" nil t start (point))
8225 (when vhdl-conditions-in-parenthesis (insert ")"))
8226 (setq start (point))
8227 (vhdl-insert-keyword " REPORT ")
8228 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8229 (delete-region start (point)))
8230 (setq start (point))
8231 (vhdl-insert-keyword " SEVERITY ")
8232 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8233 (delete-region start (point)))
8236 (defun vhdl-template-attribute ()
8237 "Insert an attribute declaration or specification."
8239 (if (eq (vhdl-decision-query
8240 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8241 (vhdl-template-attribute-spec)
8242 (vhdl-template-attribute-decl)))
8244 (defun vhdl-template-attribute-decl ()
8245 "Insert an attribute declaration."
8247 (let ((start (point)))
8248 (vhdl-insert-keyword "ATTRIBUTE ")
8249 (when (vhdl-template-field "name" " : " t start (point))
8250 (vhdl-template-field "type" ";")
8251 (vhdl-comment-insert-inline))))
8253 (defun vhdl-template-attribute-spec ()
8254 "Insert an attribute specification."
8256 (let ((start (point)))
8257 (vhdl-insert-keyword "ATTRIBUTE ")
8258 (when (vhdl-template-field "name" nil t start (point))
8259 (vhdl-insert-keyword " OF ")
8260 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8261 (vhdl-template-field "entity class")
8262 (vhdl-insert-keyword " IS ")
8263 (vhdl-template-field "expression" ";"))))
8265 (defun vhdl-template-block ()
8268 (let ((margin (current-indentation))
8271 (vhdl-insert-keyword ": BLOCK ")
8273 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8277 (if (vhdl-template-field "[guard expression]" nil t)
8280 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8282 (vhdl-template-begin-end "BLOCK" label margin)
8283 (vhdl-comment-block))))
8285 (defun vhdl-template-block-configuration ()
8286 "Insert a block configuration statement."
8288 (let ((margin (current-indentation))
8290 (vhdl-insert-keyword "FOR ")
8291 (when (vhdl-template-field "block name" nil t start (point))
8292 (vhdl-insert-keyword "\n\n")
8294 (vhdl-insert-keyword "END FOR;")
8296 (indent-to (+ margin vhdl-basic-offset)))))
8298 (defun vhdl-template-break ()
8299 "Insert a break statement."
8302 (vhdl-insert-keyword "BREAK")
8303 (setq position (point))
8306 (progn (vhdl-insert-keyword "FOR ")
8307 (if (vhdl-template-field "[quantity name]" " USE " t)
8308 (progn (vhdl-template-field "quantity name" " => ") t)
8309 (delete-region (point)
8310 (progn (forward-word -1) (point)))
8312 (vhdl-template-field "[quantity name]" " => " t))
8313 (vhdl-template-field "expression")
8314 (setq position (point))
8316 (delete-region position (point))
8317 (unless (vhdl-sequential-statement-p)
8318 (vhdl-insert-keyword " ON ")
8319 (if (vhdl-template-field "[sensitivity list]" nil t)
8320 (setq position (point))
8321 (delete-region position (point))))
8322 (vhdl-insert-keyword " WHEN ")
8323 (when vhdl-conditions-in-parenthesis (insert "("))
8324 (if (vhdl-template-field "[condition]" nil t)
8325 (when vhdl-conditions-in-parenthesis (insert ")"))
8326 (delete-region position (point)))
8329 (defun vhdl-template-case (&optional kind)
8330 "Insert a case statement."
8332 (let ((margin (current-indentation))
8335 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8336 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8337 (vhdl-insert-keyword "CASE ")
8338 (vhdl-insert-keyword ": CASE ")
8340 (setq label (vhdl-template-field "[label]" nil t))
8341 (unless label (delete-char 2))
8344 (when (vhdl-template-field "expression" nil t start (point))
8345 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8347 (vhdl-insert-keyword "END CASE")
8348 (when label (insert " " label))
8351 (indent-to (+ margin vhdl-basic-offset))
8352 (vhdl-insert-keyword "WHEN ")
8353 (let ((position (point)))
8355 (indent-to (+ margin vhdl-basic-offset))
8356 (vhdl-insert-keyword "WHEN OTHERS => null;")
8357 (goto-char position)))))
8359 (defun vhdl-template-case-is ()
8360 "Insert a sequential case statement."
8362 (vhdl-template-case 'is))
8364 (defun vhdl-template-case-use ()
8365 "Insert a simultaneous case statement."
8367 (vhdl-template-case 'use))
8369 (defun vhdl-template-component ()
8370 "Insert a component declaration."
8372 (vhdl-template-component-decl))
8374 (defun vhdl-template-component-conf ()
8375 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8376 since these are almost equivalent)."
8378 (let ((margin (current-indentation))
8379 (result (vhdl-template-configuration-spec t)))
8383 (vhdl-insert-keyword "END FOR;")
8384 (when (eq result 'no-use)
8385 (end-of-line -0)))))
8387 (defun vhdl-template-component-decl ()
8388 "Insert a component declaration."
8390 (let ((margin (current-indentation))
8393 (vhdl-insert-keyword "COMPONENT ")
8394 (when (setq name (vhdl-template-field "name" nil t start (point)))
8395 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8398 (vhdl-insert-keyword "END COMPONENT")
8399 (unless (vhdl-standard-p '87) (insert " " name))
8401 (setq end-column (current-column))
8403 (indent-to (+ margin vhdl-basic-offset))
8404 (vhdl-template-generic-list t t)
8406 (indent-to (+ margin vhdl-basic-offset))
8407 (vhdl-template-port-list t)
8408 (beginning-of-line 2)
8409 (forward-char end-column))))
8411 (defun vhdl-template-component-inst ()
8412 "Insert a component instantiation statement."
8414 (let ((margin (current-indentation))
8417 (when (vhdl-template-field "instance label" nil t start (point))
8419 (if (not (vhdl-use-direct-instantiation))
8420 (vhdl-template-field "component name")
8421 ;; direct instantiation
8422 (setq unit (vhdl-template-field
8423 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8424 (setq unit (upcase (or unit "")))
8425 (cond ((equal unit "ENTITY")
8426 (vhdl-template-field "library name" "." nil nil nil nil
8427 (vhdl-work-library))
8428 (vhdl-template-field "entity name" "(")
8429 (if (vhdl-template-field "[architecture name]" nil t)
8432 ((equal unit "CONFIGURATION")
8433 (vhdl-template-field "library name" "." nil nil nil nil
8434 (vhdl-work-library))
8435 (vhdl-template-field "configuration name"))
8436 (t (vhdl-template-field "component name"))))
8438 (indent-to (+ margin vhdl-basic-offset))
8439 (setq position (point))
8440 (vhdl-insert-keyword "GENERIC ")
8441 (when (vhdl-template-map position t t)
8443 (indent-to (+ margin vhdl-basic-offset)))
8444 (setq position (point))
8445 (vhdl-insert-keyword "PORT ")
8446 (unless (vhdl-template-map position t t)
8447 (delete-region (line-beginning-position) (point))
8451 (defun vhdl-template-conditional-signal-asst ()
8452 "Insert a conditional signal assignment."
8454 (when (vhdl-template-field "target signal")
8456 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8458 (let ((margin (current-column))
8461 (vhdl-template-field "waveform")
8462 (setq position (point))
8463 (vhdl-insert-keyword " WHEN ")
8464 (when vhdl-conditions-in-parenthesis (insert "("))
8465 (while (and (vhdl-template-field "[condition]" nil t)
8467 (when vhdl-conditions-in-parenthesis (insert ")"))
8468 (setq position (point))
8469 (vhdl-insert-keyword " ELSE")
8472 (vhdl-template-field "[waveform]" nil t)))
8473 (setq position (point))
8474 (vhdl-insert-keyword " WHEN ")
8475 (when vhdl-conditions-in-parenthesis (insert "(")))
8476 (delete-region position (point))
8478 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8480 (defun vhdl-template-configuration ()
8481 "Insert a configuration specification if within an architecture,
8482 a block or component configuration if within a configuration declaration,
8483 a configuration declaration if not within a design unit."
8485 (vhdl-prepare-search-1
8487 ((and (save-excursion ; architecture body
8488 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8489 (equal "ARCHITECTURE" (upcase (match-string 1))))
8490 (vhdl-template-configuration-spec))
8491 ((and (save-excursion ; configuration declaration
8492 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8493 (equal "CONFIGURATION" (upcase (match-string 1))))
8494 (if (eq (vhdl-decision-query
8495 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8496 (vhdl-template-component-conf)
8497 (vhdl-template-block-configuration)))
8498 (t (vhdl-template-configuration-decl))))) ; otherwise
8500 (defun vhdl-template-configuration-spec (&optional optional-use)
8501 "Insert a configuration specification."
8503 (let ((margin (current-indentation))
8506 (vhdl-insert-keyword "FOR ")
8507 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8509 (vhdl-template-field "component name" "\n")
8510 (indent-to (+ margin vhdl-basic-offset))
8511 (setq start (point))
8512 (vhdl-insert-keyword "USE ")
8513 (if (and optional-use
8514 (not (setq aspect (vhdl-template-field
8515 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8516 (progn (delete-region start (point)) 'no-use)
8517 (unless optional-use
8518 (setq aspect (vhdl-template-field
8519 "ENTITY | CONFIGURATION | OPEN" " ")))
8520 (setq aspect (upcase (or aspect "")))
8521 (cond ((equal aspect "ENTITY")
8522 (vhdl-template-field "library name" "." nil nil nil nil
8523 (vhdl-work-library))
8524 (vhdl-template-field "entity name" "(")
8525 (if (vhdl-template-field "[architecture name]" nil t)
8529 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8530 (setq position (point))
8531 (vhdl-insert-keyword "GENERIC ")
8532 (when (vhdl-template-map position t t)
8534 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8535 (setq position (point))
8536 (vhdl-insert-keyword "PORT ")
8537 (unless (vhdl-template-map position t t)
8538 (delete-region (line-beginning-position) (point))
8542 ((equal aspect "CONFIGURATION")
8543 (vhdl-template-field "library name" "." nil nil nil nil
8544 (vhdl-work-library))
8545 (vhdl-template-field "configuration name" ";"))
8546 (t (delete-char -1) (insert ";") t))))))
8549 (defun vhdl-template-configuration-decl ()
8550 "Insert a configuration declaration."
8552 (let ((margin (current-indentation))
8554 entity-exists string name position)
8555 (vhdl-insert-keyword "CONFIGURATION ")
8556 (when (setq name (vhdl-template-field "name" nil t start (point)))
8557 (vhdl-insert-keyword " OF ")
8559 (vhdl-prepare-search-1
8560 (setq entity-exists (vhdl-re-search-backward
8561 "\\<entity \\(\\w*\\) is\\>" nil t))
8562 (setq string (match-string 1))))
8563 (if (and entity-exists (not (equal string "")))
8565 (vhdl-template-field "entity name"))
8566 (vhdl-insert-keyword " IS\n")
8567 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8568 (indent-to (+ margin vhdl-basic-offset))
8569 (setq position (point))
8571 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8573 (vhdl-insert-keyword "END ")
8574 (unless (vhdl-standard-p '87)
8575 (vhdl-insert-keyword "CONFIGURATION "))
8577 (goto-char position))))
8579 (defun vhdl-template-constant ()
8580 "Insert a constant declaration."
8582 (let ((start (point))
8583 (in-arglist (vhdl-in-argument-list-p)))
8584 (vhdl-insert-keyword "CONSTANT ")
8585 (when (vhdl-template-field "name" nil t start (point))
8587 (when in-arglist (vhdl-insert-keyword "IN "))
8588 (vhdl-template-field "type")
8591 (vhdl-comment-insert-inline))
8592 (let ((position (point)))
8594 (unless (vhdl-template-field "[initialization]" nil t)
8595 (delete-region position (point)))
8597 (vhdl-comment-insert-inline))))))
8599 (defun vhdl-template-default ()
8608 (defun vhdl-template-default-indent ()
8609 "Insert nothing and indent."
8616 (indent-according-to-mode))
8618 (defun vhdl-template-disconnect ()
8619 "Insert a disconnect statement."
8621 (let ((start (point)))
8622 (vhdl-insert-keyword "DISCONNECT ")
8623 (when (vhdl-template-field "signal names | OTHERS | ALL"
8624 " : " t start (point))
8625 (vhdl-template-field "type")
8626 (vhdl-insert-keyword " AFTER ")
8627 (vhdl-template-field "time expression" ";"))))
8629 (defun vhdl-template-else ()
8630 "Insert an else statement."
8633 (vhdl-prepare-search-1
8634 (vhdl-insert-keyword "ELSE")
8635 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8636 (equal "WHEN" (upcase (match-string 1))))
8638 (indent-according-to-mode)
8639 (setq margin (current-indentation))
8641 (indent-to (+ margin vhdl-basic-offset))))))
8643 (defun vhdl-template-elsif ()
8644 "Insert an elsif statement."
8646 (let ((start (point))
8648 (vhdl-insert-keyword "ELSIF ")
8649 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8650 (when vhdl-conditions-in-parenthesis (insert "("))
8651 (when (vhdl-template-field "condition" nil t start (point))
8652 (when vhdl-conditions-in-parenthesis (insert ")"))
8653 (indent-according-to-mode)
8654 (setq margin (current-indentation))
8655 (vhdl-insert-keyword
8656 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8657 (indent-to (+ margin vhdl-basic-offset))))))
8659 (defun vhdl-template-entity ()
8662 (let ((margin (current-indentation))
8665 (vhdl-insert-keyword "ENTITY ")
8666 (when (setq name (vhdl-template-field "name" nil t start (point)))
8667 (vhdl-insert-keyword " IS\n\n")
8669 (vhdl-insert-keyword "END ")
8670 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8672 (setq end-column (current-column))
8674 (indent-to (+ margin vhdl-basic-offset))
8675 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8676 (indent-to (+ margin vhdl-basic-offset))
8677 (when (vhdl-template-generic-list t)
8678 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8680 (indent-to (+ margin vhdl-basic-offset))
8681 (when (vhdl-template-port-list t)
8682 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8683 (beginning-of-line 2)
8684 (forward-char end-column))))
8686 (defun vhdl-template-exit ()
8687 "Insert an exit statement."
8689 (let ((start (point)))
8690 (vhdl-insert-keyword "EXIT ")
8691 (if (vhdl-template-field "[loop label]" nil t start (point))
8692 (let ((position (point)))
8693 (vhdl-insert-keyword " WHEN ")
8694 (when vhdl-conditions-in-parenthesis (insert "("))
8695 (if (vhdl-template-field "[condition]" nil t)
8696 (when vhdl-conditions-in-parenthesis (insert ")"))
8697 (delete-region position (point))))
8701 (defun vhdl-template-file ()
8702 "Insert a file declaration."
8704 (let ((start (point)))
8705 (vhdl-insert-keyword "FILE ")
8706 (when (vhdl-template-field "name" nil t start (point))
8708 (vhdl-template-field "type")
8709 (unless (vhdl-standard-p '87)
8710 (vhdl-insert-keyword " OPEN ")
8711 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8714 (vhdl-insert-keyword " IS ")
8715 (when (vhdl-standard-p '87)
8716 (vhdl-template-field "[IN | OUT]" " " t))
8717 (vhdl-template-field "filename-string" nil nil nil nil t)
8719 (vhdl-comment-insert-inline))))
8721 (defun vhdl-template-for ()
8722 "Insert a block or component configuration if within a configuration
8723 declaration, a configuration specification if within an architecture
8724 declarative part (and not within a subprogram), a for-loop if within a
8725 sequential statement part (subprogram or process), and a for-generate
8728 (vhdl-prepare-search-1
8730 ((vhdl-sequential-statement-p) ; sequential statement
8731 (vhdl-template-for-loop))
8732 ((and (save-excursion ; configuration declaration
8733 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8734 (equal "CONFIGURATION" (upcase (match-string 1))))
8735 (if (eq (vhdl-decision-query
8736 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8737 (vhdl-template-component-conf)
8738 (vhdl-template-block-configuration)))
8739 ((and (save-excursion
8740 (re-search-backward ; architecture declarative part
8741 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8742 (equal "ARCHITECTURE" (upcase (match-string 1))))
8743 (vhdl-template-configuration-spec))
8744 (t (vhdl-template-for-generate))))) ; concurrent statement
8746 (defun vhdl-template-for-generate ()
8747 "Insert a for-generate."
8749 (let ((margin (current-indentation))
8752 (vhdl-insert-keyword ": FOR ")
8753 (setq position (point-marker))
8755 (when (setq label (vhdl-template-field "label" nil t start position))
8756 (goto-char position)
8757 (vhdl-template-field "loop variable")
8758 (vhdl-insert-keyword " IN ")
8759 (vhdl-template-field "range")
8760 (vhdl-template-generate-body margin label))))
8762 (defun vhdl-template-for-loop ()
8763 "Insert a for loop."
8765 (let ((margin (current-indentation))
8768 (if (not (eq vhdl-optional-labels 'all))
8769 (vhdl-insert-keyword "FOR ")
8770 (vhdl-insert-keyword ": FOR ")
8772 (setq label (vhdl-template-field "[label]" nil t))
8773 (unless label (delete-char 2))
8776 (when (setq index (vhdl-template-field "loop variable"
8777 nil t start (point)))
8778 (vhdl-insert-keyword " IN ")
8779 (vhdl-template-field "range")
8780 (vhdl-insert-keyword " LOOP\n\n")
8782 (vhdl-insert-keyword "END LOOP")
8784 (insert " " label ";")
8786 (when vhdl-self-insert-comments (insert " -- " index)))
8788 (indent-to (+ margin vhdl-basic-offset)))))
8790 (defun vhdl-template-function (&optional kind)
8791 "Insert a function declaration or body."
8793 (let ((margin (current-indentation))
8796 (vhdl-insert-keyword "FUNCTION ")
8797 (when (setq name (vhdl-template-field "name" nil t start (point)))
8798 (vhdl-template-argument-list t)
8799 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8802 (indent-to (+ margin vhdl-basic-offset))
8803 (vhdl-insert-keyword "RETURN ")
8804 (vhdl-template-field "type")
8805 (if (if kind (eq kind 'body)
8806 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8807 (progn (vhdl-insert-keyword " IS\n")
8808 (vhdl-template-begin-end
8809 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8810 (vhdl-comment-block))
8813 (defun vhdl-template-function-decl ()
8814 "Insert a function declaration."
8816 (vhdl-template-function 'decl))
8818 (defun vhdl-template-function-body ()
8819 "Insert a function declaration."
8821 (vhdl-template-function 'body))
8823 (defun vhdl-template-generate ()
8824 "Insert a generation scheme."
8826 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8827 (vhdl-template-if-generate)
8828 (vhdl-template-for-generate)))
8830 (defun vhdl-template-generic ()
8831 "Insert generic declaration, or generic map in instantiation statements."
8833 (let ((start (point)))
8834 (vhdl-prepare-search-1
8836 ((and (save-excursion ; entity declaration
8837 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8838 (equal "ENTITY" (upcase (match-string 1))))
8839 (vhdl-template-generic-list nil))
8840 ((or (save-excursion
8841 (or (beginning-of-line)
8842 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8843 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8844 (vhdl-insert-keyword "GENERIC ")
8845 (vhdl-template-map start))
8846 (t (vhdl-template-generic-list nil t))))))
8848 (defun vhdl-template-group ()
8849 "Insert group or group template declaration."
8851 (let ((start (point)))
8852 (if (eq (vhdl-decision-query
8853 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8854 (vhdl-template-group-template)
8855 (vhdl-template-group-decl))))
8857 (defun vhdl-template-group-decl ()
8858 "Insert group declaration."
8860 (let ((start (point)))
8861 (vhdl-insert-keyword "GROUP ")
8862 (when (vhdl-template-field "name" " : " t start (point))
8863 (vhdl-template-field "template name" " (")
8864 (vhdl-template-field "constituent list" ");")
8865 (vhdl-comment-insert-inline))))
8867 (defun vhdl-template-group-template ()
8868 "Insert group template declaration."
8870 (let ((start (point)))
8871 (vhdl-insert-keyword "GROUP ")
8872 (when (vhdl-template-field "template name" nil t start (point))
8873 (vhdl-insert-keyword " IS (")
8874 (vhdl-template-field "entity class list" ");")
8875 (vhdl-comment-insert-inline))))
8877 (defun vhdl-template-if ()
8878 "Insert a sequential if statement or an if-generate statement."
8880 (if (vhdl-sequential-statement-p)
8881 (vhdl-template-if-then)
8882 (if (and (vhdl-standard-p 'ams)
8883 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8884 (vhdl-template-if-use)
8885 (vhdl-template-if-generate))))
8887 (defun vhdl-template-if-generate ()
8888 "Insert an if-generate."
8890 (let ((margin (current-indentation))
8893 (vhdl-insert-keyword ": IF ")
8894 (setq position (point-marker))
8896 (when (setq label (vhdl-template-field "label" nil t start position))
8897 (goto-char position)
8898 (when vhdl-conditions-in-parenthesis (insert "("))
8899 (vhdl-template-field "condition")
8900 (when vhdl-conditions-in-parenthesis (insert ")"))
8901 (vhdl-template-generate-body margin label))))
8903 (defun vhdl-template-if-then-use (kind)
8904 "Insert a sequential if statement."
8906 (let ((margin (current-indentation))
8909 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8910 (vhdl-insert-keyword "IF ")
8911 (vhdl-insert-keyword ": IF ")
8913 (setq label (vhdl-template-field "[label]" nil t))
8914 (unless label (delete-char 2))
8917 (when vhdl-conditions-in-parenthesis (insert "("))
8918 (when (vhdl-template-field "condition" nil t start (point))
8919 (when vhdl-conditions-in-parenthesis (insert ")"))
8920 (vhdl-insert-keyword
8921 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8923 (vhdl-insert-keyword "END IF")
8924 (when label (insert " " label))
8927 (indent-to (+ margin vhdl-basic-offset)))))
8929 (defun vhdl-template-if-then ()
8930 "Insert a sequential if statement."
8932 (vhdl-template-if-then-use 'then))
8934 (defun vhdl-template-if-use ()
8935 "Insert a simultaneous if statement."
8937 (vhdl-template-if-then-use 'use))
8939 (defun vhdl-template-instance ()
8940 "Insert a component instantiation statement."
8942 (vhdl-template-component-inst))
8944 (defun vhdl-template-library ()
8945 "Insert a library specification."
8947 (let ((margin (current-indentation))
8950 (vhdl-insert-keyword "LIBRARY ")
8951 (when (setq name (vhdl-template-field "names" nil t start (point)))
8953 (unless (string-match "," name)
8954 (setq end-pos (point))
8957 (vhdl-insert-keyword "USE ")
8959 (vhdl-insert-keyword "..ALL;")
8961 (if (vhdl-template-field "package name")
8963 (delete-region end-pos (+ (point) 5)))))))
8965 (defun vhdl-template-limit ()
8968 (let ((start (point)))
8969 (vhdl-insert-keyword "LIMIT ")
8970 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8972 (vhdl-template-field "type")
8973 (vhdl-insert-keyword " WITH ")
8974 (vhdl-template-field "real expression" ";"))))
8976 (defun vhdl-template-loop ()
8979 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8981 (vhdl-template-while-loop))
8983 (vhdl-template-for-loop))
8984 (t (vhdl-template-bare-loop)))))
8986 (defun vhdl-template-bare-loop ()
8989 (let ((margin (current-indentation))
8992 (if (not (eq vhdl-optional-labels 'all))
8993 (vhdl-insert-keyword "LOOP ")
8994 (vhdl-insert-keyword ": LOOP ")
8996 (setq label (vhdl-template-field "[label]" nil t))
8997 (unless label (delete-char 2))
9002 (vhdl-insert-keyword "END LOOP")
9003 (insert (if label (concat " " label ";") ";"))
9005 (indent-to (+ margin vhdl-basic-offset))))
9007 (defun vhdl-template-map (&optional start optional secondary)
9008 "Insert a map specification with association list."
9010 (let ((start (or start (point)))
9012 (vhdl-insert-keyword "MAP (")
9013 (if (not vhdl-association-list-with-formals)
9014 (if (vhdl-template-field
9015 (concat (and optional "[") "association list" (and optional "]"))
9016 ")" (or (not secondary) optional)
9017 (and (not secondary) start) (point))
9019 (if (and optional secondary) (delete-region start (point)))
9021 (if vhdl-argument-list-indent
9022 (setq margin (current-column))
9023 (setq margin (+ (current-indentation) vhdl-basic-offset))
9026 (if (vhdl-template-field
9027 (concat (and optional "[") "formal" (and optional "]"))
9028 " => " (or (not secondary) optional)
9029 (and (not secondary) start) (point))
9031 (vhdl-template-field "actual" ",")
9032 (setq end-pos (point))
9035 (while (vhdl-template-field "[formal]" " => " t)
9036 (vhdl-template-field "actual" ",")
9037 (setq end-pos (point))
9040 (delete-region end-pos (point))
9043 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9045 (when (and optional secondary) (delete-region start (point)))
9048 (defun vhdl-template-modify (&optional noerror)
9049 "Actualize modification date."
9051 (vhdl-prepare-search-2
9053 (goto-char (point-min))
9054 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9055 (progn (delete-region (point) (progn (end-of-line) (point)))
9056 (vhdl-template-insert-date))
9058 (error "ERROR: Modification date prefix string \"%s\" not found"
9059 vhdl-modify-date-prefix-string))))))
9062 (defun vhdl-template-modify-noerror ()
9063 "Call `vhdl-template-modify' with NOERROR non-nil."
9064 (vhdl-template-modify t))
9066 (defun vhdl-template-nature ()
9067 "Insert a nature declaration."
9069 (let ((start (point))
9070 name mid-pos end-pos)
9071 (vhdl-insert-keyword "NATURE ")
9072 (when (setq name (vhdl-template-field "name" nil t start (point)))
9073 (vhdl-insert-keyword " IS ")
9076 (or (vhdl-template-field
9077 "across type | ARRAY | RECORD")
9079 (cond ((equal definition "")
9081 ((equal definition "ARRAY")
9082 (delete-region (point) (progn (forward-word -1) (point)))
9083 (vhdl-template-array 'nature t))
9084 ((equal definition "RECORD")
9085 (setq mid-pos (point-marker))
9086 (delete-region (point) (progn (forward-word -1) (point)))
9087 (vhdl-template-record 'nature name t))
9089 (vhdl-insert-keyword " ACROSS ")
9090 (vhdl-template-field "through type")
9091 (vhdl-insert-keyword " THROUGH ")
9092 (vhdl-template-field "reference name")
9093 (vhdl-insert-keyword " REFERENCE;")))
9095 (setq end-pos (point-marker))
9098 (vhdl-comment-insert-inline)
9099 (when end-pos (goto-char end-pos))))))
9101 (defun vhdl-template-next ()
9102 "Insert a next statement."
9104 (let ((start (point)))
9105 (vhdl-insert-keyword "NEXT ")
9106 (if (vhdl-template-field "[loop label]" nil t start (point))
9107 (let ((position (point)))
9108 (vhdl-insert-keyword " WHEN ")
9109 (when vhdl-conditions-in-parenthesis (insert "("))
9110 (if (vhdl-template-field "[condition]" nil t)
9111 (when vhdl-conditions-in-parenthesis (insert ")"))
9112 (delete-region position (point))))
9116 (defun vhdl-template-others ()
9117 "Insert an others aggregate."
9119 (let ((start (point)))
9120 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9121 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9122 (vhdl-insert-keyword "OTHERS => '")
9123 (when (vhdl-template-field "value" nil t start (point))
9125 (vhdl-insert-keyword "OTHERS "))))
9127 (defun vhdl-template-package (&optional kind)
9128 "Insert a package specification or body."
9130 (let ((margin (current-indentation))
9133 (vhdl-insert-keyword "PACKAGE ")
9134 (setq body (if kind (eq kind 'body)
9135 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9137 (vhdl-insert-keyword "BODY ")
9138 (when (save-excursion
9139 (vhdl-prepare-search-1
9140 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9141 (insert (setq name (match-string 1)))))
9143 (setq name (vhdl-template-field "name" nil t start (point))))
9144 (vhdl-insert-keyword " IS\n")
9145 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9146 (indent-to (+ margin vhdl-basic-offset))
9147 (setq position (point))
9149 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9151 (vhdl-insert-keyword "END ")
9152 (unless (vhdl-standard-p '87)
9153 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9154 (insert (or name "") ";")
9155 (goto-char position))))
9157 (defun vhdl-template-package-decl ()
9158 "Insert a package specification."
9160 (vhdl-template-package 'decl))
9162 (defun vhdl-template-package-body ()
9163 "Insert a package body."
9165 (vhdl-template-package 'body))
9167 (defun vhdl-template-port ()
9168 "Insert a port declaration, or port map in instantiation statements."
9170 (let ((start (point)))
9171 (vhdl-prepare-search-1
9173 ((and (save-excursion ; entity declaration
9174 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9175 (equal "ENTITY" (upcase (match-string 1))))
9176 (vhdl-template-port-list nil))
9177 ((or (save-excursion
9178 (or (beginning-of-line)
9179 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9180 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9181 (vhdl-insert-keyword "PORT ")
9182 (vhdl-template-map start))
9183 (t (vhdl-template-port-list nil))))))
9185 (defun vhdl-template-procedural ()
9186 "Insert a procedural."
9188 (let ((margin (current-indentation))
9190 (case-fold-search t)
9192 (vhdl-insert-keyword "PROCEDURAL ")
9193 (when (memq vhdl-optional-labels '(process all))
9197 (setq label (vhdl-template-field "[label]" nil t))
9198 (unless label (delete-char 2))
9201 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9203 (vhdl-template-begin-end "PROCEDURAL" label margin)
9204 (vhdl-comment-block)))
9206 (defun vhdl-template-procedure (&optional kind)
9207 "Insert a procedure declaration or body."
9209 (let ((margin (current-indentation))
9212 (vhdl-insert-keyword "PROCEDURE ")
9213 (when (setq name (vhdl-template-field "name" nil t start (point)))
9214 (vhdl-template-argument-list)
9215 (if (if kind (eq kind 'body)
9216 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9217 (progn (vhdl-insert-keyword " IS")
9218 (when vhdl-auto-align
9219 (vhdl-align-region-groups start (point) 1))
9220 (end-of-line) (insert "\n")
9221 (vhdl-template-begin-end
9222 (unless (vhdl-standard-p '87) "PROCEDURE")
9224 (vhdl-comment-block))
9226 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9229 (defun vhdl-template-procedure-decl ()
9230 "Insert a procedure declaration."
9232 (vhdl-template-procedure 'decl))
9234 (defun vhdl-template-procedure-body ()
9235 "Insert a procedure body."
9237 (vhdl-template-procedure 'body))
9239 (defun vhdl-template-process (&optional kind)
9242 (let ((margin (current-indentation))
9244 label seq input-signals clock reset final-pos)
9245 (setq seq (if kind (eq kind 'seq)
9246 (eq (vhdl-decision-query
9247 "process" "(c)ombinational or (s)equential?" t) ?s)))
9248 (vhdl-insert-keyword "PROCESS ")
9249 (when (memq vhdl-optional-labels '(process all))
9253 (setq label (vhdl-template-field "[label]" nil t))
9254 (unless label (delete-char 2))
9259 (unless (setq input-signals
9260 (vhdl-template-field "[sensitivity list]" ")" t))
9261 (setq input-signals "")
9263 (setq clock (or (and (not (equal "" vhdl-clock-name))
9264 (progn (insert vhdl-clock-name) vhdl-clock-name))
9265 (vhdl-template-field "clock name") "<clock>"))
9266 (when (eq vhdl-reset-kind 'async)
9268 (setq reset (or (and (not (equal "" vhdl-reset-name))
9269 (progn (insert vhdl-reset-name) vhdl-reset-name))
9270 (vhdl-template-field "reset name") "<reset>")))
9272 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9274 (vhdl-template-begin-end "PROCESS" label margin)
9275 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9276 (when vhdl-prompt-for-comments
9277 (setq final-pos (point-marker))
9278 (vhdl-prepare-search-2
9279 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9280 (vhdl-re-search-backward "\\<process\\>" nil t))
9283 (progn (insert "\n") (forward-line -1))
9286 (insert "-- purpose: ")
9287 (if (not (vhdl-template-field "[description]" nil t))
9288 (vhdl-line-kill-entire)
9291 (insert "-- type : ")
9292 (insert (if seq "sequential" "combinational") "\n")
9294 (insert "-- inputs : ")
9296 (insert input-signals)
9298 (when reset (insert reset ", "))
9299 (unless (vhdl-template-field "[signal names]" nil t)
9303 (insert "-- outputs: ")
9304 (vhdl-template-field "[signal names]" nil t))))
9305 (goto-char final-pos))))
9307 (defun vhdl-template-process-comb ()
9308 "Insert a combinational process."
9310 (vhdl-template-process 'comb))
9312 (defun vhdl-template-process-seq ()
9313 "Insert a sequential process."
9315 (vhdl-template-process 'seq))
9317 (defun vhdl-template-quantity ()
9318 "Insert a quantity declaration."
9320 (if (vhdl-in-argument-list-p)
9321 (let ((start (point)))
9322 (vhdl-insert-keyword "QUANTITY ")
9323 (when (vhdl-template-field "names" nil t start (point))
9325 (vhdl-template-field "[IN | OUT]" " " t)
9326 (vhdl-template-field "type")
9328 (vhdl-comment-insert-inline)))
9329 (let ((char (vhdl-decision-query
9330 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9331 (cond ((eq char ?f) (vhdl-template-quantity-free))
9332 ((eq char ?b) (vhdl-template-quantity-branch))
9333 ((eq char ?s) (vhdl-template-quantity-source))
9334 (t (vhdl-template-undo (point) (point)))))))
9336 (defun vhdl-template-quantity-free ()
9337 "Insert a free quantity declaration."
9339 (vhdl-insert-keyword "QUANTITY ")
9340 (vhdl-template-field "names")
9342 (vhdl-template-field "type")
9343 (let ((position (point)))
9345 (unless (vhdl-template-field "[initialization]" nil t)
9346 (delete-region position (point)))
9348 (vhdl-comment-insert-inline)))
9350 (defun vhdl-template-quantity-branch ()
9351 "Insert a branch quantity declaration."
9354 (vhdl-insert-keyword "QUANTITY ")
9355 (when (vhdl-template-field "[across names]" " " t)
9356 (vhdl-insert-keyword "ACROSS "))
9357 (when (vhdl-template-field "[through names]" " " t)
9358 (vhdl-insert-keyword "THROUGH "))
9359 (vhdl-template-field "plus terminal name")
9360 (setq position (point))
9361 (vhdl-insert-keyword " TO ")
9362 (unless (vhdl-template-field "[minus terminal name]" nil t)
9363 (delete-region position (point)))
9365 (vhdl-comment-insert-inline)))
9367 (defun vhdl-template-quantity-source ()
9368 "Insert a source quantity declaration."
9370 (vhdl-insert-keyword "QUANTITY ")
9371 (vhdl-template-field "names")
9373 (vhdl-template-field "type" " ")
9374 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9375 (progn (vhdl-insert-keyword "NOISE ")
9376 (vhdl-template-field "power expression"))
9377 (vhdl-insert-keyword "SPECTRUM ")
9378 (vhdl-template-field "magnitude expression" ", ")
9379 (vhdl-template-field "phase expression"))
9381 (vhdl-comment-insert-inline))
9383 (defun vhdl-template-record (kind &optional name secondary)
9384 "Insert a record type declaration."
9386 (let ((margin (current-column))
9389 (vhdl-insert-keyword "RECORD\n")
9390 (indent-to (+ margin vhdl-basic-offset))
9391 (when (or (vhdl-template-field "element names"
9392 nil (not secondary) start (point))
9394 (while (or first (vhdl-template-field "[element names]" nil t))
9396 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9397 (vhdl-comment-insert-inline)
9399 (indent-to (+ margin vhdl-basic-offset))
9401 (delete-region (line-beginning-position) (point))
9403 (vhdl-insert-keyword "END RECORD")
9404 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9406 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9408 (defun vhdl-template-report ()
9409 "Insert a report statement."
9411 (let ((start (point)))
9412 (vhdl-insert-keyword "REPORT ")
9413 (if (equal "\"\"" (vhdl-template-field
9414 "string expression" nil t start (point) t))
9416 (setq start (point))
9417 (vhdl-insert-keyword " SEVERITY ")
9418 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9419 (delete-region start (point)))
9422 (defun vhdl-template-return ()
9423 "Insert a return statement."
9425 (let ((start (point)))
9426 (vhdl-insert-keyword "RETURN ")
9427 (unless (vhdl-template-field "[expression]" nil t start (point))
9431 (defun vhdl-template-selected-signal-asst ()
9432 "Insert a selected signal assignment."
9434 (let ((margin (current-indentation))
9437 (let ((position (point)))
9438 (vhdl-insert-keyword " SELECT ")
9439 (goto-char position))
9440 (vhdl-insert-keyword "WITH ")
9441 (when (vhdl-template-field "selector expression"
9442 nil t start (+ (point) 7))
9446 (indent-to (+ margin vhdl-basic-offset))
9447 (vhdl-template-field "target signal" " <= ")
9448 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9450 (indent-to (+ margin vhdl-basic-offset))
9451 (vhdl-template-field "waveform")
9452 (vhdl-insert-keyword " WHEN ")
9453 (vhdl-template-field "choices" ",")
9455 (indent-to (+ margin vhdl-basic-offset))
9456 (while (and choices (vhdl-template-field "[waveform]" nil t))
9457 (vhdl-insert-keyword " WHEN ")
9458 (if (setq choices (vhdl-template-field "[choices]" "," t))
9459 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9460 (vhdl-insert-keyword "OTHERS")))
9465 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9467 (defun vhdl-template-signal ()
9468 "Insert a signal declaration."
9470 (let ((start (point))
9471 (in-arglist (vhdl-in-argument-list-p)))
9472 (vhdl-insert-keyword "SIGNAL ")
9473 (when (vhdl-template-field "names" nil t start (point))
9475 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9476 (vhdl-template-field "type")
9479 (vhdl-comment-insert-inline))
9480 (let ((position (point)))
9482 (unless (vhdl-template-field "[initialization]" nil t)
9483 (delete-region position (point)))
9485 (vhdl-comment-insert-inline))))))
9487 (defun vhdl-template-subnature ()
9488 "Insert a subnature declaration."
9490 (let ((start (point))
9492 (vhdl-insert-keyword "SUBNATURE ")
9493 (when (vhdl-template-field "name" nil t start (point))
9494 (vhdl-insert-keyword " IS ")
9495 (vhdl-template-field "nature" " (")
9496 (if (vhdl-template-field "[index range]" nil t)
9499 (setq position (point))
9500 (vhdl-insert-keyword " TOLERANCE ")
9501 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9503 (delete-region position (point))
9504 (vhdl-insert-keyword " ACROSS ")
9505 (vhdl-template-field "string expression" nil nil nil nil t)
9506 (vhdl-insert-keyword " THROUGH"))
9508 (vhdl-comment-insert-inline))))
9510 (defun vhdl-template-subprogram-body ()
9511 "Insert a subprogram body."
9513 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9514 (vhdl-template-function-body)
9515 (vhdl-template-procedure-body)))
9517 (defun vhdl-template-subprogram-decl ()
9518 "Insert a subprogram declaration."
9520 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9521 (vhdl-template-function-decl)
9522 (vhdl-template-procedure-decl)))
9524 (defun vhdl-template-subtype ()
9525 "Insert a subtype declaration."
9527 (let ((start (point)))
9528 (vhdl-insert-keyword "SUBTYPE ")
9529 (when (vhdl-template-field "name" nil t start (point))
9530 (vhdl-insert-keyword " IS ")
9531 (vhdl-template-field "type" " ")
9533 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9536 (vhdl-comment-insert-inline))))
9538 (defun vhdl-template-terminal ()
9539 "Insert a terminal declaration."
9541 (let ((start (point)))
9542 (vhdl-insert-keyword "TERMINAL ")
9543 (when (vhdl-template-field "names" nil t start (point))
9545 (vhdl-template-field "nature")
9547 (vhdl-comment-insert-inline))))
9549 (defun vhdl-template-type ()
9550 "Insert a type declaration."
9552 (let ((start (point))
9553 name mid-pos end-pos)
9554 (vhdl-insert-keyword "TYPE ")
9555 (when (setq name (vhdl-template-field "name" nil t start (point)))
9556 (vhdl-insert-keyword " IS ")
9559 (or (vhdl-template-field
9560 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9562 (cond ((equal definition "")
9565 ((equal definition "ARRAY")
9566 (delete-region (point) (progn (forward-word -1) (point)))
9567 (vhdl-template-array 'type t))
9568 ((equal definition "RECORD")
9569 (setq mid-pos (point-marker))
9570 (delete-region (point) (progn (forward-word -1) (point)))
9571 (vhdl-template-record 'type name t))
9572 ((equal definition "ACCESS")
9574 (vhdl-template-field "type" ";"))
9575 ((equal definition "FILE")
9576 (vhdl-insert-keyword " OF ")
9577 (vhdl-template-field "type" ";"))
9580 (setq end-pos (point-marker))
9583 (vhdl-comment-insert-inline)
9584 (when end-pos (goto-char end-pos))))))
9586 (defun vhdl-template-use ()
9587 "Insert a use clause."
9589 (let ((start (point)))
9590 (vhdl-prepare-search-1
9591 (vhdl-insert-keyword "USE ")
9592 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9593 (vhdl-insert-keyword "..ALL;")
9595 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9597 (vhdl-template-field "package name")
9598 (forward-char 5))))))
9600 (defun vhdl-template-variable ()
9601 "Insert a variable declaration."
9603 (let ((start (point))
9604 (in-arglist (vhdl-in-argument-list-p)))
9605 (vhdl-prepare-search-2
9606 (if (or (save-excursion
9607 (and (vhdl-re-search-backward
9608 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9610 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9611 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9612 (vhdl-insert-keyword "VARIABLE ")
9613 (vhdl-insert-keyword "SHARED VARIABLE ")))
9614 (when (vhdl-template-field "names" nil t start (point))
9616 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9617 (vhdl-template-field "type")
9620 (vhdl-comment-insert-inline))
9621 (let ((position (point)))
9623 (unless (vhdl-template-field "[initialization]" nil t)
9624 (delete-region position (point)))
9626 (vhdl-comment-insert-inline))))))
9628 (defun vhdl-template-wait ()
9629 "Insert a wait statement."
9631 (vhdl-insert-keyword "WAIT ")
9632 (unless (vhdl-template-field
9633 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9638 (defun vhdl-template-when ()
9639 "Indent correctly if within a case statement."
9641 (let ((position (point))
9643 (vhdl-prepare-search-2
9644 (if (and (= (current-column) (current-indentation))
9645 (vhdl-re-search-forward "\\<end\\>" nil t)
9646 (looking-at "\\s-*\\<case\\>"))
9648 (setq margin (current-indentation))
9649 (goto-char position)
9650 (delete-horizontal-space)
9651 (indent-to (+ margin vhdl-basic-offset)))
9652 (goto-char position)))
9653 (vhdl-insert-keyword "WHEN ")))
9655 (defun vhdl-template-while-loop ()
9656 "Insert a while loop."
9658 (let* ((margin (current-indentation))
9661 (if (not (eq vhdl-optional-labels 'all))
9662 (vhdl-insert-keyword "WHILE ")
9663 (vhdl-insert-keyword ": WHILE ")
9665 (setq label (vhdl-template-field "[label]" nil t))
9666 (unless label (delete-char 2))
9669 (when vhdl-conditions-in-parenthesis (insert "("))
9670 (when (vhdl-template-field "condition" nil t start (point))
9671 (when vhdl-conditions-in-parenthesis (insert ")"))
9672 (vhdl-insert-keyword " LOOP\n\n")
9674 (vhdl-insert-keyword "END LOOP")
9675 (insert (if label (concat " " label ";") ";"))
9677 (indent-to (+ margin vhdl-basic-offset)))))
9679 (defun vhdl-template-with ()
9680 "Insert a with statement (i.e. selected signal assignment)."
9682 (vhdl-prepare-search-1
9683 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9684 (equal ";" (match-string 1)))
9685 (vhdl-template-selected-signal-asst)
9686 (vhdl-insert-keyword "WITH "))))
9688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9689 ;; Special templates
9691 (defun vhdl-template-clocked-wait ()
9692 "Insert a wait statement for rising/falling clock edge."
9694 (let ((start (point))
9696 (vhdl-insert-keyword "WAIT UNTIL ")
9698 (or (and (not (equal "" vhdl-clock-name))
9699 (progn (insert vhdl-clock-name) vhdl-clock-name))
9700 (vhdl-template-field "clock name" nil t start (point))))
9702 (vhdl-insert-keyword " AND ")
9705 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9706 (vhdl-comment-insert-inline
9707 (concat (if vhdl-clock-rising-edge "rising" "falling")
9710 (defun vhdl-template-seq-process (clock reset)
9711 "Insert a template for the body of a sequential process."
9712 (let ((margin (current-indentation))
9714 (vhdl-insert-keyword "IF ")
9715 (when (eq vhdl-reset-kind 'async)
9717 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9718 (vhdl-insert-keyword " THEN")
9719 (vhdl-comment-insert-inline
9720 (concat "asynchronous reset (active "
9721 (if vhdl-reset-active-high "high" "low") ")"))
9722 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9723 (setq position (point))
9724 (insert "\n") (indent-to margin)
9725 (vhdl-insert-keyword "ELSIF "))
9726 (if (eq vhdl-clock-edge-condition 'function)
9727 (insert (if vhdl-clock-rising-edge "rising" "falling")
9729 (insert clock "'event")
9730 (vhdl-insert-keyword " AND ")
9732 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9733 (vhdl-insert-keyword " THEN")
9734 (vhdl-comment-insert-inline
9735 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9736 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9737 (when (eq vhdl-reset-kind 'sync)
9738 (vhdl-insert-keyword "IF ")
9739 (setq reset (or (and (not (equal "" vhdl-reset-name))
9740 (progn (insert vhdl-reset-name) vhdl-reset-name))
9741 (vhdl-template-field "reset name") "<reset>"))
9743 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9744 (vhdl-insert-keyword " THEN")
9745 (vhdl-comment-insert-inline
9746 (concat "synchronous reset (active "
9747 (if vhdl-reset-active-high "high" "low") ")"))
9748 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9749 (setq position (point))
9750 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9751 (vhdl-insert-keyword "ELSE")
9752 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9753 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9754 (vhdl-insert-keyword "END IF;"))
9755 (when (eq vhdl-reset-kind 'none)
9756 (setq position (point)))
9757 (insert "\n") (indent-to margin)
9758 (vhdl-insert-keyword "END IF;")
9759 (goto-char position)
9762 (defun vhdl-template-standard-package (library package)
9763 "Insert specification of a standard package. Include a library
9764 specification, if not already there."
9765 (let ((margin (current-indentation)))
9766 (unless (equal library "std")
9767 (unless (or (save-excursion
9768 (vhdl-prepare-search-1
9771 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9772 library "\\|end\\)\\>") nil t)
9774 (equal (downcase library) "work"))
9775 (vhdl-insert-keyword "LIBRARY ")
9776 (insert library ";")
9779 (indent-to margin)))
9781 (vhdl-insert-keyword "USE ")
9782 (insert library "." package)
9783 (vhdl-insert-keyword ".ALL;")))))
9785 (defun vhdl-template-package-math-complex ()
9786 "Insert specification of `math_complex' package."
9788 (vhdl-template-standard-package "ieee" "math_complex"))
9790 (defun vhdl-template-package-math-real ()
9791 "Insert specification of `math_real' package."
9793 (vhdl-template-standard-package "ieee" "math_real"))
9795 (defun vhdl-template-package-numeric-bit ()
9796 "Insert specification of `numeric_bit' package."
9798 (vhdl-template-standard-package "ieee" "numeric_bit"))
9800 (defun vhdl-template-package-numeric-std ()
9801 "Insert specification of `numeric_std' package."
9803 (vhdl-template-standard-package "ieee" "numeric_std"))
9805 (defun vhdl-template-package-std-logic-1164 ()
9806 "Insert specification of `std_logic_1164' package."
9808 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9810 (defun vhdl-template-package-std-logic-arith ()
9811 "Insert specification of `std_logic_arith' package."
9813 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9815 (defun vhdl-template-package-std-logic-misc ()
9816 "Insert specification of `std_logic_misc' package."
9818 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9820 (defun vhdl-template-package-std-logic-signed ()
9821 "Insert specification of `std_logic_signed' package."
9823 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9825 (defun vhdl-template-package-std-logic-textio ()
9826 "Insert specification of `std_logic_textio' package."
9828 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9830 (defun vhdl-template-package-std-logic-unsigned ()
9831 "Insert specification of `std_logic_unsigned' package."
9833 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9835 (defun vhdl-template-package-textio ()
9836 "Insert specification of `textio' package."
9838 (vhdl-template-standard-package "std" "textio"))
9840 (defun vhdl-template-directive (directive)
9842 (unless (= (current-indentation) (current-column))
9843 (delete-horizontal-space)
9845 (insert "-- pragma " directive))
9847 (defun vhdl-template-directive-translate-on ()
9848 "Insert directive 'translate_on'."
9850 (vhdl-template-directive "translate_on"))
9852 (defun vhdl-template-directive-translate-off ()
9853 "Insert directive 'translate_off'."
9855 (vhdl-template-directive "translate_off"))
9857 (defun vhdl-template-directive-synthesis-on ()
9858 "Insert directive 'synthesis_on'."
9860 (vhdl-template-directive "synthesis_on"))
9862 (defun vhdl-template-directive-synthesis-off ()
9863 "Insert directive 'synthesis_off'."
9865 (vhdl-template-directive "synthesis_off"))
9867 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9868 ;; Header and footer templates
9870 (defun vhdl-template-header (&optional file-title)
9871 "Insert a VHDL file header."
9873 (unless (equal vhdl-file-header "")
9876 (goto-char (point-min))
9877 (vhdl-insert-string-or-file vhdl-file-header)
9878 (setq pos (point-marker)))
9879 (vhdl-template-replace-header-keywords
9880 (point-min-marker) pos file-title))))
9882 (defun vhdl-template-footer ()
9883 "Insert a VHDL file footer."
9885 (unless (equal vhdl-file-footer "")
9888 (goto-char (point-max))
9889 (setq pos (point-marker))
9890 (vhdl-insert-string-or-file vhdl-file-footer)
9891 (unless (= (preceding-char) ?\n)
9893 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9895 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9897 "Replace keywords in header and footer."
9898 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9899 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9901 (vhdl-prepare-search-2
9904 (while (search-forward "<projectdesc>" end t)
9905 (replace-match project-desc t t))
9907 (while (search-forward "<filename>" end t)
9908 (replace-match (buffer-name) t t))
9910 (while (search-forward "<copyright>" end t)
9911 (replace-match vhdl-copyright-string t t))
9913 (while (search-forward "<author>" end t)
9914 (replace-match "" t t)
9915 (insert (user-full-name))
9916 (when user-mail-address (insert " <" user-mail-address ">")))
9918 (while (search-forward "<login>" end t)
9919 (replace-match (user-login-name) t t))
9921 (while (search-forward "<project>" end t)
9922 (replace-match project-title t t))
9924 (while (search-forward "<company>" end t)
9925 (replace-match vhdl-company-name t t))
9927 (while (search-forward "<platform>" end t)
9928 (replace-match vhdl-platform-spec t t))
9930 (while (search-forward "<standard>" end t)
9932 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9933 ((vhdl-standard-p '93) "'93"))
9934 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9935 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9937 ;; Replace <RCS> with $, so that RCS for the source is
9938 ;; not over-enthusiastic with replacements
9939 (while (search-forward "<RCS>" end t)
9940 (replace-match "$" nil t))
9942 (while (search-forward "<date>" end t)
9943 (replace-match "" t t)
9944 (vhdl-template-insert-date))
9946 (while (search-forward "<year>" end t)
9947 (replace-match (format-time-string "%Y" nil) t t))
9950 (while (search-forward "<title string>" end t)
9951 (replace-match file-title t t))
9955 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9956 (setq string (read-string (concat (match-string 1) ": ")))
9957 (replace-match string t t)))
9959 (when (and (not is-model) (search-forward "<cursor>" end t))
9960 (replace-match "" t t)
9961 (setq pos (point))))
9962 (when pos (goto-char pos))
9964 (when (or (not project-title) (equal project-title ""))
9965 (message "You can specify a project title in user option `vhdl-project-alist'"))
9966 (when (or (not project-desc) (equal project-desc ""))
9967 (message "You can specify a project description in user option `vhdl-project-alist'"))
9968 (when (equal vhdl-platform-spec "")
9969 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9970 (when (equal vhdl-company-name "")
9971 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9974 ;; Comment templates and functions
9976 (defun vhdl-comment-indent ()
9978 (let* ((position (point))
9982 (if (re-search-forward "--" position t)
9983 (- (current-column) 2) ; existing comment at bol stays there
9984 (goto-char position)
9985 (skip-chars-backward " \t")
9986 (max comment-column ; else indent to comment column
9987 (1+ (current-column))))))) ; except leave at least one space
9988 (goto-char position)
9991 (defun vhdl-comment-insert ()
9992 "Start a comment at the end of the line.
9993 If on line with code, indent at least `comment-column'.
9994 If starting after end-comment-column, start a new line."
9996 (when (> (current-column) end-comment-column) (newline-and-indent))
9997 (if (or (looking-at "\\s-*$") ; end of line
9998 (and (not unread-command-events) ; called with key binding or menu
9999 (not (end-of-line))))
10001 (while (= (preceding-char) ?-) (delete-char -1))
10002 (setq margin (current-column))
10003 (delete-horizontal-space)
10005 (progn (indent-to margin) (insert "--"))
10007 (indent-to comment-column)
10009 (if (not unread-command-events) (insert " ")))
10010 ;; else code following current point implies commenting out code
10011 (let (next-input code)
10012 (while (= (preceding-char) ?-) (delete-char -2))
10013 (while (= (setq next-input (read-char)) 13) ; CR
10014 (insert "--") ; or have a space after it?
10017 (message "Enter CR if commenting out a line of code.")
10020 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10021 (setq unread-command-events
10022 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10024 (defun vhdl-comment-display (&optional line-exists)
10025 "Add 2 comment lines at the current indent, making a display comment."
10027 (let ((margin (current-indentation)))
10028 (unless line-exists (vhdl-comment-display-line))
10029 (insert "\n") (indent-to margin)
10030 (insert "\n") (indent-to margin)
10031 (vhdl-comment-display-line)
10035 (defun vhdl-comment-display-line ()
10036 "Displays one line of dashes."
10038 (while (= (preceding-char) ?-) (delete-char -2))
10039 (let* ((col (current-column))
10040 (len (- end-comment-column col)))
10041 (insert-char ?- len)))
10043 (defun vhdl-comment-append-inline ()
10044 "Append empty inline comment to current line."
10047 (delete-horizontal-space)
10049 (indent-to comment-column)
10052 (defun vhdl-comment-insert-inline (&optional string always-insert)
10053 "Insert inline comment."
10054 (when (or (and string (or vhdl-self-insert-comments always-insert))
10055 (and (not string) vhdl-prompt-for-comments))
10056 (let ((position (point)))
10058 (indent-to comment-column)
10060 (if (not (or (and string (progn (insert string) t))
10061 (vhdl-template-field "[comment]" nil t)))
10062 (delete-region position (point))
10063 (while (= (preceding-char) ?\ ) (delete-char -1))
10064 ;; (when (> (current-column) end-comment-column)
10065 ;; (setq position (point-marker))
10066 ;; (re-search-backward "-- ")
10068 ;; (indent-to comment-column)
10069 ;; (goto-char position))
10072 (defun vhdl-comment-block ()
10073 "Insert comment for code block."
10074 (when vhdl-prompt-for-comments
10075 (let ((final-pos (point-marker)))
10076 (vhdl-prepare-search-2
10077 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10078 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10080 (back-to-indentation)
10081 (setq margin (current-column))
10084 (progn (insert "\n") (forward-line -1))
10087 (insert "-- purpose: ")
10088 (unless (vhdl-template-field "[description]" nil t)
10089 (vhdl-line-kill-entire)))))
10090 (goto-char final-pos))))
10092 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10093 "Comment out region if not commented out, uncomment otherwise."
10094 (interactive "r\nP")
10096 (goto-char (1- end))
10098 (setq end (point-marker))
10100 (beginning-of-line)
10102 (if (looking-at comment-start)
10103 (comment-region beg end '(4))
10104 (comment-region beg end))))
10106 (defun vhdl-comment-uncomment-line (&optional arg)
10107 "Comment out line if not commented out, uncomment otherwise."
10110 (beginning-of-line)
10111 (let ((position (point)))
10112 (forward-line (or arg 1))
10113 (vhdl-comment-uncomment-region position (point)))))
10115 (defun vhdl-comment-kill-region (beg end)
10116 "Kill comments in region."
10120 (setq end (point-marker))
10122 (beginning-of-line)
10123 (while (< (point) end)
10124 (if (looking-at "^\\(\\s-*--.*\n\\)")
10125 (progn (delete-region (match-beginning 1) (match-end 1)))
10126 (beginning-of-line 2)))))
10128 (defun vhdl-comment-kill-inline-region (beg end)
10129 "Kill inline comments in region."
10133 (setq end (point-marker))
10135 (beginning-of-line)
10136 (while (< (point) end)
10137 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10138 (delete-region (match-beginning 1) (match-end 1)))
10139 (beginning-of-line 2))))
10141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10144 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10145 "Insert a begin ... end pair with optional name after the end.
10146 Point is left between them."
10148 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10150 (vhdl-insert-keyword "BEGIN")
10151 (when (and (or construct name) vhdl-self-insert-comments)
10153 (when construct (insert " ") (vhdl-insert-keyword construct))
10154 (when name (insert " " name)))
10156 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10157 (indent-to (+ margin vhdl-basic-offset))
10158 (setq position (point))
10160 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10162 (vhdl-insert-keyword "END")
10163 (when construct (insert " ") (vhdl-insert-keyword construct))
10164 (insert (if name (concat " " name) "") ";")
10165 (goto-char position)))
10167 (defun vhdl-template-argument-list (&optional is-function)
10168 "Read from user a procedure or function argument list."
10170 (let ((margin (current-column))
10173 not-empty interface semicolon-pos)
10174 (unless vhdl-argument-list-indent
10175 (setq margin (+ (current-indentation) vhdl-basic-offset))
10177 (indent-to margin))
10178 (setq interface (vhdl-template-field
10179 (concat "[CONSTANT | SIGNAL"
10180 (unless is-function " | VARIABLE") "]") " " t))
10181 (while (vhdl-template-field "[names]" nil t)
10184 (unless is-function
10185 (if (and interface (equal (upcase interface) "CONSTANT"))
10186 (vhdl-insert-keyword "IN ")
10187 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10188 (vhdl-template-field "type")
10189 (setq semicolon-pos (point))
10191 (vhdl-comment-insert-inline)
10192 (setq end-pos (point))
10195 (setq interface (vhdl-template-field
10196 (concat "[CONSTANT | SIGNAL"
10197 (unless is-function " | VARIABLE") "]") " " t)))
10198 (delete-region end-pos (point))
10199 (when semicolon-pos (goto-char semicolon-pos))
10201 (progn (delete-char 1) (insert ")"))
10202 (delete-char -2))))
10204 (defun vhdl-template-generic-list (optional &optional no-value)
10205 "Read from user a generic spec argument list."
10208 (vhdl-insert-keyword "GENERIC (")
10209 (setq margin (current-column))
10210 (unless vhdl-argument-list-indent
10211 (let ((position (point)))
10212 (back-to-indentation)
10213 (setq margin (+ (current-column) vhdl-basic-offset))
10214 (goto-char position)
10216 (indent-to margin)))
10217 (let ((vhdl-generics (vhdl-template-field
10218 (concat (and optional "[") "name"
10219 (and no-value "s") (and optional "]"))
10221 (if (not vhdl-generics)
10223 (progn (vhdl-line-kill-entire) (end-of-line -0)
10224 (unless vhdl-argument-list-indent
10225 (vhdl-line-kill-entire) (end-of-line -0)))
10226 (vhdl-template-undo start (point))
10229 (let (semicolon-pos end-pos)
10230 (while vhdl-generics
10231 (vhdl-template-field "type")
10233 (progn (setq semicolon-pos (point))
10236 (unless (vhdl-template-field "[value]" nil t)
10238 (setq semicolon-pos (point))
10240 (vhdl-comment-insert-inline)
10241 (setq end-pos (point))
10244 (setq vhdl-generics (vhdl-template-field
10245 (concat "[name" (and no-value "s") "]")
10247 (delete-region end-pos (point))
10248 (goto-char semicolon-pos)
10251 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10254 (defun vhdl-template-port-list (optional)
10255 "Read from user a port spec argument list."
10256 (let ((start (point))
10257 margin vhdl-ports object)
10258 (vhdl-insert-keyword "PORT (")
10259 (setq margin (current-column))
10260 (unless vhdl-argument-list-indent
10261 (let ((position (point)))
10262 (back-to-indentation)
10263 (setq margin (+ (current-column) vhdl-basic-offset))
10264 (goto-char position)
10266 (indent-to margin)))
10267 (when (vhdl-standard-p 'ams)
10268 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10270 (setq vhdl-ports (vhdl-template-field
10271 (concat (and optional "[") "names" (and optional "]"))
10273 (if (not vhdl-ports)
10275 (progn (vhdl-line-kill-entire) (end-of-line -0)
10276 (unless vhdl-argument-list-indent
10277 (vhdl-line-kill-entire) (end-of-line -0)))
10278 (vhdl-template-undo start (point))
10281 (let (semicolon-pos end-pos)
10283 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10284 (vhdl-template-field "IN | OUT | INOUT" " "))
10285 ((equal "QUANTITY" (upcase object))
10286 (vhdl-template-field "[IN | OUT]" " " t)))
10287 (vhdl-template-field
10288 (if (and object (equal "TERMINAL" (upcase object)))
10290 (setq semicolon-pos (point))
10292 (vhdl-comment-insert-inline)
10293 (setq end-pos (point))
10296 (when (vhdl-standard-p 'ams)
10297 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10299 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10300 (delete-region end-pos (point))
10301 (goto-char semicolon-pos)
10304 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10307 (defun vhdl-template-generate-body (margin label)
10308 "Insert body for generate template."
10309 (vhdl-insert-keyword " GENERATE")
10310 ; (if (not (vhdl-standard-p '87))
10311 ; (vhdl-template-begin-end "GENERATE" label margin)
10314 (vhdl-insert-keyword "END GENERATE ")
10317 (indent-to (+ margin vhdl-basic-offset)))
10319 (defun vhdl-template-insert-date ()
10320 "Insert date in appropriate format."
10324 ;; 'american, 'european, 'scientific kept for backward compatibility
10325 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10326 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10327 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10328 (t (format-time-string vhdl-date-format nil)))))
10330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10333 (defun vhdl-electric-space (count)
10334 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10335 if in comment and past end-comment-column."
10337 (cond ((vhdl-in-comment-p)
10338 (self-insert-command count)
10339 (cond ((>= (current-column) (+ 2 end-comment-column))
10341 (skip-chars-backward "^ \t\n")
10342 (indent-new-comment-line)
10343 (skip-chars-forward "^ \t\n")
10345 ((>= (current-column) end-comment-column)
10346 (indent-new-comment-line))
10348 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10349 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10350 (vhdl-prepare-search-1
10351 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10352 (self-insert-command count))
10353 (t (self-insert-command count))))
10355 (defun vhdl-template-field (prompt &optional follow-string optional
10356 begin end is-string default)
10357 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10358 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10359 an empty string is inserted, return nil and call `vhdl-template-undo' for
10360 the region between BEGIN and END. IS-STRING indicates whether a string
10361 with double-quotes is to be inserted. DEFAULT specifies a default string."
10362 (let ((position (point))
10364 (insert "<" prompt ">")
10367 (read-from-minibuffer (concat prompt ": ")
10368 (or (and is-string '("\"\"" . 2)) default)
10369 vhdl-minibuffer-local-map)
10370 (quit (if (and optional begin end)
10372 (keyboard-quit)))))
10373 (when (or (not (equal string "")) optional)
10374 (delete-region position (point)))
10375 (when (and (equal string "") optional begin end)
10376 (vhdl-template-undo begin end)
10377 (message "Template aborted"))
10378 (unless (equal string "")
10380 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10381 vhdl-keywords-regexp)
10382 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10384 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10385 (concat "'" vhdl-attributes-regexp))
10386 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10387 vhdl-enum-values-regexp))
10388 (when (or (not (equal string "")) (not optional))
10389 (insert (or follow-string "")))
10390 (if (equal string "") nil string)))
10392 (defun vhdl-decision-query (string prompt &optional optional)
10393 "Query a decision from the user."
10394 (let ((start (point)))
10395 (when string (vhdl-insert-keyword (concat string " ")))
10396 (message "%s" (or prompt ""))
10397 (let ((char (read-char)))
10398 (delete-region start (point))
10399 (if (and optional (eq char ?\r))
10400 (progn (insert " ")
10402 (throw 'abort "ERROR: Template aborted"))
10405 (defun vhdl-insert-keyword (keyword)
10406 "Insert KEYWORD and adjust case."
10407 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10409 (defun vhdl-case-keyword (keyword)
10410 "Adjust case of KEYWORD."
10411 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10413 (defun vhdl-case-word (num)
10414 "Adjust case of following NUM words."
10415 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10417 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10418 "If preceeding character is part of a word or a paren then hippie-expand,
10419 else insert tab (used for word completion in VHDL minibuffer)."
10423 ((= (char-syntax (preceding-char)) ?w)
10424 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10426 (hippie-expand-only-buffers
10427 (or (and (boundp 'hippie-expand-only-buffers)
10428 hippie-expand-only-buffers)
10430 (vhdl-expand-abbrev prefix-arg)))
10431 ;; expand parenthesis
10432 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10433 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10434 (case-replace nil))
10435 (vhdl-expand-paren prefix-arg)))
10439 (defun vhdl-template-search-prompt ()
10440 "Search for left out template prompts and query again."
10442 (vhdl-prepare-search-2
10443 (when (or (re-search-forward
10444 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10445 (re-search-backward
10446 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10447 (let ((string (match-string 1)))
10449 (vhdl-template-field string)))))
10451 (defun vhdl-template-undo (begin end)
10452 "Undo aborted template by deleting region and unexpanding the keyword."
10453 (cond (vhdl-template-invoked-by-hook
10456 (delete-region begin end)
10458 (t (delete-region begin end))))
10460 (defun vhdl-insert-string-or-file (string)
10461 "Insert STRING or file contents if STRING is an existing file name."
10462 (unless (equal string "")
10464 (progn (string-match "^\\([^\n]+\\)" string)
10465 (vhdl-resolve-env-variable (match-string 1 string)))))
10466 (if (file-exists-p file-name)
10467 (forward-char (cadr (insert-file-contents file-name)))
10468 (insert string)))))
10470 (defun vhdl-beginning-of-block ()
10471 "Move cursor to the beginning of the enclosing block."
10474 (beginning-of-line)
10475 ;; search backward for block beginning or end
10476 (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))
10477 ;; not consider subprogram declarations
10478 (or (and (match-string 5)
10481 (goto-char (match-end 5))
10483 (vhdl-forward-syntactic-ws)
10484 (when (looking-at "(")
10486 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10488 ;; not consider configuration specifications
10489 (and (match-string 6)
10492 (vhdl-end-of-block)
10493 (beginning-of-line)
10494 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10496 ;; skip subblock if block end found
10497 (vhdl-beginning-of-block)))
10498 (when pos (goto-char pos))))
10500 (defun vhdl-end-of-block ()
10501 "Move cursor to the end of the enclosing block."
10505 ;; search forward for block beginning or end
10506 (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))
10507 ;; not consider subprogram declarations
10508 (or (and (match-string 5)
10510 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10512 ;; not consider configuration specifications
10513 (and (match-string 6)
10516 (vhdl-end-of-block)
10517 (beginning-of-line)
10518 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10519 (not (match-string 2)))
10520 ;; skip subblock if block beginning found
10521 (vhdl-end-of-block)))
10522 (when pos (goto-char pos))))
10524 (defun vhdl-sequential-statement-p ()
10525 "Check if point is within sequential statement part."
10526 (let ((start (point)))
10528 (vhdl-prepare-search-2
10529 ;; is sequential statement if ...
10530 (and (re-search-backward "^\\s-*begin\\>" nil t)
10531 ;; ... point is between "begin" and "end" of ...
10532 (progn (vhdl-end-of-block)
10534 ;; ... a sequential block
10535 (progn (vhdl-beginning-of-block)
10536 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10538 (defun vhdl-in-argument-list-p ()
10539 "Check if within an argument list."
10541 (vhdl-prepare-search-2
10542 (or (string-match "arglist"
10543 (format "%s" (caar (vhdl-get-syntactic-context))))
10544 (progn (beginning-of-line)
10545 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10547 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10550 (defun vhdl-hooked-abbrev (func)
10551 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10552 but not if inside a comment or quote."
10553 (if (or (vhdl-in-literal)
10556 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10561 (if (not vhdl-electric-mode)
10568 (let ((invoke-char last-command-event)
10570 (vhdl-template-invoked-by-hook t))
10571 (let ((caught (catch 'abort
10573 (when (stringp caught) (message "%s" caught)))
10574 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10575 ;; delete CR which is still in event queue
10576 (if (fboundp 'enqueue-eval-event)
10577 (enqueue-eval-event 'delete-char -1)
10578 (setq unread-command-events ; push back a delete char
10579 (list (vhdl-character-to-event ?\177))))))))
10581 (defun vhdl-template-alias-hook ()
10582 (vhdl-hooked-abbrev 'vhdl-template-alias))
10583 (defun vhdl-template-architecture-hook ()
10584 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10585 (defun vhdl-template-assert-hook ()
10586 (vhdl-hooked-abbrev 'vhdl-template-assert))
10587 (defun vhdl-template-attribute-hook ()
10588 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10589 (defun vhdl-template-block-hook ()
10590 (vhdl-hooked-abbrev 'vhdl-template-block))
10591 (defun vhdl-template-break-hook ()
10592 (vhdl-hooked-abbrev 'vhdl-template-break))
10593 (defun vhdl-template-case-hook ()
10594 (vhdl-hooked-abbrev 'vhdl-template-case))
10595 (defun vhdl-template-component-hook ()
10596 (vhdl-hooked-abbrev 'vhdl-template-component))
10597 (defun vhdl-template-instance-hook ()
10598 (vhdl-hooked-abbrev 'vhdl-template-instance))
10599 (defun vhdl-template-conditional-signal-asst-hook ()
10600 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10601 (defun vhdl-template-configuration-hook ()
10602 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10603 (defun vhdl-template-constant-hook ()
10604 (vhdl-hooked-abbrev 'vhdl-template-constant))
10605 (defun vhdl-template-disconnect-hook ()
10606 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10607 (defun vhdl-template-display-comment-hook ()
10608 (vhdl-hooked-abbrev 'vhdl-comment-display))
10609 (defun vhdl-template-else-hook ()
10610 (vhdl-hooked-abbrev 'vhdl-template-else))
10611 (defun vhdl-template-elsif-hook ()
10612 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10613 (defun vhdl-template-entity-hook ()
10614 (vhdl-hooked-abbrev 'vhdl-template-entity))
10615 (defun vhdl-template-exit-hook ()
10616 (vhdl-hooked-abbrev 'vhdl-template-exit))
10617 (defun vhdl-template-file-hook ()
10618 (vhdl-hooked-abbrev 'vhdl-template-file))
10619 (defun vhdl-template-for-hook ()
10620 (vhdl-hooked-abbrev 'vhdl-template-for))
10621 (defun vhdl-template-function-hook ()
10622 (vhdl-hooked-abbrev 'vhdl-template-function))
10623 (defun vhdl-template-generic-hook ()
10624 (vhdl-hooked-abbrev 'vhdl-template-generic))
10625 (defun vhdl-template-group-hook ()
10626 (vhdl-hooked-abbrev 'vhdl-template-group))
10627 (defun vhdl-template-library-hook ()
10628 (vhdl-hooked-abbrev 'vhdl-template-library))
10629 (defun vhdl-template-limit-hook ()
10630 (vhdl-hooked-abbrev 'vhdl-template-limit))
10631 (defun vhdl-template-if-hook ()
10632 (vhdl-hooked-abbrev 'vhdl-template-if))
10633 (defun vhdl-template-bare-loop-hook ()
10634 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10635 (defun vhdl-template-map-hook ()
10636 (vhdl-hooked-abbrev 'vhdl-template-map))
10637 (defun vhdl-template-nature-hook ()
10638 (vhdl-hooked-abbrev 'vhdl-template-nature))
10639 (defun vhdl-template-next-hook ()
10640 (vhdl-hooked-abbrev 'vhdl-template-next))
10641 (defun vhdl-template-others-hook ()
10642 (vhdl-hooked-abbrev 'vhdl-template-others))
10643 (defun vhdl-template-package-hook ()
10644 (vhdl-hooked-abbrev 'vhdl-template-package))
10645 (defun vhdl-template-port-hook ()
10646 (vhdl-hooked-abbrev 'vhdl-template-port))
10647 (defun vhdl-template-procedural-hook ()
10648 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10649 (defun vhdl-template-procedure-hook ()
10650 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10651 (defun vhdl-template-process-hook ()
10652 (vhdl-hooked-abbrev 'vhdl-template-process))
10653 (defun vhdl-template-quantity-hook ()
10654 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10655 (defun vhdl-template-report-hook ()
10656 (vhdl-hooked-abbrev 'vhdl-template-report))
10657 (defun vhdl-template-return-hook ()
10658 (vhdl-hooked-abbrev 'vhdl-template-return))
10659 (defun vhdl-template-selected-signal-asst-hook ()
10660 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10661 (defun vhdl-template-signal-hook ()
10662 (vhdl-hooked-abbrev 'vhdl-template-signal))
10663 (defun vhdl-template-subnature-hook ()
10664 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10665 (defun vhdl-template-subtype-hook ()
10666 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10667 (defun vhdl-template-terminal-hook ()
10668 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10669 (defun vhdl-template-type-hook ()
10670 (vhdl-hooked-abbrev 'vhdl-template-type))
10671 (defun vhdl-template-use-hook ()
10672 (vhdl-hooked-abbrev 'vhdl-template-use))
10673 (defun vhdl-template-variable-hook ()
10674 (vhdl-hooked-abbrev 'vhdl-template-variable))
10675 (defun vhdl-template-wait-hook ()
10676 (vhdl-hooked-abbrev 'vhdl-template-wait))
10677 (defun vhdl-template-when-hook ()
10678 (vhdl-hooked-abbrev 'vhdl-template-when))
10679 (defun vhdl-template-while-loop-hook ()
10680 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10681 (defun vhdl-template-with-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-with))
10683 (defun vhdl-template-and-hook ()
10684 (vhdl-hooked-abbrev 'vhdl-template-and))
10685 (defun vhdl-template-or-hook ()
10686 (vhdl-hooked-abbrev 'vhdl-template-or))
10687 (defun vhdl-template-nand-hook ()
10688 (vhdl-hooked-abbrev 'vhdl-template-nand))
10689 (defun vhdl-template-nor-hook ()
10690 (vhdl-hooked-abbrev 'vhdl-template-nor))
10691 (defun vhdl-template-xor-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-xor))
10693 (defun vhdl-template-xnor-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10695 (defun vhdl-template-not-hook ()
10696 (vhdl-hooked-abbrev 'vhdl-template-not))
10698 (defun vhdl-template-default-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-default))
10700 (defun vhdl-template-default-indent-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10703 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10704 ;; Template insertion from completion list
10706 (defun vhdl-template-insert-construct (name)
10707 "Insert the built-in construct template with NAME."
10709 (list (let ((completion-ignore-case t))
10710 (completing-read "Construct name: "
10711 vhdl-template-construct-alist nil t))))
10712 (vhdl-template-insert-fun
10713 (cadr (assoc name vhdl-template-construct-alist))))
10715 (defun vhdl-template-insert-package (name)
10716 "Insert the built-in package template with NAME."
10718 (list (let ((completion-ignore-case t))
10719 (completing-read "Package name: "
10720 vhdl-template-package-alist nil t))))
10721 (vhdl-template-insert-fun
10722 (cadr (assoc name vhdl-template-package-alist))))
10724 (defun vhdl-template-insert-directive (name)
10725 "Insert the built-in directive template with NAME."
10727 (list (let ((completion-ignore-case t))
10728 (completing-read "Directive name: "
10729 vhdl-template-directive-alist nil t))))
10730 (vhdl-template-insert-fun
10731 (cadr (assoc name vhdl-template-directive-alist))))
10733 (defun vhdl-template-insert-fun (fun)
10734 "Call FUN to insert a built-in template."
10735 (let ((caught (catch 'abort (when fun (funcall fun)))))
10736 (when (stringp caught) (message "%s" caught))))
10739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10741 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10743 (defun vhdl-model-insert (model-name)
10744 "Insert the user model with name MODEL-NAME."
10746 (let ((completion-ignore-case t))
10747 (list (completing-read "Model name: " vhdl-model-alist))))
10748 (indent-according-to-mode)
10749 (let ((start (point-marker))
10750 (margin (current-indentation))
10751 model position prompt string end)
10752 (vhdl-prepare-search-2
10753 (when (setq model (assoc model-name vhdl-model-alist))
10755 (beginning-of-line)
10756 (delete-horizontal-space)
10758 (vhdl-insert-string-or-file (nth 1 model))
10759 (setq end (point-marker))
10762 (beginning-of-line)
10763 (while (< (point) end)
10764 (unless (looking-at "^$")
10765 (insert-char ? margin))
10766 (beginning-of-line 2))
10769 (unless (equal "" vhdl-clock-name)
10770 (while (re-search-forward "<clock>" end t)
10771 (replace-match vhdl-clock-name)))
10774 (unless (equal "" vhdl-reset-name)
10775 (while (re-search-forward "<reset>" end t)
10776 (replace-match vhdl-reset-name)))
10777 ;; replace header prompts
10778 (vhdl-template-replace-header-keywords start end nil t)
10780 ;; query other prompts
10781 (while (re-search-forward
10782 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10783 (unless (equal "cursor" (match-string 1))
10784 (setq position (match-beginning 1))
10785 (setq prompt (match-string 1))
10787 (setq string (vhdl-template-field prompt nil t))
10788 ;; replace occurrences of same prompt
10789 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10790 (replace-match (or string "")))
10791 (goto-char position)))
10793 ;; goto final position
10794 (if (re-search-forward "<cursor>" end t)
10796 (goto-char end))))))
10798 (defun vhdl-model-defun ()
10799 "Define help and hook functions for user models."
10800 (let ((model-alist vhdl-model-alist)
10801 model-name model-keyword)
10803 ;; define functions for user models that can be invoked from menu and key
10804 ;; bindings and which themselves call `vhdl-model-insert' with the model
10805 ;; name as argument
10806 (setq model-name (nth 0 (car model-alist)))
10807 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10808 ,(concat "Insert model for \"" model-name "\".")
10810 (vhdl-model-insert ,model-name)))
10811 ;; define hooks for user models that are invoked from keyword abbrevs
10812 (setq model-keyword (nth 3 (car model-alist)))
10813 (unless (equal model-keyword "")
10815 ,(vhdl-function-name
10816 "vhdl-model" model-name "hook") ()
10817 (vhdl-hooked-abbrev
10818 ',(vhdl-function-name "vhdl-model" model-name)))))
10819 (setq model-alist (cdr model-alist)))))
10824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10825 ;;; Port translation
10826 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10828 (defvar vhdl-port-list nil
10829 "Variable to hold last port map parsed.")
10830 ;; structure: (parenthesised expression means list of such entries)
10832 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10833 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10834 ;; (lib-name pack-key))
10836 (defun vhdl-parse-string (string &optional optional)
10837 "Check that the text following point matches the regexp in STRING."
10838 (if (looking-at string)
10839 (goto-char (match-end 0))
10841 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10842 (vhdl-current-line) string)))
10845 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10846 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10847 (vhdl-prepare-search-1
10848 (if (string-match (car regexp-cons) string)
10850 (funcall vhdl-file-name-case
10851 (replace-match (cdr regexp-cons) t nil string))
10852 (replace-match (cdr regexp-cons) t nil string))
10855 (defun vhdl-parse-group-comment ()
10856 "Parse comment and empty lines between groups of lines."
10857 (let ((start (point))
10859 (vhdl-forward-comment (point-max))
10860 (setq string (buffer-substring-no-properties start (point)))
10861 (vhdl-forward-syntactic-ws)
10862 ;; strip off leading blanks and first newline
10863 (while (string-match "^\\(\\s-+\\)" string)
10864 (setq string (concat (substring string 0 (match-beginning 1))
10865 (substring string (match-end 1)))))
10866 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10867 (substring string 1)
10870 (defun vhdl-paste-group-comment (string indent)
10871 "Paste comment and empty lines from STRING between groups of lines
10873 (let ((pos (point-marker)))
10875 (while (string-match "^\\(--\\)" string)
10876 (setq string (concat (substring string 0 (match-beginning 1))
10877 (make-string indent ? )
10878 (substring string (match-beginning 1))))))
10879 (beginning-of-line)
10883 (defvar vhdl-port-flattened nil
10884 "Indicates whether a port has been flattened.")
10886 (defun vhdl-port-flatten (&optional as-alist)
10887 "Flatten port list so that only one generic/port exists per line.
10888 This operation is performed on an internally stored port and is only
10889 reflected in a subsequent paste operation."
10891 (if (not vhdl-port-list)
10892 (error "ERROR: No port has been read")
10893 (message "Flattening port for next paste...")
10894 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10895 (old-vhdl-port-list (cdr vhdl-port-list))
10896 old-port-list new-port-list old-port new-port names)
10897 ;; traverse port list and flatten entries
10898 (while (cdr old-vhdl-port-list)
10899 (setq old-port-list (car old-vhdl-port-list))
10900 (setq new-port-list nil)
10901 (while old-port-list
10902 (setq old-port (car old-port-list))
10903 (setq names (car old-port))
10905 (setq new-port (cons (if as-alist (car names) (list (car names)))
10907 (setq new-port-list (append new-port-list (list new-port)))
10908 (setq names (cdr names)))
10909 (setq old-port-list (cdr old-port-list)))
10910 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10911 (setq new-vhdl-port-list (append new-vhdl-port-list
10912 (list new-port-list))))
10913 (setq vhdl-port-list
10914 (append new-vhdl-port-list (list old-vhdl-port-list))
10915 vhdl-port-flattened t)
10916 (message "Flattening port for next paste...done"))))
10918 (defvar vhdl-port-reversed-direction nil
10919 "Indicates whether port directions are reversed.")
10921 (defun vhdl-port-reverse-direction ()
10922 "Reverse direction for all ports (useful in testbenches).
10923 This operation is performed on an internally stored port and is only
10924 reflected in a subsequent paste operation."
10926 (if (not vhdl-port-list)
10927 (error "ERROR: No port has been read")
10928 (message "Reversing port directions for next paste...")
10929 (let ((port-list (nth 2 vhdl-port-list))
10930 port-dir-car port-dir)
10931 ;; traverse port list and reverse directions
10933 (setq port-dir-car (cddr (car port-list))
10934 port-dir (car port-dir-car))
10935 (setcar port-dir-car
10936 (cond ((equal port-dir "in") "out")
10937 ((equal port-dir "out") "in")
10939 (setq port-list (cdr port-list)))
10940 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10941 (message "Reversing port directions for next paste...done"))))
10943 (defun vhdl-port-copy ()
10944 "Get generic and port information from an entity or component declaration."
10947 (let (parse-error end-of-list
10948 decl-type name generic-list port-list context-clause
10949 object names direct type init comment group-comment)
10950 (vhdl-prepare-search-2
10954 ;; check if within entity or component declaration
10956 (when (or (not (re-search-backward
10957 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10958 (equal "END" (upcase (match-string 1))))
10959 (throw 'parse "ERROR: Not within an entity or component declaration"))
10960 (setq decl-type (downcase (match-string-no-properties 1)))
10962 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10963 (setq name (match-string-no-properties 1))
10964 (message "Reading port of %s \"%s\"..." decl-type name)
10965 (vhdl-forward-syntactic-ws)
10966 ;; parse generic clause
10967 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10968 ;; parse group comment and spacing
10969 (setq group-comment (vhdl-parse-group-comment))
10970 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10971 (while (not end-of-list)
10972 ;; parse names (accept extended identifiers)
10973 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10974 (setq names (list (match-string-no-properties 1)))
10975 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10977 (append names (list (match-string-no-properties 1)))))
10979 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10980 (setq type (match-string-no-properties 1))
10982 (while (looking-at "(")
10985 (buffer-substring-no-properties
10986 (point) (progn (forward-sexp) (point)))
10987 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10988 (match-string-no-properties 1)))))
10989 ;; special case: closing parenthesis is on separate line
10990 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10991 (setq comment (substring type (match-beginning 2)))
10992 (setq type (substring type 0 (match-beginning 1))))
10993 ;; strip of trailing group-comment
10994 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10995 (setq type (substring type 0 (match-end 1)))
10996 ;; parse initialization expression
10998 (when (vhdl-parse-string ":=[ \t\n]*" t)
10999 (vhdl-parse-string "\\([^();\n]*\\)")
11000 (setq init (match-string-no-properties 1))
11001 (while (looking-at "(")
11004 (buffer-substring-no-properties
11005 (point) (progn (forward-sexp) (point)))
11006 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11007 (match-string-no-properties 1))))))
11008 ;; special case: closing parenthesis is on separate line
11009 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11010 (setq comment (substring init (match-beginning 2)))
11011 (setq init (substring init 0 (match-beginning 1)))
11012 (vhdl-forward-syntactic-ws))
11013 (skip-chars-forward " \t")
11014 ;; parse inline comment, special case: as above, no initial.
11016 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11017 (match-string-no-properties 1))))
11018 (vhdl-forward-syntactic-ws)
11019 (setq end-of-list (vhdl-parse-string ")" t))
11020 (vhdl-parse-string "\\s-*;\\s-*")
11021 ;; parse inline comment
11023 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11024 (match-string-no-properties 1))))
11025 ;; save everything in list
11026 (setq generic-list (append generic-list
11027 (list (list names type init
11028 comment group-comment))))
11029 ;; parse group comment and spacing
11030 (setq group-comment (vhdl-parse-group-comment))))
11031 ;; parse port clause
11032 (when (vhdl-parse-string "port[ \t\n]*(" t)
11033 ;; parse group comment and spacing
11034 (setq group-comment (vhdl-parse-group-comment))
11035 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11036 (while (not end-of-list)
11039 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11040 (match-string-no-properties 1)))
11041 ;; parse names (accept extended identifiers)
11042 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11043 (setq names (list (match-string-no-properties 1)))
11044 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11045 (setq names (append names (list (match-string-no-properties 1)))))
11047 (vhdl-parse-string ":[ \t\n]*")
11049 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11050 (match-string-no-properties 1)))
11052 (vhdl-parse-string "\\([^();\n]+\\)")
11053 (setq type (match-string-no-properties 1))
11055 (while (looking-at "(")
11056 (setq type (concat type
11057 (buffer-substring-no-properties
11058 (point) (progn (forward-sexp) (point)))
11059 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11060 (match-string-no-properties 1)))))
11061 ;; special case: closing parenthesis is on separate line
11062 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11063 (setq comment (substring type (match-beginning 2)))
11064 (setq type (substring type 0 (match-beginning 1))))
11065 ;; strip of trailing group-comment
11066 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11067 (setq type (substring type 0 (match-end 1)))
11068 (vhdl-forward-syntactic-ws)
11069 (setq end-of-list (vhdl-parse-string ")" t))
11070 (vhdl-parse-string "\\s-*;\\s-*")
11071 ;; parse inline comment
11073 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11074 (match-string-no-properties 1))))
11075 ;; save everything in list
11076 (setq port-list (append port-list
11077 (list (list names object direct type
11078 comment group-comment))))
11079 ;; parse group comment and spacing
11080 (setq group-comment (vhdl-parse-group-comment))))
11081 ; (vhdl-parse-string "end\\>")
11082 ;; parse context clause
11083 (setq context-clause (vhdl-scan-context-clause))
11084 ; ;; add surrounding package to context clause
11085 ; (when (and (equal decl-type "component")
11086 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11087 ; (setq context-clause
11088 ; (append context-clause
11089 ; (list (cons (vhdl-work-library)
11090 ; (match-string-no-properties 1))))))
11091 (message "Reading port of %s \"%s\"...done" decl-type name)
11095 (error parse-error)
11096 (setq vhdl-port-list (list name generic-list port-list context-clause)
11097 vhdl-port-reversed-direction nil
11098 vhdl-port-flattened nil)))))
11100 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11101 "Paste a context clause."
11102 (let ((margin (current-indentation))
11103 (clause-list (nth 3 vhdl-port-list))
11106 (setq clause (car clause-list))
11107 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11108 (downcase exclude-pack-name)))
11110 (re-search-backward
11111 (concat "^\\s-*use\\s-+" (car clause)
11112 "\." (cdr clause) "\\>") nil t)))
11113 (vhdl-template-standard-package (car clause) (cdr clause))
11115 (setq clause-list (cdr clause-list)))))
11117 (defun vhdl-port-paste-generic (&optional no-init)
11118 "Paste a generic clause."
11119 (let ((margin (current-indentation))
11120 (generic-list (nth 1 vhdl-port-list))
11121 list-margin start names generic)
11122 ;; paste generic clause
11124 (setq start (point))
11125 (vhdl-insert-keyword "GENERIC (")
11126 (unless vhdl-argument-list-indent
11127 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11128 (setq list-margin (current-column))
11129 (while generic-list
11130 (setq generic (car generic-list))
11131 ;; paste group comment and spacing
11132 (when (memq vhdl-include-group-comments '(decl always))
11133 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11135 (setq names (nth 0 generic))
11137 (insert (car names))
11138 (setq names (cdr names))
11139 (when names (insert ", ")))
11141 (insert " : " (nth 1 generic))
11142 ;; paste initialization
11143 (when (and (not no-init) (nth 2 generic))
11144 (insert " := " (nth 2 generic)))
11145 (unless (cdr generic-list) (insert ")"))
11148 (when (and vhdl-include-port-comments (nth 3 generic))
11149 (vhdl-comment-insert-inline (nth 3 generic) t))
11150 (setq generic-list (cdr generic-list))
11151 (when generic-list (insert "\n") (indent-to list-margin)))
11152 ;; align generic clause
11153 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11155 (defun vhdl-port-paste-port ()
11156 "Paste a port clause."
11157 (let ((margin (current-indentation))
11158 (port-list (nth 2 vhdl-port-list))
11159 list-margin start names port)
11160 ;; paste port clause
11162 (setq start (point))
11163 (vhdl-insert-keyword "PORT (")
11164 (unless vhdl-argument-list-indent
11165 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11166 (setq list-margin (current-column))
11168 (setq port (car port-list))
11169 ;; paste group comment and spacing
11170 (when (memq vhdl-include-group-comments '(decl always))
11171 (vhdl-paste-group-comment (nth 5 port) list-margin))
11173 (when (nth 1 port) (insert (nth 1 port) " "))
11175 (setq names (nth 0 port))
11177 (insert (car names))
11178 (setq names (cdr names))
11179 (when names (insert ", ")))
11182 (when (nth 2 port) (insert (nth 2 port) " "))
11184 (insert (nth 3 port))
11185 (unless (cdr port-list) (insert ")"))
11188 (when (and vhdl-include-port-comments (nth 4 port))
11189 (vhdl-comment-insert-inline (nth 4 port) t))
11190 (setq port-list (cdr port-list))
11191 (when port-list (insert "\n") (indent-to list-margin)))
11192 ;; align port clause
11193 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11195 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11196 "Paste as an entity or component declaration."
11197 (unless no-indent (indent-according-to-mode))
11198 (let ((margin (current-indentation))
11199 (name (nth 0 vhdl-port-list)))
11200 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11202 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11203 (vhdl-insert-keyword " IS"))
11204 ;; paste generic and port clause
11205 (when (nth 1 vhdl-port-list)
11207 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11209 (indent-to (+ margin vhdl-basic-offset))
11210 (vhdl-port-paste-generic (eq kind 'component)))
11211 (when (nth 2 vhdl-port-list)
11213 (when (and (memq vhdl-insert-empty-lines '(unit all))
11216 (indent-to (+ margin vhdl-basic-offset)))
11217 (vhdl-port-paste-port)
11219 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11222 (vhdl-insert-keyword "END")
11223 (if (eq kind 'entity)
11225 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11227 (vhdl-insert-keyword " COMPONENT")
11228 (unless (vhdl-standard-p '87) (insert " " name)))
11231 (defun vhdl-port-paste-entity (&optional no-indent)
11232 "Paste as an entity declaration."
11234 (if (not vhdl-port-list)
11235 (error "ERROR: No port read")
11236 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11237 (vhdl-port-paste-declaration 'entity no-indent)
11238 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11240 (defun vhdl-port-paste-component (&optional no-indent)
11241 "Paste as a component declaration."
11243 (if (not vhdl-port-list)
11244 (error "ERROR: No port read")
11245 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11246 (vhdl-port-paste-declaration 'component no-indent)
11247 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11249 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11250 "Paste as a generic map."
11252 (unless secondary (indent-according-to-mode))
11253 (let ((margin (current-indentation))
11254 list-margin start generic
11255 (generic-list (nth 1 vhdl-port-list)))
11257 (setq start (point))
11258 (vhdl-insert-keyword "GENERIC MAP (")
11259 (if (not vhdl-association-list-with-formals)
11260 ;; paste list of actual generics
11261 (while generic-list
11262 (insert (if no-constants
11263 (car (nth 0 (car generic-list)))
11264 (or (nth 2 (car generic-list)) " ")))
11265 (setq generic-list (cdr generic-list))
11266 (insert (if generic-list ", " ")"))
11267 (when (and (not generic-list) secondary
11268 (null (nth 2 vhdl-port-list)))
11270 (unless vhdl-argument-list-indent
11271 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11272 (setq list-margin (current-column))
11273 (while generic-list
11274 (setq generic (car generic-list))
11275 ;; paste group comment and spacing
11276 (when (eq vhdl-include-group-comments 'always)
11277 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11278 ;; paste formal and actual generic
11279 (insert (car (nth 0 generic)) " => "
11281 (car (nth 0 generic))
11282 (or (nth 2 generic) "")))
11283 (setq generic-list (cdr generic-list))
11284 (insert (if generic-list "," ")"))
11285 (when (and (not generic-list) secondary
11286 (null (nth 2 vhdl-port-list)))
11289 (when (or vhdl-include-type-comments
11290 (and vhdl-include-port-comments (nth 3 generic)))
11291 (vhdl-comment-insert-inline
11293 (when vhdl-include-type-comments
11294 (concat "[" (nth 1 generic) "] "))
11295 (when vhdl-include-port-comments (nth 3 generic))) t))
11296 (when generic-list (insert "\n") (indent-to list-margin)))
11297 ;; align generic map
11298 (when vhdl-auto-align
11299 (vhdl-align-region-groups start (point) 1 t))))))
11301 (defun vhdl-port-paste-port-map ()
11302 "Paste as a port map."
11303 (let ((margin (current-indentation))
11304 list-margin start port
11305 (port-list (nth 2 vhdl-port-list)))
11307 (setq start (point))
11308 (vhdl-insert-keyword "PORT MAP (")
11309 (if (not vhdl-association-list-with-formals)
11310 ;; paste list of actual ports
11312 (insert (vhdl-replace-string vhdl-actual-port-name
11313 (car (nth 0 (car port-list)))))
11314 (setq port-list (cdr port-list))
11315 (insert (if port-list ", " ")")))
11316 (unless vhdl-argument-list-indent
11317 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11318 (setq list-margin (current-column))
11320 (setq port (car port-list))
11321 ;; paste group comment and spacing
11322 (when (eq vhdl-include-group-comments 'always)
11323 (vhdl-paste-group-comment (nth 5 port) list-margin))
11324 ;; paste formal and actual port
11325 (insert (car (nth 0 port)) " => ")
11326 (insert (vhdl-replace-string vhdl-actual-port-name
11327 (car (nth 0 port))))
11328 (setq port-list (cdr port-list))
11329 (insert (if port-list "," ");"))
11331 (when (or vhdl-include-direction-comments
11332 vhdl-include-type-comments
11333 (and vhdl-include-port-comments (nth 4 port)))
11334 (vhdl-comment-insert-inline
11336 (cond ((and vhdl-include-direction-comments
11337 vhdl-include-type-comments)
11338 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11339 (nth 3 port) "] "))
11340 ((and vhdl-include-direction-comments (nth 2 port))
11341 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11342 (vhdl-include-direction-comments " ")
11343 (vhdl-include-type-comments
11344 (concat "[" (nth 3 port) "] ")))
11345 (when vhdl-include-port-comments (nth 4 port))) t))
11346 (when port-list (insert "\n") (indent-to list-margin)))
11347 ;; align port clause
11348 (when vhdl-auto-align
11349 (vhdl-align-region-groups start (point) 1))))))
11351 (defun vhdl-port-paste-instance (&optional name no-indent title)
11352 "Paste as an instantiation."
11354 (if (not vhdl-port-list)
11355 (error "ERROR: No port read")
11356 (let ((orig-vhdl-port-list vhdl-port-list))
11357 ;; flatten local copy of port list (must be flat for port mapping)
11358 (vhdl-port-flatten)
11359 (unless no-indent (indent-according-to-mode))
11360 (let ((margin (current-indentation)))
11361 ;; paste instantiation
11364 ((equal (cdr vhdl-instance-name) "")
11365 (setq name (vhdl-template-field "instance name")))
11366 ((string-match "\%d" (cdr vhdl-instance-name))
11368 (while (save-excursion
11369 (setq name (format (vhdl-replace-string
11371 (nth 0 vhdl-port-list)) n))
11372 (goto-char (point-min))
11373 (vhdl-re-search-forward name nil t))
11376 (t (insert (vhdl-replace-string vhdl-instance-name
11377 (nth 0 vhdl-port-list)))))
11378 (message "Pasting port as instantiation \"%s\"..." name)
11382 (beginning-of-line)
11383 (indent-to vhdl-basic-offset)
11384 (insert "-- instance \"" name "\"\n")))
11385 (if (not (vhdl-use-direct-instantiation))
11386 (insert (nth 0 vhdl-port-list))
11387 (vhdl-insert-keyword "ENTITY ")
11388 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11389 (when (nth 1 vhdl-port-list)
11390 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11391 (vhdl-port-paste-generic-map t t))
11392 (when (nth 2 vhdl-port-list)
11393 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11394 (vhdl-port-paste-port-map))
11395 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11397 (message "Pasting port as instantiation \"%s\"...done" name))
11398 (setq vhdl-port-list orig-vhdl-port-list))))
11400 (defun vhdl-port-paste-constants (&optional no-indent)
11401 "Paste generics as constants."
11403 (if (not vhdl-port-list)
11404 (error "ERROR: No port read")
11405 (let ((orig-vhdl-port-list vhdl-port-list))
11406 (message "Pasting port as constants...")
11407 ;; flatten local copy of port list (must be flat for constant initial.)
11408 (vhdl-port-flatten)
11409 (unless no-indent (indent-according-to-mode))
11410 (let ((margin (current-indentation))
11412 (generic-list (nth 1 vhdl-port-list)))
11414 (setq start (point))
11415 (while generic-list
11416 (setq generic (car generic-list))
11417 ;; paste group comment and spacing
11418 (when (memq vhdl-include-group-comments '(decl always))
11419 (vhdl-paste-group-comment (nth 4 generic) margin))
11420 (vhdl-insert-keyword "CONSTANT ")
11421 ;; paste generic constants
11422 (setq name (nth 0 generic))
11424 (insert (car name))
11426 (insert " : " (nth 1 generic))
11427 ;; paste initialization
11428 (when (nth 2 generic)
11429 (insert " := " (nth 2 generic)))
11432 (when (and vhdl-include-port-comments (nth 3 generic))
11433 (vhdl-comment-insert-inline (nth 3 generic) t))
11434 (setq generic-list (cdr generic-list))
11435 (when generic-list (insert "\n") (indent-to margin))))
11436 ;; align signal list
11437 (when vhdl-auto-align
11438 (vhdl-align-region-groups start (point) 1))))
11439 (message "Pasting port as constants...done")
11440 (setq vhdl-port-list orig-vhdl-port-list))))
11442 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11443 "Paste ports as internal signals."
11445 (if (not vhdl-port-list)
11446 (error "ERROR: No port read")
11447 (message "Pasting port as signals...")
11448 (unless no-indent (indent-according-to-mode))
11449 (let ((margin (current-indentation))
11451 (port-list (nth 2 vhdl-port-list)))
11453 (setq start (point))
11455 (setq port (car port-list))
11456 ;; paste group comment and spacing
11457 (when (memq vhdl-include-group-comments '(decl always))
11458 (vhdl-paste-group-comment (nth 5 port) margin))
11461 (insert (nth 1 port) " ")
11462 (vhdl-insert-keyword "SIGNAL "))
11463 ;; paste actual port signals
11464 (setq names (nth 0 port))
11466 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11467 (setq names (cdr names))
11468 (when names (insert ", ")))
11470 (insert " : " (nth 3 port))
11471 ;; paste initialization (inputs only)
11472 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11473 (insert " := " (if (string-match "(.+)" (nth 3 port))
11474 "(others => '0')" "'0'")))
11477 (when (or vhdl-include-direction-comments
11478 (and vhdl-include-port-comments (nth 4 port)))
11479 (vhdl-comment-insert-inline
11481 (cond ((and vhdl-include-direction-comments (nth 2 port))
11482 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11483 (vhdl-include-direction-comments " "))
11484 (when vhdl-include-port-comments (nth 4 port))) t))
11485 (setq port-list (cdr port-list))
11486 (when port-list (insert "\n") (indent-to margin)))
11487 ;; align signal list
11488 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11489 (message "Pasting port as signals...done")))
11491 (defun vhdl-port-paste-initializations (&optional no-indent)
11492 "Paste ports as signal initializations."
11494 (if (not vhdl-port-list)
11495 (error "ERROR: No port read")
11496 (let ((orig-vhdl-port-list vhdl-port-list))
11497 (message "Pasting port as initializations...")
11498 ;; flatten local copy of port list (must be flat for signal initial.)
11499 (vhdl-port-flatten)
11500 (unless no-indent (indent-according-to-mode))
11501 (let ((margin (current-indentation))
11503 (port-list (nth 2 vhdl-port-list)))
11505 (setq start (point))
11507 (setq port (car port-list))
11508 ;; paste actual port signal (inputs only)
11509 (when (equal "IN" (upcase (nth 2 port)))
11510 (setq name (car (nth 0 port)))
11511 (insert (vhdl-replace-string vhdl-actual-port-name name))
11512 ;; paste initialization
11513 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11514 "(others => '0')" "'0'") ";"))
11515 (setq port-list (cdr port-list))
11516 (when (and port-list
11517 (equal "IN" (upcase (nth 2 (car port-list)))))
11518 (insert "\n") (indent-to margin)))
11519 ;; align signal list
11520 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11521 (message "Pasting port as initializations...done")
11522 (setq vhdl-port-list orig-vhdl-port-list))))
11524 (defun vhdl-port-paste-testbench ()
11525 "Paste as a bare-bones testbench."
11527 (if (not vhdl-port-list)
11528 (error "ERROR: No port read")
11529 (let ((case-fold-search t)
11530 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11531 (nth 0 vhdl-port-list)))
11532 (source-buffer (current-buffer))
11533 arch-name config-name ent-file-name arch-file-name
11534 ent-buffer arch-buffer position)
11535 ;; open entity file
11536 (unless (eq vhdl-testbench-create-files 'none)
11537 (setq ent-file-name
11538 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11540 "." (file-name-extension (buffer-file-name))))
11541 (if (file-exists-p ent-file-name)
11543 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11544 (progn (find-file ent-file-name)
11546 (set-buffer-modified-p nil))
11547 (if (eq vhdl-testbench-create-files 'separate)
11548 (setq ent-file-name nil)
11549 (error "ERROR: Pasting port as testbench...aborted")))
11550 (find-file ent-file-name)))
11551 (unless (and (eq vhdl-testbench-create-files 'separate)
11552 (null ent-file-name))
11553 ;; paste entity header
11554 (if vhdl-testbench-include-header
11555 (progn (vhdl-template-header
11556 (concat "Testbench for design \""
11557 (nth 0 vhdl-port-list) "\""))
11558 (goto-char (point-max)))
11559 (vhdl-comment-display-line) (insert "\n\n"))
11560 ;; paste std_logic_1164 package
11561 (when vhdl-testbench-include-library
11562 (vhdl-template-package-std-logic-1164)
11563 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11564 ;; paste entity declaration
11565 (vhdl-insert-keyword "ENTITY ")
11567 (vhdl-insert-keyword " IS")
11568 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11570 (vhdl-insert-keyword "END ")
11571 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11572 (insert ent-name ";")
11574 (vhdl-comment-display-line) (insert "\n"))
11575 ;; get architecture name
11576 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11577 (read-from-minibuffer "architecture name: "
11578 nil vhdl-minibuffer-local-map)
11579 (vhdl-replace-string vhdl-testbench-architecture-name
11580 (nth 0 vhdl-port-list))))
11581 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11582 ;; open architecture file
11583 (if (not (eq vhdl-testbench-create-files 'separate))
11585 (setq ent-buffer (current-buffer))
11586 (setq arch-file-name
11587 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11588 (concat ent-name " " arch-name) t)
11589 "." (file-name-extension (buffer-file-name))))
11590 (when (and (file-exists-p arch-file-name)
11591 (not (y-or-n-p (concat "File \"" arch-file-name
11592 "\" exists; overwrite? "))))
11593 (error "ERROR: Pasting port as testbench...aborted"))
11594 (find-file arch-file-name)
11596 (set-buffer-modified-p nil)
11597 ;; paste architecture header
11598 (if vhdl-testbench-include-header
11599 (progn (vhdl-template-header
11600 (concat "Testbench architecture for design \""
11601 (nth 0 vhdl-port-list) "\""))
11602 (goto-char (point-max)))
11603 (vhdl-comment-display-line) (insert "\n\n")))
11604 ;; paste architecture body
11605 (vhdl-insert-keyword "ARCHITECTURE ")
11607 (vhdl-insert-keyword " OF ")
11609 (vhdl-insert-keyword " IS")
11610 (insert "\n\n") (indent-to vhdl-basic-offset)
11611 ;; paste component declaration
11612 (unless (vhdl-use-direct-instantiation)
11613 (vhdl-port-paste-component t)
11614 (insert "\n\n") (indent-to vhdl-basic-offset))
11616 (when (nth 1 vhdl-port-list)
11617 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11618 (vhdl-port-paste-constants t)
11619 (insert "\n\n") (indent-to vhdl-basic-offset))
11620 ;; paste internal signals
11621 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11622 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11624 ;; paste custom declarations
11625 (unless (equal "" vhdl-testbench-declarations)
11627 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11628 (setq position (point))
11630 (vhdl-comment-display-line) (insert "\n")
11631 (when vhdl-testbench-include-configuration
11632 (setq config-name (vhdl-replace-string
11633 vhdl-testbench-configuration-name
11634 (concat ent-name " " arch-name)))
11636 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11637 (vhdl-insert-keyword " OF ") (insert ent-name)
11638 (vhdl-insert-keyword " IS\n")
11639 (indent-to vhdl-basic-offset)
11640 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11641 (indent-to vhdl-basic-offset)
11642 (vhdl-insert-keyword "END FOR;\n")
11643 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11644 (vhdl-comment-display-line) (insert "\n"))
11645 (goto-char position)
11646 (vhdl-template-begin-end
11647 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11648 ;; paste instantiation
11649 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11650 (vhdl-port-paste-instance
11651 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11653 ;; paste custom statements
11654 (unless (equal "" vhdl-testbench-statements)
11656 (vhdl-insert-string-or-file vhdl-testbench-statements))
11658 (indent-to vhdl-basic-offset)
11659 (unless (eq vhdl-testbench-create-files 'none)
11660 (setq arch-buffer (current-buffer))
11661 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11662 (set-buffer arch-buffer) (save-buffer))
11664 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11665 ent-name arch-name)
11667 (format "\n File created: \"%s\"" ent-file-name))
11668 (and arch-file-name
11669 (format "\n File created: \"%s\"" arch-file-name)))))))
11672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11673 ;;; Subprogram interface translation
11674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11676 (defvar vhdl-subprog-list nil
11677 "Variable to hold last subprogram interface parsed.")
11678 ;; structure: (parenthesised expression means list of such entries)
11679 ;; (subprog-name kind
11680 ;; ((names) object direct type init comment group-comment)
11681 ;; return-type return-comment group-comment)
11683 (defvar vhdl-subprog-flattened nil
11684 "Indicates whether an subprogram interface has been flattened.")
11686 (defun vhdl-subprog-flatten ()
11687 "Flatten interface list so that only one parameter exists per line."
11689 (if (not vhdl-subprog-list)
11690 (error "ERROR: No subprogram interface has been read")
11691 (message "Flattening subprogram interface...")
11692 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11693 new-subprog-list old-subprog new-subprog names)
11694 ;; traverse parameter list and flatten entries
11695 (while old-subprog-list
11696 (setq old-subprog (car old-subprog-list))
11697 (setq names (car old-subprog))
11699 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11700 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11701 (setq names (cdr names)))
11702 (setq old-subprog-list (cdr old-subprog-list)))
11703 (setq vhdl-subprog-list
11704 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11705 new-subprog-list (nth 3 vhdl-subprog-list)
11706 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11707 vhdl-subprog-flattened t)
11708 (message "Flattening subprogram interface...done"))))
11710 (defun vhdl-subprog-copy ()
11711 "Get interface information from a subprogram specification."
11714 (let (parse-error pos end-of-list
11715 name kind param-list object names direct type init
11716 comment group-comment
11717 return-type return-comment return-group-comment)
11718 (vhdl-prepare-search-2
11722 ;; check if within function declaration
11725 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11726 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11727 (goto-char (match-end 0))
11728 (save-excursion (backward-char)
11731 (throw 'parse "ERROR: Not within a subprogram specification"))
11732 (setq name (match-string-no-properties 5))
11733 (setq kind (if (match-string 2) 'procedure 'function))
11734 (setq end-of-list (not (match-string 7)))
11735 (message "Reading interface of subprogram \"%s\"..." name)
11736 ;; parse parameter list
11737 (setq group-comment (vhdl-parse-group-comment))
11738 (setq end-of-list (or end-of-list
11739 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11740 (while (not end-of-list)
11743 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11744 (match-string-no-properties 1)))
11745 ;; parse names (accept extended identifiers)
11746 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11747 (setq names (list (match-string-no-properties 1)))
11748 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11749 (setq names (append names (list (match-string-no-properties 1)))))
11751 (vhdl-parse-string ":[ \t\n]*")
11753 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11754 (match-string-no-properties 1)))
11756 (vhdl-parse-string "\\([^():;\n]+\\)")
11757 (setq type (match-string-no-properties 1))
11759 (while (looking-at "(")
11762 (buffer-substring-no-properties
11763 (point) (progn (forward-sexp) (point)))
11764 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11765 (match-string-no-properties 1)))))
11766 ;; special case: closing parenthesis is on separate line
11767 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11768 (setq comment (substring type (match-beginning 2)))
11769 (setq type (substring type 0 (match-beginning 1))))
11770 ;; strip off trailing group-comment
11771 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11772 (setq type (substring type 0 (match-end 1)))
11773 ;; parse initialization expression
11775 (when (vhdl-parse-string ":=[ \t\n]*" t)
11776 (vhdl-parse-string "\\([^();\n]*\\)")
11777 (setq init (match-string-no-properties 1))
11778 (while (looking-at "(")
11781 (buffer-substring-no-properties
11782 (point) (progn (forward-sexp) (point)))
11783 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11784 (match-string-no-properties 1))))))
11785 ;; special case: closing parenthesis is on separate line
11786 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11787 (setq comment (substring init (match-beginning 2)))
11788 (setq init (substring init 0 (match-beginning 1)))
11789 (vhdl-forward-syntactic-ws))
11790 (skip-chars-forward " \t")
11791 ;; parse inline comment, special case: as above, no initial.
11793 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11794 (match-string-no-properties 1))))
11795 (vhdl-forward-syntactic-ws)
11796 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11797 ;; parse inline comment
11799 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11800 (match-string-no-properties 1))))
11801 (setq return-group-comment (vhdl-parse-group-comment))
11802 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11803 ;; parse return type
11804 (when (match-string 3)
11805 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11806 (setq return-type (match-string-no-properties 1))
11807 (when (and return-type
11808 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11809 (setq return-comment (substring return-type (match-beginning 2)))
11810 (setq return-type (substring return-type 0 (match-beginning 1))))
11811 ;; strip of trailing group-comment
11812 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11813 (setq return-type (substring return-type 0 (match-end 1)))
11814 ;; parse return comment
11815 (unless return-comment
11816 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11817 (match-string-no-properties 1)))))
11818 ;; parse inline comment
11820 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11821 (match-string-no-properties 1))))
11822 ;; save everything in list
11823 (setq param-list (append param-list
11824 (list (list names object direct type init
11825 comment group-comment))))
11826 ;; parse group comment and spacing
11827 (setq group-comment (vhdl-parse-group-comment)))
11828 (message "Reading interface of subprogram \"%s\"...done" name)
11832 (error parse-error)
11833 (setq vhdl-subprog-list
11834 (list name kind param-list return-type return-comment
11835 return-group-comment)
11836 vhdl-subprog-flattened nil)))))
11838 (defun vhdl-subprog-paste-specification (kind)
11839 "Paste as a subprogram specification."
11840 (indent-according-to-mode)
11841 (let ((margin (current-column))
11842 (param-list (nth 2 vhdl-subprog-list))
11843 list-margin start names param)
11844 ;; paste keyword and name
11845 (vhdl-insert-keyword
11846 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11847 (insert (nth 0 vhdl-subprog-list))
11848 (if (not param-list)
11849 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11850 (setq start (point))
11851 ;; paste parameter list
11853 (unless vhdl-argument-list-indent
11854 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11855 (setq list-margin (current-column))
11857 (setq param (car param-list))
11858 ;; paste group comment and spacing
11859 (when (memq vhdl-include-group-comments (list kind 'always))
11860 (vhdl-paste-group-comment (nth 6 param) list-margin))
11862 (when (nth 1 param) (insert (nth 1 param) " "))
11864 (setq names (nth 0 param))
11866 (insert (car names))
11867 (setq names (cdr names))
11868 (when names (insert ", ")))
11871 (when (nth 2 param) (insert (nth 2 param) " "))
11873 (insert (nth 3 param))
11874 ;; paste initialization
11875 (when (nth 4 param) (insert " := " (nth 4 param)))
11877 (if (cdr param-list)
11880 (when (null (nth 3 vhdl-subprog-list))
11881 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11883 (when (and vhdl-include-port-comments (nth 5 param))
11884 (vhdl-comment-insert-inline (nth 5 param) t))
11885 (setq param-list (cdr param-list))
11886 (when param-list (insert "\n") (indent-to list-margin)))
11887 (when (nth 3 vhdl-subprog-list)
11888 (insert "\n") (indent-to list-margin)
11889 ;; paste group comment and spacing
11890 (when (memq vhdl-include-group-comments (list kind 'always))
11891 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11892 ;; paste return type
11893 (insert "return " (nth 3 vhdl-subprog-list))
11894 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11895 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11896 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11897 ;; align parameter list
11898 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11900 (when (eq kind 'body)
11902 (vhdl-template-begin-end
11903 (unless (vhdl-standard-p '87)
11904 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11905 (nth 0 vhdl-subprog-list) margin))))
11907 (defun vhdl-subprog-paste-declaration ()
11908 "Paste as a subprogram declaration."
11910 (if (not vhdl-subprog-list)
11911 (error "ERROR: No subprogram interface read")
11912 (message "Pasting interface as subprogram declaration \"%s\"..."
11913 (car vhdl-subprog-list))
11914 ;; paste specification
11915 (vhdl-subprog-paste-specification 'decl)
11916 (message "Pasting interface as subprogram declaration \"%s\"...done"
11917 (car vhdl-subprog-list))))
11919 (defun vhdl-subprog-paste-body ()
11920 "Paste as a subprogram body."
11922 (if (not vhdl-subprog-list)
11923 (error "ERROR: No subprogram interface read")
11924 (message "Pasting interface as subprogram body \"%s\"..."
11925 (car vhdl-subprog-list))
11926 ;; paste specification and body
11927 (vhdl-subprog-paste-specification 'body)
11928 (message "Pasting interface as subprogram body \"%s\"...done"
11929 (car vhdl-subprog-list))))
11931 (defun vhdl-subprog-paste-call ()
11932 "Paste as a subprogram call."
11934 (if (not vhdl-subprog-list)
11935 (error "ERROR: No subprogram interface read")
11936 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11937 param-list margin list-margin param start)
11938 ;; flatten local copy of interface list (must be flat for parameter mapping)
11939 (vhdl-subprog-flatten)
11940 (setq param-list (nth 2 vhdl-subprog-list))
11941 (indent-according-to-mode)
11942 (setq margin (current-indentation))
11943 (message "Pasting interface as subprogram call \"%s\"..."
11944 (car vhdl-subprog-list))
11946 (insert (nth 0 vhdl-subprog-list))
11947 (if (not param-list)
11949 (setq start (point))
11950 ;; paste parameter list
11952 (unless vhdl-argument-list-indent
11953 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11954 (setq list-margin (current-column))
11956 (setq param (car param-list))
11957 ;; paste group comment and spacing
11958 (when (eq vhdl-include-group-comments 'always)
11959 (vhdl-paste-group-comment (nth 6 param) list-margin))
11960 ;; paste formal port
11961 (insert (car (nth 0 param)) " => ")
11962 (setq param-list (cdr param-list))
11963 (insert (if param-list "," ");"))
11965 (when (and vhdl-include-port-comments (nth 5 param))
11966 (vhdl-comment-insert-inline (nth 5 param)))
11967 (when param-list (insert "\n") (indent-to list-margin)))
11968 ;; align parameter list
11969 (when vhdl-auto-align
11970 (vhdl-align-region-groups start (point) 1)))
11971 (message "Pasting interface as subprogram call \"%s\"...done"
11972 (car vhdl-subprog-list))
11973 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11981 ;; Hippie expand customization
11983 (defvar vhdl-expand-upper-case nil)
11985 (defun vhdl-try-expand-abbrev (old)
11986 "Try expanding abbreviations from `vhdl-abbrev-list'."
11988 (he-init-string (he-dabbrev-beg) (point))
11989 (setq he-expand-list
11990 (let ((abbrev-list vhdl-abbrev-list)
11991 (sel-abbrev-list '()))
11993 (when (or (not (stringp (car abbrev-list)))
11995 (concat "^" he-search-string) (car abbrev-list)))
11996 (setq sel-abbrev-list
11997 (cons (car abbrev-list) sel-abbrev-list)))
11998 (setq abbrev-list (cdr abbrev-list)))
11999 (nreverse sel-abbrev-list))))
12000 (while (and he-expand-list
12001 (or (not (stringp (car he-expand-list)))
12002 (he-string-member (car he-expand-list) he-tried-table t)))
12003 ; (equal (car he-expand-list) he-search-string)))
12004 (unless (stringp (car he-expand-list))
12005 (setq vhdl-expand-upper-case (car he-expand-list)))
12006 (setq he-expand-list (cdr he-expand-list)))
12007 (if (null he-expand-list)
12008 (progn (when old (he-reset-string))
12010 (he-substitute-string
12011 (if vhdl-expand-upper-case
12012 (upcase (car he-expand-list))
12013 (car he-expand-list))
12015 (setq he-expand-list (cdr he-expand-list))
12018 (defun vhdl-he-list-beg ()
12019 "Also looks at the word before `(' in order to better match parenthesized
12020 expressions (e.g. for index ranges of types and signals)."
12023 (progn (backward-up-list 1)
12024 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12028 ;; override `he-list-beg' from `hippie-exp'
12029 (unless (and (boundp 'viper-mode) viper-mode)
12030 (defalias 'he-list-beg 'vhdl-he-list-beg))
12032 ;; function for expanding abbrevs and dabbrevs
12033 (defun vhdl-expand-abbrev (arg))
12034 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12035 '(try-expand-dabbrev
12036 try-expand-dabbrev-all-buffers
12037 vhdl-try-expand-abbrev)))
12039 ;; function for expanding parenthesis
12040 (defun vhdl-expand-paren (arg))
12041 (fset 'vhdl-expand-paren (make-hippie-expand-function
12043 try-expand-list-all-buffers)))
12045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12048 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12049 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12050 depending on parameter UPPER-CASE."
12051 (let ((case-replace nil)
12053 (vhdl-prepare-search-2
12056 (setq end (point-marker))
12058 (while (re-search-forward word-regexp end t)
12059 (or (vhdl-in-literal)
12062 (downcase-word -1)))
12063 (when (and count vhdl-progress-interval (not noninteractive)
12064 (< vhdl-progress-interval
12065 (- (nth 1 (current-time)) last-update)))
12066 (message "Fixing case... (%2d%s)"
12067 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12069 (setq last-update (nth 1 (current-time)))))
12070 (goto-char end)))))
12072 (defun vhdl-fix-case-region (beg end &optional arg)
12073 "Convert all VHDL words in region to lower or upper case, depending on
12074 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12075 (interactive "r\nP")
12076 (vhdl-fix-case-region-1
12077 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12078 (vhdl-fix-case-region-1
12079 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12080 (vhdl-fix-case-region-1
12081 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12082 (vhdl-fix-case-region-1
12083 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12084 (when vhdl-progress-interval (message "Fixing case...done")))
12086 (defun vhdl-fix-case-buffer ()
12087 "Convert all VHDL words in buffer to lower or upper case, depending on
12088 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12090 (vhdl-fix-case-region (point-min) (point-max)))
12092 (defun vhdl-fix-case-word (&optional arg)
12093 "Convert word after cursor to upper case if necessary."
12096 (when arg (backward-word 1))
12097 (vhdl-prepare-search-1
12098 (when (and vhdl-upper-case-keywords
12099 (looking-at vhdl-keywords-regexp))
12101 (when (and vhdl-upper-case-types
12102 (looking-at vhdl-types-regexp))
12104 (when (and vhdl-upper-case-attributes
12105 (looking-at vhdl-attributes-regexp))
12107 (when (and vhdl-upper-case-enum-values
12108 (looking-at vhdl-enum-values-regexp))
12109 (upcase-word 1)))))
12111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12112 ;; Line handling functions
12114 (defun vhdl-current-line ()
12115 "Return the line number of the line containing point."
12118 (1+ (count-lines (point-min) (point-at-bol)))))
12120 (defun vhdl-line-kill-entire (&optional arg)
12121 "Delete entire line."
12123 (beginning-of-line)
12124 (kill-line (or arg 1)))
12126 (defun vhdl-line-kill (&optional arg)
12127 "Kill current line."
12129 (vhdl-line-kill-entire arg))
12131 (defun vhdl-line-copy (&optional arg)
12132 "Copy current line."
12135 (let ((position (point-at-bol)))
12136 (forward-line (or arg 1))
12137 (copy-region-as-kill position (point)))))
12139 (defun vhdl-line-yank ()
12140 "Yank entire line."
12142 (beginning-of-line)
12145 (defun vhdl-line-expand (&optional prefix-arg)
12146 "Hippie-expand current line."
12148 (let ((case-fold-search t) (case-replace nil)
12149 (hippie-expand-try-functions-list
12150 '(try-expand-line try-expand-line-all-buffers)))
12151 (hippie-expand prefix-arg)))
12153 (defun vhdl-line-transpose-next (&optional arg)
12154 "Interchange this line with next line."
12157 (transpose-lines (or arg 1))
12160 (defun vhdl-line-transpose-previous (&optional arg)
12161 "Interchange this line with previous line."
12164 (transpose-lines (- 0 (or arg 0)))
12167 (defun vhdl-line-open ()
12168 "Open a new line and indent."
12171 (newline-and-indent))
12173 (defun vhdl-delete-indentation ()
12174 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12175 it works within comments too."
12177 (let ((fill-prefix "-- "))
12178 (delete-indentation)))
12180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12183 (defun vhdl-forward-same-indent ()
12184 "Move forward to next line with same indent."
12186 (let ((pos (point))
12187 (indent (current-indentation)))
12188 (beginning-of-line 2)
12189 (while (and (not (eobp))
12190 (or (looking-at "^\\s-*\\(--.*\\)?$")
12191 (> (current-indentation) indent)))
12192 (beginning-of-line 2))
12193 (if (= (current-indentation) indent)
12194 (back-to-indentation)
12195 (message "No following line with same indent found in this block")
12199 (defun vhdl-backward-same-indent ()
12200 "Move backward to previous line with same indent."
12202 (let ((pos (point))
12203 (indent (current-indentation)))
12204 (beginning-of-line -0)
12205 (while (and (not (bobp))
12206 (or (looking-at "^\\s-*\\(--.*\\)?$")
12207 (> (current-indentation) indent)))
12208 (beginning-of-line -0))
12209 (if (= (current-indentation) indent)
12210 (back-to-indentation)
12211 (message "No preceding line with same indent found in this block")
12215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12218 (defun vhdl-statistics-buffer ()
12219 "Get some file statistics."
12223 (no-lines (count-lines (point-min) (point-max))))
12225 ;; count statements
12226 (goto-char (point-min))
12227 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12228 (if (match-string 1)
12229 (goto-char (match-end 1))
12230 (setq no-stats (1+ no-stats))))
12231 ;; count code lines
12232 (goto-char (point-min))
12233 (while (not (eobp))
12234 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12235 (setq no-code-lines (1+ no-code-lines)))
12236 (beginning-of-line 2)))
12239 File statistics: \"%s\"\n\
12240 ---------------------\n\
12241 # statements : %5d\n\
12242 # code lines : %5d\n\
12243 # total lines : %5d\n\ "
12244 (buffer-file-name) no-stats no-code-lines no-lines)
12245 (unless vhdl-emacs-21 (vhdl-show-messages))))
12247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12250 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12251 "Like `re-search-forward', but does not match within literals."
12254 (while (and (setq pos (re-search-forward regexp bound noerror count))
12255 (vhdl-in-literal))))
12256 (when pos (goto-char pos))
12259 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12260 "Like `re-search-backward', but does not match within literals."
12263 (while (and (setq pos (re-search-backward regexp bound noerror count))
12264 (vhdl-in-literal))))
12265 (when pos (goto-char pos))
12269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12273 (defun vhdl-set-project (name)
12274 "Set current project to NAME."
12276 (list (let ((completion-ignore-case t))
12277 (completing-read "Project name: " vhdl-project-alist nil t))))
12278 (cond ((equal name "")
12279 (setq vhdl-project nil)
12280 (message "Current VHDL project: None"))
12281 ((assoc name vhdl-project-alist)
12282 (setq vhdl-project name)
12283 (message "Current VHDL project: \"%s\"" name))
12285 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12286 (vhdl-speedbar-update-current-project))
12288 (defun vhdl-set-default-project ()
12289 "Set current project as default on startup."
12291 (customize-set-variable 'vhdl-project vhdl-project)
12292 (customize-save-customized))
12294 (defun vhdl-toggle-project (name token indent)
12295 "Set current project to NAME or unset if NAME is current project."
12296 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12298 (defun vhdl-export-project (file-name)
12299 "Write project setup for current project."
12301 (let ((name (vhdl-resolve-env-variable
12302 (vhdl-replace-string
12303 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12304 (concat (subst-char-in-string
12305 ? ?_ (or (vhdl-project-p)
12306 (error "ERROR: No current project")))
12307 " " (user-login-name))))))
12308 (list (read-file-name
12309 "Write project file: "
12310 (when (file-name-absolute-p name) "") nil nil name))))
12311 (setq file-name (abbreviate-file-name file-name))
12312 (let ((orig-buffer (current-buffer)))
12313 (unless (file-exists-p (file-name-directory file-name))
12314 (make-directory (file-name-directory file-name) t))
12315 (if (not (file-writable-p file-name))
12316 (error "ERROR: File not writable: \"%s\"" file-name)
12317 (set-buffer (find-file-noselect file-name t t))
12319 (insert ";; -*- Emacs-Lisp -*-\n\n"
12320 ";;; " (file-name-nondirectory file-name)
12321 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12322 ";; Project : " vhdl-project "\n"
12323 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12324 (user-login-name) "\n\n\n"
12325 ";; project name\n"
12326 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12327 ";; project setup\n"
12328 "(aput 'vhdl-project-alist vhdl-project\n'")
12329 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12332 (kill-buffer (current-buffer))
12333 (set-buffer orig-buffer))))
12335 (defun vhdl-import-project (file-name &optional auto not-make-current)
12336 "Read project setup and set current project."
12338 (let ((name (vhdl-resolve-env-variable
12339 (vhdl-replace-string
12340 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12341 (concat "" " " (user-login-name))))))
12342 (list (read-file-name
12343 "Read project file: " (when (file-name-absolute-p name) "") nil t
12344 (file-name-directory name)))))
12345 (when (file-exists-p file-name)
12347 (let ((current-project vhdl-project))
12348 (load-file file-name)
12349 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12350 (adelete 'vhdl-project-alist vhdl-project)
12352 (when not-make-current
12353 (setq vhdl-project current-project))
12354 (vhdl-update-mode-menu)
12355 (vhdl-speedbar-refresh)
12356 (unless not-make-current
12357 (message "Current VHDL project: \"%s\"%s"
12358 vhdl-project (if auto " (auto-loaded)" ""))))
12359 (error (vhdl-warning
12360 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12362 (defun vhdl-duplicate-project ()
12363 "Duplicate setup of current project."
12365 (let ((new-name (read-from-minibuffer "New project name: "))
12366 (project-entry (aget vhdl-project-alist vhdl-project t)))
12367 (setq vhdl-project-alist
12368 (append vhdl-project-alist
12369 (list (cons new-name project-entry))))
12370 (vhdl-update-mode-menu)))
12372 (defun vhdl-auto-load-project ()
12373 "Automatically load project setup at startup."
12374 (let ((file-name-list vhdl-project-file-name)
12375 file-list list-length)
12376 (while file-name-list
12379 (file-expand-wildcards
12380 (vhdl-resolve-env-variable
12381 (vhdl-replace-string
12382 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12383 (concat "\*" " " (user-login-name)))))))
12384 (setq list-length (or list-length (length file-list)))
12385 (setq file-name-list (cdr file-name-list)))
12387 (vhdl-import-project (expand-file-name (car file-list)) t
12388 (not (> list-length 0)))
12389 (setq list-length (1- list-length))
12390 (setq file-list (cdr file-list)))))
12392 ;; automatically load project setup when idle after startup
12393 (when (memq 'startup vhdl-project-auto-load)
12395 (vhdl-auto-load-project)
12396 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12402 ;; (using `hideshow.el')
12404 (defconst vhdl-hs-start-regexp
12407 ;; generic/port clause
12408 "\\(generic\\|port\\)[ \t\n]*(\\|"
12411 ;; component instantiation
12412 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12413 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12414 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12415 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12417 "\\(function\\|procedure\\)\\>\\|"
12419 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12420 ;; configuration declaration
12423 "Regexp to match start of construct to hide.")
12425 (defun vhdl-hs-forward-sexp-func (count)
12426 "Find end of construct to hide (for hideshow). Only searches forward."
12427 (let ((pos (point)))
12428 (vhdl-prepare-search-2
12429 (beginning-of-line)
12431 ;; generic/port clause
12432 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12433 (goto-char (match-end 0))
12436 ;; component declaration
12437 ((looking-at "^\\s-*component\\>")
12438 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12439 ;; component instantiation
12442 "^\\s-*\\w+\\s-*:[ \t\n]*"
12443 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12444 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12445 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12446 (goto-char (match-end 0))
12450 (vhdl-forward-syntactic-ws)
12451 (when (looking-at "port\\s-+map[ \t\n]*(")
12452 (goto-char (match-end 0))
12455 (setq pos (point)))
12457 ;; subprogram declaration/body
12458 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12459 (goto-char (match-end 0))
12460 (vhdl-forward-syntactic-ws)
12461 (when (looking-at "(")
12463 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12464 (vhdl-in-literal)))
12466 (when (match-string 2)
12467 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12469 (vhdl-forward-sexp)))
12470 ;; block (recursive)
12471 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12472 (goto-char (match-end 0))
12473 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12474 (match-beginning 2))
12475 (vhdl-hs-forward-sexp-func count)))
12477 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12478 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12479 ;; configuration declaration
12480 ((looking-at "^\\s-*configuration\\>")
12482 (vhdl-forward-sexp))
12483 (t (goto-char pos))))))
12485 (defun vhdl-hideshow-init ()
12486 "Initialize `hideshow'."
12487 (when vhdl-hideshow-menu
12488 (vhdl-hs-minor-mode 1)))
12490 (defun vhdl-hs-minor-mode (&optional arg)
12491 "Toggle hideshow minor mode and update menu bar."
12493 (require 'hideshow)
12494 ;; check for hideshow version 5.x
12495 (if (not (boundp 'hs-block-start-mdata-select))
12496 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12497 ;; initialize hideshow
12498 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12499 (setq hs-special-modes-alist
12500 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12501 'vhdl-hs-forward-sexp-func nil)
12502 hs-special-modes-alist)))
12503 (make-local-variable 'hs-minor-mode-hook)
12504 (if vhdl-hide-all-init
12505 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12506 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12507 (hs-minor-mode arg)
12508 (force-mode-line-update))) ; hack to update menu bar
12511 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12513 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12514 ;; (using `font-lock.el')
12516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12519 (defun vhdl-within-translate-off ()
12520 "Return point if within translate-off region, else nil."
12521 (and (save-excursion
12522 (re-search-backward
12523 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12524 (equal "off" (match-string 1))
12527 (defun vhdl-start-translate-off (limit)
12528 "Return point before translate-off pragma if before LIMIT, else nil."
12529 (when (re-search-forward
12530 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12531 (match-beginning 0)))
12533 (defun vhdl-end-translate-off (limit)
12534 "Return point after translate-on pragma if before LIMIT, else nil."
12535 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12537 (defun vhdl-match-translate-off (limit)
12538 "Match a translate-off block, setting match-data and returning t, else nil."
12539 (when (< (point) limit)
12540 (let ((start (or (vhdl-within-translate-off)
12541 (vhdl-start-translate-off limit)))
12542 (case-fold-search t))
12544 (let ((end (or (vhdl-end-translate-off limit) limit)))
12545 (set-match-data (list start end))
12546 (goto-char end))))))
12548 (defun vhdl-font-lock-match-item (limit)
12549 "Match, and move over, any declaration item after point. Adapted from
12550 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12551 (condition-case nil
12553 (narrow-to-region (point-min) limit)
12555 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12557 (goto-char (match-end 1))
12558 ;; move to next item
12559 (if (looking-at "\\(\\s-*,\\)")
12560 (goto-char (match-end 1))
12561 (end-of-line) t))))
12564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12565 ;; Syntax definitions
12567 (defconst vhdl-font-lock-syntactic-keywords
12568 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12569 "Mark single quotes as having string quote syntax in 'c' instances.")
12571 (defvar vhdl-font-lock-keywords nil
12572 "Regular expressions to highlight in VHDL Mode.")
12574 (defvar vhdl-font-lock-keywords-0
12575 ;; set in `vhdl-font-lock-init' because dependent on user options
12576 "For consideration as a value of `vhdl-font-lock-keywords'.
12577 This does highlighting of template prompts and directives (pragmas).")
12579 (defvar vhdl-font-lock-keywords-1 nil
12580 ;; set in `vhdl-font-lock-init' because dependent on user options
12581 "For consideration as a value of `vhdl-font-lock-keywords'.
12582 This does highlighting of keywords and standard identifiers.")
12584 (defconst vhdl-font-lock-keywords-2
12586 ;; highlight names of units, subprograms, and components when declared
12590 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12591 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12592 "\\)\\s-+\\(\\w+\\)")
12593 5 'font-lock-function-name-face)
12595 ;; highlight entity names of architectures and configurations
12597 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12598 2 'font-lock-function-name-face)
12600 ;; highlight labels of common constructs
12603 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12604 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12605 "postponed\\|process\\|"
12606 (when (vhdl-standard-p 'ams) "procedural\\|")
12608 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12609 1 'font-lock-function-name-face)
12611 ;; highlight label and component name of component instantiations
12614 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12615 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12616 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12618 ;; highlight label and instantiated unit of component instantiations
12621 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12622 "\\(component\\|configuration\\|entity\\)\\s-+"
12623 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12624 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12625 '(5 font-lock-function-name-face nil t)
12626 '(7 font-lock-function-name-face nil t))
12628 ;; highlight names and labels at end of constructs
12631 "^\\s-*end\\s-+\\(\\("
12632 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12633 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12634 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12635 (when (vhdl-standard-p 'ams) "procedural\\|")
12637 "\\)\\s-+\\)?\\(\\w*\\)")
12638 5 'font-lock-function-name-face)
12640 ;; highlight labels in exit and next statements
12643 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12644 3 'font-lock-function-name-face)
12646 ;; highlight entity name in attribute specifications
12649 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12650 1 'font-lock-function-name-face)
12652 ;; highlight labels in block and component specifications
12655 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12656 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12657 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12659 ;; highlight names in library clauses
12660 (list "^\\s-*library\\>"
12661 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12663 ;; highlight names in use clauses
12666 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12667 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12668 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12669 '(7 font-lock-function-name-face nil t))
12671 ;; highlight attribute name in attribute declarations/specifications
12674 "^\\s-*attribute\\s-+\\(\\w+\\)")
12675 1 'vhdl-font-lock-attribute-face)
12677 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12680 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12681 3 'font-lock-type-face)
12683 ;; highlight signal/variable/constant declaration names
12684 (list "\\(:[^=]\\)"
12685 '(vhdl-font-lock-match-item
12686 (progn (goto-char (match-beginning 1))
12687 (skip-syntax-backward " ")
12688 (skip-syntax-backward "w_")
12689 (skip-syntax-backward " ")
12690 (while (= (preceding-char) ?,)
12692 (skip-syntax-backward " ")
12693 (skip-syntax-backward "w_")
12694 (skip-syntax-backward " ")))
12695 ; (skip-chars-backward "^-(\n\";")
12696 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12698 ;; highlight formal parameters in component instantiations and subprogram
12701 '(vhdl-font-lock-match-item
12702 (progn (goto-char (match-beginning 1))
12703 (skip-syntax-backward " ")
12704 (while (= (preceding-char) ?\)) (backward-sexp))
12705 (skip-syntax-backward "w_")
12706 (skip-syntax-backward " ")
12707 (when (memq (preceding-char) '(?n ?N ?|))
12708 (goto-char (point-max))))
12709 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12711 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12713 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12714 '(vhdl-font-lock-match-item
12715 (progn (goto-char (match-end 1)) (match-beginning 2))
12716 nil (1 font-lock-variable-name-face)))
12718 "For consideration as a value of `vhdl-font-lock-keywords'.
12719 This does context sensitive highlighting of names and labels.")
12721 (defvar vhdl-font-lock-keywords-3 nil
12722 ;; set in `vhdl-font-lock-init' because dependent on user options
12723 "For consideration as a value of `vhdl-font-lock-keywords'.
12724 This does highlighting of words with special syntax.")
12726 (defvar vhdl-font-lock-keywords-4 nil
12727 ;; set in `vhdl-font-lock-init' because dependent on user options
12728 "For consideration as a value of `vhdl-font-lock-keywords'.
12729 This does highlighting of additional reserved words.")
12731 (defconst vhdl-font-lock-keywords-5
12732 ;; background highlight translate-off regions
12733 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12734 "For consideration as a value of `vhdl-font-lock-keywords'.
12735 This does background highlighting of translate-off regions.")
12737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12738 ;; Font and color definitions
12740 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12741 "Face name to use for prompts.")
12743 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12744 "Face name to use for standardized attributes.")
12746 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12747 "Face name to use for standardized enumeration values.")
12749 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12750 "Face name to use for standardized functions and packages.")
12752 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12753 "Face name to use for directives.")
12755 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12756 "Face name to use for additional reserved words.")
12758 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12759 "Face name to use for translate-off regions.")
12761 ;; face names to use for words with special syntax.
12762 (let ((syntax-alist vhdl-special-syntax-alist)
12764 (while syntax-alist
12765 (setq name (vhdl-function-name
12766 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12767 (eval `(defvar ,name ',name
12768 ,(concat "Face name to use for "
12769 (nth 0 (car syntax-alist)) ".")))
12770 (setq syntax-alist (cdr syntax-alist))))
12772 (defgroup vhdl-highlight-faces nil
12773 "Faces for highlighting."
12774 :group 'vhdl-highlight)
12776 ;; add faces used from `font-lock'
12777 (custom-add-to-group
12778 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12779 (custom-add-to-group
12780 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12781 (custom-add-to-group
12782 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12783 (custom-add-to-group
12784 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12785 (custom-add-to-group
12786 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12787 (custom-add-to-group
12788 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12790 (defface vhdl-font-lock-prompt-face
12791 '((((min-colors 88) (class color) (background light))
12792 (:foreground "Red1" :bold t))
12793 (((class color) (background light)) (:foreground "Red" :bold t))
12794 (((class color) (background dark)) (:foreground "Pink" :bold t))
12795 (t (:inverse-video t)))
12796 "Font lock mode face used to highlight prompts."
12797 :group 'vhdl-highlight-faces)
12799 (defface vhdl-font-lock-attribute-face
12800 '((((class color) (background light)) (:foreground "Orchid"))
12801 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12802 (t (:italic t :bold t)))
12803 "Font lock mode face used to highlight standardized attributes."
12804 :group 'vhdl-highlight-faces)
12806 (defface vhdl-font-lock-enumvalue-face
12807 '((((class color) (background light)) (:foreground "SaddleBrown"))
12808 (((class color) (background dark)) (:foreground "BurlyWood"))
12809 (t (:italic t :bold t)))
12810 "Font lock mode face used to highlight standardized enumeration values."
12811 :group 'vhdl-highlight-faces)
12813 (defface vhdl-font-lock-function-face
12814 '((((class color) (background light)) (:foreground "Cyan4"))
12815 (((class color) (background dark)) (:foreground "Orchid1"))
12816 (t (:italic t :bold t)))
12817 "Font lock mode face used to highlight standardized functions and packages."
12818 :group 'vhdl-highlight-faces)
12820 (defface vhdl-font-lock-directive-face
12821 '((((class color) (background light)) (:foreground "CadetBlue"))
12822 (((class color) (background dark)) (:foreground "Aquamarine"))
12823 (t (:italic t :bold t)))
12824 "Font lock mode face used to highlight directives."
12825 :group 'vhdl-highlight-faces)
12827 (defface vhdl-font-lock-reserved-words-face
12828 '((((class color) (background light)) (:foreground "Orange" :bold t))
12829 (((min-colors 88) (class color) (background dark))
12830 (:foreground "Yellow1" :bold t))
12831 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12833 "Font lock mode face used to highlight additional reserved words."
12834 :group 'vhdl-highlight-faces)
12836 (defface vhdl-font-lock-translate-off-face
12837 '((((class color) (background light)) (:background "LightGray"))
12838 (((class color) (background dark)) (:background "DimGray"))
12840 "Font lock mode face used to background highlight translate-off regions."
12841 :group 'vhdl-highlight-faces)
12843 ;; font lock mode faces used to highlight words with special syntax.
12844 (let ((syntax-alist vhdl-special-syntax-alist))
12845 (while syntax-alist
12846 (eval `(defface ,(vhdl-function-name
12847 "vhdl-font-lock" (caar syntax-alist) "face")
12848 '((((class color) (background light))
12849 (:foreground ,(nth 2 (car syntax-alist))))
12850 (((class color) (background dark))
12851 (:foreground ,(nth 3 (car syntax-alist))))
12853 ,(concat "Font lock mode face used to highlight "
12854 (nth 0 (car syntax-alist)) ".")
12855 :group 'vhdl-highlight-faces))
12856 (setq syntax-alist (cdr syntax-alist))))
12858 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12859 ;; Font lock initialization
12861 (defun vhdl-font-lock-init ()
12862 "Initialize fontification."
12863 ;; highlight template prompts and directives
12864 (setq vhdl-font-lock-keywords-0
12865 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12866 vhdl-template-prompt-syntax ">\\)")
12867 2 'vhdl-font-lock-prompt-face t)
12868 (list (concat "--\\s-*"
12869 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12870 2 'vhdl-font-lock-directive-face t)
12871 ;; highlight c-preprocessor directives
12872 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12873 '(1 font-lock-builtin-face)
12874 '(3 font-lock-variable-name-face nil t))))
12875 ;; highlight keywords and standardized types, attributes, enumeration
12876 ;; values, and subprograms
12877 (setq vhdl-font-lock-keywords-1
12879 (list (concat "'" vhdl-attributes-regexp)
12880 1 'vhdl-font-lock-attribute-face)
12881 (list vhdl-types-regexp 1 'font-lock-type-face)
12882 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12883 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12884 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12885 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12886 ;; highlight words with special syntax.
12887 (setq vhdl-font-lock-keywords-3
12888 (let ((syntax-alist vhdl-special-syntax-alist)
12890 (while syntax-alist
12893 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12894 (vhdl-function-name
12895 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12897 (setq syntax-alist (cdr syntax-alist)))
12899 ;; highlight additional reserved words
12900 (setq vhdl-font-lock-keywords-4
12901 (list (list vhdl-reserved-words-regexp 1
12902 'vhdl-font-lock-reserved-words-face)))
12903 ;; highlight everything together
12904 (setq vhdl-font-lock-keywords
12906 vhdl-font-lock-keywords-0
12907 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12908 (when (or vhdl-highlight-forbidden-words
12909 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12910 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12911 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12912 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12914 ;; initialize fontification for VHDL Mode
12915 (vhdl-font-lock-init)
12917 (defun vhdl-fontify-buffer ()
12918 "Re-initialize fontification and fontify buffer."
12920 (setq font-lock-defaults
12921 `(vhdl-font-lock-keywords
12922 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
12923 beginning-of-line))
12924 (when (fboundp 'font-lock-unset-defaults)
12925 (font-lock-unset-defaults)) ; not implemented in XEmacs
12926 (font-lock-set-defaults)
12927 (font-lock-mode nil)
12928 (font-lock-mode t))
12930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12931 ;; Initialization for postscript printing
12933 (defun vhdl-ps-print-settings ()
12934 "Initialize custom face and page settings for postscript printing."
12935 ;; define custom face settings
12936 (unless (or (not vhdl-print-customize-faces)
12938 (set (make-local-variable 'ps-bold-faces)
12939 '(font-lock-keyword-face
12940 font-lock-type-face
12941 vhdl-font-lock-attribute-face
12942 vhdl-font-lock-enumvalue-face
12943 vhdl-font-lock-directive-face))
12944 (set (make-local-variable 'ps-italic-faces)
12945 '(font-lock-comment-face
12946 font-lock-function-name-face
12947 font-lock-type-face
12948 vhdl-font-lock-attribute-face
12949 vhdl-font-lock-enumvalue-face
12950 vhdl-font-lock-directive-face))
12951 (set (make-local-variable 'ps-underlined-faces)
12952 '(font-lock-string-face))
12953 (setq ps-always-build-face-reference t))
12954 ;; define page settings, so that a line containing 79 characters (default)
12955 ;; fits into one column
12956 (when vhdl-print-two-column
12957 (set (make-local-variable 'ps-landscape-mode) t)
12958 (set (make-local-variable 'ps-number-of-columns) 2)
12959 (set (make-local-variable 'ps-font-size) 7.0)
12960 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12961 (set (make-local-variable 'ps-header-font-size) 9.0)
12962 (set (make-local-variable 'ps-header-offset) 12.0)
12963 (when (eq ps-paper-type 'letter)
12964 (set (make-local-variable 'ps-inter-column) 40.0)
12965 (set (make-local-variable 'ps-left-margin) 40.0)
12966 (set (make-local-variable 'ps-right-margin) 40.0))))
12968 (defun vhdl-ps-print-init ()
12969 "Initialize postscript printing."
12970 (if (featurep 'xemacs)
12971 (when (boundp 'ps-print-color-p)
12972 (vhdl-ps-print-settings))
12973 (make-local-variable 'ps-print-hook)
12974 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12978 ;;; Hierarchy browser (using `speedbar.el')
12979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12980 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12981 ;; directory by using the speedbar.
12983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12986 (defvar vhdl-entity-alist nil
12987 "Cache with entities and corresponding architectures for each
12988 project/directory.")
12989 ;; structure: (parenthesised expression means list of such entries)
12991 ;; (ent-key ent-name ent-file ent-line
12992 ;; (arch-key arch-name arch-file arch-line
12993 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12994 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12995 ;; (lib-name pack-key))
12996 ;; mra-key (lib-name pack-key))
12998 (defvar vhdl-config-alist nil
12999 "Cache with configurations for each project/directory.")
13000 ;; structure: (parenthesised expression means list of such entries)
13002 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13003 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13004 ;; inst-conf-key inst-lib-key)
13005 ;; (lib-name pack-key)))
13007 (defvar vhdl-package-alist nil
13008 "Cache with packages for each project/directory.")
13009 ;; structure: (parenthesised expression means list of such entries)
13011 ;; (pack-key pack-name pack-file pack-line
13012 ;; (comp-key comp-name comp-file comp-line)
13013 ;; (func-key func-name func-file func-line)
13014 ;; (lib-name pack-key)
13015 ;; pack-body-file pack-body-line
13016 ;; (func-key func-name func-body-file func-body-line)
13017 ;; (lib-name pack-key)))
13019 (defvar vhdl-ent-inst-alist nil
13020 "Cache with instantiated entities for each project/directory.")
13021 ;; structure: (parenthesised expression means list of such entries)
13022 ;; (cache-key (inst-ent-key))
13024 (defvar vhdl-file-alist nil
13025 "Cache with design units in each file for each project/directory.")
13026 ;; structure: (parenthesised expression means list of such entries)
13028 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13029 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13031 (defvar vhdl-directory-alist nil
13032 "Cache with source directories for each project.")
13033 ;; structure: (parenthesised expression means list of such entries)
13034 ;; (cache-key (directory))
13036 (defvar vhdl-speedbar-shown-unit-alist nil
13037 "Alist of design units simultaneously open in the current speedbar for each
13038 directory and project.")
13040 (defvar vhdl-speedbar-shown-project-list nil
13041 "List of projects simultaneously open in the current speedbar.")
13043 (defvar vhdl-updated-project-list nil
13044 "List of projects and directories with updated files.")
13046 (defvar vhdl-modified-file-list nil
13047 "List of modified files to be rescanned for hierarchy updating.")
13049 (defvar vhdl-speedbar-hierarchy-depth 0
13050 "Depth of instantiation hierarchy to display.")
13052 (defvar vhdl-speedbar-show-projects nil
13053 "Non-nil means project hierarchy is displayed in speedbar, directory
13054 hierarchy otherwise.")
13056 (defun vhdl-get-end-of-unit ()
13057 "Return position of end of current unit."
13058 (let ((pos (point)))
13060 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13062 (goto-char (match-beginning 0))
13063 (vhdl-backward-syntactic-ws)
13064 (and (/= (preceding-char) ?\;) (not (bobp))))))
13065 (re-search-backward "^[ \t]*end\\>" pos 1)
13068 (defun vhdl-match-string-downcase (num &optional string)
13069 "Like `match-string-no-properties' with down-casing."
13070 (let ((match (match-string-no-properties num string)))
13071 (and match (downcase match))))
13074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13077 (defun vhdl-scan-context-clause ()
13078 "Scan the context clause that preceeds a design unit."
13081 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13082 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13083 (equal "USE" (upcase (match-string 1))))
13084 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13085 (setq lib-alist (cons (cons (match-string-no-properties 1)
13086 (vhdl-match-string-downcase 2))
13090 (defun vhdl-scan-directory-contents (name &optional project update num-string
13092 "Scan contents of VHDL files in directory or file pattern NAME."
13093 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13094 ; (unless (file-directory-p (match-string 1 name))
13095 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13096 (let* ((dir-name (match-string 1 name))
13097 (file-pattern (match-string 2 name))
13098 (is-directory (= 0 (length file-pattern)))
13103 (vhdl-get-source-files t dir-name)
13104 (vhdl-directory-files
13105 dir-name t (wildcard-to-regexp file-pattern)))))
13106 (key (or project dir-name))
13107 (file-exclude-regexp
13108 (or (nth 3 (aget vhdl-project-alist project)) ""))
13109 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13110 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13111 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13112 ent-alist conf-alist pack-alist ent-inst-list file-alist
13113 tmp-list tmp-entry no-files files-exist big-files)
13114 (when (or project update)
13115 (setq ent-alist (aget vhdl-entity-alist key t)
13116 conf-alist (aget vhdl-config-alist key t)
13117 pack-alist (aget vhdl-package-alist key t)
13118 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13119 file-alist (aget vhdl-file-alist key t)))
13120 (when (and (not is-directory) (null file-list))
13121 (message "No such file: \"%s\"" name))
13122 (setq files-exist file-list)
13124 (setq no-files (length file-list))
13125 (message "Scanning %s %s\"%s\"..."
13126 (if is-directory "directory" "files") (or num-string "") name)
13128 (unless (equal file-exclude-regexp "")
13129 (let ((case-fold-search nil)
13132 (unless (string-match file-exclude-regexp (car file-list))
13133 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13134 (setq file-list (cdr file-list)))
13135 (setq file-list (nreverse file-tmp-list))))
13136 ;; do for all files
13138 (unless noninteractive
13139 (message "Scanning %s %s\"%s\"... (%2d%s)"
13140 (if is-directory "directory" "files")
13141 (or num-string "") name
13142 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13143 (let ((file-name (abbreviate-file-name (car file-list)))
13144 ent-list arch-list arch-ent-list conf-list
13145 pack-list pack-body-list inst-list inst-ent-list)
13149 (vhdl-prepare-search-2
13151 ;; scan for design units
13152 (if (and limit-design-file-size
13153 (< limit-design-file-size (buffer-size)))
13154 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13155 (setq big-files t))
13156 ;; scan for entities
13157 (goto-char (point-min))
13158 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13159 (let* ((ent-name (match-string-no-properties 1))
13160 (ent-key (downcase ent-name))
13161 (ent-entry (aget ent-alist ent-key t))
13162 (lib-alist (vhdl-scan-context-clause)))
13163 (if (nth 1 ent-entry)
13164 (vhdl-warning-when-idle
13165 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13166 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13167 file-name (vhdl-current-line))
13168 (setq ent-list (cons ent-key ent-list))
13169 (aput 'ent-alist ent-key
13170 (list ent-name file-name (vhdl-current-line)
13171 (nth 3 ent-entry) (nth 4 ent-entry)
13173 ;; scan for architectures
13174 (goto-char (point-min))
13175 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13176 (let* ((arch-name (match-string-no-properties 1))
13177 (arch-key (downcase arch-name))
13178 (ent-name (match-string-no-properties 2))
13179 (ent-key (downcase ent-name))
13180 (ent-entry (aget ent-alist ent-key t))
13181 (arch-alist (nth 3 ent-entry))
13182 (arch-entry (aget arch-alist arch-key t))
13183 (lib-arch-alist (vhdl-scan-context-clause)))
13185 (vhdl-warning-when-idle
13186 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13187 arch-name ent-name (nth 1 arch-entry)
13188 (nth 2 arch-entry) file-name (vhdl-current-line))
13189 (setq arch-list (cons arch-key arch-list)
13190 arch-ent-list (cons ent-key arch-ent-list))
13191 (aput 'arch-alist arch-key
13192 (list arch-name file-name (vhdl-current-line) nil
13194 (aput 'ent-alist ent-key
13195 (list (or (nth 0 ent-entry) ent-name)
13196 (nth 1 ent-entry) (nth 2 ent-entry)
13197 (vhdl-sort-alist arch-alist)
13198 arch-key (nth 5 ent-entry))))))
13199 ;; scan for configurations
13200 (goto-char (point-min))
13201 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13202 (let* ((conf-name (match-string-no-properties 1))
13203 (conf-key (downcase conf-name))
13204 (conf-entry (aget conf-alist conf-key t))
13205 (ent-name (match-string-no-properties 2))
13206 (ent-key (downcase ent-name))
13207 (lib-alist (vhdl-scan-context-clause))
13208 (conf-line (vhdl-current-line))
13209 (end-of-unit (vhdl-get-end-of-unit))
13210 arch-key comp-conf-list inst-key-list
13211 inst-comp-key inst-ent-key inst-arch-key
13212 inst-conf-key inst-lib-key)
13213 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13214 (setq arch-key (vhdl-match-string-downcase 1)))
13216 (vhdl-warning-when-idle
13217 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13218 conf-name ent-name (nth 1 conf-entry)
13219 (nth 2 conf-entry) file-name conf-line)
13220 (setq conf-list (cons conf-key conf-list))
13221 ;; scan for subconfigurations and subentities
13222 (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)
13223 (setq inst-comp-key (vhdl-match-string-downcase 3)
13224 inst-key-list (split-string
13225 (vhdl-match-string-downcase 1)
13226 "[ \t\n]*,[ \t\n]*"))
13227 (vhdl-forward-syntactic-ws)
13228 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13230 inst-lib-key (vhdl-match-string-downcase 3)
13231 inst-ent-key (and (match-string 2)
13232 (vhdl-match-string-downcase 4))
13233 inst-arch-key (and (match-string 2)
13234 (vhdl-match-string-downcase 6))
13235 inst-conf-key (and (not (match-string 2))
13236 (vhdl-match-string-downcase 4)))
13237 (while inst-key-list
13238 (setq comp-conf-list
13239 (cons (list (car inst-key-list)
13240 inst-comp-key inst-ent-key
13241 inst-arch-key inst-conf-key
13244 (setq inst-key-list (cdr inst-key-list)))))
13245 (aput 'conf-alist conf-key
13246 (list conf-name file-name conf-line ent-key
13247 arch-key comp-conf-list lib-alist)))))
13248 ;; scan for packages
13249 (goto-char (point-min))
13250 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13251 (let* ((pack-name (match-string-no-properties 2))
13252 (pack-key (downcase pack-name))
13253 (is-body (match-string-no-properties 1))
13254 (pack-entry (aget pack-alist pack-key t))
13255 (pack-line (vhdl-current-line))
13256 (end-of-unit (vhdl-get-end-of-unit))
13257 comp-name func-name comp-alist func-alist lib-alist)
13258 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13259 (vhdl-warning-when-idle
13260 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13261 (if is-body " body" "") pack-name
13262 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13263 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13264 file-name (vhdl-current-line))
13265 ;; scan for context clauses
13266 (setq lib-alist (vhdl-scan-context-clause))
13267 ;; scan for component and subprogram declarations/bodies
13268 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13269 (if (equal (upcase (match-string 1)) "COMPONENT")
13270 (setq comp-name (match-string-no-properties 2)
13272 (cons (list (downcase comp-name) comp-name
13273 file-name (vhdl-current-line))
13275 (setq func-name (match-string-no-properties 2)
13277 (cons (list (downcase func-name) func-name
13278 file-name (vhdl-current-line))
13280 (setq func-alist (nreverse func-alist))
13281 (setq comp-alist (nreverse comp-alist))
13283 (setq pack-body-list (cons pack-key pack-body-list))
13284 (setq pack-list (cons pack-key pack-list)))
13286 'pack-alist pack-key
13288 (list (or (nth 0 pack-entry) pack-name)
13289 (nth 1 pack-entry) (nth 2 pack-entry)
13290 (nth 3 pack-entry) (nth 4 pack-entry)
13292 file-name pack-line func-alist lib-alist)
13293 (list pack-name file-name pack-line
13294 comp-alist func-alist lib-alist
13295 (nth 6 pack-entry) (nth 7 pack-entry)
13296 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13297 ;; scan for hierarchy
13298 (if (and limit-hier-file-size
13299 (< limit-hier-file-size (buffer-size)))
13300 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13301 (setq big-files t))
13302 ;; scan for architectures
13303 (goto-char (point-min))
13304 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13305 (let* ((ent-name (match-string-no-properties 2))
13306 (ent-key (downcase ent-name))
13307 (arch-name (match-string-no-properties 1))
13308 (arch-key (downcase arch-name))
13309 (ent-entry (aget ent-alist ent-key t))
13310 (arch-alist (nth 3 ent-entry))
13311 (arch-entry (aget arch-alist arch-key t))
13312 (beg-of-unit (point))
13313 (end-of-unit (vhdl-get-end-of-unit))
13315 inst-alist inst-path)
13316 ;; scan for contained instantiations
13317 (while (and (re-search-forward
13318 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13319 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13320 "component[ \t\n]+\\(\\w+\\)\\|"
13321 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13322 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13323 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13324 (or (not limit-hier-inst-no)
13325 (<= (setq inst-no (1+ inst-no))
13326 limit-hier-inst-no)))
13328 ;; block/generate beginning found
13331 (cons (match-string-no-properties 1) inst-path)))
13332 ;; block/generate end found
13334 (setq inst-path (cdr inst-path)))
13335 ;; instantiation found
13337 (let* ((inst-name (match-string-no-properties 1))
13338 (inst-key (downcase inst-name))
13340 (or (match-string-no-properties 3)
13341 (match-string-no-properties 6)))
13343 (or (and (match-string 8)
13344 (vhdl-match-string-downcase 11))
13345 (and inst-comp-name
13346 (downcase inst-comp-name))))
13347 (inst-arch-key (vhdl-match-string-downcase 13))
13349 (and (not (match-string 8))
13350 (vhdl-match-string-downcase 11)))
13351 (inst-lib-key (vhdl-match-string-downcase 10)))
13352 (goto-char (match-end 1))
13353 (setq inst-list (cons inst-key inst-list)
13355 (cons inst-ent-key inst-ent-list))
13359 (list (list inst-key inst-name file-name
13360 (vhdl-current-line) inst-comp-name
13361 inst-ent-key inst-arch-key
13362 inst-conf-key inst-lib-key
13363 (reverse inst-path)))))))))
13364 ;; scan for contained configuration specifications
13365 (goto-char beg-of-unit)
13366 (while (re-search-forward
13367 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13368 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13369 (let* ((inst-comp-name (match-string-no-properties 3))
13371 (and (match-string 6)
13372 (vhdl-match-string-downcase 9)))
13373 (inst-arch-key (vhdl-match-string-downcase 11))
13375 (and (not (match-string 6))
13376 (vhdl-match-string-downcase 9)))
13377 (inst-lib-key (vhdl-match-string-downcase 8))
13379 (split-string (vhdl-match-string-downcase 1)
13380 "[ \t\n]*,[ \t\n]*"))
13381 (tmp-inst-alist inst-alist)
13383 (while tmp-inst-alist
13384 (when (and (or (equal "all" (car inst-key-list))
13385 (member (nth 0 (car tmp-inst-alist))
13389 (or (nth 4 (car tmp-inst-alist)) ""))
13390 (downcase inst-comp-name)))
13391 (setq inst-entry (car tmp-inst-alist))
13392 (setq inst-ent-list
13393 (cons (or inst-ent-key (nth 5 inst-entry))
13395 (nth 5 inst-entry) inst-ent-list)))
13397 (list (nth 0 inst-entry) (nth 1 inst-entry)
13398 (nth 2 inst-entry) (nth 3 inst-entry)
13400 (or inst-ent-key (nth 5 inst-entry))
13401 (or inst-arch-key (nth 6 inst-entry))
13402 inst-conf-key inst-lib-key))
13403 (setcar tmp-inst-alist inst-entry))
13404 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13406 (aput 'arch-alist arch-key
13407 (list (nth 0 arch-entry) (nth 1 arch-entry)
13408 (nth 2 arch-entry) inst-alist
13409 (nth 4 arch-entry)))
13410 (aput 'ent-alist ent-key
13411 (list (nth 0 ent-entry) (nth 1 ent-entry)
13412 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13413 (nth 4 ent-entry) (nth 5 ent-entry)))
13414 (when (and limit-hier-inst-no
13415 (> inst-no limit-hier-inst-no))
13416 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13417 (setq big-files t))
13418 (goto-char end-of-unit))))
13419 ;; remember design units for this file
13420 (aput 'file-alist file-name
13421 (list ent-list arch-list arch-ent-list conf-list
13422 pack-list pack-body-list inst-list inst-ent-list))
13423 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13424 (setq file-list (cdr file-list))))
13425 (when (or (and (not project) files-exist)
13426 (and project (not non-final)))
13427 ;; consistency checks:
13428 ;; check whether each architecture has a corresponding entity
13429 (setq tmp-list ent-alist)
13431 (when (null (nth 2 (car tmp-list)))
13432 (setq tmp-entry (car (nth 4 (car tmp-list))))
13433 (vhdl-warning-when-idle
13434 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13435 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13436 (nth 3 tmp-entry)))
13437 (setq tmp-list (cdr tmp-list)))
13438 ;; check whether configuration has a corresponding entity/architecture
13439 (setq tmp-list conf-alist)
13441 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13442 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13443 (setq tmp-entry (car tmp-list))
13444 (vhdl-warning-when-idle
13445 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13446 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13447 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13448 (setq tmp-entry (car tmp-list))
13449 (vhdl-warning-when-idle
13450 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13451 (nth 1 tmp-entry) (nth 4 tmp-entry)
13452 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13453 (setq tmp-list (cdr tmp-list)))
13454 ;; check whether each package body has a package declaration
13455 (setq tmp-list pack-alist)
13457 (when (null (nth 2 (car tmp-list)))
13458 (setq tmp-entry (car tmp-list))
13459 (vhdl-warning-when-idle
13460 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13461 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13462 (setq tmp-list (cdr tmp-list)))
13464 (setq ent-alist (vhdl-sort-alist ent-alist))
13465 (setq conf-alist (vhdl-sort-alist conf-alist))
13466 (setq pack-alist (vhdl-sort-alist pack-alist))
13467 ;; remember updated directory/project
13468 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13469 ;; clear directory alists
13471 (adelete 'vhdl-entity-alist key)
13472 (adelete 'vhdl-config-alist key)
13473 (adelete 'vhdl-package-alist key)
13474 (adelete 'vhdl-ent-inst-alist key)
13475 (adelete 'vhdl-file-alist key))
13476 ;; put directory contents into cache
13477 (aput 'vhdl-entity-alist key ent-alist)
13478 (aput 'vhdl-config-alist key conf-alist)
13479 (aput 'vhdl-package-alist key pack-alist)
13480 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13481 (aput 'vhdl-file-alist key file-alist)
13483 (message "Scanning %s %s\"%s\"...done"
13484 (if is-directory "directory" "files") (or num-string "") name)
13485 (unless project (message "Scanning directory...done"))
13487 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13488 ;; save cache when scanned non-interactively
13489 (when (or (not project) (not non-final))
13490 (when (and noninteractive vhdl-speedbar-save-cache)
13491 (vhdl-save-cache key)))
13494 (defun vhdl-scan-project-contents (project)
13495 "Scan the contents of all VHDL files found in the directories and files
13497 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13498 (default-dir (vhdl-resolve-env-variable
13499 (nth 1 (aget vhdl-project-alist project))))
13500 (file-exclude-regexp
13501 (or (nth 3 (aget vhdl-project-alist project)) ""))
13502 dir-list-tmp dir dir-name num-dir act-dir recursive)
13503 ;; clear project alists
13504 (adelete 'vhdl-entity-alist project)
13505 (adelete 'vhdl-config-alist project)
13506 (adelete 'vhdl-package-alist project)
13507 (adelete 'vhdl-ent-inst-alist project)
13508 (adelete 'vhdl-file-alist project)
13509 ;; expand directory names by default-directory
13510 (message "Collecting source files...")
13512 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13513 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13514 (setq recursive (match-string 1 dir)
13515 dir-name (match-string 3 dir))
13517 (cons (concat recursive
13518 (if (file-name-absolute-p dir-name) "" default-dir)
13521 (setq dir-list (cdr dir-list)))
13522 ;; resolve path wildcards
13523 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13524 ;; expand directories
13525 (while dir-list-tmp
13526 (setq dir (car dir-list-tmp))
13527 ;; get subdirectories
13528 (if (string-match "-r \\(.*[/\\]\\)" dir)
13529 (setq dir-list (append dir-list (vhdl-get-subdirs
13530 (match-string 1 dir))))
13531 (setq dir-list (append dir-list (list dir))))
13532 (setq dir-list-tmp (cdr dir-list-tmp)))
13534 (unless (equal file-exclude-regexp "")
13535 (let ((case-fold-search nil))
13537 (unless (string-match file-exclude-regexp (car dir-list))
13538 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13539 (setq dir-list (cdr dir-list)))
13540 (setq dir-list (nreverse dir-list-tmp))))
13541 (message "Collecting source files...done")
13542 ;; scan for design units for each directory in DIR-LIST
13543 (setq dir-list-tmp nil
13544 num-dir (length dir-list)
13547 (setq dir-name (abbreviate-file-name
13548 (expand-file-name (car dir-list))))
13549 (vhdl-scan-directory-contents dir-name project nil
13550 (format "(%s/%s) " act-dir num-dir)
13552 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13553 (setq dir-list (cdr dir-list)
13554 act-dir (1+ act-dir)))
13555 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13556 (message "Scanning project \"%s\"...done" project)))
13558 (defun vhdl-update-file-contents (file-name)
13559 "Update hierarchy information by contents of current buffer."
13560 (setq file-name (abbreviate-file-name file-name))
13561 (let* ((dir-name (file-name-directory file-name))
13562 (directory-alist vhdl-directory-alist)
13564 (while directory-alist
13565 (when (member dir-name (nth 1 (car directory-alist)))
13566 (let* ((vhdl-project (nth 0 (car directory-alist)))
13567 (project (vhdl-project-p))
13568 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13569 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13570 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13571 (ent-inst-list (car (aget vhdl-ent-inst-alist
13572 (or project dir-name) t)))
13573 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13574 (file-entry (aget file-alist file-name t))
13575 (ent-list (nth 0 file-entry))
13576 (arch-list (nth 1 file-entry))
13577 (arch-ent-list (nth 2 file-entry))
13578 (conf-list (nth 3 file-entry))
13579 (pack-list (nth 4 file-entry))
13580 (pack-body-list (nth 5 file-entry))
13581 (inst-ent-list (nth 7 file-entry))
13582 (cache-key (or project dir-name))
13583 arch-alist key ent-key entry)
13584 ;; delete design units previously contained in this file:
13587 (setq key (car ent-list)
13588 entry (aget ent-alist key t))
13589 (when (equal file-name (nth 1 entry))
13591 (aput 'ent-alist key
13592 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13593 (adelete 'ent-alist key)))
13594 (setq ent-list (cdr ent-list)))
13597 (setq key (car arch-list)
13598 ent-key (car arch-ent-list)
13599 entry (aget ent-alist ent-key t)
13600 arch-alist (nth 3 entry))
13601 (when (equal file-name (nth 1 (aget arch-alist key t)))
13602 (adelete 'arch-alist key)
13603 (if (or (nth 1 entry) arch-alist)
13604 (aput 'ent-alist ent-key
13605 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13606 arch-alist (nth 4 entry) (nth 5 entry)))
13607 (adelete 'ent-alist ent-key)))
13608 (setq arch-list (cdr arch-list)
13609 arch-ent-list (cdr arch-ent-list)))
13612 (setq key (car conf-list))
13613 (when (equal file-name (nth 1 (aget conf-alist key t)))
13614 (adelete 'conf-alist key))
13615 (setq conf-list (cdr conf-list)))
13616 ;; package declarations
13618 (setq key (car pack-list)
13619 entry (aget pack-alist key t))
13620 (when (equal file-name (nth 1 entry))
13622 (aput 'pack-alist key
13623 (list (nth 0 entry) nil nil nil nil nil
13624 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13626 (adelete 'pack-alist key)))
13627 (setq pack-list (cdr pack-list)))
13629 (while pack-body-list
13630 (setq key (car pack-body-list)
13631 entry (aget pack-alist key t))
13632 (when (equal file-name (nth 6 entry))
13634 (aput 'pack-alist key
13635 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13636 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13638 (adelete 'pack-alist key)))
13639 (setq pack-body-list (cdr pack-body-list)))
13640 ;; instantiated entities
13641 (while inst-ent-list
13642 (setq ent-inst-list
13643 (vhdl-delete (car inst-ent-list) ent-inst-list))
13644 (setq inst-ent-list (cdr inst-ent-list)))
13646 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13647 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13648 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13649 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13651 (vhdl-scan-directory-contents file-name project t)
13652 (when (or (and vhdl-speedbar-show-projects project)
13653 (and (not vhdl-speedbar-show-projects) (not project)))
13654 (vhdl-speedbar-refresh project))
13656 (setq directory-alist (cdr directory-alist)))
13659 (defun vhdl-update-hierarchy ()
13660 "Update directory and hierarchy information in speedbar."
13661 (let ((file-list (reverse vhdl-modified-file-list))
13663 (when (and vhdl-speedbar-update-on-saving file-list)
13666 (or (vhdl-update-file-contents (car file-list))
13668 (setq file-list (cdr file-list)))
13669 (setq vhdl-modified-file-list nil)
13670 (vhdl-speedbar-update-current-unit)
13671 (when updated (message "Updating hierarchy...done")))))
13673 ;; structure (parenthesised expression means list of such entries)
13674 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13675 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13676 ;; comp-lib-name level)
13677 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13678 conf-inst-alist level indent
13679 &optional include-top ent-hier)
13680 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13682 (let* ((ent-entry (aget ent-alist ent-key t))
13683 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13684 (cdar (last (nth 3 ent-entry)))))
13685 (inst-alist (nth 3 arch-entry))
13686 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13687 hier-list subcomp-list tmp-list inst-key inst-comp-name
13688 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13689 (when (= level 0) (message "Extract design hierarchy..."))
13691 (setq level (1+ level)))
13692 (when (member ent-key ent-hier)
13693 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13694 ;; check configured architecture (already checked during scanning)
13695 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13696 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13697 ;; process all instances
13699 (setq inst-entry (car inst-alist)
13700 inst-key (nth 0 inst-entry)
13701 inst-comp-name (nth 4 inst-entry)
13702 inst-conf-key (nth 7 inst-entry))
13703 ;; search entry in configuration's instantiations list
13704 (setq tmp-list conf-inst-alist)
13705 (while (and tmp-list
13706 (not (and (member (nth 0 (car tmp-list))
13707 (list "all" inst-key))
13708 (equal (nth 1 (car tmp-list))
13709 (downcase (or inst-comp-name ""))))))
13710 (setq tmp-list (cdr tmp-list)))
13711 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13712 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13713 (when (and inst-conf-key (not inst-conf-entry))
13714 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13715 ;; determine entity
13717 (or (nth 2 (car tmp-list)) ; from configuration
13718 (nth 3 inst-conf-entry) ; from subconfiguration
13719 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13720 ; from configuration spec.
13721 (nth 5 inst-entry))) ; from direct instantiation
13722 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13723 ;; determine architecture
13724 (setq inst-arch-key
13725 (or (nth 3 (car tmp-list)) ; from configuration
13726 (nth 4 inst-conf-entry) ; from subconfiguration
13727 (nth 6 inst-entry) ; from direct instantiation
13728 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13729 ; from configuration spec.
13730 (nth 4 inst-ent-entry) ; MRA
13731 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13732 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13735 (or (nth 5 (car tmp-list)) ; from configuration
13736 (nth 8 inst-entry))) ; from direct instantiation
13737 ;; gather information for this instance
13739 (list (nth 1 inst-entry)
13740 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13741 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13742 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13743 (or (nth 0 inst-arch-entry) inst-arch-key)
13744 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13745 (or (nth 0 inst-conf-entry) inst-conf-key)
13746 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13747 inst-lib-key level))
13748 ;; get subcomponent hierarchy
13749 (setq subcomp-list (vhdl-get-hierarchy
13750 ent-alist conf-alist
13751 inst-ent-key inst-arch-key inst-conf-key
13752 (nth 5 inst-conf-entry)
13753 (1+ level) indent nil (cons ent-key ent-hier)))
13755 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13756 (setq inst-alist (cdr inst-alist)))
13759 (cons (list nil nil (nth 0 ent-entry)
13760 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13762 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13766 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13769 (defun vhdl-get-instantiations (ent-key indent)
13770 "Get all instantiations of entity ENT-KEY."
13771 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13772 arch-alist inst-alist ent-inst-list
13773 ent-entry arch-entry inst-entry)
13775 (setq ent-entry (car ent-alist))
13776 (setq arch-alist (nth 4 ent-entry))
13778 (setq arch-entry (car arch-alist))
13779 (setq inst-alist (nth 4 arch-entry))
13781 (setq inst-entry (car inst-alist))
13782 (when (equal ent-key (nth 5 inst-entry))
13783 (setq ent-inst-list
13784 (cons (list (nth 1 inst-entry)
13785 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13787 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13789 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13791 (setq inst-alist (cdr inst-alist)))
13792 (setq arch-alist (cdr arch-alist)))
13793 (setq ent-alist (cdr ent-alist)))
13794 (nreverse ent-inst-list)))
13796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13799 (defun vhdl-save-caches ()
13800 "Save all updated hierarchy caches to file."
13802 (condition-case nil
13803 (when vhdl-speedbar-save-cache
13804 ;; update hierarchy
13805 (vhdl-update-hierarchy)
13806 (let ((project-list vhdl-updated-project-list))
13807 (message "Saving hierarchy caches...")
13808 ;; write updated project caches
13809 (while project-list
13810 (vhdl-save-cache (car project-list))
13811 (setq project-list (cdr project-list)))
13812 (message "Saving hierarchy caches...done")))
13813 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13816 (defun vhdl-save-cache (key)
13817 "Save current hierarchy cache to file."
13818 (let* ((orig-buffer (current-buffer))
13820 (project (vhdl-project-p))
13821 (default-directory key)
13822 (directory (abbreviate-file-name (vhdl-default-directory)))
13823 (file-name (vhdl-resolve-env-variable
13824 (vhdl-replace-string
13825 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13827 (subst-char-in-string ? ?_ (or project "dir"))
13828 " " (user-login-name)))))
13829 (file-dir-name (expand-file-name file-name directory))
13830 (cache-key (or project directory))
13831 (key (if project "project" "directory")))
13832 (unless (file-exists-p (file-name-directory file-dir-name))
13833 (make-directory (file-name-directory file-dir-name) t))
13834 (if (not (file-writable-p file-dir-name))
13835 (progn (vhdl-warning (format "File not writable: \"%s\""
13836 (abbreviate-file-name file-dir-name)))
13838 (message "Saving cache: \"%s\"" file-dir-name)
13839 (set-buffer (find-file-noselect file-dir-name t t))
13841 (insert ";; -*- Emacs-Lisp -*-\n\n"
13842 ";;; " (file-name-nondirectory file-name)
13843 " - design hierarchy cache file for Emacs VHDL Mode "
13845 (insert "\n;; " (if project "Project " "Directory") " : ")
13846 (if project (insert project) (prin1 directory (current-buffer)))
13847 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13848 (user-login-name) "\n\n"
13849 "\n;; version number\n"
13850 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13851 "\n;; " (if project "project" "directory") " name"
13852 "\n(setq " key " ")
13853 (prin1 (or project directory) (current-buffer))
13855 (when (member 'hierarchy vhdl-speedbar-save-cache)
13856 (insert "\n;; entity and architecture cache\n"
13857 "(aput 'vhdl-entity-alist " key " '")
13858 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13859 (insert ")\n\n;; configuration cache\n"
13860 "(aput 'vhdl-config-alist " key " '")
13861 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13862 (insert ")\n\n;; package cache\n"
13863 "(aput 'vhdl-package-alist " key " '")
13864 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13865 (insert ")\n\n;; instantiated entities cache\n"
13866 "(aput 'vhdl-ent-inst-alist " key " '")
13867 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13868 (insert ")\n\n;; design units per file cache\n"
13869 "(aput 'vhdl-file-alist " key " '")
13870 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13872 (insert ")\n\n;; source directories in project cache\n"
13873 "(aput 'vhdl-directory-alist " key " '")
13874 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13876 (when (member 'display vhdl-speedbar-save-cache)
13877 (insert "\n;; shown design units cache\n"
13878 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13879 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13882 (setq vhdl-updated-project-list
13883 (delete cache-key vhdl-updated-project-list))
13885 (kill-buffer (current-buffer))
13886 (set-buffer orig-buffer))))
13888 (defun vhdl-load-cache (key)
13889 "Load hierarchy cache information from file."
13890 (let* ((vhdl-project key)
13891 (default-directory key)
13892 (directory (vhdl-default-directory))
13893 (file-name (vhdl-resolve-env-variable
13894 (vhdl-replace-string
13895 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13897 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13898 " " (user-login-name)))))
13899 (file-dir-name (expand-file-name file-name directory))
13900 vhdl-cache-version)
13901 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13902 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13903 (when (file-exists-p file-dir-name)
13905 (progn (load-file file-dir-name)
13906 (string< (mapconcat
13907 (lambda (a) (format "%3d" (string-to-number a)))
13908 (split-string "3.33" "\\.") "")
13910 (lambda (a) (format "%3d" (string-to-number a)))
13911 (split-string vhdl-cache-version "\\.") "")))
13912 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13915 (defun vhdl-require-hierarchy-info ()
13916 "Make sure that hierarchy information is available. Load cache or scan files
13918 (if (vhdl-project-p)
13919 (unless (or (assoc vhdl-project vhdl-file-alist)
13920 (vhdl-load-cache vhdl-project))
13921 (vhdl-scan-project-contents vhdl-project))
13922 (let ((directory (abbreviate-file-name default-directory)))
13923 (unless (or (assoc directory vhdl-file-alist)
13924 (vhdl-load-cache directory))
13925 (vhdl-scan-directory-contents directory)))))
13927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13928 ;; Add hierarchy browser functionality to speedbar
13930 (defvar vhdl-speedbar-key-map nil
13931 "Keymap used when in the VHDL hierarchy browser mode.")
13933 (defvar vhdl-speedbar-menu-items nil
13934 "Additional menu-items to add to speedbar frame.")
13936 (defun vhdl-speedbar-initialize ()
13937 "Initialize speedbar."
13938 ;; general settings
13939 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13940 ;; VHDL file extensions (extracted from `auto-mode-alist')
13941 (let ((mode-alist auto-mode-alist))
13943 (when (eq (cdar mode-alist) 'vhdl-mode)
13944 (speedbar-add-supported-extension (caar mode-alist)))
13945 (setq mode-alist (cdr mode-alist))))
13946 ;; hierarchy browser settings
13947 (when (boundp 'speedbar-mode-functions-list)
13948 ;; special functions
13949 (speedbar-add-mode-functions-list
13951 (speedbar-item-info . vhdl-speedbar-item-info)
13952 (speedbar-line-directory . speedbar-files-line-path)))
13953 (speedbar-add-mode-functions-list
13955 (speedbar-item-info . vhdl-speedbar-item-info)
13956 (speedbar-line-directory . vhdl-speedbar-line-project)))
13958 (unless vhdl-speedbar-key-map
13959 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13960 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13961 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13962 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13963 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13964 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13965 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13966 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13967 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13968 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13969 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
13970 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13971 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13972 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13975 (define-key vhdl-speedbar-key-map (int-to-string key)
13976 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13977 (setq key (1+ key)))))
13978 (define-key speedbar-key-map "h"
13979 (lambda () (interactive)
13980 (speedbar-change-initial-expansion-list "vhdl directory")))
13981 (define-key speedbar-key-map "H"
13982 (lambda () (interactive)
13983 (speedbar-change-initial-expansion-list "vhdl project")))
13985 (unless vhdl-speedbar-menu-items
13987 vhdl-speedbar-menu-items
13988 `(["Edit" speedbar-edit-line t]
13989 ["Expand" speedbar-expand-line
13990 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13991 ["Contract" vhdl-speedbar-contract-level t]
13992 ["Expand All" vhdl-speedbar-expand-all t]
13993 ["Contract All" vhdl-speedbar-contract-all t]
13994 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13997 (cons `[,(if (= key 0) "All" (int-to-string key))
13998 (vhdl-speedbar-set-depth ,key)
14000 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14001 :keys ,(int-to-string key)]
14003 (setq key (1+ key)))
14004 (nreverse menu-list))
14006 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14007 (or (vhdl-speedbar-check-unit 'entity)
14008 (vhdl-speedbar-check-unit 'subprogram))]
14009 ["Place Component" vhdl-speedbar-place-component
14010 (vhdl-speedbar-check-unit 'entity)]
14011 ["Generate Configuration" vhdl-speedbar-configuration
14012 (vhdl-speedbar-check-unit 'architecture)]
14013 ["Select as MRA" vhdl-speedbar-select-mra
14014 (vhdl-speedbar-check-unit 'architecture)]
14015 ["Make" vhdl-speedbar-make-design
14016 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14017 ["Generate Makefile" vhdl-speedbar-generate-makefile
14018 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14019 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14020 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14021 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14022 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14023 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14024 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14025 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14027 (speedbar-add-expansion-list
14028 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14029 vhdl-speedbar-display-directory))
14030 (speedbar-add-expansion-list
14031 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14032 vhdl-speedbar-display-projects))
14033 (setq speedbar-stealthy-function-list
14035 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14036 ("vhdl project" vhdl-speedbar-update-current-project
14037 vhdl-speedbar-update-current-unit)
14038 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14039 ; (speedbar-extension-list-to-regex
14040 ; speedbar-ignored-path-expressions))))
14042 speedbar-stealthy-function-list))
14043 (when (eq vhdl-speedbar-display-mode 'directory)
14044 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14045 (when (eq vhdl-speedbar-display-mode 'project)
14046 (setq speedbar-initial-expansion-list-name "vhdl project"))
14047 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14049 (defun vhdl-speedbar (&optional arg)
14050 "Open/close speedbar."
14052 (if (not (fboundp 'speedbar))
14053 (error "WARNING: Speedbar is not available or not installed")
14055 (speedbar-frame-mode arg)
14056 (error (error "WARNING: An error occurred while opening speedbar")))))
14058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14059 ;; Display functions
14061 (defvar vhdl-speedbar-last-selected-project nil
14062 "Name of last selected project.")
14064 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14065 (defmacro speedbar-with-writable (&rest forms)
14066 "Allow the buffer to be writable and evaluate FORMS."
14067 (list 'let '((inhibit-read-only t))
14068 (cons 'progn forms)))
14069 (put 'speedbar-with-writable 'lisp-indent-function 0)
14071 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14072 "Display directory and hierarchy information in speedbar."
14073 (setq vhdl-speedbar-show-projects nil)
14074 (setq speedbar-ignored-directory-regexp
14075 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14076 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14077 (setq speedbar-last-selected-file nil)
14078 (speedbar-with-writable
14079 (condition-case nil
14081 ;; insert directory path
14082 (speedbar-directory-buttons directory depth)
14083 ;; insert subdirectories
14084 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14085 ;; scan and insert hierarchy of current directory
14086 (vhdl-speedbar-insert-dir-hierarchy directory depth
14087 speedbar-power-click)
14088 ;; expand subdirectories
14089 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14090 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14092 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14093 "Display projects and hierarchy information in speedbar."
14094 (setq vhdl-speedbar-show-projects t)
14095 (setq speedbar-ignored-directory-regexp ".")
14096 (setq speedbar-last-selected-file nil)
14097 (setq vhdl-speedbar-last-selected-project nil)
14098 (speedbar-with-writable
14099 (condition-case nil
14101 (vhdl-speedbar-insert-projects)
14102 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14103 (setq speedbar-full-text-cache nil)) ; prevent caching
14105 (defun vhdl-speedbar-insert-projects ()
14106 "Insert all projects in speedbar."
14107 (vhdl-speedbar-make-title-line "Projects:")
14108 (let ((project-alist (if vhdl-project-sort
14109 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14110 vhdl-project-alist))
14111 (vhdl-speedbar-update-current-unit nil))
14113 (while project-alist
14114 (speedbar-make-tag-line
14115 'angle ?+ 'vhdl-speedbar-expand-project
14116 (caar project-alist) (caar project-alist)
14117 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14118 (setq project-alist (cdr project-alist)))
14119 (setq project-alist vhdl-project-alist)
14121 (while project-alist
14122 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14123 (goto-char (point-min))
14124 (when (re-search-forward
14125 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14126 (goto-char (match-end 1))
14127 (speedbar-do-function-pointer)))
14128 (setq project-alist (cdr project-alist))))
14129 ; (vhdl-speedbar-update-current-project)
14130 ; (vhdl-speedbar-update-current-unit nil t)
14133 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14134 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14135 otherwise use cached data."
14136 (when (or rescan (and (not (assoc project vhdl-file-alist))
14137 (not (vhdl-load-cache project))))
14138 (vhdl-scan-project-contents project))
14139 ;; insert design hierarchy
14140 (vhdl-speedbar-insert-hierarchy
14141 (aget vhdl-entity-alist project t)
14142 (aget vhdl-config-alist project t)
14143 (aget vhdl-package-alist project t)
14144 (car (aget vhdl-ent-inst-alist project t)) indent)
14145 (insert (int-to-string indent) ":\n")
14146 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14147 (put-text-property (1- (point)) (point) 'invisible nil)
14148 ;; expand design units
14149 (vhdl-speedbar-expand-units project))
14151 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14152 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14153 otherwise use cached data."
14154 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14155 (not (vhdl-load-cache directory))))
14156 (vhdl-scan-directory-contents directory))
14157 ;; insert design hierarchy
14158 (vhdl-speedbar-insert-hierarchy
14159 (aget vhdl-entity-alist directory t)
14160 (aget vhdl-config-alist directory t)
14161 (aget vhdl-package-alist directory t)
14162 (car (aget vhdl-ent-inst-alist directory t)) depth)
14163 ;; expand design units
14164 (vhdl-speedbar-expand-units directory)
14165 (aput 'vhdl-directory-alist directory (list (list directory))))
14167 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14168 ent-inst-list depth)
14169 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14170 (if (not (or ent-alist conf-alist pack-alist))
14171 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14172 (let (ent-entry conf-entry pack-entry)
14174 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14176 (setq ent-entry (car ent-alist))
14177 (speedbar-make-tag-line
14178 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14179 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14180 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14181 'vhdl-speedbar-entity-face depth)
14182 (unless (nth 2 ent-entry)
14183 (end-of-line 0) (insert "!") (forward-char 1))
14184 (unless (member (nth 0 ent-entry) ent-inst-list)
14185 (end-of-line 0) (insert " (top)") (forward-char 1))
14186 (setq ent-alist (cdr ent-alist)))
14187 ;; insert configurations
14188 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14190 (setq conf-entry (car conf-alist))
14191 (speedbar-make-tag-line
14192 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14193 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14194 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14195 'vhdl-speedbar-configuration-face depth)
14196 (setq conf-alist (cdr conf-alist)))
14198 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14200 (setq pack-entry (car pack-alist))
14201 (vhdl-speedbar-make-pack-line
14202 (nth 0 pack-entry) (nth 1 pack-entry)
14203 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14204 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14206 (setq pack-alist (cdr pack-alist))))))
14208 (defun vhdl-speedbar-rescan-hierarchy ()
14209 "Rescan hierarchy for the directory or project under the cursor."
14214 (vhdl-speedbar-show-projects
14215 (setq key (vhdl-speedbar-line-project))
14216 (vhdl-scan-project-contents key))
14217 ;; top-level directory
14218 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14219 (re-search-forward "[0-9]+:" nil t)
14220 (vhdl-scan-directory-contents
14221 (abbreviate-file-name (speedbar-line-directory))))
14222 ;; current directory
14223 (t (setq path (speedbar-line-directory))
14224 (string-match "^\\(.+[/\\]\\)" path)
14225 (vhdl-scan-directory-contents
14226 (abbreviate-file-name (match-string 1 path)))))
14227 (vhdl-speedbar-refresh key)))
14229 (defun vhdl-speedbar-expand-dirs (directory)
14230 "Expand subdirectories in DIRECTORY according to
14231 `speedbar-shown-directories'."
14232 ;; (nicked from `speedbar-default-directory-list')
14233 (let ((sf (cdr (reverse speedbar-shown-directories)))
14234 (vhdl-speedbar-update-current-unit nil))
14235 (setq speedbar-shown-directories
14236 (list (expand-file-name default-directory)))
14238 (when (speedbar-goto-this-file (car sf))
14239 (beginning-of-line)
14240 (when (looking-at "[0-9]+:\\s-*<")
14241 (goto-char (match-end 0))
14242 (speedbar-do-function-pointer)))
14243 (setq sf (cdr sf))))
14244 (vhdl-speedbar-update-current-unit nil t))
14246 (defun vhdl-speedbar-expand-units (key)
14247 "Expand design units in directory/project KEY according to
14248 `vhdl-speedbar-shown-unit-alist'."
14249 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14250 (vhdl-speedbar-update-current-unit nil)
14251 vhdl-updated-project-list)
14252 (adelete 'vhdl-speedbar-shown-unit-alist key)
14253 (vhdl-prepare-search-1
14254 (while unit-alist ; expand units
14255 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14256 (beginning-of-line)
14257 (let ((arch-alist (nth 1 (car unit-alist)))
14259 (when (looking-at "^[0-9]+:\\s-*\\[")
14260 (goto-char (match-end 0))
14261 (setq position (point))
14262 (speedbar-do-function-pointer)
14263 (select-frame speedbar-frame)
14264 (while arch-alist ; expand architectures
14265 (goto-char position)
14266 (when (re-search-forward
14267 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14268 (car arch-alist) "\\>\\)") nil t)
14269 (beginning-of-line)
14270 (when (looking-at "^[0-9]+:\\s-*{")
14271 (goto-char (match-end 0))
14272 (speedbar-do-function-pointer)
14273 (select-frame speedbar-frame)))
14274 (setq arch-alist (cdr arch-alist))))
14275 (setq unit-alist (cdr unit-alist))))))
14276 (vhdl-speedbar-update-current-unit nil t))
14278 (defun vhdl-speedbar-contract-level ()
14279 "Contract current level in current directory/project."
14281 (when (or (save-excursion
14282 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14283 (and (save-excursion
14284 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14285 (re-search-backward
14286 (format "^[0-%d]:\\s-*[[{<]-"
14287 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14288 (goto-char (match-end 0))
14289 (speedbar-do-function-pointer)
14290 (speedbar-center-buffer-smartly)))
14292 (defun vhdl-speedbar-contract-all ()
14293 "Contract all expanded design units in current directory/project."
14295 (if (and vhdl-speedbar-show-projects
14296 (save-excursion (beginning-of-line) (looking-at "^0:")))
14297 (progn (setq vhdl-speedbar-shown-project-list nil)
14298 (vhdl-speedbar-refresh))
14299 (let ((key (vhdl-speedbar-line-key)))
14300 (adelete 'vhdl-speedbar-shown-unit-alist key)
14301 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14302 (when (memq 'display vhdl-speedbar-save-cache)
14303 (add-to-list 'vhdl-updated-project-list key)))))
14305 (defun vhdl-speedbar-expand-all ()
14306 "Expand all design units in current directory/project."
14308 (let* ((key (vhdl-speedbar-line-key))
14309 (ent-alist (aget vhdl-entity-alist key t))
14310 (conf-alist (aget vhdl-config-alist key t))
14311 (pack-alist (aget vhdl-package-alist key t))
14312 arch-alist unit-alist subunit-alist)
14313 (add-to-list 'vhdl-speedbar-shown-project-list key)
14315 (setq arch-alist (nth 4 (car ent-alist)))
14316 (setq subunit-alist nil)
14318 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14319 (setq arch-alist (cdr arch-alist)))
14320 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14321 (setq ent-alist (cdr ent-alist)))
14323 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14324 (setq conf-alist (cdr conf-alist)))
14326 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14327 (setq pack-alist (cdr pack-alist)))
14328 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14329 (vhdl-speedbar-refresh)
14330 (when (memq 'display vhdl-speedbar-save-cache)
14331 (add-to-list 'vhdl-updated-project-list key))))
14333 (defun vhdl-speedbar-expand-project (text token indent)
14334 "Expand/contract the project under the cursor."
14336 ((string-match "+" text) ; expand project
14337 (speedbar-change-expand-button-char ?-)
14338 (unless (member token vhdl-speedbar-shown-project-list)
14339 (setq vhdl-speedbar-shown-project-list
14340 (cons token vhdl-speedbar-shown-project-list)))
14341 (speedbar-with-writable
14343 (end-of-line) (forward-char 1)
14344 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14345 speedbar-power-click))))
14346 ((string-match "-" text) ; contract project
14347 (speedbar-change-expand-button-char ?+)
14348 (setq vhdl-speedbar-shown-project-list
14349 (delete token vhdl-speedbar-shown-project-list))
14350 (speedbar-delete-subblock indent))
14351 (t (error "Nothing to display")))
14352 (when (equal (selected-frame) speedbar-frame)
14353 (speedbar-center-buffer-smartly)))
14355 (defun vhdl-speedbar-expand-entity (text token indent)
14356 "Expand/contract the entity under the cursor."
14358 ((string-match "+" text) ; expand entity
14359 (let* ((key (vhdl-speedbar-line-key indent))
14360 (ent-alist (aget vhdl-entity-alist key t))
14361 (ent-entry (aget ent-alist token t))
14362 (arch-alist (nth 3 ent-entry))
14363 (inst-alist (vhdl-get-instantiations token indent))
14364 (subpack-alist (nth 5 ent-entry))
14365 (multiple-arch (> (length arch-alist) 1))
14366 arch-entry inst-entry)
14367 (if (not (or arch-alist inst-alist subpack-alist))
14368 (speedbar-change-expand-button-char ??)
14369 (speedbar-change-expand-button-char ?-)
14370 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14371 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14372 (aput 'unit-alist token nil)
14373 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14374 (speedbar-with-writable
14376 (end-of-line) (forward-char 1)
14377 ;; insert architectures
14379 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14381 (setq arch-entry (car arch-alist))
14382 (speedbar-make-tag-line
14383 'curly ?+ 'vhdl-speedbar-expand-architecture
14384 (cons token (nth 0 arch-entry))
14385 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14386 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14387 'vhdl-speedbar-architecture-face (1+ indent))
14388 (when (and multiple-arch
14389 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14390 (end-of-line 0) (insert " (mra)") (forward-char 1))
14391 (setq arch-alist (cdr arch-alist)))
14392 ;; insert instantiations
14394 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14396 (setq inst-entry (car inst-alist))
14397 (vhdl-speedbar-make-inst-line
14398 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14399 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14400 nil nil nil (1+ indent) 0 " in ")
14401 (setq inst-alist (cdr inst-alist)))
14402 ;; insert required packages
14403 (vhdl-speedbar-insert-subpackages
14404 subpack-alist (1+ indent) indent)))
14405 (when (memq 'display vhdl-speedbar-save-cache)
14406 (add-to-list 'vhdl-updated-project-list key))
14407 (vhdl-speedbar-update-current-unit t t))))
14408 ((string-match "-" text) ; contract entity
14409 (speedbar-change-expand-button-char ?+)
14410 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14411 (let* ((key (vhdl-speedbar-line-key indent))
14412 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14413 (adelete 'unit-alist token)
14415 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14416 (adelete 'vhdl-speedbar-shown-unit-alist key))
14417 (speedbar-delete-subblock indent)
14418 (when (memq 'display vhdl-speedbar-save-cache)
14419 (add-to-list 'vhdl-updated-project-list key))))
14420 (t (error "Nothing to display")))
14421 (when (equal (selected-frame) speedbar-frame)
14422 (speedbar-center-buffer-smartly)))
14424 (defun vhdl-speedbar-expand-architecture (text token indent)
14425 "Expand/contract the architecture under the cursor."
14427 ((string-match "+" text) ; expand architecture
14428 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14429 (ent-alist (aget vhdl-entity-alist key t))
14430 (conf-alist (aget vhdl-config-alist key t))
14431 (hier-alist (vhdl-get-hierarchy
14432 ent-alist conf-alist (car token) (cdr token) nil nil
14434 (ent-entry (aget ent-alist (car token) t))
14435 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14436 (subpack-alist (nth 4 arch-entry))
14438 (if (not (or hier-alist subpack-alist))
14439 (speedbar-change-expand-button-char ??)
14440 (speedbar-change-expand-button-char ?-)
14441 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14442 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14443 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14444 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14445 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14446 (speedbar-with-writable
14448 (end-of-line) (forward-char 1)
14449 ;; insert instance hierarchy
14451 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14454 (setq entry (car hier-alist))
14455 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14456 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14457 (vhdl-speedbar-make-inst-line
14458 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14459 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14460 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14461 (setq hier-alist (cdr hier-alist)))
14462 ;; insert required packages
14463 (vhdl-speedbar-insert-subpackages
14464 subpack-alist (1+ indent) (1- indent))))
14465 (when (memq 'display vhdl-speedbar-save-cache)
14466 (add-to-list 'vhdl-updated-project-list key))
14467 (vhdl-speedbar-update-current-unit t t))))
14468 ((string-match "-" text) ; contract architecture
14469 (speedbar-change-expand-button-char ?+)
14470 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14471 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14472 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14473 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14474 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14475 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14476 (speedbar-delete-subblock indent)
14477 (when (memq 'display vhdl-speedbar-save-cache)
14478 (add-to-list 'vhdl-updated-project-list key))))
14479 (t (error "Nothing to display")))
14480 (when (equal (selected-frame) speedbar-frame)
14481 (speedbar-center-buffer-smartly)))
14483 (defun vhdl-speedbar-expand-config (text token indent)
14484 "Expand/contract the configuration under the cursor."
14486 ((string-match "+" text) ; expand configuration
14487 (let* ((key (vhdl-speedbar-line-key indent))
14488 (conf-alist (aget vhdl-config-alist key t))
14489 (conf-entry (aget conf-alist token))
14490 (ent-alist (aget vhdl-entity-alist key t))
14491 (hier-alist (vhdl-get-hierarchy
14492 ent-alist conf-alist (nth 3 conf-entry)
14493 (nth 4 conf-entry) token (nth 5 conf-entry)
14495 (subpack-alist (nth 6 conf-entry))
14497 (if (not (or hier-alist subpack-alist))
14498 (speedbar-change-expand-button-char ??)
14499 (speedbar-change-expand-button-char ?-)
14500 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14501 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14502 (aput 'unit-alist token nil)
14503 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14504 (speedbar-with-writable
14506 (end-of-line) (forward-char 1)
14507 ;; insert instance hierarchy
14509 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14511 (setq entry (car hier-alist))
14512 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14513 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14514 (vhdl-speedbar-make-inst-line
14515 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14516 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14517 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14518 (setq hier-alist (cdr hier-alist)))
14519 ;; insert required packages
14520 (vhdl-speedbar-insert-subpackages
14521 subpack-alist (1+ indent) indent)))
14522 (when (memq 'display vhdl-speedbar-save-cache)
14523 (add-to-list 'vhdl-updated-project-list key))
14524 (vhdl-speedbar-update-current-unit t t))))
14525 ((string-match "-" text) ; contract configuration
14526 (speedbar-change-expand-button-char ?+)
14527 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14528 (let* ((key (vhdl-speedbar-line-key indent))
14529 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14530 (adelete 'unit-alist token)
14532 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14533 (adelete 'vhdl-speedbar-shown-unit-alist key))
14534 (speedbar-delete-subblock indent)
14535 (when (memq 'display vhdl-speedbar-save-cache)
14536 (add-to-list 'vhdl-updated-project-list key))))
14537 (t (error "Nothing to display")))
14538 (when (equal (selected-frame) speedbar-frame)
14539 (speedbar-center-buffer-smartly)))
14541 (defun vhdl-speedbar-expand-package (text token indent)
14542 "Expand/contract the package under the cursor."
14544 ((string-match "+" text) ; expand package
14545 (let* ((key (vhdl-speedbar-line-key indent))
14546 (pack-alist (aget vhdl-package-alist key t))
14547 (pack-entry (aget pack-alist token t))
14548 (comp-alist (nth 3 pack-entry))
14549 (func-alist (nth 4 pack-entry))
14550 (func-body-alist (nth 8 pack-entry))
14551 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14552 comp-entry func-entry func-body-entry)
14553 (if (not (or comp-alist func-alist subpack-alist))
14554 (speedbar-change-expand-button-char ??)
14555 (speedbar-change-expand-button-char ?-)
14556 ;; add package to `vhdl-speedbar-shown-unit-alist'
14557 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14558 (aput 'unit-alist token nil)
14559 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14560 (speedbar-with-writable
14562 (end-of-line) (forward-char 1)
14563 ;; insert components
14565 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14567 (setq comp-entry (car comp-alist))
14568 (speedbar-make-tag-line
14570 (cons token (nth 0 comp-entry))
14571 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14572 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14573 'vhdl-speedbar-entity-face (1+ indent))
14574 (setq comp-alist (cdr comp-alist)))
14575 ;; insert subprograms
14577 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14579 (setq func-entry (car func-alist)
14580 func-body-entry (aget func-body-alist (car func-entry) t))
14581 (when (nth 2 func-entry)
14582 (vhdl-speedbar-make-subprogram-line
14584 (cons (nth 2 func-entry) (nth 3 func-entry))
14585 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14587 (setq func-alist (cdr func-alist)))
14588 ;; insert required packages
14589 (vhdl-speedbar-insert-subpackages
14590 subpack-alist (1+ indent) indent)))
14591 (when (memq 'display vhdl-speedbar-save-cache)
14592 (add-to-list 'vhdl-updated-project-list key))
14593 (vhdl-speedbar-update-current-unit t t))))
14594 ((string-match "-" text) ; contract package
14595 (speedbar-change-expand-button-char ?+)
14596 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14597 (let* ((key (vhdl-speedbar-line-key indent))
14598 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14599 (adelete 'unit-alist token)
14601 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14602 (adelete 'vhdl-speedbar-shown-unit-alist key))
14603 (speedbar-delete-subblock indent)
14604 (when (memq 'display vhdl-speedbar-save-cache)
14605 (add-to-list 'vhdl-updated-project-list key))))
14606 (t (error "Nothing to display")))
14607 (when (equal (selected-frame) speedbar-frame)
14608 (speedbar-center-buffer-smartly)))
14610 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14611 "Insert required packages."
14612 (let* ((pack-alist (aget vhdl-package-alist
14613 (vhdl-speedbar-line-key dir-indent) t))
14614 pack-key lib-name pack-entry)
14615 (when subpack-alist
14616 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14617 (while subpack-alist
14618 (setq pack-key (cdar subpack-alist)
14619 lib-name (caar subpack-alist))
14620 (setq pack-entry (aget pack-alist pack-key t))
14621 (vhdl-speedbar-make-subpack-line
14622 (or (nth 0 pack-entry) pack-key) lib-name
14623 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14624 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14625 (setq subpack-alist (cdr subpack-alist)))))
14627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14628 ;; Display help functions
14630 (defvar vhdl-speedbar-update-current-unit t
14631 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14633 (defun vhdl-speedbar-update-current-project ()
14634 "Highlight project that is currently active."
14635 (when (and vhdl-speedbar-show-projects
14636 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14637 (and (boundp 'speedbar-frame)
14638 (frame-live-p speedbar-frame)))
14639 (let ((last-frame (selected-frame))
14640 (project-alist vhdl-project-alist)
14642 (select-frame speedbar-frame)
14643 (speedbar-with-writable
14645 (while project-alist
14646 (goto-char (point-min))
14647 (when (re-search-forward
14648 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14649 (put-text-property (match-beginning 1) (match-end 1) 'face
14650 (if (equal (caar project-alist) vhdl-project)
14651 'speedbar-selected-face
14652 'speedbar-directory-face))
14653 (when (equal (caar project-alist) vhdl-project)
14654 (setq pos (1- (match-beginning 1)))))
14655 (setq project-alist (cdr project-alist))))
14656 (when pos (goto-char pos)))
14657 (select-frame last-frame)
14658 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14661 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14662 "Highlight all design units that are contained in the current file.
14663 NO-POSITION non-nil means do not re-position cursor."
14664 (let ((last-frame (selected-frame))
14665 (project-list vhdl-speedbar-shown-project-list)
14666 file-alist pos file-name)
14667 ;; get current file name
14668 (if (fboundp 'speedbar-select-attached-frame)
14669 (speedbar-select-attached-frame)
14670 (select-frame speedbar-attached-frame))
14671 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14672 (when (and vhdl-speedbar-update-current-unit
14673 (or always (not (equal file-name speedbar-last-selected-file))))
14674 (if vhdl-speedbar-show-projects
14675 (while project-list
14676 (setq file-alist (append file-alist (aget vhdl-file-alist
14677 (car project-list) t)))
14678 (setq project-list (cdr project-list)))
14679 (setq file-alist (aget vhdl-file-alist
14680 (abbreviate-file-name default-directory) t)))
14681 (select-frame speedbar-frame)
14682 (set-buffer speedbar-buffer)
14683 (speedbar-with-writable
14684 (vhdl-prepare-search-1
14686 ;; unhighlight last units
14687 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14688 (vhdl-speedbar-update-units
14689 "\\[.\\] " (nth 0 file-entry)
14690 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14691 (vhdl-speedbar-update-units
14692 "{.} " (nth 1 file-entry)
14693 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14694 (vhdl-speedbar-update-units
14695 "\\[.\\] " (nth 3 file-entry)
14696 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14697 (vhdl-speedbar-update-units
14698 "[]>] " (nth 4 file-entry)
14699 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14700 (vhdl-speedbar-update-units
14701 "\\[.\\].+(" '("body")
14702 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14703 (vhdl-speedbar-update-units
14704 "> " (nth 6 file-entry)
14705 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14706 ;; highlight current units
14707 (let* ((file-entry (aget file-alist file-name t)))
14709 pos (vhdl-speedbar-update-units
14710 "\\[.\\] " (nth 0 file-entry)
14711 file-name 'vhdl-speedbar-entity-selected-face pos)
14712 pos (vhdl-speedbar-update-units
14713 "{.} " (nth 1 file-entry)
14714 file-name 'vhdl-speedbar-architecture-selected-face pos)
14715 pos (vhdl-speedbar-update-units
14716 "\\[.\\] " (nth 3 file-entry)
14717 file-name 'vhdl-speedbar-configuration-selected-face pos)
14718 pos (vhdl-speedbar-update-units
14719 "[]>] " (nth 4 file-entry)
14720 file-name 'vhdl-speedbar-package-selected-face pos)
14721 pos (vhdl-speedbar-update-units
14722 "\\[.\\].+(" '("body")
14723 file-name 'vhdl-speedbar-package-selected-face pos)
14724 pos (vhdl-speedbar-update-units
14725 "> " (nth 6 file-entry)
14726 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14727 ;; move speedbar so the first highlighted unit is visible
14728 (when (and pos (not no-position))
14730 (speedbar-center-buffer-smartly)
14731 (speedbar-position-cursor-on-line))
14732 (setq speedbar-last-selected-file file-name))
14733 (select-frame last-frame)
14736 (defun vhdl-speedbar-update-units (text unit-list file-name face
14738 "Help function to highlight design units."
14740 (goto-char (point-min))
14741 (while (re-search-forward
14742 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14743 (when (equal file-name (car (get-text-property
14744 (match-beginning 1) 'speedbar-token)))
14745 (setq pos (or pos (point-marker)))
14746 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14747 (setq unit-list (cdr unit-list)))
14750 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14751 ent-name ent-file-marker
14752 arch-name arch-file-marker
14753 conf-name conf-file-marker
14754 lib-name depth offset delimiter)
14755 "Insert instantiation entry."
14756 (let ((start (point))
14758 (insert (int-to-string depth) ":")
14759 (put-text-property start (point) 'invisible t)
14760 (setq visible-start (point))
14761 (insert-char ? (* depth speedbar-indentation-width))
14762 (while (> offset 0)
14764 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14765 (setq offset (1- offset)))
14766 (put-text-property visible-start (point) 'invisible nil)
14767 (setq start (point))
14769 (speedbar-make-button start (point) nil nil nil)
14770 (setq visible-start (point))
14772 (setq start (point))
14773 (if (not inst-name)
14776 (speedbar-make-button
14777 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14778 'vhdl-speedbar-find-file inst-file-marker))
14781 (setq start (point))
14783 (speedbar-make-button
14784 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14785 'vhdl-speedbar-find-file ent-file-marker)
14788 (setq start (point))
14790 (speedbar-make-button
14791 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14792 'vhdl-speedbar-find-file arch-file-marker)
14796 (setq start (point))
14798 (speedbar-make-button
14799 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14800 'vhdl-speedbar-find-file conf-file-marker)
14802 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14803 (setq start (point))
14804 (insert " (" lib-name ")")
14805 (put-text-property (+ 2 start) (1- (point)) 'face
14806 'vhdl-speedbar-library-face))
14807 (insert-char ?\n 1)
14808 (put-text-property visible-start (point) 'invisible nil)))
14810 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14811 body-file-marker depth)
14812 "Insert package entry."
14813 (let ((start (point))
14815 (insert (int-to-string depth) ":")
14816 (put-text-property start (point) 'invisible t)
14817 (setq visible-start (point))
14818 (insert-char ? (* depth speedbar-indentation-width))
14819 (put-text-property visible-start (point) 'invisible nil)
14820 (setq start (point))
14822 (speedbar-make-button
14823 start (point) 'speedbar-button-face 'speedbar-highlight-face
14824 'vhdl-speedbar-expand-package pack-key)
14825 (setq visible-start (point))
14826 (insert-char ? 1 nil)
14827 (setq start (point))
14829 (speedbar-make-button
14830 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14831 'vhdl-speedbar-find-file pack-file-marker)
14832 (unless (car pack-file-marker)
14834 (when (car body-file-marker)
14836 (setq start (point))
14838 (speedbar-make-button
14839 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14840 'vhdl-speedbar-find-file body-file-marker)
14842 (insert-char ?\n 1)
14843 (put-text-property visible-start (point) 'invisible nil)))
14845 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14846 pack-body-file-marker depth)
14847 "Insert used package entry."
14848 (let ((start (point))
14850 (insert (int-to-string depth) ":")
14851 (put-text-property start (point) 'invisible t)
14852 (setq visible-start (point))
14853 (insert-char ? (* depth speedbar-indentation-width))
14854 (put-text-property visible-start (point) 'invisible nil)
14855 (setq start (point))
14857 (speedbar-make-button start (point) nil nil nil)
14858 (setq visible-start (point))
14860 (setq start (point))
14862 (speedbar-make-button
14863 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14864 'vhdl-speedbar-find-file pack-file-marker)
14865 (when (car pack-body-file-marker)
14867 (setq start (point))
14869 (speedbar-make-button
14870 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14871 'vhdl-speedbar-find-file pack-body-file-marker)
14873 (setq start (point))
14874 (insert " (" lib-name ")")
14875 (put-text-property (+ 2 start) (1- (point)) 'face
14876 'vhdl-speedbar-library-face)
14877 (insert-char ?\n 1)
14878 (put-text-property visible-start (point) 'invisible nil)))
14880 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14881 func-body-file-marker
14883 "Insert subprogram entry."
14884 (let ((start (point))
14886 (insert (int-to-string depth) ":")
14887 (put-text-property start (point) 'invisible t)
14888 (setq visible-start (point))
14889 (insert-char ? (* depth speedbar-indentation-width))
14890 (put-text-property visible-start (point) 'invisible nil)
14891 (setq start (point))
14893 (speedbar-make-button start (point) nil nil nil)
14894 (setq visible-start (point))
14896 (setq start (point))
14898 (speedbar-make-button
14899 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14900 'vhdl-speedbar-find-file func-file-marker)
14901 (when (car func-body-file-marker)
14903 (setq start (point))
14905 (speedbar-make-button
14906 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14907 'vhdl-speedbar-find-file func-body-file-marker)
14909 (insert-char ?\n 1)
14910 (put-text-property visible-start (point) 'invisible nil)))
14912 (defun vhdl-speedbar-make-title-line (text &optional depth)
14913 "Insert design unit title entry."
14914 (let ((start (point))
14917 (insert (int-to-string depth) ":")
14918 (put-text-property start (point) 'invisible t))
14919 (setq visible-start (point))
14920 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14921 (setq start (point))
14923 (speedbar-make-button start (point) nil nil nil nil)
14924 (insert-char ?\n 1)
14925 (put-text-property visible-start (point) 'invisible nil)))
14927 (defun vhdl-speedbar-insert-dirs (files level)
14928 "Insert subdirectories."
14929 (let ((dirs (car files)))
14931 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14932 (car dirs) 'speedbar-dir-follow nil
14933 'speedbar-directory-face level)
14934 (setq dirs (cdr dirs)))))
14936 (defun vhdl-speedbar-dired (text token indent)
14937 "Speedbar click handler for directory expand button in hierarchy mode."
14938 (cond ((string-match "+" text) ; we have to expand this dir
14939 (setq speedbar-shown-directories
14940 (cons (expand-file-name
14941 (concat (speedbar-line-directory indent) token "/"))
14942 speedbar-shown-directories))
14943 (speedbar-change-expand-button-char ?-)
14944 (speedbar-reset-scanners)
14945 (speedbar-with-writable
14947 (end-of-line) (forward-char 1)
14948 (vhdl-speedbar-insert-dirs
14949 (speedbar-file-lists
14950 (concat (speedbar-line-directory indent) token "/"))
14952 (speedbar-reset-scanners)
14953 (vhdl-speedbar-insert-dir-hierarchy
14954 (abbreviate-file-name
14955 (concat (speedbar-line-directory indent) token "/"))
14956 (1+ indent) speedbar-power-click)))
14957 (vhdl-speedbar-update-current-unit t t))
14958 ((string-match "-" text) ; we have to contract this node
14959 (speedbar-reset-scanners)
14960 (let ((oldl speedbar-shown-directories)
14962 (td (expand-file-name
14963 (concat (speedbar-line-directory indent) token))))
14965 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14966 (setq newl (cons (car oldl) newl)))
14967 (setq oldl (cdr oldl)))
14968 (setq speedbar-shown-directories (nreverse newl)))
14969 (speedbar-change-expand-button-char ?+)
14970 (speedbar-delete-subblock indent))
14971 (t (error "Nothing to display")))
14972 (when (equal (selected-frame) speedbar-frame)
14973 (speedbar-center-buffer-smartly)))
14975 (defun vhdl-speedbar-item-info ()
14976 "Derive and display information about this line item."
14978 (beginning-of-line)
14979 ;; skip invisible number info
14980 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14982 ;; project/directory entry
14983 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14984 (if vhdl-speedbar-show-projects
14985 (message "Project \"%s\"" (match-string-no-properties 1))
14986 (speedbar-files-item-info)))
14987 ;; design unit entry
14988 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14989 (goto-char (match-end 1))
14990 (let ((face (get-text-property (point) 'face)))
14992 "%s \"%s\" in \"%s\""
14993 ;; design unit kind
14994 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14995 (eq face 'vhdl-speedbar-entity-selected-face))
14996 (if (equal (match-string 2) ">") "Component" "Entity"))
14997 ((or (eq face 'vhdl-speedbar-architecture-face)
14998 (eq face 'vhdl-speedbar-architecture-selected-face))
15000 ((or (eq face 'vhdl-speedbar-configuration-face)
15001 (eq face 'vhdl-speedbar-configuration-selected-face))
15003 ((or (eq face 'vhdl-speedbar-package-face)
15004 (eq face 'vhdl-speedbar-package-selected-face))
15006 ((or (eq face 'vhdl-speedbar-instantiation-face)
15007 (eq face 'vhdl-speedbar-instantiation-selected-face))
15009 ((eq face 'vhdl-speedbar-subprogram-face)
15012 ;; design unit name
15013 (buffer-substring-no-properties
15014 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15017 (file-relative-name
15018 (or (car (get-text-property (point) 'speedbar-token))
15020 (vhdl-default-directory)))))
15021 (t (message "")))))
15023 (defun vhdl-speedbar-line-text ()
15024 "Calls `speedbar-line-text' and removes text properties."
15025 (let ((string (speedbar-line-text)))
15026 (set-text-properties 0 (length string) nil string)
15029 (defun vhdl-speedbar-higher-text ()
15030 "Get speedbar-line-text of higher level."
15031 (let (depth string)
15033 (beginning-of-line)
15034 (looking-at "^\\([0-9]+\\):")
15035 (setq depth (string-to-number (match-string 1)))
15036 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15037 (setq string (match-string 1))
15038 (set-text-properties 0 (length string) nil string)
15041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15044 (defun vhdl-speedbar-line-key (&optional indent)
15045 "Get currently displayed directory of project name."
15046 (if vhdl-speedbar-show-projects
15047 (vhdl-speedbar-line-project)
15048 (abbreviate-file-name
15049 (file-name-as-directory (speedbar-line-directory indent)))))
15051 (defun vhdl-speedbar-line-project (&optional indent)
15052 "Get currently displayed project name."
15053 (and vhdl-speedbar-show-projects
15056 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15057 (match-string-no-properties 1))))
15059 (defun vhdl-add-modified-file ()
15060 "Add file to `vhdl-modified-file-list'."
15061 (when vhdl-file-alist
15062 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15065 (defun vhdl-resolve-paths (path-list)
15066 "Resolve path wildcards in PATH-LIST."
15067 (let (path-list-1 path-list-2 path-beg path-end dir)
15068 ;; eliminate non-existent directories
15070 (setq dir (car path-list))
15071 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15072 (if (file-directory-p (match-string 2 dir))
15073 (setq path-list-1 (cons dir path-list-1))
15074 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15075 (setq path-list (cdr path-list)))
15076 ;; resolve path wildcards
15078 (setq dir (car path-list-1))
15079 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15081 (setq path-beg (match-string 1 dir)
15082 path-end (match-string 5 dir))
15087 (lambda (var) (concat path-beg var path-end)))
15088 (let ((all-list (vhdl-directory-files
15089 (match-string 2 dir) t
15090 (concat "\\<" (wildcard-to-regexp
15091 (match-string 4 dir)))))
15094 (when (file-directory-p (car all-list))
15095 (setq dir-list (cons (car all-list) dir-list)))
15096 (setq all-list (cdr all-list)))
15098 (cdr path-list-1))))
15099 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15100 (when (file-directory-p (match-string 2 dir))
15101 (setq path-list-2 (cons dir path-list-2)))
15102 (setq path-list-1 (cdr path-list-1))))
15103 (nreverse path-list-2)))
15105 (defun vhdl-speedbar-goto-this-unit (directory unit)
15106 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15107 (let ((dest (point)))
15108 (if (and (if vhdl-speedbar-show-projects
15109 (progn (goto-char (point-min)) t)
15110 (speedbar-goto-this-file directory))
15111 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15112 (progn (speedbar-position-cursor-on-line)
15117 (defun vhdl-speedbar-find-file (text token indent)
15118 "When user clicks on TEXT, load file with name and position in TOKEN.
15119 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15120 is already shown in a buffer."
15121 (if (not (car token))
15122 (error "ERROR: File cannot be found")
15123 (let ((buffer (get-file-buffer (car token))))
15124 (speedbar-find-file-in-frame (car token))
15125 (when (or vhdl-speedbar-jump-to-unit buffer)
15126 (goto-char (point-min))
15127 (forward-line (1- (cdr token)))
15129 (vhdl-speedbar-update-current-unit t t)
15130 (speedbar-set-timer dframe-update-speed)
15131 (speedbar-maybee-jump-to-attached-frame))))
15133 (defun vhdl-speedbar-port-copy ()
15134 "Copy the port of the entity/component or subprogram under the cursor."
15136 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15137 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15138 (error "ERROR: No entity/component or subprogram under cursor")
15139 (beginning-of-line)
15140 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15141 (condition-case info
15142 (let ((token (get-text-property
15143 (match-beginning 3) 'speedbar-token)))
15144 (vhdl-visit-file (car token) t
15145 (progn (goto-char (point-min))
15146 (forward-line (1- (cdr token)))
15150 (vhdl-subprog-copy)))))
15151 (error (error "ERROR: %s not scanned successfully\n (%s)"
15152 (if is-entity "Port" "Interface") (cadr info))))
15153 (error "ERROR: No entity/component or subprogram on current line")))))
15155 (defun vhdl-speedbar-place-component ()
15156 "Place the entity/component under the cursor as component."
15158 (if (not (vhdl-speedbar-check-unit 'entity))
15159 (error "ERROR: No entity/component under cursor")
15160 (vhdl-speedbar-port-copy)
15161 (if (fboundp 'speedbar-select-attached-frame)
15162 (speedbar-select-attached-frame)
15163 (select-frame speedbar-attached-frame))
15164 (vhdl-compose-place-component)
15165 (select-frame speedbar-frame)))
15167 (defun vhdl-speedbar-configuration ()
15168 "Generate configuration for the architecture under the cursor."
15170 (if (not (vhdl-speedbar-check-unit 'architecture))
15171 (error "ERROR: No architecture under cursor")
15172 (let ((arch-name (vhdl-speedbar-line-text))
15173 (ent-name (vhdl-speedbar-higher-text)))
15174 (if (fboundp 'speedbar-select-attached-frame)
15175 (speedbar-select-attached-frame)
15176 (select-frame speedbar-attached-frame))
15177 (vhdl-compose-configuration ent-name arch-name))))
15179 (defun vhdl-speedbar-select-mra ()
15180 "Select the architecture under the cursor as MRA."
15182 (if (not (vhdl-speedbar-check-unit 'architecture))
15183 (error "ERROR: No architecture under cursor")
15184 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15185 (ent-key (downcase (vhdl-speedbar-higher-text)))
15186 (ent-alist (aget vhdl-entity-alist
15187 (or (vhdl-project-p) default-directory) t))
15188 (ent-entry (aget ent-alist ent-key t)))
15189 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15190 (speedbar-refresh))))
15192 (defun vhdl-speedbar-make-design ()
15193 "Make (compile) design unit or directory/project under the cursor."
15195 (if (not (save-excursion (beginning-of-line)
15196 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15197 (error "ERROR: No primary design unit or directory/project under cursor")
15198 (let ((is-unit (match-string 2))
15199 (unit-name (vhdl-speedbar-line-text))
15200 (vhdl-project (vhdl-speedbar-line-project))
15201 (directory (file-name-as-directory
15202 (or (speedbar-line-file) (speedbar-line-directory)))))
15203 (if (fboundp 'speedbar-select-attached-frame)
15204 (speedbar-select-attached-frame)
15205 (select-frame speedbar-attached-frame))
15206 (let ((default-directory directory))
15207 (vhdl-make (and is-unit unit-name))))))
15209 (defun vhdl-speedbar-generate-makefile ()
15210 "Generate Makefile for directory/project under the cursor."
15212 (let ((vhdl-project (vhdl-speedbar-line-project))
15213 (default-directory (file-name-as-directory
15214 (or (speedbar-line-file) (speedbar-line-directory)))))
15215 (vhdl-generate-makefile)))
15217 (defun vhdl-speedbar-check-unit (design-unit)
15218 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15219 expansion function)."
15221 (speedbar-position-cursor-on-line)
15222 (cond ((eq design-unit 'entity)
15223 (memq (get-text-property (match-end 0) 'face)
15224 '(vhdl-speedbar-entity-face
15225 vhdl-speedbar-entity-selected-face)))
15226 ((eq design-unit 'architecture)
15227 (memq (get-text-property (match-end 0) 'face)
15228 '(vhdl-speedbar-architecture-face
15229 vhdl-speedbar-architecture-selected-face)))
15230 ((eq design-unit 'subprogram)
15231 (eq (get-text-property (match-end 0) 'face)
15232 'vhdl-speedbar-subprogram-face))
15235 (defun vhdl-speedbar-set-depth (depth)
15236 "Set hierarchy display depth to DEPTH and refresh speedbar."
15237 (setq vhdl-speedbar-hierarchy-depth depth)
15238 (speedbar-refresh))
15240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15243 (defface vhdl-speedbar-entity-face
15244 '((((class color) (background light)) (:foreground "ForestGreen"))
15245 (((class color) (background dark)) (:foreground "PaleGreen")))
15246 "Face used for displaying entity names."
15247 :group 'speedbar-faces)
15249 (defface vhdl-speedbar-architecture-face
15250 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15251 (((class color) (background light)) (:foreground "Blue"))
15253 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15254 "Face used for displaying architecture names."
15255 :group 'speedbar-faces)
15257 (defface vhdl-speedbar-configuration-face
15258 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15259 (((class color) (background dark)) (:foreground "Salmon")))
15260 "Face used for displaying configuration names."
15261 :group 'speedbar-faces)
15263 (defface vhdl-speedbar-package-face
15264 '((((class color) (background light)) (:foreground "Grey50"))
15265 (((class color) (background dark)) (:foreground "Grey80")))
15266 "Face used for displaying package names."
15267 :group 'speedbar-faces)
15269 (defface vhdl-speedbar-library-face
15270 '((((class color) (background light)) (:foreground "Purple"))
15271 (((class color) (background dark)) (:foreground "Orchid1")))
15272 "Face used for displaying library names."
15273 :group 'speedbar-faces)
15275 (defface vhdl-speedbar-instantiation-face
15276 '((((class color) (background light)) (:foreground "Brown"))
15277 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15278 (((class color) (background dark)) (:foreground "Yellow")))
15279 "Face used for displaying instantiation names."
15280 :group 'speedbar-faces)
15282 (defface vhdl-speedbar-subprogram-face
15283 '((((class color) (background light)) (:foreground "Orchid4"))
15284 (((class color) (background dark)) (:foreground "BurlyWood2")))
15285 "Face used for displaying subprogram names."
15286 :group 'speedbar-faces)
15288 (defface vhdl-speedbar-entity-selected-face
15289 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15290 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15291 "Face used for displaying entity names."
15292 :group 'speedbar-faces)
15294 (defface vhdl-speedbar-architecture-selected-face
15295 '((((min-colors 88) (class color) (background light)) (:foreground
15296 "Blue1" :underline t))
15297 (((class color) (background light)) (:foreground "Blue" :underline t))
15298 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15299 "Face used for displaying architecture names."
15300 :group 'speedbar-faces)
15302 (defface vhdl-speedbar-configuration-selected-face
15303 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15304 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15305 "Face used for displaying configuration names."
15306 :group 'speedbar-faces)
15308 (defface vhdl-speedbar-package-selected-face
15309 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15310 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15311 "Face used for displaying package names."
15312 :group 'speedbar-faces)
15314 (defface vhdl-speedbar-instantiation-selected-face
15315 '((((class color) (background light)) (:foreground "Brown" :underline t))
15316 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15317 "Face used for displaying instantiation names."
15318 :group 'speedbar-faces)
15320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15324 (when (fboundp 'speedbar)
15326 (when (and vhdl-speedbar-auto-open
15327 (not (and (boundp 'speedbar-frame)
15328 (frame-live-p speedbar-frame))))
15329 (speedbar-frame-mode 1)
15330 (if (fboundp 'speedbar-select-attached-frame)
15331 (speedbar-select-attached-frame)
15332 (select-frame speedbar-attached-frame)))
15333 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15335 ;; initialize speedbar
15336 (if (not (boundp 'speedbar-frame))
15337 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15338 (vhdl-speedbar-initialize)
15339 (when speedbar-frame (vhdl-speedbar-refresh)))
15342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15343 ;;; Structural composition
15344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15346 (defun vhdl-get-components-package-name ()
15347 "Return the name of the components package."
15348 (let ((project (vhdl-project-p)))
15350 (vhdl-replace-string (car vhdl-components-package-name)
15351 (subst-char-in-string ? ?_ project))
15352 (cdr vhdl-components-package-name))))
15354 (defun vhdl-compose-new-component ()
15355 "Create entity and architecture for new component."
15357 (let* ((case-fold-search t)
15358 (ent-name (read-from-minibuffer "entity name: "
15359 nil vhdl-minibuffer-local-map))
15361 (if (equal (cdr vhdl-compose-architecture-name) "")
15362 (read-from-minibuffer "architecture name: "
15363 nil vhdl-minibuffer-local-map)
15364 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15365 ent-file-name arch-file-name ent-buffer arch-buffer project)
15366 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15367 ;; open entity file
15368 (unless (eq vhdl-compose-create-files 'none)
15369 (setq ent-file-name
15370 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15371 "." (file-name-extension (buffer-file-name))))
15372 (when (and (file-exists-p ent-file-name)
15373 (not (y-or-n-p (concat "File \"" ent-file-name
15374 "\" exists; overwrite? "))))
15375 (error "ERROR: Creating component...aborted"))
15376 (find-file ent-file-name)
15378 (set-buffer-modified-p nil))
15380 (if vhdl-compose-include-header
15381 (progn (vhdl-template-header)
15382 (goto-char (point-max)))
15383 (vhdl-comment-display-line) (insert "\n\n"))
15384 ;; insert library clause
15385 (vhdl-template-package-std-logic-1164)
15386 (when vhdl-use-components-package
15388 (vhdl-template-standard-package (vhdl-work-library)
15389 (vhdl-get-components-package-name)))
15390 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15391 ;; insert entity declaration
15392 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15393 (vhdl-insert-keyword " IS\n")
15394 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15395 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15396 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15397 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15398 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15399 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15400 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15401 (vhdl-insert-keyword "END ")
15402 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15403 (insert ent-name ";\n\n")
15404 (vhdl-comment-display-line) (insert "\n")
15405 ;; open architecture file
15406 (if (not (eq vhdl-compose-create-files 'separate))
15408 (setq ent-buffer (current-buffer))
15409 (setq arch-file-name
15410 (concat (vhdl-replace-string vhdl-architecture-file-name
15411 (concat ent-name " " arch-name) t)
15412 "." (file-name-extension (buffer-file-name))))
15413 (when (and (file-exists-p arch-file-name)
15414 (not (y-or-n-p (concat "File \"" arch-file-name
15415 "\" exists; overwrite? "))))
15416 (error "ERROR: Creating component...aborted"))
15417 (find-file arch-file-name)
15419 (set-buffer-modified-p nil)
15421 (if vhdl-compose-include-header
15422 (progn (vhdl-template-header)
15423 (goto-char (point-max)))
15424 (vhdl-comment-display-line) (insert "\n\n")))
15425 ;; insert architecture body
15426 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15427 (vhdl-insert-keyword " OF ") (insert ent-name)
15428 (vhdl-insert-keyword " IS\n\n")
15429 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15430 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15431 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15432 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15433 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15434 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15435 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15436 (vhdl-insert-keyword "BEGIN")
15437 (when vhdl-self-insert-comments
15439 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15440 (insert arch-name))
15442 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15443 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15444 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15445 (vhdl-insert-keyword "END ")
15446 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15447 (insert arch-name ";\n\n")
15448 ;; insert footer and save
15449 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15450 (vhdl-template-footer)
15451 (vhdl-comment-display-line) (insert "\n"))
15452 (goto-char (point-min))
15453 (setq arch-buffer (current-buffer))
15454 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15455 (set-buffer arch-buffer) (save-buffer)
15457 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15459 (format "\n File created: \"%s\"" ent-file-name))
15460 (and arch-file-name
15461 (format "\n File created: \"%s\"" arch-file-name))))))
15463 (defun vhdl-compose-place-component ()
15464 "Place new component by pasting current port as component declaration and
15465 component instantiation."
15467 (if (not vhdl-port-list)
15468 (error "ERROR: No port has been read")
15470 (vhdl-prepare-search-2
15471 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15472 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15473 (error "ERROR: No architecture found"))
15474 (let* ((ent-name (match-string 1))
15476 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15477 "." (file-name-extension (buffer-file-name))))
15478 (orig-buffer (current-buffer)))
15479 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15480 ;; place component declaration
15481 (unless (or vhdl-use-components-package
15482 (vhdl-use-direct-instantiation)
15485 (concat "^\\s-*component\\s-+"
15486 (car vhdl-port-list) "\\>") nil t)))
15487 (re-search-forward "^begin\\>" nil)
15488 (beginning-of-line)
15489 (skip-chars-backward " \t\n")
15490 (insert "\n\n") (indent-to vhdl-basic-offset)
15491 (vhdl-port-paste-component t))
15492 ;; place component instantiation
15493 (re-search-forward "^end\\>" nil)
15494 (beginning-of-line)
15495 (skip-chars-backward " \t\n")
15496 (insert "\n\n") (indent-to vhdl-basic-offset)
15497 (vhdl-port-paste-instance nil t t)
15498 ;; place use clause for used packages
15499 (when (nth 3 vhdl-port-list)
15500 ;; open entity file
15501 (when (file-exists-p ent-file-name)
15502 (find-file ent-file-name))
15503 (goto-char (point-min))
15504 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15505 (error "ERROR: Entity not found: \"%s\"" ent-name))
15506 (goto-char (match-beginning 0))
15507 (if (and (save-excursion
15508 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15510 (progn (goto-char (match-end 0))
15511 (beginning-of-line 2))
15514 (vhdl-port-paste-context-clause)
15515 (switch-to-buffer orig-buffer))
15516 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15518 (defun vhdl-compose-wire-components ()
15519 "Connect components."
15522 (vhdl-prepare-search-2
15523 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15524 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15525 (error "ERROR: No architecture found"))
15526 (let* ((ent-name (match-string 1))
15528 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15529 "." (file-name-extension (buffer-file-name))))
15530 (arch-decl-pos (point-marker))
15531 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15532 (arch-end-pos (re-search-forward "^end\\>" nil))
15533 (pack-name (vhdl-get-components-package-name))
15535 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15536 "." (file-name-extension (buffer-file-name))))
15537 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15538 port-alist generic-alist inst-alist
15539 signal-name signal-entry signal-alist local-list written-list
15540 single-in-list multi-in-list single-out-list multi-out-list
15541 constant-name constant-entry constant-alist single-list multi-list
15542 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15543 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15544 signal-beg-pos signal-pos
15545 constant-temp-pos port-temp-pos signal-temp-pos)
15546 (message "Wiring components...")
15547 ;; process all instances
15548 (goto-char arch-stat-pos)
15549 (while (re-search-forward
15550 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15551 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15552 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15553 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15554 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15555 (setq inst-name (match-string-no-properties 1)
15556 comp-name (match-string-no-properties 4)
15557 comp-ent-name (match-string-no-properties 12)
15558 has-generic (or (match-string 7) (match-string 17)))
15561 ;; ... from component declaration
15563 (when vhdl-use-components-package pack-file-name) t
15565 (goto-char (point-min))
15566 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15567 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15569 ;; ... from entity declaration (direct instantiation)
15570 (setq comp-ent-file-name
15571 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15572 "." (file-name-extension (buffer-file-name))))
15574 comp-ent-file-name t
15576 (goto-char (point-min))
15577 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15578 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15579 (vhdl-port-copy))))
15580 (vhdl-port-flatten t)
15581 (setq generic-alist (nth 1 vhdl-port-list)
15582 port-alist (nth 2 vhdl-port-list)
15583 vhdl-port-list nil)
15584 (setq constant-alist nil
15587 ;; process all constants in generic map
15588 (vhdl-forward-syntactic-ws)
15589 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15590 (setq constant-name (match-string-no-properties 3))
15591 (setq constant-entry
15592 (cons constant-name
15593 (if (match-string 1)
15594 (or (aget generic-alist (match-string 2) t)
15595 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15596 (cdar generic-alist))))
15597 (setq constant-alist (cons constant-entry constant-alist))
15598 (setq constant-name (downcase constant-name))
15599 (if (or (member constant-name single-list)
15600 (member constant-name multi-list))
15601 (progn (setq single-list (delete constant-name single-list))
15602 (add-to-list 'multi-list constant-name))
15603 (add-to-list 'single-list constant-name))
15604 (unless (match-string 1)
15605 (setq generic-alist (cdr generic-alist)))
15606 (vhdl-forward-syntactic-ws))
15607 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15608 ;; process all signals in port map
15609 (vhdl-forward-syntactic-ws)
15610 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15611 (setq signal-name (match-string-no-properties 3))
15612 (setq signal-entry (cons signal-name
15613 (if (match-string 1)
15614 (or (aget port-alist (match-string 2) t)
15615 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15616 (cdar port-alist))))
15617 (setq signal-alist (cons signal-entry signal-alist))
15618 (setq signal-name (downcase signal-name))
15619 (if (equal (upcase (nth 2 signal-entry)) "IN")
15622 ((member signal-name local-list)
15624 ((or (member signal-name single-out-list)
15625 (member signal-name multi-out-list))
15626 (setq single-out-list (delete signal-name single-out-list))
15627 (setq multi-out-list (delete signal-name multi-out-list))
15628 (add-to-list 'local-list signal-name))
15629 ((member signal-name single-in-list)
15630 (setq single-in-list (delete signal-name single-in-list))
15631 (add-to-list 'multi-in-list signal-name))
15632 ((not (member signal-name multi-in-list))
15633 (add-to-list 'single-in-list signal-name)))
15636 ((member signal-name local-list)
15638 ((or (member signal-name single-in-list)
15639 (member signal-name multi-in-list))
15640 (setq single-in-list (delete signal-name single-in-list))
15641 (setq multi-in-list (delete signal-name multi-in-list))
15642 (add-to-list 'local-list signal-name))
15643 ((member signal-name single-out-list)
15644 (setq single-out-list (delete signal-name single-out-list))
15645 (add-to-list 'multi-out-list signal-name))
15646 ((not (member signal-name multi-out-list))
15647 (add-to-list 'single-out-list signal-name))))
15648 (unless (match-string 1)
15649 (setq port-alist (cdr port-alist)))
15650 (vhdl-forward-syntactic-ws))
15651 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15652 (nreverse signal-alist)) inst-alist)))
15653 ;; prepare signal insertion
15654 (vhdl-goto-marker arch-decl-pos)
15656 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15657 (setq signal-pos (point-marker))
15658 (while (progn (vhdl-forward-syntactic-ws)
15659 (looking-at "signal\\>"))
15660 (beginning-of-line 2)
15661 (delete-region signal-pos (point)))
15662 (setq signal-beg-pos signal-pos)
15663 ;; open entity file
15664 (when (file-exists-p ent-file-name)
15665 (find-file ent-file-name))
15666 (goto-char (point-min))
15667 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15668 (error "ERROR: Entity not found: \"%s\"" ent-name))
15669 ;; prepare generic clause insertion
15670 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15672 (goto-char (match-beginning 0))
15673 (indent-to vhdl-basic-offset)
15674 (insert "generic ();\n\n")
15677 (setq generic-pos (point-marker))
15678 (forward-sexp) (end-of-line)
15679 (delete-region generic-pos (point)) (delete-char 1)
15683 (indent-to (* 2 vhdl-basic-offset))
15684 (insert "-- global generics\n"))
15685 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15686 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15687 ;; prepare port clause insertion
15688 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15690 (goto-char (match-beginning 0))
15691 (indent-to vhdl-basic-offset)
15692 (insert "port ();\n\n")
15695 (setq port-in-pos (point-marker))
15696 (forward-sexp) (end-of-line)
15697 (delete-region port-in-pos (point)) (delete-char 1)
15699 (when (or multi-in-list multi-out-list)
15701 (indent-to (* 2 vhdl-basic-offset))
15702 (insert "-- global ports\n"))
15703 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15704 port-out-pos (point-marker) port-inst-pos (point-marker)
15705 port-end-pos (point-marker))
15706 ;; insert generics, ports and signals
15707 (setq inst-alist (nreverse inst-alist))
15709 (setq inst-name (nth 0 (car inst-alist))
15710 constant-alist (nth 1 (car inst-alist))
15711 signal-alist (nth 2 (car inst-alist))
15712 constant-temp-pos generic-inst-pos
15713 port-temp-pos port-inst-pos
15714 signal-temp-pos signal-pos)
15716 (while constant-alist
15717 (setq constant-name (downcase (caar constant-alist))
15718 constant-entry (car constant-alist))
15719 (cond ((member constant-name written-list)
15721 ((member constant-name multi-list)
15722 (vhdl-goto-marker generic-pos)
15723 (setq generic-end-pos
15726 (vhdl-compose-insert-generic constant-entry)))
15727 (setq generic-pos (point-marker))
15728 (add-to-list 'written-list constant-name))
15731 (vhdl-max-marker generic-inst-pos generic-pos))
15732 (setq generic-end-pos
15733 (vhdl-compose-insert-generic constant-entry))
15734 (setq generic-inst-pos (point-marker))
15735 (add-to-list 'written-list constant-name)))
15736 (setq constant-alist (cdr constant-alist)))
15737 (when (/= constant-temp-pos generic-inst-pos)
15738 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15739 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15740 (insert "-- generics for \"" inst-name "\"\n")
15741 (vhdl-goto-marker generic-inst-pos))
15742 ;; ports and signals
15743 (while signal-alist
15744 (setq signal-name (downcase (caar signal-alist))
15745 signal-entry (car signal-alist))
15746 (cond ((member signal-name written-list)
15748 ((member signal-name multi-in-list)
15749 (vhdl-goto-marker port-in-pos)
15752 port-end-pos (vhdl-compose-insert-port signal-entry)))
15753 (setq port-in-pos (point-marker))
15754 (add-to-list 'written-list signal-name))
15755 ((member signal-name multi-out-list)
15756 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15759 port-end-pos (vhdl-compose-insert-port signal-entry)))
15760 (setq port-out-pos (point-marker))
15761 (add-to-list 'written-list signal-name))
15762 ((or (member signal-name single-in-list)
15763 (member signal-name single-out-list))
15767 (vhdl-max-marker port-out-pos port-in-pos)))
15768 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15769 (setq port-inst-pos (point-marker))
15770 (add-to-list 'written-list signal-name))
15771 ((equal (upcase (nth 2 signal-entry)) "OUT")
15772 (vhdl-goto-marker signal-pos)
15773 (vhdl-compose-insert-signal signal-entry)
15774 (setq signal-pos (point-marker))
15775 (add-to-list 'written-list signal-name)))
15776 (setq signal-alist (cdr signal-alist)))
15777 (when (/= port-temp-pos port-inst-pos)
15779 (vhdl-max-marker port-temp-pos
15780 (vhdl-max-marker port-in-pos port-out-pos)))
15781 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15782 (insert "-- ports to \"" inst-name "\"\n")
15783 (vhdl-goto-marker port-inst-pos))
15784 (when (/= signal-temp-pos signal-pos)
15785 (vhdl-goto-marker signal-temp-pos)
15786 (insert "\n") (indent-to vhdl-basic-offset)
15787 (insert "-- outputs of \"" inst-name "\"\n")
15788 (vhdl-goto-marker signal-pos))
15789 (setq inst-alist (cdr inst-alist)))
15790 ;; finalize generic/port clause
15791 (vhdl-goto-marker generic-end-pos) (backward-char)
15792 (when (= generic-beg-pos generic-end-pos)
15793 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15794 (insert ";") (backward-char))
15796 (vhdl-goto-marker port-end-pos) (backward-char)
15797 (when (= port-beg-pos port-end-pos)
15798 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15799 (insert ";") (backward-char))
15801 ;; align everything
15802 (when vhdl-auto-align
15803 (vhdl-goto-marker generic-beg-pos)
15804 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15805 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15806 (vhdl-goto-marker signal-beg-pos)
15807 (vhdl-align-region-groups signal-beg-pos signal-pos))
15808 (switch-to-buffer (marker-buffer signal-beg-pos))
15809 (message "Wiring components...done")))))
15811 (defun vhdl-compose-insert-generic (entry)
15812 "Insert ENTRY as generic declaration."
15814 (indent-to (* 2 vhdl-basic-offset))
15815 (insert (nth 0 entry) " : " (nth 1 entry))
15816 (when (nth 2 entry)
15817 (insert " := " (nth 2 entry)))
15819 (setq pos (point-marker))
15820 (when (and vhdl-include-port-comments (nth 3 entry))
15821 (vhdl-comment-insert-inline (nth 3 entry) t))
15825 (defun vhdl-compose-insert-port (entry)
15826 "Insert ENTRY as port declaration."
15828 (indent-to (* 2 vhdl-basic-offset))
15829 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15830 (setq pos (point-marker))
15831 (when (and vhdl-include-port-comments (nth 4 entry))
15832 (vhdl-comment-insert-inline (nth 4 entry) t))
15836 (defun vhdl-compose-insert-signal (entry)
15837 "Insert ENTRY as signal declaration."
15838 (indent-to vhdl-basic-offset)
15839 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15840 (when (and vhdl-include-port-comments (nth 4 entry))
15841 (vhdl-comment-insert-inline (nth 4 entry) t))
15844 (defun vhdl-compose-components-package ()
15845 "Generate a package containing component declarations for all entities in the
15846 current project/directory."
15848 (vhdl-require-hierarchy-info)
15849 (let* ((project (vhdl-project-p))
15850 (pack-name (vhdl-get-components-package-name))
15852 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15853 "." (file-name-extension (buffer-file-name))))
15854 (ent-alist (aget vhdl-entity-alist
15855 (or project default-directory) t))
15856 (lazy-lock-minimum-size 0)
15857 clause-pos component-pos)
15858 (message "Generating components package \"%s\"..." pack-name)
15859 ;; open package file
15860 (when (and (file-exists-p pack-file-name)
15861 (not (y-or-n-p (concat "File \"" pack-file-name
15862 "\" exists; overwrite? "))))
15863 (error "ERROR: Generating components package...aborted"))
15864 (find-file pack-file-name)
15867 (if vhdl-compose-include-header
15868 (progn (vhdl-template-header
15869 (concat "Components package (generated by Emacs VHDL Mode "
15871 (goto-char (point-max)))
15872 (vhdl-comment-display-line) (insert "\n\n"))
15873 ;; insert std_logic_1164 package
15874 (vhdl-template-package-std-logic-1164)
15875 (insert "\n") (setq clause-pos (point-marker))
15876 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15877 ;; insert package declaration
15878 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15879 (vhdl-insert-keyword " IS\n\n")
15880 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15881 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15882 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15883 (indent-to vhdl-basic-offset)
15884 (setq component-pos (point-marker))
15885 (insert "\n\n") (vhdl-insert-keyword "END ")
15886 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15887 (insert pack-name ";\n\n")
15889 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15890 (vhdl-template-footer)
15891 (vhdl-comment-display-line) (insert "\n"))
15892 ;; insert component declarations
15894 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15895 (progn (goto-char (point-min))
15896 (forward-line (1- (nth 3 (car ent-alist))))
15899 (goto-char component-pos)
15900 (vhdl-port-paste-component t)
15901 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15902 (setq component-pos (point-marker))
15903 (goto-char clause-pos)
15904 (vhdl-port-paste-context-clause pack-name)
15905 (setq clause-pos (point-marker))
15906 (setq ent-alist (cdr ent-alist)))
15907 (goto-char (point-min))
15909 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15910 pack-name pack-file-name)))
15912 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15913 &optional insert-conf)
15914 "Generate block configuration for architecture."
15915 (let ((margin (current-indentation))
15916 (beg (point-at-bol))
15917 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15918 ;; insert block configuration (for architecture)
15919 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15920 (setq margin (+ margin vhdl-basic-offset))
15921 ;; process all instances
15923 (setq inst-entry (car inst-alist))
15925 (when (nth 4 inst-entry)
15926 (setq insert-conf t)
15927 (setq inst-path (nth 9 inst-entry))
15928 ;; skip common path with previous instance
15929 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15930 (setq inst-path (cdr inst-path)
15931 inst-prev-path (cdr inst-prev-path)))
15932 ;; insert block configuration end (for previous block/generate)
15933 (while inst-prev-path
15934 (setq margin (- margin vhdl-basic-offset))
15936 (vhdl-insert-keyword "END FOR;\n")
15937 (setq inst-prev-path (cdr inst-prev-path)))
15938 ;; insert block configuration beginning (for current block/generate)
15941 (setq margin (+ margin vhdl-basic-offset))
15942 (vhdl-insert-keyword "FOR ")
15943 (insert (car inst-path) "\n")
15945 (setq inst-path (cdr inst-path)))
15946 ;; insert component configuration beginning
15947 (vhdl-insert-keyword "FOR ")
15948 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15949 ;; find subconfiguration
15950 (setq conf-key (nth 7 inst-entry))
15951 (setq tmp-alist conf-alist)
15952 ;; use first configuration found for instance's entity
15953 (while (and tmp-alist (null conf-key))
15954 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15955 (setq conf-key (nth 0 (car tmp-alist))))
15956 (setq tmp-alist (cdr tmp-alist)))
15957 (setq conf-entry (aget conf-alist conf-key t))
15958 ;; insert binding indication ...
15959 ;; ... with subconfiguration (if exists)
15960 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15962 (indent-to (+ margin vhdl-basic-offset))
15963 (vhdl-insert-keyword "USE CONFIGURATION ")
15964 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15966 ;; ... with entity (if exists)
15967 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15969 (indent-to (+ margin vhdl-basic-offset))
15970 (vhdl-insert-keyword "USE ENTITY ")
15971 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15972 ;; insert architecture name (if architecture exists)
15973 (when (nth 3 ent-entry)
15975 ;; choose architecture name a) from configuration,
15976 ;; b) from mra, or c) from first architecture
15977 (or (nth 0 (aget (nth 3 ent-entry)
15978 (or (nth 6 inst-entry)
15979 (nth 4 ent-entry)) t))
15980 (nth 1 (car (nth 3 ent-entry)))))
15981 (insert "(" arch-name ")"))
15983 ;; insert block configuration (for architecture of subcomponent)
15984 (when (and vhdl-compose-configuration-hierarchical
15986 (indent-to (+ margin vhdl-basic-offset))
15987 (vhdl-compose-configuration-architecture
15988 (nth 0 ent-entry) arch-name
15989 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15990 ;; insert component configuration end
15992 (vhdl-insert-keyword "END FOR;\n")
15993 (setq inst-prev-path (nth 9 inst-entry)))
15994 (setq inst-alist (cdr inst-alist)))
15995 ;; insert block configuration end (for block/generate)
15996 (while inst-prev-path
15997 (setq margin (- margin vhdl-basic-offset))
15999 (vhdl-insert-keyword "END FOR;\n")
16000 (setq inst-prev-path (cdr inst-prev-path)))
16001 (indent-to (- margin vhdl-basic-offset))
16002 ;; insert block configuration end or remove beginning (for architecture)
16004 (vhdl-insert-keyword "END FOR;\n")
16005 (delete-region beg (point)))))
16007 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16008 "Generate configuration declaration."
16010 (vhdl-require-hierarchy-info)
16011 (let ((ent-alist (aget vhdl-entity-alist
16012 (or (vhdl-project-p) default-directory) t))
16013 (conf-alist (aget vhdl-config-alist
16014 (or (vhdl-project-p) default-directory) t))
16015 (from-speedbar ent-name)
16016 inst-alist conf-name conf-file-name pos)
16017 (vhdl-prepare-search-2
16018 ;; get entity and architecture name
16021 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16022 (not (equal "END" (upcase (match-string 1))))
16023 (setq ent-name (match-string-no-properties 3))
16024 (setq arch-name (match-string-no-properties 2)))
16025 (error "ERROR: Not within an architecture"))))
16026 (setq conf-name (vhdl-replace-string
16027 vhdl-compose-configuration-name
16028 (concat ent-name " " arch-name)))
16030 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16031 (downcase arch-name) t))))
16032 (message "Generating configuration \"%s\"..." conf-name)
16033 (if vhdl-compose-configuration-create-file
16034 ;; open configuration file
16036 (setq conf-file-name
16037 (concat (vhdl-replace-string vhdl-configuration-file-name
16039 "." (file-name-extension (buffer-file-name))))
16040 (when (and (file-exists-p conf-file-name)
16041 (not (y-or-n-p (concat "File \"" conf-file-name
16042 "\" exists; overwrite? "))))
16043 (error "ERROR: Creating configuration...aborted"))
16044 (find-file conf-file-name)
16046 (set-buffer-modified-p nil)
16048 (if vhdl-compose-include-header
16049 (progn (vhdl-template-header
16050 (concat "Configuration declaration for design \""
16051 ent-name "(" arch-name ")\""))
16052 (goto-char (point-max)))
16053 (vhdl-comment-display-line) (insert "\n\n")))
16054 ;; goto end of architecture
16055 (unless from-speedbar
16056 (re-search-forward "^end\\>" nil)
16057 (end-of-line) (insert "\n\n")
16058 (vhdl-comment-display-line) (insert "\n\n")))
16059 ;; insert library clause
16061 (vhdl-template-standard-package (vhdl-work-library) nil)
16062 (when (/= pos (point))
16064 ;; insert configuration
16065 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16066 (vhdl-insert-keyword " OF ") (insert ent-name)
16067 (vhdl-insert-keyword " IS\n")
16068 (indent-to vhdl-basic-offset)
16069 ;; insert block configuration (for architecture)
16070 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16071 (vhdl-insert-keyword "END ") (insert conf-name ";")
16072 (when conf-file-name
16073 ;; insert footer and save
16075 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16076 (vhdl-template-footer)
16077 (vhdl-comment-display-line) (insert "\n"))
16080 (concat (format "Generating configuration \"%s\"...done" conf-name)
16081 (and conf-file-name
16082 (format "\n File created: \"%s\"" conf-file-name))))))
16085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16086 ;;; Compilation / Makefile generation
16087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16088 ;; (using `compile.el')
16090 (defun vhdl-makefile-name ()
16091 "Return the Makefile name of the current project or the current compiler if
16092 no project is defined."
16093 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16094 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16095 (vhdl-replace-string
16096 (cons "\\(.*\\)\n\\(.*\\)"
16097 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16098 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16100 (defun vhdl-compile-directory ()
16101 "Return the directory where compilation/make should be run."
16102 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16103 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16104 (directory (vhdl-resolve-env-variable
16106 (vhdl-replace-string
16107 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16108 (nth 6 compiler)))))
16109 (file-name-as-directory
16110 (if (file-name-absolute-p directory)
16112 (expand-file-name directory (vhdl-default-directory))))))
16114 (defun vhdl-uniquify (in-list)
16115 "Remove duplicate elements from IN-LIST."
16118 (add-to-list 'out-list (car in-list))
16119 (setq in-list (cdr in-list)))
16122 (defun vhdl-set-compiler (name)
16123 "Set current compiler to NAME."
16125 (list (let ((completion-ignore-case t))
16126 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16127 (if (assoc name vhdl-compiler-alist)
16128 (progn (setq vhdl-compiler name)
16129 (message "Current compiler: \"%s\"" vhdl-compiler))
16130 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16135 (defun vhdl-compile-init ()
16136 "Initialize for compilation."
16137 (when (or (null compilation-error-regexp-alist)
16138 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16139 compilation-error-regexp-alist)))
16140 ;; `compilation-error-regexp-alist'
16141 (let ((commands-alist vhdl-compiler-alist)
16142 regexp-alist sublist)
16143 (while commands-alist
16144 (setq sublist (nth 11 (car commands-alist)))
16145 (unless (or (equal "" (car sublist))
16146 (assoc (car sublist) regexp-alist))
16147 (setq regexp-alist (cons (list (nth 0 sublist)
16148 (if (= 0 (nth 1 sublist))
16149 (if (featurep 'xemacs) 9 nil)
16151 (nth 2 sublist) (nth 3 sublist))
16153 (setq commands-alist (cdr commands-alist)))
16154 (setq compilation-error-regexp-alist
16155 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16156 ;; `compilation-file-regexp-alist'
16157 (let ((commands-alist vhdl-compiler-alist)
16158 regexp-alist sublist)
16159 ;; matches vhdl-mode file name output
16160 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16161 (while commands-alist
16162 (setq sublist (nth 12 (car commands-alist)))
16163 (unless (or (equal "" (car sublist))
16164 (assoc (car sublist) regexp-alist))
16165 (setq regexp-alist (cons sublist regexp-alist)))
16166 (setq commands-alist (cdr commands-alist)))
16167 (setq compilation-file-regexp-alist
16168 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16170 (defvar vhdl-compile-file-name nil
16171 "Name of file to be compiled.")
16173 (defun vhdl-compile-print-file-name ()
16174 "Function called within `compile' to print out file name for compilers that
16175 do not print any file names."
16176 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16178 (defun vhdl-get-compile-options (project compiler file-name
16179 &optional file-options-only)
16180 "Get compiler options. Returning nil means do not compile this file."
16181 (let* ((compiler-options (nth 1 compiler))
16182 (project-entry (aget (nth 4 project) vhdl-compiler))
16183 (project-options (nth 0 project-entry))
16184 (exception-list (and file-name (nth 2 project-entry)))
16185 (work-library (vhdl-work-library))
16186 (case-fold-search nil)
16188 (while (and exception-list
16189 (not (string-match (caar exception-list) file-name)))
16190 (setq exception-list (cdr exception-list)))
16191 (if (and exception-list (not (cdar exception-list)))
16193 (if (and file-options-only (not exception-list))
16195 (setq file-options (cdar exception-list))
16196 ;; insert library name in compiler-specific options
16197 (setq compiler-options
16198 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16200 ;; insert compiler-specific options in project-specific options
16201 (when project-options
16202 (setq project-options
16203 (vhdl-replace-string
16204 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16205 (concat work-library "\n" compiler-options))))
16206 ;; insert project-specific options in file-specific options
16209 (vhdl-replace-string
16210 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16211 (concat work-library "\n" compiler-options "\n"
16212 project-options))))
16214 (or file-options project-options compiler-options)))))
16216 (defun vhdl-get-make-options (project compiler)
16217 "Get make options."
16218 (let* ((compiler-options (nth 3 compiler))
16219 (project-entry (aget (nth 4 project) vhdl-compiler))
16220 (project-options (nth 1 project-entry))
16221 (makefile-name (vhdl-makefile-name)))
16222 ;; insert Makefile name in compiler-specific options
16223 (setq compiler-options
16224 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16226 ;; insert compiler-specific options in project-specific options
16227 (when project-options
16228 (setq project-options
16229 (vhdl-replace-string
16230 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16231 (concat makefile-name "\n" compiler-options))))
16233 (or project-options compiler-options)))
16235 (defun vhdl-compile ()
16236 "Compile current buffer using the VHDL compiler specified in
16239 (vhdl-compile-init)
16240 (let* ((project (aget vhdl-project-alist vhdl-project))
16241 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16242 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16243 (command (nth 0 compiler))
16244 (file-name (buffer-file-name))
16245 (options (vhdl-get-compile-options project compiler file-name))
16246 (default-directory (vhdl-compile-directory))
16247 compilation-process-setup-function)
16248 (unless (file-directory-p default-directory)
16249 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16250 ;; put file name into quotes if it contains spaces
16251 (when (string-match " " file-name)
16252 (setq file-name (concat "\"" file-name "\"")))
16253 ;; print out file name if compiler does not
16254 (setq vhdl-compile-file-name (buffer-file-name))
16255 (when (and (= 0 (nth 1 (nth 10 compiler)))
16256 (= 0 (nth 1 (nth 11 compiler))))
16257 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16261 (compile (concat command " " options " " file-name)))
16262 (vhdl-warning "Your project settings tell me not to compile this file"))))
16264 (defvar vhdl-make-target "all"
16265 "Default target for `vhdl-make' command.")
16267 (defun vhdl-make (&optional target)
16268 "Call make command for compilation of all updated source files (requires
16269 `Makefile'). Optional argument TARGET allows to compile the design
16270 specified by a target."
16272 (setq vhdl-make-target
16273 (or target (read-from-minibuffer "Target: " vhdl-make-target
16274 vhdl-minibuffer-local-map)))
16275 (vhdl-compile-init)
16276 (let* ((project (aget vhdl-project-alist vhdl-project))
16277 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16278 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16279 (command (nth 2 compiler))
16280 (options (vhdl-get-make-options project compiler))
16281 (default-directory (vhdl-compile-directory)))
16282 (unless (file-directory-p default-directory)
16283 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16285 (compile (concat (if (equal command "") "make" command)
16286 " " options " " vhdl-make-target))))
16288 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16289 ;; Makefile generation
16291 (defun vhdl-generate-makefile ()
16292 "Generate `Makefile'."
16294 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16295 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16296 (command (nth 4 compiler)))
16297 ;; generate makefile
16299 (let ((default-directory (vhdl-compile-directory)))
16300 (compile (vhdl-replace-string
16301 (cons "\\(.*\\) \\(.*\\)" command)
16302 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16303 (vhdl-generate-makefile-1))))
16305 (defun vhdl-get-packages (lib-alist work-library)
16306 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16309 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16310 (setq pack-list (cons (cdar lib-alist) pack-list)))
16311 (setq lib-alist (cdr lib-alist)))
16314 (defun vhdl-generate-makefile-1 ()
16315 "Generate Makefile for current project or directory."
16316 ;; scan hierarchy if required
16317 (if (vhdl-project-p)
16318 (unless (or (assoc vhdl-project vhdl-file-alist)
16319 (vhdl-load-cache vhdl-project))
16320 (vhdl-scan-project-contents vhdl-project))
16321 (let ((directory (abbreviate-file-name default-directory)))
16322 (unless (or (assoc directory vhdl-file-alist)
16323 (vhdl-load-cache directory))
16324 (vhdl-scan-directory-contents directory))))
16325 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16326 (project (vhdl-project-p))
16327 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16328 (conf-alist (aget vhdl-config-alist (or project directory) t))
16329 (pack-alist (aget vhdl-package-alist (or project directory) t))
16330 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16331 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16332 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16333 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16334 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16335 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16336 (adjust-case (nth 5 regexp-list))
16337 (work-library (downcase (vhdl-work-library)))
16338 (compile-directory (expand-file-name (vhdl-compile-directory)
16339 default-directory))
16340 (makefile-name (vhdl-makefile-name))
16341 rule-alist arch-alist inst-alist
16342 target-list depend-list unit-list prim-list second-list subcomp-list
16343 lib-alist lib-body-alist pack-list all-pack-list
16344 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16345 conf-key conf-file-name pack-key pack-file-name
16346 ent-entry arch-entry conf-entry pack-entry inst-entry
16347 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16348 tmp-key tmp-list rule)
16349 ;; check prerequisites
16350 (unless (file-exists-p compile-directory)
16351 (make-directory compile-directory t))
16352 (unless regexp-list
16353 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16355 (message "Generating makefile \"%s\"..." makefile-name)
16356 ;; rules for all entities
16357 (setq tmp-list ent-alist)
16359 (setq ent-entry (car ent-alist)
16360 ent-key (nth 0 ent-entry))
16361 (when (nth 2 ent-entry)
16362 (setq ent-file-name (file-relative-name
16363 (nth 2 ent-entry) compile-directory)
16364 arch-alist (nth 4 ent-entry)
16365 lib-alist (nth 6 ent-entry)
16366 rule (aget rule-alist ent-file-name)
16367 target-list (nth 0 rule)
16368 depend-list (nth 1 rule)
16371 (setq tmp-key (vhdl-replace-string
16372 ent-regexp (funcall adjust-case ent-key)))
16373 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16374 ;; rule target for this entity
16375 (setq target-list (cons ent-key target-list))
16376 ;; rule dependencies for all used packages
16377 (setq pack-list (vhdl-get-packages lib-alist work-library))
16378 (setq depend-list (append depend-list pack-list))
16379 (setq all-pack-list pack-list)
16381 (aput 'rule-alist ent-file-name (list target-list depend-list))
16382 ;; rules for all corresponding architectures
16384 (setq arch-entry (car arch-alist)
16385 arch-key (nth 0 arch-entry)
16386 ent-arch-key (concat ent-key "-" arch-key)
16387 arch-file-name (file-relative-name (nth 2 arch-entry)
16389 inst-alist (nth 4 arch-entry)
16390 lib-alist (nth 5 arch-entry)
16391 rule (aget rule-alist arch-file-name)
16392 target-list (nth 0 rule)
16393 depend-list (nth 1 rule))
16394 (setq tmp-key (vhdl-replace-string
16396 (funcall adjust-case (concat arch-key " " ent-key))))
16398 (cons (cons ent-arch-key tmp-key) unit-list))
16399 (setq second-list (cons ent-arch-key second-list))
16400 ;; rule target for this architecture
16401 (setq target-list (cons ent-arch-key target-list))
16402 ;; rule dependency for corresponding entity
16403 (setq depend-list (cons ent-key depend-list))
16404 ;; rule dependencies for contained component instantiations
16406 (setq inst-entry (car inst-alist))
16407 (when (or (null (nth 8 inst-entry))
16408 (equal (downcase (nth 8 inst-entry)) work-library))
16409 (setq inst-ent-key (or (nth 7 inst-entry)
16410 (nth 5 inst-entry)))
16411 (setq depend-list (cons inst-ent-key depend-list)
16412 subcomp-list (cons inst-ent-key subcomp-list)))
16413 (setq inst-alist (cdr inst-alist)))
16414 ;; rule dependencies for all used packages
16415 (setq pack-list (vhdl-get-packages lib-alist work-library))
16416 (setq depend-list (append depend-list pack-list))
16417 (setq all-pack-list (append all-pack-list pack-list))
16419 (aput 'rule-alist arch-file-name (list target-list depend-list))
16420 (setq arch-alist (cdr arch-alist)))
16421 (setq prim-list (cons (list ent-key second-list
16422 (append subcomp-list all-pack-list))
16424 (setq ent-alist (cdr ent-alist)))
16425 (setq ent-alist tmp-list)
16426 ;; rules for all configurations
16427 (setq tmp-list conf-alist)
16429 (setq conf-entry (car conf-alist)
16430 conf-key (nth 0 conf-entry)
16431 conf-file-name (file-relative-name
16432 (nth 2 conf-entry) compile-directory)
16433 ent-key (nth 4 conf-entry)
16434 arch-key (nth 5 conf-entry)
16435 inst-alist (nth 6 conf-entry)
16436 lib-alist (nth 7 conf-entry)
16437 rule (aget rule-alist conf-file-name)
16438 target-list (nth 0 rule)
16439 depend-list (nth 1 rule)
16440 subcomp-list (list ent-key))
16441 (setq tmp-key (vhdl-replace-string
16442 conf-regexp (funcall adjust-case conf-key)))
16443 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16444 ;; rule target for this configuration
16445 (setq target-list (cons conf-key target-list))
16446 ;; rule dependency for corresponding entity and architecture
16448 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16449 ;; rule dependencies for used packages
16450 (setq pack-list (vhdl-get-packages lib-alist work-library))
16451 (setq depend-list (append depend-list pack-list))
16452 ;; rule dependencies for contained component configurations
16454 (setq inst-entry (car inst-alist))
16455 (setq inst-ent-key (nth 2 inst-entry)
16456 ; comp-arch-key (nth 2 inst-entry))
16457 inst-conf-key (nth 4 inst-entry))
16458 (when (equal (downcase (nth 5 inst-entry)) work-library)
16460 (setq depend-list (cons inst-ent-key depend-list)
16461 subcomp-list (cons inst-ent-key subcomp-list)))
16462 ; (when comp-arch-key
16463 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16465 (when inst-conf-key
16466 (setq depend-list (cons inst-conf-key depend-list)
16467 subcomp-list (cons inst-conf-key subcomp-list))))
16468 (setq inst-alist (cdr inst-alist)))
16470 (aput 'rule-alist conf-file-name (list target-list depend-list))
16471 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16473 (setq conf-alist (cdr conf-alist)))
16474 (setq conf-alist tmp-list)
16475 ;; rules for all packages
16476 (setq tmp-list pack-alist)
16478 (setq pack-entry (car pack-alist)
16479 pack-key (nth 0 pack-entry)
16481 (when (nth 2 pack-entry)
16482 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16484 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16485 rule (aget rule-alist pack-file-name)
16486 target-list (nth 0 rule) depend-list (nth 1 rule))
16487 (setq tmp-key (vhdl-replace-string
16488 pack-regexp (funcall adjust-case pack-key)))
16489 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16490 ;; rule target for this package
16491 (setq target-list (cons pack-key target-list))
16492 ;; rule dependencies for all used packages
16493 (setq pack-list (vhdl-get-packages lib-alist work-library))
16494 (setq depend-list (append depend-list pack-list))
16495 (setq all-pack-list pack-list)
16497 (aput 'rule-alist pack-file-name (list target-list depend-list))
16498 ;; rules for this package's body
16499 (when (nth 7 pack-entry)
16500 (setq pack-body-key (concat pack-key "-body")
16501 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16503 rule (aget rule-alist pack-body-file-name)
16504 target-list (nth 0 rule)
16505 depend-list (nth 1 rule))
16506 (setq tmp-key (vhdl-replace-string
16507 pack-body-regexp (funcall adjust-case pack-key)))
16509 (cons (cons pack-body-key tmp-key) unit-list))
16510 ;; rule target for this package's body
16511 (setq target-list (cons pack-body-key target-list))
16512 ;; rule dependency for corresponding package declaration
16513 (setq depend-list (cons pack-key depend-list))
16514 ;; rule dependencies for all used packages
16515 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16516 (setq depend-list (append depend-list pack-list))
16517 (setq all-pack-list (append all-pack-list pack-list))
16519 (aput 'rule-alist pack-body-file-name
16520 (list target-list depend-list)))
16522 (cons (list pack-key (when pack-body-key (list pack-body-key))
16525 (setq pack-alist (cdr pack-alist)))
16526 (setq pack-alist tmp-list)
16527 ;; generate Makefile
16528 (let* ((project (aget vhdl-project-alist project))
16529 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16530 (compiler-id (nth 9 compiler))
16532 (vhdl-resolve-env-variable
16533 (vhdl-replace-string
16534 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16536 (makefile-path-name (expand-file-name
16537 makefile-name compile-directory))
16538 (orig-buffer (current-buffer))
16539 cell second-list subcomp-list options unit-key unit-name)
16541 (setq unit-list (vhdl-sort-alist unit-list))
16542 (setq prim-list (vhdl-sort-alist prim-list))
16543 (setq tmp-list rule-alist)
16544 (while tmp-list ; pre-sort rule targets
16545 (setq cell (cdar tmp-list))
16546 (setcar cell (sort (car cell) 'string<))
16547 (setq tmp-list (cdr tmp-list)))
16548 (setq rule-alist ; sort by first rule target
16550 (function (lambda (a b)
16551 (string< (car (cadr a)) (car (cadr b)))))))
16552 ;; open and clear Makefile
16553 (set-buffer (find-file-noselect makefile-path-name t t))
16555 (insert "# -*- Makefile -*-\n"
16556 "### " (file-name-nondirectory makefile-name)
16557 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16560 (insert "\n# Project : " (nth 0 project))
16561 (insert "\n# Directory : \"" directory "\""))
16562 (insert "\n# Platform : " vhdl-compiler
16563 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16564 (user-login-name) "\n")
16565 ;; insert compile and option variable settings
16566 (insert "\n\n# Define compilation command and options\n"
16567 "\nCOMPILE = " (nth 0 compiler)
16568 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16570 ;; insert library paths
16571 (setq library-directory
16572 (directory-file-name
16573 (if (file-name-absolute-p library-directory)
16575 (file-relative-name
16576 (expand-file-name library-directory directory)
16577 compile-directory))))
16578 (insert "\n\n# Define library paths\n"
16579 "\nLIBRARY-" work-library " = " library-directory "\n")
16580 ;; insert variable definitions for all library unit files
16581 (insert "\n\n# Define library unit files\n")
16582 (setq tmp-list unit-list)
16584 (insert "\nUNIT-" work-library "-" (caar unit-list)
16585 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16586 (setq unit-list (cdr unit-list)))
16587 ;; insert variable definition for list of all library unit files
16588 (insert "\n\n\n# Define list of all library unit files\n"
16590 (setq unit-list tmp-list)
16592 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16593 (setq unit-list (cdr unit-list)))
16595 (setq unit-list tmp-list)
16596 ;; insert `make all' rule
16597 (insert "\n\n\n# Rule for compiling entire design\n"
16600 " \\\n\t\t$(ALL_UNITS)\n")
16601 ;; insert `make clean' rule
16602 (insert "\n\n# Rule for cleaning entire design\n"
16604 "\n\t-rm -f $(ALL_UNITS)\n")
16605 ;; insert `make library' rule
16606 (insert "\n\n# Rule for creating library directory\n"
16608 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16609 "\n$(LIBRARY-" work-library ") :"
16611 (vhdl-replace-string
16612 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16613 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16615 ;; insert rule for each library unit
16616 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16618 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16620 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16621 (setq unit-key (caar prim-list)
16622 unit-name (or (nth 0 (aget ent-alist unit-key t))
16623 (nth 0 (aget conf-alist unit-key t))
16624 (nth 0 (aget pack-alist unit-key t))))
16625 (insert "\n" unit-key)
16626 (unless (equal unit-key unit-name)
16627 (insert " \\\n" unit-name))
16630 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16632 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16633 (setq second-list (cdr second-list)))
16634 (while subcomp-list
16635 (when (and (assoc (car subcomp-list) unit-list)
16636 (not (equal unit-key (car subcomp-list))))
16637 (insert " \\\n\t\t" (car subcomp-list)))
16638 (setq subcomp-list (cdr subcomp-list)))
16640 (setq prim-list (cdr prim-list)))
16641 ;; insert rule for each library unit file
16642 (insert "\n\n# Rules for compiling single library unit files\n")
16644 (setq rule (car rule-alist))
16645 ;; get compiler options for this file
16647 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16648 ;; insert rule if file is supposed to be compiled
16649 (setq target-list (nth 1 rule)
16650 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16652 (setq tmp-list target-list)
16654 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16655 (if (cdr target-list) " \\" " :"))
16656 (setq target-list (cdr target-list)))
16657 (setq target-list tmp-list)
16658 ;; insert file name as first dependency
16659 (insert " \\\n\t\t" (nth 0 rule))
16660 ;; insert dependencies (except if also target or unit does not exist)
16662 (when (and (not (member (car depend-list) target-list))
16663 (assoc (car depend-list) unit-list))
16664 (insert " \\\n\t\t"
16665 "$(UNIT-" work-library "-" (car depend-list) ")"))
16666 (setq depend-list (cdr depend-list)))
16667 ;; insert compile command
16669 (insert "\n\t$(COMPILE) "
16670 (if (eq options 'default) "$(OPTIONS)" options) " "
16672 (setq tmp-list target-list)
16674 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16675 (if (cdr target-list) " \\" "\n"))
16676 (setq target-list (cdr target-list)))
16677 (setq target-list tmp-list))
16678 (setq rule-alist (cdr rule-alist)))
16679 (insert "\n\n### " makefile-name " ends here\n")
16680 ;; run Makefile generation hook
16681 (run-hooks 'vhdl-makefile-generation-hook)
16682 (message "Generating makefile \"%s\"...done" makefile-name)
16683 ;; save and close file
16684 (if (file-writable-p makefile-path-name)
16685 (progn (save-buffer)
16686 (kill-buffer (current-buffer))
16687 (set-buffer orig-buffer)
16688 (add-to-history 'file-name-history makefile-path-name))
16689 (vhdl-warning-when-idle
16690 (format "File not writable: \"%s\""
16691 (abbreviate-file-name makefile-path-name)))
16692 (switch-to-buffer (current-buffer))))))
16695 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16698 ;; (using `reporter.el')
16700 (defconst vhdl-mode-help-address
16701 "Reto Zimmermann <reto@gnu.org>"
16702 "Address for VHDL Mode bug reports.")
16704 (defun vhdl-submit-bug-report ()
16705 "Submit via mail a bug report on VHDL Mode."
16707 ;; load in reporter
16709 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16710 (let ((reporter-prompt-for-summary-p t))
16711 (reporter-submit-bug-report
16712 vhdl-mode-help-address
16713 (concat "VHDL Mode " vhdl-version)
16715 ;; report all important user options
16716 'vhdl-offsets-alist
16717 'vhdl-comment-only-line-offset
16719 'vhdl-electric-mode
16721 'vhdl-indent-tabs-mode
16722 'vhdl-project-alist
16724 'vhdl-project-file-name
16725 'vhdl-project-auto-load
16727 'vhdl-compiler-alist
16729 'vhdl-compile-use-local-error-regexp
16730 'vhdl-makefile-generation-hook
16731 'vhdl-default-library
16734 'vhdl-upper-case-keywords
16735 'vhdl-upper-case-types
16736 'vhdl-upper-case-attributes
16737 'vhdl-upper-case-enum-values
16738 'vhdl-upper-case-constants
16739 'vhdl-use-direct-instantiation
16740 'vhdl-compose-configuration-name
16741 'vhdl-entity-file-name
16742 'vhdl-architecture-file-name
16743 'vhdl-configuration-file-name
16744 'vhdl-package-file-name
16745 'vhdl-file-name-case
16746 'vhdl-electric-keywords
16747 'vhdl-optional-labels
16748 'vhdl-insert-empty-lines
16749 'vhdl-argument-list-indent
16750 'vhdl-association-list-with-formals
16751 'vhdl-conditions-in-parenthesis
16757 'vhdl-copyright-string
16758 'vhdl-platform-spec
16760 'vhdl-modify-date-prefix-string
16761 'vhdl-modify-date-on-saving
16763 'vhdl-reset-active-high
16764 'vhdl-clock-rising-edge
16765 'vhdl-clock-edge-condition
16769 'vhdl-include-port-comments
16770 'vhdl-include-direction-comments
16771 'vhdl-include-type-comments
16772 'vhdl-include-group-comments
16773 'vhdl-actual-port-name
16774 'vhdl-instance-name
16775 'vhdl-testbench-entity-name
16776 'vhdl-testbench-architecture-name
16777 'vhdl-testbench-configuration-name
16778 'vhdl-testbench-dut-name
16779 'vhdl-testbench-include-header
16780 'vhdl-testbench-declarations
16781 'vhdl-testbench-statements
16782 'vhdl-testbench-initialize-signals
16783 'vhdl-testbench-include-library
16784 'vhdl-testbench-include-configuration
16785 'vhdl-testbench-create-files
16786 'vhdl-testbench-entity-file-name
16787 'vhdl-testbench-architecture-file-name
16788 'vhdl-compose-create-files
16789 'vhdl-compose-configuration-create-file
16790 'vhdl-compose-configuration-hierarchical
16791 'vhdl-compose-configuration-use-subconfiguration
16792 'vhdl-compose-include-header
16793 'vhdl-compose-architecture-name
16794 'vhdl-components-package-name
16795 'vhdl-use-components-package
16796 'vhdl-self-insert-comments
16797 'vhdl-prompt-for-comments
16798 'vhdl-inline-comment-column
16799 'vhdl-end-comment-column
16802 'vhdl-align-group-separate
16803 'vhdl-align-same-indent
16804 'vhdl-highlight-keywords
16805 'vhdl-highlight-names
16806 'vhdl-highlight-special-words
16807 'vhdl-highlight-forbidden-words
16808 'vhdl-highlight-verilog-keywords
16809 'vhdl-highlight-translate-off
16810 'vhdl-highlight-case-sensitive
16811 'vhdl-special-syntax-alist
16812 'vhdl-forbidden-words
16813 'vhdl-forbidden-syntax
16814 'vhdl-directive-keywords
16815 'vhdl-speedbar-auto-open
16816 'vhdl-speedbar-display-mode
16817 'vhdl-speedbar-scan-limit
16818 'vhdl-speedbar-jump-to-unit
16819 'vhdl-speedbar-update-on-saving
16820 'vhdl-speedbar-save-cache
16821 'vhdl-speedbar-cache-file-name
16823 'vhdl-source-file-menu
16824 'vhdl-hideshow-menu
16825 'vhdl-hide-all-init
16826 'vhdl-print-two-column
16827 'vhdl-print-customize-faces
16828 'vhdl-intelligent-tab
16829 'vhdl-indent-syntax-based
16830 'vhdl-word-completion-case-sensitive
16831 'vhdl-word-completion-in-minibuffer
16832 'vhdl-underscore-is-part-of-word
16837 (if vhdl-special-indent-hook
16838 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16839 "vhdl-special-indent-hook is set to '"
16840 (format "%s" vhdl-special-indent-hook)
16841 ".\nPerhaps this is your problem?\n"
16842 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16848 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16852 (defconst vhdl-doc-release-notes nil
16854 Release Notes for VHDL Mode 3.33
16855 ================================
16864 CONFIGURATION DECLARATION GENERATION:
16865 - Automatic generation of a configuration declaration for a design.
16866 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16872 `vhdl-configuration-file-name': (new)
16873 Specify how the configuration file name is obtained.
16874 `vhdl-compose-configuration-name': (new)
16875 Specify how the configuration name is optained.
16876 `vhdl-compose-configuration-create-file': (new)
16877 Specify whether a new file should be created for a configuration.
16878 `vhdl-compose-configuration-hierarchical': (new)
16879 Specify whether hierarchical configurations should be created.
16880 `vhdl-compose-configuration-use-subconfiguration': (new)
16881 Specify whether subconfigurations should be used inside configurations.
16885 (defconst vhdl-doc-keywords nil
16887 Reserved words in VHDL
16888 ----------------------
16890 VHDL'93 (IEEE Std 1076-1993):
16891 `vhdl-93-keywords' : keywords
16892 `vhdl-93-types' : standardized types
16893 `vhdl-93-attributes' : standardized attributes
16894 `vhdl-93-enum-values' : standardized enumeration values
16895 `vhdl-93-functions' : standardized functions
16896 `vhdl-93-packages' : standardized packages and libraries
16898 VHDL-AMS (IEEE Std 1076.1):
16899 `vhdl-ams-keywords' : keywords
16900 `vhdl-ams-types' : standardized types
16901 `vhdl-ams-attributes' : standardized attributes
16902 `vhdl-ams-enum-values' : standardized enumeration values
16903 `vhdl-ams-functions' : standardized functions
16905 Math Packages (IEEE Std 1076.2):
16906 `vhdl-math-types' : standardized types
16907 `vhdl-math-constants' : standardized constants
16908 `vhdl-math-functions' : standardized functions
16909 `vhdl-math-packages' : standardized packages
16912 `vhdl-verilog-keywords' : Verilog reserved words
16914 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16917 (defconst vhdl-doc-coding-style nil
16919 For VHDL coding style and naming convention guidelines, see the following
16923 \"VHDL Coding Styles and Methodologies\".
16924 Kluwer Academic Publishers, 1999.
16925 http://members.aol.com/vhdlcohen/vhdl/
16927 \[2] Michael Keating and Pierre Bricaud.
16928 \"Reuse Methodology Manual, Second Edition\".
16929 Kluwer Academic Publishers, 1999.
16930 http://www.openmore.com/openmore/rmm2.html
16932 \[3] European Space Agency.
16933 \"VHDL Modelling Guidelines\".
16934 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16936 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16937 to visually support naming conventions.")
16940 (defun vhdl-version ()
16941 "Echo the current version of VHDL Mode in the minibuffer."
16943 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16944 (vhdl-keep-region-active))
16946 (defun vhdl-doc-variable (variable)
16947 "Display VARIABLE's documentation in *Help* buffer."
16949 (unless (featurep 'xemacs)
16950 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16951 (with-output-to-temp-buffer
16952 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16953 (princ (documentation-property variable 'variable-documentation))
16954 (with-current-buffer standard-output
16956 (help-print-return-message)))
16958 (defun vhdl-doc-mode ()
16959 "Display VHDL Mode documentation in *Help* buffer."
16961 (unless (featurep 'xemacs)
16962 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16963 (with-output-to-temp-buffer
16964 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16967 (princ (documentation 'vhdl-mode))
16968 (with-current-buffer standard-output
16970 (help-print-return-message)))
16973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16975 (provide 'vhdl-mode)
16977 ;;; vhdl-mode.el ends here